blob: 203d1359190af2c8d52f694f506eda23d75de4bd [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/******************************************************************************
2 *
3 * Module Name: evrgnini- ACPI address_space (op_region) init
4 *
5 *****************************************************************************/
6
7/*
Bob Moore4a90c7e2006-01-13 16:22:00 -05008 * Copyright (C) 2000 - 2006, R. Byron Moore
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 * 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 Torvalds1da177e2005-04-16 15:20:36 -070044#include <acpi/acpi.h>
45#include <acpi/acevents.h>
46#include <acpi/acnamesp.h>
47
48#define _COMPONENT ACPI_EVENTS
Len Brown4be44fc2005-08-05 00:44:28 -040049ACPI_MODULE_NAME("evrgnini")
Linus Torvalds1da177e2005-04-16 15:20:36 -070050
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 Moore44f6c012005-04-18 22:49:35 -040062 * DESCRIPTION: Setup a system_memory operation region
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 *
64 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -070065acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -040066acpi_ev_system_memory_region_setup(acpi_handle handle,
67 u32 function,
68 void *handler_context, void **region_context)
Linus Torvalds1da177e2005-04-16 15:20:36 -070069{
Len Brown4be44fc2005-08-05 00:44:28 -040070 union acpi_operand_object *region_desc =
71 (union acpi_operand_object *)handle;
72 struct acpi_mem_space_context *local_region_context;
Linus Torvalds1da177e2005-04-16 15:20:36 -070073
Bob Mooreb229cf92006-04-21 17:15:00 -040074 ACPI_FUNCTION_TRACE(ev_system_memory_region_setup);
Linus Torvalds1da177e2005-04-16 15:20:36 -070075
76 if (function == ACPI_REGION_DEACTIVATE) {
77 if (*region_context) {
Bob Moore793c2382006-03-31 00:00:00 -050078 local_region_context =
79 (struct acpi_mem_space_context *)*region_context;
80
81 /* Delete a cached mapping if present */
82
83 if (local_region_context->mapped_length) {
84 acpi_os_unmap_memory(local_region_context->
85 mapped_logical_address,
86 local_region_context->
87 mapped_length);
88 }
89 ACPI_FREE(local_region_context);
Linus Torvalds1da177e2005-04-16 15:20:36 -070090 *region_context = NULL;
91 }
Len Brown4be44fc2005-08-05 00:44:28 -040092 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -070093 }
94
95 /* Create a new context */
96
Len Brown4be44fc2005-08-05 00:44:28 -040097 local_region_context =
Bob Moore83135242006-10-03 00:00:00 -040098 ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_mem_space_context));
Linus Torvalds1da177e2005-04-16 15:20:36 -070099 if (!(local_region_context)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400100 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101 }
102
103 /* Save the region length and address for use in the handler */
104
105 local_region_context->length = region_desc->region.length;
106 local_region_context->address = region_desc->region.address;
107
108 *region_context = local_region_context;
Len Brown4be44fc2005-08-05 00:44:28 -0400109 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110}
111
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112/*******************************************************************************
113 *
114 * FUNCTION: acpi_ev_io_space_region_setup
115 *
116 * PARAMETERS: Handle - Region we are interested in
117 * Function - Start or stop
118 * handler_context - Address space handler context
119 * region_context - Region specific context
120 *
121 * RETURN: Status
122 *
Robert Moore44f6c012005-04-18 22:49:35 -0400123 * DESCRIPTION: Setup a IO operation region
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 *
125 ******************************************************************************/
126
127acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400128acpi_ev_io_space_region_setup(acpi_handle handle,
129 u32 function,
130 void *handler_context, void **region_context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131{
Bob Mooreb229cf92006-04-21 17:15:00 -0400132 ACPI_FUNCTION_TRACE(ev_io_space_region_setup);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133
134 if (function == ACPI_REGION_DEACTIVATE) {
135 *region_context = NULL;
Len Brown4be44fc2005-08-05 00:44:28 -0400136 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 *region_context = handler_context;
138 }
139
Len Brown4be44fc2005-08-05 00:44:28 -0400140 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141}
142
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143/*******************************************************************************
144 *
145 * FUNCTION: acpi_ev_pci_config_region_setup
146 *
Robert Moore44f6c012005-04-18 22:49:35 -0400147 * PARAMETERS: Handle - Region we are interested in
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148 * Function - Start or stop
149 * handler_context - Address space handler context
150 * region_context - Region specific context
151 *
152 * RETURN: Status
153 *
Robert Moore44f6c012005-04-18 22:49:35 -0400154 * DESCRIPTION: Setup a PCI_Config operation region
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155 *
156 * MUTEX: Assumes namespace is not locked
157 *
158 ******************************************************************************/
159
160acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400161acpi_ev_pci_config_region_setup(acpi_handle handle,
162 u32 function,
163 void *handler_context, void **region_context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164{
Len Brown4be44fc2005-08-05 00:44:28 -0400165 acpi_status status = AE_OK;
166 acpi_integer pci_value;
167 struct acpi_pci_id *pci_id = *region_context;
168 union acpi_operand_object *handler_obj;
169 struct acpi_namespace_node *parent_node;
170 struct acpi_namespace_node *pci_root_node;
171 union acpi_operand_object *region_obj =
172 (union acpi_operand_object *)handle;
173 struct acpi_device_id object_hID;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174
Bob Mooreb229cf92006-04-21 17:15:00 -0400175 ACPI_FUNCTION_TRACE(ev_pci_config_region_setup);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176
177 handler_obj = region_obj->region.handler;
178 if (!handler_obj) {
179 /*
180 * No installed handler. This shouldn't happen because the dispatch
181 * routine checks before we get here, but we check again just in case.
182 */
Len Brown4be44fc2005-08-05 00:44:28 -0400183 ACPI_DEBUG_PRINT((ACPI_DB_OPREGION,
184 "Attempting to init a region %p, with no handler\n",
185 region_obj));
186 return_ACPI_STATUS(AE_NOT_EXIST);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187 }
188
189 *region_context = NULL;
190 if (function == ACPI_REGION_DEACTIVATE) {
191 if (pci_id) {
Bob Moore83135242006-10-03 00:00:00 -0400192 ACPI_FREE(pci_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193 }
Len Brown4be44fc2005-08-05 00:44:28 -0400194 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195 }
196
Len Brown4be44fc2005-08-05 00:44:28 -0400197 parent_node = acpi_ns_get_parent_node(region_obj->region.node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198
199 /*
200 * Get the _SEG and _BBN values from the device upon which the handler
201 * is installed.
202 *
203 * We need to get the _SEG and _BBN objects relative to the PCI BUS device.
204 * This is the device the handler has been registered to handle.
205 */
206
207 /*
208 * If the address_space.Node is still pointing to the root, we need
209 * to scan upward for a PCI Root bridge and re-associate the op_region
210 * handlers with that device.
211 */
212 if (handler_obj->address_space.node == acpi_gbl_root_node) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400213
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214 /* Start search from the parent object */
215
216 pci_root_node = parent_node;
217 while (pci_root_node != acpi_gbl_root_node) {
Len Brown4be44fc2005-08-05 00:44:28 -0400218 status =
219 acpi_ut_execute_HID(pci_root_node, &object_hID);
220 if (ACPI_SUCCESS(status)) {
Robert Moore6f42ccf2005-05-13 00:00:00 -0400221 /*
222 * Got a valid _HID string, check if this is a PCI root.
223 * New for ACPI 3.0: check for a PCI Express root also.
224 */
Len Brown4be44fc2005-08-05 00:44:28 -0400225 if (!
226 (ACPI_STRNCMP
227 (object_hID.value, PCI_ROOT_HID_STRING,
Eiichiro Oiwaaeb11042006-10-02 19:18:03 +0400228 sizeof(PCI_ROOT_HID_STRING)))
229 ||
230 !(ACPI_STRNCMP
231 (object_hID.value,
232 PCI_EXPRESS_ROOT_HID_STRING,
233 sizeof(PCI_EXPRESS_ROOT_HID_STRING)))) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400234
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235 /* Install a handler for this PCI root bridge */
236
Len Brown4be44fc2005-08-05 00:44:28 -0400237 status =
238 acpi_install_address_space_handler((acpi_handle) pci_root_node, ACPI_ADR_SPACE_PCI_CONFIG, ACPI_DEFAULT_HANDLER, NULL, NULL);
239 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240 if (status == AE_SAME_HANDLER) {
241 /*
242 * It is OK if the handler is already installed on the root
243 * bridge. Still need to return a context object for the
244 * new PCI_Config operation region, however.
245 */
246 status = AE_OK;
Len Brown4be44fc2005-08-05 00:44:28 -0400247 } else {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500248 ACPI_EXCEPTION((AE_INFO,
249 status,
Bob Mooreb229cf92006-04-21 17:15:00 -0400250 "Could not install PciConfig handler for Root Bridge %4.4s",
Bob Mooreb8e4d892006-01-27 16:43:00 -0500251 acpi_ut_get_node_name
252 (pci_root_node)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253 }
254 }
255 break;
256 }
257 }
258
Len Brown4be44fc2005-08-05 00:44:28 -0400259 pci_root_node = acpi_ns_get_parent_node(pci_root_node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260 }
261
262 /* PCI root bridge not found, use namespace root node */
Len Brown4be44fc2005-08-05 00:44:28 -0400263 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 pci_root_node = handler_obj->address_space.node;
265 }
266
267 /*
268 * If this region is now initialized, we are done.
269 * (install_address_space_handler could have initialized it)
270 */
271 if (region_obj->region.flags & AOPOBJ_SETUP_COMPLETE) {
Len Brown4be44fc2005-08-05 00:44:28 -0400272 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 }
274
275 /* Region is still not initialized. Create a new context */
276
Bob Moore83135242006-10-03 00:00:00 -0400277 pci_id = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_pci_id));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278 if (!pci_id) {
Len Brown4be44fc2005-08-05 00:44:28 -0400279 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280 }
281
282 /*
283 * For PCI_Config space access, we need the segment, bus,
284 * device and function numbers. Acquire them here.
285 */
286
287 /*
288 * Get the PCI device and function numbers from the _ADR object
289 * contained in the parent's scope.
290 */
Len Brown4be44fc2005-08-05 00:44:28 -0400291 status =
292 acpi_ut_evaluate_numeric_object(METHOD_NAME__ADR, parent_node,
293 &pci_value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294
295 /*
296 * The default is zero, and since the allocation above zeroed
297 * the data, just do nothing on failure.
298 */
Len Brown4be44fc2005-08-05 00:44:28 -0400299 if (ACPI_SUCCESS(status)) {
300 pci_id->device = ACPI_HIWORD(ACPI_LODWORD(pci_value));
301 pci_id->function = ACPI_LOWORD(ACPI_LODWORD(pci_value));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302 }
303
304 /* The PCI segment number comes from the _SEG method */
305
Len Brown4be44fc2005-08-05 00:44:28 -0400306 status =
307 acpi_ut_evaluate_numeric_object(METHOD_NAME__SEG, pci_root_node,
308 &pci_value);
309 if (ACPI_SUCCESS(status)) {
310 pci_id->segment = ACPI_LOWORD(pci_value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311 }
312
313 /* The PCI bus number comes from the _BBN method */
314
Len Brown4be44fc2005-08-05 00:44:28 -0400315 status =
316 acpi_ut_evaluate_numeric_object(METHOD_NAME__BBN, pci_root_node,
317 &pci_value);
318 if (ACPI_SUCCESS(status)) {
319 pci_id->bus = ACPI_LOWORD(pci_value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320 }
321
322 /* Complete this device's pci_id */
323
Len Brown4be44fc2005-08-05 00:44:28 -0400324 acpi_os_derive_pci_id(pci_root_node, region_obj->region.node, &pci_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325
326 *region_context = pci_id;
Len Brown4be44fc2005-08-05 00:44:28 -0400327 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328}
329
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330/*******************************************************************************
331 *
332 * FUNCTION: acpi_ev_pci_bar_region_setup
333 *
334 * PARAMETERS: Handle - Region we are interested in
335 * Function - Start or stop
336 * handler_context - Address space handler context
337 * region_context - Region specific context
338 *
339 * RETURN: Status
340 *
Robert Moore44f6c012005-04-18 22:49:35 -0400341 * DESCRIPTION: Setup a pci_bAR operation region
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342 *
343 * MUTEX: Assumes namespace is not locked
344 *
345 ******************************************************************************/
346
347acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400348acpi_ev_pci_bar_region_setup(acpi_handle handle,
349 u32 function,
350 void *handler_context, void **region_context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351{
Bob Mooreb229cf92006-04-21 17:15:00 -0400352 ACPI_FUNCTION_TRACE(ev_pci_bar_region_setup);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353
Len Brown4be44fc2005-08-05 00:44:28 -0400354 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355}
356
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357/*******************************************************************************
358 *
359 * FUNCTION: acpi_ev_cmos_region_setup
360 *
361 * PARAMETERS: Handle - Region we are interested in
362 * Function - Start or stop
363 * handler_context - Address space handler context
364 * region_context - Region specific context
365 *
366 * RETURN: Status
367 *
Robert Moore44f6c012005-04-18 22:49:35 -0400368 * DESCRIPTION: Setup a CMOS operation region
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369 *
370 * MUTEX: Assumes namespace is not locked
371 *
372 ******************************************************************************/
373
374acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400375acpi_ev_cmos_region_setup(acpi_handle handle,
376 u32 function,
377 void *handler_context, void **region_context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378{
Bob Mooreb229cf92006-04-21 17:15:00 -0400379 ACPI_FUNCTION_TRACE(ev_cmos_region_setup);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380
Len Brown4be44fc2005-08-05 00:44:28 -0400381 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382}
383
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384/*******************************************************************************
385 *
386 * FUNCTION: acpi_ev_default_region_setup
387 *
388 * PARAMETERS: Handle - Region we are interested in
389 * Function - Start or stop
390 * handler_context - Address space handler context
391 * region_context - Region specific context
392 *
393 * RETURN: Status
394 *
Robert Moore44f6c012005-04-18 22:49:35 -0400395 * DESCRIPTION: Default region initialization
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396 *
397 ******************************************************************************/
398
399acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400400acpi_ev_default_region_setup(acpi_handle handle,
401 u32 function,
402 void *handler_context, void **region_context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403{
Bob Mooreb229cf92006-04-21 17:15:00 -0400404 ACPI_FUNCTION_TRACE(ev_default_region_setup);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405
406 if (function == ACPI_REGION_DEACTIVATE) {
407 *region_context = NULL;
Len Brown4be44fc2005-08-05 00:44:28 -0400408 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409 *region_context = handler_context;
410 }
411
Len Brown4be44fc2005-08-05 00:44:28 -0400412 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413}
414
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415/*******************************************************************************
416 *
417 * FUNCTION: acpi_ev_initialize_region
418 *
419 * PARAMETERS: region_obj - Region we are initializing
420 * acpi_ns_locked - Is namespace locked?
421 *
422 * RETURN: Status
423 *
424 * DESCRIPTION: Initializes the region, finds any _REG methods and saves them
425 * for execution at a later time
426 *
427 * Get the appropriate address space handler for a newly
428 * created region.
429 *
430 * This also performs address space specific initialization. For
431 * example, PCI regions must have an _ADR object that contains
432 * a PCI address in the scope of the definition. This address is
433 * required to perform an access to PCI config space.
434 *
435 ******************************************************************************/
436
437acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400438acpi_ev_initialize_region(union acpi_operand_object *region_obj,
439 u8 acpi_ns_locked)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440{
Len Brown4be44fc2005-08-05 00:44:28 -0400441 union acpi_operand_object *handler_obj;
442 union acpi_operand_object *obj_desc;
443 acpi_adr_space_type space_id;
444 struct acpi_namespace_node *node;
445 acpi_status status;
446 struct acpi_namespace_node *method_node;
447 acpi_name *reg_name_ptr = (acpi_name *) METHOD_NAME__REG;
448 union acpi_operand_object *region_obj2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449
Bob Mooreb229cf92006-04-21 17:15:00 -0400450 ACPI_FUNCTION_TRACE_U32(ev_initialize_region, acpi_ns_locked);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451
452 if (!region_obj) {
Len Brown4be44fc2005-08-05 00:44:28 -0400453 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454 }
455
456 if (region_obj->common.flags & AOPOBJ_OBJECT_INITIALIZED) {
Len Brown4be44fc2005-08-05 00:44:28 -0400457 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458 }
459
Len Brown4be44fc2005-08-05 00:44:28 -0400460 region_obj2 = acpi_ns_get_secondary_object(region_obj);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461 if (!region_obj2) {
Len Brown4be44fc2005-08-05 00:44:28 -0400462 return_ACPI_STATUS(AE_NOT_EXIST);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463 }
464
Len Brown4be44fc2005-08-05 00:44:28 -0400465 node = acpi_ns_get_parent_node(region_obj->region.node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466 space_id = region_obj->region.space_id;
467
468 /* Setup defaults */
469
470 region_obj->region.handler = NULL;
471 region_obj2->extra.method_REG = NULL;
472 region_obj->common.flags &= ~(AOPOBJ_SETUP_COMPLETE);
473 region_obj->common.flags |= AOPOBJ_OBJECT_INITIALIZED;
474
475 /* Find any "_REG" method associated with this region definition */
476
Bob Moore41195322006-05-26 16:36:00 -0400477 status =
478 acpi_ns_search_one_scope(*reg_name_ptr, node, ACPI_TYPE_METHOD,
479 &method_node);
Len Brown4be44fc2005-08-05 00:44:28 -0400480 if (ACPI_SUCCESS(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481 /*
482 * The _REG method is optional and there can be only one per region
483 * definition. This will be executed when the handler is attached
484 * or removed
485 */
486 region_obj2->extra.method_REG = method_node;
487 }
488
489 /*
490 * The following loop depends upon the root Node having no parent
491 * ie: acpi_gbl_root_node->parent_entry being set to NULL
492 */
493 while (node) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400494
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495 /* Check to see if a handler exists */
496
497 handler_obj = NULL;
Len Brown4be44fc2005-08-05 00:44:28 -0400498 obj_desc = acpi_ns_get_attached_object(node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499 if (obj_desc) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400500
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 /* Can only be a handler if the object exists */
502
503 switch (node->type) {
504 case ACPI_TYPE_DEVICE:
505
506 handler_obj = obj_desc->device.handler;
507 break;
508
509 case ACPI_TYPE_PROCESSOR:
510
511 handler_obj = obj_desc->processor.handler;
512 break;
513
514 case ACPI_TYPE_THERMAL:
515
516 handler_obj = obj_desc->thermal_zone.handler;
517 break;
518
519 default:
520 /* Ignore other objects */
521 break;
522 }
523
524 while (handler_obj) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400525
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 /* Is this handler of the correct type? */
527
Len Brown4be44fc2005-08-05 00:44:28 -0400528 if (handler_obj->address_space.space_id ==
529 space_id) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400530
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 /* Found correct handler */
532
Len Brown4be44fc2005-08-05 00:44:28 -0400533 ACPI_DEBUG_PRINT((ACPI_DB_OPREGION,
534 "Found handler %p for region %p in obj %p\n",
535 handler_obj,
536 region_obj,
537 obj_desc));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538
Len Brown4be44fc2005-08-05 00:44:28 -0400539 status =
540 acpi_ev_attach_region(handler_obj,
541 region_obj,
542 acpi_ns_locked);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543
544 /*
545 * Tell all users that this region is usable by running the _REG
546 * method
547 */
548 if (acpi_ns_locked) {
Len Brown4be44fc2005-08-05 00:44:28 -0400549 status =
550 acpi_ut_release_mutex
551 (ACPI_MTX_NAMESPACE);
552 if (ACPI_FAILURE(status)) {
553 return_ACPI_STATUS
554 (status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555 }
556 }
557
Len Brown4be44fc2005-08-05 00:44:28 -0400558 status =
559 acpi_ev_execute_reg_method
560 (region_obj, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561
562 if (acpi_ns_locked) {
Len Brown4be44fc2005-08-05 00:44:28 -0400563 status =
564 acpi_ut_acquire_mutex
565 (ACPI_MTX_NAMESPACE);
566 if (ACPI_FAILURE(status)) {
567 return_ACPI_STATUS
568 (status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569 }
570 }
571
Len Brown4be44fc2005-08-05 00:44:28 -0400572 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573 }
574
575 /* Try next handler in the list */
576
577 handler_obj = handler_obj->address_space.next;
578 }
579 }
580
581 /*
582 * This node does not have the handler we need;
583 * Pop up one level
584 */
Len Brown4be44fc2005-08-05 00:44:28 -0400585 node = acpi_ns_get_parent_node(node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586 }
587
588 /* If we get here, there is no handler for this region */
589
Len Brown4be44fc2005-08-05 00:44:28 -0400590 ACPI_DEBUG_PRINT((ACPI_DB_OPREGION,
Bob Mooreb229cf92006-04-21 17:15:00 -0400591 "No handler for RegionType %s(%X) (RegionObj %p)\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400592 acpi_ut_get_region_name(space_id), space_id,
593 region_obj));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594
Len Brown4be44fc2005-08-05 00:44:28 -0400595 return_ACPI_STATUS(AE_NOT_EXIST);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596}