Home | History | Annotate | Line # | Download | only in namespace
nsinit.c revision 1.13.2.2
      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.13.2.1  pgoyette  * Copyright (C) 2000 - 2018, 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.4  christos         "Completing Region/Field/Buffer/Package initialization:\n"));
    108       1.1    jruoho 
    109       1.1    jruoho     /* Set all init info to zero */
    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.1    jruoho     Status = AcpiWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT,
    116      1.10  christos         ACPI_UINT32_MAX, AcpiNsInitOneObject, NULL,
    117      1.10  christos         &Info, NULL);
    118       1.1    jruoho     if (ACPI_FAILURE (Status))
    119       1.1    jruoho     {
    120       1.1    jruoho         ACPI_EXCEPTION ((AE_INFO, Status, "During WalkNamespace"));
    121       1.1    jruoho     }
    122       1.1    jruoho 
    123       1.1    jruoho     ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT,
    124       1.4  christos         "    Initialized %u/%u Regions %u/%u Fields %u/%u "
    125       1.1    jruoho         "Buffers %u/%u Packages (%u nodes)\n",
    126       1.1    jruoho         Info.OpRegionInit,  Info.OpRegionCount,
    127       1.1    jruoho         Info.FieldInit,     Info.FieldCount,
    128       1.1    jruoho         Info.BufferInit,    Info.BufferCount,
    129       1.1    jruoho         Info.PackageInit,   Info.PackageCount, Info.ObjectCount));
    130       1.1    jruoho 
    131       1.1    jruoho     ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
    132       1.6  christos         "%u Control Methods found\n%u Op Regions found\n",
    133       1.6  christos         Info.MethodCount, Info.OpRegionCount));
    134       1.1    jruoho 
    135       1.1    jruoho     return_ACPI_STATUS (AE_OK);
    136       1.1    jruoho }
    137       1.1    jruoho 
    138       1.1    jruoho 
    139       1.1    jruoho /*******************************************************************************
    140       1.1    jruoho  *
    141       1.1    jruoho  * FUNCTION:    AcpiNsInitializeDevices
    142       1.1    jruoho  *
    143       1.1    jruoho  * PARAMETERS:  None
    144       1.1    jruoho  *
    145       1.1    jruoho  * RETURN:      ACPI_STATUS
    146       1.1    jruoho  *
    147       1.1    jruoho  * DESCRIPTION: Walk the entire namespace and initialize all ACPI devices.
    148       1.1    jruoho  *              This means running _INI on all present devices.
    149       1.1    jruoho  *
    150       1.1    jruoho  *              Note: We install PCI config space handler on region access,
    151       1.1    jruoho  *              not here.
    152       1.1    jruoho  *
    153       1.1    jruoho  ******************************************************************************/
    154       1.1    jruoho 
    155       1.1    jruoho ACPI_STATUS
    156       1.1    jruoho AcpiNsInitializeDevices (
    157      1.11  christos     UINT32                  Flags)
    158       1.1    jruoho {
    159      1.11  christos     ACPI_STATUS             Status = AE_OK;
    160       1.1    jruoho     ACPI_DEVICE_WALK_INFO   Info;
    161      1.11  christos     ACPI_HANDLE             Handle;
    162       1.1    jruoho 
    163       1.1    jruoho 
    164       1.1    jruoho     ACPI_FUNCTION_TRACE (NsInitializeDevices);
    165       1.1    jruoho 
    166       1.1    jruoho 
    167      1.11  christos     if (!(Flags & ACPI_NO_DEVICE_INIT))
    168      1.11  christos     {
    169      1.11  christos         ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
    170      1.11  christos             "[Init] Initializing ACPI Devices\n"));
    171       1.1    jruoho 
    172      1.11  christos         /* Init counters */
    173       1.1    jruoho 
    174      1.11  christos         Info.DeviceCount = 0;
    175      1.11  christos         Info.Num_STA = 0;
    176      1.11  christos         Info.Num_INI = 0;
    177       1.1    jruoho 
    178      1.11  christos         ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT,
    179      1.11  christos             "Initializing Device/Processor/Thermal objects "
    180      1.11  christos             "and executing _INI/_STA methods:\n"));
    181       1.1    jruoho 
    182      1.11  christos         /* Tree analysis: find all subtrees that contain _INI methods */
    183       1.1    jruoho 
    184      1.11  christos         Status = AcpiNsWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT,
    185      1.11  christos             ACPI_UINT32_MAX, FALSE, AcpiNsFindIniMethods, NULL, &Info, NULL);
    186      1.11  christos         if (ACPI_FAILURE (Status))
    187      1.11  christos         {
    188      1.11  christos             goto ErrorExit;
    189      1.11  christos         }
    190       1.1    jruoho 
    191      1.11  christos         /* Allocate the evaluation information block */
    192       1.1    jruoho 
    193      1.11  christos         Info.EvaluateInfo = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_EVALUATE_INFO));
    194      1.11  christos         if (!Info.EvaluateInfo)
    195      1.11  christos         {
    196      1.11  christos             Status = AE_NO_MEMORY;
    197      1.11  christos             goto ErrorExit;
    198      1.11  christos         }
    199       1.1    jruoho 
    200      1.11  christos         /*
    201      1.11  christos          * Execute the "global" _INI method that may appear at the root.
    202      1.11  christos          * This support is provided for Windows compatibility (Vista+) and
    203      1.11  christos          * is not part of the ACPI specification.
    204      1.11  christos          */
    205      1.11  christos         Info.EvaluateInfo->PrefixNode = AcpiGbl_RootNode;
    206      1.11  christos         Info.EvaluateInfo->RelativePathname = METHOD_NAME__INI;
    207      1.11  christos         Info.EvaluateInfo->Parameters = NULL;
    208      1.11  christos         Info.EvaluateInfo->Flags = ACPI_IGNORE_RETURN_VALUE;
    209       1.1    jruoho 
    210      1.11  christos         Status = AcpiNsEvaluate (Info.EvaluateInfo);
    211      1.11  christos         if (ACPI_SUCCESS (Status))
    212      1.11  christos         {
    213      1.11  christos             Info.Num_INI++;
    214      1.11  christos         }
    215       1.1    jruoho 
    216      1.11  christos         /*
    217      1.11  christos          * Execute \_SB._INI.
    218      1.11  christos          * There appears to be a strict order requirement for \_SB._INI,
    219      1.11  christos          * which should be evaluated before any _REG evaluations.
    220      1.11  christos          */
    221      1.11  christos         Status = AcpiGetHandle (NULL, "\\_SB", &Handle);
    222      1.11  christos         if (ACPI_SUCCESS (Status))
    223      1.11  christos         {
    224      1.11  christos             memset (Info.EvaluateInfo, 0, sizeof (ACPI_EVALUATE_INFO));
    225      1.11  christos             Info.EvaluateInfo->PrefixNode = Handle;
    226      1.11  christos             Info.EvaluateInfo->RelativePathname = METHOD_NAME__INI;
    227      1.11  christos             Info.EvaluateInfo->Parameters = NULL;
    228      1.11  christos             Info.EvaluateInfo->Flags = ACPI_IGNORE_RETURN_VALUE;
    229      1.11  christos 
    230      1.11  christos             Status = AcpiNsEvaluate (Info.EvaluateInfo);
    231      1.11  christos             if (ACPI_SUCCESS (Status))
    232      1.11  christos             {
    233      1.11  christos                 Info.Num_INI++;
    234      1.11  christos             }
    235      1.11  christos         }
    236      1.11  christos     }
    237       1.1    jruoho 
    238       1.1    jruoho     /*
    239      1.11  christos      * Run all _REG methods
    240      1.11  christos      *
    241      1.11  christos      * Note: Any objects accessed by the _REG methods will be automatically
    242      1.11  christos      * initialized, even if they contain executable AML (see the call to
    243      1.11  christos      * AcpiNsInitializeObjects below).
    244      1.11  christos      *
    245      1.11  christos      * Note: According to the ACPI specification, we actually needn't execute
    246      1.11  christos      * _REG for SystemMemory/SystemIo operation regions, but for PCI_Config
    247      1.11  christos      * operation regions, it is required to evaluate _REG for those on a PCI
    248      1.11  christos      * root bus that doesn't contain _BBN object. So this code is kept here
    249      1.11  christos      * in order not to break things.
    250       1.1    jruoho      */
    251      1.11  christos     if (!(Flags & ACPI_NO_ADDRESS_SPACE_INIT))
    252       1.1    jruoho     {
    253      1.11  christos         ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
    254      1.11  christos             "[Init] Executing _REG OpRegion methods\n"));
    255      1.11  christos 
    256      1.11  christos         Status = AcpiEvInitializeOpRegions ();
    257      1.11  christos         if (ACPI_FAILURE (Status))
    258      1.11  christos         {
    259      1.11  christos             goto ErrorExit;
    260      1.11  christos         }
    261       1.1    jruoho     }
    262       1.1    jruoho 
    263      1.11  christos     if (!(Flags & ACPI_NO_DEVICE_INIT))
    264       1.1    jruoho     {
    265      1.11  christos         /* Walk namespace to execute all _INIs on present devices */
    266      1.11  christos 
    267      1.11  christos         Status = AcpiNsWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT,
    268      1.11  christos             ACPI_UINT32_MAX, FALSE, AcpiNsInitOneDevice, NULL, &Info, NULL);
    269      1.11  christos 
    270      1.11  christos         /*
    271      1.11  christos          * Any _OSI requests should be completed by now. If the BIOS has
    272      1.11  christos          * requested any Windows OSI strings, we will always truncate
    273      1.11  christos          * I/O addresses to 16 bits -- for Windows compatibility.
    274      1.11  christos          */
    275      1.11  christos         if (AcpiGbl_OsiData >= ACPI_OSI_WIN_2000)
    276      1.11  christos         {
    277      1.11  christos             AcpiGbl_TruncateIoAddresses = TRUE;
    278      1.11  christos         }
    279      1.11  christos 
    280      1.11  christos         ACPI_FREE (Info.EvaluateInfo);
    281      1.11  christos         if (ACPI_FAILURE (Status))
    282      1.11  christos         {
    283      1.11  christos             goto ErrorExit;
    284      1.11  christos         }
    285      1.11  christos 
    286      1.11  christos         ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT,
    287      1.11  christos             "    Executed %u _INI methods requiring %u _STA executions "
    288      1.11  christos             "(examined %u objects)\n",
    289      1.11  christos             Info.Num_INI, Info.Num_STA, Info.DeviceCount));
    290       1.1    jruoho     }
    291       1.1    jruoho 
    292       1.1    jruoho     return_ACPI_STATUS (Status);
    293       1.1    jruoho 
    294       1.1    jruoho 
    295       1.1    jruoho ErrorExit:
    296       1.1    jruoho     ACPI_EXCEPTION ((AE_INFO, Status, "During device initialization"));
    297       1.1    jruoho     return_ACPI_STATUS (Status);
    298       1.1    jruoho }
    299       1.1    jruoho 
    300       1.1    jruoho 
    301       1.1    jruoho /*******************************************************************************
    302       1.1    jruoho  *
    303  1.13.2.2  pgoyette  * FUNCTION:    AcpiNsInitOnePackage
    304  1.13.2.2  pgoyette  *
    305  1.13.2.2  pgoyette  * PARAMETERS:  ObjHandle       - Node
    306  1.13.2.2  pgoyette  *              Level           - Current nesting level
    307  1.13.2.2  pgoyette  *              Context         - Not used
    308  1.13.2.2  pgoyette  *              ReturnValue     - Not used
    309  1.13.2.2  pgoyette  *
    310  1.13.2.2  pgoyette  * RETURN:      Status
    311  1.13.2.2  pgoyette  *
    312  1.13.2.2  pgoyette  * DESCRIPTION: Callback from AcpiWalkNamespace. Invoked for every package
    313  1.13.2.2  pgoyette  *              within the namespace. Used during dynamic load of an SSDT.
    314  1.13.2.2  pgoyette  *
    315  1.13.2.2  pgoyette  ******************************************************************************/
    316  1.13.2.2  pgoyette 
    317  1.13.2.2  pgoyette ACPI_STATUS
    318  1.13.2.2  pgoyette AcpiNsInitOnePackage (
    319  1.13.2.2  pgoyette     ACPI_HANDLE             ObjHandle,
    320  1.13.2.2  pgoyette     UINT32                  Level,
    321  1.13.2.2  pgoyette     void                    *Context,
    322  1.13.2.2  pgoyette     void                    **ReturnValue)
    323  1.13.2.2  pgoyette {
    324  1.13.2.2  pgoyette     ACPI_STATUS             Status;
    325  1.13.2.2  pgoyette     ACPI_OPERAND_OBJECT     *ObjDesc;
    326  1.13.2.2  pgoyette     ACPI_NAMESPACE_NODE     *Node = (ACPI_NAMESPACE_NODE *) ObjHandle;
    327  1.13.2.2  pgoyette 
    328  1.13.2.2  pgoyette 
    329  1.13.2.2  pgoyette     ObjDesc = AcpiNsGetAttachedObject (Node);
    330  1.13.2.2  pgoyette     if (!ObjDesc)
    331  1.13.2.2  pgoyette     {
    332  1.13.2.2  pgoyette         return (AE_OK);
    333  1.13.2.2  pgoyette     }
    334  1.13.2.2  pgoyette 
    335  1.13.2.2  pgoyette     /* Exit if package is already initialized */
    336  1.13.2.2  pgoyette 
    337  1.13.2.2  pgoyette     if (ObjDesc->Package.Flags & AOPOBJ_DATA_VALID)
    338  1.13.2.2  pgoyette     {
    339  1.13.2.2  pgoyette         return (AE_OK);
    340  1.13.2.2  pgoyette     }
    341  1.13.2.2  pgoyette 
    342  1.13.2.2  pgoyette     Status = AcpiDsGetPackageArguments (ObjDesc);
    343  1.13.2.2  pgoyette     if (ACPI_FAILURE (Status))
    344  1.13.2.2  pgoyette     {
    345  1.13.2.2  pgoyette         return (AE_OK);
    346  1.13.2.2  pgoyette     }
    347  1.13.2.2  pgoyette 
    348  1.13.2.2  pgoyette     Status = AcpiUtWalkPackageTree (ObjDesc, NULL, AcpiDsInitPackageElement,
    349  1.13.2.2  pgoyette         NULL);
    350  1.13.2.2  pgoyette     if (ACPI_FAILURE (Status))
    351  1.13.2.2  pgoyette     {
    352  1.13.2.2  pgoyette         return (AE_OK);
    353  1.13.2.2  pgoyette     }
    354  1.13.2.2  pgoyette 
    355  1.13.2.2  pgoyette     ObjDesc->Package.Flags |= AOPOBJ_DATA_VALID;
    356  1.13.2.2  pgoyette     return (AE_OK);
    357  1.13.2.2  pgoyette }
    358  1.13.2.2  pgoyette 
    359  1.13.2.2  pgoyette 
    360  1.13.2.2  pgoyette /*******************************************************************************
    361  1.13.2.2  pgoyette  *
    362       1.1    jruoho  * FUNCTION:    AcpiNsInitOneObject
    363       1.1    jruoho  *
    364       1.1    jruoho  * PARAMETERS:  ObjHandle       - Node
    365       1.1    jruoho  *              Level           - Current nesting level
    366       1.1    jruoho  *              Context         - Points to a init info struct
    367       1.1    jruoho  *              ReturnValue     - Not used
    368       1.1    jruoho  *
    369       1.1    jruoho  * RETURN:      Status
    370       1.1    jruoho  *
    371       1.4  christos  * DESCRIPTION: Callback from AcpiWalkNamespace. Invoked for every object
    372  1.13.2.1  pgoyette  *              within the namespace.
    373       1.1    jruoho  *
    374       1.1    jruoho  *              Currently, the only objects that require initialization are:
    375       1.1    jruoho  *              1) Methods
    376       1.1    jruoho  *              2) Op Regions
    377       1.1    jruoho  *
    378       1.1    jruoho  ******************************************************************************/
    379       1.1    jruoho 
    380       1.1    jruoho static ACPI_STATUS
    381       1.1    jruoho AcpiNsInitOneObject (
    382       1.1    jruoho     ACPI_HANDLE             ObjHandle,
    383       1.1    jruoho     UINT32                  Level,
    384       1.1    jruoho     void                    *Context,
    385       1.1    jruoho     void                    **ReturnValue)
    386       1.1    jruoho {
    387       1.1    jruoho     ACPI_OBJECT_TYPE        Type;
    388       1.1    jruoho     ACPI_STATUS             Status = AE_OK;
    389       1.1    jruoho     ACPI_INIT_WALK_INFO     *Info = (ACPI_INIT_WALK_INFO *) Context;
    390       1.1    jruoho     ACPI_NAMESPACE_NODE     *Node = (ACPI_NAMESPACE_NODE *) ObjHandle;
    391       1.1    jruoho     ACPI_OPERAND_OBJECT     *ObjDesc;
    392       1.1    jruoho 
    393       1.1    jruoho 
    394       1.1    jruoho     ACPI_FUNCTION_NAME (NsInitOneObject);
    395       1.1    jruoho 
    396       1.1    jruoho 
    397       1.1    jruoho     Info->ObjectCount++;
    398       1.1    jruoho 
    399       1.1    jruoho     /* And even then, we are only interested in a few object types */
    400       1.1    jruoho 
    401       1.1    jruoho     Type = AcpiNsGetType (ObjHandle);
    402       1.1    jruoho     ObjDesc = AcpiNsGetAttachedObject (Node);
    403       1.1    jruoho     if (!ObjDesc)
    404       1.1    jruoho     {
    405       1.1    jruoho         return (AE_OK);
    406       1.1    jruoho     }
    407       1.1    jruoho 
    408       1.1    jruoho     /* Increment counters for object types we are looking for */
    409       1.1    jruoho 
    410       1.1    jruoho     switch (Type)
    411       1.1    jruoho     {
    412       1.1    jruoho     case ACPI_TYPE_REGION:
    413       1.4  christos 
    414       1.1    jruoho         Info->OpRegionCount++;
    415       1.1    jruoho         break;
    416       1.1    jruoho 
    417       1.1    jruoho     case ACPI_TYPE_BUFFER_FIELD:
    418       1.4  christos 
    419       1.1    jruoho         Info->FieldCount++;
    420       1.1    jruoho         break;
    421       1.1    jruoho 
    422       1.1    jruoho     case ACPI_TYPE_LOCAL_BANK_FIELD:
    423       1.4  christos 
    424       1.1    jruoho         Info->FieldCount++;
    425       1.1    jruoho         break;
    426       1.1    jruoho 
    427       1.1    jruoho     case ACPI_TYPE_BUFFER:
    428       1.4  christos 
    429       1.1    jruoho         Info->BufferCount++;
    430       1.1    jruoho         break;
    431       1.1    jruoho 
    432       1.1    jruoho     case ACPI_TYPE_PACKAGE:
    433       1.4  christos 
    434       1.1    jruoho         Info->PackageCount++;
    435       1.1    jruoho         break;
    436       1.1    jruoho 
    437       1.1    jruoho     default:
    438       1.1    jruoho 
    439       1.1    jruoho         /* No init required, just exit now */
    440       1.4  christos 
    441       1.1    jruoho         return (AE_OK);
    442       1.1    jruoho     }
    443       1.1    jruoho 
    444       1.1    jruoho     /* If the object is already initialized, nothing else to do */
    445       1.1    jruoho 
    446       1.1    jruoho     if (ObjDesc->Common.Flags & AOPOBJ_DATA_VALID)
    447       1.1    jruoho     {
    448       1.1    jruoho         return (AE_OK);
    449       1.1    jruoho     }
    450       1.1    jruoho 
    451       1.1    jruoho     /* Must lock the interpreter before executing AML code */
    452       1.1    jruoho 
    453       1.1    jruoho     AcpiExEnterInterpreter ();
    454       1.1    jruoho 
    455       1.1    jruoho     /*
    456       1.1    jruoho      * Each of these types can contain executable AML code within the
    457       1.1    jruoho      * declaration.
    458       1.1    jruoho      */
    459       1.1    jruoho     switch (Type)
    460       1.1    jruoho     {
    461       1.1    jruoho     case ACPI_TYPE_REGION:
    462       1.1    jruoho 
    463       1.1    jruoho         Info->OpRegionInit++;
    464       1.1    jruoho         Status = AcpiDsGetRegionArguments (ObjDesc);
    465       1.1    jruoho         break;
    466       1.1    jruoho 
    467       1.1    jruoho     case ACPI_TYPE_BUFFER_FIELD:
    468       1.1    jruoho 
    469       1.1    jruoho         Info->FieldInit++;
    470       1.1    jruoho         Status = AcpiDsGetBufferFieldArguments (ObjDesc);
    471       1.1    jruoho         break;
    472       1.1    jruoho 
    473       1.1    jruoho     case ACPI_TYPE_LOCAL_BANK_FIELD:
    474       1.1    jruoho 
    475       1.1    jruoho         Info->FieldInit++;
    476       1.1    jruoho         Status = AcpiDsGetBankFieldArguments (ObjDesc);
    477       1.1    jruoho         break;
    478       1.1    jruoho 
    479       1.1    jruoho     case ACPI_TYPE_BUFFER:
    480       1.1    jruoho 
    481       1.1    jruoho         Info->BufferInit++;
    482       1.1    jruoho         Status = AcpiDsGetBufferArguments (ObjDesc);
    483       1.1    jruoho         break;
    484       1.1    jruoho 
    485       1.1    jruoho     case ACPI_TYPE_PACKAGE:
    486       1.1    jruoho 
    487  1.13.2.2  pgoyette         /* Complete the initialization/resolution of the package object */
    488  1.13.2.1  pgoyette 
    489  1.13.2.2  pgoyette         Info->PackageInit++;
    490  1.13.2.2  pgoyette         Status = AcpiNsInitOnePackage (ObjHandle, Level, NULL, NULL);
    491       1.1    jruoho         break;
    492       1.1    jruoho 
    493       1.1    jruoho     default:
    494       1.4  christos 
    495       1.1    jruoho         /* No other types can get here */
    496       1.4  christos 
    497       1.1    jruoho         break;
    498       1.1    jruoho     }
    499       1.1    jruoho 
    500       1.1    jruoho     if (ACPI_FAILURE (Status))
    501       1.1    jruoho     {
    502       1.1    jruoho         ACPI_EXCEPTION ((AE_INFO, Status,
    503       1.1    jruoho             "Could not execute arguments for [%4.4s] (%s)",
    504       1.1    jruoho             AcpiUtGetNodeName (Node), AcpiUtGetTypeName (Type)));
    505       1.1    jruoho     }
    506       1.1    jruoho 
    507       1.1    jruoho     /*
    508       1.1    jruoho      * We ignore errors from above, and always return OK, since we don't want
    509       1.1    jruoho      * to abort the walk on any single error.
    510       1.1    jruoho      */
    511       1.1    jruoho     AcpiExExitInterpreter ();
    512       1.1    jruoho     return (AE_OK);
    513       1.1    jruoho }
    514       1.1    jruoho 
    515       1.1    jruoho 
    516       1.1    jruoho /*******************************************************************************
    517       1.1    jruoho  *
    518       1.1    jruoho  * FUNCTION:    AcpiNsFindIniMethods
    519       1.1    jruoho  *
    520       1.1    jruoho  * PARAMETERS:  ACPI_WALK_CALLBACK
    521       1.1    jruoho  *
    522       1.1    jruoho  * RETURN:      ACPI_STATUS
    523       1.1    jruoho  *
    524       1.1    jruoho  * DESCRIPTION: Called during namespace walk. Finds objects named _INI under
    525       1.1    jruoho  *              device/processor/thermal objects, and marks the entire subtree
    526       1.1    jruoho  *              with a SUBTREE_HAS_INI flag. This flag is used during the
    527       1.1    jruoho  *              subsequent device initialization walk to avoid entire subtrees
    528       1.1    jruoho  *              that do not contain an _INI.
    529       1.1    jruoho  *
    530       1.1    jruoho  ******************************************************************************/
    531       1.1    jruoho 
    532       1.1    jruoho static ACPI_STATUS
    533       1.1    jruoho AcpiNsFindIniMethods (
    534       1.1    jruoho     ACPI_HANDLE             ObjHandle,
    535       1.1    jruoho     UINT32                  NestingLevel,
    536       1.1    jruoho     void                    *Context,
    537       1.1    jruoho     void                    **ReturnValue)
    538       1.1    jruoho {
    539       1.1    jruoho     ACPI_DEVICE_WALK_INFO   *Info = ACPI_CAST_PTR (ACPI_DEVICE_WALK_INFO, Context);
    540       1.1    jruoho     ACPI_NAMESPACE_NODE     *Node;
    541       1.1    jruoho     ACPI_NAMESPACE_NODE     *ParentNode;
    542       1.1    jruoho 
    543       1.1    jruoho 
    544       1.1    jruoho     /* Keep count of device/processor/thermal objects */
    545       1.1    jruoho 
    546       1.1    jruoho     Node = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, ObjHandle);
    547       1.1    jruoho     if ((Node->Type == ACPI_TYPE_DEVICE)    ||
    548       1.1    jruoho         (Node->Type == ACPI_TYPE_PROCESSOR) ||
    549       1.1    jruoho         (Node->Type == ACPI_TYPE_THERMAL))
    550       1.1    jruoho     {
    551       1.1    jruoho         Info->DeviceCount++;
    552       1.1    jruoho         return (AE_OK);
    553       1.1    jruoho     }
    554       1.1    jruoho 
    555       1.1    jruoho     /* We are only looking for methods named _INI */
    556       1.1    jruoho 
    557       1.1    jruoho     if (!ACPI_COMPARE_NAME (Node->Name.Ascii, METHOD_NAME__INI))
    558       1.1    jruoho     {
    559       1.1    jruoho         return (AE_OK);
    560       1.1    jruoho     }
    561       1.1    jruoho 
    562       1.1    jruoho     /*
    563       1.1    jruoho      * The only _INI methods that we care about are those that are
    564       1.1    jruoho      * present under Device, Processor, and Thermal objects.
    565       1.1    jruoho      */
    566       1.1    jruoho     ParentNode = Node->Parent;
    567       1.1    jruoho     switch (ParentNode->Type)
    568       1.1    jruoho     {
    569       1.1    jruoho     case ACPI_TYPE_DEVICE:
    570       1.1    jruoho     case ACPI_TYPE_PROCESSOR:
    571       1.1    jruoho     case ACPI_TYPE_THERMAL:
    572       1.1    jruoho 
    573       1.1    jruoho         /* Mark parent and bubble up the INI present flag to the root */
    574       1.1    jruoho 
    575       1.1    jruoho         while (ParentNode)
    576       1.1    jruoho         {
    577       1.1    jruoho             ParentNode->Flags |= ANOBJ_SUBTREE_HAS_INI;
    578       1.1    jruoho             ParentNode = ParentNode->Parent;
    579       1.1    jruoho         }
    580       1.1    jruoho         break;
    581       1.1    jruoho 
    582       1.1    jruoho     default:
    583       1.4  christos 
    584       1.1    jruoho         break;
    585       1.1    jruoho     }
    586       1.1    jruoho 
    587       1.1    jruoho     return (AE_OK);
    588       1.1    jruoho }
    589       1.1    jruoho 
    590       1.1    jruoho 
    591       1.1    jruoho /*******************************************************************************
    592       1.1    jruoho  *
    593       1.1    jruoho  * FUNCTION:    AcpiNsInitOneDevice
    594       1.1    jruoho  *
    595       1.1    jruoho  * PARAMETERS:  ACPI_WALK_CALLBACK
    596       1.1    jruoho  *
    597       1.1    jruoho  * RETURN:      ACPI_STATUS
    598       1.1    jruoho  *
    599       1.1    jruoho  * DESCRIPTION: This is called once per device soon after ACPI is enabled
    600       1.1    jruoho  *              to initialize each device. It determines if the device is
    601       1.1    jruoho  *              present, and if so, calls _INI.
    602       1.1    jruoho  *
    603       1.1    jruoho  ******************************************************************************/
    604       1.1    jruoho 
    605       1.1    jruoho static ACPI_STATUS
    606       1.1    jruoho AcpiNsInitOneDevice (
    607       1.1    jruoho     ACPI_HANDLE             ObjHandle,
    608       1.1    jruoho     UINT32                  NestingLevel,
    609       1.1    jruoho     void                    *Context,
    610       1.1    jruoho     void                    **ReturnValue)
    611       1.1    jruoho {
    612       1.1    jruoho     ACPI_DEVICE_WALK_INFO   *WalkInfo = ACPI_CAST_PTR (ACPI_DEVICE_WALK_INFO, Context);
    613       1.1    jruoho     ACPI_EVALUATE_INFO      *Info = WalkInfo->EvaluateInfo;
    614       1.1    jruoho     UINT32                  Flags;
    615       1.1    jruoho     ACPI_STATUS             Status;
    616       1.1    jruoho     ACPI_NAMESPACE_NODE     *DeviceNode;
    617       1.1    jruoho 
    618       1.1    jruoho 
    619       1.1    jruoho     ACPI_FUNCTION_TRACE (NsInitOneDevice);
    620       1.1    jruoho 
    621       1.1    jruoho 
    622       1.1    jruoho     /* We are interested in Devices, Processors and ThermalZones only */
    623       1.1    jruoho 
    624       1.1    jruoho     DeviceNode = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, ObjHandle);
    625       1.1    jruoho     if ((DeviceNode->Type != ACPI_TYPE_DEVICE)    &&
    626       1.1    jruoho         (DeviceNode->Type != ACPI_TYPE_PROCESSOR) &&
    627       1.1    jruoho         (DeviceNode->Type != ACPI_TYPE_THERMAL))
    628       1.1    jruoho     {
    629       1.1    jruoho         return_ACPI_STATUS (AE_OK);
    630       1.1    jruoho     }
    631       1.1    jruoho 
    632       1.1    jruoho     /*
    633       1.1    jruoho      * Because of an earlier namespace analysis, all subtrees that contain an
    634       1.1    jruoho      * _INI method are tagged.
    635       1.1    jruoho      *
    636       1.1    jruoho      * If this device subtree does not contain any _INI methods, we
    637       1.1    jruoho      * can exit now and stop traversing this entire subtree.
    638       1.1    jruoho      */
    639       1.1    jruoho     if (!(DeviceNode->Flags & ANOBJ_SUBTREE_HAS_INI))
    640       1.1    jruoho     {
    641       1.1    jruoho         return_ACPI_STATUS (AE_CTRL_DEPTH);
    642       1.1    jruoho     }
    643       1.1    jruoho 
    644       1.1    jruoho     /*
    645       1.1    jruoho      * Run _STA to determine if this device is present and functioning. We
    646       1.1    jruoho      * must know this information for two important reasons (from ACPI spec):
    647       1.1    jruoho      *
    648       1.1    jruoho      * 1) We can only run _INI if the device is present.
    649       1.1    jruoho      * 2) We must abort the device tree walk on this subtree if the device is
    650       1.1    jruoho      *    not present and is not functional (we will not examine the children)
    651       1.1    jruoho      *
    652       1.1    jruoho      * The _STA method is not required to be present under the device, we
    653       1.1    jruoho      * assume the device is present if _STA does not exist.
    654       1.1    jruoho      */
    655       1.1    jruoho     ACPI_DEBUG_EXEC (AcpiUtDisplayInitPathname (
    656       1.1    jruoho         ACPI_TYPE_METHOD, DeviceNode, METHOD_NAME__STA));
    657       1.1    jruoho 
    658       1.1    jruoho     Status = AcpiUtExecute_STA (DeviceNode, &Flags);
    659       1.1    jruoho     if (ACPI_FAILURE (Status))
    660       1.1    jruoho     {
    661       1.1    jruoho         /* Ignore error and move on to next device */
    662       1.1    jruoho 
    663       1.1    jruoho         return_ACPI_STATUS (AE_OK);
    664       1.1    jruoho     }
    665       1.1    jruoho 
    666       1.1    jruoho     /*
    667       1.1    jruoho      * Flags == -1 means that _STA was not found. In this case, we assume that
    668       1.1    jruoho      * the device is both present and functional.
    669       1.1    jruoho      *
    670       1.1    jruoho      * From the ACPI spec, description of _STA:
    671       1.1    jruoho      *
    672       1.1    jruoho      * "If a device object (including the processor object) does not have an
    673       1.1    jruoho      * _STA object, then OSPM assumes that all of the above bits are set (in
    674       1.1    jruoho      * other words, the device is present, ..., and functioning)"
    675       1.1    jruoho      */
    676       1.1    jruoho     if (Flags != ACPI_UINT32_MAX)
    677       1.1    jruoho     {
    678       1.1    jruoho         WalkInfo->Num_STA++;
    679       1.1    jruoho     }
    680       1.1    jruoho 
    681       1.1    jruoho     /*
    682       1.1    jruoho      * Examine the PRESENT and FUNCTIONING status bits
    683       1.1    jruoho      *
    684       1.1    jruoho      * Note: ACPI spec does not seem to specify behavior for the present but
    685       1.1    jruoho      * not functioning case, so we assume functioning if present.
    686       1.1    jruoho      */
    687       1.1    jruoho     if (!(Flags & ACPI_STA_DEVICE_PRESENT))
    688       1.1    jruoho     {
    689       1.1    jruoho         /* Device is not present, we must examine the Functioning bit */
    690       1.1    jruoho 
    691       1.1    jruoho         if (Flags & ACPI_STA_DEVICE_FUNCTIONING)
    692       1.1    jruoho         {
    693       1.1    jruoho             /*
    694       1.1    jruoho              * Device is not present but is "functioning". In this case,
    695       1.1    jruoho              * we will not run _INI, but we continue to examine the children
    696       1.1    jruoho              * of this device.
    697       1.1    jruoho              *
    698       1.1    jruoho              * From the ACPI spec, description of _STA: (Note - no mention
    699       1.1    jruoho              * of whether to run _INI or not on the device in question)
    700       1.1    jruoho              *
    701       1.1    jruoho              * "_STA may return bit 0 clear (not present) with bit 3 set
    702       1.1    jruoho              * (device is functional). This case is used to indicate a valid
    703       1.1    jruoho              * device for which no device driver should be loaded (for example,
    704       1.1    jruoho              * a bridge device.) Children of this device may be present and
    705       1.1    jruoho              * valid. OSPM should continue enumeration below a device whose
    706       1.1    jruoho              * _STA returns this bit combination"
    707       1.1    jruoho              */
    708       1.1    jruoho             return_ACPI_STATUS (AE_OK);
    709       1.1    jruoho         }
    710       1.1    jruoho         else
    711       1.1    jruoho         {
    712       1.1    jruoho             /*
    713       1.1    jruoho              * Device is not present and is not functioning. We must abort the
    714       1.1    jruoho              * walk of this subtree immediately -- don't look at the children
    715       1.1    jruoho              * of such a device.
    716       1.1    jruoho              *
    717       1.1    jruoho              * From the ACPI spec, description of _INI:
    718       1.1    jruoho              *
    719       1.1    jruoho              * "If the _STA method indicates that the device is not present,
    720       1.1    jruoho              * OSPM will not run the _INI and will not examine the children
    721       1.1    jruoho              * of the device for _INI methods"
    722       1.1    jruoho              */
    723       1.1    jruoho             return_ACPI_STATUS (AE_CTRL_DEPTH);
    724       1.1    jruoho         }
    725       1.1    jruoho     }
    726       1.1    jruoho 
    727       1.1    jruoho     /*
    728       1.1    jruoho      * The device is present or is assumed present if no _STA exists.
    729       1.1    jruoho      * Run the _INI if it exists (not required to exist)
    730       1.1    jruoho      *
    731       1.1    jruoho      * Note: We know there is an _INI within this subtree, but it may not be
    732       1.1    jruoho      * under this particular device, it may be lower in the branch.
    733       1.1    jruoho      */
    734      1.11  christos     if (!ACPI_COMPARE_NAME (DeviceNode->Name.Ascii, "_SB_") ||
    735      1.11  christos         DeviceNode->Parent != AcpiGbl_RootNode)
    736      1.11  christos     {
    737      1.11  christos         ACPI_DEBUG_EXEC (AcpiUtDisplayInitPathname (
    738      1.11  christos             ACPI_TYPE_METHOD, DeviceNode, METHOD_NAME__INI));
    739       1.1    jruoho 
    740      1.11  christos         memset (Info, 0, sizeof (ACPI_EVALUATE_INFO));
    741      1.11  christos         Info->PrefixNode = DeviceNode;
    742      1.11  christos         Info->RelativePathname = METHOD_NAME__INI;
    743      1.11  christos         Info->Parameters = NULL;
    744      1.11  christos         Info->Flags = ACPI_IGNORE_RETURN_VALUE;
    745       1.1    jruoho 
    746      1.11  christos         Status = AcpiNsEvaluate (Info);
    747      1.11  christos         if (ACPI_SUCCESS (Status))
    748      1.11  christos         {
    749      1.11  christos             WalkInfo->Num_INI++;
    750      1.11  christos         }
    751       1.1    jruoho 
    752       1.1    jruoho #ifdef ACPI_DEBUG_OUTPUT
    753      1.11  christos         else if (Status != AE_NOT_FOUND)
    754      1.11  christos         {
    755      1.11  christos             /* Ignore error and move on to next device */
    756       1.1    jruoho 
    757      1.11  christos             char *ScopeName = AcpiNsGetNormalizedPathname (DeviceNode, TRUE);
    758       1.1    jruoho 
    759      1.11  christos             ACPI_EXCEPTION ((AE_INFO, Status, "during %s._INI execution",
    760      1.11  christos                 ScopeName));
    761      1.11  christos             ACPI_FREE (ScopeName);
    762      1.11  christos         }
    763      1.11  christos #endif
    764       1.1    jruoho     }
    765       1.1    jruoho 
    766       1.1    jruoho     /* Ignore errors from above */
    767       1.1    jruoho 
    768       1.1    jruoho     Status = AE_OK;
    769       1.1    jruoho 
    770       1.1    jruoho     /*
    771       1.1    jruoho      * The _INI method has been run if present; call the Global Initialization
    772       1.1    jruoho      * Handler for this device.
    773       1.1    jruoho      */
    774       1.1    jruoho     if (AcpiGbl_InitHandler)
    775       1.1    jruoho     {
    776       1.1    jruoho         Status = AcpiGbl_InitHandler (DeviceNode, ACPI_INIT_DEVICE_INI);
    777       1.1    jruoho     }
    778       1.1    jruoho 
    779       1.1    jruoho     return_ACPI_STATUS (Status);
    780       1.1    jruoho }
    781