Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
Bob Moore | 42f8fb7 | 2013-01-11 13:08:51 +0100 | [diff] [blame] | 3 | * Module Name: evregion - Operation Region support |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * |
| 5 | *****************************************************************************/ |
| 6 | |
| 7 | /* |
Bob Moore | 25f044e | 2013-01-25 05:38:56 +0000 | [diff] [blame] | 8 | * Copyright (C) 2000 - 2013, Intel Corp. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | * All rights reserved. |
| 10 | * |
| 11 | * Redistribution and use in source and binary forms, with or without |
| 12 | * modification, are permitted provided that the following conditions |
| 13 | * are met: |
| 14 | * 1. Redistributions of source code must retain the above copyright |
| 15 | * notice, this list of conditions, and the following disclaimer, |
| 16 | * without modification. |
| 17 | * 2. Redistributions in binary form must reproduce at minimum a disclaimer |
| 18 | * substantially similar to the "NO WARRANTY" disclaimer below |
| 19 | * ("Disclaimer") and any redistribution must be conditioned upon |
| 20 | * including a substantially similar Disclaimer requirement for further |
| 21 | * binary redistribution. |
| 22 | * 3. Neither the names of the above-listed copyright holders nor the names |
| 23 | * of any contributors may be used to endorse or promote products derived |
| 24 | * from this software without specific prior written permission. |
| 25 | * |
| 26 | * Alternatively, this software may be distributed under the terms of the |
| 27 | * GNU General Public License ("GPL") version 2 as published by the Free |
| 28 | * Software Foundation. |
| 29 | * |
| 30 | * NO WARRANTY |
| 31 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 32 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 33 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR |
| 34 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 35 | * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 36 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 37 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 38 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
| 39 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING |
| 40 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 41 | * POSSIBILITY OF SUCH DAMAGES. |
| 42 | */ |
| 43 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | #include <acpi/acpi.h> |
Len Brown | e2f7a77 | 2009-01-09 00:30:03 -0500 | [diff] [blame] | 45 | #include "accommon.h" |
| 46 | #include "acevents.h" |
| 47 | #include "acnamesp.h" |
| 48 | #include "acinterp.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | |
| 50 | #define _COMPONENT ACPI_EVENTS |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 51 | ACPI_MODULE_NAME("evregion") |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | |
Bob Moore | 42f8fb7 | 2013-01-11 13:08:51 +0100 | [diff] [blame] | 53 | extern u8 acpi_gbl_default_address_spaces[]; |
| 54 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 55 | /* Local prototypes */ |
Lin Ming | 74d3ec77 | 2009-10-13 10:29:30 +0800 | [diff] [blame] | 56 | |
Bob Moore | e2066ca | 2011-04-13 13:22:04 +0800 | [diff] [blame] | 57 | static void acpi_ev_orphan_ec_reg_method(void); |
| 58 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 59 | static acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 60 | acpi_ev_reg_run(acpi_handle obj_handle, |
| 61 | u32 level, void *context, void **return_value); |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 62 | |
Lin Ming | 74d3ec77 | 2009-10-13 10:29:30 +0800 | [diff] [blame] | 63 | /******************************************************************************* |
| 64 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | * FUNCTION: acpi_ev_initialize_op_regions |
| 66 | * |
| 67 | * PARAMETERS: None |
| 68 | * |
| 69 | * RETURN: Status |
| 70 | * |
| 71 | * DESCRIPTION: Execute _REG methods for all Operation Regions that have |
| 72 | * an installed default region handler. |
| 73 | * |
| 74 | ******************************************************************************/ |
| 75 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 76 | acpi_status acpi_ev_initialize_op_regions(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 78 | acpi_status status; |
Bob Moore | 67a119f | 2008-06-10 13:42:13 +0800 | [diff] [blame] | 79 | u32 i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 81 | ACPI_FUNCTION_TRACE(ev_initialize_op_regions); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 83 | status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); |
| 84 | if (ACPI_FAILURE(status)) { |
| 85 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | } |
| 87 | |
Bob Moore | 9f15fc6 | 2008-11-12 16:01:56 +0800 | [diff] [blame] | 88 | /* Run the _REG methods for op_regions in each default address space */ |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 89 | |
Bob Moore | 9f15fc6 | 2008-11-12 16:01:56 +0800 | [diff] [blame] | 90 | for (i = 0; i < ACPI_NUM_DEFAULT_SPACES; i++) { |
| 91 | /* |
Lin Ming | 74d3ec77 | 2009-10-13 10:29:30 +0800 | [diff] [blame] | 92 | * Make sure the installed handler is the DEFAULT handler. If not the |
| 93 | * default, the _REG methods will have already been run (when the |
| 94 | * handler was installed) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | */ |
Lin Ming | 74d3ec77 | 2009-10-13 10:29:30 +0800 | [diff] [blame] | 96 | if (acpi_ev_has_default_handler(acpi_gbl_root_node, |
| 97 | acpi_gbl_default_address_spaces |
| 98 | [i])) { |
| 99 | status = |
| 100 | acpi_ev_execute_reg_methods(acpi_gbl_root_node, |
| 101 | acpi_gbl_default_address_spaces |
| 102 | [i]); |
| 103 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | } |
| 105 | |
Bob Moore | ef09c4f | 2011-02-14 16:13:25 +0800 | [diff] [blame] | 106 | acpi_gbl_reg_methods_executed = TRUE; |
| 107 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 108 | (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); |
| 109 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | } |
| 111 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | /******************************************************************************* |
| 113 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | * FUNCTION: acpi_ev_address_space_dispatch |
| 115 | * |
| 116 | * PARAMETERS: region_obj - Internal region object |
Bob Moore | 9ce8178 | 2011-11-16 13:39:07 +0800 | [diff] [blame] | 117 | * field_obj - Corresponding field. Can be NULL. |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 118 | * function - Read or Write operation |
Bob Moore | f5407af | 2009-05-21 10:56:52 +0800 | [diff] [blame] | 119 | * region_offset - Where in the region to read or write |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | * bit_width - Field width in bits (8, 16, 32, or 64) |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 121 | * value - Pointer to in or out value, must be |
Bob Moore | 5df7e6c | 2010-01-21 10:06:32 +0800 | [diff] [blame] | 122 | * a full 64-bit integer |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | * |
| 124 | * RETURN: Status |
| 125 | * |
| 126 | * DESCRIPTION: Dispatch an address space or operation region access to |
| 127 | * a previously installed handler. |
| 128 | * |
| 129 | ******************************************************************************/ |
| 130 | |
| 131 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 132 | acpi_ev_address_space_dispatch(union acpi_operand_object *region_obj, |
Bob Moore | 9ce8178 | 2011-11-16 13:39:07 +0800 | [diff] [blame] | 133 | union acpi_operand_object *field_obj, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 134 | u32 function, |
Bob Moore | 5df7e6c | 2010-01-21 10:06:32 +0800 | [diff] [blame] | 135 | u32 region_offset, u32 bit_width, u64 *value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 137 | acpi_status status; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 138 | acpi_adr_space_handler handler; |
| 139 | acpi_adr_space_setup region_setup; |
| 140 | union acpi_operand_object *handler_desc; |
| 141 | union acpi_operand_object *region_obj2; |
| 142 | void *region_context = NULL; |
Bob Moore | 9ce8178 | 2011-11-16 13:39:07 +0800 | [diff] [blame] | 143 | struct acpi_connection_info *context; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 145 | ACPI_FUNCTION_TRACE(ev_address_space_dispatch); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 147 | region_obj2 = acpi_ns_get_secondary_object(region_obj); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | if (!region_obj2) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 149 | return_ACPI_STATUS(AE_NOT_EXIST); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | } |
| 151 | |
| 152 | /* Ensure that there is a handler associated with this region */ |
| 153 | |
| 154 | handler_desc = region_obj->region.handler; |
| 155 | if (!handler_desc) { |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 156 | ACPI_ERROR((AE_INFO, |
| 157 | "No handler for Region [%4.4s] (%p) [%s]", |
| 158 | acpi_ut_get_node_name(region_obj->region.node), |
| 159 | region_obj, |
| 160 | acpi_ut_get_region_name(region_obj->region. |
| 161 | space_id))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 163 | return_ACPI_STATUS(AE_NOT_EXIST); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | } |
| 165 | |
Bob Moore | 9ce8178 | 2011-11-16 13:39:07 +0800 | [diff] [blame] | 166 | context = handler_desc->address_space.context; |
| 167 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | /* |
Bob Moore | 9f15fc6 | 2008-11-12 16:01:56 +0800 | [diff] [blame] | 169 | * It may be the case that the region has never been initialized. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | * Some types of regions require special init code |
| 171 | */ |
| 172 | if (!(region_obj->region.flags & AOPOBJ_SETUP_COMPLETE)) { |
Bob Moore | 9f15fc6 | 2008-11-12 16:01:56 +0800 | [diff] [blame] | 173 | |
| 174 | /* This region has not been initialized yet, do it */ |
| 175 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | region_setup = handler_desc->address_space.setup; |
| 177 | if (!region_setup) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 178 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | /* No initialization routine, exit with error */ |
| 180 | |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 181 | ACPI_ERROR((AE_INFO, |
| 182 | "No init routine for region(%p) [%s]", |
| 183 | region_obj, |
| 184 | acpi_ut_get_region_name(region_obj->region. |
| 185 | space_id))); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 186 | return_ACPI_STATUS(AE_NOT_EXIST); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | } |
| 188 | |
| 189 | /* |
Bob Moore | 9f15fc6 | 2008-11-12 16:01:56 +0800 | [diff] [blame] | 190 | * We must exit the interpreter because the region setup will |
| 191 | * potentially execute control methods (for example, the _REG method |
| 192 | * for this region) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | */ |
Bob Moore | 014d433 | 2008-01-10 23:04:10 -0500 | [diff] [blame] | 194 | acpi_ex_exit_interpreter(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 196 | status = region_setup(region_obj, ACPI_REGION_ACTIVATE, |
Bob Moore | 9ce8178 | 2011-11-16 13:39:07 +0800 | [diff] [blame] | 197 | context, ®ion_context); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | |
| 199 | /* Re-enter the interpreter */ |
| 200 | |
Bob Moore | 014d433 | 2008-01-10 23:04:10 -0500 | [diff] [blame] | 201 | acpi_ex_enter_interpreter(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | |
| 203 | /* Check for failure of the Region Setup */ |
| 204 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 205 | if (ACPI_FAILURE(status)) { |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 206 | ACPI_EXCEPTION((AE_INFO, status, |
| 207 | "During region initialization: [%s]", |
| 208 | acpi_ut_get_region_name(region_obj-> |
| 209 | region. |
| 210 | space_id))); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 211 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | } |
| 213 | |
Bob Moore | 9f15fc6 | 2008-11-12 16:01:56 +0800 | [diff] [blame] | 214 | /* Region initialization may have been completed by region_setup */ |
| 215 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | if (!(region_obj->region.flags & AOPOBJ_SETUP_COMPLETE)) { |
| 217 | region_obj->region.flags |= AOPOBJ_SETUP_COMPLETE; |
| 218 | |
| 219 | if (region_obj2->extra.region_context) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 220 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | /* The handler for this region was already installed */ |
| 222 | |
Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 223 | ACPI_FREE(region_context); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 224 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | /* |
| 226 | * Save the returned context for use in all accesses to |
| 227 | * this particular region |
| 228 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 229 | region_obj2->extra.region_context = |
| 230 | region_context; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | } |
| 232 | } |
| 233 | } |
| 234 | |
| 235 | /* We have everything we need, we can invoke the address space handler */ |
| 236 | |
| 237 | handler = handler_desc->address_space.handler; |
| 238 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 239 | ACPI_DEBUG_PRINT((ACPI_DB_OPREGION, |
| 240 | "Handler %p (@%p) Address %8.8X%8.8X [%s]\n", |
| 241 | ®ion_obj->region.handler->address_space, handler, |
Bob Moore | f5407af | 2009-05-21 10:56:52 +0800 | [diff] [blame] | 242 | ACPI_FORMAT_NATIVE_UINT(region_obj->region.address + |
| 243 | region_offset), |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 244 | acpi_ut_get_region_name(region_obj->region. |
| 245 | space_id))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | |
Bob Moore | 9ce8178 | 2011-11-16 13:39:07 +0800 | [diff] [blame] | 247 | /* |
| 248 | * Special handling for generic_serial_bus and general_purpose_io: |
| 249 | * There are three extra parameters that must be passed to the |
| 250 | * handler via the context: |
| 251 | * 1) Connection buffer, a resource template from Connection() op. |
| 252 | * 2) Length of the above buffer. |
| 253 | * 3) Actual access length from the access_as() op. |
| 254 | */ |
| 255 | if (((region_obj->region.space_id == ACPI_ADR_SPACE_GSBUS) || |
| 256 | (region_obj->region.space_id == ACPI_ADR_SPACE_GPIO)) && |
| 257 | context && field_obj) { |
| 258 | |
| 259 | /* Get the Connection (resource_template) buffer */ |
| 260 | |
| 261 | context->connection = field_obj->field.resource_buffer; |
| 262 | context->length = field_obj->field.resource_length; |
| 263 | context->access_length = field_obj->field.access_length; |
| 264 | } |
| 265 | |
Bob Moore | 61686124 | 2006-03-17 16:44:00 -0500 | [diff] [blame] | 266 | if (!(handler_desc->address_space.handler_flags & |
| 267 | ACPI_ADDR_HANDLER_DEFAULT_INSTALLED)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | /* |
| 269 | * For handlers other than the default (supplied) handlers, we must |
| 270 | * exit the interpreter because the handler *might* block -- we don't |
| 271 | * know what it will do, so we can't hold the lock on the intepreter. |
| 272 | */ |
Bob Moore | 014d433 | 2008-01-10 23:04:10 -0500 | [diff] [blame] | 273 | acpi_ex_exit_interpreter(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | } |
| 275 | |
| 276 | /* Call the handler */ |
| 277 | |
Bob Moore | f5407af | 2009-05-21 10:56:52 +0800 | [diff] [blame] | 278 | status = handler(function, |
| 279 | (region_obj->region.address + region_offset), |
Bob Moore | 9ce8178 | 2011-11-16 13:39:07 +0800 | [diff] [blame] | 280 | bit_width, value, context, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | region_obj2->extra.region_context); |
| 282 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 283 | if (ACPI_FAILURE(status)) { |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 284 | ACPI_EXCEPTION((AE_INFO, status, "Returned by Handler for [%s]", |
| 285 | acpi_ut_get_region_name(region_obj->region. |
| 286 | space_id))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | } |
| 288 | |
Bob Moore | 61686124 | 2006-03-17 16:44:00 -0500 | [diff] [blame] | 289 | if (!(handler_desc->address_space.handler_flags & |
| 290 | ACPI_ADDR_HANDLER_DEFAULT_INSTALLED)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | /* |
| 292 | * We just returned from a non-default handler, we must re-enter the |
| 293 | * interpreter |
| 294 | */ |
Bob Moore | 014d433 | 2008-01-10 23:04:10 -0500 | [diff] [blame] | 295 | acpi_ex_enter_interpreter(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | } |
| 297 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 298 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | } |
| 300 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | /******************************************************************************* |
| 302 | * |
| 303 | * FUNCTION: acpi_ev_detach_region |
| 304 | * |
| 305 | * PARAMETERS: region_obj - Region Object |
| 306 | * acpi_ns_is_locked - Namespace Region Already Locked? |
| 307 | * |
| 308 | * RETURN: None |
| 309 | * |
| 310 | * DESCRIPTION: Break the association between the handler and the region |
| 311 | * this is a two way association. |
| 312 | * |
| 313 | ******************************************************************************/ |
| 314 | |
| 315 | void |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 316 | acpi_ev_detach_region(union acpi_operand_object *region_obj, |
| 317 | u8 acpi_ns_is_locked) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 319 | union acpi_operand_object *handler_obj; |
| 320 | union acpi_operand_object *obj_desc; |
| 321 | union acpi_operand_object **last_obj_ptr; |
| 322 | acpi_adr_space_setup region_setup; |
| 323 | void **region_context; |
| 324 | union acpi_operand_object *region_obj2; |
| 325 | acpi_status status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 327 | ACPI_FUNCTION_TRACE(ev_detach_region); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 329 | region_obj2 = acpi_ns_get_secondary_object(region_obj); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | if (!region_obj2) { |
| 331 | return_VOID; |
| 332 | } |
| 333 | region_context = ®ion_obj2->extra.region_context; |
| 334 | |
| 335 | /* Get the address handler from the region object */ |
| 336 | |
| 337 | handler_obj = region_obj->region.handler; |
| 338 | if (!handler_obj) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 339 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | /* This region has no handler, all done */ |
| 341 | |
| 342 | return_VOID; |
| 343 | } |
| 344 | |
| 345 | /* Find this region in the handler's list */ |
| 346 | |
| 347 | obj_desc = handler_obj->address_space.region_list; |
| 348 | last_obj_ptr = &handler_obj->address_space.region_list; |
| 349 | |
| 350 | while (obj_desc) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 351 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | /* Is this the correct Region? */ |
| 353 | |
| 354 | if (obj_desc == region_obj) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 355 | ACPI_DEBUG_PRINT((ACPI_DB_OPREGION, |
| 356 | "Removing Region %p from address handler %p\n", |
| 357 | region_obj, handler_obj)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | |
| 359 | /* This is it, remove it from the handler's list */ |
| 360 | |
| 361 | *last_obj_ptr = obj_desc->region.next; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 362 | obj_desc->region.next = NULL; /* Must clear field */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | |
| 364 | if (acpi_ns_is_locked) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 365 | status = |
| 366 | acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); |
| 367 | if (ACPI_FAILURE(status)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | return_VOID; |
| 369 | } |
| 370 | } |
| 371 | |
| 372 | /* Now stop region accesses by executing the _REG method */ |
| 373 | |
Bob Moore | e2066ca | 2011-04-13 13:22:04 +0800 | [diff] [blame] | 374 | status = |
| 375 | acpi_ev_execute_reg_method(region_obj, |
| 376 | ACPI_REG_DISCONNECT); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 377 | if (ACPI_FAILURE(status)) { |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 378 | ACPI_EXCEPTION((AE_INFO, status, |
| 379 | "from region _REG, [%s]", |
| 380 | acpi_ut_get_region_name |
| 381 | (region_obj->region.space_id))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | } |
| 383 | |
| 384 | if (acpi_ns_is_locked) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 385 | status = |
| 386 | acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); |
| 387 | if (ACPI_FAILURE(status)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 388 | return_VOID; |
| 389 | } |
| 390 | } |
| 391 | |
Bob Moore | f6dd922 | 2006-07-07 20:44:38 -0400 | [diff] [blame] | 392 | /* |
Bob Moore | 9f15fc6 | 2008-11-12 16:01:56 +0800 | [diff] [blame] | 393 | * If the region has been activated, call the setup handler with |
| 394 | * the deactivate notification |
Bob Moore | f6dd922 | 2006-07-07 20:44:38 -0400 | [diff] [blame] | 395 | */ |
| 396 | if (region_obj->region.flags & AOPOBJ_SETUP_COMPLETE) { |
| 397 | region_setup = handler_obj->address_space.setup; |
| 398 | status = |
| 399 | region_setup(region_obj, |
| 400 | ACPI_REGION_DEACTIVATE, |
| 401 | handler_obj->address_space. |
| 402 | context, region_context); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | |
Bob Moore | f6dd922 | 2006-07-07 20:44:38 -0400 | [diff] [blame] | 404 | /* Init routine may fail, Just ignore errors */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | |
Bob Moore | f6dd922 | 2006-07-07 20:44:38 -0400 | [diff] [blame] | 406 | if (ACPI_FAILURE(status)) { |
| 407 | ACPI_EXCEPTION((AE_INFO, status, |
| 408 | "from region handler - deactivate, [%s]", |
| 409 | acpi_ut_get_region_name |
| 410 | (region_obj->region. |
| 411 | space_id))); |
| 412 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 | |
Bob Moore | f6dd922 | 2006-07-07 20:44:38 -0400 | [diff] [blame] | 414 | region_obj->region.flags &= |
| 415 | ~(AOPOBJ_SETUP_COMPLETE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | } |
| 417 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 418 | /* |
| 419 | * Remove handler reference in the region |
| 420 | * |
Bob Moore | f6dd922 | 2006-07-07 20:44:38 -0400 | [diff] [blame] | 421 | * NOTE: this doesn't mean that the region goes away, the region |
| 422 | * is just inaccessible as indicated to the _REG method |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | * |
Bob Moore | f6dd922 | 2006-07-07 20:44:38 -0400 | [diff] [blame] | 424 | * If the region is on the handler's list, this must be the |
| 425 | * region's handler |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | */ |
| 427 | region_obj->region.handler = NULL; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 428 | acpi_ut_remove_reference(handler_obj); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | |
| 430 | return_VOID; |
| 431 | } |
| 432 | |
| 433 | /* Walk the linked list of handlers */ |
| 434 | |
| 435 | last_obj_ptr = &obj_desc->region.next; |
| 436 | obj_desc = obj_desc->region.next; |
| 437 | } |
| 438 | |
| 439 | /* If we get here, the region was not in the handler's region list */ |
| 440 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 441 | ACPI_DEBUG_PRINT((ACPI_DB_OPREGION, |
| 442 | "Cannot remove region %p from address handler %p\n", |
| 443 | region_obj, handler_obj)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 444 | |
| 445 | return_VOID; |
| 446 | } |
| 447 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | /******************************************************************************* |
| 449 | * |
| 450 | * FUNCTION: acpi_ev_attach_region |
| 451 | * |
| 452 | * PARAMETERS: handler_obj - Handler Object |
| 453 | * region_obj - Region Object |
| 454 | * acpi_ns_is_locked - Namespace Region Already Locked? |
| 455 | * |
| 456 | * RETURN: None |
| 457 | * |
| 458 | * DESCRIPTION: Create the association between the handler and the region |
| 459 | * this is a two way association. |
| 460 | * |
| 461 | ******************************************************************************/ |
| 462 | |
| 463 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 464 | acpi_ev_attach_region(union acpi_operand_object *handler_obj, |
| 465 | union acpi_operand_object *region_obj, |
| 466 | u8 acpi_ns_is_locked) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 | { |
| 468 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 469 | ACPI_FUNCTION_TRACE(ev_attach_region); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 471 | ACPI_DEBUG_PRINT((ACPI_DB_OPREGION, |
| 472 | "Adding Region [%4.4s] %p to address handler %p [%s]\n", |
| 473 | acpi_ut_get_node_name(region_obj->region.node), |
| 474 | region_obj, handler_obj, |
| 475 | acpi_ut_get_region_name(region_obj->region. |
| 476 | space_id))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 477 | |
| 478 | /* Link this region to the front of the handler's list */ |
| 479 | |
| 480 | region_obj->region.next = handler_obj->address_space.region_list; |
| 481 | handler_obj->address_space.region_list = region_obj; |
| 482 | |
| 483 | /* Install the region's handler */ |
| 484 | |
| 485 | if (region_obj->region.handler) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 486 | return_ACPI_STATUS(AE_ALREADY_EXISTS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 487 | } |
| 488 | |
| 489 | region_obj->region.handler = handler_obj; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 490 | acpi_ut_add_reference(handler_obj); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 491 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 492 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 493 | } |
| 494 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 495 | /******************************************************************************* |
| 496 | * |
Bob Moore | 42f8fb7 | 2013-01-11 13:08:51 +0100 | [diff] [blame] | 497 | * FUNCTION: acpi_ev_execute_reg_method |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 498 | * |
Bob Moore | 42f8fb7 | 2013-01-11 13:08:51 +0100 | [diff] [blame] | 499 | * PARAMETERS: region_obj - Region object |
| 500 | * function - Passed to _REG: On (1) or Off (0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 501 | * |
| 502 | * RETURN: Status |
| 503 | * |
Bob Moore | 42f8fb7 | 2013-01-11 13:08:51 +0100 | [diff] [blame] | 504 | * DESCRIPTION: Execute _REG method for a region |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 505 | * |
| 506 | ******************************************************************************/ |
| 507 | |
| 508 | acpi_status |
Bob Moore | 42f8fb7 | 2013-01-11 13:08:51 +0100 | [diff] [blame] | 509 | acpi_ev_execute_reg_method(union acpi_operand_object *region_obj, u32 function) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 510 | { |
Bob Moore | 42f8fb7 | 2013-01-11 13:08:51 +0100 | [diff] [blame] | 511 | struct acpi_evaluate_info *info; |
| 512 | union acpi_operand_object *args[3]; |
| 513 | union acpi_operand_object *region_obj2; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 514 | acpi_status status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 515 | |
Bob Moore | 42f8fb7 | 2013-01-11 13:08:51 +0100 | [diff] [blame] | 516 | ACPI_FUNCTION_TRACE(ev_execute_reg_method); |
| 517 | |
| 518 | region_obj2 = acpi_ns_get_secondary_object(region_obj); |
| 519 | if (!region_obj2) { |
| 520 | return_ACPI_STATUS(AE_NOT_EXIST); |
| 521 | } |
| 522 | |
| 523 | if (region_obj2->extra.method_REG == NULL) { |
| 524 | return_ACPI_STATUS(AE_OK); |
| 525 | } |
| 526 | |
| 527 | /* Allocate and initialize the evaluation information block */ |
| 528 | |
| 529 | info = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_evaluate_info)); |
| 530 | if (!info) { |
| 531 | return_ACPI_STATUS(AE_NO_MEMORY); |
| 532 | } |
| 533 | |
| 534 | info->prefix_node = region_obj2->extra.method_REG; |
Bob Moore | 29a241c | 2013-05-30 10:00:01 +0800 | [diff] [blame^] | 535 | info->relative_pathname = NULL; |
Bob Moore | 42f8fb7 | 2013-01-11 13:08:51 +0100 | [diff] [blame] | 536 | info->parameters = args; |
| 537 | info->flags = ACPI_IGNORE_RETURN_VALUE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 538 | |
| 539 | /* |
Bob Moore | 42f8fb7 | 2013-01-11 13:08:51 +0100 | [diff] [blame] | 540 | * The _REG method has two arguments: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 541 | * |
Bob Moore | 42f8fb7 | 2013-01-11 13:08:51 +0100 | [diff] [blame] | 542 | * arg0 - Integer: |
| 543 | * Operation region space ID Same value as region_obj->Region.space_id |
| 544 | * |
| 545 | * arg1 - Integer: |
| 546 | * connection status 1 for connecting the handler, 0 for disconnecting |
| 547 | * the handler (Passed as a parameter) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 548 | */ |
Bob Moore | 42f8fb7 | 2013-01-11 13:08:51 +0100 | [diff] [blame] | 549 | args[0] = |
| 550 | acpi_ut_create_integer_object((u64)region_obj->region.space_id); |
| 551 | if (!args[0]) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 552 | status = AE_NO_MEMORY; |
Bob Moore | 42f8fb7 | 2013-01-11 13:08:51 +0100 | [diff] [blame] | 553 | goto cleanup1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 554 | } |
| 555 | |
Bob Moore | 42f8fb7 | 2013-01-11 13:08:51 +0100 | [diff] [blame] | 556 | args[1] = acpi_ut_create_integer_object((u64)function); |
| 557 | if (!args[1]) { |
| 558 | status = AE_NO_MEMORY; |
| 559 | goto cleanup2; |
| 560 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 561 | |
Bob Moore | 42f8fb7 | 2013-01-11 13:08:51 +0100 | [diff] [blame] | 562 | args[2] = NULL; /* Terminate list */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 563 | |
Bob Moore | 42f8fb7 | 2013-01-11 13:08:51 +0100 | [diff] [blame] | 564 | /* Execute the method, no return value */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 565 | |
Bob Moore | 42f8fb7 | 2013-01-11 13:08:51 +0100 | [diff] [blame] | 566 | ACPI_DEBUG_EXEC(acpi_ut_display_init_pathname |
| 567 | (ACPI_TYPE_METHOD, info->prefix_node, NULL)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 568 | |
Bob Moore | 42f8fb7 | 2013-01-11 13:08:51 +0100 | [diff] [blame] | 569 | status = acpi_ns_evaluate(info); |
| 570 | acpi_ut_remove_reference(args[1]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 571 | |
Bob Moore | 42f8fb7 | 2013-01-11 13:08:51 +0100 | [diff] [blame] | 572 | cleanup2: |
| 573 | acpi_ut_remove_reference(args[0]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 574 | |
Bob Moore | 42f8fb7 | 2013-01-11 13:08:51 +0100 | [diff] [blame] | 575 | cleanup1: |
| 576 | ACPI_FREE(info); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 577 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 578 | } |
| 579 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 580 | /******************************************************************************* |
| 581 | * |
| 582 | * FUNCTION: acpi_ev_execute_reg_methods |
| 583 | * |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 584 | * PARAMETERS: node - Namespace node for the device |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 585 | * space_id - The address space ID |
| 586 | * |
| 587 | * RETURN: Status |
| 588 | * |
| 589 | * DESCRIPTION: Run all _REG methods for the input Space ID; |
| 590 | * Note: assumes namespace is locked, or system init time. |
| 591 | * |
| 592 | ******************************************************************************/ |
| 593 | |
| 594 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 595 | acpi_ev_execute_reg_methods(struct acpi_namespace_node *node, |
| 596 | acpi_adr_space_type space_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 597 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 598 | acpi_status status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 599 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 600 | ACPI_FUNCTION_TRACE(ev_execute_reg_methods); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 601 | |
| 602 | /* |
Bob Moore | 9f15fc6 | 2008-11-12 16:01:56 +0800 | [diff] [blame] | 603 | * Run all _REG methods for all Operation Regions for this space ID. This |
| 604 | * is a separate walk in order to handle any interdependencies between |
| 605 | * regions and _REG methods. (i.e. handlers must be installed for all |
| 606 | * regions of this Space ID before we can run any _REG methods) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 607 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 608 | status = acpi_ns_walk_namespace(ACPI_TYPE_ANY, node, ACPI_UINT32_MAX, |
| 609 | ACPI_NS_WALK_UNLOCK, acpi_ev_reg_run, |
Lin Ming | 2263576 | 2009-11-13 10:06:08 +0800 | [diff] [blame] | 610 | NULL, &space_id, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 611 | |
Bob Moore | e2066ca | 2011-04-13 13:22:04 +0800 | [diff] [blame] | 612 | /* Special case for EC: handle "orphan" _REG methods with no region */ |
| 613 | |
| 614 | if (space_id == ACPI_ADR_SPACE_EC) { |
| 615 | acpi_ev_orphan_ec_reg_method(); |
| 616 | } |
| 617 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 618 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 619 | } |
| 620 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 621 | /******************************************************************************* |
| 622 | * |
| 623 | * FUNCTION: acpi_ev_reg_run |
| 624 | * |
| 625 | * PARAMETERS: walk_namespace callback |
| 626 | * |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 627 | * DESCRIPTION: Run _REG method for region objects of the requested spaceID |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 628 | * |
| 629 | ******************************************************************************/ |
| 630 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 631 | static acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 632 | acpi_ev_reg_run(acpi_handle obj_handle, |
| 633 | u32 level, void *context, void **return_value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 634 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 635 | union acpi_operand_object *obj_desc; |
| 636 | struct acpi_namespace_node *node; |
| 637 | acpi_adr_space_type space_id; |
| 638 | acpi_status status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 639 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 640 | space_id = *ACPI_CAST_PTR(acpi_adr_space_type, context); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 641 | |
| 642 | /* Convert and validate the device handle */ |
| 643 | |
Bob Moore | f24b664 | 2009-12-11 14:57:00 +0800 | [diff] [blame] | 644 | node = acpi_ns_validate_handle(obj_handle); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 645 | if (!node) { |
| 646 | return (AE_BAD_PARAMETER); |
| 647 | } |
| 648 | |
| 649 | /* |
Bob Moore | 9f15fc6 | 2008-11-12 16:01:56 +0800 | [diff] [blame] | 650 | * We only care about regions.and objects that are allowed to have address |
| 651 | * space handlers |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 652 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 653 | if ((node->type != ACPI_TYPE_REGION) && (node != acpi_gbl_root_node)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 654 | return (AE_OK); |
| 655 | } |
| 656 | |
| 657 | /* Check for an existing internal object */ |
| 658 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 659 | obj_desc = acpi_ns_get_attached_object(node); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 660 | if (!obj_desc) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 661 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 662 | /* No object, just exit */ |
| 663 | |
| 664 | return (AE_OK); |
| 665 | } |
| 666 | |
| 667 | /* Object is a Region */ |
| 668 | |
| 669 | if (obj_desc->region.space_id != space_id) { |
Bob Moore | 9f15fc6 | 2008-11-12 16:01:56 +0800 | [diff] [blame] | 670 | |
| 671 | /* This region is for a different address space, just ignore it */ |
| 672 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 673 | return (AE_OK); |
| 674 | } |
| 675 | |
Bob Moore | e2066ca | 2011-04-13 13:22:04 +0800 | [diff] [blame] | 676 | status = acpi_ev_execute_reg_method(obj_desc, ACPI_REG_CONNECT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 677 | return (status); |
| 678 | } |
Bob Moore | e2066ca | 2011-04-13 13:22:04 +0800 | [diff] [blame] | 679 | |
| 680 | /******************************************************************************* |
| 681 | * |
| 682 | * FUNCTION: acpi_ev_orphan_ec_reg_method |
| 683 | * |
| 684 | * PARAMETERS: None |
| 685 | * |
| 686 | * RETURN: None |
| 687 | * |
| 688 | * DESCRIPTION: Execute an "orphan" _REG method that appears under the EC |
| 689 | * device. This is a _REG method that has no corresponding region |
| 690 | * within the EC device scope. The orphan _REG method appears to |
| 691 | * have been enabled by the description of the ECDT in the ACPI |
| 692 | * specification: "The availability of the region space can be |
| 693 | * detected by providing a _REG method object underneath the |
| 694 | * Embedded Controller device." |
| 695 | * |
| 696 | * To quickly access the EC device, we use the EC_ID that appears |
| 697 | * within the ECDT. Otherwise, we would need to perform a time- |
| 698 | * consuming namespace walk, executing _HID methods to find the |
| 699 | * EC device. |
| 700 | * |
| 701 | ******************************************************************************/ |
| 702 | |
| 703 | static void acpi_ev_orphan_ec_reg_method(void) |
| 704 | { |
| 705 | struct acpi_table_ecdt *table; |
| 706 | acpi_status status; |
| 707 | struct acpi_object_list args; |
| 708 | union acpi_object objects[2]; |
| 709 | struct acpi_namespace_node *ec_device_node; |
| 710 | struct acpi_namespace_node *reg_method; |
| 711 | struct acpi_namespace_node *next_node; |
| 712 | |
| 713 | ACPI_FUNCTION_TRACE(ev_orphan_ec_reg_method); |
| 714 | |
| 715 | /* Get the ECDT (if present in system) */ |
| 716 | |
| 717 | status = acpi_get_table(ACPI_SIG_ECDT, 0, |
| 718 | ACPI_CAST_INDIRECT_PTR(struct acpi_table_header, |
| 719 | &table)); |
| 720 | if (ACPI_FAILURE(status)) { |
| 721 | return_VOID; |
| 722 | } |
| 723 | |
| 724 | /* We need a valid EC_ID string */ |
| 725 | |
| 726 | if (!(*table->id)) { |
| 727 | return_VOID; |
| 728 | } |
| 729 | |
| 730 | /* Namespace is currently locked, must release */ |
| 731 | |
| 732 | (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); |
| 733 | |
| 734 | /* Get a handle to the EC device referenced in the ECDT */ |
| 735 | |
| 736 | status = acpi_get_handle(NULL, |
| 737 | ACPI_CAST_PTR(char, table->id), |
| 738 | ACPI_CAST_PTR(acpi_handle, &ec_device_node)); |
| 739 | if (ACPI_FAILURE(status)) { |
| 740 | goto exit; |
| 741 | } |
| 742 | |
| 743 | /* Get a handle to a _REG method immediately under the EC device */ |
| 744 | |
| 745 | status = acpi_get_handle(ec_device_node, |
| 746 | METHOD_NAME__REG, ACPI_CAST_PTR(acpi_handle, |
| 747 | ®_method)); |
| 748 | if (ACPI_FAILURE(status)) { |
| 749 | goto exit; |
| 750 | } |
| 751 | |
| 752 | /* |
| 753 | * Execute the _REG method only if there is no Operation Region in |
| 754 | * this scope with the Embedded Controller space ID. Otherwise, it |
| 755 | * will already have been executed. Note, this allows for Regions |
| 756 | * with other space IDs to be present; but the code below will then |
| 757 | * execute the _REG method with the EC space ID argument. |
| 758 | */ |
| 759 | next_node = acpi_ns_get_next_node(ec_device_node, NULL); |
| 760 | while (next_node) { |
| 761 | if ((next_node->type == ACPI_TYPE_REGION) && |
| 762 | (next_node->object) && |
| 763 | (next_node->object->region.space_id == ACPI_ADR_SPACE_EC)) { |
| 764 | goto exit; /* Do not execute _REG */ |
| 765 | } |
| 766 | next_node = acpi_ns_get_next_node(ec_device_node, next_node); |
| 767 | } |
| 768 | |
| 769 | /* Evaluate the _REG(EC,Connect) method */ |
| 770 | |
| 771 | args.count = 2; |
| 772 | args.pointer = objects; |
| 773 | objects[0].type = ACPI_TYPE_INTEGER; |
| 774 | objects[0].integer.value = ACPI_ADR_SPACE_EC; |
| 775 | objects[1].type = ACPI_TYPE_INTEGER; |
| 776 | objects[1].integer.value = ACPI_REG_CONNECT; |
| 777 | |
| 778 | status = acpi_evaluate_object(reg_method, NULL, &args, NULL); |
| 779 | |
| 780 | exit: |
| 781 | /* We ignore all errors from above, don't care */ |
| 782 | |
| 783 | status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); |
| 784 | return_VOID; |
| 785 | } |