1 /****************************************************************************** 2 * 3 * Module Name: evregion - Operation Region support 4 * 5 *****************************************************************************/ 6 7 /* 8 * Copyright (C) 2000 - 2016, Intel Corp. 9 * All rights reserved. 10 * 11 * Redistribution and use in source and binary forms, with or without 12 * modification, are permitted provided that the following conditions 13 * are met: 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. 25 * 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. 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 #include "acpi.h" 45 #include "accommon.h" 46 #include "acevents.h" 47 #include "acnamesp.h" 48 #include "acinterp.h" 49 50 #define _COMPONENT ACPI_EVENTS 51 ACPI_MODULE_NAME ("evregion") 52 53 54 extern UINT8 AcpiGbl_DefaultAddressSpaces[]; 55 56 /* Local prototypes */ 57 58 static void 59 AcpiEvOrphanEcRegMethod ( 60 ACPI_NAMESPACE_NODE *EcDeviceNode); 61 62 static ACPI_STATUS 63 AcpiEvRegRun ( 64 ACPI_HANDLE ObjHandle, 65 UINT32 Level, 66 void *Context, 67 void **ReturnValue); 68 69 70 /******************************************************************************* 71 * 72 * FUNCTION: AcpiEvInitializeOpRegions 73 * 74 * PARAMETERS: None 75 * 76 * RETURN: Status 77 * 78 * DESCRIPTION: Execute _REG methods for all Operation Regions that have 79 * an installed default region handler. 80 * 81 ******************************************************************************/ 82 83 ACPI_STATUS 84 AcpiEvInitializeOpRegions ( 85 void) 86 { 87 ACPI_STATUS Status; 88 UINT32 i; 89 90 91 ACPI_FUNCTION_TRACE (EvInitializeOpRegions); 92 93 94 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE); 95 if (ACPI_FAILURE (Status)) 96 { 97 return_ACPI_STATUS (Status); 98 } 99 100 /* Run the _REG methods for OpRegions in each default address space */ 101 102 for (i = 0; i < ACPI_NUM_DEFAULT_SPACES; i++) 103 { 104 /* 105 * Make sure the installed handler is the DEFAULT handler. If not the 106 * default, the _REG methods will have already been run (when the 107 * handler was installed) 108 */ 109 if (AcpiEvHasDefaultHandler (AcpiGbl_RootNode, 110 AcpiGbl_DefaultAddressSpaces[i])) 111 { 112 AcpiEvExecuteRegMethods (AcpiGbl_RootNode, 113 AcpiGbl_DefaultAddressSpaces[i], ACPI_REG_CONNECT); 114 } 115 } 116 117 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE); 118 return_ACPI_STATUS (Status); 119 } 120 121 122 /******************************************************************************* 123 * 124 * FUNCTION: AcpiEvAddressSpaceDispatch 125 * 126 * PARAMETERS: RegionObj - Internal region object 127 * FieldObj - Corresponding field. Can be NULL. 128 * Function - Read or Write operation 129 * RegionOffset - Where in the region to read or write 130 * BitWidth - Field width in bits (8, 16, 32, or 64) 131 * Value - Pointer to in or out value, must be 132 * a full 64-bit integer 133 * 134 * RETURN: Status 135 * 136 * DESCRIPTION: Dispatch an address space or operation region access to 137 * a previously installed handler. 138 * 139 * NOTE: During early initialization, we always install the default region 140 * handlers for Memory, I/O and PCI_Config. This ensures that these operation 141 * region address spaces are always available as per the ACPI specification. 142 * This is especially needed in order to support the execution of 143 * module-level AML code during loading of the ACPI tables. 144 * 145 ******************************************************************************/ 146 147 ACPI_STATUS 148 AcpiEvAddressSpaceDispatch ( 149 ACPI_OPERAND_OBJECT *RegionObj, 150 ACPI_OPERAND_OBJECT *FieldObj, 151 UINT32 Function, 152 UINT32 RegionOffset, 153 UINT32 BitWidth, 154 UINT64 *Value) 155 { 156 ACPI_STATUS Status; 157 ACPI_ADR_SPACE_HANDLER Handler; 158 ACPI_ADR_SPACE_SETUP RegionSetup; 159 ACPI_OPERAND_OBJECT *HandlerDesc; 160 ACPI_OPERAND_OBJECT *RegionObj2; 161 void *RegionContext = NULL; 162 ACPI_CONNECTION_INFO *Context; 163 ACPI_PHYSICAL_ADDRESS Address; 164 165 166 ACPI_FUNCTION_TRACE (EvAddressSpaceDispatch); 167 168 169 RegionObj2 = AcpiNsGetSecondaryObject (RegionObj); 170 if (!RegionObj2) 171 { 172 return_ACPI_STATUS (AE_NOT_EXIST); 173 } 174 175 /* Ensure that there is a handler associated with this region */ 176 177 HandlerDesc = RegionObj->Region.Handler; 178 if (!HandlerDesc) 179 { 180 ACPI_ERROR ((AE_INFO, 181 "No handler for Region [%4.4s] (%p) [%s]", 182 AcpiUtGetNodeName (RegionObj->Region.Node), 183 RegionObj, AcpiUtGetRegionName (RegionObj->Region.SpaceId))); 184 185 return_ACPI_STATUS (AE_NOT_EXIST); 186 } 187 188 Context = HandlerDesc->AddressSpace.Context; 189 190 /* 191 * It may be the case that the region has never been initialized. 192 * Some types of regions require special init code 193 */ 194 if (!(RegionObj->Region.Flags & AOPOBJ_SETUP_COMPLETE)) 195 { 196 /* This region has not been initialized yet, do it */ 197 198 RegionSetup = HandlerDesc->AddressSpace.Setup; 199 if (!RegionSetup) 200 { 201 /* No initialization routine, exit with error */ 202 203 ACPI_ERROR ((AE_INFO, 204 "No init routine for region(%p) [%s]", 205 RegionObj, AcpiUtGetRegionName (RegionObj->Region.SpaceId))); 206 return_ACPI_STATUS (AE_NOT_EXIST); 207 } 208 209 /* 210 * We must exit the interpreter because the region setup will 211 * potentially execute control methods (for example, the _REG method 212 * for this region) 213 */ 214 AcpiExExitInterpreter (); 215 216 Status = RegionSetup (RegionObj, ACPI_REGION_ACTIVATE, 217 Context, &RegionContext); 218 219 /* Re-enter the interpreter */ 220 221 AcpiExEnterInterpreter (); 222 223 /* Check for failure of the Region Setup */ 224 225 if (ACPI_FAILURE (Status)) 226 { 227 ACPI_EXCEPTION ((AE_INFO, Status, 228 "During region initialization: [%s]", 229 AcpiUtGetRegionName (RegionObj->Region.SpaceId))); 230 return_ACPI_STATUS (Status); 231 } 232 233 /* Region initialization may have been completed by RegionSetup */ 234 235 if (!(RegionObj->Region.Flags & AOPOBJ_SETUP_COMPLETE)) 236 { 237 RegionObj->Region.Flags |= AOPOBJ_SETUP_COMPLETE; 238 239 /* 240 * Save the returned context for use in all accesses to 241 * the handler for this particular region 242 */ 243 if (!(RegionObj2->Extra.RegionContext)) 244 { 245 RegionObj2->Extra.RegionContext = RegionContext; 246 } 247 } 248 } 249 250 /* We have everything we need, we can invoke the address space handler */ 251 252 Handler = HandlerDesc->AddressSpace.Handler; 253 Address = (RegionObj->Region.Address + RegionOffset); 254 255 /* 256 * Special handling for GenericSerialBus and GeneralPurposeIo: 257 * There are three extra parameters that must be passed to the 258 * handler via the context: 259 * 1) Connection buffer, a resource template from Connection() op 260 * 2) Length of the above buffer 261 * 3) Actual access length from the AccessAs() op 262 * 263 * In addition, for GeneralPurposeIo, the Address and BitWidth fields 264 * are defined as follows: 265 * 1) Address is the pin number index of the field (bit offset from 266 * the previous Connection) 267 * 2) BitWidth is the actual bit length of the field (number of pins) 268 */ 269 if ((RegionObj->Region.SpaceId == ACPI_ADR_SPACE_GSBUS) && 270 Context && 271 FieldObj) 272 { 273 /* Get the Connection (ResourceTemplate) buffer */ 274 275 Context->Connection = FieldObj->Field.ResourceBuffer; 276 Context->Length = FieldObj->Field.ResourceLength; 277 Context->AccessLength = FieldObj->Field.AccessLength; 278 } 279 if ((RegionObj->Region.SpaceId == ACPI_ADR_SPACE_GPIO) && 280 Context && 281 FieldObj) 282 { 283 /* Get the Connection (ResourceTemplate) buffer */ 284 285 Context->Connection = FieldObj->Field.ResourceBuffer; 286 Context->Length = FieldObj->Field.ResourceLength; 287 Context->AccessLength = FieldObj->Field.AccessLength; 288 Address = FieldObj->Field.PinNumberIndex; 289 BitWidth = FieldObj->Field.BitLength; 290 } 291 292 ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION, 293 "Handler %p (@%p) Address %8.8X%8.8X [%s]\n", 294 &RegionObj->Region.Handler->AddressSpace, Handler, 295 ACPI_FORMAT_UINT64 (Address), 296 AcpiUtGetRegionName (RegionObj->Region.SpaceId))); 297 298 if (!(HandlerDesc->AddressSpace.HandlerFlags & 299 ACPI_ADDR_HANDLER_DEFAULT_INSTALLED)) 300 { 301 /* 302 * For handlers other than the default (supplied) handlers, we must 303 * exit the interpreter because the handler *might* block -- we don't 304 * know what it will do, so we can't hold the lock on the intepreter. 305 */ 306 AcpiExExitInterpreter(); 307 } 308 309 /* Call the handler */ 310 311 Status = Handler (Function, Address, BitWidth, Value, Context, 312 RegionObj2->Extra.RegionContext); 313 314 if (ACPI_FAILURE (Status)) 315 { 316 ACPI_EXCEPTION ((AE_INFO, Status, "Returned by Handler for [%s]", 317 AcpiUtGetRegionName (RegionObj->Region.SpaceId))); 318 } 319 320 if (!(HandlerDesc->AddressSpace.HandlerFlags & 321 ACPI_ADDR_HANDLER_DEFAULT_INSTALLED)) 322 { 323 /* 324 * We just returned from a non-default handler, we must re-enter the 325 * interpreter 326 */ 327 AcpiExEnterInterpreter (); 328 } 329 330 return_ACPI_STATUS (Status); 331 } 332 333 334 /******************************************************************************* 335 * 336 * FUNCTION: AcpiEvDetachRegion 337 * 338 * PARAMETERS: RegionObj - Region Object 339 * AcpiNsIsLocked - Namespace Region Already Locked? 340 * 341 * RETURN: None 342 * 343 * DESCRIPTION: Break the association between the handler and the region 344 * this is a two way association. 345 * 346 ******************************************************************************/ 347 348 void 349 AcpiEvDetachRegion ( 350 ACPI_OPERAND_OBJECT *RegionObj, 351 BOOLEAN AcpiNsIsLocked) 352 { 353 ACPI_OPERAND_OBJECT *HandlerObj; 354 ACPI_OPERAND_OBJECT *ObjDesc; 355 ACPI_OPERAND_OBJECT *StartDesc; 356 ACPI_OPERAND_OBJECT **LastObjPtr; 357 ACPI_ADR_SPACE_SETUP RegionSetup; 358 void **RegionContext; 359 ACPI_OPERAND_OBJECT *RegionObj2; 360 ACPI_STATUS Status; 361 362 363 ACPI_FUNCTION_TRACE (EvDetachRegion); 364 365 366 RegionObj2 = AcpiNsGetSecondaryObject (RegionObj); 367 if (!RegionObj2) 368 { 369 return_VOID; 370 } 371 RegionContext = &RegionObj2->Extra.RegionContext; 372 373 /* Get the address handler from the region object */ 374 375 HandlerObj = RegionObj->Region.Handler; 376 if (!HandlerObj) 377 { 378 /* This region has no handler, all done */ 379 380 return_VOID; 381 } 382 383 /* Find this region in the handler's list */ 384 385 ObjDesc = HandlerObj->AddressSpace.RegionList; 386 StartDesc = ObjDesc; 387 LastObjPtr = &HandlerObj->AddressSpace.RegionList; 388 389 while (ObjDesc) 390 { 391 /* Is this the correct Region? */ 392 393 if (ObjDesc == RegionObj) 394 { 395 ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION, 396 "Removing Region %p from address handler %p\n", 397 RegionObj, HandlerObj)); 398 399 /* This is it, remove it from the handler's list */ 400 401 *LastObjPtr = ObjDesc->Region.Next; 402 ObjDesc->Region.Next = NULL; /* Must clear field */ 403 404 if (AcpiNsIsLocked) 405 { 406 Status = AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE); 407 if (ACPI_FAILURE (Status)) 408 { 409 return_VOID; 410 } 411 } 412 413 /* Now stop region accesses by executing the _REG method */ 414 415 Status = AcpiEvExecuteRegMethod (RegionObj, ACPI_REG_DISCONNECT); 416 if (ACPI_FAILURE (Status)) 417 { 418 ACPI_EXCEPTION ((AE_INFO, Status, "from region _REG, [%s]", 419 AcpiUtGetRegionName (RegionObj->Region.SpaceId))); 420 } 421 422 if (AcpiNsIsLocked) 423 { 424 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE); 425 if (ACPI_FAILURE (Status)) 426 { 427 return_VOID; 428 } 429 } 430 431 /* 432 * If the region has been activated, call the setup handler with 433 * the deactivate notification 434 */ 435 if (RegionObj->Region.Flags & AOPOBJ_SETUP_COMPLETE) 436 { 437 RegionSetup = HandlerObj->AddressSpace.Setup; 438 Status = RegionSetup (RegionObj, ACPI_REGION_DEACTIVATE, 439 HandlerObj->AddressSpace.Context, RegionContext); 440 441 /* 442 * RegionContext should have been released by the deactivate 443 * operation. We don't need access to it anymore here. 444 */ 445 if (RegionContext) 446 { 447 *RegionContext = NULL; 448 } 449 450 /* Init routine may fail, Just ignore errors */ 451 452 if (ACPI_FAILURE (Status)) 453 { 454 ACPI_EXCEPTION ((AE_INFO, Status, 455 "from region handler - deactivate, [%s]", 456 AcpiUtGetRegionName (RegionObj->Region.SpaceId))); 457 } 458 459 RegionObj->Region.Flags &= ~(AOPOBJ_SETUP_COMPLETE); 460 } 461 462 /* 463 * Remove handler reference in the region 464 * 465 * NOTE: this doesn't mean that the region goes away, the region 466 * is just inaccessible as indicated to the _REG method 467 * 468 * If the region is on the handler's list, this must be the 469 * region's handler 470 */ 471 RegionObj->Region.Handler = NULL; 472 AcpiUtRemoveReference (HandlerObj); 473 474 return_VOID; 475 } 476 477 /* Walk the linked list of handlers */ 478 479 LastObjPtr = &ObjDesc->Region.Next; 480 ObjDesc = ObjDesc->Region.Next; 481 482 /* Prevent infinite loop if list is corrupted */ 483 484 if (ObjDesc == StartDesc) 485 { 486 ACPI_ERROR ((AE_INFO, 487 "Circular handler list in region object %p", 488 RegionObj)); 489 return_VOID; 490 } 491 } 492 493 /* If we get here, the region was not in the handler's region list */ 494 495 ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION, 496 "Cannot remove region %p from address handler %p\n", 497 RegionObj, HandlerObj)); 498 499 return_VOID; 500 } 501 502 503 /******************************************************************************* 504 * 505 * FUNCTION: AcpiEvAttachRegion 506 * 507 * PARAMETERS: HandlerObj - Handler Object 508 * RegionObj - Region Object 509 * AcpiNsIsLocked - Namespace Region Already Locked? 510 * 511 * RETURN: None 512 * 513 * DESCRIPTION: Create the association between the handler and the region 514 * this is a two way association. 515 * 516 ******************************************************************************/ 517 518 ACPI_STATUS 519 AcpiEvAttachRegion ( 520 ACPI_OPERAND_OBJECT *HandlerObj, 521 ACPI_OPERAND_OBJECT *RegionObj, 522 BOOLEAN AcpiNsIsLocked) 523 { 524 525 ACPI_FUNCTION_TRACE (EvAttachRegion); 526 527 528 /* Install the region's handler */ 529 530 if (RegionObj->Region.Handler) 531 { 532 return_ACPI_STATUS (AE_ALREADY_EXISTS); 533 } 534 535 ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION, 536 "Adding Region [%4.4s] %p to address handler %p [%s]\n", 537 AcpiUtGetNodeName (RegionObj->Region.Node), 538 RegionObj, HandlerObj, 539 AcpiUtGetRegionName (RegionObj->Region.SpaceId))); 540 541 /* Link this region to the front of the handler's list */ 542 543 RegionObj->Region.Next = HandlerObj->AddressSpace.RegionList; 544 HandlerObj->AddressSpace.RegionList = RegionObj; 545 RegionObj->Region.Handler = HandlerObj; 546 AcpiUtAddReference (HandlerObj); 547 548 return_ACPI_STATUS (AE_OK); 549 } 550 551 552 /******************************************************************************* 553 * 554 * FUNCTION: AcpiEvAssociateRegMethod 555 * 556 * PARAMETERS: RegionObj - Region object 557 * 558 * RETURN: Status 559 * 560 * DESCRIPTION: Find and associate _REG method to a region 561 * 562 ******************************************************************************/ 563 564 void 565 AcpiEvAssociateRegMethod ( 566 ACPI_OPERAND_OBJECT *RegionObj) 567 { 568 ACPI_NAME *RegNamePtr = (ACPI_NAME *) METHOD_NAME__REG; 569 ACPI_NAMESPACE_NODE *MethodNode; 570 ACPI_NAMESPACE_NODE *Node; 571 ACPI_OPERAND_OBJECT *RegionObj2; 572 ACPI_STATUS Status; 573 574 575 ACPI_FUNCTION_TRACE (EvAssociateRegMethod); 576 577 578 RegionObj2 = AcpiNsGetSecondaryObject (RegionObj); 579 if (!RegionObj2) 580 { 581 return_VOID; 582 } 583 584 Node = RegionObj->Region.Node->Parent; 585 586 /* Find any "_REG" method associated with this region definition */ 587 588 Status = AcpiNsSearchOneScope ( 589 *RegNamePtr, Node, ACPI_TYPE_METHOD, &MethodNode); 590 if (ACPI_SUCCESS (Status)) 591 { 592 /* 593 * The _REG method is optional and there can be only one per region 594 * definition. This will be executed when the handler is attached 595 * or removed 596 */ 597 RegionObj2->Extra.Method_REG = MethodNode; 598 } 599 600 return_VOID; 601 } 602 603 604 /******************************************************************************* 605 * 606 * FUNCTION: AcpiEvExecuteRegMethod 607 * 608 * PARAMETERS: RegionObj - Region object 609 * Function - Passed to _REG: On (1) or Off (0) 610 * 611 * RETURN: Status 612 * 613 * DESCRIPTION: Execute _REG method for a region 614 * 615 ******************************************************************************/ 616 617 ACPI_STATUS 618 AcpiEvExecuteRegMethod ( 619 ACPI_OPERAND_OBJECT *RegionObj, 620 UINT32 Function) 621 { 622 ACPI_EVALUATE_INFO *Info; 623 ACPI_OPERAND_OBJECT *Args[3]; 624 ACPI_OPERAND_OBJECT *RegionObj2; 625 ACPI_STATUS Status; 626 627 628 ACPI_FUNCTION_TRACE (EvExecuteRegMethod); 629 630 631 RegionObj2 = AcpiNsGetSecondaryObject (RegionObj); 632 if (!RegionObj2) 633 { 634 return_ACPI_STATUS (AE_NOT_EXIST); 635 } 636 637 if (RegionObj2->Extra.Method_REG == NULL || 638 RegionObj->Region.Handler == NULL || 639 !AcpiGbl_NamespaceInitialized) 640 { 641 return_ACPI_STATUS (AE_OK); 642 } 643 644 /* _REG(DISCONNECT) should be paired with _REG(CONNECT) */ 645 646 if ((Function == ACPI_REG_CONNECT && 647 RegionObj->Common.Flags & AOPOBJ_REG_CONNECTED) || 648 (Function == ACPI_REG_DISCONNECT && 649 !(RegionObj->Common.Flags & AOPOBJ_REG_CONNECTED))) 650 { 651 return_ACPI_STATUS (AE_OK); 652 } 653 654 /* Allocate and initialize the evaluation information block */ 655 656 Info = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_EVALUATE_INFO)); 657 if (!Info) 658 { 659 return_ACPI_STATUS (AE_NO_MEMORY); 660 } 661 662 Info->PrefixNode = RegionObj2->Extra.Method_REG; 663 Info->RelativePathname = NULL; 664 Info->Parameters = Args; 665 Info->Flags = ACPI_IGNORE_RETURN_VALUE; 666 667 /* 668 * The _REG method has two arguments: 669 * 670 * Arg0 - Integer: 671 * Operation region space ID Same value as RegionObj->Region.SpaceId 672 * 673 * Arg1 - Integer: 674 * connection status 1 for connecting the handler, 0 for disconnecting 675 * the handler (Passed as a parameter) 676 */ 677 Args[0] = AcpiUtCreateIntegerObject ((UINT64) RegionObj->Region.SpaceId); 678 if (!Args[0]) 679 { 680 Status = AE_NO_MEMORY; 681 goto Cleanup1; 682 } 683 684 Args[1] = AcpiUtCreateIntegerObject ((UINT64) Function); 685 if (!Args[1]) 686 { 687 Status = AE_NO_MEMORY; 688 goto Cleanup2; 689 } 690 691 Args[2] = NULL; /* Terminate list */ 692 693 /* Execute the method, no return value */ 694 695 ACPI_DEBUG_EXEC ( 696 AcpiUtDisplayInitPathname (ACPI_TYPE_METHOD, Info->PrefixNode, NULL)); 697 698 Status = AcpiNsEvaluate (Info); 699 AcpiUtRemoveReference (Args[1]); 700 701 if (ACPI_FAILURE (Status)) 702 { 703 goto Cleanup2; 704 } 705 706 if (Function == ACPI_REG_CONNECT) 707 { 708 RegionObj->Common.Flags |= AOPOBJ_REG_CONNECTED; 709 } 710 else 711 { 712 RegionObj->Common.Flags &= ~AOPOBJ_REG_CONNECTED; 713 } 714 715 Cleanup2: 716 AcpiUtRemoveReference (Args[0]); 717 718 Cleanup1: 719 ACPI_FREE (Info); 720 return_ACPI_STATUS (Status); 721 } 722 723 724 /******************************************************************************* 725 * 726 * FUNCTION: AcpiEvExecuteRegMethods 727 * 728 * PARAMETERS: Node - Namespace node for the device 729 * SpaceId - The address space ID 730 * Function - Passed to _REG: On (1) or Off (0) 731 * 732 * RETURN: None 733 * 734 * DESCRIPTION: Run all _REG methods for the input Space ID; 735 * Note: assumes namespace is locked, or system init time. 736 * 737 ******************************************************************************/ 738 739 void 740 AcpiEvExecuteRegMethods ( 741 ACPI_NAMESPACE_NODE *Node, 742 ACPI_ADR_SPACE_TYPE SpaceId, 743 UINT32 Function) 744 { 745 ACPI_REG_WALK_INFO Info; 746 747 748 ACPI_FUNCTION_TRACE (EvExecuteRegMethods); 749 750 Info.SpaceId = SpaceId; 751 Info.Function = Function; 752 Info.RegRunCount = 0; 753 754 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_NAMES, 755 " Running _REG methods for SpaceId %s\n", 756 AcpiUtGetRegionName (Info.SpaceId))); 757 758 /* 759 * Run all _REG methods for all Operation Regions for this space ID. This 760 * is a separate walk in order to handle any interdependencies between 761 * regions and _REG methods. (i.e. handlers must be installed for all 762 * regions of this Space ID before we can run any _REG methods) 763 */ 764 (void) AcpiNsWalkNamespace (ACPI_TYPE_ANY, Node, ACPI_UINT32_MAX, 765 ACPI_NS_WALK_UNLOCK, AcpiEvRegRun, NULL, &Info, NULL); 766 767 /* Special case for EC: handle "orphan" _REG methods with no region */ 768 769 if (SpaceId == ACPI_ADR_SPACE_EC) 770 { 771 AcpiEvOrphanEcRegMethod (Node); 772 } 773 774 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_NAMES, 775 " Executed %u _REG methods for SpaceId %s\n", 776 Info.RegRunCount, AcpiUtGetRegionName (Info.SpaceId))); 777 778 return_VOID; 779 } 780 781 782 /******************************************************************************* 783 * 784 * FUNCTION: AcpiEvRegRun 785 * 786 * PARAMETERS: WalkNamespace callback 787 * 788 * DESCRIPTION: Run _REG method for region objects of the requested spaceID 789 * 790 ******************************************************************************/ 791 792 static ACPI_STATUS 793 AcpiEvRegRun ( 794 ACPI_HANDLE ObjHandle, 795 UINT32 Level, 796 void *Context, 797 void **ReturnValue) 798 { 799 ACPI_OPERAND_OBJECT *ObjDesc; 800 ACPI_NAMESPACE_NODE *Node; 801 ACPI_STATUS Status; 802 ACPI_REG_WALK_INFO *Info; 803 804 805 Info = ACPI_CAST_PTR (ACPI_REG_WALK_INFO, Context); 806 807 /* Convert and validate the device handle */ 808 809 Node = AcpiNsValidateHandle (ObjHandle); 810 if (!Node) 811 { 812 return (AE_BAD_PARAMETER); 813 } 814 815 /* 816 * We only care about regions.and objects that are allowed to have address 817 * space handlers 818 */ 819 if ((Node->Type != ACPI_TYPE_REGION) && 820 (Node != AcpiGbl_RootNode)) 821 { 822 return (AE_OK); 823 } 824 825 /* Check for an existing internal object */ 826 827 ObjDesc = AcpiNsGetAttachedObject (Node); 828 if (!ObjDesc) 829 { 830 /* No object, just exit */ 831 832 return (AE_OK); 833 } 834 835 /* Object is a Region */ 836 837 if (ObjDesc->Region.SpaceId != Info->SpaceId) 838 { 839 /* This region is for a different address space, just ignore it */ 840 841 return (AE_OK); 842 } 843 844 Info->RegRunCount++; 845 Status = AcpiEvExecuteRegMethod (ObjDesc, Info->Function); 846 return (Status); 847 } 848 849 850 /******************************************************************************* 851 * 852 * FUNCTION: AcpiEvOrphanEcRegMethod 853 * 854 * PARAMETERS: EcDeviceNode - Namespace node for an EC device 855 * 856 * RETURN: None 857 * 858 * DESCRIPTION: Execute an "orphan" _REG method that appears under the EC 859 * device. This is a _REG method that has no corresponding region 860 * within the EC device scope. The orphan _REG method appears to 861 * have been enabled by the description of the ECDT in the ACPI 862 * specification: "The availability of the region space can be 863 * detected by providing a _REG method object underneath the 864 * Embedded Controller device." 865 * 866 * To quickly access the EC device, we use the EcDeviceNode used 867 * during EC handler installation. Otherwise, we would need to 868 * perform a time consuming namespace walk, executing _HID 869 * methods to find the EC device. 870 * 871 * MUTEX: Assumes the namespace is locked 872 * 873 ******************************************************************************/ 874 875 static void 876 AcpiEvOrphanEcRegMethod ( 877 ACPI_NAMESPACE_NODE *EcDeviceNode) 878 { 879 ACPI_HANDLE RegMethod; 880 ACPI_NAMESPACE_NODE *NextNode; 881 ACPI_STATUS Status; 882 ACPI_OBJECT_LIST Args; 883 ACPI_OBJECT Objects[2]; 884 885 886 ACPI_FUNCTION_TRACE (EvOrphanEcRegMethod); 887 888 889 if (!EcDeviceNode) 890 { 891 return_VOID; 892 } 893 894 /* Namespace is currently locked, must release */ 895 896 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE); 897 898 /* Get a handle to a _REG method immediately under the EC device */ 899 900 Status = AcpiGetHandle (EcDeviceNode, METHOD_NAME__REG, &RegMethod); 901 if (ACPI_FAILURE (Status)) 902 { 903 goto Exit; /* There is no _REG method present */ 904 } 905 906 /* 907 * Execute the _REG method only if there is no Operation Region in 908 * this scope with the Embedded Controller space ID. Otherwise, it 909 * will already have been executed. Note, this allows for Regions 910 * with other space IDs to be present; but the code below will then 911 * execute the _REG method with the EmbeddedControl SpaceID argument. 912 */ 913 NextNode = AcpiNsGetNextNode (EcDeviceNode, NULL); 914 while (NextNode) 915 { 916 if ((NextNode->Type == ACPI_TYPE_REGION) && 917 (NextNode->Object) && 918 (NextNode->Object->Region.SpaceId == ACPI_ADR_SPACE_EC)) 919 { 920 goto Exit; /* Do not execute the _REG */ 921 } 922 923 NextNode = AcpiNsGetNextNode (EcDeviceNode, NextNode); 924 } 925 926 /* Evaluate the _REG(EmbeddedControl,Connect) method */ 927 928 Args.Count = 2; 929 Args.Pointer = Objects; 930 Objects[0].Type = ACPI_TYPE_INTEGER; 931 Objects[0].Integer.Value = ACPI_ADR_SPACE_EC; 932 Objects[1].Type = ACPI_TYPE_INTEGER; 933 Objects[1].Integer.Value = ACPI_REG_CONNECT; 934 935 Status = AcpiEvaluateObject (RegMethod, NULL, &Args, NULL); 936 937 Exit: 938 /* We ignore all errors from above, don't care */ 939 940 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE); 941 return_VOID; 942 } 943