blob: 665c0887ab4de9af51e4414106539058e9bc909b [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/*
Len Brown75a44ce2008-04-23 23:00:13 -04008 * Copyright (C) 2000 - 2008, Intel Corp.
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>
Len Browne2f7a772009-01-09 00:30:03 -050045#include "accommon.h"
46#include "acevents.h"
47#include "acnamesp.h"
48#include "acinterp.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
50#define _COMPONENT ACPI_EVENTS
Len Brown4be44fc2005-08-05 00:44:28 -040051ACPI_MODULE_NAME("evregion")
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
Robert Moore44f6c012005-04-18 22:49:35 -040053/* Local prototypes */
Robert Moore44f6c012005-04-18 22:49:35 -040054static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -040055acpi_ev_reg_run(acpi_handle obj_handle,
56 u32 level, void *context, void **return_value);
Robert Moore44f6c012005-04-18 22:49:35 -040057
58static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -040059acpi_ev_install_handler(acpi_handle obj_handle,
60 u32 level, void *context, void **return_value);
Linus Torvalds1da177e2005-04-16 15:20:36 -070061
Bob Moore9f15fc62008-11-12 16:01:56 +080062/* These are the address spaces that will get default handlers */
63
64#define ACPI_NUM_DEFAULT_SPACES 4
65
66static u8 acpi_gbl_default_address_spaces[ACPI_NUM_DEFAULT_SPACES] = {
67 ACPI_ADR_SPACE_SYSTEM_MEMORY,
68 ACPI_ADR_SPACE_SYSTEM_IO,
69 ACPI_ADR_SPACE_PCI_CONFIG,
70 ACPI_ADR_SPACE_DATA_TABLE
71};
72
Linus Torvalds1da177e2005-04-16 15:20:36 -070073/*******************************************************************************
74 *
75 * FUNCTION: acpi_ev_install_region_handlers
76 *
77 * PARAMETERS: None
78 *
79 * RETURN: Status
80 *
81 * DESCRIPTION: Installs the core subsystem default address space handlers.
82 *
83 ******************************************************************************/
84
Len Brown4be44fc2005-08-05 00:44:28 -040085acpi_status acpi_ev_install_region_handlers(void)
86{
87 acpi_status status;
Bob Moore67a119f2008-06-10 13:42:13 +080088 u32 i;
Linus Torvalds1da177e2005-04-16 15:20:36 -070089
Bob Mooreb229cf92006-04-21 17:15:00 -040090 ACPI_FUNCTION_TRACE(ev_install_region_handlers);
Linus Torvalds1da177e2005-04-16 15:20:36 -070091
Len Brown4be44fc2005-08-05 00:44:28 -040092 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
93 if (ACPI_FAILURE(status)) {
94 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -070095 }
96
97 /*
Bob Moore9f15fc62008-11-12 16:01:56 +080098 * All address spaces (PCI Config, EC, SMBus) are scope dependent and
99 * registration must occur for a specific device.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100 *
Bob Moore9f15fc62008-11-12 16:01:56 +0800101 * In the case of the system memory and IO address spaces there is
102 * currently no device associated with the address space. For these we
103 * use the root.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104 *
Bob Moore9f15fc62008-11-12 16:01:56 +0800105 * We install the default PCI config space handler at the root so that
106 * this space is immediately available even though the we have not
107 * enumerated all the PCI Root Buses yet. This is to conform to the ACPI
108 * specification which states that the PCI config space must be always
109 * available -- even though we are nowhere near ready to find the PCI root
110 * buses at this point.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111 *
112 * NOTE: We ignore AE_ALREADY_EXISTS because this means that a handler
113 * has already been installed (via acpi_install_address_space_handler).
114 * Similar for AE_SAME_HANDLER.
115 */
116 for (i = 0; i < ACPI_NUM_DEFAULT_SPACES; i++) {
Len Brown4be44fc2005-08-05 00:44:28 -0400117 status = acpi_ev_install_space_handler(acpi_gbl_root_node,
118 acpi_gbl_default_address_spaces
119 [i],
120 ACPI_DEFAULT_HANDLER,
121 NULL, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 switch (status) {
123 case AE_OK:
124 case AE_SAME_HANDLER:
125 case AE_ALREADY_EXISTS:
126
127 /* These exceptions are all OK */
128
129 status = AE_OK;
130 break;
131
132 default:
133
134 goto unlock_and_exit;
135 }
136 }
137
Len Brown4be44fc2005-08-05 00:44:28 -0400138 unlock_and_exit:
139 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
140 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141}
142
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143/*******************************************************************************
144 *
145 * FUNCTION: acpi_ev_initialize_op_regions
146 *
147 * PARAMETERS: None
148 *
149 * RETURN: Status
150 *
151 * DESCRIPTION: Execute _REG methods for all Operation Regions that have
152 * an installed default region handler.
153 *
154 ******************************************************************************/
155
Len Brown4be44fc2005-08-05 00:44:28 -0400156acpi_status acpi_ev_initialize_op_regions(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157{
Len Brown4be44fc2005-08-05 00:44:28 -0400158 acpi_status status;
Bob Moore67a119f2008-06-10 13:42:13 +0800159 u32 i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160
Bob Mooreb229cf92006-04-21 17:15:00 -0400161 ACPI_FUNCTION_TRACE(ev_initialize_op_regions);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162
Len Brown4be44fc2005-08-05 00:44:28 -0400163 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
164 if (ACPI_FAILURE(status)) {
165 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166 }
167
Bob Moore9f15fc62008-11-12 16:01:56 +0800168 /* Run the _REG methods for op_regions in each default address space */
Bob Moore52fc0b02006-10-02 00:00:00 -0400169
Bob Moore9f15fc62008-11-12 16:01:56 +0800170 for (i = 0; i < ACPI_NUM_DEFAULT_SPACES; i++) {
171 /*
172 * TBD: Make sure handler is the DEFAULT handler, otherwise
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173 * _REG will have already been run.
174 */
Len Brown4be44fc2005-08-05 00:44:28 -0400175 status = acpi_ev_execute_reg_methods(acpi_gbl_root_node,
176 acpi_gbl_default_address_spaces
177 [i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178 }
179
Len Brown4be44fc2005-08-05 00:44:28 -0400180 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
181 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182}
183
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184/*******************************************************************************
185 *
186 * FUNCTION: acpi_ev_execute_reg_method
187 *
Robert Moore44f6c012005-04-18 22:49:35 -0400188 * PARAMETERS: region_obj - Region object
189 * Function - Passed to _REG: On (1) or Off (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190 *
191 * RETURN: Status
192 *
193 * DESCRIPTION: Execute _REG method for a region
194 *
195 ******************************************************************************/
196
197acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400198acpi_ev_execute_reg_method(union acpi_operand_object *region_obj, u32 function)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199{
Bob Moore41195322006-05-26 16:36:00 -0400200 struct acpi_evaluate_info *info;
201 union acpi_operand_object *args[3];
Len Brown4be44fc2005-08-05 00:44:28 -0400202 union acpi_operand_object *region_obj2;
203 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204
Bob Mooreb229cf92006-04-21 17:15:00 -0400205 ACPI_FUNCTION_TRACE(ev_execute_reg_method);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206
Len Brown4be44fc2005-08-05 00:44:28 -0400207 region_obj2 = acpi_ns_get_secondary_object(region_obj);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208 if (!region_obj2) {
Len Brown4be44fc2005-08-05 00:44:28 -0400209 return_ACPI_STATUS(AE_NOT_EXIST);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210 }
211
212 if (region_obj2->extra.method_REG == NULL) {
Len Brown4be44fc2005-08-05 00:44:28 -0400213 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214 }
215
Bob Moore41195322006-05-26 16:36:00 -0400216 /* Allocate and initialize the evaluation information block */
217
218 info = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_evaluate_info));
219 if (!info) {
Len Brown4be44fc2005-08-05 00:44:28 -0400220 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221 }
222
Bob Moore41195322006-05-26 16:36:00 -0400223 info->prefix_node = region_obj2->extra.method_REG;
224 info->pathname = NULL;
225 info->parameters = args;
Bob Moore41195322006-05-26 16:36:00 -0400226 info->flags = ACPI_IGNORE_RETURN_VALUE;
227
228 /*
229 * The _REG method has two arguments:
230 *
231 * Arg0 - Integer:
232 * Operation region space ID Same value as region_obj->Region.space_id
233 *
234 * Arg1 - Integer:
235 * connection status 1 for connecting the handler, 0 for disconnecting
236 * the handler (Passed as a parameter)
237 */
238 args[0] = acpi_ut_create_internal_object(ACPI_TYPE_INTEGER);
239 if (!args[0]) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240 status = AE_NO_MEMORY;
Bob Moore41195322006-05-26 16:36:00 -0400241 goto cleanup1;
242 }
243
244 args[1] = acpi_ut_create_internal_object(ACPI_TYPE_INTEGER);
245 if (!args[1]) {
246 status = AE_NO_MEMORY;
247 goto cleanup2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248 }
249
250 /* Setup the parameter objects */
251
Bob Moore41195322006-05-26 16:36:00 -0400252 args[0]->integer.value = region_obj->region.space_id;
253 args[1]->integer.value = function;
254 args[2] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255
256 /* Execute the method, no return value */
257
Len Brown4be44fc2005-08-05 00:44:28 -0400258 ACPI_DEBUG_EXEC(acpi_ut_display_init_pathname
Bob Moore41195322006-05-26 16:36:00 -0400259 (ACPI_TYPE_METHOD, info->prefix_node, NULL));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260
Bob Moore41195322006-05-26 16:36:00 -0400261 status = acpi_ns_evaluate(info);
262 acpi_ut_remove_reference(args[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263
Bob Moore41195322006-05-26 16:36:00 -0400264 cleanup2:
265 acpi_ut_remove_reference(args[0]);
266
267 cleanup1:
268 ACPI_FREE(info);
Len Brown4be44fc2005-08-05 00:44:28 -0400269 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270}
271
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272/*******************************************************************************
273 *
274 * FUNCTION: acpi_ev_address_space_dispatch
275 *
276 * PARAMETERS: region_obj - Internal region object
277 * Function - Read or Write operation
278 * Address - Where in the space to read or write
279 * bit_width - Field width in bits (8, 16, 32, or 64)
Bob Moore958dd242006-05-12 17:12:00 -0400280 * Value - Pointer to in or out value, must be
281 * full 64-bit acpi_integer
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282 *
283 * RETURN: Status
284 *
285 * DESCRIPTION: Dispatch an address space or operation region access to
286 * a previously installed handler.
287 *
288 ******************************************************************************/
289
290acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400291acpi_ev_address_space_dispatch(union acpi_operand_object *region_obj,
292 u32 function,
293 acpi_physical_address address,
Bob Moore958dd242006-05-12 17:12:00 -0400294 u32 bit_width, acpi_integer * value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295{
Len Brown4be44fc2005-08-05 00:44:28 -0400296 acpi_status status;
Len Brown4be44fc2005-08-05 00:44:28 -0400297 acpi_adr_space_handler handler;
298 acpi_adr_space_setup region_setup;
299 union acpi_operand_object *handler_desc;
300 union acpi_operand_object *region_obj2;
301 void *region_context = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302
Bob Mooreb229cf92006-04-21 17:15:00 -0400303 ACPI_FUNCTION_TRACE(ev_address_space_dispatch);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304
Len Brown4be44fc2005-08-05 00:44:28 -0400305 region_obj2 = acpi_ns_get_secondary_object(region_obj);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306 if (!region_obj2) {
Len Brown4be44fc2005-08-05 00:44:28 -0400307 return_ACPI_STATUS(AE_NOT_EXIST);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308 }
309
310 /* Ensure that there is a handler associated with this region */
311
312 handler_desc = region_obj->region.handler;
313 if (!handler_desc) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500314 ACPI_ERROR((AE_INFO,
315 "No handler for Region [%4.4s] (%p) [%s]",
316 acpi_ut_get_node_name(region_obj->region.node),
317 region_obj,
318 acpi_ut_get_region_name(region_obj->region.
319 space_id)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320
Len Brown4be44fc2005-08-05 00:44:28 -0400321 return_ACPI_STATUS(AE_NOT_EXIST);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322 }
323
324 /*
Bob Moore9f15fc62008-11-12 16:01:56 +0800325 * It may be the case that the region has never been initialized.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326 * Some types of regions require special init code
327 */
328 if (!(region_obj->region.flags & AOPOBJ_SETUP_COMPLETE)) {
Bob Moore9f15fc62008-11-12 16:01:56 +0800329
330 /* This region has not been initialized yet, do it */
331
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332 region_setup = handler_desc->address_space.setup;
333 if (!region_setup) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400334
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335 /* No initialization routine, exit with error */
336
Bob Mooreb8e4d892006-01-27 16:43:00 -0500337 ACPI_ERROR((AE_INFO,
338 "No init routine for region(%p) [%s]",
339 region_obj,
340 acpi_ut_get_region_name(region_obj->region.
341 space_id)));
Len Brown4be44fc2005-08-05 00:44:28 -0400342 return_ACPI_STATUS(AE_NOT_EXIST);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343 }
344
345 /*
Bob Moore9f15fc62008-11-12 16:01:56 +0800346 * We must exit the interpreter because the region setup will
347 * potentially execute control methods (for example, the _REG method
348 * for this region)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349 */
Bob Moore014d4332008-01-10 23:04:10 -0500350 acpi_ex_exit_interpreter();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351
Len Brown4be44fc2005-08-05 00:44:28 -0400352 status = region_setup(region_obj, ACPI_REGION_ACTIVATE,
353 handler_desc->address_space.context,
354 &region_context);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355
356 /* Re-enter the interpreter */
357
Bob Moore014d4332008-01-10 23:04:10 -0500358 acpi_ex_enter_interpreter();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359
360 /* Check for failure of the Region Setup */
361
Len Brown4be44fc2005-08-05 00:44:28 -0400362 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500363 ACPI_EXCEPTION((AE_INFO, status,
364 "During region initialization: [%s]",
365 acpi_ut_get_region_name(region_obj->
366 region.
367 space_id)));
Len Brown4be44fc2005-08-05 00:44:28 -0400368 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369 }
370
Bob Moore9f15fc62008-11-12 16:01:56 +0800371 /* Region initialization may have been completed by region_setup */
372
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373 if (!(region_obj->region.flags & AOPOBJ_SETUP_COMPLETE)) {
374 region_obj->region.flags |= AOPOBJ_SETUP_COMPLETE;
375
376 if (region_obj2->extra.region_context) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400377
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378 /* The handler for this region was already installed */
379
Bob Moore83135242006-10-03 00:00:00 -0400380 ACPI_FREE(region_context);
Len Brown4be44fc2005-08-05 00:44:28 -0400381 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382 /*
383 * Save the returned context for use in all accesses to
384 * this particular region
385 */
Len Brown4be44fc2005-08-05 00:44:28 -0400386 region_obj2->extra.region_context =
387 region_context;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388 }
389 }
390 }
391
392 /* We have everything we need, we can invoke the address space handler */
393
394 handler = handler_desc->address_space.handler;
395
Len Brown4be44fc2005-08-05 00:44:28 -0400396 ACPI_DEBUG_PRINT((ACPI_DB_OPREGION,
397 "Handler %p (@%p) Address %8.8X%8.8X [%s]\n",
398 &region_obj->region.handler->address_space, handler,
Bob Moore1d18c052008-04-10 19:06:40 +0400399 ACPI_FORMAT_NATIVE_UINT(address),
Len Brown4be44fc2005-08-05 00:44:28 -0400400 acpi_ut_get_region_name(region_obj->region.
401 space_id)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402
Bob Moore616861242006-03-17 16:44:00 -0500403 if (!(handler_desc->address_space.handler_flags &
404 ACPI_ADDR_HANDLER_DEFAULT_INSTALLED)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 /*
406 * For handlers other than the default (supplied) handlers, we must
407 * exit the interpreter because the handler *might* block -- we don't
408 * know what it will do, so we can't hold the lock on the intepreter.
409 */
Bob Moore014d4332008-01-10 23:04:10 -0500410 acpi_ex_exit_interpreter();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411 }
412
413 /* Call the handler */
414
Len Brown4be44fc2005-08-05 00:44:28 -0400415 status = handler(function, address, bit_width, value,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416 handler_desc->address_space.context,
417 region_obj2->extra.region_context);
418
Len Brown4be44fc2005-08-05 00:44:28 -0400419 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500420 ACPI_EXCEPTION((AE_INFO, status, "Returned by Handler for [%s]",
421 acpi_ut_get_region_name(region_obj->region.
422 space_id)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 }
424
Bob Moore616861242006-03-17 16:44:00 -0500425 if (!(handler_desc->address_space.handler_flags &
426 ACPI_ADDR_HANDLER_DEFAULT_INSTALLED)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427 /*
428 * We just returned from a non-default handler, we must re-enter the
429 * interpreter
430 */
Bob Moore014d4332008-01-10 23:04:10 -0500431 acpi_ex_enter_interpreter();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432 }
433
Len Brown4be44fc2005-08-05 00:44:28 -0400434 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435}
436
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437/*******************************************************************************
438 *
439 * FUNCTION: acpi_ev_detach_region
440 *
441 * PARAMETERS: region_obj - Region Object
442 * acpi_ns_is_locked - Namespace Region Already Locked?
443 *
444 * RETURN: None
445 *
446 * DESCRIPTION: Break the association between the handler and the region
447 * this is a two way association.
448 *
449 ******************************************************************************/
450
451void
Len Brown4be44fc2005-08-05 00:44:28 -0400452acpi_ev_detach_region(union acpi_operand_object *region_obj,
453 u8 acpi_ns_is_locked)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454{
Len Brown4be44fc2005-08-05 00:44:28 -0400455 union acpi_operand_object *handler_obj;
456 union acpi_operand_object *obj_desc;
457 union acpi_operand_object **last_obj_ptr;
458 acpi_adr_space_setup region_setup;
459 void **region_context;
460 union acpi_operand_object *region_obj2;
461 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462
Bob Mooreb229cf92006-04-21 17:15:00 -0400463 ACPI_FUNCTION_TRACE(ev_detach_region);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464
Len Brown4be44fc2005-08-05 00:44:28 -0400465 region_obj2 = acpi_ns_get_secondary_object(region_obj);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466 if (!region_obj2) {
467 return_VOID;
468 }
469 region_context = &region_obj2->extra.region_context;
470
471 /* Get the address handler from the region object */
472
473 handler_obj = region_obj->region.handler;
474 if (!handler_obj) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400475
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476 /* This region has no handler, all done */
477
478 return_VOID;
479 }
480
481 /* Find this region in the handler's list */
482
483 obj_desc = handler_obj->address_space.region_list;
484 last_obj_ptr = &handler_obj->address_space.region_list;
485
486 while (obj_desc) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400487
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488 /* Is this the correct Region? */
489
490 if (obj_desc == region_obj) {
Len Brown4be44fc2005-08-05 00:44:28 -0400491 ACPI_DEBUG_PRINT((ACPI_DB_OPREGION,
492 "Removing Region %p from address handler %p\n",
493 region_obj, handler_obj));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494
495 /* This is it, remove it from the handler's list */
496
497 *last_obj_ptr = obj_desc->region.next;
Len Brown4be44fc2005-08-05 00:44:28 -0400498 obj_desc->region.next = NULL; /* Must clear field */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499
500 if (acpi_ns_is_locked) {
Len Brown4be44fc2005-08-05 00:44:28 -0400501 status =
502 acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
503 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504 return_VOID;
505 }
506 }
507
508 /* Now stop region accesses by executing the _REG method */
509
Len Brown4be44fc2005-08-05 00:44:28 -0400510 status = acpi_ev_execute_reg_method(region_obj, 0);
511 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500512 ACPI_EXCEPTION((AE_INFO, status,
513 "from region _REG, [%s]",
514 acpi_ut_get_region_name
515 (region_obj->region.space_id)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516 }
517
518 if (acpi_ns_is_locked) {
Len Brown4be44fc2005-08-05 00:44:28 -0400519 status =
520 acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
521 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 return_VOID;
523 }
524 }
525
Bob Mooref6dd9222006-07-07 20:44:38 -0400526 /*
Bob Moore9f15fc62008-11-12 16:01:56 +0800527 * If the region has been activated, call the setup handler with
528 * the deactivate notification
Bob Mooref6dd9222006-07-07 20:44:38 -0400529 */
530 if (region_obj->region.flags & AOPOBJ_SETUP_COMPLETE) {
531 region_setup = handler_obj->address_space.setup;
532 status =
533 region_setup(region_obj,
534 ACPI_REGION_DEACTIVATE,
535 handler_obj->address_space.
536 context, region_context);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537
Bob Mooref6dd9222006-07-07 20:44:38 -0400538 /* Init routine may fail, Just ignore errors */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539
Bob Mooref6dd9222006-07-07 20:44:38 -0400540 if (ACPI_FAILURE(status)) {
541 ACPI_EXCEPTION((AE_INFO, status,
542 "from region handler - deactivate, [%s]",
543 acpi_ut_get_region_name
544 (region_obj->region.
545 space_id)));
546 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547
Bob Mooref6dd9222006-07-07 20:44:38 -0400548 region_obj->region.flags &=
549 ~(AOPOBJ_SETUP_COMPLETE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550 }
551
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552 /*
553 * Remove handler reference in the region
554 *
Bob Mooref6dd9222006-07-07 20:44:38 -0400555 * NOTE: this doesn't mean that the region goes away, the region
556 * is just inaccessible as indicated to the _REG method
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 *
Bob Mooref6dd9222006-07-07 20:44:38 -0400558 * If the region is on the handler's list, this must be the
559 * region's handler
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560 */
561 region_obj->region.handler = NULL;
Len Brown4be44fc2005-08-05 00:44:28 -0400562 acpi_ut_remove_reference(handler_obj);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563
564 return_VOID;
565 }
566
567 /* Walk the linked list of handlers */
568
569 last_obj_ptr = &obj_desc->region.next;
570 obj_desc = obj_desc->region.next;
571 }
572
573 /* If we get here, the region was not in the handler's region list */
574
Len Brown4be44fc2005-08-05 00:44:28 -0400575 ACPI_DEBUG_PRINT((ACPI_DB_OPREGION,
576 "Cannot remove region %p from address handler %p\n",
577 region_obj, handler_obj));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578
579 return_VOID;
580}
581
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582/*******************************************************************************
583 *
584 * FUNCTION: acpi_ev_attach_region
585 *
586 * PARAMETERS: handler_obj - Handler Object
587 * region_obj - Region Object
588 * acpi_ns_is_locked - Namespace Region Already Locked?
589 *
590 * RETURN: None
591 *
592 * DESCRIPTION: Create the association between the handler and the region
593 * this is a two way association.
594 *
595 ******************************************************************************/
596
597acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400598acpi_ev_attach_region(union acpi_operand_object *handler_obj,
599 union acpi_operand_object *region_obj,
600 u8 acpi_ns_is_locked)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601{
602
Bob Mooreb229cf92006-04-21 17:15:00 -0400603 ACPI_FUNCTION_TRACE(ev_attach_region);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604
Len Brown4be44fc2005-08-05 00:44:28 -0400605 ACPI_DEBUG_PRINT((ACPI_DB_OPREGION,
606 "Adding Region [%4.4s] %p to address handler %p [%s]\n",
607 acpi_ut_get_node_name(region_obj->region.node),
608 region_obj, handler_obj,
609 acpi_ut_get_region_name(region_obj->region.
610 space_id)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611
612 /* Link this region to the front of the handler's list */
613
614 region_obj->region.next = handler_obj->address_space.region_list;
615 handler_obj->address_space.region_list = region_obj;
616
617 /* Install the region's handler */
618
619 if (region_obj->region.handler) {
Len Brown4be44fc2005-08-05 00:44:28 -0400620 return_ACPI_STATUS(AE_ALREADY_EXISTS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621 }
622
623 region_obj->region.handler = handler_obj;
Len Brown4be44fc2005-08-05 00:44:28 -0400624 acpi_ut_add_reference(handler_obj);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625
Len Brown4be44fc2005-08-05 00:44:28 -0400626 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627}
628
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629/*******************************************************************************
630 *
631 * FUNCTION: acpi_ev_install_handler
632 *
633 * PARAMETERS: walk_namespace callback
634 *
635 * DESCRIPTION: This routine installs an address handler into objects that are
636 * of type Region or Device.
637 *
638 * If the Object is a Device, and the device has a handler of
639 * the same type then the search is terminated in that branch.
640 *
641 * This is because the existing handler is closer in proximity
642 * to any more regions than the one we are trying to install.
643 *
644 ******************************************************************************/
645
Robert Moore44f6c012005-04-18 22:49:35 -0400646static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400647acpi_ev_install_handler(acpi_handle obj_handle,
648 u32 level, void *context, void **return_value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649{
Len Brown4be44fc2005-08-05 00:44:28 -0400650 union acpi_operand_object *handler_obj;
651 union acpi_operand_object *next_handler_obj;
652 union acpi_operand_object *obj_desc;
653 struct acpi_namespace_node *node;
654 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655
Bob Mooreb229cf92006-04-21 17:15:00 -0400656 ACPI_FUNCTION_NAME(ev_install_handler);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657
Len Brown4be44fc2005-08-05 00:44:28 -0400658 handler_obj = (union acpi_operand_object *)context;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659
660 /* Parameter validation */
661
662 if (!handler_obj) {
663 return (AE_OK);
664 }
665
666 /* Convert and validate the device handle */
667
Len Brown4be44fc2005-08-05 00:44:28 -0400668 node = acpi_ns_map_handle_to_node(obj_handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669 if (!node) {
670 return (AE_BAD_PARAMETER);
671 }
672
673 /*
Bob Moore9f15fc62008-11-12 16:01:56 +0800674 * We only care about regions and objects that are allowed to have
675 * address space handlers
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676 */
677 if ((node->type != ACPI_TYPE_DEVICE) &&
Len Brown4be44fc2005-08-05 00:44:28 -0400678 (node->type != ACPI_TYPE_REGION) && (node != acpi_gbl_root_node)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679 return (AE_OK);
680 }
681
682 /* Check for an existing internal object */
683
Len Brown4be44fc2005-08-05 00:44:28 -0400684 obj_desc = acpi_ns_get_attached_object(node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685 if (!obj_desc) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400686
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687 /* No object, just exit */
688
689 return (AE_OK);
690 }
691
692 /* Devices are handled different than regions */
693
Len Brown4be44fc2005-08-05 00:44:28 -0400694 if (ACPI_GET_OBJECT_TYPE(obj_desc) == ACPI_TYPE_DEVICE) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400695
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696 /* Check if this Device already has a handler for this address space */
697
698 next_handler_obj = obj_desc->device.handler;
699 while (next_handler_obj) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400700
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701 /* Found a handler, is it for the same address space? */
702
Len Brown4be44fc2005-08-05 00:44:28 -0400703 if (next_handler_obj->address_space.space_id ==
704 handler_obj->address_space.space_id) {
705 ACPI_DEBUG_PRINT((ACPI_DB_OPREGION,
706 "Found handler for region [%s] in device %p(%p) handler %p\n",
707 acpi_ut_get_region_name
708 (handler_obj->address_space.
709 space_id), obj_desc,
710 next_handler_obj,
711 handler_obj));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712
713 /*
714 * Since the object we found it on was a device, then it
715 * means that someone has already installed a handler for
Bob Moore9f15fc62008-11-12 16:01:56 +0800716 * the branch of the namespace from this device on. Just
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717 * bail out telling the walk routine to not traverse this
Bob Moore9f15fc62008-11-12 16:01:56 +0800718 * branch. This preserves the scoping rule for handlers.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719 */
720 return (AE_CTRL_DEPTH);
721 }
722
723 /* Walk the linked list of handlers attached to this device */
724
725 next_handler_obj = next_handler_obj->address_space.next;
726 }
727
728 /*
Bob Moore9f15fc62008-11-12 16:01:56 +0800729 * As long as the device didn't have a handler for this space we
730 * don't care about it. We just ignore it and proceed.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731 */
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) {
Bob Moore9f15fc62008-11-12 16:01:56 +0800738
739 /* This region is for a different address space, just ignore it */
740
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741 return (AE_OK);
742 }
743
744 /*
Bob Moore9f15fc62008-11-12 16:01:56 +0800745 * Now we have a region and it is for the handler's address space type.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746 *
747 * First disconnect region for any previous handler (if any)
748 */
Len Brown4be44fc2005-08-05 00:44:28 -0400749 acpi_ev_detach_region(obj_desc, FALSE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750
751 /* Connect the region to the new handler */
752
Len Brown4be44fc2005-08-05 00:44:28 -0400753 status = acpi_ev_attach_region(handler_obj, obj_desc, FALSE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754 return (status);
755}
756
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757/*******************************************************************************
758 *
759 * FUNCTION: acpi_ev_install_space_handler
760 *
761 * PARAMETERS: Node - Namespace node for the device
762 * space_id - The address space ID
763 * Handler - Address of the handler
764 * Setup - Address of the setup function
765 * Context - Value passed to the handler on each access
766 *
767 * RETURN: Status
768 *
769 * DESCRIPTION: Install a handler for all op_regions of a given space_id.
770 * Assumes namespace is locked
771 *
772 ******************************************************************************/
773
774acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400775acpi_ev_install_space_handler(struct acpi_namespace_node * node,
776 acpi_adr_space_type space_id,
777 acpi_adr_space_handler handler,
778 acpi_adr_space_setup setup, void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779{
Len Brown4be44fc2005-08-05 00:44:28 -0400780 union acpi_operand_object *obj_desc;
781 union acpi_operand_object *handler_obj;
782 acpi_status status;
783 acpi_object_type type;
Bob Moore616861242006-03-17 16:44:00 -0500784 u8 flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785
Bob Mooreb229cf92006-04-21 17:15:00 -0400786 ACPI_FUNCTION_TRACE(ev_install_space_handler);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787
788 /*
Bob Moore9f15fc62008-11-12 16:01:56 +0800789 * This registration is valid for only the types below and the root. This
790 * is where the default handlers get placed.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791 */
Len Brown4be44fc2005-08-05 00:44:28 -0400792 if ((node->type != ACPI_TYPE_DEVICE) &&
793 (node->type != ACPI_TYPE_PROCESSOR) &&
794 (node->type != ACPI_TYPE_THERMAL) && (node != acpi_gbl_root_node)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795 status = AE_BAD_PARAMETER;
796 goto unlock_and_exit;
797 }
798
799 if (handler == ACPI_DEFAULT_HANDLER) {
800 flags = ACPI_ADDR_HANDLER_DEFAULT_INSTALLED;
801
802 switch (space_id) {
803 case ACPI_ADR_SPACE_SYSTEM_MEMORY:
804 handler = acpi_ex_system_memory_space_handler;
Len Brown4be44fc2005-08-05 00:44:28 -0400805 setup = acpi_ev_system_memory_region_setup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806 break;
807
808 case ACPI_ADR_SPACE_SYSTEM_IO:
809 handler = acpi_ex_system_io_space_handler;
Len Brown4be44fc2005-08-05 00:44:28 -0400810 setup = acpi_ev_io_space_region_setup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811 break;
812
813 case ACPI_ADR_SPACE_PCI_CONFIG:
814 handler = acpi_ex_pci_config_space_handler;
Len Brown4be44fc2005-08-05 00:44:28 -0400815 setup = acpi_ev_pci_config_region_setup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816 break;
817
818 case ACPI_ADR_SPACE_CMOS:
819 handler = acpi_ex_cmos_space_handler;
Len Brown4be44fc2005-08-05 00:44:28 -0400820 setup = acpi_ev_cmos_region_setup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821 break;
822
823 case ACPI_ADR_SPACE_PCI_BAR_TARGET:
824 handler = acpi_ex_pci_bar_space_handler;
Len Brown4be44fc2005-08-05 00:44:28 -0400825 setup = acpi_ev_pci_bar_region_setup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826 break;
827
828 case ACPI_ADR_SPACE_DATA_TABLE:
829 handler = acpi_ex_data_table_space_handler;
Len Brown4be44fc2005-08-05 00:44:28 -0400830 setup = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831 break;
832
833 default:
834 status = AE_BAD_PARAMETER;
835 goto unlock_and_exit;
836 }
837 }
838
839 /* If the caller hasn't specified a setup routine, use the default */
840
841 if (!setup) {
842 setup = acpi_ev_default_region_setup;
843 }
844
845 /* Check for an existing internal object */
846
Len Brown4be44fc2005-08-05 00:44:28 -0400847 obj_desc = acpi_ns_get_attached_object(node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700848 if (obj_desc) {
849 /*
Bob Moore9f15fc62008-11-12 16:01:56 +0800850 * The attached device object already exists. Make sure the handler
851 * is not already installed.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852 */
853 handler_obj = obj_desc->device.handler;
854
855 /* Walk the handler list for this device */
856
857 while (handler_obj) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400858
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859 /* Same space_id indicates a handler already installed */
860
861 if (handler_obj->address_space.space_id == space_id) {
Len Brown4be44fc2005-08-05 00:44:28 -0400862 if (handler_obj->address_space.handler ==
863 handler) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864 /*
865 * It is (relatively) OK to attempt to install the SAME
Bob Moore9f15fc62008-11-12 16:01:56 +0800866 * handler twice. This can easily happen with the
867 * PCI_Config space.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700868 */
869 status = AE_SAME_HANDLER;
870 goto unlock_and_exit;
Len Brown4be44fc2005-08-05 00:44:28 -0400871 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872 /* A handler is already installed */
873
874 status = AE_ALREADY_EXISTS;
875 }
876 goto unlock_and_exit;
877 }
878
879 /* Walk the linked list of handlers */
880
881 handler_obj = handler_obj->address_space.next;
882 }
Len Brown4be44fc2005-08-05 00:44:28 -0400883 } else {
884 ACPI_DEBUG_PRINT((ACPI_DB_OPREGION,
885 "Creating object on Device %p while installing handler\n",
886 node));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700887
888 /* obj_desc does not exist, create one */
889
890 if (node->type == ACPI_TYPE_ANY) {
891 type = ACPI_TYPE_DEVICE;
Len Brown4be44fc2005-08-05 00:44:28 -0400892 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893 type = node->type;
894 }
895
Len Brown4be44fc2005-08-05 00:44:28 -0400896 obj_desc = acpi_ut_create_internal_object(type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700897 if (!obj_desc) {
898 status = AE_NO_MEMORY;
899 goto unlock_and_exit;
900 }
901
902 /* Init new descriptor */
903
904 obj_desc->common.type = (u8) type;
905
906 /* Attach the new object to the Node */
907
Len Brown4be44fc2005-08-05 00:44:28 -0400908 status = acpi_ns_attach_object(node, obj_desc, type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700909
910 /* Remove local reference to the object */
911
Len Brown4be44fc2005-08-05 00:44:28 -0400912 acpi_ut_remove_reference(obj_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700913
Len Brown4be44fc2005-08-05 00:44:28 -0400914 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915 goto unlock_and_exit;
916 }
917 }
918
Len Brown4be44fc2005-08-05 00:44:28 -0400919 ACPI_DEBUG_PRINT((ACPI_DB_OPREGION,
920 "Installing address handler for region %s(%X) on Device %4.4s %p(%p)\n",
921 acpi_ut_get_region_name(space_id), space_id,
922 acpi_ut_get_node_name(node), node, obj_desc));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923
924 /*
925 * Install the handler
926 *
Bob Moore9f15fc62008-11-12 16:01:56 +0800927 * At this point there is no existing handler. Just allocate the object
928 * for the handler and link it into the list.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929 */
Len Brown4be44fc2005-08-05 00:44:28 -0400930 handler_obj =
931 acpi_ut_create_internal_object(ACPI_TYPE_LOCAL_ADDRESS_HANDLER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932 if (!handler_obj) {
933 status = AE_NO_MEMORY;
934 goto unlock_and_exit;
935 }
936
937 /* Init handler obj */
938
Len Brown4be44fc2005-08-05 00:44:28 -0400939 handler_obj->address_space.space_id = (u8) space_id;
Bob Moore616861242006-03-17 16:44:00 -0500940 handler_obj->address_space.handler_flags = flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941 handler_obj->address_space.region_list = NULL;
Len Brown4be44fc2005-08-05 00:44:28 -0400942 handler_obj->address_space.node = node;
943 handler_obj->address_space.handler = handler;
944 handler_obj->address_space.context = context;
945 handler_obj->address_space.setup = setup;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700946
947 /* Install at head of Device.address_space list */
948
Len Brown4be44fc2005-08-05 00:44:28 -0400949 handler_obj->address_space.next = obj_desc->device.handler;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950
951 /*
952 * The Device object is the first reference on the handler_obj.
953 * Each region that uses the handler adds a reference.
954 */
955 obj_desc->device.handler = handler_obj;
956
957 /*
958 * Walk the namespace finding all of the regions this
959 * handler will manage.
960 *
961 * Start at the device and search the branch toward
962 * the leaf nodes until either the leaf is encountered or
963 * a device is detected that has an address handler of the
964 * same type.
965 *
966 * In either case, back up and search down the remainder
967 * of the branch
968 */
Len Brown4be44fc2005-08-05 00:44:28 -0400969 status = acpi_ns_walk_namespace(ACPI_TYPE_ANY, node, ACPI_UINT32_MAX,
970 ACPI_NS_WALK_UNLOCK,
971 acpi_ev_install_handler, handler_obj,
972 NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700973
Len Brown4be44fc2005-08-05 00:44:28 -0400974 unlock_and_exit:
975 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976}
977
Linus Torvalds1da177e2005-04-16 15:20:36 -0700978/*******************************************************************************
979 *
980 * FUNCTION: acpi_ev_execute_reg_methods
981 *
982 * PARAMETERS: Node - Namespace node for the device
983 * space_id - The address space ID
984 *
985 * RETURN: Status
986 *
987 * DESCRIPTION: Run all _REG methods for the input Space ID;
988 * Note: assumes namespace is locked, or system init time.
989 *
990 ******************************************************************************/
991
992acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400993acpi_ev_execute_reg_methods(struct acpi_namespace_node *node,
994 acpi_adr_space_type space_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995{
Len Brown4be44fc2005-08-05 00:44:28 -0400996 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700997
Bob Mooreb229cf92006-04-21 17:15:00 -0400998 ACPI_FUNCTION_TRACE(ev_execute_reg_methods);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700999
1000 /*
Bob Moore9f15fc62008-11-12 16:01:56 +08001001 * Run all _REG methods for all Operation Regions for this space ID. This
1002 * is a separate walk in order to handle any interdependencies between
1003 * regions and _REG methods. (i.e. handlers must be installed for all
1004 * regions of this Space ID before we can run any _REG methods)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001005 */
Len Brown4be44fc2005-08-05 00:44:28 -04001006 status = acpi_ns_walk_namespace(ACPI_TYPE_ANY, node, ACPI_UINT32_MAX,
1007 ACPI_NS_WALK_UNLOCK, acpi_ev_reg_run,
1008 &space_id, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001009
Len Brown4be44fc2005-08-05 00:44:28 -04001010 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011}
1012
Linus Torvalds1da177e2005-04-16 15:20:36 -07001013/*******************************************************************************
1014 *
1015 * FUNCTION: acpi_ev_reg_run
1016 *
1017 * PARAMETERS: walk_namespace callback
1018 *
Bob Moore958dd242006-05-12 17:12:00 -04001019 * DESCRIPTION: Run _REG method for region objects of the requested space_iD
Linus Torvalds1da177e2005-04-16 15:20:36 -07001020 *
1021 ******************************************************************************/
1022
Robert Moore44f6c012005-04-18 22:49:35 -04001023static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -04001024acpi_ev_reg_run(acpi_handle obj_handle,
1025 u32 level, void *context, void **return_value)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001026{
Len Brown4be44fc2005-08-05 00:44:28 -04001027 union acpi_operand_object *obj_desc;
1028 struct acpi_namespace_node *node;
1029 acpi_adr_space_type space_id;
1030 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001031
Len Brown4be44fc2005-08-05 00:44:28 -04001032 space_id = *ACPI_CAST_PTR(acpi_adr_space_type, context);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001033
1034 /* Convert and validate the device handle */
1035
Len Brown4be44fc2005-08-05 00:44:28 -04001036 node = acpi_ns_map_handle_to_node(obj_handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001037 if (!node) {
1038 return (AE_BAD_PARAMETER);
1039 }
1040
1041 /*
Bob Moore9f15fc62008-11-12 16:01:56 +08001042 * We only care about regions.and objects that are allowed to have address
1043 * space handlers
Linus Torvalds1da177e2005-04-16 15:20:36 -07001044 */
Len Brown4be44fc2005-08-05 00:44:28 -04001045 if ((node->type != ACPI_TYPE_REGION) && (node != acpi_gbl_root_node)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001046 return (AE_OK);
1047 }
1048
1049 /* Check for an existing internal object */
1050
Len Brown4be44fc2005-08-05 00:44:28 -04001051 obj_desc = acpi_ns_get_attached_object(node);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001052 if (!obj_desc) {
Bob Moore52fc0b02006-10-02 00:00:00 -04001053
Linus Torvalds1da177e2005-04-16 15:20:36 -07001054 /* No object, just exit */
1055
1056 return (AE_OK);
1057 }
1058
1059 /* Object is a Region */
1060
1061 if (obj_desc->region.space_id != space_id) {
Bob Moore9f15fc62008-11-12 16:01:56 +08001062
1063 /* This region is for a different address space, just ignore it */
1064
Linus Torvalds1da177e2005-04-16 15:20:36 -07001065 return (AE_OK);
1066 }
1067
Len Brown4be44fc2005-08-05 00:44:28 -04001068 status = acpi_ev_execute_reg_method(obj_desc, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069 return (status);
1070}