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 acpi_physical_address address;
146
147 ACPI_FUNCTION_TRACE(ev_address_space_dispatch);
148
149 region_obj2 = acpi_ns_get_secondary_object(region_obj);
150 if (!region_obj2) {
151 return_ACPI_STATUS(AE_NOT_EXIST);
152 }
153
154
155
156 handler_desc = region_obj->region.handler;
157 if (!handler_desc) {
158 ACPI_ERROR((AE_INFO,
159 "No handler for Region [%4.4s] (%p) [%s]",
160 acpi_ut_get_node_name(region_obj->region.node),
161 region_obj,
162 acpi_ut_get_region_name(region_obj->region.
163 space_id)));
164
165 return_ACPI_STATUS(AE_NOT_EXIST);
166 }
167
168 context = handler_desc->address_space.context;
169
170
171
172
173
174 if (!(region_obj->region.flags & AOPOBJ_SETUP_COMPLETE)) {
175
176
177
178 region_setup = handler_desc->address_space.setup;
179 if (!region_setup) {
180
181
182
183 ACPI_ERROR((AE_INFO,
184 "No init routine for region(%p) [%s]",
185 region_obj,
186 acpi_ut_get_region_name(region_obj->region.
187 space_id)));
188 return_ACPI_STATUS(AE_NOT_EXIST);
189 }
190
191
192
193
194
195
196 acpi_ex_exit_interpreter();
197
198 status = region_setup(region_obj, ACPI_REGION_ACTIVATE,
199 context, ®ion_context);
200
201
202
203 acpi_ex_enter_interpreter();
204
205
206
207 if (ACPI_FAILURE(status)) {
208 ACPI_EXCEPTION((AE_INFO, status,
209 "During region initialization: [%s]",
210 acpi_ut_get_region_name(region_obj->
211 region.
212 space_id)));
213 return_ACPI_STATUS(status);
214 }
215
216
217
218 if (!(region_obj->region.flags & AOPOBJ_SETUP_COMPLETE)) {
219 region_obj->region.flags |= AOPOBJ_SETUP_COMPLETE;
220
221
222
223
224
225 if (!(region_obj2->extra.region_context)) {
226 region_obj2->extra.region_context =
227 region_context;
228 }
229 }
230 }
231
232
233
234 handler = handler_desc->address_space.handler;
235 address = (region_obj->region.address + region_offset);
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251 if ((region_obj->region.space_id == ACPI_ADR_SPACE_GSBUS) &&
252 context && field_obj) {
253
254
255
256 context->connection = field_obj->field.resource_buffer;
257 context->length = field_obj->field.resource_length;
258 context->access_length = field_obj->field.access_length;
259 }
260 if ((region_obj->region.space_id == ACPI_ADR_SPACE_GPIO) &&
261 context && field_obj) {
262
263
264
265 context->connection = field_obj->field.resource_buffer;
266 context->length = field_obj->field.resource_length;
267 context->access_length = field_obj->field.access_length;
268 address = field_obj->field.pin_number_index;
269 bit_width = field_obj->field.bit_length;
270 }
271
272 ACPI_DEBUG_PRINT((ACPI_DB_OPREGION,
273 "Handler %p (@%p) Address %8.8X%8.8X [%s]\n",
274 ®ion_obj->region.handler->address_space, handler,
275 ACPI_FORMAT_NATIVE_UINT(address),
276 acpi_ut_get_region_name(region_obj->region.
277 space_id)));
278
279 if (!(handler_desc->address_space.handler_flags &
280 ACPI_ADDR_HANDLER_DEFAULT_INSTALLED)) {
281
282
283
284
285
286 acpi_ex_exit_interpreter();
287 }
288
289
290
291 status = handler(function, address, bit_width, value, context,
292 region_obj2->extra.region_context);
293
294 if (ACPI_FAILURE(status)) {
295 ACPI_EXCEPTION((AE_INFO, status, "Returned by Handler for [%s]",
296 acpi_ut_get_region_name(region_obj->region.
297 space_id)));
298 }
299
300 if (!(handler_desc->address_space.handler_flags &
301 ACPI_ADDR_HANDLER_DEFAULT_INSTALLED)) {
302
303
304
305
306 acpi_ex_enter_interpreter();
307 }
308
309 return_ACPI_STATUS(status);
310}
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326void
327acpi_ev_detach_region(union acpi_operand_object *region_obj,
328 u8 acpi_ns_is_locked)
329{
330 union acpi_operand_object *handler_obj;
331 union acpi_operand_object *obj_desc;
332 union acpi_operand_object *start_desc;
333 union acpi_operand_object **last_obj_ptr;
334 acpi_adr_space_setup region_setup;
335 void **region_context;
336 union acpi_operand_object *region_obj2;
337 acpi_status status;
338
339 ACPI_FUNCTION_TRACE(ev_detach_region);
340
341 region_obj2 = acpi_ns_get_secondary_object(region_obj);
342 if (!region_obj2) {
343 return_VOID;
344 }
345 region_context = ®ion_obj2->extra.region_context;
346
347
348
349 handler_obj = region_obj->region.handler;
350 if (!handler_obj) {
351
352
353
354 return_VOID;
355 }
356
357
358
359 obj_desc = handler_obj->address_space.region_list;
360 start_desc = obj_desc;
361 last_obj_ptr = &handler_obj->address_space.region_list;
362
363 while (obj_desc) {
364
365
366
367 if (obj_desc == region_obj) {
368 ACPI_DEBUG_PRINT((ACPI_DB_OPREGION,
369 "Removing Region %p from address handler %p\n",
370 region_obj, handler_obj));
371
372
373
374 *last_obj_ptr = obj_desc->region.next;
375 obj_desc->region.next = NULL;
376
377 if (acpi_ns_is_locked) {
378 status =
379 acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
380 if (ACPI_FAILURE(status)) {
381 return_VOID;
382 }
383 }
384
385
386
387 status =
388 acpi_ev_execute_reg_method(region_obj,
389 ACPI_REG_DISCONNECT);
390 if (ACPI_FAILURE(status)) {
391 ACPI_EXCEPTION((AE_INFO, status,
392 "from region _REG, [%s]",
393 acpi_ut_get_region_name
394 (region_obj->region.space_id)));
395 }
396
397 if (acpi_ns_is_locked) {
398 status =
399 acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
400 if (ACPI_FAILURE(status)) {
401 return_VOID;
402 }
403 }
404
405
406
407
408
409 if (region_obj->region.flags & AOPOBJ_SETUP_COMPLETE) {
410 region_setup = handler_obj->address_space.setup;
411 status =
412 region_setup(region_obj,
413 ACPI_REGION_DEACTIVATE,
414 handler_obj->address_space.
415 context, region_context);
416
417
418
419
420
421 if (region_context) {
422 *region_context = NULL;
423 }
424
425
426
427 if (ACPI_FAILURE(status)) {
428 ACPI_EXCEPTION((AE_INFO, status,
429 "from region handler - deactivate, [%s]",
430 acpi_ut_get_region_name
431 (region_obj->region.
432 space_id)));
433 }
434
435 region_obj->region.flags &=
436 ~(AOPOBJ_SETUP_COMPLETE);
437 }
438
439
440
441
442
443
444
445
446
447
448 region_obj->region.handler = NULL;
449 acpi_ut_remove_reference(handler_obj);
450
451 return_VOID;
452 }
453
454
455
456 last_obj_ptr = &obj_desc->region.next;
457 obj_desc = obj_desc->region.next;
458
459
460
461 if (obj_desc == start_desc) {
462 ACPI_ERROR((AE_INFO,
463 "Circular handler list in region object %p",
464 region_obj));
465 return_VOID;
466 }
467 }
468
469
470
471 ACPI_DEBUG_PRINT((ACPI_DB_OPREGION,
472 "Cannot remove region %p from address handler %p\n",
473 region_obj, handler_obj));
474
475 return_VOID;
476}
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493acpi_status
494acpi_ev_attach_region(union acpi_operand_object *handler_obj,
495 union acpi_operand_object *region_obj,
496 u8 acpi_ns_is_locked)
497{
498
499 ACPI_FUNCTION_TRACE(ev_attach_region);
500
501 ACPI_DEBUG_PRINT((ACPI_DB_OPREGION,
502 "Adding Region [%4.4s] %p to address handler %p [%s]\n",
503 acpi_ut_get_node_name(region_obj->region.node),
504 region_obj, handler_obj,
505 acpi_ut_get_region_name(region_obj->region.
506 space_id)));
507
508
509
510 region_obj->region.next = handler_obj->address_space.region_list;
511 handler_obj->address_space.region_list = region_obj;
512
513
514
515 if (region_obj->region.handler) {
516 return_ACPI_STATUS(AE_ALREADY_EXISTS);
517 }
518
519 region_obj->region.handler = handler_obj;
520 acpi_ut_add_reference(handler_obj);
521
522 return_ACPI_STATUS(AE_OK);
523}
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538acpi_status
539acpi_ev_execute_reg_method(union acpi_operand_object *region_obj, u32 function)
540{
541 struct acpi_evaluate_info *info;
542 union acpi_operand_object *args[3];
543 union acpi_operand_object *region_obj2;
544 acpi_status status;
545
546 ACPI_FUNCTION_TRACE(ev_execute_reg_method);
547
548 region_obj2 = acpi_ns_get_secondary_object(region_obj);
549 if (!region_obj2) {
550 return_ACPI_STATUS(AE_NOT_EXIST);
551 }
552
553 if (region_obj2->extra.method_REG == NULL) {
554 return_ACPI_STATUS(AE_OK);
555 }
556
557
558
559 info = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_evaluate_info));
560 if (!info) {
561 return_ACPI_STATUS(AE_NO_MEMORY);
562 }
563
564 info->prefix_node = region_obj2->extra.method_REG;
565 info->relative_pathname = NULL;
566 info->parameters = args;
567 info->flags = ACPI_IGNORE_RETURN_VALUE;
568
569
570
571
572
573
574
575
576
577
578
579 args[0] =
580 acpi_ut_create_integer_object((u64)region_obj->region.space_id);
581 if (!args[0]) {
582 status = AE_NO_MEMORY;
583 goto cleanup1;
584 }
585
586 args[1] = acpi_ut_create_integer_object((u64)function);
587 if (!args[1]) {
588 status = AE_NO_MEMORY;
589 goto cleanup2;
590 }
591
592 args[2] = NULL;
593
594
595
596 ACPI_DEBUG_EXEC(acpi_ut_display_init_pathname
597 (ACPI_TYPE_METHOD, info->prefix_node, NULL));
598
599 status = acpi_ns_evaluate(info);
600 acpi_ut_remove_reference(args[1]);
601
602cleanup2:
603 acpi_ut_remove_reference(args[0]);
604
605cleanup1:
606 ACPI_FREE(info);
607 return_ACPI_STATUS(status);
608}
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624acpi_status
625acpi_ev_execute_reg_methods(struct acpi_namespace_node *node,
626 acpi_adr_space_type space_id)
627{
628 acpi_status status;
629
630 ACPI_FUNCTION_TRACE(ev_execute_reg_methods);
631
632
633
634
635
636
637
638 status = acpi_ns_walk_namespace(ACPI_TYPE_ANY, node, ACPI_UINT32_MAX,
639 ACPI_NS_WALK_UNLOCK, acpi_ev_reg_run,
640 NULL, &space_id, NULL);
641
642
643
644 if (space_id == ACPI_ADR_SPACE_EC) {
645 acpi_ev_orphan_ec_reg_method(node);
646 }
647
648 return_ACPI_STATUS(status);
649}
650
651
652
653
654
655
656
657
658
659
660
661static acpi_status
662acpi_ev_reg_run(acpi_handle obj_handle,
663 u32 level, void *context, void **return_value)
664{
665 union acpi_operand_object *obj_desc;
666 struct acpi_namespace_node *node;
667 acpi_adr_space_type space_id;
668 acpi_status status;
669
670 space_id = *ACPI_CAST_PTR(acpi_adr_space_type, context);
671
672
673
674 node = acpi_ns_validate_handle(obj_handle);
675 if (!node) {
676 return (AE_BAD_PARAMETER);
677 }
678
679
680
681
682
683 if ((node->type != ACPI_TYPE_REGION) && (node != acpi_gbl_root_node)) {
684 return (AE_OK);
685 }
686
687
688
689 obj_desc = acpi_ns_get_attached_object(node);
690 if (!obj_desc) {
691
692
693
694 return (AE_OK);
695 }
696
697
698
699 if (obj_desc->region.space_id != space_id) {
700
701
702
703 return (AE_OK);
704 }
705
706 status = acpi_ev_execute_reg_method(obj_desc, ACPI_REG_CONNECT);
707 return (status);
708}
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735static void
736acpi_ev_orphan_ec_reg_method(struct acpi_namespace_node *ec_device_node)
737{
738 acpi_handle reg_method;
739 struct acpi_namespace_node *next_node;
740 acpi_status status;
741 struct acpi_object_list args;
742 union acpi_object objects[2];
743
744 ACPI_FUNCTION_TRACE(ev_orphan_ec_reg_method);
745
746 if (!ec_device_node) {
747 return_VOID;
748 }
749
750
751
752 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
753
754
755
756 status = acpi_get_handle(ec_device_node, METHOD_NAME__REG, ®_method);
757 if (ACPI_FAILURE(status)) {
758 goto exit;
759 }
760
761
762
763
764
765
766
767
768 next_node = acpi_ns_get_next_node(ec_device_node, NULL);
769 while (next_node) {
770 if ((next_node->type == ACPI_TYPE_REGION) &&
771 (next_node->object) &&
772 (next_node->object->region.space_id == ACPI_ADR_SPACE_EC)) {
773 goto exit;
774 }
775
776 next_node = acpi_ns_get_next_node(ec_device_node, next_node);
777 }
778
779
780
781 args.count = 2;
782 args.pointer = objects;
783 objects[0].type = ACPI_TYPE_INTEGER;
784 objects[0].integer.value = ACPI_ADR_SPACE_EC;
785 objects[1].type = ACPI_TYPE_INTEGER;
786 objects[1].integer.value = ACPI_REG_CONNECT;
787
788 status = acpi_evaluate_object(reg_method, NULL, &args, NULL);
789
790exit:
791
792
793 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
794 return_VOID;
795}
796