1 /******************************************************************************
3 * Module Name: nsinit - namespace initialization
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2016, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
51 #define _COMPONENT ACPI_NAMESPACE
52 ACPI_MODULE_NAME ("nsinit")
54 /* Local prototypes */
58 ACPI_HANDLE ObjHandle
,
65 ACPI_HANDLE ObjHandle
,
71 AcpiNsFindIniMethods (
72 ACPI_HANDLE ObjHandle
,
78 /*******************************************************************************
80 * FUNCTION: AcpiNsInitializeObjects
86 * DESCRIPTION: Walk the entire namespace and perform any necessary
87 * initialization on the objects found therein
89 ******************************************************************************/
92 AcpiNsInitializeObjects (
96 ACPI_INIT_WALK_INFO Info
;
99 ACPI_FUNCTION_TRACE (NsInitializeObjects
);
102 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC
,
103 "[Init] Completing Initialization of ACPI Objects\n"));
104 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH
,
105 "**** Starting initialization of namespace objects ****\n"));
106 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT
,
107 "Completing Region/Field/Buffer/Package initialization:\n"));
109 /* Set all init info to zero */
111 memset (&Info
, 0, sizeof (ACPI_INIT_WALK_INFO
));
113 /* Walk entire namespace from the supplied root */
115 Status
= AcpiWalkNamespace (ACPI_TYPE_ANY
, ACPI_ROOT_OBJECT
,
116 ACPI_UINT32_MAX
, AcpiNsInitOneObject
, NULL
,
118 if (ACPI_FAILURE (Status
))
120 ACPI_EXCEPTION ((AE_INFO
, Status
, "During WalkNamespace"));
123 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT
,
124 " Initialized %u/%u Regions %u/%u Fields %u/%u "
125 "Buffers %u/%u Packages (%u nodes)\n",
126 Info
.OpRegionInit
, Info
.OpRegionCount
,
127 Info
.FieldInit
, Info
.FieldCount
,
128 Info
.BufferInit
, Info
.BufferCount
,
129 Info
.PackageInit
, Info
.PackageCount
, Info
.ObjectCount
));
131 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH
,
132 "%u Control Methods found\n%u Op Regions found\n",
133 Info
.MethodCount
, Info
.OpRegionCount
));
135 return_ACPI_STATUS (AE_OK
);
139 /*******************************************************************************
141 * FUNCTION: AcpiNsInitializeDevices
145 * RETURN: ACPI_STATUS
147 * DESCRIPTION: Walk the entire namespace and initialize all ACPI devices.
148 * This means running _INI on all present devices.
150 * Note: We install PCI config space handler on region access,
153 ******************************************************************************/
156 AcpiNsInitializeDevices (
159 ACPI_STATUS Status
= AE_OK
;
160 ACPI_DEVICE_WALK_INFO Info
;
164 ACPI_FUNCTION_TRACE (NsInitializeDevices
);
167 if (!(Flags
& ACPI_NO_DEVICE_INIT
))
169 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC
,
170 "[Init] Initializing ACPI Devices\n"));
174 Info
.DeviceCount
= 0;
178 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT
,
179 "Initializing Device/Processor/Thermal objects "
180 "and executing _INI/_STA methods:\n"));
182 /* Tree analysis: find all subtrees that contain _INI methods */
184 Status
= AcpiNsWalkNamespace (ACPI_TYPE_ANY
, ACPI_ROOT_OBJECT
,
185 ACPI_UINT32_MAX
, FALSE
, AcpiNsFindIniMethods
, NULL
, &Info
, NULL
);
186 if (ACPI_FAILURE (Status
))
191 /* Allocate the evaluation information block */
193 Info
.EvaluateInfo
= ACPI_ALLOCATE_ZEROED (sizeof (ACPI_EVALUATE_INFO
));
194 if (!Info
.EvaluateInfo
)
196 Status
= AE_NO_MEMORY
;
201 * Execute the "global" _INI method that may appear at the root.
202 * This support is provided for Windows compatibility (Vista+) and
203 * is not part of the ACPI specification.
205 Info
.EvaluateInfo
->PrefixNode
= AcpiGbl_RootNode
;
206 Info
.EvaluateInfo
->RelativePathname
= METHOD_NAME__INI
;
207 Info
.EvaluateInfo
->Parameters
= NULL
;
208 Info
.EvaluateInfo
->Flags
= ACPI_IGNORE_RETURN_VALUE
;
210 Status
= AcpiNsEvaluate (Info
.EvaluateInfo
);
211 if (ACPI_SUCCESS (Status
))
218 * There appears to be a strict order requirement for \_SB._INI,
219 * which should be evaluated before any _REG evaluations.
221 Status
= AcpiGetHandle (NULL
, "\\_SB", &Handle
);
222 if (ACPI_SUCCESS (Status
))
224 memset (Info
.EvaluateInfo
, 0, sizeof (ACPI_EVALUATE_INFO
));
225 Info
.EvaluateInfo
->PrefixNode
= Handle
;
226 Info
.EvaluateInfo
->RelativePathname
= METHOD_NAME__INI
;
227 Info
.EvaluateInfo
->Parameters
= NULL
;
228 Info
.EvaluateInfo
->Flags
= ACPI_IGNORE_RETURN_VALUE
;
230 Status
= AcpiNsEvaluate (Info
.EvaluateInfo
);
231 if (ACPI_SUCCESS (Status
))
239 * Run all _REG methods
241 * Note: Any objects accessed by the _REG methods will be automatically
242 * initialized, even if they contain executable AML (see the call to
243 * AcpiNsInitializeObjects below).
245 * Note: According to the ACPI specification, we actually needn't execute
246 * _REG for SystemMemory/SystemIo operation regions, but for PCI_Config
247 * operation regions, it is required to evaluate _REG for those on a PCI
248 * root bus that doesn't contain _BBN object. So this code is kept here
249 * in order not to break things.
251 if (!(Flags
& ACPI_NO_ADDRESS_SPACE_INIT
))
253 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC
,
254 "[Init] Executing _REG OpRegion methods\n"));
256 Status
= AcpiEvInitializeOpRegions ();
257 if (ACPI_FAILURE (Status
))
263 if (!(Flags
& ACPI_NO_DEVICE_INIT
))
265 /* Walk namespace to execute all _INIs on present devices */
267 Status
= AcpiNsWalkNamespace (ACPI_TYPE_ANY
, ACPI_ROOT_OBJECT
,
268 ACPI_UINT32_MAX
, FALSE
, AcpiNsInitOneDevice
, NULL
, &Info
, NULL
);
271 * Any _OSI requests should be completed by now. If the BIOS has
272 * requested any Windows OSI strings, we will always truncate
273 * I/O addresses to 16 bits -- for Windows compatibility.
275 if (AcpiGbl_OsiData
>= ACPI_OSI_WIN_2000
)
277 AcpiGbl_TruncateIoAddresses
= TRUE
;
280 ACPI_FREE (Info
.EvaluateInfo
);
281 if (ACPI_FAILURE (Status
))
286 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT
,
287 " Executed %u _INI methods requiring %u _STA executions "
288 "(examined %u objects)\n",
289 Info
.Num_INI
, Info
.Num_STA
, Info
.DeviceCount
));
292 return_ACPI_STATUS (Status
);
296 ACPI_EXCEPTION ((AE_INFO
, Status
, "During device initialization"));
297 return_ACPI_STATUS (Status
);
301 /*******************************************************************************
303 * FUNCTION: AcpiNsInitOneObject
305 * PARAMETERS: ObjHandle - Node
306 * Level - Current nesting level
307 * Context - Points to a init info struct
308 * ReturnValue - Not used
312 * DESCRIPTION: Callback from AcpiWalkNamespace. Invoked for every object
313 * within the namespace.
315 * Currently, the only objects that require initialization are:
319 ******************************************************************************/
322 AcpiNsInitOneObject (
323 ACPI_HANDLE ObjHandle
,
328 ACPI_OBJECT_TYPE Type
;
329 ACPI_STATUS Status
= AE_OK
;
330 ACPI_INIT_WALK_INFO
*Info
= (ACPI_INIT_WALK_INFO
*) Context
;
331 ACPI_NAMESPACE_NODE
*Node
= (ACPI_NAMESPACE_NODE
*) ObjHandle
;
332 ACPI_OPERAND_OBJECT
*ObjDesc
;
335 ACPI_FUNCTION_NAME (NsInitOneObject
);
340 /* And even then, we are only interested in a few object types */
342 Type
= AcpiNsGetType (ObjHandle
);
343 ObjDesc
= AcpiNsGetAttachedObject (Node
);
349 /* Increment counters for object types we are looking for */
353 case ACPI_TYPE_REGION
:
355 Info
->OpRegionCount
++;
358 case ACPI_TYPE_BUFFER_FIELD
:
363 case ACPI_TYPE_LOCAL_BANK_FIELD
:
368 case ACPI_TYPE_BUFFER
:
373 case ACPI_TYPE_PACKAGE
:
375 Info
->PackageCount
++;
380 /* No init required, just exit now */
385 /* If the object is already initialized, nothing else to do */
387 if (ObjDesc
->Common
.Flags
& AOPOBJ_DATA_VALID
)
392 /* Must lock the interpreter before executing AML code */
394 AcpiExEnterInterpreter ();
397 * Each of these types can contain executable AML code within the
402 case ACPI_TYPE_REGION
:
404 Info
->OpRegionInit
++;
405 Status
= AcpiDsGetRegionArguments (ObjDesc
);
408 case ACPI_TYPE_BUFFER_FIELD
:
411 Status
= AcpiDsGetBufferFieldArguments (ObjDesc
);
414 case ACPI_TYPE_LOCAL_BANK_FIELD
:
417 Status
= AcpiDsGetBankFieldArguments (ObjDesc
);
420 case ACPI_TYPE_BUFFER
:
423 Status
= AcpiDsGetBufferArguments (ObjDesc
);
426 case ACPI_TYPE_PACKAGE
:
429 Status
= AcpiDsGetPackageArguments (ObjDesc
);
434 /* No other types can get here */
439 if (ACPI_FAILURE (Status
))
441 ACPI_EXCEPTION ((AE_INFO
, Status
,
442 "Could not execute arguments for [%4.4s] (%s)",
443 AcpiUtGetNodeName (Node
), AcpiUtGetTypeName (Type
)));
447 * We ignore errors from above, and always return OK, since we don't want
448 * to abort the walk on any single error.
450 AcpiExExitInterpreter ();
455 /*******************************************************************************
457 * FUNCTION: AcpiNsFindIniMethods
459 * PARAMETERS: ACPI_WALK_CALLBACK
461 * RETURN: ACPI_STATUS
463 * DESCRIPTION: Called during namespace walk. Finds objects named _INI under
464 * device/processor/thermal objects, and marks the entire subtree
465 * with a SUBTREE_HAS_INI flag. This flag is used during the
466 * subsequent device initialization walk to avoid entire subtrees
467 * that do not contain an _INI.
469 ******************************************************************************/
472 AcpiNsFindIniMethods (
473 ACPI_HANDLE ObjHandle
,
478 ACPI_DEVICE_WALK_INFO
*Info
= ACPI_CAST_PTR (ACPI_DEVICE_WALK_INFO
, Context
);
479 ACPI_NAMESPACE_NODE
*Node
;
480 ACPI_NAMESPACE_NODE
*ParentNode
;
483 /* Keep count of device/processor/thermal objects */
485 Node
= ACPI_CAST_PTR (ACPI_NAMESPACE_NODE
, ObjHandle
);
486 if ((Node
->Type
== ACPI_TYPE_DEVICE
) ||
487 (Node
->Type
== ACPI_TYPE_PROCESSOR
) ||
488 (Node
->Type
== ACPI_TYPE_THERMAL
))
494 /* We are only looking for methods named _INI */
496 if (!ACPI_COMPARE_NAME (Node
->Name
.Ascii
, METHOD_NAME__INI
))
502 * The only _INI methods that we care about are those that are
503 * present under Device, Processor, and Thermal objects.
505 ParentNode
= Node
->Parent
;
506 switch (ParentNode
->Type
)
508 case ACPI_TYPE_DEVICE
:
509 case ACPI_TYPE_PROCESSOR
:
510 case ACPI_TYPE_THERMAL
:
512 /* Mark parent and bubble up the INI present flag to the root */
516 ParentNode
->Flags
|= ANOBJ_SUBTREE_HAS_INI
;
517 ParentNode
= ParentNode
->Parent
;
530 /*******************************************************************************
532 * FUNCTION: AcpiNsInitOneDevice
534 * PARAMETERS: ACPI_WALK_CALLBACK
536 * RETURN: ACPI_STATUS
538 * DESCRIPTION: This is called once per device soon after ACPI is enabled
539 * to initialize each device. It determines if the device is
540 * present, and if so, calls _INI.
542 ******************************************************************************/
545 AcpiNsInitOneDevice (
546 ACPI_HANDLE ObjHandle
,
551 ACPI_DEVICE_WALK_INFO
*WalkInfo
= ACPI_CAST_PTR (ACPI_DEVICE_WALK_INFO
, Context
);
552 ACPI_EVALUATE_INFO
*Info
= WalkInfo
->EvaluateInfo
;
555 ACPI_NAMESPACE_NODE
*DeviceNode
;
558 ACPI_FUNCTION_TRACE (NsInitOneDevice
);
561 /* We are interested in Devices, Processors and ThermalZones only */
563 DeviceNode
= ACPI_CAST_PTR (ACPI_NAMESPACE_NODE
, ObjHandle
);
564 if ((DeviceNode
->Type
!= ACPI_TYPE_DEVICE
) &&
565 (DeviceNode
->Type
!= ACPI_TYPE_PROCESSOR
) &&
566 (DeviceNode
->Type
!= ACPI_TYPE_THERMAL
))
568 return_ACPI_STATUS (AE_OK
);
572 * Because of an earlier namespace analysis, all subtrees that contain an
573 * _INI method are tagged.
575 * If this device subtree does not contain any _INI methods, we
576 * can exit now and stop traversing this entire subtree.
578 if (!(DeviceNode
->Flags
& ANOBJ_SUBTREE_HAS_INI
))
580 return_ACPI_STATUS (AE_CTRL_DEPTH
);
584 * Run _STA to determine if this device is present and functioning. We
585 * must know this information for two important reasons (from ACPI spec):
587 * 1) We can only run _INI if the device is present.
588 * 2) We must abort the device tree walk on this subtree if the device is
589 * not present and is not functional (we will not examine the children)
591 * The _STA method is not required to be present under the device, we
592 * assume the device is present if _STA does not exist.
594 ACPI_DEBUG_EXEC (AcpiUtDisplayInitPathname (
595 ACPI_TYPE_METHOD
, DeviceNode
, METHOD_NAME__STA
));
597 Status
= AcpiUtExecute_STA (DeviceNode
, &Flags
);
598 if (ACPI_FAILURE (Status
))
600 /* Ignore error and move on to next device */
602 return_ACPI_STATUS (AE_OK
);
606 * Flags == -1 means that _STA was not found. In this case, we assume that
607 * the device is both present and functional.
609 * From the ACPI spec, description of _STA:
611 * "If a device object (including the processor object) does not have an
612 * _STA object, then OSPM assumes that all of the above bits are set (in
613 * other words, the device is present, ..., and functioning)"
615 if (Flags
!= ACPI_UINT32_MAX
)
621 * Examine the PRESENT and FUNCTIONING status bits
623 * Note: ACPI spec does not seem to specify behavior for the present but
624 * not functioning case, so we assume functioning if present.
626 if (!(Flags
& ACPI_STA_DEVICE_PRESENT
))
628 /* Device is not present, we must examine the Functioning bit */
630 if (Flags
& ACPI_STA_DEVICE_FUNCTIONING
)
633 * Device is not present but is "functioning". In this case,
634 * we will not run _INI, but we continue to examine the children
637 * From the ACPI spec, description of _STA: (Note - no mention
638 * of whether to run _INI or not on the device in question)
640 * "_STA may return bit 0 clear (not present) with bit 3 set
641 * (device is functional). This case is used to indicate a valid
642 * device for which no device driver should be loaded (for example,
643 * a bridge device.) Children of this device may be present and
644 * valid. OSPM should continue enumeration below a device whose
645 * _STA returns this bit combination"
647 return_ACPI_STATUS (AE_OK
);
652 * Device is not present and is not functioning. We must abort the
653 * walk of this subtree immediately -- don't look at the children
656 * From the ACPI spec, description of _INI:
658 * "If the _STA method indicates that the device is not present,
659 * OSPM will not run the _INI and will not examine the children
660 * of the device for _INI methods"
662 return_ACPI_STATUS (AE_CTRL_DEPTH
);
667 * The device is present or is assumed present if no _STA exists.
668 * Run the _INI if it exists (not required to exist)
670 * Note: We know there is an _INI within this subtree, but it may not be
671 * under this particular device, it may be lower in the branch.
673 if (!ACPI_COMPARE_NAME (DeviceNode
->Name
.Ascii
, "_SB_") ||
674 DeviceNode
->Parent
!= AcpiGbl_RootNode
)
676 ACPI_DEBUG_EXEC (AcpiUtDisplayInitPathname (
677 ACPI_TYPE_METHOD
, DeviceNode
, METHOD_NAME__INI
));
679 memset (Info
, 0, sizeof (ACPI_EVALUATE_INFO
));
680 Info
->PrefixNode
= DeviceNode
;
681 Info
->RelativePathname
= METHOD_NAME__INI
;
682 Info
->Parameters
= NULL
;
683 Info
->Flags
= ACPI_IGNORE_RETURN_VALUE
;
685 Status
= AcpiNsEvaluate (Info
);
686 if (ACPI_SUCCESS (Status
))
691 #ifdef ACPI_DEBUG_OUTPUT
692 else if (Status
!= AE_NOT_FOUND
)
694 /* Ignore error and move on to next device */
696 char *ScopeName
= AcpiNsGetNormalizedPathname (DeviceNode
, TRUE
);
698 ACPI_EXCEPTION ((AE_INFO
, Status
, "during %s._INI execution",
700 ACPI_FREE (ScopeName
);
705 /* Ignore errors from above */
710 * The _INI method has been run if present; call the Global Initialization
711 * Handler for this device.
713 if (AcpiGbl_InitHandler
)
715 Status
= AcpiGbl_InitHandler (DeviceNode
, ACPI_INIT_DEVICE_INI
);
718 return_ACPI_STATUS (Status
);