1ddbd7b91SNathan Whitehorn/******************************************************************************
2ddbd7b91SNathan Whitehorn *
3ddbd7b91SNathan Whitehorn * Module Name: exconfig - Namespace reconfiguration (Load/Unload opcodes)
4ddbd7b91SNathan Whitehorn *
5ddbd7b91SNathan Whitehorn *****************************************************************************/
6ddbd7b91SNathan Whitehorn
7ddbd7b91SNathan Whitehorn/******************************************************************************
8ddbd7b91SNathan Whitehorn *
9ddbd7b91SNathan Whitehorn * 1. Copyright Notice
10ddbd7b91SNathan Whitehorn *
11ff2e2f81SFredrik Holmqvist * Some or all of this work - Copyright (c) 1999 - 2018, Intel Corp.
12ddbd7b91SNathan Whitehorn * All rights reserved.
13ddbd7b91SNathan Whitehorn *
14ddbd7b91SNathan Whitehorn * 2. License
15ddbd7b91SNathan Whitehorn *
16ddbd7b91SNathan Whitehorn * 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
18ddbd7b91SNathan Whitehorn * you this software, covering your right to use that party's intellectual
19ddbd7b91SNathan Whitehorn * property rights.
20ddbd7b91SNathan Whitehorn *
21ddbd7b91SNathan Whitehorn * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22ddbd7b91SNathan Whitehorn * copy of the source code appearing in this file ("Covered Code") an
23ddbd7b91SNathan Whitehorn * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24ddbd7b91SNathan Whitehorn * base code distributed originally by Intel ("Original Intel Code") to copy,
25ddbd7b91SNathan Whitehorn * make derivatives, distribute, use and display any portion of the Covered
26ddbd7b91SNathan Whitehorn * Code in any form, with the right to sublicense such rights; and
27ddbd7b91SNathan Whitehorn *
28ddbd7b91SNathan Whitehorn * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29ddbd7b91SNathan Whitehorn * license (with the right to sublicense), under only those claims of Intel
30ddbd7b91SNathan Whitehorn * patents that are infringed by the Original Intel Code, to make, use, sell,
31ddbd7b91SNathan Whitehorn * offer to sell, and import the Covered Code and derivative works thereof
32ddbd7b91SNathan Whitehorn * solely to the minimum extent necessary to exercise the above copyright
33ddbd7b91SNathan Whitehorn * 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
35ddbd7b91SNathan Whitehorn * is granted directly or by implication, estoppel or otherwise;
36ddbd7b91SNathan Whitehorn *
37ddbd7b91SNathan Whitehorn * The above copyright and patent license is granted only if the following
38ddbd7b91SNathan Whitehorn * conditions are met:
39ddbd7b91SNathan Whitehorn *
40ddbd7b91SNathan Whitehorn * 3. Conditions
41ddbd7b91SNathan Whitehorn *
42ddbd7b91SNathan Whitehorn * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43ddbd7b91SNathan Whitehorn * Redistribution of source code of any substantial portion of the Covered
44ddbd7b91SNathan Whitehorn * Code or modification with rights to further distribute source must include
45ddbd7b91SNathan Whitehorn * the above Copyright Notice, the above License, this list of Conditions,
469b0d045cSFredrik Holmqvist * and the following Disclaimer and Export Compliance provision. In addition,
47ddbd7b91SNathan Whitehorn * Licensee must cause all Covered Code to which Licensee contributes to
48ddbd7b91SNathan Whitehorn * 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
51ddbd7b91SNathan Whitehorn * must include a prominent statement that the modification is derived,
52ddbd7b91SNathan Whitehorn * directly or indirectly, from Original Intel Code.
53ddbd7b91SNathan Whitehorn *
54ddbd7b91SNathan Whitehorn * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55ddbd7b91SNathan Whitehorn * Redistribution of source code of any substantial portion of the Covered
56ddbd7b91SNathan Whitehorn * Code or modification without rights to further distribute source must
57ddbd7b91SNathan Whitehorn * include the following Disclaimer and Export Compliance provision in the
589b0d045cSFredrik Holmqvist * documentation and/or other materials provided with distribution. In
59ddbd7b91SNathan Whitehorn * addition, Licensee may not authorize further sublicense of source of any
60ddbd7b91SNathan Whitehorn * portion of the Covered Code, and must include terms to the effect that the
61ddbd7b91SNathan Whitehorn * license from Licensee to its licensee is limited to the intellectual
62ddbd7b91SNathan Whitehorn * property embodied in the software Licensee provides to its licensee, and
63ddbd7b91SNathan Whitehorn * not to intellectual property embodied in modifications its licensee may
64ddbd7b91SNathan Whitehorn * make.
65ddbd7b91SNathan Whitehorn *
66ddbd7b91SNathan Whitehorn * 3.3. Redistribution of Executable. Redistribution in executable form of any
67ddbd7b91SNathan Whitehorn * substantial portion of the Covered Code or modification must reproduce the
68ddbd7b91SNathan Whitehorn * above Copyright Notice, and the following Disclaimer and Export Compliance
69ddbd7b91SNathan Whitehorn * provision in the documentation and/or other materials provided with the
70ddbd7b91SNathan Whitehorn * distribution.
71ddbd7b91SNathan Whitehorn *
72ddbd7b91SNathan Whitehorn * 3.4. Intel retains all right, title, and interest in and to the Original
73ddbd7b91SNathan Whitehorn * Intel Code.
74ddbd7b91SNathan Whitehorn *
75ddbd7b91SNathan Whitehorn * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76ddbd7b91SNathan Whitehorn * Intel shall be used in advertising or otherwise to promote the sale, use or
77ddbd7b91SNathan Whitehorn * other dealings in products derived from or relating to the Covered Code
78ddbd7b91SNathan Whitehorn * without prior written authorization from Intel.
79ddbd7b91SNathan Whitehorn *
80ddbd7b91SNathan Whitehorn * 4. Disclaimer and Export Compliance
81ddbd7b91SNathan Whitehorn *
82ddbd7b91SNathan Whitehorn * 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
86ddbd7b91SNathan Whitehorn
879b0d045cSFredrik Holmqvist * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
88ddbd7b91SNathan Whitehorn * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
89ddbd7b91SNathan Whitehorn * PARTICULAR PURPOSE.
90ddbd7b91SNathan Whitehorn *
91ddbd7b91SNathan Whitehorn * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
92ddbd7b91SNathan Whitehorn * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
93ddbd7b91SNathan Whitehorn * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
94ddbd7b91SNathan Whitehorn * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
95ddbd7b91SNathan Whitehorn * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
969b0d045cSFredrik Holmqvist * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
97ddbd7b91SNathan Whitehorn * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
98ddbd7b91SNathan Whitehorn * LIMITED REMEDY.
99ddbd7b91SNathan Whitehorn *
100ddbd7b91SNathan Whitehorn * 4.3. Licensee shall not export, either directly or indirectly, any of this
101ddbd7b91SNathan Whitehorn * software or system incorporating such software without first obtaining any
102ddbd7b91SNathan Whitehorn * required license or other approval from the U. S. Department of Commerce or
1039b0d045cSFredrik Holmqvist * any other agency or department of the United States Government. In the
104ddbd7b91SNathan Whitehorn * event Licensee exports any such software from the United States or
105ddbd7b91SNathan Whitehorn * re-exports any such software from a foreign destination, Licensee shall
106ddbd7b91SNathan Whitehorn * ensure that the distribution and export/re-export of the software is in
107ddbd7b91SNathan Whitehorn * compliance with all laws, regulations, orders, or other restrictions of the
108ddbd7b91SNathan Whitehorn * U.S. Export Administration Regulations. Licensee agrees that neither it nor
109ddbd7b91SNathan Whitehorn * any of its subsidiaries will export/re-export any technical data, process,
110ddbd7b91SNathan Whitehorn * software, or service, directly or indirectly, to any country for which the
111ddbd7b91SNathan Whitehorn * United States government or any agency thereof requires an export license,
112ddbd7b91SNathan Whitehorn * other governmental approval, or letter of assurance, without first obtaining
113ddbd7b91SNathan Whitehorn * such license, approval or letter.
114ddbd7b91SNathan Whitehorn *
115ff2e2f81SFredrik Holmqvist *****************************************************************************
116ff2e2f81SFredrik Holmqvist *
117ff2e2f81SFredrik Holmqvist * Alternatively, you may choose to be licensed under the terms of the
118ff2e2f81SFredrik Holmqvist * following license:
119ff2e2f81SFredrik Holmqvist *
120ff2e2f81SFredrik Holmqvist * Redistribution and use in source and binary forms, with or without
121ff2e2f81SFredrik Holmqvist * modification, are permitted provided that the following conditions
122ff2e2f81SFredrik Holmqvist * are met:
123ff2e2f81SFredrik Holmqvist * 1. Redistributions of source code must retain the above copyright
124ff2e2f81SFredrik Holmqvist *    notice, this list of conditions, and the following disclaimer,
125ff2e2f81SFredrik Holmqvist *    without modification.
126ff2e2f81SFredrik Holmqvist * 2. Redistributions in binary form must reproduce at minimum a disclaimer
127ff2e2f81SFredrik Holmqvist *    substantially similar to the "NO WARRANTY" disclaimer below
128ff2e2f81SFredrik Holmqvist *    ("Disclaimer") and any redistribution must be conditioned upon
129ff2e2f81SFredrik Holmqvist *    including a substantially similar Disclaimer requirement for further
130ff2e2f81SFredrik Holmqvist *    binary redistribution.
131ff2e2f81SFredrik Holmqvist * 3. Neither the names of the above-listed copyright holders nor the names
132ff2e2f81SFredrik Holmqvist *    of any contributors may be used to endorse or promote products derived
133ff2e2f81SFredrik Holmqvist *    from this software without specific prior written permission.
134ff2e2f81SFredrik Holmqvist *
135ff2e2f81SFredrik Holmqvist * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
136ff2e2f81SFredrik Holmqvist * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
137ff2e2f81SFredrik Holmqvist * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
138ff2e2f81SFredrik Holmqvist * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
139ff2e2f81SFredrik Holmqvist * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
140ff2e2f81SFredrik Holmqvist * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
141ff2e2f81SFredrik Holmqvist * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
142ff2e2f81SFredrik Holmqvist * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
143ff2e2f81SFredrik Holmqvist * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
144ff2e2f81SFredrik Holmqvist * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
145ff2e2f81SFredrik Holmqvist * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
146ff2e2f81SFredrik Holmqvist *
147ff2e2f81SFredrik Holmqvist * Alternatively, you may choose to be licensed under the terms of the
148ff2e2f81SFredrik Holmqvist * GNU General Public License ("GPL") version 2 as published by the Free
149ff2e2f81SFredrik Holmqvist * Software Foundation.
150ff2e2f81SFredrik Holmqvist *
151ddbd7b91SNathan Whitehorn *****************************************************************************/
152ddbd7b91SNathan Whitehorn
153ddbd7b91SNathan Whitehorn#include "acpi.h"
15480377d9aSJérôme Duval#include "accommon.h"
155ddbd7b91SNathan Whitehorn#include "acinterp.h"
156ddbd7b91SNathan Whitehorn#include "acnamesp.h"
157ddbd7b91SNathan Whitehorn#include "actables.h"
158ddbd7b91SNathan Whitehorn#include "acdispat.h"
15980377d9aSJérôme Duval#include "acevents.h"
160c70258b7SJérôme Duval#include "amlcode.h"
161ddbd7b91SNathan Whitehorn
162ddbd7b91SNathan Whitehorn
163ddbd7b91SNathan Whitehorn#define _COMPONENT          ACPI_EXECUTER
164ddbd7b91SNathan Whitehorn        ACPI_MODULE_NAME    ("exconfig")
165ddbd7b91SNathan Whitehorn
16643547dbeSJérôme Duval/* Local prototypes */
16743547dbeSJérôme Duval
16843547dbeSJérôme Duvalstatic ACPI_STATUS
16943547dbeSJérôme DuvalAcpiExAddTable (
17045e9de08SJérôme Duval    UINT32                  TableIndex,
17143547dbeSJérôme Duval    ACPI_OPERAND_OBJECT     **DdbHandle);
17243547dbeSJérôme Duval
17380377d9aSJérôme Duvalstatic ACPI_STATUS
17480377d9aSJérôme DuvalAcpiExRegionRead (
17580377d9aSJérôme Duval    ACPI_OPERAND_OBJECT     *ObjDesc,
17680377d9aSJérôme Duval    UINT32                  Length,
17780377d9aSJérôme Duval    UINT8                   *Buffer);
17880377d9aSJérôme Duval
179ddbd7b91SNathan Whitehorn
180ddbd7b91SNathan Whitehorn/*******************************************************************************
181ddbd7b91SNathan Whitehorn *
182ddbd7b91SNathan Whitehorn * FUNCTION:    AcpiExAddTable
183ddbd7b91SNathan Whitehorn *
184ddbd7b91SNathan Whitehorn * PARAMETERS:  Table               - Pointer to raw table
185ddbd7b91SNathan Whitehorn *              ParentNode          - Where to load the table (scope)
186ddbd7b91SNathan Whitehorn *              DdbHandle           - Where to return the table handle.
187ddbd7b91SNathan Whitehorn *
188ddbd7b91SNathan Whitehorn * RETURN:      Status
189ddbd7b91SNathan Whitehorn *
190ddbd7b91SNathan Whitehorn * DESCRIPTION: Common function to Install and Load an ACPI table with a
191ddbd7b91SNathan Whitehorn *              returned table handle.
192ddbd7b91SNathan Whitehorn *
193ddbd7b91SNathan Whitehorn ******************************************************************************/
194ddbd7b91SNathan Whitehorn
19543547dbeSJérôme Duvalstatic ACPI_STATUS
196ddbd7b91SNathan WhitehornAcpiExAddTable (
19745e9de08SJérôme Duval    UINT32                  TableIndex,
198ddbd7b91SNathan Whitehorn    ACPI_OPERAND_OBJECT     **DdbHandle)
199ddbd7b91SNathan Whitehorn{
200ddbd7b91SNathan Whitehorn    ACPI_OPERAND_OBJECT     *ObjDesc;
201ddbd7b91SNathan Whitehorn
202ddbd7b91SNathan Whitehorn
20343547dbeSJérôme Duval    ACPI_FUNCTION_TRACE (ExAddTable);
204ddbd7b91SNathan Whitehorn
205ddbd7b91SNathan Whitehorn
206ddbd7b91SNathan Whitehorn    /* Create an object to be the table handle */
207ddbd7b91SNathan Whitehorn
208ddbd7b91SNathan Whitehorn    ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_LOCAL_REFERENCE);
209ddbd7b91SNathan Whitehorn    if (!ObjDesc)
210ddbd7b91SNathan Whitehorn    {
211ddbd7b91SNathan Whitehorn        return_ACPI_STATUS (AE_NO_MEMORY);
212ddbd7b91SNathan Whitehorn    }
213ddbd7b91SNathan Whitehorn
21443547dbeSJérôme Duval    /* Init the table handle */
21543547dbeSJérôme Duval
21680377d9aSJérôme Duval    ObjDesc->Common.Flags |= AOPOBJ_DATA_VALID;
21780377d9aSJérôme Duval    ObjDesc->Reference.Class = ACPI_REFCLASS_TABLE;
2183f04c835SFredrik Holmqvist    ObjDesc->Reference.Value = TableIndex;
219ff2e2f81SFredrik Holmqvist    *DdbHandle = ObjDesc;
220ffb873afSFredrik Holmqvist    return_ACPI_STATUS (AE_OK);
221ddbd7b91SNathan Whitehorn}
222ddbd7b91SNathan Whitehorn
223ddbd7b91SNathan Whitehorn
224ddbd7b91SNathan Whitehorn/*******************************************************************************
225ddbd7b91SNathan Whitehorn *
226ddbd7b91SNathan Whitehorn * FUNCTION:    AcpiExLoadTableOp
227ddbd7b91SNathan Whitehorn *
228ddbd7b91SNathan Whitehorn * PARAMETERS:  WalkState           - Current state with operands
229ddbd7b91SNathan Whitehorn *              ReturnDesc          - Where to store the return object
230ddbd7b91SNathan Whitehorn *
231ddbd7b91SNathan Whitehorn * RETURN:      Status
232ddbd7b91SNathan Whitehorn *
23379414580SJérôme Duval * DESCRIPTION: Load an ACPI table from the RSDT/XSDT
234ddbd7b91SNathan Whitehorn *
235ddbd7b91SNathan Whitehorn ******************************************************************************/
236ddbd7b91SNathan Whitehorn
237ddbd7b91SNathan WhitehornACPI_STATUS
238ddbd7b91SNathan WhitehornAcpiExLoadTableOp (
239ddbd7b91SNathan Whitehorn    ACPI_WALK_STATE         *WalkState,
240ddbd7b91SNathan Whitehorn    ACPI_OPERAND_OBJECT     **ReturnDesc)
241ddbd7b91SNathan Whitehorn{
242ddbd7b91SNathan Whitehorn    ACPI_STATUS             Status;
243ddbd7b91SNathan Whitehorn    ACPI_OPERAND_OBJECT     **Operand = &WalkState->Operands[0];
244ddbd7b91SNathan Whitehorn    ACPI_NAMESPACE_NODE     *ParentNode;
245ddbd7b91SNathan Whitehorn    ACPI_NAMESPACE_NODE     *StartNode;
246ddbd7b91SNathan Whitehorn    ACPI_NAMESPACE_NODE     *ParameterNode = NULL;
247ddbd7b91SNathan Whitehorn    ACPI_OPERAND_OBJECT     *DdbHandle;
24845e9de08SJérôme Duval    UINT32                  TableIndex;
249ddbd7b91SNathan Whitehorn
250ddbd7b91SNathan Whitehorn
25143547dbeSJérôme Duval    ACPI_FUNCTION_TRACE (ExLoadTableOp);
252ddbd7b91SNathan Whitehorn
253ddbd7b91SNathan Whitehorn
25479414580SJérôme Duval    /* Find the ACPI table in the RSDT/XSDT */
255ddbd7b91SNathan Whitehorn
256ff2e2f81SFredrik Holmqvist    AcpiExExitInterpreter ();
257c70258b7SJérôme Duval    Status = AcpiTbFindTable (
258b64e8511SFredrik Holmqvist        Operand[0]->String.Pointer,
259b64e8511SFredrik Holmqvist        Operand[1]->String.Pointer,
260b64e8511SFredrik Holmqvist        Operand[2]->String.Pointer, &TableIndex);
261ff2e2f81SFredrik Holmqvist    AcpiExEnterInterpreter ();
262ddbd7b91SNathan Whitehorn    if (ACPI_FAILURE (Status))
263ddbd7b91SNathan Whitehorn    {
264ddbd7b91SNathan Whitehorn        if (Status != AE_NOT_FOUND)
265ddbd7b91SNathan Whitehorn        {
266ddbd7b91SNathan Whitehorn            return_ACPI_STATUS (Status);
267ddbd7b91SNathan Whitehorn        }
268ddbd7b91SNathan Whitehorn
269ddbd7b91SNathan Whitehorn        /* Table not found, return an Integer=0 and AE_OK */
270ddbd7b91SNathan Whitehorn
27157c418cdSFredrik Holmqvist        DdbHandle = AcpiUtCreateIntegerObject ((UINT64) 0);
272ddbd7b91SNathan Whitehorn        if (!DdbHandle)
273ddbd7b91SNathan Whitehorn        {
274ddbd7b91SNathan Whitehorn            return_ACPI_STATUS (AE_NO_MEMORY);
275ddbd7b91SNathan Whitehorn        }
276ddbd7b91SNathan Whitehorn
277ddbd7b91SNathan Whitehorn        *ReturnDesc = DdbHandle;
278ddbd7b91SNathan Whitehorn        return_ACPI_STATUS (AE_OK);
279ddbd7b91SNathan Whitehorn    }
280ddbd7b91SNathan Whitehorn
281ddbd7b91SNathan Whitehorn    /* Default nodes */
282ddbd7b91SNathan Whitehorn
283ddbd7b91SNathan Whitehorn    StartNode = WalkState->ScopeInfo->Scope.Node;
284ddbd7b91SNathan Whitehorn    ParentNode = AcpiGbl_RootNode;
285ddbd7b91SNathan Whitehorn
286ddbd7b91SNathan Whitehorn    /* RootPath (optional parameter) */
287ddbd7b91SNathan Whitehorn
288ddbd7b91SNathan Whitehorn    if (Operand[3]->String.Length > 0)
289ddbd7b91SNathan Whitehorn    {
290ddbd7b91SNathan Whitehorn        /*
2919b0d045cSFredrik Holmqvist         * Find the node referenced by the RootPathString. This is the
292ddbd7b91SNathan Whitehorn         * location within the namespace where the table will be loaded.
293ddbd7b91SNathan Whitehorn         */
294ff2e2f81SFredrik Holmqvist        Status = AcpiNsGetNodeUnlocked (StartNode,
295ff2e2f81SFredrik Holmqvist            Operand[3]->String.Pointer, ACPI_NS_SEARCH_PARENT,
296ff2e2f81SFredrik Holmqvist            &ParentNode);
297ddbd7b91SNathan Whitehorn        if (ACPI_FAILURE (Status))
298ddbd7b91SNathan Whitehorn        {
299ddbd7b91SNathan Whitehorn            return_ACPI_STATUS (Status);
300ddbd7b91SNathan Whitehorn        }
301ddbd7b91SNathan Whitehorn    }
302ddbd7b91SNathan Whitehorn
303ddbd7b91SNathan Whitehorn    /* ParameterPath (optional parameter) */
304ddbd7b91SNathan Whitehorn
305ddbd7b91SNathan Whitehorn    if (Operand[4]->String.Length > 0)
306ddbd7b91SNathan Whitehorn    {
307c70258b7SJérôme Duval        if ((Operand[4]->String.Pointer[0] != AML_ROOT_PREFIX) &&
308c70258b7SJérôme Duval            (Operand[4]->String.Pointer[0] != AML_PARENT_PREFIX))
309ddbd7b91SNathan Whitehorn        {
310ddbd7b91SNathan Whitehorn            /*
311ddbd7b91SNathan Whitehorn             * Path is not absolute, so it will be relative to the node
312ddbd7b91SNathan Whitehorn             * referenced by the RootPathString (or the NS root if omitted)
313ddbd7b91SNathan Whitehorn             */
314ddbd7b91SNathan Whitehorn            StartNode = ParentNode;
315ddbd7b91SNathan Whitehorn        }
316ddbd7b91SNathan Whitehorn
31743547dbeSJérôme Duval        /* Find the node referenced by the ParameterPathString */
31843547dbeSJérôme Duval
319ff2e2f81SFredrik Holmqvist        Status = AcpiNsGetNodeUnlocked (StartNode,
320ff2e2f81SFredrik Holmqvist            Operand[4]->String.Pointer, ACPI_NS_SEARCH_PARENT,
321ff2e2f81SFredrik Holmqvist            &ParameterNode);
322ddbd7b91SNathan Whitehorn        if (ACPI_FAILURE (Status))
323ddbd7b91SNathan Whitehorn        {
324ddbd7b91SNathan Whitehorn            return_ACPI_STATUS (Status);
325ddbd7b91SNathan Whitehorn        }
326ddbd7b91SNathan Whitehorn    }
327ddbd7b91SNathan Whitehorn
328ddbd7b91SNathan Whitehorn    /* Load the table into the namespace */
329ddbd7b91SNathan Whitehorn
330ff2e2f81SFredrik Holmqvist    ACPI_INFO (("Dynamic OEM Table Load:"));
331ff2e2f81SFredrik Holmqvist    AcpiExExitInterpreter ();
332ff2e2f81SFredrik Holmqvist    Status = AcpiTbLoadTable (TableIndex, ParentNode);
333ff2e2f81SFredrik Holmqvist    AcpiExEnterInterpreter ();
334ff2e2f81SFredrik Holmqvist    if (ACPI_FAILURE (Status))
335ff2e2f81SFredrik Holmqvist    {
336ff2e2f81SFredrik Holmqvist        return_ACPI_STATUS (Status);
337ff2e2f81SFredrik Holmqvist    }
338ff2e2f81SFredrik Holmqvist
339ff2e2f81SFredrik Holmqvist    Status = AcpiExAddTable (TableIndex, &DdbHandle);
340ddbd7b91SNathan Whitehorn    if (ACPI_FAILURE (Status))
341ddbd7b91SNathan Whitehorn    {
342ddbd7b91SNathan Whitehorn        return_ACPI_STATUS (Status);
343ddbd7b91SNathan Whitehorn    }
344ddbd7b91SNathan Whitehorn
34508c9948cSFredrik Holmqvist    /* Complete the initialization/resolution of package objects */
34608c9948cSFredrik Holmqvist
34708c9948cSFredrik Holmqvist    Status = AcpiNsWalkNamespace (ACPI_TYPE_PACKAGE, ACPI_ROOT_OBJECT,
34808c9948cSFredrik Holmqvist        ACPI_UINT32_MAX, 0, AcpiNsInitOnePackage, NULL, NULL, NULL);
34908c9948cSFredrik Holmqvist
350ddbd7b91SNathan Whitehorn    /* Parameter Data (optional) */
351ddbd7b91SNathan Whitehorn
352ddbd7b91SNathan Whitehorn    if (ParameterNode)
353ddbd7b91SNathan Whitehorn    {
354ddbd7b91SNathan Whitehorn        /* Store the parameter data into the optional parameter object */
355ddbd7b91SNathan Whitehorn
35643547dbeSJérôme Duval        Status = AcpiExStore (Operand[5],
357b64e8511SFredrik Holmqvist            ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, ParameterNode), WalkState);
358ddbd7b91SNathan Whitehorn        if (ACPI_FAILURE (Status))
359ddbd7b91SNathan Whitehorn        {
360ddbd7b91SNathan Whitehorn            (void) AcpiExUnloadTable (DdbHandle);
36180377d9aSJérôme Duval
36280377d9aSJérôme Duval            AcpiUtRemoveReference (DdbHandle);
363ddbd7b91SNathan Whitehorn            return_ACPI_STATUS (Status);
364ddbd7b91SNathan Whitehorn        }
365ddbd7b91SNathan Whitehorn    }
366ddbd7b91SNathan Whitehorn
367ddbd7b91SNathan Whitehorn    *ReturnDesc = DdbHandle;
368c70258b7SJérôme Duval    return_ACPI_STATUS (Status);
369ddbd7b91SNathan Whitehorn}
370ddbd7b91SNathan Whitehorn
371ddbd7b91SNathan Whitehorn
37280377d9aSJérôme Duval/*******************************************************************************
37380377d9aSJérôme Duval *
37480377d9aSJérôme Duval * FUNCTION:    AcpiExRegionRead
37580377d9aSJérôme Duval *
37680377d9aSJérôme Duval * PARAMETERS:  ObjDesc         - Region descriptor
37780377d9aSJérôme Duval *              Length          - Number of bytes to read
37880377d9aSJérôme Duval *              Buffer          - Pointer to where to put the data
37980377d9aSJérôme Duval *
38080377d9aSJérôme Duval * RETURN:      Status
38180377d9aSJérôme Duval *
38280377d9aSJérôme Duval * DESCRIPTION: Read data from an operation region. The read starts from the
38380377d9aSJérôme Duval *              beginning of the region.
38480377d9aSJérôme Duval *
38580377d9aSJérôme Duval ******************************************************************************/
38680377d9aSJérôme Duval
38780377d9aSJérôme Duvalstatic ACPI_STATUS
38880377d9aSJérôme DuvalAcpiExRegionRead (
38980377d9aSJérôme Duval    ACPI_OPERAND_OBJECT     *ObjDesc,
39080377d9aSJérôme Duval    UINT32                  Length,
39180377d9aSJérôme Duval    UINT8                   *Buffer)
39280377d9aSJérôme Duval{
39380377d9aSJérôme Duval    ACPI_STATUS             Status;
39457c418cdSFredrik Holmqvist    UINT64                  Value;
39580377d9aSJérôme Duval    UINT32                  RegionOffset = 0;
39680377d9aSJérôme Duval    UINT32                  i;
39780377d9aSJérôme Duval
39880377d9aSJérôme Duval
39980377d9aSJérôme Duval    /* Bytewise reads */
40080377d9aSJérôme Duval
40180377d9aSJérôme Duval    for (i = 0; i < Length; i++)
40280377d9aSJérôme Duval    {
4036822cda0SFredrik Holmqvist        Status = AcpiEvAddressSpaceDispatch (ObjDesc, NULL, ACPI_READ,
404b64e8511SFredrik Holmqvist            RegionOffset, 8, &Value);
40580377d9aSJérôme Duval        if (ACPI_FAILURE (Status))
40680377d9aSJérôme Duval        {
40780377d9aSJérôme Duval            return (Status);
40880377d9aSJérôme Duval        }
40980377d9aSJérôme Duval
41080377d9aSJérôme Duval        *Buffer = (UINT8) Value;
41180377d9aSJérôme Duval        Buffer++;
41280377d9aSJérôme Duval        RegionOffset++;
41380377d9aSJérôme Duval    }
41480377d9aSJérôme Duval
41580377d9aSJérôme Duval    return (AE_OK);
41680377d9aSJérôme Duval}
41780377d9aSJérôme Duval
41880377d9aSJérôme Duval
419ddbd7b91SNathan Whitehorn/*******************************************************************************
420ddbd7b91SNathan Whitehorn *
421ddbd7b91SNathan Whitehorn * FUNCTION:    AcpiExLoadOp
422ddbd7b91SNathan Whitehorn *
42379414580SJérôme Duval * PARAMETERS:  ObjDesc         - Region or Buffer/Field where the table will be
424ddbd7b91SNathan Whitehorn *                                obtained
425ddbd7b91SNathan Whitehorn *              Target          - Where a handle to the table will be stored
426ddbd7b91SNathan Whitehorn *              WalkState       - Current state
427ddbd7b91SNathan Whitehorn *
428ddbd7b91SNathan Whitehorn * RETURN:      Status
429ddbd7b91SNathan Whitehorn *
430ddbd7b91SNathan Whitehorn * DESCRIPTION: Load an ACPI table from a field or operation region
431ddbd7b91SNathan Whitehorn *
43279414580SJérôme Duval * NOTE: Region Fields (Field, BankField, IndexFields) are resolved to buffer
43379414580SJérôme Duval *       objects before this code is reached.
43479414580SJérôme Duval *
43579414580SJérôme Duval *       If source is an operation region, it must refer to SystemMemory, as
43679414580SJérôme Duval *       per the ACPI specification.
43779414580SJérôme Duval *
438ddbd7b91SNathan Whitehorn ******************************************************************************/
439ddbd7b91SNathan Whitehorn
440ddbd7b91SNathan WhitehornACPI_STATUS
441ddbd7b91SNathan WhitehornAcpiExLoadOp (
442ddbd7b91SNathan Whitehorn    ACPI_OPERAND_OBJECT     *ObjDesc,
443ddbd7b91SNathan Whitehorn    ACPI_OPERAND_OBJECT     *Target,
444ddbd7b91SNathan Whitehorn    ACPI_WALK_STATE         *WalkState)
445ddbd7b91SNathan Whitehorn{
446ddbd7b91SNathan Whitehorn    ACPI_OPERAND_OBJECT     *DdbHandle;
447ad5bbfb8SFredrik Holmqvist    ACPI_TABLE_HEADER       *TableHeader;
448cfd62a38SJérôme Duval    ACPI_TABLE_HEADER       *Table;
44945e9de08SJérôme Duval    UINT32                  TableIndex;
45079414580SJérôme Duval    ACPI_STATUS             Status;
4512608583eSJérôme Duval    UINT32                  Length;
45279414580SJérôme Duval
453ddbd7b91SNathan Whitehorn
45443547dbeSJérôme Duval    ACPI_FUNCTION_TRACE (ExLoadOp);
455ddbd7b91SNathan Whitehorn
456ddbd7b91SNathan Whitehorn
45779414580SJérôme Duval    /* Source Object can be either an OpRegion or a Buffer/Field */
458ddbd7b91SNathan Whitehorn
45980377d9aSJérôme Duval    switch (ObjDesc->Common.Type)
460ddbd7b91SNathan Whitehorn    {
461ddbd7b91SNathan Whitehorn    case ACPI_TYPE_REGION:
462ddbd7b91SNathan Whitehorn
463cfd62a38SJérôme Duval        ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
464cfd62a38SJérôme Duval            "Load table from Region %p\n", ObjDesc));
4652608583eSJérôme Duval
46679414580SJérôme Duval        /* Region must be SystemMemory (from ACPI spec) */
46779414580SJérôme Duval
46879414580SJérôme Duval        if (ObjDesc->Region.SpaceId != ACPI_ADR_SPACE_SYSTEM_MEMORY)
46979414580SJérôme Duval        {
47079414580SJérôme Duval            return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
47179414580SJérôme Duval        }
47279414580SJérôme Duval
473ddbd7b91SNathan Whitehorn        /*
474b64e8511SFredrik Holmqvist         * If the Region Address and Length have not been previously
475b64e8511SFredrik Holmqvist         * evaluated, evaluate them now and save the results.
476ddbd7b91SNathan Whitehorn         */
477ddbd7b91SNathan Whitehorn        if (!(ObjDesc->Common.Flags & AOPOBJ_DATA_VALID))
478ddbd7b91SNathan Whitehorn        {
479ddbd7b91SNathan Whitehorn            Status = AcpiDsGetRegionArguments (ObjDesc);
480ddbd7b91SNathan Whitehorn            if (ACPI_FAILURE (Status))
481ddbd7b91SNathan Whitehorn            {
482ddbd7b91SNathan Whitehorn                return_ACPI_STATUS (Status);
483ddbd7b91SNathan Whitehorn            }
484ddbd7b91SNathan Whitehorn        }
485ddbd7b91SNathan Whitehorn
48680377d9aSJérôme Duval        /* Get the table header first so we can get the table length */
48780377d9aSJérôme Duval
488ad5bbfb8SFredrik Holmqvist        TableHeader = ACPI_ALLOCATE (sizeof (ACPI_TABLE_HEADER));
489ad5bbfb8SFredrik Holmqvist        if (!TableHeader)
490cfd62a38SJérôme Duval        {
491cfd62a38SJérôme Duval            return_ACPI_STATUS (AE_NO_MEMORY);
492cfd62a38SJérôme Duval        }
493cfd62a38SJérôme Duval
49480377d9aSJérôme Duval        Status = AcpiExRegionRead (ObjDesc, sizeof (ACPI_TABLE_HEADER),
495b64e8511SFredrik Holmqvist            ACPI_CAST_PTR (UINT8, TableHeader));
496ad5bbfb8SFredrik Holmqvist        Length = TableHeader->Length;
497ad5bbfb8SFredrik Holmqvist        ACPI_FREE (TableHeader);
49880377d9aSJérôme Duval
49980377d9aSJérôme Duval        if (ACPI_FAILURE (Status))
50080377d9aSJérôme Duval        {
50180377d9aSJérôme Duval            return_ACPI_STATUS (Status);
50280377d9aSJérôme Duval        }
503cfd62a38SJérôme Duval
504cfd62a38SJérôme Duval        /* Must have at least an ACPI table header */
505cfd62a38SJérôme Duval
506cfd62a38SJérôme Duval        if (Length < sizeof (ACPI_TABLE_HEADER))
507cfd62a38SJérôme Duval        {
508cfd62a38SJérôme Duval            return_ACPI_STATUS (AE_INVALID_TABLE_LENGTH);
509cfd62a38SJérôme Duval        }
510cfd62a38SJérôme Duval
511cfd62a38SJérôme Duval        /*
51280377d9aSJérôme Duval         * The original implementation simply mapped the table, with no copy.
51380377d9aSJérôme Duval         * However, the memory region is not guaranteed to remain stable and
51480377d9aSJérôme Duval         * we must copy the table to a local buffer. For example, the memory
51580377d9aSJérôme Duval         * region is corrupted after suspend on some machines. Dynamically
51680377d9aSJérôme Duval         * loaded tables are usually small, so this overhead is minimal.
51780377d9aSJérôme Duval         *
51880377d9aSJérôme Duval         * The latest implementation (5/2009) does not use a mapping at all.
51980377d9aSJérôme Duval         * We use the low-level operation region interface to read the table
52080377d9aSJérôme Duval         * instead of the obvious optimization of using a direct mapping.
52180377d9aSJérôme Duval         * This maintains a consistent use of operation regions across the
52280377d9aSJérôme Duval         * entire subsystem. This is important if additional processing must
52380377d9aSJérôme Duval         * be performed in the (possibly user-installed) operation region
52480377d9aSJérôme Duval         * handler. For example, AcpiExec and ASLTS depend on this.
525cfd62a38SJérôme Duval         */
526cfd62a38SJérôme Duval
527cfd62a38SJérôme Duval        /* Allocate a buffer for the table */
528cfd62a38SJérôme Duval
529ad5bbfb8SFredrik Holmqvist        Table = ACPI_ALLOCATE (Length);
530ad5bbfb8SFredrik Holmqvist        if (!Table)
531cfd62a38SJérôme Duval        {
532cfd62a38SJérôme Duval            return_ACPI_STATUS (AE_NO_MEMORY);
533cfd62a38SJérôme Duval        }
534cfd62a38SJérôme Duval
53580377d9aSJérôme Duval        /* Read the entire table */
536cfd62a38SJérôme Duval
53780377d9aSJérôme Duval        Status = AcpiExRegionRead (ObjDesc, Length,
538b64e8511SFredrik Holmqvist            ACPI_CAST_PTR (UINT8, Table));
53980377d9aSJérôme Duval        if (ACPI_FAILURE (Status))
540cfd62a38SJérôme Duval        {
541ad5bbfb8SFredrik Holmqvist            ACPI_FREE (Table);
54280377d9aSJérôme Duval            return_ACPI_STATUS (Status);
543cfd62a38SJérôme Duval        }
544ddbd7b91SNathan Whitehorn        break;
545ddbd7b91SNathan Whitehorn
546cfd62a38SJérôme Duval    case ACPI_TYPE_BUFFER: /* Buffer or resolved RegionField */
547ddbd7b91SNathan Whitehorn
548cfd62a38SJérôme Duval        ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
549cfd62a38SJérôme Duval            "Load table from Buffer or Field %p\n", ObjDesc));
5502608583eSJérôme Duval
5512608583eSJérôme Duval        /* Must have at least an ACPI table header */
5522608583eSJérôme Duval
553cfd62a38SJérôme Duval        if (ObjDesc->Buffer.Length < sizeof (ACPI_TABLE_HEADER))
5542608583eSJérôme Duval        {
5552608583eSJérôme Duval            return_ACPI_STATUS (AE_INVALID_TABLE_LENGTH);
5562608583eSJérôme Duval        }
5572608583eSJérôme Duval
558cfd62a38SJérôme Duval        /* Get the actual table length from the table header */
5592608583eSJérôme Duval
560b64e8511SFredrik Holmqvist        TableHeader = ACPI_CAST_PTR (
561b64e8511SFredrik Holmqvist            ACPI_TABLE_HEADER, ObjDesc->Buffer.Pointer);
562ad5bbfb8SFredrik Holmqvist        Length = TableHeader->Length;
563cfd62a38SJérôme Duval
564cfd62a38SJérôme Duval        /* Table cannot extend beyond the buffer */
565cfd62a38SJérôme Duval
566cfd62a38SJérôme Duval        if (Length > ObjDesc->Buffer.Length)
5672608583eSJérôme Duval        {
568cfd62a38SJérôme Duval            return_ACPI_STATUS (AE_AML_BUFFER_LIMIT);
569cfd62a38SJérôme Duval        }
570cfd62a38SJérôme Duval        if (Length < sizeof (ACPI_TABLE_HEADER))
571cfd62a38SJérôme Duval        {
572cfd62a38SJérôme Duval            return_ACPI_STATUS (AE_INVALID_TABLE_LENGTH);
5732608583eSJérôme Duval        }
574ddbd7b91SNathan Whitehorn
5752608583eSJérôme Duval        /*
576b64e8511SFredrik Holmqvist         * Copy the table from the buffer because the buffer could be
577b64e8511SFredrik Holmqvist         * modified or even deleted in the future
5782608583eSJérôme Duval         */
579ad5bbfb8SFredrik Holmqvist        Table = ACPI_ALLOCATE (Length);
580ad5bbfb8SFredrik Holmqvist        if (!Table)
5812608583eSJérôme Duval        {
5822608583eSJérôme Duval            return_ACPI_STATUS (AE_NO_MEMORY);
5832608583eSJérôme Duval        }
5842608583eSJérôme Duval
585e226d1d0SFredrik Holmqvist        memcpy (Table, TableHeader, Length);
586ddbd7b91SNathan Whitehorn        break;
587ddbd7b91SNathan Whitehorn
588ddbd7b91SNathan Whitehorn    default:
589c70258b7SJérôme Duval
590ddbd7b91SNathan Whitehorn        return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
591ddbd7b91SNathan Whitehorn    }
592ddbd7b91SNathan Whitehorn
593ad5bbfb8SFredrik Holmqvist    /* Install the new table into the local data structures */
594ad5bbfb8SFredrik Holmqvist
59574ffd18dSFredrik Holmqvist    ACPI_INFO (("Dynamic OEM Table Load:"));
596ff2e2f81SFredrik Holmqvist    AcpiExExitInterpreter ();
597ff2e2f81SFredrik Holmqvist    Status = AcpiTbInstallAndLoadTable (ACPI_PTR_TO_PHYSADDR (Table),
598ff2e2f81SFredrik Holmqvist        ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL, TRUE, &TableIndex);
599ff2e2f81SFredrik Holmqvist    AcpiExEnterInterpreter ();
600cfd62a38SJérôme Duval    if (ACPI_FAILURE (Status))
601cfd62a38SJérôme Duval    {
602ad5bbfb8SFredrik Holmqvist        /* Delete allocated table buffer */
603ad5bbfb8SFredrik Holmqvist
604ad5bbfb8SFredrik Holmqvist        ACPI_FREE (Table);
605cfd62a38SJérôme Duval        return_ACPI_STATUS (Status);
606cfd62a38SJérôme Duval    }
607cfd62a38SJérôme Duval
60845e9de08SJérôme Duval    /*
60945e9de08SJérôme Duval     * Add the table to the namespace.
61045e9de08SJérôme Duval     *
611cfd62a38SJérôme Duval     * Note: Load the table objects relative to the root of the namespace.
61245e9de08SJérôme Duval     * This appears to go against the ACPI specification, but we do it for
61345e9de08SJérôme Duval     * compatibility with other ACPI implementations.
61445e9de08SJérôme Duval     */
615ff2e2f81SFredrik Holmqvist    Status = AcpiExAddTable (TableIndex, &DdbHandle);
616ddbd7b91SNathan Whitehorn    if (ACPI_FAILURE (Status))
617ddbd7b91SNathan Whitehorn    {
61843547dbeSJérôme Duval        /* On error, TablePtr was deallocated above */
61943547dbeSJérôme Duval
62043547dbeSJérôme Duval        return_ACPI_STATUS (Status);
621ddbd7b91SNathan Whitehorn    }
622ddbd7b91SNathan Whitehorn
62308c9948cSFredrik Holmqvist    /* Complete the initialization/resolution of package objects */
62408c9948cSFredrik Holmqvist
62508c9948cSFredrik Holmqvist    Status = AcpiNsWalkNamespace (ACPI_TYPE_PACKAGE, ACPI_ROOT_OBJECT,
62608c9948cSFredrik Holmqvist        ACPI_UINT32_MAX, 0, AcpiNsInitOnePackage, NULL, NULL, NULL);
62708c9948cSFredrik Holmqvist
628ddbd7b91SNathan Whitehorn    /* Store the DdbHandle into the Target operand */
629ddbd7b91SNathan Whitehorn
630ddbd7b91SNathan Whitehorn    Status = AcpiExStore (DdbHandle, Target, WalkState);
631ddbd7b91SNathan Whitehorn    if (ACPI_FAILURE (Status))
632ddbd7b91SNathan Whitehorn    {
633ddbd7b91SNathan Whitehorn        (void) AcpiExUnloadTable (DdbHandle);
634ddbd7b91SNathan Whitehorn
63543547dbeSJérôme Duval        /* TablePtr was deallocated above */
636ddbd7b91SNathan Whitehorn
6372608583eSJérôme Duval        AcpiUtRemoveReference (DdbHandle);
63843547dbeSJérôme Duval        return_ACPI_STATUS (Status);
63943547dbeSJérôme Duval    }
640ddbd7b91SNathan Whitehorn
64180377d9aSJérôme Duval    /* Remove the reference by added by AcpiExStore above */
64280377d9aSJérôme Duval
64380377d9aSJérôme Duval    AcpiUtRemoveReference (DdbHandle);
644ddbd7b91SNathan Whitehorn    return_ACPI_STATUS (Status);
645ddbd7b91SNathan Whitehorn}
646ddbd7b91SNathan Whitehorn
647ddbd7b91SNathan Whitehorn
648ddbd7b91SNathan Whitehorn/*******************************************************************************
649ddbd7b91SNathan Whitehorn *
650ddbd7b91SNathan Whitehorn * FUNCTION:    AcpiExUnloadTable
651ddbd7b91SNathan Whitehorn *
652ddbd7b91SNathan Whitehorn * PARAMETERS:  DdbHandle           - Handle to a previously loaded table
653ddbd7b91SNathan Whitehorn *
654ddbd7b91SNathan Whitehorn * RETURN:      Status
655ddbd7b91SNathan Whitehorn *
656ddbd7b91SNathan Whitehorn * DESCRIPTION: Unload an ACPI table
657ddbd7b91SNathan Whitehorn *
658ddbd7b91SNathan Whitehorn ******************************************************************************/
659ddbd7b91SNathan Whitehorn
660ddbd7b91SNathan WhitehornACPI_STATUS
661ddbd7b91SNathan WhitehornAcpiExUnloadTable (
662ddbd7b91SNathan Whitehorn    ACPI_OPERAND_OBJECT     *DdbHandle)
663ddbd7b91SNathan Whitehorn{
664ddbd7b91SNathan Whitehorn    ACPI_STATUS             Status = AE_OK;
665ddbd7b91SNathan Whitehorn    ACPI_OPERAND_OBJECT     *TableDesc = DdbHandle;
66645e9de08SJérôme Duval    UINT32                  TableIndex;
667ddbd7b91SNathan Whitehorn
668ddbd7b91SNathan Whitehorn
66943547dbeSJérôme Duval    ACPI_FUNCTION_TRACE (ExUnloadTable);
670ddbd7b91SNathan Whitehorn
671ddbd7b91SNathan Whitehorn
672ad5bbfb8SFredrik Holmqvist    /*
673ad5bbfb8SFredrik Holmqvist     * Temporarily emit a warning so that the ASL for the machine can be
674ad5bbfb8SFredrik Holmqvist     * hopefully obtained. This is to say that the Unload() operator is
675ad5bbfb8SFredrik Holmqvist     * extremely rare if not completely unused.
676ad5bbfb8SFredrik Holmqvist     */
677ad5bbfb8SFredrik Holmqvist    ACPI_WARNING ((AE_INFO,
678ad5bbfb8SFredrik Holmqvist        "Received request to unload an ACPI table"));
679ad5bbfb8SFredrik Holmqvist
68008c9948cSFredrik Holmqvist    /*
68108c9948cSFredrik Holmqvist     * May 2018: Unload is no longer supported for the following reasons:
68208c9948cSFredrik Holmqvist     * 1) A correct implementation on some hosts may not be possible.
68308c9948cSFredrik Holmqvist     * 2) Other ACPI implementations do not correctly/fully support it.
68408c9948cSFredrik Holmqvist     * 3) It requires host device driver support which does not exist.
68508c9948cSFredrik Holmqvist     *    (To properly support namespace unload out from underneath.)
68608c9948cSFredrik Holmqvist     * 4) This AML operator has never been seen in the field.
68708c9948cSFredrik Holmqvist     */
68808c9948cSFredrik Holmqvist    ACPI_EXCEPTION ((AE_INFO, AE_NOT_IMPLEMENTED,
68908c9948cSFredrik Holmqvist        "AML Unload operator is not supported"));
69008c9948cSFredrik Holmqvist
691ddbd7b91SNathan Whitehorn    /*
692ddbd7b91SNathan Whitehorn     * Validate the handle
69380377d9aSJérôme Duval     * Although the handle is partially validated in AcpiExReconfiguration()
694ddbd7b91SNathan Whitehorn     * when it calls AcpiExResolveOperands(), the handle is more completely
695ddbd7b91SNathan Whitehorn     * validated here.
69680377d9aSJérôme Duval     *
69780377d9aSJérôme Duval     * Handle must be a valid operand object of type reference. Also, the
69880377d9aSJérôme Duval     * DdbHandle must still be marked valid (table has not been previously
69980377d9aSJérôme Duval     * unloaded)
700ddbd7b91SNathan Whitehorn     */
701ddbd7b91SNathan Whitehorn    if ((!DdbHandle) ||
702ddbd7b91SNathan Whitehorn        (ACPI_GET_DESCRIPTOR_TYPE (DdbHandle) != ACPI_DESC_TYPE_OPERAND) ||
70380377d9aSJérôme Duval        (DdbHandle->Common.Type != ACPI_TYPE_LOCAL_REFERENCE) ||
70480377d9aSJérôme Duval        (!(DdbHandle->Common.Flags & AOPOBJ_DATA_VALID)))
705ddbd7b91SNathan Whitehorn    {
706c70258b7SJérôme Duval        return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
707ddbd7b91SNathan Whitehorn    }
708ddbd7b91SNathan Whitehorn
70980377d9aSJérôme Duval    /* Get the table index from the DdbHandle */
710ddbd7b91SNathan Whitehorn
71180377d9aSJérôme Duval    TableIndex = TableDesc->Reference.Value;
71280377d9aSJérôme Duval
713ff2e2f81SFredrik Holmqvist    /*
714ff2e2f81SFredrik Holmqvist     * Release the interpreter lock so that the table lock won't have
715ff2e2f81SFredrik Holmqvist     * strict order requirement against it.
716ff2e2f81SFredrik Holmqvist     */
717ff2e2f81SFredrik Holmqvist    AcpiExExitInterpreter ();
718ff2e2f81SFredrik Holmqvist    Status = AcpiTbUnloadTable (TableIndex);
719ff2e2f81SFredrik Holmqvist    AcpiExEnterInterpreter ();
720cfd62a38SJérôme Duval
72180377d9aSJérôme Duval    /*
72280377d9aSJérôme Duval     * Invalidate the handle. We do this because the handle may be stored
72380377d9aSJérôme Duval     * in a named object and may not be actually deleted until much later.
72480377d9aSJérôme Duval     */
725ff2e2f81SFredrik Holmqvist    if (ACPI_SUCCESS (Status))
726ff2e2f81SFredrik Holmqvist    {
727ff2e2f81SFredrik Holmqvist        DdbHandle->Common.Flags &= ~AOPOBJ_DATA_VALID;
728ff2e2f81SFredrik Holmqvist    }
729ff2e2f81SFredrik Holmqvist    return_ACPI_STATUS (Status);
730ddbd7b91SNathan Whitehorn}
731