195857638SErik Schmauss // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
295b482a8SLen Brown /******************************************************************************
395b482a8SLen Brown *
442f8fb75SBob Moore * Module Name: evregion - Operation Region support
595b482a8SLen Brown *
6*612c2932SBob Moore * Copyright (C) 2000 - 2023, Intel Corp.
795b482a8SLen Brown *
895857638SErik Schmauss *****************************************************************************/
995b482a8SLen Brown
1095b482a8SLen Brown #include <acpi/acpi.h>
11e2f7a777SLen Brown #include "accommon.h"
12e2f7a777SLen Brown #include "acevents.h"
13e2f7a777SLen Brown #include "acnamesp.h"
14e2f7a777SLen Brown #include "acinterp.h"
1595b482a8SLen Brown
1695b482a8SLen Brown #define _COMPONENT ACPI_EVENTS
1795b482a8SLen Brown ACPI_MODULE_NAME("evregion")
1895b482a8SLen Brown
1942f8fb75SBob Moore extern u8 acpi_gbl_default_address_spaces[];
2042f8fb75SBob Moore
2195b482a8SLen Brown /* Local prototypes */
2274d3ec77SLin Ming
238f4f5e78SZhang Rui static void
240306f035SHans de Goede acpi_ev_execute_orphan_reg_method(struct acpi_namespace_node *device_node,
250306f035SHans de Goede acpi_adr_space_type space_id);
26e2066ca1SBob Moore
2795b482a8SLen Brown static acpi_status
2895b482a8SLen Brown acpi_ev_reg_run(acpi_handle obj_handle,
2995b482a8SLen Brown u32 level, void *context, void **return_value);
3095b482a8SLen Brown
3174d3ec77SLin Ming /*******************************************************************************
3274d3ec77SLin Ming *
3395b482a8SLen Brown * FUNCTION: acpi_ev_initialize_op_regions
3495b482a8SLen Brown *
3595b482a8SLen Brown * PARAMETERS: None
3695b482a8SLen Brown *
3795b482a8SLen Brown * RETURN: Status
3895b482a8SLen Brown *
3995b482a8SLen Brown * DESCRIPTION: Execute _REG methods for all Operation Regions that have
4095b482a8SLen Brown * an installed default region handler.
4195b482a8SLen Brown *
4295b482a8SLen Brown ******************************************************************************/
4395b482a8SLen Brown
acpi_ev_initialize_op_regions(void)4495b482a8SLen Brown acpi_status acpi_ev_initialize_op_regions(void)
4595b482a8SLen Brown {
4695b482a8SLen Brown acpi_status status;
4795b482a8SLen Brown u32 i;
4895b482a8SLen Brown
4995b482a8SLen Brown ACPI_FUNCTION_TRACE(ev_initialize_op_regions);
5095b482a8SLen Brown
5195b482a8SLen Brown status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
5295b482a8SLen Brown if (ACPI_FAILURE(status)) {
5395b482a8SLen Brown return_ACPI_STATUS(status);
5495b482a8SLen Brown }
5595b482a8SLen Brown
5695b482a8SLen Brown /* Run the _REG methods for op_regions in each default address space */
5795b482a8SLen Brown
5895b482a8SLen Brown for (i = 0; i < ACPI_NUM_DEFAULT_SPACES; i++) {
5995b482a8SLen Brown /*
6074d3ec77SLin Ming * Make sure the installed handler is the DEFAULT handler. If not the
6174d3ec77SLin Ming * default, the _REG methods will have already been run (when the
6274d3ec77SLin Ming * handler was installed)
6395b482a8SLen Brown */
6474d3ec77SLin Ming if (acpi_ev_has_default_handler(acpi_gbl_root_node,
6574d3ec77SLin Ming acpi_gbl_default_address_spaces
6674d3ec77SLin Ming [i])) {
6774d3ec77SLin Ming acpi_ev_execute_reg_methods(acpi_gbl_root_node,
6895b482a8SLen Brown acpi_gbl_default_address_spaces
69d815346fSLv Zheng [i], ACPI_REG_CONNECT);
7095b482a8SLen Brown }
7174d3ec77SLin Ming }
7295b482a8SLen Brown
7395b482a8SLen Brown (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
7495b482a8SLen Brown return_ACPI_STATUS(status);
7595b482a8SLen Brown }
7695b482a8SLen Brown
7795b482a8SLen Brown /*******************************************************************************
7895b482a8SLen Brown *
7995b482a8SLen Brown * FUNCTION: acpi_ev_address_space_dispatch
8095b482a8SLen Brown *
8195b482a8SLen Brown * PARAMETERS: region_obj - Internal region object
829ce81784SBob Moore * field_obj - Corresponding field. Can be NULL.
83ba494beeSBob Moore * function - Read or Write operation
84f5407af3SBob Moore * region_offset - Where in the region to read or write
8595b482a8SLen Brown * bit_width - Field width in bits (8, 16, 32, or 64)
86ba494beeSBob Moore * value - Pointer to in or out value, must be
875df7e6cbSBob Moore * a full 64-bit integer
8895b482a8SLen Brown *
8995b482a8SLen Brown * RETURN: Status
9095b482a8SLen Brown *
9195b482a8SLen Brown * DESCRIPTION: Dispatch an address space or operation region access to
9295b482a8SLen Brown * a previously installed handler.
9395b482a8SLen Brown *
947b738064SBob Moore * NOTE: During early initialization, we always install the default region
957b738064SBob Moore * handlers for Memory, I/O and PCI_Config. This ensures that these operation
967b738064SBob Moore * region address spaces are always available as per the ACPI specification.
977b738064SBob Moore * This is especially needed in order to support the execution of
987b738064SBob Moore * module-level AML code during loading of the ACPI tables.
997b738064SBob Moore *
10095b482a8SLen Brown ******************************************************************************/
10195b482a8SLen Brown
10295b482a8SLen Brown acpi_status
acpi_ev_address_space_dispatch(union acpi_operand_object * region_obj,union acpi_operand_object * field_obj,u32 function,u32 region_offset,u32 bit_width,u64 * value)10395b482a8SLen Brown acpi_ev_address_space_dispatch(union acpi_operand_object *region_obj,
1049ce81784SBob Moore union acpi_operand_object *field_obj,
10595b482a8SLen Brown u32 function,
1065df7e6cbSBob Moore u32 region_offset, u32 bit_width, u64 *value)
10795b482a8SLen Brown {
10895b482a8SLen Brown acpi_status status;
10995b482a8SLen Brown acpi_adr_space_handler handler;
11095b482a8SLen Brown acpi_adr_space_setup region_setup;
11195b482a8SLen Brown union acpi_operand_object *handler_desc;
11295b482a8SLen Brown union acpi_operand_object *region_obj2;
11395b482a8SLen Brown void *region_context = NULL;
1149ce81784SBob Moore struct acpi_connection_info *context;
115c27f3d01SHans de Goede acpi_mutex context_mutex;
116c27f3d01SHans de Goede u8 context_locked;
11775ec6e55SBob Moore acpi_physical_address address;
11895b482a8SLen Brown
11995b482a8SLen Brown ACPI_FUNCTION_TRACE(ev_address_space_dispatch);
12095b482a8SLen Brown
12195b482a8SLen Brown region_obj2 = acpi_ns_get_secondary_object(region_obj);
12295b482a8SLen Brown if (!region_obj2) {
12395b482a8SLen Brown return_ACPI_STATUS(AE_NOT_EXIST);
12495b482a8SLen Brown }
12595b482a8SLen Brown
12695b482a8SLen Brown /* Ensure that there is a handler associated with this region */
12795b482a8SLen Brown
12895b482a8SLen Brown handler_desc = region_obj->region.handler;
12995b482a8SLen Brown if (!handler_desc) {
13095b482a8SLen Brown ACPI_ERROR((AE_INFO,
13195b482a8SLen Brown "No handler for Region [%4.4s] (%p) [%s]",
13295b482a8SLen Brown acpi_ut_get_node_name(region_obj->region.node),
13395b482a8SLen Brown region_obj,
13495b482a8SLen Brown acpi_ut_get_region_name(region_obj->region.
13595b482a8SLen Brown space_id)));
13695b482a8SLen Brown
13795b482a8SLen Brown return_ACPI_STATUS(AE_NOT_EXIST);
13895b482a8SLen Brown }
13995b482a8SLen Brown
1409ce81784SBob Moore context = handler_desc->address_space.context;
141c27f3d01SHans de Goede context_mutex = handler_desc->address_space.context_mutex;
142c27f3d01SHans de Goede context_locked = FALSE;
1439ce81784SBob Moore
14495b482a8SLen Brown /*
14595b482a8SLen Brown * It may be the case that the region has never been initialized.
14695b482a8SLen Brown * Some types of regions require special init code
14795b482a8SLen Brown */
14895b482a8SLen Brown if (!(region_obj->region.flags & AOPOBJ_SETUP_COMPLETE)) {
14995b482a8SLen Brown
15095b482a8SLen Brown /* This region has not been initialized yet, do it */
15195b482a8SLen Brown
15295b482a8SLen Brown region_setup = handler_desc->address_space.setup;
15395b482a8SLen Brown if (!region_setup) {
15495b482a8SLen Brown
15595b482a8SLen Brown /* No initialization routine, exit with error */
15695b482a8SLen Brown
15795b482a8SLen Brown ACPI_ERROR((AE_INFO,
15895b482a8SLen Brown "No init routine for region(%p) [%s]",
15995b482a8SLen Brown region_obj,
16095b482a8SLen Brown acpi_ut_get_region_name(region_obj->region.
16195b482a8SLen Brown space_id)));
16295b482a8SLen Brown return_ACPI_STATUS(AE_NOT_EXIST);
16395b482a8SLen Brown }
16495b482a8SLen Brown
1650acf24adSSudeep Holla if (region_obj->region.space_id == ACPI_ADR_SPACE_PLATFORM_COMM) {
1660acf24adSSudeep Holla struct acpi_pcc_info *ctx =
1670acf24adSSudeep Holla handler_desc->address_space.context;
1680acf24adSSudeep Holla
1690acf24adSSudeep Holla ctx->internal_buffer =
1700acf24adSSudeep Holla field_obj->field.internal_pcc_buffer;
171b70d6f07SBob Moore ctx->length = (u16)region_obj->region.length;
172b70d6f07SBob Moore ctx->subspace_id = (u8)region_obj->region.address;
1730acf24adSSudeep Holla }
1740acf24adSSudeep Holla
175ee64b827SSudeep Holla if (region_obj->region.space_id ==
176ee64b827SSudeep Holla ACPI_ADR_SPACE_FIXED_HARDWARE) {
177ee64b827SSudeep Holla struct acpi_ffh_info *ctx =
178ee64b827SSudeep Holla handler_desc->address_space.context;
179ee64b827SSudeep Holla
180ee64b827SSudeep Holla ctx->length = region_obj->region.length;
181ee64b827SSudeep Holla ctx->offset = region_obj->region.address;
182ee64b827SSudeep Holla }
183ee64b827SSudeep Holla
18495b482a8SLen Brown /*
18595b482a8SLen Brown * We must exit the interpreter because the region setup will
18695b482a8SLen Brown * potentially execute control methods (for example, the _REG method
18795b482a8SLen Brown * for this region)
18895b482a8SLen Brown */
18995b482a8SLen Brown acpi_ex_exit_interpreter();
19095b482a8SLen Brown
19195b482a8SLen Brown status = region_setup(region_obj, ACPI_REGION_ACTIVATE,
1929ce81784SBob Moore context, ®ion_context);
19395b482a8SLen Brown
19495b482a8SLen Brown /* Re-enter the interpreter */
19595b482a8SLen Brown
19695b482a8SLen Brown acpi_ex_enter_interpreter();
19795b482a8SLen Brown
19895b482a8SLen Brown /* Check for failure of the Region Setup */
19995b482a8SLen Brown
20095b482a8SLen Brown if (ACPI_FAILURE(status)) {
20195b482a8SLen Brown ACPI_EXCEPTION((AE_INFO, status,
20295b482a8SLen Brown "During region initialization: [%s]",
20395b482a8SLen Brown acpi_ut_get_region_name(region_obj->
20495b482a8SLen Brown region.
20595b482a8SLen Brown space_id)));
20695b482a8SLen Brown return_ACPI_STATUS(status);
20795b482a8SLen Brown }
20895b482a8SLen Brown
20995b482a8SLen Brown /* Region initialization may have been completed by region_setup */
21095b482a8SLen Brown
21195b482a8SLen Brown if (!(region_obj->region.flags & AOPOBJ_SETUP_COMPLETE)) {
21295b482a8SLen Brown region_obj->region.flags |= AOPOBJ_SETUP_COMPLETE;
21395b482a8SLen Brown
21495b482a8SLen Brown /*
21595b482a8SLen Brown * Save the returned context for use in all accesses to
216d2e7d079SDavid E. Box * the handler for this particular region
21795b482a8SLen Brown */
218d2e7d079SDavid E. Box if (!(region_obj2->extra.region_context)) {
21995b482a8SLen Brown region_obj2->extra.region_context =
22095b482a8SLen Brown region_context;
22195b482a8SLen Brown }
22295b482a8SLen Brown }
22395b482a8SLen Brown }
22495b482a8SLen Brown
22595b482a8SLen Brown /* We have everything we need, we can invoke the address space handler */
22695b482a8SLen Brown
22795b482a8SLen Brown handler = handler_desc->address_space.handler;
22875ec6e55SBob Moore address = (region_obj->region.address + region_offset);
22995b482a8SLen Brown
23075ec6e55SBob Moore ACPI_DEBUG_PRINT((ACPI_DB_OPREGION,
23175ec6e55SBob Moore "Handler %p (@%p) Address %8.8X%8.8X [%s]\n",
23275ec6e55SBob Moore ®ion_obj->region.handler->address_space, handler,
2331d0a0b2fSLv Zheng ACPI_FORMAT_UINT64(address),
23475ec6e55SBob Moore acpi_ut_get_region_name(region_obj->region.
23575ec6e55SBob Moore space_id)));
2369ce81784SBob Moore
23795b482a8SLen Brown if (!(handler_desc->address_space.handler_flags &
23895b482a8SLen Brown ACPI_ADDR_HANDLER_DEFAULT_INSTALLED)) {
23995b482a8SLen Brown /*
24095b482a8SLen Brown * For handlers other than the default (supplied) handlers, we must
24195b482a8SLen Brown * exit the interpreter because the handler *might* block -- we don't
242c163f90cSErik Schmauss * know what it will do, so we can't hold the lock on the interpreter.
24395b482a8SLen Brown */
24495b482a8SLen Brown acpi_ex_exit_interpreter();
24595b482a8SLen Brown }
24695b482a8SLen Brown
247c27f3d01SHans de Goede /*
248c27f3d01SHans de Goede * Special handling for generic_serial_bus and general_purpose_io:
249c27f3d01SHans de Goede * There are three extra parameters that must be passed to the
250c27f3d01SHans de Goede * handler via the context:
251c27f3d01SHans de Goede * 1) Connection buffer, a resource template from Connection() op
252c27f3d01SHans de Goede * 2) Length of the above buffer
253c27f3d01SHans de Goede * 3) Actual access length from the access_as() op
254c27f3d01SHans de Goede *
255c27f3d01SHans de Goede * Since we pass these extra parameters via the context, which is
256c27f3d01SHans de Goede * shared between threads, we must lock the context to avoid these
257c27f3d01SHans de Goede * parameters being changed from another thread before the handler
258c27f3d01SHans de Goede * has completed running.
259c27f3d01SHans de Goede *
260c27f3d01SHans de Goede * In addition, for general_purpose_io, the Address and bit_width fields
261c27f3d01SHans de Goede * are defined as follows:
262c27f3d01SHans de Goede * 1) Address is the pin number index of the field (bit offset from
263c27f3d01SHans de Goede * the previous Connection)
264c27f3d01SHans de Goede * 2) bit_width is the actual bit length of the field (number of pins)
265c27f3d01SHans de Goede */
2668f6493d1SHans de Goede if ((region_obj->region.space_id == ACPI_ADR_SPACE_GSBUS ||
2678f6493d1SHans de Goede region_obj->region.space_id == ACPI_ADR_SPACE_GPIO) &&
268c27f3d01SHans de Goede context && field_obj) {
269c27f3d01SHans de Goede
270c27f3d01SHans de Goede status =
271c27f3d01SHans de Goede acpi_os_acquire_mutex(context_mutex, ACPI_WAIT_FOREVER);
272c27f3d01SHans de Goede if (ACPI_FAILURE(status)) {
273c27f3d01SHans de Goede goto re_enter_interpreter;
274c27f3d01SHans de Goede }
275c27f3d01SHans de Goede
276c27f3d01SHans de Goede context_locked = TRUE;
277c27f3d01SHans de Goede
278c27f3d01SHans de Goede /* Get the Connection (resource_template) buffer */
279c27f3d01SHans de Goede
280c27f3d01SHans de Goede context->connection = field_obj->field.resource_buffer;
281c27f3d01SHans de Goede context->length = field_obj->field.resource_length;
282c27f3d01SHans de Goede context->access_length = field_obj->field.access_length;
283c27f3d01SHans de Goede
2848f6493d1SHans de Goede if (region_obj->region.space_id == ACPI_ADR_SPACE_GPIO) {
285c27f3d01SHans de Goede address = field_obj->field.pin_number_index;
286c27f3d01SHans de Goede bit_width = field_obj->field.bit_length;
287c27f3d01SHans de Goede }
2888f6493d1SHans de Goede }
289c27f3d01SHans de Goede
29095b482a8SLen Brown /* Call the handler */
29195b482a8SLen Brown
29275ec6e55SBob Moore status = handler(function, address, bit_width, value, context,
29395b482a8SLen Brown region_obj2->extra.region_context);
29495b482a8SLen Brown
295c27f3d01SHans de Goede if (context_locked) {
296c27f3d01SHans de Goede acpi_os_release_mutex(context_mutex);
297c27f3d01SHans de Goede }
298c27f3d01SHans de Goede
29995b482a8SLen Brown if (ACPI_FAILURE(status)) {
30095b482a8SLen Brown ACPI_EXCEPTION((AE_INFO, status, "Returned by Handler for [%s]",
30195b482a8SLen Brown acpi_ut_get_region_name(region_obj->region.
30295b482a8SLen Brown space_id)));
30353ae81e1SBob Moore
30453ae81e1SBob Moore /*
30553ae81e1SBob Moore * Special case for an EC timeout. These are seen so frequently
30653ae81e1SBob Moore * that an additional error message is helpful
30753ae81e1SBob Moore */
30853ae81e1SBob Moore if ((region_obj->region.space_id == ACPI_ADR_SPACE_EC) &&
30953ae81e1SBob Moore (status == AE_TIME)) {
31053ae81e1SBob Moore ACPI_ERROR((AE_INFO,
31153ae81e1SBob Moore "Timeout from EC hardware or EC device driver"));
31253ae81e1SBob Moore }
31395b482a8SLen Brown }
31495b482a8SLen Brown
315c27f3d01SHans de Goede re_enter_interpreter:
31695b482a8SLen Brown if (!(handler_desc->address_space.handler_flags &
31795b482a8SLen Brown ACPI_ADDR_HANDLER_DEFAULT_INSTALLED)) {
31895b482a8SLen Brown /*
31995b482a8SLen Brown * We just returned from a non-default handler, we must re-enter the
32095b482a8SLen Brown * interpreter
32195b482a8SLen Brown */
32295b482a8SLen Brown acpi_ex_enter_interpreter();
32395b482a8SLen Brown }
32495b482a8SLen Brown
32595b482a8SLen Brown return_ACPI_STATUS(status);
32695b482a8SLen Brown }
32795b482a8SLen Brown
32895b482a8SLen Brown /*******************************************************************************
32995b482a8SLen Brown *
33095b482a8SLen Brown * FUNCTION: acpi_ev_detach_region
33195b482a8SLen Brown *
33295b482a8SLen Brown * PARAMETERS: region_obj - Region Object
33395b482a8SLen Brown * acpi_ns_is_locked - Namespace Region Already Locked?
33495b482a8SLen Brown *
33595b482a8SLen Brown * RETURN: None
33695b482a8SLen Brown *
33795b482a8SLen Brown * DESCRIPTION: Break the association between the handler and the region
33895b482a8SLen Brown * this is a two way association.
33995b482a8SLen Brown *
34095b482a8SLen Brown ******************************************************************************/
34195b482a8SLen Brown
34295b482a8SLen Brown void
acpi_ev_detach_region(union acpi_operand_object * region_obj,u8 acpi_ns_is_locked)34395b482a8SLen Brown acpi_ev_detach_region(union acpi_operand_object *region_obj,
34495b482a8SLen Brown u8 acpi_ns_is_locked)
34595b482a8SLen Brown {
34695b482a8SLen Brown union acpi_operand_object *handler_obj;
34795b482a8SLen Brown union acpi_operand_object *obj_desc;
348f953529fSBob Moore union acpi_operand_object *start_desc;
34995b482a8SLen Brown union acpi_operand_object **last_obj_ptr;
35095b482a8SLen Brown acpi_adr_space_setup region_setup;
35195b482a8SLen Brown void **region_context;
35295b482a8SLen Brown union acpi_operand_object *region_obj2;
35395b482a8SLen Brown acpi_status status;
35495b482a8SLen Brown
35595b482a8SLen Brown ACPI_FUNCTION_TRACE(ev_detach_region);
35695b482a8SLen Brown
35795b482a8SLen Brown region_obj2 = acpi_ns_get_secondary_object(region_obj);
35895b482a8SLen Brown if (!region_obj2) {
35995b482a8SLen Brown return_VOID;
36095b482a8SLen Brown }
36195b482a8SLen Brown region_context = ®ion_obj2->extra.region_context;
36295b482a8SLen Brown
36395b482a8SLen Brown /* Get the address handler from the region object */
36495b482a8SLen Brown
36595b482a8SLen Brown handler_obj = region_obj->region.handler;
36695b482a8SLen Brown if (!handler_obj) {
36795b482a8SLen Brown
36895b482a8SLen Brown /* This region has no handler, all done */
36995b482a8SLen Brown
37095b482a8SLen Brown return_VOID;
37195b482a8SLen Brown }
37295b482a8SLen Brown
37395b482a8SLen Brown /* Find this region in the handler's list */
37495b482a8SLen Brown
37595b482a8SLen Brown obj_desc = handler_obj->address_space.region_list;
376f953529fSBob Moore start_desc = obj_desc;
37795b482a8SLen Brown last_obj_ptr = &handler_obj->address_space.region_list;
37895b482a8SLen Brown
37995b482a8SLen Brown while (obj_desc) {
38095b482a8SLen Brown
38195b482a8SLen Brown /* Is this the correct Region? */
38295b482a8SLen Brown
38395b482a8SLen Brown if (obj_desc == region_obj) {
38495b482a8SLen Brown ACPI_DEBUG_PRINT((ACPI_DB_OPREGION,
38595b482a8SLen Brown "Removing Region %p from address handler %p\n",
38695b482a8SLen Brown region_obj, handler_obj));
38795b482a8SLen Brown
38895b482a8SLen Brown /* This is it, remove it from the handler's list */
38995b482a8SLen Brown
39095b482a8SLen Brown *last_obj_ptr = obj_desc->region.next;
39195b482a8SLen Brown obj_desc->region.next = NULL; /* Must clear field */
39295b482a8SLen Brown
39395b482a8SLen Brown if (acpi_ns_is_locked) {
39495b482a8SLen Brown status =
39595b482a8SLen Brown acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
39695b482a8SLen Brown if (ACPI_FAILURE(status)) {
39795b482a8SLen Brown return_VOID;
39895b482a8SLen Brown }
39995b482a8SLen Brown }
40095b482a8SLen Brown
40195b482a8SLen Brown /* Now stop region accesses by executing the _REG method */
40295b482a8SLen Brown
403e2066ca1SBob Moore status =
404e2066ca1SBob Moore acpi_ev_execute_reg_method(region_obj,
405e2066ca1SBob Moore ACPI_REG_DISCONNECT);
40695b482a8SLen Brown if (ACPI_FAILURE(status)) {
40795b482a8SLen Brown ACPI_EXCEPTION((AE_INFO, status,
40895b482a8SLen Brown "from region _REG, [%s]",
40995b482a8SLen Brown acpi_ut_get_region_name
41095b482a8SLen Brown (region_obj->region.space_id)));
41195b482a8SLen Brown }
41295b482a8SLen Brown
41395b482a8SLen Brown if (acpi_ns_is_locked) {
41495b482a8SLen Brown status =
41595b482a8SLen Brown acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
41695b482a8SLen Brown if (ACPI_FAILURE(status)) {
41795b482a8SLen Brown return_VOID;
41895b482a8SLen Brown }
41995b482a8SLen Brown }
42095b482a8SLen Brown
42195b482a8SLen Brown /*
42295b482a8SLen Brown * If the region has been activated, call the setup handler with
42395b482a8SLen Brown * the deactivate notification
42495b482a8SLen Brown */
42595b482a8SLen Brown if (region_obj->region.flags & AOPOBJ_SETUP_COMPLETE) {
42695b482a8SLen Brown region_setup = handler_obj->address_space.setup;
42795b482a8SLen Brown status =
42895b482a8SLen Brown region_setup(region_obj,
42995b482a8SLen Brown ACPI_REGION_DEACTIVATE,
43095b482a8SLen Brown handler_obj->address_space.
43195b482a8SLen Brown context, region_context);
43295b482a8SLen Brown
433d2e7d079SDavid E. Box /*
434d2e7d079SDavid E. Box * region_context should have been released by the deactivate
435d2e7d079SDavid E. Box * operation. We don't need access to it anymore here.
436d2e7d079SDavid E. Box */
437d2e7d079SDavid E. Box if (region_context) {
438d2e7d079SDavid E. Box *region_context = NULL;
439d2e7d079SDavid E. Box }
440d2e7d079SDavid E. Box
44195b482a8SLen Brown /* Init routine may fail, Just ignore errors */
44295b482a8SLen Brown
44395b482a8SLen Brown if (ACPI_FAILURE(status)) {
44495b482a8SLen Brown ACPI_EXCEPTION((AE_INFO, status,
44595b482a8SLen Brown "from region handler - deactivate, [%s]",
44695b482a8SLen Brown acpi_ut_get_region_name
44795b482a8SLen Brown (region_obj->region.
44895b482a8SLen Brown space_id)));
44995b482a8SLen Brown }
45095b482a8SLen Brown
45195b482a8SLen Brown region_obj->region.flags &=
45295b482a8SLen Brown ~(AOPOBJ_SETUP_COMPLETE);
45395b482a8SLen Brown }
45495b482a8SLen Brown
45595b482a8SLen Brown /*
45695b482a8SLen Brown * Remove handler reference in the region
45795b482a8SLen Brown *
45895b482a8SLen Brown * NOTE: this doesn't mean that the region goes away, the region
45995b482a8SLen Brown * is just inaccessible as indicated to the _REG method
46095b482a8SLen Brown *
46195b482a8SLen Brown * If the region is on the handler's list, this must be the
46295b482a8SLen Brown * region's handler
46395b482a8SLen Brown */
46495b482a8SLen Brown region_obj->region.handler = NULL;
46595b482a8SLen Brown acpi_ut_remove_reference(handler_obj);
46695b482a8SLen Brown
46795b482a8SLen Brown return_VOID;
46895b482a8SLen Brown }
46995b482a8SLen Brown
47095b482a8SLen Brown /* Walk the linked list of handlers */
47195b482a8SLen Brown
47295b482a8SLen Brown last_obj_ptr = &obj_desc->region.next;
47395b482a8SLen Brown obj_desc = obj_desc->region.next;
474f953529fSBob Moore
475f953529fSBob Moore /* Prevent infinite loop if list is corrupted */
476f953529fSBob Moore
477f953529fSBob Moore if (obj_desc == start_desc) {
478f953529fSBob Moore ACPI_ERROR((AE_INFO,
479f953529fSBob Moore "Circular handler list in region object %p",
480f953529fSBob Moore region_obj));
481f953529fSBob Moore return_VOID;
482f953529fSBob Moore }
48395b482a8SLen Brown }
48495b482a8SLen Brown
48595b482a8SLen Brown /* If we get here, the region was not in the handler's region list */
48695b482a8SLen Brown
48795b482a8SLen Brown ACPI_DEBUG_PRINT((ACPI_DB_OPREGION,
48895b482a8SLen Brown "Cannot remove region %p from address handler %p\n",
48995b482a8SLen Brown region_obj, handler_obj));
49095b482a8SLen Brown
49195b482a8SLen Brown return_VOID;
49295b482a8SLen Brown }
49395b482a8SLen Brown
49495b482a8SLen Brown /*******************************************************************************
49595b482a8SLen Brown *
49695b482a8SLen Brown * FUNCTION: acpi_ev_attach_region
49795b482a8SLen Brown *
49895b482a8SLen Brown * PARAMETERS: handler_obj - Handler Object
49995b482a8SLen Brown * region_obj - Region Object
50095b482a8SLen Brown * acpi_ns_is_locked - Namespace Region Already Locked?
50195b482a8SLen Brown *
50295b482a8SLen Brown * RETURN: None
50395b482a8SLen Brown *
50495b482a8SLen Brown * DESCRIPTION: Create the association between the handler and the region
50595b482a8SLen Brown * this is a two way association.
50695b482a8SLen Brown *
50795b482a8SLen Brown ******************************************************************************/
50895b482a8SLen Brown
50995b482a8SLen Brown acpi_status
acpi_ev_attach_region(union acpi_operand_object * handler_obj,union acpi_operand_object * region_obj,u8 acpi_ns_is_locked)51095b482a8SLen Brown acpi_ev_attach_region(union acpi_operand_object *handler_obj,
51195b482a8SLen Brown union acpi_operand_object *region_obj,
51295b482a8SLen Brown u8 acpi_ns_is_locked)
51395b482a8SLen Brown {
51495b482a8SLen Brown
51595b482a8SLen Brown ACPI_FUNCTION_TRACE(ev_attach_region);
51695b482a8SLen Brown
5171d65d9a7SLv Zheng /* Install the region's handler */
5181d65d9a7SLv Zheng
5191d65d9a7SLv Zheng if (region_obj->region.handler) {
5201d65d9a7SLv Zheng return_ACPI_STATUS(AE_ALREADY_EXISTS);
5211d65d9a7SLv Zheng }
5221d65d9a7SLv Zheng
52395b482a8SLen Brown ACPI_DEBUG_PRINT((ACPI_DB_OPREGION,
52495b482a8SLen Brown "Adding Region [%4.4s] %p to address handler %p [%s]\n",
52595b482a8SLen Brown acpi_ut_get_node_name(region_obj->region.node),
52695b482a8SLen Brown region_obj, handler_obj,
52795b482a8SLen Brown acpi_ut_get_region_name(region_obj->region.
52895b482a8SLen Brown space_id)));
52995b482a8SLen Brown
53095b482a8SLen Brown /* Link this region to the front of the handler's list */
53195b482a8SLen Brown
53295b482a8SLen Brown region_obj->region.next = handler_obj->address_space.region_list;
53395b482a8SLen Brown handler_obj->address_space.region_list = region_obj;
53495b482a8SLen Brown region_obj->region.handler = handler_obj;
53595b482a8SLen Brown acpi_ut_add_reference(handler_obj);
53695b482a8SLen Brown
53795b482a8SLen Brown return_ACPI_STATUS(AE_OK);
53895b482a8SLen Brown }
53995b482a8SLen Brown
54095b482a8SLen Brown /*******************************************************************************
54195b482a8SLen Brown *
54242f8fb75SBob Moore * FUNCTION: acpi_ev_execute_reg_method
54395b482a8SLen Brown *
54442f8fb75SBob Moore * PARAMETERS: region_obj - Region object
54542f8fb75SBob Moore * function - Passed to _REG: On (1) or Off (0)
54695b482a8SLen Brown *
54795b482a8SLen Brown * RETURN: Status
54895b482a8SLen Brown *
54942f8fb75SBob Moore * DESCRIPTION: Execute _REG method for a region
55095b482a8SLen Brown *
55195b482a8SLen Brown ******************************************************************************/
55295b482a8SLen Brown
55395b482a8SLen Brown acpi_status
acpi_ev_execute_reg_method(union acpi_operand_object * region_obj,u32 function)55442f8fb75SBob Moore acpi_ev_execute_reg_method(union acpi_operand_object *region_obj, u32 function)
55595b482a8SLen Brown {
55642f8fb75SBob Moore struct acpi_evaluate_info *info;
55742f8fb75SBob Moore union acpi_operand_object *args[3];
55842f8fb75SBob Moore union acpi_operand_object *region_obj2;
559d1461a1bSLv Zheng const acpi_name *reg_name_ptr =
560d1461a1bSLv Zheng ACPI_CAST_PTR(acpi_name, METHOD_NAME__REG);
561d1461a1bSLv Zheng struct acpi_namespace_node *method_node;
562d1461a1bSLv Zheng struct acpi_namespace_node *node;
56395b482a8SLen Brown acpi_status status;
56495b482a8SLen Brown
56542f8fb75SBob Moore ACPI_FUNCTION_TRACE(ev_execute_reg_method);
56642f8fb75SBob Moore
567d1461a1bSLv Zheng if (!acpi_gbl_namespace_initialized ||
568d1461a1bSLv Zheng region_obj->region.handler == NULL) {
569d1461a1bSLv Zheng return_ACPI_STATUS(AE_OK);
570d1461a1bSLv Zheng }
571d1461a1bSLv Zheng
57242f8fb75SBob Moore region_obj2 = acpi_ns_get_secondary_object(region_obj);
57342f8fb75SBob Moore if (!region_obj2) {
57442f8fb75SBob Moore return_ACPI_STATUS(AE_NOT_EXIST);
57542f8fb75SBob Moore }
57642f8fb75SBob Moore
577d1461a1bSLv Zheng /*
578d1461a1bSLv Zheng * Find any "_REG" method associated with this region definition.
579d1461a1bSLv Zheng * The method should always be updated as this function may be
580d1461a1bSLv Zheng * invoked after a namespace change.
581d1461a1bSLv Zheng */
582d1461a1bSLv Zheng node = region_obj->region.node->parent;
583d1461a1bSLv Zheng status =
584d1461a1bSLv Zheng acpi_ns_search_one_scope(*reg_name_ptr, node, ACPI_TYPE_METHOD,
585d1461a1bSLv Zheng &method_node);
586d1461a1bSLv Zheng if (ACPI_SUCCESS(status)) {
587d1461a1bSLv Zheng /*
588d1461a1bSLv Zheng * The _REG method is optional and there can be only one per
589d1461a1bSLv Zheng * region definition. This will be executed when the handler is
590d1461a1bSLv Zheng * attached or removed.
591d1461a1bSLv Zheng */
592d1461a1bSLv Zheng region_obj2->extra.method_REG = method_node;
593d1461a1bSLv Zheng }
594d1461a1bSLv Zheng if (region_obj2->extra.method_REG == NULL) {
595efaed9beSLv Zheng return_ACPI_STATUS(AE_OK);
596efaed9beSLv Zheng }
597efaed9beSLv Zheng
598efaed9beSLv Zheng /* _REG(DISCONNECT) should be paired with _REG(CONNECT) */
599efaed9beSLv Zheng
600efaed9beSLv Zheng if ((function == ACPI_REG_CONNECT &&
601efaed9beSLv Zheng region_obj->common.flags & AOPOBJ_REG_CONNECTED) ||
602efaed9beSLv Zheng (function == ACPI_REG_DISCONNECT &&
603efaed9beSLv Zheng !(region_obj->common.flags & AOPOBJ_REG_CONNECTED))) {
60442f8fb75SBob Moore return_ACPI_STATUS(AE_OK);
60542f8fb75SBob Moore }
60642f8fb75SBob Moore
60742f8fb75SBob Moore /* Allocate and initialize the evaluation information block */
60842f8fb75SBob Moore
60942f8fb75SBob Moore info = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_evaluate_info));
61042f8fb75SBob Moore if (!info) {
61142f8fb75SBob Moore return_ACPI_STATUS(AE_NO_MEMORY);
61242f8fb75SBob Moore }
61342f8fb75SBob Moore
61442f8fb75SBob Moore info->prefix_node = region_obj2->extra.method_REG;
61529a241ccSBob Moore info->relative_pathname = NULL;
61642f8fb75SBob Moore info->parameters = args;
61742f8fb75SBob Moore info->flags = ACPI_IGNORE_RETURN_VALUE;
61895b482a8SLen Brown
61995b482a8SLen Brown /*
62042f8fb75SBob Moore * The _REG method has two arguments:
62142f8fb75SBob Moore *
62242f8fb75SBob Moore * arg0 - Integer:
62342f8fb75SBob Moore * Operation region space ID Same value as region_obj->Region.space_id
62442f8fb75SBob Moore *
62542f8fb75SBob Moore * arg1 - Integer:
62642f8fb75SBob Moore * connection status 1 for connecting the handler, 0 for disconnecting
62742f8fb75SBob Moore * the handler (Passed as a parameter)
62895b482a8SLen Brown */
62942f8fb75SBob Moore args[0] =
63042f8fb75SBob Moore acpi_ut_create_integer_object((u64)region_obj->region.space_id);
63142f8fb75SBob Moore if (!args[0]) {
63295b482a8SLen Brown status = AE_NO_MEMORY;
63342f8fb75SBob Moore goto cleanup1;
63495b482a8SLen Brown }
63595b482a8SLen Brown
63642f8fb75SBob Moore args[1] = acpi_ut_create_integer_object((u64)function);
63742f8fb75SBob Moore if (!args[1]) {
63895b482a8SLen Brown status = AE_NO_MEMORY;
63942f8fb75SBob Moore goto cleanup2;
64095b482a8SLen Brown }
64195b482a8SLen Brown
64242f8fb75SBob Moore args[2] = NULL; /* Terminate list */
64395b482a8SLen Brown
64442f8fb75SBob Moore /* Execute the method, no return value */
64595b482a8SLen Brown
64642f8fb75SBob Moore ACPI_DEBUG_EXEC(acpi_ut_display_init_pathname
64742f8fb75SBob Moore (ACPI_TYPE_METHOD, info->prefix_node, NULL));
64895b482a8SLen Brown
64942f8fb75SBob Moore status = acpi_ns_evaluate(info);
65042f8fb75SBob Moore acpi_ut_remove_reference(args[1]);
65195b482a8SLen Brown
652efaed9beSLv Zheng if (ACPI_FAILURE(status)) {
653efaed9beSLv Zheng goto cleanup2;
654efaed9beSLv Zheng }
655efaed9beSLv Zheng
656efaed9beSLv Zheng if (function == ACPI_REG_CONNECT) {
657efaed9beSLv Zheng region_obj->common.flags |= AOPOBJ_REG_CONNECTED;
658efaed9beSLv Zheng } else {
659efaed9beSLv Zheng region_obj->common.flags &= ~AOPOBJ_REG_CONNECTED;
660efaed9beSLv Zheng }
661efaed9beSLv Zheng
66242f8fb75SBob Moore cleanup2:
66342f8fb75SBob Moore acpi_ut_remove_reference(args[0]);
66495b482a8SLen Brown
66542f8fb75SBob Moore cleanup1:
66642f8fb75SBob Moore ACPI_FREE(info);
66795b482a8SLen Brown return_ACPI_STATUS(status);
66895b482a8SLen Brown }
66995b482a8SLen Brown
67095b482a8SLen Brown /*******************************************************************************
67195b482a8SLen Brown *
67295b482a8SLen Brown * FUNCTION: acpi_ev_execute_reg_methods
67395b482a8SLen Brown *
674ba494beeSBob Moore * PARAMETERS: node - Namespace node for the device
67595b482a8SLen Brown * space_id - The address space ID
676d815346fSLv Zheng * function - Passed to _REG: On (1) or Off (0)
67795b482a8SLen Brown *
678d815346fSLv Zheng * RETURN: None
67995b482a8SLen Brown *
68095b482a8SLen Brown * DESCRIPTION: Run all _REG methods for the input Space ID;
68195b482a8SLen Brown * Note: assumes namespace is locked, or system init time.
68295b482a8SLen Brown *
68395b482a8SLen Brown ******************************************************************************/
68495b482a8SLen Brown
685d815346fSLv Zheng void
acpi_ev_execute_reg_methods(struct acpi_namespace_node * node,acpi_adr_space_type space_id,u32 function)68695b482a8SLen Brown acpi_ev_execute_reg_methods(struct acpi_namespace_node *node,
687d815346fSLv Zheng acpi_adr_space_type space_id, u32 function)
68895b482a8SLen Brown {
68925823e78SBob Moore struct acpi_reg_walk_info info;
69095b482a8SLen Brown
69195b482a8SLen Brown ACPI_FUNCTION_TRACE(ev_execute_reg_methods);
69295b482a8SLen Brown
6938b1cafdcSBob Moore /*
6948b1cafdcSBob Moore * These address spaces do not need a call to _REG, since the ACPI
6958b1cafdcSBob Moore * specification defines them as: "must always be accessible". Since
6968b1cafdcSBob Moore * they never change state (never become unavailable), no need to ever
6978b1cafdcSBob Moore * call _REG on them. Also, a data_table is not a "real" address space,
6988b1cafdcSBob Moore * so do not call _REG. September 2018.
6998b1cafdcSBob Moore */
7008b1cafdcSBob Moore if ((space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY) ||
7018b1cafdcSBob Moore (space_id == ACPI_ADR_SPACE_SYSTEM_IO) ||
7028b1cafdcSBob Moore (space_id == ACPI_ADR_SPACE_DATA_TABLE)) {
7038b1cafdcSBob Moore return_VOID;
7048b1cafdcSBob Moore }
7058b1cafdcSBob Moore
70625823e78SBob Moore info.space_id = space_id;
707d815346fSLv Zheng info.function = function;
70825823e78SBob Moore info.reg_run_count = 0;
70925823e78SBob Moore
71025823e78SBob Moore ACPI_DEBUG_PRINT_RAW((ACPI_DB_NAMES,
71125823e78SBob Moore " Running _REG methods for SpaceId %s\n",
71225823e78SBob Moore acpi_ut_get_region_name(info.space_id)));
71325823e78SBob Moore
71495b482a8SLen Brown /*
71595b482a8SLen Brown * Run all _REG methods for all Operation Regions for this space ID. This
71695b482a8SLen Brown * is a separate walk in order to handle any interdependencies between
71795b482a8SLen Brown * regions and _REG methods. (i.e. handlers must be installed for all
71895b482a8SLen Brown * regions of this Space ID before we can run any _REG methods)
71995b482a8SLen Brown */
720d815346fSLv Zheng (void)acpi_ns_walk_namespace(ACPI_TYPE_ANY, node, ACPI_UINT32_MAX,
721d815346fSLv Zheng ACPI_NS_WALK_UNLOCK, acpi_ev_reg_run, NULL,
722d815346fSLv Zheng &info, NULL);
72395b482a8SLen Brown
7240306f035SHans de Goede /*
7250306f035SHans de Goede * Special case for EC and GPIO: handle "orphan" _REG methods with
7260306f035SHans de Goede * no region.
7270306f035SHans de Goede */
7280306f035SHans de Goede if (space_id == ACPI_ADR_SPACE_EC || space_id == ACPI_ADR_SPACE_GPIO) {
7290306f035SHans de Goede acpi_ev_execute_orphan_reg_method(node, space_id);
730e2066ca1SBob Moore }
731e2066ca1SBob Moore
73225823e78SBob Moore ACPI_DEBUG_PRINT_RAW((ACPI_DB_NAMES,
73325823e78SBob Moore " Executed %u _REG methods for SpaceId %s\n",
73425823e78SBob Moore info.reg_run_count,
73525823e78SBob Moore acpi_ut_get_region_name(info.space_id)));
73625823e78SBob Moore
737d815346fSLv Zheng return_VOID;
73895b482a8SLen Brown }
73995b482a8SLen Brown
74095b482a8SLen Brown /*******************************************************************************
74195b482a8SLen Brown *
74295b482a8SLen Brown * FUNCTION: acpi_ev_reg_run
74395b482a8SLen Brown *
74495b482a8SLen Brown * PARAMETERS: walk_namespace callback
74595b482a8SLen Brown *
746ba494beeSBob Moore * DESCRIPTION: Run _REG method for region objects of the requested spaceID
74795b482a8SLen Brown *
74895b482a8SLen Brown ******************************************************************************/
74995b482a8SLen Brown
75095b482a8SLen Brown static acpi_status
acpi_ev_reg_run(acpi_handle obj_handle,u32 level,void * context,void ** return_value)75195b482a8SLen Brown acpi_ev_reg_run(acpi_handle obj_handle,
75295b482a8SLen Brown u32 level, void *context, void **return_value)
75395b482a8SLen Brown {
75495b482a8SLen Brown union acpi_operand_object *obj_desc;
75595b482a8SLen Brown struct acpi_namespace_node *node;
75695b482a8SLen Brown acpi_status status;
75725823e78SBob Moore struct acpi_reg_walk_info *info;
75895b482a8SLen Brown
75925823e78SBob Moore info = ACPI_CAST_PTR(struct acpi_reg_walk_info, context);
76095b482a8SLen Brown
76195b482a8SLen Brown /* Convert and validate the device handle */
76295b482a8SLen Brown
763f24b664dSBob Moore node = acpi_ns_validate_handle(obj_handle);
76495b482a8SLen Brown if (!node) {
76595b482a8SLen Brown return (AE_BAD_PARAMETER);
76695b482a8SLen Brown }
76795b482a8SLen Brown
76895b482a8SLen Brown /*
7698b1cafdcSBob Moore * We only care about regions and objects that are allowed to have
7708b1cafdcSBob Moore * address space handlers
77195b482a8SLen Brown */
77295b482a8SLen Brown if ((node->type != ACPI_TYPE_REGION) && (node != acpi_gbl_root_node)) {
77395b482a8SLen Brown return (AE_OK);
77495b482a8SLen Brown }
77595b482a8SLen Brown
77695b482a8SLen Brown /* Check for an existing internal object */
77795b482a8SLen Brown
77895b482a8SLen Brown obj_desc = acpi_ns_get_attached_object(node);
77995b482a8SLen Brown if (!obj_desc) {
78095b482a8SLen Brown
78195b482a8SLen Brown /* No object, just exit */
78295b482a8SLen Brown
78395b482a8SLen Brown return (AE_OK);
78495b482a8SLen Brown }
78595b482a8SLen Brown
78695b482a8SLen Brown /* Object is a Region */
78795b482a8SLen Brown
78825823e78SBob Moore if (obj_desc->region.space_id != info->space_id) {
78995b482a8SLen Brown
79095b482a8SLen Brown /* This region is for a different address space, just ignore it */
79195b482a8SLen Brown
79295b482a8SLen Brown return (AE_OK);
79395b482a8SLen Brown }
79495b482a8SLen Brown
79525823e78SBob Moore info->reg_run_count++;
796d815346fSLv Zheng status = acpi_ev_execute_reg_method(obj_desc, info->function);
79795b482a8SLen Brown return (status);
79895b482a8SLen Brown }
799e2066ca1SBob Moore
800e2066ca1SBob Moore /*******************************************************************************
801e2066ca1SBob Moore *
8020306f035SHans de Goede * FUNCTION: acpi_ev_execute_orphan_reg_method
803e2066ca1SBob Moore *
8040306f035SHans de Goede * PARAMETERS: device_node - Namespace node for an ACPI device
8050306f035SHans de Goede * space_id - The address space ID
806e2066ca1SBob Moore *
807e2066ca1SBob Moore * RETURN: None
808e2066ca1SBob Moore *
8090306f035SHans de Goede * DESCRIPTION: Execute an "orphan" _REG method that appears under an ACPI
810e2066ca1SBob Moore * device. This is a _REG method that has no corresponding region
8110306f035SHans de Goede * within the device's scope. ACPI tables depending on these
8120306f035SHans de Goede * "orphan" _REG methods have been seen for both EC and GPIO
8130306f035SHans de Goede * Operation Regions. Presumably the Windows ACPI implementation
8140306f035SHans de Goede * always calls the _REG method independent of the presence of
8150306f035SHans de Goede * an actual Operation Region with the correct address space ID.
8168f4f5e78SZhang Rui *
8178f4f5e78SZhang Rui * MUTEX: Assumes the namespace is locked
818e2066ca1SBob Moore *
819e2066ca1SBob Moore ******************************************************************************/
820e2066ca1SBob Moore
8218f4f5e78SZhang Rui static void
acpi_ev_execute_orphan_reg_method(struct acpi_namespace_node * device_node,acpi_adr_space_type space_id)8220306f035SHans de Goede acpi_ev_execute_orphan_reg_method(struct acpi_namespace_node *device_node,
8230306f035SHans de Goede acpi_adr_space_type space_id)
824e2066ca1SBob Moore {
8258f4f5e78SZhang Rui acpi_handle reg_method;
8268f4f5e78SZhang Rui struct acpi_namespace_node *next_node;
827e2066ca1SBob Moore acpi_status status;
828e2066ca1SBob Moore struct acpi_object_list args;
829e2066ca1SBob Moore union acpi_object objects[2];
830e2066ca1SBob Moore
8310306f035SHans de Goede ACPI_FUNCTION_TRACE(ev_execute_orphan_reg_method);
832e2066ca1SBob Moore
8330306f035SHans de Goede if (!device_node) {
834e2066ca1SBob Moore return_VOID;
835e2066ca1SBob Moore }
836e2066ca1SBob Moore
837e2066ca1SBob Moore /* Namespace is currently locked, must release */
838e2066ca1SBob Moore
839e2066ca1SBob Moore (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
840e2066ca1SBob Moore
841e2066ca1SBob Moore /* Get a handle to a _REG method immediately under the EC device */
842e2066ca1SBob Moore
8430306f035SHans de Goede status = acpi_get_handle(device_node, METHOD_NAME__REG, ®_method);
844e2066ca1SBob Moore if (ACPI_FAILURE(status)) {
8458f4f5e78SZhang Rui goto exit; /* There is no _REG method present */
846e2066ca1SBob Moore }
847e2066ca1SBob Moore
848e2066ca1SBob Moore /*
849e2066ca1SBob Moore * Execute the _REG method only if there is no Operation Region in
850e2066ca1SBob Moore * this scope with the Embedded Controller space ID. Otherwise, it
851e2066ca1SBob Moore * will already have been executed. Note, this allows for Regions
852e2066ca1SBob Moore * with other space IDs to be present; but the code below will then
8538f4f5e78SZhang Rui * execute the _REG method with the embedded_control space_ID argument.
854e2066ca1SBob Moore */
8550306f035SHans de Goede next_node = acpi_ns_get_next_node(device_node, NULL);
856e2066ca1SBob Moore while (next_node) {
857e2066ca1SBob Moore if ((next_node->type == ACPI_TYPE_REGION) &&
858e2066ca1SBob Moore (next_node->object) &&
8590306f035SHans de Goede (next_node->object->region.space_id == space_id)) {
8608f4f5e78SZhang Rui goto exit; /* Do not execute the _REG */
861e2066ca1SBob Moore }
8628f4f5e78SZhang Rui
8630306f035SHans de Goede next_node = acpi_ns_get_next_node(device_node, next_node);
864e2066ca1SBob Moore }
865e2066ca1SBob Moore
8660306f035SHans de Goede /* Evaluate the _REG(space_id,Connect) method */
867e2066ca1SBob Moore
868e2066ca1SBob Moore args.count = 2;
869e2066ca1SBob Moore args.pointer = objects;
870e2066ca1SBob Moore objects[0].type = ACPI_TYPE_INTEGER;
8710306f035SHans de Goede objects[0].integer.value = space_id;
872e2066ca1SBob Moore objects[1].type = ACPI_TYPE_INTEGER;
873e2066ca1SBob Moore objects[1].integer.value = ACPI_REG_CONNECT;
874e2066ca1SBob Moore
875edc5935eSBob Moore (void)acpi_evaluate_object(reg_method, NULL, &args, NULL);
876e2066ca1SBob Moore
877e2066ca1SBob Moore exit:
878e2066ca1SBob Moore /* We ignore all errors from above, don't care */
879e2066ca1SBob Moore
880edc5935eSBob Moore (void)acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
881e2066ca1SBob Moore return_VOID;
882e2066ca1SBob Moore }
883