1 /******************************************************************************
3 * Module Name: evxface - External interfaces for ACPI events
5 *****************************************************************************/
7 /******************************************************************************
11 * Some or all of this work - Copyright (c) 1999 - 2012, 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__
120 #include "accommon.h"
121 #include "acnamesp.h"
122 #include "acevents.h"
123 #include "acinterp.h"
125 #define _COMPONENT ACPI_EVENTS
126 ACPI_MODULE_NAME ("evxface")
129 /*******************************************************************************
131 * FUNCTION: AcpiInstallNotifyHandler
133 * PARAMETERS: Device - The device for which notifies will be handled
134 * HandlerType - The type of handler:
135 * ACPI_SYSTEM_NOTIFY: System Handler (00-7F)
136 * ACPI_DEVICE_NOTIFY: Device Handler (80-FF)
137 * ACPI_ALL_NOTIFY: Both System and Device
138 * Handler - Address of the handler
139 * Context - Value passed to the handler on each GPE
143 * DESCRIPTION: Install a handler for notifications on an ACPI Device,
144 * ThermalZone, or Processor object.
146 * NOTES: The Root namespace object may have only one handler for each
147 * type of notify (System/Device). Device/Thermal/Processor objects
148 * may have one device notify handler, and multiple system notify
151 ******************************************************************************/
154 AcpiInstallNotifyHandler (
157 ACPI_NOTIFY_HANDLER Handler
,
160 ACPI_NAMESPACE_NODE
*Node
= ACPI_CAST_PTR (ACPI_NAMESPACE_NODE
, Device
);
161 ACPI_OPERAND_OBJECT
*ObjDesc
;
162 ACPI_OPERAND_OBJECT
*HandlerObj
;
167 ACPI_FUNCTION_TRACE (AcpiInstallNotifyHandler
);
170 /* Parameter validation */
172 if ((!Device
) || (!Handler
) || (!HandlerType
) ||
173 (HandlerType
> ACPI_MAX_NOTIFY_HANDLER_TYPE
))
175 return_ACPI_STATUS (AE_BAD_PARAMETER
);
178 Status
= AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE
);
179 if (ACPI_FAILURE (Status
))
181 return_ACPI_STATUS (Status
);
186 * Registering a notify handler on the root object indicates that the
187 * caller wishes to receive notifications for all objects. Note that
188 * only one global handler can be registered per notify type.
189 * Ensure that a handler is not already installed.
191 if (Device
== ACPI_ROOT_OBJECT
)
193 for (i
= 0; i
< ACPI_NUM_NOTIFY_TYPES
; i
++)
195 if (HandlerType
& (i
+1))
197 if (AcpiGbl_GlobalNotify
[i
].Handler
)
199 Status
= AE_ALREADY_EXISTS
;
203 AcpiGbl_GlobalNotify
[i
].Handler
= Handler
;
204 AcpiGbl_GlobalNotify
[i
].Context
= Context
;
208 goto UnlockAndExit
; /* Global notify handler installed, all done */
213 * Caller will only receive notifications specific to the target
214 * object. Note that only certain object types are allowed to
215 * receive notifications.
218 /* Are Notifies allowed on this object? */
220 if (!AcpiEvIsNotifyObject (Node
))
226 /* Check for an existing internal object, might not exist */
228 ObjDesc
= AcpiNsGetAttachedObject (Node
);
231 /* Create a new object */
233 ObjDesc
= AcpiUtCreateInternalObject (Node
->Type
);
236 Status
= AE_NO_MEMORY
;
240 /* Attach new object to the Node, remove local reference */
242 Status
= AcpiNsAttachObject (Device
, ObjDesc
, Node
->Type
);
243 AcpiUtRemoveReference (ObjDesc
);
244 if (ACPI_FAILURE (Status
))
250 /* Ensure that the handler is not already installed in the lists */
252 for (i
= 0; i
< ACPI_NUM_NOTIFY_TYPES
; i
++)
254 if (HandlerType
& (i
+1))
256 HandlerObj
= ObjDesc
->CommonNotify
.NotifyList
[i
];
259 if (HandlerObj
->Notify
.Handler
== Handler
)
261 Status
= AE_ALREADY_EXISTS
;
265 HandlerObj
= HandlerObj
->Notify
.Next
[i
];
270 /* Create and populate a new notify handler object */
272 HandlerObj
= AcpiUtCreateInternalObject (ACPI_TYPE_LOCAL_NOTIFY
);
275 Status
= AE_NO_MEMORY
;
279 HandlerObj
->Notify
.Node
= Node
;
280 HandlerObj
->Notify
.HandlerType
= HandlerType
;
281 HandlerObj
->Notify
.Handler
= Handler
;
282 HandlerObj
->Notify
.Context
= Context
;
284 /* Install the handler at the list head(s) */
286 for (i
= 0; i
< ACPI_NUM_NOTIFY_TYPES
; i
++)
288 if (HandlerType
& (i
+1))
290 HandlerObj
->Notify
.Next
[i
] =
291 ObjDesc
->CommonNotify
.NotifyList
[i
];
293 ObjDesc
->CommonNotify
.NotifyList
[i
] = HandlerObj
;
297 /* Add an extra reference if handler was installed in both lists */
299 if (HandlerType
== ACPI_ALL_NOTIFY
)
301 AcpiUtAddReference (HandlerObj
);
306 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE
);
307 return_ACPI_STATUS (Status
);
310 ACPI_EXPORT_SYMBOL (AcpiInstallNotifyHandler
)
313 /*******************************************************************************
315 * FUNCTION: AcpiRemoveNotifyHandler
317 * PARAMETERS: Device - The device for which the handler is installed
318 * HandlerType - The type of handler:
319 * ACPI_SYSTEM_NOTIFY: System Handler (00-7F)
320 * ACPI_DEVICE_NOTIFY: Device Handler (80-FF)
321 * ACPI_ALL_NOTIFY: Both System and Device
322 * Handler - Address of the handler
326 * DESCRIPTION: Remove a handler for notifies on an ACPI device
328 ******************************************************************************/
331 AcpiRemoveNotifyHandler (
334 ACPI_NOTIFY_HANDLER Handler
)
336 ACPI_NAMESPACE_NODE
*Node
= ACPI_CAST_PTR (ACPI_NAMESPACE_NODE
, Device
);
337 ACPI_OPERAND_OBJECT
*ObjDesc
;
338 ACPI_OPERAND_OBJECT
*HandlerObj
;
339 ACPI_OPERAND_OBJECT
*PreviousHandlerObj
;
344 ACPI_FUNCTION_TRACE (AcpiRemoveNotifyHandler
);
347 /* Parameter validation */
349 if ((!Device
) || (!Handler
) || (!HandlerType
) ||
350 (HandlerType
> ACPI_MAX_NOTIFY_HANDLER_TYPE
))
352 return_ACPI_STATUS (AE_BAD_PARAMETER
);
355 /* Make sure all deferred notify tasks are completed */
357 AcpiOsWaitEventsComplete ();
359 Status
= AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE
);
360 if (ACPI_FAILURE (Status
))
362 return_ACPI_STATUS (Status
);
365 /* Root Object. Global handlers are removed here */
367 if (Device
== ACPI_ROOT_OBJECT
)
369 for (i
= 0; i
< ACPI_NUM_NOTIFY_TYPES
; i
++)
371 if (HandlerType
& (i
+1))
373 if (!AcpiGbl_GlobalNotify
[i
].Handler
||
374 (AcpiGbl_GlobalNotify
[i
].Handler
!= Handler
))
376 Status
= AE_NOT_EXIST
;
380 ACPI_DEBUG_PRINT ((ACPI_DB_INFO
,
381 "Removing global notify handler\n"));
383 AcpiGbl_GlobalNotify
[i
].Handler
= NULL
;
384 AcpiGbl_GlobalNotify
[i
].Context
= NULL
;
391 /* All other objects: Are Notifies allowed on this object? */
393 if (!AcpiEvIsNotifyObject (Node
))
399 /* Must have an existing internal object */
401 ObjDesc
= AcpiNsGetAttachedObject (Node
);
404 Status
= AE_NOT_EXIST
;
408 /* Internal object exists. Find the handler and remove it */
410 for (i
= 0; i
< ACPI_NUM_NOTIFY_TYPES
; i
++)
412 if (HandlerType
& (i
+1))
414 HandlerObj
= ObjDesc
->CommonNotify
.NotifyList
[i
];
415 PreviousHandlerObj
= NULL
;
417 /* Attempt to find the handler in the handler list */
420 (HandlerObj
->Notify
.Handler
!= Handler
))
422 PreviousHandlerObj
= HandlerObj
;
423 HandlerObj
= HandlerObj
->Notify
.Next
[i
];
428 Status
= AE_NOT_EXIST
;
432 /* Remove the handler object from the list */
434 if (PreviousHandlerObj
) /* Handler is not at the list head */
436 PreviousHandlerObj
->Notify
.Next
[i
] =
437 HandlerObj
->Notify
.Next
[i
];
439 else /* Handler is at the list head */
441 ObjDesc
->CommonNotify
.NotifyList
[i
] =
442 HandlerObj
->Notify
.Next
[i
];
445 AcpiUtRemoveReference (HandlerObj
);
451 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE
);
452 return_ACPI_STATUS (Status
);
455 ACPI_EXPORT_SYMBOL (AcpiRemoveNotifyHandler
)
458 /*******************************************************************************
460 * FUNCTION: AcpiInstallExceptionHandler
462 * PARAMETERS: Handler - Pointer to the handler function for the
467 * DESCRIPTION: Saves the pointer to the handler function
469 ******************************************************************************/
472 AcpiInstallExceptionHandler (
473 ACPI_EXCEPTION_HANDLER Handler
)
478 ACPI_FUNCTION_TRACE (AcpiInstallExceptionHandler
);
481 Status
= AcpiUtAcquireMutex (ACPI_MTX_EVENTS
);
482 if (ACPI_FAILURE (Status
))
484 return_ACPI_STATUS (Status
);
487 /* Don't allow two handlers. */
489 if (AcpiGbl_ExceptionHandler
)
491 Status
= AE_ALREADY_EXISTS
;
495 /* Install the handler */
497 AcpiGbl_ExceptionHandler
= Handler
;
500 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS
);
501 return_ACPI_STATUS (Status
);
504 ACPI_EXPORT_SYMBOL (AcpiInstallExceptionHandler
)
507 #if (!ACPI_REDUCED_HARDWARE)
508 /*******************************************************************************
510 * FUNCTION: AcpiInstallGlobalEventHandler
512 * PARAMETERS: Handler - Pointer to the global event handler function
513 * Context - Value passed to the handler on each event
517 * DESCRIPTION: Saves the pointer to the handler function. The global handler
518 * is invoked upon each incoming GPE and Fixed Event. It is
519 * invoked at interrupt level at the time of the event dispatch.
520 * Can be used to update event counters, etc.
522 ******************************************************************************/
525 AcpiInstallGlobalEventHandler (
526 ACPI_GBL_EVENT_HANDLER Handler
,
532 ACPI_FUNCTION_TRACE (AcpiInstallGlobalEventHandler
);
535 /* Parameter validation */
539 return_ACPI_STATUS (AE_BAD_PARAMETER
);
542 Status
= AcpiUtAcquireMutex (ACPI_MTX_EVENTS
);
543 if (ACPI_FAILURE (Status
))
545 return_ACPI_STATUS (Status
);
548 /* Don't allow two handlers. */
550 if (AcpiGbl_GlobalEventHandler
)
552 Status
= AE_ALREADY_EXISTS
;
556 AcpiGbl_GlobalEventHandler
= Handler
;
557 AcpiGbl_GlobalEventHandlerContext
= Context
;
561 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS
);
562 return_ACPI_STATUS (Status
);
565 ACPI_EXPORT_SYMBOL (AcpiInstallGlobalEventHandler
)
568 /*******************************************************************************
570 * FUNCTION: AcpiInstallFixedEventHandler
572 * PARAMETERS: Event - Event type to enable.
573 * Handler - Pointer to the handler function for the
575 * Context - Value passed to the handler on each GPE
579 * DESCRIPTION: Saves the pointer to the handler function and then enables the
582 ******************************************************************************/
585 AcpiInstallFixedEventHandler (
587 ACPI_EVENT_HANDLER Handler
,
593 ACPI_FUNCTION_TRACE (AcpiInstallFixedEventHandler
);
596 /* Parameter validation */
598 if (Event
> ACPI_EVENT_MAX
)
600 return_ACPI_STATUS (AE_BAD_PARAMETER
);
603 Status
= AcpiUtAcquireMutex (ACPI_MTX_EVENTS
);
604 if (ACPI_FAILURE (Status
))
606 return_ACPI_STATUS (Status
);
609 /* Don't allow two handlers. */
611 if (NULL
!= AcpiGbl_FixedEventHandlers
[Event
].Handler
)
613 Status
= AE_ALREADY_EXISTS
;
617 /* Install the handler before enabling the event */
619 AcpiGbl_FixedEventHandlers
[Event
].Handler
= Handler
;
620 AcpiGbl_FixedEventHandlers
[Event
].Context
= Context
;
622 Status
= AcpiEnableEvent (Event
, 0);
623 if (ACPI_FAILURE (Status
))
625 ACPI_WARNING ((AE_INFO
, "Could not enable fixed event 0x%X", Event
));
627 /* Remove the handler */
629 AcpiGbl_FixedEventHandlers
[Event
].Handler
= NULL
;
630 AcpiGbl_FixedEventHandlers
[Event
].Context
= NULL
;
634 ACPI_DEBUG_PRINT ((ACPI_DB_INFO
,
635 "Enabled fixed event %X, Handler=%p\n", Event
, Handler
));
640 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS
);
641 return_ACPI_STATUS (Status
);
644 ACPI_EXPORT_SYMBOL (AcpiInstallFixedEventHandler
)
647 /*******************************************************************************
649 * FUNCTION: AcpiRemoveFixedEventHandler
651 * PARAMETERS: Event - Event type to disable.
652 * Handler - Address of the handler
656 * DESCRIPTION: Disables the event and unregisters the event handler.
658 ******************************************************************************/
661 AcpiRemoveFixedEventHandler (
663 ACPI_EVENT_HANDLER Handler
)
665 ACPI_STATUS Status
= AE_OK
;
668 ACPI_FUNCTION_TRACE (AcpiRemoveFixedEventHandler
);
671 /* Parameter validation */
673 if (Event
> ACPI_EVENT_MAX
)
675 return_ACPI_STATUS (AE_BAD_PARAMETER
);
678 Status
= AcpiUtAcquireMutex (ACPI_MTX_EVENTS
);
679 if (ACPI_FAILURE (Status
))
681 return_ACPI_STATUS (Status
);
684 /* Disable the event before removing the handler */
686 Status
= AcpiDisableEvent (Event
, 0);
688 /* Always Remove the handler */
690 AcpiGbl_FixedEventHandlers
[Event
].Handler
= NULL
;
691 AcpiGbl_FixedEventHandlers
[Event
].Context
= NULL
;
693 if (ACPI_FAILURE (Status
))
695 ACPI_WARNING ((AE_INFO
,
696 "Could not write to fixed event enable register 0x%X", Event
));
700 ACPI_DEBUG_PRINT ((ACPI_DB_INFO
, "Disabled fixed event %X\n", Event
));
703 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS
);
704 return_ACPI_STATUS (Status
);
707 ACPI_EXPORT_SYMBOL (AcpiRemoveFixedEventHandler
)
710 /*******************************************************************************
712 * FUNCTION: AcpiInstallGpeHandler
714 * PARAMETERS: GpeDevice - Namespace node for the GPE (NULL for FADT
716 * GpeNumber - The GPE number within the GPE block
717 * Type - Whether this GPE should be treated as an
718 * edge- or level-triggered interrupt.
719 * Address - Address of the handler
720 * Context - Value passed to the handler on each GPE
724 * DESCRIPTION: Install a handler for a General Purpose Event.
726 ******************************************************************************/
729 AcpiInstallGpeHandler (
730 ACPI_HANDLE GpeDevice
,
733 ACPI_GPE_HANDLER Address
,
736 ACPI_GPE_EVENT_INFO
*GpeEventInfo
;
737 ACPI_GPE_HANDLER_INFO
*Handler
;
739 ACPI_CPU_FLAGS Flags
;
742 ACPI_FUNCTION_TRACE (AcpiInstallGpeHandler
);
745 /* Parameter validation */
747 if ((!Address
) || (Type
& ~ACPI_GPE_XRUPT_TYPE_MASK
))
749 return_ACPI_STATUS (AE_BAD_PARAMETER
);
752 Status
= AcpiUtAcquireMutex (ACPI_MTX_EVENTS
);
753 if (ACPI_FAILURE (Status
))
755 return_ACPI_STATUS (Status
);
758 /* Allocate and init handler object (before lock) */
760 Handler
= ACPI_ALLOCATE_ZEROED (sizeof (ACPI_GPE_HANDLER_INFO
));
763 Status
= AE_NO_MEMORY
;
767 Flags
= AcpiOsAcquireLock (AcpiGbl_GpeLock
);
769 /* Ensure that we have a valid GPE number */
771 GpeEventInfo
= AcpiEvGetGpeEventInfo (GpeDevice
, GpeNumber
);
774 Status
= AE_BAD_PARAMETER
;
778 /* Make sure that there isn't a handler there already */
780 if ((GpeEventInfo
->Flags
& ACPI_GPE_DISPATCH_MASK
) ==
781 ACPI_GPE_DISPATCH_HANDLER
)
783 Status
= AE_ALREADY_EXISTS
;
787 Handler
->Address
= Address
;
788 Handler
->Context
= Context
;
789 Handler
->MethodNode
= GpeEventInfo
->Dispatch
.MethodNode
;
790 Handler
->OriginalFlags
= (UINT8
) (GpeEventInfo
->Flags
&
791 (ACPI_GPE_XRUPT_TYPE_MASK
| ACPI_GPE_DISPATCH_MASK
));
794 * If the GPE is associated with a method, it may have been enabled
795 * automatically during initialization, in which case it has to be
796 * disabled now to avoid spurious execution of the handler.
798 if (((Handler
->OriginalFlags
& ACPI_GPE_DISPATCH_METHOD
) ||
799 (Handler
->OriginalFlags
& ACPI_GPE_DISPATCH_NOTIFY
)) &&
800 GpeEventInfo
->RuntimeCount
)
802 Handler
->OriginallyEnabled
= TRUE
;
803 (void) AcpiEvRemoveGpeReference (GpeEventInfo
);
805 /* Sanity check of original type against new type */
807 if (Type
!= (UINT32
) (GpeEventInfo
->Flags
& ACPI_GPE_XRUPT_TYPE_MASK
))
809 ACPI_WARNING ((AE_INFO
, "GPE type mismatch (level/edge)"));
813 /* Install the handler */
815 GpeEventInfo
->Dispatch
.Handler
= Handler
;
817 /* Setup up dispatch flags to indicate handler (vs. method/notify) */
819 GpeEventInfo
->Flags
&= ~(ACPI_GPE_XRUPT_TYPE_MASK
| ACPI_GPE_DISPATCH_MASK
);
820 GpeEventInfo
->Flags
|= (UINT8
) (Type
| ACPI_GPE_DISPATCH_HANDLER
);
822 AcpiOsReleaseLock (AcpiGbl_GpeLock
, Flags
);
826 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS
);
827 return_ACPI_STATUS (Status
);
830 AcpiOsReleaseLock (AcpiGbl_GpeLock
, Flags
);
835 ACPI_EXPORT_SYMBOL (AcpiInstallGpeHandler
)
838 /*******************************************************************************
840 * FUNCTION: AcpiRemoveGpeHandler
842 * PARAMETERS: GpeDevice - Namespace node for the GPE (NULL for FADT
844 * GpeNumber - The event to remove a handler
845 * Address - Address of the handler
849 * DESCRIPTION: Remove a handler for a General Purpose AcpiEvent.
851 ******************************************************************************/
854 AcpiRemoveGpeHandler (
855 ACPI_HANDLE GpeDevice
,
857 ACPI_GPE_HANDLER Address
)
859 ACPI_GPE_EVENT_INFO
*GpeEventInfo
;
860 ACPI_GPE_HANDLER_INFO
*Handler
;
862 ACPI_CPU_FLAGS Flags
;
865 ACPI_FUNCTION_TRACE (AcpiRemoveGpeHandler
);
868 /* Parameter validation */
872 return_ACPI_STATUS (AE_BAD_PARAMETER
);
875 /* Make sure all deferred GPE tasks are completed */
877 AcpiOsWaitEventsComplete ();
879 Status
= AcpiUtAcquireMutex (ACPI_MTX_EVENTS
);
880 if (ACPI_FAILURE (Status
))
882 return_ACPI_STATUS (Status
);
885 Flags
= AcpiOsAcquireLock (AcpiGbl_GpeLock
);
887 /* Ensure that we have a valid GPE number */
889 GpeEventInfo
= AcpiEvGetGpeEventInfo (GpeDevice
, GpeNumber
);
892 Status
= AE_BAD_PARAMETER
;
896 /* Make sure that a handler is indeed installed */
898 if ((GpeEventInfo
->Flags
& ACPI_GPE_DISPATCH_MASK
) !=
899 ACPI_GPE_DISPATCH_HANDLER
)
901 Status
= AE_NOT_EXIST
;
905 /* Make sure that the installed handler is the same */
907 if (GpeEventInfo
->Dispatch
.Handler
->Address
!= Address
)
909 Status
= AE_BAD_PARAMETER
;
913 /* Remove the handler */
915 Handler
= GpeEventInfo
->Dispatch
.Handler
;
917 /* Restore Method node (if any), set dispatch flags */
919 GpeEventInfo
->Dispatch
.MethodNode
= Handler
->MethodNode
;
920 GpeEventInfo
->Flags
&=
921 ~(ACPI_GPE_XRUPT_TYPE_MASK
| ACPI_GPE_DISPATCH_MASK
);
922 GpeEventInfo
->Flags
|= Handler
->OriginalFlags
;
925 * If the GPE was previously associated with a method and it was
926 * enabled, it should be enabled at this point to restore the
927 * post-initialization configuration.
929 if ((Handler
->OriginalFlags
& ACPI_GPE_DISPATCH_METHOD
) &&
930 Handler
->OriginallyEnabled
)
932 (void) AcpiEvAddGpeReference (GpeEventInfo
);
935 /* Now we can free the handler object */
941 AcpiOsReleaseLock (AcpiGbl_GpeLock
, Flags
);
942 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS
);
943 return_ACPI_STATUS (Status
);
946 ACPI_EXPORT_SYMBOL (AcpiRemoveGpeHandler
)
949 /*******************************************************************************
951 * FUNCTION: AcpiAcquireGlobalLock
953 * PARAMETERS: Timeout - How long the caller is willing to wait
954 * Handle - Where the handle to the lock is returned
959 * DESCRIPTION: Acquire the ACPI Global Lock
961 * Note: Allows callers with the same thread ID to acquire the global lock
962 * multiple times. In other words, externally, the behavior of the global lock
963 * is identical to an AML mutex. On the first acquire, a new handle is
964 * returned. On any subsequent calls to acquire by the same thread, the same
965 * handle is returned.
967 ******************************************************************************/
970 AcpiAcquireGlobalLock (
979 return (AE_BAD_PARAMETER
);
982 /* Must lock interpreter to prevent race conditions */
984 AcpiExEnterInterpreter ();
986 Status
= AcpiExAcquireMutexObject (Timeout
,
987 AcpiGbl_GlobalLockMutex
, AcpiOsGetThreadId ());
989 if (ACPI_SUCCESS (Status
))
991 /* Return the global lock handle (updated in AcpiEvAcquireGlobalLock) */
993 *Handle
= AcpiGbl_GlobalLockHandle
;
996 AcpiExExitInterpreter ();
1000 ACPI_EXPORT_SYMBOL (AcpiAcquireGlobalLock
)
1003 /*******************************************************************************
1005 * FUNCTION: AcpiReleaseGlobalLock
1007 * PARAMETERS: Handle - Returned from AcpiAcquireGlobalLock
1011 * DESCRIPTION: Release the ACPI Global Lock. The handle must be valid.
1013 ******************************************************************************/
1016 AcpiReleaseGlobalLock (
1022 if (!Handle
|| (Handle
!= AcpiGbl_GlobalLockHandle
))
1024 return (AE_NOT_ACQUIRED
);
1027 Status
= AcpiExReleaseMutexObject (AcpiGbl_GlobalLockMutex
);
1031 ACPI_EXPORT_SYMBOL (AcpiReleaseGlobalLock
)
1033 #endif /* !ACPI_REDUCED_HARDWARE */