evxfgpe.c revision 216331
1/******************************************************************************
2 *
3 * Module Name: evxfgpe - External Interfaces for General Purpose Events (GPEs)
4 *
5 *****************************************************************************/
6
7/******************************************************************************
8 *
9 * 1. Copyright Notice
10 *
11 * Some or all of this work - Copyright (c) 1999 - 2010, Intel Corp.
12 * All rights reserved.
13 *
14 * 2. License
15 *
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
19 * property rights.
20 *
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
27 *
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;
36 *
37 * The above copyright and patent license is granted only if the following
38 * conditions are met:
39 *
40 * 3. Conditions
41 *
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.
53 *
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
64 * make.
65 *
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
70 * distribution.
71 *
72 * 3.4. Intel retains all right, title, and interest in and to the Original
73 * Intel Code.
74 *
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.
79 *
80 * 4. Disclaimer and Export Compliance
81 *
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
88 * PARTICULAR PURPOSE.
89 *
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
97 * LIMITED REMEDY.
98 *
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.
113 *
114 *****************************************************************************/
115
116
117#define __EVXFGPE_C__
118
119#include "acpi.h"
120#include "accommon.h"
121#include "acevents.h"
122#include "acnamesp.h"
123
124#define _COMPONENT          ACPI_EVENTS
125        ACPI_MODULE_NAME    ("evxfgpe")
126
127
128/*******************************************************************************
129 *
130 * FUNCTION:    AcpiUpdateAllGpes
131 *
132 * PARAMETERS:  None
133 *
134 * RETURN:      Status
135 *
136 * DESCRIPTION: Complete GPE initialization and enable all GPEs that have
137 *              associated _Lxx or _Exx methods and are not pointed to by any
138 *              device _PRW methods (this indicates that these GPEs are
139 *              generally intended for system or device wakeup. Such GPEs
140 *              have to be enabled directly when the devices whose _PRW
141 *              methods point to them are set up for wakeup signaling.)
142 *
143 * NOTE: Should be called after any GPEs are added to the system. Primarily,
144 * after the system _PRW methods have been run, but also after a GPE Block
145 * Device has been added or if any new GPE methods have been added via a
146 * dynamic table load.
147 *
148 ******************************************************************************/
149
150ACPI_STATUS
151AcpiUpdateAllGpes (
152    void)
153{
154    ACPI_STATUS             Status;
155
156
157    ACPI_FUNCTION_TRACE (AcpiUpdateGpes);
158
159
160    Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
161    if (ACPI_FAILURE (Status))
162    {
163        return_ACPI_STATUS (Status);
164    }
165
166    if (AcpiGbl_AllGpesInitialized)
167    {
168        goto UnlockAndExit;
169    }
170
171    Status = AcpiEvWalkGpeList (AcpiEvInitializeGpeBlock, NULL);
172    if (ACPI_SUCCESS (Status))
173    {
174        AcpiGbl_AllGpesInitialized = TRUE;
175    }
176
177UnlockAndExit:
178    (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
179    return_ACPI_STATUS (Status);
180}
181
182ACPI_EXPORT_SYMBOL (AcpiUpdateAllGpes)
183
184
185/*******************************************************************************
186 *
187 * FUNCTION:    AcpiEnableGpe
188 *
189 * PARAMETERS:  GpeDevice           - Parent GPE Device. NULL for GPE0/GPE1
190 *              GpeNumber           - GPE level within the GPE block
191 *
192 * RETURN:      Status
193 *
194 * DESCRIPTION: Add a reference to a GPE. On the first reference, the GPE is
195 *              hardware-enabled.
196 *
197 ******************************************************************************/
198
199ACPI_STATUS
200AcpiEnableGpe (
201    ACPI_HANDLE             GpeDevice,
202    UINT32                  GpeNumber)
203{
204    ACPI_STATUS             Status = AE_BAD_PARAMETER;
205    ACPI_GPE_EVENT_INFO     *GpeEventInfo;
206    ACPI_CPU_FLAGS          Flags;
207
208
209    ACPI_FUNCTION_TRACE (AcpiEnableGpe);
210
211
212    Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
213
214    /* Ensure that we have a valid GPE number */
215
216    GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
217    if (GpeEventInfo)
218    {
219        Status = AcpiEvAddGpeReference (GpeEventInfo);
220    }
221
222    AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
223    return_ACPI_STATUS (Status);
224}
225
226ACPI_EXPORT_SYMBOL (AcpiEnableGpe)
227
228
229/*******************************************************************************
230 *
231 * FUNCTION:    AcpiDisableGpe
232 *
233 * PARAMETERS:  GpeDevice           - Parent GPE Device. NULL for GPE0/GPE1
234 *              GpeNumber           - GPE level within the GPE block
235 *
236 * RETURN:      Status
237 *
238 * DESCRIPTION: Remove a reference to a GPE. When the last reference is
239 *              removed, only then is the GPE disabled (for runtime GPEs), or
240 *              the GPE mask bit disabled (for wake GPEs)
241 *
242 ******************************************************************************/
243
244ACPI_STATUS
245AcpiDisableGpe (
246    ACPI_HANDLE             GpeDevice,
247    UINT32                  GpeNumber)
248{
249    ACPI_STATUS             Status = AE_BAD_PARAMETER;
250    ACPI_GPE_EVENT_INFO     *GpeEventInfo;
251    ACPI_CPU_FLAGS          Flags;
252
253
254    ACPI_FUNCTION_TRACE (AcpiDisableGpe);
255
256
257    Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
258
259    /* Ensure that we have a valid GPE number */
260
261    GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
262    if (GpeEventInfo)
263    {
264        Status = AcpiEvRemoveGpeReference (GpeEventInfo);
265    }
266
267    AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
268    return_ACPI_STATUS (Status);
269}
270
271ACPI_EXPORT_SYMBOL (AcpiDisableGpe)
272
273
274/*******************************************************************************
275 *
276 * FUNCTION:    AcpiSetGpe
277 *
278 * PARAMETERS:  GpeDevice           - Parent GPE Device. NULL for GPE0/GPE1
279 *              GpeNumber           - GPE level within the GPE block
280 *              Action              - ACPI_GPE_ENABLE or ACPI_GPE_DISABLE
281 *
282 * RETURN:      Status
283 *
284 * DESCRIPTION: Enable or disable an individual GPE. This function bypasses
285 *              the reference count mechanism used in the AcpiEnableGpe and
286 *              AcpiDisableGpe interfaces -- and should be used with care.
287 *
288 * Note: Typically used to disable a runtime GPE for short period of time,
289 * then re-enable it, without disturbing the existing reference counts. This
290 * is useful, for example, in the Embedded Controller (EC) driver.
291 *
292 ******************************************************************************/
293
294ACPI_STATUS
295AcpiSetGpe (
296    ACPI_HANDLE             GpeDevice,
297    UINT32                  GpeNumber,
298    UINT8                   Action)
299{
300    ACPI_GPE_EVENT_INFO     *GpeEventInfo;
301    ACPI_STATUS             Status;
302    ACPI_CPU_FLAGS          Flags;
303
304
305    ACPI_FUNCTION_TRACE (AcpiSetGpe);
306
307
308    Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
309
310    /* Ensure that we have a valid GPE number */
311
312    GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
313    if (!GpeEventInfo)
314    {
315        Status = AE_BAD_PARAMETER;
316        goto UnlockAndExit;
317    }
318
319    /* Perform the action */
320
321    switch (Action)
322    {
323    case ACPI_GPE_ENABLE:
324        Status = AcpiEvEnableGpe (GpeEventInfo);
325        break;
326
327    case ACPI_GPE_DISABLE:
328        Status = AcpiHwLowSetGpe (GpeEventInfo, ACPI_GPE_DISABLE);
329        break;
330
331    default:
332        Status = AE_BAD_PARAMETER;
333        break;
334    }
335
336UnlockAndExit:
337    AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
338    return_ACPI_STATUS (Status);
339}
340
341ACPI_EXPORT_SYMBOL (AcpiSetGpe)
342
343
344/*******************************************************************************
345 *
346 * FUNCTION:    AcpiSetupGpeForWake
347 *
348 * PARAMETERS:  WakeDevice          - Device associated with the GPE (via _PRW)
349 *              GpeDevice           - Parent GPE Device. NULL for GPE0/GPE1
350 *              GpeNumber           - GPE level within the GPE block
351 *
352 * RETURN:      Status
353 *
354 * DESCRIPTION: Mark a GPE as having the ability to wake the system. This
355 *              interface is intended to be used as the host executes the
356 *              _PRW methods (Power Resources for Wake) in the system tables.
357 *              Each _PRW appears under a Device Object (The WakeDevice), and
358 *              contains the info for the wake GPE associated with the
359 *              WakeDevice.
360 *
361 ******************************************************************************/
362
363ACPI_STATUS
364AcpiSetupGpeForWake (
365    ACPI_HANDLE             WakeDevice,
366    ACPI_HANDLE             GpeDevice,
367    UINT32                  GpeNumber)
368{
369    ACPI_STATUS             Status = AE_BAD_PARAMETER;
370    ACPI_GPE_EVENT_INFO     *GpeEventInfo;
371    ACPI_NAMESPACE_NODE     *DeviceNode;
372    ACPI_CPU_FLAGS          Flags;
373
374
375    ACPI_FUNCTION_TRACE (AcpiSetupGpeForWake);
376
377
378    /* Parameter Validation */
379
380    if (!WakeDevice)
381    {
382        /*
383         * By forcing WakeDevice to be valid, we automatically enable the
384         * implicit notify feature on all hosts.
385         */
386        return_ACPI_STATUS (AE_BAD_PARAMETER);
387    }
388
389    /* Validate WakeDevice is of type Device */
390
391    DeviceNode = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, WakeDevice);
392    if (DeviceNode->Type != ACPI_TYPE_DEVICE)
393    {
394        return_ACPI_STATUS (AE_BAD_PARAMETER);
395    }
396
397    Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
398
399    /* Ensure that we have a valid GPE number */
400
401    GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
402    if (GpeEventInfo)
403    {
404        /*
405         * If there is no method or handler for this GPE, then the
406         * WakeDevice will be notified whenever this GPE fires (aka
407         * "implicit notify") Note: The GPE is assumed to be
408         * level-triggered (for windows compatibility).
409         */
410        if ((GpeEventInfo->Flags & ACPI_GPE_DISPATCH_MASK) ==
411                ACPI_GPE_DISPATCH_NONE)
412        {
413            GpeEventInfo->Flags =
414                (ACPI_GPE_DISPATCH_NOTIFY | ACPI_GPE_LEVEL_TRIGGERED);
415            GpeEventInfo->Dispatch.DeviceNode = DeviceNode;
416        }
417
418        GpeEventInfo->Flags |= ACPI_GPE_CAN_WAKE;
419        Status = AE_OK;
420    }
421
422    AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
423    return_ACPI_STATUS (Status);
424}
425
426ACPI_EXPORT_SYMBOL (AcpiSetupGpeForWake)
427
428
429/*******************************************************************************
430 *
431 * FUNCTION:    AcpiSetGpeWakeMask
432 *
433 * PARAMETERS:  GpeDevice           - Parent GPE Device. NULL for GPE0/GPE1
434 *              GpeNumber           - GPE level within the GPE block
435 *              Action              - Enable or Disable
436 *
437 * RETURN:      Status
438 *
439 * DESCRIPTION: Set or clear the GPE's wakeup enable mask bit. The GPE must
440 *              already be marked as a WAKE GPE.
441 *
442 ******************************************************************************/
443
444ACPI_STATUS
445AcpiSetGpeWakeMask (
446    ACPI_HANDLE             GpeDevice,
447    UINT32                  GpeNumber,
448    UINT8                   Action)
449{
450    ACPI_STATUS             Status = AE_OK;
451    ACPI_GPE_EVENT_INFO     *GpeEventInfo;
452    ACPI_GPE_REGISTER_INFO  *GpeRegisterInfo;
453    ACPI_CPU_FLAGS          Flags;
454    UINT32                  RegisterBit;
455
456
457    ACPI_FUNCTION_TRACE (AcpiSetGpeWakeMask);
458
459
460    Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
461
462    /*
463     * Ensure that we have a valid GPE number and that this GPE is in
464     * fact a wake GPE
465     */
466    GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
467    if (!GpeEventInfo)
468    {
469        Status = AE_BAD_PARAMETER;
470        goto UnlockAndExit;
471    }
472
473    if (!(GpeEventInfo->Flags & ACPI_GPE_CAN_WAKE))
474    {
475        Status = AE_TYPE;
476        goto UnlockAndExit;
477    }
478
479    GpeRegisterInfo = GpeEventInfo->RegisterInfo;
480    if (!GpeRegisterInfo)
481    {
482        Status = AE_NOT_EXIST;
483        goto UnlockAndExit;
484    }
485
486    RegisterBit = AcpiHwGetGpeRegisterBit (GpeEventInfo, GpeRegisterInfo);
487
488    /* Perform the action */
489
490    switch (Action)
491    {
492    case ACPI_GPE_ENABLE:
493        ACPI_SET_BIT (GpeRegisterInfo->EnableForWake, (UINT8) RegisterBit);
494        break;
495
496    case ACPI_GPE_DISABLE:
497        ACPI_CLEAR_BIT (GpeRegisterInfo->EnableForWake, (UINT8) RegisterBit);
498        break;
499
500    default:
501        ACPI_ERROR ((AE_INFO, "%u, Invalid action", Action));
502        Status = AE_BAD_PARAMETER;
503        break;
504    }
505
506UnlockAndExit:
507    AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
508    return_ACPI_STATUS (Status);
509}
510
511ACPI_EXPORT_SYMBOL (AcpiSetGpeWakeMask)
512
513
514/*******************************************************************************
515 *
516 * FUNCTION:    AcpiClearGpe
517 *
518 * PARAMETERS:  GpeDevice           - Parent GPE Device. NULL for GPE0/GPE1
519 *              GpeNumber           - GPE level within the GPE block
520 *
521 * RETURN:      Status
522 *
523 * DESCRIPTION: Clear an ACPI event (general purpose)
524 *
525 ******************************************************************************/
526
527ACPI_STATUS
528AcpiClearGpe (
529    ACPI_HANDLE             GpeDevice,
530    UINT32                  GpeNumber)
531{
532    ACPI_STATUS             Status = AE_OK;
533    ACPI_GPE_EVENT_INFO     *GpeEventInfo;
534    ACPI_CPU_FLAGS          Flags;
535
536
537    ACPI_FUNCTION_TRACE (AcpiClearGpe);
538
539
540    Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
541
542    /* Ensure that we have a valid GPE number */
543
544    GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
545    if (!GpeEventInfo)
546    {
547        Status = AE_BAD_PARAMETER;
548        goto UnlockAndExit;
549    }
550
551    Status = AcpiHwClearGpe (GpeEventInfo);
552
553UnlockAndExit:
554    AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
555    return_ACPI_STATUS (Status);
556}
557
558ACPI_EXPORT_SYMBOL (AcpiClearGpe)
559
560
561/*******************************************************************************
562 *
563 * FUNCTION:    AcpiGetGpeStatus
564 *
565 * PARAMETERS:  GpeDevice           - Parent GPE Device. NULL for GPE0/GPE1
566 *              GpeNumber           - GPE level within the GPE block
567 *              EventStatus         - Where the current status of the event
568 *                                    will be returned
569 *
570 * RETURN:      Status
571 *
572 * DESCRIPTION: Get the current status of a GPE (signalled/not_signalled)
573 *
574 ******************************************************************************/
575
576ACPI_STATUS
577AcpiGetGpeStatus (
578    ACPI_HANDLE             GpeDevice,
579    UINT32                  GpeNumber,
580    ACPI_EVENT_STATUS       *EventStatus)
581{
582    ACPI_STATUS             Status = AE_OK;
583    ACPI_GPE_EVENT_INFO     *GpeEventInfo;
584    ACPI_CPU_FLAGS          Flags;
585
586
587    ACPI_FUNCTION_TRACE (AcpiGetGpeStatus);
588
589
590    Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
591
592    /* Ensure that we have a valid GPE number */
593
594    GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
595    if (!GpeEventInfo)
596    {
597        Status = AE_BAD_PARAMETER;
598        goto UnlockAndExit;
599    }
600
601    /* Obtain status on the requested GPE number */
602
603    Status = AcpiHwGetGpeStatus (GpeEventInfo, EventStatus);
604
605UnlockAndExit:
606    AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
607    return_ACPI_STATUS (Status);
608}
609
610ACPI_EXPORT_SYMBOL (AcpiGetGpeStatus)
611
612
613/*******************************************************************************
614 *
615 * FUNCTION:    AcpiFinishGpe
616 *
617 * PARAMETERS:  GpeDevice           - Namespace node for the GPE Block
618 *                                    (NULL for FADT defined GPEs)
619 *              GpeNumber           - GPE level within the GPE block
620 *
621 * RETURN:      Status
622 *
623 * DESCRIPTION: Clear and conditionally reenable a GPE. This completes the GPE
624 *              processing. Intended for use by asynchronous host-installed
625 *              GPE handlers. The GPE is only reenabled if the EnableForRun bit
626 *              is set in the GPE info.
627 *
628 ******************************************************************************/
629
630ACPI_STATUS
631AcpiFinishGpe (
632    ACPI_HANDLE             GpeDevice,
633    UINT32                  GpeNumber)
634{
635    ACPI_GPE_EVENT_INFO     *GpeEventInfo;
636    ACPI_STATUS             Status;
637    ACPI_CPU_FLAGS          Flags;
638
639
640    ACPI_FUNCTION_TRACE (AcpiFinishGpe);
641
642
643    Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
644
645    /* Ensure that we have a valid GPE number */
646
647    GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
648    if (!GpeEventInfo)
649    {
650        Status = AE_BAD_PARAMETER;
651        goto UnlockAndExit;
652    }
653
654    Status = AcpiEvFinishGpe (GpeEventInfo);
655
656UnlockAndExit:
657    AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
658    return_ACPI_STATUS (Status);
659}
660
661ACPI_EXPORT_SYMBOL (AcpiFinishGpe)
662
663
664/******************************************************************************
665 *
666 * FUNCTION:    AcpiDisableAllGpes
667 *
668 * PARAMETERS:  None
669 *
670 * RETURN:      Status
671 *
672 * DESCRIPTION: Disable and clear all GPEs in all GPE blocks
673 *
674 ******************************************************************************/
675
676ACPI_STATUS
677AcpiDisableAllGpes (
678    void)
679{
680    ACPI_STATUS             Status;
681
682
683    ACPI_FUNCTION_TRACE (AcpiDisableAllGpes);
684
685
686    Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
687    if (ACPI_FAILURE (Status))
688    {
689        return_ACPI_STATUS (Status);
690    }
691
692    Status = AcpiHwDisableAllGpes ();
693    (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
694
695    return_ACPI_STATUS (Status);
696}
697
698ACPI_EXPORT_SYMBOL (AcpiDisableAllGpes)
699
700
701/******************************************************************************
702 *
703 * FUNCTION:    AcpiEnableAllRuntimeGpes
704 *
705 * PARAMETERS:  None
706 *
707 * RETURN:      Status
708 *
709 * DESCRIPTION: Enable all "runtime" GPEs, in all GPE blocks
710 *
711 ******************************************************************************/
712
713ACPI_STATUS
714AcpiEnableAllRuntimeGpes (
715    void)
716{
717    ACPI_STATUS             Status;
718
719
720    ACPI_FUNCTION_TRACE (AcpiEnableAllRuntimeGpes);
721
722
723    Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
724    if (ACPI_FAILURE (Status))
725    {
726        return_ACPI_STATUS (Status);
727    }
728
729    Status = AcpiHwEnableAllRuntimeGpes ();
730    (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
731
732    return_ACPI_STATUS (Status);
733}
734
735ACPI_EXPORT_SYMBOL (AcpiEnableAllRuntimeGpes)
736
737
738/*******************************************************************************
739 *
740 * FUNCTION:    AcpiInstallGpeBlock
741 *
742 * PARAMETERS:  GpeDevice           - Handle to the parent GPE Block Device
743 *              GpeBlockAddress     - Address and SpaceID
744 *              RegisterCount       - Number of GPE register pairs in the block
745 *              InterruptNumber     - H/W interrupt for the block
746 *
747 * RETURN:      Status
748 *
749 * DESCRIPTION: Create and Install a block of GPE registers. The GPEs are not
750 *              enabled here.
751 *
752 ******************************************************************************/
753
754ACPI_STATUS
755AcpiInstallGpeBlock (
756    ACPI_HANDLE             GpeDevice,
757    ACPI_GENERIC_ADDRESS    *GpeBlockAddress,
758    UINT32                  RegisterCount,
759    UINT32                  InterruptNumber)
760{
761    ACPI_STATUS             Status;
762    ACPI_OPERAND_OBJECT     *ObjDesc;
763    ACPI_NAMESPACE_NODE     *Node;
764    ACPI_GPE_BLOCK_INFO     *GpeBlock;
765
766
767    ACPI_FUNCTION_TRACE (AcpiInstallGpeBlock);
768
769
770    if ((!GpeDevice)       ||
771        (!GpeBlockAddress) ||
772        (!RegisterCount))
773    {
774        return_ACPI_STATUS (AE_BAD_PARAMETER);
775    }
776
777    Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
778    if (ACPI_FAILURE (Status))
779    {
780        return (Status);
781    }
782
783    Node = AcpiNsValidateHandle (GpeDevice);
784    if (!Node)
785    {
786        Status = AE_BAD_PARAMETER;
787        goto UnlockAndExit;
788    }
789
790    /*
791     * For user-installed GPE Block Devices, the GpeBlockBaseNumber
792     * is always zero
793     */
794    Status = AcpiEvCreateGpeBlock (Node, GpeBlockAddress, RegisterCount,
795                0, InterruptNumber, &GpeBlock);
796    if (ACPI_FAILURE (Status))
797    {
798        goto UnlockAndExit;
799    }
800
801    /* Install block in the DeviceObject attached to the node */
802
803    ObjDesc = AcpiNsGetAttachedObject (Node);
804    if (!ObjDesc)
805    {
806        /*
807         * No object, create a new one (Device nodes do not always have
808         * an attached object)
809         */
810        ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_DEVICE);
811        if (!ObjDesc)
812        {
813            Status = AE_NO_MEMORY;
814            goto UnlockAndExit;
815        }
816
817        Status = AcpiNsAttachObject (Node, ObjDesc, ACPI_TYPE_DEVICE);
818
819        /* Remove local reference to the object */
820
821        AcpiUtRemoveReference (ObjDesc);
822        if (ACPI_FAILURE (Status))
823        {
824            goto UnlockAndExit;
825        }
826    }
827
828    /* Now install the GPE block in the DeviceObject */
829
830    ObjDesc->Device.GpeBlock = GpeBlock;
831
832
833UnlockAndExit:
834    (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
835    return_ACPI_STATUS (Status);
836}
837
838ACPI_EXPORT_SYMBOL (AcpiInstallGpeBlock)
839
840
841/*******************************************************************************
842 *
843 * FUNCTION:    AcpiRemoveGpeBlock
844 *
845 * PARAMETERS:  GpeDevice           - Handle to the parent GPE Block Device
846 *
847 * RETURN:      Status
848 *
849 * DESCRIPTION: Remove a previously installed block of GPE registers
850 *
851 ******************************************************************************/
852
853ACPI_STATUS
854AcpiRemoveGpeBlock (
855    ACPI_HANDLE             GpeDevice)
856{
857    ACPI_OPERAND_OBJECT     *ObjDesc;
858    ACPI_STATUS             Status;
859    ACPI_NAMESPACE_NODE     *Node;
860
861
862    ACPI_FUNCTION_TRACE (AcpiRemoveGpeBlock);
863
864
865    if (!GpeDevice)
866    {
867        return_ACPI_STATUS (AE_BAD_PARAMETER);
868    }
869
870    Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
871    if (ACPI_FAILURE (Status))
872    {
873        return (Status);
874    }
875
876    Node = AcpiNsValidateHandle (GpeDevice);
877    if (!Node)
878    {
879        Status = AE_BAD_PARAMETER;
880        goto UnlockAndExit;
881    }
882
883    /* Get the DeviceObject attached to the node */
884
885    ObjDesc = AcpiNsGetAttachedObject (Node);
886    if (!ObjDesc ||
887        !ObjDesc->Device.GpeBlock)
888    {
889        return_ACPI_STATUS (AE_NULL_OBJECT);
890    }
891
892    /* Delete the GPE block (but not the DeviceObject) */
893
894    Status = AcpiEvDeleteGpeBlock (ObjDesc->Device.GpeBlock);
895    if (ACPI_SUCCESS (Status))
896    {
897        ObjDesc->Device.GpeBlock = NULL;
898    }
899
900UnlockAndExit:
901    (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
902    return_ACPI_STATUS (Status);
903}
904
905ACPI_EXPORT_SYMBOL (AcpiRemoveGpeBlock)
906
907
908/*******************************************************************************
909 *
910 * FUNCTION:    AcpiGetGpeDevice
911 *
912 * PARAMETERS:  Index               - System GPE index (0-CurrentGpeCount)
913 *              GpeDevice           - Where the parent GPE Device is returned
914 *
915 * RETURN:      Status
916 *
917 * DESCRIPTION: Obtain the GPE device associated with the input index. A NULL
918 *              gpe device indicates that the gpe number is contained in one of
919 *              the FADT-defined gpe blocks. Otherwise, the GPE block device.
920 *
921 ******************************************************************************/
922
923ACPI_STATUS
924AcpiGetGpeDevice (
925    UINT32                  Index,
926    ACPI_HANDLE             *GpeDevice)
927{
928    ACPI_GPE_DEVICE_INFO    Info;
929    ACPI_STATUS             Status;
930
931
932    ACPI_FUNCTION_TRACE (AcpiGetGpeDevice);
933
934
935    if (!GpeDevice)
936    {
937        return_ACPI_STATUS (AE_BAD_PARAMETER);
938    }
939
940    if (Index >= AcpiCurrentGpeCount)
941    {
942        return_ACPI_STATUS (AE_NOT_EXIST);
943    }
944
945    /* Setup and walk the GPE list */
946
947    Info.Index = Index;
948    Info.Status = AE_NOT_EXIST;
949    Info.GpeDevice = NULL;
950    Info.NextBlockBaseIndex = 0;
951
952    Status = AcpiEvWalkGpeList (AcpiEvGetGpeDevice, &Info);
953    if (ACPI_FAILURE (Status))
954    {
955        return_ACPI_STATUS (Status);
956    }
957
958    *GpeDevice = ACPI_CAST_PTR (ACPI_HANDLE, Info.GpeDevice);
959    return_ACPI_STATUS (Info.Status);
960}
961
962ACPI_EXPORT_SYMBOL (AcpiGetGpeDevice)
963