1 /******************************************************************************
3 * Module Name: evxfgpe - External Interfaces for General Purpose Events (GPEs)
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2011, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
47 #include <contrib/dev/acpica/include/acpi.h>
48 #include <contrib/dev/acpica/include/accommon.h>
49 #include <contrib/dev/acpica/include/acevents.h>
50 #include <contrib/dev/acpica/include/acnamesp.h>
52 #define _COMPONENT ACPI_EVENTS
53 ACPI_MODULE_NAME ("evxfgpe")
56 /*******************************************************************************
58 * FUNCTION: AcpiUpdateAllGpes
64 * DESCRIPTION: Complete GPE initialization and enable all GPEs that have
65 * associated _Lxx or _Exx methods and are not pointed to by any
66 * device _PRW methods (this indicates that these GPEs are
67 * generally intended for system or device wakeup. Such GPEs
68 * have to be enabled directly when the devices whose _PRW
69 * methods point to them are set up for wakeup signaling.)
71 * NOTE: Should be called after any GPEs are added to the system. Primarily,
72 * after the system _PRW methods have been run, but also after a GPE Block
73 * Device has been added or if any new GPE methods have been added via a
76 ******************************************************************************/
85 ACPI_FUNCTION_TRACE (AcpiUpdateGpes);
88 Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
89 if (ACPI_FAILURE (Status))
91 return_ACPI_STATUS (Status);
94 if (AcpiGbl_AllGpesInitialized)
99 Status = AcpiEvWalkGpeList (AcpiEvInitializeGpeBlock, NULL);
100 if (ACPI_SUCCESS (Status))
102 AcpiGbl_AllGpesInitialized = TRUE;
106 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
107 return_ACPI_STATUS (Status);
110 ACPI_EXPORT_SYMBOL (AcpiUpdateAllGpes)
113 /*******************************************************************************
115 * FUNCTION: AcpiEnableGpe
117 * PARAMETERS: GpeDevice - Parent GPE Device. NULL for GPE0/GPE1
118 * GpeNumber - GPE level within the GPE block
122 * DESCRIPTION: Add a reference to a GPE. On the first reference, the GPE is
125 ******************************************************************************/
129 ACPI_HANDLE GpeDevice,
132 ACPI_STATUS Status = AE_BAD_PARAMETER;
133 ACPI_GPE_EVENT_INFO *GpeEventInfo;
134 ACPI_CPU_FLAGS Flags;
137 ACPI_FUNCTION_TRACE (AcpiEnableGpe);
140 Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
142 /* Ensure that we have a valid GPE number */
144 GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
147 Status = AcpiEvAddGpeReference (GpeEventInfo);
150 AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
151 return_ACPI_STATUS (Status);
154 ACPI_EXPORT_SYMBOL (AcpiEnableGpe)
157 /*******************************************************************************
159 * FUNCTION: AcpiDisableGpe
161 * PARAMETERS: GpeDevice - Parent GPE Device. NULL for GPE0/GPE1
162 * GpeNumber - GPE level within the GPE block
166 * DESCRIPTION: Remove a reference to a GPE. When the last reference is
167 * removed, only then is the GPE disabled (for runtime GPEs), or
168 * the GPE mask bit disabled (for wake GPEs)
170 ******************************************************************************/
174 ACPI_HANDLE GpeDevice,
177 ACPI_STATUS Status = AE_BAD_PARAMETER;
178 ACPI_GPE_EVENT_INFO *GpeEventInfo;
179 ACPI_CPU_FLAGS Flags;
182 ACPI_FUNCTION_TRACE (AcpiDisableGpe);
185 Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
187 /* Ensure that we have a valid GPE number */
189 GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
192 Status = AcpiEvRemoveGpeReference (GpeEventInfo);
195 AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
196 return_ACPI_STATUS (Status);
199 ACPI_EXPORT_SYMBOL (AcpiDisableGpe)
202 /*******************************************************************************
204 * FUNCTION: AcpiSetGpe
206 * PARAMETERS: GpeDevice - Parent GPE Device. NULL for GPE0/GPE1
207 * GpeNumber - GPE level within the GPE block
208 * Action - ACPI_GPE_ENABLE or ACPI_GPE_DISABLE
212 * DESCRIPTION: Enable or disable an individual GPE. This function bypasses
213 * the reference count mechanism used in the AcpiEnableGpe and
214 * AcpiDisableGpe interfaces -- and should be used with care.
216 * Note: Typically used to disable a runtime GPE for short period of time,
217 * then re-enable it, without disturbing the existing reference counts. This
218 * is useful, for example, in the Embedded Controller (EC) driver.
220 ******************************************************************************/
224 ACPI_HANDLE GpeDevice,
228 ACPI_GPE_EVENT_INFO *GpeEventInfo;
230 ACPI_CPU_FLAGS Flags;
233 ACPI_FUNCTION_TRACE (AcpiSetGpe);
236 Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
238 /* Ensure that we have a valid GPE number */
240 GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
243 Status = AE_BAD_PARAMETER;
247 /* Perform the action */
251 case ACPI_GPE_ENABLE:
252 Status = AcpiEvEnableGpe (GpeEventInfo);
255 case ACPI_GPE_DISABLE:
256 Status = AcpiHwLowSetGpe (GpeEventInfo, ACPI_GPE_DISABLE);
260 Status = AE_BAD_PARAMETER;
265 AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
266 return_ACPI_STATUS (Status);
269 ACPI_EXPORT_SYMBOL (AcpiSetGpe)
272 /*******************************************************************************
274 * FUNCTION: AcpiSetupGpeForWake
276 * PARAMETERS: WakeDevice - Device associated with the GPE (via _PRW)
277 * GpeDevice - Parent GPE Device. NULL for GPE0/GPE1
278 * GpeNumber - GPE level within the GPE block
282 * DESCRIPTION: Mark a GPE as having the ability to wake the system. This
283 * interface is intended to be used as the host executes the
284 * _PRW methods (Power Resources for Wake) in the system tables.
285 * Each _PRW appears under a Device Object (The WakeDevice), and
286 * contains the info for the wake GPE associated with the
289 ******************************************************************************/
292 AcpiSetupGpeForWake (
293 ACPI_HANDLE WakeDevice,
294 ACPI_HANDLE GpeDevice,
297 ACPI_STATUS Status = AE_BAD_PARAMETER;
298 ACPI_GPE_EVENT_INFO *GpeEventInfo;
299 ACPI_NAMESPACE_NODE *DeviceNode;
300 ACPI_CPU_FLAGS Flags;
303 ACPI_FUNCTION_TRACE (AcpiSetupGpeForWake);
306 /* Parameter Validation */
311 * By forcing WakeDevice to be valid, we automatically enable the
312 * implicit notify feature on all hosts.
314 return_ACPI_STATUS (AE_BAD_PARAMETER);
317 /* Handle root object case */
319 if (WakeDevice == ACPI_ROOT_OBJECT)
321 DeviceNode = AcpiGbl_RootNode;
325 DeviceNode = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, WakeDevice);
328 /* Validate WakeDevice is of type Device */
330 if (DeviceNode->Type != ACPI_TYPE_DEVICE)
332 return_ACPI_STATUS (AE_BAD_PARAMETER);
335 Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
337 /* Ensure that we have a valid GPE number */
339 GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
343 * If there is no method or handler for this GPE, then the
344 * WakeDevice will be notified whenever this GPE fires (aka
345 * "implicit notify") Note: The GPE is assumed to be
346 * level-triggered (for windows compatibility).
348 if ((GpeEventInfo->Flags & ACPI_GPE_DISPATCH_MASK) ==
349 ACPI_GPE_DISPATCH_NONE)
351 GpeEventInfo->Flags =
352 (ACPI_GPE_DISPATCH_NOTIFY | ACPI_GPE_LEVEL_TRIGGERED);
353 GpeEventInfo->Dispatch.DeviceNode = DeviceNode;
356 GpeEventInfo->Flags |= ACPI_GPE_CAN_WAKE;
360 AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
361 return_ACPI_STATUS (Status);
364 ACPI_EXPORT_SYMBOL (AcpiSetupGpeForWake)
367 /*******************************************************************************
369 * FUNCTION: AcpiSetGpeWakeMask
371 * PARAMETERS: GpeDevice - Parent GPE Device. NULL for GPE0/GPE1
372 * GpeNumber - GPE level within the GPE block
373 * Action - Enable or Disable
377 * DESCRIPTION: Set or clear the GPE's wakeup enable mask bit. The GPE must
378 * already be marked as a WAKE GPE.
380 ******************************************************************************/
384 ACPI_HANDLE GpeDevice,
388 ACPI_STATUS Status = AE_OK;
389 ACPI_GPE_EVENT_INFO *GpeEventInfo;
390 ACPI_GPE_REGISTER_INFO *GpeRegisterInfo;
391 ACPI_CPU_FLAGS Flags;
395 ACPI_FUNCTION_TRACE (AcpiSetGpeWakeMask);
398 Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
401 * Ensure that we have a valid GPE number and that this GPE is in
404 GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
407 Status = AE_BAD_PARAMETER;
411 if (!(GpeEventInfo->Flags & ACPI_GPE_CAN_WAKE))
417 GpeRegisterInfo = GpeEventInfo->RegisterInfo;
418 if (!GpeRegisterInfo)
420 Status = AE_NOT_EXIST;
424 RegisterBit = AcpiHwGetGpeRegisterBit (GpeEventInfo, GpeRegisterInfo);
426 /* Perform the action */
430 case ACPI_GPE_ENABLE:
431 ACPI_SET_BIT (GpeRegisterInfo->EnableForWake, (UINT8) RegisterBit);
434 case ACPI_GPE_DISABLE:
435 ACPI_CLEAR_BIT (GpeRegisterInfo->EnableForWake, (UINT8) RegisterBit);
439 ACPI_ERROR ((AE_INFO, "%u, Invalid action", Action));
440 Status = AE_BAD_PARAMETER;
445 AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
446 return_ACPI_STATUS (Status);
449 ACPI_EXPORT_SYMBOL (AcpiSetGpeWakeMask)
452 /*******************************************************************************
454 * FUNCTION: AcpiClearGpe
456 * PARAMETERS: GpeDevice - Parent GPE Device. NULL for GPE0/GPE1
457 * GpeNumber - GPE level within the GPE block
461 * DESCRIPTION: Clear an ACPI event (general purpose)
463 ******************************************************************************/
467 ACPI_HANDLE GpeDevice,
470 ACPI_STATUS Status = AE_OK;
471 ACPI_GPE_EVENT_INFO *GpeEventInfo;
472 ACPI_CPU_FLAGS Flags;
475 ACPI_FUNCTION_TRACE (AcpiClearGpe);
478 Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
480 /* Ensure that we have a valid GPE number */
482 GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
485 Status = AE_BAD_PARAMETER;
489 Status = AcpiHwClearGpe (GpeEventInfo);
492 AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
493 return_ACPI_STATUS (Status);
496 ACPI_EXPORT_SYMBOL (AcpiClearGpe)
499 /*******************************************************************************
501 * FUNCTION: AcpiGetGpeStatus
503 * PARAMETERS: GpeDevice - Parent GPE Device. NULL for GPE0/GPE1
504 * GpeNumber - GPE level within the GPE block
505 * EventStatus - Where the current status of the event
510 * DESCRIPTION: Get the current status of a GPE (signalled/not_signalled)
512 ******************************************************************************/
516 ACPI_HANDLE GpeDevice,
518 ACPI_EVENT_STATUS *EventStatus)
520 ACPI_STATUS Status = AE_OK;
521 ACPI_GPE_EVENT_INFO *GpeEventInfo;
522 ACPI_CPU_FLAGS Flags;
525 ACPI_FUNCTION_TRACE (AcpiGetGpeStatus);
528 Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
530 /* Ensure that we have a valid GPE number */
532 GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
535 Status = AE_BAD_PARAMETER;
539 /* Obtain status on the requested GPE number */
541 Status = AcpiHwGetGpeStatus (GpeEventInfo, EventStatus);
544 AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
545 return_ACPI_STATUS (Status);
548 ACPI_EXPORT_SYMBOL (AcpiGetGpeStatus)
551 /*******************************************************************************
553 * FUNCTION: AcpiFinishGpe
555 * PARAMETERS: GpeDevice - Namespace node for the GPE Block
556 * (NULL for FADT defined GPEs)
557 * GpeNumber - GPE level within the GPE block
561 * DESCRIPTION: Clear and conditionally reenable a GPE. This completes the GPE
562 * processing. Intended for use by asynchronous host-installed
563 * GPE handlers. The GPE is only reenabled if the EnableForRun bit
564 * is set in the GPE info.
566 ******************************************************************************/
570 ACPI_HANDLE GpeDevice,
573 ACPI_GPE_EVENT_INFO *GpeEventInfo;
575 ACPI_CPU_FLAGS Flags;
578 ACPI_FUNCTION_TRACE (AcpiFinishGpe);
581 Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
583 /* Ensure that we have a valid GPE number */
585 GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
588 Status = AE_BAD_PARAMETER;
592 Status = AcpiEvFinishGpe (GpeEventInfo);
595 AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
596 return_ACPI_STATUS (Status);
599 ACPI_EXPORT_SYMBOL (AcpiFinishGpe)
602 /******************************************************************************
604 * FUNCTION: AcpiDisableAllGpes
610 * DESCRIPTION: Disable and clear all GPEs in all GPE blocks
612 ******************************************************************************/
621 ACPI_FUNCTION_TRACE (AcpiDisableAllGpes);
624 Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
625 if (ACPI_FAILURE (Status))
627 return_ACPI_STATUS (Status);
630 Status = AcpiHwDisableAllGpes ();
631 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
633 return_ACPI_STATUS (Status);
636 ACPI_EXPORT_SYMBOL (AcpiDisableAllGpes)
639 /******************************************************************************
641 * FUNCTION: AcpiEnableAllRuntimeGpes
647 * DESCRIPTION: Enable all "runtime" GPEs, in all GPE blocks
649 ******************************************************************************/
652 AcpiEnableAllRuntimeGpes (
658 ACPI_FUNCTION_TRACE (AcpiEnableAllRuntimeGpes);
661 Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
662 if (ACPI_FAILURE (Status))
664 return_ACPI_STATUS (Status);
667 Status = AcpiHwEnableAllRuntimeGpes ();
668 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
670 return_ACPI_STATUS (Status);
673 ACPI_EXPORT_SYMBOL (AcpiEnableAllRuntimeGpes)
676 /*******************************************************************************
678 * FUNCTION: AcpiInstallGpeBlock
680 * PARAMETERS: GpeDevice - Handle to the parent GPE Block Device
681 * GpeBlockAddress - Address and SpaceID
682 * RegisterCount - Number of GPE register pairs in the block
683 * InterruptNumber - H/W interrupt for the block
687 * DESCRIPTION: Create and Install a block of GPE registers. The GPEs are not
690 ******************************************************************************/
693 AcpiInstallGpeBlock (
694 ACPI_HANDLE GpeDevice,
695 ACPI_GENERIC_ADDRESS *GpeBlockAddress,
696 UINT32 RegisterCount,
697 UINT32 InterruptNumber)
700 ACPI_OPERAND_OBJECT *ObjDesc;
701 ACPI_NAMESPACE_NODE *Node;
702 ACPI_GPE_BLOCK_INFO *GpeBlock;
705 ACPI_FUNCTION_TRACE (AcpiInstallGpeBlock);
709 (!GpeBlockAddress) ||
712 return_ACPI_STATUS (AE_BAD_PARAMETER);
715 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
716 if (ACPI_FAILURE (Status))
721 Node = AcpiNsValidateHandle (GpeDevice);
724 Status = AE_BAD_PARAMETER;
729 * For user-installed GPE Block Devices, the GpeBlockBaseNumber
732 Status = AcpiEvCreateGpeBlock (Node, GpeBlockAddress, RegisterCount,
733 0, InterruptNumber, &GpeBlock);
734 if (ACPI_FAILURE (Status))
739 /* Install block in the DeviceObject attached to the node */
741 ObjDesc = AcpiNsGetAttachedObject (Node);
745 * No object, create a new one (Device nodes do not always have
746 * an attached object)
748 ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_DEVICE);
751 Status = AE_NO_MEMORY;
755 Status = AcpiNsAttachObject (Node, ObjDesc, ACPI_TYPE_DEVICE);
757 /* Remove local reference to the object */
759 AcpiUtRemoveReference (ObjDesc);
760 if (ACPI_FAILURE (Status))
766 /* Now install the GPE block in the DeviceObject */
768 ObjDesc->Device.GpeBlock = GpeBlock;
772 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
773 return_ACPI_STATUS (Status);
776 ACPI_EXPORT_SYMBOL (AcpiInstallGpeBlock)
779 /*******************************************************************************
781 * FUNCTION: AcpiRemoveGpeBlock
783 * PARAMETERS: GpeDevice - Handle to the parent GPE Block Device
787 * DESCRIPTION: Remove a previously installed block of GPE registers
789 ******************************************************************************/
793 ACPI_HANDLE GpeDevice)
795 ACPI_OPERAND_OBJECT *ObjDesc;
797 ACPI_NAMESPACE_NODE *Node;
800 ACPI_FUNCTION_TRACE (AcpiRemoveGpeBlock);
805 return_ACPI_STATUS (AE_BAD_PARAMETER);
808 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
809 if (ACPI_FAILURE (Status))
814 Node = AcpiNsValidateHandle (GpeDevice);
817 Status = AE_BAD_PARAMETER;
821 /* Get the DeviceObject attached to the node */
823 ObjDesc = AcpiNsGetAttachedObject (Node);
825 !ObjDesc->Device.GpeBlock)
827 return_ACPI_STATUS (AE_NULL_OBJECT);
830 /* Delete the GPE block (but not the DeviceObject) */
832 Status = AcpiEvDeleteGpeBlock (ObjDesc->Device.GpeBlock);
833 if (ACPI_SUCCESS (Status))
835 ObjDesc->Device.GpeBlock = NULL;
839 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
840 return_ACPI_STATUS (Status);
843 ACPI_EXPORT_SYMBOL (AcpiRemoveGpeBlock)
846 /*******************************************************************************
848 * FUNCTION: AcpiGetGpeDevice
850 * PARAMETERS: Index - System GPE index (0-CurrentGpeCount)
851 * GpeDevice - Where the parent GPE Device is returned
855 * DESCRIPTION: Obtain the GPE device associated with the input index. A NULL
856 * gpe device indicates that the gpe number is contained in one of
857 * the FADT-defined gpe blocks. Otherwise, the GPE block device.
859 ******************************************************************************/
864 ACPI_HANDLE *GpeDevice)
866 ACPI_GPE_DEVICE_INFO Info;
870 ACPI_FUNCTION_TRACE (AcpiGetGpeDevice);
875 return_ACPI_STATUS (AE_BAD_PARAMETER);
878 if (Index >= AcpiCurrentGpeCount)
880 return_ACPI_STATUS (AE_NOT_EXIST);
883 /* Setup and walk the GPE list */
886 Info.Status = AE_NOT_EXIST;
887 Info.GpeDevice = NULL;
888 Info.NextBlockBaseIndex = 0;
890 Status = AcpiEvWalkGpeList (AcpiEvGetGpeDevice, &Info);
891 if (ACPI_FAILURE (Status))
893 return_ACPI_STATUS (Status);
896 *GpeDevice = ACPI_CAST_PTR (ACPI_HANDLE, Info.GpeDevice);
897 return_ACPI_STATUS (Info.Status);
900 ACPI_EXPORT_SYMBOL (AcpiGetGpeDevice)