1 /******************************************************************************
3 * Module Name: evxface - External interfaces for ACPI events
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2012, 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 <linux/export.h>
45 #include <acpi/acpi.h>
51 #define _COMPONENT ACPI_EVENTS
52 ACPI_MODULE_NAME("evxface")
55 /*******************************************************************************
57 * FUNCTION: acpi_populate_handler_object
59 * PARAMETERS: handler_obj - Handler object to populate
60 * handler_type - The type of handler:
61 * ACPI_SYSTEM_NOTIFY: system_handler (00-7f)
62 * ACPI_DEVICE_NOTIFY: driver_handler (80-ff)
63 * ACPI_ALL_NOTIFY: both system and device
64 * handler - Address of the handler
65 * context - Value passed to the handler on each GPE
66 * next - Address of a handler object to link to
70 * DESCRIPTION: Populate a handler object.
72 ******************************************************************************/
74 acpi_populate_handler_object(struct acpi_object_notify_handler *handler_obj,
76 acpi_notify_handler handler, void *context,
77 struct acpi_object_notify_handler *next)
79 handler_obj->handler_type = handler_type;
80 handler_obj->handler = handler;
81 handler_obj->context = context;
82 handler_obj->next = next;
85 /*******************************************************************************
87 * FUNCTION: acpi_add_handler_object
89 * PARAMETERS: parent_obj - Parent of the new object
90 * handler - Address of the handler
91 * context - Value passed to the handler on each GPE
95 * DESCRIPTION: Create a new handler object and populate it.
97 ******************************************************************************/
99 acpi_add_handler_object(struct acpi_object_notify_handler *parent_obj,
100 acpi_notify_handler handler, void *context)
102 struct acpi_object_notify_handler *handler_obj;
104 /* The parent must not be a defice notify handler object. */
105 if (parent_obj->handler_type & ACPI_DEVICE_NOTIFY)
106 return AE_BAD_PARAMETER;
108 handler_obj = ACPI_ALLOCATE_ZEROED(sizeof(*handler_obj));
112 acpi_populate_handler_object(handler_obj,
116 parent_obj->next = handler_obj;
122 /*******************************************************************************
124 * FUNCTION: acpi_install_notify_handler
126 * PARAMETERS: Device - The device for which notifies will be handled
127 * handler_type - The type of handler:
128 * ACPI_SYSTEM_NOTIFY: system_handler (00-7f)
129 * ACPI_DEVICE_NOTIFY: driver_handler (80-ff)
130 * ACPI_ALL_NOTIFY: both system and device
131 * Handler - Address of the handler
132 * Context - Value passed to the handler on each GPE
136 * DESCRIPTION: Install a handler for notifies on an ACPI device
138 ******************************************************************************/
140 acpi_install_notify_handler(acpi_handle device,
142 acpi_notify_handler handler, void *context)
144 union acpi_operand_object *obj_desc;
145 union acpi_operand_object *notify_obj;
146 struct acpi_namespace_node *node;
149 ACPI_FUNCTION_TRACE(acpi_install_notify_handler);
151 /* Parameter validation */
154 (!handler) || (handler_type > ACPI_MAX_NOTIFY_HANDLER_TYPE)) {
155 return_ACPI_STATUS(AE_BAD_PARAMETER);
158 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
159 if (ACPI_FAILURE(status)) {
160 return_ACPI_STATUS(status);
163 /* Convert and validate the device handle */
165 node = acpi_ns_validate_handle(device);
167 status = AE_BAD_PARAMETER;
168 goto unlock_and_exit;
173 * Registering a notify handler on the root object indicates that the
174 * caller wishes to receive notifications for all objects. Note that
175 * only one <external> global handler can be regsitered (per notify type).
177 if (device == ACPI_ROOT_OBJECT) {
179 /* Make sure the handler is not already installed */
181 if (((handler_type & ACPI_SYSTEM_NOTIFY) &&
182 acpi_gbl_system_notify.handler) ||
183 ((handler_type & ACPI_DEVICE_NOTIFY) &&
184 acpi_gbl_device_notify.handler)) {
185 status = AE_ALREADY_EXISTS;
186 goto unlock_and_exit;
189 if (handler_type & ACPI_SYSTEM_NOTIFY) {
190 acpi_gbl_system_notify.node = node;
191 acpi_gbl_system_notify.handler = handler;
192 acpi_gbl_system_notify.context = context;
195 if (handler_type & ACPI_DEVICE_NOTIFY) {
196 acpi_gbl_device_notify.node = node;
197 acpi_gbl_device_notify.handler = handler;
198 acpi_gbl_device_notify.context = context;
201 /* Global notify handler installed */
206 * Caller will only receive notifications specific to the target object.
207 * Note that only certain object types can receive notifications.
210 /* Notifies allowed on this object? */
212 if (!acpi_ev_is_notify_object(node)) {
214 goto unlock_and_exit;
217 /* Check for an existing internal object */
219 obj_desc = acpi_ns_get_attached_object(node);
224 /* For a device notify, make sure there's no handler. */
225 if ((handler_type & ACPI_DEVICE_NOTIFY) &&
226 obj_desc->common_notify.device_notify) {
227 status = AE_ALREADY_EXISTS;
228 goto unlock_and_exit;
231 /* System notifies may have more handlers installed. */
232 notify_obj = obj_desc->common_notify.system_notify;
234 if ((handler_type & ACPI_SYSTEM_NOTIFY) && notify_obj) {
235 struct acpi_object_notify_handler *parent_obj;
237 if (handler_type & ACPI_DEVICE_NOTIFY) {
238 status = AE_ALREADY_EXISTS;
239 goto unlock_and_exit;
242 parent_obj = ¬ify_obj->notify;
243 status = acpi_add_handler_object(parent_obj,
246 goto unlock_and_exit;
249 /* Create a new object */
251 obj_desc = acpi_ut_create_internal_object(node->type);
253 status = AE_NO_MEMORY;
254 goto unlock_and_exit;
257 /* Attach new object to the Node */
260 acpi_ns_attach_object(device, obj_desc, node->type);
262 /* Remove local reference to the object */
264 acpi_ut_remove_reference(obj_desc);
265 if (ACPI_FAILURE(status)) {
266 goto unlock_and_exit;
270 /* Install the handler */
273 acpi_ut_create_internal_object(ACPI_TYPE_LOCAL_NOTIFY);
275 status = AE_NO_MEMORY;
276 goto unlock_and_exit;
279 acpi_populate_handler_object(¬ify_obj->notify,
284 if (handler_type & ACPI_SYSTEM_NOTIFY) {
285 obj_desc->common_notify.system_notify = notify_obj;
288 if (handler_type & ACPI_DEVICE_NOTIFY) {
289 obj_desc->common_notify.device_notify = notify_obj;
292 if (handler_type == ACPI_ALL_NOTIFY) {
294 /* Extra ref if installed in both */
296 acpi_ut_add_reference(notify_obj);
301 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
302 return_ACPI_STATUS(status);
305 ACPI_EXPORT_SYMBOL(acpi_install_notify_handler)
307 /*******************************************************************************
309 * FUNCTION: acpi_remove_notify_handler
311 * PARAMETERS: Device - The device for which notifies will be handled
312 * handler_type - The type of handler:
313 * ACPI_SYSTEM_NOTIFY: system_handler (00-7f)
314 * ACPI_DEVICE_NOTIFY: driver_handler (80-ff)
315 * ACPI_ALL_NOTIFY: both system and device
316 * Handler - Address of the handler
320 * DESCRIPTION: Remove a handler for notifies on an ACPI device
322 ******************************************************************************/
324 acpi_remove_notify_handler(acpi_handle device,
325 u32 handler_type, acpi_notify_handler handler)
327 union acpi_operand_object *notify_obj;
328 union acpi_operand_object *obj_desc;
329 struct acpi_namespace_node *node;
332 ACPI_FUNCTION_TRACE(acpi_remove_notify_handler);
334 /* Parameter validation */
337 (!handler) || (handler_type > ACPI_MAX_NOTIFY_HANDLER_TYPE)) {
338 status = AE_BAD_PARAMETER;
343 /* Make sure all deferred tasks are completed */
344 acpi_os_wait_events_complete(NULL);
346 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
347 if (ACPI_FAILURE(status)) {
351 /* Convert and validate the device handle */
353 node = acpi_ns_validate_handle(device);
355 status = AE_BAD_PARAMETER;
356 goto unlock_and_exit;
361 if (device == ACPI_ROOT_OBJECT) {
362 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
363 "Removing notify handler for namespace root object\n"));
365 if (((handler_type & ACPI_SYSTEM_NOTIFY) &&
366 !acpi_gbl_system_notify.handler) ||
367 ((handler_type & ACPI_DEVICE_NOTIFY) &&
368 !acpi_gbl_device_notify.handler)) {
369 status = AE_NOT_EXIST;
370 goto unlock_and_exit;
373 if (handler_type & ACPI_SYSTEM_NOTIFY) {
374 acpi_gbl_system_notify.node = NULL;
375 acpi_gbl_system_notify.handler = NULL;
376 acpi_gbl_system_notify.context = NULL;
379 if (handler_type & ACPI_DEVICE_NOTIFY) {
380 acpi_gbl_device_notify.node = NULL;
381 acpi_gbl_device_notify.handler = NULL;
382 acpi_gbl_device_notify.context = NULL;
386 /* All Other Objects */
389 /* Notifies allowed on this object? */
391 if (!acpi_ev_is_notify_object(node)) {
393 goto unlock_and_exit;
396 /* Check for an existing internal object */
398 obj_desc = acpi_ns_get_attached_object(node);
400 status = AE_NOT_EXIST;
401 goto unlock_and_exit;
404 /* Object exists - make sure there's an existing handler */
406 if (handler_type & ACPI_SYSTEM_NOTIFY) {
407 struct acpi_object_notify_handler *handler_obj;
408 struct acpi_object_notify_handler *parent_obj;
410 notify_obj = obj_desc->common_notify.system_notify;
412 status = AE_NOT_EXIST;
413 goto unlock_and_exit;
416 handler_obj = ¬ify_obj->notify;
418 while (handler_obj->handler != handler) {
419 if (handler_obj->next) {
420 parent_obj = handler_obj;
421 handler_obj = handler_obj->next;
427 if (handler_obj->handler != handler) {
428 status = AE_BAD_PARAMETER;
429 goto unlock_and_exit;
433 * Remove the handler. There are three possible cases.
434 * First, we may need to remove a non-embedded object.
435 * Second, we may need to remove the embedded object's
436 * handler data, while non-embedded objects exist.
437 * Finally, we may need to remove the embedded object
438 * entirely along with its container.
441 /* Non-embedded object is being removed. */
442 parent_obj->next = handler_obj->next;
443 ACPI_FREE(handler_obj);
444 } else if (notify_obj->notify.next) {
446 * The handler matches the embedded object, but
447 * there are more handler objects in the list.
448 * Replace the embedded object's data with the
449 * first next object's data and remove that
452 parent_obj = ¬ify_obj->notify;
453 handler_obj = notify_obj->notify.next;
454 *parent_obj = *handler_obj;
455 ACPI_FREE(handler_obj);
457 /* No more handler objects in the list. */
458 obj_desc->common_notify.system_notify = NULL;
459 acpi_ut_remove_reference(notify_obj);
463 if (handler_type & ACPI_DEVICE_NOTIFY) {
464 notify_obj = obj_desc->common_notify.device_notify;
466 status = AE_NOT_EXIST;
467 goto unlock_and_exit;
470 if (notify_obj->notify.handler != handler) {
471 status = AE_BAD_PARAMETER;
472 goto unlock_and_exit;
475 /* Remove the handler */
476 obj_desc->common_notify.device_notify = NULL;
477 acpi_ut_remove_reference(notify_obj);
482 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
484 if (ACPI_FAILURE(status))
485 ACPI_EXCEPTION((AE_INFO, status, "Removing notify handler"));
486 return_ACPI_STATUS(status);
489 ACPI_EXPORT_SYMBOL(acpi_remove_notify_handler)
491 /*******************************************************************************
493 * FUNCTION: acpi_install_exception_handler
495 * PARAMETERS: Handler - Pointer to the handler function for the
500 * DESCRIPTION: Saves the pointer to the handler function
502 ******************************************************************************/
503 #ifdef ACPI_FUTURE_USAGE
504 acpi_status acpi_install_exception_handler(acpi_exception_handler handler)
508 ACPI_FUNCTION_TRACE(acpi_install_exception_handler);
510 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
511 if (ACPI_FAILURE(status)) {
512 return_ACPI_STATUS(status);
515 /* Don't allow two handlers. */
517 if (acpi_gbl_exception_handler) {
518 status = AE_ALREADY_EXISTS;
522 /* Install the handler */
524 acpi_gbl_exception_handler = handler;
527 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
528 return_ACPI_STATUS(status);
531 ACPI_EXPORT_SYMBOL(acpi_install_exception_handler)
532 #endif /* ACPI_FUTURE_USAGE */
534 #if (!ACPI_REDUCED_HARDWARE)
535 /*******************************************************************************
537 * FUNCTION: acpi_install_global_event_handler
539 * PARAMETERS: Handler - Pointer to the global event handler function
540 * Context - Value passed to the handler on each event
544 * DESCRIPTION: Saves the pointer to the handler function. The global handler
545 * is invoked upon each incoming GPE and Fixed Event. It is
546 * invoked at interrupt level at the time of the event dispatch.
547 * Can be used to update event counters, etc.
549 ******************************************************************************/
551 acpi_install_global_event_handler(ACPI_GBL_EVENT_HANDLER handler, void *context)
555 ACPI_FUNCTION_TRACE(acpi_install_global_event_handler);
557 /* Parameter validation */
560 return_ACPI_STATUS(AE_BAD_PARAMETER);
563 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
564 if (ACPI_FAILURE(status)) {
565 return_ACPI_STATUS(status);
568 /* Don't allow two handlers. */
570 if (acpi_gbl_global_event_handler) {
571 status = AE_ALREADY_EXISTS;
575 acpi_gbl_global_event_handler = handler;
576 acpi_gbl_global_event_handler_context = context;
579 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
580 return_ACPI_STATUS(status);
583 ACPI_EXPORT_SYMBOL(acpi_install_global_event_handler)
585 /*******************************************************************************
587 * FUNCTION: acpi_install_fixed_event_handler
589 * PARAMETERS: Event - Event type to enable.
590 * Handler - Pointer to the handler function for the
592 * Context - Value passed to the handler on each GPE
596 * DESCRIPTION: Saves the pointer to the handler function and then enables the
599 ******************************************************************************/
601 acpi_install_fixed_event_handler(u32 event,
602 acpi_event_handler handler, void *context)
606 ACPI_FUNCTION_TRACE(acpi_install_fixed_event_handler);
608 /* Parameter validation */
610 if (event > ACPI_EVENT_MAX) {
611 return_ACPI_STATUS(AE_BAD_PARAMETER);
614 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
615 if (ACPI_FAILURE(status)) {
616 return_ACPI_STATUS(status);
619 /* Don't allow two handlers. */
621 if (NULL != acpi_gbl_fixed_event_handlers[event].handler) {
622 status = AE_ALREADY_EXISTS;
626 /* Install the handler before enabling the event */
628 acpi_gbl_fixed_event_handlers[event].handler = handler;
629 acpi_gbl_fixed_event_handlers[event].context = context;
631 status = acpi_clear_event(event);
632 if (ACPI_SUCCESS(status))
633 status = acpi_enable_event(event, 0);
634 if (ACPI_FAILURE(status)) {
635 ACPI_WARNING((AE_INFO, "Could not enable fixed event 0x%X",
638 /* Remove the handler */
640 acpi_gbl_fixed_event_handlers[event].handler = NULL;
641 acpi_gbl_fixed_event_handlers[event].context = NULL;
643 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
644 "Enabled fixed event %X, Handler=%p\n", event,
649 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
650 return_ACPI_STATUS(status);
653 ACPI_EXPORT_SYMBOL(acpi_install_fixed_event_handler)
655 /*******************************************************************************
657 * FUNCTION: acpi_remove_fixed_event_handler
659 * PARAMETERS: Event - Event type to disable.
660 * Handler - Address of the handler
664 * DESCRIPTION: Disables the event and unregisters the event handler.
666 ******************************************************************************/
668 acpi_remove_fixed_event_handler(u32 event, acpi_event_handler handler)
670 acpi_status status = AE_OK;
672 ACPI_FUNCTION_TRACE(acpi_remove_fixed_event_handler);
674 /* Parameter validation */
676 if (event > ACPI_EVENT_MAX) {
677 return_ACPI_STATUS(AE_BAD_PARAMETER);
680 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
681 if (ACPI_FAILURE(status)) {
682 return_ACPI_STATUS(status);
685 /* Disable the event before removing the handler */
687 status = acpi_disable_event(event, 0);
689 /* Always Remove the handler */
691 acpi_gbl_fixed_event_handlers[event].handler = NULL;
692 acpi_gbl_fixed_event_handlers[event].context = NULL;
694 if (ACPI_FAILURE(status)) {
695 ACPI_WARNING((AE_INFO,
696 "Could not write to fixed event enable register 0x%X",
699 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Disabled fixed event %X\n",
703 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
704 return_ACPI_STATUS(status);
707 ACPI_EXPORT_SYMBOL(acpi_remove_fixed_event_handler)
709 /*******************************************************************************
711 * FUNCTION: acpi_install_gpe_handler
713 * PARAMETERS: gpe_device - Namespace node for the GPE (NULL for FADT
715 * gpe_number - The GPE number within the GPE block
716 * Type - Whether this GPE should be treated as an
717 * edge- or level-triggered interrupt.
718 * Address - Address of the handler
719 * Context - Value passed to the handler on each GPE
723 * DESCRIPTION: Install a handler for a General Purpose Event.
725 ******************************************************************************/
727 acpi_install_gpe_handler(acpi_handle gpe_device,
729 u32 type, acpi_gpe_handler address, void *context)
731 struct acpi_gpe_event_info *gpe_event_info;
732 struct acpi_gpe_handler_info *handler;
734 acpi_cpu_flags flags;
736 ACPI_FUNCTION_TRACE(acpi_install_gpe_handler);
738 /* Parameter validation */
740 if ((!address) || (type & ~ACPI_GPE_XRUPT_TYPE_MASK)) {
741 return_ACPI_STATUS(AE_BAD_PARAMETER);
744 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
745 if (ACPI_FAILURE(status)) {
746 return_ACPI_STATUS(status);
749 /* Allocate memory for the handler object */
751 handler = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_gpe_handler_info));
753 status = AE_NO_MEMORY;
754 goto unlock_and_exit;
757 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
759 /* Ensure that we have a valid GPE number */
761 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
762 if (!gpe_event_info) {
763 status = AE_BAD_PARAMETER;
767 /* Make sure that there isn't a handler there already */
769 if ((gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) ==
770 ACPI_GPE_DISPATCH_HANDLER) {
771 status = AE_ALREADY_EXISTS;
775 /* Allocate and init handler object */
777 handler->address = address;
778 handler->context = context;
779 handler->method_node = gpe_event_info->dispatch.method_node;
780 handler->original_flags = gpe_event_info->flags &
781 (ACPI_GPE_XRUPT_TYPE_MASK | ACPI_GPE_DISPATCH_MASK);
784 * If the GPE is associated with a method, it might have been enabled
785 * automatically during initialization, in which case it has to be
786 * disabled now to avoid spurious execution of the handler.
789 if ((handler->original_flags & ACPI_GPE_DISPATCH_METHOD)
790 && gpe_event_info->runtime_count) {
791 handler->originally_enabled = 1;
792 (void)acpi_ev_remove_gpe_reference(gpe_event_info);
795 /* Install the handler */
797 gpe_event_info->dispatch.handler = handler;
799 /* Setup up dispatch flags to indicate handler (vs. method) */
801 gpe_event_info->flags &=
802 ~(ACPI_GPE_XRUPT_TYPE_MASK | ACPI_GPE_DISPATCH_MASK);
803 gpe_event_info->flags |= (u8) (type | ACPI_GPE_DISPATCH_HANDLER);
805 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
808 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
809 return_ACPI_STATUS(status);
812 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
814 goto unlock_and_exit;
817 ACPI_EXPORT_SYMBOL(acpi_install_gpe_handler)
819 /*******************************************************************************
821 * FUNCTION: acpi_remove_gpe_handler
823 * PARAMETERS: gpe_device - Namespace node for the GPE (NULL for FADT
825 * gpe_number - The event to remove a handler
826 * Address - Address of the handler
830 * DESCRIPTION: Remove a handler for a General Purpose acpi_event.
832 ******************************************************************************/
834 acpi_remove_gpe_handler(acpi_handle gpe_device,
835 u32 gpe_number, acpi_gpe_handler address)
837 struct acpi_gpe_event_info *gpe_event_info;
838 struct acpi_gpe_handler_info *handler;
840 acpi_cpu_flags flags;
842 ACPI_FUNCTION_TRACE(acpi_remove_gpe_handler);
844 /* Parameter validation */
847 return_ACPI_STATUS(AE_BAD_PARAMETER);
850 /* Make sure all deferred tasks are completed */
852 acpi_os_wait_events_complete(NULL);
854 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
855 if (ACPI_FAILURE(status)) {
856 return_ACPI_STATUS(status);
859 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
861 /* Ensure that we have a valid GPE number */
863 gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
864 if (!gpe_event_info) {
865 status = AE_BAD_PARAMETER;
866 goto unlock_and_exit;
869 /* Make sure that a handler is indeed installed */
871 if ((gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) !=
872 ACPI_GPE_DISPATCH_HANDLER) {
873 status = AE_NOT_EXIST;
874 goto unlock_and_exit;
877 /* Make sure that the installed handler is the same */
879 if (gpe_event_info->dispatch.handler->address != address) {
880 status = AE_BAD_PARAMETER;
881 goto unlock_and_exit;
884 /* Remove the handler */
886 handler = gpe_event_info->dispatch.handler;
888 /* Restore Method node (if any), set dispatch flags */
890 gpe_event_info->dispatch.method_node = handler->method_node;
891 gpe_event_info->flags &=
892 ~(ACPI_GPE_XRUPT_TYPE_MASK | ACPI_GPE_DISPATCH_MASK);
893 gpe_event_info->flags |= handler->original_flags;
896 * If the GPE was previously associated with a method and it was
897 * enabled, it should be enabled at this point to restore the
898 * post-initialization configuration.
901 if ((handler->original_flags & ACPI_GPE_DISPATCH_METHOD)
902 && handler->originally_enabled)
903 (void)acpi_ev_add_gpe_reference(gpe_event_info);
905 /* Now we can free the handler object */
910 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
912 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
913 return_ACPI_STATUS(status);
916 ACPI_EXPORT_SYMBOL(acpi_remove_gpe_handler)
918 /*******************************************************************************
920 * FUNCTION: acpi_acquire_global_lock
922 * PARAMETERS: Timeout - How long the caller is willing to wait
923 * Handle - Where the handle to the lock is returned
928 * DESCRIPTION: Acquire the ACPI Global Lock
930 * Note: Allows callers with the same thread ID to acquire the global lock
931 * multiple times. In other words, externally, the behavior of the global lock
932 * is identical to an AML mutex. On the first acquire, a new handle is
933 * returned. On any subsequent calls to acquire by the same thread, the same
934 * handle is returned.
936 ******************************************************************************/
937 acpi_status acpi_acquire_global_lock(u16 timeout, u32 * handle)
942 return (AE_BAD_PARAMETER);
945 /* Must lock interpreter to prevent race conditions */
947 acpi_ex_enter_interpreter();
949 status = acpi_ex_acquire_mutex_object(timeout,
950 acpi_gbl_global_lock_mutex,
951 acpi_os_get_thread_id());
953 if (ACPI_SUCCESS(status)) {
955 /* Return the global lock handle (updated in acpi_ev_acquire_global_lock) */
957 *handle = acpi_gbl_global_lock_handle;
960 acpi_ex_exit_interpreter();
964 ACPI_EXPORT_SYMBOL(acpi_acquire_global_lock)
966 /*******************************************************************************
968 * FUNCTION: acpi_release_global_lock
970 * PARAMETERS: Handle - Returned from acpi_acquire_global_lock
974 * DESCRIPTION: Release the ACPI Global Lock. The handle must be valid.
976 ******************************************************************************/
977 acpi_status acpi_release_global_lock(u32 handle)
981 if (!handle || (handle != acpi_gbl_global_lock_handle)) {
982 return (AE_NOT_ACQUIRED);
985 status = acpi_ex_release_mutex_object(acpi_gbl_global_lock_mutex);
989 ACPI_EXPORT_SYMBOL(acpi_release_global_lock)
990 #endif /* !ACPI_REDUCED_HARDWARE */