1*3446Smrj /******************************************************************************
2*3446Smrj  *
3*3446Smrj  * Module Name: nsinit - namespace initialization
4*3446Smrj  *              $Revision: 1.84 $
5*3446Smrj  *
6*3446Smrj  *****************************************************************************/
7*3446Smrj 
8*3446Smrj /******************************************************************************
9*3446Smrj  *
10*3446Smrj  * 1. Copyright Notice
11*3446Smrj  *
12*3446Smrj  * Some or all of this work - Copyright (c) 1999 - 2006, Intel Corp.
13*3446Smrj  * All rights reserved.
14*3446Smrj  *
15*3446Smrj  * 2. License
16*3446Smrj  *
17*3446Smrj  * 2.1. This is your license from Intel Corp. under its intellectual property
18*3446Smrj  * rights.  You may have additional license terms from the party that provided
19*3446Smrj  * you this software, covering your right to use that party's intellectual
20*3446Smrj  * property rights.
21*3446Smrj  *
22*3446Smrj  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
23*3446Smrj  * copy of the source code appearing in this file ("Covered Code") an
24*3446Smrj  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
25*3446Smrj  * base code distributed originally by Intel ("Original Intel Code") to copy,
26*3446Smrj  * make derivatives, distribute, use and display any portion of the Covered
27*3446Smrj  * Code in any form, with the right to sublicense such rights; and
28*3446Smrj  *
29*3446Smrj  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
30*3446Smrj  * license (with the right to sublicense), under only those claims of Intel
31*3446Smrj  * patents that are infringed by the Original Intel Code, to make, use, sell,
32*3446Smrj  * offer to sell, and import the Covered Code and derivative works thereof
33*3446Smrj  * solely to the minimum extent necessary to exercise the above copyright
34*3446Smrj  * license, and in no event shall the patent license extend to any additions
35*3446Smrj  * to or modifications of the Original Intel Code.  No other license or right
36*3446Smrj  * is granted directly or by implication, estoppel or otherwise;
37*3446Smrj  *
38*3446Smrj  * The above copyright and patent license is granted only if the following
39*3446Smrj  * conditions are met:
40*3446Smrj  *
41*3446Smrj  * 3. Conditions
42*3446Smrj  *
43*3446Smrj  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
44*3446Smrj  * Redistribution of source code of any substantial portion of the Covered
45*3446Smrj  * Code or modification with rights to further distribute source must include
46*3446Smrj  * the above Copyright Notice, the above License, this list of Conditions,
47*3446Smrj  * and the following Disclaimer and Export Compliance provision.  In addition,
48*3446Smrj  * Licensee must cause all Covered Code to which Licensee contributes to
49*3446Smrj  * contain a file documenting the changes Licensee made to create that Covered
50*3446Smrj  * Code and the date of any change.  Licensee must include in that file the
51*3446Smrj  * documentation of any changes made by any predecessor Licensee.  Licensee
52*3446Smrj  * must include a prominent statement that the modification is derived,
53*3446Smrj  * directly or indirectly, from Original Intel Code.
54*3446Smrj  *
55*3446Smrj  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
56*3446Smrj  * Redistribution of source code of any substantial portion of the Covered
57*3446Smrj  * Code or modification without rights to further distribute source must
58*3446Smrj  * include the following Disclaimer and Export Compliance provision in the
59*3446Smrj  * documentation and/or other materials provided with distribution.  In
60*3446Smrj  * addition, Licensee may not authorize further sublicense of source of any
61*3446Smrj  * portion of the Covered Code, and must include terms to the effect that the
62*3446Smrj  * license from Licensee to its licensee is limited to the intellectual
63*3446Smrj  * property embodied in the software Licensee provides to its licensee, and
64*3446Smrj  * not to intellectual property embodied in modifications its licensee may
65*3446Smrj  * make.
66*3446Smrj  *
67*3446Smrj  * 3.3. Redistribution of Executable. Redistribution in executable form of any
68*3446Smrj  * substantial portion of the Covered Code or modification must reproduce the
69*3446Smrj  * above Copyright Notice, and the following Disclaimer and Export Compliance
70*3446Smrj  * provision in the documentation and/or other materials provided with the
71*3446Smrj  * distribution.
72*3446Smrj  *
73*3446Smrj  * 3.4. Intel retains all right, title, and interest in and to the Original
74*3446Smrj  * Intel Code.
75*3446Smrj  *
76*3446Smrj  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
77*3446Smrj  * Intel shall be used in advertising or otherwise to promote the sale, use or
78*3446Smrj  * other dealings in products derived from or relating to the Covered Code
79*3446Smrj  * without prior written authorization from Intel.
80*3446Smrj  *
81*3446Smrj  * 4. Disclaimer and Export Compliance
82*3446Smrj  *
83*3446Smrj  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
84*3446Smrj  * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
85*3446Smrj  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
86*3446Smrj  * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
87*3446Smrj  * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
88*3446Smrj  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
89*3446Smrj  * PARTICULAR PURPOSE.
90*3446Smrj  *
91*3446Smrj  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
92*3446Smrj  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
93*3446Smrj  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
94*3446Smrj  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
95*3446Smrj  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
96*3446Smrj  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
97*3446Smrj  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
98*3446Smrj  * LIMITED REMEDY.
99*3446Smrj  *
100*3446Smrj  * 4.3. Licensee shall not export, either directly or indirectly, any of this
101*3446Smrj  * software or system incorporating such software without first obtaining any
102*3446Smrj  * required license or other approval from the U. S. Department of Commerce or
103*3446Smrj  * any other agency or department of the United States Government.  In the
104*3446Smrj  * event Licensee exports any such software from the United States or
105*3446Smrj  * re-exports any such software from a foreign destination, Licensee shall
106*3446Smrj  * ensure that the distribution and export/re-export of the software is in
107*3446Smrj  * compliance with all laws, regulations, orders, or other restrictions of the
108*3446Smrj  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
109*3446Smrj  * any of its subsidiaries will export/re-export any technical data, process,
110*3446Smrj  * software, or service, directly or indirectly, to any country for which the
111*3446Smrj  * United States government or any agency thereof requires an export license,
112*3446Smrj  * other governmental approval, or letter of assurance, without first obtaining
113*3446Smrj  * such license, approval or letter.
114*3446Smrj  *
115*3446Smrj  *****************************************************************************/
116*3446Smrj 
117*3446Smrj 
118*3446Smrj #define __NSXFINIT_C__
119*3446Smrj 
120*3446Smrj #include "acpi.h"
121*3446Smrj #include "acnamesp.h"
122*3446Smrj #include "acdispat.h"
123*3446Smrj #include "acinterp.h"
124*3446Smrj 
125*3446Smrj #define _COMPONENT          ACPI_NAMESPACE
126*3446Smrj         ACPI_MODULE_NAME    ("nsinit")
127*3446Smrj 
128*3446Smrj /* Local prototypes */
129*3446Smrj 
130*3446Smrj static ACPI_STATUS
131*3446Smrj AcpiNsInitOneObject (
132*3446Smrj     ACPI_HANDLE             ObjHandle,
133*3446Smrj     UINT32                  Level,
134*3446Smrj     void                    *Context,
135*3446Smrj     void                    **ReturnValue);
136*3446Smrj 
137*3446Smrj static ACPI_STATUS
138*3446Smrj AcpiNsInitOneDevice (
139*3446Smrj     ACPI_HANDLE             ObjHandle,
140*3446Smrj     UINT32                  NestingLevel,
141*3446Smrj     void                    *Context,
142*3446Smrj     void                    **ReturnValue);
143*3446Smrj 
144*3446Smrj static ACPI_STATUS
145*3446Smrj AcpiNsFindIniMethods (
146*3446Smrj     ACPI_HANDLE             ObjHandle,
147*3446Smrj     UINT32                  NestingLevel,
148*3446Smrj     void                    *Context,
149*3446Smrj     void                    **ReturnValue);
150*3446Smrj 
151*3446Smrj 
152*3446Smrj /*******************************************************************************
153*3446Smrj  *
154*3446Smrj  * FUNCTION:    AcpiNsInitializeObjects
155*3446Smrj  *
156*3446Smrj  * PARAMETERS:  None
157*3446Smrj  *
158*3446Smrj  * RETURN:      Status
159*3446Smrj  *
160*3446Smrj  * DESCRIPTION: Walk the entire namespace and perform any necessary
161*3446Smrj  *              initialization on the objects found therein
162*3446Smrj  *
163*3446Smrj  ******************************************************************************/
164*3446Smrj 
165*3446Smrj ACPI_STATUS
166*3446Smrj AcpiNsInitializeObjects (
167*3446Smrj     void)
168*3446Smrj {
169*3446Smrj     ACPI_STATUS             Status;
170*3446Smrj     ACPI_INIT_WALK_INFO     Info;
171*3446Smrj 
172*3446Smrj 
173*3446Smrj     ACPI_FUNCTION_TRACE (NsInitializeObjects);
174*3446Smrj 
175*3446Smrj 
176*3446Smrj     ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
177*3446Smrj         "**** Starting initialization of namespace objects ****\n"));
178*3446Smrj     ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT,
179*3446Smrj         "Completing Region/Field/Buffer/Package initialization:"));
180*3446Smrj 
181*3446Smrj     /* Set all init info to zero */
182*3446Smrj 
183*3446Smrj     ACPI_MEMSET (&Info, 0, sizeof (ACPI_INIT_WALK_INFO));
184*3446Smrj 
185*3446Smrj     /* Walk entire namespace from the supplied root */
186*3446Smrj 
187*3446Smrj     Status = AcpiWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT,
188*3446Smrj                                 ACPI_UINT32_MAX, AcpiNsInitOneObject,
189*3446Smrj                                 &Info, NULL);
190*3446Smrj     if (ACPI_FAILURE (Status))
191*3446Smrj     {
192*3446Smrj         ACPI_EXCEPTION ((AE_INFO, Status, "During WalkNamespace"));
193*3446Smrj     }
194*3446Smrj 
195*3446Smrj     ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT,
196*3446Smrj         "\nInitialized %hd/%hd Regions %hd/%hd Fields %hd/%hd Buffers %hd/%hd Packages (%hd nodes)\n",
197*3446Smrj         Info.OpRegionInit,  Info.OpRegionCount,
198*3446Smrj         Info.FieldInit,     Info.FieldCount,
199*3446Smrj         Info.BufferInit,    Info.BufferCount,
200*3446Smrj         Info.PackageInit,   Info.PackageCount, Info.ObjectCount));
201*3446Smrj 
202*3446Smrj     ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
203*3446Smrj         "%hd Control Methods found\n", Info.MethodCount));
204*3446Smrj     ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
205*3446Smrj         "%hd Op Regions found\n", Info.OpRegionCount));
206*3446Smrj 
207*3446Smrj     return_ACPI_STATUS (AE_OK);
208*3446Smrj }
209*3446Smrj 
210*3446Smrj 
211*3446Smrj /*******************************************************************************
212*3446Smrj  *
213*3446Smrj  * FUNCTION:    AcpiNsInitializeDevices
214*3446Smrj  *
215*3446Smrj  * PARAMETERS:  None
216*3446Smrj  *
217*3446Smrj  * RETURN:      ACPI_STATUS
218*3446Smrj  *
219*3446Smrj  * DESCRIPTION: Walk the entire namespace and initialize all ACPI devices.
220*3446Smrj  *              This means running _INI on all present devices.
221*3446Smrj  *
222*3446Smrj  *              Note: We install PCI config space handler on region access,
223*3446Smrj  *              not here.
224*3446Smrj  *
225*3446Smrj  ******************************************************************************/
226*3446Smrj 
227*3446Smrj ACPI_STATUS
228*3446Smrj AcpiNsInitializeDevices (
229*3446Smrj     void)
230*3446Smrj {
231*3446Smrj     ACPI_STATUS             Status;
232*3446Smrj     ACPI_DEVICE_WALK_INFO   Info;
233*3446Smrj 
234*3446Smrj 
235*3446Smrj     ACPI_FUNCTION_TRACE (NsInitializeDevices);
236*3446Smrj 
237*3446Smrj 
238*3446Smrj     /* Init counters */
239*3446Smrj 
240*3446Smrj     Info.DeviceCount = 0;
241*3446Smrj     Info.Num_STA = 0;
242*3446Smrj     Info.Num_INI = 0;
243*3446Smrj 
244*3446Smrj     ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT,
245*3446Smrj         "Initializing Device/Processor/Thermal objects by executing _INI methods:"));
246*3446Smrj 
247*3446Smrj     /* Tree analysis: find all subtrees that contain _INI methods */
248*3446Smrj 
249*3446Smrj     Status = AcpiNsWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT,
250*3446Smrj                 ACPI_UINT32_MAX, FALSE, AcpiNsFindIniMethods, &Info, NULL);
251*3446Smrj     if (ACPI_FAILURE (Status))
252*3446Smrj     {
253*3446Smrj         goto ErrorExit;
254*3446Smrj     }
255*3446Smrj 
256*3446Smrj     /* Allocate the evaluation information block */
257*3446Smrj 
258*3446Smrj     Info.EvaluateInfo = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_EVALUATE_INFO));
259*3446Smrj     if (!Info.EvaluateInfo)
260*3446Smrj     {
261*3446Smrj         Status = AE_NO_MEMORY;
262*3446Smrj         goto ErrorExit;
263*3446Smrj     }
264*3446Smrj 
265*3446Smrj     /* Walk namespace to execute all _INIs on present devices */
266*3446Smrj 
267*3446Smrj     Status = AcpiNsWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT,
268*3446Smrj                 ACPI_UINT32_MAX, FALSE, AcpiNsInitOneDevice, &Info, NULL);
269*3446Smrj 
270*3446Smrj     ACPI_FREE (Info.EvaluateInfo);
271*3446Smrj     if (ACPI_FAILURE (Status))
272*3446Smrj     {
273*3446Smrj         goto ErrorExit;
274*3446Smrj     }
275*3446Smrj 
276*3446Smrj     ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT,
277*3446Smrj         "\nExecuted %hd _INI methods requiring %hd _STA executions (examined %hd objects)\n",
278*3446Smrj         Info.Num_INI, Info.Num_STA, Info.DeviceCount));
279*3446Smrj 
280*3446Smrj     return_ACPI_STATUS (Status);
281*3446Smrj 
282*3446Smrj 
283*3446Smrj ErrorExit:
284*3446Smrj     ACPI_EXCEPTION ((AE_INFO, Status, "During device initialization"));
285*3446Smrj     return_ACPI_STATUS (Status);
286*3446Smrj }
287*3446Smrj 
288*3446Smrj 
289*3446Smrj /*******************************************************************************
290*3446Smrj  *
291*3446Smrj  * FUNCTION:    AcpiNsInitOneObject
292*3446Smrj  *
293*3446Smrj  * PARAMETERS:  ObjHandle       - Node
294*3446Smrj  *              Level           - Current nesting level
295*3446Smrj  *              Context         - Points to a init info struct
296*3446Smrj  *              ReturnValue     - Not used
297*3446Smrj  *
298*3446Smrj  * RETURN:      Status
299*3446Smrj  *
300*3446Smrj  * DESCRIPTION: Callback from AcpiWalkNamespace.  Invoked for every object
301*3446Smrj  *              within the  namespace.
302*3446Smrj  *
303*3446Smrj  *              Currently, the only objects that require initialization are:
304*3446Smrj  *              1) Methods
305*3446Smrj  *              2) Op Regions
306*3446Smrj  *
307*3446Smrj  ******************************************************************************/
308*3446Smrj 
309*3446Smrj static ACPI_STATUS
310*3446Smrj AcpiNsInitOneObject (
311*3446Smrj     ACPI_HANDLE             ObjHandle,
312*3446Smrj     UINT32                  Level,
313*3446Smrj     void                    *Context,
314*3446Smrj     void                    **ReturnValue)
315*3446Smrj {
316*3446Smrj     ACPI_OBJECT_TYPE        Type;
317*3446Smrj     ACPI_STATUS             Status;
318*3446Smrj     ACPI_INIT_WALK_INFO     *Info = (ACPI_INIT_WALK_INFO *) Context;
319*3446Smrj     ACPI_NAMESPACE_NODE     *Node = (ACPI_NAMESPACE_NODE *) ObjHandle;
320*3446Smrj     ACPI_OPERAND_OBJECT     *ObjDesc;
321*3446Smrj 
322*3446Smrj 
323*3446Smrj     ACPI_FUNCTION_NAME (NsInitOneObject);
324*3446Smrj 
325*3446Smrj 
326*3446Smrj     Info->ObjectCount++;
327*3446Smrj 
328*3446Smrj     /* And even then, we are only interested in a few object types */
329*3446Smrj 
330*3446Smrj     Type = AcpiNsGetType (ObjHandle);
331*3446Smrj     ObjDesc = AcpiNsGetAttachedObject (Node);
332*3446Smrj     if (!ObjDesc)
333*3446Smrj     {
334*3446Smrj         return (AE_OK);
335*3446Smrj     }
336*3446Smrj 
337*3446Smrj     /* Increment counters for object types we are looking for */
338*3446Smrj 
339*3446Smrj     switch (Type)
340*3446Smrj     {
341*3446Smrj     case ACPI_TYPE_REGION:
342*3446Smrj         Info->OpRegionCount++;
343*3446Smrj         break;
344*3446Smrj 
345*3446Smrj     case ACPI_TYPE_BUFFER_FIELD:
346*3446Smrj         Info->FieldCount++;
347*3446Smrj         break;
348*3446Smrj 
349*3446Smrj     case ACPI_TYPE_BUFFER:
350*3446Smrj         Info->BufferCount++;
351*3446Smrj         break;
352*3446Smrj 
353*3446Smrj     case ACPI_TYPE_PACKAGE:
354*3446Smrj         Info->PackageCount++;
355*3446Smrj         break;
356*3446Smrj 
357*3446Smrj     default:
358*3446Smrj 
359*3446Smrj         /* No init required, just exit now */
360*3446Smrj         return (AE_OK);
361*3446Smrj     }
362*3446Smrj 
363*3446Smrj     /*
364*3446Smrj      * If the object is already initialized, nothing else to do
365*3446Smrj      */
366*3446Smrj     if (ObjDesc->Common.Flags & AOPOBJ_DATA_VALID)
367*3446Smrj     {
368*3446Smrj         return (AE_OK);
369*3446Smrj     }
370*3446Smrj 
371*3446Smrj     /*
372*3446Smrj      * Must lock the interpreter before executing AML code
373*3446Smrj      */
374*3446Smrj     Status = AcpiExEnterInterpreter ();
375*3446Smrj     if (ACPI_FAILURE (Status))
376*3446Smrj     {
377*3446Smrj         return (Status);
378*3446Smrj     }
379*3446Smrj 
380*3446Smrj     /*
381*3446Smrj      * Each of these types can contain executable AML code within the
382*3446Smrj      * declaration.
383*3446Smrj      */
384*3446Smrj     switch (Type)
385*3446Smrj     {
386*3446Smrj     case ACPI_TYPE_REGION:
387*3446Smrj 
388*3446Smrj         Info->OpRegionInit++;
389*3446Smrj         Status = AcpiDsGetRegionArguments (ObjDesc);
390*3446Smrj         break;
391*3446Smrj 
392*3446Smrj     case ACPI_TYPE_BUFFER_FIELD:
393*3446Smrj 
394*3446Smrj         Info->FieldInit++;
395*3446Smrj         Status = AcpiDsGetBufferFieldArguments (ObjDesc);
396*3446Smrj         break;
397*3446Smrj 
398*3446Smrj     case ACPI_TYPE_BUFFER:
399*3446Smrj 
400*3446Smrj         Info->BufferInit++;
401*3446Smrj         Status = AcpiDsGetBufferArguments (ObjDesc);
402*3446Smrj         break;
403*3446Smrj 
404*3446Smrj     case ACPI_TYPE_PACKAGE:
405*3446Smrj 
406*3446Smrj         Info->PackageInit++;
407*3446Smrj         Status = AcpiDsGetPackageArguments (ObjDesc);
408*3446Smrj         break;
409*3446Smrj 
410*3446Smrj     default:
411*3446Smrj         /* No other types can get here */
412*3446Smrj         break;
413*3446Smrj     }
414*3446Smrj 
415*3446Smrj     if (ACPI_FAILURE (Status))
416*3446Smrj     {
417*3446Smrj         ACPI_EXCEPTION ((AE_INFO, Status,
418*3446Smrj             "Could not execute arguments for [%4.4s] (%s)",
419*3446Smrj             AcpiUtGetNodeName (Node), AcpiUtGetTypeName (Type)));
420*3446Smrj     }
421*3446Smrj 
422*3446Smrj     /*
423*3446Smrj      * Print a dot for each object unless we are going to print the entire
424*3446Smrj      * pathname
425*3446Smrj      */
426*3446Smrj     if (!(AcpiDbgLevel & ACPI_LV_INIT_NAMES))
427*3446Smrj     {
428*3446Smrj         ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT, "."));
429*3446Smrj     }
430*3446Smrj 
431*3446Smrj     /*
432*3446Smrj      * We ignore errors from above, and always return OK, since we don't want
433*3446Smrj      * to abort the walk on any single error.
434*3446Smrj      */
435*3446Smrj     AcpiExExitInterpreter ();
436*3446Smrj     return (AE_OK);
437*3446Smrj }
438*3446Smrj 
439*3446Smrj 
440*3446Smrj /*******************************************************************************
441*3446Smrj  *
442*3446Smrj  * FUNCTION:    AcpiNsFindIniMethods
443*3446Smrj  *
444*3446Smrj  * PARAMETERS:  ACPI_WALK_CALLBACK
445*3446Smrj  *
446*3446Smrj  * RETURN:      ACPI_STATUS
447*3446Smrj  *
448*3446Smrj  * DESCRIPTION: Called during namespace walk. Finds objects named _INI under
449*3446Smrj  *              device/processor/thermal objects, and marks the entire subtree
450*3446Smrj  *              with a SUBTREE_HAS_INI flag. This flag is used during the
451*3446Smrj  *              subsequent device initialization walk to avoid entire subtrees
452*3446Smrj  *              that do not contain an _INI.
453*3446Smrj  *
454*3446Smrj  ******************************************************************************/
455*3446Smrj 
456*3446Smrj static ACPI_STATUS
457*3446Smrj AcpiNsFindIniMethods (
458*3446Smrj     ACPI_HANDLE             ObjHandle,
459*3446Smrj     UINT32                  NestingLevel,
460*3446Smrj     void                    *Context,
461*3446Smrj     void                    **ReturnValue)
462*3446Smrj {
463*3446Smrj     ACPI_DEVICE_WALK_INFO   *Info = ACPI_CAST_PTR (ACPI_DEVICE_WALK_INFO, Context);
464*3446Smrj     ACPI_NAMESPACE_NODE     *Node;
465*3446Smrj     ACPI_NAMESPACE_NODE     *ParentNode;
466*3446Smrj 
467*3446Smrj 
468*3446Smrj     /* Keep count of device/processor/thermal objects */
469*3446Smrj 
470*3446Smrj     Node = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, ObjHandle);
471*3446Smrj     if ((Node->Type == ACPI_TYPE_DEVICE)    ||
472*3446Smrj         (Node->Type == ACPI_TYPE_PROCESSOR) ||
473*3446Smrj         (Node->Type == ACPI_TYPE_THERMAL))
474*3446Smrj     {
475*3446Smrj         Info->DeviceCount++;
476*3446Smrj         return (AE_OK);
477*3446Smrj     }
478*3446Smrj 
479*3446Smrj     /* We are only looking for methods named _INI */
480*3446Smrj 
481*3446Smrj     if (!ACPI_COMPARE_NAME (Node->Name.Ascii, METHOD_NAME__INI))
482*3446Smrj     {
483*3446Smrj         return (AE_OK);
484*3446Smrj     }
485*3446Smrj 
486*3446Smrj     /*
487*3446Smrj      * The only _INI methods that we care about are those that are
488*3446Smrj      * present under Device, Processor, and Thermal objects.
489*3446Smrj      */
490*3446Smrj     ParentNode = AcpiNsGetParentNode (Node);
491*3446Smrj     switch (ParentNode->Type)
492*3446Smrj     {
493*3446Smrj     case ACPI_TYPE_DEVICE:
494*3446Smrj     case ACPI_TYPE_PROCESSOR:
495*3446Smrj     case ACPI_TYPE_THERMAL:
496*3446Smrj 
497*3446Smrj         /* Mark parent and bubble up the INI present flag to the root */
498*3446Smrj 
499*3446Smrj         while (ParentNode)
500*3446Smrj         {
501*3446Smrj             ParentNode->Flags |= ANOBJ_SUBTREE_HAS_INI;
502*3446Smrj             ParentNode = AcpiNsGetParentNode (ParentNode);
503*3446Smrj         }
504*3446Smrj         break;
505*3446Smrj 
506*3446Smrj     default:
507*3446Smrj         break;
508*3446Smrj     }
509*3446Smrj 
510*3446Smrj     return (AE_OK);
511*3446Smrj }
512*3446Smrj 
513*3446Smrj 
514*3446Smrj /*******************************************************************************
515*3446Smrj  *
516*3446Smrj  * FUNCTION:    AcpiNsInitOneDevice
517*3446Smrj  *
518*3446Smrj  * PARAMETERS:  ACPI_WALK_CALLBACK
519*3446Smrj  *
520*3446Smrj  * RETURN:      ACPI_STATUS
521*3446Smrj  *
522*3446Smrj  * DESCRIPTION: This is called once per device soon after ACPI is enabled
523*3446Smrj  *              to initialize each device. It determines if the device is
524*3446Smrj  *              present, and if so, calls _INI.
525*3446Smrj  *
526*3446Smrj  ******************************************************************************/
527*3446Smrj 
528*3446Smrj static ACPI_STATUS
529*3446Smrj AcpiNsInitOneDevice (
530*3446Smrj     ACPI_HANDLE             ObjHandle,
531*3446Smrj     UINT32                  NestingLevel,
532*3446Smrj     void                    *Context,
533*3446Smrj     void                    **ReturnValue)
534*3446Smrj {
535*3446Smrj     ACPI_DEVICE_WALK_INFO   *WalkInfo = ACPI_CAST_PTR (ACPI_DEVICE_WALK_INFO, Context);
536*3446Smrj     ACPI_EVALUATE_INFO      *Info = WalkInfo->EvaluateInfo;
537*3446Smrj     UINT32                  Flags;
538*3446Smrj     ACPI_STATUS             Status;
539*3446Smrj     ACPI_NAMESPACE_NODE     *DeviceNode;
540*3446Smrj 
541*3446Smrj 
542*3446Smrj     ACPI_FUNCTION_TRACE (NsInitOneDevice);
543*3446Smrj 
544*3446Smrj 
545*3446Smrj     /* We are interested in Devices, Processors and ThermalZones only */
546*3446Smrj 
547*3446Smrj     DeviceNode = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, ObjHandle);
548*3446Smrj     if ((DeviceNode->Type != ACPI_TYPE_DEVICE)    &&
549*3446Smrj         (DeviceNode->Type != ACPI_TYPE_PROCESSOR) &&
550*3446Smrj         (DeviceNode->Type != ACPI_TYPE_THERMAL))
551*3446Smrj     {
552*3446Smrj         return_ACPI_STATUS (AE_OK);
553*3446Smrj     }
554*3446Smrj 
555*3446Smrj     /*
556*3446Smrj      * Because of an earlier namespace analysis, all subtrees that contain an
557*3446Smrj      * _INI method are tagged.
558*3446Smrj      *
559*3446Smrj      * If this device subtree does not contain any _INI methods, we
560*3446Smrj      * can exit now and stop traversing this entire subtree.
561*3446Smrj      */
562*3446Smrj     if (!(DeviceNode->Flags & ANOBJ_SUBTREE_HAS_INI))
563*3446Smrj     {
564*3446Smrj         return_ACPI_STATUS (AE_CTRL_DEPTH);
565*3446Smrj     }
566*3446Smrj 
567*3446Smrj     /*
568*3446Smrj      * Run _STA to determine if this device is present and functioning. We
569*3446Smrj      * must know this information for two important reasons (from ACPI spec):
570*3446Smrj      *
571*3446Smrj      * 1) We can only run _INI if the device is present.
572*3446Smrj      * 2) We must abort the device tree walk on this subtree if the device is
573*3446Smrj      *    not present and is not functional (we will not examine the children)
574*3446Smrj      *
575*3446Smrj      * The _STA method is not required to be present under the device, we
576*3446Smrj      * assume the device is present if _STA does not exist.
577*3446Smrj      */
578*3446Smrj     ACPI_DEBUG_EXEC (AcpiUtDisplayInitPathname (
579*3446Smrj         ACPI_TYPE_METHOD, DeviceNode, METHOD_NAME__STA));
580*3446Smrj 
581*3446Smrj     Status = AcpiUtExecute_STA (DeviceNode, &Flags);
582*3446Smrj     if (ACPI_FAILURE (Status))
583*3446Smrj     {
584*3446Smrj         /* Ignore error and move on to next device */
585*3446Smrj 
586*3446Smrj         return_ACPI_STATUS (AE_OK);
587*3446Smrj     }
588*3446Smrj 
589*3446Smrj     /*
590*3446Smrj      * Flags == -1 means that _STA was not found. In this case, we assume that
591*3446Smrj      * the device is both present and functional.
592*3446Smrj      *
593*3446Smrj      * From the ACPI spec, description of _STA:
594*3446Smrj      *
595*3446Smrj      * "If a device object (including the processor object) does not have an
596*3446Smrj      * _STA object, then OSPM assumes that all of the above bits are set (in
597*3446Smrj      * other words, the device is present, ..., and functioning)"
598*3446Smrj      */
599*3446Smrj     if (Flags != ACPI_UINT32_MAX)
600*3446Smrj     {
601*3446Smrj         WalkInfo->Num_STA++;
602*3446Smrj     }
603*3446Smrj 
604*3446Smrj     /*
605*3446Smrj      * Examine the PRESENT and FUNCTIONING status bits
606*3446Smrj      *
607*3446Smrj      * Note: ACPI spec does not seem to specify behavior for the present but
608*3446Smrj      * not functioning case, so we assume functioning if present.
609*3446Smrj      */
610*3446Smrj     if (!(Flags & ACPI_STA_DEVICE_PRESENT))
611*3446Smrj     {
612*3446Smrj         /* Device is not present, we must examine the Functioning bit */
613*3446Smrj 
614*3446Smrj         if (Flags & ACPI_STA_DEVICE_FUNCTIONING)
615*3446Smrj         {
616*3446Smrj             /*
617*3446Smrj              * Device is not present but is "functioning". In this case,
618*3446Smrj              * we will not run _INI, but we continue to examine the children
619*3446Smrj              * of this device.
620*3446Smrj              *
621*3446Smrj              * From the ACPI spec, description of _STA: (Note - no mention
622*3446Smrj              * of whether to run _INI or not on the device in question)
623*3446Smrj              *
624*3446Smrj              * "_STA may return bit 0 clear (not present) with bit 3 set
625*3446Smrj              * (device is functional). This case is used to indicate a valid
626*3446Smrj              * device for which no device driver should be loaded (for example,
627*3446Smrj              * a bridge device.) Children of this device may be present and
628*3446Smrj              * valid. OSPM should continue enumeration below a device whose
629*3446Smrj              * _STA returns this bit combination"
630*3446Smrj              */
631*3446Smrj             return_ACPI_STATUS (AE_OK);
632*3446Smrj         }
633*3446Smrj         else
634*3446Smrj         {
635*3446Smrj             /*
636*3446Smrj              * Device is not present and is not functioning. We must abort the
637*3446Smrj              * walk of this subtree immediately -- don't look at the children
638*3446Smrj              * of such a device.
639*3446Smrj              *
640*3446Smrj              * From the ACPI spec, description of _INI:
641*3446Smrj              *
642*3446Smrj              * "If the _STA method indicates that the device is not present,
643*3446Smrj              * OSPM will not run the _INI and will not examine the children
644*3446Smrj              * of the device for _INI methods"
645*3446Smrj              */
646*3446Smrj             return_ACPI_STATUS (AE_CTRL_DEPTH);
647*3446Smrj         }
648*3446Smrj     }
649*3446Smrj 
650*3446Smrj     /*
651*3446Smrj      * The device is present or is assumed present if no _STA exists.
652*3446Smrj      * Run the _INI if it exists (not required to exist)
653*3446Smrj      *
654*3446Smrj      * Note: We know there is an _INI within this subtree, but it may not be
655*3446Smrj      * under this particular device, it may be lower in the branch.
656*3446Smrj      */
657*3446Smrj     ACPI_DEBUG_EXEC (AcpiUtDisplayInitPathname (
658*3446Smrj         ACPI_TYPE_METHOD, DeviceNode, METHOD_NAME__INI));
659*3446Smrj 
660*3446Smrj     Info->PrefixNode = DeviceNode;
661*3446Smrj     Info->Pathname = METHOD_NAME__INI;
662*3446Smrj     Info->Parameters = NULL;
663*3446Smrj     Info->ParameterType = ACPI_PARAM_ARGS;
664*3446Smrj     Info->Flags = ACPI_IGNORE_RETURN_VALUE;
665*3446Smrj 
666*3446Smrj     Status = AcpiNsEvaluate (Info);
667*3446Smrj     if (ACPI_SUCCESS (Status))
668*3446Smrj     {
669*3446Smrj         WalkInfo->Num_INI++;
670*3446Smrj 
671*3446Smrj         if ((AcpiDbgLevel <= ACPI_LV_ALL_EXCEPTIONS) &&
672*3446Smrj             (!(AcpiDbgLevel & ACPI_LV_INFO)))
673*3446Smrj         {
674*3446Smrj             ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT, "."));
675*3446Smrj         }
676*3446Smrj     }
677*3446Smrj 
678*3446Smrj #ifdef ACPI_DEBUG_OUTPUT
679*3446Smrj     else if (Status != AE_NOT_FOUND)
680*3446Smrj     {
681*3446Smrj         /* Ignore error and move on to next device */
682*3446Smrj 
683*3446Smrj         char *ScopeName = AcpiNsGetExternalPathname (Info->ResolvedNode);
684*3446Smrj 
685*3446Smrj         ACPI_EXCEPTION ((AE_INFO, Status, "during %s._INI execution",
686*3446Smrj             ScopeName));
687*3446Smrj         ACPI_FREE (ScopeName);
688*3446Smrj     }
689*3446Smrj #endif
690*3446Smrj 
691*3446Smrj     /* Ignore errors from above */
692*3446Smrj 
693*3446Smrj     Status = AE_OK;
694*3446Smrj 
695*3446Smrj     /*
696*3446Smrj      * The _INI method has been run if present; call the Global Initialization
697*3446Smrj      * Handler for this device.
698*3446Smrj      */
699*3446Smrj     if (AcpiGbl_InitHandler)
700*3446Smrj     {
701*3446Smrj         Status = AcpiGbl_InitHandler (DeviceNode, ACPI_INIT_DEVICE_INI);
702*3446Smrj     }
703*3446Smrj 
704*3446Smrj     return_ACPI_STATUS (Status);
705*3446Smrj }
706