accel/qaic: Add AIC200 support
[drm/drm-misc.git] / drivers / acpi / acpica / evregion.c
blobcf53b9535f18e00730781769d1ec54874f440ac7
1 // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
2 /******************************************************************************
4 * Module Name: evregion - Operation Region support
6 * Copyright (C) 2000 - 2023, Intel Corp.
8 *****************************************************************************/
10 #include <acpi/acpi.h>
11 #include "accommon.h"
12 #include "acevents.h"
13 #include "acnamesp.h"
14 #include "acinterp.h"
16 #define _COMPONENT ACPI_EVENTS
17 ACPI_MODULE_NAME("evregion")
19 extern u8 acpi_gbl_default_address_spaces[];
21 /* Local prototypes */
23 static void
24 acpi_ev_execute_orphan_reg_method(struct acpi_namespace_node *device_node,
25 acpi_adr_space_type space_id);
27 static acpi_status
28 acpi_ev_reg_run(acpi_handle obj_handle,
29 u32 level, void *context, void **return_value);
31 /*******************************************************************************
33 * FUNCTION: acpi_ev_initialize_op_regions
35 * PARAMETERS: None
37 * RETURN: Status
39 * DESCRIPTION: Execute _REG methods for all Operation Regions that have
40 * an installed default region handler.
42 ******************************************************************************/
44 acpi_status acpi_ev_initialize_op_regions(void)
46 acpi_status status;
47 u32 i;
49 ACPI_FUNCTION_TRACE(ev_initialize_op_regions);
51 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
52 if (ACPI_FAILURE(status)) {
53 return_ACPI_STATUS(status);
56 /* Run the _REG methods for op_regions in each default address space */
58 for (i = 0; i < ACPI_NUM_DEFAULT_SPACES; i++) {
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)
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_UINT32_MAX,
69 acpi_gbl_default_address_spaces
70 [i], ACPI_REG_CONNECT);
74 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
75 return_ACPI_STATUS(status);
78 /*******************************************************************************
80 * FUNCTION: acpi_ev_address_space_dispatch
82 * PARAMETERS: region_obj - Internal region object
83 * field_obj - Corresponding field. Can be NULL.
84 * function - Read or Write operation
85 * region_offset - Where in the region to read or write
86 * bit_width - Field width in bits (8, 16, 32, or 64)
87 * value - Pointer to in or out value, must be
88 * a full 64-bit integer
90 * RETURN: Status
92 * DESCRIPTION: Dispatch an address space or operation region access to
93 * a previously installed handler.
95 * NOTE: During early initialization, we always install the default region
96 * handlers for Memory, I/O and PCI_Config. This ensures that these operation
97 * region address spaces are always available as per the ACPI specification.
98 * This is especially needed in order to support the execution of
99 * module-level AML code during loading of the ACPI tables.
101 ******************************************************************************/
103 acpi_status
104 acpi_ev_address_space_dispatch(union acpi_operand_object *region_obj,
105 union acpi_operand_object *field_obj,
106 u32 function,
107 u32 region_offset, u32 bit_width, u64 *value)
109 acpi_status status;
110 acpi_adr_space_handler handler;
111 acpi_adr_space_setup region_setup;
112 union acpi_operand_object *handler_desc;
113 union acpi_operand_object *region_obj2;
114 void *region_context = NULL;
115 struct acpi_connection_info *context;
116 acpi_mutex context_mutex;
117 u8 context_locked;
118 acpi_physical_address address;
120 ACPI_FUNCTION_TRACE(ev_address_space_dispatch);
122 region_obj2 = acpi_ns_get_secondary_object(region_obj);
123 if (!region_obj2) {
124 return_ACPI_STATUS(AE_NOT_EXIST);
127 /* Ensure that there is a handler associated with this region */
129 handler_desc = region_obj->region.handler;
130 if (!handler_desc) {
131 ACPI_ERROR((AE_INFO,
132 "No handler for Region [%4.4s] (%p) [%s]",
133 acpi_ut_get_node_name(region_obj->region.node),
134 region_obj,
135 acpi_ut_get_region_name(region_obj->region.
136 space_id)));
138 return_ACPI_STATUS(AE_NOT_EXIST);
141 context = handler_desc->address_space.context;
142 context_mutex = handler_desc->address_space.context_mutex;
143 context_locked = FALSE;
146 * It may be the case that the region has never been initialized.
147 * Some types of regions require special init code
149 if (!(region_obj->region.flags & AOPOBJ_SETUP_COMPLETE)) {
151 /* This region has not been initialized yet, do it */
153 region_setup = handler_desc->address_space.setup;
154 if (!region_setup) {
156 /* No initialization routine, exit with error */
158 ACPI_ERROR((AE_INFO,
159 "No init routine for region(%p) [%s]",
160 region_obj,
161 acpi_ut_get_region_name(region_obj->region.
162 space_id)));
163 return_ACPI_STATUS(AE_NOT_EXIST);
166 if (region_obj->region.space_id == ACPI_ADR_SPACE_PLATFORM_COMM) {
167 struct acpi_pcc_info *ctx =
168 handler_desc->address_space.context;
170 ctx->internal_buffer =
171 field_obj->field.internal_pcc_buffer;
172 ctx->length = (u16)region_obj->region.length;
173 ctx->subspace_id = (u8)region_obj->region.address;
176 if (region_obj->region.space_id ==
177 ACPI_ADR_SPACE_FIXED_HARDWARE) {
178 struct acpi_ffh_info *ctx =
179 handler_desc->address_space.context;
181 ctx->length = region_obj->region.length;
182 ctx->offset = region_obj->region.address;
186 * We must exit the interpreter because the region setup will
187 * potentially execute control methods (for example, the _REG method
188 * for this region)
190 acpi_ex_exit_interpreter();
192 status = region_setup(region_obj, ACPI_REGION_ACTIVATE,
193 context, &region_context);
195 /* Re-enter the interpreter */
197 acpi_ex_enter_interpreter();
199 /* Check for failure of the Region Setup */
201 if (ACPI_FAILURE(status)) {
202 ACPI_EXCEPTION((AE_INFO, status,
203 "During region initialization: [%s]",
204 acpi_ut_get_region_name(region_obj->
205 region.
206 space_id)));
207 return_ACPI_STATUS(status);
210 /* Region initialization may have been completed by region_setup */
212 if (!(region_obj->region.flags & AOPOBJ_SETUP_COMPLETE)) {
213 region_obj->region.flags |= AOPOBJ_SETUP_COMPLETE;
216 * Save the returned context for use in all accesses to
217 * the handler for this particular region
219 if (!(region_obj2->extra.region_context)) {
220 region_obj2->extra.region_context =
221 region_context;
226 /* We have everything we need, we can invoke the address space handler */
228 handler = handler_desc->address_space.handler;
229 address = (region_obj->region.address + region_offset);
231 ACPI_DEBUG_PRINT((ACPI_DB_OPREGION,
232 "Handler %p (@%p) Address %8.8X%8.8X [%s]\n",
233 &region_obj->region.handler->address_space, handler,
234 ACPI_FORMAT_UINT64(address),
235 acpi_ut_get_region_name(region_obj->region.
236 space_id)));
238 if (!(handler_desc->address_space.handler_flags &
239 ACPI_ADDR_HANDLER_DEFAULT_INSTALLED)) {
241 * For handlers other than the default (supplied) handlers, we must
242 * exit the interpreter because the handler *might* block -- we don't
243 * know what it will do, so we can't hold the lock on the interpreter.
245 acpi_ex_exit_interpreter();
249 * Special handling for generic_serial_bus and general_purpose_io:
250 * There are three extra parameters that must be passed to the
251 * handler via the context:
252 * 1) Connection buffer, a resource template from Connection() op
253 * 2) Length of the above buffer
254 * 3) Actual access length from the access_as() op
256 * Since we pass these extra parameters via the context, which is
257 * shared between threads, we must lock the context to avoid these
258 * parameters being changed from another thread before the handler
259 * has completed running.
261 * In addition, for general_purpose_io, the Address and bit_width fields
262 * are defined as follows:
263 * 1) Address is the pin number index of the field (bit offset from
264 * the previous Connection)
265 * 2) bit_width is the actual bit length of the field (number of pins)
267 if ((region_obj->region.space_id == ACPI_ADR_SPACE_GSBUS ||
268 region_obj->region.space_id == ACPI_ADR_SPACE_GPIO) &&
269 context && field_obj) {
271 status =
272 acpi_os_acquire_mutex(context_mutex, ACPI_WAIT_FOREVER);
273 if (ACPI_FAILURE(status)) {
274 goto re_enter_interpreter;
277 context_locked = TRUE;
279 /* Get the Connection (resource_template) buffer */
281 context->connection = field_obj->field.resource_buffer;
282 context->length = field_obj->field.resource_length;
283 context->access_length = field_obj->field.access_length;
285 if (region_obj->region.space_id == ACPI_ADR_SPACE_GPIO) {
286 address = field_obj->field.pin_number_index;
287 bit_width = field_obj->field.bit_length;
291 /* Call the handler */
293 status = handler(function, address, bit_width, value, context,
294 region_obj2->extra.region_context);
296 if (context_locked) {
297 acpi_os_release_mutex(context_mutex);
300 if (ACPI_FAILURE(status)) {
301 ACPI_EXCEPTION((AE_INFO, status, "Returned by Handler for [%s]",
302 acpi_ut_get_region_name(region_obj->region.
303 space_id)));
306 * Special case for an EC timeout. These are seen so frequently
307 * that an additional error message is helpful
309 if ((region_obj->region.space_id == ACPI_ADR_SPACE_EC) &&
310 (status == AE_TIME)) {
311 ACPI_ERROR((AE_INFO,
312 "Timeout from EC hardware or EC device driver"));
316 re_enter_interpreter:
317 if (!(handler_desc->address_space.handler_flags &
318 ACPI_ADDR_HANDLER_DEFAULT_INSTALLED)) {
320 * We just returned from a non-default handler, we must re-enter the
321 * interpreter
323 acpi_ex_enter_interpreter();
326 return_ACPI_STATUS(status);
329 /*******************************************************************************
331 * FUNCTION: acpi_ev_detach_region
333 * PARAMETERS: region_obj - Region Object
334 * acpi_ns_is_locked - Namespace Region Already Locked?
336 * RETURN: None
338 * DESCRIPTION: Break the association between the handler and the region
339 * this is a two way association.
341 ******************************************************************************/
343 void
344 acpi_ev_detach_region(union acpi_operand_object *region_obj,
345 u8 acpi_ns_is_locked)
347 union acpi_operand_object *handler_obj;
348 union acpi_operand_object *obj_desc;
349 union acpi_operand_object *start_desc;
350 union acpi_operand_object **last_obj_ptr;
351 acpi_adr_space_setup region_setup;
352 void **region_context;
353 union acpi_operand_object *region_obj2;
354 acpi_status status;
356 ACPI_FUNCTION_TRACE(ev_detach_region);
358 region_obj2 = acpi_ns_get_secondary_object(region_obj);
359 if (!region_obj2) {
360 return_VOID;
362 region_context = &region_obj2->extra.region_context;
364 /* Get the address handler from the region object */
366 handler_obj = region_obj->region.handler;
367 if (!handler_obj) {
369 /* This region has no handler, all done */
371 return_VOID;
374 /* Find this region in the handler's list */
376 obj_desc = handler_obj->address_space.region_list;
377 start_desc = obj_desc;
378 last_obj_ptr = &handler_obj->address_space.region_list;
380 while (obj_desc) {
382 /* Is this the correct Region? */
384 if (obj_desc == region_obj) {
385 ACPI_DEBUG_PRINT((ACPI_DB_OPREGION,
386 "Removing Region %p from address handler %p\n",
387 region_obj, handler_obj));
389 /* This is it, remove it from the handler's list */
391 *last_obj_ptr = obj_desc->region.next;
392 obj_desc->region.next = NULL; /* Must clear field */
394 if (acpi_ns_is_locked) {
395 status =
396 acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
397 if (ACPI_FAILURE(status)) {
398 return_VOID;
402 /* Now stop region accesses by executing the _REG method */
404 status =
405 acpi_ev_execute_reg_method(region_obj,
406 ACPI_REG_DISCONNECT);
407 if (ACPI_FAILURE(status)) {
408 ACPI_EXCEPTION((AE_INFO, status,
409 "from region _REG, [%s]",
410 acpi_ut_get_region_name
411 (region_obj->region.space_id)));
414 if (acpi_ns_is_locked) {
415 status =
416 acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
417 if (ACPI_FAILURE(status)) {
418 return_VOID;
423 * If the region has been activated, call the setup handler with
424 * the deactivate notification
426 if (region_obj->region.flags & AOPOBJ_SETUP_COMPLETE) {
427 region_setup = handler_obj->address_space.setup;
428 status =
429 region_setup(region_obj,
430 ACPI_REGION_DEACTIVATE,
431 handler_obj->address_space.
432 context, region_context);
435 * region_context should have been released by the deactivate
436 * operation. We don't need access to it anymore here.
438 if (region_context) {
439 *region_context = NULL;
442 /* Init routine may fail, Just ignore errors */
444 if (ACPI_FAILURE(status)) {
445 ACPI_EXCEPTION((AE_INFO, status,
446 "from region handler - deactivate, [%s]",
447 acpi_ut_get_region_name
448 (region_obj->region.
449 space_id)));
452 region_obj->region.flags &=
453 ~(AOPOBJ_SETUP_COMPLETE);
457 * Remove handler reference in the region
459 * NOTE: this doesn't mean that the region goes away, the region
460 * is just inaccessible as indicated to the _REG method
462 * If the region is on the handler's list, this must be the
463 * region's handler
465 region_obj->region.handler = NULL;
466 acpi_ut_remove_reference(handler_obj);
468 return_VOID;
471 /* Walk the linked list of handlers */
473 last_obj_ptr = &obj_desc->region.next;
474 obj_desc = obj_desc->region.next;
476 /* Prevent infinite loop if list is corrupted */
478 if (obj_desc == start_desc) {
479 ACPI_ERROR((AE_INFO,
480 "Circular handler list in region object %p",
481 region_obj));
482 return_VOID;
486 /* If we get here, the region was not in the handler's region list */
488 ACPI_DEBUG_PRINT((ACPI_DB_OPREGION,
489 "Cannot remove region %p from address handler %p\n",
490 region_obj, handler_obj));
492 return_VOID;
495 /*******************************************************************************
497 * FUNCTION: acpi_ev_attach_region
499 * PARAMETERS: handler_obj - Handler Object
500 * region_obj - Region Object
501 * acpi_ns_is_locked - Namespace Region Already Locked?
503 * RETURN: None
505 * DESCRIPTION: Create the association between the handler and the region
506 * this is a two way association.
508 ******************************************************************************/
510 acpi_status
511 acpi_ev_attach_region(union acpi_operand_object *handler_obj,
512 union acpi_operand_object *region_obj,
513 u8 acpi_ns_is_locked)
516 ACPI_FUNCTION_TRACE(ev_attach_region);
518 /* Install the region's handler */
520 if (region_obj->region.handler) {
521 return_ACPI_STATUS(AE_ALREADY_EXISTS);
524 ACPI_DEBUG_PRINT((ACPI_DB_OPREGION,
525 "Adding Region [%4.4s] %p to address handler %p [%s]\n",
526 acpi_ut_get_node_name(region_obj->region.node),
527 region_obj, handler_obj,
528 acpi_ut_get_region_name(region_obj->region.
529 space_id)));
531 /* Link this region to the front of the handler's list */
533 region_obj->region.next = handler_obj->address_space.region_list;
534 handler_obj->address_space.region_list = region_obj;
535 region_obj->region.handler = handler_obj;
536 acpi_ut_add_reference(handler_obj);
538 return_ACPI_STATUS(AE_OK);
541 /*******************************************************************************
543 * FUNCTION: acpi_ev_execute_reg_method
545 * PARAMETERS: region_obj - Region object
546 * function - Passed to _REG: On (1) or Off (0)
548 * RETURN: Status
550 * DESCRIPTION: Execute _REG method for a region
552 ******************************************************************************/
554 acpi_status
555 acpi_ev_execute_reg_method(union acpi_operand_object *region_obj, u32 function)
557 struct acpi_evaluate_info *info;
558 union acpi_operand_object *args[3];
559 union acpi_operand_object *region_obj2;
560 const acpi_name *reg_name_ptr =
561 ACPI_CAST_PTR(acpi_name, METHOD_NAME__REG);
562 struct acpi_namespace_node *method_node;
563 struct acpi_namespace_node *node;
564 acpi_status status;
566 ACPI_FUNCTION_TRACE(ev_execute_reg_method);
568 if (!acpi_gbl_namespace_initialized ||
569 region_obj->region.handler == NULL) {
570 return_ACPI_STATUS(AE_OK);
573 region_obj2 = acpi_ns_get_secondary_object(region_obj);
574 if (!region_obj2) {
575 return_ACPI_STATUS(AE_NOT_EXIST);
579 * Find any "_REG" method associated with this region definition.
580 * The method should always be updated as this function may be
581 * invoked after a namespace change.
583 node = region_obj->region.node->parent;
584 status =
585 acpi_ns_search_one_scope(*reg_name_ptr, node, ACPI_TYPE_METHOD,
586 &method_node);
587 if (ACPI_SUCCESS(status)) {
589 * The _REG method is optional and there can be only one per
590 * region definition. This will be executed when the handler is
591 * attached or removed.
593 region_obj2->extra.method_REG = method_node;
595 if (region_obj2->extra.method_REG == NULL) {
596 return_ACPI_STATUS(AE_OK);
599 /* _REG(DISCONNECT) should be paired with _REG(CONNECT) */
601 if ((function == ACPI_REG_CONNECT &&
602 region_obj->common.flags & AOPOBJ_REG_CONNECTED) ||
603 (function == ACPI_REG_DISCONNECT &&
604 !(region_obj->common.flags & AOPOBJ_REG_CONNECTED))) {
605 return_ACPI_STATUS(AE_OK);
608 /* Allocate and initialize the evaluation information block */
610 info = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_evaluate_info));
611 if (!info) {
612 return_ACPI_STATUS(AE_NO_MEMORY);
615 info->prefix_node = region_obj2->extra.method_REG;
616 info->relative_pathname = NULL;
617 info->parameters = args;
618 info->flags = ACPI_IGNORE_RETURN_VALUE;
621 * The _REG method has two arguments:
623 * arg0 - Integer:
624 * Operation region space ID Same value as region_obj->Region.space_id
626 * arg1 - Integer:
627 * connection status 1 for connecting the handler, 0 for disconnecting
628 * the handler (Passed as a parameter)
630 args[0] =
631 acpi_ut_create_integer_object((u64)region_obj->region.space_id);
632 if (!args[0]) {
633 status = AE_NO_MEMORY;
634 goto cleanup1;
637 args[1] = acpi_ut_create_integer_object((u64)function);
638 if (!args[1]) {
639 status = AE_NO_MEMORY;
640 goto cleanup2;
643 args[2] = NULL; /* Terminate list */
645 /* Execute the method, no return value */
647 ACPI_DEBUG_EXEC(acpi_ut_display_init_pathname
648 (ACPI_TYPE_METHOD, info->prefix_node, NULL));
650 status = acpi_ns_evaluate(info);
651 acpi_ut_remove_reference(args[1]);
653 if (ACPI_FAILURE(status)) {
654 goto cleanup2;
657 if (function == ACPI_REG_CONNECT) {
658 region_obj->common.flags |= AOPOBJ_REG_CONNECTED;
659 } else {
660 region_obj->common.flags &= ~AOPOBJ_REG_CONNECTED;
663 cleanup2:
664 acpi_ut_remove_reference(args[0]);
666 cleanup1:
667 ACPI_FREE(info);
668 return_ACPI_STATUS(status);
671 /*******************************************************************************
673 * FUNCTION: acpi_ev_execute_reg_methods
675 * PARAMETERS: node - Namespace node for the device
676 * max_depth - Depth to which search for _REG
677 * space_id - The address space ID
678 * function - Passed to _REG: On (1) or Off (0)
680 * RETURN: None
682 * DESCRIPTION: Run all _REG methods for the input Space ID;
683 * Note: assumes namespace is locked, or system init time.
685 ******************************************************************************/
687 void
688 acpi_ev_execute_reg_methods(struct acpi_namespace_node *node, u32 max_depth,
689 acpi_adr_space_type space_id, u32 function)
691 struct acpi_reg_walk_info info;
693 ACPI_FUNCTION_TRACE(ev_execute_reg_methods);
696 * These address spaces do not need a call to _REG, since the ACPI
697 * specification defines them as: "must always be accessible". Since
698 * they never change state (never become unavailable), no need to ever
699 * call _REG on them. Also, a data_table is not a "real" address space,
700 * so do not call _REG. September 2018.
702 if ((space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY) ||
703 (space_id == ACPI_ADR_SPACE_SYSTEM_IO) ||
704 (space_id == ACPI_ADR_SPACE_DATA_TABLE)) {
705 return_VOID;
708 info.space_id = space_id;
709 info.function = function;
710 info.reg_run_count = 0;
712 ACPI_DEBUG_PRINT_RAW((ACPI_DB_NAMES,
713 " Running _REG methods for SpaceId %s\n",
714 acpi_ut_get_region_name(info.space_id)));
717 * Run all _REG methods for all Operation Regions for this space ID. This
718 * is a separate walk in order to handle any interdependencies between
719 * regions and _REG methods. (i.e. handlers must be installed for all
720 * regions of this Space ID before we can run any _REG methods)
722 (void)acpi_ns_walk_namespace(ACPI_TYPE_ANY, node, max_depth,
723 ACPI_NS_WALK_UNLOCK, acpi_ev_reg_run, NULL,
724 &info, NULL);
727 * Special case for EC and GPIO: handle "orphan" _REG methods with
728 * no region.
730 if (space_id == ACPI_ADR_SPACE_EC || space_id == ACPI_ADR_SPACE_GPIO) {
731 acpi_ev_execute_orphan_reg_method(node, space_id);
734 ACPI_DEBUG_PRINT_RAW((ACPI_DB_NAMES,
735 " Executed %u _REG methods for SpaceId %s\n",
736 info.reg_run_count,
737 acpi_ut_get_region_name(info.space_id)));
739 return_VOID;
742 /*******************************************************************************
744 * FUNCTION: acpi_ev_reg_run
746 * PARAMETERS: walk_namespace callback
748 * DESCRIPTION: Run _REG method for region objects of the requested spaceID
750 ******************************************************************************/
752 static acpi_status
753 acpi_ev_reg_run(acpi_handle obj_handle,
754 u32 level, void *context, void **return_value)
756 union acpi_operand_object *obj_desc;
757 struct acpi_namespace_node *node;
758 acpi_status status;
759 struct acpi_reg_walk_info *info;
761 info = ACPI_CAST_PTR(struct acpi_reg_walk_info, context);
763 /* Convert and validate the device handle */
765 node = acpi_ns_validate_handle(obj_handle);
766 if (!node) {
767 return (AE_BAD_PARAMETER);
771 * We only care about regions and objects that are allowed to have
772 * address space handlers
774 if ((node->type != ACPI_TYPE_REGION) && (node != acpi_gbl_root_node)) {
775 return (AE_OK);
778 /* Check for an existing internal object */
780 obj_desc = acpi_ns_get_attached_object(node);
781 if (!obj_desc) {
783 /* No object, just exit */
785 return (AE_OK);
788 /* Object is a Region */
790 if (obj_desc->region.space_id != info->space_id) {
792 /* This region is for a different address space, just ignore it */
794 return (AE_OK);
797 info->reg_run_count++;
798 status = acpi_ev_execute_reg_method(obj_desc, info->function);
799 return (status);
802 /*******************************************************************************
804 * FUNCTION: acpi_ev_execute_orphan_reg_method
806 * PARAMETERS: device_node - Namespace node for an ACPI device
807 * space_id - The address space ID
809 * RETURN: None
811 * DESCRIPTION: Execute an "orphan" _REG method that appears under an ACPI
812 * device. This is a _REG method that has no corresponding region
813 * within the device's scope. ACPI tables depending on these
814 * "orphan" _REG methods have been seen for both EC and GPIO
815 * Operation Regions. Presumably the Windows ACPI implementation
816 * always calls the _REG method independent of the presence of
817 * an actual Operation Region with the correct address space ID.
819 * MUTEX: Assumes the namespace is locked
821 ******************************************************************************/
823 static void
824 acpi_ev_execute_orphan_reg_method(struct acpi_namespace_node *device_node,
825 acpi_adr_space_type space_id)
827 acpi_handle reg_method;
828 struct acpi_namespace_node *next_node;
829 acpi_status status;
830 struct acpi_object_list args;
831 union acpi_object objects[2];
833 ACPI_FUNCTION_TRACE(ev_execute_orphan_reg_method);
835 if (!device_node) {
836 return_VOID;
839 /* Namespace is currently locked, must release */
841 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
843 /* Get a handle to a _REG method immediately under the EC device */
845 status = acpi_get_handle(device_node, METHOD_NAME__REG, &reg_method);
846 if (ACPI_FAILURE(status)) {
847 goto exit; /* There is no _REG method present */
851 * Execute the _REG method only if there is no Operation Region in
852 * this scope with the Embedded Controller space ID. Otherwise, it
853 * will already have been executed. Note, this allows for Regions
854 * with other space IDs to be present; but the code below will then
855 * execute the _REG method with the embedded_control space_ID argument.
857 next_node = acpi_ns_get_next_node(device_node, NULL);
858 while (next_node) {
859 if ((next_node->type == ACPI_TYPE_REGION) &&
860 (next_node->object) &&
861 (next_node->object->region.space_id == space_id)) {
862 goto exit; /* Do not execute the _REG */
865 next_node = acpi_ns_get_next_node(device_node, next_node);
868 /* Evaluate the _REG(space_id,Connect) method */
870 args.count = 2;
871 args.pointer = objects;
872 objects[0].type = ACPI_TYPE_INTEGER;
873 objects[0].integer.value = space_id;
874 objects[1].type = ACPI_TYPE_INTEGER;
875 objects[1].integer.value = ACPI_REG_CONNECT;
877 (void)acpi_evaluate_object(reg_method, NULL, &args, NULL);
879 exit:
880 /* We ignore all errors from above, don't care */
882 (void)acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
883 return_VOID;