1 /******************************************************************************
3 * Module Name: evxface - External interfaces for ACPI events
5 *****************************************************************************/
7 /******************************************************************************
11 * Some or all of this work - Copyright (c) 1999 - 2018, 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 * Alternatively, you may choose to be licensed under the terms of the
119 * Redistribution and use in source and binary forms, with or without
120 * modification, are permitted provided that the following conditions
122 * 1. Redistributions of source code must retain the above copyright
123 * notice, this list of conditions, and the following disclaimer,
124 * without modification.
125 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
126 * substantially similar to the "NO WARRANTY" disclaimer below
127 * ("Disclaimer") and any redistribution must be conditioned upon
128 * including a substantially similar Disclaimer requirement for further
129 * binary redistribution.
130 * 3. Neither the names of the above-listed copyright holders nor the names
131 * of any contributors may be used to endorse or promote products derived
132 * from this software without specific prior written permission.
134 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
135 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
136 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
137 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
138 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
139 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
140 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
141 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
142 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
143 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
144 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
146 * Alternatively, you may choose to be licensed under the terms of the
147 * GNU General Public License ("GPL") version 2 as published by the Free
148 * Software Foundation.
150 *****************************************************************************/
152 #define EXPORT_ACPI_INTERFACES
154 #include <contrib/dev/acpica/include/acpi.h>
155 #include <contrib/dev/acpica/include/accommon.h>
156 #include <contrib/dev/acpica/include/acnamesp.h>
157 #include <contrib/dev/acpica/include/acevents.h>
158 #include <contrib/dev/acpica/include/acinterp.h>
160 #define _COMPONENT ACPI_EVENTS
161 ACPI_MODULE_NAME ("evxface")
163 #if (!ACPI_REDUCED_HARDWARE)
165 /* Local prototypes */
168 AcpiEvInstallGpeHandler (
169 ACPI_HANDLE GpeDevice,
172 BOOLEAN IsRawHandler,
173 ACPI_GPE_HANDLER Address,
179 /*******************************************************************************
181 * FUNCTION: AcpiInstallNotifyHandler
183 * PARAMETERS: Device - The device for which notifies will be handled
184 * HandlerType - The type of handler:
185 * ACPI_SYSTEM_NOTIFY: System Handler (00-7F)
186 * ACPI_DEVICE_NOTIFY: Device Handler (80-FF)
187 * ACPI_ALL_NOTIFY: Both System and Device
188 * Handler - Address of the handler
189 * Context - Value passed to the handler on each GPE
193 * DESCRIPTION: Install a handler for notifications on an ACPI Device,
194 * ThermalZone, or Processor object.
196 * NOTES: The Root namespace object may have only one handler for each
197 * type of notify (System/Device). Device/Thermal/Processor objects
198 * may have one device notify handler, and multiple system notify
201 ******************************************************************************/
204 AcpiInstallNotifyHandler (
207 ACPI_NOTIFY_HANDLER Handler,
210 ACPI_NAMESPACE_NODE *Node = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, Device);
211 ACPI_OPERAND_OBJECT *ObjDesc;
212 ACPI_OPERAND_OBJECT *HandlerObj;
217 ACPI_FUNCTION_TRACE (AcpiInstallNotifyHandler);
220 /* Parameter validation */
222 if ((!Device) || (!Handler) || (!HandlerType) ||
223 (HandlerType > ACPI_MAX_NOTIFY_HANDLER_TYPE))
225 return_ACPI_STATUS (AE_BAD_PARAMETER);
228 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
229 if (ACPI_FAILURE (Status))
231 return_ACPI_STATUS (Status);
236 * Registering a notify handler on the root object indicates that the
237 * caller wishes to receive notifications for all objects. Note that
238 * only one global handler can be registered per notify type.
239 * Ensure that a handler is not already installed.
241 if (Device == ACPI_ROOT_OBJECT)
243 for (i = 0; i < ACPI_NUM_NOTIFY_TYPES; i++)
245 if (HandlerType & (i+1))
247 if (AcpiGbl_GlobalNotify[i].Handler)
249 Status = AE_ALREADY_EXISTS;
253 AcpiGbl_GlobalNotify[i].Handler = Handler;
254 AcpiGbl_GlobalNotify[i].Context = Context;
258 goto UnlockAndExit; /* Global notify handler installed, all done */
263 * Caller will only receive notifications specific to the target
264 * object. Note that only certain object types are allowed to
265 * receive notifications.
268 /* Are Notifies allowed on this object? */
270 if (!AcpiEvIsNotifyObject (Node))
276 /* Check for an existing internal object, might not exist */
278 ObjDesc = AcpiNsGetAttachedObject (Node);
281 /* Create a new object */
283 ObjDesc = AcpiUtCreateInternalObject (Node->Type);
286 Status = AE_NO_MEMORY;
290 /* Attach new object to the Node, remove local reference */
292 Status = AcpiNsAttachObject (Device, ObjDesc, Node->Type);
293 AcpiUtRemoveReference (ObjDesc);
294 if (ACPI_FAILURE (Status))
300 /* Ensure that the handler is not already installed in the lists */
302 for (i = 0; i < ACPI_NUM_NOTIFY_TYPES; i++)
304 if (HandlerType & (i+1))
306 HandlerObj = ObjDesc->CommonNotify.NotifyList[i];
309 if (HandlerObj->Notify.Handler == Handler)
311 Status = AE_ALREADY_EXISTS;
315 HandlerObj = HandlerObj->Notify.Next[i];
320 /* Create and populate a new notify handler object */
322 HandlerObj = AcpiUtCreateInternalObject (ACPI_TYPE_LOCAL_NOTIFY);
325 Status = AE_NO_MEMORY;
329 HandlerObj->Notify.Node = Node;
330 HandlerObj->Notify.HandlerType = HandlerType;
331 HandlerObj->Notify.Handler = Handler;
332 HandlerObj->Notify.Context = Context;
334 /* Install the handler at the list head(s) */
336 for (i = 0; i < ACPI_NUM_NOTIFY_TYPES; i++)
338 if (HandlerType & (i+1))
340 HandlerObj->Notify.Next[i] =
341 ObjDesc->CommonNotify.NotifyList[i];
343 ObjDesc->CommonNotify.NotifyList[i] = HandlerObj;
347 /* Add an extra reference if handler was installed in both lists */
349 if (HandlerType == ACPI_ALL_NOTIFY)
351 AcpiUtAddReference (HandlerObj);
356 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
357 return_ACPI_STATUS (Status);
360 ACPI_EXPORT_SYMBOL (AcpiInstallNotifyHandler)
363 /*******************************************************************************
365 * FUNCTION: AcpiRemoveNotifyHandler
367 * PARAMETERS: Device - The device for which the handler is installed
368 * HandlerType - The type of handler:
369 * ACPI_SYSTEM_NOTIFY: System Handler (00-7F)
370 * ACPI_DEVICE_NOTIFY: Device Handler (80-FF)
371 * ACPI_ALL_NOTIFY: Both System and Device
372 * Handler - Address of the handler
376 * DESCRIPTION: Remove a handler for notifies on an ACPI device
378 ******************************************************************************/
381 AcpiRemoveNotifyHandler (
384 ACPI_NOTIFY_HANDLER Handler)
386 ACPI_NAMESPACE_NODE *Node = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, Device);
387 ACPI_OPERAND_OBJECT *ObjDesc;
388 ACPI_OPERAND_OBJECT *HandlerObj;
389 ACPI_OPERAND_OBJECT *PreviousHandlerObj;
390 ACPI_STATUS Status = AE_OK;
394 ACPI_FUNCTION_TRACE (AcpiRemoveNotifyHandler);
397 /* Parameter validation */
399 if ((!Device) || (!Handler) || (!HandlerType) ||
400 (HandlerType > ACPI_MAX_NOTIFY_HANDLER_TYPE))
402 return_ACPI_STATUS (AE_BAD_PARAMETER);
405 /* Root Object. Global handlers are removed here */
407 if (Device == ACPI_ROOT_OBJECT)
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 if (!AcpiGbl_GlobalNotify[i].Handler ||
420 (AcpiGbl_GlobalNotify[i].Handler != Handler))
422 Status = AE_NOT_EXIST;
426 ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
427 "Removing global notify handler\n"));
429 AcpiGbl_GlobalNotify[i].Handler = NULL;
430 AcpiGbl_GlobalNotify[i].Context = NULL;
432 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
434 /* Make sure all deferred notify tasks are completed */
436 AcpiOsWaitEventsComplete ();
440 return_ACPI_STATUS (AE_OK);
443 /* All other objects: Are Notifies allowed on this object? */
445 if (!AcpiEvIsNotifyObject (Node))
447 return_ACPI_STATUS (AE_TYPE);
450 /* Must have an existing internal object */
452 ObjDesc = AcpiNsGetAttachedObject (Node);
455 return_ACPI_STATUS (AE_NOT_EXIST);
458 /* Internal object exists. Find the handler and remove it */
460 for (i = 0; i < ACPI_NUM_NOTIFY_TYPES; i++)
462 if (HandlerType & (i+1))
464 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
465 if (ACPI_FAILURE (Status))
467 return_ACPI_STATUS (Status);
470 HandlerObj = ObjDesc->CommonNotify.NotifyList[i];
471 PreviousHandlerObj = NULL;
473 /* Attempt to find the handler in the handler list */
476 (HandlerObj->Notify.Handler != Handler))
478 PreviousHandlerObj = HandlerObj;
479 HandlerObj = HandlerObj->Notify.Next[i];
484 Status = AE_NOT_EXIST;
488 /* Remove the handler object from the list */
490 if (PreviousHandlerObj) /* Handler is not at the list head */
492 PreviousHandlerObj->Notify.Next[i] =
493 HandlerObj->Notify.Next[i];
495 else /* Handler is at the list head */
497 ObjDesc->CommonNotify.NotifyList[i] =
498 HandlerObj->Notify.Next[i];
501 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
503 /* Make sure all deferred notify tasks are completed */
505 AcpiOsWaitEventsComplete ();
506 AcpiUtRemoveReference (HandlerObj);
510 return_ACPI_STATUS (Status);
514 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
515 return_ACPI_STATUS (Status);
518 ACPI_EXPORT_SYMBOL (AcpiRemoveNotifyHandler)
521 /*******************************************************************************
523 * FUNCTION: AcpiInstallExceptionHandler
525 * PARAMETERS: Handler - Pointer to the handler function for the
530 * DESCRIPTION: Saves the pointer to the handler function
532 ******************************************************************************/
535 AcpiInstallExceptionHandler (
536 ACPI_EXCEPTION_HANDLER Handler)
541 ACPI_FUNCTION_TRACE (AcpiInstallExceptionHandler);
544 Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
545 if (ACPI_FAILURE (Status))
547 return_ACPI_STATUS (Status);
550 /* Don't allow two handlers. */
552 if (AcpiGbl_ExceptionHandler)
554 Status = AE_ALREADY_EXISTS;
558 /* Install the handler */
560 AcpiGbl_ExceptionHandler = Handler;
563 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
564 return_ACPI_STATUS (Status);
567 ACPI_EXPORT_SYMBOL (AcpiInstallExceptionHandler)
570 #if (!ACPI_REDUCED_HARDWARE)
571 /*******************************************************************************
573 * FUNCTION: AcpiInstallSciHandler
575 * PARAMETERS: Address - Address of the handler
576 * Context - Value passed to the handler on each SCI
580 * DESCRIPTION: Install a handler for a System Control Interrupt.
582 ******************************************************************************/
585 AcpiInstallSciHandler (
586 ACPI_SCI_HANDLER Address,
589 ACPI_SCI_HANDLER_INFO *NewSciHandler;
590 ACPI_SCI_HANDLER_INFO *SciHandler;
591 ACPI_CPU_FLAGS Flags;
595 ACPI_FUNCTION_TRACE (AcpiInstallSciHandler);
600 return_ACPI_STATUS (AE_BAD_PARAMETER);
603 /* Allocate and init a handler object */
605 NewSciHandler = ACPI_ALLOCATE (sizeof (ACPI_SCI_HANDLER_INFO));
608 return_ACPI_STATUS (AE_NO_MEMORY);
611 NewSciHandler->Address = Address;
612 NewSciHandler->Context = Context;
614 Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
615 if (ACPI_FAILURE (Status))
620 /* Lock list during installation */
622 Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
623 SciHandler = AcpiGbl_SciHandlerList;
625 /* Ensure handler does not already exist */
629 if (Address == SciHandler->Address)
631 Status = AE_ALREADY_EXISTS;
635 SciHandler = SciHandler->Next;
638 /* Install the new handler into the global list (at head) */
640 NewSciHandler->Next = AcpiGbl_SciHandlerList;
641 AcpiGbl_SciHandlerList = NewSciHandler;
646 AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
647 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
650 if (ACPI_FAILURE (Status))
652 ACPI_FREE (NewSciHandler);
654 return_ACPI_STATUS (Status);
657 ACPI_EXPORT_SYMBOL (AcpiInstallSciHandler)
660 /*******************************************************************************
662 * FUNCTION: AcpiRemoveSciHandler
664 * PARAMETERS: Address - Address of the handler
668 * DESCRIPTION: Remove a handler for a System Control Interrupt.
670 ******************************************************************************/
673 AcpiRemoveSciHandler (
674 ACPI_SCI_HANDLER Address)
676 ACPI_SCI_HANDLER_INFO *PrevSciHandler;
677 ACPI_SCI_HANDLER_INFO *NextSciHandler;
678 ACPI_CPU_FLAGS Flags;
682 ACPI_FUNCTION_TRACE (AcpiRemoveSciHandler);
687 return_ACPI_STATUS (AE_BAD_PARAMETER);
690 Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
691 if (ACPI_FAILURE (Status))
693 return_ACPI_STATUS (Status);
696 /* Remove the SCI handler with lock */
698 Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
700 PrevSciHandler = NULL;
701 NextSciHandler = AcpiGbl_SciHandlerList;
702 while (NextSciHandler)
704 if (NextSciHandler->Address == Address)
706 /* Unlink and free the SCI handler info block */
710 PrevSciHandler->Next = NextSciHandler->Next;
714 AcpiGbl_SciHandlerList = NextSciHandler->Next;
717 AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
718 ACPI_FREE (NextSciHandler);
722 PrevSciHandler = NextSciHandler;
723 NextSciHandler = NextSciHandler->Next;
726 AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
727 Status = AE_NOT_EXIST;
731 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
732 return_ACPI_STATUS (Status);
735 ACPI_EXPORT_SYMBOL (AcpiRemoveSciHandler)
738 /*******************************************************************************
740 * FUNCTION: AcpiInstallGlobalEventHandler
742 * PARAMETERS: Handler - Pointer to the global event handler function
743 * Context - Value passed to the handler on each event
747 * DESCRIPTION: Saves the pointer to the handler function. The global handler
748 * is invoked upon each incoming GPE and Fixed Event. It is
749 * invoked at interrupt level at the time of the event dispatch.
750 * Can be used to update event counters, etc.
752 ******************************************************************************/
755 AcpiInstallGlobalEventHandler (
756 ACPI_GBL_EVENT_HANDLER Handler,
762 ACPI_FUNCTION_TRACE (AcpiInstallGlobalEventHandler);
765 /* Parameter validation */
769 return_ACPI_STATUS (AE_BAD_PARAMETER);
772 Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
773 if (ACPI_FAILURE (Status))
775 return_ACPI_STATUS (Status);
778 /* Don't allow two handlers. */
780 if (AcpiGbl_GlobalEventHandler)
782 Status = AE_ALREADY_EXISTS;
786 AcpiGbl_GlobalEventHandler = Handler;
787 AcpiGbl_GlobalEventHandlerContext = Context;
791 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
792 return_ACPI_STATUS (Status);
795 ACPI_EXPORT_SYMBOL (AcpiInstallGlobalEventHandler)
798 /*******************************************************************************
800 * FUNCTION: AcpiInstallFixedEventHandler
802 * PARAMETERS: Event - Event type to enable.
803 * Handler - Pointer to the handler function for the
805 * Context - Value passed to the handler on each GPE
809 * DESCRIPTION: Saves the pointer to the handler function and then enables the
812 ******************************************************************************/
815 AcpiInstallFixedEventHandler (
817 ACPI_EVENT_HANDLER Handler,
823 ACPI_FUNCTION_TRACE (AcpiInstallFixedEventHandler);
826 /* Parameter validation */
828 if (Event > ACPI_EVENT_MAX)
830 return_ACPI_STATUS (AE_BAD_PARAMETER);
833 Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
834 if (ACPI_FAILURE (Status))
836 return_ACPI_STATUS (Status);
839 /* Do not allow multiple handlers */
841 if (AcpiGbl_FixedEventHandlers[Event].Handler)
843 Status = AE_ALREADY_EXISTS;
847 /* Install the handler before enabling the event */
849 AcpiGbl_FixedEventHandlers[Event].Handler = Handler;
850 AcpiGbl_FixedEventHandlers[Event].Context = Context;
852 Status = AcpiEnableEvent (Event, 0);
853 if (ACPI_FAILURE (Status))
855 ACPI_WARNING ((AE_INFO,
856 "Could not enable fixed event - %s (%u)",
857 AcpiUtGetEventName (Event), Event));
859 /* Remove the handler */
861 AcpiGbl_FixedEventHandlers[Event].Handler = NULL;
862 AcpiGbl_FixedEventHandlers[Event].Context = NULL;
866 ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
867 "Enabled fixed event %s (%X), Handler=%p\n",
868 AcpiUtGetEventName (Event), Event, Handler));
873 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
874 return_ACPI_STATUS (Status);
877 ACPI_EXPORT_SYMBOL (AcpiInstallFixedEventHandler)
880 /*******************************************************************************
882 * FUNCTION: AcpiRemoveFixedEventHandler
884 * PARAMETERS: Event - Event type to disable.
885 * Handler - Address of the handler
889 * DESCRIPTION: Disables the event and unregisters the event handler.
891 ******************************************************************************/
894 AcpiRemoveFixedEventHandler (
896 ACPI_EVENT_HANDLER Handler)
898 ACPI_STATUS Status = AE_OK;
901 ACPI_FUNCTION_TRACE (AcpiRemoveFixedEventHandler);
904 /* Parameter validation */
906 if (Event > ACPI_EVENT_MAX)
908 return_ACPI_STATUS (AE_BAD_PARAMETER);
911 Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
912 if (ACPI_FAILURE (Status))
914 return_ACPI_STATUS (Status);
917 /* Disable the event before removing the handler */
919 Status = AcpiDisableEvent (Event, 0);
921 /* Always Remove the handler */
923 AcpiGbl_FixedEventHandlers[Event].Handler = NULL;
924 AcpiGbl_FixedEventHandlers[Event].Context = NULL;
926 if (ACPI_FAILURE (Status))
928 ACPI_WARNING ((AE_INFO,
929 "Could not disable fixed event - %s (%u)",
930 AcpiUtGetEventName (Event), Event));
934 ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
935 "Disabled fixed event - %s (%X)\n",
936 AcpiUtGetEventName (Event), Event));
939 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
940 return_ACPI_STATUS (Status);
943 ACPI_EXPORT_SYMBOL (AcpiRemoveFixedEventHandler)
946 /*******************************************************************************
948 * FUNCTION: AcpiEvInstallGpeHandler
950 * PARAMETERS: GpeDevice - Namespace node for the GPE (NULL for FADT
952 * GpeNumber - The GPE number within the GPE block
953 * Type - Whether this GPE should be treated as an
954 * edge- or level-triggered interrupt.
955 * IsRawHandler - Whether this GPE should be handled using
956 * the special GPE handler mode.
957 * Address - Address of the handler
958 * Context - Value passed to the handler on each GPE
962 * DESCRIPTION: Internal function to install a handler for a General Purpose
965 ******************************************************************************/
968 AcpiEvInstallGpeHandler (
969 ACPI_HANDLE GpeDevice,
972 BOOLEAN IsRawHandler,
973 ACPI_GPE_HANDLER Address,
976 ACPI_GPE_EVENT_INFO *GpeEventInfo;
977 ACPI_GPE_HANDLER_INFO *Handler;
979 ACPI_CPU_FLAGS Flags;
982 ACPI_FUNCTION_TRACE (EvInstallGpeHandler);
985 /* Parameter validation */
987 if ((!Address) || (Type & ~ACPI_GPE_XRUPT_TYPE_MASK))
989 return_ACPI_STATUS (AE_BAD_PARAMETER);
992 Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
993 if (ACPI_FAILURE (Status))
995 return_ACPI_STATUS (Status);
998 /* Allocate and init handler object (before lock) */
1000 Handler = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_GPE_HANDLER_INFO));
1003 Status = AE_NO_MEMORY;
1007 Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
1009 /* Ensure that we have a valid GPE number */
1011 GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
1014 Status = AE_BAD_PARAMETER;
1018 /* Make sure that there isn't a handler there already */
1020 if ((ACPI_GPE_DISPATCH_TYPE (GpeEventInfo->Flags) ==
1021 ACPI_GPE_DISPATCH_HANDLER) ||
1022 (ACPI_GPE_DISPATCH_TYPE (GpeEventInfo->Flags) ==
1023 ACPI_GPE_DISPATCH_RAW_HANDLER))
1025 Status = AE_ALREADY_EXISTS;
1029 Handler->Address = Address;
1030 Handler->Context = Context;
1031 Handler->MethodNode = GpeEventInfo->Dispatch.MethodNode;
1032 Handler->OriginalFlags = (UINT8) (GpeEventInfo->Flags &
1033 (ACPI_GPE_XRUPT_TYPE_MASK | ACPI_GPE_DISPATCH_MASK));
1036 * If the GPE is associated with a method, it may have been enabled
1037 * automatically during initialization, in which case it has to be
1038 * disabled now to avoid spurious execution of the handler.
1040 if (((ACPI_GPE_DISPATCH_TYPE (Handler->OriginalFlags) ==
1041 ACPI_GPE_DISPATCH_METHOD) ||
1042 (ACPI_GPE_DISPATCH_TYPE (Handler->OriginalFlags) ==
1043 ACPI_GPE_DISPATCH_NOTIFY)) &&
1044 GpeEventInfo->RuntimeCount)
1046 Handler->OriginallyEnabled = TRUE;
1047 (void) AcpiEvRemoveGpeReference (GpeEventInfo);
1049 /* Sanity check of original type against new type */
1051 if (Type != (UINT32) (GpeEventInfo->Flags & ACPI_GPE_XRUPT_TYPE_MASK))
1053 ACPI_WARNING ((AE_INFO, "GPE type mismatch (level/edge)"));
1057 /* Install the handler */
1059 GpeEventInfo->Dispatch.Handler = Handler;
1061 /* Setup up dispatch flags to indicate handler (vs. method/notify) */
1063 GpeEventInfo->Flags &= ~(ACPI_GPE_XRUPT_TYPE_MASK | ACPI_GPE_DISPATCH_MASK);
1064 GpeEventInfo->Flags |= (UINT8) (Type | (IsRawHandler ?
1065 ACPI_GPE_DISPATCH_RAW_HANDLER : ACPI_GPE_DISPATCH_HANDLER));
1067 AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
1071 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
1072 return_ACPI_STATUS (Status);
1075 AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
1076 ACPI_FREE (Handler);
1081 /*******************************************************************************
1083 * FUNCTION: AcpiInstallGpeHandler
1085 * PARAMETERS: GpeDevice - Namespace node for the GPE (NULL for FADT
1087 * GpeNumber - The GPE number within the GPE block
1088 * Type - Whether this GPE should be treated as an
1089 * edge- or level-triggered interrupt.
1090 * Address - Address of the handler
1091 * Context - Value passed to the handler on each GPE
1095 * DESCRIPTION: Install a handler for a General Purpose Event.
1097 ******************************************************************************/
1100 AcpiInstallGpeHandler (
1101 ACPI_HANDLE GpeDevice,
1104 ACPI_GPE_HANDLER Address,
1110 ACPI_FUNCTION_TRACE (AcpiInstallGpeHandler);
1113 Status = AcpiEvInstallGpeHandler (GpeDevice, GpeNumber, Type,
1114 FALSE, Address, Context);
1116 return_ACPI_STATUS (Status);
1119 ACPI_EXPORT_SYMBOL (AcpiInstallGpeHandler)
1122 /*******************************************************************************
1124 * FUNCTION: AcpiInstallGpeRawHandler
1126 * PARAMETERS: GpeDevice - Namespace node for the GPE (NULL for FADT
1128 * GpeNumber - The GPE number within the GPE block
1129 * Type - Whether this GPE should be treated as an
1130 * edge- or level-triggered interrupt.
1131 * Address - Address of the handler
1132 * Context - Value passed to the handler on each GPE
1136 * DESCRIPTION: Install a handler for a General Purpose Event.
1138 ******************************************************************************/
1141 AcpiInstallGpeRawHandler (
1142 ACPI_HANDLE GpeDevice,
1145 ACPI_GPE_HANDLER Address,
1151 ACPI_FUNCTION_TRACE (AcpiInstallGpeRawHandler);
1154 Status = AcpiEvInstallGpeHandler (GpeDevice, GpeNumber, Type,
1155 TRUE, Address, Context);
1157 return_ACPI_STATUS (Status);
1160 ACPI_EXPORT_SYMBOL (AcpiInstallGpeRawHandler)
1163 /*******************************************************************************
1165 * FUNCTION: AcpiRemoveGpeHandler
1167 * PARAMETERS: GpeDevice - Namespace node for the GPE (NULL for FADT
1169 * GpeNumber - The event to remove a handler
1170 * Address - Address of the handler
1174 * DESCRIPTION: Remove a handler for a General Purpose AcpiEvent.
1176 ******************************************************************************/
1179 AcpiRemoveGpeHandler (
1180 ACPI_HANDLE GpeDevice,
1182 ACPI_GPE_HANDLER Address)
1184 ACPI_GPE_EVENT_INFO *GpeEventInfo;
1185 ACPI_GPE_HANDLER_INFO *Handler;
1187 ACPI_CPU_FLAGS Flags;
1190 ACPI_FUNCTION_TRACE (AcpiRemoveGpeHandler);
1193 /* Parameter validation */
1197 return_ACPI_STATUS (AE_BAD_PARAMETER);
1200 Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
1201 if (ACPI_FAILURE (Status))
1203 return_ACPI_STATUS (Status);
1206 Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
1208 /* Ensure that we have a valid GPE number */
1210 GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
1213 Status = AE_BAD_PARAMETER;
1217 /* Make sure that a handler is indeed installed */
1219 if ((ACPI_GPE_DISPATCH_TYPE (GpeEventInfo->Flags) !=
1220 ACPI_GPE_DISPATCH_HANDLER) &&
1221 (ACPI_GPE_DISPATCH_TYPE (GpeEventInfo->Flags) !=
1222 ACPI_GPE_DISPATCH_RAW_HANDLER))
1224 Status = AE_NOT_EXIST;
1228 /* Make sure that the installed handler is the same */
1230 if (GpeEventInfo->Dispatch.Handler->Address != Address)
1232 Status = AE_BAD_PARAMETER;
1236 /* Remove the handler */
1238 Handler = GpeEventInfo->Dispatch.Handler;
1239 GpeEventInfo->Dispatch.Handler = NULL;
1241 /* Restore Method node (if any), set dispatch flags */
1243 GpeEventInfo->Dispatch.MethodNode = Handler->MethodNode;
1244 GpeEventInfo->Flags &=
1245 ~(ACPI_GPE_XRUPT_TYPE_MASK | ACPI_GPE_DISPATCH_MASK);
1246 GpeEventInfo->Flags |= Handler->OriginalFlags;
1249 * If the GPE was previously associated with a method and it was
1250 * enabled, it should be enabled at this point to restore the
1251 * post-initialization configuration.
1253 if (((ACPI_GPE_DISPATCH_TYPE (Handler->OriginalFlags) ==
1254 ACPI_GPE_DISPATCH_METHOD) ||
1255 (ACPI_GPE_DISPATCH_TYPE (Handler->OriginalFlags) ==
1256 ACPI_GPE_DISPATCH_NOTIFY)) &&
1257 Handler->OriginallyEnabled)
1259 (void) AcpiEvAddGpeReference (GpeEventInfo);
1260 if (ACPI_GPE_IS_POLLING_NEEDED (GpeEventInfo))
1262 /* Poll edge triggered GPEs to handle existing events */
1264 AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
1265 (void) AcpiEvDetectGpe (
1266 GpeDevice, GpeEventInfo, GpeNumber);
1267 Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
1271 AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
1272 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
1274 /* Make sure all deferred GPE tasks are completed */
1276 AcpiOsWaitEventsComplete ();
1278 /* Now we can free the handler object */
1280 ACPI_FREE (Handler);
1281 return_ACPI_STATUS (Status);
1284 AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
1285 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
1286 return_ACPI_STATUS (Status);
1289 ACPI_EXPORT_SYMBOL (AcpiRemoveGpeHandler)
1292 /*******************************************************************************
1294 * FUNCTION: AcpiAcquireGlobalLock
1296 * PARAMETERS: Timeout - How long the caller is willing to wait
1297 * Handle - Where the handle to the lock is returned
1302 * DESCRIPTION: Acquire the ACPI Global Lock
1304 * Note: Allows callers with the same thread ID to acquire the global lock
1305 * multiple times. In other words, externally, the behavior of the global lock
1306 * is identical to an AML mutex. On the first acquire, a new handle is
1307 * returned. On any subsequent calls to acquire by the same thread, the same
1308 * handle is returned.
1310 ******************************************************************************/
1313 AcpiAcquireGlobalLock (
1322 return (AE_BAD_PARAMETER);
1325 /* Must lock interpreter to prevent race conditions */
1327 AcpiExEnterInterpreter ();
1329 Status = AcpiExAcquireMutexObject (Timeout,
1330 AcpiGbl_GlobalLockMutex, AcpiOsGetThreadId ());
1332 if (ACPI_SUCCESS (Status))
1334 /* Return the global lock handle (updated in AcpiEvAcquireGlobalLock) */
1336 *Handle = AcpiGbl_GlobalLockHandle;
1339 AcpiExExitInterpreter ();
1343 ACPI_EXPORT_SYMBOL (AcpiAcquireGlobalLock)
1346 /*******************************************************************************
1348 * FUNCTION: AcpiReleaseGlobalLock
1350 * PARAMETERS: Handle - Returned from AcpiAcquireGlobalLock
1354 * DESCRIPTION: Release the ACPI Global Lock. The handle must be valid.
1356 ******************************************************************************/
1359 AcpiReleaseGlobalLock (
1365 if (!Handle || (Handle != AcpiGbl_GlobalLockHandle))
1367 return (AE_NOT_ACQUIRED);
1370 Status = AcpiExReleaseMutexObject (AcpiGbl_GlobalLockMutex);
1374 ACPI_EXPORT_SYMBOL (AcpiReleaseGlobalLock)
1376 #endif /* !ACPI_REDUCED_HARDWARE */