1 /******************************************************************************
3 * Module Name: tbxfload - Table load/unload external interfaces
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2016, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
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.
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.
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.
44 #define EXPORT_ACPI_INTERFACES
52 #define _COMPONENT ACPI_TABLES
53 ACPI_MODULE_NAME ("tbxfload")
56 /*******************************************************************************
58 * FUNCTION: AcpiLoadTables
64 * DESCRIPTION: Load the ACPI tables from the RSDT/XSDT
66 ******************************************************************************/
68 ACPI_STATUS ACPI_INIT_FUNCTION
75 ACPI_FUNCTION_TRACE (AcpiLoadTables
);
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.
90 Status
= AcpiEvInstallRegionHandlers ();
91 if (ACPI_FAILURE (Status
))
93 ACPI_EXCEPTION ((AE_INFO
, Status
, "During Region initialization"));
94 return_ACPI_STATUS (Status
);
97 /* Load the namespace from the tables */
99 Status
= AcpiTbLoadNamespace ();
101 /* Don't let single failures abort the load */
103 if (Status
== AE_CTRL_TERMINATE
)
108 if (ACPI_FAILURE (Status
))
110 ACPI_EXCEPTION ((AE_INFO
, Status
,
111 "While loading namespace from ACPI tables"));
114 if (AcpiGbl_ParseTableAsTermList
|| !AcpiGbl_GroupModuleLevelCode
)
117 * Initialize the objects that remain uninitialized. This
118 * runs the executable AML that may be part of the
119 * declaration of these objects:
120 * OperationRegions, BufferFields, Buffers, and Packages.
122 Status
= AcpiNsInitializeObjects ();
123 if (ACPI_FAILURE (Status
))
125 return_ACPI_STATUS (Status
);
129 AcpiGbl_NamespaceInitialized
= TRUE
;
130 return_ACPI_STATUS (Status
);
133 ACPI_EXPORT_SYMBOL_INIT (AcpiLoadTables
)
136 /*******************************************************************************
138 * FUNCTION: AcpiTbLoadNamespace
144 * DESCRIPTION: Load the namespace from the DSDT and all SSDTs/PSDTs found in
147 ******************************************************************************/
150 AcpiTbLoadNamespace (
155 ACPI_TABLE_HEADER
*NewDsdt
;
156 ACPI_TABLE_DESC
*Table
;
157 UINT32 TablesLoaded
= 0;
158 UINT32 TablesFailed
= 0;
161 ACPI_FUNCTION_TRACE (TbLoadNamespace
);
164 (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES
);
167 * Load the namespace. The DSDT is required, but any SSDT and
168 * PSDT tables are optional. Verify the DSDT.
170 Table
= &AcpiGbl_RootTableList
.Tables
[AcpiGbl_DsdtIndex
];
172 if (!AcpiGbl_RootTableList
.CurrentTableCount
||
173 !ACPI_COMPARE_NAME (Table
->Signature
.Ascii
, ACPI_SIG_DSDT
) ||
174 ACPI_FAILURE (AcpiTbValidateTable (Table
)))
176 Status
= AE_NO_ACPI_TABLES
;
181 * Save the DSDT pointer for simple access. This is the mapped memory
182 * address. We must take care here because the address of the .Tables
183 * array can change dynamically as tables are loaded at run-time. Note:
184 * .Pointer field is not validated until after call to AcpiTbValidateTable.
186 AcpiGbl_DSDT
= Table
->Pointer
;
189 * Optionally copy the entire DSDT to local memory (instead of simply
190 * mapping it.) There are some BIOSs that corrupt or replace the original
191 * DSDT, creating the need for this option. Default is FALSE, do not copy
194 if (AcpiGbl_CopyDsdtLocally
)
196 NewDsdt
= AcpiTbCopyDsdt (AcpiGbl_DsdtIndex
);
199 AcpiGbl_DSDT
= NewDsdt
;
204 * Save the original DSDT header for detection of table corruption
205 * and/or replacement of the DSDT from outside the OS.
207 memcpy (&AcpiGbl_OriginalDsdtHeader
, AcpiGbl_DSDT
,
208 sizeof (ACPI_TABLE_HEADER
));
210 /* Load and parse tables */
212 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES
);
213 Status
= AcpiNsLoadTable (AcpiGbl_DsdtIndex
, AcpiGbl_RootNode
);
214 (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES
);
215 if (ACPI_FAILURE (Status
))
217 ACPI_EXCEPTION ((AE_INFO
, Status
, "[DSDT] table load failed"));
225 /* Load any SSDT or PSDT tables. Note: Loop leaves tables locked */
227 for (i
= 0; i
< AcpiGbl_RootTableList
.CurrentTableCount
; ++i
)
229 Table
= &AcpiGbl_RootTableList
.Tables
[i
];
231 if (!AcpiGbl_RootTableList
.Tables
[i
].Address
||
232 (!ACPI_COMPARE_NAME (Table
->Signature
.Ascii
, ACPI_SIG_SSDT
) &&
233 !ACPI_COMPARE_NAME (Table
->Signature
.Ascii
, ACPI_SIG_PSDT
) &&
234 !ACPI_COMPARE_NAME (Table
->Signature
.Ascii
, ACPI_SIG_OSDT
)) ||
235 ACPI_FAILURE (AcpiTbValidateTable (Table
)))
240 /* Ignore errors while loading tables, get as many as possible */
242 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES
);
243 Status
= AcpiNsLoadTable (i
, AcpiGbl_RootNode
);
244 (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES
);
245 if (ACPI_FAILURE (Status
))
247 ACPI_EXCEPTION ((AE_INFO
, Status
, "(%4.4s:%8.8s) while loading table",
248 Table
->Signature
.Ascii
, Table
->Pointer
->OemTableId
));
252 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT
,
253 "Table [%4.4s:%8.8s] (id FF) - Table namespace load failed\n\n",
254 Table
->Signature
.Ascii
, Table
->Pointer
->OemTableId
));
265 "%u ACPI AML tables successfully acquired and loaded",
270 ACPI_ERROR ((AE_INFO
,
271 "%u table load failures, %u successful",
272 TablesFailed
, TablesLoaded
));
274 /* Indicate at least one failure */
276 Status
= AE_CTRL_TERMINATE
;
279 #ifdef ACPI_APPLICATION
280 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT
, "\n"));
285 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES
);
286 return_ACPI_STATUS (Status
);
290 /*******************************************************************************
292 * FUNCTION: AcpiInstallTable
294 * PARAMETERS: Address - Address of the ACPI table to be installed.
295 * Physical - Whether the address is a physical table
300 * DESCRIPTION: Dynamically install an ACPI table.
301 * Note: This function should only be invoked after
302 * AcpiInitializeTables() and before AcpiLoadTables().
304 ******************************************************************************/
306 ACPI_STATUS ACPI_INIT_FUNCTION
308 ACPI_PHYSICAL_ADDRESS Address
,
316 ACPI_FUNCTION_TRACE (AcpiInstallTable
);
321 Flags
= ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL
;
325 Flags
= ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL
;
328 Status
= AcpiTbInstallStandardTable (Address
, Flags
,
329 FALSE
, FALSE
, &TableIndex
);
331 return_ACPI_STATUS (Status
);
334 ACPI_EXPORT_SYMBOL_INIT (AcpiInstallTable
)
337 /*******************************************************************************
339 * FUNCTION: AcpiLoadTable
341 * PARAMETERS: Table - Pointer to a buffer containing the ACPI
342 * table to be loaded.
346 * DESCRIPTION: Dynamically load an ACPI table from the caller's buffer. Must
347 * be a valid ACPI table with a valid ACPI table header.
348 * Note1: Mainly intended to support hotplug addition of SSDTs.
349 * Note2: Does not copy the incoming table. User is responsible
350 * to ensure that the table is not deleted or unmapped.
352 ******************************************************************************/
356 ACPI_TABLE_HEADER
*Table
)
362 ACPI_FUNCTION_TRACE (AcpiLoadTable
);
365 /* Parameter validation */
369 return_ACPI_STATUS (AE_BAD_PARAMETER
);
372 /* Install the table and load it into the namespace */
374 ACPI_INFO (("Host-directed Dynamic ACPI Table Load:"));
375 Status
= AcpiTbInstallAndLoadTable (ACPI_PTR_TO_PHYSADDR (Table
),
376 ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL
, FALSE
, &TableIndex
);
377 return_ACPI_STATUS (Status
);
380 ACPI_EXPORT_SYMBOL (AcpiLoadTable
)
383 /*******************************************************************************
385 * FUNCTION: AcpiUnloadParentTable
387 * PARAMETERS: Object - Handle to any namespace object owned by
388 * the table to be unloaded
392 * DESCRIPTION: Via any namespace object within an SSDT or OEMx table, unloads
393 * the table and deletes all namespace objects associated with
394 * that table. Unloading of the DSDT is not allowed.
395 * Note: Mainly intended to support hotplug removal of SSDTs.
397 ******************************************************************************/
400 AcpiUnloadParentTable (
403 ACPI_NAMESPACE_NODE
*Node
= ACPI_CAST_PTR (ACPI_NAMESPACE_NODE
, Object
);
404 ACPI_STATUS Status
= AE_NOT_EXIST
;
405 ACPI_OWNER_ID OwnerId
;
409 ACPI_FUNCTION_TRACE (AcpiUnloadParentTable
);
412 /* Parameter validation */
416 return_ACPI_STATUS (AE_BAD_PARAMETER
);
420 * The node OwnerId is currently the same as the parent table ID.
421 * However, this could change in the future.
423 OwnerId
= Node
->OwnerId
;
426 /* OwnerId==0 means DSDT is the owner. DSDT cannot be unloaded */
428 return_ACPI_STATUS (AE_TYPE
);
431 /* Must acquire the table lock during this operation */
433 Status
= AcpiUtAcquireMutex (ACPI_MTX_TABLES
);
434 if (ACPI_FAILURE (Status
))
436 return_ACPI_STATUS (Status
);
439 /* Find the table in the global table list */
441 for (i
= 0; i
< AcpiGbl_RootTableList
.CurrentTableCount
; i
++)
443 if (OwnerId
!= AcpiGbl_RootTableList
.Tables
[i
].OwnerId
)
449 * Allow unload of SSDT and OEMx tables only. Do not allow unload
450 * of the DSDT. No other types of tables should get here, since
451 * only these types can contain AML and thus are the only types
452 * that can create namespace objects.
454 if (ACPI_COMPARE_NAME (
455 AcpiGbl_RootTableList
.Tables
[i
].Signature
.Ascii
,
462 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES
);
463 Status
= AcpiTbUnloadTable (i
);
464 (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES
);
468 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES
);
469 return_ACPI_STATUS (Status
);
472 ACPI_EXPORT_SYMBOL (AcpiUnloadParentTable
)