1 /******************************************************************************
3 * Module Name: evxface - External interfaces for ACPI events
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2013, 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.
46 #define EXPORT_ACPI_INTERFACES
54 #define _COMPONENT ACPI_EVENTS
55 ACPI_MODULE_NAME ("evxface")
58 /*******************************************************************************
60 * FUNCTION: AcpiInstallNotifyHandler
62 * PARAMETERS: Device - The device for which notifies will be handled
63 * HandlerType - The type of handler:
64 * ACPI_SYSTEM_NOTIFY: System Handler (00-7F)
65 * ACPI_DEVICE_NOTIFY: Device Handler (80-FF)
66 * ACPI_ALL_NOTIFY: Both System and Device
67 * Handler - Address of the handler
68 * Context - Value passed to the handler on each GPE
72 * DESCRIPTION: Install a handler for notifications on an ACPI Device,
73 * ThermalZone, or Processor object.
75 * NOTES: The Root namespace object may have only one handler for each
76 * type of notify (System/Device). Device/Thermal/Processor objects
77 * may have one device notify handler, and multiple system notify
80 ******************************************************************************/
83 AcpiInstallNotifyHandler (
86 ACPI_NOTIFY_HANDLER Handler
,
89 ACPI_NAMESPACE_NODE
*Node
= ACPI_CAST_PTR (ACPI_NAMESPACE_NODE
, Device
);
90 ACPI_OPERAND_OBJECT
*ObjDesc
;
91 ACPI_OPERAND_OBJECT
*HandlerObj
;
96 ACPI_FUNCTION_TRACE (AcpiInstallNotifyHandler
);
99 /* Parameter validation */
101 if ((!Device
) || (!Handler
) || (!HandlerType
) ||
102 (HandlerType
> ACPI_MAX_NOTIFY_HANDLER_TYPE
))
104 return_ACPI_STATUS (AE_BAD_PARAMETER
);
107 Status
= AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE
);
108 if (ACPI_FAILURE (Status
))
110 return_ACPI_STATUS (Status
);
115 * Registering a notify handler on the root object indicates that the
116 * caller wishes to receive notifications for all objects. Note that
117 * only one global handler can be registered per notify type.
118 * Ensure that a handler is not already installed.
120 if (Device
== ACPI_ROOT_OBJECT
)
122 for (i
= 0; i
< ACPI_NUM_NOTIFY_TYPES
; i
++)
124 if (HandlerType
& (i
+1))
126 if (AcpiGbl_GlobalNotify
[i
].Handler
)
128 Status
= AE_ALREADY_EXISTS
;
132 AcpiGbl_GlobalNotify
[i
].Handler
= Handler
;
133 AcpiGbl_GlobalNotify
[i
].Context
= Context
;
137 goto UnlockAndExit
; /* Global notify handler installed, all done */
142 * Caller will only receive notifications specific to the target
143 * object. Note that only certain object types are allowed to
144 * receive notifications.
147 /* Are Notifies allowed on this object? */
149 if (!AcpiEvIsNotifyObject (Node
))
155 /* Check for an existing internal object, might not exist */
157 ObjDesc
= AcpiNsGetAttachedObject (Node
);
160 /* Create a new object */
162 ObjDesc
= AcpiUtCreateInternalObject (Node
->Type
);
165 Status
= AE_NO_MEMORY
;
169 /* Attach new object to the Node, remove local reference */
171 Status
= AcpiNsAttachObject (Device
, ObjDesc
, Node
->Type
);
172 AcpiUtRemoveReference (ObjDesc
);
173 if (ACPI_FAILURE (Status
))
179 /* Ensure that the handler is not already installed in the lists */
181 for (i
= 0; i
< ACPI_NUM_NOTIFY_TYPES
; i
++)
183 if (HandlerType
& (i
+1))
185 HandlerObj
= ObjDesc
->CommonNotify
.NotifyList
[i
];
188 if (HandlerObj
->Notify
.Handler
== Handler
)
190 Status
= AE_ALREADY_EXISTS
;
194 HandlerObj
= HandlerObj
->Notify
.Next
[i
];
199 /* Create and populate a new notify handler object */
201 HandlerObj
= AcpiUtCreateInternalObject (ACPI_TYPE_LOCAL_NOTIFY
);
204 Status
= AE_NO_MEMORY
;
208 HandlerObj
->Notify
.Node
= Node
;
209 HandlerObj
->Notify
.HandlerType
= HandlerType
;
210 HandlerObj
->Notify
.Handler
= Handler
;
211 HandlerObj
->Notify
.Context
= Context
;
213 /* Install the handler at the list head(s) */
215 for (i
= 0; i
< ACPI_NUM_NOTIFY_TYPES
; i
++)
217 if (HandlerType
& (i
+1))
219 HandlerObj
->Notify
.Next
[i
] =
220 ObjDesc
->CommonNotify
.NotifyList
[i
];
222 ObjDesc
->CommonNotify
.NotifyList
[i
] = HandlerObj
;
226 /* Add an extra reference if handler was installed in both lists */
228 if (HandlerType
== ACPI_ALL_NOTIFY
)
230 AcpiUtAddReference (HandlerObj
);
235 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE
);
236 return_ACPI_STATUS (Status
);
239 ACPI_EXPORT_SYMBOL (AcpiInstallNotifyHandler
)
242 /*******************************************************************************
244 * FUNCTION: AcpiRemoveNotifyHandler
246 * PARAMETERS: Device - The device for which the handler is installed
247 * HandlerType - The type of handler:
248 * ACPI_SYSTEM_NOTIFY: System Handler (00-7F)
249 * ACPI_DEVICE_NOTIFY: Device Handler (80-FF)
250 * ACPI_ALL_NOTIFY: Both System and Device
251 * Handler - Address of the handler
255 * DESCRIPTION: Remove a handler for notifies on an ACPI device
257 ******************************************************************************/
260 AcpiRemoveNotifyHandler (
263 ACPI_NOTIFY_HANDLER Handler
)
265 ACPI_NAMESPACE_NODE
*Node
= ACPI_CAST_PTR (ACPI_NAMESPACE_NODE
, Device
);
266 ACPI_OPERAND_OBJECT
*ObjDesc
;
267 ACPI_OPERAND_OBJECT
*HandlerObj
;
268 ACPI_OPERAND_OBJECT
*PreviousHandlerObj
;
273 ACPI_FUNCTION_TRACE (AcpiRemoveNotifyHandler
);
276 /* Parameter validation */
278 if ((!Device
) || (!Handler
) || (!HandlerType
) ||
279 (HandlerType
> ACPI_MAX_NOTIFY_HANDLER_TYPE
))
281 return_ACPI_STATUS (AE_BAD_PARAMETER
);
284 /* Make sure all deferred notify tasks are completed */
286 AcpiOsWaitEventsComplete ();
288 Status
= AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE
);
289 if (ACPI_FAILURE (Status
))
291 return_ACPI_STATUS (Status
);
294 /* Root Object. Global handlers are removed here */
296 if (Device
== ACPI_ROOT_OBJECT
)
298 for (i
= 0; i
< ACPI_NUM_NOTIFY_TYPES
; i
++)
300 if (HandlerType
& (i
+1))
302 if (!AcpiGbl_GlobalNotify
[i
].Handler
||
303 (AcpiGbl_GlobalNotify
[i
].Handler
!= Handler
))
305 Status
= AE_NOT_EXIST
;
309 ACPI_DEBUG_PRINT ((ACPI_DB_INFO
,
310 "Removing global notify handler\n"));
312 AcpiGbl_GlobalNotify
[i
].Handler
= NULL
;
313 AcpiGbl_GlobalNotify
[i
].Context
= NULL
;
320 /* All other objects: Are Notifies allowed on this object? */
322 if (!AcpiEvIsNotifyObject (Node
))
328 /* Must have an existing internal object */
330 ObjDesc
= AcpiNsGetAttachedObject (Node
);
333 Status
= AE_NOT_EXIST
;
337 /* Internal object exists. Find the handler and remove it */
339 for (i
= 0; i
< ACPI_NUM_NOTIFY_TYPES
; i
++)
341 if (HandlerType
& (i
+1))
343 HandlerObj
= ObjDesc
->CommonNotify
.NotifyList
[i
];
344 PreviousHandlerObj
= NULL
;
346 /* Attempt to find the handler in the handler list */
349 (HandlerObj
->Notify
.Handler
!= Handler
))
351 PreviousHandlerObj
= HandlerObj
;
352 HandlerObj
= HandlerObj
->Notify
.Next
[i
];
357 Status
= AE_NOT_EXIST
;
361 /* Remove the handler object from the list */
363 if (PreviousHandlerObj
) /* Handler is not at the list head */
365 PreviousHandlerObj
->Notify
.Next
[i
] =
366 HandlerObj
->Notify
.Next
[i
];
368 else /* Handler is at the list head */
370 ObjDesc
->CommonNotify
.NotifyList
[i
] =
371 HandlerObj
->Notify
.Next
[i
];
374 AcpiUtRemoveReference (HandlerObj
);
380 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE
);
381 return_ACPI_STATUS (Status
);
384 ACPI_EXPORT_SYMBOL (AcpiRemoveNotifyHandler
)
387 /*******************************************************************************
389 * FUNCTION: AcpiInstallExceptionHandler
391 * PARAMETERS: Handler - Pointer to the handler function for the
396 * DESCRIPTION: Saves the pointer to the handler function
398 ******************************************************************************/
401 AcpiInstallExceptionHandler (
402 ACPI_EXCEPTION_HANDLER Handler
)
407 ACPI_FUNCTION_TRACE (AcpiInstallExceptionHandler
);
410 Status
= AcpiUtAcquireMutex (ACPI_MTX_EVENTS
);
411 if (ACPI_FAILURE (Status
))
413 return_ACPI_STATUS (Status
);
416 /* Don't allow two handlers. */
418 if (AcpiGbl_ExceptionHandler
)
420 Status
= AE_ALREADY_EXISTS
;
424 /* Install the handler */
426 AcpiGbl_ExceptionHandler
= Handler
;
429 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS
);
430 return_ACPI_STATUS (Status
);
433 ACPI_EXPORT_SYMBOL (AcpiInstallExceptionHandler
)
436 #if (!ACPI_REDUCED_HARDWARE)
437 /*******************************************************************************
439 * FUNCTION: AcpiInstallSciHandler
441 * PARAMETERS: Address - Address of the handler
442 * Context - Value passed to the handler on each SCI
446 * DESCRIPTION: Install a handler for a System Control Interrupt.
448 ******************************************************************************/
451 AcpiInstallSciHandler (
452 ACPI_SCI_HANDLER Address
,
455 ACPI_SCI_HANDLER_INFO
*NewSciHandler
;
456 ACPI_SCI_HANDLER_INFO
*SciHandler
;
457 ACPI_CPU_FLAGS Flags
;
461 ACPI_FUNCTION_TRACE (AcpiInstallSciHandler
);
466 return_ACPI_STATUS (AE_BAD_PARAMETER
);
469 /* Allocate and init a handler object */
471 NewSciHandler
= ACPI_ALLOCATE (sizeof (ACPI_SCI_HANDLER_INFO
));
474 return_ACPI_STATUS (AE_NO_MEMORY
);
477 NewSciHandler
->Address
= Address
;
478 NewSciHandler
->Context
= Context
;
480 Status
= AcpiUtAcquireMutex (ACPI_MTX_EVENTS
);
481 if (ACPI_FAILURE (Status
))
486 /* Lock list during installation */
488 Flags
= AcpiOsAcquireLock (AcpiGbl_GpeLock
);
489 SciHandler
= AcpiGbl_SciHandlerList
;
491 /* Ensure handler does not already exist */
495 if (Address
== SciHandler
->Address
)
497 Status
= AE_ALREADY_EXISTS
;
501 SciHandler
= SciHandler
->Next
;
504 /* Install the new handler into the global list (at head) */
506 NewSciHandler
->Next
= AcpiGbl_SciHandlerList
;
507 AcpiGbl_SciHandlerList
= NewSciHandler
;
512 AcpiOsReleaseLock (AcpiGbl_GpeLock
, Flags
);
513 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS
);
516 if (ACPI_FAILURE (Status
))
518 ACPI_FREE (NewSciHandler
);
520 return_ACPI_STATUS (Status
);
524 /*******************************************************************************
526 * FUNCTION: AcpiRemoveSciHandler
528 * PARAMETERS: Address - Address of the handler
532 * DESCRIPTION: Remove a handler for a System Control Interrupt.
534 ******************************************************************************/
537 AcpiRemoveSciHandler (
538 ACPI_SCI_HANDLER Address
)
540 ACPI_SCI_HANDLER_INFO
*PrevSciHandler
;
541 ACPI_SCI_HANDLER_INFO
*NextSciHandler
;
542 ACPI_CPU_FLAGS Flags
;
546 ACPI_FUNCTION_TRACE (AcpiRemoveSciHandler
);
551 return_ACPI_STATUS (AE_BAD_PARAMETER
);
554 Status
= AcpiUtAcquireMutex (ACPI_MTX_EVENTS
);
555 if (ACPI_FAILURE (Status
))
557 return_ACPI_STATUS (Status
);
560 /* Remove the SCI handler with lock */
562 Flags
= AcpiOsAcquireLock (AcpiGbl_GpeLock
);
564 PrevSciHandler
= NULL
;
565 NextSciHandler
= AcpiGbl_SciHandlerList
;
566 while (NextSciHandler
)
568 if (NextSciHandler
->Address
== Address
)
570 /* Unlink and free the SCI handler info block */
574 PrevSciHandler
->Next
= NextSciHandler
->Next
;
578 AcpiGbl_SciHandlerList
= NextSciHandler
->Next
;
581 AcpiOsReleaseLock (AcpiGbl_GpeLock
, Flags
);
582 ACPI_FREE (NextSciHandler
);
586 PrevSciHandler
= NextSciHandler
;
587 NextSciHandler
= NextSciHandler
->Next
;
590 AcpiOsReleaseLock (AcpiGbl_GpeLock
, Flags
);
591 Status
= AE_NOT_EXIST
;
595 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS
);
596 return_ACPI_STATUS (Status
);
600 /*******************************************************************************
602 * FUNCTION: AcpiInstallGlobalEventHandler
604 * PARAMETERS: Handler - Pointer to the global event handler function
605 * Context - Value passed to the handler on each event
609 * DESCRIPTION: Saves the pointer to the handler function. The global handler
610 * is invoked upon each incoming GPE and Fixed Event. It is
611 * invoked at interrupt level at the time of the event dispatch.
612 * Can be used to update event counters, etc.
614 ******************************************************************************/
617 AcpiInstallGlobalEventHandler (
618 ACPI_GBL_EVENT_HANDLER Handler
,
624 ACPI_FUNCTION_TRACE (AcpiInstallGlobalEventHandler
);
627 /* Parameter validation */
631 return_ACPI_STATUS (AE_BAD_PARAMETER
);
634 Status
= AcpiUtAcquireMutex (ACPI_MTX_EVENTS
);
635 if (ACPI_FAILURE (Status
))
637 return_ACPI_STATUS (Status
);
640 /* Don't allow two handlers. */
642 if (AcpiGbl_GlobalEventHandler
)
644 Status
= AE_ALREADY_EXISTS
;
648 AcpiGbl_GlobalEventHandler
= Handler
;
649 AcpiGbl_GlobalEventHandlerContext
= Context
;
653 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS
);
654 return_ACPI_STATUS (Status
);
657 ACPI_EXPORT_SYMBOL (AcpiInstallGlobalEventHandler
)
660 /*******************************************************************************
662 * FUNCTION: AcpiInstallFixedEventHandler
664 * PARAMETERS: Event - Event type to enable.
665 * Handler - Pointer to the handler function for the
667 * Context - Value passed to the handler on each GPE
671 * DESCRIPTION: Saves the pointer to the handler function and then enables the
674 ******************************************************************************/
677 AcpiInstallFixedEventHandler (
679 ACPI_EVENT_HANDLER Handler
,
685 ACPI_FUNCTION_TRACE (AcpiInstallFixedEventHandler
);
688 /* Parameter validation */
690 if (Event
> ACPI_EVENT_MAX
)
692 return_ACPI_STATUS (AE_BAD_PARAMETER
);
695 Status
= AcpiUtAcquireMutex (ACPI_MTX_EVENTS
);
696 if (ACPI_FAILURE (Status
))
698 return_ACPI_STATUS (Status
);
701 /* Do not allow multiple handlers */
703 if (AcpiGbl_FixedEventHandlers
[Event
].Handler
)
705 Status
= AE_ALREADY_EXISTS
;
709 /* Install the handler before enabling the event */
711 AcpiGbl_FixedEventHandlers
[Event
].Handler
= Handler
;
712 AcpiGbl_FixedEventHandlers
[Event
].Context
= Context
;
714 Status
= AcpiEnableEvent (Event
, 0);
715 if (ACPI_FAILURE (Status
))
717 ACPI_WARNING ((AE_INFO
,
718 "Could not enable fixed event - %s (%u)",
719 AcpiUtGetEventName (Event
), Event
));
721 /* Remove the handler */
723 AcpiGbl_FixedEventHandlers
[Event
].Handler
= NULL
;
724 AcpiGbl_FixedEventHandlers
[Event
].Context
= NULL
;
728 ACPI_DEBUG_PRINT ((ACPI_DB_INFO
,
729 "Enabled fixed event %s (%X), Handler=%p\n",
730 AcpiUtGetEventName (Event
), Event
, Handler
));
735 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS
);
736 return_ACPI_STATUS (Status
);
739 ACPI_EXPORT_SYMBOL (AcpiInstallFixedEventHandler
)
742 /*******************************************************************************
744 * FUNCTION: AcpiRemoveFixedEventHandler
746 * PARAMETERS: Event - Event type to disable.
747 * Handler - Address of the handler
751 * DESCRIPTION: Disables the event and unregisters the event handler.
753 ******************************************************************************/
756 AcpiRemoveFixedEventHandler (
758 ACPI_EVENT_HANDLER Handler
)
760 ACPI_STATUS Status
= AE_OK
;
763 ACPI_FUNCTION_TRACE (AcpiRemoveFixedEventHandler
);
766 /* Parameter validation */
768 if (Event
> ACPI_EVENT_MAX
)
770 return_ACPI_STATUS (AE_BAD_PARAMETER
);
773 Status
= AcpiUtAcquireMutex (ACPI_MTX_EVENTS
);
774 if (ACPI_FAILURE (Status
))
776 return_ACPI_STATUS (Status
);
779 /* Disable the event before removing the handler */
781 Status
= AcpiDisableEvent (Event
, 0);
783 /* Always Remove the handler */
785 AcpiGbl_FixedEventHandlers
[Event
].Handler
= NULL
;
786 AcpiGbl_FixedEventHandlers
[Event
].Context
= NULL
;
788 if (ACPI_FAILURE (Status
))
790 ACPI_WARNING ((AE_INFO
,
791 "Could not disable fixed event - %s (%u)",
792 AcpiUtGetEventName (Event
), Event
));
796 ACPI_DEBUG_PRINT ((ACPI_DB_INFO
,
797 "Disabled fixed event - %s (%X)\n",
798 AcpiUtGetEventName (Event
), Event
));
801 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS
);
802 return_ACPI_STATUS (Status
);
805 ACPI_EXPORT_SYMBOL (AcpiRemoveFixedEventHandler
)
808 /*******************************************************************************
810 * FUNCTION: AcpiInstallGpeHandler
812 * PARAMETERS: GpeDevice - Namespace node for the GPE (NULL for FADT
814 * GpeNumber - The GPE number within the GPE block
815 * Type - Whether this GPE should be treated as an
816 * edge- or level-triggered interrupt.
817 * Address - Address of the handler
818 * Context - Value passed to the handler on each GPE
822 * DESCRIPTION: Install a handler for a General Purpose Event.
824 ******************************************************************************/
827 AcpiInstallGpeHandler (
828 ACPI_HANDLE GpeDevice
,
831 ACPI_GPE_HANDLER Address
,
834 ACPI_GPE_EVENT_INFO
*GpeEventInfo
;
835 ACPI_GPE_HANDLER_INFO
*Handler
;
837 ACPI_CPU_FLAGS Flags
;
840 ACPI_FUNCTION_TRACE (AcpiInstallGpeHandler
);
843 /* Parameter validation */
845 if ((!Address
) || (Type
& ~ACPI_GPE_XRUPT_TYPE_MASK
))
847 return_ACPI_STATUS (AE_BAD_PARAMETER
);
850 Status
= AcpiUtAcquireMutex (ACPI_MTX_EVENTS
);
851 if (ACPI_FAILURE (Status
))
853 return_ACPI_STATUS (Status
);
856 /* Allocate and init handler object (before lock) */
858 Handler
= ACPI_ALLOCATE_ZEROED (sizeof (ACPI_GPE_HANDLER_INFO
));
861 Status
= AE_NO_MEMORY
;
865 Flags
= AcpiOsAcquireLock (AcpiGbl_GpeLock
);
867 /* Ensure that we have a valid GPE number */
869 GpeEventInfo
= AcpiEvGetGpeEventInfo (GpeDevice
, GpeNumber
);
872 Status
= AE_BAD_PARAMETER
;
876 /* Make sure that there isn't a handler there already */
878 if ((GpeEventInfo
->Flags
& ACPI_GPE_DISPATCH_MASK
) ==
879 ACPI_GPE_DISPATCH_HANDLER
)
881 Status
= AE_ALREADY_EXISTS
;
885 Handler
->Address
= Address
;
886 Handler
->Context
= Context
;
887 Handler
->MethodNode
= GpeEventInfo
->Dispatch
.MethodNode
;
888 Handler
->OriginalFlags
= (UINT8
) (GpeEventInfo
->Flags
&
889 (ACPI_GPE_XRUPT_TYPE_MASK
| ACPI_GPE_DISPATCH_MASK
));
892 * If the GPE is associated with a method, it may have been enabled
893 * automatically during initialization, in which case it has to be
894 * disabled now to avoid spurious execution of the handler.
896 if (((Handler
->OriginalFlags
& ACPI_GPE_DISPATCH_METHOD
) ||
897 (Handler
->OriginalFlags
& ACPI_GPE_DISPATCH_NOTIFY
)) &&
898 GpeEventInfo
->RuntimeCount
)
900 Handler
->OriginallyEnabled
= TRUE
;
901 (void) AcpiEvRemoveGpeReference (GpeEventInfo
);
903 /* Sanity check of original type against new type */
905 if (Type
!= (UINT32
) (GpeEventInfo
->Flags
& ACPI_GPE_XRUPT_TYPE_MASK
))
907 ACPI_WARNING ((AE_INFO
, "GPE type mismatch (level/edge)"));
911 /* Install the handler */
913 GpeEventInfo
->Dispatch
.Handler
= Handler
;
915 /* Setup up dispatch flags to indicate handler (vs. method/notify) */
917 GpeEventInfo
->Flags
&= ~(ACPI_GPE_XRUPT_TYPE_MASK
| ACPI_GPE_DISPATCH_MASK
);
918 GpeEventInfo
->Flags
|= (UINT8
) (Type
| ACPI_GPE_DISPATCH_HANDLER
);
920 AcpiOsReleaseLock (AcpiGbl_GpeLock
, Flags
);
924 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS
);
925 return_ACPI_STATUS (Status
);
928 AcpiOsReleaseLock (AcpiGbl_GpeLock
, Flags
);
933 ACPI_EXPORT_SYMBOL (AcpiInstallGpeHandler
)
936 /*******************************************************************************
938 * FUNCTION: AcpiRemoveGpeHandler
940 * PARAMETERS: GpeDevice - Namespace node for the GPE (NULL for FADT
942 * GpeNumber - The event to remove a handler
943 * Address - Address of the handler
947 * DESCRIPTION: Remove a handler for a General Purpose AcpiEvent.
949 ******************************************************************************/
952 AcpiRemoveGpeHandler (
953 ACPI_HANDLE GpeDevice
,
955 ACPI_GPE_HANDLER Address
)
957 ACPI_GPE_EVENT_INFO
*GpeEventInfo
;
958 ACPI_GPE_HANDLER_INFO
*Handler
;
960 ACPI_CPU_FLAGS Flags
;
963 ACPI_FUNCTION_TRACE (AcpiRemoveGpeHandler
);
966 /* Parameter validation */
970 return_ACPI_STATUS (AE_BAD_PARAMETER
);
973 /* Make sure all deferred GPE tasks are completed */
975 AcpiOsWaitEventsComplete ();
977 Status
= AcpiUtAcquireMutex (ACPI_MTX_EVENTS
);
978 if (ACPI_FAILURE (Status
))
980 return_ACPI_STATUS (Status
);
983 Flags
= AcpiOsAcquireLock (AcpiGbl_GpeLock
);
985 /* Ensure that we have a valid GPE number */
987 GpeEventInfo
= AcpiEvGetGpeEventInfo (GpeDevice
, GpeNumber
);
990 Status
= AE_BAD_PARAMETER
;
994 /* Make sure that a handler is indeed installed */
996 if ((GpeEventInfo
->Flags
& ACPI_GPE_DISPATCH_MASK
) !=
997 ACPI_GPE_DISPATCH_HANDLER
)
999 Status
= AE_NOT_EXIST
;
1003 /* Make sure that the installed handler is the same */
1005 if (GpeEventInfo
->Dispatch
.Handler
->Address
!= Address
)
1007 Status
= AE_BAD_PARAMETER
;
1011 /* Remove the handler */
1013 Handler
= GpeEventInfo
->Dispatch
.Handler
;
1015 /* Restore Method node (if any), set dispatch flags */
1017 GpeEventInfo
->Dispatch
.MethodNode
= Handler
->MethodNode
;
1018 GpeEventInfo
->Flags
&=
1019 ~(ACPI_GPE_XRUPT_TYPE_MASK
| ACPI_GPE_DISPATCH_MASK
);
1020 GpeEventInfo
->Flags
|= Handler
->OriginalFlags
;
1023 * If the GPE was previously associated with a method and it was
1024 * enabled, it should be enabled at this point to restore the
1025 * post-initialization configuration.
1027 if ((Handler
->OriginalFlags
& ACPI_GPE_DISPATCH_METHOD
) &&
1028 Handler
->OriginallyEnabled
)
1030 (void) AcpiEvAddGpeReference (GpeEventInfo
);
1033 /* Now we can free the handler object */
1035 ACPI_FREE (Handler
);
1039 AcpiOsReleaseLock (AcpiGbl_GpeLock
, Flags
);
1040 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS
);
1041 return_ACPI_STATUS (Status
);
1044 ACPI_EXPORT_SYMBOL (AcpiRemoveGpeHandler
)
1047 /*******************************************************************************
1049 * FUNCTION: AcpiAcquireGlobalLock
1051 * PARAMETERS: Timeout - How long the caller is willing to wait
1052 * Handle - Where the handle to the lock is returned
1057 * DESCRIPTION: Acquire the ACPI Global Lock
1059 * Note: Allows callers with the same thread ID to acquire the global lock
1060 * multiple times. In other words, externally, the behavior of the global lock
1061 * is identical to an AML mutex. On the first acquire, a new handle is
1062 * returned. On any subsequent calls to acquire by the same thread, the same
1063 * handle is returned.
1065 ******************************************************************************/
1068 AcpiAcquireGlobalLock (
1077 return (AE_BAD_PARAMETER
);
1080 /* Must lock interpreter to prevent race conditions */
1082 AcpiExEnterInterpreter ();
1084 Status
= AcpiExAcquireMutexObject (Timeout
,
1085 AcpiGbl_GlobalLockMutex
, AcpiOsGetThreadId ());
1087 if (ACPI_SUCCESS (Status
))
1089 /* Return the global lock handle (updated in AcpiEvAcquireGlobalLock) */
1091 *Handle
= AcpiGbl_GlobalLockHandle
;
1094 AcpiExExitInterpreter ();
1098 ACPI_EXPORT_SYMBOL (AcpiAcquireGlobalLock
)
1101 /*******************************************************************************
1103 * FUNCTION: AcpiReleaseGlobalLock
1105 * PARAMETERS: Handle - Returned from AcpiAcquireGlobalLock
1109 * DESCRIPTION: Release the ACPI Global Lock. The handle must be valid.
1111 ******************************************************************************/
1114 AcpiReleaseGlobalLock (
1120 if (!Handle
|| (Handle
!= AcpiGbl_GlobalLockHandle
))
1122 return (AE_NOT_ACQUIRED
);
1125 Status
= AcpiExReleaseMutexObject (AcpiGbl_GlobalLockMutex
);
1129 ACPI_EXPORT_SYMBOL (AcpiReleaseGlobalLock
)
1131 #endif /* !ACPI_REDUCED_HARDWARE */