1 /******************************************************************************
3 * Module Name: evxfgpe - External Interfaces for General Purpose Events (GPEs)
5 *****************************************************************************/
7 /******************************************************************************
11 * Some or all of this work - Copyright (c) 1999 - 2018, Intel Corp.
12 * All rights reserved.
16 * 2.1. This is your license from Intel Corp. under its intellectual property
17 * rights. You may have additional license terms from the party that provided
18 * you this software, covering your right to use that party's intellectual
21 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22 * copy of the source code appearing in this file ("Covered Code") an
23 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24 * base code distributed originally by Intel ("Original Intel Code") to copy,
25 * make derivatives, distribute, use and display any portion of the Covered
26 * Code in any form, with the right to sublicense such rights; and
28 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29 * license (with the right to sublicense), under only those claims of Intel
30 * patents that are infringed by the Original Intel Code, to make, use, sell,
31 * offer to sell, and import the Covered Code and derivative works thereof
32 * solely to the minimum extent necessary to exercise the above copyright
33 * license, and in no event shall the patent license extend to any additions
34 * to or modifications of the Original Intel Code. No other license or right
35 * is granted directly or by implication, estoppel or otherwise;
37 * The above copyright and patent license is granted only if the following
42 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43 * Redistribution of source code of any substantial portion of the Covered
44 * Code or modification with rights to further distribute source must include
45 * the above Copyright Notice, the above License, this list of Conditions,
46 * and the following Disclaimer and Export Compliance provision. In addition,
47 * Licensee must cause all Covered Code to which Licensee contributes to
48 * contain a file documenting the changes Licensee made to create that Covered
49 * Code and the date of any change. Licensee must include in that file the
50 * documentation of any changes made by any predecessor Licensee. Licensee
51 * must include a prominent statement that the modification is derived,
52 * directly or indirectly, from Original Intel Code.
54 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55 * Redistribution of source code of any substantial portion of the Covered
56 * Code or modification without rights to further distribute source must
57 * include the following Disclaimer and Export Compliance provision in the
58 * documentation and/or other materials provided with distribution. In
59 * addition, Licensee may not authorize further sublicense of source of any
60 * portion of the Covered Code, and must include terms to the effect that the
61 * license from Licensee to its licensee is limited to the intellectual
62 * property embodied in the software Licensee provides to its licensee, and
63 * not to intellectual property embodied in modifications its licensee may
66 * 3.3. Redistribution of Executable. Redistribution in executable form of any
67 * substantial portion of the Covered Code or modification must reproduce the
68 * above Copyright Notice, and the following Disclaimer and Export Compliance
69 * provision in the documentation and/or other materials provided with the
72 * 3.4. Intel retains all right, title, and interest in and to the Original
75 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76 * Intel shall be used in advertising or otherwise to promote the sale, use or
77 * other dealings in products derived from or relating to the Covered Code
78 * without prior written authorization from Intel.
80 * 4. Disclaimer and Export Compliance
82 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
90 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
99 * 4.3. Licensee shall not export, either directly or indirectly, any of this
100 * software or system incorporating such software without first obtaining any
101 * required license or other approval from the U. S. Department of Commerce or
102 * any other agency or department of the United States Government. In the
103 * event Licensee exports any such software from the United States or
104 * re-exports any such software from a foreign destination, Licensee shall
105 * ensure that the distribution and export/re-export of the software is in
106 * compliance with all laws, regulations, orders, or other restrictions of the
107 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108 * any of its subsidiaries will export/re-export any technical data, process,
109 * software, or service, directly or indirectly, to any country for which the
110 * United States government or any agency thereof requires an export license,
111 * other governmental approval, or letter of assurance, without first obtaining
112 * such license, approval or letter.
114 *****************************************************************************
116 * Alternatively, you may choose to be licensed under the terms of the
119 * Redistribution and use in source and binary forms, with or without
120 * modification, are permitted provided that the following conditions
122 * 1. Redistributions of source code must retain the above copyright
123 * notice, this list of conditions, and the following disclaimer,
124 * without modification.
125 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
126 * substantially similar to the "NO WARRANTY" disclaimer below
127 * ("Disclaimer") and any redistribution must be conditioned upon
128 * including a substantially similar Disclaimer requirement for further
129 * binary redistribution.
130 * 3. Neither the names of the above-listed copyright holders nor the names
131 * of any contributors may be used to endorse or promote products derived
132 * from this software without specific prior written permission.
134 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
135 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
136 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
137 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
138 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
139 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
140 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
141 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
142 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
143 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
144 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
146 * Alternatively, you may choose to be licensed under the terms of the
147 * GNU General Public License ("GPL") version 2 as published by the Free
148 * Software Foundation.
150 *****************************************************************************/
152 #define EXPORT_ACPI_INTERFACES
154 #include <contrib/dev/acpica/include/acpi.h>
155 #include <contrib/dev/acpica/include/accommon.h>
156 #include <contrib/dev/acpica/include/acevents.h>
157 #include <contrib/dev/acpica/include/acnamesp.h>
159 #define _COMPONENT ACPI_EVENTS
160 ACPI_MODULE_NAME ("evxfgpe")
163 #if (!ACPI_REDUCED_HARDWARE) /* Entire module */
164 /*******************************************************************************
166 * FUNCTION: AcpiUpdateAllGpes
172 * DESCRIPTION: Complete GPE initialization and enable all GPEs that have
173 * associated _Lxx or _Exx methods and are not pointed to by any
174 * device _PRW methods (this indicates that these GPEs are
175 * generally intended for system or device wakeup. Such GPEs
176 * have to be enabled directly when the devices whose _PRW
177 * methods point to them are set up for wakeup signaling.)
179 * NOTE: Should be called after any GPEs are added to the system. Primarily,
180 * after the system _PRW methods have been run, but also after a GPE Block
181 * Device has been added or if any new GPE methods have been added via a
182 * dynamic table load.
184 ******************************************************************************/
191 BOOLEAN IsPollingNeeded = FALSE;
194 ACPI_FUNCTION_TRACE (AcpiUpdateAllGpes);
197 Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
198 if (ACPI_FAILURE (Status))
200 return_ACPI_STATUS (Status);
203 if (AcpiGbl_AllGpesInitialized)
208 Status = AcpiEvWalkGpeList (AcpiEvInitializeGpeBlock,
210 if (ACPI_SUCCESS (Status))
212 AcpiGbl_AllGpesInitialized = TRUE;
216 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
218 if (IsPollingNeeded && AcpiGbl_AllGpesInitialized)
220 /* Poll GPEs to handle already triggered events */
222 AcpiEvGpeDetect (AcpiGbl_GpeXruptListHead);
224 return_ACPI_STATUS (Status);
227 ACPI_EXPORT_SYMBOL (AcpiUpdateAllGpes)
230 /*******************************************************************************
232 * FUNCTION: AcpiEnableGpe
234 * PARAMETERS: GpeDevice - Parent GPE Device. NULL for GPE0/GPE1
235 * GpeNumber - GPE level within the GPE block
239 * DESCRIPTION: Add a reference to a GPE. On the first reference, the GPE is
242 ******************************************************************************/
246 ACPI_HANDLE GpeDevice,
249 ACPI_STATUS Status = AE_BAD_PARAMETER;
250 ACPI_GPE_EVENT_INFO *GpeEventInfo;
251 ACPI_CPU_FLAGS Flags;
254 ACPI_FUNCTION_TRACE (AcpiEnableGpe);
257 Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
260 * Ensure that we have a valid GPE number and that there is some way
261 * of handling the GPE (handler or a GPE method). In other words, we
262 * won't allow a valid GPE to be enabled if there is no way to handle it.
264 GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
267 if (ACPI_GPE_DISPATCH_TYPE (GpeEventInfo->Flags) !=
268 ACPI_GPE_DISPATCH_NONE)
270 Status = AcpiEvAddGpeReference (GpeEventInfo);
271 if (ACPI_SUCCESS (Status) &&
272 ACPI_GPE_IS_POLLING_NEEDED (GpeEventInfo))
274 /* Poll edge-triggered GPEs to handle existing events */
276 AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
277 (void) AcpiEvDetectGpe (
278 GpeDevice, GpeEventInfo, GpeNumber);
279 Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
284 Status = AE_NO_HANDLER;
288 AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
289 return_ACPI_STATUS (Status);
292 ACPI_EXPORT_SYMBOL (AcpiEnableGpe)
295 /*******************************************************************************
297 * FUNCTION: AcpiDisableGpe
299 * PARAMETERS: GpeDevice - Parent GPE Device. NULL for GPE0/GPE1
300 * GpeNumber - GPE level within the GPE block
304 * DESCRIPTION: Remove a reference to a GPE. When the last reference is
305 * removed, only then is the GPE disabled (for runtime GPEs), or
306 * the GPE mask bit disabled (for wake GPEs)
308 ******************************************************************************/
312 ACPI_HANDLE GpeDevice,
315 ACPI_STATUS Status = AE_BAD_PARAMETER;
316 ACPI_GPE_EVENT_INFO *GpeEventInfo;
317 ACPI_CPU_FLAGS Flags;
320 ACPI_FUNCTION_TRACE (AcpiDisableGpe);
323 Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
325 /* Ensure that we have a valid GPE number */
327 GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
330 Status = AcpiEvRemoveGpeReference (GpeEventInfo);
333 AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
334 return_ACPI_STATUS (Status);
337 ACPI_EXPORT_SYMBOL (AcpiDisableGpe)
340 /*******************************************************************************
342 * FUNCTION: AcpiSetGpe
344 * PARAMETERS: GpeDevice - Parent GPE Device. NULL for GPE0/GPE1
345 * GpeNumber - GPE level within the GPE block
346 * Action - ACPI_GPE_ENABLE or ACPI_GPE_DISABLE
350 * DESCRIPTION: Enable or disable an individual GPE. This function bypasses
351 * the reference count mechanism used in the AcpiEnableGpe(),
352 * AcpiDisableGpe() interfaces.
353 * This API is typically used by the GPE raw handler mode driver
354 * to switch between the polling mode and the interrupt mode after
355 * the driver has enabled the GPE.
356 * The APIs should be invoked in this order:
357 * AcpiEnableGpe() <- Ensure the reference count > 0
358 * AcpiSetGpe(ACPI_GPE_DISABLE) <- Enter polling mode
359 * AcpiSetGpe(ACPI_GPE_ENABLE) <- Leave polling mode
360 * AcpiDisableGpe() <- Decrease the reference count
362 * Note: If a GPE is shared by 2 silicon components, then both the drivers
363 * should support GPE polling mode or disabling the GPE for long period
364 * for one driver may break the other. So use it with care since all
365 * firmware _Lxx/_Exx handlers currently rely on the GPE interrupt mode.
367 ******************************************************************************/
371 ACPI_HANDLE GpeDevice,
375 ACPI_GPE_EVENT_INFO *GpeEventInfo;
377 ACPI_CPU_FLAGS Flags;
380 ACPI_FUNCTION_TRACE (AcpiSetGpe);
383 Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
385 /* Ensure that we have a valid GPE number */
387 GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
390 Status = AE_BAD_PARAMETER;
394 /* Perform the action */
398 case ACPI_GPE_ENABLE:
400 Status = AcpiHwLowSetGpe (GpeEventInfo, ACPI_GPE_ENABLE);
401 GpeEventInfo->DisableForDispatch = FALSE;
404 case ACPI_GPE_DISABLE:
406 Status = AcpiHwLowSetGpe (GpeEventInfo, ACPI_GPE_DISABLE);
407 GpeEventInfo->DisableForDispatch = TRUE;
412 Status = AE_BAD_PARAMETER;
417 AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
418 return_ACPI_STATUS (Status);
421 ACPI_EXPORT_SYMBOL (AcpiSetGpe)
424 /*******************************************************************************
426 * FUNCTION: AcpiMaskGpe
428 * PARAMETERS: GpeDevice - Parent GPE Device. NULL for GPE0/GPE1
429 * GpeNumber - GPE level within the GPE block
430 * IsMasked - Whether the GPE is masked or not
434 * DESCRIPTION: Unconditionally mask/unmask the an individual GPE, ex., to
435 * prevent a GPE flooding.
437 ******************************************************************************/
441 ACPI_HANDLE GpeDevice,
445 ACPI_GPE_EVENT_INFO *GpeEventInfo;
447 ACPI_CPU_FLAGS Flags;
450 ACPI_FUNCTION_TRACE (AcpiMaskGpe);
453 Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
455 /* Ensure that we have a valid GPE number */
457 GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
460 Status = AE_BAD_PARAMETER;
464 Status = AcpiEvMaskGpe (GpeEventInfo, IsMasked);
467 AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
468 return_ACPI_STATUS (Status);
471 ACPI_EXPORT_SYMBOL (AcpiMaskGpe)
474 /*******************************************************************************
476 * FUNCTION: AcpiMarkGpeForWake
478 * PARAMETERS: GpeDevice - Parent GPE Device. NULL for GPE0/GPE1
479 * GpeNumber - GPE level within the GPE block
483 * DESCRIPTION: Mark a GPE as having the ability to wake the system. Simply
484 * sets the ACPI_GPE_CAN_WAKE flag.
486 * Some potential callers of AcpiSetupGpeForWake may know in advance that
487 * there won't be any notify handlers installed for device wake notifications
488 * from the given GPE (one example is a button GPE in Linux). For these cases,
489 * AcpiMarkGpeForWake should be used instead of AcpiSetupGpeForWake.
490 * This will set the ACPI_GPE_CAN_WAKE flag for the GPE without trying to
491 * setup implicit wake notification for it (since there's no handler method).
493 ******************************************************************************/
497 ACPI_HANDLE GpeDevice,
500 ACPI_GPE_EVENT_INFO *GpeEventInfo;
501 ACPI_STATUS Status = AE_BAD_PARAMETER;
502 ACPI_CPU_FLAGS Flags;
505 ACPI_FUNCTION_TRACE (AcpiMarkGpeForWake);
508 Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
510 /* Ensure that we have a valid GPE number */
512 GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
515 /* Mark the GPE as a possible wake event */
517 GpeEventInfo->Flags |= ACPI_GPE_CAN_WAKE;
521 AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
522 return_ACPI_STATUS (Status);
525 ACPI_EXPORT_SYMBOL (AcpiMarkGpeForWake)
528 /*******************************************************************************
530 * FUNCTION: AcpiSetupGpeForWake
532 * PARAMETERS: WakeDevice - Device associated with the GPE (via _PRW)
533 * GpeDevice - Parent GPE Device. NULL for GPE0/GPE1
534 * GpeNumber - GPE level within the GPE block
538 * DESCRIPTION: Mark a GPE as having the ability to wake the system. This
539 * interface is intended to be used as the host executes the
540 * _PRW methods (Power Resources for Wake) in the system tables.
541 * Each _PRW appears under a Device Object (The WakeDevice), and
542 * contains the info for the wake GPE associated with the
545 ******************************************************************************/
548 AcpiSetupGpeForWake (
549 ACPI_HANDLE WakeDevice,
550 ACPI_HANDLE GpeDevice,
554 ACPI_GPE_EVENT_INFO *GpeEventInfo;
555 ACPI_NAMESPACE_NODE *DeviceNode;
556 ACPI_GPE_NOTIFY_INFO *Notify;
557 ACPI_GPE_NOTIFY_INFO *NewNotify;
558 ACPI_CPU_FLAGS Flags;
561 ACPI_FUNCTION_TRACE (AcpiSetupGpeForWake);
564 /* Parameter Validation */
569 * By forcing WakeDevice to be valid, we automatically enable the
570 * implicit notify feature on all hosts.
572 return_ACPI_STATUS (AE_BAD_PARAMETER);
575 /* Handle root object case */
577 if (WakeDevice == ACPI_ROOT_OBJECT)
579 DeviceNode = AcpiGbl_RootNode;
583 DeviceNode = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, WakeDevice);
586 /* Validate WakeDevice is of type Device */
588 if (DeviceNode->Type != ACPI_TYPE_DEVICE)
590 return_ACPI_STATUS (AE_BAD_PARAMETER);
594 * Allocate a new notify object up front, in case it is needed.
595 * Memory allocation while holding a spinlock is a big no-no
598 NewNotify = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_GPE_NOTIFY_INFO));
601 return_ACPI_STATUS (AE_NO_MEMORY);
604 Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
606 /* Ensure that we have a valid GPE number */
608 GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
611 Status = AE_BAD_PARAMETER;
616 * If there is no method or handler for this GPE, then the
617 * WakeDevice will be notified whenever this GPE fires. This is
618 * known as an "implicit notify". Note: The GPE is assumed to be
619 * level-triggered (for windows compatibility).
621 if (ACPI_GPE_DISPATCH_TYPE (GpeEventInfo->Flags) ==
622 ACPI_GPE_DISPATCH_NONE)
625 * This is the first device for implicit notify on this GPE.
626 * Just set the flags here, and enter the NOTIFY block below.
628 GpeEventInfo->Flags =
629 (ACPI_GPE_DISPATCH_NOTIFY | ACPI_GPE_LEVEL_TRIGGERED);
631 else if (GpeEventInfo->Flags & ACPI_GPE_AUTO_ENABLED)
634 * A reference to this GPE has been added during the GPE block
635 * initialization, so drop it now to prevent the GPE from being
636 * permanently enabled and clear its ACPI_GPE_AUTO_ENABLED flag.
638 (void) AcpiEvRemoveGpeReference (GpeEventInfo);
639 GpeEventInfo->Flags &= ~~ACPI_GPE_AUTO_ENABLED;
643 * If we already have an implicit notify on this GPE, add
644 * this device to the notify list.
646 if (ACPI_GPE_DISPATCH_TYPE (GpeEventInfo->Flags) ==
647 ACPI_GPE_DISPATCH_NOTIFY)
649 /* Ensure that the device is not already in the list */
651 Notify = GpeEventInfo->Dispatch.NotifyList;
654 if (Notify->DeviceNode == DeviceNode)
656 Status = AE_ALREADY_EXISTS;
659 Notify = Notify->Next;
662 /* Add this device to the notify list for this GPE */
664 NewNotify->DeviceNode = DeviceNode;
665 NewNotify->Next = GpeEventInfo->Dispatch.NotifyList;
666 GpeEventInfo->Dispatch.NotifyList = NewNotify;
670 /* Mark the GPE as a possible wake event */
672 GpeEventInfo->Flags |= ACPI_GPE_CAN_WAKE;
677 AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
679 /* Delete the notify object if it was not used above */
683 ACPI_FREE (NewNotify);
685 return_ACPI_STATUS (Status);
688 ACPI_EXPORT_SYMBOL (AcpiSetupGpeForWake)
691 /*******************************************************************************
693 * FUNCTION: AcpiSetGpeWakeMask
695 * PARAMETERS: GpeDevice - Parent GPE Device. NULL for GPE0/GPE1
696 * GpeNumber - GPE level within the GPE block
697 * Action - Enable or Disable
701 * DESCRIPTION: Set or clear the GPE's wakeup enable mask bit. The GPE must
702 * already be marked as a WAKE GPE.
704 ******************************************************************************/
708 ACPI_HANDLE GpeDevice,
712 ACPI_STATUS Status = AE_OK;
713 ACPI_GPE_EVENT_INFO *GpeEventInfo;
714 ACPI_GPE_REGISTER_INFO *GpeRegisterInfo;
715 ACPI_CPU_FLAGS Flags;
719 ACPI_FUNCTION_TRACE (AcpiSetGpeWakeMask);
722 Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
725 * Ensure that we have a valid GPE number and that this GPE is in
728 GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
731 Status = AE_BAD_PARAMETER;
735 if (!(GpeEventInfo->Flags & ACPI_GPE_CAN_WAKE))
741 GpeRegisterInfo = GpeEventInfo->RegisterInfo;
742 if (!GpeRegisterInfo)
744 Status = AE_NOT_EXIST;
748 RegisterBit = AcpiHwGetGpeRegisterBit (GpeEventInfo);
750 /* Perform the action */
754 case ACPI_GPE_ENABLE:
756 ACPI_SET_BIT (GpeRegisterInfo->EnableForWake, (UINT8) RegisterBit);
759 case ACPI_GPE_DISABLE:
761 ACPI_CLEAR_BIT (GpeRegisterInfo->EnableForWake, (UINT8) RegisterBit);
766 ACPI_ERROR ((AE_INFO, "%u, Invalid action", Action));
767 Status = AE_BAD_PARAMETER;
772 AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
773 return_ACPI_STATUS (Status);
776 ACPI_EXPORT_SYMBOL (AcpiSetGpeWakeMask)
779 /*******************************************************************************
781 * FUNCTION: AcpiClearGpe
783 * PARAMETERS: GpeDevice - Parent GPE Device. NULL for GPE0/GPE1
784 * GpeNumber - GPE level within the GPE block
788 * DESCRIPTION: Clear an ACPI event (general purpose)
790 ******************************************************************************/
794 ACPI_HANDLE GpeDevice,
797 ACPI_STATUS Status = AE_OK;
798 ACPI_GPE_EVENT_INFO *GpeEventInfo;
799 ACPI_CPU_FLAGS Flags;
802 ACPI_FUNCTION_TRACE (AcpiClearGpe);
805 Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
807 /* Ensure that we have a valid GPE number */
809 GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
812 Status = AE_BAD_PARAMETER;
816 Status = AcpiHwClearGpe (GpeEventInfo);
819 AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
820 return_ACPI_STATUS (Status);
823 ACPI_EXPORT_SYMBOL (AcpiClearGpe)
826 /*******************************************************************************
828 * FUNCTION: AcpiGetGpeStatus
830 * PARAMETERS: GpeDevice - Parent GPE Device. NULL for GPE0/GPE1
831 * GpeNumber - GPE level within the GPE block
832 * EventStatus - Where the current status of the event
837 * DESCRIPTION: Get the current status of a GPE (signalled/not_signalled)
839 ******************************************************************************/
843 ACPI_HANDLE GpeDevice,
845 ACPI_EVENT_STATUS *EventStatus)
847 ACPI_STATUS Status = AE_OK;
848 ACPI_GPE_EVENT_INFO *GpeEventInfo;
849 ACPI_CPU_FLAGS Flags;
852 ACPI_FUNCTION_TRACE (AcpiGetGpeStatus);
855 Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
857 /* Ensure that we have a valid GPE number */
859 GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
862 Status = AE_BAD_PARAMETER;
866 /* Obtain status on the requested GPE number */
868 Status = AcpiHwGetGpeStatus (GpeEventInfo, EventStatus);
871 AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
872 return_ACPI_STATUS (Status);
875 ACPI_EXPORT_SYMBOL (AcpiGetGpeStatus)
878 /*******************************************************************************
880 * FUNCTION: AcpiFinishGpe
882 * PARAMETERS: GpeDevice - Namespace node for the GPE Block
883 * (NULL for FADT defined GPEs)
884 * GpeNumber - GPE level within the GPE block
888 * DESCRIPTION: Clear and conditionally reenable a GPE. This completes the GPE
889 * processing. Intended for use by asynchronous host-installed
890 * GPE handlers. The GPE is only reenabled if the EnableForRun bit
891 * is set in the GPE info.
893 ******************************************************************************/
897 ACPI_HANDLE GpeDevice,
900 ACPI_GPE_EVENT_INFO *GpeEventInfo;
902 ACPI_CPU_FLAGS Flags;
905 ACPI_FUNCTION_TRACE (AcpiFinishGpe);
908 Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
910 /* Ensure that we have a valid GPE number */
912 GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
915 Status = AE_BAD_PARAMETER;
919 Status = AcpiEvFinishGpe (GpeEventInfo);
922 AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
923 return_ACPI_STATUS (Status);
926 ACPI_EXPORT_SYMBOL (AcpiFinishGpe)
929 /******************************************************************************
931 * FUNCTION: AcpiDisableAllGpes
937 * DESCRIPTION: Disable and clear all GPEs in all GPE blocks
939 ******************************************************************************/
948 ACPI_FUNCTION_TRACE (AcpiDisableAllGpes);
951 Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
952 if (ACPI_FAILURE (Status))
954 return_ACPI_STATUS (Status);
957 Status = AcpiHwDisableAllGpes ();
958 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
960 return_ACPI_STATUS (Status);
963 ACPI_EXPORT_SYMBOL (AcpiDisableAllGpes)
966 /******************************************************************************
968 * FUNCTION: AcpiEnableAllRuntimeGpes
974 * DESCRIPTION: Enable all "runtime" GPEs, in all GPE blocks
976 ******************************************************************************/
979 AcpiEnableAllRuntimeGpes (
985 ACPI_FUNCTION_TRACE (AcpiEnableAllRuntimeGpes);
988 Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
989 if (ACPI_FAILURE (Status))
991 return_ACPI_STATUS (Status);
994 Status = AcpiHwEnableAllRuntimeGpes ();
995 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
997 return_ACPI_STATUS (Status);
1000 ACPI_EXPORT_SYMBOL (AcpiEnableAllRuntimeGpes)
1003 /******************************************************************************
1005 * FUNCTION: AcpiEnableAllWakeupGpes
1011 * DESCRIPTION: Enable all "wakeup" GPEs and disable all of the other GPEs, in
1014 ******************************************************************************/
1017 AcpiEnableAllWakeupGpes (
1023 ACPI_FUNCTION_TRACE (AcpiEnableAllWakeupGpes);
1026 Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
1027 if (ACPI_FAILURE (Status))
1029 return_ACPI_STATUS (Status);
1032 Status = AcpiHwEnableAllWakeupGpes ();
1033 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
1035 return_ACPI_STATUS (Status);
1038 ACPI_EXPORT_SYMBOL (AcpiEnableAllWakeupGpes)
1041 /*******************************************************************************
1043 * FUNCTION: AcpiInstallGpeBlock
1045 * PARAMETERS: GpeDevice - Handle to the parent GPE Block Device
1046 * GpeBlockAddress - Address and SpaceID
1047 * RegisterCount - Number of GPE register pairs in the block
1048 * InterruptNumber - H/W interrupt for the block
1052 * DESCRIPTION: Create and Install a block of GPE registers. The GPEs are not
1055 ******************************************************************************/
1058 AcpiInstallGpeBlock (
1059 ACPI_HANDLE GpeDevice,
1060 ACPI_GENERIC_ADDRESS *GpeBlockAddress,
1061 UINT32 RegisterCount,
1062 UINT32 InterruptNumber)
1065 ACPI_OPERAND_OBJECT *ObjDesc;
1066 ACPI_NAMESPACE_NODE *Node;
1067 ACPI_GPE_BLOCK_INFO *GpeBlock;
1070 ACPI_FUNCTION_TRACE (AcpiInstallGpeBlock);
1074 (!GpeBlockAddress) ||
1077 return_ACPI_STATUS (AE_BAD_PARAMETER);
1080 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
1081 if (ACPI_FAILURE (Status))
1083 return_ACPI_STATUS (Status);
1086 Node = AcpiNsValidateHandle (GpeDevice);
1089 Status = AE_BAD_PARAMETER;
1093 /* Validate the parent device */
1095 if (Node->Type != ACPI_TYPE_DEVICE)
1103 Status = AE_ALREADY_EXISTS;
1108 * For user-installed GPE Block Devices, the GpeBlockBaseNumber
1111 Status = AcpiEvCreateGpeBlock (Node, GpeBlockAddress->Address,
1112 GpeBlockAddress->SpaceId, RegisterCount,
1113 0, InterruptNumber, &GpeBlock);
1114 if (ACPI_FAILURE (Status))
1119 /* Install block in the DeviceObject attached to the node */
1121 ObjDesc = AcpiNsGetAttachedObject (Node);
1125 * No object, create a new one (Device nodes do not always have
1126 * an attached object)
1128 ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_DEVICE);
1131 Status = AE_NO_MEMORY;
1135 Status = AcpiNsAttachObject (Node, ObjDesc, ACPI_TYPE_DEVICE);
1137 /* Remove local reference to the object */
1139 AcpiUtRemoveReference (ObjDesc);
1140 if (ACPI_FAILURE (Status))
1146 /* Now install the GPE block in the DeviceObject */
1148 ObjDesc->Device.GpeBlock = GpeBlock;
1152 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
1153 return_ACPI_STATUS (Status);
1156 ACPI_EXPORT_SYMBOL (AcpiInstallGpeBlock)
1159 /*******************************************************************************
1161 * FUNCTION: AcpiRemoveGpeBlock
1163 * PARAMETERS: GpeDevice - Handle to the parent GPE Block Device
1167 * DESCRIPTION: Remove a previously installed block of GPE registers
1169 ******************************************************************************/
1172 AcpiRemoveGpeBlock (
1173 ACPI_HANDLE GpeDevice)
1175 ACPI_OPERAND_OBJECT *ObjDesc;
1177 ACPI_NAMESPACE_NODE *Node;
1180 ACPI_FUNCTION_TRACE (AcpiRemoveGpeBlock);
1185 return_ACPI_STATUS (AE_BAD_PARAMETER);
1188 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
1189 if (ACPI_FAILURE (Status))
1191 return_ACPI_STATUS (Status);
1194 Node = AcpiNsValidateHandle (GpeDevice);
1197 Status = AE_BAD_PARAMETER;
1201 /* Validate the parent device */
1203 if (Node->Type != ACPI_TYPE_DEVICE)
1209 /* Get the DeviceObject attached to the node */
1211 ObjDesc = AcpiNsGetAttachedObject (Node);
1213 !ObjDesc->Device.GpeBlock)
1215 return_ACPI_STATUS (AE_NULL_OBJECT);
1218 /* Delete the GPE block (but not the DeviceObject) */
1220 Status = AcpiEvDeleteGpeBlock (ObjDesc->Device.GpeBlock);
1221 if (ACPI_SUCCESS (Status))
1223 ObjDesc->Device.GpeBlock = NULL;
1227 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
1228 return_ACPI_STATUS (Status);
1231 ACPI_EXPORT_SYMBOL (AcpiRemoveGpeBlock)
1234 /*******************************************************************************
1236 * FUNCTION: AcpiGetGpeDevice
1238 * PARAMETERS: Index - System GPE index (0-CurrentGpeCount)
1239 * GpeDevice - Where the parent GPE Device is returned
1243 * DESCRIPTION: Obtain the GPE device associated with the input index. A NULL
1244 * gpe device indicates that the gpe number is contained in one of
1245 * the FADT-defined gpe blocks. Otherwise, the GPE block device.
1247 ******************************************************************************/
1252 ACPI_HANDLE *GpeDevice)
1254 ACPI_GPE_DEVICE_INFO Info;
1258 ACPI_FUNCTION_TRACE (AcpiGetGpeDevice);
1263 return_ACPI_STATUS (AE_BAD_PARAMETER);
1266 if (Index >= AcpiCurrentGpeCount)
1268 return_ACPI_STATUS (AE_NOT_EXIST);
1271 /* Setup and walk the GPE list */
1274 Info.Status = AE_NOT_EXIST;
1275 Info.GpeDevice = NULL;
1276 Info.NextBlockBaseIndex = 0;
1278 Status = AcpiEvWalkGpeList (AcpiEvGetGpeDevice, &Info);
1279 if (ACPI_FAILURE (Status))
1281 return_ACPI_STATUS (Status);
1284 *GpeDevice = ACPI_CAST_PTR (ACPI_HANDLE, Info.GpeDevice);
1285 return_ACPI_STATUS (Info.Status);
1288 ACPI_EXPORT_SYMBOL (AcpiGetGpeDevice)
1290 #endif /* !ACPI_REDUCED_HARDWARE */