xref: /onnv-gate/usr/src/uts/intel/io/acpica/namespace/nsload.c (revision 11225:eb6056029d84)
13446Smrj /******************************************************************************
23446Smrj  *
33446Smrj  * Module Name: nsload - namespace loading/expanding/contracting procedures
43446Smrj  *
53446Smrj  *****************************************************************************/
63446Smrj 
73446Smrj /******************************************************************************
83446Smrj  *
93446Smrj  * 1. Copyright Notice
103446Smrj  *
119980SDana.Myers@Sun.COM  * Some or all of this work - Copyright (c) 1999 - 2009, Intel Corp.
123446Smrj  * All rights reserved.
133446Smrj  *
143446Smrj  * 2. License
153446Smrj  *
163446Smrj  * 2.1. This is your license from Intel Corp. under its intellectual property
173446Smrj  * rights.  You may have additional license terms from the party that provided
183446Smrj  * you this software, covering your right to use that party's intellectual
193446Smrj  * property rights.
203446Smrj  *
213446Smrj  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
223446Smrj  * copy of the source code appearing in this file ("Covered Code") an
233446Smrj  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
243446Smrj  * base code distributed originally by Intel ("Original Intel Code") to copy,
253446Smrj  * make derivatives, distribute, use and display any portion of the Covered
263446Smrj  * Code in any form, with the right to sublicense such rights; and
273446Smrj  *
283446Smrj  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
293446Smrj  * license (with the right to sublicense), under only those claims of Intel
303446Smrj  * patents that are infringed by the Original Intel Code, to make, use, sell,
313446Smrj  * offer to sell, and import the Covered Code and derivative works thereof
323446Smrj  * solely to the minimum extent necessary to exercise the above copyright
333446Smrj  * license, and in no event shall the patent license extend to any additions
343446Smrj  * to or modifications of the Original Intel Code.  No other license or right
353446Smrj  * is granted directly or by implication, estoppel or otherwise;
363446Smrj  *
373446Smrj  * The above copyright and patent license is granted only if the following
383446Smrj  * conditions are met:
393446Smrj  *
403446Smrj  * 3. Conditions
413446Smrj  *
423446Smrj  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
433446Smrj  * Redistribution of source code of any substantial portion of the Covered
443446Smrj  * Code or modification with rights to further distribute source must include
453446Smrj  * the above Copyright Notice, the above License, this list of Conditions,
463446Smrj  * and the following Disclaimer and Export Compliance provision.  In addition,
473446Smrj  * Licensee must cause all Covered Code to which Licensee contributes to
483446Smrj  * contain a file documenting the changes Licensee made to create that Covered
493446Smrj  * Code and the date of any change.  Licensee must include in that file the
503446Smrj  * documentation of any changes made by any predecessor Licensee.  Licensee
513446Smrj  * must include a prominent statement that the modification is derived,
523446Smrj  * directly or indirectly, from Original Intel Code.
533446Smrj  *
543446Smrj  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
553446Smrj  * Redistribution of source code of any substantial portion of the Covered
563446Smrj  * Code or modification without rights to further distribute source must
573446Smrj  * include the following Disclaimer and Export Compliance provision in the
583446Smrj  * documentation and/or other materials provided with distribution.  In
593446Smrj  * addition, Licensee may not authorize further sublicense of source of any
603446Smrj  * portion of the Covered Code, and must include terms to the effect that the
613446Smrj  * license from Licensee to its licensee is limited to the intellectual
623446Smrj  * property embodied in the software Licensee provides to its licensee, and
633446Smrj  * not to intellectual property embodied in modifications its licensee may
643446Smrj  * make.
653446Smrj  *
663446Smrj  * 3.3. Redistribution of Executable. Redistribution in executable form of any
673446Smrj  * substantial portion of the Covered Code or modification must reproduce the
683446Smrj  * above Copyright Notice, and the following Disclaimer and Export Compliance
693446Smrj  * provision in the documentation and/or other materials provided with the
703446Smrj  * distribution.
713446Smrj  *
723446Smrj  * 3.4. Intel retains all right, title, and interest in and to the Original
733446Smrj  * Intel Code.
743446Smrj  *
753446Smrj  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
763446Smrj  * Intel shall be used in advertising or otherwise to promote the sale, use or
773446Smrj  * other dealings in products derived from or relating to the Covered Code
783446Smrj  * without prior written authorization from Intel.
793446Smrj  *
803446Smrj  * 4. Disclaimer and Export Compliance
813446Smrj  *
823446Smrj  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
833446Smrj  * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
843446Smrj  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
853446Smrj  * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
863446Smrj  * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
873446Smrj  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
883446Smrj  * PARTICULAR PURPOSE.
893446Smrj  *
903446Smrj  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
913446Smrj  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
923446Smrj  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
933446Smrj  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
943446Smrj  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
953446Smrj  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
963446Smrj  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
973446Smrj  * LIMITED REMEDY.
983446Smrj  *
993446Smrj  * 4.3. Licensee shall not export, either directly or indirectly, any of this
1003446Smrj  * software or system incorporating such software without first obtaining any
1013446Smrj  * required license or other approval from the U. S. Department of Commerce or
1023446Smrj  * any other agency or department of the United States Government.  In the
1033446Smrj  * event Licensee exports any such software from the United States or
1043446Smrj  * re-exports any such software from a foreign destination, Licensee shall
1053446Smrj  * ensure that the distribution and export/re-export of the software is in
1063446Smrj  * compliance with all laws, regulations, orders, or other restrictions of the
1073446Smrj  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
1083446Smrj  * any of its subsidiaries will export/re-export any technical data, process,
1093446Smrj  * software, or service, directly or indirectly, to any country for which the
1103446Smrj  * United States government or any agency thereof requires an export license,
1113446Smrj  * other governmental approval, or letter of assurance, without first obtaining
1123446Smrj  * such license, approval or letter.
1133446Smrj  *
1143446Smrj  *****************************************************************************/
1153446Smrj 
1163446Smrj #define __NSLOAD_C__
1173446Smrj 
1183446Smrj #include "acpi.h"
1199980SDana.Myers@Sun.COM #include "accommon.h"
1203446Smrj #include "acnamesp.h"
1213446Smrj #include "acdispat.h"
1227851SDana.Myers@Sun.COM #include "actables.h"
1233446Smrj 
1243446Smrj 
1253446Smrj #define _COMPONENT          ACPI_NAMESPACE
1263446Smrj         ACPI_MODULE_NAME    ("nsload")
1273446Smrj 
1283446Smrj /* Local prototypes */
1293446Smrj 
1303446Smrj #ifdef ACPI_FUTURE_IMPLEMENTATION
1313446Smrj ACPI_STATUS
1323446Smrj AcpiNsUnloadNamespace (
1333446Smrj     ACPI_HANDLE             Handle);
1343446Smrj 
1353446Smrj static ACPI_STATUS
1363446Smrj AcpiNsDeleteSubtree (
1373446Smrj     ACPI_HANDLE             StartHandle);
1383446Smrj #endif
1393446Smrj 
1403446Smrj 
1413446Smrj #ifndef ACPI_NO_METHOD_EXECUTION
1423446Smrj /*******************************************************************************
1433446Smrj  *
1443446Smrj  * FUNCTION:    AcpiNsLoadTable
1453446Smrj  *
1467851SDana.Myers@Sun.COM  * PARAMETERS:  TableIndex      - Index for table to be loaded
1473446Smrj  *              Node            - Owning NS node
1483446Smrj  *
1493446Smrj  * RETURN:      Status
1503446Smrj  *
1513446Smrj  * DESCRIPTION: Load one ACPI table into the namespace
1523446Smrj  *
1533446Smrj  ******************************************************************************/
1543446Smrj 
1553446Smrj ACPI_STATUS
AcpiNsLoadTable(UINT32 TableIndex,ACPI_NAMESPACE_NODE * Node)1563446Smrj AcpiNsLoadTable (
1577851SDana.Myers@Sun.COM     UINT32                  TableIndex,
1583446Smrj     ACPI_NAMESPACE_NODE     *Node)
1593446Smrj {
1603446Smrj     ACPI_STATUS             Status;
1613446Smrj 
1623446Smrj 
1633446Smrj     ACPI_FUNCTION_TRACE (NsLoadTable);
1643446Smrj 
1653446Smrj 
1663446Smrj     /*
1673446Smrj      * Parse the table and load the namespace with all named
1683446Smrj      * objects found within.  Control methods are NOT parsed
1693446Smrj      * at this time.  In fact, the control methods cannot be
1703446Smrj      * parsed until the entire namespace is loaded, because
1713446Smrj      * if a control method makes a forward reference (call)
1723446Smrj      * to another control method, we can't continue parsing
1733446Smrj      * because we don't know how many arguments to parse next!
1743446Smrj      */
1753446Smrj     Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
1763446Smrj     if (ACPI_FAILURE (Status))
1773446Smrj     {
1783446Smrj         return_ACPI_STATUS (Status);
1793446Smrj     }
1803446Smrj 
1817851SDana.Myers@Sun.COM     /* If table already loaded into namespace, just return */
1827851SDana.Myers@Sun.COM 
1837851SDana.Myers@Sun.COM     if (AcpiTbIsTableLoaded (TableIndex))
1847851SDana.Myers@Sun.COM     {
1857851SDana.Myers@Sun.COM         Status = AE_ALREADY_EXISTS;
1867851SDana.Myers@Sun.COM         goto Unlock;
1877851SDana.Myers@Sun.COM     }
1887851SDana.Myers@Sun.COM 
1897851SDana.Myers@Sun.COM     ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
1907851SDana.Myers@Sun.COM         "**** Loading table into namespace ****\n"));
1917851SDana.Myers@Sun.COM 
1927851SDana.Myers@Sun.COM     Status = AcpiTbAllocateOwnerId (TableIndex);
1937851SDana.Myers@Sun.COM     if (ACPI_FAILURE (Status))
1947851SDana.Myers@Sun.COM     {
1957851SDana.Myers@Sun.COM         goto Unlock;
1967851SDana.Myers@Sun.COM     }
1977851SDana.Myers@Sun.COM 
1987851SDana.Myers@Sun.COM     Status = AcpiNsParseTable (TableIndex, Node);
1997851SDana.Myers@Sun.COM     if (ACPI_SUCCESS (Status))
2007851SDana.Myers@Sun.COM     {
2017851SDana.Myers@Sun.COM         AcpiTbSetTableLoadedFlag (TableIndex, TRUE);
2027851SDana.Myers@Sun.COM     }
2037851SDana.Myers@Sun.COM     else
2047851SDana.Myers@Sun.COM     {
2057851SDana.Myers@Sun.COM         (void) AcpiTbReleaseOwnerId (TableIndex);
2067851SDana.Myers@Sun.COM     }
2077851SDana.Myers@Sun.COM 
2087851SDana.Myers@Sun.COM Unlock:
2093446Smrj     (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
2103446Smrj 
2113446Smrj     if (ACPI_FAILURE (Status))
2123446Smrj     {
2133446Smrj         return_ACPI_STATUS (Status);
2143446Smrj     }
2153446Smrj 
2163446Smrj     /*
2173446Smrj      * Now we can parse the control methods.  We always parse
2183446Smrj      * them here for a sanity check, and if configured for
2193446Smrj      * just-in-time parsing, we delete the control method
2203446Smrj      * parse trees.
2213446Smrj      */
2223446Smrj     ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
2239980SDana.Myers@Sun.COM         "**** Begin Table Method Parsing and Object Initialization\n"));
2243446Smrj 
2257851SDana.Myers@Sun.COM     Status = AcpiDsInitializeObjects (TableIndex, Node);
2263446Smrj 
2273446Smrj     ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
2289980SDana.Myers@Sun.COM         "**** Completed Table Method Parsing and Object Initialization\n"));
2293446Smrj 
2303446Smrj     return_ACPI_STATUS (Status);
2313446Smrj }
2323446Smrj 
2333446Smrj 
2347851SDana.Myers@Sun.COM #ifdef ACPI_OBSOLETE_FUNCTIONS
2353446Smrj /*******************************************************************************
2363446Smrj  *
2373446Smrj  * FUNCTION:    AcpiLoadNamespace
2383446Smrj  *
2393446Smrj  * PARAMETERS:  None
2403446Smrj  *
2413446Smrj  * RETURN:      Status
2423446Smrj  *
2433446Smrj  * DESCRIPTION: Load the name space from what ever is pointed to by DSDT.
2443446Smrj  *              (DSDT points to either the BIOS or a buffer.)
2453446Smrj  *
2463446Smrj  ******************************************************************************/
2473446Smrj 
2483446Smrj ACPI_STATUS
AcpiNsLoadNamespace(void)2493446Smrj AcpiNsLoadNamespace (
2503446Smrj     void)
2513446Smrj {
2523446Smrj     ACPI_STATUS             Status;
2533446Smrj 
2543446Smrj 
2553446Smrj     ACPI_FUNCTION_TRACE (AcpiLoadNameSpace);
2563446Smrj 
2573446Smrj 
2583446Smrj     /* There must be at least a DSDT installed */
2593446Smrj 
2603446Smrj     if (AcpiGbl_DSDT == NULL)
2613446Smrj     {
2623446Smrj         ACPI_ERROR ((AE_INFO, "DSDT is not in memory"));
2633446Smrj         return_ACPI_STATUS (AE_NO_ACPI_TABLES);
2643446Smrj     }
2653446Smrj 
2663446Smrj     /*
2673446Smrj      * Load the namespace.  The DSDT is required,
2683446Smrj      * but the SSDT and PSDT tables are optional.
2693446Smrj      */
2703446Smrj     Status = AcpiNsLoadTableByType (ACPI_TABLE_ID_DSDT);
2713446Smrj     if (ACPI_FAILURE (Status))
2723446Smrj     {
2733446Smrj         return_ACPI_STATUS (Status);
2743446Smrj     }
2753446Smrj 
2763446Smrj     /* Ignore exceptions from these */
2773446Smrj 
2783446Smrj     (void) AcpiNsLoadTableByType (ACPI_TABLE_ID_SSDT);
2793446Smrj     (void) AcpiNsLoadTableByType (ACPI_TABLE_ID_PSDT);
2803446Smrj 
2813446Smrj     ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT,
2823446Smrj         "ACPI Namespace successfully loaded at root %p\n",
2833446Smrj         AcpiGbl_RootNode));
2843446Smrj 
2853446Smrj     return_ACPI_STATUS (Status);
2863446Smrj }
2877851SDana.Myers@Sun.COM #endif
2883446Smrj 
2893446Smrj #ifdef ACPI_FUTURE_IMPLEMENTATION
2903446Smrj /*******************************************************************************
2913446Smrj  *
2923446Smrj  * FUNCTION:    AcpiNsDeleteSubtree
2933446Smrj  *
2943446Smrj  * PARAMETERS:  StartHandle         - Handle in namespace where search begins
2953446Smrj  *
2963446Smrj  * RETURNS      Status
2973446Smrj  *
2983446Smrj  * DESCRIPTION: Walks the namespace starting at the given handle and deletes
2993446Smrj  *              all objects, entries, and scopes in the entire subtree.
3003446Smrj  *
3013446Smrj  *              Namespace/Interpreter should be locked or the subsystem should
3023446Smrj  *              be in shutdown before this routine is called.
3033446Smrj  *
3043446Smrj  ******************************************************************************/
3053446Smrj 
3063446Smrj static ACPI_STATUS
AcpiNsDeleteSubtree(ACPI_HANDLE StartHandle)3073446Smrj AcpiNsDeleteSubtree (
3083446Smrj     ACPI_HANDLE             StartHandle)
3093446Smrj {
3103446Smrj     ACPI_STATUS             Status;
3113446Smrj     ACPI_HANDLE             ChildHandle;
3123446Smrj     ACPI_HANDLE             ParentHandle;
3133446Smrj     ACPI_HANDLE             NextChildHandle;
3143446Smrj     ACPI_HANDLE             Dummy;
3153446Smrj     UINT32                  Level;
3163446Smrj 
3173446Smrj 
3183446Smrj     ACPI_FUNCTION_TRACE (NsDeleteSubtree);
3193446Smrj 
3203446Smrj 
3213446Smrj     ParentHandle = StartHandle;
3223446Smrj     ChildHandle  = NULL;
3233446Smrj     Level        = 1;
3243446Smrj 
3253446Smrj     /*
3263446Smrj      * Traverse the tree of objects until we bubble back up
3273446Smrj      * to where we started.
3283446Smrj      */
3293446Smrj     while (Level > 0)
3303446Smrj     {
3313446Smrj         /* Attempt to get the next object in this scope */
3323446Smrj 
3333446Smrj         Status = AcpiGetNextObject (ACPI_TYPE_ANY, ParentHandle,
3343446Smrj                                     ChildHandle, &NextChildHandle);
3353446Smrj 
3363446Smrj         ChildHandle = NextChildHandle;
3373446Smrj 
3383446Smrj         /* Did we get a new object? */
3393446Smrj 
3403446Smrj         if (ACPI_SUCCESS (Status))
3413446Smrj         {
3423446Smrj             /* Check if this object has any children */
3433446Smrj 
3443446Smrj             if (ACPI_SUCCESS (AcpiGetNextObject (ACPI_TYPE_ANY, ChildHandle,
3453446Smrj                                     NULL, &Dummy)))
3463446Smrj             {
3473446Smrj                 /*
3483446Smrj                  * There is at least one child of this object,
3493446Smrj                  * visit the object
3503446Smrj                  */
3513446Smrj                 Level++;
3523446Smrj                 ParentHandle = ChildHandle;
3533446Smrj                 ChildHandle  = NULL;
3543446Smrj             }
3553446Smrj         }
3563446Smrj         else
3573446Smrj         {
3583446Smrj             /*
3593446Smrj              * No more children in this object, go back up to
3603446Smrj              * the object's parent
3613446Smrj              */
3623446Smrj             Level--;
3633446Smrj 
3643446Smrj             /* Delete all children now */
3653446Smrj 
3663446Smrj             AcpiNsDeleteChildren (ChildHandle);
3673446Smrj 
3683446Smrj             ChildHandle = ParentHandle;
3693446Smrj             Status = AcpiGetParent (ParentHandle, &ParentHandle);
3703446Smrj             if (ACPI_FAILURE (Status))
3713446Smrj             {
3723446Smrj                 return_ACPI_STATUS (Status);
3733446Smrj             }
3743446Smrj         }
3753446Smrj     }
3763446Smrj 
3773446Smrj     /* Now delete the starting object, and we are done */
3783446Smrj 
379*11225SDana.Myers@Sun.COM     AcpiNsRemoveNode (ChildHandle);
3803446Smrj     return_ACPI_STATUS (AE_OK);
3813446Smrj }
3823446Smrj 
3833446Smrj 
3843446Smrj /*******************************************************************************
3853446Smrj  *
3863446Smrj  *  FUNCTION:       AcpiNsUnloadNameSpace
3873446Smrj  *
3883446Smrj  *  PARAMETERS:     Handle          - Root of namespace subtree to be deleted
3893446Smrj  *
3903446Smrj  *  RETURN:         Status
3913446Smrj  *
3923446Smrj  *  DESCRIPTION:    Shrinks the namespace, typically in response to an undocking
3933446Smrj  *                  event.  Deletes an entire subtree starting from (and
3943446Smrj  *                  including) the given handle.
3953446Smrj  *
3963446Smrj  ******************************************************************************/
3973446Smrj 
3983446Smrj ACPI_STATUS
AcpiNsUnloadNamespace(ACPI_HANDLE Handle)3993446Smrj AcpiNsUnloadNamespace (
4003446Smrj     ACPI_HANDLE             Handle)
4013446Smrj {
4023446Smrj     ACPI_STATUS             Status;
4033446Smrj 
4043446Smrj 
4053446Smrj     ACPI_FUNCTION_TRACE (NsUnloadNameSpace);
4063446Smrj 
4073446Smrj 
4083446Smrj     /* Parameter validation */
4093446Smrj 
4103446Smrj     if (!AcpiGbl_RootNode)
4113446Smrj     {
4123446Smrj         return_ACPI_STATUS (AE_NO_NAMESPACE);
4133446Smrj     }
4143446Smrj 
4153446Smrj     if (!Handle)
4163446Smrj     {
4173446Smrj         return_ACPI_STATUS (AE_BAD_PARAMETER);
4183446Smrj     }
4193446Smrj 
4203446Smrj     /* This function does the real work */
4213446Smrj 
4223446Smrj     Status = AcpiNsDeleteSubtree (Handle);
4233446Smrj 
4243446Smrj     return_ACPI_STATUS (Status);
4253446Smrj }
4263446Smrj #endif
4273446Smrj #endif
4283446Smrj 
429