1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44#include <acpi/acpi.h>
45#include "accommon.h"
46#include "acevents.h"
47#include "acnamesp.h"
48#include "acinterp.h"
49
50#define _COMPONENT ACPI_EVENTS
51ACPI_MODULE_NAME("evregion")
52
53extern u8 acpi_gbl_default_address_spaces[];
54
55
56
57static void
58acpi_ev_orphan_ec_reg_method(struct acpi_namespace_node *ec_device_node);
59
60static acpi_status
61acpi_ev_reg_run(acpi_handle obj_handle,
62 u32 level, void *context, void **return_value);
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77acpi_status acpi_ev_initialize_op_regions(void)
78{
79 acpi_status status;
80 u32 i;
81
82 ACPI_FUNCTION_TRACE(ev_initialize_op_regions);
83
84 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
85 if (ACPI_FAILURE(status)) {
86 return_ACPI_STATUS(status);
87 }
88
89
90
91 for (i = 0; i < ACPI_NUM_DEFAULT_SPACES; i++) {
92
93
94
95
96
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 }
105 }
106
107 acpi_gbl_reg_methods_executed = TRUE;
108
109 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
110 return_ACPI_STATUS(status);
111}
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132acpi_status
133acpi_ev_address_space_dispatch(union acpi_operand_object *region_obj,
134 union acpi_operand_object *field_obj,
135 u32 function,
136 u32 region_offset, u32 bit_width, u64 *value)
137{
138 acpi_status status;
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;
144 struct acpi_connection_info *context;
145
146 ACPI_FUNCTION_TRACE(ev_address_space_dispatch);
147
148 region_obj2 = acpi_ns_get_secondary_object(region_obj);
149 if (!region_obj2) {
150 return_ACPI_STATUS(AE_NOT_EXIST);
151 }
152
153
154
155 handler_desc = region_obj->region.handler;
156 if (!handler_desc) {
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)));
163
164 return_ACPI_STATUS(AE_NOT_EXIST);
165 }
166
167 context = handler_desc->address_space.context;
168
169
170
171
172
173 if (!(region_obj->region.flags & AOPOBJ_SETUP_COMPLETE)) {
174
175
176
177 region_setup = handler_desc->address_space.setup;
178 if (!region_setup) {
179
180
181
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)));
187 return_ACPI_STATUS(AE_NOT_EXIST);
188 }
189
190
191
192
193
194
195 acpi_ex_exit_interpreter();
196
197 status = region_setup(region_obj, ACPI_REGION_ACTIVATE,
198 context, ®ion_context);
199
200
201
202 acpi_ex_enter_interpreter();
203
204
205
206 if (ACPI_FAILURE(status)) {
207 ACPI_EXCEPTION((AE_INFO, status,
208 "During region initialization: [%s]",
209 acpi_ut_get_region_name(region_obj->
210 region.
211 space_id)));
212 return_ACPI_STATUS(status);
213 }
214
215
216
217 if (!(region_obj->region.flags & AOPOBJ_SETUP_COMPLETE)) {
218 region_obj->region.flags |= AOPOBJ_SETUP_COMPLETE;
219
220
221
222
223
224 if (!(region_obj2->extra.region_context)) {
225 region_obj2->extra.region_context =
226 region_context;
227 }
228 }
229 }
230
231
232
233 handler = handler_desc->address_space.handler;
234
235 ACPI_DEBUG_PRINT((ACPI_DB_OPREGION,
236 "Handler %p (@%p) Address %8.8X%8.8X [%s]\n",
237 ®ion_obj->region.handler->address_space, handler,
238 ACPI_FORMAT_NATIVE_UINT(region_obj->region.address +
239 region_offset),
240 acpi_ut_get_region_name(region_obj->region.
241 space_id)));
242
243
244
245
246
247
248
249
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
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
262 if (!(handler_desc->address_space.handler_flags &
263 ACPI_ADDR_HANDLER_DEFAULT_INSTALLED)) {
264
265
266
267
268
269 acpi_ex_exit_interpreter();
270 }
271
272
273
274 status = handler(function,
275 (region_obj->region.address + region_offset),
276 bit_width, value, context,
277 region_obj2->extra.region_context);
278
279 if (ACPI_FAILURE(status)) {
280 ACPI_EXCEPTION((AE_INFO, status, "Returned by Handler for [%s]",
281 acpi_ut_get_region_name(region_obj->region.
282 space_id)));
283 }
284
285 if (!(handler_desc->address_space.handler_flags &
286 ACPI_ADDR_HANDLER_DEFAULT_INSTALLED)) {
287
288
289
290
291 acpi_ex_enter_interpreter();
292 }
293
294 return_ACPI_STATUS(status);
295}
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311void
312acpi_ev_detach_region(union acpi_operand_object *region_obj,
313 u8 acpi_ns_is_locked)
314{
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;
322
323 ACPI_FUNCTION_TRACE(ev_detach_region);
324
325 region_obj2 = acpi_ns_get_secondary_object(region_obj);
326 if (!region_obj2) {
327 return_VOID;
328 }
329 region_context = ®ion_obj2->extra.region_context;
330
331
332
333 handler_obj = region_obj->region.handler;
334 if (!handler_obj) {
335
336
337
338 return_VOID;
339 }
340
341
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) {
347
348
349
350 if (obj_desc == region_obj) {
351 ACPI_DEBUG_PRINT((ACPI_DB_OPREGION,
352 "Removing Region %p from address handler %p\n",
353 region_obj, handler_obj));
354
355
356
357 *last_obj_ptr = obj_desc->region.next;
358 obj_desc->region.next = NULL;
359
360 if (acpi_ns_is_locked) {
361 status =
362 acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
363 if (ACPI_FAILURE(status)) {
364 return_VOID;
365 }
366 }
367
368
369
370 status =
371 acpi_ev_execute_reg_method(region_obj,
372 ACPI_REG_DISCONNECT);
373 if (ACPI_FAILURE(status)) {
374 ACPI_EXCEPTION((AE_INFO, status,
375 "from region _REG, [%s]",
376 acpi_ut_get_region_name
377 (region_obj->region.space_id)));
378 }
379
380 if (acpi_ns_is_locked) {
381 status =
382 acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
383 if (ACPI_FAILURE(status)) {
384 return_VOID;
385 }
386 }
387
388
389
390
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);
399
400
401
402
403
404 if (region_context) {
405 *region_context = NULL;
406 }
407
408
409
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 }
417
418 region_obj->region.flags &=
419 ~(AOPOBJ_SETUP_COMPLETE);
420 }
421
422
423
424
425
426
427
428
429
430
431 region_obj->region.handler = NULL;
432 acpi_ut_remove_reference(handler_obj);
433
434 return_VOID;
435 }
436
437
438
439 last_obj_ptr = &obj_desc->region.next;
440 obj_desc = obj_desc->region.next;
441 }
442
443
444
445 ACPI_DEBUG_PRINT((ACPI_DB_OPREGION,
446 "Cannot remove region %p from address handler %p\n",
447 region_obj, handler_obj));
448
449 return_VOID;
450}
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467acpi_status
468acpi_ev_attach_region(union acpi_operand_object *handler_obj,
469 union acpi_operand_object *region_obj,
470 u8 acpi_ns_is_locked)
471{
472
473 ACPI_FUNCTION_TRACE(ev_attach_region);
474
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)));
481
482
483
484 region_obj->region.next = handler_obj->address_space.region_list;
485 handler_obj->address_space.region_list = region_obj;
486
487
488
489 if (region_obj->region.handler) {
490 return_ACPI_STATUS(AE_ALREADY_EXISTS);
491 }
492
493 region_obj->region.handler = handler_obj;
494 acpi_ut_add_reference(handler_obj);
495
496 return_ACPI_STATUS(AE_OK);
497}
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512acpi_status
513acpi_ev_execute_reg_method(union acpi_operand_object *region_obj, u32 function)
514{
515 struct acpi_evaluate_info *info;
516 union acpi_operand_object *args[3];
517 union acpi_operand_object *region_obj2;
518 acpi_status status;
519
520 ACPI_FUNCTION_TRACE(ev_execute_reg_method);
521
522 region_obj2 = acpi_ns_get_secondary_object(region_obj);
523 if (!region_obj2) {
524 return_ACPI_STATUS(AE_NOT_EXIST);
525 }
526
527 if (region_obj2->extra.method_REG == NULL) {
528 return_ACPI_STATUS(AE_OK);
529 }
530
531
532
533 info = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_evaluate_info));
534 if (!info) {
535 return_ACPI_STATUS(AE_NO_MEMORY);
536 }
537
538 info->prefix_node = region_obj2->extra.method_REG;
539 info->relative_pathname = NULL;
540 info->parameters = args;
541 info->flags = ACPI_IGNORE_RETURN_VALUE;
542
543
544
545
546
547
548
549
550
551
552
553 args[0] =
554 acpi_ut_create_integer_object((u64)region_obj->region.space_id);
555 if (!args[0]) {
556 status = AE_NO_MEMORY;
557 goto cleanup1;
558 }
559
560 args[1] = acpi_ut_create_integer_object((u64)function);
561 if (!args[1]) {
562 status = AE_NO_MEMORY;
563 goto cleanup2;
564 }
565
566 args[2] = NULL;
567
568
569
570 ACPI_DEBUG_EXEC(acpi_ut_display_init_pathname
571 (ACPI_TYPE_METHOD, info->prefix_node, NULL));
572
573 status = acpi_ns_evaluate(info);
574 acpi_ut_remove_reference(args[1]);
575
576cleanup2:
577 acpi_ut_remove_reference(args[0]);
578
579cleanup1:
580 ACPI_FREE(info);
581 return_ACPI_STATUS(status);
582}
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598acpi_status
599acpi_ev_execute_reg_methods(struct acpi_namespace_node *node,
600 acpi_adr_space_type space_id)
601{
602 acpi_status status;
603
604 ACPI_FUNCTION_TRACE(ev_execute_reg_methods);
605
606
607
608
609
610
611
612 status = acpi_ns_walk_namespace(ACPI_TYPE_ANY, node, ACPI_UINT32_MAX,
613 ACPI_NS_WALK_UNLOCK, acpi_ev_reg_run,
614 NULL, &space_id, NULL);
615
616
617
618 if (space_id == ACPI_ADR_SPACE_EC) {
619 acpi_ev_orphan_ec_reg_method(node);
620 }
621
622 return_ACPI_STATUS(status);
623}
624
625
626
627
628
629
630
631
632
633
634
635static acpi_status
636acpi_ev_reg_run(acpi_handle obj_handle,
637 u32 level, void *context, void **return_value)
638{
639 union acpi_operand_object *obj_desc;
640 struct acpi_namespace_node *node;
641 acpi_adr_space_type space_id;
642 acpi_status status;
643
644 space_id = *ACPI_CAST_PTR(acpi_adr_space_type, context);
645
646
647
648 node = acpi_ns_validate_handle(obj_handle);
649 if (!node) {
650 return (AE_BAD_PARAMETER);
651 }
652
653
654
655
656
657 if ((node->type != ACPI_TYPE_REGION) && (node != acpi_gbl_root_node)) {
658 return (AE_OK);
659 }
660
661
662
663 obj_desc = acpi_ns_get_attached_object(node);
664 if (!obj_desc) {
665
666
667
668 return (AE_OK);
669 }
670
671
672
673 if (obj_desc->region.space_id != space_id) {
674
675
676
677 return (AE_OK);
678 }
679
680 status = acpi_ev_execute_reg_method(obj_desc, ACPI_REG_CONNECT);
681 return (status);
682}
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709static void
710acpi_ev_orphan_ec_reg_method(struct acpi_namespace_node *ec_device_node)
711{
712 acpi_handle reg_method;
713 struct acpi_namespace_node *next_node;
714 acpi_status status;
715 struct acpi_object_list args;
716 union acpi_object objects[2];
717
718 ACPI_FUNCTION_TRACE(ev_orphan_ec_reg_method);
719
720 if (!ec_device_node) {
721 return_VOID;
722 }
723
724
725
726 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
727
728
729
730 status = acpi_get_handle(ec_device_node, METHOD_NAME__REG, ®_method);
731 if (ACPI_FAILURE(status)) {
732 goto exit;
733 }
734
735
736
737
738
739
740
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)) {
747 goto exit;
748 }
749
750 next_node = acpi_ns_get_next_node(ec_device_node, next_node);
751 }
752
753
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
764exit:
765
766
767 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
768 return_VOID;
769}
770