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 "acnamesp.h"
15#include "acevents.h"
16#include "acinterp.h"
17
18#define _COMPONENT ACPI_EVENTS
19ACPI_MODULE_NAME("evxface")
20#if (!ACPI_REDUCED_HARDWARE)
21
22static acpi_status
23acpi_ev_install_gpe_handler(acpi_handle gpe_device,
24 u32 gpe_number,
25 u32 type,
26 u8 is_raw_handler,
27 acpi_gpe_handler address, void *context);
28
29#endif
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56acpi_status
57acpi_install_notify_handler(acpi_handle device,
58 u32 handler_type,
59 acpi_notify_handler handler, void *context)
60{
61 struct acpi_namespace_node *node =
62 ACPI_CAST_PTR(struct acpi_namespace_node, device);
63 union acpi_operand_object *obj_desc;
64 union acpi_operand_object *handler_obj;
65 acpi_status status;
66 u32 i;
67
68 ACPI_FUNCTION_TRACE(acpi_install_notify_handler);
69
70
71
72 if ((!device) || (!handler) || (!handler_type) ||
73 (handler_type > ACPI_MAX_NOTIFY_HANDLER_TYPE)) {
74 return_ACPI_STATUS(AE_BAD_PARAMETER);
75 }
76
77 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
78 if (ACPI_FAILURE(status)) {
79 return_ACPI_STATUS(status);
80 }
81
82
83
84
85
86
87
88
89 if (device == ACPI_ROOT_OBJECT) {
90 for (i = 0; i < ACPI_NUM_NOTIFY_TYPES; i++) {
91 if (handler_type & (i + 1)) {
92 if (acpi_gbl_global_notify[i].handler) {
93 status = AE_ALREADY_EXISTS;
94 goto unlock_and_exit;
95 }
96
97 acpi_gbl_global_notify[i].handler = handler;
98 acpi_gbl_global_notify[i].context = context;
99 }
100 }
101
102 goto unlock_and_exit;
103 }
104
105
106
107
108
109
110
111
112
113
114 if (!acpi_ev_is_notify_object(node)) {
115 status = AE_TYPE;
116 goto unlock_and_exit;
117 }
118
119
120
121 obj_desc = acpi_ns_get_attached_object(node);
122 if (!obj_desc) {
123
124
125
126 obj_desc = acpi_ut_create_internal_object(node->type);
127 if (!obj_desc) {
128 status = AE_NO_MEMORY;
129 goto unlock_and_exit;
130 }
131
132
133
134 status = acpi_ns_attach_object(device, obj_desc, node->type);
135 acpi_ut_remove_reference(obj_desc);
136 if (ACPI_FAILURE(status)) {
137 goto unlock_and_exit;
138 }
139 }
140
141
142
143 for (i = 0; i < ACPI_NUM_NOTIFY_TYPES; i++) {
144 if (handler_type & (i + 1)) {
145 handler_obj = obj_desc->common_notify.notify_list[i];
146 while (handler_obj) {
147 if (handler_obj->notify.handler == handler) {
148 status = AE_ALREADY_EXISTS;
149 goto unlock_and_exit;
150 }
151
152 handler_obj = handler_obj->notify.next[i];
153 }
154 }
155 }
156
157
158
159 handler_obj = acpi_ut_create_internal_object(ACPI_TYPE_LOCAL_NOTIFY);
160 if (!handler_obj) {
161 status = AE_NO_MEMORY;
162 goto unlock_and_exit;
163 }
164
165 handler_obj->notify.node = node;
166 handler_obj->notify.handler_type = handler_type;
167 handler_obj->notify.handler = handler;
168 handler_obj->notify.context = context;
169
170
171
172 for (i = 0; i < ACPI_NUM_NOTIFY_TYPES; i++) {
173 if (handler_type & (i + 1)) {
174 handler_obj->notify.next[i] =
175 obj_desc->common_notify.notify_list[i];
176
177 obj_desc->common_notify.notify_list[i] = handler_obj;
178 }
179 }
180
181
182
183 if (handler_type == ACPI_ALL_NOTIFY) {
184 acpi_ut_add_reference(handler_obj);
185 }
186
187unlock_and_exit:
188 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
189 return_ACPI_STATUS(status);
190}
191
192ACPI_EXPORT_SYMBOL(acpi_install_notify_handler)
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210acpi_status
211acpi_remove_notify_handler(acpi_handle device,
212 u32 handler_type, acpi_notify_handler handler)
213{
214 struct acpi_namespace_node *node =
215 ACPI_CAST_PTR(struct acpi_namespace_node, device);
216 union acpi_operand_object *obj_desc;
217 union acpi_operand_object *handler_obj;
218 union acpi_operand_object *previous_handler_obj;
219 acpi_status status = AE_OK;
220 u32 i;
221
222 ACPI_FUNCTION_TRACE(acpi_remove_notify_handler);
223
224
225
226 if ((!device) || (!handler) || (!handler_type) ||
227 (handler_type > ACPI_MAX_NOTIFY_HANDLER_TYPE)) {
228 return_ACPI_STATUS(AE_BAD_PARAMETER);
229 }
230
231
232
233 if (device == ACPI_ROOT_OBJECT) {
234 for (i = 0; i < ACPI_NUM_NOTIFY_TYPES; i++) {
235 if (handler_type & (i + 1)) {
236 status =
237 acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
238 if (ACPI_FAILURE(status)) {
239 return_ACPI_STATUS(status);
240 }
241
242 if (!acpi_gbl_global_notify[i].handler ||
243 (acpi_gbl_global_notify[i].handler !=
244 handler)) {
245 status = AE_NOT_EXIST;
246 goto unlock_and_exit;
247 }
248
249 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
250 "Removing global notify handler\n"));
251
252 acpi_gbl_global_notify[i].handler = NULL;
253 acpi_gbl_global_notify[i].context = NULL;
254
255 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
256
257
258
259 acpi_os_wait_events_complete();
260 }
261 }
262
263 return_ACPI_STATUS(AE_OK);
264 }
265
266
267
268 if (!acpi_ev_is_notify_object(node)) {
269 return_ACPI_STATUS(AE_TYPE);
270 }
271
272
273
274 obj_desc = acpi_ns_get_attached_object(node);
275 if (!obj_desc) {
276 return_ACPI_STATUS(AE_NOT_EXIST);
277 }
278
279
280
281 for (i = 0; i < ACPI_NUM_NOTIFY_TYPES; i++) {
282 if (handler_type & (i + 1)) {
283 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
284 if (ACPI_FAILURE(status)) {
285 return_ACPI_STATUS(status);
286 }
287
288 handler_obj = obj_desc->common_notify.notify_list[i];
289 previous_handler_obj = NULL;
290
291
292
293 while (handler_obj &&
294 (handler_obj->notify.handler != handler)) {
295 previous_handler_obj = handler_obj;
296 handler_obj = handler_obj->notify.next[i];
297 }
298
299 if (!handler_obj) {
300 status = AE_NOT_EXIST;
301 goto unlock_and_exit;
302 }
303
304
305
306 if (previous_handler_obj) {
307 previous_handler_obj->notify.next[i] =
308 handler_obj->notify.next[i];
309 } else {
310
311 obj_desc->common_notify.notify_list[i] =
312 handler_obj->notify.next[i];
313 }
314
315 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
316
317
318
319 acpi_os_wait_events_complete();
320 acpi_ut_remove_reference(handler_obj);
321 }
322 }
323
324 return_ACPI_STATUS(status);
325
326unlock_and_exit:
327 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
328 return_ACPI_STATUS(status);
329}
330
331ACPI_EXPORT_SYMBOL(acpi_remove_notify_handler)
332
333
334
335
336
337
338
339
340
341
342
343
344
345#ifdef ACPI_FUTURE_USAGE
346acpi_status acpi_install_exception_handler(acpi_exception_handler handler)
347{
348 acpi_status status;
349
350 ACPI_FUNCTION_TRACE(acpi_install_exception_handler);
351
352 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
353 if (ACPI_FAILURE(status)) {
354 return_ACPI_STATUS(status);
355 }
356
357
358
359 if (acpi_gbl_exception_handler) {
360 status = AE_ALREADY_EXISTS;
361 goto cleanup;
362 }
363
364
365
366 acpi_gbl_exception_handler = handler;
367
368cleanup:
369 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
370 return_ACPI_STATUS(status);
371}
372
373ACPI_EXPORT_SYMBOL(acpi_install_exception_handler)
374#endif
375
376#if (!ACPI_REDUCED_HARDWARE)
377
378
379
380
381
382
383
384
385
386
387
388
389acpi_status acpi_install_sci_handler(acpi_sci_handler address, void *context)
390{
391 struct acpi_sci_handler_info *new_sci_handler;
392 struct acpi_sci_handler_info *sci_handler;
393 acpi_cpu_flags flags;
394 acpi_status status;
395
396 ACPI_FUNCTION_TRACE(acpi_install_sci_handler);
397
398 if (!address) {
399 return_ACPI_STATUS(AE_BAD_PARAMETER);
400 }
401
402
403
404 new_sci_handler = ACPI_ALLOCATE(sizeof(struct acpi_sci_handler_info));
405 if (!new_sci_handler) {
406 return_ACPI_STATUS(AE_NO_MEMORY);
407 }
408
409 new_sci_handler->address = address;
410 new_sci_handler->context = context;
411
412 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
413 if (ACPI_FAILURE(status)) {
414 goto exit;
415 }
416
417
418
419 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
420 sci_handler = acpi_gbl_sci_handler_list;
421
422
423
424 while (sci_handler) {
425 if (address == sci_handler->address) {
426 status = AE_ALREADY_EXISTS;
427 goto unlock_and_exit;
428 }
429
430 sci_handler = sci_handler->next;
431 }
432
433
434
435 new_sci_handler->next = acpi_gbl_sci_handler_list;
436 acpi_gbl_sci_handler_list = new_sci_handler;
437
438unlock_and_exit:
439
440 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
441 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
442
443exit:
444 if (ACPI_FAILURE(status)) {
445 ACPI_FREE(new_sci_handler);
446 }
447 return_ACPI_STATUS(status);
448}
449
450ACPI_EXPORT_SYMBOL(acpi_install_sci_handler)
451
452
453
454
455
456
457
458
459
460
461
462
463acpi_status acpi_remove_sci_handler(acpi_sci_handler address)
464{
465 struct acpi_sci_handler_info *prev_sci_handler;
466 struct acpi_sci_handler_info *next_sci_handler;
467 acpi_cpu_flags flags;
468 acpi_status status;
469
470 ACPI_FUNCTION_TRACE(acpi_remove_sci_handler);
471
472 if (!address) {
473 return_ACPI_STATUS(AE_BAD_PARAMETER);
474 }
475
476 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
477 if (ACPI_FAILURE(status)) {
478 return_ACPI_STATUS(status);
479 }
480
481
482
483 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
484
485 prev_sci_handler = NULL;
486 next_sci_handler = acpi_gbl_sci_handler_list;
487 while (next_sci_handler) {
488 if (next_sci_handler->address == address) {
489
490
491
492 if (prev_sci_handler) {
493 prev_sci_handler->next = next_sci_handler->next;
494 } else {
495 acpi_gbl_sci_handler_list =
496 next_sci_handler->next;
497 }
498
499 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
500 ACPI_FREE(next_sci_handler);
501 goto unlock_and_exit;
502 }
503
504 prev_sci_handler = next_sci_handler;
505 next_sci_handler = next_sci_handler->next;
506 }
507
508 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
509 status = AE_NOT_EXIST;
510
511unlock_and_exit:
512 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
513 return_ACPI_STATUS(status);
514}
515
516ACPI_EXPORT_SYMBOL(acpi_remove_sci_handler)
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533acpi_status
534acpi_install_global_event_handler(acpi_gbl_event_handler handler, void *context)
535{
536 acpi_status status;
537
538 ACPI_FUNCTION_TRACE(acpi_install_global_event_handler);
539
540
541
542 if (!handler) {
543 return_ACPI_STATUS(AE_BAD_PARAMETER);
544 }
545
546 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
547 if (ACPI_FAILURE(status)) {
548 return_ACPI_STATUS(status);
549 }
550
551
552
553 if (acpi_gbl_global_event_handler) {
554 status = AE_ALREADY_EXISTS;
555 goto cleanup;
556 }
557
558 acpi_gbl_global_event_handler = handler;
559 acpi_gbl_global_event_handler_context = context;
560
561cleanup:
562 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
563 return_ACPI_STATUS(status);
564}
565
566ACPI_EXPORT_SYMBOL(acpi_install_global_event_handler)
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583acpi_status
584acpi_install_fixed_event_handler(u32 event,
585 acpi_event_handler handler, void *context)
586{
587 acpi_status status;
588
589 ACPI_FUNCTION_TRACE(acpi_install_fixed_event_handler);
590
591
592
593 if (event > ACPI_EVENT_MAX) {
594 return_ACPI_STATUS(AE_BAD_PARAMETER);
595 }
596
597 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
598 if (ACPI_FAILURE(status)) {
599 return_ACPI_STATUS(status);
600 }
601
602
603
604 if (acpi_gbl_fixed_event_handlers[event].handler) {
605 status = AE_ALREADY_EXISTS;
606 goto cleanup;
607 }
608
609
610
611 acpi_gbl_fixed_event_handlers[event].handler = handler;
612 acpi_gbl_fixed_event_handlers[event].context = context;
613
614 status = acpi_clear_event(event);
615 if (ACPI_SUCCESS(status))
616 status = acpi_enable_event(event, 0);
617 if (ACPI_FAILURE(status)) {
618 ACPI_WARNING((AE_INFO,
619 "Could not enable fixed event - %s (%u)",
620 acpi_ut_get_event_name(event), event));
621
622
623
624 acpi_gbl_fixed_event_handlers[event].handler = NULL;
625 acpi_gbl_fixed_event_handlers[event].context = NULL;
626 } else {
627 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
628 "Enabled fixed event %s (%X), Handler=%p\n",
629 acpi_ut_get_event_name(event), event,
630 handler));
631 }
632
633cleanup:
634 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
635 return_ACPI_STATUS(status);
636}
637
638ACPI_EXPORT_SYMBOL(acpi_install_fixed_event_handler)
639
640
641
642
643
644
645
646
647
648
649
650
651
652acpi_status
653acpi_remove_fixed_event_handler(u32 event, acpi_event_handler handler)
654{
655 acpi_status status = AE_OK;
656
657 ACPI_FUNCTION_TRACE(acpi_remove_fixed_event_handler);
658
659
660
661 if (event > ACPI_EVENT_MAX) {
662 return_ACPI_STATUS(AE_BAD_PARAMETER);
663 }
664
665 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
666 if (ACPI_FAILURE(status)) {
667 return_ACPI_STATUS(status);
668 }
669
670
671
672 status = acpi_disable_event(event, 0);
673
674
675
676 acpi_gbl_fixed_event_handlers[event].handler = NULL;
677 acpi_gbl_fixed_event_handlers[event].context = NULL;
678
679 if (ACPI_FAILURE(status)) {
680 ACPI_WARNING((AE_INFO,
681 "Could not disable fixed event - %s (%u)",
682 acpi_ut_get_event_name(event), event));
683 } else {
684 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
685 "Disabled fixed event - %s (%X)\n",
686 acpi_ut_get_event_name(event), event));
687 }
688
689 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
690 return_ACPI_STATUS(status);
691}
692
693ACPI_EXPORT_SYMBOL(acpi_remove_fixed_event_handler)
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715static acpi_status
716acpi_ev_install_gpe_handler(acpi_handle gpe_device,
717 u32 gpe_number,
718 u32 type,
719 u8 is_raw_handler,
720 acpi_gpe_handler address, void *context)
721{
722 struct acpi_gpe_event_info *gpe_event_info;
723 struct acpi_gpe_handler_info *handler;
724 acpi_status status;
725 acpi_cpu_flags flags;
726
727 ACPI_FUNCTION_TRACE(ev_install_gpe_handler);
728
729
730
731 if ((!address) || (type & ~ACPI_GPE_XRUPT_TYPE_MASK)) {
732 return_ACPI_STATUS(AE_BAD_PARAMETER);
733 }
734
735 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
736 if (ACPI_FAILURE(status)) {
737 return_ACPI_STATUS(status);
738 }
739
740
741
742 handler = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_gpe_handler_info));
743 if (!handler) {
744 status = AE_NO_MEMORY;
745 goto unlock_and_exit;
746 }
747
748 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
749
750
751
752 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
753 if (!gpe_event_info) {
754 status = AE_BAD_PARAMETER;
755 goto free_and_exit;
756 }
757
758
759
760 if ((ACPI_GPE_DISPATCH_TYPE(gpe_event_info->flags) ==
761 ACPI_GPE_DISPATCH_HANDLER) ||
762 (ACPI_GPE_DISPATCH_TYPE(gpe_event_info->flags) ==
763 ACPI_GPE_DISPATCH_RAW_HANDLER)) {
764 status = AE_ALREADY_EXISTS;
765 goto free_and_exit;
766 }
767
768 handler->address = address;
769 handler->context = context;
770 handler->method_node = gpe_event_info->dispatch.method_node;
771 handler->original_flags = (u8)(gpe_event_info->flags &
772 (ACPI_GPE_XRUPT_TYPE_MASK |
773 ACPI_GPE_DISPATCH_MASK));
774
775
776
777
778
779
780 if (((ACPI_GPE_DISPATCH_TYPE(handler->original_flags) ==
781 ACPI_GPE_DISPATCH_METHOD) ||
782 (ACPI_GPE_DISPATCH_TYPE(handler->original_flags) ==
783 ACPI_GPE_DISPATCH_NOTIFY)) && gpe_event_info->runtime_count) {
784 handler->originally_enabled = TRUE;
785 (void)acpi_ev_remove_gpe_reference(gpe_event_info);
786
787
788
789 if (type !=
790 (u32)(gpe_event_info->flags & ACPI_GPE_XRUPT_TYPE_MASK)) {
791 ACPI_WARNING((AE_INFO,
792 "GPE type mismatch (level/edge)"));
793 }
794 }
795
796
797
798 gpe_event_info->dispatch.handler = handler;
799
800
801
802 gpe_event_info->flags &=
803 ~(ACPI_GPE_XRUPT_TYPE_MASK | ACPI_GPE_DISPATCH_MASK);
804 gpe_event_info->flags |=
805 (u8)(type |
806 (is_raw_handler ? ACPI_GPE_DISPATCH_RAW_HANDLER :
807 ACPI_GPE_DISPATCH_HANDLER));
808
809 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
810
811unlock_and_exit:
812 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
813 return_ACPI_STATUS(status);
814
815free_and_exit:
816 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
817 ACPI_FREE(handler);
818 goto unlock_and_exit;
819}
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839acpi_status
840acpi_install_gpe_handler(acpi_handle gpe_device,
841 u32 gpe_number,
842 u32 type, acpi_gpe_handler address, void *context)
843{
844 acpi_status status;
845
846 ACPI_FUNCTION_TRACE(acpi_install_gpe_handler);
847
848 status = acpi_ev_install_gpe_handler(gpe_device, gpe_number, type,
849 FALSE, address, context);
850
851 return_ACPI_STATUS(status);
852}
853
854ACPI_EXPORT_SYMBOL(acpi_install_gpe_handler)
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873acpi_status
874acpi_install_gpe_raw_handler(acpi_handle gpe_device,
875 u32 gpe_number,
876 u32 type, acpi_gpe_handler address, void *context)
877{
878 acpi_status status;
879
880 ACPI_FUNCTION_TRACE(acpi_install_gpe_raw_handler);
881
882 status = acpi_ev_install_gpe_handler(gpe_device, gpe_number, type,
883 TRUE, address, context);
884
885 return_ACPI_STATUS(status);
886}
887
888ACPI_EXPORT_SYMBOL(acpi_install_gpe_raw_handler)
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904acpi_status
905acpi_remove_gpe_handler(acpi_handle gpe_device,
906 u32 gpe_number, acpi_gpe_handler address)
907{
908 struct acpi_gpe_event_info *gpe_event_info;
909 struct acpi_gpe_handler_info *handler;
910 acpi_status status;
911 acpi_cpu_flags flags;
912
913 ACPI_FUNCTION_TRACE(acpi_remove_gpe_handler);
914
915
916
917 if (!address) {
918 return_ACPI_STATUS(AE_BAD_PARAMETER);
919 }
920
921 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
922 if (ACPI_FAILURE(status)) {
923 return_ACPI_STATUS(status);
924 }
925
926 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
927
928
929
930 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
931 if (!gpe_event_info) {
932 status = AE_BAD_PARAMETER;
933 goto unlock_and_exit;
934 }
935
936
937
938 if ((ACPI_GPE_DISPATCH_TYPE(gpe_event_info->flags) !=
939 ACPI_GPE_DISPATCH_HANDLER) &&
940 (ACPI_GPE_DISPATCH_TYPE(gpe_event_info->flags) !=
941 ACPI_GPE_DISPATCH_RAW_HANDLER)) {
942 status = AE_NOT_EXIST;
943 goto unlock_and_exit;
944 }
945
946
947
948 if (gpe_event_info->dispatch.handler->address != address) {
949 status = AE_BAD_PARAMETER;
950 goto unlock_and_exit;
951 }
952
953
954
955 handler = gpe_event_info->dispatch.handler;
956 gpe_event_info->dispatch.handler = NULL;
957
958
959
960 gpe_event_info->dispatch.method_node = handler->method_node;
961 gpe_event_info->flags &=
962 ~(ACPI_GPE_XRUPT_TYPE_MASK | ACPI_GPE_DISPATCH_MASK);
963 gpe_event_info->flags |= handler->original_flags;
964
965
966
967
968
969
970 if (((ACPI_GPE_DISPATCH_TYPE(handler->original_flags) ==
971 ACPI_GPE_DISPATCH_METHOD) ||
972 (ACPI_GPE_DISPATCH_TYPE(handler->original_flags) ==
973 ACPI_GPE_DISPATCH_NOTIFY)) && handler->originally_enabled) {
974 (void)acpi_ev_add_gpe_reference(gpe_event_info);
975 if (ACPI_GPE_IS_POLLING_NEEDED(gpe_event_info)) {
976
977
978
979 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
980 (void)acpi_ev_detect_gpe(gpe_device, gpe_event_info,
981 gpe_number);
982 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
983 }
984 }
985
986 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
987 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
988
989
990
991 acpi_os_wait_events_complete();
992
993
994
995 ACPI_FREE(handler);
996 return_ACPI_STATUS(status);
997
998unlock_and_exit:
999 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
1000
1001 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
1002 return_ACPI_STATUS(status);
1003}
1004
1005ACPI_EXPORT_SYMBOL(acpi_remove_gpe_handler)
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026acpi_status acpi_acquire_global_lock(u16 timeout, u32 *handle)
1027{
1028 acpi_status status;
1029
1030 if (!handle) {
1031 return (AE_BAD_PARAMETER);
1032 }
1033
1034
1035
1036 acpi_ex_enter_interpreter();
1037
1038 status = acpi_ex_acquire_mutex_object(timeout,
1039 acpi_gbl_global_lock_mutex,
1040 acpi_os_get_thread_id());
1041
1042 if (ACPI_SUCCESS(status)) {
1043
1044
1045
1046 *handle = acpi_gbl_global_lock_handle;
1047 }
1048
1049 acpi_ex_exit_interpreter();
1050 return (status);
1051}
1052
1053ACPI_EXPORT_SYMBOL(acpi_acquire_global_lock)
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066acpi_status acpi_release_global_lock(u32 handle)
1067{
1068 acpi_status status;
1069
1070 if (!handle || (handle != acpi_gbl_global_lock_handle)) {
1071 return (AE_NOT_ACQUIRED);
1072 }
1073
1074 status = acpi_ex_release_mutex_object(acpi_gbl_global_lock_mutex);
1075 return (status);
1076}
1077
1078ACPI_EXPORT_SYMBOL(acpi_release_global_lock)
1079#endif
1080