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