nsload.c revision 193249
1234285Sdim/******************************************************************************
2234285Sdim *
3234285Sdim * Module Name: nsload - namespace loading/expanding/contracting procedures
4234285Sdim *              $Revision: 1.80 $
5234285Sdim *
6234285Sdim *****************************************************************************/
7234285Sdim
8234285Sdim/******************************************************************************
9234285Sdim *
10234285Sdim * 1. Copyright Notice
11234285Sdim *
12234285Sdim * Some or all of this work - Copyright (c) 1999 - 2007, Intel Corp.
13234285Sdim * All rights reserved.
14239462Sdim *
15234285Sdim * 2. License
16234285Sdim *
17234285Sdim * 2.1. This is your license from Intel Corp. under its intellectual property
18234285Sdim * rights.  You may have additional license terms from the party that provided
19234285Sdim * you this software, covering your right to use that party's intellectual
20234285Sdim * property rights.
21234285Sdim *
22234285Sdim * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
23234285Sdim * copy of the source code appearing in this file ("Covered Code") an
24234285Sdim * irrevocable, perpetual, worldwide license under Intel's copyrights in the
25234285Sdim * base code distributed originally by Intel ("Original Intel Code") to copy,
26234285Sdim * make derivatives, distribute, use and display any portion of the Covered
27234285Sdim * Code in any form, with the right to sublicense such rights; and
28249423Sdim *
29249423Sdim * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
30249423Sdim * license (with the right to sublicense), under only those claims of Intel
31249423Sdim * patents that are infringed by the Original Intel Code, to make, use, sell,
32249423Sdim * offer to sell, and import the Covered Code and derivative works thereof
33234285Sdim * solely to the minimum extent necessary to exercise the above copyright
34234285Sdim * license, and in no event shall the patent license extend to any additions
35234285Sdim * to or modifications of the Original Intel Code.  No other license or right
36288943Sdim * is granted directly or by implication, estoppel or otherwise;
37234285Sdim *
38234285Sdim * The above copyright and patent license is granted only if the following
39234285Sdim * conditions are met:
40234285Sdim *
41234285Sdim * 3. Conditions
42251662Sdim *
43234285Sdim * 3.1. Redistribution of Source with Rights to Further Distribute Source.
44288943Sdim * Redistribution of source code of any substantial portion of the Covered
45234285Sdim * Code or modification with rights to further distribute source must include
46234285Sdim * the above Copyright Notice, the above License, this list of Conditions,
47280031Sdim * and the following Disclaimer and Export Compliance provision.  In addition,
48234285Sdim * Licensee must cause all Covered Code to which Licensee contributes to
49234285Sdim * contain a file documenting the changes Licensee made to create that Covered
50234285Sdim * Code and the date of any change.  Licensee must include in that file the
51288943Sdim * documentation of any changes made by any predecessor Licensee.  Licensee
52276479Sdim * must include a prominent statement that the modification is derived,
53234285Sdim * directly or indirectly, from Original Intel Code.
54296417Sdim *
55234285Sdim * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
56234285Sdim * Redistribution of source code of any substantial portion of the Covered
57234285Sdim * Code or modification without rights to further distribute source must
58234285Sdim * include the following Disclaimer and Export Compliance provision in the
59234285Sdim * documentation and/or other materials provided with distribution.  In
60251662Sdim * addition, Licensee may not authorize further sublicense of source of any
61251662Sdim * portion of the Covered Code, and must include terms to the effect that the
62251662Sdim * license from Licensee to its licensee is limited to the intellectual
63251662Sdim * property embodied in the software Licensee provides to its licensee, and
64251662Sdim * not to intellectual property embodied in modifications its licensee may
65296417Sdim * make.
66296417Sdim *
67296417Sdim * 3.3. Redistribution of Executable. Redistribution in executable form of any
68296417Sdim * substantial portion of the Covered Code or modification must reproduce the
69296417Sdim * above Copyright Notice, and the following Disclaimer and Export Compliance
70276479Sdim * provision in the documentation and/or other materials provided with the
71288943Sdim * distribution.
72288943Sdim *
73288943Sdim * 3.4. Intel retains all right, title, and interest in and to the Original
74288943Sdim * Intel Code.
75288943Sdim *
76276479Sdim * 3.5. Neither the name Intel nor any other trademark owned or controlled by
77288943Sdim * Intel shall be used in advertising or otherwise to promote the sale, use or
78288943Sdim * other dealings in products derived from or relating to the Covered Code
79288943Sdim * without prior written authorization from Intel.
80288943Sdim *
81288943Sdim * 4. Disclaimer and Export Compliance
82288943Sdim *
83288943Sdim * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
84288943Sdim * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
85288943Sdim * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
86288943Sdim * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
87288943Sdim * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
88288943Sdim * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
89296417Sdim * PARTICULAR PURPOSE.
90296417Sdim *
91296417Sdim * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
92296417Sdim * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
93296417Sdim * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
94296417Sdim * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
95296417Sdim * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
96296417Sdim * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
97296417Sdim * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
98296417Sdim * LIMITED REMEDY.
99296417Sdim *
100296417Sdim * 4.3. Licensee shall not export, either directly or indirectly, any of this
101296417Sdim * software or system incorporating such software without first obtaining any
102296417Sdim * required license or other approval from the U. S. Department of Commerce or
103296417Sdim * any other agency or department of the United States Government.  In the
104296417Sdim * event Licensee exports any such software from the United States or
105296417Sdim * re-exports any such software from a foreign destination, Licensee shall
106296417Sdim * ensure that the distribution and export/re-export of the software is in
107296417Sdim * compliance with all laws, regulations, orders, or other restrictions of the
108296417Sdim * U.S. Export Administration Regulations. Licensee agrees that neither it nor
109296417Sdim * any of its subsidiaries will export/re-export any technical data, process,
110296417Sdim * software, or service, directly or indirectly, to any country for which the
111296417Sdim * United States government or any agency thereof requires an export license,
112234285Sdim * other governmental approval, or letter of assurance, without first obtaining
113234285Sdim * such license, approval or letter.
114234285Sdim *
115234285Sdim *****************************************************************************/
116234285Sdim
117234285Sdim#define __NSLOAD_C__
118234285Sdim
119234285Sdim#include <contrib/dev/acpica/acpi.h>
120234285Sdim#include <contrib/dev/acpica/acnamesp.h>
121234285Sdim#include <contrib/dev/acpica/acdispat.h>
122234285Sdim#include <contrib/dev/acpica/actables.h>
123239462Sdim
124239462Sdim
125239462Sdim#define _COMPONENT          ACPI_NAMESPACE
126234285Sdim        ACPI_MODULE_NAME    ("nsload")
127239462Sdim
128239462Sdim/* Local prototypes */
129239462Sdim
130234285Sdim#ifdef ACPI_FUTURE_IMPLEMENTATION
131234285SdimACPI_STATUS
132234285SdimAcpiNsUnloadNamespace (
133234285Sdim    ACPI_HANDLE             Handle);
134234285Sdim
135234285Sdimstatic ACPI_STATUS
136234285SdimAcpiNsDeleteSubtree (
137234285Sdim    ACPI_HANDLE             StartHandle);
138234285Sdim#endif
139234285Sdim
140234285Sdim
141234285Sdim#ifndef ACPI_NO_METHOD_EXECUTION
142234285Sdim/*******************************************************************************
143234285Sdim *
144234285Sdim * FUNCTION:    AcpiNsLoadTable
145234285Sdim *
146234285Sdim * PARAMETERS:  TableIndex      - Index for table to be loaded
147234285Sdim *              Node            - Owning NS node
148234285Sdim *
149234285Sdim * RETURN:      Status
150234285Sdim *
151234285Sdim * DESCRIPTION: Load one ACPI table into the namespace
152288943Sdim *
153234285Sdim ******************************************************************************/
154234285Sdim
155234285SdimACPI_STATUS
156234285SdimAcpiNsLoadTable (
157234285Sdim    ACPI_NATIVE_UINT        TableIndex,
158234982Sdim    ACPI_NAMESPACE_NODE     *Node)
159234285Sdim{
160234285Sdim    ACPI_STATUS             Status;
161234982Sdim
162234285Sdim
163234285Sdim    ACPI_FUNCTION_TRACE (NsLoadTable);
164234982Sdim
165234285Sdim
166234285Sdim    /*
167234285Sdim     * Parse the table and load the namespace with all named
168234285Sdim     * objects found within.  Control methods are NOT parsed
169234285Sdim     * at this time.  In fact, the control methods cannot be
170234285Sdim     * parsed until the entire namespace is loaded, because
171234285Sdim     * if a control method makes a forward reference (call)
172234285Sdim     * to another control method, we can't continue parsing
173234285Sdim     * because we don't know how many arguments to parse next!
174234285Sdim     */
175234285Sdim    Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
176234285Sdim    if (ACPI_FAILURE (Status))
177234285Sdim    {
178234285Sdim        return_ACPI_STATUS (Status);
179234285Sdim    }
180234285Sdim
181234285Sdim    /* If table already loaded into namespace, just return */
182234285Sdim
183234285Sdim    if (AcpiTbIsTableLoaded (TableIndex))
184234285Sdim    {
185234285Sdim        Status = AE_ALREADY_EXISTS;
186234285Sdim        goto Unlock;
187234285Sdim    }
188234285Sdim
189288943Sdim    ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
190288943Sdim        "**** Loading table into namespace ****\n"));
191288943Sdim
192288943Sdim    Status = AcpiTbAllocateOwnerId (TableIndex);
193234285Sdim    if (ACPI_FAILURE (Status))
194234285Sdim    {
195234285Sdim        goto Unlock;
196234285Sdim    }
197234285Sdim
198276479Sdim    Status = AcpiNsParseTable (TableIndex, Node->Child);
199288943Sdim    if (ACPI_SUCCESS (Status))
200288943Sdim    {
201234285Sdim        AcpiTbSetTableLoadedFlag (TableIndex, TRUE);
202234285Sdim    }
203234285Sdim    else
204234285Sdim    {
205234285Sdim        AcpiTbReleaseOwnerId (TableIndex);
206234285Sdim    }
207234285Sdim
208234285SdimUnlock:
209234285Sdim    (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
210234285Sdim
211234285Sdim    if (ACPI_FAILURE (Status))
212234285Sdim    {
213234285Sdim        return_ACPI_STATUS (Status);
214234285Sdim    }
215234285Sdim
216234285Sdim    /*
217234285Sdim     * Now we can parse the control methods.  We always parse
218234285Sdim     * them here for a sanity check, and if configured for
219234285Sdim     * just-in-time parsing, we delete the control method
220234285Sdim     * parse trees.
221234285Sdim     */
222234285Sdim    ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
223234285Sdim        "**** Begin Table Method Parsing and Object Initialization ****\n"));
224234285Sdim
225234285Sdim    Status = AcpiDsInitializeObjects (TableIndex, Node);
226234285Sdim
227234285Sdim    ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
228234285Sdim        "**** Completed Table Method Parsing and Object Initialization ****\n"));
229234285Sdim
230249423Sdim    return_ACPI_STATUS (Status);
231234285Sdim}
232288943Sdim
233288943Sdim
234288943Sdim#ifdef ACPI_OBSOLETE_FUNCTIONS
235288943Sdim/*******************************************************************************
236288943Sdim *
237288943Sdim * FUNCTION:    AcpiLoadNamespace
238288943Sdim *
239234285Sdim * PARAMETERS:  None
240234285Sdim *
241239462Sdim * RETURN:      Status
242239462Sdim *
243239462Sdim * DESCRIPTION: Load the name space from what ever is pointed to by DSDT.
244239462Sdim *              (DSDT points to either the BIOS or a buffer.)
245239462Sdim *
246234285Sdim ******************************************************************************/
247234285Sdim
248234285SdimACPI_STATUS
249234285SdimAcpiNsLoadNamespace (
250234285Sdim    void)
251234285Sdim{
252234285Sdim    ACPI_STATUS             Status;
253234285Sdim
254234285Sdim
255234285Sdim    ACPI_FUNCTION_TRACE (AcpiLoadNameSpace);
256288943Sdim
257234285Sdim
258276479Sdim    /* There must be at least a DSDT installed */
259234285Sdim
260234285Sdim    if (AcpiGbl_DSDT == NULL)
261234285Sdim    {
262288943Sdim        ACPI_ERROR ((AE_INFO, "DSDT is not in memory"));
263288943Sdim        return_ACPI_STATUS (AE_NO_ACPI_TABLES);
264288943Sdim    }
265288943Sdim
266288943Sdim    /*
267288943Sdim     * Load the namespace.  The DSDT is required,
268288943Sdim     * but the SSDT and PSDT tables are optional.
269288943Sdim     */
270234285Sdim    Status = AcpiNsLoadTableByType (ACPI_TABLE_ID_DSDT);
271234285Sdim    if (ACPI_FAILURE (Status))
272276479Sdim    {
273234982Sdim        return_ACPI_STATUS (Status);
274234285Sdim    }
275288943Sdim
276234982Sdim    /* Ignore exceptions from these */
277296417Sdim
278234285Sdim    (void) AcpiNsLoadTableByType (ACPI_TABLE_ID_SSDT);
279234982Sdim    (void) AcpiNsLoadTableByType (ACPI_TABLE_ID_PSDT);
280234982Sdim
281296417Sdim    ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT,
282296417Sdim        "ACPI Namespace successfully loaded at root %p\n",
283234285Sdim        AcpiGbl_RootNode));
284234285Sdim
285234285Sdim    return_ACPI_STATUS (Status);
286234285Sdim}
287234285Sdim#endif
288234285Sdim
289234285Sdim#ifdef ACPI_FUTURE_IMPLEMENTATION
290234285Sdim/*******************************************************************************
291276479Sdim *
292234285Sdim * FUNCTION:    AcpiNsDeleteSubtree
293276479Sdim *
294234285Sdim * PARAMETERS:  StartHandle         - Handle in namespace where search begins
295234285Sdim *
296288943Sdim * RETURNS      Status
297234285Sdim *
298234285Sdim * DESCRIPTION: Walks the namespace starting at the given handle and deletes
299234285Sdim *              all objects, entries, and scopes in the entire subtree.
300234285Sdim *
301234285Sdim *              Namespace/Interpreter should be locked or the subsystem should
302234285Sdim *              be in shutdown before this routine is called.
303234285Sdim *
304234285Sdim ******************************************************************************/
305288943Sdim
306234285Sdimstatic ACPI_STATUS
307234285SdimAcpiNsDeleteSubtree (
308234285Sdim    ACPI_HANDLE             StartHandle)
309288943Sdim{
310234285Sdim    ACPI_STATUS             Status;
311288943Sdim    ACPI_HANDLE             ChildHandle;
312234285Sdim    ACPI_HANDLE             ParentHandle;
313234285Sdim    ACPI_HANDLE             NextChildHandle;
314234285Sdim    ACPI_HANDLE             Dummy;
315234285Sdim    UINT32                  Level;
316234285Sdim
317234285Sdim
318234285Sdim    ACPI_FUNCTION_TRACE (NsDeleteSubtree);
319234285Sdim
320234285Sdim
321288943Sdim    ParentHandle = StartHandle;
322288943Sdim    ChildHandle  = NULL;
323234285Sdim    Level        = 1;
324234285Sdim
325234285Sdim    /*
326234285Sdim     * Traverse the tree of objects until we bubble back up
327234285Sdim     * to where we started.
328234285Sdim     */
329234285Sdim    while (Level > 0)
330234285Sdim    {
331234285Sdim        /* Attempt to get the next object in this scope */
332234285Sdim
333234285Sdim        Status = AcpiGetNextObject (ACPI_TYPE_ANY, ParentHandle,
334234285Sdim                                    ChildHandle, &NextChildHandle);
335234285Sdim
336234285Sdim        ChildHandle = NextChildHandle;
337234285Sdim
338234285Sdim        /* Did we get a new object? */
339234285Sdim
340234285Sdim        if (ACPI_SUCCESS (Status))
341234285Sdim        {
342234285Sdim            /* Check if this object has any children */
343234285Sdim
344234285Sdim            if (ACPI_SUCCESS (AcpiGetNextObject (ACPI_TYPE_ANY, ChildHandle,
345234285Sdim                                    NULL, &Dummy)))
346288943Sdim            {
347234285Sdim                /*
348234285Sdim                 * There is at least one child of this object,
349234285Sdim                 * visit the object
350234285Sdim                 */
351288943Sdim                Level++;
352234285Sdim                ParentHandle = ChildHandle;
353234285Sdim                ChildHandle  = NULL;
354234285Sdim            }
355234285Sdim        }
356288943Sdim        else
357288943Sdim        {
358234285Sdim            /*
359288943Sdim             * No more children in this object, go back up to
360234285Sdim             * the object's parent
361288943Sdim             */
362234285Sdim            Level--;
363234285Sdim
364234285Sdim            /* Delete all children now */
365234285Sdim
366234285Sdim            AcpiNsDeleteChildren (ChildHandle);
367234285Sdim
368234285Sdim            ChildHandle = ParentHandle;
369234285Sdim            Status = AcpiGetParent (ParentHandle, &ParentHandle);
370234285Sdim            if (ACPI_FAILURE (Status))
371234285Sdim            {
372234285Sdim                return_ACPI_STATUS (Status);
373234285Sdim            }
374234285Sdim        }
375234285Sdim    }
376234285Sdim
377234285Sdim    /* Now delete the starting object, and we are done */
378234285Sdim
379234285Sdim    AcpiNsDeleteNode (ChildHandle);
380234285Sdim
381288943Sdim    return_ACPI_STATUS (AE_OK);
382288943Sdim}
383288943Sdim
384288943Sdim
385234285Sdim/*******************************************************************************
386234285Sdim *
387276479Sdim *  FUNCTION:       AcpiNsUnloadNameSpace
388296417Sdim *
389296417Sdim *  PARAMETERS:     Handle          - Root of namespace subtree to be deleted
390296417Sdim *
391296417Sdim *  RETURN:         Status
392296417Sdim *
393296417Sdim *  DESCRIPTION:    Shrinks the namespace, typically in response to an undocking
394296417Sdim *                  event.  Deletes an entire subtree starting from (and
395296417Sdim *                  including) the given handle.
396296417Sdim *
397296417Sdim ******************************************************************************/
398296417Sdim
399296417SdimACPI_STATUS
400296417SdimAcpiNsUnloadNamespace (
401296417Sdim    ACPI_HANDLE             Handle)
402296417Sdim{
403296417Sdim    ACPI_STATUS             Status;
404296417Sdim
405296417Sdim
406296417Sdim    ACPI_FUNCTION_TRACE (NsUnloadNameSpace);
407296417Sdim
408288943Sdim
409296417Sdim    /* Parameter validation */
410296417Sdim
411296417Sdim    if (!AcpiGbl_RootNode)
412296417Sdim    {
413296417Sdim        return_ACPI_STATUS (AE_NO_NAMESPACE);
414296417Sdim    }
415296417Sdim
416296417Sdim    if (!Handle)
417296417Sdim    {
418296417Sdim        return_ACPI_STATUS (AE_BAD_PARAMETER);
419296417Sdim    }
420296417Sdim
421296417Sdim    /* This function does the real work */
422234285Sdim
423296417Sdim    Status = AcpiNsDeleteSubtree (Handle);
424296417Sdim
425296417Sdim    return_ACPI_STATUS (Status);
426296417Sdim}
427296417Sdim#endif
428234285Sdim#endif
429296417Sdim
430296417Sdim