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