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 *****************************************************************************/
116 #define EXPORT_ACPI_INTERFACES
119 #include "accommon.h"
120 #include "acnamesp.h"
121 #include "acevents.h"
122 #include "acinterp.h"
124 #define _COMPONENT ACPI_EVENTS
125 ACPI_MODULE_NAME ("evxface")
128 /*******************************************************************************
130 * FUNCTION: AcpiInstallNotifyHandler
132 * PARAMETERS: Device - The device for which notifies will be handled
133 * HandlerType - The type of handler:
134 * ACPI_SYSTEM_NOTIFY: System Handler (00-7F)
135 * ACPI_DEVICE_NOTIFY: Device Handler (80-FF)
136 * ACPI_ALL_NOTIFY: Both System and Device
137 * Handler - Address of the handler
138 * Context - Value passed to the handler on each GPE
142 * DESCRIPTION: Install a handler for notifications on an ACPI Device,
143 * ThermalZone, or Processor object.
145 * NOTES: The Root namespace object may have only one handler for each
146 * type of notify (System/Device). Device/Thermal/Processor objects
147 * may have one device notify handler, and multiple system notify
150 ******************************************************************************/
153 AcpiInstallNotifyHandler (
156 ACPI_NOTIFY_HANDLER Handler
,
159 ACPI_NAMESPACE_NODE
*Node
= ACPI_CAST_PTR (ACPI_NAMESPACE_NODE
, Device
);
160 ACPI_OPERAND_OBJECT
*ObjDesc
;
161 ACPI_OPERAND_OBJECT
*HandlerObj
;
166 ACPI_FUNCTION_TRACE (AcpiInstallNotifyHandler
);
169 /* Parameter validation */
171 if ((!Device
) || (!Handler
) || (!HandlerType
) ||
172 (HandlerType
> ACPI_MAX_NOTIFY_HANDLER_TYPE
))
174 return_ACPI_STATUS (AE_BAD_PARAMETER
);
177 Status
= AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE
);
178 if (ACPI_FAILURE (Status
))
180 return_ACPI_STATUS (Status
);
185 * Registering a notify handler on the root object indicates that the
186 * caller wishes to receive notifications for all objects. Note that
187 * only one global handler can be registered per notify type.
188 * Ensure that a handler is not already installed.
190 if (Device
== ACPI_ROOT_OBJECT
)
192 for (i
= 0; i
< ACPI_NUM_NOTIFY_TYPES
; i
++)
194 if (HandlerType
& (i
+1))
196 if (AcpiGbl_GlobalNotify
[i
].Handler
)
198 Status
= AE_ALREADY_EXISTS
;
202 AcpiGbl_GlobalNotify
[i
].Handler
= Handler
;
203 AcpiGbl_GlobalNotify
[i
].Context
= Context
;
207 goto UnlockAndExit
; /* Global notify handler installed, all done */
212 * Caller will only receive notifications specific to the target
213 * object. Note that only certain object types are allowed to
214 * receive notifications.
217 /* Are Notifies allowed on this object? */
219 if (!AcpiEvIsNotifyObject (Node
))
225 /* Check for an existing internal object, might not exist */
227 ObjDesc
= AcpiNsGetAttachedObject (Node
);
230 /* Create a new object */
232 ObjDesc
= AcpiUtCreateInternalObject (Node
->Type
);
235 Status
= AE_NO_MEMORY
;
239 /* Attach new object to the Node, remove local reference */
241 Status
= AcpiNsAttachObject (Device
, ObjDesc
, Node
->Type
);
242 AcpiUtRemoveReference (ObjDesc
);
243 if (ACPI_FAILURE (Status
))
249 /* Ensure that the handler is not already installed in the lists */
251 for (i
= 0; i
< ACPI_NUM_NOTIFY_TYPES
; i
++)
253 if (HandlerType
& (i
+1))
255 HandlerObj
= ObjDesc
->CommonNotify
.NotifyList
[i
];
258 if (HandlerObj
->Notify
.Handler
== Handler
)
260 Status
= AE_ALREADY_EXISTS
;
264 HandlerObj
= HandlerObj
->Notify
.Next
[i
];
269 /* Create and populate a new notify handler object */
271 HandlerObj
= AcpiUtCreateInternalObject (ACPI_TYPE_LOCAL_NOTIFY
);
274 Status
= AE_NO_MEMORY
;
278 HandlerObj
->Notify
.Node
= Node
;
279 HandlerObj
->Notify
.HandlerType
= HandlerType
;
280 HandlerObj
->Notify
.Handler
= Handler
;
281 HandlerObj
->Notify
.Context
= Context
;
283 /* Install the handler at the list head(s) */
285 for (i
= 0; i
< ACPI_NUM_NOTIFY_TYPES
; i
++)
287 if (HandlerType
& (i
+1))
289 HandlerObj
->Notify
.Next
[i
] =
290 ObjDesc
->CommonNotify
.NotifyList
[i
];
292 ObjDesc
->CommonNotify
.NotifyList
[i
] = HandlerObj
;
296 /* Add an extra reference if handler was installed in both lists */
298 if (HandlerType
== ACPI_ALL_NOTIFY
)
300 AcpiUtAddReference (HandlerObj
);
305 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE
);
306 return_ACPI_STATUS (Status
);
309 ACPI_EXPORT_SYMBOL (AcpiInstallNotifyHandler
)
312 /*******************************************************************************
314 * FUNCTION: AcpiRemoveNotifyHandler
316 * PARAMETERS: Device - The device for which the handler is installed
317 * HandlerType - The type of handler:
318 * ACPI_SYSTEM_NOTIFY: System Handler (00-7F)
319 * ACPI_DEVICE_NOTIFY: Device Handler (80-FF)
320 * ACPI_ALL_NOTIFY: Both System and Device
321 * Handler - Address of the handler
325 * DESCRIPTION: Remove a handler for notifies on an ACPI device
327 ******************************************************************************/
330 AcpiRemoveNotifyHandler (
333 ACPI_NOTIFY_HANDLER Handler
)
335 ACPI_NAMESPACE_NODE
*Node
= ACPI_CAST_PTR (ACPI_NAMESPACE_NODE
, Device
);
336 ACPI_OPERAND_OBJECT
*ObjDesc
;
337 ACPI_OPERAND_OBJECT
*HandlerObj
;
338 ACPI_OPERAND_OBJECT
*PreviousHandlerObj
;
339 ACPI_STATUS Status
= AE_OK
;
343 ACPI_FUNCTION_TRACE (AcpiRemoveNotifyHandler
);
346 /* Parameter validation */
348 if ((!Device
) || (!Handler
) || (!HandlerType
) ||
349 (HandlerType
> ACPI_MAX_NOTIFY_HANDLER_TYPE
))
351 return_ACPI_STATUS (AE_BAD_PARAMETER
);
354 /* Root Object. Global handlers are removed here */
356 if (Device
== ACPI_ROOT_OBJECT
)
358 for (i
= 0; i
< ACPI_NUM_NOTIFY_TYPES
; i
++)
360 if (HandlerType
& (i
+1))
362 Status
= AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE
);
363 if (ACPI_FAILURE (Status
))
365 return_ACPI_STATUS (Status
);
368 if (!AcpiGbl_GlobalNotify
[i
].Handler
||
369 (AcpiGbl_GlobalNotify
[i
].Handler
!= Handler
))
371 Status
= AE_NOT_EXIST
;
375 ACPI_DEBUG_PRINT ((ACPI_DB_INFO
,
376 "Removing global notify handler\n"));
378 AcpiGbl_GlobalNotify
[i
].Handler
= NULL
;
379 AcpiGbl_GlobalNotify
[i
].Context
= NULL
;
381 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE
);
383 /* Make sure all deferred notify tasks are completed */
385 AcpiOsWaitEventsComplete ();
389 return_ACPI_STATUS (AE_OK
);
392 /* All other objects: Are Notifies allowed on this object? */
394 if (!AcpiEvIsNotifyObject (Node
))
396 return_ACPI_STATUS (AE_TYPE
);
399 /* Must have an existing internal object */
401 ObjDesc
= AcpiNsGetAttachedObject (Node
);
404 return_ACPI_STATUS (AE_NOT_EXIST
);
407 /* Internal object exists. Find the handler and remove it */
409 for (i
= 0; i
< ACPI_NUM_NOTIFY_TYPES
; i
++)
411 if (HandlerType
& (i
+1))
413 Status
= AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE
);
414 if (ACPI_FAILURE (Status
))
416 return_ACPI_STATUS (Status
);
419 HandlerObj
= ObjDesc
->CommonNotify
.NotifyList
[i
];
420 PreviousHandlerObj
= NULL
;
422 /* Attempt to find the handler in the handler list */
425 (HandlerObj
->Notify
.Handler
!= Handler
))
427 PreviousHandlerObj
= HandlerObj
;
428 HandlerObj
= HandlerObj
->Notify
.Next
[i
];
433 Status
= AE_NOT_EXIST
;
437 /* Remove the handler object from the list */
439 if (PreviousHandlerObj
) /* Handler is not at the list head */
441 PreviousHandlerObj
->Notify
.Next
[i
] =
442 HandlerObj
->Notify
.Next
[i
];
444 else /* Handler is at the list head */
446 ObjDesc
->CommonNotify
.NotifyList
[i
] =
447 HandlerObj
->Notify
.Next
[i
];
450 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE
);
452 /* Make sure all deferred notify tasks are completed */
454 AcpiOsWaitEventsComplete ();
455 AcpiUtRemoveReference (HandlerObj
);
459 return_ACPI_STATUS (Status
);
463 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE
);
464 return_ACPI_STATUS (Status
);
467 ACPI_EXPORT_SYMBOL (AcpiRemoveNotifyHandler
)
470 /*******************************************************************************
472 * FUNCTION: AcpiInstallExceptionHandler
474 * PARAMETERS: Handler - Pointer to the handler function for the
479 * DESCRIPTION: Saves the pointer to the handler function
481 ******************************************************************************/
484 AcpiInstallExceptionHandler (
485 ACPI_EXCEPTION_HANDLER Handler
)
490 ACPI_FUNCTION_TRACE (AcpiInstallExceptionHandler
);
493 Status
= AcpiUtAcquireMutex (ACPI_MTX_EVENTS
);
494 if (ACPI_FAILURE (Status
))
496 return_ACPI_STATUS (Status
);
499 /* Don't allow two handlers. */
501 if (AcpiGbl_ExceptionHandler
)
503 Status
= AE_ALREADY_EXISTS
;
507 /* Install the handler */
509 AcpiGbl_ExceptionHandler
= Handler
;
512 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS
);
513 return_ACPI_STATUS (Status
);
516 ACPI_EXPORT_SYMBOL (AcpiInstallExceptionHandler
)
519 #if (!ACPI_REDUCED_HARDWARE)
520 /*******************************************************************************
522 * FUNCTION: AcpiInstallSciHandler
524 * PARAMETERS: Address - Address of the handler
525 * Context - Value passed to the handler on each SCI
529 * DESCRIPTION: Install a handler for a System Control Interrupt.
531 ******************************************************************************/
534 AcpiInstallSciHandler (
535 ACPI_SCI_HANDLER Address
,
538 ACPI_SCI_HANDLER_INFO
*NewSciHandler
;
539 ACPI_SCI_HANDLER_INFO
*SciHandler
;
540 ACPI_CPU_FLAGS Flags
;
544 ACPI_FUNCTION_TRACE (AcpiInstallSciHandler
);
549 return_ACPI_STATUS (AE_BAD_PARAMETER
);
552 /* Allocate and init a handler object */
554 NewSciHandler
= ACPI_ALLOCATE (sizeof (ACPI_SCI_HANDLER_INFO
));
557 return_ACPI_STATUS (AE_NO_MEMORY
);
560 NewSciHandler
->Address
= Address
;
561 NewSciHandler
->Context
= Context
;
563 Status
= AcpiUtAcquireMutex (ACPI_MTX_EVENTS
);
564 if (ACPI_FAILURE (Status
))
569 /* Lock list during installation */
571 Flags
= AcpiOsAcquireLock (AcpiGbl_GpeLock
);
572 SciHandler
= AcpiGbl_SciHandlerList
;
574 /* Ensure handler does not already exist */
578 if (Address
== SciHandler
->Address
)
580 Status
= AE_ALREADY_EXISTS
;
584 SciHandler
= SciHandler
->Next
;
587 /* Install the new handler into the global list (at head) */
589 NewSciHandler
->Next
= AcpiGbl_SciHandlerList
;
590 AcpiGbl_SciHandlerList
= NewSciHandler
;
595 AcpiOsReleaseLock (AcpiGbl_GpeLock
, Flags
);
596 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS
);
599 if (ACPI_FAILURE (Status
))
601 ACPI_FREE (NewSciHandler
);
603 return_ACPI_STATUS (Status
);
606 ACPI_EXPORT_SYMBOL (AcpiInstallSciHandler
)
609 /*******************************************************************************
611 * FUNCTION: AcpiRemoveSciHandler
613 * PARAMETERS: Address - Address of the handler
617 * DESCRIPTION: Remove a handler for a System Control Interrupt.
619 ******************************************************************************/
622 AcpiRemoveSciHandler (
623 ACPI_SCI_HANDLER Address
)
625 ACPI_SCI_HANDLER_INFO
*PrevSciHandler
;
626 ACPI_SCI_HANDLER_INFO
*NextSciHandler
;
627 ACPI_CPU_FLAGS Flags
;
631 ACPI_FUNCTION_TRACE (AcpiRemoveSciHandler
);
636 return_ACPI_STATUS (AE_BAD_PARAMETER
);
639 Status
= AcpiUtAcquireMutex (ACPI_MTX_EVENTS
);
640 if (ACPI_FAILURE (Status
))
642 return_ACPI_STATUS (Status
);
645 /* Remove the SCI handler with lock */
647 Flags
= AcpiOsAcquireLock (AcpiGbl_GpeLock
);
649 PrevSciHandler
= NULL
;
650 NextSciHandler
= AcpiGbl_SciHandlerList
;
651 while (NextSciHandler
)
653 if (NextSciHandler
->Address
== Address
)
655 /* Unlink and free the SCI handler info block */
659 PrevSciHandler
->Next
= NextSciHandler
->Next
;
663 AcpiGbl_SciHandlerList
= NextSciHandler
->Next
;
666 AcpiOsReleaseLock (AcpiGbl_GpeLock
, Flags
);
667 ACPI_FREE (NextSciHandler
);
671 PrevSciHandler
= NextSciHandler
;
672 NextSciHandler
= NextSciHandler
->Next
;
675 AcpiOsReleaseLock (AcpiGbl_GpeLock
, Flags
);
676 Status
= AE_NOT_EXIST
;
680 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS
);
681 return_ACPI_STATUS (Status
);
684 ACPI_EXPORT_SYMBOL (AcpiRemoveSciHandler
)
687 /*******************************************************************************
689 * FUNCTION: AcpiInstallGlobalEventHandler
691 * PARAMETERS: Handler - Pointer to the global event handler function
692 * Context - Value passed to the handler on each event
696 * DESCRIPTION: Saves the pointer to the handler function. The global handler
697 * is invoked upon each incoming GPE and Fixed Event. It is
698 * invoked at interrupt level at the time of the event dispatch.
699 * Can be used to update event counters, etc.
701 ******************************************************************************/
704 AcpiInstallGlobalEventHandler (
705 ACPI_GBL_EVENT_HANDLER Handler
,
711 ACPI_FUNCTION_TRACE (AcpiInstallGlobalEventHandler
);
714 /* Parameter validation */
718 return_ACPI_STATUS (AE_BAD_PARAMETER
);
721 Status
= AcpiUtAcquireMutex (ACPI_MTX_EVENTS
);
722 if (ACPI_FAILURE (Status
))
724 return_ACPI_STATUS (Status
);
727 /* Don't allow two handlers. */
729 if (AcpiGbl_GlobalEventHandler
)
731 Status
= AE_ALREADY_EXISTS
;
735 AcpiGbl_GlobalEventHandler
= Handler
;
736 AcpiGbl_GlobalEventHandlerContext
= Context
;
740 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS
);
741 return_ACPI_STATUS (Status
);
744 ACPI_EXPORT_SYMBOL (AcpiInstallGlobalEventHandler
)
747 /*******************************************************************************
749 * FUNCTION: AcpiInstallFixedEventHandler
751 * PARAMETERS: Event - Event type to enable.
752 * Handler - Pointer to the handler function for the
754 * Context - Value passed to the handler on each GPE
758 * DESCRIPTION: Saves the pointer to the handler function and then enables the
761 ******************************************************************************/
764 AcpiInstallFixedEventHandler (
766 ACPI_EVENT_HANDLER Handler
,
772 ACPI_FUNCTION_TRACE (AcpiInstallFixedEventHandler
);
775 /* Parameter validation */
777 if (Event
> ACPI_EVENT_MAX
)
779 return_ACPI_STATUS (AE_BAD_PARAMETER
);
782 Status
= AcpiUtAcquireMutex (ACPI_MTX_EVENTS
);
783 if (ACPI_FAILURE (Status
))
785 return_ACPI_STATUS (Status
);
788 /* Do not allow multiple handlers */
790 if (AcpiGbl_FixedEventHandlers
[Event
].Handler
)
792 Status
= AE_ALREADY_EXISTS
;
796 /* Install the handler before enabling the event */
798 AcpiGbl_FixedEventHandlers
[Event
].Handler
= Handler
;
799 AcpiGbl_FixedEventHandlers
[Event
].Context
= Context
;
801 Status
= AcpiEnableEvent (Event
, 0);
802 if (ACPI_FAILURE (Status
))
804 ACPI_WARNING ((AE_INFO
,
805 "Could not enable fixed event - %s (%u)",
806 AcpiUtGetEventName (Event
), Event
));
808 /* Remove the handler */
810 AcpiGbl_FixedEventHandlers
[Event
].Handler
= NULL
;
811 AcpiGbl_FixedEventHandlers
[Event
].Context
= NULL
;
815 ACPI_DEBUG_PRINT ((ACPI_DB_INFO
,
816 "Enabled fixed event %s (%X), Handler=%p\n",
817 AcpiUtGetEventName (Event
), Event
, Handler
));
822 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS
);
823 return_ACPI_STATUS (Status
);
826 ACPI_EXPORT_SYMBOL (AcpiInstallFixedEventHandler
)
829 /*******************************************************************************
831 * FUNCTION: AcpiRemoveFixedEventHandler
833 * PARAMETERS: Event - Event type to disable.
834 * Handler - Address of the handler
838 * DESCRIPTION: Disables the event and unregisters the event handler.
840 ******************************************************************************/
843 AcpiRemoveFixedEventHandler (
845 ACPI_EVENT_HANDLER Handler
)
847 ACPI_STATUS Status
= AE_OK
;
850 ACPI_FUNCTION_TRACE (AcpiRemoveFixedEventHandler
);
853 /* Parameter validation */
855 if (Event
> ACPI_EVENT_MAX
)
857 return_ACPI_STATUS (AE_BAD_PARAMETER
);
860 Status
= AcpiUtAcquireMutex (ACPI_MTX_EVENTS
);
861 if (ACPI_FAILURE (Status
))
863 return_ACPI_STATUS (Status
);
866 /* Disable the event before removing the handler */
868 Status
= AcpiDisableEvent (Event
, 0);
870 /* Always Remove the handler */
872 AcpiGbl_FixedEventHandlers
[Event
].Handler
= NULL
;
873 AcpiGbl_FixedEventHandlers
[Event
].Context
= NULL
;
875 if (ACPI_FAILURE (Status
))
877 ACPI_WARNING ((AE_INFO
,
878 "Could not disable fixed event - %s (%u)",
879 AcpiUtGetEventName (Event
), Event
));
883 ACPI_DEBUG_PRINT ((ACPI_DB_INFO
,
884 "Disabled fixed event - %s (%X)\n",
885 AcpiUtGetEventName (Event
), Event
));
888 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS
);
889 return_ACPI_STATUS (Status
);
892 ACPI_EXPORT_SYMBOL (AcpiRemoveFixedEventHandler
)
895 /*******************************************************************************
897 * FUNCTION: AcpiInstallGpeHandler
899 * PARAMETERS: GpeDevice - Namespace node for the GPE (NULL for FADT
901 * GpeNumber - The GPE number within the GPE block
902 * Type - Whether this GPE should be treated as an
903 * edge- or level-triggered interrupt.
904 * Address - Address of the handler
905 * Context - Value passed to the handler on each GPE
909 * DESCRIPTION: Install a handler for a General Purpose Event.
911 ******************************************************************************/
914 AcpiInstallGpeHandler (
915 ACPI_HANDLE GpeDevice
,
918 ACPI_GPE_HANDLER Address
,
921 ACPI_GPE_EVENT_INFO
*GpeEventInfo
;
922 ACPI_GPE_HANDLER_INFO
*Handler
;
924 ACPI_CPU_FLAGS Flags
;
927 ACPI_FUNCTION_TRACE (AcpiInstallGpeHandler
);
930 /* Parameter validation */
932 if ((!Address
) || (Type
& ~ACPI_GPE_XRUPT_TYPE_MASK
))
934 return_ACPI_STATUS (AE_BAD_PARAMETER
);
937 Status
= AcpiUtAcquireMutex (ACPI_MTX_EVENTS
);
938 if (ACPI_FAILURE (Status
))
940 return_ACPI_STATUS (Status
);
943 /* Allocate and init handler object (before lock) */
945 Handler
= ACPI_ALLOCATE_ZEROED (sizeof (ACPI_GPE_HANDLER_INFO
));
948 Status
= AE_NO_MEMORY
;
952 Flags
= AcpiOsAcquireLock (AcpiGbl_GpeLock
);
954 /* Ensure that we have a valid GPE number */
956 GpeEventInfo
= AcpiEvGetGpeEventInfo (GpeDevice
, GpeNumber
);
959 Status
= AE_BAD_PARAMETER
;
963 /* Make sure that there isn't a handler there already */
965 if ((GpeEventInfo
->Flags
& ACPI_GPE_DISPATCH_MASK
) ==
966 ACPI_GPE_DISPATCH_HANDLER
)
968 Status
= AE_ALREADY_EXISTS
;
972 Handler
->Address
= Address
;
973 Handler
->Context
= Context
;
974 Handler
->MethodNode
= GpeEventInfo
->Dispatch
.MethodNode
;
975 Handler
->OriginalFlags
= (UINT8
) (GpeEventInfo
->Flags
&
976 (ACPI_GPE_XRUPT_TYPE_MASK
| ACPI_GPE_DISPATCH_MASK
));
979 * If the GPE is associated with a method, it may have been enabled
980 * automatically during initialization, in which case it has to be
981 * disabled now to avoid spurious execution of the handler.
983 if (((Handler
->OriginalFlags
& ACPI_GPE_DISPATCH_METHOD
) ||
984 (Handler
->OriginalFlags
& ACPI_GPE_DISPATCH_NOTIFY
)) &&
985 GpeEventInfo
->RuntimeCount
)
987 Handler
->OriginallyEnabled
= TRUE
;
988 (void) AcpiEvRemoveGpeReference (GpeEventInfo
);
990 /* Sanity check of original type against new type */
992 if (Type
!= (UINT32
) (GpeEventInfo
->Flags
& ACPI_GPE_XRUPT_TYPE_MASK
))
994 ACPI_WARNING ((AE_INFO
, "GPE type mismatch (level/edge)"));
998 /* Install the handler */
1000 GpeEventInfo
->Dispatch
.Handler
= Handler
;
1002 /* Setup up dispatch flags to indicate handler (vs. method/notify) */
1004 GpeEventInfo
->Flags
&= ~(ACPI_GPE_XRUPT_TYPE_MASK
| ACPI_GPE_DISPATCH_MASK
);
1005 GpeEventInfo
->Flags
|= (UINT8
) (Type
| ACPI_GPE_DISPATCH_HANDLER
);
1007 AcpiOsReleaseLock (AcpiGbl_GpeLock
, Flags
);
1011 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS
);
1012 return_ACPI_STATUS (Status
);
1015 AcpiOsReleaseLock (AcpiGbl_GpeLock
, Flags
);
1016 ACPI_FREE (Handler
);
1020 ACPI_EXPORT_SYMBOL (AcpiInstallGpeHandler
)
1023 /*******************************************************************************
1025 * FUNCTION: AcpiRemoveGpeHandler
1027 * PARAMETERS: GpeDevice - Namespace node for the GPE (NULL for FADT
1029 * GpeNumber - The event to remove a handler
1030 * Address - Address of the handler
1034 * DESCRIPTION: Remove a handler for a General Purpose AcpiEvent.
1036 ******************************************************************************/
1039 AcpiRemoveGpeHandler (
1040 ACPI_HANDLE GpeDevice
,
1042 ACPI_GPE_HANDLER Address
)
1044 ACPI_GPE_EVENT_INFO
*GpeEventInfo
;
1045 ACPI_GPE_HANDLER_INFO
*Handler
;
1047 ACPI_CPU_FLAGS Flags
;
1050 ACPI_FUNCTION_TRACE (AcpiRemoveGpeHandler
);
1053 /* Parameter validation */
1057 return_ACPI_STATUS (AE_BAD_PARAMETER
);
1060 Status
= AcpiUtAcquireMutex (ACPI_MTX_EVENTS
);
1061 if (ACPI_FAILURE (Status
))
1063 return_ACPI_STATUS (Status
);
1066 Flags
= AcpiOsAcquireLock (AcpiGbl_GpeLock
);
1068 /* Ensure that we have a valid GPE number */
1070 GpeEventInfo
= AcpiEvGetGpeEventInfo (GpeDevice
, GpeNumber
);
1073 Status
= AE_BAD_PARAMETER
;
1077 /* Make sure that a handler is indeed installed */
1079 if ((GpeEventInfo
->Flags
& ACPI_GPE_DISPATCH_MASK
) !=
1080 ACPI_GPE_DISPATCH_HANDLER
)
1082 Status
= AE_NOT_EXIST
;
1086 /* Make sure that the installed handler is the same */
1088 if (GpeEventInfo
->Dispatch
.Handler
->Address
!= Address
)
1090 Status
= AE_BAD_PARAMETER
;
1094 /* Remove the handler */
1096 Handler
= GpeEventInfo
->Dispatch
.Handler
;
1098 /* Restore Method node (if any), set dispatch flags */
1100 GpeEventInfo
->Dispatch
.MethodNode
= Handler
->MethodNode
;
1101 GpeEventInfo
->Flags
&=
1102 ~(ACPI_GPE_XRUPT_TYPE_MASK
| ACPI_GPE_DISPATCH_MASK
);
1103 GpeEventInfo
->Flags
|= Handler
->OriginalFlags
;
1106 * If the GPE was previously associated with a method and it was
1107 * enabled, it should be enabled at this point to restore the
1108 * post-initialization configuration.
1110 if (((Handler
->OriginalFlags
& ACPI_GPE_DISPATCH_METHOD
) ||
1111 (Handler
->OriginalFlags
& ACPI_GPE_DISPATCH_NOTIFY
)) &&
1112 Handler
->OriginallyEnabled
)
1114 (void) AcpiEvAddGpeReference (GpeEventInfo
);
1117 AcpiOsReleaseLock (AcpiGbl_GpeLock
, Flags
);
1118 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS
);
1120 /* Make sure all deferred GPE tasks are completed */
1122 AcpiOsWaitEventsComplete ();
1124 /* Now we can free the handler object */
1126 ACPI_FREE (Handler
);
1127 return_ACPI_STATUS (Status
);
1130 AcpiOsReleaseLock (AcpiGbl_GpeLock
, Flags
);
1131 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS
);
1132 return_ACPI_STATUS (Status
);
1135 ACPI_EXPORT_SYMBOL (AcpiRemoveGpeHandler
)
1138 /*******************************************************************************
1140 * FUNCTION: AcpiAcquireGlobalLock
1142 * PARAMETERS: Timeout - How long the caller is willing to wait
1143 * Handle - Where the handle to the lock is returned
1148 * DESCRIPTION: Acquire the ACPI Global Lock
1150 * Note: Allows callers with the same thread ID to acquire the global lock
1151 * multiple times. In other words, externally, the behavior of the global lock
1152 * is identical to an AML mutex. On the first acquire, a new handle is
1153 * returned. On any subsequent calls to acquire by the same thread, the same
1154 * handle is returned.
1156 ******************************************************************************/
1159 AcpiAcquireGlobalLock (
1168 return (AE_BAD_PARAMETER
);
1171 /* Must lock interpreter to prevent race conditions */
1173 AcpiExEnterInterpreter ();
1175 Status
= AcpiExAcquireMutexObject (Timeout
,
1176 AcpiGbl_GlobalLockMutex
, AcpiOsGetThreadId ());
1178 if (ACPI_SUCCESS (Status
))
1180 /* Return the global lock handle (updated in AcpiEvAcquireGlobalLock) */
1182 *Handle
= AcpiGbl_GlobalLockHandle
;
1185 AcpiExExitInterpreter ();
1189 ACPI_EXPORT_SYMBOL (AcpiAcquireGlobalLock
)
1192 /*******************************************************************************
1194 * FUNCTION: AcpiReleaseGlobalLock
1196 * PARAMETERS: Handle - Returned from AcpiAcquireGlobalLock
1200 * DESCRIPTION: Release the ACPI Global Lock. The handle must be valid.
1202 ******************************************************************************/
1205 AcpiReleaseGlobalLock (
1211 if (!Handle
|| (Handle
!= AcpiGbl_GlobalLockHandle
))
1213 return (AE_NOT_ACQUIRED
);
1216 Status
= AcpiExReleaseMutexObject (AcpiGbl_GlobalLockMutex
);
1220 ACPI_EXPORT_SYMBOL (AcpiReleaseGlobalLock
)
1222 #endif /* !ACPI_REDUCED_HARDWARE */