blob: 900e5b32e595ad414ff3945e340bf3e15731559b [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/******************************************************************************
2 *
3 * Module Name: evregion - ACPI address_space (op_region) handler dispatch
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#include <acpi/acinterp.h>
48
49#define _COMPONENT ACPI_EVENTS
Len Brown4be44fc2005-08-05 00:44:28 -040050ACPI_MODULE_NAME("evregion")
Linus Torvalds1da177e2005-04-16 15:20:36 -070051#define ACPI_NUM_DEFAULT_SPACES 4
Len Brown4be44fc2005-08-05 00:44:28 -040052static u8 acpi_gbl_default_address_spaces[ACPI_NUM_DEFAULT_SPACES] = {
53 ACPI_ADR_SPACE_SYSTEM_MEMORY,
54 ACPI_ADR_SPACE_SYSTEM_IO,
55 ACPI_ADR_SPACE_PCI_CONFIG,
56 ACPI_ADR_SPACE_DATA_TABLE
57};
Linus Torvalds1da177e2005-04-16 15:20:36 -070058
Robert Moore44f6c012005-04-18 22:49:35 -040059/* Local prototypes */
60
61static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -040062acpi_ev_reg_run(acpi_handle obj_handle,
63 u32 level, void *context, void **return_value);
Robert Moore44f6c012005-04-18 22:49:35 -040064
65static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -040066acpi_ev_install_handler(acpi_handle obj_handle,
67 u32 level, void *context, void **return_value);
Linus Torvalds1da177e2005-04-16 15:20:36 -070068
69/*******************************************************************************
70 *
71 * FUNCTION: acpi_ev_install_region_handlers
72 *
73 * PARAMETERS: None
74 *
75 * RETURN: Status
76 *
77 * DESCRIPTION: Installs the core subsystem default address space handlers.
78 *
79 ******************************************************************************/
80
Len Brown4be44fc2005-08-05 00:44:28 -040081acpi_status acpi_ev_install_region_handlers(void)
82{
83 acpi_status status;
84 acpi_native_uint i;
Linus Torvalds1da177e2005-04-16 15:20:36 -070085
Len Brown4be44fc2005-08-05 00:44:28 -040086 ACPI_FUNCTION_TRACE("ev_install_region_handlers");
Linus Torvalds1da177e2005-04-16 15:20:36 -070087
Len Brown4be44fc2005-08-05 00:44:28 -040088 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
89 if (ACPI_FAILURE(status)) {
90 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 }
92
93 /*
94 * All address spaces (PCI Config, EC, SMBus) are scope dependent
95 * and registration must occur for a specific device.
96 *
97 * In the case of the system memory and IO address spaces there is currently
98 * no device associated with the address space. For these we use the root.
99 *
100 * We install the default PCI config space handler at the root so
101 * that this space is immediately available even though the we have
102 * not enumerated all the PCI Root Buses yet. This is to conform
103 * to the ACPI specification which states that the PCI config
104 * space must be always available -- even though we are nowhere
105 * near ready to find the PCI root buses at this point.
106 *
107 * NOTE: We ignore AE_ALREADY_EXISTS because this means that a handler
108 * has already been installed (via acpi_install_address_space_handler).
109 * Similar for AE_SAME_HANDLER.
110 */
111 for (i = 0; i < ACPI_NUM_DEFAULT_SPACES; i++) {
Len Brown4be44fc2005-08-05 00:44:28 -0400112 status = acpi_ev_install_space_handler(acpi_gbl_root_node,
113 acpi_gbl_default_address_spaces
114 [i],
115 ACPI_DEFAULT_HANDLER,
116 NULL, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117 switch (status) {
118 case AE_OK:
119 case AE_SAME_HANDLER:
120 case AE_ALREADY_EXISTS:
121
122 /* These exceptions are all OK */
123
124 status = AE_OK;
125 break;
126
127 default:
128
129 goto unlock_and_exit;
130 }
131 }
132
Len Brown4be44fc2005-08-05 00:44:28 -0400133 unlock_and_exit:
134 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
135 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136}
137
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138/*******************************************************************************
139 *
140 * FUNCTION: acpi_ev_initialize_op_regions
141 *
142 * PARAMETERS: None
143 *
144 * RETURN: Status
145 *
146 * DESCRIPTION: Execute _REG methods for all Operation Regions that have
147 * an installed default region handler.
148 *
149 ******************************************************************************/
150
Len Brown4be44fc2005-08-05 00:44:28 -0400151acpi_status acpi_ev_initialize_op_regions(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152{
Len Brown4be44fc2005-08-05 00:44:28 -0400153 acpi_status status;
154 acpi_native_uint i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155
Len Brown4be44fc2005-08-05 00:44:28 -0400156 ACPI_FUNCTION_TRACE("ev_initialize_op_regions");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157
Len Brown4be44fc2005-08-05 00:44:28 -0400158 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
159 if (ACPI_FAILURE(status)) {
160 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 }
162
163 /*
164 * Run the _REG methods for op_regions in each default address space
165 */
166 for (i = 0; i < ACPI_NUM_DEFAULT_SPACES; i++) {
167 /* TBD: Make sure handler is the DEFAULT handler, otherwise
168 * _REG will have already been run.
169 */
Len Brown4be44fc2005-08-05 00:44:28 -0400170 status = acpi_ev_execute_reg_methods(acpi_gbl_root_node,
171 acpi_gbl_default_address_spaces
172 [i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173 }
174
Len Brown4be44fc2005-08-05 00:44:28 -0400175 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
176 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177}
178
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179/*******************************************************************************
180 *
181 * FUNCTION: acpi_ev_execute_reg_method
182 *
Robert Moore44f6c012005-04-18 22:49:35 -0400183 * PARAMETERS: region_obj - Region object
184 * Function - Passed to _REG: On (1) or Off (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185 *
186 * RETURN: Status
187 *
188 * DESCRIPTION: Execute _REG method for a region
189 *
190 ******************************************************************************/
191
192acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400193acpi_ev_execute_reg_method(union acpi_operand_object *region_obj, u32 function)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194{
Len Brown4be44fc2005-08-05 00:44:28 -0400195 struct acpi_parameter_info info;
196 union acpi_operand_object *params[3];
197 union acpi_operand_object *region_obj2;
198 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199
Len Brown4be44fc2005-08-05 00:44:28 -0400200 ACPI_FUNCTION_TRACE("ev_execute_reg_method");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201
Len Brown4be44fc2005-08-05 00:44:28 -0400202 region_obj2 = acpi_ns_get_secondary_object(region_obj);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203 if (!region_obj2) {
Len Brown4be44fc2005-08-05 00:44:28 -0400204 return_ACPI_STATUS(AE_NOT_EXIST);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205 }
206
207 if (region_obj2->extra.method_REG == NULL) {
Len Brown4be44fc2005-08-05 00:44:28 -0400208 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209 }
210
211 /*
212 * The _REG method has two arguments:
213 *
214 * Arg0, Integer: Operation region space ID
215 * Same value as region_obj->Region.space_id
216 * Arg1, Integer: connection status
217 * 1 for connecting the handler,
218 * 0 for disconnecting the handler
219 * Passed as a parameter
220 */
Len Brown4be44fc2005-08-05 00:44:28 -0400221 params[0] = acpi_ut_create_internal_object(ACPI_TYPE_INTEGER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222 if (!params[0]) {
Len Brown4be44fc2005-08-05 00:44:28 -0400223 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224 }
225
Len Brown4be44fc2005-08-05 00:44:28 -0400226 params[1] = acpi_ut_create_internal_object(ACPI_TYPE_INTEGER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 if (!params[1]) {
228 status = AE_NO_MEMORY;
229 goto cleanup;
230 }
231
232 /* Setup the parameter objects */
233
234 params[0]->integer.value = region_obj->region.space_id;
235 params[1]->integer.value = function;
236 params[2] = NULL;
237
238 info.node = region_obj2->extra.method_REG;
239 info.parameters = params;
240 info.parameter_type = ACPI_PARAM_ARGS;
241
242 /* Execute the method, no return value */
243
Len Brown4be44fc2005-08-05 00:44:28 -0400244 ACPI_DEBUG_EXEC(acpi_ut_display_init_pathname
245 (ACPI_TYPE_METHOD, info.node, NULL));
246 status = acpi_ns_evaluate_by_handle(&info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247
Len Brown4be44fc2005-08-05 00:44:28 -0400248 acpi_ut_remove_reference(params[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249
Len Brown4be44fc2005-08-05 00:44:28 -0400250 cleanup:
251 acpi_ut_remove_reference(params[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252
Len Brown4be44fc2005-08-05 00:44:28 -0400253 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254}
255
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256/*******************************************************************************
257 *
258 * FUNCTION: acpi_ev_address_space_dispatch
259 *
260 * PARAMETERS: region_obj - Internal region object
261 * Function - Read or Write operation
262 * Address - Where in the space to read or write
263 * bit_width - Field width in bits (8, 16, 32, or 64)
264 * Value - Pointer to in or out value
265 *
266 * RETURN: Status
267 *
268 * DESCRIPTION: Dispatch an address space or operation region access to
269 * a previously installed handler.
270 *
271 ******************************************************************************/
272
273acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400274acpi_ev_address_space_dispatch(union acpi_operand_object *region_obj,
275 u32 function,
276 acpi_physical_address address,
277 u32 bit_width, void *value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278{
Len Brown4be44fc2005-08-05 00:44:28 -0400279 acpi_status status;
280 acpi_status status2;
281 acpi_adr_space_handler handler;
282 acpi_adr_space_setup region_setup;
283 union acpi_operand_object *handler_desc;
284 union acpi_operand_object *region_obj2;
285 void *region_context = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286
Len Brown4be44fc2005-08-05 00:44:28 -0400287 ACPI_FUNCTION_TRACE("ev_address_space_dispatch");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288
Len Brown4be44fc2005-08-05 00:44:28 -0400289 region_obj2 = acpi_ns_get_secondary_object(region_obj);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290 if (!region_obj2) {
Len Brown4be44fc2005-08-05 00:44:28 -0400291 return_ACPI_STATUS(AE_NOT_EXIST);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292 }
293
294 /* Ensure that there is a handler associated with this region */
295
296 handler_desc = region_obj->region.handler;
297 if (!handler_desc) {
Bob Moore4a90c7e2006-01-13 16:22:00 -0500298 ACPI_REPORT_ERROR(("No handler for Region [%4.4s] (%p) [%s]\n",
299 acpi_ut_get_node_name(region_obj->region.
300 node), region_obj,
301 acpi_ut_get_region_name(region_obj->region.
302 space_id)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303
Len Brown4be44fc2005-08-05 00:44:28 -0400304 return_ACPI_STATUS(AE_NOT_EXIST);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305 }
306
307 /*
308 * It may be the case that the region has never been initialized
309 * Some types of regions require special init code
310 */
311 if (!(region_obj->region.flags & AOPOBJ_SETUP_COMPLETE)) {
312 /*
313 * This region has not been initialized yet, do it
314 */
315 region_setup = handler_desc->address_space.setup;
316 if (!region_setup) {
317 /* No initialization routine, exit with error */
318
Bob Moore4a90c7e2006-01-13 16:22:00 -0500319 ACPI_REPORT_ERROR(("No init routine for region(%p) [%s]\n", region_obj, acpi_ut_get_region_name(region_obj->region.space_id)));
Len Brown4be44fc2005-08-05 00:44:28 -0400320 return_ACPI_STATUS(AE_NOT_EXIST);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321 }
322
323 /*
Robert Moore44f6c012005-04-18 22:49:35 -0400324 * We must exit the interpreter because the region
325 * setup will potentially execute control methods
326 * (e.g., _REG method for this region)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327 */
Len Brown4be44fc2005-08-05 00:44:28 -0400328 acpi_ex_exit_interpreter();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329
Len Brown4be44fc2005-08-05 00:44:28 -0400330 status = region_setup(region_obj, ACPI_REGION_ACTIVATE,
331 handler_desc->address_space.context,
332 &region_context);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333
334 /* Re-enter the interpreter */
335
Len Brown4be44fc2005-08-05 00:44:28 -0400336 status2 = acpi_ex_enter_interpreter();
337 if (ACPI_FAILURE(status2)) {
338 return_ACPI_STATUS(status2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339 }
340
341 /* Check for failure of the Region Setup */
342
Len Brown4be44fc2005-08-05 00:44:28 -0400343 if (ACPI_FAILURE(status)) {
Bob Moore4a90c7e2006-01-13 16:22:00 -0500344 ACPI_REPORT_ERROR(("Region Initialization: %s [%s]\n",
345 acpi_format_exception(status),
346 acpi_ut_get_region_name(region_obj->
347 region.
348 space_id)));
Len Brown4be44fc2005-08-05 00:44:28 -0400349 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350 }
351
352 /*
353 * Region initialization may have been completed by region_setup
354 */
355 if (!(region_obj->region.flags & AOPOBJ_SETUP_COMPLETE)) {
356 region_obj->region.flags |= AOPOBJ_SETUP_COMPLETE;
357
358 if (region_obj2->extra.region_context) {
359 /* The handler for this region was already installed */
360
Len Brown4be44fc2005-08-05 00:44:28 -0400361 ACPI_MEM_FREE(region_context);
362 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363 /*
364 * Save the returned context for use in all accesses to
365 * this particular region
366 */
Len Brown4be44fc2005-08-05 00:44:28 -0400367 region_obj2->extra.region_context =
368 region_context;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369 }
370 }
371 }
372
373 /* We have everything we need, we can invoke the address space handler */
374
375 handler = handler_desc->address_space.handler;
376
Len Brown4be44fc2005-08-05 00:44:28 -0400377 ACPI_DEBUG_PRINT((ACPI_DB_OPREGION,
378 "Handler %p (@%p) Address %8.8X%8.8X [%s]\n",
379 &region_obj->region.handler->address_space, handler,
380 ACPI_FORMAT_UINT64(address),
381 acpi_ut_get_region_name(region_obj->region.
382 space_id)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383
Len Brown4be44fc2005-08-05 00:44:28 -0400384 if (!
385 (handler_desc->address_space.
386 hflags & ACPI_ADDR_HANDLER_DEFAULT_INSTALLED)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387 /*
388 * For handlers other than the default (supplied) handlers, we must
389 * exit the interpreter because the handler *might* block -- we don't
390 * know what it will do, so we can't hold the lock on the intepreter.
391 */
392 acpi_ex_exit_interpreter();
393 }
394
395 /* Call the handler */
396
Len Brown4be44fc2005-08-05 00:44:28 -0400397 status = handler(function, address, bit_width, value,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398 handler_desc->address_space.context,
399 region_obj2->extra.region_context);
400
Len Brown4be44fc2005-08-05 00:44:28 -0400401 if (ACPI_FAILURE(status)) {
402 ACPI_REPORT_ERROR(("Handler for [%s] returned %s\n",
403 acpi_ut_get_region_name(region_obj->region.
404 space_id),
405 acpi_format_exception(status)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406 }
407
Len Brown4be44fc2005-08-05 00:44:28 -0400408 if (!
409 (handler_desc->address_space.
410 hflags & ACPI_ADDR_HANDLER_DEFAULT_INSTALLED)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411 /*
412 * We just returned from a non-default handler, we must re-enter the
413 * interpreter
414 */
Len Brown4be44fc2005-08-05 00:44:28 -0400415 status2 = acpi_ex_enter_interpreter();
416 if (ACPI_FAILURE(status2)) {
417 return_ACPI_STATUS(status2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 }
419 }
420
Len Brown4be44fc2005-08-05 00:44:28 -0400421 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422}
423
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424/*******************************************************************************
425 *
426 * FUNCTION: acpi_ev_detach_region
427 *
428 * PARAMETERS: region_obj - Region Object
429 * acpi_ns_is_locked - Namespace Region Already Locked?
430 *
431 * RETURN: None
432 *
433 * DESCRIPTION: Break the association between the handler and the region
434 * this is a two way association.
435 *
436 ******************************************************************************/
437
438void
Len Brown4be44fc2005-08-05 00:44:28 -0400439acpi_ev_detach_region(union acpi_operand_object *region_obj,
440 u8 acpi_ns_is_locked)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441{
Len Brown4be44fc2005-08-05 00:44:28 -0400442 union acpi_operand_object *handler_obj;
443 union acpi_operand_object *obj_desc;
444 union acpi_operand_object **last_obj_ptr;
445 acpi_adr_space_setup region_setup;
446 void **region_context;
447 union acpi_operand_object *region_obj2;
448 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449
Len Brown4be44fc2005-08-05 00:44:28 -0400450 ACPI_FUNCTION_TRACE("ev_detach_region");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451
Len Brown4be44fc2005-08-05 00:44:28 -0400452 region_obj2 = acpi_ns_get_secondary_object(region_obj);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453 if (!region_obj2) {
454 return_VOID;
455 }
456 region_context = &region_obj2->extra.region_context;
457
458 /* Get the address handler from the region object */
459
460 handler_obj = region_obj->region.handler;
461 if (!handler_obj) {
462 /* This region has no handler, all done */
463
464 return_VOID;
465 }
466
467 /* Find this region in the handler's list */
468
469 obj_desc = handler_obj->address_space.region_list;
470 last_obj_ptr = &handler_obj->address_space.region_list;
471
472 while (obj_desc) {
473 /* Is this the correct Region? */
474
475 if (obj_desc == region_obj) {
Len Brown4be44fc2005-08-05 00:44:28 -0400476 ACPI_DEBUG_PRINT((ACPI_DB_OPREGION,
477 "Removing Region %p from address handler %p\n",
478 region_obj, handler_obj));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479
480 /* This is it, remove it from the handler's list */
481
482 *last_obj_ptr = obj_desc->region.next;
Len Brown4be44fc2005-08-05 00:44:28 -0400483 obj_desc->region.next = NULL; /* Must clear field */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484
485 if (acpi_ns_is_locked) {
Len Brown4be44fc2005-08-05 00:44:28 -0400486 status =
487 acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
488 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489 return_VOID;
490 }
491 }
492
493 /* Now stop region accesses by executing the _REG method */
494
Len Brown4be44fc2005-08-05 00:44:28 -0400495 status = acpi_ev_execute_reg_method(region_obj, 0);
496 if (ACPI_FAILURE(status)) {
Bob Moore4a90c7e2006-01-13 16:22:00 -0500497 ACPI_REPORT_ERROR(("%s from region _REG, [%s]\n", acpi_format_exception(status), acpi_ut_get_region_name(region_obj->region.space_id)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 }
499
500 if (acpi_ns_is_locked) {
Len Brown4be44fc2005-08-05 00:44:28 -0400501 status =
502 acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
503 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504 return_VOID;
505 }
506 }
507
508 /* Call the setup handler with the deactivate notification */
509
510 region_setup = handler_obj->address_space.setup;
Len Brown4be44fc2005-08-05 00:44:28 -0400511 status =
512 region_setup(region_obj, ACPI_REGION_DEACTIVATE,
513 handler_obj->address_space.context,
514 region_context);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515
516 /* Init routine may fail, Just ignore errors */
517
Len Brown4be44fc2005-08-05 00:44:28 -0400518 if (ACPI_FAILURE(status)) {
Bob Moore4a90c7e2006-01-13 16:22:00 -0500519 ACPI_REPORT_ERROR(("%s from region init, [%s]\n", acpi_format_exception(status), acpi_ut_get_region_name(region_obj->region.space_id)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520 }
521
522 region_obj->region.flags &= ~(AOPOBJ_SETUP_COMPLETE);
523
524 /*
525 * Remove handler reference in the region
526 *
527 * NOTE: this doesn't mean that the region goes away
528 * The region is just inaccessible as indicated to
529 * the _REG method
530 *
531 * If the region is on the handler's list
532 * this better be the region's handler
533 */
534 region_obj->region.handler = NULL;
Len Brown4be44fc2005-08-05 00:44:28 -0400535 acpi_ut_remove_reference(handler_obj);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536
537 return_VOID;
538 }
539
540 /* Walk the linked list of handlers */
541
542 last_obj_ptr = &obj_desc->region.next;
543 obj_desc = obj_desc->region.next;
544 }
545
546 /* If we get here, the region was not in the handler's region list */
547
Len Brown4be44fc2005-08-05 00:44:28 -0400548 ACPI_DEBUG_PRINT((ACPI_DB_OPREGION,
549 "Cannot remove region %p from address handler %p\n",
550 region_obj, handler_obj));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551
552 return_VOID;
553}
554
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555/*******************************************************************************
556 *
557 * FUNCTION: acpi_ev_attach_region
558 *
559 * PARAMETERS: handler_obj - Handler Object
560 * region_obj - Region Object
561 * acpi_ns_is_locked - Namespace Region Already Locked?
562 *
563 * RETURN: None
564 *
565 * DESCRIPTION: Create the association between the handler and the region
566 * this is a two way association.
567 *
568 ******************************************************************************/
569
570acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400571acpi_ev_attach_region(union acpi_operand_object *handler_obj,
572 union acpi_operand_object *region_obj,
573 u8 acpi_ns_is_locked)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574{
575
Len Brown4be44fc2005-08-05 00:44:28 -0400576 ACPI_FUNCTION_TRACE("ev_attach_region");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577
Len Brown4be44fc2005-08-05 00:44:28 -0400578 ACPI_DEBUG_PRINT((ACPI_DB_OPREGION,
579 "Adding Region [%4.4s] %p to address handler %p [%s]\n",
580 acpi_ut_get_node_name(region_obj->region.node),
581 region_obj, handler_obj,
582 acpi_ut_get_region_name(region_obj->region.
583 space_id)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584
585 /* Link this region to the front of the handler's list */
586
587 region_obj->region.next = handler_obj->address_space.region_list;
588 handler_obj->address_space.region_list = region_obj;
589
590 /* Install the region's handler */
591
592 if (region_obj->region.handler) {
Len Brown4be44fc2005-08-05 00:44:28 -0400593 return_ACPI_STATUS(AE_ALREADY_EXISTS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594 }
595
596 region_obj->region.handler = handler_obj;
Len Brown4be44fc2005-08-05 00:44:28 -0400597 acpi_ut_add_reference(handler_obj);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598
Len Brown4be44fc2005-08-05 00:44:28 -0400599 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600}
601
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602/*******************************************************************************
603 *
604 * FUNCTION: acpi_ev_install_handler
605 *
606 * PARAMETERS: walk_namespace callback
607 *
608 * DESCRIPTION: This routine installs an address handler into objects that are
609 * of type Region or Device.
610 *
611 * If the Object is a Device, and the device has a handler of
612 * the same type then the search is terminated in that branch.
613 *
614 * This is because the existing handler is closer in proximity
615 * to any more regions than the one we are trying to install.
616 *
617 ******************************************************************************/
618
Robert Moore44f6c012005-04-18 22:49:35 -0400619static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400620acpi_ev_install_handler(acpi_handle obj_handle,
621 u32 level, void *context, void **return_value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622{
Len Brown4be44fc2005-08-05 00:44:28 -0400623 union acpi_operand_object *handler_obj;
624 union acpi_operand_object *next_handler_obj;
625 union acpi_operand_object *obj_desc;
626 struct acpi_namespace_node *node;
627 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628
Len Brown4be44fc2005-08-05 00:44:28 -0400629 ACPI_FUNCTION_NAME("ev_install_handler");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630
Len Brown4be44fc2005-08-05 00:44:28 -0400631 handler_obj = (union acpi_operand_object *)context;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632
633 /* Parameter validation */
634
635 if (!handler_obj) {
636 return (AE_OK);
637 }
638
639 /* Convert and validate the device handle */
640
Len Brown4be44fc2005-08-05 00:44:28 -0400641 node = acpi_ns_map_handle_to_node(obj_handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642 if (!node) {
643 return (AE_BAD_PARAMETER);
644 }
645
646 /*
647 * We only care about regions.and objects
648 * that are allowed to have address space handlers
649 */
650 if ((node->type != ACPI_TYPE_DEVICE) &&
Len Brown4be44fc2005-08-05 00:44:28 -0400651 (node->type != ACPI_TYPE_REGION) && (node != acpi_gbl_root_node)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652 return (AE_OK);
653 }
654
655 /* Check for an existing internal object */
656
Len Brown4be44fc2005-08-05 00:44:28 -0400657 obj_desc = acpi_ns_get_attached_object(node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658 if (!obj_desc) {
659 /* No object, just exit */
660
661 return (AE_OK);
662 }
663
664 /* Devices are handled different than regions */
665
Len Brown4be44fc2005-08-05 00:44:28 -0400666 if (ACPI_GET_OBJECT_TYPE(obj_desc) == ACPI_TYPE_DEVICE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667 /* Check if this Device already has a handler for this address space */
668
669 next_handler_obj = obj_desc->device.handler;
670 while (next_handler_obj) {
671 /* Found a handler, is it for the same address space? */
672
Len Brown4be44fc2005-08-05 00:44:28 -0400673 if (next_handler_obj->address_space.space_id ==
674 handler_obj->address_space.space_id) {
675 ACPI_DEBUG_PRINT((ACPI_DB_OPREGION,
676 "Found handler for region [%s] in device %p(%p) handler %p\n",
677 acpi_ut_get_region_name
678 (handler_obj->address_space.
679 space_id), obj_desc,
680 next_handler_obj,
681 handler_obj));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682
683 /*
684 * Since the object we found it on was a device, then it
685 * means that someone has already installed a handler for
686 * the branch of the namespace from this device on. Just
687 * bail out telling the walk routine to not traverse this
688 * branch. This preserves the scoping rule for handlers.
689 */
690 return (AE_CTRL_DEPTH);
691 }
692
693 /* Walk the linked list of handlers attached to this device */
694
695 next_handler_obj = next_handler_obj->address_space.next;
696 }
697
698 /*
699 * As long as the device didn't have a handler for this
700 * space we don't care about it. We just ignore it and
701 * proceed.
702 */
703 return (AE_OK);
704 }
705
706 /* Object is a Region */
707
708 if (obj_desc->region.space_id != handler_obj->address_space.space_id) {
709 /*
710 * This region is for a different address space
711 * -- just ignore it
712 */
713 return (AE_OK);
714 }
715
716 /*
717 * Now we have a region and it is for the handler's address
718 * space type.
719 *
720 * First disconnect region for any previous handler (if any)
721 */
Len Brown4be44fc2005-08-05 00:44:28 -0400722 acpi_ev_detach_region(obj_desc, FALSE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723
724 /* Connect the region to the new handler */
725
Len Brown4be44fc2005-08-05 00:44:28 -0400726 status = acpi_ev_attach_region(handler_obj, obj_desc, FALSE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727 return (status);
728}
729
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730/*******************************************************************************
731 *
732 * FUNCTION: acpi_ev_install_space_handler
733 *
734 * PARAMETERS: Node - Namespace node for the device
735 * space_id - The address space ID
736 * Handler - Address of the handler
737 * Setup - Address of the setup function
738 * Context - Value passed to the handler on each access
739 *
740 * RETURN: Status
741 *
742 * DESCRIPTION: Install a handler for all op_regions of a given space_id.
743 * Assumes namespace is locked
744 *
745 ******************************************************************************/
746
747acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400748acpi_ev_install_space_handler(struct acpi_namespace_node * node,
749 acpi_adr_space_type space_id,
750 acpi_adr_space_handler handler,
751 acpi_adr_space_setup setup, void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752{
Len Brown4be44fc2005-08-05 00:44:28 -0400753 union acpi_operand_object *obj_desc;
754 union acpi_operand_object *handler_obj;
755 acpi_status status;
756 acpi_object_type type;
757 u16 flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758
Len Brown4be44fc2005-08-05 00:44:28 -0400759 ACPI_FUNCTION_TRACE("ev_install_space_handler");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760
761 /*
762 * This registration is valid for only the types below
763 * and the root. This is where the default handlers
764 * get placed.
765 */
Len Brown4be44fc2005-08-05 00:44:28 -0400766 if ((node->type != ACPI_TYPE_DEVICE) &&
767 (node->type != ACPI_TYPE_PROCESSOR) &&
768 (node->type != ACPI_TYPE_THERMAL) && (node != acpi_gbl_root_node)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769 status = AE_BAD_PARAMETER;
770 goto unlock_and_exit;
771 }
772
773 if (handler == ACPI_DEFAULT_HANDLER) {
774 flags = ACPI_ADDR_HANDLER_DEFAULT_INSTALLED;
775
776 switch (space_id) {
777 case ACPI_ADR_SPACE_SYSTEM_MEMORY:
778 handler = acpi_ex_system_memory_space_handler;
Len Brown4be44fc2005-08-05 00:44:28 -0400779 setup = acpi_ev_system_memory_region_setup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780 break;
781
782 case ACPI_ADR_SPACE_SYSTEM_IO:
783 handler = acpi_ex_system_io_space_handler;
Len Brown4be44fc2005-08-05 00:44:28 -0400784 setup = acpi_ev_io_space_region_setup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785 break;
786
787 case ACPI_ADR_SPACE_PCI_CONFIG:
788 handler = acpi_ex_pci_config_space_handler;
Len Brown4be44fc2005-08-05 00:44:28 -0400789 setup = acpi_ev_pci_config_region_setup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790 break;
791
792 case ACPI_ADR_SPACE_CMOS:
793 handler = acpi_ex_cmos_space_handler;
Len Brown4be44fc2005-08-05 00:44:28 -0400794 setup = acpi_ev_cmos_region_setup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795 break;
796
797 case ACPI_ADR_SPACE_PCI_BAR_TARGET:
798 handler = acpi_ex_pci_bar_space_handler;
Len Brown4be44fc2005-08-05 00:44:28 -0400799 setup = acpi_ev_pci_bar_region_setup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800 break;
801
802 case ACPI_ADR_SPACE_DATA_TABLE:
803 handler = acpi_ex_data_table_space_handler;
Len Brown4be44fc2005-08-05 00:44:28 -0400804 setup = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805 break;
806
807 default:
808 status = AE_BAD_PARAMETER;
809 goto unlock_and_exit;
810 }
811 }
812
813 /* If the caller hasn't specified a setup routine, use the default */
814
815 if (!setup) {
816 setup = acpi_ev_default_region_setup;
817 }
818
819 /* Check for an existing internal object */
820
Len Brown4be44fc2005-08-05 00:44:28 -0400821 obj_desc = acpi_ns_get_attached_object(node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822 if (obj_desc) {
823 /*
824 * The attached device object already exists.
825 * Make sure the handler is not already installed.
826 */
827 handler_obj = obj_desc->device.handler;
828
829 /* Walk the handler list for this device */
830
831 while (handler_obj) {
832 /* Same space_id indicates a handler already installed */
833
834 if (handler_obj->address_space.space_id == space_id) {
Len Brown4be44fc2005-08-05 00:44:28 -0400835 if (handler_obj->address_space.handler ==
836 handler) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837 /*
838 * It is (relatively) OK to attempt to install the SAME
Robert Moore44f6c012005-04-18 22:49:35 -0400839 * handler twice. This can easily happen
840 * with PCI_Config space.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841 */
842 status = AE_SAME_HANDLER;
843 goto unlock_and_exit;
Len Brown4be44fc2005-08-05 00:44:28 -0400844 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845 /* A handler is already installed */
846
847 status = AE_ALREADY_EXISTS;
848 }
849 goto unlock_and_exit;
850 }
851
852 /* Walk the linked list of handlers */
853
854 handler_obj = handler_obj->address_space.next;
855 }
Len Brown4be44fc2005-08-05 00:44:28 -0400856 } else {
857 ACPI_DEBUG_PRINT((ACPI_DB_OPREGION,
858 "Creating object on Device %p while installing handler\n",
859 node));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860
861 /* obj_desc does not exist, create one */
862
863 if (node->type == ACPI_TYPE_ANY) {
864 type = ACPI_TYPE_DEVICE;
Len Brown4be44fc2005-08-05 00:44:28 -0400865 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866 type = node->type;
867 }
868
Len Brown4be44fc2005-08-05 00:44:28 -0400869 obj_desc = acpi_ut_create_internal_object(type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700870 if (!obj_desc) {
871 status = AE_NO_MEMORY;
872 goto unlock_and_exit;
873 }
874
875 /* Init new descriptor */
876
877 obj_desc->common.type = (u8) type;
878
879 /* Attach the new object to the Node */
880
Len Brown4be44fc2005-08-05 00:44:28 -0400881 status = acpi_ns_attach_object(node, obj_desc, type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882
883 /* Remove local reference to the object */
884
Len Brown4be44fc2005-08-05 00:44:28 -0400885 acpi_ut_remove_reference(obj_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886
Len Brown4be44fc2005-08-05 00:44:28 -0400887 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700888 goto unlock_and_exit;
889 }
890 }
891
Len Brown4be44fc2005-08-05 00:44:28 -0400892 ACPI_DEBUG_PRINT((ACPI_DB_OPREGION,
893 "Installing address handler for region %s(%X) on Device %4.4s %p(%p)\n",
894 acpi_ut_get_region_name(space_id), space_id,
895 acpi_ut_get_node_name(node), node, obj_desc));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896
897 /*
898 * Install the handler
899 *
900 * At this point there is no existing handler.
901 * Just allocate the object for the handler and link it
902 * into the list.
903 */
Len Brown4be44fc2005-08-05 00:44:28 -0400904 handler_obj =
905 acpi_ut_create_internal_object(ACPI_TYPE_LOCAL_ADDRESS_HANDLER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700906 if (!handler_obj) {
907 status = AE_NO_MEMORY;
908 goto unlock_and_exit;
909 }
910
911 /* Init handler obj */
912
Len Brown4be44fc2005-08-05 00:44:28 -0400913 handler_obj->address_space.space_id = (u8) space_id;
914 handler_obj->address_space.hflags = flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915 handler_obj->address_space.region_list = NULL;
Len Brown4be44fc2005-08-05 00:44:28 -0400916 handler_obj->address_space.node = node;
917 handler_obj->address_space.handler = handler;
918 handler_obj->address_space.context = context;
919 handler_obj->address_space.setup = setup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920
921 /* Install at head of Device.address_space list */
922
Len Brown4be44fc2005-08-05 00:44:28 -0400923 handler_obj->address_space.next = obj_desc->device.handler;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924
925 /*
926 * The Device object is the first reference on the handler_obj.
927 * Each region that uses the handler adds a reference.
928 */
929 obj_desc->device.handler = handler_obj;
930
931 /*
932 * Walk the namespace finding all of the regions this
933 * handler will manage.
934 *
935 * Start at the device and search the branch toward
936 * the leaf nodes until either the leaf is encountered or
937 * a device is detected that has an address handler of the
938 * same type.
939 *
940 * In either case, back up and search down the remainder
941 * of the branch
942 */
Len Brown4be44fc2005-08-05 00:44:28 -0400943 status = acpi_ns_walk_namespace(ACPI_TYPE_ANY, node, ACPI_UINT32_MAX,
944 ACPI_NS_WALK_UNLOCK,
945 acpi_ev_install_handler, handler_obj,
946 NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947
Len Brown4be44fc2005-08-05 00:44:28 -0400948 unlock_and_exit:
949 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950}
951
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952/*******************************************************************************
953 *
954 * FUNCTION: acpi_ev_execute_reg_methods
955 *
956 * PARAMETERS: Node - Namespace node for the device
957 * space_id - The address space ID
958 *
959 * RETURN: Status
960 *
961 * DESCRIPTION: Run all _REG methods for the input Space ID;
962 * Note: assumes namespace is locked, or system init time.
963 *
964 ******************************************************************************/
965
966acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400967acpi_ev_execute_reg_methods(struct acpi_namespace_node *node,
968 acpi_adr_space_type space_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969{
Len Brown4be44fc2005-08-05 00:44:28 -0400970 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700971
Len Brown4be44fc2005-08-05 00:44:28 -0400972 ACPI_FUNCTION_TRACE("ev_execute_reg_methods");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700973
974 /*
975 * Run all _REG methods for all Operation Regions for this
976 * space ID. This is a separate walk in order to handle any
977 * interdependencies between regions and _REG methods. (i.e. handlers
978 * must be installed for all regions of this Space ID before we
979 * can run any _REG methods)
980 */
Len Brown4be44fc2005-08-05 00:44:28 -0400981 status = acpi_ns_walk_namespace(ACPI_TYPE_ANY, node, ACPI_UINT32_MAX,
982 ACPI_NS_WALK_UNLOCK, acpi_ev_reg_run,
983 &space_id, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700984
Len Brown4be44fc2005-08-05 00:44:28 -0400985 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700986}
987
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988/*******************************************************************************
989 *
990 * FUNCTION: acpi_ev_reg_run
991 *
992 * PARAMETERS: walk_namespace callback
993 *
994 * DESCRIPTION: Run _REg method for region objects of the requested space_iD
995 *
996 ******************************************************************************/
997
Robert Moore44f6c012005-04-18 22:49:35 -0400998static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400999acpi_ev_reg_run(acpi_handle obj_handle,
1000 u32 level, void *context, void **return_value)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001001{
Len Brown4be44fc2005-08-05 00:44:28 -04001002 union acpi_operand_object *obj_desc;
1003 struct acpi_namespace_node *node;
1004 acpi_adr_space_type space_id;
1005 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001006
Len Brown4be44fc2005-08-05 00:44:28 -04001007 space_id = *ACPI_CAST_PTR(acpi_adr_space_type, context);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008
1009 /* Convert and validate the device handle */
1010
Len Brown4be44fc2005-08-05 00:44:28 -04001011 node = acpi_ns_map_handle_to_node(obj_handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001012 if (!node) {
1013 return (AE_BAD_PARAMETER);
1014 }
1015
1016 /*
1017 * We only care about regions.and objects
1018 * that are allowed to have address space handlers
1019 */
Len Brown4be44fc2005-08-05 00:44:28 -04001020 if ((node->type != ACPI_TYPE_REGION) && (node != acpi_gbl_root_node)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001021 return (AE_OK);
1022 }
1023
1024 /* Check for an existing internal object */
1025
Len Brown4be44fc2005-08-05 00:44:28 -04001026 obj_desc = acpi_ns_get_attached_object(node);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027 if (!obj_desc) {
1028 /* No object, just exit */
1029
1030 return (AE_OK);
1031 }
1032
1033 /* Object is a Region */
1034
1035 if (obj_desc->region.space_id != space_id) {
1036 /*
1037 * This region is for a different address space
1038 * -- just ignore it
1039 */
1040 return (AE_OK);
1041 }
1042
Len Brown4be44fc2005-08-05 00:44:28 -04001043 status = acpi_ev_execute_reg_method(obj_desc, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001044 return (status);
1045}