1 /******************************************************************************
3 * Module Name: evxface - External interfaces for ACPI events
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2016, 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
52 #define _COMPONENT ACPI_EVENTS
53 ACPI_MODULE_NAME ("evxface")
55 #if (!ACPI_REDUCED_HARDWARE)
57 /* Local prototypes */
60 AcpiEvInstallGpeHandler (
61 ACPI_HANDLE GpeDevice
,
65 ACPI_GPE_HANDLER Address
,
71 /*******************************************************************************
73 * FUNCTION: AcpiInstallNotifyHandler
75 * PARAMETERS: Device - The device for which notifies will be handled
76 * HandlerType - The type of handler:
77 * ACPI_SYSTEM_NOTIFY: System Handler (00-7F)
78 * ACPI_DEVICE_NOTIFY: Device Handler (80-FF)
79 * ACPI_ALL_NOTIFY: Both System and Device
80 * Handler - Address of the handler
81 * Context - Value passed to the handler on each GPE
85 * DESCRIPTION: Install a handler for notifications on an ACPI Device,
86 * ThermalZone, or Processor object.
88 * NOTES: The Root namespace object may have only one handler for each
89 * type of notify (System/Device). Device/Thermal/Processor objects
90 * may have one device notify handler, and multiple system notify
93 ******************************************************************************/
96 AcpiInstallNotifyHandler (
99 ACPI_NOTIFY_HANDLER Handler
,
102 ACPI_NAMESPACE_NODE
*Node
= ACPI_CAST_PTR (ACPI_NAMESPACE_NODE
, Device
);
103 ACPI_OPERAND_OBJECT
*ObjDesc
;
104 ACPI_OPERAND_OBJECT
*HandlerObj
;
109 ACPI_FUNCTION_TRACE (AcpiInstallNotifyHandler
);
112 /* Parameter validation */
114 if ((!Device
) || (!Handler
) || (!HandlerType
) ||
115 (HandlerType
> ACPI_MAX_NOTIFY_HANDLER_TYPE
))
117 return_ACPI_STATUS (AE_BAD_PARAMETER
);
120 Status
= AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE
);
121 if (ACPI_FAILURE (Status
))
123 return_ACPI_STATUS (Status
);
128 * Registering a notify handler on the root object indicates that the
129 * caller wishes to receive notifications for all objects. Note that
130 * only one global handler can be registered per notify type.
131 * Ensure that a handler is not already installed.
133 if (Device
== ACPI_ROOT_OBJECT
)
135 for (i
= 0; i
< ACPI_NUM_NOTIFY_TYPES
; i
++)
137 if (HandlerType
& (i
+1))
139 if (AcpiGbl_GlobalNotify
[i
].Handler
)
141 Status
= AE_ALREADY_EXISTS
;
145 AcpiGbl_GlobalNotify
[i
].Handler
= Handler
;
146 AcpiGbl_GlobalNotify
[i
].Context
= Context
;
150 goto UnlockAndExit
; /* Global notify handler installed, all done */
155 * Caller will only receive notifications specific to the target
156 * object. Note that only certain object types are allowed to
157 * receive notifications.
160 /* Are Notifies allowed on this object? */
162 if (!AcpiEvIsNotifyObject (Node
))
168 /* Check for an existing internal object, might not exist */
170 ObjDesc
= AcpiNsGetAttachedObject (Node
);
173 /* Create a new object */
175 ObjDesc
= AcpiUtCreateInternalObject (Node
->Type
);
178 Status
= AE_NO_MEMORY
;
182 /* Attach new object to the Node, remove local reference */
184 Status
= AcpiNsAttachObject (Device
, ObjDesc
, Node
->Type
);
185 AcpiUtRemoveReference (ObjDesc
);
186 if (ACPI_FAILURE (Status
))
192 /* Ensure that the handler is not already installed in the lists */
194 for (i
= 0; i
< ACPI_NUM_NOTIFY_TYPES
; i
++)
196 if (HandlerType
& (i
+1))
198 HandlerObj
= ObjDesc
->CommonNotify
.NotifyList
[i
];
201 if (HandlerObj
->Notify
.Handler
== Handler
)
203 Status
= AE_ALREADY_EXISTS
;
207 HandlerObj
= HandlerObj
->Notify
.Next
[i
];
212 /* Create and populate a new notify handler object */
214 HandlerObj
= AcpiUtCreateInternalObject (ACPI_TYPE_LOCAL_NOTIFY
);
217 Status
= AE_NO_MEMORY
;
221 HandlerObj
->Notify
.Node
= Node
;
222 HandlerObj
->Notify
.HandlerType
= HandlerType
;
223 HandlerObj
->Notify
.Handler
= Handler
;
224 HandlerObj
->Notify
.Context
= Context
;
226 /* Install the handler at the list head(s) */
228 for (i
= 0; i
< ACPI_NUM_NOTIFY_TYPES
; i
++)
230 if (HandlerType
& (i
+1))
232 HandlerObj
->Notify
.Next
[i
] =
233 ObjDesc
->CommonNotify
.NotifyList
[i
];
235 ObjDesc
->CommonNotify
.NotifyList
[i
] = HandlerObj
;
239 /* Add an extra reference if handler was installed in both lists */
241 if (HandlerType
== ACPI_ALL_NOTIFY
)
243 AcpiUtAddReference (HandlerObj
);
248 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE
);
249 return_ACPI_STATUS (Status
);
252 ACPI_EXPORT_SYMBOL (AcpiInstallNotifyHandler
)
255 /*******************************************************************************
257 * FUNCTION: AcpiRemoveNotifyHandler
259 * PARAMETERS: Device - The device for which the handler is installed
260 * HandlerType - The type of handler:
261 * ACPI_SYSTEM_NOTIFY: System Handler (00-7F)
262 * ACPI_DEVICE_NOTIFY: Device Handler (80-FF)
263 * ACPI_ALL_NOTIFY: Both System and Device
264 * Handler - Address of the handler
268 * DESCRIPTION: Remove a handler for notifies on an ACPI device
270 ******************************************************************************/
273 AcpiRemoveNotifyHandler (
276 ACPI_NOTIFY_HANDLER Handler
)
278 ACPI_NAMESPACE_NODE
*Node
= ACPI_CAST_PTR (ACPI_NAMESPACE_NODE
, Device
);
279 ACPI_OPERAND_OBJECT
*ObjDesc
;
280 ACPI_OPERAND_OBJECT
*HandlerObj
;
281 ACPI_OPERAND_OBJECT
*PreviousHandlerObj
;
282 ACPI_STATUS Status
= AE_OK
;
286 ACPI_FUNCTION_TRACE (AcpiRemoveNotifyHandler
);
289 /* Parameter validation */
291 if ((!Device
) || (!Handler
) || (!HandlerType
) ||
292 (HandlerType
> ACPI_MAX_NOTIFY_HANDLER_TYPE
))
294 return_ACPI_STATUS (AE_BAD_PARAMETER
);
297 /* Root Object. Global handlers are removed here */
299 if (Device
== ACPI_ROOT_OBJECT
)
301 for (i
= 0; i
< ACPI_NUM_NOTIFY_TYPES
; i
++)
303 if (HandlerType
& (i
+1))
305 Status
= AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE
);
306 if (ACPI_FAILURE (Status
))
308 return_ACPI_STATUS (Status
);
311 if (!AcpiGbl_GlobalNotify
[i
].Handler
||
312 (AcpiGbl_GlobalNotify
[i
].Handler
!= Handler
))
314 Status
= AE_NOT_EXIST
;
318 ACPI_DEBUG_PRINT ((ACPI_DB_INFO
,
319 "Removing global notify handler\n"));
321 AcpiGbl_GlobalNotify
[i
].Handler
= NULL
;
322 AcpiGbl_GlobalNotify
[i
].Context
= NULL
;
324 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE
);
326 /* Make sure all deferred notify tasks are completed */
328 AcpiOsWaitEventsComplete ();
332 return_ACPI_STATUS (AE_OK
);
335 /* All other objects: Are Notifies allowed on this object? */
337 if (!AcpiEvIsNotifyObject (Node
))
339 return_ACPI_STATUS (AE_TYPE
);
342 /* Must have an existing internal object */
344 ObjDesc
= AcpiNsGetAttachedObject (Node
);
347 return_ACPI_STATUS (AE_NOT_EXIST
);
350 /* Internal object exists. Find the handler and remove it */
352 for (i
= 0; i
< ACPI_NUM_NOTIFY_TYPES
; i
++)
354 if (HandlerType
& (i
+1))
356 Status
= AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE
);
357 if (ACPI_FAILURE (Status
))
359 return_ACPI_STATUS (Status
);
362 HandlerObj
= ObjDesc
->CommonNotify
.NotifyList
[i
];
363 PreviousHandlerObj
= NULL
;
365 /* Attempt to find the handler in the handler list */
368 (HandlerObj
->Notify
.Handler
!= Handler
))
370 PreviousHandlerObj
= HandlerObj
;
371 HandlerObj
= HandlerObj
->Notify
.Next
[i
];
376 Status
= AE_NOT_EXIST
;
380 /* Remove the handler object from the list */
382 if (PreviousHandlerObj
) /* Handler is not at the list head */
384 PreviousHandlerObj
->Notify
.Next
[i
] =
385 HandlerObj
->Notify
.Next
[i
];
387 else /* Handler is at the list head */
389 ObjDesc
->CommonNotify
.NotifyList
[i
] =
390 HandlerObj
->Notify
.Next
[i
];
393 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE
);
395 /* Make sure all deferred notify tasks are completed */
397 AcpiOsWaitEventsComplete ();
398 AcpiUtRemoveReference (HandlerObj
);
402 return_ACPI_STATUS (Status
);
406 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE
);
407 return_ACPI_STATUS (Status
);
410 ACPI_EXPORT_SYMBOL (AcpiRemoveNotifyHandler
)
413 /*******************************************************************************
415 * FUNCTION: AcpiInstallExceptionHandler
417 * PARAMETERS: Handler - Pointer to the handler function for the
422 * DESCRIPTION: Saves the pointer to the handler function
424 ******************************************************************************/
427 AcpiInstallExceptionHandler (
428 ACPI_EXCEPTION_HANDLER Handler
)
433 ACPI_FUNCTION_TRACE (AcpiInstallExceptionHandler
);
436 Status
= AcpiUtAcquireMutex (ACPI_MTX_EVENTS
);
437 if (ACPI_FAILURE (Status
))
439 return_ACPI_STATUS (Status
);
442 /* Don't allow two handlers. */
444 if (AcpiGbl_ExceptionHandler
)
446 Status
= AE_ALREADY_EXISTS
;
450 /* Install the handler */
452 AcpiGbl_ExceptionHandler
= Handler
;
455 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS
);
456 return_ACPI_STATUS (Status
);
459 ACPI_EXPORT_SYMBOL (AcpiInstallExceptionHandler
)
462 #if (!ACPI_REDUCED_HARDWARE)
463 /*******************************************************************************
465 * FUNCTION: AcpiInstallSciHandler
467 * PARAMETERS: Address - Address of the handler
468 * Context - Value passed to the handler on each SCI
472 * DESCRIPTION: Install a handler for a System Control Interrupt.
474 ******************************************************************************/
477 AcpiInstallSciHandler (
478 ACPI_SCI_HANDLER Address
,
481 ACPI_SCI_HANDLER_INFO
*NewSciHandler
;
482 ACPI_SCI_HANDLER_INFO
*SciHandler
;
483 ACPI_CPU_FLAGS Flags
;
487 ACPI_FUNCTION_TRACE (AcpiInstallSciHandler
);
492 return_ACPI_STATUS (AE_BAD_PARAMETER
);
495 /* Allocate and init a handler object */
497 NewSciHandler
= ACPI_ALLOCATE (sizeof (ACPI_SCI_HANDLER_INFO
));
500 return_ACPI_STATUS (AE_NO_MEMORY
);
503 NewSciHandler
->Address
= Address
;
504 NewSciHandler
->Context
= Context
;
506 Status
= AcpiUtAcquireMutex (ACPI_MTX_EVENTS
);
507 if (ACPI_FAILURE (Status
))
512 /* Lock list during installation */
514 Flags
= AcpiOsAcquireLock (AcpiGbl_GpeLock
);
515 SciHandler
= AcpiGbl_SciHandlerList
;
517 /* Ensure handler does not already exist */
521 if (Address
== SciHandler
->Address
)
523 Status
= AE_ALREADY_EXISTS
;
527 SciHandler
= SciHandler
->Next
;
530 /* Install the new handler into the global list (at head) */
532 NewSciHandler
->Next
= AcpiGbl_SciHandlerList
;
533 AcpiGbl_SciHandlerList
= NewSciHandler
;
538 AcpiOsReleaseLock (AcpiGbl_GpeLock
, Flags
);
539 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS
);
542 if (ACPI_FAILURE (Status
))
544 ACPI_FREE (NewSciHandler
);
546 return_ACPI_STATUS (Status
);
549 ACPI_EXPORT_SYMBOL (AcpiInstallSciHandler
)
552 /*******************************************************************************
554 * FUNCTION: AcpiRemoveSciHandler
556 * PARAMETERS: Address - Address of the handler
560 * DESCRIPTION: Remove a handler for a System Control Interrupt.
562 ******************************************************************************/
565 AcpiRemoveSciHandler (
566 ACPI_SCI_HANDLER Address
)
568 ACPI_SCI_HANDLER_INFO
*PrevSciHandler
;
569 ACPI_SCI_HANDLER_INFO
*NextSciHandler
;
570 ACPI_CPU_FLAGS Flags
;
574 ACPI_FUNCTION_TRACE (AcpiRemoveSciHandler
);
579 return_ACPI_STATUS (AE_BAD_PARAMETER
);
582 Status
= AcpiUtAcquireMutex (ACPI_MTX_EVENTS
);
583 if (ACPI_FAILURE (Status
))
585 return_ACPI_STATUS (Status
);
588 /* Remove the SCI handler with lock */
590 Flags
= AcpiOsAcquireLock (AcpiGbl_GpeLock
);
592 PrevSciHandler
= NULL
;
593 NextSciHandler
= AcpiGbl_SciHandlerList
;
594 while (NextSciHandler
)
596 if (NextSciHandler
->Address
== Address
)
598 /* Unlink and free the SCI handler info block */
602 PrevSciHandler
->Next
= NextSciHandler
->Next
;
606 AcpiGbl_SciHandlerList
= NextSciHandler
->Next
;
609 AcpiOsReleaseLock (AcpiGbl_GpeLock
, Flags
);
610 ACPI_FREE (NextSciHandler
);
614 PrevSciHandler
= NextSciHandler
;
615 NextSciHandler
= NextSciHandler
->Next
;
618 AcpiOsReleaseLock (AcpiGbl_GpeLock
, Flags
);
619 Status
= AE_NOT_EXIST
;
623 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS
);
624 return_ACPI_STATUS (Status
);
627 ACPI_EXPORT_SYMBOL (AcpiRemoveSciHandler
)
630 /*******************************************************************************
632 * FUNCTION: AcpiInstallGlobalEventHandler
634 * PARAMETERS: Handler - Pointer to the global event handler function
635 * Context - Value passed to the handler on each event
639 * DESCRIPTION: Saves the pointer to the handler function. The global handler
640 * is invoked upon each incoming GPE and Fixed Event. It is
641 * invoked at interrupt level at the time of the event dispatch.
642 * Can be used to update event counters, etc.
644 ******************************************************************************/
647 AcpiInstallGlobalEventHandler (
648 ACPI_GBL_EVENT_HANDLER Handler
,
654 ACPI_FUNCTION_TRACE (AcpiInstallGlobalEventHandler
);
657 /* Parameter validation */
661 return_ACPI_STATUS (AE_BAD_PARAMETER
);
664 Status
= AcpiUtAcquireMutex (ACPI_MTX_EVENTS
);
665 if (ACPI_FAILURE (Status
))
667 return_ACPI_STATUS (Status
);
670 /* Don't allow two handlers. */
672 if (AcpiGbl_GlobalEventHandler
)
674 Status
= AE_ALREADY_EXISTS
;
678 AcpiGbl_GlobalEventHandler
= Handler
;
679 AcpiGbl_GlobalEventHandlerContext
= Context
;
683 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS
);
684 return_ACPI_STATUS (Status
);
687 ACPI_EXPORT_SYMBOL (AcpiInstallGlobalEventHandler
)
690 /*******************************************************************************
692 * FUNCTION: AcpiInstallFixedEventHandler
694 * PARAMETERS: Event - Event type to enable.
695 * Handler - Pointer to the handler function for the
697 * Context - Value passed to the handler on each GPE
701 * DESCRIPTION: Saves the pointer to the handler function and then enables the
704 ******************************************************************************/
707 AcpiInstallFixedEventHandler (
709 ACPI_EVENT_HANDLER Handler
,
715 ACPI_FUNCTION_TRACE (AcpiInstallFixedEventHandler
);
718 /* Parameter validation */
720 if (Event
> ACPI_EVENT_MAX
)
722 return_ACPI_STATUS (AE_BAD_PARAMETER
);
725 Status
= AcpiUtAcquireMutex (ACPI_MTX_EVENTS
);
726 if (ACPI_FAILURE (Status
))
728 return_ACPI_STATUS (Status
);
731 /* Do not allow multiple handlers */
733 if (AcpiGbl_FixedEventHandlers
[Event
].Handler
)
735 Status
= AE_ALREADY_EXISTS
;
739 /* Install the handler before enabling the event */
741 AcpiGbl_FixedEventHandlers
[Event
].Handler
= Handler
;
742 AcpiGbl_FixedEventHandlers
[Event
].Context
= Context
;
744 Status
= AcpiEnableEvent (Event
, 0);
745 if (ACPI_FAILURE (Status
))
747 ACPI_WARNING ((AE_INFO
,
748 "Could not enable fixed event - %s (%u)",
749 AcpiUtGetEventName (Event
), Event
));
751 /* Remove the handler */
753 AcpiGbl_FixedEventHandlers
[Event
].Handler
= NULL
;
754 AcpiGbl_FixedEventHandlers
[Event
].Context
= NULL
;
758 ACPI_DEBUG_PRINT ((ACPI_DB_INFO
,
759 "Enabled fixed event %s (%X), Handler=%p\n",
760 AcpiUtGetEventName (Event
), Event
, Handler
));
765 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS
);
766 return_ACPI_STATUS (Status
);
769 ACPI_EXPORT_SYMBOL (AcpiInstallFixedEventHandler
)
772 /*******************************************************************************
774 * FUNCTION: AcpiRemoveFixedEventHandler
776 * PARAMETERS: Event - Event type to disable.
777 * Handler - Address of the handler
781 * DESCRIPTION: Disables the event and unregisters the event handler.
783 ******************************************************************************/
786 AcpiRemoveFixedEventHandler (
788 ACPI_EVENT_HANDLER Handler
)
790 ACPI_STATUS Status
= AE_OK
;
793 ACPI_FUNCTION_TRACE (AcpiRemoveFixedEventHandler
);
796 /* Parameter validation */
798 if (Event
> ACPI_EVENT_MAX
)
800 return_ACPI_STATUS (AE_BAD_PARAMETER
);
803 Status
= AcpiUtAcquireMutex (ACPI_MTX_EVENTS
);
804 if (ACPI_FAILURE (Status
))
806 return_ACPI_STATUS (Status
);
809 /* Disable the event before removing the handler */
811 Status
= AcpiDisableEvent (Event
, 0);
813 /* Always Remove the handler */
815 AcpiGbl_FixedEventHandlers
[Event
].Handler
= NULL
;
816 AcpiGbl_FixedEventHandlers
[Event
].Context
= NULL
;
818 if (ACPI_FAILURE (Status
))
820 ACPI_WARNING ((AE_INFO
,
821 "Could not disable fixed event - %s (%u)",
822 AcpiUtGetEventName (Event
), Event
));
826 ACPI_DEBUG_PRINT ((ACPI_DB_INFO
,
827 "Disabled fixed event - %s (%X)\n",
828 AcpiUtGetEventName (Event
), Event
));
831 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS
);
832 return_ACPI_STATUS (Status
);
835 ACPI_EXPORT_SYMBOL (AcpiRemoveFixedEventHandler
)
838 /*******************************************************************************
840 * FUNCTION: AcpiEvInstallGpeHandler
842 * PARAMETERS: GpeDevice - Namespace node for the GPE (NULL for FADT
844 * GpeNumber - The GPE number within the GPE block
845 * Type - Whether this GPE should be treated as an
846 * edge- or level-triggered interrupt.
847 * IsRawHandler - Whether this GPE should be handled using
848 * the special GPE handler mode.
849 * Address - Address of the handler
850 * Context - Value passed to the handler on each GPE
854 * DESCRIPTION: Internal function to install a handler for a General Purpose
857 ******************************************************************************/
860 AcpiEvInstallGpeHandler (
861 ACPI_HANDLE GpeDevice
,
864 BOOLEAN IsRawHandler
,
865 ACPI_GPE_HANDLER Address
,
868 ACPI_GPE_EVENT_INFO
*GpeEventInfo
;
869 ACPI_GPE_HANDLER_INFO
*Handler
;
871 ACPI_CPU_FLAGS Flags
;
874 ACPI_FUNCTION_TRACE (EvInstallGpeHandler
);
877 /* Parameter validation */
879 if ((!Address
) || (Type
& ~ACPI_GPE_XRUPT_TYPE_MASK
))
881 return_ACPI_STATUS (AE_BAD_PARAMETER
);
884 Status
= AcpiUtAcquireMutex (ACPI_MTX_EVENTS
);
885 if (ACPI_FAILURE (Status
))
887 return_ACPI_STATUS (Status
);
890 /* Allocate and init handler object (before lock) */
892 Handler
= ACPI_ALLOCATE_ZEROED (sizeof (ACPI_GPE_HANDLER_INFO
));
895 Status
= AE_NO_MEMORY
;
899 Flags
= AcpiOsAcquireLock (AcpiGbl_GpeLock
);
901 /* Ensure that we have a valid GPE number */
903 GpeEventInfo
= AcpiEvGetGpeEventInfo (GpeDevice
, GpeNumber
);
906 Status
= AE_BAD_PARAMETER
;
910 /* Make sure that there isn't a handler there already */
912 if ((ACPI_GPE_DISPATCH_TYPE (GpeEventInfo
->Flags
) ==
913 ACPI_GPE_DISPATCH_HANDLER
) ||
914 (ACPI_GPE_DISPATCH_TYPE (GpeEventInfo
->Flags
) ==
915 ACPI_GPE_DISPATCH_RAW_HANDLER
))
917 Status
= AE_ALREADY_EXISTS
;
921 Handler
->Address
= Address
;
922 Handler
->Context
= Context
;
923 Handler
->MethodNode
= GpeEventInfo
->Dispatch
.MethodNode
;
924 Handler
->OriginalFlags
= (UINT8
) (GpeEventInfo
->Flags
&
925 (ACPI_GPE_XRUPT_TYPE_MASK
| ACPI_GPE_DISPATCH_MASK
));
928 * If the GPE is associated with a method, it may have been enabled
929 * automatically during initialization, in which case it has to be
930 * disabled now to avoid spurious execution of the handler.
932 if (((ACPI_GPE_DISPATCH_TYPE (Handler
->OriginalFlags
) ==
933 ACPI_GPE_DISPATCH_METHOD
) ||
934 (ACPI_GPE_DISPATCH_TYPE (Handler
->OriginalFlags
) ==
935 ACPI_GPE_DISPATCH_NOTIFY
)) &&
936 GpeEventInfo
->RuntimeCount
)
938 Handler
->OriginallyEnabled
= TRUE
;
939 (void) AcpiEvRemoveGpeReference (GpeEventInfo
);
941 /* Sanity check of original type against new type */
943 if (Type
!= (UINT32
) (GpeEventInfo
->Flags
& ACPI_GPE_XRUPT_TYPE_MASK
))
945 ACPI_WARNING ((AE_INFO
, "GPE type mismatch (level/edge)"));
949 /* Install the handler */
951 GpeEventInfo
->Dispatch
.Handler
= Handler
;
953 /* Setup up dispatch flags to indicate handler (vs. method/notify) */
955 GpeEventInfo
->Flags
&= ~(ACPI_GPE_XRUPT_TYPE_MASK
| ACPI_GPE_DISPATCH_MASK
);
956 GpeEventInfo
->Flags
|= (UINT8
) (Type
| (IsRawHandler
?
957 ACPI_GPE_DISPATCH_RAW_HANDLER
: ACPI_GPE_DISPATCH_HANDLER
));
959 AcpiOsReleaseLock (AcpiGbl_GpeLock
, Flags
);
963 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS
);
964 return_ACPI_STATUS (Status
);
967 AcpiOsReleaseLock (AcpiGbl_GpeLock
, Flags
);
973 /*******************************************************************************
975 * FUNCTION: AcpiInstallGpeHandler
977 * PARAMETERS: GpeDevice - Namespace node for the GPE (NULL for FADT
979 * GpeNumber - The GPE number within the GPE block
980 * Type - Whether this GPE should be treated as an
981 * edge- or level-triggered interrupt.
982 * Address - Address of the handler
983 * Context - Value passed to the handler on each GPE
987 * DESCRIPTION: Install a handler for a General Purpose Event.
989 ******************************************************************************/
992 AcpiInstallGpeHandler (
993 ACPI_HANDLE GpeDevice
,
996 ACPI_GPE_HANDLER Address
,
1002 ACPI_FUNCTION_TRACE (AcpiInstallGpeHandler
);
1005 Status
= AcpiEvInstallGpeHandler (GpeDevice
, GpeNumber
, Type
,
1006 FALSE
, Address
, Context
);
1008 return_ACPI_STATUS (Status
);
1011 ACPI_EXPORT_SYMBOL (AcpiInstallGpeHandler
)
1014 /*******************************************************************************
1016 * FUNCTION: AcpiInstallGpeRawHandler
1018 * PARAMETERS: GpeDevice - Namespace node for the GPE (NULL for FADT
1020 * GpeNumber - The GPE number within the GPE block
1021 * Type - Whether this GPE should be treated as an
1022 * edge- or level-triggered interrupt.
1023 * Address - Address of the handler
1024 * Context - Value passed to the handler on each GPE
1028 * DESCRIPTION: Install a handler for a General Purpose Event.
1030 ******************************************************************************/
1033 AcpiInstallGpeRawHandler (
1034 ACPI_HANDLE GpeDevice
,
1037 ACPI_GPE_HANDLER Address
,
1043 ACPI_FUNCTION_TRACE (AcpiInstallGpeRawHandler
);
1046 Status
= AcpiEvInstallGpeHandler (GpeDevice
, GpeNumber
, Type
,
1047 TRUE
, Address
, Context
);
1049 return_ACPI_STATUS (Status
);
1052 ACPI_EXPORT_SYMBOL (AcpiInstallGpeRawHandler
)
1055 /*******************************************************************************
1057 * FUNCTION: AcpiRemoveGpeHandler
1059 * PARAMETERS: GpeDevice - Namespace node for the GPE (NULL for FADT
1061 * GpeNumber - The event to remove a handler
1062 * Address - Address of the handler
1066 * DESCRIPTION: Remove a handler for a General Purpose AcpiEvent.
1068 ******************************************************************************/
1071 AcpiRemoveGpeHandler (
1072 ACPI_HANDLE GpeDevice
,
1074 ACPI_GPE_HANDLER Address
)
1076 ACPI_GPE_EVENT_INFO
*GpeEventInfo
;
1077 ACPI_GPE_HANDLER_INFO
*Handler
;
1079 ACPI_CPU_FLAGS Flags
;
1082 ACPI_FUNCTION_TRACE (AcpiRemoveGpeHandler
);
1085 /* Parameter validation */
1089 return_ACPI_STATUS (AE_BAD_PARAMETER
);
1092 Status
= AcpiUtAcquireMutex (ACPI_MTX_EVENTS
);
1093 if (ACPI_FAILURE (Status
))
1095 return_ACPI_STATUS (Status
);
1098 Flags
= AcpiOsAcquireLock (AcpiGbl_GpeLock
);
1100 /* Ensure that we have a valid GPE number */
1102 GpeEventInfo
= AcpiEvGetGpeEventInfo (GpeDevice
, GpeNumber
);
1105 Status
= AE_BAD_PARAMETER
;
1109 /* Make sure that a handler is indeed installed */
1111 if ((ACPI_GPE_DISPATCH_TYPE (GpeEventInfo
->Flags
) !=
1112 ACPI_GPE_DISPATCH_HANDLER
) &&
1113 (ACPI_GPE_DISPATCH_TYPE (GpeEventInfo
->Flags
) !=
1114 ACPI_GPE_DISPATCH_RAW_HANDLER
))
1116 Status
= AE_NOT_EXIST
;
1120 /* Make sure that the installed handler is the same */
1122 if (GpeEventInfo
->Dispatch
.Handler
->Address
!= Address
)
1124 Status
= AE_BAD_PARAMETER
;
1128 /* Remove the handler */
1130 Handler
= GpeEventInfo
->Dispatch
.Handler
;
1131 GpeEventInfo
->Dispatch
.Handler
= NULL
;
1133 /* Restore Method node (if any), set dispatch flags */
1135 GpeEventInfo
->Dispatch
.MethodNode
= Handler
->MethodNode
;
1136 GpeEventInfo
->Flags
&=
1137 ~(ACPI_GPE_XRUPT_TYPE_MASK
| ACPI_GPE_DISPATCH_MASK
);
1138 GpeEventInfo
->Flags
|= Handler
->OriginalFlags
;
1141 * If the GPE was previously associated with a method and it was
1142 * enabled, it should be enabled at this point to restore the
1143 * post-initialization configuration.
1145 if (((ACPI_GPE_DISPATCH_TYPE (Handler
->OriginalFlags
) ==
1146 ACPI_GPE_DISPATCH_METHOD
) ||
1147 (ACPI_GPE_DISPATCH_TYPE (Handler
->OriginalFlags
) ==
1148 ACPI_GPE_DISPATCH_NOTIFY
)) &&
1149 Handler
->OriginallyEnabled
)
1151 (void) AcpiEvAddGpeReference (GpeEventInfo
);
1154 AcpiOsReleaseLock (AcpiGbl_GpeLock
, Flags
);
1155 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS
);
1157 /* Make sure all deferred GPE tasks are completed */
1159 AcpiOsWaitEventsComplete ();
1161 /* Now we can free the handler object */
1163 ACPI_FREE (Handler
);
1164 return_ACPI_STATUS (Status
);
1167 AcpiOsReleaseLock (AcpiGbl_GpeLock
, Flags
);
1168 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS
);
1169 return_ACPI_STATUS (Status
);
1172 ACPI_EXPORT_SYMBOL (AcpiRemoveGpeHandler
)
1175 /*******************************************************************************
1177 * FUNCTION: AcpiAcquireGlobalLock
1179 * PARAMETERS: Timeout - How long the caller is willing to wait
1180 * Handle - Where the handle to the lock is returned
1185 * DESCRIPTION: Acquire the ACPI Global Lock
1187 * Note: Allows callers with the same thread ID to acquire the global lock
1188 * multiple times. In other words, externally, the behavior of the global lock
1189 * is identical to an AML mutex. On the first acquire, a new handle is
1190 * returned. On any subsequent calls to acquire by the same thread, the same
1191 * handle is returned.
1193 ******************************************************************************/
1196 AcpiAcquireGlobalLock (
1205 return (AE_BAD_PARAMETER
);
1208 /* Must lock interpreter to prevent race conditions */
1210 AcpiExEnterInterpreter ();
1212 Status
= AcpiExAcquireMutexObject (Timeout
,
1213 AcpiGbl_GlobalLockMutex
, AcpiOsGetThreadId ());
1215 if (ACPI_SUCCESS (Status
))
1217 /* Return the global lock handle (updated in AcpiEvAcquireGlobalLock) */
1219 *Handle
= AcpiGbl_GlobalLockHandle
;
1222 AcpiExExitInterpreter ();
1226 ACPI_EXPORT_SYMBOL (AcpiAcquireGlobalLock
)
1229 /*******************************************************************************
1231 * FUNCTION: AcpiReleaseGlobalLock
1233 * PARAMETERS: Handle - Returned from AcpiAcquireGlobalLock
1237 * DESCRIPTION: Release the ACPI Global Lock. The handle must be valid.
1239 ******************************************************************************/
1242 AcpiReleaseGlobalLock (
1248 if (!Handle
|| (Handle
!= AcpiGbl_GlobalLockHandle
))
1250 return (AE_NOT_ACQUIRED
);
1253 Status
= AcpiExReleaseMutexObject (AcpiGbl_GlobalLockMutex
);
1257 ACPI_EXPORT_SYMBOL (AcpiReleaseGlobalLock
)
1259 #endif /* !ACPI_REDUCED_HARDWARE */