13446Smrj /******************************************************************************
23446Smrj *
33446Smrj * Module Name: nsinit - namespace initialization
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
1173446Smrj #define __NSXFINIT_C__
1183446Smrj
1193446Smrj #include "acpi.h"
1209980SDana.Myers@Sun.COM #include "accommon.h"
1213446Smrj #include "acnamesp.h"
1223446Smrj #include "acdispat.h"
1233446Smrj #include "acinterp.h"
1243446Smrj
1253446Smrj #define _COMPONENT ACPI_NAMESPACE
1263446Smrj ACPI_MODULE_NAME ("nsinit")
1273446Smrj
1283446Smrj /* Local prototypes */
1293446Smrj
1303446Smrj static ACPI_STATUS
1313446Smrj AcpiNsInitOneObject (
1323446Smrj ACPI_HANDLE ObjHandle,
1333446Smrj UINT32 Level,
1343446Smrj void *Context,
1353446Smrj void **ReturnValue);
1363446Smrj
1373446Smrj static ACPI_STATUS
1383446Smrj AcpiNsInitOneDevice (
1393446Smrj ACPI_HANDLE ObjHandle,
1403446Smrj UINT32 NestingLevel,
1413446Smrj void *Context,
1423446Smrj void **ReturnValue);
1433446Smrj
1443446Smrj static ACPI_STATUS
1453446Smrj AcpiNsFindIniMethods (
1463446Smrj ACPI_HANDLE ObjHandle,
1473446Smrj UINT32 NestingLevel,
1483446Smrj void *Context,
1493446Smrj void **ReturnValue);
1503446Smrj
1513446Smrj
1523446Smrj /*******************************************************************************
1533446Smrj *
1543446Smrj * FUNCTION: AcpiNsInitializeObjects
1553446Smrj *
1563446Smrj * PARAMETERS: None
1573446Smrj *
1583446Smrj * RETURN: Status
1593446Smrj *
1603446Smrj * DESCRIPTION: Walk the entire namespace and perform any necessary
1613446Smrj * initialization on the objects found therein
1623446Smrj *
1633446Smrj ******************************************************************************/
1643446Smrj
1653446Smrj ACPI_STATUS
AcpiNsInitializeObjects(void)1663446Smrj AcpiNsInitializeObjects (
1673446Smrj void)
1683446Smrj {
1693446Smrj ACPI_STATUS Status;
1703446Smrj ACPI_INIT_WALK_INFO Info;
1713446Smrj
1723446Smrj
1733446Smrj ACPI_FUNCTION_TRACE (NsInitializeObjects);
1743446Smrj
1753446Smrj
1763446Smrj ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
1773446Smrj "**** Starting initialization of namespace objects ****\n"));
1783446Smrj ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT,
1793446Smrj "Completing Region/Field/Buffer/Package initialization:"));
1803446Smrj
1813446Smrj /* Set all init info to zero */
1823446Smrj
1833446Smrj ACPI_MEMSET (&Info, 0, sizeof (ACPI_INIT_WALK_INFO));
1843446Smrj
1853446Smrj /* Walk entire namespace from the supplied root */
1863446Smrj
1873446Smrj Status = AcpiWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT,
188*11225SDana.Myers@Sun.COM ACPI_UINT32_MAX, AcpiNsInitOneObject, NULL,
1893446Smrj &Info, NULL);
1903446Smrj if (ACPI_FAILURE (Status))
1913446Smrj {
1923446Smrj ACPI_EXCEPTION ((AE_INFO, Status, "During WalkNamespace"));
1933446Smrj }
1943446Smrj
1953446Smrj ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT,
1969980SDana.Myers@Sun.COM "\nInitialized %hd/%hd Regions %hd/%hd Fields %hd/%hd "
1979980SDana.Myers@Sun.COM "Buffers %hd/%hd Packages (%hd nodes)\n",
1983446Smrj Info.OpRegionInit, Info.OpRegionCount,
1993446Smrj Info.FieldInit, Info.FieldCount,
2003446Smrj Info.BufferInit, Info.BufferCount,
2013446Smrj Info.PackageInit, Info.PackageCount, Info.ObjectCount));
2023446Smrj
2033446Smrj ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
2043446Smrj "%hd Control Methods found\n", Info.MethodCount));
2053446Smrj ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
2063446Smrj "%hd Op Regions found\n", Info.OpRegionCount));
2073446Smrj
2083446Smrj return_ACPI_STATUS (AE_OK);
2093446Smrj }
2103446Smrj
2113446Smrj
2123446Smrj /*******************************************************************************
2133446Smrj *
2143446Smrj * FUNCTION: AcpiNsInitializeDevices
2153446Smrj *
2163446Smrj * PARAMETERS: None
2173446Smrj *
2183446Smrj * RETURN: ACPI_STATUS
2193446Smrj *
2203446Smrj * DESCRIPTION: Walk the entire namespace and initialize all ACPI devices.
2213446Smrj * This means running _INI on all present devices.
2223446Smrj *
2233446Smrj * Note: We install PCI config space handler on region access,
2243446Smrj * not here.
2253446Smrj *
2263446Smrj ******************************************************************************/
2273446Smrj
2283446Smrj ACPI_STATUS
AcpiNsInitializeDevices(void)2293446Smrj AcpiNsInitializeDevices (
2303446Smrj void)
2313446Smrj {
2323446Smrj ACPI_STATUS Status;
2333446Smrj ACPI_DEVICE_WALK_INFO Info;
2343446Smrj
2353446Smrj
2363446Smrj ACPI_FUNCTION_TRACE (NsInitializeDevices);
2373446Smrj
2383446Smrj
2393446Smrj /* Init counters */
2403446Smrj
2413446Smrj Info.DeviceCount = 0;
2423446Smrj Info.Num_STA = 0;
2433446Smrj Info.Num_INI = 0;
2443446Smrj
2453446Smrj ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT,
2469980SDana.Myers@Sun.COM "Initializing Device/Processor/Thermal objects "
2479980SDana.Myers@Sun.COM "by executing _INI methods:"));
2483446Smrj
2493446Smrj /* Tree analysis: find all subtrees that contain _INI methods */
2503446Smrj
2513446Smrj Status = AcpiNsWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT,
252*11225SDana.Myers@Sun.COM ACPI_UINT32_MAX, FALSE, AcpiNsFindIniMethods, NULL, &Info, NULL);
2533446Smrj if (ACPI_FAILURE (Status))
2543446Smrj {
2553446Smrj goto ErrorExit;
2563446Smrj }
2573446Smrj
2583446Smrj /* Allocate the evaluation information block */
2593446Smrj
2603446Smrj Info.EvaluateInfo = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_EVALUATE_INFO));
2613446Smrj if (!Info.EvaluateInfo)
2623446Smrj {
2633446Smrj Status = AE_NO_MEMORY;
2643446Smrj goto ErrorExit;
2653446Smrj }
2663446Smrj
267*11225SDana.Myers@Sun.COM /*
268*11225SDana.Myers@Sun.COM * Execute the "global" _INI method that may appear at the root. This
269*11225SDana.Myers@Sun.COM * support is provided for Windows compatibility (Vista+) and is not
270*11225SDana.Myers@Sun.COM * part of the ACPI specification.
271*11225SDana.Myers@Sun.COM */
272*11225SDana.Myers@Sun.COM Info.EvaluateInfo->PrefixNode = AcpiGbl_RootNode;
273*11225SDana.Myers@Sun.COM Info.EvaluateInfo->Pathname = METHOD_NAME__INI;
274*11225SDana.Myers@Sun.COM Info.EvaluateInfo->Parameters = NULL;
275*11225SDana.Myers@Sun.COM Info.EvaluateInfo->Flags = ACPI_IGNORE_RETURN_VALUE;
276*11225SDana.Myers@Sun.COM
277*11225SDana.Myers@Sun.COM Status = AcpiNsEvaluate (Info.EvaluateInfo);
278*11225SDana.Myers@Sun.COM if (ACPI_SUCCESS (Status))
279*11225SDana.Myers@Sun.COM {
280*11225SDana.Myers@Sun.COM Info.Num_INI++;
281*11225SDana.Myers@Sun.COM }
282*11225SDana.Myers@Sun.COM
2833446Smrj /* Walk namespace to execute all _INIs on present devices */
2843446Smrj
2853446Smrj Status = AcpiNsWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT,
286*11225SDana.Myers@Sun.COM ACPI_UINT32_MAX, FALSE, AcpiNsInitOneDevice, NULL, &Info, NULL);
2873446Smrj
2883446Smrj ACPI_FREE (Info.EvaluateInfo);
2893446Smrj if (ACPI_FAILURE (Status))
2903446Smrj {
2913446Smrj goto ErrorExit;
2923446Smrj }
2933446Smrj
2943446Smrj ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT,
2959980SDana.Myers@Sun.COM "\nExecuted %hd _INI methods requiring %hd _STA executions "
2969980SDana.Myers@Sun.COM "(examined %hd objects)\n",
2973446Smrj Info.Num_INI, Info.Num_STA, Info.DeviceCount));
2983446Smrj
2993446Smrj return_ACPI_STATUS (Status);
3003446Smrj
3013446Smrj
3023446Smrj ErrorExit:
3033446Smrj ACPI_EXCEPTION ((AE_INFO, Status, "During device initialization"));
3043446Smrj return_ACPI_STATUS (Status);
3053446Smrj }
3063446Smrj
3073446Smrj
3083446Smrj /*******************************************************************************
3093446Smrj *
3103446Smrj * FUNCTION: AcpiNsInitOneObject
3113446Smrj *
3123446Smrj * PARAMETERS: ObjHandle - Node
3133446Smrj * Level - Current nesting level
3143446Smrj * Context - Points to a init info struct
3153446Smrj * ReturnValue - Not used
3163446Smrj *
3173446Smrj * RETURN: Status
3183446Smrj *
3193446Smrj * DESCRIPTION: Callback from AcpiWalkNamespace. Invoked for every object
3203446Smrj * within the namespace.
3213446Smrj *
3223446Smrj * Currently, the only objects that require initialization are:
3233446Smrj * 1) Methods
3243446Smrj * 2) Op Regions
3253446Smrj *
3263446Smrj ******************************************************************************/
3273446Smrj
3283446Smrj static ACPI_STATUS
AcpiNsInitOneObject(ACPI_HANDLE ObjHandle,UINT32 Level,void * Context,void ** ReturnValue)3293446Smrj AcpiNsInitOneObject (
3303446Smrj ACPI_HANDLE ObjHandle,
3313446Smrj UINT32 Level,
3323446Smrj void *Context,
3333446Smrj void **ReturnValue)
3343446Smrj {
3353446Smrj ACPI_OBJECT_TYPE Type;
3367851SDana.Myers@Sun.COM ACPI_STATUS Status = AE_OK;
3373446Smrj ACPI_INIT_WALK_INFO *Info = (ACPI_INIT_WALK_INFO *) Context;
3383446Smrj ACPI_NAMESPACE_NODE *Node = (ACPI_NAMESPACE_NODE *) ObjHandle;
3393446Smrj ACPI_OPERAND_OBJECT *ObjDesc;
3403446Smrj
3413446Smrj
3423446Smrj ACPI_FUNCTION_NAME (NsInitOneObject);
3433446Smrj
3443446Smrj
3453446Smrj Info->ObjectCount++;
3463446Smrj
3473446Smrj /* And even then, we are only interested in a few object types */
3483446Smrj
3493446Smrj Type = AcpiNsGetType (ObjHandle);
3503446Smrj ObjDesc = AcpiNsGetAttachedObject (Node);
3513446Smrj if (!ObjDesc)
3523446Smrj {
3533446Smrj return (AE_OK);
3543446Smrj }
3553446Smrj
3563446Smrj /* Increment counters for object types we are looking for */
3573446Smrj
3583446Smrj switch (Type)
3593446Smrj {
3603446Smrj case ACPI_TYPE_REGION:
3613446Smrj Info->OpRegionCount++;
3623446Smrj break;
3633446Smrj
3643446Smrj case ACPI_TYPE_BUFFER_FIELD:
3653446Smrj Info->FieldCount++;
3663446Smrj break;
3673446Smrj
3687851SDana.Myers@Sun.COM case ACPI_TYPE_LOCAL_BANK_FIELD:
3697851SDana.Myers@Sun.COM Info->FieldCount++;
3707851SDana.Myers@Sun.COM break;
3717851SDana.Myers@Sun.COM
3723446Smrj case ACPI_TYPE_BUFFER:
3733446Smrj Info->BufferCount++;
3743446Smrj break;
3753446Smrj
3763446Smrj case ACPI_TYPE_PACKAGE:
3773446Smrj Info->PackageCount++;
3783446Smrj break;
3793446Smrj
3803446Smrj default:
3813446Smrj
3823446Smrj /* No init required, just exit now */
3833446Smrj return (AE_OK);
3843446Smrj }
3853446Smrj
3869980SDana.Myers@Sun.COM /* If the object is already initialized, nothing else to do */
3879980SDana.Myers@Sun.COM
3883446Smrj if (ObjDesc->Common.Flags & AOPOBJ_DATA_VALID)
3893446Smrj {
3903446Smrj return (AE_OK);
3913446Smrj }
3923446Smrj
3939980SDana.Myers@Sun.COM /* Must lock the interpreter before executing AML code */
3949980SDana.Myers@Sun.COM
3957851SDana.Myers@Sun.COM AcpiExEnterInterpreter ();
3963446Smrj
3973446Smrj /*
3983446Smrj * Each of these types can contain executable AML code within the
3993446Smrj * declaration.
4003446Smrj */
4013446Smrj switch (Type)
4023446Smrj {
4033446Smrj case ACPI_TYPE_REGION:
4043446Smrj
4053446Smrj Info->OpRegionInit++;
4063446Smrj Status = AcpiDsGetRegionArguments (ObjDesc);
4073446Smrj break;
4083446Smrj
4093446Smrj case ACPI_TYPE_BUFFER_FIELD:
4103446Smrj
4113446Smrj Info->FieldInit++;
4123446Smrj Status = AcpiDsGetBufferFieldArguments (ObjDesc);
4133446Smrj break;
4143446Smrj
4157851SDana.Myers@Sun.COM case ACPI_TYPE_LOCAL_BANK_FIELD:
4167851SDana.Myers@Sun.COM
4177851SDana.Myers@Sun.COM Info->FieldInit++;
4187851SDana.Myers@Sun.COM Status = AcpiDsGetBankFieldArguments (ObjDesc);
4197851SDana.Myers@Sun.COM break;
4207851SDana.Myers@Sun.COM
4213446Smrj case ACPI_TYPE_BUFFER:
4223446Smrj
4233446Smrj Info->BufferInit++;
4243446Smrj Status = AcpiDsGetBufferArguments (ObjDesc);
4253446Smrj break;
4263446Smrj
4273446Smrj case ACPI_TYPE_PACKAGE:
4283446Smrj
4293446Smrj Info->PackageInit++;
4303446Smrj Status = AcpiDsGetPackageArguments (ObjDesc);
4313446Smrj break;
4323446Smrj
4333446Smrj default:
4343446Smrj /* No other types can get here */
4353446Smrj break;
4363446Smrj }
4373446Smrj
4383446Smrj if (ACPI_FAILURE (Status))
4393446Smrj {
4403446Smrj ACPI_EXCEPTION ((AE_INFO, Status,
4413446Smrj "Could not execute arguments for [%4.4s] (%s)",
4423446Smrj AcpiUtGetNodeName (Node), AcpiUtGetTypeName (Type)));
4433446Smrj }
4443446Smrj
4453446Smrj /*
4463446Smrj * Print a dot for each object unless we are going to print the entire
4473446Smrj * pathname
4483446Smrj */
4493446Smrj if (!(AcpiDbgLevel & ACPI_LV_INIT_NAMES))
4503446Smrj {
4513446Smrj ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT, "."));
4523446Smrj }
4533446Smrj
4543446Smrj /*
4553446Smrj * We ignore errors from above, and always return OK, since we don't want
4563446Smrj * to abort the walk on any single error.
4573446Smrj */
4583446Smrj AcpiExExitInterpreter ();
4593446Smrj return (AE_OK);
4603446Smrj }
4613446Smrj
4623446Smrj
4633446Smrj /*******************************************************************************
4643446Smrj *
4653446Smrj * FUNCTION: AcpiNsFindIniMethods
4663446Smrj *
4673446Smrj * PARAMETERS: ACPI_WALK_CALLBACK
4683446Smrj *
4693446Smrj * RETURN: ACPI_STATUS
4703446Smrj *
4713446Smrj * DESCRIPTION: Called during namespace walk. Finds objects named _INI under
4723446Smrj * device/processor/thermal objects, and marks the entire subtree
4733446Smrj * with a SUBTREE_HAS_INI flag. This flag is used during the
4743446Smrj * subsequent device initialization walk to avoid entire subtrees
4753446Smrj * that do not contain an _INI.
4763446Smrj *
4773446Smrj ******************************************************************************/
4783446Smrj
4793446Smrj static ACPI_STATUS
AcpiNsFindIniMethods(ACPI_HANDLE ObjHandle,UINT32 NestingLevel,void * Context,void ** ReturnValue)4803446Smrj AcpiNsFindIniMethods (
4813446Smrj ACPI_HANDLE ObjHandle,
4823446Smrj UINT32 NestingLevel,
4833446Smrj void *Context,
4843446Smrj void **ReturnValue)
4853446Smrj {
4863446Smrj ACPI_DEVICE_WALK_INFO *Info = ACPI_CAST_PTR (ACPI_DEVICE_WALK_INFO, Context);
4873446Smrj ACPI_NAMESPACE_NODE *Node;
4883446Smrj ACPI_NAMESPACE_NODE *ParentNode;
4893446Smrj
4903446Smrj
4913446Smrj /* Keep count of device/processor/thermal objects */
4923446Smrj
4933446Smrj Node = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, ObjHandle);
4943446Smrj if ((Node->Type == ACPI_TYPE_DEVICE) ||
4953446Smrj (Node->Type == ACPI_TYPE_PROCESSOR) ||
4963446Smrj (Node->Type == ACPI_TYPE_THERMAL))
4973446Smrj {
4983446Smrj Info->DeviceCount++;
4993446Smrj return (AE_OK);
5003446Smrj }
5013446Smrj
5023446Smrj /* We are only looking for methods named _INI */
5033446Smrj
5043446Smrj if (!ACPI_COMPARE_NAME (Node->Name.Ascii, METHOD_NAME__INI))
5053446Smrj {
5063446Smrj return (AE_OK);
5073446Smrj }
5083446Smrj
5093446Smrj /*
5103446Smrj * The only _INI methods that we care about are those that are
5113446Smrj * present under Device, Processor, and Thermal objects.
5123446Smrj */
5133446Smrj ParentNode = AcpiNsGetParentNode (Node);
5143446Smrj switch (ParentNode->Type)
5153446Smrj {
5163446Smrj case ACPI_TYPE_DEVICE:
5173446Smrj case ACPI_TYPE_PROCESSOR:
5183446Smrj case ACPI_TYPE_THERMAL:
5193446Smrj
5203446Smrj /* Mark parent and bubble up the INI present flag to the root */
5213446Smrj
5223446Smrj while (ParentNode)
5233446Smrj {
5243446Smrj ParentNode->Flags |= ANOBJ_SUBTREE_HAS_INI;
5253446Smrj ParentNode = AcpiNsGetParentNode (ParentNode);
5263446Smrj }
5273446Smrj break;
5283446Smrj
5293446Smrj default:
5303446Smrj break;
5313446Smrj }
5323446Smrj
5333446Smrj return (AE_OK);
5343446Smrj }
5353446Smrj
5363446Smrj
5373446Smrj /*******************************************************************************
5383446Smrj *
5393446Smrj * FUNCTION: AcpiNsInitOneDevice
5403446Smrj *
5413446Smrj * PARAMETERS: ACPI_WALK_CALLBACK
5423446Smrj *
5433446Smrj * RETURN: ACPI_STATUS
5443446Smrj *
5453446Smrj * DESCRIPTION: This is called once per device soon after ACPI is enabled
5463446Smrj * to initialize each device. It determines if the device is
5473446Smrj * present, and if so, calls _INI.
5483446Smrj *
5493446Smrj ******************************************************************************/
5503446Smrj
5513446Smrj static ACPI_STATUS
AcpiNsInitOneDevice(ACPI_HANDLE ObjHandle,UINT32 NestingLevel,void * Context,void ** ReturnValue)5523446Smrj AcpiNsInitOneDevice (
5533446Smrj ACPI_HANDLE ObjHandle,
5543446Smrj UINT32 NestingLevel,
5553446Smrj void *Context,
5563446Smrj void **ReturnValue)
5573446Smrj {
5583446Smrj ACPI_DEVICE_WALK_INFO *WalkInfo = ACPI_CAST_PTR (ACPI_DEVICE_WALK_INFO, Context);
5593446Smrj ACPI_EVALUATE_INFO *Info = WalkInfo->EvaluateInfo;
5603446Smrj UINT32 Flags;
5613446Smrj ACPI_STATUS Status;
5623446Smrj ACPI_NAMESPACE_NODE *DeviceNode;
5633446Smrj
5643446Smrj
5653446Smrj ACPI_FUNCTION_TRACE (NsInitOneDevice);
5663446Smrj
5673446Smrj
5683446Smrj /* We are interested in Devices, Processors and ThermalZones only */
5693446Smrj
5703446Smrj DeviceNode = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, ObjHandle);
5713446Smrj if ((DeviceNode->Type != ACPI_TYPE_DEVICE) &&
5723446Smrj (DeviceNode->Type != ACPI_TYPE_PROCESSOR) &&
5733446Smrj (DeviceNode->Type != ACPI_TYPE_THERMAL))
5743446Smrj {
5753446Smrj return_ACPI_STATUS (AE_OK);
5763446Smrj }
5773446Smrj
5783446Smrj /*
5793446Smrj * Because of an earlier namespace analysis, all subtrees that contain an
5803446Smrj * _INI method are tagged.
5813446Smrj *
5823446Smrj * If this device subtree does not contain any _INI methods, we
5833446Smrj * can exit now and stop traversing this entire subtree.
5843446Smrj */
5853446Smrj if (!(DeviceNode->Flags & ANOBJ_SUBTREE_HAS_INI))
5863446Smrj {
5873446Smrj return_ACPI_STATUS (AE_CTRL_DEPTH);
5883446Smrj }
5893446Smrj
5903446Smrj /*
5913446Smrj * Run _STA to determine if this device is present and functioning. We
5923446Smrj * must know this information for two important reasons (from ACPI spec):
5933446Smrj *
5943446Smrj * 1) We can only run _INI if the device is present.
5953446Smrj * 2) We must abort the device tree walk on this subtree if the device is
5963446Smrj * not present and is not functional (we will not examine the children)
5973446Smrj *
5983446Smrj * The _STA method is not required to be present under the device, we
5993446Smrj * assume the device is present if _STA does not exist.
6003446Smrj */
6013446Smrj ACPI_DEBUG_EXEC (AcpiUtDisplayInitPathname (
6023446Smrj ACPI_TYPE_METHOD, DeviceNode, METHOD_NAME__STA));
6033446Smrj
6043446Smrj Status = AcpiUtExecute_STA (DeviceNode, &Flags);
6053446Smrj if (ACPI_FAILURE (Status))
6063446Smrj {
6073446Smrj /* Ignore error and move on to next device */
6083446Smrj
6093446Smrj return_ACPI_STATUS (AE_OK);
6103446Smrj }
6113446Smrj
6123446Smrj /*
6133446Smrj * Flags == -1 means that _STA was not found. In this case, we assume that
6143446Smrj * the device is both present and functional.
6153446Smrj *
6163446Smrj * From the ACPI spec, description of _STA:
6173446Smrj *
6183446Smrj * "If a device object (including the processor object) does not have an
6193446Smrj * _STA object, then OSPM assumes that all of the above bits are set (in
6203446Smrj * other words, the device is present, ..., and functioning)"
6213446Smrj */
6223446Smrj if (Flags != ACPI_UINT32_MAX)
6233446Smrj {
6243446Smrj WalkInfo->Num_STA++;
6253446Smrj }
6263446Smrj
6273446Smrj /*
6283446Smrj * Examine the PRESENT and FUNCTIONING status bits
6293446Smrj *
6303446Smrj * Note: ACPI spec does not seem to specify behavior for the present but
6313446Smrj * not functioning case, so we assume functioning if present.
6323446Smrj */
6333446Smrj if (!(Flags & ACPI_STA_DEVICE_PRESENT))
6343446Smrj {
6353446Smrj /* Device is not present, we must examine the Functioning bit */
6363446Smrj
6373446Smrj if (Flags & ACPI_STA_DEVICE_FUNCTIONING)
6383446Smrj {
6393446Smrj /*
6403446Smrj * Device is not present but is "functioning". In this case,
6413446Smrj * we will not run _INI, but we continue to examine the children
6423446Smrj * of this device.
6433446Smrj *
6443446Smrj * From the ACPI spec, description of _STA: (Note - no mention
6453446Smrj * of whether to run _INI or not on the device in question)
6463446Smrj *
6473446Smrj * "_STA may return bit 0 clear (not present) with bit 3 set
6483446Smrj * (device is functional). This case is used to indicate a valid
6493446Smrj * device for which no device driver should be loaded (for example,
6503446Smrj * a bridge device.) Children of this device may be present and
6513446Smrj * valid. OSPM should continue enumeration below a device whose
6523446Smrj * _STA returns this bit combination"
6533446Smrj */
6543446Smrj return_ACPI_STATUS (AE_OK);
6553446Smrj }
6563446Smrj else
6573446Smrj {
6583446Smrj /*
6593446Smrj * Device is not present and is not functioning. We must abort the
6603446Smrj * walk of this subtree immediately -- don't look at the children
6613446Smrj * of such a device.
6623446Smrj *
6633446Smrj * From the ACPI spec, description of _INI:
6643446Smrj *
6653446Smrj * "If the _STA method indicates that the device is not present,
6663446Smrj * OSPM will not run the _INI and will not examine the children
6673446Smrj * of the device for _INI methods"
6683446Smrj */
6693446Smrj return_ACPI_STATUS (AE_CTRL_DEPTH);
6703446Smrj }
6713446Smrj }
6723446Smrj
6733446Smrj /*
6743446Smrj * The device is present or is assumed present if no _STA exists.
6753446Smrj * Run the _INI if it exists (not required to exist)
6763446Smrj *
6773446Smrj * Note: We know there is an _INI within this subtree, but it may not be
6783446Smrj * under this particular device, it may be lower in the branch.
6793446Smrj */
6803446Smrj ACPI_DEBUG_EXEC (AcpiUtDisplayInitPathname (
6813446Smrj ACPI_TYPE_METHOD, DeviceNode, METHOD_NAME__INI));
6823446Smrj
6833446Smrj Info->PrefixNode = DeviceNode;
6843446Smrj Info->Pathname = METHOD_NAME__INI;
6853446Smrj Info->Parameters = NULL;
6863446Smrj Info->Flags = ACPI_IGNORE_RETURN_VALUE;
6873446Smrj
6883446Smrj Status = AcpiNsEvaluate (Info);
6893446Smrj if (ACPI_SUCCESS (Status))
6903446Smrj {
6913446Smrj WalkInfo->Num_INI++;
6923446Smrj
6933446Smrj if ((AcpiDbgLevel <= ACPI_LV_ALL_EXCEPTIONS) &&
6943446Smrj (!(AcpiDbgLevel & ACPI_LV_INFO)))
6953446Smrj {
6963446Smrj ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT, "."));
6973446Smrj }
6983446Smrj }
6993446Smrj
7003446Smrj #ifdef ACPI_DEBUG_OUTPUT
7013446Smrj else if (Status != AE_NOT_FOUND)
7023446Smrj {
7033446Smrj /* Ignore error and move on to next device */
7043446Smrj
7053446Smrj char *ScopeName = AcpiNsGetExternalPathname (Info->ResolvedNode);
7063446Smrj
7073446Smrj ACPI_EXCEPTION ((AE_INFO, Status, "during %s._INI execution",
7083446Smrj ScopeName));
7093446Smrj ACPI_FREE (ScopeName);
7103446Smrj }
7113446Smrj #endif
7123446Smrj
7133446Smrj /* Ignore errors from above */
7143446Smrj
7153446Smrj Status = AE_OK;
7163446Smrj
7173446Smrj /*
7183446Smrj * The _INI method has been run if present; call the Global Initialization
7193446Smrj * Handler for this device.
7203446Smrj */
7213446Smrj if (AcpiGbl_InitHandler)
7223446Smrj {
7233446Smrj Status = AcpiGbl_InitHandler (DeviceNode, ACPI_INIT_DEVICE_INI);
7243446Smrj }
7253446Smrj
7263446Smrj return_ACPI_STATUS (Status);
7273446Smrj }
728