16822cda0SFredrik Holmqvist/******************************************************************************
26822cda0SFredrik Holmqvist *
36822cda0SFredrik Holmqvist * Module Name: tbxfload - Table load/unload external interfaces
46822cda0SFredrik Holmqvist *
56822cda0SFredrik Holmqvist *****************************************************************************/
66822cda0SFredrik Holmqvist
76822cda0SFredrik Holmqvist/******************************************************************************
86822cda0SFredrik Holmqvist *
96822cda0SFredrik Holmqvist * 1. Copyright Notice
106822cda0SFredrik Holmqvist *
11ff2e2f81SFredrik Holmqvist * Some or all of this work - Copyright (c) 1999 - 2018, Intel Corp.
126822cda0SFredrik Holmqvist * All rights reserved.
136822cda0SFredrik Holmqvist *
146822cda0SFredrik Holmqvist * 2. License
156822cda0SFredrik Holmqvist *
166822cda0SFredrik Holmqvist * 2.1. This is your license from Intel Corp. under its intellectual property
179b0d045cSFredrik Holmqvist * rights. You may have additional license terms from the party that provided
186822cda0SFredrik Holmqvist * you this software, covering your right to use that party's intellectual
196822cda0SFredrik Holmqvist * property rights.
206822cda0SFredrik Holmqvist *
216822cda0SFredrik Holmqvist * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
226822cda0SFredrik Holmqvist * copy of the source code appearing in this file ("Covered Code") an
236822cda0SFredrik Holmqvist * irrevocable, perpetual, worldwide license under Intel's copyrights in the
246822cda0SFredrik Holmqvist * base code distributed originally by Intel ("Original Intel Code") to copy,
256822cda0SFredrik Holmqvist * make derivatives, distribute, use and display any portion of the Covered
266822cda0SFredrik Holmqvist * Code in any form, with the right to sublicense such rights; and
276822cda0SFredrik Holmqvist *
286822cda0SFredrik Holmqvist * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
296822cda0SFredrik Holmqvist * license (with the right to sublicense), under only those claims of Intel
306822cda0SFredrik Holmqvist * patents that are infringed by the Original Intel Code, to make, use, sell,
316822cda0SFredrik Holmqvist * offer to sell, and import the Covered Code and derivative works thereof
326822cda0SFredrik Holmqvist * solely to the minimum extent necessary to exercise the above copyright
336822cda0SFredrik Holmqvist * license, and in no event shall the patent license extend to any additions
349b0d045cSFredrik Holmqvist * to or modifications of the Original Intel Code. No other license or right
356822cda0SFredrik Holmqvist * is granted directly or by implication, estoppel or otherwise;
366822cda0SFredrik Holmqvist *
376822cda0SFredrik Holmqvist * The above copyright and patent license is granted only if the following
386822cda0SFredrik Holmqvist * conditions are met:
396822cda0SFredrik Holmqvist *
406822cda0SFredrik Holmqvist * 3. Conditions
416822cda0SFredrik Holmqvist *
426822cda0SFredrik Holmqvist * 3.1. Redistribution of Source with Rights to Further Distribute Source.
436822cda0SFredrik Holmqvist * Redistribution of source code of any substantial portion of the Covered
446822cda0SFredrik Holmqvist * Code or modification with rights to further distribute source must include
456822cda0SFredrik Holmqvist * the above Copyright Notice, the above License, this list of Conditions,
469b0d045cSFredrik Holmqvist * and the following Disclaimer and Export Compliance provision. In addition,
476822cda0SFredrik Holmqvist * Licensee must cause all Covered Code to which Licensee contributes to
486822cda0SFredrik Holmqvist * contain a file documenting the changes Licensee made to create that Covered
499b0d045cSFredrik Holmqvist * Code and the date of any change. Licensee must include in that file the
509b0d045cSFredrik Holmqvist * documentation of any changes made by any predecessor Licensee. Licensee
516822cda0SFredrik Holmqvist * must include a prominent statement that the modification is derived,
526822cda0SFredrik Holmqvist * directly or indirectly, from Original Intel Code.
536822cda0SFredrik Holmqvist *
546822cda0SFredrik Holmqvist * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
556822cda0SFredrik Holmqvist * Redistribution of source code of any substantial portion of the Covered
566822cda0SFredrik Holmqvist * Code or modification without rights to further distribute source must
576822cda0SFredrik Holmqvist * include the following Disclaimer and Export Compliance provision in the
589b0d045cSFredrik Holmqvist * documentation and/or other materials provided with distribution. In
596822cda0SFredrik Holmqvist * addition, Licensee may not authorize further sublicense of source of any
606822cda0SFredrik Holmqvist * portion of the Covered Code, and must include terms to the effect that the
616822cda0SFredrik Holmqvist * license from Licensee to its licensee is limited to the intellectual
626822cda0SFredrik Holmqvist * property embodied in the software Licensee provides to its licensee, and
636822cda0SFredrik Holmqvist * not to intellectual property embodied in modifications its licensee may
646822cda0SFredrik Holmqvist * make.
656822cda0SFredrik Holmqvist *
666822cda0SFredrik Holmqvist * 3.3. Redistribution of Executable. Redistribution in executable form of any
676822cda0SFredrik Holmqvist * substantial portion of the Covered Code or modification must reproduce the
686822cda0SFredrik Holmqvist * above Copyright Notice, and the following Disclaimer and Export Compliance
696822cda0SFredrik Holmqvist * provision in the documentation and/or other materials provided with the
706822cda0SFredrik Holmqvist * distribution.
716822cda0SFredrik Holmqvist *
726822cda0SFredrik Holmqvist * 3.4. Intel retains all right, title, and interest in and to the Original
736822cda0SFredrik Holmqvist * Intel Code.
746822cda0SFredrik Holmqvist *
756822cda0SFredrik Holmqvist * 3.5. Neither the name Intel nor any other trademark owned or controlled by
766822cda0SFredrik Holmqvist * Intel shall be used in advertising or otherwise to promote the sale, use or
776822cda0SFredrik Holmqvist * other dealings in products derived from or relating to the Covered Code
786822cda0SFredrik Holmqvist * without prior written authorization from Intel.
796822cda0SFredrik Holmqvist *
806822cda0SFredrik Holmqvist * 4. Disclaimer and Export Compliance
816822cda0SFredrik Holmqvist *
826822cda0SFredrik Holmqvist * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
839b0d045cSFredrik Holmqvist * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
849b0d045cSFredrik Holmqvist * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
859b0d045cSFredrik Holmqvist * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
869b0d045cSFredrik Holmqvist * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
876822cda0SFredrik Holmqvist * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
886822cda0SFredrik Holmqvist * PARTICULAR PURPOSE.
896822cda0SFredrik Holmqvist *
906822cda0SFredrik Holmqvist * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
916822cda0SFredrik Holmqvist * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
926822cda0SFredrik Holmqvist * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
936822cda0SFredrik Holmqvist * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
946822cda0SFredrik Holmqvist * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
959b0d045cSFredrik Holmqvist * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
966822cda0SFredrik Holmqvist * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
976822cda0SFredrik Holmqvist * LIMITED REMEDY.
986822cda0SFredrik Holmqvist *
996822cda0SFredrik Holmqvist * 4.3. Licensee shall not export, either directly or indirectly, any of this
1006822cda0SFredrik Holmqvist * software or system incorporating such software without first obtaining any
1016822cda0SFredrik Holmqvist * required license or other approval from the U. S. Department of Commerce or
1029b0d045cSFredrik Holmqvist * any other agency or department of the United States Government. In the
1036822cda0SFredrik Holmqvist * event Licensee exports any such software from the United States or
1046822cda0SFredrik Holmqvist * re-exports any such software from a foreign destination, Licensee shall
1056822cda0SFredrik Holmqvist * ensure that the distribution and export/re-export of the software is in
1066822cda0SFredrik Holmqvist * compliance with all laws, regulations, orders, or other restrictions of the
1076822cda0SFredrik Holmqvist * U.S. Export Administration Regulations. Licensee agrees that neither it nor
1086822cda0SFredrik Holmqvist * any of its subsidiaries will export/re-export any technical data, process,
1096822cda0SFredrik Holmqvist * software, or service, directly or indirectly, to any country for which the
1106822cda0SFredrik Holmqvist * United States government or any agency thereof requires an export license,
1116822cda0SFredrik Holmqvist * other governmental approval, or letter of assurance, without first obtaining
1126822cda0SFredrik Holmqvist * such license, approval or letter.
1136822cda0SFredrik Holmqvist *
114ff2e2f81SFredrik Holmqvist *****************************************************************************
115ff2e2f81SFredrik Holmqvist *
116ff2e2f81SFredrik Holmqvist * Alternatively, you may choose to be licensed under the terms of the
117ff2e2f81SFredrik Holmqvist * following license:
118ff2e2f81SFredrik Holmqvist *
119ff2e2f81SFredrik Holmqvist * Redistribution and use in source and binary forms, with or without
120ff2e2f81SFredrik Holmqvist * modification, are permitted provided that the following conditions
121ff2e2f81SFredrik Holmqvist * are met:
122ff2e2f81SFredrik Holmqvist * 1. Redistributions of source code must retain the above copyright
123ff2e2f81SFredrik Holmqvist *    notice, this list of conditions, and the following disclaimer,
124ff2e2f81SFredrik Holmqvist *    without modification.
125ff2e2f81SFredrik Holmqvist * 2. Redistributions in binary form must reproduce at minimum a disclaimer
126ff2e2f81SFredrik Holmqvist *    substantially similar to the "NO WARRANTY" disclaimer below
127ff2e2f81SFredrik Holmqvist *    ("Disclaimer") and any redistribution must be conditioned upon
128ff2e2f81SFredrik Holmqvist *    including a substantially similar Disclaimer requirement for further
129ff2e2f81SFredrik Holmqvist *    binary redistribution.
130ff2e2f81SFredrik Holmqvist * 3. Neither the names of the above-listed copyright holders nor the names
131ff2e2f81SFredrik Holmqvist *    of any contributors may be used to endorse or promote products derived
132ff2e2f81SFredrik Holmqvist *    from this software without specific prior written permission.
133ff2e2f81SFredrik Holmqvist *
134ff2e2f81SFredrik Holmqvist * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
135ff2e2f81SFredrik Holmqvist * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
136ff2e2f81SFredrik Holmqvist * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
137ff2e2f81SFredrik Holmqvist * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
138ff2e2f81SFredrik Holmqvist * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
139ff2e2f81SFredrik Holmqvist * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
140ff2e2f81SFredrik Holmqvist * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
141ff2e2f81SFredrik Holmqvist * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
142ff2e2f81SFredrik Holmqvist * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
143ff2e2f81SFredrik Holmqvist * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
144ff2e2f81SFredrik Holmqvist * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
145ff2e2f81SFredrik Holmqvist *
146ff2e2f81SFredrik Holmqvist * Alternatively, you may choose to be licensed under the terms of the
147ff2e2f81SFredrik Holmqvist * GNU General Public License ("GPL") version 2 as published by the Free
148ff2e2f81SFredrik Holmqvist * Software Foundation.
149ff2e2f81SFredrik Holmqvist *
1506822cda0SFredrik Holmqvist *****************************************************************************/
1516822cda0SFredrik Holmqvist
152ad5bbfb8SFredrik Holmqvist#define EXPORT_ACPI_INTERFACES
1536822cda0SFredrik Holmqvist
1546822cda0SFredrik Holmqvist#include "acpi.h"
1556822cda0SFredrik Holmqvist#include "accommon.h"
1566822cda0SFredrik Holmqvist#include "acnamesp.h"
1576822cda0SFredrik Holmqvist#include "actables.h"
15874ffd18dSFredrik Holmqvist#include "acevents.h"
1596822cda0SFredrik Holmqvist
1606822cda0SFredrik Holmqvist#define _COMPONENT          ACPI_TABLES
1616822cda0SFredrik Holmqvist        ACPI_MODULE_NAME    ("tbxfload")
1626822cda0SFredrik Holmqvist
1636822cda0SFredrik Holmqvist
1646822cda0SFredrik Holmqvist/*******************************************************************************
1656822cda0SFredrik Holmqvist *
1666822cda0SFredrik Holmqvist * FUNCTION:    AcpiLoadTables
1676822cda0SFredrik Holmqvist *
1686822cda0SFredrik Holmqvist * PARAMETERS:  None
1696822cda0SFredrik Holmqvist *
1706822cda0SFredrik Holmqvist * RETURN:      Status
1716822cda0SFredrik Holmqvist *
1726822cda0SFredrik Holmqvist * DESCRIPTION: Load the ACPI tables from the RSDT/XSDT
1736822cda0SFredrik Holmqvist *
1746822cda0SFredrik Holmqvist ******************************************************************************/
1756822cda0SFredrik Holmqvist
17674ffd18dSFredrik HolmqvistACPI_STATUS ACPI_INIT_FUNCTION
1776822cda0SFredrik HolmqvistAcpiLoadTables (
1786822cda0SFredrik Holmqvist    void)
1796822cda0SFredrik Holmqvist{
1806822cda0SFredrik Holmqvist    ACPI_STATUS             Status;
1816822cda0SFredrik Holmqvist
1826822cda0SFredrik Holmqvist
1836822cda0SFredrik Holmqvist    ACPI_FUNCTION_TRACE (AcpiLoadTables);
1846822cda0SFredrik Holmqvist
1856822cda0SFredrik Holmqvist
18674ffd18dSFredrik Holmqvist    /*
18774ffd18dSFredrik Holmqvist     * Install the default operation region handlers. These are the
18874ffd18dSFredrik Holmqvist     * handlers that are defined by the ACPI specification to be
18974ffd18dSFredrik Holmqvist     * "always accessible" -- namely, SystemMemory, SystemIO, and
19074ffd18dSFredrik Holmqvist     * PCI_Config. This also means that no _REG methods need to be
19174ffd18dSFredrik Holmqvist     * run for these address spaces. We need to have these handlers
19274ffd18dSFredrik Holmqvist     * installed before any AML code can be executed, especially any
19374ffd18dSFredrik Holmqvist     * module-level code (11/2015).
19474ffd18dSFredrik Holmqvist     * Note that we allow OSPMs to install their own region handlers
19574ffd18dSFredrik Holmqvist     * between AcpiInitializeSubsystem() and AcpiLoadTables() to use
19674ffd18dSFredrik Holmqvist     * their customized default region handlers.
19774ffd18dSFredrik Holmqvist     */
19874ffd18dSFredrik Holmqvist    Status = AcpiEvInstallRegionHandlers ();
19974ffd18dSFredrik Holmqvist    if (ACPI_FAILURE (Status))
20074ffd18dSFredrik Holmqvist    {
20174ffd18dSFredrik Holmqvist        ACPI_EXCEPTION ((AE_INFO, Status, "During Region initialization"));
20274ffd18dSFredrik Holmqvist        return_ACPI_STATUS (Status);
20374ffd18dSFredrik Holmqvist    }
20474ffd18dSFredrik Holmqvist
2056822cda0SFredrik Holmqvist    /* Load the namespace from the tables */
2066822cda0SFredrik Holmqvist
2076822cda0SFredrik Holmqvist    Status = AcpiTbLoadNamespace ();
208e226d1d0SFredrik Holmqvist
209e226d1d0SFredrik Holmqvist    /* Don't let single failures abort the load */
210e226d1d0SFredrik Holmqvist
211e226d1d0SFredrik Holmqvist    if (Status == AE_CTRL_TERMINATE)
212e226d1d0SFredrik Holmqvist    {
213e226d1d0SFredrik Holmqvist        Status = AE_OK;
214e226d1d0SFredrik Holmqvist    }
215e226d1d0SFredrik Holmqvist
2166822cda0SFredrik Holmqvist    if (ACPI_FAILURE (Status))
2176822cda0SFredrik Holmqvist    {
2186822cda0SFredrik Holmqvist        ACPI_EXCEPTION ((AE_INFO, Status,
2196822cda0SFredrik Holmqvist            "While loading namespace from ACPI tables"));
2206822cda0SFredrik Holmqvist    }
2216822cda0SFredrik Holmqvist
22208c9948cSFredrik Holmqvist    if (AcpiGbl_ExecuteTablesAsMethods)
22374ffd18dSFredrik Holmqvist    {
22474ffd18dSFredrik Holmqvist        /*
22508c9948cSFredrik Holmqvist         * If the module-level code support is enabled, initialize the objects
22608c9948cSFredrik Holmqvist         * in the namespace that remain uninitialized. This runs the executable
22708c9948cSFredrik Holmqvist         * AML that may be part of the declaration of these name objects:
22808c9948cSFredrik Holmqvist         *     OperationRegions, BufferFields, Buffers, and Packages.
22908c9948cSFredrik Holmqvist         *
23008c9948cSFredrik Holmqvist         * Note: The module-level code is optional at this time, but will
23108c9948cSFredrik Holmqvist         * become the default in the future.
23274ffd18dSFredrik Holmqvist         */
23374ffd18dSFredrik Holmqvist        Status = AcpiNsInitializeObjects ();
23474ffd18dSFredrik Holmqvist        if (ACPI_FAILURE (Status))
23574ffd18dSFredrik Holmqvist        {
23674ffd18dSFredrik Holmqvist            return_ACPI_STATUS (Status);
23774ffd18dSFredrik Holmqvist        }
23874ffd18dSFredrik Holmqvist    }
23974ffd18dSFredrik Holmqvist
24074ffd18dSFredrik Holmqvist    AcpiGbl_NamespaceInitialized = TRUE;
2416822cda0SFredrik Holmqvist    return_ACPI_STATUS (Status);
2426822cda0SFredrik Holmqvist}
2436822cda0SFredrik Holmqvist
244ad5bbfb8SFredrik HolmqvistACPI_EXPORT_SYMBOL_INIT (AcpiLoadTables)
2456822cda0SFredrik Holmqvist
2466822cda0SFredrik Holmqvist
2476822cda0SFredrik Holmqvist/*******************************************************************************
2486822cda0SFredrik Holmqvist *
2496822cda0SFredrik Holmqvist * FUNCTION:    AcpiTbLoadNamespace
2506822cda0SFredrik Holmqvist *
2516822cda0SFredrik Holmqvist * PARAMETERS:  None
2526822cda0SFredrik Holmqvist *
2536822cda0SFredrik Holmqvist * RETURN:      Status
2546822cda0SFredrik Holmqvist *
2556822cda0SFredrik Holmqvist * DESCRIPTION: Load the namespace from the DSDT and all SSDTs/PSDTs found in
2566822cda0SFredrik Holmqvist *              the RSDT/XSDT.
2576822cda0SFredrik Holmqvist *
2586822cda0SFredrik Holmqvist ******************************************************************************/
2596822cda0SFredrik Holmqvist
260e226d1d0SFredrik HolmqvistACPI_STATUS
2616822cda0SFredrik HolmqvistAcpiTbLoadNamespace (
2626822cda0SFredrik Holmqvist    void)
2636822cda0SFredrik Holmqvist{
2646822cda0SFredrik Holmqvist    ACPI_STATUS             Status;
2656822cda0SFredrik Holmqvist    UINT32                  i;
2666822cda0SFredrik Holmqvist    ACPI_TABLE_HEADER       *NewDsdt;
267e226d1d0SFredrik Holmqvist    ACPI_TABLE_DESC         *Table;
268e226d1d0SFredrik Holmqvist    UINT32                  TablesLoaded = 0;
269e226d1d0SFredrik Holmqvist    UINT32                  TablesFailed = 0;
2706822cda0SFredrik Holmqvist
2716822cda0SFredrik Holmqvist
2726822cda0SFredrik Holmqvist    ACPI_FUNCTION_TRACE (TbLoadNamespace);
2736822cda0SFredrik Holmqvist
2746822cda0SFredrik Holmqvist
2756822cda0SFredrik Holmqvist    (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
2766822cda0SFredrik Holmqvist
2776822cda0SFredrik Holmqvist    /*
2786822cda0SFredrik Holmqvist     * Load the namespace. The DSDT is required, but any SSDT and
2796822cda0SFredrik Holmqvist     * PSDT tables are optional. Verify the DSDT.
2806822cda0SFredrik Holmqvist     */
281e226d1d0SFredrik Holmqvist    Table = &AcpiGbl_RootTableList.Tables[AcpiGbl_DsdtIndex];
282e226d1d0SFredrik Holmqvist
2836822cda0SFredrik Holmqvist    if (!AcpiGbl_RootTableList.CurrentTableCount ||
284e226d1d0SFredrik Holmqvist        !ACPI_COMPARE_NAME (Table->Signature.Ascii, ACPI_SIG_DSDT) ||
285e226d1d0SFredrik Holmqvist         ACPI_FAILURE (AcpiTbValidateTable (Table)))
2866822cda0SFredrik Holmqvist    {
2876822cda0SFredrik Holmqvist        Status = AE_NO_ACPI_TABLES;
2886822cda0SFredrik Holmqvist        goto UnlockAndExit;
2896822cda0SFredrik Holmqvist    }
2906822cda0SFredrik Holmqvist
2916822cda0SFredrik Holmqvist    /*
2926822cda0SFredrik Holmqvist     * Save the DSDT pointer for simple access. This is the mapped memory
2936822cda0SFredrik Holmqvist     * address. We must take care here because the address of the .Tables
2946822cda0SFredrik Holmqvist     * array can change dynamically as tables are loaded at run-time. Note:
295ad5bbfb8SFredrik Holmqvist     * .Pointer field is not validated until after call to AcpiTbValidateTable.
2966822cda0SFredrik Holmqvist     */
297e226d1d0SFredrik Holmqvist    AcpiGbl_DSDT = Table->Pointer;
2986822cda0SFredrik Holmqvist
2996822cda0SFredrik Holmqvist    /*
3006822cda0SFredrik Holmqvist     * Optionally copy the entire DSDT to local memory (instead of simply
3016822cda0SFredrik Holmqvist     * mapping it.) There are some BIOSs that corrupt or replace the original
3026822cda0SFredrik Holmqvist     * DSDT, creating the need for this option. Default is FALSE, do not copy
3036822cda0SFredrik Holmqvist     * the DSDT.
3046822cda0SFredrik Holmqvist     */
3056822cda0SFredrik Holmqvist    if (AcpiGbl_CopyDsdtLocally)
3066822cda0SFredrik Holmqvist    {
307e226d1d0SFredrik Holmqvist        NewDsdt = AcpiTbCopyDsdt (AcpiGbl_DsdtIndex);
3086822cda0SFredrik Holmqvist        if (NewDsdt)
3096822cda0SFredrik Holmqvist        {
3106822cda0SFredrik Holmqvist            AcpiGbl_DSDT = NewDsdt;
3116822cda0SFredrik Holmqvist        }
3126822cda0SFredrik Holmqvist    }
3136822cda0SFredrik Holmqvist
3146822cda0SFredrik Holmqvist    /*
3156822cda0SFredrik Holmqvist     * Save the original DSDT header for detection of table corruption
3166822cda0SFredrik Holmqvist     * and/or replacement of the DSDT from outside the OS.
3176822cda0SFredrik Holmqvist     */
318e226d1d0SFredrik Holmqvist    memcpy (&AcpiGbl_OriginalDsdtHeader, AcpiGbl_DSDT,
3196822cda0SFredrik Holmqvist        sizeof (ACPI_TABLE_HEADER));
3206822cda0SFredrik Holmqvist
3216822cda0SFredrik Holmqvist    /* Load and parse tables */
3226822cda0SFredrik Holmqvist
323ff2e2f81SFredrik Holmqvist    (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
324e226d1d0SFredrik Holmqvist    Status = AcpiNsLoadTable (AcpiGbl_DsdtIndex, AcpiGbl_RootNode);
325ff2e2f81SFredrik Holmqvist    (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
3266822cda0SFredrik Holmqvist    if (ACPI_FAILURE (Status))
3276822cda0SFredrik Holmqvist    {
328e226d1d0SFredrik Holmqvist        ACPI_EXCEPTION ((AE_INFO, Status, "[DSDT] table load failed"));
329e226d1d0SFredrik Holmqvist        TablesFailed++;
330e226d1d0SFredrik Holmqvist    }
331e226d1d0SFredrik Holmqvist    else
332e226d1d0SFredrik Holmqvist    {
333e226d1d0SFredrik Holmqvist        TablesLoaded++;
3346822cda0SFredrik Holmqvist    }
3356822cda0SFredrik Holmqvist
3366822cda0SFredrik Holmqvist    /* Load any SSDT or PSDT tables. Note: Loop leaves tables locked */
3376822cda0SFredrik Holmqvist
3386822cda0SFredrik Holmqvist    for (i = 0; i < AcpiGbl_RootTableList.CurrentTableCount; ++i)
3396822cda0SFredrik Holmqvist    {
340e226d1d0SFredrik Holmqvist        Table = &AcpiGbl_RootTableList.Tables[i];
341e226d1d0SFredrik Holmqvist
342ff2e2f81SFredrik Holmqvist        if (!Table->Address ||
343e226d1d0SFredrik Holmqvist            (!ACPI_COMPARE_NAME (Table->Signature.Ascii, ACPI_SIG_SSDT) &&
344e226d1d0SFredrik Holmqvist             !ACPI_COMPARE_NAME (Table->Signature.Ascii, ACPI_SIG_PSDT) &&
345e226d1d0SFredrik Holmqvist             !ACPI_COMPARE_NAME (Table->Signature.Ascii, ACPI_SIG_OSDT)) ||
346ff2e2f81SFredrik Holmqvist            ACPI_FAILURE (AcpiTbValidateTable (Table)))
3476822cda0SFredrik Holmqvist        {
3486822cda0SFredrik Holmqvist            continue;
3496822cda0SFredrik Holmqvist        }
3506822cda0SFredrik Holmqvist
3516822cda0SFredrik Holmqvist        /* Ignore errors while loading tables, get as many as possible */
3526822cda0SFredrik Holmqvist
3536822cda0SFredrik Holmqvist        (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
354e226d1d0SFredrik Holmqvist        Status =  AcpiNsLoadTable (i, AcpiGbl_RootNode);
355ff2e2f81SFredrik Holmqvist        (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
356e226d1d0SFredrik Holmqvist        if (ACPI_FAILURE (Status))
357e226d1d0SFredrik Holmqvist        {
358e226d1d0SFredrik Holmqvist            ACPI_EXCEPTION ((AE_INFO, Status, "(%4.4s:%8.8s) while loading table",
359e226d1d0SFredrik Holmqvist                Table->Signature.Ascii, Table->Pointer->OemTableId));
360b64e8511SFredrik Holmqvist
361e226d1d0SFredrik Holmqvist            TablesFailed++;
362e226d1d0SFredrik Holmqvist
363e226d1d0SFredrik Holmqvist            ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT,
364e226d1d0SFredrik Holmqvist                "Table [%4.4s:%8.8s] (id FF) - Table namespace load failed\n\n",
365e226d1d0SFredrik Holmqvist                Table->Signature.Ascii, Table->Pointer->OemTableId));
366e226d1d0SFredrik Holmqvist        }
367e226d1d0SFredrik Holmqvist        else
368e226d1d0SFredrik Holmqvist        {
369e226d1d0SFredrik Holmqvist            TablesLoaded++;
370e226d1d0SFredrik Holmqvist        }
3716822cda0SFredrik Holmqvist    }
3726822cda0SFredrik Holmqvist
373e226d1d0SFredrik Holmqvist    if (!TablesFailed)
374e226d1d0SFredrik Holmqvist    {
37574ffd18dSFredrik Holmqvist        ACPI_INFO ((
376ff2e2f81SFredrik Holmqvist            "%u ACPI AML tables successfully acquired and loaded",
377e226d1d0SFredrik Holmqvist            TablesLoaded));
378e226d1d0SFredrik Holmqvist    }
379e226d1d0SFredrik Holmqvist    else
380e226d1d0SFredrik Holmqvist    {
381e226d1d0SFredrik Holmqvist        ACPI_ERROR ((AE_INFO,
382e226d1d0SFredrik Holmqvist            "%u table load failures, %u successful",
383e226d1d0SFredrik Holmqvist            TablesFailed, TablesLoaded));
384e226d1d0SFredrik Holmqvist
385e226d1d0SFredrik Holmqvist        /* Indicate at least one failure */
386e226d1d0SFredrik Holmqvist
387e226d1d0SFredrik Holmqvist        Status = AE_CTRL_TERMINATE;
388e226d1d0SFredrik Holmqvist    }
3896822cda0SFredrik Holmqvist
390ff2e2f81SFredrik Holmqvist#ifdef ACPI_APPLICATION
391ff2e2f81SFredrik Holmqvist    ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT, "\n"));
392ff2e2f81SFredrik Holmqvist#endif
393ff2e2f81SFredrik Holmqvist
394ff2e2f81SFredrik Holmqvist
3956822cda0SFredrik HolmqvistUnlockAndExit:
3966822cda0SFredrik Holmqvist    (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
3976822cda0SFredrik Holmqvist    return_ACPI_STATUS (Status);
3986822cda0SFredrik Holmqvist}
3996822cda0SFredrik Holmqvist
4006822cda0SFredrik Holmqvist
401ad5bbfb8SFredrik Holmqvist/*******************************************************************************
402ad5bbfb8SFredrik Holmqvist *
403ad5bbfb8SFredrik Holmqvist * FUNCTION:    AcpiInstallTable
404ad5bbfb8SFredrik Holmqvist *
405ad5bbfb8SFredrik Holmqvist * PARAMETERS:  Address             - Address of the ACPI table to be installed.
406ad5bbfb8SFredrik Holmqvist *              Physical            - Whether the address is a physical table
407ad5bbfb8SFredrik Holmqvist *                                    address or not
408ad5bbfb8SFredrik Holmqvist *
409ad5bbfb8SFredrik Holmqvist * RETURN:      Status
410ad5bbfb8SFredrik Holmqvist *
411ad5bbfb8SFredrik Holmqvist * DESCRIPTION: Dynamically install an ACPI table.
412ad5bbfb8SFredrik Holmqvist *              Note: This function should only be invoked after
413ad5bbfb8SFredrik Holmqvist *                    AcpiInitializeTables() and before AcpiLoadTables().
414ad5bbfb8SFredrik Holmqvist *
415ad5bbfb8SFredrik Holmqvist ******************************************************************************/
416ad5bbfb8SFredrik Holmqvist
41774ffd18dSFredrik HolmqvistACPI_STATUS ACPI_INIT_FUNCTION
418ad5bbfb8SFredrik HolmqvistAcpiInstallTable (
419ad5bbfb8SFredrik Holmqvist    ACPI_PHYSICAL_ADDRESS   Address,
420ad5bbfb8SFredrik Holmqvist    BOOLEAN                 Physical)
421ad5bbfb8SFredrik Holmqvist{
422ad5bbfb8SFredrik Holmqvist    ACPI_STATUS             Status;
423ad5bbfb8SFredrik Holmqvist    UINT8                   Flags;
424ad5bbfb8SFredrik Holmqvist    UINT32                  TableIndex;
425ad5bbfb8SFredrik Holmqvist
426ad5bbfb8SFredrik Holmqvist
427ad5bbfb8SFredrik Holmqvist    ACPI_FUNCTION_TRACE (AcpiInstallTable);
428ad5bbfb8SFredrik Holmqvist
429ad5bbfb8SFredrik Holmqvist
430ad5bbfb8SFredrik Holmqvist    if (Physical)
431ad5bbfb8SFredrik Holmqvist    {
432e226d1d0SFredrik Holmqvist        Flags = ACPI_TABLE_ORIGIN_INTERNAL_PHYSICAL;
433ad5bbfb8SFredrik Holmqvist    }
434ad5bbfb8SFredrik Holmqvist    else
435ad5bbfb8SFredrik Holmqvist    {
436e226d1d0SFredrik Holmqvist        Flags = ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL;
437ad5bbfb8SFredrik Holmqvist    }
438ad5bbfb8SFredrik Holmqvist
439ad5bbfb8SFredrik Holmqvist    Status = AcpiTbInstallStandardTable (Address, Flags,
440ad5bbfb8SFredrik Holmqvist        FALSE, FALSE, &TableIndex);
441ad5bbfb8SFredrik Holmqvist
442ad5bbfb8SFredrik Holmqvist    return_ACPI_STATUS (Status);
443ad5bbfb8SFredrik Holmqvist}
444ad5bbfb8SFredrik Holmqvist
445ad5bbfb8SFredrik HolmqvistACPI_EXPORT_SYMBOL_INIT (AcpiInstallTable)
446ad5bbfb8SFredrik Holmqvist
447ad5bbfb8SFredrik Holmqvist
4486822cda0SFredrik Holmqvist/*******************************************************************************
4496822cda0SFredrik Holmqvist *
4506822cda0SFredrik Holmqvist * FUNCTION:    AcpiLoadTable
4516822cda0SFredrik Holmqvist *
4526822cda0SFredrik Holmqvist * PARAMETERS:  Table               - Pointer to a buffer containing the ACPI
4536822cda0SFredrik Holmqvist *                                    table to be loaded.
4546822cda0SFredrik Holmqvist *
4556822cda0SFredrik Holmqvist * RETURN:      Status
4566822cda0SFredrik Holmqvist *
4576822cda0SFredrik Holmqvist * DESCRIPTION: Dynamically load an ACPI table from the caller's buffer. Must
4586822cda0SFredrik Holmqvist *              be a valid ACPI table with a valid ACPI table header.
4596822cda0SFredrik Holmqvist *              Note1: Mainly intended to support hotplug addition of SSDTs.
4609b0d045cSFredrik Holmqvist *              Note2: Does not copy the incoming table. User is responsible
4616822cda0SFredrik Holmqvist *              to ensure that the table is not deleted or unmapped.
4626822cda0SFredrik Holmqvist *
4636822cda0SFredrik Holmqvist ******************************************************************************/
4646822cda0SFredrik Holmqvist
4656822cda0SFredrik HolmqvistACPI_STATUS
4666822cda0SFredrik HolmqvistAcpiLoadTable (
4676822cda0SFredrik Holmqvist    ACPI_TABLE_HEADER       *Table)
4686822cda0SFredrik Holmqvist{
4696822cda0SFredrik Holmqvist    ACPI_STATUS             Status;
4706822cda0SFredrik Holmqvist    UINT32                  TableIndex;
4716822cda0SFredrik Holmqvist
4726822cda0SFredrik Holmqvist
4736822cda0SFredrik Holmqvist    ACPI_FUNCTION_TRACE (AcpiLoadTable);
4746822cda0SFredrik Holmqvist
4756822cda0SFredrik Holmqvist
4766822cda0SFredrik Holmqvist    /* Parameter validation */
4776822cda0SFredrik Holmqvist
4786822cda0SFredrik Holmqvist    if (!Table)
4796822cda0SFredrik Holmqvist    {
4806822cda0SFredrik Holmqvist        return_ACPI_STATUS (AE_BAD_PARAMETER);
4816822cda0SFredrik Holmqvist    }
4826822cda0SFredrik Holmqvist
4836822cda0SFredrik Holmqvist    /* Install the table and load it into the namespace */
4846822cda0SFredrik Holmqvist
48574ffd18dSFredrik Holmqvist    ACPI_INFO (("Host-directed Dynamic ACPI Table Load:"));
486ff2e2f81SFredrik Holmqvist    Status = AcpiTbInstallAndLoadTable (ACPI_PTR_TO_PHYSADDR (Table),
487ff2e2f81SFredrik Holmqvist        ACPI_TABLE_ORIGIN_EXTERNAL_VIRTUAL, FALSE, &TableIndex);
4886822cda0SFredrik Holmqvist    return_ACPI_STATUS (Status);
4896822cda0SFredrik Holmqvist}
4906822cda0SFredrik Holmqvist
4916822cda0SFredrik HolmqvistACPI_EXPORT_SYMBOL (AcpiLoadTable)
4926822cda0SFredrik Holmqvist
4936822cda0SFredrik Holmqvist
4946822cda0SFredrik Holmqvist/*******************************************************************************
4956822cda0SFredrik Holmqvist *
4966822cda0SFredrik Holmqvist * FUNCTION:    AcpiUnloadParentTable
4976822cda0SFredrik Holmqvist *
4986822cda0SFredrik Holmqvist * PARAMETERS:  Object              - Handle to any namespace object owned by
4996822cda0SFredrik Holmqvist *                                    the table to be unloaded
5006822cda0SFredrik Holmqvist *
5016822cda0SFredrik Holmqvist * RETURN:      Status
5026822cda0SFredrik Holmqvist *
5036822cda0SFredrik Holmqvist * DESCRIPTION: Via any namespace object within an SSDT or OEMx table, unloads
5046822cda0SFredrik Holmqvist *              the table and deletes all namespace objects associated with
5056822cda0SFredrik Holmqvist *              that table. Unloading of the DSDT is not allowed.
5066822cda0SFredrik Holmqvist *              Note: Mainly intended to support hotplug removal of SSDTs.
5076822cda0SFredrik Holmqvist *
5086822cda0SFredrik Holmqvist ******************************************************************************/
5096822cda0SFredrik Holmqvist
5106822cda0SFredrik HolmqvistACPI_STATUS
5116822cda0SFredrik HolmqvistAcpiUnloadParentTable (
5126822cda0SFredrik Holmqvist    ACPI_HANDLE             Object)
5136822cda0SFredrik Holmqvist{
5146822cda0SFredrik Holmqvist    ACPI_NAMESPACE_NODE     *Node = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, Object);
5156822cda0SFredrik Holmqvist    ACPI_STATUS             Status = AE_NOT_EXIST;
5166822cda0SFredrik Holmqvist    ACPI_OWNER_ID           OwnerId;
5176822cda0SFredrik Holmqvist    UINT32                  i;
5186822cda0SFredrik Holmqvist
5196822cda0SFredrik Holmqvist
5206822cda0SFredrik Holmqvist    ACPI_FUNCTION_TRACE (AcpiUnloadParentTable);
5216822cda0SFredrik Holmqvist
5226822cda0SFredrik Holmqvist
5236822cda0SFredrik Holmqvist    /* Parameter validation */
5246822cda0SFredrik Holmqvist
5256822cda0SFredrik Holmqvist    if (!Object)
5266822cda0SFredrik Holmqvist    {
5276822cda0SFredrik Holmqvist        return_ACPI_STATUS (AE_BAD_PARAMETER);
5286822cda0SFredrik Holmqvist    }
5296822cda0SFredrik Holmqvist
5306822cda0SFredrik Holmqvist    /*
5316822cda0SFredrik Holmqvist     * The node OwnerId is currently the same as the parent table ID.
5326822cda0SFredrik Holmqvist     * However, this could change in the future.
5336822cda0SFredrik Holmqvist     */
5346822cda0SFredrik Holmqvist    OwnerId = Node->OwnerId;
5356822cda0SFredrik Holmqvist    if (!OwnerId)
5366822cda0SFredrik Holmqvist    {
5376822cda0SFredrik Holmqvist        /* OwnerId==0 means DSDT is the owner. DSDT cannot be unloaded */
5386822cda0SFredrik Holmqvist
5396822cda0SFredrik Holmqvist        return_ACPI_STATUS (AE_TYPE);
5406822cda0SFredrik Holmqvist    }
5416822cda0SFredrik Holmqvist
542ff2e2f81SFredrik Holmqvist    /* Must acquire the table lock during this operation */
5436822cda0SFredrik Holmqvist
544ff2e2f81SFredrik Holmqvist    Status = AcpiUtAcquireMutex (ACPI_MTX_TABLES);
5456822cda0SFredrik Holmqvist    if (ACPI_FAILURE (Status))
5466822cda0SFredrik Holmqvist    {
5476822cda0SFredrik Holmqvist        return_ACPI_STATUS (Status);
5486822cda0SFredrik Holmqvist    }
5496822cda0SFredrik Holmqvist
5506822cda0SFredrik Holmqvist    /* Find the table in the global table list */
5516822cda0SFredrik Holmqvist
5526822cda0SFredrik Holmqvist    for (i = 0; i < AcpiGbl_RootTableList.CurrentTableCount; i++)
5536822cda0SFredrik Holmqvist    {
5546822cda0SFredrik Holmqvist        if (OwnerId != AcpiGbl_RootTableList.Tables[i].OwnerId)
5556822cda0SFredrik Holmqvist        {
5566822cda0SFredrik Holmqvist            continue;
5576822cda0SFredrik Holmqvist        }
5586822cda0SFredrik Holmqvist
5596822cda0SFredrik Holmqvist        /*
5606822cda0SFredrik Holmqvist         * Allow unload of SSDT and OEMx tables only. Do not allow unload
5616822cda0SFredrik Holmqvist         * of the DSDT. No other types of tables should get here, since
5626822cda0SFredrik Holmqvist         * only these types can contain AML and thus are the only types
5636822cda0SFredrik Holmqvist         * that can create namespace objects.
5646822cda0SFredrik Holmqvist         */
5656822cda0SFredrik Holmqvist        if (ACPI_COMPARE_NAME (
566b64e8511SFredrik Holmqvist                AcpiGbl_RootTableList.Tables[i].Signature.Ascii,
567b64e8511SFredrik Holmqvist                ACPI_SIG_DSDT))
5686822cda0SFredrik Holmqvist        {
5696822cda0SFredrik Holmqvist            Status = AE_TYPE;
5706822cda0SFredrik Holmqvist            break;
5716822cda0SFredrik Holmqvist        }
5726822cda0SFredrik Holmqvist
573ff2e2f81SFredrik Holmqvist        (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
574ff2e2f81SFredrik Holmqvist        Status = AcpiTbUnloadTable (i);
575ff2e2f81SFredrik Holmqvist        (void) AcpiUtAcquireMutex (ACPI_MTX_TABLES);
5766822cda0SFredrik Holmqvist        break;
5776822cda0SFredrik Holmqvist    }
5786822cda0SFredrik Holmqvist
579ff2e2f81SFredrik Holmqvist    (void) AcpiUtReleaseMutex (ACPI_MTX_TABLES);
5806822cda0SFredrik Holmqvist    return_ACPI_STATUS (Status);
5816822cda0SFredrik Holmqvist}
5826822cda0SFredrik Holmqvist
5836822cda0SFredrik HolmqvistACPI_EXPORT_SYMBOL (AcpiUnloadParentTable)
584