ReactOS  0.4.14-dev-376-gaedba84
tbxfload.c
Go to the documentation of this file.
1 /******************************************************************************
2  *
3  * Module Name: tbxfload - Table load/unload external interfaces
4  *
5  *****************************************************************************/
6 
7 /*
8  * Copyright (C) 2000 - 2019, Intel Corp.
9  * All rights reserved.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  * 1. Redistributions of source code must retain the above copyright
15  * notice, this list of conditions, and the following disclaimer,
16  * without modification.
17  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18  * substantially similar to the "NO WARRANTY" disclaimer below
19  * ("Disclaimer") and any redistribution must be conditioned upon
20  * including a substantially similar Disclaimer requirement for further
21  * binary redistribution.
22  * 3. Neither the names of the above-listed copyright holders nor the names
23  * of any contributors may be used to endorse or promote products derived
24  * from this software without specific prior written permission.
25  *
26  * Alternatively, this software may be distributed under the terms of the
27  * GNU General Public License ("GPL") version 2 as published by the Free
28  * Software Foundation.
29  *
30  * NO WARRANTY
31  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41  * POSSIBILITY OF SUCH DAMAGES.
42  */
43 
44 #define EXPORT_ACPI_INTERFACES
45 
46 #include "acpi.h"
47 #include "accommon.h"
48 #include "acnamesp.h"
49 #include "actables.h"
50 #include "acevents.h"
51 
52 #define _COMPONENT ACPI_TABLES
53  ACPI_MODULE_NAME ("tbxfload")
54 
55 
56 /*******************************************************************************
57  *
58  * FUNCTION: AcpiLoadTables
59  *
60  * PARAMETERS: None
61  *
62  * RETURN: Status
63  *
64  * DESCRIPTION: Load the ACPI tables from the RSDT/XSDT
65  *
66  ******************************************************************************/
67 
70  void)
71 {
73 
74 
76 
77 
78  /*
79  * Install the default operation region handlers. These are the
80  * handlers that are defined by the ACPI specification to be
81  * "always accessible" -- namely, SystemMemory, SystemIO, and
82  * PCI_Config. This also means that no _REG methods need to be
83  * run for these address spaces. We need to have these handlers
84  * installed before any AML code can be executed, especially any
85  * module-level code (11/2015).
86  * Note that we allow OSPMs to install their own region handlers
87  * between AcpiInitializeSubsystem() and AcpiLoadTables() to use
88  * their customized default region handlers.
89  */
91  if (ACPI_FAILURE (Status))
92  {
93  ACPI_EXCEPTION ((AE_INFO, Status, "During Region initialization"));
95  }
96 
97  /* Load the namespace from the tables */
98 
100 
101  /* Don't let single failures abort the load */
102 
103  if (Status == AE_CTRL_TERMINATE)
104  {
105  Status = AE_OK;
106  }
107 
108  if (ACPI_FAILURE (Status))
109  {
111  "While loading namespace from ACPI tables"));
112  }
113 
114  /*
115  * Initialize the objects in the namespace that remain uninitialized.
116  * This runs the executable AML that may be part of the declaration of
117  * these name objects:
118  * OperationRegions, BufferFields, Buffers, and Packages.
119  *
120  */
122  if (ACPI_SUCCESS (Status))
123  {
124  AcpiGbl_NamespaceInitialized = TRUE;
125  }
126 
128 }
129 
131 
132 
133 /*******************************************************************************
134  *
135  * FUNCTION: AcpiTbLoadNamespace
136  *
137  * PARAMETERS: None
138  *
139  * RETURN: Status
140  *
141  * DESCRIPTION: Load the namespace from the DSDT and all SSDTs/PSDTs found in
142  * the RSDT/XSDT.
143  *
144  ******************************************************************************/
145 
148  void)
149 {
151  UINT32 i;
152  ACPI_TABLE_HEADER *NewDsdt;
154  UINT32 TablesLoaded = 0;
155  UINT32 TablesFailed = 0;
156 
157 
158  ACPI_FUNCTION_TRACE (TbLoadNamespace);
159 
160 
162 
163  /*
164  * Load the namespace. The DSDT is required, but any SSDT and
165  * PSDT tables are optional. Verify the DSDT.
166  */
167  Table = &AcpiGbl_RootTableList.Tables[AcpiGbl_DsdtIndex];
168 
169  if (!AcpiGbl_RootTableList.CurrentTableCount ||
170  !ACPI_COMPARE_NAMESEG (Table->Signature.Ascii, ACPI_SIG_DSDT) ||
172  {
174  goto UnlockAndExit;
175  }
176 
177  /*
178  * Save the DSDT pointer for simple access. This is the mapped memory
179  * address. We must take care here because the address of the .Tables
180  * array can change dynamically as tables are loaded at run-time. Note:
181  * .Pointer field is not validated until after call to AcpiTbValidateTable.
182  */
183  AcpiGbl_DSDT = Table->Pointer;
184 
185  /*
186  * Optionally copy the entire DSDT to local memory (instead of simply
187  * mapping it.) There are some BIOSs that corrupt or replace the original
188  * DSDT, creating the need for this option. Default is FALSE, do not copy
189  * the DSDT.
190  */
191  if (AcpiGbl_CopyDsdtLocally)
192  {
193  NewDsdt = AcpiTbCopyDsdt (AcpiGbl_DsdtIndex);
194  if (NewDsdt)
195  {
196  AcpiGbl_DSDT = NewDsdt;
197  }
198  }
199 
200  /*
201  * Save the original DSDT header for detection of table corruption
202  * and/or replacement of the DSDT from outside the OS.
203  */
204  memcpy (&AcpiGbl_OriginalDsdtHeader, AcpiGbl_DSDT,
205  sizeof (ACPI_TABLE_HEADER));
206 
207  /* Load and parse tables */
208 
210  Status = AcpiNsLoadTable (AcpiGbl_DsdtIndex, AcpiGbl_RootNode);
212  if (ACPI_FAILURE (Status))
213  {
214  ACPI_EXCEPTION ((AE_INFO, Status, "[DSDT] table load failed"));
215  TablesFailed++;
216  }
217  else
218  {
219  TablesLoaded++;
220  }
221 
222  /* Load any SSDT or PSDT tables. Note: Loop leaves tables locked */
223 
224  for (i = 0; i < AcpiGbl_RootTableList.CurrentTableCount; ++i)
225  {
226  Table = &AcpiGbl_RootTableList.Tables[i];
227 
228  if (!Table->Address ||
229  (!ACPI_COMPARE_NAMESEG (Table->Signature.Ascii, ACPI_SIG_SSDT) &&
230  !ACPI_COMPARE_NAMESEG (Table->Signature.Ascii, ACPI_SIG_PSDT) &&
231  !ACPI_COMPARE_NAMESEG (Table->Signature.Ascii, ACPI_SIG_OSDT)) ||
233  {
234  continue;
235  }
236 
237  /* Ignore errors while loading tables, get as many as possible */
238 
240  Status = AcpiNsLoadTable (i, AcpiGbl_RootNode);
242  if (ACPI_FAILURE (Status))
243  {
244  ACPI_EXCEPTION ((AE_INFO, Status, "(%4.4s:%8.8s) while loading table",
245  Table->Signature.Ascii, Table->Pointer->OemTableId));
246 
247  TablesFailed++;
248 
250  "Table [%4.4s:%8.8s] (id FF) - Table namespace load failed\n\n",
251  Table->Signature.Ascii, Table->Pointer->OemTableId));
252  }
253  else
254  {
255  TablesLoaded++;
256  }
257  }
258 
259  if (!TablesFailed)
260  {
261  ACPI_INFO ((
262  "%u ACPI AML tables successfully acquired and loaded",
263  TablesLoaded));
264  }
265  else
266  {
268  "%u table load failures, %u successful",
269  TablesFailed, TablesLoaded));
270 
271  /* Indicate at least one failure */
272 
274  }
275 
276 #ifdef ACPI_APPLICATION
278 #endif
279 
280 
281 UnlockAndExit:
284 }
285 
286 
287 /*******************************************************************************
288  *
289  * FUNCTION: AcpiInstallTable
290  *
291  * PARAMETERS: Address - Address of the ACPI table to be installed.
292  * Physical - Whether the address is a physical table
293  * address or not
294  *
295  * RETURN: Status
296  *
297  * DESCRIPTION: Dynamically install an ACPI table.
298  * Note: This function should only be invoked after
299  * AcpiInitializeTables() and before AcpiLoadTables().
300  *
301  ******************************************************************************/
302 
305  ACPI_PHYSICAL_ADDRESS Address,
306  BOOLEAN Physical)
307 {
309  UINT8 Flags;
310  UINT32 TableIndex;
311 
312 
314 
315 
316  if (Physical)
317  {
319  }
320  else
321  {
323  }
324 
326  FALSE, FALSE, &TableIndex);
327 
329 }
330 
332 
333 
334 /*******************************************************************************
335  *
336  * FUNCTION: AcpiLoadTable
337  *
338  * PARAMETERS: Table - Pointer to a buffer containing the ACPI
339  * table to be loaded.
340  * TableIdx - Pointer to a UINT32 for storing the table
341  * index, might be NULL
342  *
343  * RETURN: Status
344  *
345  * DESCRIPTION: Dynamically load an ACPI table from the caller's buffer. Must
346  * be a valid ACPI table with a valid ACPI table header.
347  * Note1: Mainly intended to support hotplug addition of SSDTs.
348  * Note2: Does not copy the incoming table. User is responsible
349  * to ensure that the table is not deleted or unmapped.
350  *
351  ******************************************************************************/
352 
356  UINT32 *TableIdx)
357 {
359  UINT32 TableIndex;
360 
361 
363 
364 
365  /* Parameter validation */
366 
367  if (!Table)
368  {
370  }
371 
372  /* Install the table and load it into the namespace */
373 
374  ACPI_INFO (("Host-directed Dynamic ACPI Table Load:"));
377  if (TableIdx)
378  {
379  *TableIdx = TableIndex;
380  }
381 
382  if (ACPI_SUCCESS (Status))
383  {
384  /* Complete the initialization/resolution of new objects */
385 
387  }
388 
390 }
391 
393 
394 
395 /*******************************************************************************
396  *
397  * FUNCTION: AcpiUnloadParentTable
398  *
399  * PARAMETERS: Object - Handle to any namespace object owned by
400  * the table to be unloaded
401  *
402  * RETURN: Status
403  *
404  * DESCRIPTION: Via any namespace object within an SSDT or OEMx table, unloads
405  * the table and deletes all namespace objects associated with
406  * that table. Unloading of the DSDT is not allowed.
407  * Note: Mainly intended to support hotplug removal of SSDTs.
408  *
409  ******************************************************************************/
410 
414 {
418  UINT32 i;
419 
420 
422 
423 
424  /* Parameter validation */
425 
426  if (!Object)
427  {
429  }
430 
431  /*
432  * The node OwnerId is currently the same as the parent table ID.
433  * However, this could change in the future.
434  */
435  OwnerId = Node->OwnerId;
436  if (!OwnerId)
437  {
438  /* OwnerId==0 means DSDT is the owner. DSDT cannot be unloaded */
439 
441  }
442 
443  /* Must acquire the table lock during this operation */
444 
446  if (ACPI_FAILURE (Status))
447  {
449  }
450 
451  /* Find the table in the global table list */
452 
453  for (i = 0; i < AcpiGbl_RootTableList.CurrentTableCount; i++)
454  {
455  if (OwnerId != AcpiGbl_RootTableList.Tables[i].OwnerId)
456  {
457  continue;
458  }
459 
460  /*
461  * Allow unload of SSDT and OEMx tables only. Do not allow unload
462  * of the DSDT. No other types of tables should get here, since
463  * only these types can contain AML and thus are the only types
464  * that can create namespace objects.
465  */
467  AcpiGbl_RootTableList.Tables[i].Signature.Ascii,
468  ACPI_SIG_DSDT))
469  {
470  Status = AE_TYPE;
471  break;
472  }
473 
477  break;
478  }
479 
482 }
483 
485 
486 
487 /*******************************************************************************
488  *
489  * FUNCTION: AcpiUnloadTable
490  *
491  * PARAMETERS: TableIndex - Index as returned by AcpiLoadTable
492  *
493  * RETURN: Status
494  *
495  * DESCRIPTION: Via the TableIndex representing an SSDT or OEMx table, unloads
496  * the table and deletes all namespace objects associated with
497  * that table. Unloading of the DSDT is not allowed.
498  * Note: Mainly intended to support hotplug removal of SSDTs.
499  *
500  ******************************************************************************/
501 
504  UINT32 TableIndex)
505 {
507 
508 
510 
511 
512  if (TableIndex == 1)
513  {
514  /* TableIndex==1 means DSDT is the owner. DSDT cannot be unloaded */
515 
517  }
518 
519  Status = AcpiTbUnloadTable (TableIndex);
521 }
522 
#define ACPI_EXCEPTION(plist)
Definition: acoutput.h:239
#define ACPI_DEBUG_PRINT_RAW(pl)
Definition: acoutput.h:476
ASMGENDATA Table[]
Definition: genincdata.c:61
#define TRUE
Definition: types.h:120
#define ACPI_SUCCESS(a)
Definition: acexcep.h:94
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
ACPI_STATUS AcpiNsInitializeObjects(void)
Definition: nsinit.c:92
#define AE_BAD_PARAMETER
Definition: acexcep.h:151
#define AE_NO_ACPI_TABLES
Definition: acexcep.h:110
ACPI_STATUS AcpiNsLoadTable(UINT32 TableIndex, ACPI_NAMESPACE_NODE *Node)
Definition: nsload.c:82
ACPI_STATUS AcpiUnloadTable(UINT32 TableIndex)
Definition: tbxfload.c:503
UINT32 ACPI_STATUS
Definition: actypes.h:460
ACPI_STATUS AcpiTbInstallStandardTable(ACPI_PHYSICAL_ADDRESS Address, UINT8 Flags, BOOLEAN Reload, BOOLEAN Override, UINT32 *TableIndex)
Definition: tbinstal.c:137
#define ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL
Definition: actbl.h:430
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
#define ACPI_FAILURE(a)
Definition: acexcep.h:95
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
ACPI_STATUS AcpiUtReleaseMutex(ACPI_MUTEX_HANDLE MutexId)
Definition: utmutex.c:348
#define AE_CTRL_TERMINATE
Definition: acexcep.h:226
ACPI_STATUS ACPI_INIT_FUNCTION AcpiLoadTables(void)
Definition: tbxfload.c:69
ACPI_STATUS AcpiUtAcquireMutex(ACPI_MUTEX_HANDLE MutexId)
Definition: utmutex.c:256
unsigned int UINT32
#define ACPI_MODULE_NAME(Name)
Definition: acoutput.h:216
#define ACPI_EXPORT_SYMBOL(Symbol)
Definition: actypes.h:343
unsigned char BOOLEAN
#define AE_INFO
Definition: acoutput.h:230
static WCHAR Address[46]
Definition: ping.c:68
ACPI_STATUS AcpiEvInstallRegionHandlers(void)
Definition: evhandler.c:88
#define ACPI_SIG_DSDT
Definition: actbl.h:67
ACPI_STATUS AcpiUnloadParentTable(ACPI_HANDLE Object)
Definition: tbxfload.c:412
ACPI_STATUS AcpiTbLoadNamespace(void)
Definition: tbxfload.c:147
UINT16 ACPI_OWNER_ID
Definition: actypes.h:486
#define ACPI_SIG_OSDT
Definition: actbl.h:70
#define ACPI_MTX_TABLES
Definition: aclocal.h:86
#define ACPI_COMPARE_NAMESEG(a, b)
Definition: actypes.h:561
static IUnknown Object
Definition: main.c:512
#define AE_NOT_EXIST
Definition: acexcep.h:114
#define ACPI_PTR_TO_PHYSADDR(i)
Definition: actypes.h:556
#define ACPI_SIG_SSDT
Definition: actbl.h:75
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define AE_TYPE
Definition: acexcep.h:116
#define ACPI_INFO(plist)
Definition: acoutput.h:237
Status
Definition: gdiplustypes.h:24
#define ACPI_DB_INIT
Definition: acoutput.h:151
ACPI_STATUS AcpiTbUnloadTable(UINT32 TableIndex)
Definition: tbdata.c:1167
#define return_ACPI_STATUS(s)
Definition: acoutput.h:496
#define ACPI_EXPORT_SYMBOL_INIT(Symbol)
Definition: actypes.h:339
#define ACPI_FUNCTION_TRACE(a)
Definition: acoutput.h:480
ACPI_STATUS AcpiLoadTable(ACPI_TABLE_HEADER *Table, UINT32 *TableIdx)
Definition: tbxfload.c:354
ACPI_TABLE_HEADER * AcpiTbCopyDsdt(UINT32 TableIndex)
Definition: tbutils.c:163
#define ACPI_INIT_FUNCTION
Definition: acenv.h:395
#define ACPI_ERROR(plist)
Definition: acoutput.h:240
ACPI_STATUS ACPI_INIT_FUNCTION AcpiInstallTable(ACPI_PHYSICAL_ADDRESS Address, BOOLEAN Physical)
Definition: tbxfload.c:304
ACPI_STATUS AcpiTbValidateTable(ACPI_TABLE_DESC *TableDesc)
Definition: tbdata.c:353
#define ACPI_SIG_PSDT
Definition: actbl.h:71
_Must_inspect_result_ _In_opt_ PVOID OwnerId
Definition: fsrtlfuncs.h:907
#define ACPI_CAST_PTR(t, p)
Definition: actypes.h:544
unsigned char UINT8
#define AE_OK
Definition: acexcep.h:97
ACPI_STATUS AcpiTbInstallAndLoadTable(ACPI_PHYSICAL_ADDRESS Address, UINT8 Flags, BOOLEAN Override, UINT32 *TableIndex)
Definition: tbdata.c:1124
#define ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL
Definition: actbl.h:429
Definition: dlist.c:348