xref: /freebsd/sys/contrib/dev/acpica/components/tables/tbxfload.c (revision 58308fadece25ae4c12bd2f4dce3d73d9c23be43)
1e8241eabSJung-uk Kim /******************************************************************************
2e8241eabSJung-uk Kim  *
3e8241eabSJung-uk Kim  * Module Name: tbxfload - Table load/unload external interfaces
4e8241eabSJung-uk Kim  *
5e8241eabSJung-uk Kim  *****************************************************************************/
6e8241eabSJung-uk Kim 
70d84335fSJung-uk Kim /******************************************************************************
80d84335fSJung-uk Kim  *
90d84335fSJung-uk Kim  * 1. Copyright Notice
100d84335fSJung-uk Kim  *
11*58308fadSJung-uk Kim  * Some or all of this work - Copyright (c) 1999 - 2025, Intel Corp.
12e8241eabSJung-uk Kim  * All rights reserved.
13e8241eabSJung-uk Kim  *
140d84335fSJung-uk Kim  * 2. License
150d84335fSJung-uk Kim  *
160d84335fSJung-uk Kim  * 2.1. This is your license from Intel Corp. under its intellectual property
170d84335fSJung-uk Kim  * rights. You may have additional license terms from the party that provided
180d84335fSJung-uk Kim  * you this software, covering your right to use that party's intellectual
190d84335fSJung-uk Kim  * property rights.
200d84335fSJung-uk Kim  *
210d84335fSJung-uk Kim  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
220d84335fSJung-uk Kim  * copy of the source code appearing in this file ("Covered Code") an
230d84335fSJung-uk Kim  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
240d84335fSJung-uk Kim  * base code distributed originally by Intel ("Original Intel Code") to copy,
250d84335fSJung-uk Kim  * make derivatives, distribute, use and display any portion of the Covered
260d84335fSJung-uk Kim  * Code in any form, with the right to sublicense such rights; and
270d84335fSJung-uk Kim  *
280d84335fSJung-uk Kim  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
290d84335fSJung-uk Kim  * license (with the right to sublicense), under only those claims of Intel
300d84335fSJung-uk Kim  * patents that are infringed by the Original Intel Code, to make, use, sell,
310d84335fSJung-uk Kim  * offer to sell, and import the Covered Code and derivative works thereof
320d84335fSJung-uk Kim  * solely to the minimum extent necessary to exercise the above copyright
330d84335fSJung-uk Kim  * license, and in no event shall the patent license extend to any additions
340d84335fSJung-uk Kim  * to or modifications of the Original Intel Code. No other license or right
350d84335fSJung-uk Kim  * is granted directly or by implication, estoppel or otherwise;
360d84335fSJung-uk Kim  *
370d84335fSJung-uk Kim  * The above copyright and patent license is granted only if the following
380d84335fSJung-uk Kim  * conditions are met:
390d84335fSJung-uk Kim  *
400d84335fSJung-uk Kim  * 3. Conditions
410d84335fSJung-uk Kim  *
420d84335fSJung-uk Kim  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
430d84335fSJung-uk Kim  * Redistribution of source code of any substantial portion of the Covered
440d84335fSJung-uk Kim  * Code or modification with rights to further distribute source must include
450d84335fSJung-uk Kim  * the above Copyright Notice, the above License, this list of Conditions,
460d84335fSJung-uk Kim  * and the following Disclaimer and Export Compliance provision. In addition,
470d84335fSJung-uk Kim  * Licensee must cause all Covered Code to which Licensee contributes to
480d84335fSJung-uk Kim  * contain a file documenting the changes Licensee made to create that Covered
490d84335fSJung-uk Kim  * Code and the date of any change. Licensee must include in that file the
500d84335fSJung-uk Kim  * documentation of any changes made by any predecessor Licensee. Licensee
510d84335fSJung-uk Kim  * must include a prominent statement that the modification is derived,
520d84335fSJung-uk Kim  * directly or indirectly, from Original Intel Code.
530d84335fSJung-uk Kim  *
540d84335fSJung-uk Kim  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
550d84335fSJung-uk Kim  * Redistribution of source code of any substantial portion of the Covered
560d84335fSJung-uk Kim  * Code or modification without rights to further distribute source must
570d84335fSJung-uk Kim  * include the following Disclaimer and Export Compliance provision in the
580d84335fSJung-uk Kim  * documentation and/or other materials provided with distribution. In
590d84335fSJung-uk Kim  * addition, Licensee may not authorize further sublicense of source of any
600d84335fSJung-uk Kim  * portion of the Covered Code, and must include terms to the effect that the
610d84335fSJung-uk Kim  * license from Licensee to its licensee is limited to the intellectual
620d84335fSJung-uk Kim  * property embodied in the software Licensee provides to its licensee, and
630d84335fSJung-uk Kim  * not to intellectual property embodied in modifications its licensee may
640d84335fSJung-uk Kim  * make.
650d84335fSJung-uk Kim  *
660d84335fSJung-uk Kim  * 3.3. Redistribution of Executable. Redistribution in executable form of any
670d84335fSJung-uk Kim  * substantial portion of the Covered Code or modification must reproduce the
680d84335fSJung-uk Kim  * above Copyright Notice, and the following Disclaimer and Export Compliance
690d84335fSJung-uk Kim  * provision in the documentation and/or other materials provided with the
700d84335fSJung-uk Kim  * distribution.
710d84335fSJung-uk Kim  *
720d84335fSJung-uk Kim  * 3.4. Intel retains all right, title, and interest in and to the Original
730d84335fSJung-uk Kim  * Intel Code.
740d84335fSJung-uk Kim  *
750d84335fSJung-uk Kim  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
760d84335fSJung-uk Kim  * Intel shall be used in advertising or otherwise to promote the sale, use or
770d84335fSJung-uk Kim  * other dealings in products derived from or relating to the Covered Code
780d84335fSJung-uk Kim  * without prior written authorization from Intel.
790d84335fSJung-uk Kim  *
800d84335fSJung-uk Kim  * 4. Disclaimer and Export Compliance
810d84335fSJung-uk Kim  *
820d84335fSJung-uk Kim  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
830d84335fSJung-uk Kim  * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
840d84335fSJung-uk Kim  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
850d84335fSJung-uk Kim  * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
860d84335fSJung-uk Kim  * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
870d84335fSJung-uk Kim  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
880d84335fSJung-uk Kim  * PARTICULAR PURPOSE.
890d84335fSJung-uk Kim  *
900d84335fSJung-uk Kim  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
910d84335fSJung-uk Kim  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
920d84335fSJung-uk Kim  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
930d84335fSJung-uk Kim  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
940d84335fSJung-uk Kim  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
950d84335fSJung-uk Kim  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
960d84335fSJung-uk Kim  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
970d84335fSJung-uk Kim  * LIMITED REMEDY.
980d84335fSJung-uk Kim  *
990d84335fSJung-uk Kim  * 4.3. Licensee shall not export, either directly or indirectly, any of this
1000d84335fSJung-uk Kim  * software or system incorporating such software without first obtaining any
1010d84335fSJung-uk Kim  * required license or other approval from the U. S. Department of Commerce or
1020d84335fSJung-uk Kim  * any other agency or department of the United States Government. In the
1030d84335fSJung-uk Kim  * event Licensee exports any such software from the United States or
1040d84335fSJung-uk Kim  * re-exports any such software from a foreign destination, Licensee shall
1050d84335fSJung-uk Kim  * ensure that the distribution and export/re-export of the software is in
1060d84335fSJung-uk Kim  * compliance with all laws, regulations, orders, or other restrictions of the
1070d84335fSJung-uk Kim  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
1080d84335fSJung-uk Kim  * any of its subsidiaries will export/re-export any technical data, process,
1090d84335fSJung-uk Kim  * software, or service, directly or indirectly, to any country for which the
1100d84335fSJung-uk Kim  * United States government or any agency thereof requires an export license,
1110d84335fSJung-uk Kim  * other governmental approval, or letter of assurance, without first obtaining
1120d84335fSJung-uk Kim  * such license, approval or letter.
1130d84335fSJung-uk Kim  *
1140d84335fSJung-uk Kim  *****************************************************************************
1150d84335fSJung-uk Kim  *
1160d84335fSJung-uk Kim  * Alternatively, you may choose to be licensed under the terms of the
1170d84335fSJung-uk Kim  * following license:
1180d84335fSJung-uk Kim  *
119e8241eabSJung-uk Kim  * Redistribution and use in source and binary forms, with or without
120e8241eabSJung-uk Kim  * modification, are permitted provided that the following conditions
121e8241eabSJung-uk Kim  * are met:
122e8241eabSJung-uk Kim  * 1. Redistributions of source code must retain the above copyright
123e8241eabSJung-uk Kim  *    notice, this list of conditions, and the following disclaimer,
124e8241eabSJung-uk Kim  *    without modification.
125e8241eabSJung-uk Kim  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
126e8241eabSJung-uk Kim  *    substantially similar to the "NO WARRANTY" disclaimer below
127e8241eabSJung-uk Kim  *    ("Disclaimer") and any redistribution must be conditioned upon
128e8241eabSJung-uk Kim  *    including a substantially similar Disclaimer requirement for further
129e8241eabSJung-uk Kim  *    binary redistribution.
130e8241eabSJung-uk Kim  * 3. Neither the names of the above-listed copyright holders nor the names
131e8241eabSJung-uk Kim  *    of any contributors may be used to endorse or promote products derived
132e8241eabSJung-uk Kim  *    from this software without specific prior written permission.
133e8241eabSJung-uk Kim  *
1340d84335fSJung-uk Kim  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1350d84335fSJung-uk Kim  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1360d84335fSJung-uk Kim  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1370d84335fSJung-uk Kim  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
1380d84335fSJung-uk Kim  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
1390d84335fSJung-uk Kim  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
1400d84335fSJung-uk Kim  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
1410d84335fSJung-uk Kim  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
1420d84335fSJung-uk Kim  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
1430d84335fSJung-uk Kim  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
1440d84335fSJung-uk Kim  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1450d84335fSJung-uk Kim  *
1460d84335fSJung-uk Kim  * Alternatively, you may choose to be licensed under the terms of the
147e8241eabSJung-uk Kim  * GNU General Public License ("GPL") version 2 as published by the Free
148e8241eabSJung-uk Kim  * Software Foundation.
149e8241eabSJung-uk Kim  *
1500d84335fSJung-uk Kim  *****************************************************************************/
151e8241eabSJung-uk Kim 
152313a0c13SJung-uk Kim #define EXPORT_ACPI_INTERFACES
153e8241eabSJung-uk Kim 
154e8241eabSJung-uk Kim #include <contrib/dev/acpica/include/acpi.h>
155e8241eabSJung-uk Kim #include <contrib/dev/acpica/include/accommon.h>
156e8241eabSJung-uk Kim #include <contrib/dev/acpica/include/acnamesp.h>
157e8241eabSJung-uk Kim #include <contrib/dev/acpica/include/actables.h>
158f8146b88SJung-uk Kim #include <contrib/dev/acpica/include/acevents.h>
159e8241eabSJung-uk Kim 
160e8241eabSJung-uk Kim #define _COMPONENT          ACPI_TABLES
161e8241eabSJung-uk Kim         ACPI_MODULE_NAME    ("tbxfload")
162e8241eabSJung-uk Kim 
163e8241eabSJung-uk Kim 
164e8241eabSJung-uk Kim /*******************************************************************************
165e8241eabSJung-uk Kim  *
166e8241eabSJung-uk Kim  * FUNCTION:    AcpiLoadTables
167e8241eabSJung-uk Kim  *
168e8241eabSJung-uk Kim  * PARAMETERS:  None
169e8241eabSJung-uk Kim  *
170e8241eabSJung-uk Kim  * RETURN:      Status
171e8241eabSJung-uk Kim  *
172e8241eabSJung-uk Kim  * DESCRIPTION: Load the ACPI tables from the RSDT/XSDT
173e8241eabSJung-uk Kim  *
174e8241eabSJung-uk Kim  ******************************************************************************/
175e8241eabSJung-uk Kim 
176493deb39SJung-uk Kim ACPI_STATUS ACPI_INIT_FUNCTION
AcpiLoadTables(void)177e8241eabSJung-uk Kim AcpiLoadTables (
178e8241eabSJung-uk Kim     void)
179e8241eabSJung-uk Kim {
180e8241eabSJung-uk Kim     ACPI_STATUS             Status;
181e8241eabSJung-uk Kim 
182e8241eabSJung-uk Kim 
183e8241eabSJung-uk Kim     ACPI_FUNCTION_TRACE (AcpiLoadTables);
184e8241eabSJung-uk Kim 
185e8241eabSJung-uk Kim 
186f8146b88SJung-uk Kim     /*
187f8146b88SJung-uk Kim      * Install the default operation region handlers. These are the
188f8146b88SJung-uk Kim      * handlers that are defined by the ACPI specification to be
189f8146b88SJung-uk Kim      * "always accessible" -- namely, SystemMemory, SystemIO, and
190f8146b88SJung-uk Kim      * PCI_Config. This also means that no _REG methods need to be
191f8146b88SJung-uk Kim      * run for these address spaces. We need to have these handlers
192f8146b88SJung-uk Kim      * installed before any AML code can be executed, especially any
193f8146b88SJung-uk Kim      * module-level code (11/2015).
194f8146b88SJung-uk Kim      * Note that we allow OSPMs to install their own region handlers
195f8146b88SJung-uk Kim      * between AcpiInitializeSubsystem() and AcpiLoadTables() to use
196f8146b88SJung-uk Kim      * their customized default region handlers.
197f8146b88SJung-uk Kim      */
198f8146b88SJung-uk Kim     Status = AcpiEvInstallRegionHandlers ();
199f8146b88SJung-uk Kim     if (ACPI_FAILURE (Status))
200f8146b88SJung-uk Kim     {
201f8146b88SJung-uk Kim         ACPI_EXCEPTION ((AE_INFO, Status, "During Region initialization"));
202f8146b88SJung-uk Kim         return_ACPI_STATUS (Status);
203f8146b88SJung-uk Kim     }
204f8146b88SJung-uk Kim 
205e8241eabSJung-uk Kim     /* Load the namespace from the tables */
206e8241eabSJung-uk Kim 
207e8241eabSJung-uk Kim     Status = AcpiTbLoadNamespace ();
20870e6ab8fSJung-uk Kim 
20970e6ab8fSJung-uk Kim     /* Don't let single failures abort the load */
21070e6ab8fSJung-uk Kim 
21170e6ab8fSJung-uk Kim     if (Status == AE_CTRL_TERMINATE)
21270e6ab8fSJung-uk Kim     {
21370e6ab8fSJung-uk Kim         Status = AE_OK;
21470e6ab8fSJung-uk Kim     }
21570e6ab8fSJung-uk Kim 
216e8241eabSJung-uk Kim     if (ACPI_FAILURE (Status))
217e8241eabSJung-uk Kim     {
218e8241eabSJung-uk Kim         ACPI_EXCEPTION ((AE_INFO, Status,
219e8241eabSJung-uk Kim             "While loading namespace from ACPI tables"));
220e8241eabSJung-uk Kim     }
221e8241eabSJung-uk Kim 
222f8146b88SJung-uk Kim     /*
223cd6518c7SJung-uk Kim      * Initialize the objects in the namespace that remain uninitialized.
224cd6518c7SJung-uk Kim      * This runs the executable AML that may be part of the declaration of
225cd6518c7SJung-uk Kim      * these name objects:
226f8146b88SJung-uk Kim      *     OperationRegions, BufferFields, Buffers, and Packages.
2278438a7a8SJung-uk Kim      *
228f8146b88SJung-uk Kim      */
229f8146b88SJung-uk Kim     Status = AcpiNsInitializeObjects ();
230cd6518c7SJung-uk Kim     if (ACPI_SUCCESS (Status))
231f8146b88SJung-uk Kim     {
232cd6518c7SJung-uk Kim         AcpiGbl_NamespaceInitialized = TRUE;
233f8146b88SJung-uk Kim     }
234f8146b88SJung-uk Kim 
235e8241eabSJung-uk Kim     return_ACPI_STATUS (Status);
236e8241eabSJung-uk Kim }
237e8241eabSJung-uk Kim 
ACPI_EXPORT_SYMBOL_INIT(AcpiLoadTables)238313a0c13SJung-uk Kim ACPI_EXPORT_SYMBOL_INIT (AcpiLoadTables)
239e8241eabSJung-uk Kim 
240e8241eabSJung-uk Kim 
241e8241eabSJung-uk Kim /*******************************************************************************
242e8241eabSJung-uk Kim  *
243e8241eabSJung-uk Kim  * FUNCTION:    AcpiTbLoadNamespace
244e8241eabSJung-uk Kim  *
245e8241eabSJung-uk Kim  * PARAMETERS:  None
246e8241eabSJung-uk Kim  *
247e8241eabSJung-uk Kim  * RETURN:      Status
248e8241eabSJung-uk Kim  *
249e8241eabSJung-uk Kim  * DESCRIPTION: Load the namespace from the DSDT and all SSDTs/PSDTs found in
250e8241eabSJung-uk Kim  *              the RSDT/XSDT.
251e8241eabSJung-uk Kim  *
252e8241eabSJung-uk Kim  ******************************************************************************/
253e8241eabSJung-uk Kim 
25470e6ab8fSJung-uk Kim ACPI_STATUS
255e8241eabSJung-uk Kim AcpiTbLoadNamespace (
256e8241eabSJung-uk Kim     void)
257e8241eabSJung-uk Kim {
258e8241eabSJung-uk Kim     ACPI_STATUS             Status;
259e8241eabSJung-uk Kim     UINT32                  i;
260e8241eabSJung-uk Kim     ACPI_TABLE_HEADER       *NewDsdt;
26170e6ab8fSJung-uk Kim     ACPI_TABLE_DESC         *Table;
26270e6ab8fSJung-uk Kim     UINT32                  TablesLoaded = 0;
26370e6ab8fSJung-uk Kim     UINT32                  TablesFailed = 0;
264e8241eabSJung-uk Kim 
265e8241eabSJung-uk Kim 
266e8241eabSJung-uk Kim     ACPI_FUNCTION_TRACE (TbLoadNamespace);
267e8241eabSJung-uk Kim 
268e8241eabSJung-uk Kim 
269e8241eabSJung-uk Kim     (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
270e8241eabSJung-uk Kim 
271e8241eabSJung-uk Kim     /*
272e8241eabSJung-uk Kim      * Load the namespace. The DSDT is required, but any SSDT and
273e8241eabSJung-uk Kim      * PSDT tables are optional. Verify the DSDT.
274e8241eabSJung-uk Kim      */
27570e6ab8fSJung-uk Kim     Table = &AcpiGbl_RootTableList.Tables[AcpiGbl_DsdtIndex];
27670e6ab8fSJung-uk Kim 
277e8241eabSJung-uk Kim     if (!AcpiGbl_RootTableList.CurrentTableCount ||
278278f0de6SJung-uk Kim         !ACPI_COMPARE_NAMESEG (Table->Signature.Ascii, ACPI_SIG_DSDT) ||
27970e6ab8fSJung-uk Kim          ACPI_FAILURE (AcpiTbValidateTable (Table)))
280e8241eabSJung-uk Kim     {
281e8241eabSJung-uk Kim         Status = AE_NO_ACPI_TABLES;
282e8241eabSJung-uk Kim         goto UnlockAndExit;
283e8241eabSJung-uk Kim     }
284e8241eabSJung-uk Kim 
285e8241eabSJung-uk Kim     /*
286e8241eabSJung-uk Kim      * Save the DSDT pointer for simple access. This is the mapped memory
287e8241eabSJung-uk Kim      * address. We must take care here because the address of the .Tables
288e8241eabSJung-uk Kim      * array can change dynamically as tables are loaded at run-time. Note:
289313a0c13SJung-uk Kim      * .Pointer field is not validated until after call to AcpiTbValidateTable.
290e8241eabSJung-uk Kim      */
29170e6ab8fSJung-uk Kim     AcpiGbl_DSDT = Table->Pointer;
292e8241eabSJung-uk Kim 
293e8241eabSJung-uk Kim     /*
294e8241eabSJung-uk Kim      * Optionally copy the entire DSDT to local memory (instead of simply
295e8241eabSJung-uk Kim      * mapping it.) There are some BIOSs that corrupt or replace the original
296e8241eabSJung-uk Kim      * DSDT, creating the need for this option. Default is FALSE, do not copy
297e8241eabSJung-uk Kim      * the DSDT.
298e8241eabSJung-uk Kim      */
299e8241eabSJung-uk Kim     if (AcpiGbl_CopyDsdtLocally)
300e8241eabSJung-uk Kim     {
30170e6ab8fSJung-uk Kim         NewDsdt = AcpiTbCopyDsdt (AcpiGbl_DsdtIndex);
302e8241eabSJung-uk Kim         if (NewDsdt)
303e8241eabSJung-uk Kim         {
304e8241eabSJung-uk Kim             AcpiGbl_DSDT = NewDsdt;
305e8241eabSJung-uk Kim         }
306e8241eabSJung-uk Kim     }
307e8241eabSJung-uk Kim 
308e8241eabSJung-uk Kim     /*
309e8241eabSJung-uk Kim      * Save the original DSDT header for detection of table corruption
310e8241eabSJung-uk Kim      * and/or replacement of the DSDT from outside the OS.
311e8241eabSJung-uk Kim      */
3125ef50723SJung-uk Kim     memcpy (&AcpiGbl_OriginalDsdtHeader, AcpiGbl_DSDT,
313e8241eabSJung-uk Kim         sizeof (ACPI_TABLE_HEADER));
314e8241eabSJung-uk Kim 
315e8241eabSJung-uk Kim     /* Load and parse tables */
316e8241eabSJung-uk Kim 
317493deb39SJung-uk Kim     (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
31870e6ab8fSJung-uk Kim     Status = AcpiNsLoadTable (AcpiGbl_DsdtIndex, AcpiGbl_RootNode);
319493deb39SJung-uk Kim     (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
320e8241eabSJung-uk Kim     if (ACPI_FAILURE (Status))
321e8241eabSJung-uk Kim     {
32270e6ab8fSJung-uk Kim         ACPI_EXCEPTION ((AE_INFO, Status, "[DSDT] table load failed"));
32370e6ab8fSJung-uk Kim         TablesFailed++;
32470e6ab8fSJung-uk Kim     }
32570e6ab8fSJung-uk Kim     else
32670e6ab8fSJung-uk Kim     {
32770e6ab8fSJung-uk Kim         TablesLoaded++;
328e8241eabSJung-uk Kim     }
329e8241eabSJung-uk Kim 
330e8241eabSJung-uk Kim     /* Load any SSDT or PSDT tables. Note: Loop leaves tables locked */
331e8241eabSJung-uk Kim 
332a9d8d09cSJung-uk Kim     for (i = 0; i < AcpiGbl_RootTableList.CurrentTableCount; ++i)
333e8241eabSJung-uk Kim     {
33470e6ab8fSJung-uk Kim         Table = &AcpiGbl_RootTableList.Tables[i];
33570e6ab8fSJung-uk Kim 
3365f9b24faSJung-uk Kim         if (!Table->Address ||
337278f0de6SJung-uk Kim             (!ACPI_COMPARE_NAMESEG (Table->Signature.Ascii, ACPI_SIG_SSDT) &&
338278f0de6SJung-uk Kim              !ACPI_COMPARE_NAMESEG (Table->Signature.Ascii, ACPI_SIG_PSDT) &&
339278f0de6SJung-uk Kim              !ACPI_COMPARE_NAMESEG (Table->Signature.Ascii, ACPI_SIG_OSDT)) ||
34070e6ab8fSJung-uk Kim             ACPI_FAILURE (AcpiTbValidateTable (Table)))
341e8241eabSJung-uk Kim         {
342e8241eabSJung-uk Kim             continue;
343e8241eabSJung-uk Kim         }
344e8241eabSJung-uk Kim 
345e8241eabSJung-uk Kim         /* Ignore errors while loading tables, get as many as possible */
346e8241eabSJung-uk Kim 
347e8241eabSJung-uk Kim         (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
34870e6ab8fSJung-uk Kim         Status =  AcpiNsLoadTable (i, AcpiGbl_RootNode);
349493deb39SJung-uk Kim         (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
35070e6ab8fSJung-uk Kim         if (ACPI_FAILURE (Status))
35170e6ab8fSJung-uk Kim         {
35270e6ab8fSJung-uk Kim             ACPI_EXCEPTION ((AE_INFO, Status, "(%4.4s:%8.8s) while loading table",
35370e6ab8fSJung-uk Kim                 Table->Signature.Ascii, Table->Pointer->OemTableId));
354f8146b88SJung-uk Kim 
35570e6ab8fSJung-uk Kim             TablesFailed++;
35670e6ab8fSJung-uk Kim 
35770e6ab8fSJung-uk Kim             ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT,
35870e6ab8fSJung-uk Kim                 "Table [%4.4s:%8.8s] (id FF) - Table namespace load failed\n\n",
35970e6ab8fSJung-uk Kim                 Table->Signature.Ascii, Table->Pointer->OemTableId));
36070e6ab8fSJung-uk Kim         }
36170e6ab8fSJung-uk Kim         else
36270e6ab8fSJung-uk Kim         {
36370e6ab8fSJung-uk Kim             TablesLoaded++;
36470e6ab8fSJung-uk Kim         }
365e8241eabSJung-uk Kim     }
366e8241eabSJung-uk Kim 
36770e6ab8fSJung-uk Kim     if (!TablesFailed)
36870e6ab8fSJung-uk Kim     {
369f8146b88SJung-uk Kim         ACPI_INFO ((
370493deb39SJung-uk Kim             "%u ACPI AML tables successfully acquired and loaded",
37170e6ab8fSJung-uk Kim             TablesLoaded));
37270e6ab8fSJung-uk Kim     }
37370e6ab8fSJung-uk Kim     else
37470e6ab8fSJung-uk Kim     {
37570e6ab8fSJung-uk Kim         ACPI_ERROR ((AE_INFO,
37670e6ab8fSJung-uk Kim             "%u table load failures, %u successful",
37770e6ab8fSJung-uk Kim             TablesFailed, TablesLoaded));
37870e6ab8fSJung-uk Kim 
37970e6ab8fSJung-uk Kim         /* Indicate at least one failure */
38070e6ab8fSJung-uk Kim 
38170e6ab8fSJung-uk Kim         Status = AE_CTRL_TERMINATE;
38270e6ab8fSJung-uk Kim     }
383e8241eabSJung-uk Kim 
384493deb39SJung-uk Kim #ifdef ACPI_APPLICATION
385493deb39SJung-uk Kim     ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT, "\n"));
386493deb39SJung-uk Kim #endif
387493deb39SJung-uk Kim 
388493deb39SJung-uk Kim 
389e8241eabSJung-uk Kim UnlockAndExit:
390e8241eabSJung-uk Kim     (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
391e8241eabSJung-uk Kim     return_ACPI_STATUS (Status);
392e8241eabSJung-uk Kim }
393e8241eabSJung-uk Kim 
394e8241eabSJung-uk Kim 
395e8241eabSJung-uk Kim /*******************************************************************************
396e8241eabSJung-uk Kim  *
397313a0c13SJung-uk Kim  * FUNCTION:    AcpiInstallTable
398313a0c13SJung-uk Kim  *
399ab71bbb7SJung-uk Kim  * PARAMETERS:  Table               - Pointer to the ACPI table to be installed.
400313a0c13SJung-uk Kim  *
401313a0c13SJung-uk Kim  * RETURN:      Status
402313a0c13SJung-uk Kim  *
403313a0c13SJung-uk Kim  * DESCRIPTION: Dynamically install an ACPI table.
404313a0c13SJung-uk Kim  *              Note: This function should only be invoked after
405313a0c13SJung-uk Kim  *                    AcpiInitializeTables() and before AcpiLoadTables().
406313a0c13SJung-uk Kim  *
407313a0c13SJung-uk Kim  ******************************************************************************/
408313a0c13SJung-uk Kim 
409493deb39SJung-uk Kim ACPI_STATUS ACPI_INIT_FUNCTION
AcpiInstallTable(ACPI_TABLE_HEADER * Table)410313a0c13SJung-uk Kim AcpiInstallTable (
411ab71bbb7SJung-uk Kim     ACPI_TABLE_HEADER       *Table)
412313a0c13SJung-uk Kim {
413313a0c13SJung-uk Kim     ACPI_STATUS             Status;
414313a0c13SJung-uk Kim     UINT32                  TableIndex;
415313a0c13SJung-uk Kim 
416313a0c13SJung-uk Kim 
417313a0c13SJung-uk Kim     ACPI_FUNCTION_TRACE (AcpiInstallTable);
418313a0c13SJung-uk Kim 
419313a0c13SJung-uk Kim 
420ab71bbb7SJung-uk Kim     Status = AcpiTbInstallStandardTable (ACPI_PTR_TO_PHYSADDR (Table),
421ab71bbb7SJung-uk Kim         ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL, Table, FALSE, FALSE, &TableIndex);
422313a0c13SJung-uk Kim 
423313a0c13SJung-uk Kim     return_ACPI_STATUS (Status);
424313a0c13SJung-uk Kim }
425313a0c13SJung-uk Kim 
ACPI_EXPORT_SYMBOL_INIT(AcpiInstallTable)426313a0c13SJung-uk Kim ACPI_EXPORT_SYMBOL_INIT (AcpiInstallTable)
427313a0c13SJung-uk Kim 
428313a0c13SJung-uk Kim 
429313a0c13SJung-uk Kim /*******************************************************************************
430313a0c13SJung-uk Kim  *
431ab71bbb7SJung-uk Kim  * FUNCTION:    AcpiInstallPhysicalTable
432ab71bbb7SJung-uk Kim  *
433ab71bbb7SJung-uk Kim  * PARAMETERS:  Address             - Address of the ACPI table to be installed.
434ab71bbb7SJung-uk Kim  *
435ab71bbb7SJung-uk Kim  * RETURN:      Status
436ab71bbb7SJung-uk Kim  *
437ab71bbb7SJung-uk Kim  * DESCRIPTION: Dynamically install an ACPI table.
438ab71bbb7SJung-uk Kim  *              Note: This function should only be invoked after
439ab71bbb7SJung-uk Kim  *                    AcpiInitializeTables() and before AcpiLoadTables().
440ab71bbb7SJung-uk Kim  *
441ab71bbb7SJung-uk Kim  ******************************************************************************/
442ab71bbb7SJung-uk Kim 
443ab71bbb7SJung-uk Kim ACPI_STATUS ACPI_INIT_FUNCTION
444ab71bbb7SJung-uk Kim AcpiInstallPhysicalTable (
445ab71bbb7SJung-uk Kim     ACPI_PHYSICAL_ADDRESS   Address)
446ab71bbb7SJung-uk Kim {
447ab71bbb7SJung-uk Kim     ACPI_STATUS             Status;
448ab71bbb7SJung-uk Kim     UINT32                  TableIndex;
449ab71bbb7SJung-uk Kim 
450ab71bbb7SJung-uk Kim 
451ab71bbb7SJung-uk Kim     ACPI_FUNCTION_TRACE (AcpiInstallPhysicalTable);
452ab71bbb7SJung-uk Kim 
453ab71bbb7SJung-uk Kim 
454ab71bbb7SJung-uk Kim     Status = AcpiTbInstallStandardTable (Address,
455ab71bbb7SJung-uk Kim         ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL, NULL, FALSE, FALSE, &TableIndex);
456ab71bbb7SJung-uk Kim 
457ab71bbb7SJung-uk Kim     return_ACPI_STATUS (Status);
458ab71bbb7SJung-uk Kim }
459ab71bbb7SJung-uk Kim 
ACPI_EXPORT_SYMBOL_INIT(AcpiInstallPhysicalTable)460ab71bbb7SJung-uk Kim ACPI_EXPORT_SYMBOL_INIT (AcpiInstallPhysicalTable)
461ab71bbb7SJung-uk Kim 
462ab71bbb7SJung-uk Kim 
463ab71bbb7SJung-uk Kim /*******************************************************************************
464ab71bbb7SJung-uk Kim  *
465e8241eabSJung-uk Kim  * FUNCTION:    AcpiLoadTable
466e8241eabSJung-uk Kim  *
467e8241eabSJung-uk Kim  * PARAMETERS:  Table               - Pointer to a buffer containing the ACPI
468e8241eabSJung-uk Kim  *                                    table to be loaded.
469a009b7dcSJung-uk Kim  *              TableIdx            - Pointer to a UINT32 for storing the table
470a009b7dcSJung-uk Kim  *                                    index, might be NULL
471e8241eabSJung-uk Kim  *
472e8241eabSJung-uk Kim  * RETURN:      Status
473e8241eabSJung-uk Kim  *
474e8241eabSJung-uk Kim  * DESCRIPTION: Dynamically load an ACPI table from the caller's buffer. Must
475e8241eabSJung-uk Kim  *              be a valid ACPI table with a valid ACPI table header.
476e8241eabSJung-uk Kim  *              Note1: Mainly intended to support hotplug addition of SSDTs.
4778ef1a331SJung-uk Kim  *              Note2: Does not copy the incoming table. User is responsible
478e8241eabSJung-uk Kim  *              to ensure that the table is not deleted or unmapped.
479e8241eabSJung-uk Kim  *
480e8241eabSJung-uk Kim  ******************************************************************************/
481e8241eabSJung-uk Kim 
482e8241eabSJung-uk Kim ACPI_STATUS
483e8241eabSJung-uk Kim AcpiLoadTable (
484a009b7dcSJung-uk Kim     ACPI_TABLE_HEADER       *Table,
485a009b7dcSJung-uk Kim     UINT32                  *TableIdx)
486e8241eabSJung-uk Kim {
487e8241eabSJung-uk Kim     ACPI_STATUS             Status;
488e8241eabSJung-uk Kim     UINT32                  TableIndex;
489e8241eabSJung-uk Kim 
490e8241eabSJung-uk Kim 
491e8241eabSJung-uk Kim     ACPI_FUNCTION_TRACE (AcpiLoadTable);
492e8241eabSJung-uk Kim 
493e8241eabSJung-uk Kim 
494e8241eabSJung-uk Kim     /* Parameter validation */
495e8241eabSJung-uk Kim 
496e8241eabSJung-uk Kim     if (!Table)
497e8241eabSJung-uk Kim     {
498e8241eabSJung-uk Kim         return_ACPI_STATUS (AE_BAD_PARAMETER);
499e8241eabSJung-uk Kim     }
500e8241eabSJung-uk Kim 
501e8241eabSJung-uk Kim     /* Install the table and load it into the namespace */
502e8241eabSJung-uk Kim 
503f8146b88SJung-uk Kim     ACPI_INFO (("Host-directed Dynamic ACPI Table Load:"));
5041cc50d6bSJung-uk Kim     Status = AcpiTbInstallAndLoadTable (ACPI_PTR_TO_PHYSADDR (Table),
505ab71bbb7SJung-uk Kim         ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL, Table, FALSE, &TableIndex);
506a009b7dcSJung-uk Kim     if (TableIdx)
507a009b7dcSJung-uk Kim     {
508a009b7dcSJung-uk Kim         *TableIdx = TableIndex;
509a009b7dcSJung-uk Kim     }
510a009b7dcSJung-uk Kim 
51137d7a5bcSJung-uk Kim     if (ACPI_SUCCESS (Status))
51237d7a5bcSJung-uk Kim     {
51337d7a5bcSJung-uk Kim         /* Complete the initialization/resolution of new objects */
51437d7a5bcSJung-uk Kim 
51537d7a5bcSJung-uk Kim         AcpiNsInitializeObjects ();
51637d7a5bcSJung-uk Kim     }
51737d7a5bcSJung-uk Kim 
518e8241eabSJung-uk Kim     return_ACPI_STATUS (Status);
519e8241eabSJung-uk Kim }
520e8241eabSJung-uk Kim 
ACPI_EXPORT_SYMBOL(AcpiLoadTable)521e8241eabSJung-uk Kim ACPI_EXPORT_SYMBOL (AcpiLoadTable)
522e8241eabSJung-uk Kim 
523e8241eabSJung-uk Kim 
524e8241eabSJung-uk Kim /*******************************************************************************
525e8241eabSJung-uk Kim  *
526e8241eabSJung-uk Kim  * FUNCTION:    AcpiUnloadParentTable
527e8241eabSJung-uk Kim  *
528e8241eabSJung-uk Kim  * PARAMETERS:  Object              - Handle to any namespace object owned by
529e8241eabSJung-uk Kim  *                                    the table to be unloaded
530e8241eabSJung-uk Kim  *
531e8241eabSJung-uk Kim  * RETURN:      Status
532e8241eabSJung-uk Kim  *
533e8241eabSJung-uk Kim  * DESCRIPTION: Via any namespace object within an SSDT or OEMx table, unloads
534e8241eabSJung-uk Kim  *              the table and deletes all namespace objects associated with
535e8241eabSJung-uk Kim  *              that table. Unloading of the DSDT is not allowed.
536e8241eabSJung-uk Kim  *              Note: Mainly intended to support hotplug removal of SSDTs.
537e8241eabSJung-uk Kim  *
538e8241eabSJung-uk Kim  ******************************************************************************/
539e8241eabSJung-uk Kim 
540e8241eabSJung-uk Kim ACPI_STATUS
541e8241eabSJung-uk Kim AcpiUnloadParentTable (
542e8241eabSJung-uk Kim     ACPI_HANDLE             Object)
543e8241eabSJung-uk Kim {
544e8241eabSJung-uk Kim     ACPI_NAMESPACE_NODE     *Node = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, Object);
545e8241eabSJung-uk Kim     ACPI_STATUS             Status = AE_NOT_EXIST;
546e8241eabSJung-uk Kim     ACPI_OWNER_ID           OwnerId;
547e8241eabSJung-uk Kim     UINT32                  i;
548e8241eabSJung-uk Kim 
549e8241eabSJung-uk Kim 
550e8241eabSJung-uk Kim     ACPI_FUNCTION_TRACE (AcpiUnloadParentTable);
551e8241eabSJung-uk Kim 
552e8241eabSJung-uk Kim 
553e8241eabSJung-uk Kim     /* Parameter validation */
554e8241eabSJung-uk Kim 
555e8241eabSJung-uk Kim     if (!Object)
556e8241eabSJung-uk Kim     {
557e8241eabSJung-uk Kim         return_ACPI_STATUS (AE_BAD_PARAMETER);
558e8241eabSJung-uk Kim     }
559e8241eabSJung-uk Kim 
560e8241eabSJung-uk Kim     /*
561e8241eabSJung-uk Kim      * The node OwnerId is currently the same as the parent table ID.
562e8241eabSJung-uk Kim      * However, this could change in the future.
563e8241eabSJung-uk Kim      */
564e8241eabSJung-uk Kim     OwnerId = Node->OwnerId;
565e8241eabSJung-uk Kim     if (!OwnerId)
566e8241eabSJung-uk Kim     {
567e8241eabSJung-uk Kim         /* OwnerId==0 means DSDT is the owner. DSDT cannot be unloaded */
568e8241eabSJung-uk Kim 
569e8241eabSJung-uk Kim         return_ACPI_STATUS (AE_TYPE);
570e8241eabSJung-uk Kim     }
571e8241eabSJung-uk Kim 
572493deb39SJung-uk Kim     /* Must acquire the table lock during this operation */
573e8241eabSJung-uk Kim 
574493deb39SJung-uk Kim     Status = AcpiUtAcquireMutex (ACPI_MTX_TABLES);
575e8241eabSJung-uk Kim     if (ACPI_FAILURE (Status))
576e8241eabSJung-uk Kim     {
577e8241eabSJung-uk Kim         return_ACPI_STATUS (Status);
578e8241eabSJung-uk Kim     }
579e8241eabSJung-uk Kim 
580e8241eabSJung-uk Kim     /* Find the table in the global table list */
581e8241eabSJung-uk Kim 
582e8241eabSJung-uk Kim     for (i = 0; i < AcpiGbl_RootTableList.CurrentTableCount; i++)
583e8241eabSJung-uk Kim     {
584e8241eabSJung-uk Kim         if (OwnerId != AcpiGbl_RootTableList.Tables[i].OwnerId)
585e8241eabSJung-uk Kim         {
586e8241eabSJung-uk Kim             continue;
587e8241eabSJung-uk Kim         }
588e8241eabSJung-uk Kim 
589e8241eabSJung-uk Kim         /*
590e8241eabSJung-uk Kim          * Allow unload of SSDT and OEMx tables only. Do not allow unload
591e8241eabSJung-uk Kim          * of the DSDT. No other types of tables should get here, since
592e8241eabSJung-uk Kim          * only these types can contain AML and thus are the only types
593e8241eabSJung-uk Kim          * that can create namespace objects.
594e8241eabSJung-uk Kim          */
595278f0de6SJung-uk Kim         if (ACPI_COMPARE_NAMESEG (
596e8241eabSJung-uk Kim                 AcpiGbl_RootTableList.Tables[i].Signature.Ascii,
597e8241eabSJung-uk Kim                 ACPI_SIG_DSDT))
598e8241eabSJung-uk Kim         {
599e8241eabSJung-uk Kim             Status = AE_TYPE;
600e8241eabSJung-uk Kim             break;
601e8241eabSJung-uk Kim         }
602e8241eabSJung-uk Kim 
603493deb39SJung-uk Kim         (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
6041cc50d6bSJung-uk Kim         Status = AcpiTbUnloadTable (i);
605493deb39SJung-uk Kim         (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
606e8241eabSJung-uk Kim         break;
607e8241eabSJung-uk Kim     }
608e8241eabSJung-uk Kim 
609493deb39SJung-uk Kim     (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
610e8241eabSJung-uk Kim     return_ACPI_STATUS (Status);
611e8241eabSJung-uk Kim }
612e8241eabSJung-uk Kim 
ACPI_EXPORT_SYMBOL(AcpiUnloadParentTable)613e8241eabSJung-uk Kim ACPI_EXPORT_SYMBOL (AcpiUnloadParentTable)
614a009b7dcSJung-uk Kim 
615a009b7dcSJung-uk Kim 
616a009b7dcSJung-uk Kim /*******************************************************************************
617a009b7dcSJung-uk Kim  *
618a009b7dcSJung-uk Kim  * FUNCTION:    AcpiUnloadTable
619a009b7dcSJung-uk Kim  *
620a009b7dcSJung-uk Kim  * PARAMETERS:  TableIndex          - Index as returned by AcpiLoadTable
621a009b7dcSJung-uk Kim  *
622a009b7dcSJung-uk Kim  * RETURN:      Status
623a009b7dcSJung-uk Kim  *
624a009b7dcSJung-uk Kim  * DESCRIPTION: Via the TableIndex representing an SSDT or OEMx table, unloads
625a009b7dcSJung-uk Kim  *              the table and deletes all namespace objects associated with
626a009b7dcSJung-uk Kim  *              that table. Unloading of the DSDT is not allowed.
627a009b7dcSJung-uk Kim  *              Note: Mainly intended to support hotplug removal of SSDTs.
628a009b7dcSJung-uk Kim  *
629a009b7dcSJung-uk Kim  ******************************************************************************/
630a009b7dcSJung-uk Kim 
631a009b7dcSJung-uk Kim ACPI_STATUS
632a009b7dcSJung-uk Kim AcpiUnloadTable (
633a009b7dcSJung-uk Kim     UINT32                  TableIndex)
634a009b7dcSJung-uk Kim {
635a009b7dcSJung-uk Kim     ACPI_STATUS             Status;
636a009b7dcSJung-uk Kim 
637a009b7dcSJung-uk Kim 
638a009b7dcSJung-uk Kim     ACPI_FUNCTION_TRACE (AcpiUnloadTable);
639a009b7dcSJung-uk Kim 
640a009b7dcSJung-uk Kim 
641a009b7dcSJung-uk Kim     if (TableIndex == 1)
642a009b7dcSJung-uk Kim     {
643a009b7dcSJung-uk Kim         /* TableIndex==1 means DSDT is the owner. DSDT cannot be unloaded */
644a009b7dcSJung-uk Kim 
645a009b7dcSJung-uk Kim         return_ACPI_STATUS (AE_TYPE);
646a009b7dcSJung-uk Kim     }
647a009b7dcSJung-uk Kim 
648a009b7dcSJung-uk Kim     Status = AcpiTbUnloadTable (TableIndex);
649a009b7dcSJung-uk Kim     return_ACPI_STATUS (Status);
650a009b7dcSJung-uk Kim }
651a009b7dcSJung-uk Kim 
652a009b7dcSJung-uk Kim ACPI_EXPORT_SYMBOL (AcpiUnloadTable)
653