]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /****************************************************************************** |
2 | * | |
3 | * Module Name: evregion - ACPI address_space (op_region) handler dispatch | |
4 | * | |
5 | *****************************************************************************/ | |
6 | ||
7 | /* | |
a8357b0c | 8 | * Copyright (C) 2000 - 2010, Intel Corp. |
1da177e4 LT |
9 | * All rights reserved. |
10 | * | |
11 | * Redistribution and use in source and binary forms, with or without | |
12 | * modification, are permitted provided that the following conditions | |
13 | * are met: | |
14 | * 1. Redistributions of source code must retain the above copyright | |
15 | * notice, this list of conditions, and the following disclaimer, | |
16 | * without modification. | |
17 | * 2. Redistributions in binary form must reproduce at minimum a disclaimer | |
18 | * substantially similar to the "NO WARRANTY" disclaimer below | |
19 | * ("Disclaimer") and any redistribution must be conditioned upon | |
20 | * including a substantially similar Disclaimer requirement for further | |
21 | * binary redistribution. | |
22 | * 3. Neither the names of the above-listed copyright holders nor the names | |
23 | * of any contributors may be used to endorse or promote products derived | |
24 | * from this software without specific prior written permission. | |
25 | * | |
26 | * Alternatively, this software may be distributed under the terms of the | |
27 | * GNU General Public License ("GPL") version 2 as published by the Free | |
28 | * Software Foundation. | |
29 | * | |
30 | * NO WARRANTY | |
31 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
32 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
33 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR | |
34 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
35 | * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
36 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
37 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
38 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | |
39 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING | |
40 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
41 | * POSSIBILITY OF SUCH DAMAGES. | |
42 | */ | |
43 | ||
1da177e4 | 44 | #include <acpi/acpi.h> |
e2f7a777 LB |
45 | #include "accommon.h" |
46 | #include "acevents.h" | |
47 | #include "acnamesp.h" | |
48 | #include "acinterp.h" | |
1da177e4 LT |
49 | |
50 | #define _COMPONENT ACPI_EVENTS | |
4be44fcd | 51 | ACPI_MODULE_NAME("evregion") |
1da177e4 | 52 | |
44f6c012 | 53 | /* Local prototypes */ |
74d3ec77 LM |
54 | static u8 |
55 | acpi_ev_has_default_handler(struct acpi_namespace_node *node, | |
56 | acpi_adr_space_type space_id); | |
57 | ||
44f6c012 | 58 | static acpi_status |
4be44fcd LB |
59 | acpi_ev_reg_run(acpi_handle obj_handle, |
60 | u32 level, void *context, void **return_value); | |
44f6c012 RM |
61 | |
62 | static acpi_status | |
4be44fcd LB |
63 | acpi_ev_install_handler(acpi_handle obj_handle, |
64 | u32 level, void *context, void **return_value); | |
1da177e4 | 65 | |
9f15fc66 BM |
66 | /* These are the address spaces that will get default handlers */ |
67 | ||
68 | #define ACPI_NUM_DEFAULT_SPACES 4 | |
69 | ||
70 | static u8 acpi_gbl_default_address_spaces[ACPI_NUM_DEFAULT_SPACES] = { | |
71 | ACPI_ADR_SPACE_SYSTEM_MEMORY, | |
72 | ACPI_ADR_SPACE_SYSTEM_IO, | |
73 | ACPI_ADR_SPACE_PCI_CONFIG, | |
74 | ACPI_ADR_SPACE_DATA_TABLE | |
75 | }; | |
76 | ||
1da177e4 LT |
77 | /******************************************************************************* |
78 | * | |
79 | * FUNCTION: acpi_ev_install_region_handlers | |
80 | * | |
81 | * PARAMETERS: None | |
82 | * | |
83 | * RETURN: Status | |
84 | * | |
85 | * DESCRIPTION: Installs the core subsystem default address space handlers. | |
86 | * | |
87 | ******************************************************************************/ | |
88 | ||
4be44fcd LB |
89 | acpi_status acpi_ev_install_region_handlers(void) |
90 | { | |
91 | acpi_status status; | |
67a119f9 | 92 | u32 i; |
1da177e4 | 93 | |
b229cf92 | 94 | ACPI_FUNCTION_TRACE(ev_install_region_handlers); |
1da177e4 | 95 | |
4be44fcd LB |
96 | status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); |
97 | if (ACPI_FAILURE(status)) { | |
98 | return_ACPI_STATUS(status); | |
1da177e4 LT |
99 | } |
100 | ||
101 | /* | |
9f15fc66 BM |
102 | * All address spaces (PCI Config, EC, SMBus) are scope dependent and |
103 | * registration must occur for a specific device. | |
1da177e4 | 104 | * |
9f15fc66 BM |
105 | * In the case of the system memory and IO address spaces there is |
106 | * currently no device associated with the address space. For these we | |
107 | * use the root. | |
1da177e4 | 108 | * |
9f15fc66 BM |
109 | * We install the default PCI config space handler at the root so that |
110 | * this space is immediately available even though the we have not | |
111 | * enumerated all the PCI Root Buses yet. This is to conform to the ACPI | |
112 | * specification which states that the PCI config space must be always | |
113 | * available -- even though we are nowhere near ready to find the PCI root | |
114 | * buses at this point. | |
1da177e4 LT |
115 | * |
116 | * NOTE: We ignore AE_ALREADY_EXISTS because this means that a handler | |
117 | * has already been installed (via acpi_install_address_space_handler). | |
118 | * Similar for AE_SAME_HANDLER. | |
119 | */ | |
120 | for (i = 0; i < ACPI_NUM_DEFAULT_SPACES; i++) { | |
4be44fcd LB |
121 | status = acpi_ev_install_space_handler(acpi_gbl_root_node, |
122 | acpi_gbl_default_address_spaces | |
123 | [i], | |
124 | ACPI_DEFAULT_HANDLER, | |
125 | NULL, NULL); | |
1da177e4 LT |
126 | switch (status) { |
127 | case AE_OK: | |
128 | case AE_SAME_HANDLER: | |
129 | case AE_ALREADY_EXISTS: | |
130 | ||
131 | /* These exceptions are all OK */ | |
132 | ||
133 | status = AE_OK; | |
134 | break; | |
135 | ||
136 | default: | |
137 | ||
138 | goto unlock_and_exit; | |
139 | } | |
140 | } | |
141 | ||
4be44fcd LB |
142 | unlock_and_exit: |
143 | (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); | |
144 | return_ACPI_STATUS(status); | |
1da177e4 LT |
145 | } |
146 | ||
74d3ec77 LM |
147 | /******************************************************************************* |
148 | * | |
149 | * FUNCTION: acpi_ev_has_default_handler | |
150 | * | |
151 | * PARAMETERS: Node - Namespace node for the device | |
152 | * space_id - The address space ID | |
153 | * | |
154 | * RETURN: TRUE if default handler is installed, FALSE otherwise | |
155 | * | |
156 | * DESCRIPTION: Check if the default handler is installed for the requested | |
157 | * space ID. | |
158 | * | |
159 | ******************************************************************************/ | |
160 | ||
161 | static u8 | |
162 | acpi_ev_has_default_handler(struct acpi_namespace_node *node, | |
163 | acpi_adr_space_type space_id) | |
164 | { | |
165 | union acpi_operand_object *obj_desc; | |
166 | union acpi_operand_object *handler_obj; | |
167 | ||
168 | /* Must have an existing internal object */ | |
169 | ||
170 | obj_desc = acpi_ns_get_attached_object(node); | |
171 | if (obj_desc) { | |
172 | handler_obj = obj_desc->device.handler; | |
173 | ||
174 | /* Walk the linked list of handlers for this object */ | |
175 | ||
176 | while (handler_obj) { | |
177 | if (handler_obj->address_space.space_id == space_id) { | |
178 | if (handler_obj->address_space.handler_flags & | |
179 | ACPI_ADDR_HANDLER_DEFAULT_INSTALLED) { | |
180 | return (TRUE); | |
181 | } | |
182 | } | |
183 | ||
184 | handler_obj = handler_obj->address_space.next; | |
185 | } | |
186 | } | |
187 | ||
188 | return (FALSE); | |
189 | } | |
190 | ||
1da177e4 LT |
191 | /******************************************************************************* |
192 | * | |
193 | * FUNCTION: acpi_ev_initialize_op_regions | |
194 | * | |
195 | * PARAMETERS: None | |
196 | * | |
197 | * RETURN: Status | |
198 | * | |
199 | * DESCRIPTION: Execute _REG methods for all Operation Regions that have | |
200 | * an installed default region handler. | |
201 | * | |
202 | ******************************************************************************/ | |
203 | ||
4be44fcd | 204 | acpi_status acpi_ev_initialize_op_regions(void) |
1da177e4 | 205 | { |
4be44fcd | 206 | acpi_status status; |
67a119f9 | 207 | u32 i; |
1da177e4 | 208 | |
b229cf92 | 209 | ACPI_FUNCTION_TRACE(ev_initialize_op_regions); |
1da177e4 | 210 | |
4be44fcd LB |
211 | status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); |
212 | if (ACPI_FAILURE(status)) { | |
213 | return_ACPI_STATUS(status); | |
1da177e4 LT |
214 | } |
215 | ||
9f15fc66 | 216 | /* Run the _REG methods for op_regions in each default address space */ |
52fc0b02 | 217 | |
9f15fc66 BM |
218 | for (i = 0; i < ACPI_NUM_DEFAULT_SPACES; i++) { |
219 | /* | |
74d3ec77 LM |
220 | * Make sure the installed handler is the DEFAULT handler. If not the |
221 | * default, the _REG methods will have already been run (when the | |
222 | * handler was installed) | |
1da177e4 | 223 | */ |
74d3ec77 LM |
224 | if (acpi_ev_has_default_handler(acpi_gbl_root_node, |
225 | acpi_gbl_default_address_spaces | |
226 | [i])) { | |
227 | status = | |
228 | acpi_ev_execute_reg_methods(acpi_gbl_root_node, | |
229 | acpi_gbl_default_address_spaces | |
230 | [i]); | |
231 | } | |
1da177e4 LT |
232 | } |
233 | ||
4be44fcd LB |
234 | (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); |
235 | return_ACPI_STATUS(status); | |
1da177e4 LT |
236 | } |
237 | ||
1da177e4 LT |
238 | /******************************************************************************* |
239 | * | |
240 | * FUNCTION: acpi_ev_execute_reg_method | |
241 | * | |
44f6c012 RM |
242 | * PARAMETERS: region_obj - Region object |
243 | * Function - Passed to _REG: On (1) or Off (0) | |
1da177e4 LT |
244 | * |
245 | * RETURN: Status | |
246 | * | |
247 | * DESCRIPTION: Execute _REG method for a region | |
248 | * | |
249 | ******************************************************************************/ | |
250 | ||
251 | acpi_status | |
4be44fcd | 252 | acpi_ev_execute_reg_method(union acpi_operand_object *region_obj, u32 function) |
1da177e4 | 253 | { |
4119532c BM |
254 | struct acpi_evaluate_info *info; |
255 | union acpi_operand_object *args[3]; | |
4be44fcd LB |
256 | union acpi_operand_object *region_obj2; |
257 | acpi_status status; | |
1da177e4 | 258 | |
b229cf92 | 259 | ACPI_FUNCTION_TRACE(ev_execute_reg_method); |
1da177e4 | 260 | |
4be44fcd | 261 | region_obj2 = acpi_ns_get_secondary_object(region_obj); |
1da177e4 | 262 | if (!region_obj2) { |
4be44fcd | 263 | return_ACPI_STATUS(AE_NOT_EXIST); |
1da177e4 LT |
264 | } |
265 | ||
266 | if (region_obj2->extra.method_REG == NULL) { | |
4be44fcd | 267 | return_ACPI_STATUS(AE_OK); |
1da177e4 LT |
268 | } |
269 | ||
4119532c BM |
270 | /* Allocate and initialize the evaluation information block */ |
271 | ||
272 | info = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_evaluate_info)); | |
273 | if (!info) { | |
274 | return_ACPI_STATUS(AE_NO_MEMORY); | |
275 | } | |
276 | ||
277 | info->prefix_node = region_obj2->extra.method_REG; | |
278 | info->pathname = NULL; | |
279 | info->parameters = args; | |
4119532c BM |
280 | info->flags = ACPI_IGNORE_RETURN_VALUE; |
281 | ||
1da177e4 LT |
282 | /* |
283 | * The _REG method has two arguments: | |
284 | * | |
4119532c BM |
285 | * Arg0 - Integer: |
286 | * Operation region space ID Same value as region_obj->Region.space_id | |
287 | * | |
288 | * Arg1 - Integer: | |
289 | * connection status 1 for connecting the handler, 0 for disconnecting | |
290 | * the handler (Passed as a parameter) | |
1da177e4 | 291 | */ |
dc95a270 BM |
292 | args[0] = |
293 | acpi_ut_create_integer_object((u64) region_obj->region.space_id); | |
4119532c BM |
294 | if (!args[0]) { |
295 | status = AE_NO_MEMORY; | |
296 | goto cleanup1; | |
1da177e4 LT |
297 | } |
298 | ||
dc95a270 | 299 | args[1] = acpi_ut_create_integer_object((u64) function); |
4119532c | 300 | if (!args[1]) { |
1da177e4 | 301 | status = AE_NO_MEMORY; |
4119532c | 302 | goto cleanup2; |
1da177e4 LT |
303 | } |
304 | ||
dc95a270 | 305 | args[2] = NULL; /* Terminate list */ |
1da177e4 LT |
306 | |
307 | /* Execute the method, no return value */ | |
308 | ||
4be44fcd | 309 | ACPI_DEBUG_EXEC(acpi_ut_display_init_pathname |
4119532c BM |
310 | (ACPI_TYPE_METHOD, info->prefix_node, NULL)); |
311 | ||
312 | status = acpi_ns_evaluate(info); | |
313 | acpi_ut_remove_reference(args[1]); | |
1da177e4 | 314 | |
4119532c BM |
315 | cleanup2: |
316 | acpi_ut_remove_reference(args[0]); | |
1da177e4 | 317 | |
4119532c BM |
318 | cleanup1: |
319 | ACPI_FREE(info); | |
4be44fcd | 320 | return_ACPI_STATUS(status); |
1da177e4 LT |
321 | } |
322 | ||
1da177e4 LT |
323 | /******************************************************************************* |
324 | * | |
325 | * FUNCTION: acpi_ev_address_space_dispatch | |
326 | * | |
327 | * PARAMETERS: region_obj - Internal region object | |
328 | * Function - Read or Write operation | |
f5407af3 | 329 | * region_offset - Where in the region to read or write |
1da177e4 | 330 | * bit_width - Field width in bits (8, 16, 32, or 64) |
958dd242 | 331 | * Value - Pointer to in or out value, must be |
5df7e6cb | 332 | * a full 64-bit integer |
1da177e4 LT |
333 | * |
334 | * RETURN: Status | |
335 | * | |
336 | * DESCRIPTION: Dispatch an address space or operation region access to | |
337 | * a previously installed handler. | |
338 | * | |
339 | ******************************************************************************/ | |
340 | ||
341 | acpi_status | |
4be44fcd LB |
342 | acpi_ev_address_space_dispatch(union acpi_operand_object *region_obj, |
343 | u32 function, | |
5df7e6cb | 344 | u32 region_offset, u32 bit_width, u64 *value) |
1da177e4 | 345 | { |
4be44fcd | 346 | acpi_status status; |
4be44fcd LB |
347 | acpi_adr_space_handler handler; |
348 | acpi_adr_space_setup region_setup; | |
349 | union acpi_operand_object *handler_desc; | |
350 | union acpi_operand_object *region_obj2; | |
351 | void *region_context = NULL; | |
1da177e4 | 352 | |
b229cf92 | 353 | ACPI_FUNCTION_TRACE(ev_address_space_dispatch); |
1da177e4 | 354 | |
4be44fcd | 355 | region_obj2 = acpi_ns_get_secondary_object(region_obj); |
1da177e4 | 356 | if (!region_obj2) { |
4be44fcd | 357 | return_ACPI_STATUS(AE_NOT_EXIST); |
1da177e4 LT |
358 | } |
359 | ||
360 | /* Ensure that there is a handler associated with this region */ | |
361 | ||
362 | handler_desc = region_obj->region.handler; | |
363 | if (!handler_desc) { | |
b8e4d893 BM |
364 | ACPI_ERROR((AE_INFO, |
365 | "No handler for Region [%4.4s] (%p) [%s]", | |
366 | acpi_ut_get_node_name(region_obj->region.node), | |
367 | region_obj, | |
368 | acpi_ut_get_region_name(region_obj->region. | |
369 | space_id))); | |
4be44fcd LB |
370 | |
371 | return_ACPI_STATUS(AE_NOT_EXIST); | |
1da177e4 LT |
372 | } |
373 | ||
374 | /* | |
9f15fc66 | 375 | * It may be the case that the region has never been initialized. |
1da177e4 LT |
376 | * Some types of regions require special init code |
377 | */ | |
378 | if (!(region_obj->region.flags & AOPOBJ_SETUP_COMPLETE)) { | |
9f15fc66 BM |
379 | |
380 | /* This region has not been initialized yet, do it */ | |
381 | ||
1da177e4 LT |
382 | region_setup = handler_desc->address_space.setup; |
383 | if (!region_setup) { | |
52fc0b02 | 384 | |
1da177e4 LT |
385 | /* No initialization routine, exit with error */ |
386 | ||
b8e4d893 BM |
387 | ACPI_ERROR((AE_INFO, |
388 | "No init routine for region(%p) [%s]", | |
389 | region_obj, | |
390 | acpi_ut_get_region_name(region_obj->region. | |
391 | space_id))); | |
4be44fcd | 392 | return_ACPI_STATUS(AE_NOT_EXIST); |
1da177e4 LT |
393 | } |
394 | ||
395 | /* | |
9f15fc66 BM |
396 | * We must exit the interpreter because the region setup will |
397 | * potentially execute control methods (for example, the _REG method | |
398 | * for this region) | |
1da177e4 | 399 | */ |
014d433f | 400 | acpi_ex_exit_interpreter(); |
1da177e4 | 401 | |
4be44fcd LB |
402 | status = region_setup(region_obj, ACPI_REGION_ACTIVATE, |
403 | handler_desc->address_space.context, | |
404 | ®ion_context); | |
1da177e4 LT |
405 | |
406 | /* Re-enter the interpreter */ | |
407 | ||
014d433f | 408 | acpi_ex_enter_interpreter(); |
1da177e4 LT |
409 | |
410 | /* Check for failure of the Region Setup */ | |
411 | ||
4be44fcd | 412 | if (ACPI_FAILURE(status)) { |
b8e4d893 BM |
413 | ACPI_EXCEPTION((AE_INFO, status, |
414 | "During region initialization: [%s]", | |
415 | acpi_ut_get_region_name(region_obj-> | |
416 | region. | |
417 | space_id))); | |
4be44fcd | 418 | return_ACPI_STATUS(status); |
1da177e4 LT |
419 | } |
420 | ||
9f15fc66 BM |
421 | /* Region initialization may have been completed by region_setup */ |
422 | ||
1da177e4 LT |
423 | if (!(region_obj->region.flags & AOPOBJ_SETUP_COMPLETE)) { |
424 | region_obj->region.flags |= AOPOBJ_SETUP_COMPLETE; | |
425 | ||
426 | if (region_obj2->extra.region_context) { | |
52fc0b02 | 427 | |
1da177e4 LT |
428 | /* The handler for this region was already installed */ |
429 | ||
8313524a | 430 | ACPI_FREE(region_context); |
4be44fcd | 431 | } else { |
1da177e4 LT |
432 | /* |
433 | * Save the returned context for use in all accesses to | |
434 | * this particular region | |
435 | */ | |
4be44fcd LB |
436 | region_obj2->extra.region_context = |
437 | region_context; | |
1da177e4 LT |
438 | } |
439 | } | |
440 | } | |
441 | ||
442 | /* We have everything we need, we can invoke the address space handler */ | |
443 | ||
444 | handler = handler_desc->address_space.handler; | |
445 | ||
4be44fcd LB |
446 | ACPI_DEBUG_PRINT((ACPI_DB_OPREGION, |
447 | "Handler %p (@%p) Address %8.8X%8.8X [%s]\n", | |
448 | ®ion_obj->region.handler->address_space, handler, | |
f5407af3 BM |
449 | ACPI_FORMAT_NATIVE_UINT(region_obj->region.address + |
450 | region_offset), | |
4be44fcd LB |
451 | acpi_ut_get_region_name(region_obj->region. |
452 | space_id))); | |
1da177e4 | 453 | |
61686124 BM |
454 | if (!(handler_desc->address_space.handler_flags & |
455 | ACPI_ADDR_HANDLER_DEFAULT_INSTALLED)) { | |
1da177e4 LT |
456 | /* |
457 | * For handlers other than the default (supplied) handlers, we must | |
458 | * exit the interpreter because the handler *might* block -- we don't | |
459 | * know what it will do, so we can't hold the lock on the intepreter. | |
460 | */ | |
014d433f | 461 | acpi_ex_exit_interpreter(); |
1da177e4 LT |
462 | } |
463 | ||
464 | /* Call the handler */ | |
465 | ||
f5407af3 BM |
466 | status = handler(function, |
467 | (region_obj->region.address + region_offset), | |
468 | bit_width, value, handler_desc->address_space.context, | |
1da177e4 LT |
469 | region_obj2->extra.region_context); |
470 | ||
4be44fcd | 471 | if (ACPI_FAILURE(status)) { |
b8e4d893 BM |
472 | ACPI_EXCEPTION((AE_INFO, status, "Returned by Handler for [%s]", |
473 | acpi_ut_get_region_name(region_obj->region. | |
474 | space_id))); | |
1da177e4 LT |
475 | } |
476 | ||
61686124 BM |
477 | if (!(handler_desc->address_space.handler_flags & |
478 | ACPI_ADDR_HANDLER_DEFAULT_INSTALLED)) { | |
1da177e4 LT |
479 | /* |
480 | * We just returned from a non-default handler, we must re-enter the | |
481 | * interpreter | |
482 | */ | |
014d433f | 483 | acpi_ex_enter_interpreter(); |
1da177e4 LT |
484 | } |
485 | ||
4be44fcd | 486 | return_ACPI_STATUS(status); |
1da177e4 LT |
487 | } |
488 | ||
1da177e4 LT |
489 | /******************************************************************************* |
490 | * | |
491 | * FUNCTION: acpi_ev_detach_region | |
492 | * | |
493 | * PARAMETERS: region_obj - Region Object | |
494 | * acpi_ns_is_locked - Namespace Region Already Locked? | |
495 | * | |
496 | * RETURN: None | |
497 | * | |
498 | * DESCRIPTION: Break the association between the handler and the region | |
499 | * this is a two way association. | |
500 | * | |
501 | ******************************************************************************/ | |
502 | ||
503 | void | |
4be44fcd LB |
504 | acpi_ev_detach_region(union acpi_operand_object *region_obj, |
505 | u8 acpi_ns_is_locked) | |
1da177e4 | 506 | { |
4be44fcd LB |
507 | union acpi_operand_object *handler_obj; |
508 | union acpi_operand_object *obj_desc; | |
509 | union acpi_operand_object **last_obj_ptr; | |
510 | acpi_adr_space_setup region_setup; | |
511 | void **region_context; | |
512 | union acpi_operand_object *region_obj2; | |
513 | acpi_status status; | |
1da177e4 | 514 | |
b229cf92 | 515 | ACPI_FUNCTION_TRACE(ev_detach_region); |
1da177e4 | 516 | |
4be44fcd | 517 | region_obj2 = acpi_ns_get_secondary_object(region_obj); |
1da177e4 LT |
518 | if (!region_obj2) { |
519 | return_VOID; | |
520 | } | |
521 | region_context = ®ion_obj2->extra.region_context; | |
522 | ||
523 | /* Get the address handler from the region object */ | |
524 | ||
525 | handler_obj = region_obj->region.handler; | |
526 | if (!handler_obj) { | |
52fc0b02 | 527 | |
1da177e4 LT |
528 | /* This region has no handler, all done */ |
529 | ||
530 | return_VOID; | |
531 | } | |
532 | ||
533 | /* Find this region in the handler's list */ | |
534 | ||
535 | obj_desc = handler_obj->address_space.region_list; | |
536 | last_obj_ptr = &handler_obj->address_space.region_list; | |
537 | ||
538 | while (obj_desc) { | |
52fc0b02 | 539 | |
1da177e4 LT |
540 | /* Is this the correct Region? */ |
541 | ||
542 | if (obj_desc == region_obj) { | |
4be44fcd LB |
543 | ACPI_DEBUG_PRINT((ACPI_DB_OPREGION, |
544 | "Removing Region %p from address handler %p\n", | |
545 | region_obj, handler_obj)); | |
1da177e4 LT |
546 | |
547 | /* This is it, remove it from the handler's list */ | |
548 | ||
549 | *last_obj_ptr = obj_desc->region.next; | |
4be44fcd | 550 | obj_desc->region.next = NULL; /* Must clear field */ |
1da177e4 LT |
551 | |
552 | if (acpi_ns_is_locked) { | |
4be44fcd LB |
553 | status = |
554 | acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); | |
555 | if (ACPI_FAILURE(status)) { | |
1da177e4 LT |
556 | return_VOID; |
557 | } | |
558 | } | |
559 | ||
560 | /* Now stop region accesses by executing the _REG method */ | |
561 | ||
4be44fcd LB |
562 | status = acpi_ev_execute_reg_method(region_obj, 0); |
563 | if (ACPI_FAILURE(status)) { | |
b8e4d893 BM |
564 | ACPI_EXCEPTION((AE_INFO, status, |
565 | "from region _REG, [%s]", | |
566 | acpi_ut_get_region_name | |
567 | (region_obj->region.space_id))); | |
1da177e4 LT |
568 | } |
569 | ||
570 | if (acpi_ns_is_locked) { | |
4be44fcd LB |
571 | status = |
572 | acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); | |
573 | if (ACPI_FAILURE(status)) { | |
1da177e4 LT |
574 | return_VOID; |
575 | } | |
576 | } | |
577 | ||
f6dd9221 | 578 | /* |
9f15fc66 BM |
579 | * If the region has been activated, call the setup handler with |
580 | * the deactivate notification | |
f6dd9221 BM |
581 | */ |
582 | if (region_obj->region.flags & AOPOBJ_SETUP_COMPLETE) { | |
583 | region_setup = handler_obj->address_space.setup; | |
584 | status = | |
585 | region_setup(region_obj, | |
586 | ACPI_REGION_DEACTIVATE, | |
587 | handler_obj->address_space. | |
588 | context, region_context); | |
1da177e4 | 589 | |
f6dd9221 | 590 | /* Init routine may fail, Just ignore errors */ |
1da177e4 | 591 | |
f6dd9221 BM |
592 | if (ACPI_FAILURE(status)) { |
593 | ACPI_EXCEPTION((AE_INFO, status, | |
594 | "from region handler - deactivate, [%s]", | |
595 | acpi_ut_get_region_name | |
596 | (region_obj->region. | |
597 | space_id))); | |
598 | } | |
1da177e4 | 599 | |
f6dd9221 BM |
600 | region_obj->region.flags &= |
601 | ~(AOPOBJ_SETUP_COMPLETE); | |
1da177e4 LT |
602 | } |
603 | ||
1da177e4 LT |
604 | /* |
605 | * Remove handler reference in the region | |
606 | * | |
f6dd9221 BM |
607 | * NOTE: this doesn't mean that the region goes away, the region |
608 | * is just inaccessible as indicated to the _REG method | |
1da177e4 | 609 | * |
f6dd9221 BM |
610 | * If the region is on the handler's list, this must be the |
611 | * region's handler | |
1da177e4 LT |
612 | */ |
613 | region_obj->region.handler = NULL; | |
4be44fcd | 614 | acpi_ut_remove_reference(handler_obj); |
1da177e4 LT |
615 | |
616 | return_VOID; | |
617 | } | |
618 | ||
619 | /* Walk the linked list of handlers */ | |
620 | ||
621 | last_obj_ptr = &obj_desc->region.next; | |
622 | obj_desc = obj_desc->region.next; | |
623 | } | |
624 | ||
625 | /* If we get here, the region was not in the handler's region list */ | |
626 | ||
4be44fcd LB |
627 | ACPI_DEBUG_PRINT((ACPI_DB_OPREGION, |
628 | "Cannot remove region %p from address handler %p\n", | |
629 | region_obj, handler_obj)); | |
1da177e4 LT |
630 | |
631 | return_VOID; | |
632 | } | |
633 | ||
1da177e4 LT |
634 | /******************************************************************************* |
635 | * | |
636 | * FUNCTION: acpi_ev_attach_region | |
637 | * | |
638 | * PARAMETERS: handler_obj - Handler Object | |
639 | * region_obj - Region Object | |
640 | * acpi_ns_is_locked - Namespace Region Already Locked? | |
641 | * | |
642 | * RETURN: None | |
643 | * | |
644 | * DESCRIPTION: Create the association between the handler and the region | |
645 | * this is a two way association. | |
646 | * | |
647 | ******************************************************************************/ | |
648 | ||
649 | acpi_status | |
4be44fcd LB |
650 | acpi_ev_attach_region(union acpi_operand_object *handler_obj, |
651 | union acpi_operand_object *region_obj, | |
652 | u8 acpi_ns_is_locked) | |
1da177e4 LT |
653 | { |
654 | ||
b229cf92 | 655 | ACPI_FUNCTION_TRACE(ev_attach_region); |
1da177e4 | 656 | |
4be44fcd LB |
657 | ACPI_DEBUG_PRINT((ACPI_DB_OPREGION, |
658 | "Adding Region [%4.4s] %p to address handler %p [%s]\n", | |
659 | acpi_ut_get_node_name(region_obj->region.node), | |
660 | region_obj, handler_obj, | |
661 | acpi_ut_get_region_name(region_obj->region. | |
662 | space_id))); | |
1da177e4 LT |
663 | |
664 | /* Link this region to the front of the handler's list */ | |
665 | ||
666 | region_obj->region.next = handler_obj->address_space.region_list; | |
667 | handler_obj->address_space.region_list = region_obj; | |
668 | ||
669 | /* Install the region's handler */ | |
670 | ||
671 | if (region_obj->region.handler) { | |
4be44fcd | 672 | return_ACPI_STATUS(AE_ALREADY_EXISTS); |
1da177e4 LT |
673 | } |
674 | ||
675 | region_obj->region.handler = handler_obj; | |
4be44fcd | 676 | acpi_ut_add_reference(handler_obj); |
1da177e4 | 677 | |
4be44fcd | 678 | return_ACPI_STATUS(AE_OK); |
1da177e4 LT |
679 | } |
680 | ||
1da177e4 LT |
681 | /******************************************************************************* |
682 | * | |
683 | * FUNCTION: acpi_ev_install_handler | |
684 | * | |
685 | * PARAMETERS: walk_namespace callback | |
686 | * | |
687 | * DESCRIPTION: This routine installs an address handler into objects that are | |
688 | * of type Region or Device. | |
689 | * | |
690 | * If the Object is a Device, and the device has a handler of | |
691 | * the same type then the search is terminated in that branch. | |
692 | * | |
693 | * This is because the existing handler is closer in proximity | |
694 | * to any more regions than the one we are trying to install. | |
695 | * | |
696 | ******************************************************************************/ | |
697 | ||
44f6c012 | 698 | static acpi_status |
4be44fcd LB |
699 | acpi_ev_install_handler(acpi_handle obj_handle, |
700 | u32 level, void *context, void **return_value) | |
1da177e4 | 701 | { |
4be44fcd LB |
702 | union acpi_operand_object *handler_obj; |
703 | union acpi_operand_object *next_handler_obj; | |
704 | union acpi_operand_object *obj_desc; | |
705 | struct acpi_namespace_node *node; | |
706 | acpi_status status; | |
1da177e4 | 707 | |
b229cf92 | 708 | ACPI_FUNCTION_NAME(ev_install_handler); |
1da177e4 | 709 | |
4be44fcd | 710 | handler_obj = (union acpi_operand_object *)context; |
1da177e4 LT |
711 | |
712 | /* Parameter validation */ | |
713 | ||
714 | if (!handler_obj) { | |
715 | return (AE_OK); | |
716 | } | |
717 | ||
718 | /* Convert and validate the device handle */ | |
719 | ||
f24b664d | 720 | node = acpi_ns_validate_handle(obj_handle); |
1da177e4 LT |
721 | if (!node) { |
722 | return (AE_BAD_PARAMETER); | |
723 | } | |
724 | ||
725 | /* | |
9f15fc66 BM |
726 | * We only care about regions and objects that are allowed to have |
727 | * address space handlers | |
1da177e4 LT |
728 | */ |
729 | if ((node->type != ACPI_TYPE_DEVICE) && | |
4be44fcd | 730 | (node->type != ACPI_TYPE_REGION) && (node != acpi_gbl_root_node)) { |
1da177e4 LT |
731 | return (AE_OK); |
732 | } | |
733 | ||
734 | /* Check for an existing internal object */ | |
735 | ||
4be44fcd | 736 | obj_desc = acpi_ns_get_attached_object(node); |
1da177e4 | 737 | if (!obj_desc) { |
52fc0b02 | 738 | |
1da177e4 LT |
739 | /* No object, just exit */ |
740 | ||
741 | return (AE_OK); | |
742 | } | |
743 | ||
744 | /* Devices are handled different than regions */ | |
745 | ||
3371c19c | 746 | if (obj_desc->common.type == ACPI_TYPE_DEVICE) { |
52fc0b02 | 747 | |
1da177e4 LT |
748 | /* Check if this Device already has a handler for this address space */ |
749 | ||
750 | next_handler_obj = obj_desc->device.handler; | |
751 | while (next_handler_obj) { | |
52fc0b02 | 752 | |
1da177e4 LT |
753 | /* Found a handler, is it for the same address space? */ |
754 | ||
4be44fcd LB |
755 | if (next_handler_obj->address_space.space_id == |
756 | handler_obj->address_space.space_id) { | |
757 | ACPI_DEBUG_PRINT((ACPI_DB_OPREGION, | |
d4913dc6 BM |
758 | "Found handler for region [%s] in device %p(%p) " |
759 | "handler %p\n", | |
4be44fcd LB |
760 | acpi_ut_get_region_name |
761 | (handler_obj->address_space. | |
762 | space_id), obj_desc, | |
763 | next_handler_obj, | |
764 | handler_obj)); | |
1da177e4 LT |
765 | |
766 | /* | |
767 | * Since the object we found it on was a device, then it | |
768 | * means that someone has already installed a handler for | |
9f15fc66 | 769 | * the branch of the namespace from this device on. Just |
1da177e4 | 770 | * bail out telling the walk routine to not traverse this |
9f15fc66 | 771 | * branch. This preserves the scoping rule for handlers. |
1da177e4 LT |
772 | */ |
773 | return (AE_CTRL_DEPTH); | |
774 | } | |
775 | ||
776 | /* Walk the linked list of handlers attached to this device */ | |
777 | ||
778 | next_handler_obj = next_handler_obj->address_space.next; | |
779 | } | |
780 | ||
781 | /* | |
9f15fc66 BM |
782 | * As long as the device didn't have a handler for this space we |
783 | * don't care about it. We just ignore it and proceed. | |
1da177e4 LT |
784 | */ |
785 | return (AE_OK); | |
786 | } | |
787 | ||
788 | /* Object is a Region */ | |
789 | ||
790 | if (obj_desc->region.space_id != handler_obj->address_space.space_id) { | |
9f15fc66 BM |
791 | |
792 | /* This region is for a different address space, just ignore it */ | |
793 | ||
1da177e4 LT |
794 | return (AE_OK); |
795 | } | |
796 | ||
797 | /* | |
9f15fc66 | 798 | * Now we have a region and it is for the handler's address space type. |
1da177e4 LT |
799 | * |
800 | * First disconnect region for any previous handler (if any) | |
801 | */ | |
4be44fcd | 802 | acpi_ev_detach_region(obj_desc, FALSE); |
1da177e4 LT |
803 | |
804 | /* Connect the region to the new handler */ | |
805 | ||
4be44fcd | 806 | status = acpi_ev_attach_region(handler_obj, obj_desc, FALSE); |
1da177e4 LT |
807 | return (status); |
808 | } | |
809 | ||
1da177e4 LT |
810 | /******************************************************************************* |
811 | * | |
812 | * FUNCTION: acpi_ev_install_space_handler | |
813 | * | |
814 | * PARAMETERS: Node - Namespace node for the device | |
815 | * space_id - The address space ID | |
816 | * Handler - Address of the handler | |
817 | * Setup - Address of the setup function | |
818 | * Context - Value passed to the handler on each access | |
819 | * | |
820 | * RETURN: Status | |
821 | * | |
822 | * DESCRIPTION: Install a handler for all op_regions of a given space_id. | |
823 | * Assumes namespace is locked | |
824 | * | |
825 | ******************************************************************************/ | |
826 | ||
827 | acpi_status | |
4be44fcd LB |
828 | acpi_ev_install_space_handler(struct acpi_namespace_node * node, |
829 | acpi_adr_space_type space_id, | |
830 | acpi_adr_space_handler handler, | |
831 | acpi_adr_space_setup setup, void *context) | |
1da177e4 | 832 | { |
4be44fcd LB |
833 | union acpi_operand_object *obj_desc; |
834 | union acpi_operand_object *handler_obj; | |
835 | acpi_status status; | |
836 | acpi_object_type type; | |
61686124 | 837 | u8 flags = 0; |
1da177e4 | 838 | |
b229cf92 | 839 | ACPI_FUNCTION_TRACE(ev_install_space_handler); |
1da177e4 LT |
840 | |
841 | /* | |
9f15fc66 BM |
842 | * This registration is valid for only the types below and the root. This |
843 | * is where the default handlers get placed. | |
1da177e4 | 844 | */ |
4be44fcd LB |
845 | if ((node->type != ACPI_TYPE_DEVICE) && |
846 | (node->type != ACPI_TYPE_PROCESSOR) && | |
847 | (node->type != ACPI_TYPE_THERMAL) && (node != acpi_gbl_root_node)) { | |
1da177e4 LT |
848 | status = AE_BAD_PARAMETER; |
849 | goto unlock_and_exit; | |
850 | } | |
851 | ||
852 | if (handler == ACPI_DEFAULT_HANDLER) { | |
853 | flags = ACPI_ADDR_HANDLER_DEFAULT_INSTALLED; | |
854 | ||
855 | switch (space_id) { | |
856 | case ACPI_ADR_SPACE_SYSTEM_MEMORY: | |
857 | handler = acpi_ex_system_memory_space_handler; | |
4be44fcd | 858 | setup = acpi_ev_system_memory_region_setup; |
1da177e4 LT |
859 | break; |
860 | ||
861 | case ACPI_ADR_SPACE_SYSTEM_IO: | |
862 | handler = acpi_ex_system_io_space_handler; | |
4be44fcd | 863 | setup = acpi_ev_io_space_region_setup; |
1da177e4 LT |
864 | break; |
865 | ||
866 | case ACPI_ADR_SPACE_PCI_CONFIG: | |
867 | handler = acpi_ex_pci_config_space_handler; | |
4be44fcd | 868 | setup = acpi_ev_pci_config_region_setup; |
1da177e4 LT |
869 | break; |
870 | ||
871 | case ACPI_ADR_SPACE_CMOS: | |
872 | handler = acpi_ex_cmos_space_handler; | |
4be44fcd | 873 | setup = acpi_ev_cmos_region_setup; |
1da177e4 LT |
874 | break; |
875 | ||
876 | case ACPI_ADR_SPACE_PCI_BAR_TARGET: | |
877 | handler = acpi_ex_pci_bar_space_handler; | |
4be44fcd | 878 | setup = acpi_ev_pci_bar_region_setup; |
1da177e4 LT |
879 | break; |
880 | ||
881 | case ACPI_ADR_SPACE_DATA_TABLE: | |
882 | handler = acpi_ex_data_table_space_handler; | |
4be44fcd | 883 | setup = NULL; |
1da177e4 LT |
884 | break; |
885 | ||
886 | default: | |
887 | status = AE_BAD_PARAMETER; | |
888 | goto unlock_and_exit; | |
889 | } | |
890 | } | |
891 | ||
892 | /* If the caller hasn't specified a setup routine, use the default */ | |
893 | ||
894 | if (!setup) { | |
895 | setup = acpi_ev_default_region_setup; | |
896 | } | |
897 | ||
898 | /* Check for an existing internal object */ | |
899 | ||
4be44fcd | 900 | obj_desc = acpi_ns_get_attached_object(node); |
1da177e4 LT |
901 | if (obj_desc) { |
902 | /* | |
9f15fc66 BM |
903 | * The attached device object already exists. Make sure the handler |
904 | * is not already installed. | |
1da177e4 LT |
905 | */ |
906 | handler_obj = obj_desc->device.handler; | |
907 | ||
908 | /* Walk the handler list for this device */ | |
909 | ||
910 | while (handler_obj) { | |
52fc0b02 | 911 | |
1da177e4 LT |
912 | /* Same space_id indicates a handler already installed */ |
913 | ||
914 | if (handler_obj->address_space.space_id == space_id) { | |
4be44fcd LB |
915 | if (handler_obj->address_space.handler == |
916 | handler) { | |
1da177e4 LT |
917 | /* |
918 | * It is (relatively) OK to attempt to install the SAME | |
9f15fc66 BM |
919 | * handler twice. This can easily happen with the |
920 | * PCI_Config space. | |
1da177e4 LT |
921 | */ |
922 | status = AE_SAME_HANDLER; | |
923 | goto unlock_and_exit; | |
4be44fcd | 924 | } else { |
1da177e4 LT |
925 | /* A handler is already installed */ |
926 | ||
927 | status = AE_ALREADY_EXISTS; | |
928 | } | |
929 | goto unlock_and_exit; | |
930 | } | |
931 | ||
932 | /* Walk the linked list of handlers */ | |
933 | ||
934 | handler_obj = handler_obj->address_space.next; | |
935 | } | |
4be44fcd LB |
936 | } else { |
937 | ACPI_DEBUG_PRINT((ACPI_DB_OPREGION, | |
938 | "Creating object on Device %p while installing handler\n", | |
939 | node)); | |
1da177e4 LT |
940 | |
941 | /* obj_desc does not exist, create one */ | |
942 | ||
943 | if (node->type == ACPI_TYPE_ANY) { | |
944 | type = ACPI_TYPE_DEVICE; | |
4be44fcd | 945 | } else { |
1da177e4 LT |
946 | type = node->type; |
947 | } | |
948 | ||
4be44fcd | 949 | obj_desc = acpi_ut_create_internal_object(type); |
1da177e4 LT |
950 | if (!obj_desc) { |
951 | status = AE_NO_MEMORY; | |
952 | goto unlock_and_exit; | |
953 | } | |
954 | ||
955 | /* Init new descriptor */ | |
956 | ||
957 | obj_desc->common.type = (u8) type; | |
958 | ||
959 | /* Attach the new object to the Node */ | |
960 | ||
4be44fcd | 961 | status = acpi_ns_attach_object(node, obj_desc, type); |
1da177e4 LT |
962 | |
963 | /* Remove local reference to the object */ | |
964 | ||
4be44fcd | 965 | acpi_ut_remove_reference(obj_desc); |
1da177e4 | 966 | |
4be44fcd | 967 | if (ACPI_FAILURE(status)) { |
1da177e4 LT |
968 | goto unlock_and_exit; |
969 | } | |
970 | } | |
971 | ||
4be44fcd LB |
972 | ACPI_DEBUG_PRINT((ACPI_DB_OPREGION, |
973 | "Installing address handler for region %s(%X) on Device %4.4s %p(%p)\n", | |
974 | acpi_ut_get_region_name(space_id), space_id, | |
975 | acpi_ut_get_node_name(node), node, obj_desc)); | |
1da177e4 LT |
976 | |
977 | /* | |
978 | * Install the handler | |
979 | * | |
9f15fc66 BM |
980 | * At this point there is no existing handler. Just allocate the object |
981 | * for the handler and link it into the list. | |
1da177e4 | 982 | */ |
4be44fcd LB |
983 | handler_obj = |
984 | acpi_ut_create_internal_object(ACPI_TYPE_LOCAL_ADDRESS_HANDLER); | |
1da177e4 LT |
985 | if (!handler_obj) { |
986 | status = AE_NO_MEMORY; | |
987 | goto unlock_and_exit; | |
988 | } | |
989 | ||
990 | /* Init handler obj */ | |
991 | ||
4be44fcd | 992 | handler_obj->address_space.space_id = (u8) space_id; |
61686124 | 993 | handler_obj->address_space.handler_flags = flags; |
1da177e4 | 994 | handler_obj->address_space.region_list = NULL; |
4be44fcd LB |
995 | handler_obj->address_space.node = node; |
996 | handler_obj->address_space.handler = handler; | |
997 | handler_obj->address_space.context = context; | |
998 | handler_obj->address_space.setup = setup; | |
1da177e4 LT |
999 | |
1000 | /* Install at head of Device.address_space list */ | |
1001 | ||
4be44fcd | 1002 | handler_obj->address_space.next = obj_desc->device.handler; |
1da177e4 LT |
1003 | |
1004 | /* | |
1005 | * The Device object is the first reference on the handler_obj. | |
1006 | * Each region that uses the handler adds a reference. | |
1007 | */ | |
1008 | obj_desc->device.handler = handler_obj; | |
1009 | ||
1010 | /* | |
1011 | * Walk the namespace finding all of the regions this | |
1012 | * handler will manage. | |
1013 | * | |
1014 | * Start at the device and search the branch toward | |
1015 | * the leaf nodes until either the leaf is encountered or | |
1016 | * a device is detected that has an address handler of the | |
1017 | * same type. | |
1018 | * | |
1019 | * In either case, back up and search down the remainder | |
1020 | * of the branch | |
1021 | */ | |
4be44fcd LB |
1022 | status = acpi_ns_walk_namespace(ACPI_TYPE_ANY, node, ACPI_UINT32_MAX, |
1023 | ACPI_NS_WALK_UNLOCK, | |
2263576c LM |
1024 | acpi_ev_install_handler, NULL, |
1025 | handler_obj, NULL); | |
1da177e4 | 1026 | |
4be44fcd LB |
1027 | unlock_and_exit: |
1028 | return_ACPI_STATUS(status); | |
1da177e4 LT |
1029 | } |
1030 | ||
1da177e4 LT |
1031 | /******************************************************************************* |
1032 | * | |
1033 | * FUNCTION: acpi_ev_execute_reg_methods | |
1034 | * | |
1035 | * PARAMETERS: Node - Namespace node for the device | |
1036 | * space_id - The address space ID | |
1037 | * | |
1038 | * RETURN: Status | |
1039 | * | |
1040 | * DESCRIPTION: Run all _REG methods for the input Space ID; | |
1041 | * Note: assumes namespace is locked, or system init time. | |
1042 | * | |
1043 | ******************************************************************************/ | |
1044 | ||
1045 | acpi_status | |
4be44fcd LB |
1046 | acpi_ev_execute_reg_methods(struct acpi_namespace_node *node, |
1047 | acpi_adr_space_type space_id) | |
1da177e4 | 1048 | { |
4be44fcd | 1049 | acpi_status status; |
1da177e4 | 1050 | |
b229cf92 | 1051 | ACPI_FUNCTION_TRACE(ev_execute_reg_methods); |
1da177e4 LT |
1052 | |
1053 | /* | |
9f15fc66 BM |
1054 | * Run all _REG methods for all Operation Regions for this space ID. This |
1055 | * is a separate walk in order to handle any interdependencies between | |
1056 | * regions and _REG methods. (i.e. handlers must be installed for all | |
1057 | * regions of this Space ID before we can run any _REG methods) | |
1da177e4 | 1058 | */ |
4be44fcd LB |
1059 | status = acpi_ns_walk_namespace(ACPI_TYPE_ANY, node, ACPI_UINT32_MAX, |
1060 | ACPI_NS_WALK_UNLOCK, acpi_ev_reg_run, | |
2263576c | 1061 | NULL, &space_id, NULL); |
1da177e4 | 1062 | |
4be44fcd | 1063 | return_ACPI_STATUS(status); |
1da177e4 LT |
1064 | } |
1065 | ||
1da177e4 LT |
1066 | /******************************************************************************* |
1067 | * | |
1068 | * FUNCTION: acpi_ev_reg_run | |
1069 | * | |
1070 | * PARAMETERS: walk_namespace callback | |
1071 | * | |
958dd242 | 1072 | * DESCRIPTION: Run _REG method for region objects of the requested space_iD |
1da177e4 LT |
1073 | * |
1074 | ******************************************************************************/ | |
1075 | ||
44f6c012 | 1076 | static acpi_status |
4be44fcd LB |
1077 | acpi_ev_reg_run(acpi_handle obj_handle, |
1078 | u32 level, void *context, void **return_value) | |
1da177e4 | 1079 | { |
4be44fcd LB |
1080 | union acpi_operand_object *obj_desc; |
1081 | struct acpi_namespace_node *node; | |
1082 | acpi_adr_space_type space_id; | |
1083 | acpi_status status; | |
1da177e4 | 1084 | |
4be44fcd | 1085 | space_id = *ACPI_CAST_PTR(acpi_adr_space_type, context); |
1da177e4 LT |
1086 | |
1087 | /* Convert and validate the device handle */ | |
1088 | ||
f24b664d | 1089 | node = acpi_ns_validate_handle(obj_handle); |
1da177e4 LT |
1090 | if (!node) { |
1091 | return (AE_BAD_PARAMETER); | |
1092 | } | |
1093 | ||
1094 | /* | |
9f15fc66 BM |
1095 | * We only care about regions.and objects that are allowed to have address |
1096 | * space handlers | |
1da177e4 | 1097 | */ |
4be44fcd | 1098 | if ((node->type != ACPI_TYPE_REGION) && (node != acpi_gbl_root_node)) { |
1da177e4 LT |
1099 | return (AE_OK); |
1100 | } | |
1101 | ||
1102 | /* Check for an existing internal object */ | |
1103 | ||
4be44fcd | 1104 | obj_desc = acpi_ns_get_attached_object(node); |
1da177e4 | 1105 | if (!obj_desc) { |
52fc0b02 | 1106 | |
1da177e4 LT |
1107 | /* No object, just exit */ |
1108 | ||
1109 | return (AE_OK); | |
1110 | } | |
1111 | ||
1112 | /* Object is a Region */ | |
1113 | ||
1114 | if (obj_desc->region.space_id != space_id) { | |
9f15fc66 BM |
1115 | |
1116 | /* This region is for a different address space, just ignore it */ | |
1117 | ||
1da177e4 LT |
1118 | return (AE_OK); |
1119 | } | |
1120 | ||
4be44fcd | 1121 | status = acpi_ev_execute_reg_method(obj_desc, 1); |
1da177e4 LT |
1122 | return (status); |
1123 | } |