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#define EXPORT_ACPI_INTERFACES
45
46#include <acpi/acpi.h>
47#include "accommon.h"
48#include "acevents.h"
49#include "acnamesp.h"
50
51#define _COMPONENT ACPI_EVENTS
52ACPI_MODULE_NAME("evxfgpe")
53
54#if (!ACPI_REDUCED_HARDWARE)
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77acpi_status acpi_update_all_gpes(void)
78{
79 acpi_status status;
80
81 ACPI_FUNCTION_TRACE(acpi_update_all_gpes);
82
83 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
84 if (ACPI_FAILURE(status)) {
85 return_ACPI_STATUS(status);
86 }
87
88 if (acpi_gbl_all_gpes_initialized) {
89 goto unlock_and_exit;
90 }
91
92 status = acpi_ev_walk_gpe_list(acpi_ev_initialize_gpe_block, NULL);
93 if (ACPI_SUCCESS(status)) {
94 acpi_gbl_all_gpes_initialized = TRUE;
95 }
96
97unlock_and_exit:
98 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
99
100 return_ACPI_STATUS(status);
101}
102
103ACPI_EXPORT_SYMBOL(acpi_update_all_gpes)
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118acpi_status acpi_enable_gpe(acpi_handle gpe_device, u32 gpe_number)
119{
120 acpi_status status = AE_BAD_PARAMETER;
121 struct acpi_gpe_event_info *gpe_event_info;
122 acpi_cpu_flags flags;
123
124 ACPI_FUNCTION_TRACE(acpi_enable_gpe);
125
126 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
127
128
129
130
131
132
133 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
134 if (gpe_event_info) {
135 if (ACPI_GPE_DISPATCH_TYPE(gpe_event_info->flags) !=
136 ACPI_GPE_DISPATCH_NONE) {
137 status = acpi_ev_add_gpe_reference(gpe_event_info);
138 } else {
139 status = AE_NO_HANDLER;
140 }
141 }
142
143 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
144 return_ACPI_STATUS(status);
145}
146ACPI_EXPORT_SYMBOL(acpi_enable_gpe)
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163acpi_status acpi_disable_gpe(acpi_handle gpe_device, u32 gpe_number)
164{
165 acpi_status status = AE_BAD_PARAMETER;
166 struct acpi_gpe_event_info *gpe_event_info;
167 acpi_cpu_flags flags;
168
169 ACPI_FUNCTION_TRACE(acpi_disable_gpe);
170
171 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
172
173
174
175 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
176 if (gpe_event_info) {
177 status = acpi_ev_remove_gpe_reference(gpe_event_info) ;
178 }
179
180 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
181 return_ACPI_STATUS(status);
182}
183
184ACPI_EXPORT_SYMBOL(acpi_disable_gpe)
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214acpi_status acpi_set_gpe(acpi_handle gpe_device, u32 gpe_number, u8 action)
215{
216 struct acpi_gpe_event_info *gpe_event_info;
217 acpi_status status;
218 acpi_cpu_flags flags;
219
220 ACPI_FUNCTION_TRACE(acpi_set_gpe);
221
222 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
223
224
225
226 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
227 if (!gpe_event_info) {
228 status = AE_BAD_PARAMETER;
229 goto unlock_and_exit;
230 }
231
232
233
234 switch (action) {
235 case ACPI_GPE_ENABLE:
236
237 status = acpi_hw_low_set_gpe(gpe_event_info, ACPI_GPE_ENABLE);
238 gpe_event_info->disable_for_dispatch = FALSE;
239 break;
240
241 case ACPI_GPE_DISABLE:
242
243 status = acpi_hw_low_set_gpe(gpe_event_info, ACPI_GPE_DISABLE);
244 gpe_event_info->disable_for_dispatch = TRUE;
245 break;
246
247 default:
248
249 status = AE_BAD_PARAMETER;
250 break;
251 }
252
253unlock_and_exit:
254 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
255 return_ACPI_STATUS(status);
256}
257
258ACPI_EXPORT_SYMBOL(acpi_set_gpe)
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274acpi_status acpi_mask_gpe(acpi_handle gpe_device, u32 gpe_number, u8 is_masked)
275{
276 struct acpi_gpe_event_info *gpe_event_info;
277 acpi_status status;
278 acpi_cpu_flags flags;
279
280 ACPI_FUNCTION_TRACE(acpi_mask_gpe);
281
282 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
283
284
285
286 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
287 if (!gpe_event_info) {
288 status = AE_BAD_PARAMETER;
289 goto unlock_and_exit;
290 }
291
292 status = acpi_ev_mask_gpe(gpe_event_info, is_masked);
293
294unlock_and_exit:
295 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
296 return_ACPI_STATUS(status);
297}
298
299ACPI_EXPORT_SYMBOL(acpi_mask_gpe)
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321acpi_status acpi_mark_gpe_for_wake(acpi_handle gpe_device, u32 gpe_number)
322{
323 struct acpi_gpe_event_info *gpe_event_info;
324 acpi_status status = AE_BAD_PARAMETER;
325 acpi_cpu_flags flags;
326
327 ACPI_FUNCTION_TRACE(acpi_mark_gpe_for_wake);
328
329 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
330
331
332
333 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
334 if (gpe_event_info) {
335
336
337
338 gpe_event_info->flags |= ACPI_GPE_CAN_WAKE;
339 status = AE_OK;
340 }
341
342 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
343 return_ACPI_STATUS(status);
344}
345
346ACPI_EXPORT_SYMBOL(acpi_mark_gpe_for_wake)
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366acpi_status
367acpi_setup_gpe_for_wake(acpi_handle wake_device,
368 acpi_handle gpe_device, u32 gpe_number)
369{
370 acpi_status status;
371 struct acpi_gpe_event_info *gpe_event_info;
372 struct acpi_namespace_node *device_node;
373 struct acpi_gpe_notify_info *notify;
374 struct acpi_gpe_notify_info *new_notify;
375 acpi_cpu_flags flags;
376
377 ACPI_FUNCTION_TRACE(acpi_setup_gpe_for_wake);
378
379
380
381 if (!wake_device) {
382
383
384
385
386 return_ACPI_STATUS(AE_BAD_PARAMETER);
387 }
388
389
390
391 if (wake_device == ACPI_ROOT_OBJECT) {
392 device_node = acpi_gbl_root_node;
393 } else {
394 device_node =
395 ACPI_CAST_PTR(struct acpi_namespace_node, wake_device);
396 }
397
398
399
400 if (device_node->type != ACPI_TYPE_DEVICE) {
401 return_ACPI_STATUS (AE_BAD_PARAMETER);
402 }
403
404
405
406
407
408
409 new_notify = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_gpe_notify_info));
410 if (!new_notify) {
411 return_ACPI_STATUS(AE_NO_MEMORY);
412 }
413
414 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
415
416
417
418 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
419 if (!gpe_event_info) {
420 status = AE_BAD_PARAMETER;
421 goto unlock_and_exit;
422 }
423
424
425
426
427
428
429
430 if (ACPI_GPE_DISPATCH_TYPE(gpe_event_info->flags) ==
431 ACPI_GPE_DISPATCH_NONE) {
432
433
434
435
436 gpe_event_info->flags =
437 (ACPI_GPE_DISPATCH_NOTIFY | ACPI_GPE_LEVEL_TRIGGERED);
438 }
439
440
441
442
443
444 if (ACPI_GPE_DISPATCH_TYPE(gpe_event_info->flags) ==
445 ACPI_GPE_DISPATCH_NOTIFY) {
446
447
448
449 notify = gpe_event_info->dispatch.notify_list;
450 while (notify) {
451 if (notify->device_node == device_node) {
452 status = AE_ALREADY_EXISTS;
453 goto unlock_and_exit;
454 }
455 notify = notify->next;
456 }
457
458
459
460 new_notify->device_node = device_node;
461 new_notify->next = gpe_event_info->dispatch.notify_list;
462 gpe_event_info->dispatch.notify_list = new_notify;
463 new_notify = NULL;
464 }
465
466
467
468 gpe_event_info->flags |= ACPI_GPE_CAN_WAKE;
469 status = AE_OK;
470
471unlock_and_exit:
472 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
473
474
475
476 if (new_notify) {
477 ACPI_FREE(new_notify);
478 }
479 return_ACPI_STATUS(status);
480}
481ACPI_EXPORT_SYMBOL(acpi_setup_gpe_for_wake)
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498acpi_status
499acpi_set_gpe_wake_mask(acpi_handle gpe_device, u32 gpe_number, u8 action)
500{
501 acpi_status status = AE_OK;
502 struct acpi_gpe_event_info *gpe_event_info;
503 struct acpi_gpe_register_info *gpe_register_info;
504 acpi_cpu_flags flags;
505 u32 register_bit;
506
507 ACPI_FUNCTION_TRACE(acpi_set_gpe_wake_mask);
508
509 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
510
511
512
513
514
515 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
516 if (!gpe_event_info) {
517 status = AE_BAD_PARAMETER;
518 goto unlock_and_exit;
519 }
520
521 if (!(gpe_event_info->flags & ACPI_GPE_CAN_WAKE)) {
522 status = AE_TYPE;
523 goto unlock_and_exit;
524 }
525
526 gpe_register_info = gpe_event_info->register_info;
527 if (!gpe_register_info) {
528 status = AE_NOT_EXIST;
529 goto unlock_and_exit;
530 }
531
532 register_bit = acpi_hw_get_gpe_register_bit(gpe_event_info);
533
534
535
536 switch (action) {
537 case ACPI_GPE_ENABLE:
538
539 ACPI_SET_BIT(gpe_register_info->enable_for_wake,
540 (u8)register_bit);
541 break;
542
543 case ACPI_GPE_DISABLE:
544
545 ACPI_CLEAR_BIT(gpe_register_info->enable_for_wake,
546 (u8)register_bit);
547 break;
548
549 default:
550
551 ACPI_ERROR((AE_INFO, "%u, Invalid action", action));
552 status = AE_BAD_PARAMETER;
553 break;
554 }
555
556unlock_and_exit:
557 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
558 return_ACPI_STATUS(status);
559}
560
561ACPI_EXPORT_SYMBOL(acpi_set_gpe_wake_mask)
562
563
564
565
566
567
568
569
570
571
572
573
574
575acpi_status acpi_clear_gpe(acpi_handle gpe_device, u32 gpe_number)
576{
577 acpi_status status = AE_OK;
578 struct acpi_gpe_event_info *gpe_event_info;
579 acpi_cpu_flags flags;
580
581 ACPI_FUNCTION_TRACE(acpi_clear_gpe);
582
583 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
584
585
586
587 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
588 if (!gpe_event_info) {
589 status = AE_BAD_PARAMETER;
590 goto unlock_and_exit;
591 }
592
593 status = acpi_hw_clear_gpe(gpe_event_info);
594
595 unlock_and_exit:
596 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
597 return_ACPI_STATUS(status);
598}
599
600ACPI_EXPORT_SYMBOL(acpi_clear_gpe)
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616acpi_status
617acpi_get_gpe_status(acpi_handle gpe_device,
618 u32 gpe_number, acpi_event_status *event_status)
619{
620 acpi_status status = AE_OK;
621 struct acpi_gpe_event_info *gpe_event_info;
622 acpi_cpu_flags flags;
623
624 ACPI_FUNCTION_TRACE(acpi_get_gpe_status);
625
626 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
627
628
629
630 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
631 if (!gpe_event_info) {
632 status = AE_BAD_PARAMETER;
633 goto unlock_and_exit;
634 }
635
636
637
638 status = acpi_hw_get_gpe_status(gpe_event_info, event_status);
639
640unlock_and_exit:
641 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
642 return_ACPI_STATUS(status);
643}
644
645ACPI_EXPORT_SYMBOL(acpi_get_gpe_status)
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663acpi_status acpi_finish_gpe(acpi_handle gpe_device, u32 gpe_number)
664{
665 struct acpi_gpe_event_info *gpe_event_info;
666 acpi_status status;
667 acpi_cpu_flags flags;
668
669 ACPI_FUNCTION_TRACE(acpi_finish_gpe);
670
671 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
672
673
674
675 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
676 if (!gpe_event_info) {
677 status = AE_BAD_PARAMETER;
678 goto unlock_and_exit;
679 }
680
681 status = acpi_ev_finish_gpe(gpe_event_info);
682
683unlock_and_exit:
684 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
685 return_ACPI_STATUS(status);
686}
687
688ACPI_EXPORT_SYMBOL(acpi_finish_gpe)
689
690
691
692
693
694
695
696
697
698
699
700
701
702acpi_status acpi_disable_all_gpes(void)
703{
704 acpi_status status;
705
706 ACPI_FUNCTION_TRACE(acpi_disable_all_gpes);
707
708 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
709 if (ACPI_FAILURE(status)) {
710 return_ACPI_STATUS(status);
711 }
712
713 status = acpi_hw_disable_all_gpes();
714 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
715
716 return_ACPI_STATUS(status);
717}
718
719ACPI_EXPORT_SYMBOL(acpi_disable_all_gpes)
720
721
722
723
724
725
726
727
728
729
730
731
732
733acpi_status acpi_enable_all_runtime_gpes(void)
734{
735 acpi_status status;
736
737 ACPI_FUNCTION_TRACE(acpi_enable_all_runtime_gpes);
738
739 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
740 if (ACPI_FAILURE(status)) {
741 return_ACPI_STATUS(status);
742 }
743
744 status = acpi_hw_enable_all_runtime_gpes();
745 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
746
747 return_ACPI_STATUS(status);
748}
749
750ACPI_EXPORT_SYMBOL(acpi_enable_all_runtime_gpes)
751
752
753
754
755
756
757
758
759
760
761
762
763
764acpi_status acpi_enable_all_wakeup_gpes(void)
765{
766 acpi_status status;
767
768 ACPI_FUNCTION_TRACE(acpi_enable_all_wakeup_gpes);
769
770 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
771 if (ACPI_FAILURE(status)) {
772 return_ACPI_STATUS(status);
773 }
774
775 status = acpi_hw_enable_all_wakeup_gpes();
776 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
777
778 return_ACPI_STATUS(status);
779}
780
781ACPI_EXPORT_SYMBOL(acpi_enable_all_wakeup_gpes)
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798acpi_status
799acpi_install_gpe_block(acpi_handle gpe_device,
800 struct acpi_generic_address *gpe_block_address,
801 u32 register_count, u32 interrupt_number)
802{
803 acpi_status status;
804 union acpi_operand_object *obj_desc;
805 struct acpi_namespace_node *node;
806 struct acpi_gpe_block_info *gpe_block;
807
808 ACPI_FUNCTION_TRACE(acpi_install_gpe_block);
809
810 if ((!gpe_device) || (!gpe_block_address) || (!register_count)) {
811 return_ACPI_STATUS(AE_BAD_PARAMETER);
812 }
813
814 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
815 if (ACPI_FAILURE(status)) {
816 return_ACPI_STATUS(status);
817 }
818
819 node = acpi_ns_validate_handle(gpe_device);
820 if (!node) {
821 status = AE_BAD_PARAMETER;
822 goto unlock_and_exit;
823 }
824
825
826
827 if (node->type != ACPI_TYPE_DEVICE) {
828 status = AE_TYPE;
829 goto unlock_and_exit;
830 }
831
832 if (node->object) {
833 status = AE_ALREADY_EXISTS;
834 goto unlock_and_exit;
835 }
836
837
838
839
840
841 status = acpi_ev_create_gpe_block(node, gpe_block_address->address,
842 gpe_block_address->space_id,
843 register_count, 0, interrupt_number,
844 &gpe_block);
845 if (ACPI_FAILURE(status)) {
846 goto unlock_and_exit;
847 }
848
849
850
851 obj_desc = acpi_ns_get_attached_object(node);
852 if (!obj_desc) {
853
854
855
856
857
858 obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_DEVICE);
859 if (!obj_desc) {
860 status = AE_NO_MEMORY;
861 goto unlock_and_exit;
862 }
863
864 status =
865 acpi_ns_attach_object(node, obj_desc, ACPI_TYPE_DEVICE);
866
867
868
869 acpi_ut_remove_reference(obj_desc);
870
871 if (ACPI_FAILURE(status)) {
872 goto unlock_and_exit;
873 }
874 }
875
876
877
878 obj_desc->device.gpe_block = gpe_block;
879
880unlock_and_exit:
881 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
882 return_ACPI_STATUS(status);
883}
884
885ACPI_EXPORT_SYMBOL(acpi_install_gpe_block)
886
887
888
889
890
891
892
893
894
895
896
897
898acpi_status acpi_remove_gpe_block(acpi_handle gpe_device)
899{
900 union acpi_operand_object *obj_desc;
901 acpi_status status;
902 struct acpi_namespace_node *node;
903
904 ACPI_FUNCTION_TRACE(acpi_remove_gpe_block);
905
906 if (!gpe_device) {
907 return_ACPI_STATUS(AE_BAD_PARAMETER);
908 }
909
910 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
911 if (ACPI_FAILURE(status)) {
912 return_ACPI_STATUS(status);
913 }
914
915 node = acpi_ns_validate_handle(gpe_device);
916 if (!node) {
917 status = AE_BAD_PARAMETER;
918 goto unlock_and_exit;
919 }
920
921
922
923 if (node->type != ACPI_TYPE_DEVICE) {
924 status = AE_TYPE;
925 goto unlock_and_exit;
926 }
927
928
929
930 obj_desc = acpi_ns_get_attached_object(node);
931 if (!obj_desc || !obj_desc->device.gpe_block) {
932 return_ACPI_STATUS(AE_NULL_OBJECT);
933 }
934
935
936
937 status = acpi_ev_delete_gpe_block(obj_desc->device.gpe_block);
938 if (ACPI_SUCCESS(status)) {
939 obj_desc->device.gpe_block = NULL;
940 }
941
942unlock_and_exit:
943 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
944 return_ACPI_STATUS(status);
945}
946
947ACPI_EXPORT_SYMBOL(acpi_remove_gpe_block)
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963acpi_status acpi_get_gpe_device(u32 index, acpi_handle *gpe_device)
964{
965 struct acpi_gpe_device_info info;
966 acpi_status status;
967
968 ACPI_FUNCTION_TRACE(acpi_get_gpe_device);
969
970 if (!gpe_device) {
971 return_ACPI_STATUS(AE_BAD_PARAMETER);
972 }
973
974 if (index >= acpi_current_gpe_count) {
975 return_ACPI_STATUS(AE_NOT_EXIST);
976 }
977
978
979
980 info.index = index;
981 info.status = AE_NOT_EXIST;
982 info.gpe_device = NULL;
983 info.next_block_base_index = 0;
984
985 status = acpi_ev_walk_gpe_list(acpi_ev_get_gpe_device, &info);
986 if (ACPI_FAILURE(status)) {
987 return_ACPI_STATUS(status);
988 }
989
990 *gpe_device = ACPI_CAST_PTR(acpi_handle, info.gpe_device);
991 return_ACPI_STATUS(info.status);
992}
993
994ACPI_EXPORT_SYMBOL(acpi_get_gpe_device)
995#endif
996