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 } else if (gpe_event_info->flags & ACPI_GPE_AUTO_ENABLED) {
439
440
441
442
443
444 (void)acpi_ev_remove_gpe_reference(gpe_event_info);
445 gpe_event_info->flags &= ~ACPI_GPE_AUTO_ENABLED;
446 }
447
448
449
450
451
452 if (ACPI_GPE_DISPATCH_TYPE(gpe_event_info->flags) ==
453 ACPI_GPE_DISPATCH_NOTIFY) {
454
455
456
457 notify = gpe_event_info->dispatch.notify_list;
458 while (notify) {
459 if (notify->device_node == device_node) {
460 status = AE_ALREADY_EXISTS;
461 goto unlock_and_exit;
462 }
463 notify = notify->next;
464 }
465
466
467
468 new_notify->device_node = device_node;
469 new_notify->next = gpe_event_info->dispatch.notify_list;
470 gpe_event_info->dispatch.notify_list = new_notify;
471 new_notify = NULL;
472 }
473
474
475
476 gpe_event_info->flags |= ACPI_GPE_CAN_WAKE;
477 status = AE_OK;
478
479unlock_and_exit:
480 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
481
482
483
484 if (new_notify) {
485 ACPI_FREE(new_notify);
486 }
487 return_ACPI_STATUS(status);
488}
489ACPI_EXPORT_SYMBOL(acpi_setup_gpe_for_wake)
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506acpi_status
507acpi_set_gpe_wake_mask(acpi_handle gpe_device, u32 gpe_number, u8 action)
508{
509 acpi_status status = AE_OK;
510 struct acpi_gpe_event_info *gpe_event_info;
511 struct acpi_gpe_register_info *gpe_register_info;
512 acpi_cpu_flags flags;
513 u32 register_bit;
514
515 ACPI_FUNCTION_TRACE(acpi_set_gpe_wake_mask);
516
517 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
518
519
520
521
522
523 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
524 if (!gpe_event_info) {
525 status = AE_BAD_PARAMETER;
526 goto unlock_and_exit;
527 }
528
529 if (!(gpe_event_info->flags & ACPI_GPE_CAN_WAKE)) {
530 status = AE_TYPE;
531 goto unlock_and_exit;
532 }
533
534 gpe_register_info = gpe_event_info->register_info;
535 if (!gpe_register_info) {
536 status = AE_NOT_EXIST;
537 goto unlock_and_exit;
538 }
539
540 register_bit = acpi_hw_get_gpe_register_bit(gpe_event_info);
541
542
543
544 switch (action) {
545 case ACPI_GPE_ENABLE:
546
547 ACPI_SET_BIT(gpe_register_info->enable_for_wake,
548 (u8)register_bit);
549 break;
550
551 case ACPI_GPE_DISABLE:
552
553 ACPI_CLEAR_BIT(gpe_register_info->enable_for_wake,
554 (u8)register_bit);
555 break;
556
557 default:
558
559 ACPI_ERROR((AE_INFO, "%u, Invalid action", action));
560 status = AE_BAD_PARAMETER;
561 break;
562 }
563
564unlock_and_exit:
565 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
566 return_ACPI_STATUS(status);
567}
568
569ACPI_EXPORT_SYMBOL(acpi_set_gpe_wake_mask)
570
571
572
573
574
575
576
577
578
579
580
581
582
583acpi_status acpi_clear_gpe(acpi_handle gpe_device, u32 gpe_number)
584{
585 acpi_status status = AE_OK;
586 struct acpi_gpe_event_info *gpe_event_info;
587 acpi_cpu_flags flags;
588
589 ACPI_FUNCTION_TRACE(acpi_clear_gpe);
590
591 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
592
593
594
595 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
596 if (!gpe_event_info) {
597 status = AE_BAD_PARAMETER;
598 goto unlock_and_exit;
599 }
600
601 status = acpi_hw_clear_gpe(gpe_event_info);
602
603 unlock_and_exit:
604 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
605 return_ACPI_STATUS(status);
606}
607
608ACPI_EXPORT_SYMBOL(acpi_clear_gpe)
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624acpi_status
625acpi_get_gpe_status(acpi_handle gpe_device,
626 u32 gpe_number, acpi_event_status *event_status)
627{
628 acpi_status status = AE_OK;
629 struct acpi_gpe_event_info *gpe_event_info;
630 acpi_cpu_flags flags;
631
632 ACPI_FUNCTION_TRACE(acpi_get_gpe_status);
633
634 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
635
636
637
638 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
639 if (!gpe_event_info) {
640 status = AE_BAD_PARAMETER;
641 goto unlock_and_exit;
642 }
643
644
645
646 status = acpi_hw_get_gpe_status(gpe_event_info, event_status);
647
648unlock_and_exit:
649 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
650 return_ACPI_STATUS(status);
651}
652
653ACPI_EXPORT_SYMBOL(acpi_get_gpe_status)
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671acpi_status acpi_finish_gpe(acpi_handle gpe_device, u32 gpe_number)
672{
673 struct acpi_gpe_event_info *gpe_event_info;
674 acpi_status status;
675 acpi_cpu_flags flags;
676
677 ACPI_FUNCTION_TRACE(acpi_finish_gpe);
678
679 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
680
681
682
683 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
684 if (!gpe_event_info) {
685 status = AE_BAD_PARAMETER;
686 goto unlock_and_exit;
687 }
688
689 status = acpi_ev_finish_gpe(gpe_event_info);
690
691unlock_and_exit:
692 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
693 return_ACPI_STATUS(status);
694}
695
696ACPI_EXPORT_SYMBOL(acpi_finish_gpe)
697
698
699
700
701
702
703
704
705
706
707
708
709
710acpi_status acpi_disable_all_gpes(void)
711{
712 acpi_status status;
713
714 ACPI_FUNCTION_TRACE(acpi_disable_all_gpes);
715
716 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
717 if (ACPI_FAILURE(status)) {
718 return_ACPI_STATUS(status);
719 }
720
721 status = acpi_hw_disable_all_gpes();
722 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
723
724 return_ACPI_STATUS(status);
725}
726
727ACPI_EXPORT_SYMBOL(acpi_disable_all_gpes)
728
729
730
731
732
733
734
735
736
737
738
739
740
741acpi_status acpi_enable_all_runtime_gpes(void)
742{
743 acpi_status status;
744
745 ACPI_FUNCTION_TRACE(acpi_enable_all_runtime_gpes);
746
747 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
748 if (ACPI_FAILURE(status)) {
749 return_ACPI_STATUS(status);
750 }
751
752 status = acpi_hw_enable_all_runtime_gpes();
753 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
754
755 return_ACPI_STATUS(status);
756}
757
758ACPI_EXPORT_SYMBOL(acpi_enable_all_runtime_gpes)
759
760
761
762
763
764
765
766
767
768
769
770
771
772acpi_status acpi_enable_all_wakeup_gpes(void)
773{
774 acpi_status status;
775
776 ACPI_FUNCTION_TRACE(acpi_enable_all_wakeup_gpes);
777
778 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
779 if (ACPI_FAILURE(status)) {
780 return_ACPI_STATUS(status);
781 }
782
783 status = acpi_hw_enable_all_wakeup_gpes();
784 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
785
786 return_ACPI_STATUS(status);
787}
788
789ACPI_EXPORT_SYMBOL(acpi_enable_all_wakeup_gpes)
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806acpi_status
807acpi_install_gpe_block(acpi_handle gpe_device,
808 struct acpi_generic_address *gpe_block_address,
809 u32 register_count, u32 interrupt_number)
810{
811 acpi_status status;
812 union acpi_operand_object *obj_desc;
813 struct acpi_namespace_node *node;
814 struct acpi_gpe_block_info *gpe_block;
815
816 ACPI_FUNCTION_TRACE(acpi_install_gpe_block);
817
818 if ((!gpe_device) || (!gpe_block_address) || (!register_count)) {
819 return_ACPI_STATUS(AE_BAD_PARAMETER);
820 }
821
822 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
823 if (ACPI_FAILURE(status)) {
824 return_ACPI_STATUS(status);
825 }
826
827 node = acpi_ns_validate_handle(gpe_device);
828 if (!node) {
829 status = AE_BAD_PARAMETER;
830 goto unlock_and_exit;
831 }
832
833
834
835 if (node->type != ACPI_TYPE_DEVICE) {
836 status = AE_TYPE;
837 goto unlock_and_exit;
838 }
839
840 if (node->object) {
841 status = AE_ALREADY_EXISTS;
842 goto unlock_and_exit;
843 }
844
845
846
847
848
849 status = acpi_ev_create_gpe_block(node, gpe_block_address->address,
850 gpe_block_address->space_id,
851 register_count, 0, interrupt_number,
852 &gpe_block);
853 if (ACPI_FAILURE(status)) {
854 goto unlock_and_exit;
855 }
856
857
858
859 obj_desc = acpi_ns_get_attached_object(node);
860 if (!obj_desc) {
861
862
863
864
865
866 obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_DEVICE);
867 if (!obj_desc) {
868 status = AE_NO_MEMORY;
869 goto unlock_and_exit;
870 }
871
872 status =
873 acpi_ns_attach_object(node, obj_desc, ACPI_TYPE_DEVICE);
874
875
876
877 acpi_ut_remove_reference(obj_desc);
878
879 if (ACPI_FAILURE(status)) {
880 goto unlock_and_exit;
881 }
882 }
883
884
885
886 obj_desc->device.gpe_block = gpe_block;
887
888unlock_and_exit:
889 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
890 return_ACPI_STATUS(status);
891}
892
893ACPI_EXPORT_SYMBOL(acpi_install_gpe_block)
894
895
896
897
898
899
900
901
902
903
904
905
906acpi_status acpi_remove_gpe_block(acpi_handle gpe_device)
907{
908 union acpi_operand_object *obj_desc;
909 acpi_status status;
910 struct acpi_namespace_node *node;
911
912 ACPI_FUNCTION_TRACE(acpi_remove_gpe_block);
913
914 if (!gpe_device) {
915 return_ACPI_STATUS(AE_BAD_PARAMETER);
916 }
917
918 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
919 if (ACPI_FAILURE(status)) {
920 return_ACPI_STATUS(status);
921 }
922
923 node = acpi_ns_validate_handle(gpe_device);
924 if (!node) {
925 status = AE_BAD_PARAMETER;
926 goto unlock_and_exit;
927 }
928
929
930
931 if (node->type != ACPI_TYPE_DEVICE) {
932 status = AE_TYPE;
933 goto unlock_and_exit;
934 }
935
936
937
938 obj_desc = acpi_ns_get_attached_object(node);
939 if (!obj_desc || !obj_desc->device.gpe_block) {
940 return_ACPI_STATUS(AE_NULL_OBJECT);
941 }
942
943
944
945 status = acpi_ev_delete_gpe_block(obj_desc->device.gpe_block);
946 if (ACPI_SUCCESS(status)) {
947 obj_desc->device.gpe_block = NULL;
948 }
949
950unlock_and_exit:
951 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
952 return_ACPI_STATUS(status);
953}
954
955ACPI_EXPORT_SYMBOL(acpi_remove_gpe_block)
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971acpi_status acpi_get_gpe_device(u32 index, acpi_handle *gpe_device)
972{
973 struct acpi_gpe_device_info info;
974 acpi_status status;
975
976 ACPI_FUNCTION_TRACE(acpi_get_gpe_device);
977
978 if (!gpe_device) {
979 return_ACPI_STATUS(AE_BAD_PARAMETER);
980 }
981
982 if (index >= acpi_current_gpe_count) {
983 return_ACPI_STATUS(AE_NOT_EXIST);
984 }
985
986
987
988 info.index = index;
989 info.status = AE_NOT_EXIST;
990 info.gpe_device = NULL;
991 info.next_block_base_index = 0;
992
993 status = acpi_ev_walk_gpe_list(acpi_ev_get_gpe_device, &info);
994 if (ACPI_FAILURE(status)) {
995 return_ACPI_STATUS(status);
996 }
997
998 *gpe_device = ACPI_CAST_PTR(acpi_handle, info.gpe_device);
999 return_ACPI_STATUS(info.status);
1000}
1001
1002ACPI_EXPORT_SYMBOL(acpi_get_gpe_device)
1003#endif
1004