1 // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 2 /****************************************************************************** 3 * 4 * Module Name: evregion - Operation Region support 5 * 6 * Copyright (C) 2000 - 2020, Intel Corp. 7 * 8 *****************************************************************************/ 9 10 #include <acpi/acpi.h> 11 #include "accommon.h" 12 #include "acevents.h" 13 #include "acnamesp.h" 14 #include "acinterp.h" 15 16 #define _COMPONENT ACPI_EVENTS 17 ACPI_MODULE_NAME("evregion") 18 19 extern u8 acpi_gbl_default_address_spaces[]; 20 21 /* Local prototypes */ 22 23 static void 24 acpi_ev_execute_orphan_reg_method(struct acpi_namespace_node *device_node, 25 acpi_adr_space_type space_id); 26 27 static acpi_status 28 acpi_ev_reg_run(acpi_handle obj_handle, 29 u32 level, void *context, void **return_value); 30 31 /******************************************************************************* 32 * 33 * FUNCTION: acpi_ev_initialize_op_regions 34 * 35 * PARAMETERS: None 36 * 37 * RETURN: Status 38 * 39 * DESCRIPTION: Execute _REG methods for all Operation Regions that have 40 * an installed default region handler. 41 * 42 ******************************************************************************/ 43 44 acpi_status acpi_ev_initialize_op_regions(void) 45 { 46 acpi_status status; 47 u32 i; 48 49 ACPI_FUNCTION_TRACE(ev_initialize_op_regions); 50 51 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); 52 if (ACPI_FAILURE(status)) { 53 return_ACPI_STATUS(status); 54 } 55 56 /* Run the _REG methods for op_regions in each default address space */ 57 58 for (i = 0; i < ACPI_NUM_DEFAULT_SPACES; i++) { 59 /* 60 * Make sure the installed handler is the DEFAULT handler. If not the 61 * default, the _REG methods will have already been run (when the 62 * handler was installed) 63 */ 64 if (acpi_ev_has_default_handler(acpi_gbl_root_node, 65 acpi_gbl_default_address_spaces 66 [i])) { 67 acpi_ev_execute_reg_methods(acpi_gbl_root_node, 68 acpi_gbl_default_address_spaces 69 [i], ACPI_REG_CONNECT); 70 } 71 } 72 73 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); 74 return_ACPI_STATUS(status); 75 } 76 77 /******************************************************************************* 78 * 79 * FUNCTION: acpi_ev_address_space_dispatch 80 * 81 * PARAMETERS: region_obj - Internal region object 82 * field_obj - Corresponding field. Can be NULL. 83 * function - Read or Write operation 84 * region_offset - Where in the region to read or write 85 * bit_width - Field width in bits (8, 16, 32, or 64) 86 * value - Pointer to in or out value, must be 87 * a full 64-bit integer 88 * 89 * RETURN: Status 90 * 91 * DESCRIPTION: Dispatch an address space or operation region access to 92 * a previously installed handler. 93 * 94 * NOTE: During early initialization, we always install the default region 95 * handlers for Memory, I/O and PCI_Config. This ensures that these operation 96 * region address spaces are always available as per the ACPI specification. 97 * This is especially needed in order to support the execution of 98 * module-level AML code during loading of the ACPI tables. 99 * 100 ******************************************************************************/ 101 102 acpi_status 103 acpi_ev_address_space_dispatch(union acpi_operand_object *region_obj, 104 union acpi_operand_object *field_obj, 105 u32 function, 106 u32 region_offset, u32 bit_width, u64 *value) 107 { 108 acpi_status status; 109 acpi_adr_space_handler handler; 110 acpi_adr_space_setup region_setup; 111 union acpi_operand_object *handler_desc; 112 union acpi_operand_object *region_obj2; 113 void *region_context = NULL; 114 struct acpi_connection_info *context; 115 acpi_physical_address address; 116 117 ACPI_FUNCTION_TRACE(ev_address_space_dispatch); 118 119 region_obj2 = acpi_ns_get_secondary_object(region_obj); 120 if (!region_obj2) { 121 return_ACPI_STATUS(AE_NOT_EXIST); 122 } 123 124 /* Ensure that there is a handler associated with this region */ 125 126 handler_desc = region_obj->region.handler; 127 if (!handler_desc) { 128 ACPI_ERROR((AE_INFO, 129 "No handler for Region [%4.4s] (%p) [%s]", 130 acpi_ut_get_node_name(region_obj->region.node), 131 region_obj, 132 acpi_ut_get_region_name(region_obj->region. 133 space_id))); 134 135 return_ACPI_STATUS(AE_NOT_EXIST); 136 } 137 138 context = handler_desc->address_space.context; 139 140 /* 141 * It may be the case that the region has never been initialized. 142 * Some types of regions require special init code 143 */ 144 if (!(region_obj->region.flags & AOPOBJ_SETUP_COMPLETE)) { 145 146 /* This region has not been initialized yet, do it */ 147 148 region_setup = handler_desc->address_space.setup; 149 if (!region_setup) { 150 151 /* No initialization routine, exit with error */ 152 153 ACPI_ERROR((AE_INFO, 154 "No init routine for region(%p) [%s]", 155 region_obj, 156 acpi_ut_get_region_name(region_obj->region. 157 space_id))); 158 return_ACPI_STATUS(AE_NOT_EXIST); 159 } 160 161 /* 162 * We must exit the interpreter because the region setup will 163 * potentially execute control methods (for example, the _REG method 164 * for this region) 165 */ 166 acpi_ex_exit_interpreter(); 167 168 status = region_setup(region_obj, ACPI_REGION_ACTIVATE, 169 context, ®ion_context); 170 171 /* Re-enter the interpreter */ 172 173 acpi_ex_enter_interpreter(); 174 175 /* Check for failure of the Region Setup */ 176 177 if (ACPI_FAILURE(status)) { 178 ACPI_EXCEPTION((AE_INFO, status, 179 "During region initialization: [%s]", 180 acpi_ut_get_region_name(region_obj-> 181 region. 182 space_id))); 183 return_ACPI_STATUS(status); 184 } 185 186 /* Region initialization may have been completed by region_setup */ 187 188 if (!(region_obj->region.flags & AOPOBJ_SETUP_COMPLETE)) { 189 region_obj->region.flags |= AOPOBJ_SETUP_COMPLETE; 190 191 /* 192 * Save the returned context for use in all accesses to 193 * the handler for this particular region 194 */ 195 if (!(region_obj2->extra.region_context)) { 196 region_obj2->extra.region_context = 197 region_context; 198 } 199 } 200 } 201 202 /* We have everything we need, we can invoke the address space handler */ 203 204 handler = handler_desc->address_space.handler; 205 address = (region_obj->region.address + region_offset); 206 207 /* 208 * Special handling for generic_serial_bus and general_purpose_io: 209 * There are three extra parameters that must be passed to the 210 * handler via the context: 211 * 1) Connection buffer, a resource template from Connection() op 212 * 2) Length of the above buffer 213 * 3) Actual access length from the access_as() op 214 * 215 * In addition, for general_purpose_io, the Address and bit_width fields 216 * are defined as follows: 217 * 1) Address is the pin number index of the field (bit offset from 218 * the previous Connection) 219 * 2) bit_width is the actual bit length of the field (number of pins) 220 */ 221 if ((region_obj->region.space_id == ACPI_ADR_SPACE_GSBUS) && 222 context && field_obj) { 223 224 /* Get the Connection (resource_template) buffer */ 225 226 context->connection = field_obj->field.resource_buffer; 227 context->length = field_obj->field.resource_length; 228 context->access_length = field_obj->field.access_length; 229 } 230 if ((region_obj->region.space_id == ACPI_ADR_SPACE_GPIO) && 231 context && field_obj) { 232 233 /* Get the Connection (resource_template) buffer */ 234 235 context->connection = field_obj->field.resource_buffer; 236 context->length = field_obj->field.resource_length; 237 context->access_length = field_obj->field.access_length; 238 address = field_obj->field.pin_number_index; 239 bit_width = field_obj->field.bit_length; 240 } 241 242 ACPI_DEBUG_PRINT((ACPI_DB_OPREGION, 243 "Handler %p (@%p) Address %8.8X%8.8X [%s]\n", 244 ®ion_obj->region.handler->address_space, handler, 245 ACPI_FORMAT_UINT64(address), 246 acpi_ut_get_region_name(region_obj->region. 247 space_id))); 248 249 if (!(handler_desc->address_space.handler_flags & 250 ACPI_ADDR_HANDLER_DEFAULT_INSTALLED)) { 251 /* 252 * For handlers other than the default (supplied) handlers, we must 253 * exit the interpreter because the handler *might* block -- we don't 254 * know what it will do, so we can't hold the lock on the interpreter. 255 */ 256 acpi_ex_exit_interpreter(); 257 } 258 259 /* Call the handler */ 260 261 status = handler(function, address, bit_width, value, context, 262 region_obj2->extra.region_context); 263 264 if (ACPI_FAILURE(status)) { 265 ACPI_EXCEPTION((AE_INFO, status, "Returned by Handler for [%s]", 266 acpi_ut_get_region_name(region_obj->region. 267 space_id))); 268 269 /* 270 * Special case for an EC timeout. These are seen so frequently 271 * that an additional error message is helpful 272 */ 273 if ((region_obj->region.space_id == ACPI_ADR_SPACE_EC) && 274 (status == AE_TIME)) { 275 ACPI_ERROR((AE_INFO, 276 "Timeout from EC hardware or EC device driver")); 277 } 278 } 279 280 if (!(handler_desc->address_space.handler_flags & 281 ACPI_ADDR_HANDLER_DEFAULT_INSTALLED)) { 282 /* 283 * We just returned from a non-default handler, we must re-enter the 284 * interpreter 285 */ 286 acpi_ex_enter_interpreter(); 287 } 288 289 return_ACPI_STATUS(status); 290 } 291 292 /******************************************************************************* 293 * 294 * FUNCTION: acpi_ev_detach_region 295 * 296 * PARAMETERS: region_obj - Region Object 297 * acpi_ns_is_locked - Namespace Region Already Locked? 298 * 299 * RETURN: None 300 * 301 * DESCRIPTION: Break the association between the handler and the region 302 * this is a two way association. 303 * 304 ******************************************************************************/ 305 306 void 307 acpi_ev_detach_region(union acpi_operand_object *region_obj, 308 u8 acpi_ns_is_locked) 309 { 310 union acpi_operand_object *handler_obj; 311 union acpi_operand_object *obj_desc; 312 union acpi_operand_object *start_desc; 313 union acpi_operand_object **last_obj_ptr; 314 acpi_adr_space_setup region_setup; 315 void **region_context; 316 union acpi_operand_object *region_obj2; 317 acpi_status status; 318 319 ACPI_FUNCTION_TRACE(ev_detach_region); 320 321 region_obj2 = acpi_ns_get_secondary_object(region_obj); 322 if (!region_obj2) { 323 return_VOID; 324 } 325 region_context = ®ion_obj2->extra.region_context; 326 327 /* Get the address handler from the region object */ 328 329 handler_obj = region_obj->region.handler; 330 if (!handler_obj) { 331 332 /* This region has no handler, all done */ 333 334 return_VOID; 335 } 336 337 /* Find this region in the handler's list */ 338 339 obj_desc = handler_obj->address_space.region_list; 340 start_desc = obj_desc; 341 last_obj_ptr = &handler_obj->address_space.region_list; 342 343 while (obj_desc) { 344 345 /* Is this the correct Region? */ 346 347 if (obj_desc == region_obj) { 348 ACPI_DEBUG_PRINT((ACPI_DB_OPREGION, 349 "Removing Region %p from address handler %p\n", 350 region_obj, handler_obj)); 351 352 /* This is it, remove it from the handler's list */ 353 354 *last_obj_ptr = obj_desc->region.next; 355 obj_desc->region.next = NULL; /* Must clear field */ 356 357 if (acpi_ns_is_locked) { 358 status = 359 acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); 360 if (ACPI_FAILURE(status)) { 361 return_VOID; 362 } 363 } 364 365 /* Now stop region accesses by executing the _REG method */ 366 367 status = 368 acpi_ev_execute_reg_method(region_obj, 369 ACPI_REG_DISCONNECT); 370 if (ACPI_FAILURE(status)) { 371 ACPI_EXCEPTION((AE_INFO, status, 372 "from region _REG, [%s]", 373 acpi_ut_get_region_name 374 (region_obj->region.space_id))); 375 } 376 377 if (acpi_ns_is_locked) { 378 status = 379 acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); 380 if (ACPI_FAILURE(status)) { 381 return_VOID; 382 } 383 } 384 385 /* 386 * If the region has been activated, call the setup handler with 387 * the deactivate notification 388 */ 389 if (region_obj->region.flags & AOPOBJ_SETUP_COMPLETE) { 390 region_setup = handler_obj->address_space.setup; 391 status = 392 region_setup(region_obj, 393 ACPI_REGION_DEACTIVATE, 394 handler_obj->address_space. 395 context, region_context); 396 397 /* 398 * region_context should have been released by the deactivate 399 * operation. We don't need access to it anymore here. 400 */ 401 if (region_context) { 402 *region_context = NULL; 403 } 404 405 /* Init routine may fail, Just ignore errors */ 406 407 if (ACPI_FAILURE(status)) { 408 ACPI_EXCEPTION((AE_INFO, status, 409 "from region handler - deactivate, [%s]", 410 acpi_ut_get_region_name 411 (region_obj->region. 412 space_id))); 413 } 414 415 region_obj->region.flags &= 416 ~(AOPOBJ_SETUP_COMPLETE); 417 } 418 419 /* 420 * Remove handler reference in the region 421 * 422 * NOTE: this doesn't mean that the region goes away, the region 423 * is just inaccessible as indicated to the _REG method 424 * 425 * If the region is on the handler's list, this must be the 426 * region's handler 427 */ 428 region_obj->region.handler = NULL; 429 acpi_ut_remove_reference(handler_obj); 430 431 return_VOID; 432 } 433 434 /* Walk the linked list of handlers */ 435 436 last_obj_ptr = &obj_desc->region.next; 437 obj_desc = obj_desc->region.next; 438 439 /* Prevent infinite loop if list is corrupted */ 440 441 if (obj_desc == start_desc) { 442 ACPI_ERROR((AE_INFO, 443 "Circular handler list in region object %p", 444 region_obj)); 445 return_VOID; 446 } 447 } 448 449 /* If we get here, the region was not in the handler's region list */ 450 451 ACPI_DEBUG_PRINT((ACPI_DB_OPREGION, 452 "Cannot remove region %p from address handler %p\n", 453 region_obj, handler_obj)); 454 455 return_VOID; 456 } 457 458 /******************************************************************************* 459 * 460 * FUNCTION: acpi_ev_attach_region 461 * 462 * PARAMETERS: handler_obj - Handler Object 463 * region_obj - Region Object 464 * acpi_ns_is_locked - Namespace Region Already Locked? 465 * 466 * RETURN: None 467 * 468 * DESCRIPTION: Create the association between the handler and the region 469 * this is a two way association. 470 * 471 ******************************************************************************/ 472 473 acpi_status 474 acpi_ev_attach_region(union acpi_operand_object *handler_obj, 475 union acpi_operand_object *region_obj, 476 u8 acpi_ns_is_locked) 477 { 478 479 ACPI_FUNCTION_TRACE(ev_attach_region); 480 481 /* Install the region's handler */ 482 483 if (region_obj->region.handler) { 484 return_ACPI_STATUS(AE_ALREADY_EXISTS); 485 } 486 487 ACPI_DEBUG_PRINT((ACPI_DB_OPREGION, 488 "Adding Region [%4.4s] %p to address handler %p [%s]\n", 489 acpi_ut_get_node_name(region_obj->region.node), 490 region_obj, handler_obj, 491 acpi_ut_get_region_name(region_obj->region. 492 space_id))); 493 494 /* Link this region to the front of the handler's list */ 495 496 region_obj->region.next = handler_obj->address_space.region_list; 497 handler_obj->address_space.region_list = region_obj; 498 region_obj->region.handler = handler_obj; 499 acpi_ut_add_reference(handler_obj); 500 501 return_ACPI_STATUS(AE_OK); 502 } 503 504 /******************************************************************************* 505 * 506 * FUNCTION: acpi_ev_execute_reg_method 507 * 508 * PARAMETERS: region_obj - Region object 509 * function - Passed to _REG: On (1) or Off (0) 510 * 511 * RETURN: Status 512 * 513 * DESCRIPTION: Execute _REG method for a region 514 * 515 ******************************************************************************/ 516 517 acpi_status 518 acpi_ev_execute_reg_method(union acpi_operand_object *region_obj, u32 function) 519 { 520 struct acpi_evaluate_info *info; 521 union acpi_operand_object *args[3]; 522 union acpi_operand_object *region_obj2; 523 const acpi_name *reg_name_ptr = 524 ACPI_CAST_PTR(acpi_name, METHOD_NAME__REG); 525 struct acpi_namespace_node *method_node; 526 struct acpi_namespace_node *node; 527 acpi_status status; 528 529 ACPI_FUNCTION_TRACE(ev_execute_reg_method); 530 531 if (!acpi_gbl_namespace_initialized || 532 region_obj->region.handler == NULL) { 533 return_ACPI_STATUS(AE_OK); 534 } 535 536 region_obj2 = acpi_ns_get_secondary_object(region_obj); 537 if (!region_obj2) { 538 return_ACPI_STATUS(AE_NOT_EXIST); 539 } 540 541 /* 542 * Find any "_REG" method associated with this region definition. 543 * The method should always be updated as this function may be 544 * invoked after a namespace change. 545 */ 546 node = region_obj->region.node->parent; 547 status = 548 acpi_ns_search_one_scope(*reg_name_ptr, node, ACPI_TYPE_METHOD, 549 &method_node); 550 if (ACPI_SUCCESS(status)) { 551 /* 552 * The _REG method is optional and there can be only one per 553 * region definition. This will be executed when the handler is 554 * attached or removed. 555 */ 556 region_obj2->extra.method_REG = method_node; 557 } 558 if (region_obj2->extra.method_REG == NULL) { 559 return_ACPI_STATUS(AE_OK); 560 } 561 562 /* _REG(DISCONNECT) should be paired with _REG(CONNECT) */ 563 564 if ((function == ACPI_REG_CONNECT && 565 region_obj->common.flags & AOPOBJ_REG_CONNECTED) || 566 (function == ACPI_REG_DISCONNECT && 567 !(region_obj->common.flags & AOPOBJ_REG_CONNECTED))) { 568 return_ACPI_STATUS(AE_OK); 569 } 570 571 /* Allocate and initialize the evaluation information block */ 572 573 info = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_evaluate_info)); 574 if (!info) { 575 return_ACPI_STATUS(AE_NO_MEMORY); 576 } 577 578 info->prefix_node = region_obj2->extra.method_REG; 579 info->relative_pathname = NULL; 580 info->parameters = args; 581 info->flags = ACPI_IGNORE_RETURN_VALUE; 582 583 /* 584 * The _REG method has two arguments: 585 * 586 * arg0 - Integer: 587 * Operation region space ID Same value as region_obj->Region.space_id 588 * 589 * arg1 - Integer: 590 * connection status 1 for connecting the handler, 0 for disconnecting 591 * the handler (Passed as a parameter) 592 */ 593 args[0] = 594 acpi_ut_create_integer_object((u64)region_obj->region.space_id); 595 if (!args[0]) { 596 status = AE_NO_MEMORY; 597 goto cleanup1; 598 } 599 600 args[1] = acpi_ut_create_integer_object((u64)function); 601 if (!args[1]) { 602 status = AE_NO_MEMORY; 603 goto cleanup2; 604 } 605 606 args[2] = NULL; /* Terminate list */ 607 608 /* Execute the method, no return value */ 609 610 ACPI_DEBUG_EXEC(acpi_ut_display_init_pathname 611 (ACPI_TYPE_METHOD, info->prefix_node, NULL)); 612 613 status = acpi_ns_evaluate(info); 614 acpi_ut_remove_reference(args[1]); 615 616 if (ACPI_FAILURE(status)) { 617 goto cleanup2; 618 } 619 620 if (function == ACPI_REG_CONNECT) { 621 region_obj->common.flags |= AOPOBJ_REG_CONNECTED; 622 } else { 623 region_obj->common.flags &= ~AOPOBJ_REG_CONNECTED; 624 } 625 626 cleanup2: 627 acpi_ut_remove_reference(args[0]); 628 629 cleanup1: 630 ACPI_FREE(info); 631 return_ACPI_STATUS(status); 632 } 633 634 /******************************************************************************* 635 * 636 * FUNCTION: acpi_ev_execute_reg_methods 637 * 638 * PARAMETERS: node - Namespace node for the device 639 * space_id - The address space ID 640 * function - Passed to _REG: On (1) or Off (0) 641 * 642 * RETURN: None 643 * 644 * DESCRIPTION: Run all _REG methods for the input Space ID; 645 * Note: assumes namespace is locked, or system init time. 646 * 647 ******************************************************************************/ 648 649 void 650 acpi_ev_execute_reg_methods(struct acpi_namespace_node *node, 651 acpi_adr_space_type space_id, u32 function) 652 { 653 struct acpi_reg_walk_info info; 654 655 ACPI_FUNCTION_TRACE(ev_execute_reg_methods); 656 657 /* 658 * These address spaces do not need a call to _REG, since the ACPI 659 * specification defines them as: "must always be accessible". Since 660 * they never change state (never become unavailable), no need to ever 661 * call _REG on them. Also, a data_table is not a "real" address space, 662 * so do not call _REG. September 2018. 663 */ 664 if ((space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY) || 665 (space_id == ACPI_ADR_SPACE_SYSTEM_IO) || 666 (space_id == ACPI_ADR_SPACE_DATA_TABLE)) { 667 return_VOID; 668 } 669 670 info.space_id = space_id; 671 info.function = function; 672 info.reg_run_count = 0; 673 674 ACPI_DEBUG_PRINT_RAW((ACPI_DB_NAMES, 675 " Running _REG methods for SpaceId %s\n", 676 acpi_ut_get_region_name(info.space_id))); 677 678 /* 679 * Run all _REG methods for all Operation Regions for this space ID. This 680 * is a separate walk in order to handle any interdependencies between 681 * regions and _REG methods. (i.e. handlers must be installed for all 682 * regions of this Space ID before we can run any _REG methods) 683 */ 684 (void)acpi_ns_walk_namespace(ACPI_TYPE_ANY, node, ACPI_UINT32_MAX, 685 ACPI_NS_WALK_UNLOCK, acpi_ev_reg_run, NULL, 686 &info, NULL); 687 688 /* 689 * Special case for EC and GPIO: handle "orphan" _REG methods with 690 * no region. 691 */ 692 if (space_id == ACPI_ADR_SPACE_EC || space_id == ACPI_ADR_SPACE_GPIO) { 693 acpi_ev_execute_orphan_reg_method(node, space_id); 694 } 695 696 ACPI_DEBUG_PRINT_RAW((ACPI_DB_NAMES, 697 " Executed %u _REG methods for SpaceId %s\n", 698 info.reg_run_count, 699 acpi_ut_get_region_name(info.space_id))); 700 701 return_VOID; 702 } 703 704 /******************************************************************************* 705 * 706 * FUNCTION: acpi_ev_reg_run 707 * 708 * PARAMETERS: walk_namespace callback 709 * 710 * DESCRIPTION: Run _REG method for region objects of the requested spaceID 711 * 712 ******************************************************************************/ 713 714 static acpi_status 715 acpi_ev_reg_run(acpi_handle obj_handle, 716 u32 level, void *context, void **return_value) 717 { 718 union acpi_operand_object *obj_desc; 719 struct acpi_namespace_node *node; 720 acpi_status status; 721 struct acpi_reg_walk_info *info; 722 723 info = ACPI_CAST_PTR(struct acpi_reg_walk_info, context); 724 725 /* Convert and validate the device handle */ 726 727 node = acpi_ns_validate_handle(obj_handle); 728 if (!node) { 729 return (AE_BAD_PARAMETER); 730 } 731 732 /* 733 * We only care about regions and objects that are allowed to have 734 * address space handlers 735 */ 736 if ((node->type != ACPI_TYPE_REGION) && (node != acpi_gbl_root_node)) { 737 return (AE_OK); 738 } 739 740 /* Check for an existing internal object */ 741 742 obj_desc = acpi_ns_get_attached_object(node); 743 if (!obj_desc) { 744 745 /* No object, just exit */ 746 747 return (AE_OK); 748 } 749 750 /* Object is a Region */ 751 752 if (obj_desc->region.space_id != info->space_id) { 753 754 /* This region is for a different address space, just ignore it */ 755 756 return (AE_OK); 757 } 758 759 info->reg_run_count++; 760 status = acpi_ev_execute_reg_method(obj_desc, info->function); 761 return (status); 762 } 763 764 /******************************************************************************* 765 * 766 * FUNCTION: acpi_ev_execute_orphan_reg_method 767 * 768 * PARAMETERS: device_node - Namespace node for an ACPI device 769 * space_id - The address space ID 770 * 771 * RETURN: None 772 * 773 * DESCRIPTION: Execute an "orphan" _REG method that appears under an ACPI 774 * device. This is a _REG method that has no corresponding region 775 * within the device's scope. ACPI tables depending on these 776 * "orphan" _REG methods have been seen for both EC and GPIO 777 * Operation Regions. Presumably the Windows ACPI implementation 778 * always calls the _REG method independent of the presence of 779 * an actual Operation Region with the correct address space ID. 780 * 781 * MUTEX: Assumes the namespace is locked 782 * 783 ******************************************************************************/ 784 785 static void 786 acpi_ev_execute_orphan_reg_method(struct acpi_namespace_node *device_node, 787 acpi_adr_space_type space_id) 788 { 789 acpi_handle reg_method; 790 struct acpi_namespace_node *next_node; 791 acpi_status status; 792 struct acpi_object_list args; 793 union acpi_object objects[2]; 794 795 ACPI_FUNCTION_TRACE(ev_execute_orphan_reg_method); 796 797 if (!device_node) { 798 return_VOID; 799 } 800 801 /* Namespace is currently locked, must release */ 802 803 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); 804 805 /* Get a handle to a _REG method immediately under the EC device */ 806 807 status = acpi_get_handle(device_node, METHOD_NAME__REG, ®_method); 808 if (ACPI_FAILURE(status)) { 809 goto exit; /* There is no _REG method present */ 810 } 811 812 /* 813 * Execute the _REG method only if there is no Operation Region in 814 * this scope with the Embedded Controller space ID. Otherwise, it 815 * will already have been executed. Note, this allows for Regions 816 * with other space IDs to be present; but the code below will then 817 * execute the _REG method with the embedded_control space_ID argument. 818 */ 819 next_node = acpi_ns_get_next_node(device_node, NULL); 820 while (next_node) { 821 if ((next_node->type == ACPI_TYPE_REGION) && 822 (next_node->object) && 823 (next_node->object->region.space_id == space_id)) { 824 goto exit; /* Do not execute the _REG */ 825 } 826 827 next_node = acpi_ns_get_next_node(device_node, next_node); 828 } 829 830 /* Evaluate the _REG(space_id,Connect) method */ 831 832 args.count = 2; 833 args.pointer = objects; 834 objects[0].type = ACPI_TYPE_INTEGER; 835 objects[0].integer.value = space_id; 836 objects[1].type = ACPI_TYPE_INTEGER; 837 objects[1].integer.value = ACPI_REG_CONNECT; 838 839 (void)acpi_evaluate_object(reg_method, NULL, &args, NULL); 840 841 exit: 842 /* We ignore all errors from above, don't care */ 843 844 (void)acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); 845 return_VOID; 846 } 847