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"));
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.
121 Status
= AcpiNsInitializeObjects ();
122 if (ACPI_SUCCESS (Status
))
124 AcpiGbl_NamespaceInitialized
= TRUE
;
127 return_ACPI_STATUS (Status
);
130 ACPI_EXPORT_SYMBOL_INIT (AcpiLoadTables
)
133 /*******************************************************************************
135 * FUNCTION: AcpiTbLoadNamespace
141 * DESCRIPTION: Load the namespace from the DSDT and all SSDTs/PSDTs found in
144 ******************************************************************************/
147 AcpiTbLoadNamespace (
152 ACPI_TABLE_HEADER
*NewDsdt
;
153 ACPI_TABLE_DESC
*Table
;
154 UINT32 TablesLoaded
= 0;
155 UINT32 TablesFailed
= 0;
158 ACPI_FUNCTION_TRACE (TbLoadNamespace
);
161 (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES
);
164 * Load the namespace. The DSDT is required, but any SSDT and
165 * PSDT tables are optional. Verify the DSDT.
167 Table
= &AcpiGbl_RootTableList
.Tables
[AcpiGbl_DsdtIndex
];
169 if (!AcpiGbl_RootTableList
.CurrentTableCount
||
170 !ACPI_COMPARE_NAMESEG (Table
->Signature
.Ascii
, ACPI_SIG_DSDT
) ||
171 ACPI_FAILURE (AcpiTbValidateTable (Table
)))
173 Status
= AE_NO_ACPI_TABLES
;
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.
183 AcpiGbl_DSDT
= Table
->Pointer
;
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
191 if (AcpiGbl_CopyDsdtLocally
)
193 NewDsdt
= AcpiTbCopyDsdt (AcpiGbl_DsdtIndex
);
196 AcpiGbl_DSDT
= NewDsdt
;
201 * Save the original DSDT header for detection of table corruption
202 * and/or replacement of the DSDT from outside the OS.
204 memcpy (&AcpiGbl_OriginalDsdtHeader
, AcpiGbl_DSDT
,
205 sizeof (ACPI_TABLE_HEADER
));
207 /* Load and parse tables */
209 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES
);
210 Status
= AcpiNsLoadTable (AcpiGbl_DsdtIndex
, AcpiGbl_RootNode
);
211 (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES
);
212 if (ACPI_FAILURE (Status
))
214 ACPI_EXCEPTION ((AE_INFO
, Status
, "[DSDT] table load failed"));
222 /* Load any SSDT or PSDT tables. Note: Loop leaves tables locked */
224 for (i
= 0; i
< AcpiGbl_RootTableList
.CurrentTableCount
; ++i
)
226 Table
= &AcpiGbl_RootTableList
.Tables
[i
];
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
)) ||
232 ACPI_FAILURE (AcpiTbValidateTable (Table
)))
237 /* Ignore errors while loading tables, get as many as possible */
239 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES
);
240 Status
= AcpiNsLoadTable (i
, AcpiGbl_RootNode
);
241 (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES
);
242 if (ACPI_FAILURE (Status
))
244 ACPI_EXCEPTION ((AE_INFO
, Status
, "(%4.4s:%8.8s) while loading table",
245 Table
->Signature
.Ascii
, Table
->Pointer
->OemTableId
));
249 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT
,
250 "Table [%4.4s:%8.8s] (id FF) - Table namespace load failed\n\n",
251 Table
->Signature
.Ascii
, Table
->Pointer
->OemTableId
));
262 "%u ACPI AML tables successfully acquired and loaded",
267 ACPI_ERROR ((AE_INFO
,
268 "%u table load failures, %u successful",
269 TablesFailed
, TablesLoaded
));
271 /* Indicate at least one failure */
273 Status
= AE_CTRL_TERMINATE
;
276 #ifdef ACPI_APPLICATION
277 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT
, "\n"));
282 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES
);
283 return_ACPI_STATUS (Status
);
287 /*******************************************************************************
289 * FUNCTION: AcpiInstallTable
291 * PARAMETERS: Address - Address of the ACPI table to be installed.
292 * Physical - Whether the address is a physical table
297 * DESCRIPTION: Dynamically install an ACPI table.
298 * Note: This function should only be invoked after
299 * AcpiInitializeTables() and before AcpiLoadTables().
301 ******************************************************************************/
303 ACPI_STATUS ACPI_INIT_FUNCTION
305 ACPI_PHYSICAL_ADDRESS Address
,
313 ACPI_FUNCTION_TRACE (AcpiInstallTable
);
318 Flags
= ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL
;
322 Flags
= ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL
;
325 Status
= AcpiTbInstallStandardTable (Address
, Flags
,
326 FALSE
, FALSE
, &TableIndex
);
328 return_ACPI_STATUS (Status
);
331 ACPI_EXPORT_SYMBOL_INIT (AcpiInstallTable
)
334 /*******************************************************************************
336 * FUNCTION: AcpiLoadTable
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
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.
351 ******************************************************************************/
355 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
);
379 *TableIdx
= TableIndex
;
382 if (ACPI_SUCCESS (Status
))
384 /* Complete the initialization/resolution of new objects */
386 AcpiNsInitializeObjects ();
389 return_ACPI_STATUS (Status
);
392 ACPI_EXPORT_SYMBOL (AcpiLoadTable
)
395 /*******************************************************************************
397 * FUNCTION: AcpiUnloadParentTable
399 * PARAMETERS: Object - Handle to any namespace object owned by
400 * the table to be unloaded
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.
409 ******************************************************************************/
412 AcpiUnloadParentTable (
415 ACPI_NAMESPACE_NODE
*Node
= ACPI_CAST_PTR (ACPI_NAMESPACE_NODE
, Object
);
416 ACPI_STATUS Status
= AE_NOT_EXIST
;
417 ACPI_OWNER_ID OwnerId
;
421 ACPI_FUNCTION_TRACE (AcpiUnloadParentTable
);
424 /* Parameter validation */
428 return_ACPI_STATUS (AE_BAD_PARAMETER
);
432 * The node OwnerId is currently the same as the parent table ID.
433 * However, this could change in the future.
435 OwnerId
= Node
->OwnerId
;
438 /* OwnerId==0 means DSDT is the owner. DSDT cannot be unloaded */
440 return_ACPI_STATUS (AE_TYPE
);
443 /* Must acquire the table lock during this operation */
445 Status
= AcpiUtAcquireMutex (ACPI_MTX_TABLES
);
446 if (ACPI_FAILURE (Status
))
448 return_ACPI_STATUS (Status
);
451 /* Find the table in the global table list */
453 for (i
= 0; i
< AcpiGbl_RootTableList
.CurrentTableCount
; i
++)
455 if (OwnerId
!= AcpiGbl_RootTableList
.Tables
[i
].OwnerId
)
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.
466 if (ACPI_COMPARE_NAMESEG (
467 AcpiGbl_RootTableList
.Tables
[i
].Signature
.Ascii
,
474 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES
);
475 Status
= AcpiTbUnloadTable (i
);
476 (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES
);
480 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES
);
481 return_ACPI_STATUS (Status
);
484 ACPI_EXPORT_SYMBOL (AcpiUnloadParentTable
)
487 /*******************************************************************************
489 * FUNCTION: AcpiUnloadTable
491 * PARAMETERS: TableIndex - Index as returned by AcpiLoadTable
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.
500 ******************************************************************************/
509 ACPI_FUNCTION_TRACE (AcpiUnloadTable
);
514 /* TableIndex==1 means DSDT is the owner. DSDT cannot be unloaded */
516 return_ACPI_STATUS (AE_TYPE
);
519 Status
= AcpiTbUnloadTable (TableIndex
);
520 return_ACPI_STATUS (Status
);
523 ACPI_EXPORT_SYMBOL (AcpiUnloadTable
)