nsinit.c revision 250341
10SN/A/****************************************************************************** 2553SN/A * 30SN/A * Module Name: nsinit - namespace initialization 40SN/A * 50SN/A *****************************************************************************/ 60SN/A 70SN/A/* 80SN/A * Copyright (C) 2000 - 2013, Intel Corp. 90SN/A * All rights reserved. 100SN/A * 110SN/A * Redistribution and use in source and binary forms, with or without 120SN/A * modification, are permitted provided that the following conditions 130SN/A * are met: 140SN/A * 1. Redistributions of source code must retain the above copyright 150SN/A * notice, this list of conditions, and the following disclaimer, 160SN/A * without modification. 170SN/A * 2. Redistributions in binary form must reproduce at minimum a disclaimer 180SN/A * substantially similar to the "NO WARRANTY" disclaimer below 19553SN/A * ("Disclaimer") and any redistribution must be conditioned upon 20553SN/A * including a substantially similar Disclaimer requirement for further 21553SN/A * binary redistribution. 220SN/A * 3. Neither the names of the above-listed copyright holders nor the names 230SN/A * of any contributors may be used to endorse or promote products derived 240SN/A * from this software without specific prior written permission. 250SN/A * 260SN/A * 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. 29 * 30 * NO WARRANTY 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. 42 */ 43 44 45#define __NSXFINIT_C__ 46 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> 52 53#define _COMPONENT ACPI_NAMESPACE 54 ACPI_MODULE_NAME ("nsinit") 55 56/* Local prototypes */ 57 58static ACPI_STATUS 59AcpiNsInitOneObject ( 60 ACPI_HANDLE ObjHandle, 61 UINT32 Level, 62 void *Context, 63 void **ReturnValue); 64 65static ACPI_STATUS 66AcpiNsInitOneDevice ( 67 ACPI_HANDLE ObjHandle, 68 UINT32 NestingLevel, 69 void *Context, 70 void **ReturnValue); 71 72static ACPI_STATUS 73AcpiNsFindIniMethods ( 74 ACPI_HANDLE ObjHandle, 75 UINT32 NestingLevel, 76 void *Context, 77 void **ReturnValue); 78 79 80/******************************************************************************* 81 * 82 * FUNCTION: AcpiNsInitializeObjects 83 * 84 * PARAMETERS: None 85 * 86 * RETURN: Status 87 * 88 * DESCRIPTION: Walk the entire namespace and perform any necessary 89 * initialization on the objects found therein 90 * 91 ******************************************************************************/ 92 93ACPI_STATUS 94AcpiNsInitializeObjects ( 95 void) 96{ 97 ACPI_STATUS Status; 98 ACPI_INIT_WALK_INFO Info; 99 100 101 ACPI_FUNCTION_TRACE (NsInitializeObjects); 102 103 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")); 108 109 /* Set all init info to zero */ 110 111 ACPI_MEMSET (&Info, 0, sizeof (ACPI_INIT_WALK_INFO)); 112 113 /* Walk entire namespace from the supplied root */ 114 115 Status = AcpiWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT, 116 ACPI_UINT32_MAX, AcpiNsInitOneObject, NULL, 117 &Info, NULL); 118 if (ACPI_FAILURE (Status)) 119 { 120 ACPI_EXCEPTION ((AE_INFO, Status, "During WalkNamespace")); 121 } 122 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)); 130 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)); 135 136 return_ACPI_STATUS (AE_OK); 137} 138 139 140/******************************************************************************* 141 * 142 * FUNCTION: AcpiNsInitializeDevices 143 * 144 * PARAMETERS: None 145 * 146 * RETURN: ACPI_STATUS 147 * 148 * DESCRIPTION: Walk the entire namespace and initialize all ACPI devices. 149 * This means running _INI on all present devices. 150 * 151 * Note: We install PCI config space handler on region access, 152 * not here. 153 * 154 ******************************************************************************/ 155 156ACPI_STATUS 157AcpiNsInitializeDevices ( 158 void) 159{ 160 ACPI_STATUS Status; 161 ACPI_DEVICE_WALK_INFO Info; 162 163 164 ACPI_FUNCTION_TRACE (NsInitializeDevices); 165 166 167 /* Init counters */ 168 169 Info.DeviceCount = 0; 170 Info.Num_STA = 0; 171 Info.Num_INI = 0; 172 173 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT, 174 "Initializing Device/Processor/Thermal objects " 175 "and executing _INI/_STA methods:\n")); 176 177 /* Tree analysis: find all subtrees that contain _INI methods */ 178 179 Status = AcpiNsWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT, 180 ACPI_UINT32_MAX, FALSE, AcpiNsFindIniMethods, NULL, &Info, NULL); 181 if (ACPI_FAILURE (Status)) 182 { 183 goto ErrorExit; 184 } 185 186 /* Allocate the evaluation information block */ 187 188 Info.EvaluateInfo = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_EVALUATE_INFO)); 189 if (!Info.EvaluateInfo) 190 { 191 Status = AE_NO_MEMORY; 192 goto ErrorExit; 193 } 194 195 /* 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. 199 */ 200 Info.EvaluateInfo->PrefixNode = AcpiGbl_RootNode; 201 Info.EvaluateInfo->RelativePathname = METHOD_NAME__INI; 202 Info.EvaluateInfo->Parameters = NULL; 203 Info.EvaluateInfo->Flags = ACPI_IGNORE_RETURN_VALUE; 204 205 Status = AcpiNsEvaluate (Info.EvaluateInfo); 206 if (ACPI_SUCCESS (Status)) 207 { 208 Info.Num_INI++; 209 } 210 211 /* Walk namespace to execute all _INIs on present devices */ 212 213 Status = AcpiNsWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT, 214 ACPI_UINT32_MAX, FALSE, AcpiNsInitOneDevice, NULL, &Info, NULL); 215 216 /* 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. 220 */ 221 if (AcpiGbl_OsiData >= ACPI_OSI_WIN_2000) 222 { 223 AcpiGbl_TruncateIoAddresses = TRUE; 224 } 225 226 ACPI_FREE (Info.EvaluateInfo); 227 if (ACPI_FAILURE (Status)) 228 { 229 goto ErrorExit; 230 } 231 232 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_INIT, 233 " Executed %u _INI methods requiring %u _STA executions " 234 "(examined %u objects)\n", 235 Info.Num_INI, Info.Num_STA, Info.DeviceCount)); 236 237 return_ACPI_STATUS (Status); 238 239 240ErrorExit: 241 ACPI_EXCEPTION ((AE_INFO, Status, "During device initialization")); 242 return_ACPI_STATUS (Status); 243} 244 245 246/******************************************************************************* 247 * 248 * FUNCTION: AcpiNsInitOneObject 249 * 250 * PARAMETERS: ObjHandle - Node 251 * Level - Current nesting level 252 * Context - Points to a init info struct 253 * ReturnValue - Not used 254 * 255 * RETURN: Status 256 * 257 * DESCRIPTION: Callback from AcpiWalkNamespace. Invoked for every object 258 * within the namespace. 259 * 260 * Currently, the only objects that require initialization are: 261 * 1) Methods 262 * 2) Op Regions 263 * 264 ******************************************************************************/ 265 266static ACPI_STATUS 267AcpiNsInitOneObject ( 268 ACPI_HANDLE ObjHandle, 269 UINT32 Level, 270 void *Context, 271 void **ReturnValue) 272{ 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; 278 279 280 ACPI_FUNCTION_NAME (NsInitOneObject); 281 282 283 Info->ObjectCount++; 284 285 /* And even then, we are only interested in a few object types */ 286 287 Type = AcpiNsGetType (ObjHandle); 288 ObjDesc = AcpiNsGetAttachedObject (Node); 289 if (!ObjDesc) 290 { 291 return (AE_OK); 292 } 293 294 /* Increment counters for object types we are looking for */ 295 296 switch (Type) 297 { 298 case ACPI_TYPE_REGION: 299 Info->OpRegionCount++; 300 break; 301 302 case ACPI_TYPE_BUFFER_FIELD: 303 Info->FieldCount++; 304 break; 305 306 case ACPI_TYPE_LOCAL_BANK_FIELD: 307 Info->FieldCount++; 308 break; 309 310 case ACPI_TYPE_BUFFER: 311 Info->BufferCount++; 312 break; 313 314 case ACPI_TYPE_PACKAGE: 315 Info->PackageCount++; 316 break; 317 318 default: 319 320 /* No init required, just exit now */ 321 return (AE_OK); 322 } 323 324 /* If the object is already initialized, nothing else to do */ 325 326 if (ObjDesc->Common.Flags & AOPOBJ_DATA_VALID) 327 { 328 return (AE_OK); 329 } 330 331 /* Must lock the interpreter before executing AML code */ 332 333 AcpiExEnterInterpreter (); 334 335 /* 336 * Each of these types can contain executable AML code within the 337 * declaration. 338 */ 339 switch (Type) 340 { 341 case ACPI_TYPE_REGION: 342 343 Info->OpRegionInit++; 344 Status = AcpiDsGetRegionArguments (ObjDesc); 345 break; 346 347 case ACPI_TYPE_BUFFER_FIELD: 348 349 Info->FieldInit++; 350 Status = AcpiDsGetBufferFieldArguments (ObjDesc); 351 break; 352 353 case ACPI_TYPE_LOCAL_BANK_FIELD: 354 355 Info->FieldInit++; 356 Status = AcpiDsGetBankFieldArguments (ObjDesc); 357 break; 358 359 case ACPI_TYPE_BUFFER: 360 361 Info->BufferInit++; 362 Status = AcpiDsGetBufferArguments (ObjDesc); 363 break; 364 365 case ACPI_TYPE_PACKAGE: 366 367 Info->PackageInit++; 368 Status = AcpiDsGetPackageArguments (ObjDesc); 369 break; 370 371 default: 372 /* No other types can get here */ 373 break; 374 } 375 376 if (ACPI_FAILURE (Status)) 377 { 378 ACPI_EXCEPTION ((AE_INFO, Status, 379 "Could not execute arguments for [%4.4s] (%s)", 380 AcpiUtGetNodeName (Node), AcpiUtGetTypeName (Type))); 381 } 382 383 /* 384 * We ignore errors from above, and always return OK, since we don't want 385 * to abort the walk on any single error. 386 */ 387 AcpiExExitInterpreter (); 388 return (AE_OK); 389} 390 391 392/******************************************************************************* 393 * 394 * FUNCTION: AcpiNsFindIniMethods 395 * 396 * PARAMETERS: ACPI_WALK_CALLBACK 397 * 398 * RETURN: ACPI_STATUS 399 * 400 * DESCRIPTION: Called during namespace walk. Finds objects named _INI under 401 * device/processor/thermal objects, and marks the entire subtree 402 * with a SUBTREE_HAS_INI flag. This flag is used during the 403 * subsequent device initialization walk to avoid entire subtrees 404 * that do not contain an _INI. 405 * 406 ******************************************************************************/ 407 408static ACPI_STATUS 409AcpiNsFindIniMethods ( 410 ACPI_HANDLE ObjHandle, 411 UINT32 NestingLevel, 412 void *Context, 413 void **ReturnValue) 414{ 415 ACPI_DEVICE_WALK_INFO *Info = ACPI_CAST_PTR (ACPI_DEVICE_WALK_INFO, Context); 416 ACPI_NAMESPACE_NODE *Node; 417 ACPI_NAMESPACE_NODE *ParentNode; 418 419 420 /* Keep count of device/processor/thermal objects */ 421 422 Node = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, ObjHandle); 423 if ((Node->Type == ACPI_TYPE_DEVICE) || 424 (Node->Type == ACPI_TYPE_PROCESSOR) || 425 (Node->Type == ACPI_TYPE_THERMAL)) 426 { 427 Info->DeviceCount++; 428 return (AE_OK); 429 } 430 431 /* We are only looking for methods named _INI */ 432 433 if (!ACPI_COMPARE_NAME (Node->Name.Ascii, METHOD_NAME__INI)) 434 { 435 return (AE_OK); 436 } 437 438 /* 439 * The only _INI methods that we care about are those that are 440 * present under Device, Processor, and Thermal objects. 441 */ 442 ParentNode = Node->Parent; 443 switch (ParentNode->Type) 444 { 445 case ACPI_TYPE_DEVICE: 446 case ACPI_TYPE_PROCESSOR: 447 case ACPI_TYPE_THERMAL: 448 449 /* Mark parent and bubble up the INI present flag to the root */ 450 451 while (ParentNode) 452 { 453 ParentNode->Flags |= ANOBJ_SUBTREE_HAS_INI; 454 ParentNode = ParentNode->Parent; 455 } 456 break; 457 458 default: 459 break; 460 } 461 462 return (AE_OK); 463} 464 465 466/******************************************************************************* 467 * 468 * FUNCTION: AcpiNsInitOneDevice 469 * 470 * PARAMETERS: ACPI_WALK_CALLBACK 471 * 472 * RETURN: ACPI_STATUS 473 * 474 * DESCRIPTION: This is called once per device soon after ACPI is enabled 475 * to initialize each device. It determines if the device is 476 * present, and if so, calls _INI. 477 * 478 ******************************************************************************/ 479 480static ACPI_STATUS 481AcpiNsInitOneDevice ( 482 ACPI_HANDLE ObjHandle, 483 UINT32 NestingLevel, 484 void *Context, 485 void **ReturnValue) 486{ 487 ACPI_DEVICE_WALK_INFO *WalkInfo = ACPI_CAST_PTR (ACPI_DEVICE_WALK_INFO, Context); 488 ACPI_EVALUATE_INFO *Info = WalkInfo->EvaluateInfo; 489 UINT32 Flags; 490 ACPI_STATUS Status; 491 ACPI_NAMESPACE_NODE *DeviceNode; 492 493 494 ACPI_FUNCTION_TRACE (NsInitOneDevice); 495 496 497 /* We are interested in Devices, Processors and ThermalZones only */ 498 499 DeviceNode = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, ObjHandle); 500 if ((DeviceNode->Type != ACPI_TYPE_DEVICE) && 501 (DeviceNode->Type != ACPI_TYPE_PROCESSOR) && 502 (DeviceNode->Type != ACPI_TYPE_THERMAL)) 503 { 504 return_ACPI_STATUS (AE_OK); 505 } 506 507 /* 508 * Because of an earlier namespace analysis, all subtrees that contain an 509 * _INI method are tagged. 510 * 511 * If this device subtree does not contain any _INI methods, we 512 * can exit now and stop traversing this entire subtree. 513 */ 514 if (!(DeviceNode->Flags & ANOBJ_SUBTREE_HAS_INI)) 515 { 516 return_ACPI_STATUS (AE_CTRL_DEPTH); 517 } 518 519 /* 520 * Run _STA to determine if this device is present and functioning. We 521 * must know this information for two important reasons (from ACPI spec): 522 * 523 * 1) We can only run _INI if the device is present. 524 * 2) We must abort the device tree walk on this subtree if the device is 525 * not present and is not functional (we will not examine the children) 526 * 527 * The _STA method is not required to be present under the device, we 528 * assume the device is present if _STA does not exist. 529 */ 530 ACPI_DEBUG_EXEC (AcpiUtDisplayInitPathname ( 531 ACPI_TYPE_METHOD, DeviceNode, METHOD_NAME__STA)); 532 533 Status = AcpiUtExecute_STA (DeviceNode, &Flags); 534 if (ACPI_FAILURE (Status)) 535 { 536 /* Ignore error and move on to next device */ 537 538 return_ACPI_STATUS (AE_OK); 539 } 540 541 /* 542 * Flags == -1 means that _STA was not found. In this case, we assume that 543 * the device is both present and functional. 544 * 545 * From the ACPI spec, description of _STA: 546 * 547 * "If a device object (including the processor object) does not have an 548 * _STA object, then OSPM assumes that all of the above bits are set (in 549 * other words, the device is present, ..., and functioning)" 550 */ 551 if (Flags != ACPI_UINT32_MAX) 552 { 553 WalkInfo->Num_STA++; 554 } 555 556 /* 557 * Examine the PRESENT and FUNCTIONING status bits 558 * 559 * Note: ACPI spec does not seem to specify behavior for the present but 560 * not functioning case, so we assume functioning if present. 561 */ 562 if (!(Flags & ACPI_STA_DEVICE_PRESENT)) 563 { 564 /* Device is not present, we must examine the Functioning bit */ 565 566 if (Flags & ACPI_STA_DEVICE_FUNCTIONING) 567 { 568 /* 569 * Device is not present but is "functioning". In this case, 570 * we will not run _INI, but we continue to examine the children 571 * of this device. 572 * 573 * From the ACPI spec, description of _STA: (Note - no mention 574 * of whether to run _INI or not on the device in question) 575 * 576 * "_STA may return bit 0 clear (not present) with bit 3 set 577 * (device is functional). This case is used to indicate a valid 578 * device for which no device driver should be loaded (for example, 579 * a bridge device.) Children of this device may be present and 580 * valid. OSPM should continue enumeration below a device whose 581 * _STA returns this bit combination" 582 */ 583 return_ACPI_STATUS (AE_OK); 584 } 585 else 586 { 587 /* 588 * Device is not present and is not functioning. We must abort the 589 * walk of this subtree immediately -- don't look at the children 590 * of such a device. 591 * 592 * From the ACPI spec, description of _INI: 593 * 594 * "If the _STA method indicates that the device is not present, 595 * OSPM will not run the _INI and will not examine the children 596 * of the device for _INI methods" 597 */ 598 return_ACPI_STATUS (AE_CTRL_DEPTH); 599 } 600 } 601 602 /* 603 * The device is present or is assumed present if no _STA exists. 604 * Run the _INI if it exists (not required to exist) 605 * 606 * Note: We know there is an _INI within this subtree, but it may not be 607 * under this particular device, it may be lower in the branch. 608 */ 609 ACPI_DEBUG_EXEC (AcpiUtDisplayInitPathname ( 610 ACPI_TYPE_METHOD, DeviceNode, METHOD_NAME__INI)); 611 612 ACPI_MEMSET (Info, 0, sizeof (ACPI_EVALUATE_INFO)); 613 Info->PrefixNode = DeviceNode; 614 Info->RelativePathname = METHOD_NAME__INI; 615 Info->Parameters = NULL; 616 Info->Flags = ACPI_IGNORE_RETURN_VALUE; 617 618 Status = AcpiNsEvaluate (Info); 619 if (ACPI_SUCCESS (Status)) 620 { 621 WalkInfo->Num_INI++; 622 } 623 624#ifdef ACPI_DEBUG_OUTPUT 625 else if (Status != AE_NOT_FOUND) 626 { 627 /* Ignore error and move on to next device */ 628 629 char *ScopeName = AcpiNsGetExternalPathname (Info->Node); 630 631 ACPI_EXCEPTION ((AE_INFO, Status, "during %s._INI execution", 632 ScopeName)); 633 ACPI_FREE (ScopeName); 634 } 635#endif 636 637 /* Ignore errors from above */ 638 639 Status = AE_OK; 640 641 /* 642 * The _INI method has been run if present; call the Global Initialization 643 * Handler for this device. 644 */ 645 if (AcpiGbl_InitHandler) 646 { 647 Status = AcpiGbl_InitHandler (DeviceNode, ACPI_INIT_DEVICE_INI); 648 } 649 650 return_ACPI_STATUS (Status); 651} 652