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