blob: 094a17e4c86deec03416cd71cd39fd075e660751 [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
Bob Mooreb229cf92006-04-21 17:15:00 -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
Bob Mooreb229cf92006-04-21 17:15:00 -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++) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400167
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168 /* TBD: Make sure handler is the DEFAULT handler, otherwise
169 * _REG will have already been run.
170 */
Len Brown4be44fc2005-08-05 00:44:28 -0400171 status = acpi_ev_execute_reg_methods(acpi_gbl_root_node,
172 acpi_gbl_default_address_spaces
173 [i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174 }
175
Len Brown4be44fc2005-08-05 00:44:28 -0400176 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
177 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178}
179
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180/*******************************************************************************
181 *
182 * FUNCTION: acpi_ev_execute_reg_method
183 *
Robert Moore44f6c012005-04-18 22:49:35 -0400184 * PARAMETERS: region_obj - Region object
185 * Function - Passed to _REG: On (1) or Off (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186 *
187 * RETURN: Status
188 *
189 * DESCRIPTION: Execute _REG method for a region
190 *
191 ******************************************************************************/
192
193acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400194acpi_ev_execute_reg_method(union acpi_operand_object *region_obj, u32 function)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195{
Bob Moore41195322006-05-26 16:36:00 -0400196 struct acpi_evaluate_info *info;
197 union acpi_operand_object *args[3];
Len Brown4be44fc2005-08-05 00:44:28 -0400198 union acpi_operand_object *region_obj2;
199 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200
Bob Mooreb229cf92006-04-21 17:15:00 -0400201 ACPI_FUNCTION_TRACE(ev_execute_reg_method);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202
Len Brown4be44fc2005-08-05 00:44:28 -0400203 region_obj2 = acpi_ns_get_secondary_object(region_obj);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204 if (!region_obj2) {
Len Brown4be44fc2005-08-05 00:44:28 -0400205 return_ACPI_STATUS(AE_NOT_EXIST);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206 }
207
208 if (region_obj2->extra.method_REG == NULL) {
Len Brown4be44fc2005-08-05 00:44:28 -0400209 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210 }
211
Bob Moore41195322006-05-26 16:36:00 -0400212 /* Allocate and initialize the evaluation information block */
213
214 info = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_evaluate_info));
215 if (!info) {
Len Brown4be44fc2005-08-05 00:44:28 -0400216 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217 }
218
Bob Moore41195322006-05-26 16:36:00 -0400219 info->prefix_node = region_obj2->extra.method_REG;
220 info->pathname = NULL;
221 info->parameters = args;
222 info->parameter_type = ACPI_PARAM_ARGS;
223 info->flags = ACPI_IGNORE_RETURN_VALUE;
224
225 /*
226 * The _REG method has two arguments:
227 *
228 * Arg0 - Integer:
229 * Operation region space ID Same value as region_obj->Region.space_id
230 *
231 * Arg1 - Integer:
232 * connection status 1 for connecting the handler, 0 for disconnecting
233 * the handler (Passed as a parameter)
234 */
235 args[0] = acpi_ut_create_internal_object(ACPI_TYPE_INTEGER);
236 if (!args[0]) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237 status = AE_NO_MEMORY;
Bob Moore41195322006-05-26 16:36:00 -0400238 goto cleanup1;
239 }
240
241 args[1] = acpi_ut_create_internal_object(ACPI_TYPE_INTEGER);
242 if (!args[1]) {
243 status = AE_NO_MEMORY;
244 goto cleanup2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245 }
246
247 /* Setup the parameter objects */
248
Bob Moore41195322006-05-26 16:36:00 -0400249 args[0]->integer.value = region_obj->region.space_id;
250 args[1]->integer.value = function;
251 args[2] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252
253 /* Execute the method, no return value */
254
Len Brown4be44fc2005-08-05 00:44:28 -0400255 ACPI_DEBUG_EXEC(acpi_ut_display_init_pathname
Bob Moore41195322006-05-26 16:36:00 -0400256 (ACPI_TYPE_METHOD, info->prefix_node, NULL));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257
Bob Moore41195322006-05-26 16:36:00 -0400258 status = acpi_ns_evaluate(info);
259 acpi_ut_remove_reference(args[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260
Bob Moore41195322006-05-26 16:36:00 -0400261 cleanup2:
262 acpi_ut_remove_reference(args[0]);
263
264 cleanup1:
265 ACPI_FREE(info);
Len Brown4be44fc2005-08-05 00:44:28 -0400266 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267}
268
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269/*******************************************************************************
270 *
271 * FUNCTION: acpi_ev_address_space_dispatch
272 *
273 * PARAMETERS: region_obj - Internal region object
274 * Function - Read or Write operation
275 * Address - Where in the space to read or write
276 * bit_width - Field width in bits (8, 16, 32, or 64)
Bob Moore958dd242006-05-12 17:12:00 -0400277 * Value - Pointer to in or out value, must be
278 * full 64-bit acpi_integer
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279 *
280 * RETURN: Status
281 *
282 * DESCRIPTION: Dispatch an address space or operation region access to
283 * a previously installed handler.
284 *
285 ******************************************************************************/
286
287acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400288acpi_ev_address_space_dispatch(union acpi_operand_object *region_obj,
289 u32 function,
290 acpi_physical_address address,
Bob Moore958dd242006-05-12 17:12:00 -0400291 u32 bit_width, acpi_integer * value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292{
Len Brown4be44fc2005-08-05 00:44:28 -0400293 acpi_status status;
294 acpi_status status2;
295 acpi_adr_space_handler handler;
296 acpi_adr_space_setup region_setup;
297 union acpi_operand_object *handler_desc;
298 union acpi_operand_object *region_obj2;
299 void *region_context = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300
Bob Mooreb229cf92006-04-21 17:15:00 -0400301 ACPI_FUNCTION_TRACE(ev_address_space_dispatch);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302
Len Brown4be44fc2005-08-05 00:44:28 -0400303 region_obj2 = acpi_ns_get_secondary_object(region_obj);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304 if (!region_obj2) {
Len Brown4be44fc2005-08-05 00:44:28 -0400305 return_ACPI_STATUS(AE_NOT_EXIST);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306 }
307
308 /* Ensure that there is a handler associated with this region */
309
310 handler_desc = region_obj->region.handler;
311 if (!handler_desc) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500312 ACPI_ERROR((AE_INFO,
313 "No handler for Region [%4.4s] (%p) [%s]",
314 acpi_ut_get_node_name(region_obj->region.node),
315 region_obj,
316 acpi_ut_get_region_name(region_obj->region.
317 space_id)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318
Len Brown4be44fc2005-08-05 00:44:28 -0400319 return_ACPI_STATUS(AE_NOT_EXIST);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320 }
321
322 /*
323 * It may be the case that the region has never been initialized
324 * Some types of regions require special init code
325 */
326 if (!(region_obj->region.flags & AOPOBJ_SETUP_COMPLETE)) {
327 /*
328 * This region has not been initialized yet, do it
329 */
330 region_setup = handler_desc->address_space.setup;
331 if (!region_setup) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400332
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333 /* No initialization routine, exit with error */
334
Bob Mooreb8e4d892006-01-27 16:43:00 -0500335 ACPI_ERROR((AE_INFO,
336 "No init routine for region(%p) [%s]",
337 region_obj,
338 acpi_ut_get_region_name(region_obj->region.
339 space_id)));
Len Brown4be44fc2005-08-05 00:44:28 -0400340 return_ACPI_STATUS(AE_NOT_EXIST);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341 }
342
343 /*
Robert Moore44f6c012005-04-18 22:49:35 -0400344 * We must exit the interpreter because the region
345 * setup will potentially execute control methods
346 * (e.g., _REG method for this region)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347 */
Len Brown4be44fc2005-08-05 00:44:28 -0400348 acpi_ex_exit_interpreter();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349
Len Brown4be44fc2005-08-05 00:44:28 -0400350 status = region_setup(region_obj, ACPI_REGION_ACTIVATE,
351 handler_desc->address_space.context,
352 &region_context);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353
354 /* Re-enter the interpreter */
355
Len Brown4be44fc2005-08-05 00:44:28 -0400356 status2 = acpi_ex_enter_interpreter();
357 if (ACPI_FAILURE(status2)) {
358 return_ACPI_STATUS(status2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359 }
360
361 /* Check for failure of the Region Setup */
362
Len Brown4be44fc2005-08-05 00:44:28 -0400363 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500364 ACPI_EXCEPTION((AE_INFO, status,
365 "During region initialization: [%s]",
366 acpi_ut_get_region_name(region_obj->
367 region.
368 space_id)));
Len Brown4be44fc2005-08-05 00:44:28 -0400369 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370 }
371
372 /*
373 * Region initialization may have been completed by region_setup
374 */
375 if (!(region_obj->region.flags & AOPOBJ_SETUP_COMPLETE)) {
376 region_obj->region.flags |= AOPOBJ_SETUP_COMPLETE;
377
378 if (region_obj2->extra.region_context) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400379
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380 /* The handler for this region was already installed */
381
Bob Moore83135242006-10-03 00:00:00 -0400382 ACPI_FREE(region_context);
Len Brown4be44fc2005-08-05 00:44:28 -0400383 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384 /*
385 * Save the returned context for use in all accesses to
386 * this particular region
387 */
Len Brown4be44fc2005-08-05 00:44:28 -0400388 region_obj2->extra.region_context =
389 region_context;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 }
391 }
392 }
393
394 /* We have everything we need, we can invoke the address space handler */
395
396 handler = handler_desc->address_space.handler;
397
Len Brown4be44fc2005-08-05 00:44:28 -0400398 ACPI_DEBUG_PRINT((ACPI_DB_OPREGION,
399 "Handler %p (@%p) Address %8.8X%8.8X [%s]\n",
400 &region_obj->region.handler->address_space, handler,
401 ACPI_FORMAT_UINT64(address),
402 acpi_ut_get_region_name(region_obj->region.
403 space_id)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404
Bob Moore616861242006-03-17 16:44:00 -0500405 if (!(handler_desc->address_space.handler_flags &
406 ACPI_ADDR_HANDLER_DEFAULT_INSTALLED)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407 /*
408 * For handlers other than the default (supplied) handlers, we must
409 * exit the interpreter because the handler *might* block -- we don't
410 * know what it will do, so we can't hold the lock on the intepreter.
411 */
412 acpi_ex_exit_interpreter();
413 }
414
415 /* Call the handler */
416
Len Brown4be44fc2005-08-05 00:44:28 -0400417 status = handler(function, address, bit_width, value,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 handler_desc->address_space.context,
419 region_obj2->extra.region_context);
420
Len Brown4be44fc2005-08-05 00:44:28 -0400421 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500422 ACPI_EXCEPTION((AE_INFO, status, "Returned by Handler for [%s]",
423 acpi_ut_get_region_name(region_obj->region.
424 space_id)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425 }
426
Bob Moore616861242006-03-17 16:44:00 -0500427 if (!(handler_desc->address_space.handler_flags &
428 ACPI_ADDR_HANDLER_DEFAULT_INSTALLED)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 /*
430 * We just returned from a non-default handler, we must re-enter the
431 * interpreter
432 */
Len Brown4be44fc2005-08-05 00:44:28 -0400433 status2 = acpi_ex_enter_interpreter();
434 if (ACPI_FAILURE(status2)) {
435 return_ACPI_STATUS(status2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436 }
437 }
438
Len Brown4be44fc2005-08-05 00:44:28 -0400439 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440}
441
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442/*******************************************************************************
443 *
444 * FUNCTION: acpi_ev_detach_region
445 *
446 * PARAMETERS: region_obj - Region Object
447 * acpi_ns_is_locked - Namespace Region Already Locked?
448 *
449 * RETURN: None
450 *
451 * DESCRIPTION: Break the association between the handler and the region
452 * this is a two way association.
453 *
454 ******************************************************************************/
455
456void
Len Brown4be44fc2005-08-05 00:44:28 -0400457acpi_ev_detach_region(union acpi_operand_object *region_obj,
458 u8 acpi_ns_is_locked)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459{
Len Brown4be44fc2005-08-05 00:44:28 -0400460 union acpi_operand_object *handler_obj;
461 union acpi_operand_object *obj_desc;
462 union acpi_operand_object **last_obj_ptr;
463 acpi_adr_space_setup region_setup;
464 void **region_context;
465 union acpi_operand_object *region_obj2;
466 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467
Bob Mooreb229cf92006-04-21 17:15:00 -0400468 ACPI_FUNCTION_TRACE(ev_detach_region);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469
Len Brown4be44fc2005-08-05 00:44:28 -0400470 region_obj2 = acpi_ns_get_secondary_object(region_obj);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471 if (!region_obj2) {
472 return_VOID;
473 }
474 region_context = &region_obj2->extra.region_context;
475
476 /* Get the address handler from the region object */
477
478 handler_obj = region_obj->region.handler;
479 if (!handler_obj) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400480
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481 /* This region has no handler, all done */
482
483 return_VOID;
484 }
485
486 /* Find this region in the handler's list */
487
488 obj_desc = handler_obj->address_space.region_list;
489 last_obj_ptr = &handler_obj->address_space.region_list;
490
491 while (obj_desc) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400492
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493 /* Is this the correct Region? */
494
495 if (obj_desc == region_obj) {
Len Brown4be44fc2005-08-05 00:44:28 -0400496 ACPI_DEBUG_PRINT((ACPI_DB_OPREGION,
497 "Removing Region %p from address handler %p\n",
498 region_obj, handler_obj));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499
500 /* This is it, remove it from the handler's list */
501
502 *last_obj_ptr = obj_desc->region.next;
Len Brown4be44fc2005-08-05 00:44:28 -0400503 obj_desc->region.next = NULL; /* Must clear field */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504
505 if (acpi_ns_is_locked) {
Len Brown4be44fc2005-08-05 00:44:28 -0400506 status =
507 acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
508 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 return_VOID;
510 }
511 }
512
513 /* Now stop region accesses by executing the _REG method */
514
Len Brown4be44fc2005-08-05 00:44:28 -0400515 status = acpi_ev_execute_reg_method(region_obj, 0);
516 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500517 ACPI_EXCEPTION((AE_INFO, status,
518 "from region _REG, [%s]",
519 acpi_ut_get_region_name
520 (region_obj->region.space_id)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 }
522
523 if (acpi_ns_is_locked) {
Len Brown4be44fc2005-08-05 00:44:28 -0400524 status =
525 acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
526 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527 return_VOID;
528 }
529 }
530
531 /* Call the setup handler with the deactivate notification */
532
533 region_setup = handler_obj->address_space.setup;
Len Brown4be44fc2005-08-05 00:44:28 -0400534 status =
535 region_setup(region_obj, ACPI_REGION_DEACTIVATE,
536 handler_obj->address_space.context,
537 region_context);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538
539 /* Init routine may fail, Just ignore errors */
540
Len Brown4be44fc2005-08-05 00:44:28 -0400541 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500542 ACPI_EXCEPTION((AE_INFO, status,
543 "from region init, [%s]",
544 acpi_ut_get_region_name
545 (region_obj->region.space_id)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546 }
547
548 region_obj->region.flags &= ~(AOPOBJ_SETUP_COMPLETE);
549
550 /*
551 * Remove handler reference in the region
552 *
553 * NOTE: this doesn't mean that the region goes away
554 * The region is just inaccessible as indicated to
555 * the _REG method
556 *
557 * If the region is on the handler's list
558 * this better be the region's handler
559 */
560 region_obj->region.handler = NULL;
Len Brown4be44fc2005-08-05 00:44:28 -0400561 acpi_ut_remove_reference(handler_obj);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562
563 return_VOID;
564 }
565
566 /* Walk the linked list of handlers */
567
568 last_obj_ptr = &obj_desc->region.next;
569 obj_desc = obj_desc->region.next;
570 }
571
572 /* If we get here, the region was not in the handler's region list */
573
Len Brown4be44fc2005-08-05 00:44:28 -0400574 ACPI_DEBUG_PRINT((ACPI_DB_OPREGION,
575 "Cannot remove region %p from address handler %p\n",
576 region_obj, handler_obj));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577
578 return_VOID;
579}
580
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581/*******************************************************************************
582 *
583 * FUNCTION: acpi_ev_attach_region
584 *
585 * PARAMETERS: handler_obj - Handler Object
586 * region_obj - Region Object
587 * acpi_ns_is_locked - Namespace Region Already Locked?
588 *
589 * RETURN: None
590 *
591 * DESCRIPTION: Create the association between the handler and the region
592 * this is a two way association.
593 *
594 ******************************************************************************/
595
596acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400597acpi_ev_attach_region(union acpi_operand_object *handler_obj,
598 union acpi_operand_object *region_obj,
599 u8 acpi_ns_is_locked)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600{
601
Bob Mooreb229cf92006-04-21 17:15:00 -0400602 ACPI_FUNCTION_TRACE(ev_attach_region);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603
Len Brown4be44fc2005-08-05 00:44:28 -0400604 ACPI_DEBUG_PRINT((ACPI_DB_OPREGION,
605 "Adding Region [%4.4s] %p to address handler %p [%s]\n",
606 acpi_ut_get_node_name(region_obj->region.node),
607 region_obj, handler_obj,
608 acpi_ut_get_region_name(region_obj->region.
609 space_id)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610
611 /* Link this region to the front of the handler's list */
612
613 region_obj->region.next = handler_obj->address_space.region_list;
614 handler_obj->address_space.region_list = region_obj;
615
616 /* Install the region's handler */
617
618 if (region_obj->region.handler) {
Len Brown4be44fc2005-08-05 00:44:28 -0400619 return_ACPI_STATUS(AE_ALREADY_EXISTS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620 }
621
622 region_obj->region.handler = handler_obj;
Len Brown4be44fc2005-08-05 00:44:28 -0400623 acpi_ut_add_reference(handler_obj);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624
Len Brown4be44fc2005-08-05 00:44:28 -0400625 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626}
627
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628/*******************************************************************************
629 *
630 * FUNCTION: acpi_ev_install_handler
631 *
632 * PARAMETERS: walk_namespace callback
633 *
634 * DESCRIPTION: This routine installs an address handler into objects that are
635 * of type Region or Device.
636 *
637 * If the Object is a Device, and the device has a handler of
638 * the same type then the search is terminated in that branch.
639 *
640 * This is because the existing handler is closer in proximity
641 * to any more regions than the one we are trying to install.
642 *
643 ******************************************************************************/
644
Robert Moore44f6c012005-04-18 22:49:35 -0400645static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400646acpi_ev_install_handler(acpi_handle obj_handle,
647 u32 level, void *context, void **return_value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648{
Len Brown4be44fc2005-08-05 00:44:28 -0400649 union acpi_operand_object *handler_obj;
650 union acpi_operand_object *next_handler_obj;
651 union acpi_operand_object *obj_desc;
652 struct acpi_namespace_node *node;
653 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654
Bob Mooreb229cf92006-04-21 17:15:00 -0400655 ACPI_FUNCTION_NAME(ev_install_handler);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656
Len Brown4be44fc2005-08-05 00:44:28 -0400657 handler_obj = (union acpi_operand_object *)context;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658
659 /* Parameter validation */
660
661 if (!handler_obj) {
662 return (AE_OK);
663 }
664
665 /* Convert and validate the device handle */
666
Len Brown4be44fc2005-08-05 00:44:28 -0400667 node = acpi_ns_map_handle_to_node(obj_handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668 if (!node) {
669 return (AE_BAD_PARAMETER);
670 }
671
672 /*
673 * We only care about regions.and objects
674 * that are allowed to have address space handlers
675 */
676 if ((node->type != ACPI_TYPE_DEVICE) &&
Len Brown4be44fc2005-08-05 00:44:28 -0400677 (node->type != ACPI_TYPE_REGION) && (node != acpi_gbl_root_node)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678 return (AE_OK);
679 }
680
681 /* Check for an existing internal object */
682
Len Brown4be44fc2005-08-05 00:44:28 -0400683 obj_desc = acpi_ns_get_attached_object(node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684 if (!obj_desc) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400685
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686 /* No object, just exit */
687
688 return (AE_OK);
689 }
690
691 /* Devices are handled different than regions */
692
Len Brown4be44fc2005-08-05 00:44:28 -0400693 if (ACPI_GET_OBJECT_TYPE(obj_desc) == ACPI_TYPE_DEVICE) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400694
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695 /* Check if this Device already has a handler for this address space */
696
697 next_handler_obj = obj_desc->device.handler;
698 while (next_handler_obj) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400699
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700 /* Found a handler, is it for the same address space? */
701
Len Brown4be44fc2005-08-05 00:44:28 -0400702 if (next_handler_obj->address_space.space_id ==
703 handler_obj->address_space.space_id) {
704 ACPI_DEBUG_PRINT((ACPI_DB_OPREGION,
705 "Found handler for region [%s] in device %p(%p) handler %p\n",
706 acpi_ut_get_region_name
707 (handler_obj->address_space.
708 space_id), obj_desc,
709 next_handler_obj,
710 handler_obj));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711
712 /*
713 * Since the object we found it on was a device, then it
714 * means that someone has already installed a handler for
715 * the branch of the namespace from this device on. Just
716 * bail out telling the walk routine to not traverse this
717 * branch. This preserves the scoping rule for handlers.
718 */
719 return (AE_CTRL_DEPTH);
720 }
721
722 /* Walk the linked list of handlers attached to this device */
723
724 next_handler_obj = next_handler_obj->address_space.next;
725 }
726
727 /*
728 * As long as the device didn't have a handler for this
729 * space we don't care about it. We just ignore it and
730 * proceed.
731 */
732 return (AE_OK);
733 }
734
735 /* Object is a Region */
736
737 if (obj_desc->region.space_id != handler_obj->address_space.space_id) {
738 /*
739 * This region is for a different address space
740 * -- just ignore it
741 */
742 return (AE_OK);
743 }
744
745 /*
746 * Now we have a region and it is for the handler's address
747 * space type.
748 *
749 * First disconnect region for any previous handler (if any)
750 */
Len Brown4be44fc2005-08-05 00:44:28 -0400751 acpi_ev_detach_region(obj_desc, FALSE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752
753 /* Connect the region to the new handler */
754
Len Brown4be44fc2005-08-05 00:44:28 -0400755 status = acpi_ev_attach_region(handler_obj, obj_desc, FALSE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756 return (status);
757}
758
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759/*******************************************************************************
760 *
761 * FUNCTION: acpi_ev_install_space_handler
762 *
763 * PARAMETERS: Node - Namespace node for the device
764 * space_id - The address space ID
765 * Handler - Address of the handler
766 * Setup - Address of the setup function
767 * Context - Value passed to the handler on each access
768 *
769 * RETURN: Status
770 *
771 * DESCRIPTION: Install a handler for all op_regions of a given space_id.
772 * Assumes namespace is locked
773 *
774 ******************************************************************************/
775
776acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400777acpi_ev_install_space_handler(struct acpi_namespace_node * node,
778 acpi_adr_space_type space_id,
779 acpi_adr_space_handler handler,
780 acpi_adr_space_setup setup, void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781{
Len Brown4be44fc2005-08-05 00:44:28 -0400782 union acpi_operand_object *obj_desc;
783 union acpi_operand_object *handler_obj;
784 acpi_status status;
785 acpi_object_type type;
Bob Moore616861242006-03-17 16:44:00 -0500786 u8 flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787
Bob Mooreb229cf92006-04-21 17:15:00 -0400788 ACPI_FUNCTION_TRACE(ev_install_space_handler);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789
790 /*
791 * This registration is valid for only the types below
792 * and the root. This is where the default handlers
793 * get placed.
794 */
Len Brown4be44fc2005-08-05 00:44:28 -0400795 if ((node->type != ACPI_TYPE_DEVICE) &&
796 (node->type != ACPI_TYPE_PROCESSOR) &&
797 (node->type != ACPI_TYPE_THERMAL) && (node != acpi_gbl_root_node)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798 status = AE_BAD_PARAMETER;
799 goto unlock_and_exit;
800 }
801
802 if (handler == ACPI_DEFAULT_HANDLER) {
803 flags = ACPI_ADDR_HANDLER_DEFAULT_INSTALLED;
804
805 switch (space_id) {
806 case ACPI_ADR_SPACE_SYSTEM_MEMORY:
807 handler = acpi_ex_system_memory_space_handler;
Len Brown4be44fc2005-08-05 00:44:28 -0400808 setup = acpi_ev_system_memory_region_setup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809 break;
810
811 case ACPI_ADR_SPACE_SYSTEM_IO:
812 handler = acpi_ex_system_io_space_handler;
Len Brown4be44fc2005-08-05 00:44:28 -0400813 setup = acpi_ev_io_space_region_setup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814 break;
815
816 case ACPI_ADR_SPACE_PCI_CONFIG:
817 handler = acpi_ex_pci_config_space_handler;
Len Brown4be44fc2005-08-05 00:44:28 -0400818 setup = acpi_ev_pci_config_region_setup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819 break;
820
821 case ACPI_ADR_SPACE_CMOS:
822 handler = acpi_ex_cmos_space_handler;
Len Brown4be44fc2005-08-05 00:44:28 -0400823 setup = acpi_ev_cmos_region_setup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824 break;
825
826 case ACPI_ADR_SPACE_PCI_BAR_TARGET:
827 handler = acpi_ex_pci_bar_space_handler;
Len Brown4be44fc2005-08-05 00:44:28 -0400828 setup = acpi_ev_pci_bar_region_setup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829 break;
830
831 case ACPI_ADR_SPACE_DATA_TABLE:
832 handler = acpi_ex_data_table_space_handler;
Len Brown4be44fc2005-08-05 00:44:28 -0400833 setup = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834 break;
835
836 default:
837 status = AE_BAD_PARAMETER;
838 goto unlock_and_exit;
839 }
840 }
841
842 /* If the caller hasn't specified a setup routine, use the default */
843
844 if (!setup) {
845 setup = acpi_ev_default_region_setup;
846 }
847
848 /* Check for an existing internal object */
849
Len Brown4be44fc2005-08-05 00:44:28 -0400850 obj_desc = acpi_ns_get_attached_object(node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851 if (obj_desc) {
852 /*
853 * The attached device object already exists.
854 * Make sure the handler is not already installed.
855 */
856 handler_obj = obj_desc->device.handler;
857
858 /* Walk the handler list for this device */
859
860 while (handler_obj) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400861
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862 /* Same space_id indicates a handler already installed */
863
864 if (handler_obj->address_space.space_id == space_id) {
Len Brown4be44fc2005-08-05 00:44:28 -0400865 if (handler_obj->address_space.handler ==
866 handler) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867 /*
868 * It is (relatively) OK to attempt to install the SAME
Robert Moore44f6c012005-04-18 22:49:35 -0400869 * handler twice. This can easily happen
870 * with PCI_Config space.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871 */
872 status = AE_SAME_HANDLER;
873 goto unlock_and_exit;
Len Brown4be44fc2005-08-05 00:44:28 -0400874 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875 /* A handler is already installed */
876
877 status = AE_ALREADY_EXISTS;
878 }
879 goto unlock_and_exit;
880 }
881
882 /* Walk the linked list of handlers */
883
884 handler_obj = handler_obj->address_space.next;
885 }
Len Brown4be44fc2005-08-05 00:44:28 -0400886 } else {
887 ACPI_DEBUG_PRINT((ACPI_DB_OPREGION,
888 "Creating object on Device %p while installing handler\n",
889 node));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890
891 /* obj_desc does not exist, create one */
892
893 if (node->type == ACPI_TYPE_ANY) {
894 type = ACPI_TYPE_DEVICE;
Len Brown4be44fc2005-08-05 00:44:28 -0400895 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896 type = node->type;
897 }
898
Len Brown4be44fc2005-08-05 00:44:28 -0400899 obj_desc = acpi_ut_create_internal_object(type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700900 if (!obj_desc) {
901 status = AE_NO_MEMORY;
902 goto unlock_and_exit;
903 }
904
905 /* Init new descriptor */
906
907 obj_desc->common.type = (u8) type;
908
909 /* Attach the new object to the Node */
910
Len Brown4be44fc2005-08-05 00:44:28 -0400911 status = acpi_ns_attach_object(node, obj_desc, type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700912
913 /* Remove local reference to the object */
914
Len Brown4be44fc2005-08-05 00:44:28 -0400915 acpi_ut_remove_reference(obj_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916
Len Brown4be44fc2005-08-05 00:44:28 -0400917 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918 goto unlock_and_exit;
919 }
920 }
921
Len Brown4be44fc2005-08-05 00:44:28 -0400922 ACPI_DEBUG_PRINT((ACPI_DB_OPREGION,
923 "Installing address handler for region %s(%X) on Device %4.4s %p(%p)\n",
924 acpi_ut_get_region_name(space_id), space_id,
925 acpi_ut_get_node_name(node), node, obj_desc));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926
927 /*
928 * Install the handler
929 *
930 * At this point there is no existing handler.
931 * Just allocate the object for the handler and link it
932 * into the list.
933 */
Len Brown4be44fc2005-08-05 00:44:28 -0400934 handler_obj =
935 acpi_ut_create_internal_object(ACPI_TYPE_LOCAL_ADDRESS_HANDLER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936 if (!handler_obj) {
937 status = AE_NO_MEMORY;
938 goto unlock_and_exit;
939 }
940
941 /* Init handler obj */
942
Len Brown4be44fc2005-08-05 00:44:28 -0400943 handler_obj->address_space.space_id = (u8) space_id;
Bob Moore616861242006-03-17 16:44:00 -0500944 handler_obj->address_space.handler_flags = flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700945 handler_obj->address_space.region_list = NULL;
Len Brown4be44fc2005-08-05 00:44:28 -0400946 handler_obj->address_space.node = node;
947 handler_obj->address_space.handler = handler;
948 handler_obj->address_space.context = context;
949 handler_obj->address_space.setup = setup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950
951 /* Install at head of Device.address_space list */
952
Len Brown4be44fc2005-08-05 00:44:28 -0400953 handler_obj->address_space.next = obj_desc->device.handler;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954
955 /*
956 * The Device object is the first reference on the handler_obj.
957 * Each region that uses the handler adds a reference.
958 */
959 obj_desc->device.handler = handler_obj;
960
961 /*
962 * Walk the namespace finding all of the regions this
963 * handler will manage.
964 *
965 * Start at the device and search the branch toward
966 * the leaf nodes until either the leaf is encountered or
967 * a device is detected that has an address handler of the
968 * same type.
969 *
970 * In either case, back up and search down the remainder
971 * of the branch
972 */
Len Brown4be44fc2005-08-05 00:44:28 -0400973 status = acpi_ns_walk_namespace(ACPI_TYPE_ANY, node, ACPI_UINT32_MAX,
974 ACPI_NS_WALK_UNLOCK,
975 acpi_ev_install_handler, handler_obj,
976 NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700977
Len Brown4be44fc2005-08-05 00:44:28 -0400978 unlock_and_exit:
979 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700980}
981
Linus Torvalds1da177e2005-04-16 15:20:36 -0700982/*******************************************************************************
983 *
984 * FUNCTION: acpi_ev_execute_reg_methods
985 *
986 * PARAMETERS: Node - Namespace node for the device
987 * space_id - The address space ID
988 *
989 * RETURN: Status
990 *
991 * DESCRIPTION: Run all _REG methods for the input Space ID;
992 * Note: assumes namespace is locked, or system init time.
993 *
994 ******************************************************************************/
995
996acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400997acpi_ev_execute_reg_methods(struct acpi_namespace_node *node,
998 acpi_adr_space_type space_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700999{
Len Brown4be44fc2005-08-05 00:44:28 -04001000 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001001
Bob Mooreb229cf92006-04-21 17:15:00 -04001002 ACPI_FUNCTION_TRACE(ev_execute_reg_methods);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003
1004 /*
1005 * Run all _REG methods for all Operation Regions for this
1006 * space ID. This is a separate walk in order to handle any
1007 * interdependencies between regions and _REG methods. (i.e. handlers
1008 * must be installed for all regions of this Space ID before we
1009 * can run any _REG methods)
1010 */
Len Brown4be44fc2005-08-05 00:44:28 -04001011 status = acpi_ns_walk_namespace(ACPI_TYPE_ANY, node, ACPI_UINT32_MAX,
1012 ACPI_NS_WALK_UNLOCK, acpi_ev_reg_run,
1013 &space_id, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001014
Len Brown4be44fc2005-08-05 00:44:28 -04001015 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001016}
1017
Linus Torvalds1da177e2005-04-16 15:20:36 -07001018/*******************************************************************************
1019 *
1020 * FUNCTION: acpi_ev_reg_run
1021 *
1022 * PARAMETERS: walk_namespace callback
1023 *
Bob Moore958dd242006-05-12 17:12:00 -04001024 * DESCRIPTION: Run _REG method for region objects of the requested space_iD
Linus Torvalds1da177e2005-04-16 15:20:36 -07001025 *
1026 ******************************************************************************/
1027
Robert Moore44f6c012005-04-18 22:49:35 -04001028static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -04001029acpi_ev_reg_run(acpi_handle obj_handle,
1030 u32 level, void *context, void **return_value)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001031{
Len Brown4be44fc2005-08-05 00:44:28 -04001032 union acpi_operand_object *obj_desc;
1033 struct acpi_namespace_node *node;
1034 acpi_adr_space_type space_id;
1035 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001036
Len Brown4be44fc2005-08-05 00:44:28 -04001037 space_id = *ACPI_CAST_PTR(acpi_adr_space_type, context);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001038
1039 /* Convert and validate the device handle */
1040
Len Brown4be44fc2005-08-05 00:44:28 -04001041 node = acpi_ns_map_handle_to_node(obj_handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001042 if (!node) {
1043 return (AE_BAD_PARAMETER);
1044 }
1045
1046 /*
1047 * We only care about regions.and objects
1048 * that are allowed to have address space handlers
1049 */
Len Brown4be44fc2005-08-05 00:44:28 -04001050 if ((node->type != ACPI_TYPE_REGION) && (node != acpi_gbl_root_node)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001051 return (AE_OK);
1052 }
1053
1054 /* Check for an existing internal object */
1055
Len Brown4be44fc2005-08-05 00:44:28 -04001056 obj_desc = acpi_ns_get_attached_object(node);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057 if (!obj_desc) {
Bob Moore52fc0b02006-10-02 00:00:00 -04001058
Linus Torvalds1da177e2005-04-16 15:20:36 -07001059 /* No object, just exit */
1060
1061 return (AE_OK);
1062 }
1063
1064 /* Object is a Region */
1065
1066 if (obj_desc->region.space_id != space_id) {
1067 /*
1068 * This region is for a different address space
1069 * -- just ignore it
1070 */
1071 return (AE_OK);
1072 }
1073
Len Brown4be44fc2005-08-05 00:44:28 -04001074 status = acpi_ev_execute_reg_method(obj_desc, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001075 return (status);
1076}