1 /******************************************************************************
3 * Module Name: tbxfload - Table load/unload external interfaces
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2013, 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 __TBXFLOAD_C__
46 #include <contrib/dev/acpica/include/acpi.h>
47 #include <contrib/dev/acpica/include/accommon.h>
48 #include <contrib/dev/acpica/include/acnamesp.h>
49 #include <contrib/dev/acpica/include/actables.h>
51 #define _COMPONENT ACPI_TABLES
52 ACPI_MODULE_NAME ("tbxfload")
54 /* Local prototypes */
61 /*******************************************************************************
63 * FUNCTION: AcpiLoadTables
69 * DESCRIPTION: Load the ACPI tables from the RSDT/XSDT
71 ******************************************************************************/
80 ACPI_FUNCTION_TRACE (AcpiLoadTables);
83 /* Load the namespace from the tables */
85 Status = AcpiTbLoadNamespace ();
86 if (ACPI_FAILURE (Status))
88 ACPI_EXCEPTION ((AE_INFO, Status,
89 "While loading namespace from ACPI tables"));
92 return_ACPI_STATUS (Status);
95 ACPI_EXPORT_SYMBOL (AcpiLoadTables)
98 /*******************************************************************************
100 * FUNCTION: AcpiTbLoadNamespace
106 * DESCRIPTION: Load the namespace from the DSDT and all SSDTs/PSDTs found in
109 ******************************************************************************/
112 AcpiTbLoadNamespace (
117 ACPI_TABLE_HEADER *NewDsdt;
120 ACPI_FUNCTION_TRACE (TbLoadNamespace);
123 (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
126 * Load the namespace. The DSDT is required, but any SSDT and
127 * PSDT tables are optional. Verify the DSDT.
129 if (!AcpiGbl_RootTableList.CurrentTableCount ||
131 &(AcpiGbl_RootTableList.Tables[ACPI_TABLE_INDEX_DSDT].Signature),
133 ACPI_FAILURE (AcpiTbVerifyTable (
134 &AcpiGbl_RootTableList.Tables[ACPI_TABLE_INDEX_DSDT])))
136 Status = AE_NO_ACPI_TABLES;
141 * Save the DSDT pointer for simple access. This is the mapped memory
142 * address. We must take care here because the address of the .Tables
143 * array can change dynamically as tables are loaded at run-time. Note:
144 * .Pointer field is not validated until after call to AcpiTbVerifyTable.
146 AcpiGbl_DSDT = AcpiGbl_RootTableList.Tables[ACPI_TABLE_INDEX_DSDT].Pointer;
149 * Optionally copy the entire DSDT to local memory (instead of simply
150 * mapping it.) There are some BIOSs that corrupt or replace the original
151 * DSDT, creating the need for this option. Default is FALSE, do not copy
154 if (AcpiGbl_CopyDsdtLocally)
156 NewDsdt = AcpiTbCopyDsdt (ACPI_TABLE_INDEX_DSDT);
159 AcpiGbl_DSDT = NewDsdt;
164 * Save the original DSDT header for detection of table corruption
165 * and/or replacement of the DSDT from outside the OS.
167 ACPI_MEMCPY (&AcpiGbl_OriginalDsdtHeader, AcpiGbl_DSDT,
168 sizeof (ACPI_TABLE_HEADER));
170 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
172 /* Load and parse tables */
174 Status = AcpiNsLoadTable (ACPI_TABLE_INDEX_DSDT, AcpiGbl_RootNode);
175 if (ACPI_FAILURE (Status))
177 return_ACPI_STATUS (Status);
180 /* Load any SSDT or PSDT tables. Note: Loop leaves tables locked */
182 (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
183 for (i = 0; i < AcpiGbl_RootTableList.CurrentTableCount; ++i)
185 if ((!ACPI_COMPARE_NAME (&(AcpiGbl_RootTableList.Tables[i].Signature),
187 !ACPI_COMPARE_NAME (&(AcpiGbl_RootTableList.Tables[i].Signature),
189 ACPI_FAILURE (AcpiTbVerifyTable (
190 &AcpiGbl_RootTableList.Tables[i])))
196 * Optionally do not load any SSDTs from the RSDT/XSDT. This can
197 * be useful for debugging ACPI problems on some machines.
199 if (AcpiGbl_DisableSsdtTableLoad)
201 ACPI_INFO ((AE_INFO, "Ignoring %4.4s at %p",
202 AcpiGbl_RootTableList.Tables[i].Signature.Ascii,
203 ACPI_CAST_PTR (void, AcpiGbl_RootTableList.Tables[i].Address)));
207 /* Ignore errors while loading tables, get as many as possible */
209 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
210 (void) AcpiNsLoadTable (i, AcpiGbl_RootNode);
211 (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
214 ACPI_INFO ((AE_INFO, "All ACPI Tables successfully acquired"));
217 (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
218 return_ACPI_STATUS (Status);
222 /*******************************************************************************
224 * FUNCTION: AcpiLoadTable
226 * PARAMETERS: Table - Pointer to a buffer containing the ACPI
227 * table to be loaded.
231 * DESCRIPTION: Dynamically load an ACPI table from the caller's buffer. Must
232 * be a valid ACPI table with a valid ACPI table header.
233 * Note1: Mainly intended to support hotplug addition of SSDTs.
234 * Note2: Does not copy the incoming table. User is responsible
235 * to ensure that the table is not deleted or unmapped.
237 ******************************************************************************/
241 ACPI_TABLE_HEADER *Table)
244 ACPI_TABLE_DESC TableDesc;
248 ACPI_FUNCTION_TRACE (AcpiLoadTable);
251 /* Parameter validation */
255 return_ACPI_STATUS (AE_BAD_PARAMETER);
258 /* Init local table descriptor */
260 ACPI_MEMSET (&TableDesc, 0, sizeof (ACPI_TABLE_DESC));
261 TableDesc.Address = ACPI_PTR_TO_PHYSADDR (Table);
262 TableDesc.Pointer = Table;
263 TableDesc.Length = Table->Length;
264 TableDesc.Flags = ACPI_TABLE_ORIGIN_UNKNOWN;
266 /* Must acquire the interpreter lock during this operation */
268 Status = AcpiUtAcquireMutex (ACPI_MTX_INTERPRETER);
269 if (ACPI_FAILURE (Status))
271 return_ACPI_STATUS (Status);
274 /* Install the table and load it into the namespace */
276 ACPI_INFO ((AE_INFO, "Host-directed Dynamic ACPI Table Load:"));
277 Status = AcpiTbAddTable (&TableDesc, &TableIndex);
278 if (ACPI_FAILURE (Status))
283 Status = AcpiNsLoadTable (TableIndex, AcpiGbl_RootNode);
285 /* Invoke table handler if present */
287 if (AcpiGbl_TableHandler)
289 (void) AcpiGbl_TableHandler (ACPI_TABLE_EVENT_LOAD, Table,
290 AcpiGbl_TableHandlerContext);
294 (void) AcpiUtReleaseMutex (ACPI_MTX_INTERPRETER);
295 return_ACPI_STATUS (Status);
298 ACPI_EXPORT_SYMBOL (AcpiLoadTable)
301 /*******************************************************************************
303 * FUNCTION: AcpiUnloadParentTable
305 * PARAMETERS: Object - Handle to any namespace object owned by
306 * the table to be unloaded
310 * DESCRIPTION: Via any namespace object within an SSDT or OEMx table, unloads
311 * the table and deletes all namespace objects associated with
312 * that table. Unloading of the DSDT is not allowed.
313 * Note: Mainly intended to support hotplug removal of SSDTs.
315 ******************************************************************************/
318 AcpiUnloadParentTable (
321 ACPI_NAMESPACE_NODE *Node = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, Object);
322 ACPI_STATUS Status = AE_NOT_EXIST;
323 ACPI_OWNER_ID OwnerId;
327 ACPI_FUNCTION_TRACE (AcpiUnloadParentTable);
330 /* Parameter validation */
334 return_ACPI_STATUS (AE_BAD_PARAMETER);
338 * The node OwnerId is currently the same as the parent table ID.
339 * However, this could change in the future.
341 OwnerId = Node->OwnerId;
344 /* OwnerId==0 means DSDT is the owner. DSDT cannot be unloaded */
346 return_ACPI_STATUS (AE_TYPE);
349 /* Must acquire the interpreter lock during this operation */
351 Status = AcpiUtAcquireMutex (ACPI_MTX_INTERPRETER);
352 if (ACPI_FAILURE (Status))
354 return_ACPI_STATUS (Status);
357 /* Find the table in the global table list */
359 for (i = 0; i < AcpiGbl_RootTableList.CurrentTableCount; i++)
361 if (OwnerId != AcpiGbl_RootTableList.Tables[i].OwnerId)
367 * Allow unload of SSDT and OEMx tables only. Do not allow unload
368 * of the DSDT. No other types of tables should get here, since
369 * only these types can contain AML and thus are the only types
370 * that can create namespace objects.
372 if (ACPI_COMPARE_NAME (
373 AcpiGbl_RootTableList.Tables[i].Signature.Ascii,
380 /* Ensure the table is actually loaded */
382 if (!AcpiTbIsTableLoaded (i))
384 Status = AE_NOT_EXIST;
388 /* Invoke table handler if present */
390 if (AcpiGbl_TableHandler)
392 (void) AcpiGbl_TableHandler (ACPI_TABLE_EVENT_UNLOAD,
393 AcpiGbl_RootTableList.Tables[i].Pointer,
394 AcpiGbl_TableHandlerContext);
398 * Delete all namespace objects owned by this table. Note that
399 * these objects can appear anywhere in the namespace by virtue
400 * of the AML "Scope" operator. Thus, we need to track ownership
401 * by an ID, not simply a position within the hierarchy.
403 Status = AcpiTbDeleteNamespaceByOwner (i);
404 if (ACPI_FAILURE (Status))
409 Status = AcpiTbReleaseOwnerId (i);
410 AcpiTbSetTableLoadedFlag (i, FALSE);
414 (void) AcpiUtReleaseMutex (ACPI_MTX_INTERPRETER);
415 return_ACPI_STATUS (Status);
418 ACPI_EXPORT_SYMBOL (AcpiUnloadParentTable)