1 /******************************************************************************
3 * Module Name: evxface - External interfaces for ACPI events
5 *****************************************************************************/
7 /******************************************************************************
11 * Some or all of this work - Copyright (c) 1999 - 2014, Intel Corp.
12 * All rights reserved.
16 * 2.1. This is your license from Intel Corp. under its intellectual property
17 * rights. You may have additional license terms from the party that provided
18 * you this software, covering your right to use that party's intellectual
21 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22 * copy of the source code appearing in this file ("Covered Code") an
23 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24 * base code distributed originally by Intel ("Original Intel Code") to copy,
25 * make derivatives, distribute, use and display any portion of the Covered
26 * Code in any form, with the right to sublicense such rights; and
28 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29 * license (with the right to sublicense), under only those claims of Intel
30 * patents that are infringed by the Original Intel Code, to make, use, sell,
31 * offer to sell, and import the Covered Code and derivative works thereof
32 * solely to the minimum extent necessary to exercise the above copyright
33 * license, and in no event shall the patent license extend to any additions
34 * to or modifications of the Original Intel Code. No other license or right
35 * is granted directly or by implication, estoppel or otherwise;
37 * The above copyright and patent license is granted only if the following
42 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43 * Redistribution of source code of any substantial portion of the Covered
44 * Code or modification with rights to further distribute source must include
45 * the above Copyright Notice, the above License, this list of Conditions,
46 * and the following Disclaimer and Export Compliance provision. In addition,
47 * Licensee must cause all Covered Code to which Licensee contributes to
48 * contain a file documenting the changes Licensee made to create that Covered
49 * Code and the date of any change. Licensee must include in that file the
50 * documentation of any changes made by any predecessor Licensee. Licensee
51 * must include a prominent statement that the modification is derived,
52 * directly or indirectly, from Original Intel Code.
54 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55 * Redistribution of source code of any substantial portion of the Covered
56 * Code or modification without rights to further distribute source must
57 * include the following Disclaimer and Export Compliance provision in the
58 * documentation and/or other materials provided with distribution. In
59 * addition, Licensee may not authorize further sublicense of source of any
60 * portion of the Covered Code, and must include terms to the effect that the
61 * license from Licensee to its licensee is limited to the intellectual
62 * property embodied in the software Licensee provides to its licensee, and
63 * not to intellectual property embodied in modifications its licensee may
66 * 3.3. Redistribution of Executable. Redistribution in executable form of any
67 * substantial portion of the Covered Code or modification must reproduce the
68 * above Copyright Notice, and the following Disclaimer and Export Compliance
69 * provision in the documentation and/or other materials provided with the
72 * 3.4. Intel retains all right, title, and interest in and to the Original
75 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76 * Intel shall be used in advertising or otherwise to promote the sale, use or
77 * other dealings in products derived from or relating to the Covered Code
78 * without prior written authorization from Intel.
80 * 4. Disclaimer and Export Compliance
82 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
90 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
99 * 4.3. Licensee shall not export, either directly or indirectly, any of this
100 * software or system incorporating such software without first obtaining any
101 * required license or other approval from the U. S. Department of Commerce or
102 * any other agency or department of the United States Government. In the
103 * event Licensee exports any such software from the United States or
104 * re-exports any such software from a foreign destination, Licensee shall
105 * ensure that the distribution and export/re-export of the software is in
106 * compliance with all laws, regulations, orders, or other restrictions of the
107 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108 * any of its subsidiaries will export/re-export any technical data, process,
109 * software, or service, directly or indirectly, to any country for which the
110 * United States government or any agency thereof requires an export license,
111 * other governmental approval, or letter of assurance, without first obtaining
112 * such license, approval or letter.
114 *****************************************************************************/
117 #define __EVXFACE_C__
118 #define EXPORT_ACPI_INTERFACES
121 #include "accommon.h"
122 #include "acnamesp.h"
123 #include "acevents.h"
124 #include "acinterp.h"
126 #define _COMPONENT ACPI_EVENTS
127 ACPI_MODULE_NAME ("evxface")
130 /*******************************************************************************
132 * FUNCTION: AcpiInstallNotifyHandler
134 * PARAMETERS: Device - The device for which notifies will be handled
135 * HandlerType - The type of handler:
136 * ACPI_SYSTEM_NOTIFY: System Handler (00-7F)
137 * ACPI_DEVICE_NOTIFY: Device Handler (80-FF)
138 * ACPI_ALL_NOTIFY: Both System and Device
139 * Handler - Address of the handler
140 * Context - Value passed to the handler on each GPE
144 * DESCRIPTION: Install a handler for notifications on an ACPI Device,
145 * ThermalZone, or Processor object.
147 * NOTES: The Root namespace object may have only one handler for each
148 * type of notify (System/Device). Device/Thermal/Processor objects
149 * may have one device notify handler, and multiple system notify
152 ******************************************************************************/
155 AcpiInstallNotifyHandler (
158 ACPI_NOTIFY_HANDLER Handler
,
161 ACPI_NAMESPACE_NODE
*Node
= ACPI_CAST_PTR (ACPI_NAMESPACE_NODE
, Device
);
162 ACPI_OPERAND_OBJECT
*ObjDesc
;
163 ACPI_OPERAND_OBJECT
*HandlerObj
;
168 ACPI_FUNCTION_TRACE (AcpiInstallNotifyHandler
);
171 /* Parameter validation */
173 if ((!Device
) || (!Handler
) || (!HandlerType
) ||
174 (HandlerType
> ACPI_MAX_NOTIFY_HANDLER_TYPE
))
176 return_ACPI_STATUS (AE_BAD_PARAMETER
);
179 Status
= AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE
);
180 if (ACPI_FAILURE (Status
))
182 return_ACPI_STATUS (Status
);
187 * Registering a notify handler on the root object indicates that the
188 * caller wishes to receive notifications for all objects. Note that
189 * only one global handler can be registered per notify type.
190 * Ensure that a handler is not already installed.
192 if (Device
== ACPI_ROOT_OBJECT
)
194 for (i
= 0; i
< ACPI_NUM_NOTIFY_TYPES
; i
++)
196 if (HandlerType
& (i
+1))
198 if (AcpiGbl_GlobalNotify
[i
].Handler
)
200 Status
= AE_ALREADY_EXISTS
;
204 AcpiGbl_GlobalNotify
[i
].Handler
= Handler
;
205 AcpiGbl_GlobalNotify
[i
].Context
= Context
;
209 goto UnlockAndExit
; /* Global notify handler installed, all done */
214 * Caller will only receive notifications specific to the target
215 * object. Note that only certain object types are allowed to
216 * receive notifications.
219 /* Are Notifies allowed on this object? */
221 if (!AcpiEvIsNotifyObject (Node
))
227 /* Check for an existing internal object, might not exist */
229 ObjDesc
= AcpiNsGetAttachedObject (Node
);
232 /* Create a new object */
234 ObjDesc
= AcpiUtCreateInternalObject (Node
->Type
);
237 Status
= AE_NO_MEMORY
;
241 /* Attach new object to the Node, remove local reference */
243 Status
= AcpiNsAttachObject (Device
, ObjDesc
, Node
->Type
);
244 AcpiUtRemoveReference (ObjDesc
);
245 if (ACPI_FAILURE (Status
))
251 /* Ensure that the handler is not already installed in the lists */
253 for (i
= 0; i
< ACPI_NUM_NOTIFY_TYPES
; i
++)
255 if (HandlerType
& (i
+1))
257 HandlerObj
= ObjDesc
->CommonNotify
.NotifyList
[i
];
260 if (HandlerObj
->Notify
.Handler
== Handler
)
262 Status
= AE_ALREADY_EXISTS
;
266 HandlerObj
= HandlerObj
->Notify
.Next
[i
];
271 /* Create and populate a new notify handler object */
273 HandlerObj
= AcpiUtCreateInternalObject (ACPI_TYPE_LOCAL_NOTIFY
);
276 Status
= AE_NO_MEMORY
;
280 HandlerObj
->Notify
.Node
= Node
;
281 HandlerObj
->Notify
.HandlerType
= HandlerType
;
282 HandlerObj
->Notify
.Handler
= Handler
;
283 HandlerObj
->Notify
.Context
= Context
;
285 /* Install the handler at the list head(s) */
287 for (i
= 0; i
< ACPI_NUM_NOTIFY_TYPES
; i
++)
289 if (HandlerType
& (i
+1))
291 HandlerObj
->Notify
.Next
[i
] =
292 ObjDesc
->CommonNotify
.NotifyList
[i
];
294 ObjDesc
->CommonNotify
.NotifyList
[i
] = HandlerObj
;
298 /* Add an extra reference if handler was installed in both lists */
300 if (HandlerType
== ACPI_ALL_NOTIFY
)
302 AcpiUtAddReference (HandlerObj
);
307 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE
);
308 return_ACPI_STATUS (Status
);
311 ACPI_EXPORT_SYMBOL (AcpiInstallNotifyHandler
)
314 /*******************************************************************************
316 * FUNCTION: AcpiRemoveNotifyHandler
318 * PARAMETERS: Device - The device for which the handler is installed
319 * HandlerType - The type of handler:
320 * ACPI_SYSTEM_NOTIFY: System Handler (00-7F)
321 * ACPI_DEVICE_NOTIFY: Device Handler (80-FF)
322 * ACPI_ALL_NOTIFY: Both System and Device
323 * Handler - Address of the handler
327 * DESCRIPTION: Remove a handler for notifies on an ACPI device
329 ******************************************************************************/
332 AcpiRemoveNotifyHandler (
335 ACPI_NOTIFY_HANDLER Handler
)
337 ACPI_NAMESPACE_NODE
*Node
= ACPI_CAST_PTR (ACPI_NAMESPACE_NODE
, Device
);
338 ACPI_OPERAND_OBJECT
*ObjDesc
;
339 ACPI_OPERAND_OBJECT
*HandlerObj
;
340 ACPI_OPERAND_OBJECT
*PreviousHandlerObj
;
341 ACPI_STATUS Status
= AE_OK
;
345 ACPI_FUNCTION_TRACE (AcpiRemoveNotifyHandler
);
348 /* Parameter validation */
350 if ((!Device
) || (!Handler
) || (!HandlerType
) ||
351 (HandlerType
> ACPI_MAX_NOTIFY_HANDLER_TYPE
))
353 return_ACPI_STATUS (AE_BAD_PARAMETER
);
356 /* Root Object. Global handlers are removed here */
358 if (Device
== ACPI_ROOT_OBJECT
)
360 for (i
= 0; i
< ACPI_NUM_NOTIFY_TYPES
; i
++)
362 if (HandlerType
& (i
+1))
364 Status
= AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE
);
365 if (ACPI_FAILURE (Status
))
367 return_ACPI_STATUS (Status
);
370 if (!AcpiGbl_GlobalNotify
[i
].Handler
||
371 (AcpiGbl_GlobalNotify
[i
].Handler
!= Handler
))
373 Status
= AE_NOT_EXIST
;
377 ACPI_DEBUG_PRINT ((ACPI_DB_INFO
,
378 "Removing global notify handler\n"));
380 AcpiGbl_GlobalNotify
[i
].Handler
= NULL
;
381 AcpiGbl_GlobalNotify
[i
].Context
= NULL
;
383 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE
);
385 /* Make sure all deferred notify tasks are completed */
387 AcpiOsWaitEventsComplete ();
391 return_ACPI_STATUS (AE_OK
);
394 /* All other objects: Are Notifies allowed on this object? */
396 if (!AcpiEvIsNotifyObject (Node
))
398 return_ACPI_STATUS (AE_TYPE
);
401 /* Must have an existing internal object */
403 ObjDesc
= AcpiNsGetAttachedObject (Node
);
406 return_ACPI_STATUS (AE_NOT_EXIST
);
409 /* Internal object exists. Find the handler and remove it */
411 for (i
= 0; i
< ACPI_NUM_NOTIFY_TYPES
; i
++)
413 if (HandlerType
& (i
+1))
415 Status
= AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE
);
416 if (ACPI_FAILURE (Status
))
418 return_ACPI_STATUS (Status
);
421 HandlerObj
= ObjDesc
->CommonNotify
.NotifyList
[i
];
422 PreviousHandlerObj
= NULL
;
424 /* Attempt to find the handler in the handler list */
427 (HandlerObj
->Notify
.Handler
!= Handler
))
429 PreviousHandlerObj
= HandlerObj
;
430 HandlerObj
= HandlerObj
->Notify
.Next
[i
];
435 Status
= AE_NOT_EXIST
;
439 /* Remove the handler object from the list */
441 if (PreviousHandlerObj
) /* Handler is not at the list head */
443 PreviousHandlerObj
->Notify
.Next
[i
] =
444 HandlerObj
->Notify
.Next
[i
];
446 else /* Handler is at the list head */
448 ObjDesc
->CommonNotify
.NotifyList
[i
] =
449 HandlerObj
->Notify
.Next
[i
];
452 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE
);
454 /* Make sure all deferred notify tasks are completed */
456 AcpiOsWaitEventsComplete ();
457 AcpiUtRemoveReference (HandlerObj
);
461 return_ACPI_STATUS (Status
);
465 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE
);
466 return_ACPI_STATUS (Status
);
469 ACPI_EXPORT_SYMBOL (AcpiRemoveNotifyHandler
)
472 /*******************************************************************************
474 * FUNCTION: AcpiInstallExceptionHandler
476 * PARAMETERS: Handler - Pointer to the handler function for the
481 * DESCRIPTION: Saves the pointer to the handler function
483 ******************************************************************************/
486 AcpiInstallExceptionHandler (
487 ACPI_EXCEPTION_HANDLER Handler
)
492 ACPI_FUNCTION_TRACE (AcpiInstallExceptionHandler
);
495 Status
= AcpiUtAcquireMutex (ACPI_MTX_EVENTS
);
496 if (ACPI_FAILURE (Status
))
498 return_ACPI_STATUS (Status
);
501 /* Don't allow two handlers. */
503 if (AcpiGbl_ExceptionHandler
)
505 Status
= AE_ALREADY_EXISTS
;
509 /* Install the handler */
511 AcpiGbl_ExceptionHandler
= Handler
;
514 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS
);
515 return_ACPI_STATUS (Status
);
518 ACPI_EXPORT_SYMBOL (AcpiInstallExceptionHandler
)
521 #if (!ACPI_REDUCED_HARDWARE)
522 /*******************************************************************************
524 * FUNCTION: AcpiInstallSciHandler
526 * PARAMETERS: Address - Address of the handler
527 * Context - Value passed to the handler on each SCI
531 * DESCRIPTION: Install a handler for a System Control Interrupt.
533 ******************************************************************************/
536 AcpiInstallSciHandler (
537 ACPI_SCI_HANDLER Address
,
540 ACPI_SCI_HANDLER_INFO
*NewSciHandler
;
541 ACPI_SCI_HANDLER_INFO
*SciHandler
;
542 ACPI_CPU_FLAGS Flags
;
546 ACPI_FUNCTION_TRACE (AcpiInstallSciHandler
);
551 return_ACPI_STATUS (AE_BAD_PARAMETER
);
554 /* Allocate and init a handler object */
556 NewSciHandler
= ACPI_ALLOCATE (sizeof (ACPI_SCI_HANDLER_INFO
));
559 return_ACPI_STATUS (AE_NO_MEMORY
);
562 NewSciHandler
->Address
= Address
;
563 NewSciHandler
->Context
= Context
;
565 Status
= AcpiUtAcquireMutex (ACPI_MTX_EVENTS
);
566 if (ACPI_FAILURE (Status
))
571 /* Lock list during installation */
573 Flags
= AcpiOsAcquireLock (AcpiGbl_GpeLock
);
574 SciHandler
= AcpiGbl_SciHandlerList
;
576 /* Ensure handler does not already exist */
580 if (Address
== SciHandler
->Address
)
582 Status
= AE_ALREADY_EXISTS
;
586 SciHandler
= SciHandler
->Next
;
589 /* Install the new handler into the global list (at head) */
591 NewSciHandler
->Next
= AcpiGbl_SciHandlerList
;
592 AcpiGbl_SciHandlerList
= NewSciHandler
;
597 AcpiOsReleaseLock (AcpiGbl_GpeLock
, Flags
);
598 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS
);
601 if (ACPI_FAILURE (Status
))
603 ACPI_FREE (NewSciHandler
);
605 return_ACPI_STATUS (Status
);
608 ACPI_EXPORT_SYMBOL (AcpiInstallSciHandler
)
611 /*******************************************************************************
613 * FUNCTION: AcpiRemoveSciHandler
615 * PARAMETERS: Address - Address of the handler
619 * DESCRIPTION: Remove a handler for a System Control Interrupt.
621 ******************************************************************************/
624 AcpiRemoveSciHandler (
625 ACPI_SCI_HANDLER Address
)
627 ACPI_SCI_HANDLER_INFO
*PrevSciHandler
;
628 ACPI_SCI_HANDLER_INFO
*NextSciHandler
;
629 ACPI_CPU_FLAGS Flags
;
633 ACPI_FUNCTION_TRACE (AcpiRemoveSciHandler
);
638 return_ACPI_STATUS (AE_BAD_PARAMETER
);
641 Status
= AcpiUtAcquireMutex (ACPI_MTX_EVENTS
);
642 if (ACPI_FAILURE (Status
))
644 return_ACPI_STATUS (Status
);
647 /* Remove the SCI handler with lock */
649 Flags
= AcpiOsAcquireLock (AcpiGbl_GpeLock
);
651 PrevSciHandler
= NULL
;
652 NextSciHandler
= AcpiGbl_SciHandlerList
;
653 while (NextSciHandler
)
655 if (NextSciHandler
->Address
== Address
)
657 /* Unlink and free the SCI handler info block */
661 PrevSciHandler
->Next
= NextSciHandler
->Next
;
665 AcpiGbl_SciHandlerList
= NextSciHandler
->Next
;
668 AcpiOsReleaseLock (AcpiGbl_GpeLock
, Flags
);
669 ACPI_FREE (NextSciHandler
);
673 PrevSciHandler
= NextSciHandler
;
674 NextSciHandler
= NextSciHandler
->Next
;
677 AcpiOsReleaseLock (AcpiGbl_GpeLock
, Flags
);
678 Status
= AE_NOT_EXIST
;
682 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS
);
683 return_ACPI_STATUS (Status
);
686 ACPI_EXPORT_SYMBOL (AcpiRemoveSciHandler
)
689 /*******************************************************************************
691 * FUNCTION: AcpiInstallGlobalEventHandler
693 * PARAMETERS: Handler - Pointer to the global event handler function
694 * Context - Value passed to the handler on each event
698 * DESCRIPTION: Saves the pointer to the handler function. The global handler
699 * is invoked upon each incoming GPE and Fixed Event. It is
700 * invoked at interrupt level at the time of the event dispatch.
701 * Can be used to update event counters, etc.
703 ******************************************************************************/
706 AcpiInstallGlobalEventHandler (
707 ACPI_GBL_EVENT_HANDLER Handler
,
713 ACPI_FUNCTION_TRACE (AcpiInstallGlobalEventHandler
);
716 /* Parameter validation */
720 return_ACPI_STATUS (AE_BAD_PARAMETER
);
723 Status
= AcpiUtAcquireMutex (ACPI_MTX_EVENTS
);
724 if (ACPI_FAILURE (Status
))
726 return_ACPI_STATUS (Status
);
729 /* Don't allow two handlers. */
731 if (AcpiGbl_GlobalEventHandler
)
733 Status
= AE_ALREADY_EXISTS
;
737 AcpiGbl_GlobalEventHandler
= Handler
;
738 AcpiGbl_GlobalEventHandlerContext
= Context
;
742 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS
);
743 return_ACPI_STATUS (Status
);
746 ACPI_EXPORT_SYMBOL (AcpiInstallGlobalEventHandler
)
749 /*******************************************************************************
751 * FUNCTION: AcpiInstallFixedEventHandler
753 * PARAMETERS: Event - Event type to enable.
754 * Handler - Pointer to the handler function for the
756 * Context - Value passed to the handler on each GPE
760 * DESCRIPTION: Saves the pointer to the handler function and then enables the
763 ******************************************************************************/
766 AcpiInstallFixedEventHandler (
768 ACPI_EVENT_HANDLER Handler
,
774 ACPI_FUNCTION_TRACE (AcpiInstallFixedEventHandler
);
777 /* Parameter validation */
779 if (Event
> ACPI_EVENT_MAX
)
781 return_ACPI_STATUS (AE_BAD_PARAMETER
);
784 Status
= AcpiUtAcquireMutex (ACPI_MTX_EVENTS
);
785 if (ACPI_FAILURE (Status
))
787 return_ACPI_STATUS (Status
);
790 /* Do not allow multiple handlers */
792 if (AcpiGbl_FixedEventHandlers
[Event
].Handler
)
794 Status
= AE_ALREADY_EXISTS
;
798 /* Install the handler before enabling the event */
800 AcpiGbl_FixedEventHandlers
[Event
].Handler
= Handler
;
801 AcpiGbl_FixedEventHandlers
[Event
].Context
= Context
;
803 Status
= AcpiEnableEvent (Event
, 0);
804 if (ACPI_FAILURE (Status
))
806 ACPI_WARNING ((AE_INFO
,
807 "Could not enable fixed event - %s (%u)",
808 AcpiUtGetEventName (Event
), Event
));
810 /* Remove the handler */
812 AcpiGbl_FixedEventHandlers
[Event
].Handler
= NULL
;
813 AcpiGbl_FixedEventHandlers
[Event
].Context
= NULL
;
817 ACPI_DEBUG_PRINT ((ACPI_DB_INFO
,
818 "Enabled fixed event %s (%X), Handler=%p\n",
819 AcpiUtGetEventName (Event
), Event
, Handler
));
824 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS
);
825 return_ACPI_STATUS (Status
);
828 ACPI_EXPORT_SYMBOL (AcpiInstallFixedEventHandler
)
831 /*******************************************************************************
833 * FUNCTION: AcpiRemoveFixedEventHandler
835 * PARAMETERS: Event - Event type to disable.
836 * Handler - Address of the handler
840 * DESCRIPTION: Disables the event and unregisters the event handler.
842 ******************************************************************************/
845 AcpiRemoveFixedEventHandler (
847 ACPI_EVENT_HANDLER Handler
)
849 ACPI_STATUS Status
= AE_OK
;
852 ACPI_FUNCTION_TRACE (AcpiRemoveFixedEventHandler
);
855 /* Parameter validation */
857 if (Event
> ACPI_EVENT_MAX
)
859 return_ACPI_STATUS (AE_BAD_PARAMETER
);
862 Status
= AcpiUtAcquireMutex (ACPI_MTX_EVENTS
);
863 if (ACPI_FAILURE (Status
))
865 return_ACPI_STATUS (Status
);
868 /* Disable the event before removing the handler */
870 Status
= AcpiDisableEvent (Event
, 0);
872 /* Always Remove the handler */
874 AcpiGbl_FixedEventHandlers
[Event
].Handler
= NULL
;
875 AcpiGbl_FixedEventHandlers
[Event
].Context
= NULL
;
877 if (ACPI_FAILURE (Status
))
879 ACPI_WARNING ((AE_INFO
,
880 "Could not disable fixed event - %s (%u)",
881 AcpiUtGetEventName (Event
), Event
));
885 ACPI_DEBUG_PRINT ((ACPI_DB_INFO
,
886 "Disabled fixed event - %s (%X)\n",
887 AcpiUtGetEventName (Event
), Event
));
890 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS
);
891 return_ACPI_STATUS (Status
);
894 ACPI_EXPORT_SYMBOL (AcpiRemoveFixedEventHandler
)
897 /*******************************************************************************
899 * FUNCTION: AcpiInstallGpeHandler
901 * PARAMETERS: GpeDevice - Namespace node for the GPE (NULL for FADT
903 * GpeNumber - The GPE number within the GPE block
904 * Type - Whether this GPE should be treated as an
905 * edge- or level-triggered interrupt.
906 * Address - Address of the handler
907 * Context - Value passed to the handler on each GPE
911 * DESCRIPTION: Install a handler for a General Purpose Event.
913 ******************************************************************************/
916 AcpiInstallGpeHandler (
917 ACPI_HANDLE GpeDevice
,
920 ACPI_GPE_HANDLER Address
,
923 ACPI_GPE_EVENT_INFO
*GpeEventInfo
;
924 ACPI_GPE_HANDLER_INFO
*Handler
;
926 ACPI_CPU_FLAGS Flags
;
929 ACPI_FUNCTION_TRACE (AcpiInstallGpeHandler
);
932 /* Parameter validation */
934 if ((!Address
) || (Type
& ~ACPI_GPE_XRUPT_TYPE_MASK
))
936 return_ACPI_STATUS (AE_BAD_PARAMETER
);
939 Status
= AcpiUtAcquireMutex (ACPI_MTX_EVENTS
);
940 if (ACPI_FAILURE (Status
))
942 return_ACPI_STATUS (Status
);
945 /* Allocate and init handler object (before lock) */
947 Handler
= ACPI_ALLOCATE_ZEROED (sizeof (ACPI_GPE_HANDLER_INFO
));
950 Status
= AE_NO_MEMORY
;
954 Flags
= AcpiOsAcquireLock (AcpiGbl_GpeLock
);
956 /* Ensure that we have a valid GPE number */
958 GpeEventInfo
= AcpiEvGetGpeEventInfo (GpeDevice
, GpeNumber
);
961 Status
= AE_BAD_PARAMETER
;
965 /* Make sure that there isn't a handler there already */
967 if ((GpeEventInfo
->Flags
& ACPI_GPE_DISPATCH_MASK
) ==
968 ACPI_GPE_DISPATCH_HANDLER
)
970 Status
= AE_ALREADY_EXISTS
;
974 Handler
->Address
= Address
;
975 Handler
->Context
= Context
;
976 Handler
->MethodNode
= GpeEventInfo
->Dispatch
.MethodNode
;
977 Handler
->OriginalFlags
= (UINT8
) (GpeEventInfo
->Flags
&
978 (ACPI_GPE_XRUPT_TYPE_MASK
| ACPI_GPE_DISPATCH_MASK
));
981 * If the GPE is associated with a method, it may have been enabled
982 * automatically during initialization, in which case it has to be
983 * disabled now to avoid spurious execution of the handler.
985 if (((Handler
->OriginalFlags
& ACPI_GPE_DISPATCH_METHOD
) ||
986 (Handler
->OriginalFlags
& ACPI_GPE_DISPATCH_NOTIFY
)) &&
987 GpeEventInfo
->RuntimeCount
)
989 Handler
->OriginallyEnabled
= TRUE
;
990 (void) AcpiEvRemoveGpeReference (GpeEventInfo
);
992 /* Sanity check of original type against new type */
994 if (Type
!= (UINT32
) (GpeEventInfo
->Flags
& ACPI_GPE_XRUPT_TYPE_MASK
))
996 ACPI_WARNING ((AE_INFO
, "GPE type mismatch (level/edge)"));
1000 /* Install the handler */
1002 GpeEventInfo
->Dispatch
.Handler
= Handler
;
1004 /* Setup up dispatch flags to indicate handler (vs. method/notify) */
1006 GpeEventInfo
->Flags
&= ~(ACPI_GPE_XRUPT_TYPE_MASK
| ACPI_GPE_DISPATCH_MASK
);
1007 GpeEventInfo
->Flags
|= (UINT8
) (Type
| ACPI_GPE_DISPATCH_HANDLER
);
1009 AcpiOsReleaseLock (AcpiGbl_GpeLock
, Flags
);
1013 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS
);
1014 return_ACPI_STATUS (Status
);
1017 AcpiOsReleaseLock (AcpiGbl_GpeLock
, Flags
);
1018 ACPI_FREE (Handler
);
1022 ACPI_EXPORT_SYMBOL (AcpiInstallGpeHandler
)
1025 /*******************************************************************************
1027 * FUNCTION: AcpiRemoveGpeHandler
1029 * PARAMETERS: GpeDevice - Namespace node for the GPE (NULL for FADT
1031 * GpeNumber - The event to remove a handler
1032 * Address - Address of the handler
1036 * DESCRIPTION: Remove a handler for a General Purpose AcpiEvent.
1038 ******************************************************************************/
1041 AcpiRemoveGpeHandler (
1042 ACPI_HANDLE GpeDevice
,
1044 ACPI_GPE_HANDLER Address
)
1046 ACPI_GPE_EVENT_INFO
*GpeEventInfo
;
1047 ACPI_GPE_HANDLER_INFO
*Handler
;
1049 ACPI_CPU_FLAGS Flags
;
1052 ACPI_FUNCTION_TRACE (AcpiRemoveGpeHandler
);
1055 /* Parameter validation */
1059 return_ACPI_STATUS (AE_BAD_PARAMETER
);
1062 Status
= AcpiUtAcquireMutex (ACPI_MTX_EVENTS
);
1063 if (ACPI_FAILURE (Status
))
1065 return_ACPI_STATUS (Status
);
1068 Flags
= AcpiOsAcquireLock (AcpiGbl_GpeLock
);
1070 /* Ensure that we have a valid GPE number */
1072 GpeEventInfo
= AcpiEvGetGpeEventInfo (GpeDevice
, GpeNumber
);
1075 Status
= AE_BAD_PARAMETER
;
1079 /* Make sure that a handler is indeed installed */
1081 if ((GpeEventInfo
->Flags
& ACPI_GPE_DISPATCH_MASK
) !=
1082 ACPI_GPE_DISPATCH_HANDLER
)
1084 Status
= AE_NOT_EXIST
;
1088 /* Make sure that the installed handler is the same */
1090 if (GpeEventInfo
->Dispatch
.Handler
->Address
!= Address
)
1092 Status
= AE_BAD_PARAMETER
;
1096 /* Remove the handler */
1098 Handler
= GpeEventInfo
->Dispatch
.Handler
;
1100 /* Restore Method node (if any), set dispatch flags */
1102 GpeEventInfo
->Dispatch
.MethodNode
= Handler
->MethodNode
;
1103 GpeEventInfo
->Flags
&=
1104 ~(ACPI_GPE_XRUPT_TYPE_MASK
| ACPI_GPE_DISPATCH_MASK
);
1105 GpeEventInfo
->Flags
|= Handler
->OriginalFlags
;
1108 * If the GPE was previously associated with a method and it was
1109 * enabled, it should be enabled at this point to restore the
1110 * post-initialization configuration.
1112 if ((Handler
->OriginalFlags
& ACPI_GPE_DISPATCH_METHOD
) &&
1113 Handler
->OriginallyEnabled
)
1115 (void) AcpiEvAddGpeReference (GpeEventInfo
);
1118 AcpiOsReleaseLock (AcpiGbl_GpeLock
, Flags
);
1119 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS
);
1121 /* Make sure all deferred GPE tasks are completed */
1123 AcpiOsWaitEventsComplete ();
1125 /* Now we can free the handler object */
1127 ACPI_FREE (Handler
);
1128 return_ACPI_STATUS (Status
);
1131 AcpiOsReleaseLock (AcpiGbl_GpeLock
, Flags
);
1132 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS
);
1133 return_ACPI_STATUS (Status
);
1136 ACPI_EXPORT_SYMBOL (AcpiRemoveGpeHandler
)
1139 /*******************************************************************************
1141 * FUNCTION: AcpiAcquireGlobalLock
1143 * PARAMETERS: Timeout - How long the caller is willing to wait
1144 * Handle - Where the handle to the lock is returned
1149 * DESCRIPTION: Acquire the ACPI Global Lock
1151 * Note: Allows callers with the same thread ID to acquire the global lock
1152 * multiple times. In other words, externally, the behavior of the global lock
1153 * is identical to an AML mutex. On the first acquire, a new handle is
1154 * returned. On any subsequent calls to acquire by the same thread, the same
1155 * handle is returned.
1157 ******************************************************************************/
1160 AcpiAcquireGlobalLock (
1169 return (AE_BAD_PARAMETER
);
1172 /* Must lock interpreter to prevent race conditions */
1174 AcpiExEnterInterpreter ();
1176 Status
= AcpiExAcquireMutexObject (Timeout
,
1177 AcpiGbl_GlobalLockMutex
, AcpiOsGetThreadId ());
1179 if (ACPI_SUCCESS (Status
))
1181 /* Return the global lock handle (updated in AcpiEvAcquireGlobalLock) */
1183 *Handle
= AcpiGbl_GlobalLockHandle
;
1186 AcpiExExitInterpreter ();
1190 ACPI_EXPORT_SYMBOL (AcpiAcquireGlobalLock
)
1193 /*******************************************************************************
1195 * FUNCTION: AcpiReleaseGlobalLock
1197 * PARAMETERS: Handle - Returned from AcpiAcquireGlobalLock
1201 * DESCRIPTION: Release the ACPI Global Lock. The handle must be valid.
1203 ******************************************************************************/
1206 AcpiReleaseGlobalLock (
1212 if (!Handle
|| (Handle
!= AcpiGbl_GlobalLockHandle
))
1214 return (AE_NOT_ACQUIRED
);
1217 Status
= AcpiExReleaseMutexObject (AcpiGbl_GlobalLockMutex
);
1221 ACPI_EXPORT_SYMBOL (AcpiReleaseGlobalLock
)
1223 #endif /* !ACPI_REDUCED_HARDWARE */