1 /******************************************************************************
3 * Module Name: evxface - External interfaces for ACPI events
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2010, 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 #include <acpi/acpi.h>
50 #define _COMPONENT ACPI_EVENTS
51 ACPI_MODULE_NAME("evxface")
53 /*******************************************************************************
55 * FUNCTION: acpi_install_exception_handler
57 * PARAMETERS: Handler - Pointer to the handler function for the
62 * DESCRIPTION: Saves the pointer to the handler function
64 ******************************************************************************/
65 #ifdef ACPI_FUTURE_USAGE
66 acpi_status
acpi_install_exception_handler(acpi_exception_handler handler
)
70 ACPI_FUNCTION_TRACE(acpi_install_exception_handler
);
72 status
= acpi_ut_acquire_mutex(ACPI_MTX_EVENTS
);
73 if (ACPI_FAILURE(status
)) {
74 return_ACPI_STATUS(status
);
77 /* Don't allow two handlers. */
79 if (acpi_gbl_exception_handler
) {
80 status
= AE_ALREADY_EXISTS
;
84 /* Install the handler */
86 acpi_gbl_exception_handler
= handler
;
89 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS
);
90 return_ACPI_STATUS(status
);
93 ACPI_EXPORT_SYMBOL(acpi_install_exception_handler
)
94 #endif /* ACPI_FUTURE_USAGE */
95 /*******************************************************************************
97 * FUNCTION: acpi_install_fixed_event_handler
99 * PARAMETERS: Event - Event type to enable.
100 * Handler - Pointer to the handler function for the
102 * Context - Value passed to the handler on each GPE
106 * DESCRIPTION: Saves the pointer to the handler function and then enables the
109 ******************************************************************************/
111 acpi_install_fixed_event_handler(u32 event
,
112 acpi_event_handler handler
, void *context
)
116 ACPI_FUNCTION_TRACE(acpi_install_fixed_event_handler
);
118 /* Parameter validation */
120 if (event
> ACPI_EVENT_MAX
) {
121 return_ACPI_STATUS(AE_BAD_PARAMETER
);
124 status
= acpi_ut_acquire_mutex(ACPI_MTX_EVENTS
);
125 if (ACPI_FAILURE(status
)) {
126 return_ACPI_STATUS(status
);
129 /* Don't allow two handlers. */
131 if (NULL
!= acpi_gbl_fixed_event_handlers
[event
].handler
) {
132 status
= AE_ALREADY_EXISTS
;
136 /* Install the handler before enabling the event */
138 acpi_gbl_fixed_event_handlers
[event
].handler
= handler
;
139 acpi_gbl_fixed_event_handlers
[event
].context
= context
;
141 status
= acpi_clear_event(event
);
142 if (ACPI_SUCCESS(status
))
143 status
= acpi_enable_event(event
, 0);
144 if (ACPI_FAILURE(status
)) {
145 ACPI_WARNING((AE_INFO
, "Could not enable fixed event 0x%X",
148 /* Remove the handler */
150 acpi_gbl_fixed_event_handlers
[event
].handler
= NULL
;
151 acpi_gbl_fixed_event_handlers
[event
].context
= NULL
;
153 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
154 "Enabled fixed event %X, Handler=%p\n", event
,
159 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS
);
160 return_ACPI_STATUS(status
);
163 ACPI_EXPORT_SYMBOL(acpi_install_fixed_event_handler
)
165 /*******************************************************************************
167 * FUNCTION: acpi_remove_fixed_event_handler
169 * PARAMETERS: Event - Event type to disable.
170 * Handler - Address of the handler
174 * DESCRIPTION: Disables the event and unregisters the event handler.
176 ******************************************************************************/
178 acpi_remove_fixed_event_handler(u32 event
, acpi_event_handler handler
)
180 acpi_status status
= AE_OK
;
182 ACPI_FUNCTION_TRACE(acpi_remove_fixed_event_handler
);
184 /* Parameter validation */
186 if (event
> ACPI_EVENT_MAX
) {
187 return_ACPI_STATUS(AE_BAD_PARAMETER
);
190 status
= acpi_ut_acquire_mutex(ACPI_MTX_EVENTS
);
191 if (ACPI_FAILURE(status
)) {
192 return_ACPI_STATUS(status
);
195 /* Disable the event before removing the handler */
197 status
= acpi_disable_event(event
, 0);
199 /* Always Remove the handler */
201 acpi_gbl_fixed_event_handlers
[event
].handler
= NULL
;
202 acpi_gbl_fixed_event_handlers
[event
].context
= NULL
;
204 if (ACPI_FAILURE(status
)) {
205 ACPI_WARNING((AE_INFO
,
206 "Could not write to fixed event enable register 0x%X",
209 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "Disabled fixed event %X\n",
213 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS
);
214 return_ACPI_STATUS(status
);
217 ACPI_EXPORT_SYMBOL(acpi_remove_fixed_event_handler
)
219 /*******************************************************************************
221 * FUNCTION: acpi_populate_handler_object
223 * PARAMETERS: handler_obj - Handler object to populate
224 * handler_type - The type of handler:
225 * ACPI_SYSTEM_NOTIFY: system_handler (00-7f)
226 * ACPI_DEVICE_NOTIFY: driver_handler (80-ff)
227 * ACPI_ALL_NOTIFY: both system and device
228 * handler - Address of the handler
229 * context - Value passed to the handler on each GPE
230 * next - Address of a handler object to link to
234 * DESCRIPTION: Populate a handler object.
236 ******************************************************************************/
238 acpi_populate_handler_object(struct acpi_object_notify_handler
*handler_obj
,
240 acpi_notify_handler handler
, void *context
,
241 struct acpi_object_notify_handler
*next
)
243 handler_obj
->handler_type
= handler_type
;
244 handler_obj
->handler
= handler
;
245 handler_obj
->context
= context
;
246 handler_obj
->next
= next
;
249 /*******************************************************************************
251 * FUNCTION: acpi_add_handler_object
253 * PARAMETERS: parent_obj - Parent of the new object
254 * handler - Address of the handler
255 * context - Value passed to the handler on each GPE
259 * DESCRIPTION: Create a new handler object and populate it.
261 ******************************************************************************/
263 acpi_add_handler_object(struct acpi_object_notify_handler
*parent_obj
,
264 acpi_notify_handler handler
, void *context
)
266 struct acpi_object_notify_handler
*handler_obj
;
268 /* The parent must not be a defice notify handler object. */
269 if (parent_obj
->handler_type
& ACPI_DEVICE_NOTIFY
)
270 return AE_BAD_PARAMETER
;
272 handler_obj
= ACPI_ALLOCATE_ZEROED(sizeof(*handler_obj
));
276 acpi_populate_handler_object(handler_obj
,
280 parent_obj
->next
= handler_obj
;
285 /*******************************************************************************
287 * FUNCTION: acpi_install_notify_handler
289 * PARAMETERS: Device - The device for which notifies will be handled
290 * handler_type - The type of handler:
291 * ACPI_SYSTEM_NOTIFY: system_handler (00-7f)
292 * ACPI_DEVICE_NOTIFY: driver_handler (80-ff)
293 * ACPI_ALL_NOTIFY: both system and device
294 * Handler - Address of the handler
295 * Context - Value passed to the handler on each GPE
299 * DESCRIPTION: Install a handler for notifies on an ACPI device
301 ******************************************************************************/
303 acpi_install_notify_handler(acpi_handle device
,
305 acpi_notify_handler handler
, void *context
)
307 union acpi_operand_object
*obj_desc
;
308 union acpi_operand_object
*notify_obj
;
309 struct acpi_namespace_node
*node
;
312 ACPI_FUNCTION_TRACE(acpi_install_notify_handler
);
314 /* Parameter validation */
317 (!handler
) || (handler_type
> ACPI_MAX_NOTIFY_HANDLER_TYPE
)) {
318 return_ACPI_STATUS(AE_BAD_PARAMETER
);
321 status
= acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE
);
322 if (ACPI_FAILURE(status
)) {
323 return_ACPI_STATUS(status
);
326 /* Convert and validate the device handle */
328 node
= acpi_ns_validate_handle(device
);
330 status
= AE_BAD_PARAMETER
;
331 goto unlock_and_exit
;
336 * Registering a notify handler on the root object indicates that the
337 * caller wishes to receive notifications for all objects. Note that
338 * only one <external> global handler can be regsitered (per notify type).
340 if (device
== ACPI_ROOT_OBJECT
) {
342 /* Make sure the handler is not already installed */
344 if (((handler_type
& ACPI_SYSTEM_NOTIFY
) &&
345 acpi_gbl_system_notify
.handler
) ||
346 ((handler_type
& ACPI_DEVICE_NOTIFY
) &&
347 acpi_gbl_device_notify
.handler
)) {
348 status
= AE_ALREADY_EXISTS
;
349 goto unlock_and_exit
;
352 if (handler_type
& ACPI_SYSTEM_NOTIFY
) {
353 acpi_gbl_system_notify
.node
= node
;
354 acpi_gbl_system_notify
.handler
= handler
;
355 acpi_gbl_system_notify
.context
= context
;
358 if (handler_type
& ACPI_DEVICE_NOTIFY
) {
359 acpi_gbl_device_notify
.node
= node
;
360 acpi_gbl_device_notify
.handler
= handler
;
361 acpi_gbl_device_notify
.context
= context
;
364 /* Global notify handler installed */
369 * Caller will only receive notifications specific to the target object.
370 * Note that only certain object types can receive notifications.
373 /* Notifies allowed on this object? */
375 if (!acpi_ev_is_notify_object(node
)) {
377 goto unlock_and_exit
;
380 /* Check for an existing internal object */
382 obj_desc
= acpi_ns_get_attached_object(node
);
387 /* For a device notify, make sure there's no handler. */
388 if ((handler_type
& ACPI_DEVICE_NOTIFY
) &&
389 obj_desc
->common_notify
.device_notify
) {
390 status
= AE_ALREADY_EXISTS
;
391 goto unlock_and_exit
;
394 /* System notifies may have more handlers installed. */
395 notify_obj
= obj_desc
->common_notify
.system_notify
;
397 if ((handler_type
& ACPI_SYSTEM_NOTIFY
) && notify_obj
) {
398 struct acpi_object_notify_handler
*parent_obj
;
400 if (handler_type
& ACPI_DEVICE_NOTIFY
) {
401 status
= AE_ALREADY_EXISTS
;
402 goto unlock_and_exit
;
405 parent_obj
= ¬ify_obj
->notify
;
406 status
= acpi_add_handler_object(parent_obj
,
409 goto unlock_and_exit
;
412 /* Create a new object */
414 obj_desc
= acpi_ut_create_internal_object(node
->type
);
416 status
= AE_NO_MEMORY
;
417 goto unlock_and_exit
;
420 /* Attach new object to the Node */
423 acpi_ns_attach_object(device
, obj_desc
, node
->type
);
425 /* Remove local reference to the object */
427 acpi_ut_remove_reference(obj_desc
);
428 if (ACPI_FAILURE(status
)) {
429 goto unlock_and_exit
;
433 /* Install the handler */
436 acpi_ut_create_internal_object(ACPI_TYPE_LOCAL_NOTIFY
);
438 status
= AE_NO_MEMORY
;
439 goto unlock_and_exit
;
442 acpi_populate_handler_object(¬ify_obj
->notify
,
447 if (handler_type
& ACPI_SYSTEM_NOTIFY
) {
448 obj_desc
->common_notify
.system_notify
= notify_obj
;
451 if (handler_type
& ACPI_DEVICE_NOTIFY
) {
452 obj_desc
->common_notify
.device_notify
= notify_obj
;
455 if (handler_type
== ACPI_ALL_NOTIFY
) {
457 /* Extra ref if installed in both */
459 acpi_ut_add_reference(notify_obj
);
464 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE
);
465 return_ACPI_STATUS(status
);
468 ACPI_EXPORT_SYMBOL(acpi_install_notify_handler
)
470 /*******************************************************************************
472 * FUNCTION: acpi_remove_notify_handler
474 * PARAMETERS: Device - The device for which notifies will be handled
475 * handler_type - The type of handler:
476 * ACPI_SYSTEM_NOTIFY: system_handler (00-7f)
477 * ACPI_DEVICE_NOTIFY: driver_handler (80-ff)
478 * ACPI_ALL_NOTIFY: both system and device
479 * Handler - Address of the handler
483 * DESCRIPTION: Remove a handler for notifies on an ACPI device
485 ******************************************************************************/
487 acpi_remove_notify_handler(acpi_handle device
,
488 u32 handler_type
, acpi_notify_handler handler
)
490 union acpi_operand_object
*notify_obj
;
491 union acpi_operand_object
*obj_desc
;
492 struct acpi_namespace_node
*node
;
495 ACPI_FUNCTION_TRACE(acpi_remove_notify_handler
);
497 /* Parameter validation */
500 (!handler
) || (handler_type
> ACPI_MAX_NOTIFY_HANDLER_TYPE
)) {
501 status
= AE_BAD_PARAMETER
;
506 /* Make sure all deferred tasks are completed */
507 acpi_os_wait_events_complete(NULL
);
509 status
= acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE
);
510 if (ACPI_FAILURE(status
)) {
514 /* Convert and validate the device handle */
516 node
= acpi_ns_validate_handle(device
);
518 status
= AE_BAD_PARAMETER
;
519 goto unlock_and_exit
;
524 if (device
== ACPI_ROOT_OBJECT
) {
525 ACPI_DEBUG_PRINT((ACPI_DB_INFO
,
526 "Removing notify handler for namespace root object\n"));
528 if (((handler_type
& ACPI_SYSTEM_NOTIFY
) &&
529 !acpi_gbl_system_notify
.handler
) ||
530 ((handler_type
& ACPI_DEVICE_NOTIFY
) &&
531 !acpi_gbl_device_notify
.handler
)) {
532 status
= AE_NOT_EXIST
;
533 goto unlock_and_exit
;
536 if (handler_type
& ACPI_SYSTEM_NOTIFY
) {
537 acpi_gbl_system_notify
.node
= NULL
;
538 acpi_gbl_system_notify
.handler
= NULL
;
539 acpi_gbl_system_notify
.context
= NULL
;
542 if (handler_type
& ACPI_DEVICE_NOTIFY
) {
543 acpi_gbl_device_notify
.node
= NULL
;
544 acpi_gbl_device_notify
.handler
= NULL
;
545 acpi_gbl_device_notify
.context
= NULL
;
549 /* All Other Objects */
552 /* Notifies allowed on this object? */
554 if (!acpi_ev_is_notify_object(node
)) {
556 goto unlock_and_exit
;
559 /* Check for an existing internal object */
561 obj_desc
= acpi_ns_get_attached_object(node
);
563 status
= AE_NOT_EXIST
;
564 goto unlock_and_exit
;
567 /* Object exists - make sure there's an existing handler */
569 if (handler_type
& ACPI_SYSTEM_NOTIFY
) {
570 struct acpi_object_notify_handler
*handler_obj
;
571 struct acpi_object_notify_handler
*parent_obj
;
573 notify_obj
= obj_desc
->common_notify
.system_notify
;
575 status
= AE_NOT_EXIST
;
576 goto unlock_and_exit
;
579 handler_obj
= ¬ify_obj
->notify
;
581 while (handler_obj
->handler
!= handler
) {
582 if (handler_obj
->next
) {
583 parent_obj
= handler_obj
;
584 handler_obj
= handler_obj
->next
;
590 if (handler_obj
->handler
!= handler
) {
591 status
= AE_BAD_PARAMETER
;
592 goto unlock_and_exit
;
596 * Remove the handler. There are three possible cases.
597 * First, we may need to remove a non-embedded object.
598 * Second, we may need to remove the embedded object's
599 * handler data, while non-embedded objects exist.
600 * Finally, we may need to remove the embedded object
601 * entirely along with its container.
604 /* Non-embedded object is being removed. */
605 parent_obj
->next
= handler_obj
->next
;
606 ACPI_FREE(handler_obj
);
607 } else if (notify_obj
->notify
.next
) {
609 * The handler matches the embedded object, but
610 * there are more handler objects in the list.
611 * Replace the embedded object's data with the
612 * first next object's data and remove that
615 parent_obj
= ¬ify_obj
->notify
;
616 handler_obj
= notify_obj
->notify
.next
;
617 *parent_obj
= *handler_obj
;
618 ACPI_FREE(handler_obj
);
620 /* No more handler objects in the list. */
621 obj_desc
->common_notify
.system_notify
= NULL
;
622 acpi_ut_remove_reference(notify_obj
);
626 if (handler_type
& ACPI_DEVICE_NOTIFY
) {
627 notify_obj
= obj_desc
->common_notify
.device_notify
;
629 status
= AE_NOT_EXIST
;
630 goto unlock_and_exit
;
633 if (notify_obj
->notify
.handler
!= handler
) {
634 status
= AE_BAD_PARAMETER
;
635 goto unlock_and_exit
;
638 /* Remove the handler */
639 obj_desc
->common_notify
.device_notify
= NULL
;
640 acpi_ut_remove_reference(notify_obj
);
645 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE
);
647 if (ACPI_FAILURE(status
))
648 ACPI_EXCEPTION((AE_INFO
, status
, "Removing notify handler"));
649 return_ACPI_STATUS(status
);
652 ACPI_EXPORT_SYMBOL(acpi_remove_notify_handler
)
654 /*******************************************************************************
656 * FUNCTION: acpi_install_gpe_handler
658 * PARAMETERS: gpe_device - Namespace node for the GPE (NULL for FADT
660 * gpe_number - The GPE number within the GPE block
661 * Type - Whether this GPE should be treated as an
662 * edge- or level-triggered interrupt.
663 * Address - Address of the handler
664 * Context - Value passed to the handler on each GPE
668 * DESCRIPTION: Install a handler for a General Purpose Event.
670 ******************************************************************************/
672 acpi_install_gpe_handler(acpi_handle gpe_device
,
674 u32 type
, acpi_gpe_handler address
, void *context
)
676 struct acpi_gpe_event_info
*gpe_event_info
;
677 struct acpi_gpe_handler_info
*handler
;
679 acpi_cpu_flags flags
;
681 ACPI_FUNCTION_TRACE(acpi_install_gpe_handler
);
683 /* Parameter validation */
685 if ((!address
) || (type
& ~ACPI_GPE_XRUPT_TYPE_MASK
)) {
686 return_ACPI_STATUS(AE_BAD_PARAMETER
);
689 status
= acpi_ut_acquire_mutex(ACPI_MTX_EVENTS
);
690 if (ACPI_FAILURE(status
)) {
691 return_ACPI_STATUS(status
);
694 /* Allocate memory for the handler object */
696 handler
= ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_gpe_handler_info
));
698 status
= AE_NO_MEMORY
;
699 goto unlock_and_exit
;
702 flags
= acpi_os_acquire_lock(acpi_gbl_gpe_lock
);
704 /* Ensure that we have a valid GPE number */
706 gpe_event_info
= acpi_ev_get_gpe_event_info(gpe_device
, gpe_number
);
707 if (!gpe_event_info
) {
708 status
= AE_BAD_PARAMETER
;
712 /* Make sure that there isn't a handler there already */
714 if ((gpe_event_info
->flags
& ACPI_GPE_DISPATCH_MASK
) ==
715 ACPI_GPE_DISPATCH_HANDLER
) {
716 status
= AE_ALREADY_EXISTS
;
720 /* Allocate and init handler object */
722 handler
->address
= address
;
723 handler
->context
= context
;
724 handler
->method_node
= gpe_event_info
->dispatch
.method_node
;
725 handler
->original_flags
= gpe_event_info
->flags
&
726 (ACPI_GPE_XRUPT_TYPE_MASK
| ACPI_GPE_DISPATCH_MASK
);
729 * If the GPE is associated with a method, it might have been enabled
730 * automatically during initialization, in which case it has to be
731 * disabled now to avoid spurious execution of the handler.
734 if ((handler
->original_flags
& ACPI_GPE_DISPATCH_METHOD
)
735 && gpe_event_info
->runtime_count
) {
736 handler
->originally_enabled
= 1;
737 (void)acpi_ev_remove_gpe_reference(gpe_event_info
);
740 /* Install the handler */
742 gpe_event_info
->dispatch
.handler
= handler
;
744 /* Setup up dispatch flags to indicate handler (vs. method) */
746 gpe_event_info
->flags
&=
747 ~(ACPI_GPE_XRUPT_TYPE_MASK
| ACPI_GPE_DISPATCH_MASK
);
748 gpe_event_info
->flags
|= (u8
) (type
| ACPI_GPE_DISPATCH_HANDLER
);
750 acpi_os_release_lock(acpi_gbl_gpe_lock
, flags
);
753 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS
);
754 return_ACPI_STATUS(status
);
757 acpi_os_release_lock(acpi_gbl_gpe_lock
, flags
);
759 goto unlock_and_exit
;
762 ACPI_EXPORT_SYMBOL(acpi_install_gpe_handler
)
764 /*******************************************************************************
766 * FUNCTION: acpi_remove_gpe_handler
768 * PARAMETERS: gpe_device - Namespace node for the GPE (NULL for FADT
770 * gpe_number - The event to remove a handler
771 * Address - Address of the handler
775 * DESCRIPTION: Remove a handler for a General Purpose acpi_event.
777 ******************************************************************************/
779 acpi_remove_gpe_handler(acpi_handle gpe_device
,
780 u32 gpe_number
, acpi_gpe_handler address
)
782 struct acpi_gpe_event_info
*gpe_event_info
;
783 struct acpi_gpe_handler_info
*handler
;
785 acpi_cpu_flags flags
;
787 ACPI_FUNCTION_TRACE(acpi_remove_gpe_handler
);
789 /* Parameter validation */
792 return_ACPI_STATUS(AE_BAD_PARAMETER
);
795 /* Make sure all deferred tasks are completed */
797 acpi_os_wait_events_complete(NULL
);
799 status
= acpi_ut_acquire_mutex(ACPI_MTX_EVENTS
);
800 if (ACPI_FAILURE(status
)) {
801 return_ACPI_STATUS(status
);
804 flags
= acpi_os_acquire_lock(acpi_gbl_gpe_lock
);
806 /* Ensure that we have a valid GPE number */
808 gpe_event_info
= acpi_ev_get_gpe_event_info(gpe_device
, gpe_number
);
809 if (!gpe_event_info
) {
810 status
= AE_BAD_PARAMETER
;
811 goto unlock_and_exit
;
814 /* Make sure that a handler is indeed installed */
816 if ((gpe_event_info
->flags
& ACPI_GPE_DISPATCH_MASK
) !=
817 ACPI_GPE_DISPATCH_HANDLER
) {
818 status
= AE_NOT_EXIST
;
819 goto unlock_and_exit
;
822 /* Make sure that the installed handler is the same */
824 if (gpe_event_info
->dispatch
.handler
->address
!= address
) {
825 status
= AE_BAD_PARAMETER
;
826 goto unlock_and_exit
;
829 /* Remove the handler */
831 handler
= gpe_event_info
->dispatch
.handler
;
833 /* Restore Method node (if any), set dispatch flags */
835 gpe_event_info
->dispatch
.method_node
= handler
->method_node
;
836 gpe_event_info
->flags
&=
837 ~(ACPI_GPE_XRUPT_TYPE_MASK
| ACPI_GPE_DISPATCH_MASK
);
838 gpe_event_info
->flags
|= handler
->original_flags
;
841 * If the GPE was previously associated with a method and it was
842 * enabled, it should be enabled at this point to restore the
843 * post-initialization configuration.
846 if ((handler
->original_flags
& ACPI_GPE_DISPATCH_METHOD
)
847 && handler
->originally_enabled
)
848 (void)acpi_ev_add_gpe_reference(gpe_event_info
);
850 /* Now we can free the handler object */
855 acpi_os_release_lock(acpi_gbl_gpe_lock
, flags
);
857 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS
);
858 return_ACPI_STATUS(status
);
861 ACPI_EXPORT_SYMBOL(acpi_remove_gpe_handler
)
863 /*******************************************************************************
865 * FUNCTION: acpi_acquire_global_lock
867 * PARAMETERS: Timeout - How long the caller is willing to wait
868 * Handle - Where the handle to the lock is returned
873 * DESCRIPTION: Acquire the ACPI Global Lock
875 * Note: Allows callers with the same thread ID to acquire the global lock
876 * multiple times. In other words, externally, the behavior of the global lock
877 * is identical to an AML mutex. On the first acquire, a new handle is
878 * returned. On any subsequent calls to acquire by the same thread, the same
879 * handle is returned.
881 ******************************************************************************/
882 acpi_status
acpi_acquire_global_lock(u16 timeout
, u32
* handle
)
887 return (AE_BAD_PARAMETER
);
890 /* Must lock interpreter to prevent race conditions */
892 acpi_ex_enter_interpreter();
894 status
= acpi_ex_acquire_mutex_object(timeout
,
895 acpi_gbl_global_lock_mutex
,
896 acpi_os_get_thread_id());
898 if (ACPI_SUCCESS(status
)) {
900 /* Return the global lock handle (updated in acpi_ev_acquire_global_lock) */
902 *handle
= acpi_gbl_global_lock_handle
;
905 acpi_ex_exit_interpreter();
909 ACPI_EXPORT_SYMBOL(acpi_acquire_global_lock
)
911 /*******************************************************************************
913 * FUNCTION: acpi_release_global_lock
915 * PARAMETERS: Handle - Returned from acpi_acquire_global_lock
919 * DESCRIPTION: Release the ACPI Global Lock. The handle must be valid.
921 ******************************************************************************/
922 acpi_status
acpi_release_global_lock(u32 handle
)
926 if (!handle
|| (handle
!= acpi_gbl_global_lock_handle
)) {
927 return (AE_NOT_ACQUIRED
);
930 status
= acpi_ex_release_mutex_object(acpi_gbl_global_lock_mutex
);
934 ACPI_EXPORT_SYMBOL(acpi_release_global_lock
)