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