Home | History | Annotate | Line # | Download | only in namespace
nsinit.c revision 1.14.2.3
      1       1.1    jruoho /******************************************************************************
      2       1.1    jruoho  *
      3       1.1    jruoho  * Module Name: nsinit - namespace initialization
      4       1.1    jruoho  *
      5       1.1    jruoho  *****************************************************************************/
      6       1.1    jruoho 
      7       1.3    jruoho /*
      8  1.14.2.2    martin  * Copyright (C) 2000 - 2020, Intel Corp.
      9       1.1    jruoho  * All rights reserved.
     10       1.1    jruoho  *
     11       1.3    jruoho  * Redistribution and use in source and binary forms, with or without
     12       1.3    jruoho  * modification, are permitted provided that the following conditions
     13       1.3    jruoho  * are met:
     14       1.3    jruoho  * 1. Redistributions of source code must retain the above copyright
     15       1.3    jruoho  *    notice, this list of conditions, and the following disclaimer,
     16       1.3    jruoho  *    without modification.
     17       1.3    jruoho  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
     18       1.3    jruoho  *    substantially similar to the "NO WARRANTY" disclaimer below
     19       1.3    jruoho  *    ("Disclaimer") and any redistribution must be conditioned upon
     20       1.3    jruoho  *    including a substantially similar Disclaimer requirement for further
     21       1.3    jruoho  *    binary redistribution.
     22       1.3    jruoho  * 3. Neither the names of the above-listed copyright holders nor the names
     23       1.3    jruoho  *    of any contributors may be used to endorse or promote products derived
     24       1.3    jruoho  *    from this software without specific prior written permission.
     25       1.3    jruoho  *
     26       1.3    jruoho  * Alternatively, this software may be distributed under the terms of the
     27       1.3    jruoho  * GNU General Public License ("GPL") version 2 as published by the Free
     28       1.3    jruoho  * Software Foundation.
     29       1.3    jruoho  *
     30       1.3    jruoho  * NO WARRANTY
     31       1.3    jruoho  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     32       1.3    jruoho  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     33       1.3    jruoho  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
     34       1.3    jruoho  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     35       1.3    jruoho  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     36       1.3    jruoho  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     37       1.3    jruoho  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     38       1.3    jruoho  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     39       1.3    jruoho  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     40       1.3    jruoho  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     41       1.3    jruoho  * POSSIBILITY OF SUCH DAMAGES.
     42       1.3    jruoho  */
     43       1.1    jruoho 
     44       1.1    jruoho #include "acpi.h"
     45       1.1    jruoho #include "accommon.h"
     46       1.1    jruoho #include "acnamesp.h"
     47       1.1    jruoho #include "acdispat.h"
     48       1.1    jruoho #include "acinterp.h"
     49      1.11  christos #include "acevents.h"
     50       1.1    jruoho 
     51       1.1    jruoho #define _COMPONENT          ACPI_NAMESPACE
     52       1.1    jruoho         ACPI_MODULE_NAME    ("nsinit")
     53       1.1    jruoho 
     54       1.1    jruoho /* Local prototypes */
     55       1.1    jruoho 
     56       1.1    jruoho static ACPI_STATUS
     57       1.1    jruoho AcpiNsInitOneObject (
     58       1.1    jruoho     ACPI_HANDLE             ObjHandle,
     59       1.1    jruoho     UINT32                  Level,
     60       1.1    jruoho     void                    *Context,
     61       1.1    jruoho     void                    **ReturnValue);
     62       1.1    jruoho 
     63       1.1    jruoho static ACPI_STATUS
     64       1.1    jruoho AcpiNsInitOneDevice (
     65       1.1    jruoho     ACPI_HANDLE             ObjHandle,
     66       1.1    jruoho     UINT32                  NestingLevel,
     67       1.1    jruoho     void                    *Context,
     68       1.1    jruoho     void                    **ReturnValue);
     69       1.1    jruoho 
     70       1.1    jruoho static ACPI_STATUS
     71       1.1    jruoho AcpiNsFindIniMethods (
     72       1.1    jruoho     ACPI_HANDLE             ObjHandle,
     73       1.1    jruoho     UINT32                  NestingLevel,
     74       1.1    jruoho     void                    *Context,
     75       1.1    jruoho     void                    **ReturnValue);
     76       1.1    jruoho 
     77       1.1    jruoho 
     78       1.1    jruoho /*******************************************************************************
     79       1.1    jruoho  *
     80       1.1    jruoho  * FUNCTION:    AcpiNsInitializeObjects
     81       1.1    jruoho  *
     82       1.1    jruoho  * PARAMETERS:  None
     83       1.1    jruoho  *
     84       1.1    jruoho  * RETURN:      Status
     85       1.1    jruoho  *
     86       1.1    jruoho  * DESCRIPTION: Walk the entire namespace and perform any necessary
     87       1.1    jruoho  *              initialization on the objects found therein
     88       1.1    jruoho  *
     89       1.1    jruoho  ******************************************************************************/
     90       1.1    jruoho 
     91       1.1    jruoho ACPI_STATUS
     92       1.1    jruoho AcpiNsInitializeObjects (
     93       1.1    jruoho     void)
     94       1.1    jruoho {
     95       1.1    jruoho     ACPI_STATUS             Status;
     96       1.1    jruoho     ACPI_INIT_WALK_INFO     Info;
     97       1.1    jruoho 
     98       1.1    jruoho 
     99       1.1    jruoho     ACPI_FUNCTION_TRACE (NsInitializeObjects);
    100       1.1    jruoho 
    101       1.1    jruoho 
    102      1.11  christos     ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
    103      1.11  christos         "[Init] Completing Initialization of ACPI Objects\n"));
    104       1.1    jruoho     ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
    105       1.1    jruoho         "**** Starting initialization of namespace objects ****\n"));
    106       1.1    jruoho     ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT,
    107  1.14.2.3    martin         "Final data object initialization: "));
    108       1.1    jruoho 
    109  1.14.2.3    martin     /* Clear the info block */
    110       1.1    jruoho 
    111       1.9  christos     memset (&Info, 0, sizeof (ACPI_INIT_WALK_INFO));
    112       1.1    jruoho 
    113       1.1    jruoho     /* Walk entire namespace from the supplied root */
    114       1.1    jruoho 
    115  1.14.2.3    martin     /*
    116  1.14.2.3    martin      * TBD: will become ACPI_TYPE_PACKAGE as this type object
    117  1.14.2.3    martin      * is now the only one that supports deferred initialization
    118  1.14.2.3    martin      * (forward references).
    119  1.14.2.3    martin      */
    120       1.1    jruoho     Status = AcpiWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT,
    121  1.14.2.3    martin         ACPI_UINT32_MAX, AcpiNsInitOneObject, NULL, &Info, NULL);
    122       1.1    jruoho     if (ACPI_FAILURE (Status))
    123       1.1    jruoho     {
    124       1.1    jruoho         ACPI_EXCEPTION ((AE_INFO, Status, "During WalkNamespace"));
    125       1.1    jruoho     }
    126       1.1    jruoho 
    127       1.1    jruoho     ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT,
    128  1.14.2.3    martin         "Namespace contains %u (0x%X) objects\n",
    129  1.14.2.3    martin         Info.ObjectCount,
    130  1.14.2.3    martin         Info.ObjectCount));
    131       1.1    jruoho 
    132       1.1    jruoho     ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
    133       1.6  christos         "%u Control Methods found\n%u Op Regions found\n",
    134       1.6  christos         Info.MethodCount, Info.OpRegionCount));
    135       1.1    jruoho 
    136       1.1    jruoho     return_ACPI_STATUS (AE_OK);
    137       1.1    jruoho }
    138       1.1    jruoho 
    139       1.1    jruoho 
    140       1.1    jruoho /*******************************************************************************
    141       1.1    jruoho  *
    142       1.1    jruoho  * FUNCTION:    AcpiNsInitializeDevices
    143       1.1    jruoho  *
    144       1.1    jruoho  * PARAMETERS:  None
    145       1.1    jruoho  *
    146       1.1    jruoho  * RETURN:      ACPI_STATUS
    147       1.1    jruoho  *
    148       1.1    jruoho  * DESCRIPTION: Walk the entire namespace and initialize all ACPI devices.
    149       1.1    jruoho  *              This means running _INI on all present devices.
    150       1.1    jruoho  *
    151       1.1    jruoho  *              Note: We install PCI config space handler on region access,
    152       1.1    jruoho  *              not here.
    153       1.1    jruoho  *
    154       1.1    jruoho  ******************************************************************************/
    155       1.1    jruoho 
    156       1.1    jruoho ACPI_STATUS
    157       1.1    jruoho AcpiNsInitializeDevices (
    158      1.11  christos     UINT32                  Flags)
    159       1.1    jruoho {
    160      1.11  christos     ACPI_STATUS             Status = AE_OK;
    161       1.1    jruoho     ACPI_DEVICE_WALK_INFO   Info;
    162      1.11  christos     ACPI_HANDLE             Handle;
    163       1.1    jruoho 
    164       1.1    jruoho 
    165       1.1    jruoho     ACPI_FUNCTION_TRACE (NsInitializeDevices);
    166       1.1    jruoho 
    167       1.1    jruoho 
    168      1.11  christos     if (!(Flags & ACPI_NO_DEVICE_INIT))
    169      1.11  christos     {
    170      1.11  christos         ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
    171      1.11  christos             "[Init] Initializing ACPI Devices\n"));
    172       1.1    jruoho 
    173      1.11  christos         /* Init counters */
    174       1.1    jruoho 
    175      1.11  christos         Info.DeviceCount = 0;
    176      1.11  christos         Info.Num_STA = 0;
    177      1.11  christos         Info.Num_INI = 0;
    178       1.1    jruoho 
    179      1.11  christos         ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT,
    180      1.11  christos             "Initializing Device/Processor/Thermal objects "
    181      1.11  christos             "and executing _INI/_STA methods:\n"));
    182       1.1    jruoho 
    183      1.11  christos         /* Tree analysis: find all subtrees that contain _INI methods */
    184       1.1    jruoho 
    185      1.11  christos         Status = AcpiNsWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT,
    186      1.11  christos             ACPI_UINT32_MAX, FALSE, AcpiNsFindIniMethods, NULL, &Info, NULL);
    187      1.11  christos         if (ACPI_FAILURE (Status))
    188      1.11  christos         {
    189      1.11  christos             goto ErrorExit;
    190      1.11  christos         }
    191       1.1    jruoho 
    192      1.11  christos         /* Allocate the evaluation information block */
    193       1.1    jruoho 
    194      1.11  christos         Info.EvaluateInfo = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_EVALUATE_INFO));
    195      1.11  christos         if (!Info.EvaluateInfo)
    196      1.11  christos         {
    197      1.11  christos             Status = AE_NO_MEMORY;
    198      1.11  christos             goto ErrorExit;
    199      1.11  christos         }
    200       1.1    jruoho 
    201      1.11  christos         /*
    202      1.11  christos          * Execute the "global" _INI method that may appear at the root.
    203      1.11  christos          * This support is provided for Windows compatibility (Vista+) and
    204      1.11  christos          * is not part of the ACPI specification.
    205      1.11  christos          */
    206      1.11  christos         Info.EvaluateInfo->PrefixNode = AcpiGbl_RootNode;
    207      1.11  christos         Info.EvaluateInfo->RelativePathname = METHOD_NAME__INI;
    208      1.11  christos         Info.EvaluateInfo->Parameters = NULL;
    209      1.11  christos         Info.EvaluateInfo->Flags = ACPI_IGNORE_RETURN_VALUE;
    210       1.1    jruoho 
    211      1.11  christos         Status = AcpiNsEvaluate (Info.EvaluateInfo);
    212      1.11  christos         if (ACPI_SUCCESS (Status))
    213      1.11  christos         {
    214      1.11  christos             Info.Num_INI++;
    215      1.11  christos         }
    216       1.1    jruoho 
    217      1.11  christos         /*
    218      1.11  christos          * Execute \_SB._INI.
    219      1.11  christos          * There appears to be a strict order requirement for \_SB._INI,
    220      1.11  christos          * which should be evaluated before any _REG evaluations.
    221      1.11  christos          */
    222      1.11  christos         Status = AcpiGetHandle (NULL, "\\_SB", &Handle);
    223      1.11  christos         if (ACPI_SUCCESS (Status))
    224      1.11  christos         {
    225      1.11  christos             memset (Info.EvaluateInfo, 0, sizeof (ACPI_EVALUATE_INFO));
    226      1.11  christos             Info.EvaluateInfo->PrefixNode = Handle;
    227      1.11  christos             Info.EvaluateInfo->RelativePathname = METHOD_NAME__INI;
    228      1.11  christos             Info.EvaluateInfo->Parameters = NULL;
    229      1.11  christos             Info.EvaluateInfo->Flags = ACPI_IGNORE_RETURN_VALUE;
    230      1.11  christos 
    231      1.11  christos             Status = AcpiNsEvaluate (Info.EvaluateInfo);
    232      1.11  christos             if (ACPI_SUCCESS (Status))
    233      1.11  christos             {
    234      1.11  christos                 Info.Num_INI++;
    235      1.11  christos             }
    236      1.11  christos         }
    237      1.11  christos     }
    238       1.1    jruoho 
    239       1.1    jruoho     /*
    240      1.11  christos      * Run all _REG methods
    241      1.11  christos      *
    242      1.11  christos      * Note: Any objects accessed by the _REG methods will be automatically
    243      1.11  christos      * initialized, even if they contain executable AML (see the call to
    244      1.11  christos      * AcpiNsInitializeObjects below).
    245      1.11  christos      *
    246      1.11  christos      * Note: According to the ACPI specification, we actually needn't execute
    247      1.11  christos      * _REG for SystemMemory/SystemIo operation regions, but for PCI_Config
    248      1.11  christos      * operation regions, it is required to evaluate _REG for those on a PCI
    249      1.11  christos      * root bus that doesn't contain _BBN object. So this code is kept here
    250      1.11  christos      * in order not to break things.
    251       1.1    jruoho      */
    252      1.11  christos     if (!(Flags & ACPI_NO_ADDRESS_SPACE_INIT))
    253       1.1    jruoho     {
    254      1.11  christos         ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
    255      1.11  christos             "[Init] Executing _REG OpRegion methods\n"));
    256      1.11  christos 
    257      1.11  christos         Status = AcpiEvInitializeOpRegions ();
    258      1.11  christos         if (ACPI_FAILURE (Status))
    259      1.11  christos         {
    260      1.11  christos             goto ErrorExit;
    261      1.11  christos         }
    262       1.1    jruoho     }
    263       1.1    jruoho 
    264      1.11  christos     if (!(Flags & ACPI_NO_DEVICE_INIT))
    265       1.1    jruoho     {
    266      1.11  christos         /* Walk namespace to execute all _INIs on present devices */
    267      1.11  christos 
    268      1.11  christos         Status = AcpiNsWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT,
    269      1.11  christos             ACPI_UINT32_MAX, FALSE, AcpiNsInitOneDevice, NULL, &Info, NULL);
    270      1.11  christos 
    271      1.11  christos         /*
    272      1.11  christos          * Any _OSI requests should be completed by now. If the BIOS has
    273      1.11  christos          * requested any Windows OSI strings, we will always truncate
    274      1.11  christos          * I/O addresses to 16 bits -- for Windows compatibility.
    275      1.11  christos          */
    276      1.11  christos         if (AcpiGbl_OsiData >= ACPI_OSI_WIN_2000)
    277      1.11  christos         {
    278      1.11  christos             AcpiGbl_TruncateIoAddresses = TRUE;
    279      1.11  christos         }
    280      1.11  christos 
    281      1.11  christos         ACPI_FREE (Info.EvaluateInfo);
    282      1.11  christos         if (ACPI_FAILURE (Status))
    283      1.11  christos         {
    284      1.11  christos             goto ErrorExit;
    285      1.11  christos         }
    286      1.11  christos 
    287      1.11  christos         ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT,
    288      1.11  christos             "    Executed %u _INI methods requiring %u _STA executions "
    289      1.11  christos             "(examined %u objects)\n",
    290      1.11  christos             Info.Num_INI, Info.Num_STA, Info.DeviceCount));
    291       1.1    jruoho     }
    292       1.1    jruoho 
    293       1.1    jruoho     return_ACPI_STATUS (Status);
    294       1.1    jruoho 
    295       1.1    jruoho 
    296       1.1    jruoho ErrorExit:
    297       1.1    jruoho     ACPI_EXCEPTION ((AE_INFO, Status, "During device initialization"));
    298       1.1    jruoho     return_ACPI_STATUS (Status);
    299       1.1    jruoho }
    300       1.1    jruoho 
    301       1.1    jruoho 
    302       1.1    jruoho /*******************************************************************************
    303       1.1    jruoho  *
    304  1.14.2.1  christos  * FUNCTION:    AcpiNsInitOnePackage
    305  1.14.2.1  christos  *
    306  1.14.2.1  christos  * PARAMETERS:  ObjHandle       - Node
    307  1.14.2.1  christos  *              Level           - Current nesting level
    308  1.14.2.1  christos  *              Context         - Not used
    309  1.14.2.1  christos  *              ReturnValue     - Not used
    310  1.14.2.1  christos  *
    311  1.14.2.1  christos  * RETURN:      Status
    312  1.14.2.1  christos  *
    313  1.14.2.1  christos  * DESCRIPTION: Callback from AcpiWalkNamespace. Invoked for every package
    314  1.14.2.1  christos  *              within the namespace. Used during dynamic load of an SSDT.
    315  1.14.2.1  christos  *
    316  1.14.2.1  christos  ******************************************************************************/
    317  1.14.2.1  christos 
    318  1.14.2.1  christos ACPI_STATUS
    319  1.14.2.1  christos AcpiNsInitOnePackage (
    320  1.14.2.1  christos     ACPI_HANDLE             ObjHandle,
    321  1.14.2.1  christos     UINT32                  Level,
    322  1.14.2.1  christos     void                    *Context,
    323  1.14.2.1  christos     void                    **ReturnValue)
    324  1.14.2.1  christos {
    325  1.14.2.1  christos     ACPI_STATUS             Status;
    326  1.14.2.1  christos     ACPI_OPERAND_OBJECT     *ObjDesc;
    327  1.14.2.1  christos     ACPI_NAMESPACE_NODE     *Node = (ACPI_NAMESPACE_NODE *) ObjHandle;
    328  1.14.2.1  christos 
    329  1.14.2.1  christos 
    330  1.14.2.1  christos     ObjDesc = AcpiNsGetAttachedObject (Node);
    331  1.14.2.1  christos     if (!ObjDesc)
    332  1.14.2.1  christos     {
    333  1.14.2.1  christos         return (AE_OK);
    334  1.14.2.1  christos     }
    335  1.14.2.1  christos 
    336  1.14.2.1  christos     /* Exit if package is already initialized */
    337  1.14.2.1  christos 
    338  1.14.2.1  christos     if (ObjDesc->Package.Flags & AOPOBJ_DATA_VALID)
    339  1.14.2.1  christos     {
    340  1.14.2.1  christos         return (AE_OK);
    341  1.14.2.1  christos     }
    342  1.14.2.1  christos 
    343  1.14.2.1  christos     Status = AcpiDsGetPackageArguments (ObjDesc);
    344  1.14.2.1  christos     if (ACPI_FAILURE (Status))
    345  1.14.2.1  christos     {
    346  1.14.2.1  christos         return (AE_OK);
    347  1.14.2.1  christos     }
    348  1.14.2.1  christos 
    349  1.14.2.1  christos     Status = AcpiUtWalkPackageTree (ObjDesc, NULL, AcpiDsInitPackageElement,
    350  1.14.2.1  christos         NULL);
    351  1.14.2.1  christos     if (ACPI_FAILURE (Status))
    352  1.14.2.1  christos     {
    353  1.14.2.1  christos         return (AE_OK);
    354  1.14.2.1  christos     }
    355  1.14.2.1  christos 
    356  1.14.2.1  christos     ObjDesc->Package.Flags |= AOPOBJ_DATA_VALID;
    357  1.14.2.1  christos     return (AE_OK);
    358  1.14.2.1  christos }
    359  1.14.2.1  christos 
    360  1.14.2.1  christos 
    361  1.14.2.1  christos /*******************************************************************************
    362  1.14.2.1  christos  *
    363       1.1    jruoho  * FUNCTION:    AcpiNsInitOneObject
    364       1.1    jruoho  *
    365       1.1    jruoho  * PARAMETERS:  ObjHandle       - Node
    366       1.1    jruoho  *              Level           - Current nesting level
    367       1.1    jruoho  *              Context         - Points to a init info struct
    368       1.1    jruoho  *              ReturnValue     - Not used
    369       1.1    jruoho  *
    370       1.1    jruoho  * RETURN:      Status
    371       1.1    jruoho  *
    372       1.4  christos  * DESCRIPTION: Callback from AcpiWalkNamespace. Invoked for every object
    373      1.14  christos  *              within the namespace.
    374       1.1    jruoho  *
    375       1.1    jruoho  *              Currently, the only objects that require initialization are:
    376       1.1    jruoho  *              1) Methods
    377       1.1    jruoho  *              2) Op Regions
    378       1.1    jruoho  *
    379       1.1    jruoho  ******************************************************************************/
    380       1.1    jruoho 
    381       1.1    jruoho static ACPI_STATUS
    382       1.1    jruoho AcpiNsInitOneObject (
    383       1.1    jruoho     ACPI_HANDLE             ObjHandle,
    384       1.1    jruoho     UINT32                  Level,
    385       1.1    jruoho     void                    *Context,
    386       1.1    jruoho     void                    **ReturnValue)
    387       1.1    jruoho {
    388       1.1    jruoho     ACPI_OBJECT_TYPE        Type;
    389       1.1    jruoho     ACPI_STATUS             Status = AE_OK;
    390       1.1    jruoho     ACPI_INIT_WALK_INFO     *Info = (ACPI_INIT_WALK_INFO *) Context;
    391       1.1    jruoho     ACPI_NAMESPACE_NODE     *Node = (ACPI_NAMESPACE_NODE *) ObjHandle;
    392       1.1    jruoho     ACPI_OPERAND_OBJECT     *ObjDesc;
    393       1.1    jruoho 
    394       1.1    jruoho 
    395       1.1    jruoho     ACPI_FUNCTION_NAME (NsInitOneObject);
    396       1.1    jruoho 
    397       1.1    jruoho 
    398       1.1    jruoho     Info->ObjectCount++;
    399       1.1    jruoho 
    400       1.1    jruoho     /* And even then, we are only interested in a few object types */
    401       1.1    jruoho 
    402       1.1    jruoho     Type = AcpiNsGetType (ObjHandle);
    403       1.1    jruoho     ObjDesc = AcpiNsGetAttachedObject (Node);
    404       1.1    jruoho     if (!ObjDesc)
    405       1.1    jruoho     {
    406       1.1    jruoho         return (AE_OK);
    407       1.1    jruoho     }
    408       1.1    jruoho 
    409       1.1    jruoho     /* Increment counters for object types we are looking for */
    410       1.1    jruoho 
    411       1.1    jruoho     switch (Type)
    412       1.1    jruoho     {
    413       1.1    jruoho     case ACPI_TYPE_REGION:
    414       1.4  christos 
    415       1.1    jruoho         Info->OpRegionCount++;
    416       1.1    jruoho         break;
    417       1.1    jruoho 
    418       1.1    jruoho     case ACPI_TYPE_BUFFER_FIELD:
    419       1.4  christos 
    420       1.1    jruoho         Info->FieldCount++;
    421       1.1    jruoho         break;
    422       1.1    jruoho 
    423       1.1    jruoho     case ACPI_TYPE_LOCAL_BANK_FIELD:
    424       1.4  christos 
    425       1.1    jruoho         Info->FieldCount++;
    426       1.1    jruoho         break;
    427       1.1    jruoho 
    428       1.1    jruoho     case ACPI_TYPE_BUFFER:
    429       1.4  christos 
    430       1.1    jruoho         Info->BufferCount++;
    431       1.1    jruoho         break;
    432       1.1    jruoho 
    433       1.1    jruoho     case ACPI_TYPE_PACKAGE:
    434       1.4  christos 
    435       1.1    jruoho         Info->PackageCount++;
    436       1.1    jruoho         break;
    437       1.1    jruoho 
    438       1.1    jruoho     default:
    439       1.1    jruoho 
    440       1.1    jruoho         /* No init required, just exit now */
    441       1.4  christos 
    442       1.1    jruoho         return (AE_OK);
    443       1.1    jruoho     }
    444       1.1    jruoho 
    445       1.1    jruoho     /* If the object is already initialized, nothing else to do */
    446       1.1    jruoho 
    447       1.1    jruoho     if (ObjDesc->Common.Flags & AOPOBJ_DATA_VALID)
    448       1.1    jruoho     {
    449       1.1    jruoho         return (AE_OK);
    450       1.1    jruoho     }
    451       1.1    jruoho 
    452       1.1    jruoho     /* Must lock the interpreter before executing AML code */
    453       1.1    jruoho 
    454       1.1    jruoho     AcpiExEnterInterpreter ();
    455       1.1    jruoho 
    456       1.1    jruoho     /*
    457  1.14.2.3    martin      * Only initialization of Package objects can be deferred, in order
    458  1.14.2.3    martin      * to support forward references.
    459       1.1    jruoho      */
    460       1.1    jruoho     switch (Type)
    461       1.1    jruoho     {
    462       1.1    jruoho     case ACPI_TYPE_LOCAL_BANK_FIELD:
    463       1.1    jruoho 
    464  1.14.2.3    martin         /* TBD: BankFields do not require deferred init, remove this code */
    465  1.14.2.3    martin 
    466       1.1    jruoho         Info->FieldInit++;
    467       1.1    jruoho         Status = AcpiDsGetBankFieldArguments (ObjDesc);
    468       1.1    jruoho         break;
    469       1.1    jruoho 
    470       1.1    jruoho     case ACPI_TYPE_PACKAGE:
    471       1.1    jruoho 
    472  1.14.2.1  christos         /* Complete the initialization/resolution of the package object */
    473      1.14  christos 
    474  1.14.2.1  christos         Info->PackageInit++;
    475  1.14.2.1  christos         Status = AcpiNsInitOnePackage (ObjHandle, Level, NULL, NULL);
    476       1.1    jruoho         break;
    477       1.1    jruoho 
    478       1.1    jruoho     default:
    479       1.4  christos 
    480  1.14.2.3    martin         /* No other types should get here */
    481       1.4  christos 
    482  1.14.2.3    martin         Status = AE_TYPE;
    483  1.14.2.3    martin         ACPI_EXCEPTION ((AE_INFO, Status,
    484  1.14.2.3    martin             "Opcode is not deferred [%4.4s] (%s)",
    485  1.14.2.3    martin             AcpiUtGetNodeName (Node), AcpiUtGetTypeName (Type)));
    486       1.1    jruoho         break;
    487       1.1    jruoho     }
    488       1.1    jruoho 
    489       1.1    jruoho     if (ACPI_FAILURE (Status))
    490       1.1    jruoho     {
    491       1.1    jruoho         ACPI_EXCEPTION ((AE_INFO, Status,
    492       1.1    jruoho             "Could not execute arguments for [%4.4s] (%s)",
    493       1.1    jruoho             AcpiUtGetNodeName (Node), AcpiUtGetTypeName (Type)));
    494       1.1    jruoho     }
    495       1.1    jruoho 
    496       1.1    jruoho     /*
    497       1.1    jruoho      * We ignore errors from above, and always return OK, since we don't want
    498       1.1    jruoho      * to abort the walk on any single error.
    499       1.1    jruoho      */
    500       1.1    jruoho     AcpiExExitInterpreter ();
    501       1.1    jruoho     return (AE_OK);
    502       1.1    jruoho }
    503       1.1    jruoho 
    504       1.1    jruoho 
    505       1.1    jruoho /*******************************************************************************
    506       1.1    jruoho  *
    507       1.1    jruoho  * FUNCTION:    AcpiNsFindIniMethods
    508       1.1    jruoho  *
    509       1.1    jruoho  * PARAMETERS:  ACPI_WALK_CALLBACK
    510       1.1    jruoho  *
    511       1.1    jruoho  * RETURN:      ACPI_STATUS
    512       1.1    jruoho  *
    513       1.1    jruoho  * DESCRIPTION: Called during namespace walk. Finds objects named _INI under
    514       1.1    jruoho  *              device/processor/thermal objects, and marks the entire subtree
    515       1.1    jruoho  *              with a SUBTREE_HAS_INI flag. This flag is used during the
    516       1.1    jruoho  *              subsequent device initialization walk to avoid entire subtrees
    517       1.1    jruoho  *              that do not contain an _INI.
    518       1.1    jruoho  *
    519       1.1    jruoho  ******************************************************************************/
    520       1.1    jruoho 
    521       1.1    jruoho static ACPI_STATUS
    522       1.1    jruoho AcpiNsFindIniMethods (
    523       1.1    jruoho     ACPI_HANDLE             ObjHandle,
    524       1.1    jruoho     UINT32                  NestingLevel,
    525       1.1    jruoho     void                    *Context,
    526       1.1    jruoho     void                    **ReturnValue)
    527       1.1    jruoho {
    528       1.1    jruoho     ACPI_DEVICE_WALK_INFO   *Info = ACPI_CAST_PTR (ACPI_DEVICE_WALK_INFO, Context);
    529       1.1    jruoho     ACPI_NAMESPACE_NODE     *Node;
    530       1.1    jruoho     ACPI_NAMESPACE_NODE     *ParentNode;
    531       1.1    jruoho 
    532       1.1    jruoho 
    533       1.1    jruoho     /* Keep count of device/processor/thermal objects */
    534       1.1    jruoho 
    535       1.1    jruoho     Node = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, ObjHandle);
    536       1.1    jruoho     if ((Node->Type == ACPI_TYPE_DEVICE)    ||
    537       1.1    jruoho         (Node->Type == ACPI_TYPE_PROCESSOR) ||
    538       1.1    jruoho         (Node->Type == ACPI_TYPE_THERMAL))
    539       1.1    jruoho     {
    540       1.1    jruoho         Info->DeviceCount++;
    541       1.1    jruoho         return (AE_OK);
    542       1.1    jruoho     }
    543       1.1    jruoho 
    544       1.1    jruoho     /* We are only looking for methods named _INI */
    545       1.1    jruoho 
    546  1.14.2.1  christos     if (!ACPI_COMPARE_NAMESEG (Node->Name.Ascii, METHOD_NAME__INI))
    547       1.1    jruoho     {
    548       1.1    jruoho         return (AE_OK);
    549       1.1    jruoho     }
    550       1.1    jruoho 
    551       1.1    jruoho     /*
    552       1.1    jruoho      * The only _INI methods that we care about are those that are
    553       1.1    jruoho      * present under Device, Processor, and Thermal objects.
    554       1.1    jruoho      */
    555       1.1    jruoho     ParentNode = Node->Parent;
    556       1.1    jruoho     switch (ParentNode->Type)
    557       1.1    jruoho     {
    558       1.1    jruoho     case ACPI_TYPE_DEVICE:
    559       1.1    jruoho     case ACPI_TYPE_PROCESSOR:
    560       1.1    jruoho     case ACPI_TYPE_THERMAL:
    561       1.1    jruoho 
    562       1.1    jruoho         /* Mark parent and bubble up the INI present flag to the root */
    563       1.1    jruoho 
    564       1.1    jruoho         while (ParentNode)
    565       1.1    jruoho         {
    566       1.1    jruoho             ParentNode->Flags |= ANOBJ_SUBTREE_HAS_INI;
    567       1.1    jruoho             ParentNode = ParentNode->Parent;
    568       1.1    jruoho         }
    569       1.1    jruoho         break;
    570       1.1    jruoho 
    571       1.1    jruoho     default:
    572       1.4  christos 
    573       1.1    jruoho         break;
    574       1.1    jruoho     }
    575       1.1    jruoho 
    576       1.1    jruoho     return (AE_OK);
    577       1.1    jruoho }
    578       1.1    jruoho 
    579       1.1    jruoho 
    580       1.1    jruoho /*******************************************************************************
    581       1.1    jruoho  *
    582       1.1    jruoho  * FUNCTION:    AcpiNsInitOneDevice
    583       1.1    jruoho  *
    584       1.1    jruoho  * PARAMETERS:  ACPI_WALK_CALLBACK
    585       1.1    jruoho  *
    586       1.1    jruoho  * RETURN:      ACPI_STATUS
    587       1.1    jruoho  *
    588       1.1    jruoho  * DESCRIPTION: This is called once per device soon after ACPI is enabled
    589       1.1    jruoho  *              to initialize each device. It determines if the device is
    590       1.1    jruoho  *              present, and if so, calls _INI.
    591       1.1    jruoho  *
    592       1.1    jruoho  ******************************************************************************/
    593       1.1    jruoho 
    594       1.1    jruoho static ACPI_STATUS
    595       1.1    jruoho AcpiNsInitOneDevice (
    596       1.1    jruoho     ACPI_HANDLE             ObjHandle,
    597       1.1    jruoho     UINT32                  NestingLevel,
    598       1.1    jruoho     void                    *Context,
    599       1.1    jruoho     void                    **ReturnValue)
    600       1.1    jruoho {
    601       1.1    jruoho     ACPI_DEVICE_WALK_INFO   *WalkInfo = ACPI_CAST_PTR (ACPI_DEVICE_WALK_INFO, Context);
    602       1.1    jruoho     ACPI_EVALUATE_INFO      *Info = WalkInfo->EvaluateInfo;
    603       1.1    jruoho     UINT32                  Flags;
    604       1.1    jruoho     ACPI_STATUS             Status;
    605       1.1    jruoho     ACPI_NAMESPACE_NODE     *DeviceNode;
    606       1.1    jruoho 
    607       1.1    jruoho 
    608       1.1    jruoho     ACPI_FUNCTION_TRACE (NsInitOneDevice);
    609       1.1    jruoho 
    610       1.1    jruoho 
    611       1.1    jruoho     /* We are interested in Devices, Processors and ThermalZones only */
    612       1.1    jruoho 
    613       1.1    jruoho     DeviceNode = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, ObjHandle);
    614       1.1    jruoho     if ((DeviceNode->Type != ACPI_TYPE_DEVICE)    &&
    615       1.1    jruoho         (DeviceNode->Type != ACPI_TYPE_PROCESSOR) &&
    616       1.1    jruoho         (DeviceNode->Type != ACPI_TYPE_THERMAL))
    617       1.1    jruoho     {
    618       1.1    jruoho         return_ACPI_STATUS (AE_OK);
    619       1.1    jruoho     }
    620       1.1    jruoho 
    621       1.1    jruoho     /*
    622       1.1    jruoho      * Because of an earlier namespace analysis, all subtrees that contain an
    623       1.1    jruoho      * _INI method are tagged.
    624       1.1    jruoho      *
    625       1.1    jruoho      * If this device subtree does not contain any _INI methods, we
    626       1.1    jruoho      * can exit now and stop traversing this entire subtree.
    627       1.1    jruoho      */
    628       1.1    jruoho     if (!(DeviceNode->Flags & ANOBJ_SUBTREE_HAS_INI))
    629       1.1    jruoho     {
    630       1.1    jruoho         return_ACPI_STATUS (AE_CTRL_DEPTH);
    631       1.1    jruoho     }
    632       1.1    jruoho 
    633       1.1    jruoho     /*
    634       1.1    jruoho      * Run _STA to determine if this device is present and functioning. We
    635       1.1    jruoho      * must know this information for two important reasons (from ACPI spec):
    636       1.1    jruoho      *
    637       1.1    jruoho      * 1) We can only run _INI if the device is present.
    638       1.1    jruoho      * 2) We must abort the device tree walk on this subtree if the device is
    639       1.1    jruoho      *    not present and is not functional (we will not examine the children)
    640       1.1    jruoho      *
    641       1.1    jruoho      * The _STA method is not required to be present under the device, we
    642       1.1    jruoho      * assume the device is present if _STA does not exist.
    643       1.1    jruoho      */
    644       1.1    jruoho     ACPI_DEBUG_EXEC (AcpiUtDisplayInitPathname (
    645       1.1    jruoho         ACPI_TYPE_METHOD, DeviceNode, METHOD_NAME__STA));
    646       1.1    jruoho 
    647       1.1    jruoho     Status = AcpiUtExecute_STA (DeviceNode, &Flags);
    648       1.1    jruoho     if (ACPI_FAILURE (Status))
    649       1.1    jruoho     {
    650       1.1    jruoho         /* Ignore error and move on to next device */
    651       1.1    jruoho 
    652       1.1    jruoho         return_ACPI_STATUS (AE_OK);
    653       1.1    jruoho     }
    654       1.1    jruoho 
    655       1.1    jruoho     /*
    656       1.1    jruoho      * Flags == -1 means that _STA was not found. In this case, we assume that
    657       1.1    jruoho      * the device is both present and functional.
    658       1.1    jruoho      *
    659       1.1    jruoho      * From the ACPI spec, description of _STA:
    660       1.1    jruoho      *
    661       1.1    jruoho      * "If a device object (including the processor object) does not have an
    662       1.1    jruoho      * _STA object, then OSPM assumes that all of the above bits are set (in
    663       1.1    jruoho      * other words, the device is present, ..., and functioning)"
    664       1.1    jruoho      */
    665       1.1    jruoho     if (Flags != ACPI_UINT32_MAX)
    666       1.1    jruoho     {
    667       1.1    jruoho         WalkInfo->Num_STA++;
    668       1.1    jruoho     }
    669       1.1    jruoho 
    670       1.1    jruoho     /*
    671       1.1    jruoho      * Examine the PRESENT and FUNCTIONING status bits
    672       1.1    jruoho      *
    673       1.1    jruoho      * Note: ACPI spec does not seem to specify behavior for the present but
    674       1.1    jruoho      * not functioning case, so we assume functioning if present.
    675       1.1    jruoho      */
    676       1.1    jruoho     if (!(Flags & ACPI_STA_DEVICE_PRESENT))
    677       1.1    jruoho     {
    678       1.1    jruoho         /* Device is not present, we must examine the Functioning bit */
    679       1.1    jruoho 
    680       1.1    jruoho         if (Flags & ACPI_STA_DEVICE_FUNCTIONING)
    681       1.1    jruoho         {
    682       1.1    jruoho             /*
    683       1.1    jruoho              * Device is not present but is "functioning". In this case,
    684       1.1    jruoho              * we will not run _INI, but we continue to examine the children
    685       1.1    jruoho              * of this device.
    686       1.1    jruoho              *
    687       1.1    jruoho              * From the ACPI spec, description of _STA: (Note - no mention
    688       1.1    jruoho              * of whether to run _INI or not on the device in question)
    689       1.1    jruoho              *
    690       1.1    jruoho              * "_STA may return bit 0 clear (not present) with bit 3 set
    691       1.1    jruoho              * (device is functional). This case is used to indicate a valid
    692       1.1    jruoho              * device for which no device driver should be loaded (for example,
    693       1.1    jruoho              * a bridge device.) Children of this device may be present and
    694       1.1    jruoho              * valid. OSPM should continue enumeration below a device whose
    695       1.1    jruoho              * _STA returns this bit combination"
    696       1.1    jruoho              */
    697       1.1    jruoho             return_ACPI_STATUS (AE_OK);
    698       1.1    jruoho         }
    699       1.1    jruoho         else
    700       1.1    jruoho         {
    701       1.1    jruoho             /*
    702       1.1    jruoho              * Device is not present and is not functioning. We must abort the
    703       1.1    jruoho              * walk of this subtree immediately -- don't look at the children
    704       1.1    jruoho              * of such a device.
    705       1.1    jruoho              *
    706       1.1    jruoho              * From the ACPI spec, description of _INI:
    707       1.1    jruoho              *
    708       1.1    jruoho              * "If the _STA method indicates that the device is not present,
    709       1.1    jruoho              * OSPM will not run the _INI and will not examine the children
    710       1.1    jruoho              * of the device for _INI methods"
    711       1.1    jruoho              */
    712       1.1    jruoho             return_ACPI_STATUS (AE_CTRL_DEPTH);
    713       1.1    jruoho         }
    714       1.1    jruoho     }
    715       1.1    jruoho 
    716       1.1    jruoho     /*
    717       1.1    jruoho      * The device is present or is assumed present if no _STA exists.
    718       1.1    jruoho      * Run the _INI if it exists (not required to exist)
    719       1.1    jruoho      *
    720       1.1    jruoho      * Note: We know there is an _INI within this subtree, but it may not be
    721       1.1    jruoho      * under this particular device, it may be lower in the branch.
    722       1.1    jruoho      */
    723  1.14.2.1  christos     if (!ACPI_COMPARE_NAMESEG (DeviceNode->Name.Ascii, "_SB_") ||
    724      1.11  christos         DeviceNode->Parent != AcpiGbl_RootNode)
    725      1.11  christos     {
    726      1.11  christos         ACPI_DEBUG_EXEC (AcpiUtDisplayInitPathname (
    727      1.11  christos             ACPI_TYPE_METHOD, DeviceNode, METHOD_NAME__INI));
    728       1.1    jruoho 
    729      1.11  christos         memset (Info, 0, sizeof (ACPI_EVALUATE_INFO));
    730      1.11  christos         Info->PrefixNode = DeviceNode;
    731      1.11  christos         Info->RelativePathname = METHOD_NAME__INI;
    732      1.11  christos         Info->Parameters = NULL;
    733      1.11  christos         Info->Flags = ACPI_IGNORE_RETURN_VALUE;
    734       1.1    jruoho 
    735      1.11  christos         Status = AcpiNsEvaluate (Info);
    736      1.11  christos         if (ACPI_SUCCESS (Status))
    737      1.11  christos         {
    738      1.11  christos             WalkInfo->Num_INI++;
    739      1.11  christos         }
    740       1.1    jruoho 
    741       1.1    jruoho #ifdef ACPI_DEBUG_OUTPUT
    742      1.11  christos         else if (Status != AE_NOT_FOUND)
    743      1.11  christos         {
    744      1.11  christos             /* Ignore error and move on to next device */
    745       1.1    jruoho 
    746      1.11  christos             char *ScopeName = AcpiNsGetNormalizedPathname (DeviceNode, TRUE);
    747       1.1    jruoho 
    748      1.11  christos             ACPI_EXCEPTION ((AE_INFO, Status, "during %s._INI execution",
    749      1.11  christos                 ScopeName));
    750      1.11  christos             ACPI_FREE (ScopeName);
    751      1.11  christos         }
    752      1.11  christos #endif
    753       1.1    jruoho     }
    754       1.1    jruoho 
    755       1.1    jruoho     /* Ignore errors from above */
    756       1.1    jruoho 
    757       1.1    jruoho     Status = AE_OK;
    758       1.1    jruoho 
    759       1.1    jruoho     /*
    760       1.1    jruoho      * The _INI method has been run if present; call the Global Initialization
    761       1.1    jruoho      * Handler for this device.
    762       1.1    jruoho      */
    763       1.1    jruoho     if (AcpiGbl_InitHandler)
    764       1.1    jruoho     {
    765       1.1    jruoho         Status = AcpiGbl_InitHandler (DeviceNode, ACPI_INIT_DEVICE_INI);
    766       1.1    jruoho     }
    767       1.1    jruoho 
    768       1.1    jruoho     return_ACPI_STATUS (Status);
    769       1.1    jruoho }
    770