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