1 /******************************************************************************
3 * Module Name: evxface - External interfaces for ACPI events
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2014, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
44 #define EXPORT_ACPI_INTERFACES
46 #include <acpi/acpi.h>
52 #define _COMPONENT ACPI_EVENTS
53 ACPI_MODULE_NAME("evxface")
56 /*******************************************************************************
58 * FUNCTION: acpi_install_notify_handler
60 * PARAMETERS: device - The device for which notifies will be handled
61 * handler_type - The type of handler:
62 * ACPI_SYSTEM_NOTIFY: System Handler (00-7F)
63 * ACPI_DEVICE_NOTIFY: Device Handler (80-FF)
64 * ACPI_ALL_NOTIFY: Both System and Device
65 * handler - Address of the handler
66 * context - Value passed to the handler on each GPE
70 * DESCRIPTION: Install a handler for notifications on an ACPI Device,
71 * thermal_zone, or Processor object.
73 * NOTES: The Root namespace object may have only one handler for each
74 * type of notify (System/Device). Device/Thermal/Processor objects
75 * may have one device notify handler, and multiple system notify
78 ******************************************************************************/
80 acpi_install_notify_handler(acpi_handle device
,
82 acpi_notify_handler handler
, void *context
)
84 struct acpi_namespace_node
*node
=
85 ACPI_CAST_PTR(struct acpi_namespace_node
, device
);
86 union acpi_operand_object
*obj_desc
;
87 union acpi_operand_object
*handler_obj
;
91 ACPI_FUNCTION_TRACE(acpi_install_notify_handler
);
93 /* Parameter validation */
95 if ((!device
) || (!handler
) || (!handler_type
) ||
96 (handler_type
> ACPI_MAX_NOTIFY_HANDLER_TYPE
)) {
97 return_ACPI_STATUS(AE_BAD_PARAMETER
);
100 status
= acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE
);
101 if (ACPI_FAILURE(status
)) {
102 return_ACPI_STATUS(status
);
107 * Registering a notify handler on the root object indicates that the
108 * caller wishes to receive notifications for all objects. Note that
109 * only one global handler can be registered per notify type.
110 * Ensure that a handler is not already installed.
112 if (device
== ACPI_ROOT_OBJECT
) {
113 for (i
= 0; i
< ACPI_NUM_NOTIFY_TYPES
; i
++) {
114 if (handler_type
& (i
+ 1)) {
115 if (acpi_gbl_global_notify
[i
].handler
) {
116 status
= AE_ALREADY_EXISTS
;
117 goto unlock_and_exit
;
120 acpi_gbl_global_notify
[i
].handler
= handler
;
121 acpi_gbl_global_notify
[i
].context
= context
;
125 goto unlock_and_exit
; /* Global notify handler installed, all done */
130 * Caller will only receive notifications specific to the target
131 * object. Note that only certain object types are allowed to
132 * receive notifications.
135 /* Are Notifies allowed on this object? */
137 if (!acpi_ev_is_notify_object(node
)) {
139 goto unlock_and_exit
;
142 /* Check for an existing internal object, might not exist */
144 obj_desc
= acpi_ns_get_attached_object(node
);
147 /* Create a new object */
149 obj_desc
= acpi_ut_create_internal_object(node
->type
);
151 status
= AE_NO_MEMORY
;
152 goto unlock_and_exit
;
155 /* Attach new object to the Node, remove local reference */
157 status
= acpi_ns_attach_object(device
, obj_desc
, node
->type
);
158 acpi_ut_remove_reference(obj_desc
);
159 if (ACPI_FAILURE(status
)) {
160 goto unlock_and_exit
;
164 /* Ensure that the handler is not already installed in the lists */
166 for (i
= 0; i
< ACPI_NUM_NOTIFY_TYPES
; i
++) {
167 if (handler_type
& (i
+ 1)) {
168 handler_obj
= obj_desc
->common_notify
.notify_list
[i
];
169 while (handler_obj
) {
170 if (handler_obj
->notify
.handler
== handler
) {
171 status
= AE_ALREADY_EXISTS
;
172 goto unlock_and_exit
;
175 handler_obj
= handler_obj
->notify
.next
[i
];
180 /* Create and populate a new notify handler object */
182 handler_obj
= acpi_ut_create_internal_object(ACPI_TYPE_LOCAL_NOTIFY
);
184 status
= AE_NO_MEMORY
;
185 goto unlock_and_exit
;
188 handler_obj
->notify
.node
= node
;
189 handler_obj
->notify
.handler_type
= handler_type
;
190 handler_obj
->notify
.handler
= handler
;
191 handler_obj
->notify
.context
= context
;
193 /* Install the handler at the list head(s) */
195 for (i
= 0; i
< ACPI_NUM_NOTIFY_TYPES
; i
++) {
196 if (handler_type
& (i
+ 1)) {
197 handler_obj
->notify
.next
[i
] =
198 obj_desc
->common_notify
.notify_list
[i
];
200 obj_desc
->common_notify
.notify_list
[i
] = handler_obj
;
204 /* Add an extra reference if handler was installed in both lists */
206 if (handler_type
== ACPI_ALL_NOTIFY
) {
207 acpi_ut_add_reference(handler_obj
);
211 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE
);
212 return_ACPI_STATUS(status
);
215 ACPI_EXPORT_SYMBOL(acpi_install_notify_handler
)
217 /*******************************************************************************
219 * FUNCTION: acpi_remove_notify_handler
221 * PARAMETERS: device - The device for which the handler is installed
222 * handler_type - The type of handler:
223 * ACPI_SYSTEM_NOTIFY: System Handler (00-7F)
224 * ACPI_DEVICE_NOTIFY: Device Handler (80-FF)
225 * ACPI_ALL_NOTIFY: Both System and Device
226 * handler - Address of the handler
230 * DESCRIPTION: Remove a handler for notifies on an ACPI device
232 ******************************************************************************/
234 acpi_remove_notify_handler(acpi_handle device
,
235 u32 handler_type
, acpi_notify_handler handler
)
237 struct acpi_namespace_node
*node
=
238 ACPI_CAST_PTR(struct acpi_namespace_node
, device
);
239 union acpi_operand_object
*obj_desc
;
240 union acpi_operand_object
*handler_obj
;
241 union acpi_operand_object
*previous_handler_obj
;
242 acpi_status status
= AE_OK
;
245 ACPI_FUNCTION_TRACE(acpi_remove_notify_handler
);
247 /* Parameter validation */
249 if ((!device
) || (!handler
) || (!handler_type
) ||
250 (handler_type
> ACPI_MAX_NOTIFY_HANDLER_TYPE
)) {
251 return_ACPI_STATUS(AE_BAD_PARAMETER
);
254 /* Root Object. Global handlers are removed here */
256 if (device
== ACPI_ROOT_OBJECT
) {
257 for (i
= 0; i
< ACPI_NUM_NOTIFY_TYPES
; i
++) {
258 if (handler_type
& (i
+ 1)) {
260 acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE
);
261 if (ACPI_FAILURE(status
)) {
262 return_ACPI_STATUS(status
);
265 if (!acpi_gbl_global_notify
[i
].handler
||
266 (acpi_gbl_global_notify
[i
].handler
!=
268 status
= AE_NOT_EXIST
;
269 goto unlock_and_exit
;
272 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
273 "Removing global notify handler\n"));
275 acpi_gbl_global_notify
[i
].handler
= NULL
;
276 acpi_gbl_global_notify
[i
].context
= NULL
;
278 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE
);
280 /* Make sure all deferred notify tasks are completed */
282 acpi_os_wait_events_complete();
286 return_ACPI_STATUS(AE_OK
);
289 /* All other objects: Are Notifies allowed on this object? */
291 if (!acpi_ev_is_notify_object(node
)) {
292 return_ACPI_STATUS(AE_TYPE
);
295 /* Must have an existing internal object */
297 obj_desc
= acpi_ns_get_attached_object(node
);
299 return_ACPI_STATUS(AE_NOT_EXIST
);
302 /* Internal object exists. Find the handler and remove it */
304 for (i
= 0; i
< ACPI_NUM_NOTIFY_TYPES
; i
++) {
305 if (handler_type
& (i
+ 1)) {
306 status
= acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE
);
307 if (ACPI_FAILURE(status
)) {
308 return_ACPI_STATUS(status
);
311 handler_obj
= obj_desc
->common_notify
.notify_list
[i
];
312 previous_handler_obj
= NULL
;
314 /* Attempt to find the handler in the handler list */
316 while (handler_obj
&&
317 (handler_obj
->notify
.handler
!= handler
)) {
318 previous_handler_obj
= handler_obj
;
319 handler_obj
= handler_obj
->notify
.next
[i
];
323 status
= AE_NOT_EXIST
;
324 goto unlock_and_exit
;
327 /* Remove the handler object from the list */
329 if (previous_handler_obj
) { /* Handler is not at the list head */
330 previous_handler_obj
->notify
.next
[i
] =
331 handler_obj
->notify
.next
[i
];
332 } else { /* Handler is at the list head */
334 obj_desc
->common_notify
.notify_list
[i
] =
335 handler_obj
->notify
.next
[i
];
338 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE
);
340 /* Make sure all deferred notify tasks are completed */
342 acpi_os_wait_events_complete();
343 acpi_ut_remove_reference(handler_obj
);
347 return_ACPI_STATUS(status
);
350 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE
);
351 return_ACPI_STATUS(status
);
354 ACPI_EXPORT_SYMBOL(acpi_remove_notify_handler
)
356 /*******************************************************************************
358 * FUNCTION: acpi_install_exception_handler
360 * PARAMETERS: handler - Pointer to the handler function for the
365 * DESCRIPTION: Saves the pointer to the handler function
367 ******************************************************************************/
368 #ifdef ACPI_FUTURE_USAGE
369 acpi_status
acpi_install_exception_handler(acpi_exception_handler handler
)
373 ACPI_FUNCTION_TRACE(acpi_install_exception_handler
);
375 status
= acpi_ut_acquire_mutex(ACPI_MTX_EVENTS
);
376 if (ACPI_FAILURE(status
)) {
377 return_ACPI_STATUS(status
);
380 /* Don't allow two handlers. */
382 if (acpi_gbl_exception_handler
) {
383 status
= AE_ALREADY_EXISTS
;
387 /* Install the handler */
389 acpi_gbl_exception_handler
= handler
;
392 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS
);
393 return_ACPI_STATUS(status
);
396 ACPI_EXPORT_SYMBOL(acpi_install_exception_handler
)
397 #endif /* ACPI_FUTURE_USAGE */
399 #if (!ACPI_REDUCED_HARDWARE)
400 /*******************************************************************************
402 * FUNCTION: acpi_install_sci_handler
404 * PARAMETERS: address - Address of the handler
405 * context - Value passed to the handler on each SCI
409 * DESCRIPTION: Install a handler for a System Control Interrupt.
411 ******************************************************************************/
412 acpi_status
acpi_install_sci_handler(acpi_sci_handler address
, void *context
)
414 struct acpi_sci_handler_info
*new_sci_handler
;
415 struct acpi_sci_handler_info
*sci_handler
;
416 acpi_cpu_flags flags
;
419 ACPI_FUNCTION_TRACE(acpi_install_sci_handler
);
422 return_ACPI_STATUS(AE_BAD_PARAMETER
);
425 /* Allocate and init a handler object */
427 new_sci_handler
= ACPI_ALLOCATE(sizeof(struct acpi_sci_handler_info
));
428 if (!new_sci_handler
) {
429 return_ACPI_STATUS(AE_NO_MEMORY
);
432 new_sci_handler
->address
= address
;
433 new_sci_handler
->context
= context
;
435 status
= acpi_ut_acquire_mutex(ACPI_MTX_EVENTS
);
436 if (ACPI_FAILURE(status
)) {
440 /* Lock list during installation */
442 flags
= acpi_os_acquire_lock(acpi_gbl_gpe_lock
);
443 sci_handler
= acpi_gbl_sci_handler_list
;
445 /* Ensure handler does not already exist */
447 while (sci_handler
) {
448 if (address
== sci_handler
->address
) {
449 status
= AE_ALREADY_EXISTS
;
450 goto unlock_and_exit
;
453 sci_handler
= sci_handler
->next
;
456 /* Install the new handler into the global list (at head) */
458 new_sci_handler
->next
= acpi_gbl_sci_handler_list
;
459 acpi_gbl_sci_handler_list
= new_sci_handler
;
463 acpi_os_release_lock(acpi_gbl_gpe_lock
, flags
);
464 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS
);
467 if (ACPI_FAILURE(status
)) {
468 ACPI_FREE(new_sci_handler
);
470 return_ACPI_STATUS(status
);
473 ACPI_EXPORT_SYMBOL(acpi_install_sci_handler
)
475 /*******************************************************************************
477 * FUNCTION: acpi_remove_sci_handler
479 * PARAMETERS: address - Address of the handler
483 * DESCRIPTION: Remove a handler for a System Control Interrupt.
485 ******************************************************************************/
486 acpi_status
acpi_remove_sci_handler(acpi_sci_handler address
)
488 struct acpi_sci_handler_info
*prev_sci_handler
;
489 struct acpi_sci_handler_info
*next_sci_handler
;
490 acpi_cpu_flags flags
;
493 ACPI_FUNCTION_TRACE(acpi_remove_sci_handler
);
496 return_ACPI_STATUS(AE_BAD_PARAMETER
);
499 status
= acpi_ut_acquire_mutex(ACPI_MTX_EVENTS
);
500 if (ACPI_FAILURE(status
)) {
501 return_ACPI_STATUS(status
);
504 /* Remove the SCI handler with lock */
506 flags
= acpi_os_acquire_lock(acpi_gbl_gpe_lock
);
508 prev_sci_handler
= NULL
;
509 next_sci_handler
= acpi_gbl_sci_handler_list
;
510 while (next_sci_handler
) {
511 if (next_sci_handler
->address
== address
) {
513 /* Unlink and free the SCI handler info block */
515 if (prev_sci_handler
) {
516 prev_sci_handler
->next
= next_sci_handler
->next
;
518 acpi_gbl_sci_handler_list
=
519 next_sci_handler
->next
;
522 acpi_os_release_lock(acpi_gbl_gpe_lock
, flags
);
523 ACPI_FREE(next_sci_handler
);
524 goto unlock_and_exit
;
527 prev_sci_handler
= next_sci_handler
;
528 next_sci_handler
= next_sci_handler
->next
;
531 acpi_os_release_lock(acpi_gbl_gpe_lock
, flags
);
532 status
= AE_NOT_EXIST
;
535 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS
);
536 return_ACPI_STATUS(status
);
539 ACPI_EXPORT_SYMBOL(acpi_remove_sci_handler
)
541 /*******************************************************************************
543 * FUNCTION: acpi_install_global_event_handler
545 * PARAMETERS: handler - Pointer to the global event handler function
546 * context - Value passed to the handler on each event
550 * DESCRIPTION: Saves the pointer to the handler function. The global handler
551 * is invoked upon each incoming GPE and Fixed Event. It is
552 * invoked at interrupt level at the time of the event dispatch.
553 * Can be used to update event counters, etc.
555 ******************************************************************************/
557 acpi_install_global_event_handler(acpi_gbl_event_handler handler
, void *context
)
561 ACPI_FUNCTION_TRACE(acpi_install_global_event_handler
);
563 /* Parameter validation */
566 return_ACPI_STATUS(AE_BAD_PARAMETER
);
569 status
= acpi_ut_acquire_mutex(ACPI_MTX_EVENTS
);
570 if (ACPI_FAILURE(status
)) {
571 return_ACPI_STATUS(status
);
574 /* Don't allow two handlers. */
576 if (acpi_gbl_global_event_handler
) {
577 status
= AE_ALREADY_EXISTS
;
581 acpi_gbl_global_event_handler
= handler
;
582 acpi_gbl_global_event_handler_context
= context
;
585 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS
);
586 return_ACPI_STATUS(status
);
589 ACPI_EXPORT_SYMBOL(acpi_install_global_event_handler
)
591 /*******************************************************************************
593 * FUNCTION: acpi_install_fixed_event_handler
595 * PARAMETERS: event - Event type to enable.
596 * handler - Pointer to the handler function for the
598 * context - Value passed to the handler on each GPE
602 * DESCRIPTION: Saves the pointer to the handler function and then enables the
605 ******************************************************************************/
607 acpi_install_fixed_event_handler(u32 event
,
608 acpi_event_handler handler
, void *context
)
612 ACPI_FUNCTION_TRACE(acpi_install_fixed_event_handler
);
614 /* Parameter validation */
616 if (event
> ACPI_EVENT_MAX
) {
617 return_ACPI_STATUS(AE_BAD_PARAMETER
);
620 status
= acpi_ut_acquire_mutex(ACPI_MTX_EVENTS
);
621 if (ACPI_FAILURE(status
)) {
622 return_ACPI_STATUS(status
);
625 /* Do not allow multiple handlers */
627 if (acpi_gbl_fixed_event_handlers
[event
].handler
) {
628 status
= AE_ALREADY_EXISTS
;
632 /* Install the handler before enabling the event */
634 acpi_gbl_fixed_event_handlers
[event
].handler
= handler
;
635 acpi_gbl_fixed_event_handlers
[event
].context
= context
;
637 status
= acpi_clear_event(event
);
638 if (ACPI_SUCCESS(status
))
639 status
= acpi_enable_event(event
, 0);
640 if (ACPI_FAILURE(status
)) {
641 ACPI_WARNING((AE_INFO
,
642 "Could not enable fixed event - %s (%u)",
643 acpi_ut_get_event_name(event
), event
));
645 /* Remove the handler */
647 acpi_gbl_fixed_event_handlers
[event
].handler
= NULL
;
648 acpi_gbl_fixed_event_handlers
[event
].context
= NULL
;
650 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
651 "Enabled fixed event %s (%X), Handler=%p\n",
652 acpi_ut_get_event_name(event
), event
,
657 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS
);
658 return_ACPI_STATUS(status
);
661 ACPI_EXPORT_SYMBOL(acpi_install_fixed_event_handler
)
663 /*******************************************************************************
665 * FUNCTION: acpi_remove_fixed_event_handler
667 * PARAMETERS: event - Event type to disable.
668 * handler - Address of the handler
672 * DESCRIPTION: Disables the event and unregisters the event handler.
674 ******************************************************************************/
676 acpi_remove_fixed_event_handler(u32 event
, acpi_event_handler handler
)
678 acpi_status status
= AE_OK
;
680 ACPI_FUNCTION_TRACE(acpi_remove_fixed_event_handler
);
682 /* Parameter validation */
684 if (event
> ACPI_EVENT_MAX
) {
685 return_ACPI_STATUS(AE_BAD_PARAMETER
);
688 status
= acpi_ut_acquire_mutex(ACPI_MTX_EVENTS
);
689 if (ACPI_FAILURE(status
)) {
690 return_ACPI_STATUS(status
);
693 /* Disable the event before removing the handler */
695 status
= acpi_disable_event(event
, 0);
697 /* Always Remove the handler */
699 acpi_gbl_fixed_event_handlers
[event
].handler
= NULL
;
700 acpi_gbl_fixed_event_handlers
[event
].context
= NULL
;
702 if (ACPI_FAILURE(status
)) {
703 ACPI_WARNING((AE_INFO
,
704 "Could not disable fixed event - %s (%u)",
705 acpi_ut_get_event_name(event
), event
));
707 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
708 "Disabled fixed event - %s (%X)\n",
709 acpi_ut_get_event_name(event
), event
));
712 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS
);
713 return_ACPI_STATUS(status
);
716 ACPI_EXPORT_SYMBOL(acpi_remove_fixed_event_handler
)
718 /*******************************************************************************
720 * FUNCTION: acpi_install_gpe_handler
722 * PARAMETERS: gpe_device - Namespace node for the GPE (NULL for FADT
724 * gpe_number - The GPE number within the GPE block
725 * type - Whether this GPE should be treated as an
726 * edge- or level-triggered interrupt.
727 * address - Address of the handler
728 * context - Value passed to the handler on each GPE
732 * DESCRIPTION: Install a handler for a General Purpose Event.
734 ******************************************************************************/
736 acpi_install_gpe_handler(acpi_handle gpe_device
,
738 u32 type
, acpi_gpe_handler address
, void *context
)
740 struct acpi_gpe_event_info
*gpe_event_info
;
741 struct acpi_gpe_handler_info
*handler
;
743 acpi_cpu_flags flags
;
745 ACPI_FUNCTION_TRACE(acpi_install_gpe_handler
);
747 /* Parameter validation */
749 if ((!address
) || (type
& ~ACPI_GPE_XRUPT_TYPE_MASK
)) {
750 return_ACPI_STATUS(AE_BAD_PARAMETER
);
753 status
= acpi_ut_acquire_mutex(ACPI_MTX_EVENTS
);
754 if (ACPI_FAILURE(status
)) {
755 return_ACPI_STATUS(status
);
758 /* Allocate and init handler object (before lock) */
760 handler
= ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_gpe_handler_info
));
762 status
= AE_NO_MEMORY
;
763 goto unlock_and_exit
;
766 flags
= acpi_os_acquire_lock(acpi_gbl_gpe_lock
);
768 /* Ensure that we have a valid GPE number */
770 gpe_event_info
= acpi_ev_get_gpe_event_info(gpe_device
, gpe_number
);
771 if (!gpe_event_info
) {
772 status
= AE_BAD_PARAMETER
;
776 /* Make sure that there isn't a handler there already */
778 if ((gpe_event_info
->flags
& ACPI_GPE_DISPATCH_MASK
) ==
779 ACPI_GPE_DISPATCH_HANDLER
) {
780 status
= AE_ALREADY_EXISTS
;
784 handler
->address
= address
;
785 handler
->context
= context
;
786 handler
->method_node
= gpe_event_info
->dispatch
.method_node
;
787 handler
->original_flags
= (u8
)(gpe_event_info
->flags
&
788 (ACPI_GPE_XRUPT_TYPE_MASK
|
789 ACPI_GPE_DISPATCH_MASK
));
792 * If the GPE is associated with a method, it may have been enabled
793 * automatically during initialization, in which case it has to be
794 * disabled now to avoid spurious execution of the handler.
796 if (((handler
->original_flags
& ACPI_GPE_DISPATCH_METHOD
) ||
797 (handler
->original_flags
& ACPI_GPE_DISPATCH_NOTIFY
)) &&
798 gpe_event_info
->runtime_count
) {
799 handler
->originally_enabled
= TRUE
;
800 (void)acpi_ev_remove_gpe_reference(gpe_event_info
);
802 /* Sanity check of original type against new type */
805 (u32
)(gpe_event_info
->flags
& ACPI_GPE_XRUPT_TYPE_MASK
)) {
806 ACPI_WARNING((AE_INFO
,
807 "GPE type mismatch (level/edge)"));
811 /* Install the handler */
813 gpe_event_info
->dispatch
.handler
= handler
;
815 /* Setup up dispatch flags to indicate handler (vs. method/notify) */
817 gpe_event_info
->flags
&=
818 ~(ACPI_GPE_XRUPT_TYPE_MASK
| ACPI_GPE_DISPATCH_MASK
);
819 gpe_event_info
->flags
|= (u8
)(type
| ACPI_GPE_DISPATCH_HANDLER
);
821 acpi_os_release_lock(acpi_gbl_gpe_lock
, flags
);
824 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS
);
825 return_ACPI_STATUS(status
);
828 acpi_os_release_lock(acpi_gbl_gpe_lock
, flags
);
830 goto unlock_and_exit
;
833 ACPI_EXPORT_SYMBOL(acpi_install_gpe_handler
)
835 /*******************************************************************************
837 * FUNCTION: acpi_remove_gpe_handler
839 * PARAMETERS: gpe_device - Namespace node for the GPE (NULL for FADT
841 * gpe_number - The event to remove a handler
842 * address - Address of the handler
846 * DESCRIPTION: Remove a handler for a General Purpose acpi_event.
848 ******************************************************************************/
850 acpi_remove_gpe_handler(acpi_handle gpe_device
,
851 u32 gpe_number
, acpi_gpe_handler address
)
853 struct acpi_gpe_event_info
*gpe_event_info
;
854 struct acpi_gpe_handler_info
*handler
;
856 acpi_cpu_flags flags
;
858 ACPI_FUNCTION_TRACE(acpi_remove_gpe_handler
);
860 /* Parameter validation */
863 return_ACPI_STATUS(AE_BAD_PARAMETER
);
866 status
= acpi_ut_acquire_mutex(ACPI_MTX_EVENTS
);
867 if (ACPI_FAILURE(status
)) {
868 return_ACPI_STATUS(status
);
871 flags
= acpi_os_acquire_lock(acpi_gbl_gpe_lock
);
873 /* Ensure that we have a valid GPE number */
875 gpe_event_info
= acpi_ev_get_gpe_event_info(gpe_device
, gpe_number
);
876 if (!gpe_event_info
) {
877 status
= AE_BAD_PARAMETER
;
878 goto unlock_and_exit
;
881 /* Make sure that a handler is indeed installed */
883 if ((gpe_event_info
->flags
& ACPI_GPE_DISPATCH_MASK
) !=
884 ACPI_GPE_DISPATCH_HANDLER
) {
885 status
= AE_NOT_EXIST
;
886 goto unlock_and_exit
;
889 /* Make sure that the installed handler is the same */
891 if (gpe_event_info
->dispatch
.handler
->address
!= address
) {
892 status
= AE_BAD_PARAMETER
;
893 goto unlock_and_exit
;
896 /* Remove the handler */
898 handler
= gpe_event_info
->dispatch
.handler
;
900 /* Restore Method node (if any), set dispatch flags */
902 gpe_event_info
->dispatch
.method_node
= handler
->method_node
;
903 gpe_event_info
->flags
&=
904 ~(ACPI_GPE_XRUPT_TYPE_MASK
| ACPI_GPE_DISPATCH_MASK
);
905 gpe_event_info
->flags
|= handler
->original_flags
;
908 * If the GPE was previously associated with a method and it was
909 * enabled, it should be enabled at this point to restore the
910 * post-initialization configuration.
912 if (((handler
->original_flags
& ACPI_GPE_DISPATCH_METHOD
) ||
913 (handler
->original_flags
& ACPI_GPE_DISPATCH_NOTIFY
)) &&
914 handler
->originally_enabled
) {
915 (void)acpi_ev_add_gpe_reference(gpe_event_info
);
918 acpi_os_release_lock(acpi_gbl_gpe_lock
, flags
);
919 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS
);
921 /* Make sure all deferred GPE tasks are completed */
923 acpi_os_wait_events_complete();
925 /* Now we can free the handler object */
928 return_ACPI_STATUS(status
);
931 acpi_os_release_lock(acpi_gbl_gpe_lock
, flags
);
933 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS
);
934 return_ACPI_STATUS(status
);
937 ACPI_EXPORT_SYMBOL(acpi_remove_gpe_handler
)
939 /*******************************************************************************
941 * FUNCTION: acpi_acquire_global_lock
943 * PARAMETERS: timeout - How long the caller is willing to wait
944 * handle - Where the handle to the lock is returned
949 * DESCRIPTION: Acquire the ACPI Global Lock
951 * Note: Allows callers with the same thread ID to acquire the global lock
952 * multiple times. In other words, externally, the behavior of the global lock
953 * is identical to an AML mutex. On the first acquire, a new handle is
954 * returned. On any subsequent calls to acquire by the same thread, the same
955 * handle is returned.
957 ******************************************************************************/
958 acpi_status
acpi_acquire_global_lock(u16 timeout
, u32
*handle
)
963 return (AE_BAD_PARAMETER
);
966 /* Must lock interpreter to prevent race conditions */
968 acpi_ex_enter_interpreter();
970 status
= acpi_ex_acquire_mutex_object(timeout
,
971 acpi_gbl_global_lock_mutex
,
972 acpi_os_get_thread_id());
974 if (ACPI_SUCCESS(status
)) {
976 /* Return the global lock handle (updated in acpi_ev_acquire_global_lock) */
978 *handle
= acpi_gbl_global_lock_handle
;
981 acpi_ex_exit_interpreter();
985 ACPI_EXPORT_SYMBOL(acpi_acquire_global_lock
)
987 /*******************************************************************************
989 * FUNCTION: acpi_release_global_lock
991 * PARAMETERS: handle - Returned from acpi_acquire_global_lock
995 * DESCRIPTION: Release the ACPI Global Lock. The handle must be valid.
997 ******************************************************************************/
998 acpi_status
acpi_release_global_lock(u32 handle
)
1002 if (!handle
|| (handle
!= acpi_gbl_global_lock_handle
)) {
1003 return (AE_NOT_ACQUIRED
);
1006 status
= acpi_ex_release_mutex_object(acpi_gbl_global_lock_mutex
);
1010 ACPI_EXPORT_SYMBOL(acpi_release_global_lock
)
1011 #endif /* !ACPI_REDUCED_HARDWARE */