Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
| 3 | * Module Name: evregion - ACPI address_space (op_region) handler dispatch |
| 4 | * |
| 5 | *****************************************************************************/ |
| 6 | |
| 7 | /* |
Bob Moore | 4a90c7e | 2006-01-13 16:22:00 -0500 | [diff] [blame] | 8 | * Copyright (C) 2000 - 2006, R. Byron Moore |
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> |
| 45 | #include <acpi/acevents.h> |
| 46 | #include <acpi/acnamesp.h> |
| 47 | #include <acpi/acinterp.h> |
| 48 | |
| 49 | #define _COMPONENT ACPI_EVENTS |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 50 | ACPI_MODULE_NAME("evregion") |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | #define ACPI_NUM_DEFAULT_SPACES 4 |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 52 | static u8 acpi_gbl_default_address_spaces[ACPI_NUM_DEFAULT_SPACES] = { |
| 53 | ACPI_ADR_SPACE_SYSTEM_MEMORY, |
| 54 | ACPI_ADR_SPACE_SYSTEM_IO, |
| 55 | ACPI_ADR_SPACE_PCI_CONFIG, |
| 56 | ACPI_ADR_SPACE_DATA_TABLE |
| 57 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 59 | /* Local prototypes */ |
| 60 | |
| 61 | static acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 62 | acpi_ev_reg_run(acpi_handle obj_handle, |
| 63 | u32 level, void *context, void **return_value); |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 64 | |
| 65 | static acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 66 | acpi_ev_install_handler(acpi_handle obj_handle, |
| 67 | u32 level, void *context, void **return_value); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | |
| 69 | /******************************************************************************* |
| 70 | * |
| 71 | * FUNCTION: acpi_ev_install_region_handlers |
| 72 | * |
| 73 | * PARAMETERS: None |
| 74 | * |
| 75 | * RETURN: Status |
| 76 | * |
| 77 | * DESCRIPTION: Installs the core subsystem default address space handlers. |
| 78 | * |
| 79 | ******************************************************************************/ |
| 80 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 81 | acpi_status acpi_ev_install_region_handlers(void) |
| 82 | { |
| 83 | acpi_status status; |
| 84 | acpi_native_uint i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 86 | ACPI_FUNCTION_TRACE("ev_install_region_handlers"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 88 | status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); |
| 89 | if (ACPI_FAILURE(status)) { |
| 90 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | /* |
| 94 | * All address spaces (PCI Config, EC, SMBus) are scope dependent |
| 95 | * and registration must occur for a specific device. |
| 96 | * |
| 97 | * In the case of the system memory and IO address spaces there is currently |
| 98 | * no device associated with the address space. For these we use the root. |
| 99 | * |
| 100 | * We install the default PCI config space handler at the root so |
| 101 | * that this space is immediately available even though the we have |
| 102 | * not enumerated all the PCI Root Buses yet. This is to conform |
| 103 | * to the ACPI specification which states that the PCI config |
| 104 | * space must be always available -- even though we are nowhere |
| 105 | * near ready to find the PCI root buses at this point. |
| 106 | * |
| 107 | * NOTE: We ignore AE_ALREADY_EXISTS because this means that a handler |
| 108 | * has already been installed (via acpi_install_address_space_handler). |
| 109 | * Similar for AE_SAME_HANDLER. |
| 110 | */ |
| 111 | for (i = 0; i < ACPI_NUM_DEFAULT_SPACES; i++) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 112 | status = acpi_ev_install_space_handler(acpi_gbl_root_node, |
| 113 | acpi_gbl_default_address_spaces |
| 114 | [i], |
| 115 | ACPI_DEFAULT_HANDLER, |
| 116 | NULL, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | switch (status) { |
| 118 | case AE_OK: |
| 119 | case AE_SAME_HANDLER: |
| 120 | case AE_ALREADY_EXISTS: |
| 121 | |
| 122 | /* These exceptions are all OK */ |
| 123 | |
| 124 | status = AE_OK; |
| 125 | break; |
| 126 | |
| 127 | default: |
| 128 | |
| 129 | goto unlock_and_exit; |
| 130 | } |
| 131 | } |
| 132 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 133 | unlock_and_exit: |
| 134 | (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); |
| 135 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | } |
| 137 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | /******************************************************************************* |
| 139 | * |
| 140 | * FUNCTION: acpi_ev_initialize_op_regions |
| 141 | * |
| 142 | * PARAMETERS: None |
| 143 | * |
| 144 | * RETURN: Status |
| 145 | * |
| 146 | * DESCRIPTION: Execute _REG methods for all Operation Regions that have |
| 147 | * an installed default region handler. |
| 148 | * |
| 149 | ******************************************************************************/ |
| 150 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 151 | acpi_status acpi_ev_initialize_op_regions(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 153 | acpi_status status; |
| 154 | acpi_native_uint i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 156 | ACPI_FUNCTION_TRACE("ev_initialize_op_regions"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 158 | status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); |
| 159 | if (ACPI_FAILURE(status)) { |
| 160 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | /* |
| 164 | * Run the _REG methods for op_regions in each default address space |
| 165 | */ |
| 166 | for (i = 0; i < ACPI_NUM_DEFAULT_SPACES; i++) { |
| 167 | /* TBD: Make sure handler is the DEFAULT handler, otherwise |
| 168 | * _REG will have already been run. |
| 169 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 170 | status = acpi_ev_execute_reg_methods(acpi_gbl_root_node, |
| 171 | acpi_gbl_default_address_spaces |
| 172 | [i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | } |
| 174 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 175 | (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); |
| 176 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | } |
| 178 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | /******************************************************************************* |
| 180 | * |
| 181 | * FUNCTION: acpi_ev_execute_reg_method |
| 182 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 183 | * PARAMETERS: region_obj - Region object |
| 184 | * Function - Passed to _REG: On (1) or Off (0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | * |
| 186 | * RETURN: Status |
| 187 | * |
| 188 | * DESCRIPTION: Execute _REG method for a region |
| 189 | * |
| 190 | ******************************************************************************/ |
| 191 | |
| 192 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 193 | 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] | 194 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 195 | struct acpi_parameter_info info; |
| 196 | union acpi_operand_object *params[3]; |
| 197 | union acpi_operand_object *region_obj2; |
| 198 | acpi_status status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 200 | ACPI_FUNCTION_TRACE("ev_execute_reg_method"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 202 | region_obj2 = acpi_ns_get_secondary_object(region_obj); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | if (!region_obj2) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 204 | return_ACPI_STATUS(AE_NOT_EXIST); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | } |
| 206 | |
| 207 | if (region_obj2->extra.method_REG == NULL) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 208 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | /* |
| 212 | * The _REG method has two arguments: |
| 213 | * |
| 214 | * Arg0, Integer: Operation region space ID |
| 215 | * Same value as region_obj->Region.space_id |
| 216 | * Arg1, Integer: connection status |
| 217 | * 1 for connecting the handler, |
| 218 | * 0 for disconnecting the handler |
| 219 | * Passed as a parameter |
| 220 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 221 | params[0] = acpi_ut_create_internal_object(ACPI_TYPE_INTEGER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | if (!params[0]) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 223 | return_ACPI_STATUS(AE_NO_MEMORY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | } |
| 225 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 226 | params[1] = acpi_ut_create_internal_object(ACPI_TYPE_INTEGER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | if (!params[1]) { |
| 228 | status = AE_NO_MEMORY; |
| 229 | goto cleanup; |
| 230 | } |
| 231 | |
| 232 | /* Setup the parameter objects */ |
| 233 | |
| 234 | params[0]->integer.value = region_obj->region.space_id; |
| 235 | params[1]->integer.value = function; |
| 236 | params[2] = NULL; |
| 237 | |
| 238 | info.node = region_obj2->extra.method_REG; |
| 239 | info.parameters = params; |
| 240 | info.parameter_type = ACPI_PARAM_ARGS; |
| 241 | |
| 242 | /* Execute the method, no return value */ |
| 243 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 244 | ACPI_DEBUG_EXEC(acpi_ut_display_init_pathname |
| 245 | (ACPI_TYPE_METHOD, info.node, NULL)); |
| 246 | status = acpi_ns_evaluate_by_handle(&info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 248 | acpi_ut_remove_reference(params[1]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 250 | cleanup: |
| 251 | acpi_ut_remove_reference(params[0]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 253 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | } |
| 255 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | /******************************************************************************* |
| 257 | * |
| 258 | * FUNCTION: acpi_ev_address_space_dispatch |
| 259 | * |
| 260 | * PARAMETERS: region_obj - Internal region object |
| 261 | * Function - Read or Write operation |
| 262 | * Address - Where in the space to read or write |
| 263 | * bit_width - Field width in bits (8, 16, 32, or 64) |
| 264 | * Value - Pointer to in or out value |
| 265 | * |
| 266 | * RETURN: Status |
| 267 | * |
| 268 | * DESCRIPTION: Dispatch an address space or operation region access to |
| 269 | * a previously installed handler. |
| 270 | * |
| 271 | ******************************************************************************/ |
| 272 | |
| 273 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 274 | acpi_ev_address_space_dispatch(union acpi_operand_object *region_obj, |
| 275 | u32 function, |
| 276 | acpi_physical_address address, |
| 277 | u32 bit_width, void *value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 279 | acpi_status status; |
| 280 | acpi_status status2; |
| 281 | acpi_adr_space_handler handler; |
| 282 | acpi_adr_space_setup region_setup; |
| 283 | union acpi_operand_object *handler_desc; |
| 284 | union acpi_operand_object *region_obj2; |
| 285 | void *region_context = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 287 | ACPI_FUNCTION_TRACE("ev_address_space_dispatch"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 289 | region_obj2 = acpi_ns_get_secondary_object(region_obj); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | if (!region_obj2) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 291 | return_ACPI_STATUS(AE_NOT_EXIST); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | } |
| 293 | |
| 294 | /* Ensure that there is a handler associated with this region */ |
| 295 | |
| 296 | handler_desc = region_obj->region.handler; |
| 297 | if (!handler_desc) { |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 298 | ACPI_ERROR((AE_INFO, |
| 299 | "No handler for Region [%4.4s] (%p) [%s]", |
| 300 | acpi_ut_get_node_name(region_obj->region.node), |
| 301 | region_obj, |
| 302 | acpi_ut_get_region_name(region_obj->region. |
| 303 | space_id))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 305 | return_ACPI_STATUS(AE_NOT_EXIST); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | } |
| 307 | |
| 308 | /* |
| 309 | * It may be the case that the region has never been initialized |
| 310 | * Some types of regions require special init code |
| 311 | */ |
| 312 | if (!(region_obj->region.flags & AOPOBJ_SETUP_COMPLETE)) { |
| 313 | /* |
| 314 | * This region has not been initialized yet, do it |
| 315 | */ |
| 316 | region_setup = handler_desc->address_space.setup; |
| 317 | if (!region_setup) { |
| 318 | /* No initialization routine, exit with error */ |
| 319 | |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 320 | ACPI_ERROR((AE_INFO, |
| 321 | "No init routine for region(%p) [%s]", |
| 322 | region_obj, |
| 323 | acpi_ut_get_region_name(region_obj->region. |
| 324 | space_id))); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 325 | return_ACPI_STATUS(AE_NOT_EXIST); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | } |
| 327 | |
| 328 | /* |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 329 | * We must exit the interpreter because the region |
| 330 | * setup will potentially execute control methods |
| 331 | * (e.g., _REG method for this region) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 333 | acpi_ex_exit_interpreter(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 335 | status = region_setup(region_obj, ACPI_REGION_ACTIVATE, |
| 336 | handler_desc->address_space.context, |
| 337 | ®ion_context); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | |
| 339 | /* Re-enter the interpreter */ |
| 340 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 341 | status2 = acpi_ex_enter_interpreter(); |
| 342 | if (ACPI_FAILURE(status2)) { |
| 343 | return_ACPI_STATUS(status2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | } |
| 345 | |
| 346 | /* Check for failure of the Region Setup */ |
| 347 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 348 | if (ACPI_FAILURE(status)) { |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 349 | ACPI_EXCEPTION((AE_INFO, status, |
| 350 | "During region initialization: [%s]", |
| 351 | acpi_ut_get_region_name(region_obj-> |
| 352 | region. |
| 353 | space_id))); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 354 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | } |
| 356 | |
| 357 | /* |
| 358 | * Region initialization may have been completed by region_setup |
| 359 | */ |
| 360 | if (!(region_obj->region.flags & AOPOBJ_SETUP_COMPLETE)) { |
| 361 | region_obj->region.flags |= AOPOBJ_SETUP_COMPLETE; |
| 362 | |
| 363 | if (region_obj2->extra.region_context) { |
| 364 | /* The handler for this region was already installed */ |
| 365 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 366 | ACPI_MEM_FREE(region_context); |
| 367 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | /* |
| 369 | * Save the returned context for use in all accesses to |
| 370 | * this particular region |
| 371 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 372 | region_obj2->extra.region_context = |
| 373 | region_context; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | } |
| 375 | } |
| 376 | } |
| 377 | |
| 378 | /* We have everything we need, we can invoke the address space handler */ |
| 379 | |
| 380 | handler = handler_desc->address_space.handler; |
| 381 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 382 | ACPI_DEBUG_PRINT((ACPI_DB_OPREGION, |
| 383 | "Handler %p (@%p) Address %8.8X%8.8X [%s]\n", |
| 384 | ®ion_obj->region.handler->address_space, handler, |
| 385 | ACPI_FORMAT_UINT64(address), |
| 386 | acpi_ut_get_region_name(region_obj->region. |
| 387 | space_id))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 388 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 389 | if (! |
| 390 | (handler_desc->address_space. |
| 391 | hflags & ACPI_ADDR_HANDLER_DEFAULT_INSTALLED)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | /* |
| 393 | * For handlers other than the default (supplied) handlers, we must |
| 394 | * exit the interpreter because the handler *might* block -- we don't |
| 395 | * know what it will do, so we can't hold the lock on the intepreter. |
| 396 | */ |
| 397 | acpi_ex_exit_interpreter(); |
| 398 | } |
| 399 | |
| 400 | /* Call the handler */ |
| 401 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 402 | status = handler(function, address, bit_width, value, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | handler_desc->address_space.context, |
| 404 | region_obj2->extra.region_context); |
| 405 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 406 | if (ACPI_FAILURE(status)) { |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 407 | ACPI_EXCEPTION((AE_INFO, status, "Returned by Handler for [%s]", |
| 408 | acpi_ut_get_region_name(region_obj->region. |
| 409 | space_id))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | } |
| 411 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 412 | if (! |
| 413 | (handler_desc->address_space. |
| 414 | hflags & ACPI_ADDR_HANDLER_DEFAULT_INSTALLED)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | /* |
| 416 | * We just returned from a non-default handler, we must re-enter the |
| 417 | * interpreter |
| 418 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 419 | status2 = acpi_ex_enter_interpreter(); |
| 420 | if (ACPI_FAILURE(status2)) { |
| 421 | return_ACPI_STATUS(status2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 | } |
| 423 | } |
| 424 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 425 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | } |
| 427 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | /******************************************************************************* |
| 429 | * |
| 430 | * FUNCTION: acpi_ev_detach_region |
| 431 | * |
| 432 | * PARAMETERS: region_obj - Region Object |
| 433 | * acpi_ns_is_locked - Namespace Region Already Locked? |
| 434 | * |
| 435 | * RETURN: None |
| 436 | * |
| 437 | * DESCRIPTION: Break the association between the handler and the region |
| 438 | * this is a two way association. |
| 439 | * |
| 440 | ******************************************************************************/ |
| 441 | |
| 442 | void |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 443 | acpi_ev_detach_region(union acpi_operand_object *region_obj, |
| 444 | u8 acpi_ns_is_locked) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 445 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 446 | union acpi_operand_object *handler_obj; |
| 447 | union acpi_operand_object *obj_desc; |
| 448 | union acpi_operand_object **last_obj_ptr; |
| 449 | acpi_adr_space_setup region_setup; |
| 450 | void **region_context; |
| 451 | union acpi_operand_object *region_obj2; |
| 452 | acpi_status status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 453 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 454 | ACPI_FUNCTION_TRACE("ev_detach_region"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 456 | region_obj2 = acpi_ns_get_secondary_object(region_obj); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | if (!region_obj2) { |
| 458 | return_VOID; |
| 459 | } |
| 460 | region_context = ®ion_obj2->extra.region_context; |
| 461 | |
| 462 | /* Get the address handler from the region object */ |
| 463 | |
| 464 | handler_obj = region_obj->region.handler; |
| 465 | if (!handler_obj) { |
| 466 | /* This region has no handler, all done */ |
| 467 | |
| 468 | return_VOID; |
| 469 | } |
| 470 | |
| 471 | /* Find this region in the handler's list */ |
| 472 | |
| 473 | obj_desc = handler_obj->address_space.region_list; |
| 474 | last_obj_ptr = &handler_obj->address_space.region_list; |
| 475 | |
| 476 | while (obj_desc) { |
| 477 | /* Is this the correct Region? */ |
| 478 | |
| 479 | if (obj_desc == region_obj) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 480 | ACPI_DEBUG_PRINT((ACPI_DB_OPREGION, |
| 481 | "Removing Region %p from address handler %p\n", |
| 482 | region_obj, handler_obj)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 | |
| 484 | /* This is it, remove it from the handler's list */ |
| 485 | |
| 486 | *last_obj_ptr = obj_desc->region.next; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 487 | obj_desc->region.next = NULL; /* Must clear field */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 488 | |
| 489 | if (acpi_ns_is_locked) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 490 | status = |
| 491 | acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); |
| 492 | if (ACPI_FAILURE(status)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 493 | return_VOID; |
| 494 | } |
| 495 | } |
| 496 | |
| 497 | /* Now stop region accesses by executing the _REG method */ |
| 498 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 499 | status = acpi_ev_execute_reg_method(region_obj, 0); |
| 500 | if (ACPI_FAILURE(status)) { |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 501 | ACPI_EXCEPTION((AE_INFO, status, |
| 502 | "from region _REG, [%s]", |
| 503 | acpi_ut_get_region_name |
| 504 | (region_obj->region.space_id))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 505 | } |
| 506 | |
| 507 | if (acpi_ns_is_locked) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 508 | status = |
| 509 | acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); |
| 510 | if (ACPI_FAILURE(status)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 511 | return_VOID; |
| 512 | } |
| 513 | } |
| 514 | |
| 515 | /* Call the setup handler with the deactivate notification */ |
| 516 | |
| 517 | region_setup = handler_obj->address_space.setup; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 518 | status = |
| 519 | region_setup(region_obj, ACPI_REGION_DEACTIVATE, |
| 520 | handler_obj->address_space.context, |
| 521 | region_context); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 522 | |
| 523 | /* Init routine may fail, Just ignore errors */ |
| 524 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 525 | if (ACPI_FAILURE(status)) { |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 526 | ACPI_EXCEPTION((AE_INFO, status, |
| 527 | "from region init, [%s]", |
| 528 | acpi_ut_get_region_name |
| 529 | (region_obj->region.space_id))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 530 | } |
| 531 | |
| 532 | region_obj->region.flags &= ~(AOPOBJ_SETUP_COMPLETE); |
| 533 | |
| 534 | /* |
| 535 | * Remove handler reference in the region |
| 536 | * |
| 537 | * NOTE: this doesn't mean that the region goes away |
| 538 | * The region is just inaccessible as indicated to |
| 539 | * the _REG method |
| 540 | * |
| 541 | * If the region is on the handler's list |
| 542 | * this better be the region's handler |
| 543 | */ |
| 544 | region_obj->region.handler = NULL; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 545 | acpi_ut_remove_reference(handler_obj); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 546 | |
| 547 | return_VOID; |
| 548 | } |
| 549 | |
| 550 | /* Walk the linked list of handlers */ |
| 551 | |
| 552 | last_obj_ptr = &obj_desc->region.next; |
| 553 | obj_desc = obj_desc->region.next; |
| 554 | } |
| 555 | |
| 556 | /* If we get here, the region was not in the handler's region list */ |
| 557 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 558 | ACPI_DEBUG_PRINT((ACPI_DB_OPREGION, |
| 559 | "Cannot remove region %p from address handler %p\n", |
| 560 | region_obj, handler_obj)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 561 | |
| 562 | return_VOID; |
| 563 | } |
| 564 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 565 | /******************************************************************************* |
| 566 | * |
| 567 | * FUNCTION: acpi_ev_attach_region |
| 568 | * |
| 569 | * PARAMETERS: handler_obj - Handler Object |
| 570 | * region_obj - Region Object |
| 571 | * acpi_ns_is_locked - Namespace Region Already Locked? |
| 572 | * |
| 573 | * RETURN: None |
| 574 | * |
| 575 | * DESCRIPTION: Create the association between the handler and the region |
| 576 | * this is a two way association. |
| 577 | * |
| 578 | ******************************************************************************/ |
| 579 | |
| 580 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 581 | acpi_ev_attach_region(union acpi_operand_object *handler_obj, |
| 582 | union acpi_operand_object *region_obj, |
| 583 | u8 acpi_ns_is_locked) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 584 | { |
| 585 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 586 | ACPI_FUNCTION_TRACE("ev_attach_region"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 587 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 588 | ACPI_DEBUG_PRINT((ACPI_DB_OPREGION, |
| 589 | "Adding Region [%4.4s] %p to address handler %p [%s]\n", |
| 590 | acpi_ut_get_node_name(region_obj->region.node), |
| 591 | region_obj, handler_obj, |
| 592 | acpi_ut_get_region_name(region_obj->region. |
| 593 | space_id))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 594 | |
| 595 | /* Link this region to the front of the handler's list */ |
| 596 | |
| 597 | region_obj->region.next = handler_obj->address_space.region_list; |
| 598 | handler_obj->address_space.region_list = region_obj; |
| 599 | |
| 600 | /* Install the region's handler */ |
| 601 | |
| 602 | if (region_obj->region.handler) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 603 | return_ACPI_STATUS(AE_ALREADY_EXISTS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 604 | } |
| 605 | |
| 606 | region_obj->region.handler = handler_obj; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 607 | acpi_ut_add_reference(handler_obj); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 608 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 609 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 610 | } |
| 611 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 612 | /******************************************************************************* |
| 613 | * |
| 614 | * FUNCTION: acpi_ev_install_handler |
| 615 | * |
| 616 | * PARAMETERS: walk_namespace callback |
| 617 | * |
| 618 | * DESCRIPTION: This routine installs an address handler into objects that are |
| 619 | * of type Region or Device. |
| 620 | * |
| 621 | * If the Object is a Device, and the device has a handler of |
| 622 | * the same type then the search is terminated in that branch. |
| 623 | * |
| 624 | * This is because the existing handler is closer in proximity |
| 625 | * to any more regions than the one we are trying to install. |
| 626 | * |
| 627 | ******************************************************************************/ |
| 628 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 629 | static acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 630 | acpi_ev_install_handler(acpi_handle obj_handle, |
| 631 | u32 level, void *context, void **return_value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 632 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 633 | union acpi_operand_object *handler_obj; |
| 634 | union acpi_operand_object *next_handler_obj; |
| 635 | union acpi_operand_object *obj_desc; |
| 636 | struct acpi_namespace_node *node; |
| 637 | acpi_status status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 638 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 639 | ACPI_FUNCTION_NAME("ev_install_handler"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 640 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 641 | handler_obj = (union acpi_operand_object *)context; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 642 | |
| 643 | /* Parameter validation */ |
| 644 | |
| 645 | if (!handler_obj) { |
| 646 | return (AE_OK); |
| 647 | } |
| 648 | |
| 649 | /* Convert and validate the device handle */ |
| 650 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 651 | node = acpi_ns_map_handle_to_node(obj_handle); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 652 | if (!node) { |
| 653 | return (AE_BAD_PARAMETER); |
| 654 | } |
| 655 | |
| 656 | /* |
| 657 | * We only care about regions.and objects |
| 658 | * that are allowed to have address space handlers |
| 659 | */ |
| 660 | if ((node->type != ACPI_TYPE_DEVICE) && |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 661 | (node->type != ACPI_TYPE_REGION) && (node != acpi_gbl_root_node)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 662 | return (AE_OK); |
| 663 | } |
| 664 | |
| 665 | /* Check for an existing internal object */ |
| 666 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 667 | obj_desc = acpi_ns_get_attached_object(node); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 668 | if (!obj_desc) { |
| 669 | /* No object, just exit */ |
| 670 | |
| 671 | return (AE_OK); |
| 672 | } |
| 673 | |
| 674 | /* Devices are handled different than regions */ |
| 675 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 676 | if (ACPI_GET_OBJECT_TYPE(obj_desc) == ACPI_TYPE_DEVICE) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 677 | /* Check if this Device already has a handler for this address space */ |
| 678 | |
| 679 | next_handler_obj = obj_desc->device.handler; |
| 680 | while (next_handler_obj) { |
| 681 | /* Found a handler, is it for the same address space? */ |
| 682 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 683 | if (next_handler_obj->address_space.space_id == |
| 684 | handler_obj->address_space.space_id) { |
| 685 | ACPI_DEBUG_PRINT((ACPI_DB_OPREGION, |
| 686 | "Found handler for region [%s] in device %p(%p) handler %p\n", |
| 687 | acpi_ut_get_region_name |
| 688 | (handler_obj->address_space. |
| 689 | space_id), obj_desc, |
| 690 | next_handler_obj, |
| 691 | handler_obj)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 692 | |
| 693 | /* |
| 694 | * Since the object we found it on was a device, then it |
| 695 | * means that someone has already installed a handler for |
| 696 | * the branch of the namespace from this device on. Just |
| 697 | * bail out telling the walk routine to not traverse this |
| 698 | * branch. This preserves the scoping rule for handlers. |
| 699 | */ |
| 700 | return (AE_CTRL_DEPTH); |
| 701 | } |
| 702 | |
| 703 | /* Walk the linked list of handlers attached to this device */ |
| 704 | |
| 705 | next_handler_obj = next_handler_obj->address_space.next; |
| 706 | } |
| 707 | |
| 708 | /* |
| 709 | * As long as the device didn't have a handler for this |
| 710 | * space we don't care about it. We just ignore it and |
| 711 | * proceed. |
| 712 | */ |
| 713 | return (AE_OK); |
| 714 | } |
| 715 | |
| 716 | /* Object is a Region */ |
| 717 | |
| 718 | if (obj_desc->region.space_id != handler_obj->address_space.space_id) { |
| 719 | /* |
| 720 | * This region is for a different address space |
| 721 | * -- just ignore it |
| 722 | */ |
| 723 | return (AE_OK); |
| 724 | } |
| 725 | |
| 726 | /* |
| 727 | * Now we have a region and it is for the handler's address |
| 728 | * space type. |
| 729 | * |
| 730 | * First disconnect region for any previous handler (if any) |
| 731 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 732 | acpi_ev_detach_region(obj_desc, FALSE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 733 | |
| 734 | /* Connect the region to the new handler */ |
| 735 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 736 | status = acpi_ev_attach_region(handler_obj, obj_desc, FALSE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 737 | return (status); |
| 738 | } |
| 739 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 740 | /******************************************************************************* |
| 741 | * |
| 742 | * FUNCTION: acpi_ev_install_space_handler |
| 743 | * |
| 744 | * PARAMETERS: Node - Namespace node for the device |
| 745 | * space_id - The address space ID |
| 746 | * Handler - Address of the handler |
| 747 | * Setup - Address of the setup function |
| 748 | * Context - Value passed to the handler on each access |
| 749 | * |
| 750 | * RETURN: Status |
| 751 | * |
| 752 | * DESCRIPTION: Install a handler for all op_regions of a given space_id. |
| 753 | * Assumes namespace is locked |
| 754 | * |
| 755 | ******************************************************************************/ |
| 756 | |
| 757 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 758 | acpi_ev_install_space_handler(struct acpi_namespace_node * node, |
| 759 | acpi_adr_space_type space_id, |
| 760 | acpi_adr_space_handler handler, |
| 761 | acpi_adr_space_setup setup, void *context) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 762 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 763 | union acpi_operand_object *obj_desc; |
| 764 | union acpi_operand_object *handler_obj; |
| 765 | acpi_status status; |
| 766 | acpi_object_type type; |
| 767 | u16 flags = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 768 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 769 | ACPI_FUNCTION_TRACE("ev_install_space_handler"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 770 | |
| 771 | /* |
| 772 | * This registration is valid for only the types below |
| 773 | * and the root. This is where the default handlers |
| 774 | * get placed. |
| 775 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 776 | if ((node->type != ACPI_TYPE_DEVICE) && |
| 777 | (node->type != ACPI_TYPE_PROCESSOR) && |
| 778 | (node->type != ACPI_TYPE_THERMAL) && (node != acpi_gbl_root_node)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 779 | status = AE_BAD_PARAMETER; |
| 780 | goto unlock_and_exit; |
| 781 | } |
| 782 | |
| 783 | if (handler == ACPI_DEFAULT_HANDLER) { |
| 784 | flags = ACPI_ADDR_HANDLER_DEFAULT_INSTALLED; |
| 785 | |
| 786 | switch (space_id) { |
| 787 | case ACPI_ADR_SPACE_SYSTEM_MEMORY: |
| 788 | handler = acpi_ex_system_memory_space_handler; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 789 | setup = acpi_ev_system_memory_region_setup; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 790 | break; |
| 791 | |
| 792 | case ACPI_ADR_SPACE_SYSTEM_IO: |
| 793 | handler = acpi_ex_system_io_space_handler; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 794 | setup = acpi_ev_io_space_region_setup; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 795 | break; |
| 796 | |
| 797 | case ACPI_ADR_SPACE_PCI_CONFIG: |
| 798 | handler = acpi_ex_pci_config_space_handler; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 799 | setup = acpi_ev_pci_config_region_setup; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 800 | break; |
| 801 | |
| 802 | case ACPI_ADR_SPACE_CMOS: |
| 803 | handler = acpi_ex_cmos_space_handler; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 804 | setup = acpi_ev_cmos_region_setup; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 805 | break; |
| 806 | |
| 807 | case ACPI_ADR_SPACE_PCI_BAR_TARGET: |
| 808 | handler = acpi_ex_pci_bar_space_handler; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 809 | setup = acpi_ev_pci_bar_region_setup; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 810 | break; |
| 811 | |
| 812 | case ACPI_ADR_SPACE_DATA_TABLE: |
| 813 | handler = acpi_ex_data_table_space_handler; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 814 | setup = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 815 | break; |
| 816 | |
| 817 | default: |
| 818 | status = AE_BAD_PARAMETER; |
| 819 | goto unlock_and_exit; |
| 820 | } |
| 821 | } |
| 822 | |
| 823 | /* If the caller hasn't specified a setup routine, use the default */ |
| 824 | |
| 825 | if (!setup) { |
| 826 | setup = acpi_ev_default_region_setup; |
| 827 | } |
| 828 | |
| 829 | /* Check for an existing internal object */ |
| 830 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 831 | obj_desc = acpi_ns_get_attached_object(node); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 832 | if (obj_desc) { |
| 833 | /* |
| 834 | * The attached device object already exists. |
| 835 | * Make sure the handler is not already installed. |
| 836 | */ |
| 837 | handler_obj = obj_desc->device.handler; |
| 838 | |
| 839 | /* Walk the handler list for this device */ |
| 840 | |
| 841 | while (handler_obj) { |
| 842 | /* Same space_id indicates a handler already installed */ |
| 843 | |
| 844 | if (handler_obj->address_space.space_id == space_id) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 845 | if (handler_obj->address_space.handler == |
| 846 | handler) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 847 | /* |
| 848 | * It is (relatively) OK to attempt to install the SAME |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 849 | * handler twice. This can easily happen |
| 850 | * with PCI_Config space. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 851 | */ |
| 852 | status = AE_SAME_HANDLER; |
| 853 | goto unlock_and_exit; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 854 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 855 | /* A handler is already installed */ |
| 856 | |
| 857 | status = AE_ALREADY_EXISTS; |
| 858 | } |
| 859 | goto unlock_and_exit; |
| 860 | } |
| 861 | |
| 862 | /* Walk the linked list of handlers */ |
| 863 | |
| 864 | handler_obj = handler_obj->address_space.next; |
| 865 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 866 | } else { |
| 867 | ACPI_DEBUG_PRINT((ACPI_DB_OPREGION, |
| 868 | "Creating object on Device %p while installing handler\n", |
| 869 | node)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 870 | |
| 871 | /* obj_desc does not exist, create one */ |
| 872 | |
| 873 | if (node->type == ACPI_TYPE_ANY) { |
| 874 | type = ACPI_TYPE_DEVICE; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 875 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 876 | type = node->type; |
| 877 | } |
| 878 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 879 | obj_desc = acpi_ut_create_internal_object(type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 880 | if (!obj_desc) { |
| 881 | status = AE_NO_MEMORY; |
| 882 | goto unlock_and_exit; |
| 883 | } |
| 884 | |
| 885 | /* Init new descriptor */ |
| 886 | |
| 887 | obj_desc->common.type = (u8) type; |
| 888 | |
| 889 | /* Attach the new object to the Node */ |
| 890 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 891 | status = acpi_ns_attach_object(node, obj_desc, type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 892 | |
| 893 | /* Remove local reference to the object */ |
| 894 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 895 | acpi_ut_remove_reference(obj_desc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 896 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 897 | if (ACPI_FAILURE(status)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 898 | goto unlock_and_exit; |
| 899 | } |
| 900 | } |
| 901 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 902 | ACPI_DEBUG_PRINT((ACPI_DB_OPREGION, |
| 903 | "Installing address handler for region %s(%X) on Device %4.4s %p(%p)\n", |
| 904 | acpi_ut_get_region_name(space_id), space_id, |
| 905 | acpi_ut_get_node_name(node), node, obj_desc)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 906 | |
| 907 | /* |
| 908 | * Install the handler |
| 909 | * |
| 910 | * At this point there is no existing handler. |
| 911 | * Just allocate the object for the handler and link it |
| 912 | * into the list. |
| 913 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 914 | handler_obj = |
| 915 | acpi_ut_create_internal_object(ACPI_TYPE_LOCAL_ADDRESS_HANDLER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 916 | if (!handler_obj) { |
| 917 | status = AE_NO_MEMORY; |
| 918 | goto unlock_and_exit; |
| 919 | } |
| 920 | |
| 921 | /* Init handler obj */ |
| 922 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 923 | handler_obj->address_space.space_id = (u8) space_id; |
| 924 | handler_obj->address_space.hflags = flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 925 | handler_obj->address_space.region_list = NULL; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 926 | handler_obj->address_space.node = node; |
| 927 | handler_obj->address_space.handler = handler; |
| 928 | handler_obj->address_space.context = context; |
| 929 | handler_obj->address_space.setup = setup; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 930 | |
| 931 | /* Install at head of Device.address_space list */ |
| 932 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 933 | handler_obj->address_space.next = obj_desc->device.handler; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 934 | |
| 935 | /* |
| 936 | * The Device object is the first reference on the handler_obj. |
| 937 | * Each region that uses the handler adds a reference. |
| 938 | */ |
| 939 | obj_desc->device.handler = handler_obj; |
| 940 | |
| 941 | /* |
| 942 | * Walk the namespace finding all of the regions this |
| 943 | * handler will manage. |
| 944 | * |
| 945 | * Start at the device and search the branch toward |
| 946 | * the leaf nodes until either the leaf is encountered or |
| 947 | * a device is detected that has an address handler of the |
| 948 | * same type. |
| 949 | * |
| 950 | * In either case, back up and search down the remainder |
| 951 | * of the branch |
| 952 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 953 | status = acpi_ns_walk_namespace(ACPI_TYPE_ANY, node, ACPI_UINT32_MAX, |
| 954 | ACPI_NS_WALK_UNLOCK, |
| 955 | acpi_ev_install_handler, handler_obj, |
| 956 | NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 957 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 958 | unlock_and_exit: |
| 959 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 960 | } |
| 961 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 962 | /******************************************************************************* |
| 963 | * |
| 964 | * FUNCTION: acpi_ev_execute_reg_methods |
| 965 | * |
| 966 | * PARAMETERS: Node - Namespace node for the device |
| 967 | * space_id - The address space ID |
| 968 | * |
| 969 | * RETURN: Status |
| 970 | * |
| 971 | * DESCRIPTION: Run all _REG methods for the input Space ID; |
| 972 | * Note: assumes namespace is locked, or system init time. |
| 973 | * |
| 974 | ******************************************************************************/ |
| 975 | |
| 976 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 977 | acpi_ev_execute_reg_methods(struct acpi_namespace_node *node, |
| 978 | acpi_adr_space_type space_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 979 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 980 | acpi_status status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 981 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 982 | ACPI_FUNCTION_TRACE("ev_execute_reg_methods"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 983 | |
| 984 | /* |
| 985 | * Run all _REG methods for all Operation Regions for this |
| 986 | * space ID. This is a separate walk in order to handle any |
| 987 | * interdependencies between regions and _REG methods. (i.e. handlers |
| 988 | * must be installed for all regions of this Space ID before we |
| 989 | * can run any _REG methods) |
| 990 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 991 | status = acpi_ns_walk_namespace(ACPI_TYPE_ANY, node, ACPI_UINT32_MAX, |
| 992 | ACPI_NS_WALK_UNLOCK, acpi_ev_reg_run, |
| 993 | &space_id, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 994 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 995 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 996 | } |
| 997 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 998 | /******************************************************************************* |
| 999 | * |
| 1000 | * FUNCTION: acpi_ev_reg_run |
| 1001 | * |
| 1002 | * PARAMETERS: walk_namespace callback |
| 1003 | * |
| 1004 | * DESCRIPTION: Run _REg method for region objects of the requested space_iD |
| 1005 | * |
| 1006 | ******************************************************************************/ |
| 1007 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 1008 | static acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1009 | acpi_ev_reg_run(acpi_handle obj_handle, |
| 1010 | u32 level, void *context, void **return_value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1011 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1012 | union acpi_operand_object *obj_desc; |
| 1013 | struct acpi_namespace_node *node; |
| 1014 | acpi_adr_space_type space_id; |
| 1015 | acpi_status status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1016 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1017 | space_id = *ACPI_CAST_PTR(acpi_adr_space_type, context); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1018 | |
| 1019 | /* Convert and validate the device handle */ |
| 1020 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1021 | node = acpi_ns_map_handle_to_node(obj_handle); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1022 | if (!node) { |
| 1023 | return (AE_BAD_PARAMETER); |
| 1024 | } |
| 1025 | |
| 1026 | /* |
| 1027 | * We only care about regions.and objects |
| 1028 | * that are allowed to have address space handlers |
| 1029 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1030 | if ((node->type != ACPI_TYPE_REGION) && (node != acpi_gbl_root_node)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1031 | return (AE_OK); |
| 1032 | } |
| 1033 | |
| 1034 | /* Check for an existing internal object */ |
| 1035 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1036 | obj_desc = acpi_ns_get_attached_object(node); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1037 | if (!obj_desc) { |
| 1038 | /* No object, just exit */ |
| 1039 | |
| 1040 | return (AE_OK); |
| 1041 | } |
| 1042 | |
| 1043 | /* Object is a Region */ |
| 1044 | |
| 1045 | if (obj_desc->region.space_id != space_id) { |
| 1046 | /* |
| 1047 | * This region is for a different address space |
| 1048 | * -- just ignore it |
| 1049 | */ |
| 1050 | return (AE_OK); |
| 1051 | } |
| 1052 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1053 | status = acpi_ev_execute_reg_method(obj_desc, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1054 | return (status); |
| 1055 | } |