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