1 // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
2 /******************************************************************************
4 * Module Name: evxface - External interfaces for ACPI events
6 * Copyright (C) 2000 - 2018, Intel Corp.
8 *****************************************************************************/
10 #define EXPORT_ACPI_INTERFACES
12 #include <acpi/acpi.h>
18 #define _COMPONENT ACPI_EVENTS
19 ACPI_MODULE_NAME("evxface")
20 #if (!ACPI_REDUCED_HARDWARE)
21 /* Local prototypes */
23 acpi_ev_install_gpe_handler(acpi_handle gpe_device
,
27 acpi_gpe_handler address
, void *context
);
32 /*******************************************************************************
34 * FUNCTION: acpi_install_notify_handler
36 * PARAMETERS: device - The device for which notifies will be handled
37 * handler_type - The type of handler:
38 * ACPI_SYSTEM_NOTIFY: System Handler (00-7F)
39 * ACPI_DEVICE_NOTIFY: Device Handler (80-FF)
40 * ACPI_ALL_NOTIFY: Both System and Device
41 * handler - Address of the handler
42 * context - Value passed to the handler on each GPE
46 * DESCRIPTION: Install a handler for notifications on an ACPI Device,
47 * thermal_zone, or Processor object.
49 * NOTES: The Root namespace object may have only one handler for each
50 * type of notify (System/Device). Device/Thermal/Processor objects
51 * may have one device notify handler, and multiple system notify
54 ******************************************************************************/
57 acpi_install_notify_handler(acpi_handle device
,
59 acpi_notify_handler handler
, void *context
)
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
;
68 ACPI_FUNCTION_TRACE(acpi_install_notify_handler
);
70 /* Parameter validation */
72 if ((!device
) || (!handler
) || (!handler_type
) ||
73 (handler_type
> ACPI_MAX_NOTIFY_HANDLER_TYPE
)) {
74 return_ACPI_STATUS(AE_BAD_PARAMETER
);
77 status
= acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE
);
78 if (ACPI_FAILURE(status
)) {
79 return_ACPI_STATUS(status
);
84 * Registering a notify handler on the root object indicates that the
85 * caller wishes to receive notifications for all objects. Note that
86 * only one global handler can be registered per notify type.
87 * Ensure that a handler is not already installed.
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
;
97 acpi_gbl_global_notify
[i
].handler
= handler
;
98 acpi_gbl_global_notify
[i
].context
= context
;
102 goto unlock_and_exit
; /* Global notify handler installed, all done */
107 * Caller will only receive notifications specific to the target
108 * object. Note that only certain object types are allowed to
109 * receive notifications.
112 /* Are Notifies allowed on this object? */
114 if (!acpi_ev_is_notify_object(node
)) {
116 goto unlock_and_exit
;
119 /* Check for an existing internal object, might not exist */
121 obj_desc
= acpi_ns_get_attached_object(node
);
124 /* Create a new object */
126 obj_desc
= acpi_ut_create_internal_object(node
->type
);
128 status
= AE_NO_MEMORY
;
129 goto unlock_and_exit
;
132 /* Attach new object to the Node, remove local reference */
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
;
141 /* Ensure that the handler is not already installed in the lists */
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
;
152 handler_obj
= handler_obj
->notify
.next
[i
];
157 /* Create and populate a new notify handler object */
159 handler_obj
= acpi_ut_create_internal_object(ACPI_TYPE_LOCAL_NOTIFY
);
161 status
= AE_NO_MEMORY
;
162 goto unlock_and_exit
;
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
;
170 /* Install the handler at the list head(s) */
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
];
177 obj_desc
->common_notify
.notify_list
[i
] = handler_obj
;
181 /* Add an extra reference if handler was installed in both lists */
183 if (handler_type
== ACPI_ALL_NOTIFY
) {
184 acpi_ut_add_reference(handler_obj
);
188 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE
);
189 return_ACPI_STATUS(status
);
192 ACPI_EXPORT_SYMBOL(acpi_install_notify_handler
)
194 /*******************************************************************************
196 * FUNCTION: acpi_remove_notify_handler
198 * PARAMETERS: device - The device for which the handler is installed
199 * handler_type - The type of handler:
200 * ACPI_SYSTEM_NOTIFY: System Handler (00-7F)
201 * ACPI_DEVICE_NOTIFY: Device Handler (80-FF)
202 * ACPI_ALL_NOTIFY: Both System and Device
203 * handler - Address of the handler
207 * DESCRIPTION: Remove a handler for notifies on an ACPI device
209 ******************************************************************************/
211 acpi_remove_notify_handler(acpi_handle device
,
212 u32 handler_type
, acpi_notify_handler handler
)
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
;
222 ACPI_FUNCTION_TRACE(acpi_remove_notify_handler
);
224 /* Parameter validation */
226 if ((!device
) || (!handler
) || (!handler_type
) ||
227 (handler_type
> ACPI_MAX_NOTIFY_HANDLER_TYPE
)) {
228 return_ACPI_STATUS(AE_BAD_PARAMETER
);
231 /* Root Object. Global handlers are removed here */
233 if (device
== ACPI_ROOT_OBJECT
) {
234 for (i
= 0; i
< ACPI_NUM_NOTIFY_TYPES
; i
++) {
235 if (handler_type
& (i
+ 1)) {
237 acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE
);
238 if (ACPI_FAILURE(status
)) {
239 return_ACPI_STATUS(status
);
242 if (!acpi_gbl_global_notify
[i
].handler
||
243 (acpi_gbl_global_notify
[i
].handler
!=
245 status
= AE_NOT_EXIST
;
246 goto unlock_and_exit
;
249 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
250 "Removing global notify handler\n"));
252 acpi_gbl_global_notify
[i
].handler
= NULL
;
253 acpi_gbl_global_notify
[i
].context
= NULL
;
255 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE
);
257 /* Make sure all deferred notify tasks are completed */
259 acpi_os_wait_events_complete();
263 return_ACPI_STATUS(AE_OK
);
266 /* All other objects: Are Notifies allowed on this object? */
268 if (!acpi_ev_is_notify_object(node
)) {
269 return_ACPI_STATUS(AE_TYPE
);
272 /* Must have an existing internal object */
274 obj_desc
= acpi_ns_get_attached_object(node
);
276 return_ACPI_STATUS(AE_NOT_EXIST
);
279 /* Internal object exists. Find the handler and remove it */
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
);
288 handler_obj
= obj_desc
->common_notify
.notify_list
[i
];
289 previous_handler_obj
= NULL
;
291 /* Attempt to find the handler in the handler list */
293 while (handler_obj
&&
294 (handler_obj
->notify
.handler
!= handler
)) {
295 previous_handler_obj
= handler_obj
;
296 handler_obj
= handler_obj
->notify
.next
[i
];
300 status
= AE_NOT_EXIST
;
301 goto unlock_and_exit
;
304 /* Remove the handler object from the list */
306 if (previous_handler_obj
) { /* Handler is not at the list head */
307 previous_handler_obj
->notify
.next
[i
] =
308 handler_obj
->notify
.next
[i
];
309 } else { /* Handler is at the list head */
311 obj_desc
->common_notify
.notify_list
[i
] =
312 handler_obj
->notify
.next
[i
];
315 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE
);
317 /* Make sure all deferred notify tasks are completed */
319 acpi_os_wait_events_complete();
320 acpi_ut_remove_reference(handler_obj
);
324 return_ACPI_STATUS(status
);
327 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE
);
328 return_ACPI_STATUS(status
);
331 ACPI_EXPORT_SYMBOL(acpi_remove_notify_handler
)
333 /*******************************************************************************
335 * FUNCTION: acpi_install_exception_handler
337 * PARAMETERS: handler - Pointer to the handler function for the
342 * DESCRIPTION: Saves the pointer to the handler function
344 ******************************************************************************/
345 #ifdef ACPI_FUTURE_USAGE
346 acpi_status
acpi_install_exception_handler(acpi_exception_handler handler
)
350 ACPI_FUNCTION_TRACE(acpi_install_exception_handler
);
352 status
= acpi_ut_acquire_mutex(ACPI_MTX_EVENTS
);
353 if (ACPI_FAILURE(status
)) {
354 return_ACPI_STATUS(status
);
357 /* Don't allow two handlers. */
359 if (acpi_gbl_exception_handler
) {
360 status
= AE_ALREADY_EXISTS
;
364 /* Install the handler */
366 acpi_gbl_exception_handler
= handler
;
369 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS
);
370 return_ACPI_STATUS(status
);
373 ACPI_EXPORT_SYMBOL(acpi_install_exception_handler
)
376 #if (!ACPI_REDUCED_HARDWARE)
377 /*******************************************************************************
379 * FUNCTION: acpi_install_sci_handler
381 * PARAMETERS: address - Address of the handler
382 * context - Value passed to the handler on each SCI
386 * DESCRIPTION: Install a handler for a System Control Interrupt.
388 ******************************************************************************/
389 acpi_status
acpi_install_sci_handler(acpi_sci_handler address
, void *context
)
391 struct acpi_sci_handler_info
*new_sci_handler
;
392 struct acpi_sci_handler_info
*sci_handler
;
393 acpi_cpu_flags flags
;
396 ACPI_FUNCTION_TRACE(acpi_install_sci_handler
);
399 return_ACPI_STATUS(AE_BAD_PARAMETER
);
402 /* Allocate and init a handler object */
404 new_sci_handler
= ACPI_ALLOCATE(sizeof(struct acpi_sci_handler_info
));
405 if (!new_sci_handler
) {
406 return_ACPI_STATUS(AE_NO_MEMORY
);
409 new_sci_handler
->address
= address
;
410 new_sci_handler
->context
= context
;
412 status
= acpi_ut_acquire_mutex(ACPI_MTX_EVENTS
);
413 if (ACPI_FAILURE(status
)) {
417 /* Lock list during installation */
419 flags
= acpi_os_acquire_lock(acpi_gbl_gpe_lock
);
420 sci_handler
= acpi_gbl_sci_handler_list
;
422 /* Ensure handler does not already exist */
424 while (sci_handler
) {
425 if (address
== sci_handler
->address
) {
426 status
= AE_ALREADY_EXISTS
;
427 goto unlock_and_exit
;
430 sci_handler
= sci_handler
->next
;
433 /* Install the new handler into the global list (at head) */
435 new_sci_handler
->next
= acpi_gbl_sci_handler_list
;
436 acpi_gbl_sci_handler_list
= new_sci_handler
;
440 acpi_os_release_lock(acpi_gbl_gpe_lock
, flags
);
441 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS
);
444 if (ACPI_FAILURE(status
)) {
445 ACPI_FREE(new_sci_handler
);
447 return_ACPI_STATUS(status
);
450 ACPI_EXPORT_SYMBOL(acpi_install_sci_handler
)
452 /*******************************************************************************
454 * FUNCTION: acpi_remove_sci_handler
456 * PARAMETERS: address - Address of the handler
460 * DESCRIPTION: Remove a handler for a System Control Interrupt.
462 ******************************************************************************/
463 acpi_status
acpi_remove_sci_handler(acpi_sci_handler address
)
465 struct acpi_sci_handler_info
*prev_sci_handler
;
466 struct acpi_sci_handler_info
*next_sci_handler
;
467 acpi_cpu_flags flags
;
470 ACPI_FUNCTION_TRACE(acpi_remove_sci_handler
);
473 return_ACPI_STATUS(AE_BAD_PARAMETER
);
476 status
= acpi_ut_acquire_mutex(ACPI_MTX_EVENTS
);
477 if (ACPI_FAILURE(status
)) {
478 return_ACPI_STATUS(status
);
481 /* Remove the SCI handler with lock */
483 flags
= acpi_os_acquire_lock(acpi_gbl_gpe_lock
);
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
) {
490 /* Unlink and free the SCI handler info block */
492 if (prev_sci_handler
) {
493 prev_sci_handler
->next
= next_sci_handler
->next
;
495 acpi_gbl_sci_handler_list
=
496 next_sci_handler
->next
;
499 acpi_os_release_lock(acpi_gbl_gpe_lock
, flags
);
500 ACPI_FREE(next_sci_handler
);
501 goto unlock_and_exit
;
504 prev_sci_handler
= next_sci_handler
;
505 next_sci_handler
= next_sci_handler
->next
;
508 acpi_os_release_lock(acpi_gbl_gpe_lock
, flags
);
509 status
= AE_NOT_EXIST
;
512 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS
);
513 return_ACPI_STATUS(status
);
516 ACPI_EXPORT_SYMBOL(acpi_remove_sci_handler
)
518 /*******************************************************************************
520 * FUNCTION: acpi_install_global_event_handler
522 * PARAMETERS: handler - Pointer to the global event handler function
523 * context - Value passed to the handler on each event
527 * DESCRIPTION: Saves the pointer to the handler function. The global handler
528 * is invoked upon each incoming GPE and Fixed Event. It is
529 * invoked at interrupt level at the time of the event dispatch.
530 * Can be used to update event counters, etc.
532 ******************************************************************************/
534 acpi_install_global_event_handler(acpi_gbl_event_handler handler
, void *context
)
538 ACPI_FUNCTION_TRACE(acpi_install_global_event_handler
);
540 /* Parameter validation */
543 return_ACPI_STATUS(AE_BAD_PARAMETER
);
546 status
= acpi_ut_acquire_mutex(ACPI_MTX_EVENTS
);
547 if (ACPI_FAILURE(status
)) {
548 return_ACPI_STATUS(status
);
551 /* Don't allow two handlers. */
553 if (acpi_gbl_global_event_handler
) {
554 status
= AE_ALREADY_EXISTS
;
558 acpi_gbl_global_event_handler
= handler
;
559 acpi_gbl_global_event_handler_context
= context
;
562 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS
);
563 return_ACPI_STATUS(status
);
566 ACPI_EXPORT_SYMBOL(acpi_install_global_event_handler
)
568 /*******************************************************************************
570 * FUNCTION: acpi_install_fixed_event_handler
572 * PARAMETERS: event - Event type to enable.
573 * handler - Pointer to the handler function for the
575 * context - Value passed to the handler on each GPE
579 * DESCRIPTION: Saves the pointer to the handler function and then enables the
582 ******************************************************************************/
584 acpi_install_fixed_event_handler(u32 event
,
585 acpi_event_handler handler
, void *context
)
589 ACPI_FUNCTION_TRACE(acpi_install_fixed_event_handler
);
591 /* Parameter validation */
593 if (event
> ACPI_EVENT_MAX
) {
594 return_ACPI_STATUS(AE_BAD_PARAMETER
);
597 status
= acpi_ut_acquire_mutex(ACPI_MTX_EVENTS
);
598 if (ACPI_FAILURE(status
)) {
599 return_ACPI_STATUS(status
);
602 /* Do not allow multiple handlers */
604 if (acpi_gbl_fixed_event_handlers
[event
].handler
) {
605 status
= AE_ALREADY_EXISTS
;
609 /* Install the handler before enabling the event */
611 acpi_gbl_fixed_event_handlers
[event
].handler
= handler
;
612 acpi_gbl_fixed_event_handlers
[event
].context
= context
;
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
));
622 /* Remove the handler */
624 acpi_gbl_fixed_event_handlers
[event
].handler
= NULL
;
625 acpi_gbl_fixed_event_handlers
[event
].context
= NULL
;
627 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
628 "Enabled fixed event %s (%X), Handler=%p\n",
629 acpi_ut_get_event_name(event
), event
,
634 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS
);
635 return_ACPI_STATUS(status
);
638 ACPI_EXPORT_SYMBOL(acpi_install_fixed_event_handler
)
640 /*******************************************************************************
642 * FUNCTION: acpi_remove_fixed_event_handler
644 * PARAMETERS: event - Event type to disable.
645 * handler - Address of the handler
649 * DESCRIPTION: Disables the event and unregisters the event handler.
651 ******************************************************************************/
653 acpi_remove_fixed_event_handler(u32 event
, acpi_event_handler handler
)
655 acpi_status status
= AE_OK
;
657 ACPI_FUNCTION_TRACE(acpi_remove_fixed_event_handler
);
659 /* Parameter validation */
661 if (event
> ACPI_EVENT_MAX
) {
662 return_ACPI_STATUS(AE_BAD_PARAMETER
);
665 status
= acpi_ut_acquire_mutex(ACPI_MTX_EVENTS
);
666 if (ACPI_FAILURE(status
)) {
667 return_ACPI_STATUS(status
);
670 /* Disable the event before removing the handler */
672 status
= acpi_disable_event(event
, 0);
674 /* Always Remove the handler */
676 acpi_gbl_fixed_event_handlers
[event
].handler
= NULL
;
677 acpi_gbl_fixed_event_handlers
[event
].context
= NULL
;
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
));
684 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
685 "Disabled fixed event - %s (%X)\n",
686 acpi_ut_get_event_name(event
), event
));
689 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS
);
690 return_ACPI_STATUS(status
);
693 ACPI_EXPORT_SYMBOL(acpi_remove_fixed_event_handler
)
695 /*******************************************************************************
697 * FUNCTION: acpi_ev_install_gpe_handler
699 * PARAMETERS: gpe_device - Namespace node for the GPE (NULL for FADT
701 * gpe_number - The GPE number within the GPE block
702 * type - Whether this GPE should be treated as an
703 * edge- or level-triggered interrupt.
704 * is_raw_handler - Whether this GPE should be handled using
705 * the special GPE handler mode.
706 * address - Address of the handler
707 * context - Value passed to the handler on each GPE
711 * DESCRIPTION: Internal function to install a handler for a General Purpose
714 ******************************************************************************/
716 acpi_ev_install_gpe_handler(acpi_handle gpe_device
,
720 acpi_gpe_handler address
, void *context
)
722 struct acpi_gpe_event_info
*gpe_event_info
;
723 struct acpi_gpe_handler_info
*handler
;
725 acpi_cpu_flags flags
;
727 ACPI_FUNCTION_TRACE(ev_install_gpe_handler
);
729 /* Parameter validation */
731 if ((!address
) || (type
& ~ACPI_GPE_XRUPT_TYPE_MASK
)) {
732 return_ACPI_STATUS(AE_BAD_PARAMETER
);
735 status
= acpi_ut_acquire_mutex(ACPI_MTX_EVENTS
);
736 if (ACPI_FAILURE(status
)) {
737 return_ACPI_STATUS(status
);
740 /* Allocate and init handler object (before lock) */
742 handler
= ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_gpe_handler_info
));
744 status
= AE_NO_MEMORY
;
745 goto unlock_and_exit
;
748 flags
= acpi_os_acquire_lock(acpi_gbl_gpe_lock
);
750 /* Ensure that we have a valid GPE number */
752 gpe_event_info
= acpi_ev_get_gpe_event_info(gpe_device
, gpe_number
);
753 if (!gpe_event_info
) {
754 status
= AE_BAD_PARAMETER
;
758 /* Make sure that there isn't a handler there already */
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
;
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
));
776 * If the GPE is associated with a method, it may have been enabled
777 * automatically during initialization, in which case it has to be
778 * disabled now to avoid spurious execution of the handler.
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
);
787 /* Sanity check of original type against new type */
790 (u32
)(gpe_event_info
->flags
& ACPI_GPE_XRUPT_TYPE_MASK
)) {
791 ACPI_WARNING((AE_INFO
,
792 "GPE type mismatch (level/edge)"));
796 /* Install the handler */
798 gpe_event_info
->dispatch
.handler
= handler
;
800 /* Setup up dispatch flags to indicate handler (vs. method/notify) */
802 gpe_event_info
->flags
&=
803 ~(ACPI_GPE_XRUPT_TYPE_MASK
| ACPI_GPE_DISPATCH_MASK
);
804 gpe_event_info
->flags
|=
806 (is_raw_handler
? ACPI_GPE_DISPATCH_RAW_HANDLER
:
807 ACPI_GPE_DISPATCH_HANDLER
));
809 acpi_os_release_lock(acpi_gbl_gpe_lock
, flags
);
812 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS
);
813 return_ACPI_STATUS(status
);
816 acpi_os_release_lock(acpi_gbl_gpe_lock
, flags
);
818 goto unlock_and_exit
;
821 /*******************************************************************************
823 * FUNCTION: acpi_install_gpe_handler
825 * PARAMETERS: gpe_device - Namespace node for the GPE (NULL for FADT
827 * gpe_number - The GPE number within the GPE block
828 * type - Whether this GPE should be treated as an
829 * edge- or level-triggered interrupt.
830 * address - Address of the handler
831 * context - Value passed to the handler on each GPE
835 * DESCRIPTION: Install a handler for a General Purpose Event.
837 ******************************************************************************/
840 acpi_install_gpe_handler(acpi_handle gpe_device
,
842 u32 type
, acpi_gpe_handler address
, void *context
)
846 ACPI_FUNCTION_TRACE(acpi_install_gpe_handler
);
848 status
= acpi_ev_install_gpe_handler(gpe_device
, gpe_number
, type
,
849 FALSE
, address
, context
);
851 return_ACPI_STATUS(status
);
854 ACPI_EXPORT_SYMBOL(acpi_install_gpe_handler
)
856 /*******************************************************************************
858 * FUNCTION: acpi_install_gpe_raw_handler
860 * PARAMETERS: gpe_device - Namespace node for the GPE (NULL for FADT
862 * gpe_number - The GPE number within the GPE block
863 * type - Whether this GPE should be treated as an
864 * edge- or level-triggered interrupt.
865 * address - Address of the handler
866 * context - Value passed to the handler on each GPE
870 * DESCRIPTION: Install a handler for a General Purpose Event.
872 ******************************************************************************/
874 acpi_install_gpe_raw_handler(acpi_handle gpe_device
,
876 u32 type
, acpi_gpe_handler address
, void *context
)
880 ACPI_FUNCTION_TRACE(acpi_install_gpe_raw_handler
);
882 status
= acpi_ev_install_gpe_handler(gpe_device
, gpe_number
, type
,
883 TRUE
, address
, context
);
885 return_ACPI_STATUS(status
);
888 ACPI_EXPORT_SYMBOL(acpi_install_gpe_raw_handler
)
890 /*******************************************************************************
892 * FUNCTION: acpi_remove_gpe_handler
894 * PARAMETERS: gpe_device - Namespace node for the GPE (NULL for FADT
896 * gpe_number - The event to remove a handler
897 * address - Address of the handler
901 * DESCRIPTION: Remove a handler for a General Purpose acpi_event.
903 ******************************************************************************/
905 acpi_remove_gpe_handler(acpi_handle gpe_device
,
906 u32 gpe_number
, acpi_gpe_handler address
)
908 struct acpi_gpe_event_info
*gpe_event_info
;
909 struct acpi_gpe_handler_info
*handler
;
911 acpi_cpu_flags flags
;
913 ACPI_FUNCTION_TRACE(acpi_remove_gpe_handler
);
915 /* Parameter validation */
918 return_ACPI_STATUS(AE_BAD_PARAMETER
);
921 status
= acpi_ut_acquire_mutex(ACPI_MTX_EVENTS
);
922 if (ACPI_FAILURE(status
)) {
923 return_ACPI_STATUS(status
);
926 flags
= acpi_os_acquire_lock(acpi_gbl_gpe_lock
);
928 /* Ensure that we have a valid GPE number */
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
;
936 /* Make sure that a handler is indeed installed */
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
;
946 /* Make sure that the installed handler is the same */
948 if (gpe_event_info
->dispatch
.handler
->address
!= address
) {
949 status
= AE_BAD_PARAMETER
;
950 goto unlock_and_exit
;
953 /* Remove the handler */
955 handler
= gpe_event_info
->dispatch
.handler
;
956 gpe_event_info
->dispatch
.handler
= NULL
;
958 /* Restore Method node (if any), set dispatch flags */
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
;
966 * If the GPE was previously associated with a method and it was
967 * enabled, it should be enabled at this point to restore the
968 * post-initialization configuration.
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
)) {
977 /* Poll edge triggered GPEs to handle existing events */
979 acpi_os_release_lock(acpi_gbl_gpe_lock
, flags
);
980 (void)acpi_ev_detect_gpe(gpe_device
, gpe_event_info
,
982 flags
= acpi_os_acquire_lock(acpi_gbl_gpe_lock
);
986 acpi_os_release_lock(acpi_gbl_gpe_lock
, flags
);
987 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS
);
989 /* Make sure all deferred GPE tasks are completed */
991 acpi_os_wait_events_complete();
993 /* Now we can free the handler object */
996 return_ACPI_STATUS(status
);
999 acpi_os_release_lock(acpi_gbl_gpe_lock
, flags
);
1001 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS
);
1002 return_ACPI_STATUS(status
);
1005 ACPI_EXPORT_SYMBOL(acpi_remove_gpe_handler
)
1007 /*******************************************************************************
1009 * FUNCTION: acpi_acquire_global_lock
1011 * PARAMETERS: timeout - How long the caller is willing to wait
1012 * handle - Where the handle to the lock is returned
1017 * DESCRIPTION: Acquire the ACPI Global Lock
1019 * Note: Allows callers with the same thread ID to acquire the global lock
1020 * multiple times. In other words, externally, the behavior of the global lock
1021 * is identical to an AML mutex. On the first acquire, a new handle is
1022 * returned. On any subsequent calls to acquire by the same thread, the same
1023 * handle is returned.
1025 ******************************************************************************/
1026 acpi_status
acpi_acquire_global_lock(u16 timeout
, u32
*handle
)
1031 return (AE_BAD_PARAMETER
);
1034 /* Must lock interpreter to prevent race conditions */
1036 acpi_ex_enter_interpreter();
1038 status
= acpi_ex_acquire_mutex_object(timeout
,
1039 acpi_gbl_global_lock_mutex
,
1040 acpi_os_get_thread_id());
1042 if (ACPI_SUCCESS(status
)) {
1044 /* Return the global lock handle (updated in acpi_ev_acquire_global_lock) */
1046 *handle
= acpi_gbl_global_lock_handle
;
1049 acpi_ex_exit_interpreter();
1053 ACPI_EXPORT_SYMBOL(acpi_acquire_global_lock
)
1055 /*******************************************************************************
1057 * FUNCTION: acpi_release_global_lock
1059 * PARAMETERS: handle - Returned from acpi_acquire_global_lock
1063 * DESCRIPTION: Release the ACPI Global Lock. The handle must be valid.
1065 ******************************************************************************/
1066 acpi_status
acpi_release_global_lock(u32 handle
)
1070 if (!handle
|| (handle
!= acpi_gbl_global_lock_handle
)) {
1071 return (AE_NOT_ACQUIRED
);
1074 status
= acpi_ex_release_mutex_object(acpi_gbl_global_lock_mutex
);
1078 ACPI_EXPORT_SYMBOL(acpi_release_global_lock
)
1079 #endif /* !ACPI_REDUCED_HARDWARE */