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