evxface.c revision 87031
1/******************************************************************************
2 *
3 * Module Name: evxface - External interfaces for ACPI events
4 *              $Revision: 118 $
5 *
6 *****************************************************************************/
7
8/******************************************************************************
9 *
10 * 1. Copyright Notice
11 *
12 * Some or all of this work - Copyright (c) 1999, 2000, 2001, Intel Corp.
13 * All rights reserved.
14 *
15 * 2. License
16 *
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.
21 *
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
28 *
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;
37 *
38 * The above copyright and patent license is granted only if the following
39 * conditions are met:
40 *
41 * 3. Conditions
42 *
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.
54 *
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.
66 *
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.
72 *
73 * 3.4. Intel retains all right, title, and interest in and to the Original
74 * Intel Code.
75 *
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.
80 *
81 * 4. Disclaimer and Export Compliance
82 *
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.
90 *
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.
99 *
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.
114 *
115 *****************************************************************************/
116
117
118#define __EVXFACE_C__
119
120#include "acpi.h"
121#include "achware.h"
122#include "acnamesp.h"
123#include "acevents.h"
124#include "amlcode.h"
125#include "acinterp.h"
126
127#define _COMPONENT          ACPI_EVENTS
128        MODULE_NAME         ("evxface")
129
130
131/*******************************************************************************
132 *
133 * FUNCTION:    AcpiInstallFixedEventHandler
134 *
135 * PARAMETERS:  Event           - Event type to enable.
136 *              Handler         - Pointer to the handler function for the
137 *                                event
138 *              Context         - Value passed to the handler on each GPE
139 *
140 * RETURN:      Status
141 *
142 * DESCRIPTION: Saves the pointer to the handler function and then enables the
143 *              event.
144 *
145 ******************************************************************************/
146
147ACPI_STATUS
148AcpiInstallFixedEventHandler (
149    UINT32                  Event,
150    ACPI_EVENT_HANDLER      Handler,
151    void                    *Context)
152{
153    ACPI_STATUS             Status;
154
155
156    FUNCTION_TRACE ("AcpiInstallFixedEventHandler");
157
158
159    /* Parameter validation */
160
161    if (Event > ACPI_EVENT_MAX)
162    {
163        return_ACPI_STATUS (AE_BAD_PARAMETER);
164    }
165
166    AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
167
168    /* Don't allow two handlers. */
169
170    if (NULL != AcpiGbl_FixedEventHandlers[Event].Handler)
171    {
172        Status = AE_ALREADY_EXISTS;
173        goto Cleanup;
174    }
175
176
177    /* Install the handler before enabling the event */
178
179    AcpiGbl_FixedEventHandlers[Event].Handler = Handler;
180    AcpiGbl_FixedEventHandlers[Event].Context = Context;
181
182    Status = AcpiEnableEvent (Event, ACPI_EVENT_FIXED, 0);
183    if (!ACPI_SUCCESS (Status))
184    {
185        ACPI_DEBUG_PRINT ((ACPI_DB_WARN, "Could not enable fixed event.\n"));
186
187        /* Remove the handler */
188
189        AcpiGbl_FixedEventHandlers[Event].Handler = NULL;
190        AcpiGbl_FixedEventHandlers[Event].Context = NULL;
191    }
192
193    else
194    {
195        ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
196            "Enabled fixed event %X, Handler=%p\n", Event, Handler));
197    }
198
199
200Cleanup:
201    AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
202    return_ACPI_STATUS (Status);
203}
204
205
206/*******************************************************************************
207 *
208 * FUNCTION:    AcpiRemoveFixedEventHandler
209 *
210 * PARAMETERS:  Event           - Event type to disable.
211 *              Handler         - Address of the handler
212 *
213 * RETURN:      Status
214 *
215 * DESCRIPTION: Disables the event and unregisters the event handler.
216 *
217 ******************************************************************************/
218
219ACPI_STATUS
220AcpiRemoveFixedEventHandler (
221    UINT32                  Event,
222    ACPI_EVENT_HANDLER      Handler)
223{
224    ACPI_STATUS             Status = AE_OK;
225
226
227    FUNCTION_TRACE ("AcpiRemoveFixedEventHandler");
228
229
230    /* Parameter validation */
231
232    if (Event > ACPI_EVENT_MAX)
233    {
234        return_ACPI_STATUS (AE_BAD_PARAMETER);
235    }
236
237    AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
238
239    /* Disable the event before removing the handler */
240
241    Status = AcpiDisableEvent(Event, ACPI_EVENT_FIXED, 0);
242
243    /* Always Remove the handler */
244
245    AcpiGbl_FixedEventHandlers[Event].Handler = NULL;
246    AcpiGbl_FixedEventHandlers[Event].Context = NULL;
247
248    if (!ACPI_SUCCESS (Status))
249    {
250        ACPI_DEBUG_PRINT ((ACPI_DB_WARN,
251            "Could not write to fixed event enable register.\n"));
252    }
253    else
254    {
255        ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Disabled fixed event %X.\n", Event));
256    }
257
258    AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
259    return_ACPI_STATUS (Status);
260}
261
262
263/*******************************************************************************
264 *
265 * FUNCTION:    AcpiInstallNotifyHandler
266 *
267 * PARAMETERS:  Device          - The device for which notifies will be handled
268 *              HandlerType     - The type of handler:
269 *                                  ACPI_SYSTEM_NOTIFY: SystemHandler (00-7f)
270 *                                  ACPI_DEVICE_NOTIFY: DriverHandler (80-ff)
271 *              Handler         - Address of the handler
272 *              Context         - Value passed to the handler on each GPE
273 *
274 * RETURN:      Status
275 *
276 * DESCRIPTION: Install a handler for notifies on an ACPI device
277 *
278 ******************************************************************************/
279
280ACPI_STATUS
281AcpiInstallNotifyHandler (
282    ACPI_HANDLE             Device,
283    UINT32                  HandlerType,
284    ACPI_NOTIFY_HANDLER     Handler,
285    void                    *Context)
286{
287    ACPI_OPERAND_OBJECT     *ObjDesc;
288    ACPI_OPERAND_OBJECT     *NotifyObj;
289    ACPI_NAMESPACE_NODE     *DeviceNode;
290    ACPI_STATUS             Status = AE_OK;
291
292
293    FUNCTION_TRACE ("AcpiInstallNotifyHandler");
294
295
296    /* Parameter validation */
297
298    if ((!Handler) ||
299        (HandlerType > ACPI_MAX_NOTIFY_HANDLER_TYPE))
300    {
301        return_ACPI_STATUS (AE_BAD_PARAMETER);
302    }
303
304    AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
305
306    /* Convert and validate the device handle */
307
308    DeviceNode = AcpiNsMapHandleToNode (Device);
309    if (!DeviceNode)
310    {
311        Status = AE_BAD_PARAMETER;
312        goto UnlockAndExit;
313    }
314
315    /*
316     * Root Object:
317     * Registering a notify handler on the root object indicates that the
318     * caller wishes to receive notifications for all objects.  Note that
319     * only one <external> global handler can be regsitered (per notify type).
320     */
321    if (Device == ACPI_ROOT_OBJECT)
322    {
323        /* Make sure the handler is not already installed */
324
325        if (((HandlerType == ACPI_SYSTEM_NOTIFY) &&
326              AcpiGbl_SysNotify.Handler) ||
327            ((HandlerType == ACPI_DEVICE_NOTIFY) &&
328              AcpiGbl_DrvNotify.Handler))
329        {
330            Status = AE_ALREADY_EXISTS;
331            goto UnlockAndExit;
332        }
333
334        if (HandlerType == ACPI_SYSTEM_NOTIFY)
335        {
336            AcpiGbl_SysNotify.Node = DeviceNode;
337            AcpiGbl_SysNotify.Handler = Handler;
338            AcpiGbl_SysNotify.Context = Context;
339        }
340        else /* ACPI_DEVICE_NOTIFY */
341        {
342            AcpiGbl_DrvNotify.Node = DeviceNode;
343            AcpiGbl_DrvNotify.Handler = Handler;
344            AcpiGbl_DrvNotify.Context = Context;
345        }
346
347        /* Global notify handler installed */
348    }
349
350    /*
351     * All Other Objects:
352     * Caller will only receive notifications specific to the target object.
353     * Note that only certain object types can receive notifications.
354     */
355    else
356    {
357        /*
358         * These are the ONLY objects that can receive ACPI notifications
359         */
360        if ((DeviceNode->Type != ACPI_TYPE_DEVICE)     &&
361            (DeviceNode->Type != ACPI_TYPE_PROCESSOR)  &&
362            (DeviceNode->Type != ACPI_TYPE_POWER)      &&
363            (DeviceNode->Type != ACPI_TYPE_THERMAL))
364        {
365            Status = AE_BAD_PARAMETER;
366            goto UnlockAndExit;
367        }
368
369        /* Check for an existing internal object */
370
371        ObjDesc = AcpiNsGetAttachedObject (DeviceNode);
372        if (ObjDesc)
373        {
374
375            /* Object exists - make sure there's no handler */
376
377            if (((HandlerType == ACPI_SYSTEM_NOTIFY) &&
378                  ObjDesc->Device.SysHandler) ||
379                ((HandlerType == ACPI_DEVICE_NOTIFY) &&
380                  ObjDesc->Device.DrvHandler))
381            {
382                Status = AE_ALREADY_EXISTS;
383                goto UnlockAndExit;
384            }
385        }
386
387        else
388        {
389            /* Create a new object */
390
391            ObjDesc = AcpiUtCreateInternalObject (DeviceNode->Type);
392            if (!ObjDesc)
393            {
394                Status = AE_NO_MEMORY;
395                goto UnlockAndExit;
396            }
397
398            /* Attach new object to the Node */
399
400            Status = AcpiNsAttachObject (Device, ObjDesc, (UINT8) DeviceNode->Type);
401            if (ACPI_FAILURE (Status))
402            {
403                goto UnlockAndExit;
404            }
405        }
406
407        /* Install the handler */
408
409        NotifyObj = AcpiUtCreateInternalObject (INTERNAL_TYPE_NOTIFY);
410        if (!NotifyObj)
411        {
412            Status = AE_NO_MEMORY;
413            goto UnlockAndExit;
414        }
415
416        NotifyObj->NotifyHandler.Node = DeviceNode;
417        NotifyObj->NotifyHandler.Handler = Handler;
418        NotifyObj->NotifyHandler.Context = Context;
419
420
421        if (HandlerType == ACPI_SYSTEM_NOTIFY)
422        {
423            ObjDesc->Device.SysHandler = NotifyObj;
424        }
425
426        else /* ACPI_DEVICE_NOTIFY */
427        {
428            ObjDesc->Device.DrvHandler = NotifyObj;
429        }
430    }
431
432
433UnlockAndExit:
434    AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
435    return_ACPI_STATUS (Status);
436}
437
438
439/*******************************************************************************
440 *
441 * FUNCTION:    AcpiRemoveNotifyHandler
442 *
443 * PARAMETERS:  Device          - The device for which notifies will be handled
444 *              HandlerType     - The type of handler:
445 *                                  ACPI_SYSTEM_NOTIFY: SystemHandler (00-7f)
446 *                                  ACPI_DEVICE_NOTIFY: DriverHandler (80-ff)
447 *              Handler         - Address of the handler
448 * RETURN:      Status
449 *
450 * DESCRIPTION: Remove a handler for notifies on an ACPI device
451 *
452 ******************************************************************************/
453
454ACPI_STATUS
455AcpiRemoveNotifyHandler (
456    ACPI_HANDLE             Device,
457    UINT32                  HandlerType,
458    ACPI_NOTIFY_HANDLER     Handler)
459{
460    ACPI_OPERAND_OBJECT     *NotifyObj;
461    ACPI_OPERAND_OBJECT     *ObjDesc;
462    ACPI_NAMESPACE_NODE     *DeviceNode;
463    ACPI_STATUS             Status = AE_OK;
464
465
466    FUNCTION_TRACE ("AcpiRemoveNotifyHandler");
467
468
469    /* Parameter validation */
470
471    if ((!Handler) ||
472        (HandlerType > ACPI_MAX_NOTIFY_HANDLER_TYPE))
473    {
474        return_ACPI_STATUS (AE_BAD_PARAMETER);
475    }
476
477    AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
478
479    /* Convert and validate the device handle */
480
481    DeviceNode = AcpiNsMapHandleToNode (Device);
482    if (!DeviceNode)
483    {
484        Status = AE_BAD_PARAMETER;
485        goto UnlockAndExit;
486    }
487
488    /*
489     * Root Object
490     */
491    if (Device == ACPI_ROOT_OBJECT)
492    {
493        ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Removing notify handler for ROOT object.\n"));
494
495        if (((HandlerType == ACPI_SYSTEM_NOTIFY) &&
496              !AcpiGbl_SysNotify.Handler) ||
497            ((HandlerType == ACPI_DEVICE_NOTIFY) &&
498              !AcpiGbl_DrvNotify.Handler))
499        {
500            Status = AE_NOT_EXIST;
501            goto UnlockAndExit;
502        }
503
504        if (HandlerType == ACPI_SYSTEM_NOTIFY)
505        {
506            AcpiGbl_SysNotify.Node    = NULL;
507            AcpiGbl_SysNotify.Handler = NULL;
508            AcpiGbl_SysNotify.Context = NULL;
509        }
510        else
511        {
512            AcpiGbl_DrvNotify.Node    = NULL;
513            AcpiGbl_DrvNotify.Handler = NULL;
514            AcpiGbl_DrvNotify.Context = NULL;
515        }
516    }
517
518    /*
519     * All Other Objects
520     */
521    else
522    {
523        /*
524         * These are the ONLY objects that can receive ACPI notifications
525         */
526        if ((DeviceNode->Type != ACPI_TYPE_DEVICE)     &&
527            (DeviceNode->Type != ACPI_TYPE_PROCESSOR)  &&
528            (DeviceNode->Type != ACPI_TYPE_POWER)      &&
529            (DeviceNode->Type != ACPI_TYPE_THERMAL))
530        {
531            Status = AE_BAD_PARAMETER;
532            goto UnlockAndExit;
533        }
534
535        /* Check for an existing internal object */
536
537        ObjDesc = AcpiNsGetAttachedObject (DeviceNode);
538        if (!ObjDesc)
539        {
540            Status = AE_NOT_EXIST;
541            goto UnlockAndExit;
542        }
543
544        /* Object exists - make sure there's an existing handler */
545
546        if (HandlerType == ACPI_SYSTEM_NOTIFY)
547        {
548            NotifyObj = ObjDesc->Device.SysHandler;
549        }
550        else
551        {
552            NotifyObj = ObjDesc->Device.DrvHandler;
553        }
554
555        if ((!NotifyObj) ||
556            (NotifyObj->NotifyHandler.Handler != Handler))
557        {
558            Status = AE_BAD_PARAMETER;
559            goto UnlockAndExit;
560        }
561
562        /* Remove the handler */
563
564        if (HandlerType == ACPI_SYSTEM_NOTIFY)
565        {
566            ObjDesc->Device.SysHandler = NULL;
567        }
568        else
569        {
570            ObjDesc->Device.DrvHandler = NULL;
571        }
572
573        AcpiUtRemoveReference (NotifyObj);
574    }
575
576
577UnlockAndExit:
578    AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
579    return_ACPI_STATUS (Status);
580}
581
582
583/*******************************************************************************
584 *
585 * FUNCTION:    AcpiInstallGpeHandler
586 *
587 * PARAMETERS:  GpeNumber       - The GPE number.  The numbering scheme is
588 *                                bank 0 first, then bank 1.
589 *              Type            - Whether this GPE should be treated as an
590 *                                edge- or level-triggered interrupt.
591 *              Handler         - Address of the handler
592 *              Context         - Value passed to the handler on each GPE
593 *
594 * RETURN:      Status
595 *
596 * DESCRIPTION: Install a handler for a General Purpose Event.
597 *
598 ******************************************************************************/
599
600ACPI_STATUS
601AcpiInstallGpeHandler (
602    UINT32                  GpeNumber,
603    UINT32                  Type,
604    ACPI_GPE_HANDLER        Handler,
605    void                    *Context)
606{
607    ACPI_STATUS             Status = AE_OK;
608
609
610    FUNCTION_TRACE ("AcpiInstallGpeHandler");
611
612
613    /* Parameter validation */
614
615    if (!Handler || (GpeNumber > ACPI_GPE_MAX))
616    {
617        return_ACPI_STATUS (AE_BAD_PARAMETER);
618    }
619
620    /* Ensure that we have a valid GPE number */
621
622    if (AcpiGbl_GpeValid[GpeNumber] == ACPI_GPE_INVALID)
623    {
624        return_ACPI_STATUS (AE_BAD_PARAMETER);
625    }
626
627    AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
628
629    /* Make sure that there isn't a handler there already */
630
631    if (AcpiGbl_GpeInfo[GpeNumber].Handler)
632    {
633        Status = AE_ALREADY_EXISTS;
634        goto Cleanup;
635    }
636
637    /* Install the handler */
638
639    AcpiGbl_GpeInfo[GpeNumber].Handler = Handler;
640    AcpiGbl_GpeInfo[GpeNumber].Context = Context;
641    AcpiGbl_GpeInfo[GpeNumber].Type = (UINT8) Type;
642
643    /* Clear the GPE (of stale events), the enable it */
644
645    AcpiHwClearGpe (GpeNumber);
646    AcpiHwEnableGpe (GpeNumber);
647
648
649Cleanup:
650    AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
651    return_ACPI_STATUS (Status);
652}
653
654
655/*******************************************************************************
656 *
657 * FUNCTION:    AcpiRemoveGpeHandler
658 *
659 * PARAMETERS:  GpeNumber       - The event to remove a handler
660 *              Handler         - Address of the handler
661 *
662 * RETURN:      Status
663 *
664 * DESCRIPTION: Remove a handler for a General Purpose AcpiEvent.
665 *
666 ******************************************************************************/
667
668ACPI_STATUS
669AcpiRemoveGpeHandler (
670    UINT32                  GpeNumber,
671    ACPI_GPE_HANDLER        Handler)
672{
673    ACPI_STATUS             Status = AE_OK;
674
675
676    FUNCTION_TRACE ("AcpiRemoveGpeHandler");
677
678
679    /* Parameter validation */
680
681    if (!Handler || (GpeNumber > ACPI_GPE_MAX))
682    {
683        return_ACPI_STATUS (AE_BAD_PARAMETER);
684    }
685
686    /* Ensure that we have a valid GPE number */
687
688    if (AcpiGbl_GpeValid[GpeNumber] == ACPI_GPE_INVALID)
689    {
690        return_ACPI_STATUS (AE_BAD_PARAMETER);
691    }
692
693    /* Disable the GPE before removing the handler */
694
695    AcpiHwDisableGpe (GpeNumber);
696
697    AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
698
699    /* Make sure that the installed handler is the same */
700
701    if (AcpiGbl_GpeInfo[GpeNumber].Handler != Handler)
702    {
703        AcpiHwEnableGpe (GpeNumber);
704        Status = AE_BAD_PARAMETER;
705        goto Cleanup;
706    }
707
708    /* Remove the handler */
709
710    AcpiGbl_GpeInfo[GpeNumber].Handler = NULL;
711    AcpiGbl_GpeInfo[GpeNumber].Context = NULL;
712
713
714Cleanup:
715    AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
716    return_ACPI_STATUS (Status);
717}
718
719
720/*******************************************************************************
721 *
722 * FUNCTION:    AcpiAcquireGlobalLock
723 *
724 * PARAMETERS:  Timeout         - How long the caller is willing to wait
725 *              OutHandle       - A handle to the lock if acquired
726 *
727 * RETURN:      Status
728 *
729 * DESCRIPTION: Acquire the ACPI Global Lock
730 *
731 ******************************************************************************/
732
733ACPI_STATUS
734AcpiAcquireGlobalLock (
735    void)
736{
737    ACPI_STATUS             Status;
738
739
740    Status = AcpiExEnterInterpreter ();
741    if (ACPI_FAILURE (Status))
742    {
743        return (Status);
744    }
745
746    /*
747     * TBD: [Restructure] add timeout param to internal interface, and
748     * perhaps INTERPRETER_LOCKED
749     */
750    Status = AcpiEvAcquireGlobalLock ();
751    AcpiExExitInterpreter ();
752
753    return (Status);
754}
755
756
757/*******************************************************************************
758 *
759 * FUNCTION:    AcpiReleaseGlobalLock
760 *
761 * PARAMETERS:  Handle      - Returned from AcpiAcquireGlobalLock
762 *
763 * RETURN:      Status
764 *
765 * DESCRIPTION: Release the ACPI Global Lock
766 *
767 ******************************************************************************/
768
769ACPI_STATUS
770AcpiReleaseGlobalLock (
771    void)
772{
773
774    AcpiEvReleaseGlobalLock ();
775    return (AE_OK);
776}
777
778
779