1 /******************************************************************************
3 * Module Name: tbxfload - Table load/unload external interfaces
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2015, 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
51 #define _COMPONENT ACPI_TABLES
52 ACPI_MODULE_NAME ("tbxfload")
55 /*******************************************************************************
57 * FUNCTION: AcpiLoadTables
63 * DESCRIPTION: Load the ACPI tables from the RSDT/XSDT
65 ******************************************************************************/
74 ACPI_FUNCTION_TRACE (AcpiLoadTables
);
77 /* Load the namespace from the tables */
79 Status
= AcpiTbLoadNamespace ();
81 /* Don't let single failures abort the load */
83 if (Status
== AE_CTRL_TERMINATE
)
88 if (ACPI_FAILURE (Status
))
90 ACPI_EXCEPTION ((AE_INFO
, Status
,
91 "While loading namespace from ACPI tables"));
94 return_ACPI_STATUS (Status
);
97 ACPI_EXPORT_SYMBOL_INIT (AcpiLoadTables
)
100 /*******************************************************************************
102 * FUNCTION: AcpiTbLoadNamespace
108 * DESCRIPTION: Load the namespace from the DSDT and all SSDTs/PSDTs found in
111 ******************************************************************************/
114 AcpiTbLoadNamespace (
119 ACPI_TABLE_HEADER
*NewDsdt
;
120 ACPI_TABLE_DESC
*Table
;
121 UINT32 TablesLoaded
= 0;
122 UINT32 TablesFailed
= 0;
125 ACPI_FUNCTION_TRACE (TbLoadNamespace
);
128 (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES
);
131 * Load the namespace. The DSDT is required, but any SSDT and
132 * PSDT tables are optional. Verify the DSDT.
134 Table
= &AcpiGbl_RootTableList
.Tables
[AcpiGbl_DsdtIndex
];
136 if (!AcpiGbl_RootTableList
.CurrentTableCount
||
137 !ACPI_COMPARE_NAME (Table
->Signature
.Ascii
, ACPI_SIG_DSDT
) ||
138 ACPI_FAILURE (AcpiTbValidateTable (Table
)))
140 Status
= AE_NO_ACPI_TABLES
;
145 * Save the DSDT pointer for simple access. This is the mapped memory
146 * address. We must take care here because the address of the .Tables
147 * array can change dynamically as tables are loaded at run-time. Note:
148 * .Pointer field is not validated until after call to AcpiTbValidateTable.
150 AcpiGbl_DSDT
= Table
->Pointer
;
153 * Optionally copy the entire DSDT to local memory (instead of simply
154 * mapping it.) There are some BIOSs that corrupt or replace the original
155 * DSDT, creating the need for this option. Default is FALSE, do not copy
158 if (AcpiGbl_CopyDsdtLocally
)
160 NewDsdt
= AcpiTbCopyDsdt (AcpiGbl_DsdtIndex
);
163 AcpiGbl_DSDT
= NewDsdt
;
168 * Save the original DSDT header for detection of table corruption
169 * and/or replacement of the DSDT from outside the OS.
171 memcpy (&AcpiGbl_OriginalDsdtHeader
, AcpiGbl_DSDT
,
172 sizeof (ACPI_TABLE_HEADER
));
174 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES
);
176 /* Load and parse tables */
178 Status
= AcpiNsLoadTable (AcpiGbl_DsdtIndex
, AcpiGbl_RootNode
);
179 if (ACPI_FAILURE (Status
))
181 ACPI_EXCEPTION ((AE_INFO
, Status
, "[DSDT] table load failed"));
189 /* Load any SSDT or PSDT tables. Note: Loop leaves tables locked */
191 (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES
);
192 for (i
= 0; i
< AcpiGbl_RootTableList
.CurrentTableCount
; ++i
)
194 Table
= &AcpiGbl_RootTableList
.Tables
[i
];
196 if (!AcpiGbl_RootTableList
.Tables
[i
].Address
||
197 (!ACPI_COMPARE_NAME (Table
->Signature
.Ascii
, ACPI_SIG_SSDT
) &&
198 !ACPI_COMPARE_NAME (Table
->Signature
.Ascii
, ACPI_SIG_PSDT
) &&
199 !ACPI_COMPARE_NAME (Table
->Signature
.Ascii
, ACPI_SIG_OSDT
)) ||
200 ACPI_FAILURE (AcpiTbValidateTable (Table
)))
205 /* Ignore errors while loading tables, get as many as possible */
207 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES
);
208 Status
= AcpiNsLoadTable (i
, AcpiGbl_RootNode
);
209 if (ACPI_FAILURE (Status
))
211 ACPI_EXCEPTION ((AE_INFO
, Status
, "(%4.4s:%8.8s) while loading table",
212 Table
->Signature
.Ascii
, Table
->Pointer
->OemTableId
));
216 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT
,
217 "Table [%4.4s:%8.8s] (id FF) - Table namespace load failed\n\n",
218 Table
->Signature
.Ascii
, Table
->Pointer
->OemTableId
));
225 (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES
);
231 "%u ACPI AML tables successfully acquired and loaded\n",
236 ACPI_ERROR ((AE_INFO
,
237 "%u table load failures, %u successful",
238 TablesFailed
, TablesLoaded
));
240 /* Indicate at least one failure */
242 Status
= AE_CTRL_TERMINATE
;
246 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES
);
247 return_ACPI_STATUS (Status
);
251 /*******************************************************************************
253 * FUNCTION: AcpiInstallTable
255 * PARAMETERS: Address - Address of the ACPI table to be installed.
256 * Physical - Whether the address is a physical table
261 * DESCRIPTION: Dynamically install an ACPI table.
262 * Note: This function should only be invoked after
263 * AcpiInitializeTables() and before AcpiLoadTables().
265 ******************************************************************************/
269 ACPI_PHYSICAL_ADDRESS Address
,
277 ACPI_FUNCTION_TRACE (AcpiInstallTable
);
282 Flags
= ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL
;
286 Flags
= ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL
;
289 Status
= AcpiTbInstallStandardTable (Address
, Flags
,
290 FALSE
, FALSE
, &TableIndex
);
292 return_ACPI_STATUS (Status
);
295 ACPI_EXPORT_SYMBOL_INIT (AcpiInstallTable
)
298 /*******************************************************************************
300 * FUNCTION: AcpiLoadTable
302 * PARAMETERS: Table - Pointer to a buffer containing the ACPI
303 * table to be loaded.
307 * DESCRIPTION: Dynamically load an ACPI table from the caller's buffer. Must
308 * be a valid ACPI table with a valid ACPI table header.
309 * Note1: Mainly intended to support hotplug addition of SSDTs.
310 * Note2: Does not copy the incoming table. User is responsible
311 * to ensure that the table is not deleted or unmapped.
313 ******************************************************************************/
317 ACPI_TABLE_HEADER
*Table
)
323 ACPI_FUNCTION_TRACE (AcpiLoadTable
);
326 /* Parameter validation */
330 return_ACPI_STATUS (AE_BAD_PARAMETER
);
333 /* Must acquire the interpreter lock during this operation */
335 Status
= AcpiUtAcquireMutex (ACPI_MTX_INTERPRETER
);
336 if (ACPI_FAILURE (Status
))
338 return_ACPI_STATUS (Status
);
341 /* Install the table and load it into the namespace */
343 ACPI_INFO ((AE_INFO
, "Host-directed Dynamic ACPI Table Load:"));
344 (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES
);
346 Status
= AcpiTbInstallStandardTable (ACPI_PTR_TO_PHYSADDR (Table
),
347 ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL
, TRUE
, FALSE
,
350 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES
);
351 if (ACPI_FAILURE (Status
))
357 * Note: Now table is "INSTALLED", it must be validated before
360 Status
= AcpiTbValidateTable (
361 &AcpiGbl_RootTableList
.Tables
[TableIndex
]);
362 if (ACPI_FAILURE (Status
))
367 Status
= AcpiNsLoadTable (TableIndex
, AcpiGbl_RootNode
);
369 /* Invoke table handler if present */
371 if (AcpiGbl_TableHandler
)
373 (void) AcpiGbl_TableHandler (ACPI_TABLE_EVENT_LOAD
, Table
,
374 AcpiGbl_TableHandlerContext
);
378 (void) AcpiUtReleaseMutex (ACPI_MTX_INTERPRETER
);
379 return_ACPI_STATUS (Status
);
382 ACPI_EXPORT_SYMBOL (AcpiLoadTable
)
385 /*******************************************************************************
387 * FUNCTION: AcpiUnloadParentTable
389 * PARAMETERS: Object - Handle to any namespace object owned by
390 * the table to be unloaded
394 * DESCRIPTION: Via any namespace object within an SSDT or OEMx table, unloads
395 * the table and deletes all namespace objects associated with
396 * that table. Unloading of the DSDT is not allowed.
397 * Note: Mainly intended to support hotplug removal of SSDTs.
399 ******************************************************************************/
402 AcpiUnloadParentTable (
405 ACPI_NAMESPACE_NODE
*Node
= ACPI_CAST_PTR (ACPI_NAMESPACE_NODE
, Object
);
406 ACPI_STATUS Status
= AE_NOT_EXIST
;
407 ACPI_OWNER_ID OwnerId
;
411 ACPI_FUNCTION_TRACE (AcpiUnloadParentTable
);
414 /* Parameter validation */
418 return_ACPI_STATUS (AE_BAD_PARAMETER
);
422 * The node OwnerId is currently the same as the parent table ID.
423 * However, this could change in the future.
425 OwnerId
= Node
->OwnerId
;
428 /* OwnerId==0 means DSDT is the owner. DSDT cannot be unloaded */
430 return_ACPI_STATUS (AE_TYPE
);
433 /* Must acquire the interpreter lock during this operation */
435 Status
= AcpiUtAcquireMutex (ACPI_MTX_INTERPRETER
);
436 if (ACPI_FAILURE (Status
))
438 return_ACPI_STATUS (Status
);
441 /* Find the table in the global table list */
443 for (i
= 0; i
< AcpiGbl_RootTableList
.CurrentTableCount
; i
++)
445 if (OwnerId
!= AcpiGbl_RootTableList
.Tables
[i
].OwnerId
)
451 * Allow unload of SSDT and OEMx tables only. Do not allow unload
452 * of the DSDT. No other types of tables should get here, since
453 * only these types can contain AML and thus are the only types
454 * that can create namespace objects.
456 if (ACPI_COMPARE_NAME (
457 AcpiGbl_RootTableList
.Tables
[i
].Signature
.Ascii
,
464 /* Ensure the table is actually loaded */
466 if (!AcpiTbIsTableLoaded (i
))
468 Status
= AE_NOT_EXIST
;
472 /* Invoke table handler if present */
474 if (AcpiGbl_TableHandler
)
476 (void) AcpiGbl_TableHandler (ACPI_TABLE_EVENT_UNLOAD
,
477 AcpiGbl_RootTableList
.Tables
[i
].Pointer
,
478 AcpiGbl_TableHandlerContext
);
482 * Delete all namespace objects owned by this table. Note that
483 * these objects can appear anywhere in the namespace by virtue
484 * of the AML "Scope" operator. Thus, we need to track ownership
485 * by an ID, not simply a position within the hierarchy.
487 Status
= AcpiTbDeleteNamespaceByOwner (i
);
488 if (ACPI_FAILURE (Status
))
493 Status
= AcpiTbReleaseOwnerId (i
);
494 AcpiTbSetTableLoadedFlag (i
, FALSE
);
498 (void) AcpiUtReleaseMutex (ACPI_MTX_INTERPRETER
);
499 return_ACPI_STATUS (Status
);
502 ACPI_EXPORT_SYMBOL (AcpiUnloadParentTable
)