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