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