i386/identcpu.c: Add VIA Nano support
[dragonfly.git] / sys / contrib / dev / acpica-unix-20061109 / events / evxface.c
blobcc9bba11736553d324d16d676cf5316bc1968eed
1 /******************************************************************************
3 * Module Name: evxface - External interfaces for ACPI events
4 * $Revision: 1.162 $
6 *****************************************************************************/
8 /******************************************************************************
10 * 1. Copyright Notice
12 * Some or all of this work - Copyright (c) 1999 - 2006, Intel Corp.
13 * All rights reserved.
15 * 2. License
17 * 2.1. This is your license from Intel Corp. under its intellectual property
18 * rights. You may have additional license terms from the party that provided
19 * you this software, covering your right to use that party's intellectual
20 * property rights.
22 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
23 * copy of the source code appearing in this file ("Covered Code") an
24 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
25 * base code distributed originally by Intel ("Original Intel Code") to copy,
26 * make derivatives, distribute, use and display any portion of the Covered
27 * Code in any form, with the right to sublicense such rights; and
29 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
30 * license (with the right to sublicense), under only those claims of Intel
31 * patents that are infringed by the Original Intel Code, to make, use, sell,
32 * offer to sell, and import the Covered Code and derivative works thereof
33 * solely to the minimum extent necessary to exercise the above copyright
34 * license, and in no event shall the patent license extend to any additions
35 * to or modifications of the Original Intel Code. No other license or right
36 * is granted directly or by implication, estoppel or otherwise;
38 * The above copyright and patent license is granted only if the following
39 * conditions are met:
41 * 3. Conditions
43 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
44 * Redistribution of source code of any substantial portion of the Covered
45 * Code or modification with rights to further distribute source must include
46 * the above Copyright Notice, the above License, this list of Conditions,
47 * and the following Disclaimer and Export Compliance provision. In addition,
48 * Licensee must cause all Covered Code to which Licensee contributes to
49 * contain a file documenting the changes Licensee made to create that Covered
50 * Code and the date of any change. Licensee must include in that file the
51 * documentation of any changes made by any predecessor Licensee. Licensee
52 * must include a prominent statement that the modification is derived,
53 * directly or indirectly, from Original Intel Code.
55 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
56 * Redistribution of source code of any substantial portion of the Covered
57 * Code or modification without rights to further distribute source must
58 * include the following Disclaimer and Export Compliance provision in the
59 * documentation and/or other materials provided with distribution. In
60 * addition, Licensee may not authorize further sublicense of source of any
61 * portion of the Covered Code, and must include terms to the effect that the
62 * license from Licensee to its licensee is limited to the intellectual
63 * property embodied in the software Licensee provides to its licensee, and
64 * not to intellectual property embodied in modifications its licensee may
65 * make.
67 * 3.3. Redistribution of Executable. Redistribution in executable form of any
68 * substantial portion of the Covered Code or modification must reproduce the
69 * above Copyright Notice, and the following Disclaimer and Export Compliance
70 * provision in the documentation and/or other materials provided with the
71 * distribution.
73 * 3.4. Intel retains all right, title, and interest in and to the Original
74 * Intel Code.
76 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
77 * Intel shall be used in advertising or otherwise to promote the sale, use or
78 * other dealings in products derived from or relating to the Covered Code
79 * without prior written authorization from Intel.
81 * 4. Disclaimer and Export Compliance
83 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
84 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
85 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
86 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
87 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
88 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
89 * PARTICULAR PURPOSE.
91 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
92 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
93 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
94 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
95 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
96 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
97 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
98 * LIMITED REMEDY.
100 * 4.3. Licensee shall not export, either directly or indirectly, any of this
101 * software or system incorporating such software without first obtaining any
102 * required license or other approval from the U. S. Department of Commerce or
103 * any other agency or department of the United States Government. In the
104 * event Licensee exports any such software from the United States or
105 * re-exports any such software from a foreign destination, Licensee shall
106 * ensure that the distribution and export/re-export of the software is in
107 * compliance with all laws, regulations, orders, or other restrictions of the
108 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
109 * any of its subsidiaries will export/re-export any technical data, process,
110 * software, or service, directly or indirectly, to any country for which the
111 * United States government or any agency thereof requires an export license,
112 * other governmental approval, or letter of assurance, without first obtaining
113 * such license, approval or letter.
115 *****************************************************************************/
118 #define __EVXFACE_C__
120 #include "acpi.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
134 * event
136 * RETURN: Status
138 * DESCRIPTION: Saves the pointer to the handler function
140 ******************************************************************************/
142 ACPI_STATUS
143 AcpiInstallExceptionHandler (
144 ACPI_EXCEPTION_HANDLER Handler)
146 ACPI_STATUS Status;
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;
163 goto Cleanup;
166 /* Install the handler */
168 AcpiGbl_ExceptionHandler = Handler;
170 Cleanup:
171 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
172 return_ACPI_STATUS (Status);
175 ACPI_EXPORT_SYMBOL (AcpiInstallExceptionHandler)
178 /*******************************************************************************
180 * FUNCTION: AcpiInstallFixedEventHandler
182 * PARAMETERS: Event - Event type to enable.
183 * Handler - Pointer to the handler function for the
184 * event
185 * Context - Value passed to the handler on each GPE
187 * RETURN: Status
189 * DESCRIPTION: Saves the pointer to the handler function and then enables the
190 * event.
192 ******************************************************************************/
194 ACPI_STATUS
195 AcpiInstallFixedEventHandler (
196 UINT32 Event,
197 ACPI_EVENT_HANDLER Handler,
198 void *Context)
200 ACPI_STATUS Status;
203 ACPI_FUNCTION_TRACE (AcpiInstallFixedEventHandler);
206 /* Parameter validation */
208 if (Event > ACPI_EVENT_MAX)
210 return_ACPI_STATUS (AE_BAD_PARAMETER);
213 Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
214 if (ACPI_FAILURE (Status))
216 return_ACPI_STATUS (Status);
219 /* Don't allow two handlers. */
221 if (NULL != AcpiGbl_FixedEventHandlers[Event].Handler)
223 Status = AE_ALREADY_EXISTS;
224 goto Cleanup;
227 /* Install the handler before enabling the event */
229 AcpiGbl_FixedEventHandlers[Event].Handler = Handler;
230 AcpiGbl_FixedEventHandlers[Event].Context = Context;
232 Status = AcpiEnableEvent (Event, 0);
233 if (ACPI_FAILURE (Status))
235 ACPI_WARNING ((AE_INFO, "Could not enable fixed event %X", Event));
237 /* Remove the handler */
239 AcpiGbl_FixedEventHandlers[Event].Handler = NULL;
240 AcpiGbl_FixedEventHandlers[Event].Context = NULL;
242 else
244 ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
245 "Enabled fixed event %X, Handler=%p\n", Event, Handler));
249 Cleanup:
250 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
251 return_ACPI_STATUS (Status);
254 ACPI_EXPORT_SYMBOL (AcpiInstallFixedEventHandler)
257 /*******************************************************************************
259 * FUNCTION: AcpiRemoveFixedEventHandler
261 * PARAMETERS: Event - Event type to disable.
262 * Handler - Address of the handler
264 * RETURN: Status
266 * DESCRIPTION: Disables the event and unregisters the event handler.
268 ******************************************************************************/
270 ACPI_STATUS
271 AcpiRemoveFixedEventHandler (
272 UINT32 Event,
273 ACPI_EVENT_HANDLER Handler)
275 ACPI_STATUS Status = AE_OK;
278 ACPI_FUNCTION_TRACE (AcpiRemoveFixedEventHandler);
281 /* Parameter validation */
283 if (Event > ACPI_EVENT_MAX)
285 return_ACPI_STATUS (AE_BAD_PARAMETER);
288 Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
289 if (ACPI_FAILURE (Status))
291 return_ACPI_STATUS (Status);
294 /* Disable the event before removing the handler */
296 Status = AcpiDisableEvent (Event, 0);
298 /* Always Remove the handler */
300 AcpiGbl_FixedEventHandlers[Event].Handler = NULL;
301 AcpiGbl_FixedEventHandlers[Event].Context = NULL;
303 if (ACPI_FAILURE (Status))
305 ACPI_WARNING ((AE_INFO,
306 "Could not write to fixed event enable register %X", Event));
308 else
310 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Disabled fixed event %X\n", Event));
313 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
314 return_ACPI_STATUS (Status);
317 ACPI_EXPORT_SYMBOL (AcpiRemoveFixedEventHandler)
320 /*******************************************************************************
322 * FUNCTION: AcpiInstallNotifyHandler
324 * PARAMETERS: Device - The device for which notifies will be handled
325 * HandlerType - The type of handler:
326 * ACPI_SYSTEM_NOTIFY: SystemHandler (00-7f)
327 * ACPI_DEVICE_NOTIFY: DriverHandler (80-ff)
328 * ACPI_ALL_NOTIFY: both system and device
329 * Handler - Address of the handler
330 * Context - Value passed to the handler on each GPE
332 * RETURN: Status
334 * DESCRIPTION: Install a handler for notifies on an ACPI device
336 ******************************************************************************/
338 ACPI_STATUS
339 AcpiInstallNotifyHandler (
340 ACPI_HANDLE Device,
341 UINT32 HandlerType,
342 ACPI_NOTIFY_HANDLER Handler,
343 void *Context)
345 ACPI_OPERAND_OBJECT *ObjDesc;
346 ACPI_OPERAND_OBJECT *NotifyObj;
347 ACPI_NAMESPACE_NODE *Node;
348 ACPI_STATUS Status;
351 ACPI_FUNCTION_TRACE (AcpiInstallNotifyHandler);
354 /* Parameter validation */
356 if ((!Device) ||
357 (!Handler) ||
358 (HandlerType > ACPI_MAX_NOTIFY_HANDLER_TYPE))
360 return_ACPI_STATUS (AE_BAD_PARAMETER);
363 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
364 if (ACPI_FAILURE (Status))
366 return_ACPI_STATUS (Status);
369 /* Convert and validate the device handle */
371 Node = AcpiNsMapHandleToNode (Device);
372 if (!Node)
374 Status = AE_BAD_PARAMETER;
375 goto UnlockAndExit;
379 * Root Object:
380 * Registering a notify handler on the root object indicates that the
381 * caller wishes to receive notifications for all objects. Note that
382 * only one <external> global handler can be regsitered (per notify type).
384 if (Device == ACPI_ROOT_OBJECT)
386 /* Make sure the handler is not already installed */
388 if (((HandlerType & ACPI_SYSTEM_NOTIFY) &&
389 AcpiGbl_SystemNotify.Handler) ||
390 ((HandlerType & ACPI_DEVICE_NOTIFY) &&
391 AcpiGbl_DeviceNotify.Handler))
393 Status = AE_ALREADY_EXISTS;
394 goto UnlockAndExit;
397 if (HandlerType & ACPI_SYSTEM_NOTIFY)
399 AcpiGbl_SystemNotify.Node = Node;
400 AcpiGbl_SystemNotify.Handler = Handler;
401 AcpiGbl_SystemNotify.Context = Context;
404 if (HandlerType & ACPI_DEVICE_NOTIFY)
406 AcpiGbl_DeviceNotify.Node = Node;
407 AcpiGbl_DeviceNotify.Handler = Handler;
408 AcpiGbl_DeviceNotify.Context = Context;
411 /* Global notify handler installed */
415 * All Other Objects:
416 * Caller will only receive notifications specific to the target object.
417 * Note that only certain object types can receive notifications.
419 else
421 /* Notifies allowed on this object? */
423 if (!AcpiEvIsNotifyObject (Node))
425 Status = AE_TYPE;
426 goto UnlockAndExit;
429 /* Check for an existing internal object */
431 ObjDesc = AcpiNsGetAttachedObject (Node);
432 if (ObjDesc)
434 /* Object exists - make sure there's no handler */
436 if (((HandlerType & ACPI_SYSTEM_NOTIFY) &&
437 ObjDesc->CommonNotify.SystemNotify) ||
438 ((HandlerType & ACPI_DEVICE_NOTIFY) &&
439 ObjDesc->CommonNotify.DeviceNotify))
441 Status = AE_ALREADY_EXISTS;
442 goto UnlockAndExit;
445 else
447 /* Create a new object */
449 ObjDesc = AcpiUtCreateInternalObject (Node->Type);
450 if (!ObjDesc)
452 Status = AE_NO_MEMORY;
453 goto UnlockAndExit;
456 /* Attach new object to the Node */
458 Status = AcpiNsAttachObject (Device, ObjDesc, Node->Type);
460 /* Remove local reference to the object */
462 AcpiUtRemoveReference (ObjDesc);
463 if (ACPI_FAILURE (Status))
465 goto UnlockAndExit;
469 /* Install the handler */
471 NotifyObj = AcpiUtCreateInternalObject (ACPI_TYPE_LOCAL_NOTIFY);
472 if (!NotifyObj)
474 Status = AE_NO_MEMORY;
475 goto UnlockAndExit;
478 NotifyObj->Notify.Node = Node;
479 NotifyObj->Notify.Handler = Handler;
480 NotifyObj->Notify.Context = Context;
482 if (HandlerType & ACPI_SYSTEM_NOTIFY)
484 ObjDesc->CommonNotify.SystemNotify = NotifyObj;
487 if (HandlerType & ACPI_DEVICE_NOTIFY)
489 ObjDesc->CommonNotify.DeviceNotify = NotifyObj;
492 if (HandlerType == ACPI_ALL_NOTIFY)
494 /* Extra ref if installed in both */
496 AcpiUtAddReference (NotifyObj);
501 UnlockAndExit:
502 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
503 return_ACPI_STATUS (Status);
506 ACPI_EXPORT_SYMBOL (AcpiInstallNotifyHandler)
509 /*******************************************************************************
511 * FUNCTION: AcpiRemoveNotifyHandler
513 * PARAMETERS: Device - The device for which notifies will be handled
514 * HandlerType - The type of handler:
515 * ACPI_SYSTEM_NOTIFY: SystemHandler (00-7f)
516 * ACPI_DEVICE_NOTIFY: DriverHandler (80-ff)
517 * ACPI_ALL_NOTIFY: both system and device
518 * Handler - Address of the handler
520 * RETURN: Status
522 * DESCRIPTION: Remove a handler for notifies on an ACPI device
524 ******************************************************************************/
526 ACPI_STATUS
527 AcpiRemoveNotifyHandler (
528 ACPI_HANDLE Device,
529 UINT32 HandlerType,
530 ACPI_NOTIFY_HANDLER Handler)
532 ACPI_OPERAND_OBJECT *NotifyObj;
533 ACPI_OPERAND_OBJECT *ObjDesc;
534 ACPI_NAMESPACE_NODE *Node;
535 ACPI_STATUS Status;
538 ACPI_FUNCTION_TRACE (AcpiRemoveNotifyHandler);
541 /* Parameter validation */
543 if ((!Device) ||
544 (!Handler) ||
545 (HandlerType > ACPI_MAX_NOTIFY_HANDLER_TYPE))
547 return_ACPI_STATUS (AE_BAD_PARAMETER);
550 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
551 if (ACPI_FAILURE (Status))
553 return_ACPI_STATUS (Status);
556 /* Convert and validate the device handle */
558 Node = AcpiNsMapHandleToNode (Device);
559 if (!Node)
561 Status = AE_BAD_PARAMETER;
562 goto UnlockAndExit;
565 /* Root Object */
567 if (Device == ACPI_ROOT_OBJECT)
569 ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
570 "Removing notify handler for namespace root object\n"));
572 if (((HandlerType & ACPI_SYSTEM_NOTIFY) &&
573 !AcpiGbl_SystemNotify.Handler) ||
574 ((HandlerType & ACPI_DEVICE_NOTIFY) &&
575 !AcpiGbl_DeviceNotify.Handler))
577 Status = AE_NOT_EXIST;
578 goto UnlockAndExit;
581 if (HandlerType & ACPI_SYSTEM_NOTIFY)
583 AcpiGbl_SystemNotify.Node = NULL;
584 AcpiGbl_SystemNotify.Handler = NULL;
585 AcpiGbl_SystemNotify.Context = NULL;
588 if (HandlerType & ACPI_DEVICE_NOTIFY)
590 AcpiGbl_DeviceNotify.Node = NULL;
591 AcpiGbl_DeviceNotify.Handler = NULL;
592 AcpiGbl_DeviceNotify.Context = NULL;
596 /* All Other Objects */
598 else
600 /* Notifies allowed on this object? */
602 if (!AcpiEvIsNotifyObject (Node))
604 Status = AE_TYPE;
605 goto UnlockAndExit;
608 /* Check for an existing internal object */
610 ObjDesc = AcpiNsGetAttachedObject (Node);
611 if (!ObjDesc)
613 Status = AE_NOT_EXIST;
614 goto UnlockAndExit;
617 /* Object exists - make sure there's an existing handler */
619 if (HandlerType & ACPI_SYSTEM_NOTIFY)
621 NotifyObj = ObjDesc->CommonNotify.SystemNotify;
622 if (!NotifyObj)
624 Status = AE_NOT_EXIST;
625 goto UnlockAndExit;
628 if (NotifyObj->Notify.Handler != Handler)
630 Status = AE_BAD_PARAMETER;
631 goto UnlockAndExit;
634 /* Remove the handler */
636 ObjDesc->CommonNotify.SystemNotify = NULL;
637 AcpiUtRemoveReference (NotifyObj);
640 if (HandlerType & ACPI_DEVICE_NOTIFY)
642 NotifyObj = ObjDesc->CommonNotify.DeviceNotify;
643 if (!NotifyObj)
645 Status = AE_NOT_EXIST;
646 goto UnlockAndExit;
649 if (NotifyObj->Notify.Handler != Handler)
651 Status = AE_BAD_PARAMETER;
652 goto UnlockAndExit;
655 /* Remove the handler */
657 ObjDesc->CommonNotify.DeviceNotify = NULL;
658 AcpiUtRemoveReference (NotifyObj);
663 UnlockAndExit:
664 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
665 return_ACPI_STATUS (Status);
668 ACPI_EXPORT_SYMBOL (AcpiRemoveNotifyHandler)
671 /*******************************************************************************
673 * FUNCTION: AcpiInstallGpeHandler
675 * PARAMETERS: GpeDevice - Namespace node for the GPE (NULL for FADT
676 * defined GPEs)
677 * GpeNumber - The GPE number within the GPE block
678 * Type - Whether this GPE should be treated as an
679 * edge- or level-triggered interrupt.
680 * Address - Address of the handler
681 * Context - Value passed to the handler on each GPE
683 * RETURN: Status
685 * DESCRIPTION: Install a handler for a General Purpose Event.
687 ******************************************************************************/
689 ACPI_STATUS
690 AcpiInstallGpeHandler (
691 ACPI_HANDLE GpeDevice,
692 UINT32 GpeNumber,
693 UINT32 Type,
694 ACPI_EVENT_HANDLER Address,
695 void *Context)
697 ACPI_GPE_EVENT_INFO *GpeEventInfo;
698 ACPI_HANDLER_INFO *Handler;
699 ACPI_STATUS Status;
700 ACPI_CPU_FLAGS Flags;
703 ACPI_FUNCTION_TRACE (AcpiInstallGpeHandler);
706 /* Parameter validation */
708 if ((!Address) || (Type > ACPI_GPE_XRUPT_TYPE_MASK))
710 return_ACPI_STATUS (AE_BAD_PARAMETER);
713 Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
714 if (ACPI_FAILURE (Status))
716 return_ACPI_STATUS (Status);
719 /* Ensure that we have a valid GPE number */
721 GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
722 if (!GpeEventInfo)
724 Status = AE_BAD_PARAMETER;
725 goto UnlockAndExit;
728 /* Make sure that there isn't a handler there already */
730 if ((GpeEventInfo->Flags & ACPI_GPE_DISPATCH_MASK) == ACPI_GPE_DISPATCH_HANDLER)
732 Status = AE_ALREADY_EXISTS;
733 goto UnlockAndExit;
736 /* Allocate and init handler object */
738 Handler = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_HANDLER_INFO));
739 if (!Handler)
741 Status = AE_NO_MEMORY;
742 goto UnlockAndExit;
745 Handler->Address = Address;
746 Handler->Context = Context;
747 Handler->MethodNode = GpeEventInfo->Dispatch.MethodNode;
749 /* Disable the GPE before installing the handler */
751 Status = AcpiEvDisableGpe (GpeEventInfo);
752 if (ACPI_FAILURE (Status))
754 goto UnlockAndExit;
757 /* Install the handler */
759 Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
760 GpeEventInfo->Dispatch.Handler = Handler;
762 /* Setup up dispatch flags to indicate handler (vs. method) */
764 GpeEventInfo->Flags &= ~(ACPI_GPE_XRUPT_TYPE_MASK | ACPI_GPE_DISPATCH_MASK); /* Clear bits */
765 GpeEventInfo->Flags |= (UINT8) (Type | ACPI_GPE_DISPATCH_HANDLER);
767 AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
770 UnlockAndExit:
771 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
772 return_ACPI_STATUS (Status);
775 ACPI_EXPORT_SYMBOL (AcpiInstallGpeHandler)
778 /*******************************************************************************
780 * FUNCTION: AcpiRemoveGpeHandler
782 * PARAMETERS: GpeDevice - Namespace node for the GPE (NULL for FADT
783 * defined GPEs)
784 * GpeNumber - The event to remove a handler
785 * Address - Address of the handler
787 * RETURN: Status
789 * DESCRIPTION: Remove a handler for a General Purpose AcpiEvent.
791 ******************************************************************************/
793 ACPI_STATUS
794 AcpiRemoveGpeHandler (
795 ACPI_HANDLE GpeDevice,
796 UINT32 GpeNumber,
797 ACPI_EVENT_HANDLER Address)
799 ACPI_GPE_EVENT_INFO *GpeEventInfo;
800 ACPI_HANDLER_INFO *Handler;
801 ACPI_STATUS Status;
802 ACPI_CPU_FLAGS Flags;
805 ACPI_FUNCTION_TRACE (AcpiRemoveGpeHandler);
808 /* Parameter validation */
810 if (!Address)
812 return_ACPI_STATUS (AE_BAD_PARAMETER);
815 Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
816 if (ACPI_FAILURE (Status))
818 return_ACPI_STATUS (Status);
821 /* Ensure that we have a valid GPE number */
823 GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
824 if (!GpeEventInfo)
826 Status = AE_BAD_PARAMETER;
827 goto UnlockAndExit;
830 /* Make sure that a handler is indeed installed */
832 if ((GpeEventInfo->Flags & ACPI_GPE_DISPATCH_MASK) != ACPI_GPE_DISPATCH_HANDLER)
834 Status = AE_NOT_EXIST;
835 goto UnlockAndExit;
838 /* Make sure that the installed handler is the same */
840 if (GpeEventInfo->Dispatch.Handler->Address != Address)
842 Status = AE_BAD_PARAMETER;
843 goto UnlockAndExit;
846 /* Disable the GPE before removing the handler */
848 Status = AcpiEvDisableGpe (GpeEventInfo);
849 if (ACPI_FAILURE (Status))
851 goto UnlockAndExit;
854 /* Remove the handler */
856 Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
857 Handler = GpeEventInfo->Dispatch.Handler;
859 /* Restore Method node (if any), set dispatch flags */
861 GpeEventInfo->Dispatch.MethodNode = Handler->MethodNode;
862 GpeEventInfo->Flags &= ~ACPI_GPE_DISPATCH_MASK; /* Clear bits */
863 if (Handler->MethodNode)
865 GpeEventInfo->Flags |= ACPI_GPE_DISPATCH_METHOD;
867 AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
869 /* Now we can free the handler object */
871 ACPI_FREE (Handler);
874 UnlockAndExit:
875 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
876 return_ACPI_STATUS (Status);
879 ACPI_EXPORT_SYMBOL (AcpiRemoveGpeHandler)
882 /*******************************************************************************
884 * FUNCTION: AcpiAcquireGlobalLock
886 * PARAMETERS: Timeout - How long the caller is willing to wait
887 * Handle - Where the handle to the lock is returned
888 * (if acquired)
890 * RETURN: Status
892 * DESCRIPTION: Acquire the ACPI Global Lock
894 ******************************************************************************/
896 ACPI_STATUS
897 AcpiAcquireGlobalLock (
898 UINT16 Timeout,
899 UINT32 *Handle)
901 ACPI_STATUS Status;
904 if (!Handle)
906 return (AE_BAD_PARAMETER);
909 /* Must lock interpreter to prevent race conditions */
911 AcpiExEnterInterpreter ();
912 Status = AcpiEvAcquireGlobalLock (Timeout);
913 AcpiExExitInterpreter ();
915 if (ACPI_SUCCESS (Status))
917 AcpiGbl_GlobalLockHandle++;
918 *Handle = AcpiGbl_GlobalLockHandle;
921 return (Status);
924 ACPI_EXPORT_SYMBOL (AcpiAcquireGlobalLock)
927 /*******************************************************************************
929 * FUNCTION: AcpiReleaseGlobalLock
931 * PARAMETERS: Handle - Returned from AcpiAcquireGlobalLock
933 * RETURN: Status
935 * DESCRIPTION: Release the ACPI Global Lock. The handle must be valid.
937 ******************************************************************************/
939 ACPI_STATUS
940 AcpiReleaseGlobalLock (
941 UINT32 Handle)
943 ACPI_STATUS Status;
946 if (Handle != AcpiGbl_GlobalLockHandle)
948 return (AE_NOT_ACQUIRED);
951 Status = AcpiEvReleaseGlobalLock ();
952 return (Status);
955 ACPI_EXPORT_SYMBOL (AcpiReleaseGlobalLock)