Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
| 3 | * Module Name: evrgnini- ACPI address_space (op_region) init |
| 4 | * |
| 5 | *****************************************************************************/ |
| 6 | |
| 7 | /* |
| 8 | * Copyright (C) 2000 - 2005, R. Byron Moore |
| 9 | * All rights reserved. |
| 10 | * |
| 11 | * Redistribution and use in source and binary forms, with or without |
| 12 | * modification, are permitted provided that the following conditions |
| 13 | * are met: |
| 14 | * 1. Redistributions of source code must retain the above copyright |
| 15 | * notice, this list of conditions, and the following disclaimer, |
| 16 | * without modification. |
| 17 | * 2. Redistributions in binary form must reproduce at minimum a disclaimer |
| 18 | * substantially similar to the "NO WARRANTY" disclaimer below |
| 19 | * ("Disclaimer") and any redistribution must be conditioned upon |
| 20 | * including a substantially similar Disclaimer requirement for further |
| 21 | * binary redistribution. |
| 22 | * 3. Neither the names of the above-listed copyright holders nor the names |
| 23 | * of any contributors may be used to endorse or promote products derived |
| 24 | * from this software without specific prior written permission. |
| 25 | * |
| 26 | * Alternatively, this software may be distributed under the terms of the |
| 27 | * GNU General Public License ("GPL") version 2 as published by the Free |
| 28 | * Software Foundation. |
| 29 | * |
| 30 | * NO WARRANTY |
| 31 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 32 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 33 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR |
| 34 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 35 | * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 36 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 37 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 38 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
| 39 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING |
| 40 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 41 | * POSSIBILITY OF SUCH DAMAGES. |
| 42 | */ |
| 43 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | #include <acpi/acpi.h> |
| 45 | #include <acpi/acevents.h> |
| 46 | #include <acpi/acnamesp.h> |
| 47 | |
| 48 | #define _COMPONENT ACPI_EVENTS |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 49 | ACPI_MODULE_NAME("evrgnini") |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | |
| 51 | /******************************************************************************* |
| 52 | * |
| 53 | * FUNCTION: acpi_ev_system_memory_region_setup |
| 54 | * |
| 55 | * PARAMETERS: Handle - Region we are interested in |
| 56 | * Function - Start or stop |
| 57 | * handler_context - Address space handler context |
| 58 | * region_context - Region specific context |
| 59 | * |
| 60 | * RETURN: Status |
| 61 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 62 | * DESCRIPTION: Setup a system_memory operation region |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | * |
| 64 | ******************************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 66 | acpi_ev_system_memory_region_setup(acpi_handle handle, |
| 67 | u32 function, |
| 68 | void *handler_context, void **region_context) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 70 | union acpi_operand_object *region_desc = |
| 71 | (union acpi_operand_object *)handle; |
| 72 | struct acpi_mem_space_context *local_region_context; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 74 | ACPI_FUNCTION_TRACE("ev_system_memory_region_setup"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | |
| 76 | if (function == ACPI_REGION_DEACTIVATE) { |
| 77 | if (*region_context) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 78 | ACPI_MEM_FREE(*region_context); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | *region_context = NULL; |
| 80 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 81 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | /* Create a new context */ |
| 85 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 86 | local_region_context = |
| 87 | ACPI_MEM_CALLOCATE(sizeof(struct acpi_mem_space_context)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | if (!(local_region_context)) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 89 | return_ACPI_STATUS(AE_NO_MEMORY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | /* Save the region length and address for use in the handler */ |
| 93 | |
| 94 | local_region_context->length = region_desc->region.length; |
| 95 | local_region_context->address = region_desc->region.address; |
| 96 | |
| 97 | *region_context = local_region_context; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 98 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | } |
| 100 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | /******************************************************************************* |
| 102 | * |
| 103 | * FUNCTION: acpi_ev_io_space_region_setup |
| 104 | * |
| 105 | * PARAMETERS: Handle - Region we are interested in |
| 106 | * Function - Start or stop |
| 107 | * handler_context - Address space handler context |
| 108 | * region_context - Region specific context |
| 109 | * |
| 110 | * RETURN: Status |
| 111 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 112 | * DESCRIPTION: Setup a IO operation region |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | * |
| 114 | ******************************************************************************/ |
| 115 | |
| 116 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 117 | acpi_ev_io_space_region_setup(acpi_handle handle, |
| 118 | u32 function, |
| 119 | void *handler_context, void **region_context) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 121 | ACPI_FUNCTION_TRACE("ev_io_space_region_setup"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | |
| 123 | if (function == ACPI_REGION_DEACTIVATE) { |
| 124 | *region_context = NULL; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 125 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | *region_context = handler_context; |
| 127 | } |
| 128 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 129 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | } |
| 131 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | /******************************************************************************* |
| 133 | * |
| 134 | * FUNCTION: acpi_ev_pci_config_region_setup |
| 135 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 136 | * PARAMETERS: Handle - Region we are interested in |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | * Function - Start or stop |
| 138 | * handler_context - Address space handler context |
| 139 | * region_context - Region specific context |
| 140 | * |
| 141 | * RETURN: Status |
| 142 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 143 | * DESCRIPTION: Setup a PCI_Config operation region |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | * |
| 145 | * MUTEX: Assumes namespace is not locked |
| 146 | * |
| 147 | ******************************************************************************/ |
| 148 | |
| 149 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 150 | acpi_ev_pci_config_region_setup(acpi_handle handle, |
| 151 | u32 function, |
| 152 | void *handler_context, void **region_context) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 154 | acpi_status status = AE_OK; |
| 155 | acpi_integer pci_value; |
| 156 | struct acpi_pci_id *pci_id = *region_context; |
| 157 | union acpi_operand_object *handler_obj; |
| 158 | struct acpi_namespace_node *parent_node; |
| 159 | struct acpi_namespace_node *pci_root_node; |
| 160 | union acpi_operand_object *region_obj = |
| 161 | (union acpi_operand_object *)handle; |
| 162 | struct acpi_device_id object_hID; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 164 | ACPI_FUNCTION_TRACE("ev_pci_config_region_setup"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | |
| 166 | handler_obj = region_obj->region.handler; |
| 167 | if (!handler_obj) { |
| 168 | /* |
| 169 | * No installed handler. This shouldn't happen because the dispatch |
| 170 | * routine checks before we get here, but we check again just in case. |
| 171 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 172 | ACPI_DEBUG_PRINT((ACPI_DB_OPREGION, |
| 173 | "Attempting to init a region %p, with no handler\n", |
| 174 | region_obj)); |
| 175 | return_ACPI_STATUS(AE_NOT_EXIST); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | *region_context = NULL; |
| 179 | if (function == ACPI_REGION_DEACTIVATE) { |
| 180 | if (pci_id) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 181 | ACPI_MEM_FREE(pci_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 183 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | } |
| 185 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 186 | parent_node = acpi_ns_get_parent_node(region_obj->region.node); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | |
| 188 | /* |
| 189 | * Get the _SEG and _BBN values from the device upon which the handler |
| 190 | * is installed. |
| 191 | * |
| 192 | * We need to get the _SEG and _BBN objects relative to the PCI BUS device. |
| 193 | * This is the device the handler has been registered to handle. |
| 194 | */ |
| 195 | |
| 196 | /* |
| 197 | * If the address_space.Node is still pointing to the root, we need |
| 198 | * to scan upward for a PCI Root bridge and re-associate the op_region |
| 199 | * handlers with that device. |
| 200 | */ |
| 201 | if (handler_obj->address_space.node == acpi_gbl_root_node) { |
| 202 | /* Start search from the parent object */ |
| 203 | |
| 204 | pci_root_node = parent_node; |
| 205 | while (pci_root_node != acpi_gbl_root_node) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 206 | status = |
| 207 | acpi_ut_execute_HID(pci_root_node, &object_hID); |
| 208 | if (ACPI_SUCCESS(status)) { |
Robert Moore | 6f42ccf | 2005-05-13 00:00:00 -0400 | [diff] [blame] | 209 | /* |
| 210 | * Got a valid _HID string, check if this is a PCI root. |
| 211 | * New for ACPI 3.0: check for a PCI Express root also. |
| 212 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 213 | if (! |
| 214 | (ACPI_STRNCMP |
| 215 | (object_hID.value, PCI_ROOT_HID_STRING, |
| 216 | sizeof(PCI_ROOT_HID_STRING)) |
| 217 | || |
| 218 | !(ACPI_STRNCMP |
| 219 | (object_hID.value, |
| 220 | PCI_EXPRESS_ROOT_HID_STRING, |
| 221 | sizeof(PCI_EXPRESS_ROOT_HID_STRING))))) |
| 222 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | /* Install a handler for this PCI root bridge */ |
| 224 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 225 | status = |
| 226 | acpi_install_address_space_handler((acpi_handle) pci_root_node, ACPI_ADR_SPACE_PCI_CONFIG, ACPI_DEFAULT_HANDLER, NULL, NULL); |
| 227 | if (ACPI_FAILURE(status)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | if (status == AE_SAME_HANDLER) { |
| 229 | /* |
| 230 | * It is OK if the handler is already installed on the root |
| 231 | * bridge. Still need to return a context object for the |
| 232 | * new PCI_Config operation region, however. |
| 233 | */ |
| 234 | status = AE_OK; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 235 | } else { |
| 236 | ACPI_REPORT_ERROR(("Could not install pci_config handler for Root Bridge %4.4s, %s\n", acpi_ut_get_node_name(pci_root_node), acpi_format_exception(status))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | } |
| 238 | } |
| 239 | break; |
| 240 | } |
| 241 | } |
| 242 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 243 | pci_root_node = acpi_ns_get_parent_node(pci_root_node); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | } |
| 245 | |
| 246 | /* PCI root bridge not found, use namespace root node */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 247 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | pci_root_node = handler_obj->address_space.node; |
| 249 | } |
| 250 | |
| 251 | /* |
| 252 | * If this region is now initialized, we are done. |
| 253 | * (install_address_space_handler could have initialized it) |
| 254 | */ |
| 255 | if (region_obj->region.flags & AOPOBJ_SETUP_COMPLETE) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 256 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | } |
| 258 | |
| 259 | /* Region is still not initialized. Create a new context */ |
| 260 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 261 | pci_id = ACPI_MEM_CALLOCATE(sizeof(struct acpi_pci_id)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | if (!pci_id) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 263 | return_ACPI_STATUS(AE_NO_MEMORY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | } |
| 265 | |
| 266 | /* |
| 267 | * For PCI_Config space access, we need the segment, bus, |
| 268 | * device and function numbers. Acquire them here. |
| 269 | */ |
| 270 | |
| 271 | /* |
| 272 | * Get the PCI device and function numbers from the _ADR object |
| 273 | * contained in the parent's scope. |
| 274 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 275 | status = |
| 276 | acpi_ut_evaluate_numeric_object(METHOD_NAME__ADR, parent_node, |
| 277 | &pci_value); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | |
| 279 | /* |
| 280 | * The default is zero, and since the allocation above zeroed |
| 281 | * the data, just do nothing on failure. |
| 282 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 283 | if (ACPI_SUCCESS(status)) { |
| 284 | pci_id->device = ACPI_HIWORD(ACPI_LODWORD(pci_value)); |
| 285 | pci_id->function = ACPI_LOWORD(ACPI_LODWORD(pci_value)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | } |
| 287 | |
| 288 | /* The PCI segment number comes from the _SEG method */ |
| 289 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 290 | status = |
| 291 | acpi_ut_evaluate_numeric_object(METHOD_NAME__SEG, pci_root_node, |
| 292 | &pci_value); |
| 293 | if (ACPI_SUCCESS(status)) { |
| 294 | pci_id->segment = ACPI_LOWORD(pci_value); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | } |
| 296 | |
| 297 | /* The PCI bus number comes from the _BBN method */ |
| 298 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 299 | status = |
| 300 | acpi_ut_evaluate_numeric_object(METHOD_NAME__BBN, pci_root_node, |
| 301 | &pci_value); |
| 302 | if (ACPI_SUCCESS(status)) { |
| 303 | pci_id->bus = ACPI_LOWORD(pci_value); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | } |
| 305 | |
| 306 | /* Complete this device's pci_id */ |
| 307 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 308 | acpi_os_derive_pci_id(pci_root_node, region_obj->region.node, &pci_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | |
| 310 | *region_context = pci_id; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 311 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | } |
| 313 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | /******************************************************************************* |
| 315 | * |
| 316 | * FUNCTION: acpi_ev_pci_bar_region_setup |
| 317 | * |
| 318 | * PARAMETERS: Handle - Region we are interested in |
| 319 | * Function - Start or stop |
| 320 | * handler_context - Address space handler context |
| 321 | * region_context - Region specific context |
| 322 | * |
| 323 | * RETURN: Status |
| 324 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 325 | * DESCRIPTION: Setup a pci_bAR operation region |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | * |
| 327 | * MUTEX: Assumes namespace is not locked |
| 328 | * |
| 329 | ******************************************************************************/ |
| 330 | |
| 331 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 332 | acpi_ev_pci_bar_region_setup(acpi_handle handle, |
| 333 | u32 function, |
| 334 | void *handler_context, void **region_context) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 336 | ACPI_FUNCTION_TRACE("ev_pci_bar_region_setup"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 338 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | } |
| 340 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | /******************************************************************************* |
| 342 | * |
| 343 | * FUNCTION: acpi_ev_cmos_region_setup |
| 344 | * |
| 345 | * PARAMETERS: Handle - Region we are interested in |
| 346 | * Function - Start or stop |
| 347 | * handler_context - Address space handler context |
| 348 | * region_context - Region specific context |
| 349 | * |
| 350 | * RETURN: Status |
| 351 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 352 | * DESCRIPTION: Setup a CMOS operation region |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | * |
| 354 | * MUTEX: Assumes namespace is not locked |
| 355 | * |
| 356 | ******************************************************************************/ |
| 357 | |
| 358 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 359 | acpi_ev_cmos_region_setup(acpi_handle handle, |
| 360 | u32 function, |
| 361 | void *handler_context, void **region_context) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 363 | ACPI_FUNCTION_TRACE("ev_cmos_region_setup"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 365 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | } |
| 367 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | /******************************************************************************* |
| 369 | * |
| 370 | * FUNCTION: acpi_ev_default_region_setup |
| 371 | * |
| 372 | * PARAMETERS: Handle - Region we are interested in |
| 373 | * Function - Start or stop |
| 374 | * handler_context - Address space handler context |
| 375 | * region_context - Region specific context |
| 376 | * |
| 377 | * RETURN: Status |
| 378 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 379 | * DESCRIPTION: Default region initialization |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 380 | * |
| 381 | ******************************************************************************/ |
| 382 | |
| 383 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 384 | acpi_ev_default_region_setup(acpi_handle handle, |
| 385 | u32 function, |
| 386 | void *handler_context, void **region_context) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 388 | ACPI_FUNCTION_TRACE("ev_default_region_setup"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | |
| 390 | if (function == ACPI_REGION_DEACTIVATE) { |
| 391 | *region_context = NULL; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 392 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | *region_context = handler_context; |
| 394 | } |
| 395 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 396 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | } |
| 398 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | /******************************************************************************* |
| 400 | * |
| 401 | * FUNCTION: acpi_ev_initialize_region |
| 402 | * |
| 403 | * PARAMETERS: region_obj - Region we are initializing |
| 404 | * acpi_ns_locked - Is namespace locked? |
| 405 | * |
| 406 | * RETURN: Status |
| 407 | * |
| 408 | * DESCRIPTION: Initializes the region, finds any _REG methods and saves them |
| 409 | * for execution at a later time |
| 410 | * |
| 411 | * Get the appropriate address space handler for a newly |
| 412 | * created region. |
| 413 | * |
| 414 | * This also performs address space specific initialization. For |
| 415 | * example, PCI regions must have an _ADR object that contains |
| 416 | * a PCI address in the scope of the definition. This address is |
| 417 | * required to perform an access to PCI config space. |
| 418 | * |
| 419 | ******************************************************************************/ |
| 420 | |
| 421 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 422 | acpi_ev_initialize_region(union acpi_operand_object *region_obj, |
| 423 | u8 acpi_ns_locked) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 424 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 425 | union acpi_operand_object *handler_obj; |
| 426 | union acpi_operand_object *obj_desc; |
| 427 | acpi_adr_space_type space_id; |
| 428 | struct acpi_namespace_node *node; |
| 429 | acpi_status status; |
| 430 | struct acpi_namespace_node *method_node; |
| 431 | acpi_name *reg_name_ptr = (acpi_name *) METHOD_NAME__REG; |
| 432 | union acpi_operand_object *region_obj2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 434 | ACPI_FUNCTION_TRACE_U32("ev_initialize_region", acpi_ns_locked); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | |
| 436 | if (!region_obj) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 437 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 | } |
| 439 | |
| 440 | if (region_obj->common.flags & AOPOBJ_OBJECT_INITIALIZED) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 441 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 442 | } |
| 443 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 444 | region_obj2 = acpi_ns_get_secondary_object(region_obj); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 445 | if (!region_obj2) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 446 | return_ACPI_STATUS(AE_NOT_EXIST); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 447 | } |
| 448 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 449 | node = acpi_ns_get_parent_node(region_obj->region.node); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 450 | space_id = region_obj->region.space_id; |
| 451 | |
| 452 | /* Setup defaults */ |
| 453 | |
| 454 | region_obj->region.handler = NULL; |
| 455 | region_obj2->extra.method_REG = NULL; |
| 456 | region_obj->common.flags &= ~(AOPOBJ_SETUP_COMPLETE); |
| 457 | region_obj->common.flags |= AOPOBJ_OBJECT_INITIALIZED; |
| 458 | |
| 459 | /* Find any "_REG" method associated with this region definition */ |
| 460 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 461 | status = acpi_ns_search_node(*reg_name_ptr, node, |
| 462 | ACPI_TYPE_METHOD, &method_node); |
| 463 | if (ACPI_SUCCESS(status)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 464 | /* |
| 465 | * The _REG method is optional and there can be only one per region |
| 466 | * definition. This will be executed when the handler is attached |
| 467 | * or removed |
| 468 | */ |
| 469 | region_obj2->extra.method_REG = method_node; |
| 470 | } |
| 471 | |
| 472 | /* |
| 473 | * The following loop depends upon the root Node having no parent |
| 474 | * ie: acpi_gbl_root_node->parent_entry being set to NULL |
| 475 | */ |
| 476 | while (node) { |
| 477 | /* Check to see if a handler exists */ |
| 478 | |
| 479 | handler_obj = NULL; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 480 | obj_desc = acpi_ns_get_attached_object(node); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 481 | if (obj_desc) { |
| 482 | /* Can only be a handler if the object exists */ |
| 483 | |
| 484 | switch (node->type) { |
| 485 | case ACPI_TYPE_DEVICE: |
| 486 | |
| 487 | handler_obj = obj_desc->device.handler; |
| 488 | break; |
| 489 | |
| 490 | case ACPI_TYPE_PROCESSOR: |
| 491 | |
| 492 | handler_obj = obj_desc->processor.handler; |
| 493 | break; |
| 494 | |
| 495 | case ACPI_TYPE_THERMAL: |
| 496 | |
| 497 | handler_obj = obj_desc->thermal_zone.handler; |
| 498 | break; |
| 499 | |
| 500 | default: |
| 501 | /* Ignore other objects */ |
| 502 | break; |
| 503 | } |
| 504 | |
| 505 | while (handler_obj) { |
| 506 | /* Is this handler of the correct type? */ |
| 507 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 508 | if (handler_obj->address_space.space_id == |
| 509 | space_id) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 510 | /* Found correct handler */ |
| 511 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 512 | ACPI_DEBUG_PRINT((ACPI_DB_OPREGION, |
| 513 | "Found handler %p for region %p in obj %p\n", |
| 514 | handler_obj, |
| 515 | region_obj, |
| 516 | obj_desc)); |
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 | status = |
| 519 | acpi_ev_attach_region(handler_obj, |
| 520 | region_obj, |
| 521 | acpi_ns_locked); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 522 | |
| 523 | /* |
| 524 | * Tell all users that this region is usable by running the _REG |
| 525 | * method |
| 526 | */ |
| 527 | if (acpi_ns_locked) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 528 | status = |
| 529 | acpi_ut_release_mutex |
| 530 | (ACPI_MTX_NAMESPACE); |
| 531 | if (ACPI_FAILURE(status)) { |
| 532 | return_ACPI_STATUS |
| 533 | (status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 534 | } |
| 535 | } |
| 536 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 537 | status = |
| 538 | acpi_ev_execute_reg_method |
| 539 | (region_obj, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 540 | |
| 541 | if (acpi_ns_locked) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 542 | status = |
| 543 | acpi_ut_acquire_mutex |
| 544 | (ACPI_MTX_NAMESPACE); |
| 545 | if (ACPI_FAILURE(status)) { |
| 546 | return_ACPI_STATUS |
| 547 | (status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 548 | } |
| 549 | } |
| 550 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 551 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 552 | } |
| 553 | |
| 554 | /* Try next handler in the list */ |
| 555 | |
| 556 | handler_obj = handler_obj->address_space.next; |
| 557 | } |
| 558 | } |
| 559 | |
| 560 | /* |
| 561 | * This node does not have the handler we need; |
| 562 | * Pop up one level |
| 563 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 564 | node = acpi_ns_get_parent_node(node); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 565 | } |
| 566 | |
| 567 | /* If we get here, there is no handler for this region */ |
| 568 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 569 | ACPI_DEBUG_PRINT((ACPI_DB_OPREGION, |
| 570 | "No handler for region_type %s(%X) (region_obj %p)\n", |
| 571 | acpi_ut_get_region_name(space_id), space_id, |
| 572 | region_obj)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 573 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame^] | 574 | return_ACPI_STATUS(AE_NOT_EXIST); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 575 | } |