1 /******************************************************************************
3 * Module Name: nsinit - namespace initialization
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2011, 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.
45 #define __NSXFINIT_C__
47 #include <contrib/dev/acpica/include/acpi.h>
48 #include <contrib/dev/acpica/include/accommon.h>
49 #include <contrib/dev/acpica/include/acnamesp.h>
50 #include <contrib/dev/acpica/include/acdispat.h>
51 #include <contrib/dev/acpica/include/acinterp.h>
53 #define _COMPONENT ACPI_NAMESPACE
54 ACPI_MODULE_NAME ("nsinit")
56 /* Local prototypes */
60 ACPI_HANDLE ObjHandle,
67 ACPI_HANDLE ObjHandle,
73 AcpiNsFindIniMethods (
74 ACPI_HANDLE ObjHandle,
80 /*******************************************************************************
82 * FUNCTION: AcpiNsInitializeObjects
88 * DESCRIPTION: Walk the entire namespace and perform any necessary
89 * initialization on the objects found therein
91 ******************************************************************************/
94 AcpiNsInitializeObjects (
98 ACPI_INIT_WALK_INFO Info;
101 ACPI_FUNCTION_TRACE (NsInitializeObjects);
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:"));
109 /* Set all init info to zero */
111 ACPI_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 "\nInitialized %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", Info.MethodCount));
133 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
134 "%u Op Regions found\n", Info.OpRegionCount));
136 return_ACPI_STATUS (AE_OK);
140 /*******************************************************************************
142 * FUNCTION: AcpiNsInitializeDevices
146 * RETURN: ACPI_STATUS
148 * DESCRIPTION: Walk the entire namespace and initialize all ACPI devices.
149 * This means running _INI on all present devices.
151 * Note: We install PCI config space handler on region access,
154 ******************************************************************************/
157 AcpiNsInitializeDevices (
161 ACPI_DEVICE_WALK_INFO Info;
164 ACPI_FUNCTION_TRACE (NsInitializeDevices);
169 Info.DeviceCount = 0;
173 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT,
174 "Initializing Device/Processor/Thermal objects "
175 "by executing _INI methods:"));
177 /* Tree analysis: find all subtrees that contain _INI methods */
179 Status = AcpiNsWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT,
180 ACPI_UINT32_MAX, FALSE, AcpiNsFindIniMethods, NULL, &Info, NULL);
181 if (ACPI_FAILURE (Status))
186 /* Allocate the evaluation information block */
188 Info.EvaluateInfo = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_EVALUATE_INFO));
189 if (!Info.EvaluateInfo)
191 Status = AE_NO_MEMORY;
196 * Execute the "global" _INI method that may appear at the root. This
197 * support is provided for Windows compatibility (Vista+) and is not
198 * part of the ACPI specification.
200 Info.EvaluateInfo->PrefixNode = AcpiGbl_RootNode;
201 Info.EvaluateInfo->Pathname = METHOD_NAME__INI;
202 Info.EvaluateInfo->Parameters = NULL;
203 Info.EvaluateInfo->Flags = ACPI_IGNORE_RETURN_VALUE;
205 Status = AcpiNsEvaluate (Info.EvaluateInfo);
206 if (ACPI_SUCCESS (Status))
211 /* Walk namespace to execute all _INIs on present devices */
213 Status = AcpiNsWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT,
214 ACPI_UINT32_MAX, FALSE, AcpiNsInitOneDevice, NULL, &Info, NULL);
217 * Any _OSI requests should be completed by now. If the BIOS has
218 * requested any Windows OSI strings, we will always truncate
219 * I/O addresses to 16 bits -- for Windows compatibility.
221 if (AcpiGbl_OsiData >= ACPI_OSI_WIN_2000)
223 AcpiGbl_TruncateIoAddresses = TRUE;
226 ACPI_FREE (Info.EvaluateInfo);
227 if (ACPI_FAILURE (Status))
232 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT,
233 "\nExecuted %u _INI methods requiring %u _STA executions "
234 "(examined %u objects)\n",
235 Info.Num_INI, Info.Num_STA, Info.DeviceCount));
237 return_ACPI_STATUS (Status);
241 ACPI_EXCEPTION ((AE_INFO, Status, "During device initialization"));
242 return_ACPI_STATUS (Status);
246 /*******************************************************************************
248 * FUNCTION: AcpiNsInitOneObject
250 * PARAMETERS: ObjHandle - Node
251 * Level - Current nesting level
252 * Context - Points to a init info struct
253 * ReturnValue - Not used
257 * DESCRIPTION: Callback from AcpiWalkNamespace. Invoked for every object
258 * within the namespace.
260 * Currently, the only objects that require initialization are:
264 ******************************************************************************/
267 AcpiNsInitOneObject (
268 ACPI_HANDLE ObjHandle,
273 ACPI_OBJECT_TYPE Type;
274 ACPI_STATUS Status = AE_OK;
275 ACPI_INIT_WALK_INFO *Info = (ACPI_INIT_WALK_INFO *) Context;
276 ACPI_NAMESPACE_NODE *Node = (ACPI_NAMESPACE_NODE *) ObjHandle;
277 ACPI_OPERAND_OBJECT *ObjDesc;
280 ACPI_FUNCTION_NAME (NsInitOneObject);
285 /* And even then, we are only interested in a few object types */
287 Type = AcpiNsGetType (ObjHandle);
288 ObjDesc = AcpiNsGetAttachedObject (Node);
294 /* Increment counters for object types we are looking for */
298 case ACPI_TYPE_REGION:
299 Info->OpRegionCount++;
302 case ACPI_TYPE_BUFFER_FIELD:
306 case ACPI_TYPE_LOCAL_BANK_FIELD:
310 case ACPI_TYPE_BUFFER:
314 case ACPI_TYPE_PACKAGE:
315 Info->PackageCount++;
320 /* No init required, just exit now */
324 /* If the object is already initialized, nothing else to do */
326 if (ObjDesc->Common.Flags & AOPOBJ_DATA_VALID)
331 /* Must lock the interpreter before executing AML code */
333 AcpiExEnterInterpreter ();
336 * Each of these types can contain executable AML code within the
341 case ACPI_TYPE_REGION:
343 Info->OpRegionInit++;
344 Status = AcpiDsGetRegionArguments (ObjDesc);
347 case ACPI_TYPE_BUFFER_FIELD:
350 Status = AcpiDsGetBufferFieldArguments (ObjDesc);
353 case ACPI_TYPE_LOCAL_BANK_FIELD:
356 Status = AcpiDsGetBankFieldArguments (ObjDesc);
359 case ACPI_TYPE_BUFFER:
362 Status = AcpiDsGetBufferArguments (ObjDesc);
365 case ACPI_TYPE_PACKAGE:
368 Status = AcpiDsGetPackageArguments (ObjDesc);
372 /* No other types can get here */
376 if (ACPI_FAILURE (Status))
378 ACPI_EXCEPTION ((AE_INFO, Status,
379 "Could not execute arguments for [%4.4s] (%s)",
380 AcpiUtGetNodeName (Node), AcpiUtGetTypeName (Type)));
384 * Print a dot for each object unless we are going to print the entire
387 if (!(AcpiDbgLevel & ACPI_LV_INIT_NAMES))
389 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT, "."));
393 * We ignore errors from above, and always return OK, since we don't want
394 * to abort the walk on any single error.
396 AcpiExExitInterpreter ();
401 /*******************************************************************************
403 * FUNCTION: AcpiNsFindIniMethods
405 * PARAMETERS: ACPI_WALK_CALLBACK
407 * RETURN: ACPI_STATUS
409 * DESCRIPTION: Called during namespace walk. Finds objects named _INI under
410 * device/processor/thermal objects, and marks the entire subtree
411 * with a SUBTREE_HAS_INI flag. This flag is used during the
412 * subsequent device initialization walk to avoid entire subtrees
413 * that do not contain an _INI.
415 ******************************************************************************/
418 AcpiNsFindIniMethods (
419 ACPI_HANDLE ObjHandle,
424 ACPI_DEVICE_WALK_INFO *Info = ACPI_CAST_PTR (ACPI_DEVICE_WALK_INFO, Context);
425 ACPI_NAMESPACE_NODE *Node;
426 ACPI_NAMESPACE_NODE *ParentNode;
429 /* Keep count of device/processor/thermal objects */
431 Node = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, ObjHandle);
432 if ((Node->Type == ACPI_TYPE_DEVICE) ||
433 (Node->Type == ACPI_TYPE_PROCESSOR) ||
434 (Node->Type == ACPI_TYPE_THERMAL))
440 /* We are only looking for methods named _INI */
442 if (!ACPI_COMPARE_NAME (Node->Name.Ascii, METHOD_NAME__INI))
448 * The only _INI methods that we care about are those that are
449 * present under Device, Processor, and Thermal objects.
451 ParentNode = Node->Parent;
452 switch (ParentNode->Type)
454 case ACPI_TYPE_DEVICE:
455 case ACPI_TYPE_PROCESSOR:
456 case ACPI_TYPE_THERMAL:
458 /* Mark parent and bubble up the INI present flag to the root */
462 ParentNode->Flags |= ANOBJ_SUBTREE_HAS_INI;
463 ParentNode = ParentNode->Parent;
475 /*******************************************************************************
477 * FUNCTION: AcpiNsInitOneDevice
479 * PARAMETERS: ACPI_WALK_CALLBACK
481 * RETURN: ACPI_STATUS
483 * DESCRIPTION: This is called once per device soon after ACPI is enabled
484 * to initialize each device. It determines if the device is
485 * present, and if so, calls _INI.
487 ******************************************************************************/
490 AcpiNsInitOneDevice (
491 ACPI_HANDLE ObjHandle,
496 ACPI_DEVICE_WALK_INFO *WalkInfo = ACPI_CAST_PTR (ACPI_DEVICE_WALK_INFO, Context);
497 ACPI_EVALUATE_INFO *Info = WalkInfo->EvaluateInfo;
500 ACPI_NAMESPACE_NODE *DeviceNode;
503 ACPI_FUNCTION_TRACE (NsInitOneDevice);
506 /* We are interested in Devices, Processors and ThermalZones only */
508 DeviceNode = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, ObjHandle);
509 if ((DeviceNode->Type != ACPI_TYPE_DEVICE) &&
510 (DeviceNode->Type != ACPI_TYPE_PROCESSOR) &&
511 (DeviceNode->Type != ACPI_TYPE_THERMAL))
513 return_ACPI_STATUS (AE_OK);
517 * Because of an earlier namespace analysis, all subtrees that contain an
518 * _INI method are tagged.
520 * If this device subtree does not contain any _INI methods, we
521 * can exit now and stop traversing this entire subtree.
523 if (!(DeviceNode->Flags & ANOBJ_SUBTREE_HAS_INI))
525 return_ACPI_STATUS (AE_CTRL_DEPTH);
529 * Run _STA to determine if this device is present and functioning. We
530 * must know this information for two important reasons (from ACPI spec):
532 * 1) We can only run _INI if the device is present.
533 * 2) We must abort the device tree walk on this subtree if the device is
534 * not present and is not functional (we will not examine the children)
536 * The _STA method is not required to be present under the device, we
537 * assume the device is present if _STA does not exist.
539 ACPI_DEBUG_EXEC (AcpiUtDisplayInitPathname (
540 ACPI_TYPE_METHOD, DeviceNode, METHOD_NAME__STA));
542 Status = AcpiUtExecute_STA (DeviceNode, &Flags);
543 if (ACPI_FAILURE (Status))
545 /* Ignore error and move on to next device */
547 return_ACPI_STATUS (AE_OK);
551 * Flags == -1 means that _STA was not found. In this case, we assume that
552 * the device is both present and functional.
554 * From the ACPI spec, description of _STA:
556 * "If a device object (including the processor object) does not have an
557 * _STA object, then OSPM assumes that all of the above bits are set (in
558 * other words, the device is present, ..., and functioning)"
560 if (Flags != ACPI_UINT32_MAX)
566 * Examine the PRESENT and FUNCTIONING status bits
568 * Note: ACPI spec does not seem to specify behavior for the present but
569 * not functioning case, so we assume functioning if present.
571 if (!(Flags & ACPI_STA_DEVICE_PRESENT))
573 /* Device is not present, we must examine the Functioning bit */
575 if (Flags & ACPI_STA_DEVICE_FUNCTIONING)
578 * Device is not present but is "functioning". In this case,
579 * we will not run _INI, but we continue to examine the children
582 * From the ACPI spec, description of _STA: (Note - no mention
583 * of whether to run _INI or not on the device in question)
585 * "_STA may return bit 0 clear (not present) with bit 3 set
586 * (device is functional). This case is used to indicate a valid
587 * device for which no device driver should be loaded (for example,
588 * a bridge device.) Children of this device may be present and
589 * valid. OSPM should continue enumeration below a device whose
590 * _STA returns this bit combination"
592 return_ACPI_STATUS (AE_OK);
597 * Device is not present and is not functioning. We must abort the
598 * walk of this subtree immediately -- don't look at the children
601 * From the ACPI spec, description of _INI:
603 * "If the _STA method indicates that the device is not present,
604 * OSPM will not run the _INI and will not examine the children
605 * of the device for _INI methods"
607 return_ACPI_STATUS (AE_CTRL_DEPTH);
612 * The device is present or is assumed present if no _STA exists.
613 * Run the _INI if it exists (not required to exist)
615 * Note: We know there is an _INI within this subtree, but it may not be
616 * under this particular device, it may be lower in the branch.
618 ACPI_DEBUG_EXEC (AcpiUtDisplayInitPathname (
619 ACPI_TYPE_METHOD, DeviceNode, METHOD_NAME__INI));
621 Info->PrefixNode = DeviceNode;
622 Info->Pathname = METHOD_NAME__INI;
623 Info->Parameters = NULL;
624 Info->Flags = ACPI_IGNORE_RETURN_VALUE;
626 Status = AcpiNsEvaluate (Info);
627 if (ACPI_SUCCESS (Status))
631 if ((AcpiDbgLevel <= ACPI_LV_ALL_EXCEPTIONS) &&
632 (!(AcpiDbgLevel & ACPI_LV_INFO)))
634 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT, "."));
638 #ifdef ACPI_DEBUG_OUTPUT
639 else if (Status != AE_NOT_FOUND)
641 /* Ignore error and move on to next device */
643 char *ScopeName = AcpiNsGetExternalPathname (Info->ResolvedNode);
645 ACPI_EXCEPTION ((AE_INFO, Status, "during %s._INI execution",
647 ACPI_FREE (ScopeName);
651 /* Ignore errors from above */
656 * The _INI method has been run if present; call the Global Initialization
657 * Handler for this device.
659 if (AcpiGbl_InitHandler)
661 Status = AcpiGbl_InitHandler (DeviceNode, ACPI_INIT_DEVICE_INI);
664 return_ACPI_STATUS (Status);