1 /******************************************************************************
3 * Module Name: evxface - External interfaces for ACPI events
5 *****************************************************************************/
7 /******************************************************************************
11 * Some or all of this work - Copyright (c) 1999 - 2011, 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: AcpiInstallExceptionHandler
133 * PARAMETERS: Handler - Pointer to the handler function for the
138 * DESCRIPTION: Saves the pointer to the handler function
140 ******************************************************************************/
143 AcpiInstallExceptionHandler (
144 ACPI_EXCEPTION_HANDLER Handler
)
149 ACPI_FUNCTION_TRACE (AcpiInstallExceptionHandler
);
152 Status
= AcpiUtAcquireMutex (ACPI_MTX_EVENTS
);
153 if (ACPI_FAILURE (Status
))
155 return_ACPI_STATUS (Status
);
158 /* Don't allow two handlers. */
160 if (AcpiGbl_ExceptionHandler
)
162 Status
= AE_ALREADY_EXISTS
;
166 /* Install the handler */
168 AcpiGbl_ExceptionHandler
= Handler
;
171 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS
);
172 return_ACPI_STATUS (Status
);
175 ACPI_EXPORT_SYMBOL (AcpiInstallExceptionHandler
)
178 /*******************************************************************************
180 * FUNCTION: AcpiInstallGlobalEventHandler
182 * PARAMETERS: Handler - Pointer to the global event handler function
183 * Context - Value passed to the handler on each event
187 * DESCRIPTION: Saves the pointer to the handler function. The global handler
188 * is invoked upon each incoming GPE and Fixed Event. It is
189 * invoked at interrupt level at the time of the event dispatch.
190 * Can be used to update event counters, etc.
192 ******************************************************************************/
195 AcpiInstallGlobalEventHandler (
196 ACPI_GBL_EVENT_HANDLER Handler
,
202 ACPI_FUNCTION_TRACE (AcpiInstallGlobalEventHandler
);
205 /* Parameter validation */
209 return_ACPI_STATUS (AE_BAD_PARAMETER
);
212 Status
= AcpiUtAcquireMutex (ACPI_MTX_EVENTS
);
213 if (ACPI_FAILURE (Status
))
215 return_ACPI_STATUS (Status
);
218 /* Don't allow two handlers. */
220 if (AcpiGbl_GlobalEventHandler
)
222 Status
= AE_ALREADY_EXISTS
;
226 AcpiGbl_GlobalEventHandler
= Handler
;
227 AcpiGbl_GlobalEventHandlerContext
= Context
;
231 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS
);
232 return_ACPI_STATUS (Status
);
235 ACPI_EXPORT_SYMBOL (AcpiInstallGlobalEventHandler
)
238 /*******************************************************************************
240 * FUNCTION: AcpiInstallFixedEventHandler
242 * PARAMETERS: Event - Event type to enable.
243 * Handler - Pointer to the handler function for the
245 * Context - Value passed to the handler on each GPE
249 * DESCRIPTION: Saves the pointer to the handler function and then enables the
252 ******************************************************************************/
255 AcpiInstallFixedEventHandler (
257 ACPI_EVENT_HANDLER Handler
,
263 ACPI_FUNCTION_TRACE (AcpiInstallFixedEventHandler
);
266 /* Parameter validation */
268 if (Event
> ACPI_EVENT_MAX
)
270 return_ACPI_STATUS (AE_BAD_PARAMETER
);
273 Status
= AcpiUtAcquireMutex (ACPI_MTX_EVENTS
);
274 if (ACPI_FAILURE (Status
))
276 return_ACPI_STATUS (Status
);
279 /* Don't allow two handlers. */
281 if (NULL
!= AcpiGbl_FixedEventHandlers
[Event
].Handler
)
283 Status
= AE_ALREADY_EXISTS
;
287 /* Install the handler before enabling the event */
289 AcpiGbl_FixedEventHandlers
[Event
].Handler
= Handler
;
290 AcpiGbl_FixedEventHandlers
[Event
].Context
= Context
;
292 Status
= AcpiEnableEvent (Event
, 0);
293 if (ACPI_FAILURE (Status
))
295 ACPI_WARNING ((AE_INFO
, "Could not enable fixed event 0x%X", Event
));
297 /* Remove the handler */
299 AcpiGbl_FixedEventHandlers
[Event
].Handler
= NULL
;
300 AcpiGbl_FixedEventHandlers
[Event
].Context
= NULL
;
304 ACPI_DEBUG_PRINT ((ACPI_DB_INFO
,
305 "Enabled fixed event %X, Handler=%p\n", Event
, Handler
));
310 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS
);
311 return_ACPI_STATUS (Status
);
314 ACPI_EXPORT_SYMBOL (AcpiInstallFixedEventHandler
)
317 /*******************************************************************************
319 * FUNCTION: AcpiRemoveFixedEventHandler
321 * PARAMETERS: Event - Event type to disable.
322 * Handler - Address of the handler
326 * DESCRIPTION: Disables the event and unregisters the event handler.
328 ******************************************************************************/
331 AcpiRemoveFixedEventHandler (
333 ACPI_EVENT_HANDLER Handler
)
335 ACPI_STATUS Status
= AE_OK
;
338 ACPI_FUNCTION_TRACE (AcpiRemoveFixedEventHandler
);
341 /* Parameter validation */
343 if (Event
> ACPI_EVENT_MAX
)
345 return_ACPI_STATUS (AE_BAD_PARAMETER
);
348 Status
= AcpiUtAcquireMutex (ACPI_MTX_EVENTS
);
349 if (ACPI_FAILURE (Status
))
351 return_ACPI_STATUS (Status
);
354 /* Disable the event before removing the handler */
356 Status
= AcpiDisableEvent (Event
, 0);
358 /* Always Remove the handler */
360 AcpiGbl_FixedEventHandlers
[Event
].Handler
= NULL
;
361 AcpiGbl_FixedEventHandlers
[Event
].Context
= NULL
;
363 if (ACPI_FAILURE (Status
))
365 ACPI_WARNING ((AE_INFO
,
366 "Could not write to fixed event enable register 0x%X", Event
));
370 ACPI_DEBUG_PRINT ((ACPI_DB_INFO
, "Disabled fixed event %X\n", Event
));
373 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS
);
374 return_ACPI_STATUS (Status
);
377 ACPI_EXPORT_SYMBOL (AcpiRemoveFixedEventHandler
)
380 /*******************************************************************************
382 * FUNCTION: AcpiInstallNotifyHandler
384 * PARAMETERS: Device - The device for which notifies will be handled
385 * HandlerType - The type of handler:
386 * ACPI_SYSTEM_NOTIFY: SystemHandler (00-7f)
387 * ACPI_DEVICE_NOTIFY: DriverHandler (80-ff)
388 * ACPI_ALL_NOTIFY: both system and device
389 * Handler - Address of the handler
390 * Context - Value passed to the handler on each GPE
394 * DESCRIPTION: Install a handler for notifies on an ACPI device
396 ******************************************************************************/
399 AcpiInstallNotifyHandler (
402 ACPI_NOTIFY_HANDLER Handler
,
405 ACPI_OPERAND_OBJECT
*ObjDesc
;
406 ACPI_OPERAND_OBJECT
*NotifyObj
;
407 ACPI_NAMESPACE_NODE
*Node
;
411 ACPI_FUNCTION_TRACE (AcpiInstallNotifyHandler
);
414 /* Parameter validation */
418 (HandlerType
> ACPI_MAX_NOTIFY_HANDLER_TYPE
))
420 return_ACPI_STATUS (AE_BAD_PARAMETER
);
423 Status
= AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE
);
424 if (ACPI_FAILURE (Status
))
426 return_ACPI_STATUS (Status
);
429 /* Convert and validate the device handle */
431 Node
= AcpiNsValidateHandle (Device
);
434 Status
= AE_BAD_PARAMETER
;
440 * Registering a notify handler on the root object indicates that the
441 * caller wishes to receive notifications for all objects. Note that
442 * only one <external> global handler can be regsitered (per notify type).
444 if (Device
== ACPI_ROOT_OBJECT
)
446 /* Make sure the handler is not already installed */
448 if (((HandlerType
& ACPI_SYSTEM_NOTIFY
) &&
449 AcpiGbl_SystemNotify
.Handler
) ||
450 ((HandlerType
& ACPI_DEVICE_NOTIFY
) &&
451 AcpiGbl_DeviceNotify
.Handler
))
453 Status
= AE_ALREADY_EXISTS
;
457 if (HandlerType
& ACPI_SYSTEM_NOTIFY
)
459 AcpiGbl_SystemNotify
.Node
= Node
;
460 AcpiGbl_SystemNotify
.Handler
= Handler
;
461 AcpiGbl_SystemNotify
.Context
= Context
;
464 if (HandlerType
& ACPI_DEVICE_NOTIFY
)
466 AcpiGbl_DeviceNotify
.Node
= Node
;
467 AcpiGbl_DeviceNotify
.Handler
= Handler
;
468 AcpiGbl_DeviceNotify
.Context
= Context
;
471 /* Global notify handler installed */
476 * Caller will only receive notifications specific to the target object.
477 * Note that only certain object types can receive notifications.
481 /* Notifies allowed on this object? */
483 if (!AcpiEvIsNotifyObject (Node
))
489 /* Check for an existing internal object */
491 ObjDesc
= AcpiNsGetAttachedObject (Node
);
494 /* Object exists - make sure there's no handler */
496 if (((HandlerType
& ACPI_SYSTEM_NOTIFY
) &&
497 ObjDesc
->CommonNotify
.SystemNotify
) ||
498 ((HandlerType
& ACPI_DEVICE_NOTIFY
) &&
499 ObjDesc
->CommonNotify
.DeviceNotify
))
501 Status
= AE_ALREADY_EXISTS
;
507 /* Create a new object */
509 ObjDesc
= AcpiUtCreateInternalObject (Node
->Type
);
512 Status
= AE_NO_MEMORY
;
516 /* Attach new object to the Node */
518 Status
= AcpiNsAttachObject (Device
, ObjDesc
, Node
->Type
);
520 /* Remove local reference to the object */
522 AcpiUtRemoveReference (ObjDesc
);
523 if (ACPI_FAILURE (Status
))
529 /* Install the handler */
531 NotifyObj
= AcpiUtCreateInternalObject (ACPI_TYPE_LOCAL_NOTIFY
);
534 Status
= AE_NO_MEMORY
;
538 NotifyObj
->Notify
.Node
= Node
;
539 NotifyObj
->Notify
.Handler
= Handler
;
540 NotifyObj
->Notify
.Context
= Context
;
542 if (HandlerType
& ACPI_SYSTEM_NOTIFY
)
544 ObjDesc
->CommonNotify
.SystemNotify
= NotifyObj
;
547 if (HandlerType
& ACPI_DEVICE_NOTIFY
)
549 ObjDesc
->CommonNotify
.DeviceNotify
= NotifyObj
;
552 if (HandlerType
== ACPI_ALL_NOTIFY
)
554 /* Extra ref if installed in both */
556 AcpiUtAddReference (NotifyObj
);
562 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE
);
563 return_ACPI_STATUS (Status
);
566 ACPI_EXPORT_SYMBOL (AcpiInstallNotifyHandler
)
569 /*******************************************************************************
571 * FUNCTION: AcpiRemoveNotifyHandler
573 * PARAMETERS: Device - The device for which notifies will be handled
574 * HandlerType - The type of handler:
575 * ACPI_SYSTEM_NOTIFY: SystemHandler (00-7f)
576 * ACPI_DEVICE_NOTIFY: DriverHandler (80-ff)
577 * ACPI_ALL_NOTIFY: both system and device
578 * Handler - Address of the handler
582 * DESCRIPTION: Remove a handler for notifies on an ACPI device
584 ******************************************************************************/
587 AcpiRemoveNotifyHandler (
590 ACPI_NOTIFY_HANDLER Handler
)
592 ACPI_OPERAND_OBJECT
*NotifyObj
;
593 ACPI_OPERAND_OBJECT
*ObjDesc
;
594 ACPI_NAMESPACE_NODE
*Node
;
598 ACPI_FUNCTION_TRACE (AcpiRemoveNotifyHandler
);
601 /* Parameter validation */
605 (HandlerType
> ACPI_MAX_NOTIFY_HANDLER_TYPE
))
607 return_ACPI_STATUS (AE_BAD_PARAMETER
);
610 Status
= AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE
);
611 if (ACPI_FAILURE (Status
))
613 return_ACPI_STATUS (Status
);
616 /* Convert and validate the device handle */
618 Node
= AcpiNsValidateHandle (Device
);
621 Status
= AE_BAD_PARAMETER
;
627 if (Device
== ACPI_ROOT_OBJECT
)
629 ACPI_DEBUG_PRINT ((ACPI_DB_INFO
,
630 "Removing notify handler for namespace root object\n"));
632 if (((HandlerType
& ACPI_SYSTEM_NOTIFY
) &&
633 !AcpiGbl_SystemNotify
.Handler
) ||
634 ((HandlerType
& ACPI_DEVICE_NOTIFY
) &&
635 !AcpiGbl_DeviceNotify
.Handler
))
637 Status
= AE_NOT_EXIST
;
641 if (HandlerType
& ACPI_SYSTEM_NOTIFY
)
643 AcpiGbl_SystemNotify
.Node
= NULL
;
644 AcpiGbl_SystemNotify
.Handler
= NULL
;
645 AcpiGbl_SystemNotify
.Context
= NULL
;
648 if (HandlerType
& ACPI_DEVICE_NOTIFY
)
650 AcpiGbl_DeviceNotify
.Node
= NULL
;
651 AcpiGbl_DeviceNotify
.Handler
= NULL
;
652 AcpiGbl_DeviceNotify
.Context
= NULL
;
656 /* All Other Objects */
660 /* Notifies allowed on this object? */
662 if (!AcpiEvIsNotifyObject (Node
))
668 /* Check for an existing internal object */
670 ObjDesc
= AcpiNsGetAttachedObject (Node
);
673 Status
= AE_NOT_EXIST
;
677 /* Object exists - make sure there's an existing handler */
679 if (HandlerType
& ACPI_SYSTEM_NOTIFY
)
681 NotifyObj
= ObjDesc
->CommonNotify
.SystemNotify
;
684 Status
= AE_NOT_EXIST
;
688 if (NotifyObj
->Notify
.Handler
!= Handler
)
690 Status
= AE_BAD_PARAMETER
;
694 /* Remove the handler */
696 ObjDesc
->CommonNotify
.SystemNotify
= NULL
;
697 AcpiUtRemoveReference (NotifyObj
);
700 if (HandlerType
& ACPI_DEVICE_NOTIFY
)
702 NotifyObj
= ObjDesc
->CommonNotify
.DeviceNotify
;
705 Status
= AE_NOT_EXIST
;
709 if (NotifyObj
->Notify
.Handler
!= Handler
)
711 Status
= AE_BAD_PARAMETER
;
715 /* Remove the handler */
717 ObjDesc
->CommonNotify
.DeviceNotify
= NULL
;
718 AcpiUtRemoveReference (NotifyObj
);
724 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE
);
725 return_ACPI_STATUS (Status
);
728 ACPI_EXPORT_SYMBOL (AcpiRemoveNotifyHandler
)
731 /*******************************************************************************
733 * FUNCTION: AcpiInstallGpeHandler
735 * PARAMETERS: GpeDevice - Namespace node for the GPE (NULL for FADT
737 * GpeNumber - The GPE number within the GPE block
738 * Type - Whether this GPE should be treated as an
739 * edge- or level-triggered interrupt.
740 * Address - Address of the handler
741 * Context - Value passed to the handler on each GPE
745 * DESCRIPTION: Install a handler for a General Purpose Event.
747 ******************************************************************************/
750 AcpiInstallGpeHandler (
751 ACPI_HANDLE GpeDevice
,
754 ACPI_GPE_HANDLER Address
,
757 ACPI_GPE_EVENT_INFO
*GpeEventInfo
;
758 ACPI_GPE_HANDLER_INFO
*Handler
;
760 ACPI_CPU_FLAGS Flags
;
763 ACPI_FUNCTION_TRACE (AcpiInstallGpeHandler
);
766 /* Parameter validation */
768 if ((!Address
) || (Type
& ~ACPI_GPE_XRUPT_TYPE_MASK
))
770 return_ACPI_STATUS (AE_BAD_PARAMETER
);
773 Status
= AcpiUtAcquireMutex (ACPI_MTX_EVENTS
);
774 if (ACPI_FAILURE (Status
))
776 return_ACPI_STATUS (Status
);
779 /* Allocate and init handler object (before lock) */
781 Handler
= ACPI_ALLOCATE_ZEROED (sizeof (ACPI_GPE_HANDLER_INFO
));
784 Status
= AE_NO_MEMORY
;
788 Flags
= AcpiOsAcquireLock (AcpiGbl_GpeLock
);
790 /* Ensure that we have a valid GPE number */
792 GpeEventInfo
= AcpiEvGetGpeEventInfo (GpeDevice
, GpeNumber
);
795 Status
= AE_BAD_PARAMETER
;
799 /* Make sure that there isn't a handler there already */
801 if ((GpeEventInfo
->Flags
& ACPI_GPE_DISPATCH_MASK
) ==
802 ACPI_GPE_DISPATCH_HANDLER
)
804 Status
= AE_ALREADY_EXISTS
;
808 Handler
->Address
= Address
;
809 Handler
->Context
= Context
;
810 Handler
->MethodNode
= GpeEventInfo
->Dispatch
.MethodNode
;
811 Handler
->OriginalFlags
= (UINT8
) (GpeEventInfo
->Flags
&
812 (ACPI_GPE_XRUPT_TYPE_MASK
| ACPI_GPE_DISPATCH_MASK
));
815 * If the GPE is associated with a method, it may have been enabled
816 * automatically during initialization, in which case it has to be
817 * disabled now to avoid spurious execution of the handler.
819 if (((Handler
->OriginalFlags
& ACPI_GPE_DISPATCH_METHOD
) ||
820 (Handler
->OriginalFlags
& ACPI_GPE_DISPATCH_NOTIFY
)) &&
821 GpeEventInfo
->RuntimeCount
)
823 Handler
->OriginallyEnabled
= TRUE
;
824 (void) AcpiEvRemoveGpeReference (GpeEventInfo
);
826 /* Sanity check of original type against new type */
828 if (Type
!= (UINT32
) (GpeEventInfo
->Flags
& ACPI_GPE_XRUPT_TYPE_MASK
))
830 ACPI_WARNING ((AE_INFO
, "GPE type mismatch (level/edge)"));
834 /* Install the handler */
836 GpeEventInfo
->Dispatch
.Handler
= Handler
;
838 /* Setup up dispatch flags to indicate handler (vs. method/notify) */
840 GpeEventInfo
->Flags
&= ~(ACPI_GPE_XRUPT_TYPE_MASK
| ACPI_GPE_DISPATCH_MASK
);
841 GpeEventInfo
->Flags
|= (UINT8
) (Type
| ACPI_GPE_DISPATCH_HANDLER
);
843 AcpiOsReleaseLock (AcpiGbl_GpeLock
, Flags
);
847 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS
);
848 return_ACPI_STATUS (Status
);
851 AcpiOsReleaseLock (AcpiGbl_GpeLock
, Flags
);
856 ACPI_EXPORT_SYMBOL (AcpiInstallGpeHandler
)
859 /*******************************************************************************
861 * FUNCTION: AcpiRemoveGpeHandler
863 * PARAMETERS: GpeDevice - Namespace node for the GPE (NULL for FADT
865 * GpeNumber - The event to remove a handler
866 * Address - Address of the handler
870 * DESCRIPTION: Remove a handler for a General Purpose AcpiEvent.
872 ******************************************************************************/
875 AcpiRemoveGpeHandler (
876 ACPI_HANDLE GpeDevice
,
878 ACPI_GPE_HANDLER Address
)
880 ACPI_GPE_EVENT_INFO
*GpeEventInfo
;
881 ACPI_GPE_HANDLER_INFO
*Handler
;
883 ACPI_CPU_FLAGS Flags
;
886 ACPI_FUNCTION_TRACE (AcpiRemoveGpeHandler
);
889 /* Parameter validation */
893 return_ACPI_STATUS (AE_BAD_PARAMETER
);
896 Status
= AcpiUtAcquireMutex (ACPI_MTX_EVENTS
);
897 if (ACPI_FAILURE (Status
))
899 return_ACPI_STATUS (Status
);
902 Flags
= AcpiOsAcquireLock (AcpiGbl_GpeLock
);
904 /* Ensure that we have a valid GPE number */
906 GpeEventInfo
= AcpiEvGetGpeEventInfo (GpeDevice
, GpeNumber
);
909 Status
= AE_BAD_PARAMETER
;
913 /* Make sure that a handler is indeed installed */
915 if ((GpeEventInfo
->Flags
& ACPI_GPE_DISPATCH_MASK
) !=
916 ACPI_GPE_DISPATCH_HANDLER
)
918 Status
= AE_NOT_EXIST
;
922 /* Make sure that the installed handler is the same */
924 if (GpeEventInfo
->Dispatch
.Handler
->Address
!= Address
)
926 Status
= AE_BAD_PARAMETER
;
930 /* Remove the handler */
932 Handler
= GpeEventInfo
->Dispatch
.Handler
;
934 /* Restore Method node (if any), set dispatch flags */
936 GpeEventInfo
->Dispatch
.MethodNode
= Handler
->MethodNode
;
937 GpeEventInfo
->Flags
&=
938 ~(ACPI_GPE_XRUPT_TYPE_MASK
| ACPI_GPE_DISPATCH_MASK
);
939 GpeEventInfo
->Flags
|= Handler
->OriginalFlags
;
942 * If the GPE was previously associated with a method and it was
943 * enabled, it should be enabled at this point to restore the
944 * post-initialization configuration.
946 if ((Handler
->OriginalFlags
& ACPI_GPE_DISPATCH_METHOD
) &&
947 Handler
->OriginallyEnabled
)
949 (void) AcpiEvAddGpeReference (GpeEventInfo
);
952 /* Now we can free the handler object */
958 AcpiOsReleaseLock (AcpiGbl_GpeLock
, Flags
);
959 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS
);
960 return_ACPI_STATUS (Status
);
963 ACPI_EXPORT_SYMBOL (AcpiRemoveGpeHandler
)
966 /*******************************************************************************
968 * FUNCTION: AcpiAcquireGlobalLock
970 * PARAMETERS: Timeout - How long the caller is willing to wait
971 * Handle - Where the handle to the lock is returned
976 * DESCRIPTION: Acquire the ACPI Global Lock
978 * Note: Allows callers with the same thread ID to acquire the global lock
979 * multiple times. In other words, externally, the behavior of the global lock
980 * is identical to an AML mutex. On the first acquire, a new handle is
981 * returned. On any subsequent calls to acquire by the same thread, the same
982 * handle is returned.
984 ******************************************************************************/
987 AcpiAcquireGlobalLock (
996 return (AE_BAD_PARAMETER
);
999 /* Must lock interpreter to prevent race conditions */
1001 AcpiExEnterInterpreter ();
1003 Status
= AcpiExAcquireMutexObject (Timeout
,
1004 AcpiGbl_GlobalLockMutex
, AcpiOsGetThreadId ());
1006 if (ACPI_SUCCESS (Status
))
1008 /* Return the global lock handle (updated in AcpiEvAcquireGlobalLock) */
1010 *Handle
= AcpiGbl_GlobalLockHandle
;
1013 AcpiExExitInterpreter ();
1017 ACPI_EXPORT_SYMBOL (AcpiAcquireGlobalLock
)
1020 /*******************************************************************************
1022 * FUNCTION: AcpiReleaseGlobalLock
1024 * PARAMETERS: Handle - Returned from AcpiAcquireGlobalLock
1028 * DESCRIPTION: Release the ACPI Global Lock. The handle must be valid.
1030 ******************************************************************************/
1033 AcpiReleaseGlobalLock (
1039 if (!Handle
|| (Handle
!= AcpiGbl_GlobalLockHandle
))
1041 return (AE_NOT_ACQUIRED
);
1044 Status
= AcpiExReleaseMutexObject (AcpiGbl_GlobalLockMutex
);
1048 ACPI_EXPORT_SYMBOL (AcpiReleaseGlobalLock
)