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