1 /******************************************************************************
3 * Module Name: tbxfload - Table load/unload external interfaces
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2019, 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_ExecuteTablesAsMethods
)
117 * If the module-level code support is enabled, initialize the objects
118 * in the namespace that remain uninitialized. This runs the executable
119 * AML that may be part of the declaration of these name objects:
120 * OperationRegions, BufferFields, Buffers, and Packages.
122 * Note: The module-level code is optional at this time, but will
123 * become the default in the future.
125 Status
= AcpiNsInitializeObjects ();
126 if (ACPI_FAILURE (Status
))
128 return_ACPI_STATUS (Status
);
132 AcpiGbl_NamespaceInitialized
= TRUE
;
133 return_ACPI_STATUS (Status
);
136 ACPI_EXPORT_SYMBOL_INIT (AcpiLoadTables
)
139 /*******************************************************************************
141 * FUNCTION: AcpiTbLoadNamespace
147 * DESCRIPTION: Load the namespace from the DSDT and all SSDTs/PSDTs found in
150 ******************************************************************************/
153 AcpiTbLoadNamespace (
158 ACPI_TABLE_HEADER
*NewDsdt
;
159 ACPI_TABLE_DESC
*Table
;
160 UINT32 TablesLoaded
= 0;
161 UINT32 TablesFailed
= 0;
164 ACPI_FUNCTION_TRACE (TbLoadNamespace
);
167 (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES
);
170 * Load the namespace. The DSDT is required, but any SSDT and
171 * PSDT tables are optional. Verify the DSDT.
173 Table
= &AcpiGbl_RootTableList
.Tables
[AcpiGbl_DsdtIndex
];
175 if (!AcpiGbl_RootTableList
.CurrentTableCount
||
176 !ACPI_COMPARE_NAME (Table
->Signature
.Ascii
, ACPI_SIG_DSDT
) ||
177 ACPI_FAILURE (AcpiTbValidateTable (Table
)))
179 Status
= AE_NO_ACPI_TABLES
;
184 * Save the DSDT pointer for simple access. This is the mapped memory
185 * address. We must take care here because the address of the .Tables
186 * array can change dynamically as tables are loaded at run-time. Note:
187 * .Pointer field is not validated until after call to AcpiTbValidateTable.
189 AcpiGbl_DSDT
= Table
->Pointer
;
192 * Optionally copy the entire DSDT to local memory (instead of simply
193 * mapping it.) There are some BIOSs that corrupt or replace the original
194 * DSDT, creating the need for this option. Default is FALSE, do not copy
197 if (AcpiGbl_CopyDsdtLocally
)
199 NewDsdt
= AcpiTbCopyDsdt (AcpiGbl_DsdtIndex
);
202 AcpiGbl_DSDT
= NewDsdt
;
207 * Save the original DSDT header for detection of table corruption
208 * and/or replacement of the DSDT from outside the OS.
210 memcpy (&AcpiGbl_OriginalDsdtHeader
, AcpiGbl_DSDT
,
211 sizeof (ACPI_TABLE_HEADER
));
213 /* Load and parse tables */
215 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES
);
216 Status
= AcpiNsLoadTable (AcpiGbl_DsdtIndex
, AcpiGbl_RootNode
);
217 (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES
);
218 if (ACPI_FAILURE (Status
))
220 ACPI_EXCEPTION ((AE_INFO
, Status
, "[DSDT] table load failed"));
228 /* Load any SSDT or PSDT tables. Note: Loop leaves tables locked */
230 for (i
= 0; i
< AcpiGbl_RootTableList
.CurrentTableCount
; ++i
)
232 Table
= &AcpiGbl_RootTableList
.Tables
[i
];
234 if (!Table
->Address
||
235 (!ACPI_COMPARE_NAME (Table
->Signature
.Ascii
, ACPI_SIG_SSDT
) &&
236 !ACPI_COMPARE_NAME (Table
->Signature
.Ascii
, ACPI_SIG_PSDT
) &&
237 !ACPI_COMPARE_NAME (Table
->Signature
.Ascii
, ACPI_SIG_OSDT
)) ||
238 ACPI_FAILURE (AcpiTbValidateTable (Table
)))
243 /* Ignore errors while loading tables, get as many as possible */
245 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES
);
246 Status
= AcpiNsLoadTable (i
, AcpiGbl_RootNode
);
247 (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES
);
248 if (ACPI_FAILURE (Status
))
250 ACPI_EXCEPTION ((AE_INFO
, Status
, "(%4.4s:%8.8s) while loading table",
251 Table
->Signature
.Ascii
, Table
->Pointer
->OemTableId
));
255 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT
,
256 "Table [%4.4s:%8.8s] (id FF) - Table namespace load failed\n\n",
257 Table
->Signature
.Ascii
, Table
->Pointer
->OemTableId
));
268 "%u ACPI AML tables successfully acquired and loaded",
273 ACPI_ERROR ((AE_INFO
,
274 "%u table load failures, %u successful",
275 TablesFailed
, TablesLoaded
));
277 /* Indicate at least one failure */
279 Status
= AE_CTRL_TERMINATE
;
282 #ifdef ACPI_APPLICATION
283 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT
, "\n"));
288 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES
);
289 return_ACPI_STATUS (Status
);
293 /*******************************************************************************
295 * FUNCTION: AcpiInstallTable
297 * PARAMETERS: Address - Address of the ACPI table to be installed.
298 * Physical - Whether the address is a physical table
303 * DESCRIPTION: Dynamically install an ACPI table.
304 * Note: This function should only be invoked after
305 * AcpiInitializeTables() and before AcpiLoadTables().
307 ******************************************************************************/
309 ACPI_STATUS ACPI_INIT_FUNCTION
311 ACPI_PHYSICAL_ADDRESS Address
,
319 ACPI_FUNCTION_TRACE (AcpiInstallTable
);
324 Flags
= ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL
;
328 Flags
= ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL
;
331 Status
= AcpiTbInstallStandardTable (Address
, Flags
,
332 FALSE
, FALSE
, &TableIndex
);
334 return_ACPI_STATUS (Status
);
337 ACPI_EXPORT_SYMBOL_INIT (AcpiInstallTable
)
340 /*******************************************************************************
342 * FUNCTION: AcpiLoadTable
344 * PARAMETERS: Table - Pointer to a buffer containing the ACPI
345 * table to be loaded.
349 * DESCRIPTION: Dynamically load an ACPI table from the caller's buffer. Must
350 * be a valid ACPI table with a valid ACPI table header.
351 * Note1: Mainly intended to support hotplug addition of SSDTs.
352 * Note2: Does not copy the incoming table. User is responsible
353 * to ensure that the table is not deleted or unmapped.
355 ******************************************************************************/
359 ACPI_TABLE_HEADER
*Table
)
365 ACPI_FUNCTION_TRACE (AcpiLoadTable
);
368 /* Parameter validation */
372 return_ACPI_STATUS (AE_BAD_PARAMETER
);
375 /* Install the table and load it into the namespace */
377 ACPI_INFO (("Host-directed Dynamic ACPI Table Load:"));
378 Status
= AcpiTbInstallAndLoadTable (ACPI_PTR_TO_PHYSADDR (Table
),
379 ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL
, FALSE
, &TableIndex
);
380 return_ACPI_STATUS (Status
);
383 ACPI_EXPORT_SYMBOL (AcpiLoadTable
)
386 /*******************************************************************************
388 * FUNCTION: AcpiUnloadParentTable
390 * PARAMETERS: Object - Handle to any namespace object owned by
391 * the table to be unloaded
395 * DESCRIPTION: Via any namespace object within an SSDT or OEMx table, unloads
396 * the table and deletes all namespace objects associated with
397 * that table. Unloading of the DSDT is not allowed.
398 * Note: Mainly intended to support hotplug removal of SSDTs.
400 ******************************************************************************/
403 AcpiUnloadParentTable (
406 ACPI_NAMESPACE_NODE
*Node
= ACPI_CAST_PTR (ACPI_NAMESPACE_NODE
, Object
);
407 ACPI_STATUS Status
= AE_NOT_EXIST
;
408 ACPI_OWNER_ID OwnerId
;
412 ACPI_FUNCTION_TRACE (AcpiUnloadParentTable
);
415 /* Parameter validation */
419 return_ACPI_STATUS (AE_BAD_PARAMETER
);
423 * The node OwnerId is currently the same as the parent table ID.
424 * However, this could change in the future.
426 OwnerId
= Node
->OwnerId
;
429 /* OwnerId==0 means DSDT is the owner. DSDT cannot be unloaded */
431 return_ACPI_STATUS (AE_TYPE
);
434 /* Must acquire the table lock during this operation */
436 Status
= AcpiUtAcquireMutex (ACPI_MTX_TABLES
);
437 if (ACPI_FAILURE (Status
))
439 return_ACPI_STATUS (Status
);
442 /* Find the table in the global table list */
444 for (i
= 0; i
< AcpiGbl_RootTableList
.CurrentTableCount
; i
++)
446 if (OwnerId
!= AcpiGbl_RootTableList
.Tables
[i
].OwnerId
)
452 * Allow unload of SSDT and OEMx tables only. Do not allow unload
453 * of the DSDT. No other types of tables should get here, since
454 * only these types can contain AML and thus are the only types
455 * that can create namespace objects.
457 if (ACPI_COMPARE_NAME (
458 AcpiGbl_RootTableList
.Tables
[i
].Signature
.Ascii
,
465 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES
);
466 Status
= AcpiTbUnloadTable (i
);
467 (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES
);
471 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES
);
472 return_ACPI_STATUS (Status
);
475 ACPI_EXPORT_SYMBOL (AcpiUnloadParentTable
)