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