checkdirs() was being passed the wrong mount point, resulting in a panic
[dragonfly.git] / sys / contrib / dev / acpica-unix-20050309 / events / evxface.c
blobe4fc3639c723925ff057e31f163c390fc1e52048
1 /******************************************************************************
3 * Module Name: evxface - External interfaces for ACPI events
4 * $Revision: 148 $
6 *****************************************************************************/
8 /******************************************************************************
10 * 1. Copyright Notice
12 * Some or all of this work - Copyright (c) 1999 - 2005, 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 prton 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);
176 /*******************************************************************************
178 * FUNCTION: AcpiInstallFixedEventHandler
180 * PARAMETERS: Event - Event type to enable.
181 * Handler - Pointer to the handler function for the
182 * event
183 * Context - Value passed to the handler on each GPE
185 * RETURN: Status
187 * DESCRIPTION: Saves the pointer to the handler function and then enables the
188 * event.
190 ******************************************************************************/
192 ACPI_STATUS
193 AcpiInstallFixedEventHandler (
194 UINT32 Event,
195 ACPI_EVENT_HANDLER Handler,
196 void *Context)
198 ACPI_STATUS Status;
201 ACPI_FUNCTION_TRACE ("AcpiInstallFixedEventHandler");
204 /* Parameter validation */
206 if (Event > ACPI_EVENT_MAX)
208 return_ACPI_STATUS (AE_BAD_PARAMETER);
211 Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
212 if (ACPI_FAILURE (Status))
214 return_ACPI_STATUS (Status);
217 /* Don't allow two handlers. */
219 if (NULL != AcpiGbl_FixedEventHandlers[Event].Handler)
221 Status = AE_ALREADY_EXISTS;
222 goto Cleanup;
225 /* Install the handler before enabling the event */
227 AcpiGbl_FixedEventHandlers[Event].Handler = Handler;
228 AcpiGbl_FixedEventHandlers[Event].Context = Context;
230 Status = AcpiEnableEvent (Event, 0);
231 if (ACPI_FAILURE (Status))
233 ACPI_DEBUG_PRINT ((ACPI_DB_WARN, "Could not enable fixed event.\n"));
235 /* Remove the handler */
237 AcpiGbl_FixedEventHandlers[Event].Handler = NULL;
238 AcpiGbl_FixedEventHandlers[Event].Context = NULL;
240 else
242 ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
243 "Enabled fixed event %X, Handler=%p\n", Event, Handler));
247 Cleanup:
248 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
249 return_ACPI_STATUS (Status);
253 /*******************************************************************************
255 * FUNCTION: AcpiRemoveFixedEventHandler
257 * PARAMETERS: Event - Event type to disable.
258 * Handler - Address of the handler
260 * RETURN: Status
262 * DESCRIPTION: Disables the event and unregisters the event handler.
264 ******************************************************************************/
266 ACPI_STATUS
267 AcpiRemoveFixedEventHandler (
268 UINT32 Event,
269 ACPI_EVENT_HANDLER Handler)
271 ACPI_STATUS Status = AE_OK;
274 ACPI_FUNCTION_TRACE ("AcpiRemoveFixedEventHandler");
277 /* Parameter validation */
279 if (Event > ACPI_EVENT_MAX)
281 return_ACPI_STATUS (AE_BAD_PARAMETER);
284 Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
285 if (ACPI_FAILURE (Status))
287 return_ACPI_STATUS (Status);
290 /* Disable the event before removing the handler */
292 Status = AcpiDisableEvent (Event, 0);
294 /* Always Remove the handler */
296 AcpiGbl_FixedEventHandlers[Event].Handler = NULL;
297 AcpiGbl_FixedEventHandlers[Event].Context = NULL;
299 if (ACPI_FAILURE (Status))
301 ACPI_DEBUG_PRINT ((ACPI_DB_WARN,
302 "Could not write to fixed event enable register.\n"));
304 else
306 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Disabled fixed event %X.\n", Event));
309 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
310 return_ACPI_STATUS (Status);
314 /*******************************************************************************
316 * FUNCTION: AcpiInstallNotifyHandler
318 * PARAMETERS: Device - The device for which notifies will be handled
319 * HandlerType - The type of handler:
320 * ACPI_SYSTEM_NOTIFY: SystemHandler (00-7f)
321 * ACPI_DEVICE_NOTIFY: DriverHandler (80-ff)
322 * ACPI_ALL_NOTIFY: both system and device
323 * Handler - Address of the handler
324 * Context - Value passed to the handler on each GPE
326 * RETURN: Status
328 * DESCRIPTION: Install a handler for notifies on an ACPI device
330 ******************************************************************************/
332 ACPI_STATUS
333 AcpiInstallNotifyHandler (
334 ACPI_HANDLE Device,
335 UINT32 HandlerType,
336 ACPI_NOTIFY_HANDLER Handler,
337 void *Context)
339 ACPI_OPERAND_OBJECT *ObjDesc;
340 ACPI_OPERAND_OBJECT *NotifyObj;
341 ACPI_NAMESPACE_NODE *Node;
342 ACPI_STATUS Status;
345 ACPI_FUNCTION_TRACE ("AcpiInstallNotifyHandler");
348 /* Parameter validation */
350 if ((!Device) ||
351 (!Handler) ||
352 (HandlerType > ACPI_MAX_NOTIFY_HANDLER_TYPE))
354 return_ACPI_STATUS (AE_BAD_PARAMETER);
357 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
358 if (ACPI_FAILURE (Status))
360 return_ACPI_STATUS (Status);
363 /* Convert and validate the device handle */
365 Node = AcpiNsMapHandleToNode (Device);
366 if (!Node)
368 Status = AE_BAD_PARAMETER;
369 goto UnlockAndExit;
373 * Root Object:
374 * Registering a notify handler on the root object indicates that the
375 * caller wishes to receive notifications for all objects. Note that
376 * only one <external> global handler can be regsitered (per notify type).
378 if (Device == ACPI_ROOT_OBJECT)
380 /* Make sure the handler is not already installed */
382 if (((HandlerType & ACPI_SYSTEM_NOTIFY) &&
383 AcpiGbl_SystemNotify.Handler) ||
384 ((HandlerType & ACPI_DEVICE_NOTIFY) &&
385 AcpiGbl_DeviceNotify.Handler))
387 Status = AE_ALREADY_EXISTS;
388 goto UnlockAndExit;
391 if (HandlerType & ACPI_SYSTEM_NOTIFY)
393 AcpiGbl_SystemNotify.Node = Node;
394 AcpiGbl_SystemNotify.Handler = Handler;
395 AcpiGbl_SystemNotify.Context = Context;
398 if (HandlerType & ACPI_DEVICE_NOTIFY)
400 AcpiGbl_DeviceNotify.Node = Node;
401 AcpiGbl_DeviceNotify.Handler = Handler;
402 AcpiGbl_DeviceNotify.Context = Context;
405 /* Global notify handler installed */
409 * All Other Objects:
410 * Caller will only receive notifications specific to the target object.
411 * Note that only certain object types can receive notifications.
413 else
415 /* Notifies allowed on this object? */
417 if (!AcpiEvIsNotifyObject (Node))
419 Status = AE_TYPE;
420 goto UnlockAndExit;
423 /* Check for an existing internal object */
425 ObjDesc = AcpiNsGetAttachedObject (Node);
426 if (ObjDesc)
428 /* Object exists - make sure there's no handler */
430 if (((HandlerType & ACPI_SYSTEM_NOTIFY) &&
431 ObjDesc->CommonNotify.SystemNotify) ||
432 ((HandlerType & ACPI_DEVICE_NOTIFY) &&
433 ObjDesc->CommonNotify.DeviceNotify))
435 Status = AE_ALREADY_EXISTS;
436 goto UnlockAndExit;
439 else
441 /* Create a new object */
443 ObjDesc = AcpiUtCreateInternalObject (Node->Type);
444 if (!ObjDesc)
446 Status = AE_NO_MEMORY;
447 goto UnlockAndExit;
450 /* Attach new object to the Node */
452 Status = AcpiNsAttachObject (Device, ObjDesc, Node->Type);
454 /* Remove local reference to the object */
456 AcpiUtRemoveReference (ObjDesc);
457 if (ACPI_FAILURE (Status))
459 goto UnlockAndExit;
463 /* Install the handler */
465 NotifyObj = AcpiUtCreateInternalObject (ACPI_TYPE_LOCAL_NOTIFY);
466 if (!NotifyObj)
468 Status = AE_NO_MEMORY;
469 goto UnlockAndExit;
472 NotifyObj->Notify.Node = Node;
473 NotifyObj->Notify.Handler = Handler;
474 NotifyObj->Notify.Context = Context;
476 if (HandlerType & ACPI_SYSTEM_NOTIFY)
478 ObjDesc->CommonNotify.SystemNotify = NotifyObj;
481 if (HandlerType & ACPI_DEVICE_NOTIFY)
483 ObjDesc->CommonNotify.DeviceNotify = NotifyObj;
486 if (HandlerType == ACPI_ALL_NOTIFY)
488 /* Extra ref if installed in both */
490 AcpiUtAddReference (NotifyObj);
495 UnlockAndExit:
496 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
497 return_ACPI_STATUS (Status);
501 /*******************************************************************************
503 * FUNCTION: AcpiRemoveNotifyHandler
505 * PARAMETERS: Device - The device for which notifies will be handled
506 * HandlerType - The type of handler:
507 * ACPI_SYSTEM_NOTIFY: SystemHandler (00-7f)
508 * ACPI_DEVICE_NOTIFY: DriverHandler (80-ff)
509 * ACPI_ALL_NOTIFY: both system and device
510 * Handler - Address of the handler
512 * RETURN: Status
514 * DESCRIPTION: Remove a handler for notifies on an ACPI device
516 ******************************************************************************/
518 ACPI_STATUS
519 AcpiRemoveNotifyHandler (
520 ACPI_HANDLE Device,
521 UINT32 HandlerType,
522 ACPI_NOTIFY_HANDLER Handler)
524 ACPI_OPERAND_OBJECT *NotifyObj;
525 ACPI_OPERAND_OBJECT *ObjDesc;
526 ACPI_NAMESPACE_NODE *Node;
527 ACPI_STATUS Status;
530 ACPI_FUNCTION_TRACE ("AcpiRemoveNotifyHandler");
533 /* Parameter validation */
535 if ((!Device) ||
536 (!Handler) ||
537 (HandlerType > ACPI_MAX_NOTIFY_HANDLER_TYPE))
539 return_ACPI_STATUS (AE_BAD_PARAMETER);
542 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
543 if (ACPI_FAILURE (Status))
545 return_ACPI_STATUS (Status);
548 /* Convert and validate the device handle */
550 Node = AcpiNsMapHandleToNode (Device);
551 if (!Node)
553 Status = AE_BAD_PARAMETER;
554 goto UnlockAndExit;
557 /* Root Object */
559 if (Device == ACPI_ROOT_OBJECT)
561 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Removing notify handler for ROOT object.\n"));
563 if (((HandlerType & ACPI_SYSTEM_NOTIFY) &&
564 !AcpiGbl_SystemNotify.Handler) ||
565 ((HandlerType & ACPI_DEVICE_NOTIFY) &&
566 !AcpiGbl_DeviceNotify.Handler))
568 Status = AE_NOT_EXIST;
569 goto UnlockAndExit;
572 if (HandlerType & ACPI_SYSTEM_NOTIFY)
574 AcpiGbl_SystemNotify.Node = NULL;
575 AcpiGbl_SystemNotify.Handler = NULL;
576 AcpiGbl_SystemNotify.Context = NULL;
579 if (HandlerType & ACPI_DEVICE_NOTIFY)
581 AcpiGbl_DeviceNotify.Node = NULL;
582 AcpiGbl_DeviceNotify.Handler = NULL;
583 AcpiGbl_DeviceNotify.Context = NULL;
587 /* All Other Objects */
589 else
591 /* Notifies allowed on this object? */
593 if (!AcpiEvIsNotifyObject (Node))
595 Status = AE_TYPE;
596 goto UnlockAndExit;
599 /* Check for an existing internal object */
601 ObjDesc = AcpiNsGetAttachedObject (Node);
602 if (!ObjDesc)
604 Status = AE_NOT_EXIST;
605 goto UnlockAndExit;
608 /* Object exists - make sure there's an existing handler */
610 if (HandlerType & ACPI_SYSTEM_NOTIFY)
612 NotifyObj = ObjDesc->CommonNotify.SystemNotify;
613 if ((!NotifyObj) ||
614 (NotifyObj->Notify.Handler != Handler))
616 Status = AE_BAD_PARAMETER;
617 goto UnlockAndExit;
620 /* Remove the handler */
622 ObjDesc->CommonNotify.SystemNotify = NULL;
623 AcpiUtRemoveReference (NotifyObj);
626 if (HandlerType & ACPI_DEVICE_NOTIFY)
628 NotifyObj = ObjDesc->CommonNotify.DeviceNotify;
629 if ((!NotifyObj) ||
630 (NotifyObj->Notify.Handler != Handler))
632 Status = AE_BAD_PARAMETER;
633 goto UnlockAndExit;
636 /* Remove the handler */
638 ObjDesc->CommonNotify.DeviceNotify = NULL;
639 AcpiUtRemoveReference (NotifyObj);
644 UnlockAndExit:
645 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
646 return_ACPI_STATUS (Status);
650 /*******************************************************************************
652 * FUNCTION: AcpiInstallGpeHandler
654 * PARAMETERS: GpeNumber - The GPE number within the GPE block
655 * GpeBlock - GPE block (NULL == FADT GPEs)
656 * Type - Whether this GPE should be treated as an
657 * edge- or level-triggered interrupt.
658 * Address - Address of the handler
659 * Context - Value passed to the handler on each GPE
661 * RETURN: Status
663 * DESCRIPTION: Install a handler for a General Purpose Event.
665 ******************************************************************************/
667 ACPI_STATUS
668 AcpiInstallGpeHandler (
669 ACPI_HANDLE GpeDevice,
670 UINT32 GpeNumber,
671 UINT32 Type,
672 ACPI_EVENT_HANDLER Address,
673 void *Context)
675 ACPI_GPE_EVENT_INFO *GpeEventInfo;
676 ACPI_HANDLER_INFO *Handler;
677 ACPI_STATUS Status;
680 ACPI_FUNCTION_TRACE ("AcpiInstallGpeHandler");
683 /* Parameter validation */
685 if ((!Address) || (Type > ACPI_GPE_XRUPT_TYPE_MASK))
687 return_ACPI_STATUS (AE_BAD_PARAMETER);
690 Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
691 if (ACPI_FAILURE (Status))
693 return_ACPI_STATUS (Status);
696 /* Ensure that we have a valid GPE number */
698 GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
699 if (!GpeEventInfo)
701 Status = AE_BAD_PARAMETER;
702 goto UnlockAndExit;
705 /* Make sure that there isn't a handler there already */
707 if ((GpeEventInfo->Flags & ACPI_GPE_DISPATCH_MASK) == ACPI_GPE_DISPATCH_HANDLER)
709 Status = AE_ALREADY_EXISTS;
710 goto UnlockAndExit;
713 /* Allocate and init handler object */
715 Handler = ACPI_MEM_CALLOCATE (sizeof (ACPI_HANDLER_INFO));
716 if (!Handler)
718 Status = AE_NO_MEMORY;
719 goto UnlockAndExit;
722 Handler->Address = Address;
723 Handler->Context = Context;
724 Handler->MethodNode = GpeEventInfo->Dispatch.MethodNode;
726 /* Disable the GPE before installing the handler */
728 Status = AcpiEvDisableGpe (GpeEventInfo);
729 if (ACPI_FAILURE (Status))
731 goto UnlockAndExit;
734 /* Install the handler */
736 AcpiOsAcquireLock (AcpiGbl_GpeLock, ACPI_NOT_ISR);
737 GpeEventInfo->Dispatch.Handler = Handler;
739 /* Setup up dispatch flags to indicate handler (vs. method) */
741 GpeEventInfo->Flags &= ~(ACPI_GPE_XRUPT_TYPE_MASK | ACPI_GPE_DISPATCH_MASK); /* Clear bits */
742 GpeEventInfo->Flags |= (UINT8) (Type | ACPI_GPE_DISPATCH_HANDLER);
744 AcpiOsReleaseLock (AcpiGbl_GpeLock, ACPI_NOT_ISR);
747 UnlockAndExit:
748 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
749 return_ACPI_STATUS (Status);
753 /*******************************************************************************
755 * FUNCTION: AcpiRemoveGpeHandler
757 * PARAMETERS: GpeNumber - The event to remove a handler
758 * GpeBlock - GPE block (NULL == FADT GPEs)
759 * Address - Address of the handler
761 * RETURN: Status
763 * DESCRIPTION: Remove a handler for a General Purpose AcpiEvent.
765 ******************************************************************************/
767 ACPI_STATUS
768 AcpiRemoveGpeHandler (
769 ACPI_HANDLE GpeDevice,
770 UINT32 GpeNumber,
771 ACPI_EVENT_HANDLER Address)
773 ACPI_GPE_EVENT_INFO *GpeEventInfo;
774 ACPI_HANDLER_INFO *Handler;
775 ACPI_STATUS Status;
778 ACPI_FUNCTION_TRACE ("AcpiRemoveGpeHandler");
781 /* Parameter validation */
783 if (!Address)
785 return_ACPI_STATUS (AE_BAD_PARAMETER);
788 Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
789 if (ACPI_FAILURE (Status))
791 return_ACPI_STATUS (Status);
794 /* Ensure that we have a valid GPE number */
796 GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
797 if (!GpeEventInfo)
799 Status = AE_BAD_PARAMETER;
800 goto UnlockAndExit;
803 /* Make sure that a handler is indeed installed */
805 if ((GpeEventInfo->Flags & ACPI_GPE_DISPATCH_MASK) != ACPI_GPE_DISPATCH_HANDLER)
807 Status = AE_NOT_EXIST;
808 goto UnlockAndExit;
811 /* Make sure that the installed handler is the same */
813 if (GpeEventInfo->Dispatch.Handler->Address != Address)
815 Status = AE_BAD_PARAMETER;
816 goto UnlockAndExit;
819 /* Disable the GPE before removing the handler */
821 Status = AcpiEvDisableGpe (GpeEventInfo);
822 if (ACPI_FAILURE (Status))
824 goto UnlockAndExit;
827 /* Remove the handler */
829 AcpiOsAcquireLock (AcpiGbl_GpeLock, ACPI_NOT_ISR);
830 Handler = GpeEventInfo->Dispatch.Handler;
832 /* Restore Method node (if any), set dispatch flags */
834 GpeEventInfo->Dispatch.MethodNode = Handler->MethodNode;
835 GpeEventInfo->Flags &= ~ACPI_GPE_DISPATCH_MASK; /* Clear bits */
836 if (Handler->MethodNode)
838 GpeEventInfo->Flags |= ACPI_GPE_DISPATCH_METHOD;
840 AcpiOsReleaseLock (AcpiGbl_GpeLock, ACPI_NOT_ISR);
842 /* Now we can free the handler object */
844 ACPI_MEM_FREE (Handler);
847 UnlockAndExit:
848 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
849 return_ACPI_STATUS (Status);
853 /*******************************************************************************
855 * FUNCTION: AcpiAcquireGlobalLock
857 * PARAMETERS: Timeout - How long the caller is willing to wait
858 * OutHandle - A handle to the lock if acquired
860 * RETURN: Status
862 * DESCRIPTION: Acquire the ACPI Global Lock
864 ******************************************************************************/
866 ACPI_STATUS
867 AcpiAcquireGlobalLock (
868 UINT16 Timeout,
869 UINT32 *Handle)
871 ACPI_STATUS Status;
874 if (!Handle)
876 return (AE_BAD_PARAMETER);
879 Status = AcpiExEnterInterpreter ();
880 if (ACPI_FAILURE (Status))
882 return (Status);
885 Status = AcpiEvAcquireGlobalLock (Timeout);
886 AcpiExExitInterpreter ();
888 if (ACPI_SUCCESS (Status))
890 AcpiGbl_GlobalLockHandle++;
891 *Handle = AcpiGbl_GlobalLockHandle;
894 return (Status);
898 /*******************************************************************************
900 * FUNCTION: AcpiReleaseGlobalLock
902 * PARAMETERS: Handle - Returned from AcpiAcquireGlobalLock
904 * RETURN: Status
906 * DESCRIPTION: Release the ACPI Global Lock
908 ******************************************************************************/
910 ACPI_STATUS
911 AcpiReleaseGlobalLock (
912 UINT32 Handle)
914 ACPI_STATUS Status;
917 if (Handle != AcpiGbl_GlobalLockHandle)
919 return (AE_NOT_ACQUIRED);
922 Status = AcpiEvReleaseGlobalLock ();
923 return (Status);