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 ******************************************************************************/
193 ACPI_FUNCTION_TRACE (AcpiUpdateAllGpes);
196 Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
197 if (ACPI_FAILURE (Status))
199 return_ACPI_STATUS (Status);
202 if (AcpiGbl_AllGpesInitialized)
207 Status = AcpiEvWalkGpeList (AcpiEvInitializeGpeBlock, NULL);
208 if (ACPI_SUCCESS (Status))
210 AcpiGbl_AllGpesInitialized = TRUE;
214 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
215 return_ACPI_STATUS (Status);
218 ACPI_EXPORT_SYMBOL (AcpiUpdateAllGpes)
221 /*******************************************************************************
223 * FUNCTION: AcpiEnableGpe
225 * PARAMETERS: GpeDevice - Parent GPE Device. NULL for GPE0/GPE1
226 * GpeNumber - GPE level within the GPE block
230 * DESCRIPTION: Add a reference to a GPE. On the first reference, the GPE is
233 ******************************************************************************/
237 ACPI_HANDLE GpeDevice,
240 ACPI_STATUS Status = AE_BAD_PARAMETER;
241 ACPI_GPE_EVENT_INFO *GpeEventInfo;
242 ACPI_CPU_FLAGS Flags;
245 ACPI_FUNCTION_TRACE (AcpiEnableGpe);
248 Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
251 * Ensure that we have a valid GPE number and that there is some way
252 * of handling the GPE (handler or a GPE method). In other words, we
253 * won't allow a valid GPE to be enabled if there is no way to handle it.
255 GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
258 if (ACPI_GPE_DISPATCH_TYPE (GpeEventInfo->Flags) !=
259 ACPI_GPE_DISPATCH_NONE)
261 Status = AcpiEvAddGpeReference (GpeEventInfo);
265 Status = AE_NO_HANDLER;
269 AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
270 return_ACPI_STATUS (Status);
273 ACPI_EXPORT_SYMBOL (AcpiEnableGpe)
276 /*******************************************************************************
278 * FUNCTION: AcpiDisableGpe
280 * PARAMETERS: GpeDevice - Parent GPE Device. NULL for GPE0/GPE1
281 * GpeNumber - GPE level within the GPE block
285 * DESCRIPTION: Remove a reference to a GPE. When the last reference is
286 * removed, only then is the GPE disabled (for runtime GPEs), or
287 * the GPE mask bit disabled (for wake GPEs)
289 ******************************************************************************/
293 ACPI_HANDLE GpeDevice,
296 ACPI_STATUS Status = AE_BAD_PARAMETER;
297 ACPI_GPE_EVENT_INFO *GpeEventInfo;
298 ACPI_CPU_FLAGS Flags;
301 ACPI_FUNCTION_TRACE (AcpiDisableGpe);
304 Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
306 /* Ensure that we have a valid GPE number */
308 GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
311 Status = AcpiEvRemoveGpeReference (GpeEventInfo);
314 AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
315 return_ACPI_STATUS (Status);
318 ACPI_EXPORT_SYMBOL (AcpiDisableGpe)
321 /*******************************************************************************
323 * FUNCTION: AcpiSetGpe
325 * PARAMETERS: GpeDevice - Parent GPE Device. NULL for GPE0/GPE1
326 * GpeNumber - GPE level within the GPE block
327 * Action - ACPI_GPE_ENABLE or ACPI_GPE_DISABLE
331 * DESCRIPTION: Enable or disable an individual GPE. This function bypasses
332 * the reference count mechanism used in the AcpiEnableGpe(),
333 * AcpiDisableGpe() interfaces.
334 * This API is typically used by the GPE raw handler mode driver
335 * to switch between the polling mode and the interrupt mode after
336 * the driver has enabled the GPE.
337 * The APIs should be invoked in this order:
338 * AcpiEnableGpe() <- Ensure the reference count > 0
339 * AcpiSetGpe(ACPI_GPE_DISABLE) <- Enter polling mode
340 * AcpiSetGpe(ACPI_GPE_ENABLE) <- Leave polling mode
341 * AcpiDisableGpe() <- Decrease the reference count
343 * Note: If a GPE is shared by 2 silicon components, then both the drivers
344 * should support GPE polling mode or disabling the GPE for long period
345 * for one driver may break the other. So use it with care since all
346 * firmware _Lxx/_Exx handlers currently rely on the GPE interrupt mode.
348 ******************************************************************************/
352 ACPI_HANDLE GpeDevice,
356 ACPI_GPE_EVENT_INFO *GpeEventInfo;
358 ACPI_CPU_FLAGS Flags;
361 ACPI_FUNCTION_TRACE (AcpiSetGpe);
364 Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
366 /* Ensure that we have a valid GPE number */
368 GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
371 Status = AE_BAD_PARAMETER;
375 /* Perform the action */
379 case ACPI_GPE_ENABLE:
381 Status = AcpiHwLowSetGpe (GpeEventInfo, ACPI_GPE_ENABLE);
382 GpeEventInfo->DisableForDispatch = FALSE;
385 case ACPI_GPE_DISABLE:
387 Status = AcpiHwLowSetGpe (GpeEventInfo, ACPI_GPE_DISABLE);
388 GpeEventInfo->DisableForDispatch = TRUE;
393 Status = AE_BAD_PARAMETER;
398 AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
399 return_ACPI_STATUS (Status);
402 ACPI_EXPORT_SYMBOL (AcpiSetGpe)
405 /*******************************************************************************
407 * FUNCTION: AcpiMaskGpe
409 * PARAMETERS: GpeDevice - Parent GPE Device. NULL for GPE0/GPE1
410 * GpeNumber - GPE level within the GPE block
411 * IsMasked - Whether the GPE is masked or not
415 * DESCRIPTION: Unconditionally mask/unmask the an individual GPE, ex., to
416 * prevent a GPE flooding.
418 ******************************************************************************/
422 ACPI_HANDLE GpeDevice,
426 ACPI_GPE_EVENT_INFO *GpeEventInfo;
428 ACPI_CPU_FLAGS Flags;
431 ACPI_FUNCTION_TRACE (AcpiMaskGpe);
434 Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
436 /* Ensure that we have a valid GPE number */
438 GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
441 Status = AE_BAD_PARAMETER;
445 Status = AcpiEvMaskGpe (GpeEventInfo, IsMasked);
448 AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
449 return_ACPI_STATUS (Status);
452 ACPI_EXPORT_SYMBOL (AcpiMaskGpe)
455 /*******************************************************************************
457 * FUNCTION: AcpiMarkGpeForWake
459 * PARAMETERS: GpeDevice - Parent GPE Device. NULL for GPE0/GPE1
460 * GpeNumber - GPE level within the GPE block
464 * DESCRIPTION: Mark a GPE as having the ability to wake the system. Simply
465 * sets the ACPI_GPE_CAN_WAKE flag.
467 * Some potential callers of AcpiSetupGpeForWake may know in advance that
468 * there won't be any notify handlers installed for device wake notifications
469 * from the given GPE (one example is a button GPE in Linux). For these cases,
470 * AcpiMarkGpeForWake should be used instead of AcpiSetupGpeForWake.
471 * This will set the ACPI_GPE_CAN_WAKE flag for the GPE without trying to
472 * setup implicit wake notification for it (since there's no handler method).
474 ******************************************************************************/
478 ACPI_HANDLE GpeDevice,
481 ACPI_GPE_EVENT_INFO *GpeEventInfo;
482 ACPI_STATUS Status = AE_BAD_PARAMETER;
483 ACPI_CPU_FLAGS Flags;
486 ACPI_FUNCTION_TRACE (AcpiMarkGpeForWake);
489 Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
491 /* Ensure that we have a valid GPE number */
493 GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
496 /* Mark the GPE as a possible wake event */
498 GpeEventInfo->Flags |= ACPI_GPE_CAN_WAKE;
502 AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
503 return_ACPI_STATUS (Status);
506 ACPI_EXPORT_SYMBOL (AcpiMarkGpeForWake)
509 /*******************************************************************************
511 * FUNCTION: AcpiSetupGpeForWake
513 * PARAMETERS: WakeDevice - Device associated with the GPE (via _PRW)
514 * GpeDevice - Parent GPE Device. NULL for GPE0/GPE1
515 * GpeNumber - GPE level within the GPE block
519 * DESCRIPTION: Mark a GPE as having the ability to wake the system. This
520 * interface is intended to be used as the host executes the
521 * _PRW methods (Power Resources for Wake) in the system tables.
522 * Each _PRW appears under a Device Object (The WakeDevice), and
523 * contains the info for the wake GPE associated with the
526 ******************************************************************************/
529 AcpiSetupGpeForWake (
530 ACPI_HANDLE WakeDevice,
531 ACPI_HANDLE GpeDevice,
535 ACPI_GPE_EVENT_INFO *GpeEventInfo;
536 ACPI_NAMESPACE_NODE *DeviceNode;
537 ACPI_GPE_NOTIFY_INFO *Notify;
538 ACPI_GPE_NOTIFY_INFO *NewNotify;
539 ACPI_CPU_FLAGS Flags;
542 ACPI_FUNCTION_TRACE (AcpiSetupGpeForWake);
545 /* Parameter Validation */
550 * By forcing WakeDevice to be valid, we automatically enable the
551 * implicit notify feature on all hosts.
553 return_ACPI_STATUS (AE_BAD_PARAMETER);
556 /* Handle root object case */
558 if (WakeDevice == ACPI_ROOT_OBJECT)
560 DeviceNode = AcpiGbl_RootNode;
564 DeviceNode = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, WakeDevice);
567 /* Validate WakeDevice is of type Device */
569 if (DeviceNode->Type != ACPI_TYPE_DEVICE)
571 return_ACPI_STATUS (AE_BAD_PARAMETER);
575 * Allocate a new notify object up front, in case it is needed.
576 * Memory allocation while holding a spinlock is a big no-no
579 NewNotify = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_GPE_NOTIFY_INFO));
582 return_ACPI_STATUS (AE_NO_MEMORY);
585 Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
587 /* Ensure that we have a valid GPE number */
589 GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
592 Status = AE_BAD_PARAMETER;
597 * If there is no method or handler for this GPE, then the
598 * WakeDevice will be notified whenever this GPE fires. This is
599 * known as an "implicit notify". Note: The GPE is assumed to be
600 * level-triggered (for windows compatibility).
602 if (ACPI_GPE_DISPATCH_TYPE (GpeEventInfo->Flags) ==
603 ACPI_GPE_DISPATCH_NONE)
606 * This is the first device for implicit notify on this GPE.
607 * Just set the flags here, and enter the NOTIFY block below.
609 GpeEventInfo->Flags =
610 (ACPI_GPE_DISPATCH_NOTIFY | ACPI_GPE_LEVEL_TRIGGERED);
614 * If we already have an implicit notify on this GPE, add
615 * this device to the notify list.
617 if (ACPI_GPE_DISPATCH_TYPE (GpeEventInfo->Flags) ==
618 ACPI_GPE_DISPATCH_NOTIFY)
620 /* Ensure that the device is not already in the list */
622 Notify = GpeEventInfo->Dispatch.NotifyList;
625 if (Notify->DeviceNode == DeviceNode)
627 Status = AE_ALREADY_EXISTS;
630 Notify = Notify->Next;
633 /* Add this device to the notify list for this GPE */
635 NewNotify->DeviceNode = DeviceNode;
636 NewNotify->Next = GpeEventInfo->Dispatch.NotifyList;
637 GpeEventInfo->Dispatch.NotifyList = NewNotify;
641 /* Mark the GPE as a possible wake event */
643 GpeEventInfo->Flags |= ACPI_GPE_CAN_WAKE;
648 AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
650 /* Delete the notify object if it was not used above */
654 ACPI_FREE (NewNotify);
656 return_ACPI_STATUS (Status);
659 ACPI_EXPORT_SYMBOL (AcpiSetupGpeForWake)
662 /*******************************************************************************
664 * FUNCTION: AcpiSetGpeWakeMask
666 * PARAMETERS: GpeDevice - Parent GPE Device. NULL for GPE0/GPE1
667 * GpeNumber - GPE level within the GPE block
668 * Action - Enable or Disable
672 * DESCRIPTION: Set or clear the GPE's wakeup enable mask bit. The GPE must
673 * already be marked as a WAKE GPE.
675 ******************************************************************************/
679 ACPI_HANDLE GpeDevice,
683 ACPI_STATUS Status = AE_OK;
684 ACPI_GPE_EVENT_INFO *GpeEventInfo;
685 ACPI_GPE_REGISTER_INFO *GpeRegisterInfo;
686 ACPI_CPU_FLAGS Flags;
690 ACPI_FUNCTION_TRACE (AcpiSetGpeWakeMask);
693 Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
696 * Ensure that we have a valid GPE number and that this GPE is in
699 GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
702 Status = AE_BAD_PARAMETER;
706 if (!(GpeEventInfo->Flags & ACPI_GPE_CAN_WAKE))
712 GpeRegisterInfo = GpeEventInfo->RegisterInfo;
713 if (!GpeRegisterInfo)
715 Status = AE_NOT_EXIST;
719 RegisterBit = AcpiHwGetGpeRegisterBit (GpeEventInfo);
721 /* Perform the action */
725 case ACPI_GPE_ENABLE:
727 ACPI_SET_BIT (GpeRegisterInfo->EnableForWake, (UINT8) RegisterBit);
730 case ACPI_GPE_DISABLE:
732 ACPI_CLEAR_BIT (GpeRegisterInfo->EnableForWake, (UINT8) RegisterBit);
737 ACPI_ERROR ((AE_INFO, "%u, Invalid action", Action));
738 Status = AE_BAD_PARAMETER;
743 AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
744 return_ACPI_STATUS (Status);
747 ACPI_EXPORT_SYMBOL (AcpiSetGpeWakeMask)
750 /*******************************************************************************
752 * FUNCTION: AcpiClearGpe
754 * PARAMETERS: GpeDevice - Parent GPE Device. NULL for GPE0/GPE1
755 * GpeNumber - GPE level within the GPE block
759 * DESCRIPTION: Clear an ACPI event (general purpose)
761 ******************************************************************************/
765 ACPI_HANDLE GpeDevice,
768 ACPI_STATUS Status = AE_OK;
769 ACPI_GPE_EVENT_INFO *GpeEventInfo;
770 ACPI_CPU_FLAGS Flags;
773 ACPI_FUNCTION_TRACE (AcpiClearGpe);
776 Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
778 /* Ensure that we have a valid GPE number */
780 GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
783 Status = AE_BAD_PARAMETER;
787 Status = AcpiHwClearGpe (GpeEventInfo);
790 AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
791 return_ACPI_STATUS (Status);
794 ACPI_EXPORT_SYMBOL (AcpiClearGpe)
797 /*******************************************************************************
799 * FUNCTION: AcpiGetGpeStatus
801 * PARAMETERS: GpeDevice - Parent GPE Device. NULL for GPE0/GPE1
802 * GpeNumber - GPE level within the GPE block
803 * EventStatus - Where the current status of the event
808 * DESCRIPTION: Get the current status of a GPE (signalled/not_signalled)
810 ******************************************************************************/
814 ACPI_HANDLE GpeDevice,
816 ACPI_EVENT_STATUS *EventStatus)
818 ACPI_STATUS Status = AE_OK;
819 ACPI_GPE_EVENT_INFO *GpeEventInfo;
820 ACPI_CPU_FLAGS Flags;
823 ACPI_FUNCTION_TRACE (AcpiGetGpeStatus);
826 Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
828 /* Ensure that we have a valid GPE number */
830 GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
833 Status = AE_BAD_PARAMETER;
837 /* Obtain status on the requested GPE number */
839 Status = AcpiHwGetGpeStatus (GpeEventInfo, EventStatus);
842 AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
843 return_ACPI_STATUS (Status);
846 ACPI_EXPORT_SYMBOL (AcpiGetGpeStatus)
849 /*******************************************************************************
851 * FUNCTION: AcpiFinishGpe
853 * PARAMETERS: GpeDevice - Namespace node for the GPE Block
854 * (NULL for FADT defined GPEs)
855 * GpeNumber - GPE level within the GPE block
859 * DESCRIPTION: Clear and conditionally reenable a GPE. This completes the GPE
860 * processing. Intended for use by asynchronous host-installed
861 * GPE handlers. The GPE is only reenabled if the EnableForRun bit
862 * is set in the GPE info.
864 ******************************************************************************/
868 ACPI_HANDLE GpeDevice,
871 ACPI_GPE_EVENT_INFO *GpeEventInfo;
873 ACPI_CPU_FLAGS Flags;
876 ACPI_FUNCTION_TRACE (AcpiFinishGpe);
879 Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
881 /* Ensure that we have a valid GPE number */
883 GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
886 Status = AE_BAD_PARAMETER;
890 Status = AcpiEvFinishGpe (GpeEventInfo);
893 AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
894 return_ACPI_STATUS (Status);
897 ACPI_EXPORT_SYMBOL (AcpiFinishGpe)
900 /******************************************************************************
902 * FUNCTION: AcpiDisableAllGpes
908 * DESCRIPTION: Disable and clear all GPEs in all GPE blocks
910 ******************************************************************************/
919 ACPI_FUNCTION_TRACE (AcpiDisableAllGpes);
922 Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
923 if (ACPI_FAILURE (Status))
925 return_ACPI_STATUS (Status);
928 Status = AcpiHwDisableAllGpes ();
929 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
931 return_ACPI_STATUS (Status);
934 ACPI_EXPORT_SYMBOL (AcpiDisableAllGpes)
937 /******************************************************************************
939 * FUNCTION: AcpiEnableAllRuntimeGpes
945 * DESCRIPTION: Enable all "runtime" GPEs, in all GPE blocks
947 ******************************************************************************/
950 AcpiEnableAllRuntimeGpes (
956 ACPI_FUNCTION_TRACE (AcpiEnableAllRuntimeGpes);
959 Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
960 if (ACPI_FAILURE (Status))
962 return_ACPI_STATUS (Status);
965 Status = AcpiHwEnableAllRuntimeGpes ();
966 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
968 return_ACPI_STATUS (Status);
971 ACPI_EXPORT_SYMBOL (AcpiEnableAllRuntimeGpes)
974 /******************************************************************************
976 * FUNCTION: AcpiEnableAllWakeupGpes
982 * DESCRIPTION: Enable all "wakeup" GPEs and disable all of the other GPEs, in
985 ******************************************************************************/
988 AcpiEnableAllWakeupGpes (
994 ACPI_FUNCTION_TRACE (AcpiEnableAllWakeupGpes);
997 Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
998 if (ACPI_FAILURE (Status))
1000 return_ACPI_STATUS (Status);
1003 Status = AcpiHwEnableAllWakeupGpes ();
1004 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
1006 return_ACPI_STATUS (Status);
1009 ACPI_EXPORT_SYMBOL (AcpiEnableAllWakeupGpes)
1012 /*******************************************************************************
1014 * FUNCTION: AcpiInstallGpeBlock
1016 * PARAMETERS: GpeDevice - Handle to the parent GPE Block Device
1017 * GpeBlockAddress - Address and SpaceID
1018 * RegisterCount - Number of GPE register pairs in the block
1019 * InterruptNumber - H/W interrupt for the block
1023 * DESCRIPTION: Create and Install a block of GPE registers. The GPEs are not
1026 ******************************************************************************/
1029 AcpiInstallGpeBlock (
1030 ACPI_HANDLE GpeDevice,
1031 ACPI_GENERIC_ADDRESS *GpeBlockAddress,
1032 UINT32 RegisterCount,
1033 UINT32 InterruptNumber)
1036 ACPI_OPERAND_OBJECT *ObjDesc;
1037 ACPI_NAMESPACE_NODE *Node;
1038 ACPI_GPE_BLOCK_INFO *GpeBlock;
1041 ACPI_FUNCTION_TRACE (AcpiInstallGpeBlock);
1045 (!GpeBlockAddress) ||
1048 return_ACPI_STATUS (AE_BAD_PARAMETER);
1051 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
1052 if (ACPI_FAILURE (Status))
1054 return_ACPI_STATUS (Status);
1057 Node = AcpiNsValidateHandle (GpeDevice);
1060 Status = AE_BAD_PARAMETER;
1064 /* Validate the parent device */
1066 if (Node->Type != ACPI_TYPE_DEVICE)
1074 Status = AE_ALREADY_EXISTS;
1079 * For user-installed GPE Block Devices, the GpeBlockBaseNumber
1082 Status = AcpiEvCreateGpeBlock (Node, GpeBlockAddress->Address,
1083 GpeBlockAddress->SpaceId, RegisterCount,
1084 0, InterruptNumber, &GpeBlock);
1085 if (ACPI_FAILURE (Status))
1090 /* Install block in the DeviceObject attached to the node */
1092 ObjDesc = AcpiNsGetAttachedObject (Node);
1096 * No object, create a new one (Device nodes do not always have
1097 * an attached object)
1099 ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_DEVICE);
1102 Status = AE_NO_MEMORY;
1106 Status = AcpiNsAttachObject (Node, ObjDesc, ACPI_TYPE_DEVICE);
1108 /* Remove local reference to the object */
1110 AcpiUtRemoveReference (ObjDesc);
1111 if (ACPI_FAILURE (Status))
1117 /* Now install the GPE block in the DeviceObject */
1119 ObjDesc->Device.GpeBlock = GpeBlock;
1123 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
1124 return_ACPI_STATUS (Status);
1127 ACPI_EXPORT_SYMBOL (AcpiInstallGpeBlock)
1130 /*******************************************************************************
1132 * FUNCTION: AcpiRemoveGpeBlock
1134 * PARAMETERS: GpeDevice - Handle to the parent GPE Block Device
1138 * DESCRIPTION: Remove a previously installed block of GPE registers
1140 ******************************************************************************/
1143 AcpiRemoveGpeBlock (
1144 ACPI_HANDLE GpeDevice)
1146 ACPI_OPERAND_OBJECT *ObjDesc;
1148 ACPI_NAMESPACE_NODE *Node;
1151 ACPI_FUNCTION_TRACE (AcpiRemoveGpeBlock);
1156 return_ACPI_STATUS (AE_BAD_PARAMETER);
1159 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
1160 if (ACPI_FAILURE (Status))
1162 return_ACPI_STATUS (Status);
1165 Node = AcpiNsValidateHandle (GpeDevice);
1168 Status = AE_BAD_PARAMETER;
1172 /* Validate the parent device */
1174 if (Node->Type != ACPI_TYPE_DEVICE)
1180 /* Get the DeviceObject attached to the node */
1182 ObjDesc = AcpiNsGetAttachedObject (Node);
1184 !ObjDesc->Device.GpeBlock)
1186 return_ACPI_STATUS (AE_NULL_OBJECT);
1189 /* Delete the GPE block (but not the DeviceObject) */
1191 Status = AcpiEvDeleteGpeBlock (ObjDesc->Device.GpeBlock);
1192 if (ACPI_SUCCESS (Status))
1194 ObjDesc->Device.GpeBlock = NULL;
1198 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
1199 return_ACPI_STATUS (Status);
1202 ACPI_EXPORT_SYMBOL (AcpiRemoveGpeBlock)
1205 /*******************************************************************************
1207 * FUNCTION: AcpiGetGpeDevice
1209 * PARAMETERS: Index - System GPE index (0-CurrentGpeCount)
1210 * GpeDevice - Where the parent GPE Device is returned
1214 * DESCRIPTION: Obtain the GPE device associated with the input index. A NULL
1215 * gpe device indicates that the gpe number is contained in one of
1216 * the FADT-defined gpe blocks. Otherwise, the GPE block device.
1218 ******************************************************************************/
1223 ACPI_HANDLE *GpeDevice)
1225 ACPI_GPE_DEVICE_INFO Info;
1229 ACPI_FUNCTION_TRACE (AcpiGetGpeDevice);
1234 return_ACPI_STATUS (AE_BAD_PARAMETER);
1237 if (Index >= AcpiCurrentGpeCount)
1239 return_ACPI_STATUS (AE_NOT_EXIST);
1242 /* Setup and walk the GPE list */
1245 Info.Status = AE_NOT_EXIST;
1246 Info.GpeDevice = NULL;
1247 Info.NextBlockBaseIndex = 0;
1249 Status = AcpiEvWalkGpeList (AcpiEvGetGpeDevice, &Info);
1250 if (ACPI_FAILURE (Status))
1252 return_ACPI_STATUS (Status);
1255 *GpeDevice = ACPI_CAST_PTR (ACPI_HANDLE, Info.GpeDevice);
1256 return_ACPI_STATUS (Info.Status);
1259 ACPI_EXPORT_SYMBOL (AcpiGetGpeDevice)
1261 #endif /* !ACPI_REDUCED_HARDWARE */