ACPICA: Events: Fix an issue that region object is re-attached to another scope when...
[linux-2.6-block.git] / drivers / acpi / acpica / evregion.c
CommitLineData
1da177e4
LT
1/******************************************************************************
2 *
42f8fb75 3 * Module Name: evregion - Operation Region support
1da177e4
LT
4 *
5 *****************************************************************************/
6
7/*
82a80941 8 * Copyright (C) 2000 - 2015, 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 51ACPI_MODULE_NAME("evregion")
1da177e4 52
42f8fb75
BM
53extern u8 acpi_gbl_default_address_spaces[];
54
44f6c012 55/* Local prototypes */
74d3ec77 56
8f4f5e78
ZR
57static void
58acpi_ev_orphan_ec_reg_method(struct acpi_namespace_node *ec_device_node);
e2066ca1 59
44f6c012 60static acpi_status
4be44fcd
LB
61acpi_ev_reg_run(acpi_handle obj_handle,
62 u32 level, void *context, void **return_value);
44f6c012 63
1da177e4
LT
64/*******************************************************************************
65 *
66 * FUNCTION: acpi_ev_initialize_op_regions
67 *
68 * PARAMETERS: None
69 *
70 * RETURN: Status
71 *
72 * DESCRIPTION: Execute _REG methods for all Operation Regions that have
73 * an installed default region handler.
74 *
75 ******************************************************************************/
76
4be44fcd 77acpi_status acpi_ev_initialize_op_regions(void)
1da177e4 78{
4be44fcd 79 acpi_status status;
67a119f9 80 u32 i;
1da177e4 81
b229cf92 82 ACPI_FUNCTION_TRACE(ev_initialize_op_regions);
1da177e4 83
4be44fcd
LB
84 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
85 if (ACPI_FAILURE(status)) {
86 return_ACPI_STATUS(status);
1da177e4
LT
87 }
88
9f15fc66 89 /* Run the _REG methods for op_regions in each default address space */
52fc0b02 90
9f15fc66
BM
91 for (i = 0; i < ACPI_NUM_DEFAULT_SPACES; i++) {
92 /*
74d3ec77
LM
93 * Make sure the installed handler is the DEFAULT handler. If not the
94 * default, the _REG methods will have already been run (when the
95 * handler was installed)
1da177e4 96 */
74d3ec77
LM
97 if (acpi_ev_has_default_handler(acpi_gbl_root_node,
98 acpi_gbl_default_address_spaces
99 [i])) {
100 status =
101 acpi_ev_execute_reg_methods(acpi_gbl_root_node,
102 acpi_gbl_default_address_spaces
103 [i]);
104 }
1da177e4
LT
105 }
106
ef09c4f5
BM
107 acpi_gbl_reg_methods_executed = TRUE;
108
4be44fcd
LB
109 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
110 return_ACPI_STATUS(status);
1da177e4
LT
111}
112
1da177e4
LT
113/*******************************************************************************
114 *
115 * FUNCTION: acpi_ev_address_space_dispatch
116 *
117 * PARAMETERS: region_obj - Internal region object
9ce81784 118 * field_obj - Corresponding field. Can be NULL.
ba494bee 119 * function - Read or Write operation
f5407af3 120 * region_offset - Where in the region to read or write
1da177e4 121 * bit_width - Field width in bits (8, 16, 32, or 64)
ba494bee 122 * value - Pointer to in or out value, must be
5df7e6cb 123 * a full 64-bit integer
1da177e4
LT
124 *
125 * RETURN: Status
126 *
127 * DESCRIPTION: Dispatch an address space or operation region access to
128 * a previously installed handler.
129 *
7b738064
BM
130 * NOTE: During early initialization, we always install the default region
131 * handlers for Memory, I/O and PCI_Config. This ensures that these operation
132 * region address spaces are always available as per the ACPI specification.
133 * This is especially needed in order to support the execution of
134 * module-level AML code during loading of the ACPI tables.
135 *
1da177e4
LT
136 ******************************************************************************/
137
138acpi_status
4be44fcd 139acpi_ev_address_space_dispatch(union acpi_operand_object *region_obj,
9ce81784 140 union acpi_operand_object *field_obj,
4be44fcd 141 u32 function,
5df7e6cb 142 u32 region_offset, u32 bit_width, u64 *value)
1da177e4 143{
4be44fcd 144 acpi_status status;
4be44fcd
LB
145 acpi_adr_space_handler handler;
146 acpi_adr_space_setup region_setup;
147 union acpi_operand_object *handler_desc;
148 union acpi_operand_object *region_obj2;
149 void *region_context = NULL;
9ce81784 150 struct acpi_connection_info *context;
75ec6e55 151 acpi_physical_address address;
1da177e4 152
b229cf92 153 ACPI_FUNCTION_TRACE(ev_address_space_dispatch);
1da177e4 154
4be44fcd 155 region_obj2 = acpi_ns_get_secondary_object(region_obj);
1da177e4 156 if (!region_obj2) {
4be44fcd 157 return_ACPI_STATUS(AE_NOT_EXIST);
1da177e4
LT
158 }
159
160 /* Ensure that there is a handler associated with this region */
161
162 handler_desc = region_obj->region.handler;
163 if (!handler_desc) {
b8e4d893
BM
164 ACPI_ERROR((AE_INFO,
165 "No handler for Region [%4.4s] (%p) [%s]",
166 acpi_ut_get_node_name(region_obj->region.node),
167 region_obj,
168 acpi_ut_get_region_name(region_obj->region.
169 space_id)));
4be44fcd
LB
170
171 return_ACPI_STATUS(AE_NOT_EXIST);
1da177e4
LT
172 }
173
9ce81784
BM
174 context = handler_desc->address_space.context;
175
1da177e4 176 /*
9f15fc66 177 * It may be the case that the region has never been initialized.
1da177e4
LT
178 * Some types of regions require special init code
179 */
180 if (!(region_obj->region.flags & AOPOBJ_SETUP_COMPLETE)) {
9f15fc66
BM
181
182 /* This region has not been initialized yet, do it */
183
1da177e4
LT
184 region_setup = handler_desc->address_space.setup;
185 if (!region_setup) {
52fc0b02 186
1da177e4
LT
187 /* No initialization routine, exit with error */
188
b8e4d893
BM
189 ACPI_ERROR((AE_INFO,
190 "No init routine for region(%p) [%s]",
191 region_obj,
192 acpi_ut_get_region_name(region_obj->region.
193 space_id)));
4be44fcd 194 return_ACPI_STATUS(AE_NOT_EXIST);
1da177e4
LT
195 }
196
197 /*
9f15fc66
BM
198 * We must exit the interpreter because the region setup will
199 * potentially execute control methods (for example, the _REG method
200 * for this region)
1da177e4 201 */
014d433f 202 acpi_ex_exit_interpreter();
1da177e4 203
4be44fcd 204 status = region_setup(region_obj, ACPI_REGION_ACTIVATE,
9ce81784 205 context, &region_context);
1da177e4
LT
206
207 /* Re-enter the interpreter */
208
014d433f 209 acpi_ex_enter_interpreter();
1da177e4
LT
210
211 /* Check for failure of the Region Setup */
212
4be44fcd 213 if (ACPI_FAILURE(status)) {
b8e4d893
BM
214 ACPI_EXCEPTION((AE_INFO, status,
215 "During region initialization: [%s]",
216 acpi_ut_get_region_name(region_obj->
217 region.
218 space_id)));
4be44fcd 219 return_ACPI_STATUS(status);
1da177e4
LT
220 }
221
9f15fc66
BM
222 /* Region initialization may have been completed by region_setup */
223
1da177e4
LT
224 if (!(region_obj->region.flags & AOPOBJ_SETUP_COMPLETE)) {
225 region_obj->region.flags |= AOPOBJ_SETUP_COMPLETE;
226
d2e7d079
DB
227 /*
228 * Save the returned context for use in all accesses to
229 * the handler for this particular region
230 */
231 if (!(region_obj2->extra.region_context)) {
4be44fcd
LB
232 region_obj2->extra.region_context =
233 region_context;
1da177e4
LT
234 }
235 }
236 }
237
238 /* We have everything we need, we can invoke the address space handler */
239
240 handler = handler_desc->address_space.handler;
75ec6e55 241 address = (region_obj->region.address + region_offset);
1da177e4 242
9ce81784
BM
243 /*
244 * Special handling for generic_serial_bus and general_purpose_io:
245 * There are three extra parameters that must be passed to the
246 * handler via the context:
75ec6e55
BM
247 * 1) Connection buffer, a resource template from Connection() op
248 * 2) Length of the above buffer
249 * 3) Actual access length from the access_as() op
250 *
251 * In addition, for general_purpose_io, the Address and bit_width fields
252 * are defined as follows:
253 * 1) Address is the pin number index of the field (bit offset from
254 * the previous Connection)
255 * 2) bit_width is the actual bit length of the field (number of pins)
9ce81784 256 */
75ec6e55
BM
257 if ((region_obj->region.space_id == ACPI_ADR_SPACE_GSBUS) &&
258 context && field_obj) {
259
260 /* Get the Connection (resource_template) buffer */
261
262 context->connection = field_obj->field.resource_buffer;
263 context->length = field_obj->field.resource_length;
264 context->access_length = field_obj->field.access_length;
265 }
266 if ((region_obj->region.space_id == ACPI_ADR_SPACE_GPIO) &&
9ce81784
BM
267 context && field_obj) {
268
269 /* Get the Connection (resource_template) buffer */
270
271 context->connection = field_obj->field.resource_buffer;
272 context->length = field_obj->field.resource_length;
273 context->access_length = field_obj->field.access_length;
75ec6e55
BM
274 address = field_obj->field.pin_number_index;
275 bit_width = field_obj->field.bit_length;
9ce81784
BM
276 }
277
75ec6e55
BM
278 ACPI_DEBUG_PRINT((ACPI_DB_OPREGION,
279 "Handler %p (@%p) Address %8.8X%8.8X [%s]\n",
280 &region_obj->region.handler->address_space, handler,
1d0a0b2f 281 ACPI_FORMAT_UINT64(address),
75ec6e55
BM
282 acpi_ut_get_region_name(region_obj->region.
283 space_id)));
284
61686124
BM
285 if (!(handler_desc->address_space.handler_flags &
286 ACPI_ADDR_HANDLER_DEFAULT_INSTALLED)) {
1da177e4
LT
287 /*
288 * For handlers other than the default (supplied) handlers, we must
289 * exit the interpreter because the handler *might* block -- we don't
290 * know what it will do, so we can't hold the lock on the intepreter.
291 */
014d433f 292 acpi_ex_exit_interpreter();
1da177e4
LT
293 }
294
295 /* Call the handler */
296
75ec6e55 297 status = handler(function, address, bit_width, value, context,
1da177e4
LT
298 region_obj2->extra.region_context);
299
4be44fcd 300 if (ACPI_FAILURE(status)) {
b8e4d893
BM
301 ACPI_EXCEPTION((AE_INFO, status, "Returned by Handler for [%s]",
302 acpi_ut_get_region_name(region_obj->region.
303 space_id)));
1da177e4
LT
304 }
305
61686124
BM
306 if (!(handler_desc->address_space.handler_flags &
307 ACPI_ADDR_HANDLER_DEFAULT_INSTALLED)) {
1da177e4
LT
308 /*
309 * We just returned from a non-default handler, we must re-enter the
310 * interpreter
311 */
014d433f 312 acpi_ex_enter_interpreter();
1da177e4
LT
313 }
314
4be44fcd 315 return_ACPI_STATUS(status);
1da177e4
LT
316}
317
1da177e4
LT
318/*******************************************************************************
319 *
320 * FUNCTION: acpi_ev_detach_region
321 *
322 * PARAMETERS: region_obj - Region Object
323 * acpi_ns_is_locked - Namespace Region Already Locked?
324 *
325 * RETURN: None
326 *
327 * DESCRIPTION: Break the association between the handler and the region
328 * this is a two way association.
329 *
330 ******************************************************************************/
331
332void
4be44fcd
LB
333acpi_ev_detach_region(union acpi_operand_object *region_obj,
334 u8 acpi_ns_is_locked)
1da177e4 335{
4be44fcd
LB
336 union acpi_operand_object *handler_obj;
337 union acpi_operand_object *obj_desc;
f953529f 338 union acpi_operand_object *start_desc;
4be44fcd
LB
339 union acpi_operand_object **last_obj_ptr;
340 acpi_adr_space_setup region_setup;
341 void **region_context;
342 union acpi_operand_object *region_obj2;
343 acpi_status status;
1da177e4 344
b229cf92 345 ACPI_FUNCTION_TRACE(ev_detach_region);
1da177e4 346
4be44fcd 347 region_obj2 = acpi_ns_get_secondary_object(region_obj);
1da177e4
LT
348 if (!region_obj2) {
349 return_VOID;
350 }
351 region_context = &region_obj2->extra.region_context;
352
353 /* Get the address handler from the region object */
354
355 handler_obj = region_obj->region.handler;
356 if (!handler_obj) {
52fc0b02 357
1da177e4
LT
358 /* This region has no handler, all done */
359
360 return_VOID;
361 }
362
363 /* Find this region in the handler's list */
364
365 obj_desc = handler_obj->address_space.region_list;
f953529f 366 start_desc = obj_desc;
1da177e4
LT
367 last_obj_ptr = &handler_obj->address_space.region_list;
368
369 while (obj_desc) {
52fc0b02 370
1da177e4
LT
371 /* Is this the correct Region? */
372
373 if (obj_desc == region_obj) {
4be44fcd
LB
374 ACPI_DEBUG_PRINT((ACPI_DB_OPREGION,
375 "Removing Region %p from address handler %p\n",
376 region_obj, handler_obj));
1da177e4
LT
377
378 /* This is it, remove it from the handler's list */
379
380 *last_obj_ptr = obj_desc->region.next;
4be44fcd 381 obj_desc->region.next = NULL; /* Must clear field */
1da177e4
LT
382
383 if (acpi_ns_is_locked) {
4be44fcd
LB
384 status =
385 acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
386 if (ACPI_FAILURE(status)) {
1da177e4
LT
387 return_VOID;
388 }
389 }
390
391 /* Now stop region accesses by executing the _REG method */
392
e2066ca1
BM
393 status =
394 acpi_ev_execute_reg_method(region_obj,
395 ACPI_REG_DISCONNECT);
4be44fcd 396 if (ACPI_FAILURE(status)) {
b8e4d893
BM
397 ACPI_EXCEPTION((AE_INFO, status,
398 "from region _REG, [%s]",
399 acpi_ut_get_region_name
400 (region_obj->region.space_id)));
1da177e4
LT
401 }
402
403 if (acpi_ns_is_locked) {
4be44fcd
LB
404 status =
405 acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
406 if (ACPI_FAILURE(status)) {
1da177e4
LT
407 return_VOID;
408 }
409 }
410
f6dd9221 411 /*
9f15fc66
BM
412 * If the region has been activated, call the setup handler with
413 * the deactivate notification
f6dd9221
BM
414 */
415 if (region_obj->region.flags & AOPOBJ_SETUP_COMPLETE) {
416 region_setup = handler_obj->address_space.setup;
417 status =
418 region_setup(region_obj,
419 ACPI_REGION_DEACTIVATE,
420 handler_obj->address_space.
421 context, region_context);
1da177e4 422
d2e7d079
DB
423 /*
424 * region_context should have been released by the deactivate
425 * operation. We don't need access to it anymore here.
426 */
427 if (region_context) {
428 *region_context = NULL;
429 }
430
f6dd9221 431 /* Init routine may fail, Just ignore errors */
1da177e4 432
f6dd9221
BM
433 if (ACPI_FAILURE(status)) {
434 ACPI_EXCEPTION((AE_INFO, status,
435 "from region handler - deactivate, [%s]",
436 acpi_ut_get_region_name
437 (region_obj->region.
438 space_id)));
439 }
1da177e4 440
f6dd9221
BM
441 region_obj->region.flags &=
442 ~(AOPOBJ_SETUP_COMPLETE);
1da177e4
LT
443 }
444
1da177e4
LT
445 /*
446 * Remove handler reference in the region
447 *
f6dd9221
BM
448 * NOTE: this doesn't mean that the region goes away, the region
449 * is just inaccessible as indicated to the _REG method
1da177e4 450 *
f6dd9221
BM
451 * If the region is on the handler's list, this must be the
452 * region's handler
1da177e4
LT
453 */
454 region_obj->region.handler = NULL;
4be44fcd 455 acpi_ut_remove_reference(handler_obj);
1da177e4
LT
456
457 return_VOID;
458 }
459
460 /* Walk the linked list of handlers */
461
462 last_obj_ptr = &obj_desc->region.next;
463 obj_desc = obj_desc->region.next;
f953529f
BM
464
465 /* Prevent infinite loop if list is corrupted */
466
467 if (obj_desc == start_desc) {
468 ACPI_ERROR((AE_INFO,
469 "Circular handler list in region object %p",
470 region_obj));
471 return_VOID;
472 }
1da177e4
LT
473 }
474
475 /* If we get here, the region was not in the handler's region list */
476
4be44fcd
LB
477 ACPI_DEBUG_PRINT((ACPI_DB_OPREGION,
478 "Cannot remove region %p from address handler %p\n",
479 region_obj, handler_obj));
1da177e4
LT
480
481 return_VOID;
482}
483
1da177e4
LT
484/*******************************************************************************
485 *
486 * FUNCTION: acpi_ev_attach_region
487 *
488 * PARAMETERS: handler_obj - Handler Object
489 * region_obj - Region Object
490 * acpi_ns_is_locked - Namespace Region Already Locked?
491 *
492 * RETURN: None
493 *
494 * DESCRIPTION: Create the association between the handler and the region
495 * this is a two way association.
496 *
497 ******************************************************************************/
498
499acpi_status
4be44fcd
LB
500acpi_ev_attach_region(union acpi_operand_object *handler_obj,
501 union acpi_operand_object *region_obj,
502 u8 acpi_ns_is_locked)
1da177e4
LT
503{
504
b229cf92 505 ACPI_FUNCTION_TRACE(ev_attach_region);
1da177e4 506
1d65d9a7
LZ
507 /* Install the region's handler */
508
509 if (region_obj->region.handler) {
510 return_ACPI_STATUS(AE_ALREADY_EXISTS);
511 }
512
4be44fcd
LB
513 ACPI_DEBUG_PRINT((ACPI_DB_OPREGION,
514 "Adding Region [%4.4s] %p to address handler %p [%s]\n",
515 acpi_ut_get_node_name(region_obj->region.node),
516 region_obj, handler_obj,
517 acpi_ut_get_region_name(region_obj->region.
518 space_id)));
1da177e4
LT
519
520 /* Link this region to the front of the handler's list */
521
522 region_obj->region.next = handler_obj->address_space.region_list;
523 handler_obj->address_space.region_list = region_obj;
1da177e4 524 region_obj->region.handler = handler_obj;
4be44fcd 525 acpi_ut_add_reference(handler_obj);
1da177e4 526
4be44fcd 527 return_ACPI_STATUS(AE_OK);
1da177e4
LT
528}
529
1da177e4
LT
530/*******************************************************************************
531 *
42f8fb75 532 * FUNCTION: acpi_ev_execute_reg_method
1da177e4 533 *
42f8fb75
BM
534 * PARAMETERS: region_obj - Region object
535 * function - Passed to _REG: On (1) or Off (0)
1da177e4
LT
536 *
537 * RETURN: Status
538 *
42f8fb75 539 * DESCRIPTION: Execute _REG method for a region
1da177e4
LT
540 *
541 ******************************************************************************/
542
543acpi_status
42f8fb75 544acpi_ev_execute_reg_method(union acpi_operand_object *region_obj, u32 function)
1da177e4 545{
42f8fb75
BM
546 struct acpi_evaluate_info *info;
547 union acpi_operand_object *args[3];
548 union acpi_operand_object *region_obj2;
4be44fcd 549 acpi_status status;
1da177e4 550
42f8fb75 551 ACPI_FUNCTION_TRACE(ev_execute_reg_method);
1da177e4 552
42f8fb75
BM
553 region_obj2 = acpi_ns_get_secondary_object(region_obj);
554 if (!region_obj2) {
555 return_ACPI_STATUS(AE_NOT_EXIST);
1da177e4
LT
556 }
557
42f8fb75
BM
558 if (region_obj2->extra.method_REG == NULL) {
559 return_ACPI_STATUS(AE_OK);
1da177e4
LT
560 }
561
42f8fb75 562 /* Allocate and initialize the evaluation information block */
1da177e4 563
42f8fb75
BM
564 info = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_evaluate_info));
565 if (!info) {
566 return_ACPI_STATUS(AE_NO_MEMORY);
1da177e4
LT
567 }
568
42f8fb75 569 info->prefix_node = region_obj2->extra.method_REG;
29a241cc 570 info->relative_pathname = NULL;
42f8fb75
BM
571 info->parameters = args;
572 info->flags = ACPI_IGNORE_RETURN_VALUE;
1da177e4
LT
573
574 /*
42f8fb75
BM
575 * The _REG method has two arguments:
576 *
577 * arg0 - Integer:
578 * Operation region space ID Same value as region_obj->Region.space_id
1da177e4 579 *
42f8fb75
BM
580 * arg1 - Integer:
581 * connection status 1 for connecting the handler, 0 for disconnecting
582 * the handler (Passed as a parameter)
1da177e4 583 */
42f8fb75
BM
584 args[0] =
585 acpi_ut_create_integer_object((u64)region_obj->region.space_id);
586 if (!args[0]) {
1da177e4 587 status = AE_NO_MEMORY;
42f8fb75 588 goto cleanup1;
1da177e4
LT
589 }
590
42f8fb75
BM
591 args[1] = acpi_ut_create_integer_object((u64)function);
592 if (!args[1]) {
593 status = AE_NO_MEMORY;
594 goto cleanup2;
595 }
1da177e4 596
42f8fb75 597 args[2] = NULL; /* Terminate list */
1da177e4 598
42f8fb75 599 /* Execute the method, no return value */
1da177e4 600
42f8fb75
BM
601 ACPI_DEBUG_EXEC(acpi_ut_display_init_pathname
602 (ACPI_TYPE_METHOD, info->prefix_node, NULL));
1da177e4 603
42f8fb75
BM
604 status = acpi_ns_evaluate(info);
605 acpi_ut_remove_reference(args[1]);
1da177e4 606
10622bf8 607cleanup2:
42f8fb75 608 acpi_ut_remove_reference(args[0]);
1da177e4 609
10622bf8 610cleanup1:
42f8fb75 611 ACPI_FREE(info);
4be44fcd 612 return_ACPI_STATUS(status);
1da177e4
LT
613}
614
1da177e4
LT
615/*******************************************************************************
616 *
617 * FUNCTION: acpi_ev_execute_reg_methods
618 *
ba494bee 619 * PARAMETERS: node - Namespace node for the device
1da177e4
LT
620 * space_id - The address space ID
621 *
622 * RETURN: Status
623 *
624 * DESCRIPTION: Run all _REG methods for the input Space ID;
625 * Note: assumes namespace is locked, or system init time.
626 *
627 ******************************************************************************/
628
629acpi_status
4be44fcd
LB
630acpi_ev_execute_reg_methods(struct acpi_namespace_node *node,
631 acpi_adr_space_type space_id)
1da177e4 632{
4be44fcd 633 acpi_status status;
25823e78 634 struct acpi_reg_walk_info info;
1da177e4 635
b229cf92 636 ACPI_FUNCTION_TRACE(ev_execute_reg_methods);
1da177e4 637
25823e78
BM
638 info.space_id = space_id;
639 info.reg_run_count = 0;
640
641 ACPI_DEBUG_PRINT_RAW((ACPI_DB_NAMES,
642 " Running _REG methods for SpaceId %s\n",
643 acpi_ut_get_region_name(info.space_id)));
644
1da177e4 645 /*
9f15fc66
BM
646 * Run all _REG methods for all Operation Regions for this space ID. This
647 * is a separate walk in order to handle any interdependencies between
648 * regions and _REG methods. (i.e. handlers must be installed for all
649 * regions of this Space ID before we can run any _REG methods)
1da177e4 650 */
4be44fcd
LB
651 status = acpi_ns_walk_namespace(ACPI_TYPE_ANY, node, ACPI_UINT32_MAX,
652 ACPI_NS_WALK_UNLOCK, acpi_ev_reg_run,
25823e78 653 NULL, &info, NULL);
1da177e4 654
e2066ca1
BM
655 /* Special case for EC: handle "orphan" _REG methods with no region */
656
657 if (space_id == ACPI_ADR_SPACE_EC) {
8f4f5e78 658 acpi_ev_orphan_ec_reg_method(node);
e2066ca1
BM
659 }
660
25823e78
BM
661 ACPI_DEBUG_PRINT_RAW((ACPI_DB_NAMES,
662 " Executed %u _REG methods for SpaceId %s\n",
663 info.reg_run_count,
664 acpi_ut_get_region_name(info.space_id)));
665
4be44fcd 666 return_ACPI_STATUS(status);
1da177e4
LT
667}
668
1da177e4
LT
669/*******************************************************************************
670 *
671 * FUNCTION: acpi_ev_reg_run
672 *
673 * PARAMETERS: walk_namespace callback
674 *
ba494bee 675 * DESCRIPTION: Run _REG method for region objects of the requested spaceID
1da177e4
LT
676 *
677 ******************************************************************************/
678
44f6c012 679static acpi_status
4be44fcd
LB
680acpi_ev_reg_run(acpi_handle obj_handle,
681 u32 level, void *context, void **return_value)
1da177e4 682{
4be44fcd
LB
683 union acpi_operand_object *obj_desc;
684 struct acpi_namespace_node *node;
4be44fcd 685 acpi_status status;
25823e78 686 struct acpi_reg_walk_info *info;
1da177e4 687
25823e78 688 info = ACPI_CAST_PTR(struct acpi_reg_walk_info, context);
1da177e4
LT
689
690 /* Convert and validate the device handle */
691
f24b664d 692 node = acpi_ns_validate_handle(obj_handle);
1da177e4
LT
693 if (!node) {
694 return (AE_BAD_PARAMETER);
695 }
696
697 /*
9f15fc66
BM
698 * We only care about regions.and objects that are allowed to have address
699 * space handlers
1da177e4 700 */
4be44fcd 701 if ((node->type != ACPI_TYPE_REGION) && (node != acpi_gbl_root_node)) {
1da177e4
LT
702 return (AE_OK);
703 }
704
705 /* Check for an existing internal object */
706
4be44fcd 707 obj_desc = acpi_ns_get_attached_object(node);
1da177e4 708 if (!obj_desc) {
52fc0b02 709
1da177e4
LT
710 /* No object, just exit */
711
712 return (AE_OK);
713 }
714
715 /* Object is a Region */
716
25823e78 717 if (obj_desc->region.space_id != info->space_id) {
9f15fc66
BM
718
719 /* This region is for a different address space, just ignore it */
720
1da177e4
LT
721 return (AE_OK);
722 }
723
25823e78 724 info->reg_run_count++;
e2066ca1 725 status = acpi_ev_execute_reg_method(obj_desc, ACPI_REG_CONNECT);
1da177e4
LT
726 return (status);
727}
e2066ca1
BM
728
729/*******************************************************************************
730 *
731 * FUNCTION: acpi_ev_orphan_ec_reg_method
732 *
8f4f5e78 733 * PARAMETERS: ec_device_node - Namespace node for an EC device
e2066ca1
BM
734 *
735 * RETURN: None
736 *
737 * DESCRIPTION: Execute an "orphan" _REG method that appears under the EC
738 * device. This is a _REG method that has no corresponding region
739 * within the EC device scope. The orphan _REG method appears to
740 * have been enabled by the description of the ECDT in the ACPI
741 * specification: "The availability of the region space can be
742 * detected by providing a _REG method object underneath the
743 * Embedded Controller device."
744 *
8f4f5e78
ZR
745 * To quickly access the EC device, we use the ec_device_node used
746 * during EC handler installation. Otherwise, we would need to
747 * perform a time consuming namespace walk, executing _HID
748 * methods to find the EC device.
749 *
750 * MUTEX: Assumes the namespace is locked
e2066ca1
BM
751 *
752 ******************************************************************************/
753
8f4f5e78
ZR
754static void
755acpi_ev_orphan_ec_reg_method(struct acpi_namespace_node *ec_device_node)
e2066ca1 756{
8f4f5e78
ZR
757 acpi_handle reg_method;
758 struct acpi_namespace_node *next_node;
e2066ca1
BM
759 acpi_status status;
760 struct acpi_object_list args;
761 union acpi_object objects[2];
e2066ca1
BM
762
763 ACPI_FUNCTION_TRACE(ev_orphan_ec_reg_method);
764
8f4f5e78 765 if (!ec_device_node) {
e2066ca1
BM
766 return_VOID;
767 }
768
769 /* Namespace is currently locked, must release */
770
771 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
772
e2066ca1
BM
773 /* Get a handle to a _REG method immediately under the EC device */
774
8f4f5e78 775 status = acpi_get_handle(ec_device_node, METHOD_NAME__REG, &reg_method);
e2066ca1 776 if (ACPI_FAILURE(status)) {
8f4f5e78 777 goto exit; /* There is no _REG method present */
e2066ca1
BM
778 }
779
780 /*
781 * Execute the _REG method only if there is no Operation Region in
782 * this scope with the Embedded Controller space ID. Otherwise, it
783 * will already have been executed. Note, this allows for Regions
784 * with other space IDs to be present; but the code below will then
8f4f5e78 785 * execute the _REG method with the embedded_control space_ID argument.
e2066ca1
BM
786 */
787 next_node = acpi_ns_get_next_node(ec_device_node, NULL);
788 while (next_node) {
789 if ((next_node->type == ACPI_TYPE_REGION) &&
790 (next_node->object) &&
791 (next_node->object->region.space_id == ACPI_ADR_SPACE_EC)) {
8f4f5e78 792 goto exit; /* Do not execute the _REG */
e2066ca1 793 }
8f4f5e78 794
e2066ca1
BM
795 next_node = acpi_ns_get_next_node(ec_device_node, next_node);
796 }
797
8f4f5e78 798 /* Evaluate the _REG(embedded_control,Connect) method */
e2066ca1
BM
799
800 args.count = 2;
801 args.pointer = objects;
802 objects[0].type = ACPI_TYPE_INTEGER;
803 objects[0].integer.value = ACPI_ADR_SPACE_EC;
804 objects[1].type = ACPI_TYPE_INTEGER;
805 objects[1].integer.value = ACPI_REG_CONNECT;
806
807 status = acpi_evaluate_object(reg_method, NULL, &args, NULL);
808
10622bf8 809exit:
e2066ca1
BM
810 /* We ignore all errors from above, don't care */
811
812 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
813 return_VOID;
814}