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 /* Validate WakeDevice is of type Device */
319 DeviceNode = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, WakeDevice);
320 if (DeviceNode->Type != ACPI_TYPE_DEVICE)
322 return_ACPI_STATUS (AE_BAD_PARAMETER);
325 Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
327 /* Ensure that we have a valid GPE number */
329 GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
333 * If there is no method or handler for this GPE, then the
334 * WakeDevice will be notified whenever this GPE fires (aka
335 * "implicit notify") Note: The GPE is assumed to be
336 * level-triggered (for windows compatibility).
338 if ((GpeEventInfo->Flags & ACPI_GPE_DISPATCH_MASK) ==
339 ACPI_GPE_DISPATCH_NONE)
341 GpeEventInfo->Flags =
342 (ACPI_GPE_DISPATCH_NOTIFY | ACPI_GPE_LEVEL_TRIGGERED);
343 GpeEventInfo->Dispatch.DeviceNode = DeviceNode;
346 GpeEventInfo->Flags |= ACPI_GPE_CAN_WAKE;
350 AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
351 return_ACPI_STATUS (Status);
354 ACPI_EXPORT_SYMBOL (AcpiSetupGpeForWake)
357 /*******************************************************************************
359 * FUNCTION: AcpiSetGpeWakeMask
361 * PARAMETERS: GpeDevice - Parent GPE Device. NULL for GPE0/GPE1
362 * GpeNumber - GPE level within the GPE block
363 * Action - Enable or Disable
367 * DESCRIPTION: Set or clear the GPE's wakeup enable mask bit. The GPE must
368 * already be marked as a WAKE GPE.
370 ******************************************************************************/
374 ACPI_HANDLE GpeDevice,
378 ACPI_STATUS Status = AE_OK;
379 ACPI_GPE_EVENT_INFO *GpeEventInfo;
380 ACPI_GPE_REGISTER_INFO *GpeRegisterInfo;
381 ACPI_CPU_FLAGS Flags;
385 ACPI_FUNCTION_TRACE (AcpiSetGpeWakeMask);
388 Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
391 * Ensure that we have a valid GPE number and that this GPE is in
394 GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
397 Status = AE_BAD_PARAMETER;
401 if (!(GpeEventInfo->Flags & ACPI_GPE_CAN_WAKE))
407 GpeRegisterInfo = GpeEventInfo->RegisterInfo;
408 if (!GpeRegisterInfo)
410 Status = AE_NOT_EXIST;
414 RegisterBit = AcpiHwGetGpeRegisterBit (GpeEventInfo, GpeRegisterInfo);
416 /* Perform the action */
420 case ACPI_GPE_ENABLE:
421 ACPI_SET_BIT (GpeRegisterInfo->EnableForWake, (UINT8) RegisterBit);
424 case ACPI_GPE_DISABLE:
425 ACPI_CLEAR_BIT (GpeRegisterInfo->EnableForWake, (UINT8) RegisterBit);
429 ACPI_ERROR ((AE_INFO, "%u, Invalid action", Action));
430 Status = AE_BAD_PARAMETER;
435 AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
436 return_ACPI_STATUS (Status);
439 ACPI_EXPORT_SYMBOL (AcpiSetGpeWakeMask)
442 /*******************************************************************************
444 * FUNCTION: AcpiClearGpe
446 * PARAMETERS: GpeDevice - Parent GPE Device. NULL for GPE0/GPE1
447 * GpeNumber - GPE level within the GPE block
451 * DESCRIPTION: Clear an ACPI event (general purpose)
453 ******************************************************************************/
457 ACPI_HANDLE GpeDevice,
460 ACPI_STATUS Status = AE_OK;
461 ACPI_GPE_EVENT_INFO *GpeEventInfo;
462 ACPI_CPU_FLAGS Flags;
465 ACPI_FUNCTION_TRACE (AcpiClearGpe);
468 Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
470 /* Ensure that we have a valid GPE number */
472 GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
475 Status = AE_BAD_PARAMETER;
479 Status = AcpiHwClearGpe (GpeEventInfo);
482 AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
483 return_ACPI_STATUS (Status);
486 ACPI_EXPORT_SYMBOL (AcpiClearGpe)
489 /*******************************************************************************
491 * FUNCTION: AcpiGetGpeStatus
493 * PARAMETERS: GpeDevice - Parent GPE Device. NULL for GPE0/GPE1
494 * GpeNumber - GPE level within the GPE block
495 * EventStatus - Where the current status of the event
500 * DESCRIPTION: Get the current status of a GPE (signalled/not_signalled)
502 ******************************************************************************/
506 ACPI_HANDLE GpeDevice,
508 ACPI_EVENT_STATUS *EventStatus)
510 ACPI_STATUS Status = AE_OK;
511 ACPI_GPE_EVENT_INFO *GpeEventInfo;
512 ACPI_CPU_FLAGS Flags;
515 ACPI_FUNCTION_TRACE (AcpiGetGpeStatus);
518 Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
520 /* Ensure that we have a valid GPE number */
522 GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
525 Status = AE_BAD_PARAMETER;
529 /* Obtain status on the requested GPE number */
531 Status = AcpiHwGetGpeStatus (GpeEventInfo, EventStatus);
534 AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
535 return_ACPI_STATUS (Status);
538 ACPI_EXPORT_SYMBOL (AcpiGetGpeStatus)
541 /*******************************************************************************
543 * FUNCTION: AcpiFinishGpe
545 * PARAMETERS: GpeDevice - Namespace node for the GPE Block
546 * (NULL for FADT defined GPEs)
547 * GpeNumber - GPE level within the GPE block
551 * DESCRIPTION: Clear and conditionally reenable a GPE. This completes the GPE
552 * processing. Intended for use by asynchronous host-installed
553 * GPE handlers. The GPE is only reenabled if the EnableForRun bit
554 * is set in the GPE info.
556 ******************************************************************************/
560 ACPI_HANDLE GpeDevice,
563 ACPI_GPE_EVENT_INFO *GpeEventInfo;
565 ACPI_CPU_FLAGS Flags;
568 ACPI_FUNCTION_TRACE (AcpiFinishGpe);
571 Flags = AcpiOsAcquireLock (AcpiGbl_GpeLock);
573 /* Ensure that we have a valid GPE number */
575 GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
578 Status = AE_BAD_PARAMETER;
582 Status = AcpiEvFinishGpe (GpeEventInfo);
585 AcpiOsReleaseLock (AcpiGbl_GpeLock, Flags);
586 return_ACPI_STATUS (Status);
589 ACPI_EXPORT_SYMBOL (AcpiFinishGpe)
592 /******************************************************************************
594 * FUNCTION: AcpiDisableAllGpes
600 * DESCRIPTION: Disable and clear all GPEs in all GPE blocks
602 ******************************************************************************/
611 ACPI_FUNCTION_TRACE (AcpiDisableAllGpes);
614 Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
615 if (ACPI_FAILURE (Status))
617 return_ACPI_STATUS (Status);
620 Status = AcpiHwDisableAllGpes ();
621 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
623 return_ACPI_STATUS (Status);
626 ACPI_EXPORT_SYMBOL (AcpiDisableAllGpes)
629 /******************************************************************************
631 * FUNCTION: AcpiEnableAllRuntimeGpes
637 * DESCRIPTION: Enable all "runtime" GPEs, in all GPE blocks
639 ******************************************************************************/
642 AcpiEnableAllRuntimeGpes (
648 ACPI_FUNCTION_TRACE (AcpiEnableAllRuntimeGpes);
651 Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
652 if (ACPI_FAILURE (Status))
654 return_ACPI_STATUS (Status);
657 Status = AcpiHwEnableAllRuntimeGpes ();
658 (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
660 return_ACPI_STATUS (Status);
663 ACPI_EXPORT_SYMBOL (AcpiEnableAllRuntimeGpes)
666 /*******************************************************************************
668 * FUNCTION: AcpiInstallGpeBlock
670 * PARAMETERS: GpeDevice - Handle to the parent GPE Block Device
671 * GpeBlockAddress - Address and SpaceID
672 * RegisterCount - Number of GPE register pairs in the block
673 * InterruptNumber - H/W interrupt for the block
677 * DESCRIPTION: Create and Install a block of GPE registers. The GPEs are not
680 ******************************************************************************/
683 AcpiInstallGpeBlock (
684 ACPI_HANDLE GpeDevice,
685 ACPI_GENERIC_ADDRESS *GpeBlockAddress,
686 UINT32 RegisterCount,
687 UINT32 InterruptNumber)
690 ACPI_OPERAND_OBJECT *ObjDesc;
691 ACPI_NAMESPACE_NODE *Node;
692 ACPI_GPE_BLOCK_INFO *GpeBlock;
695 ACPI_FUNCTION_TRACE (AcpiInstallGpeBlock);
699 (!GpeBlockAddress) ||
702 return_ACPI_STATUS (AE_BAD_PARAMETER);
705 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
706 if (ACPI_FAILURE (Status))
711 Node = AcpiNsValidateHandle (GpeDevice);
714 Status = AE_BAD_PARAMETER;
719 * For user-installed GPE Block Devices, the GpeBlockBaseNumber
722 Status = AcpiEvCreateGpeBlock (Node, GpeBlockAddress, RegisterCount,
723 0, InterruptNumber, &GpeBlock);
724 if (ACPI_FAILURE (Status))
729 /* Install block in the DeviceObject attached to the node */
731 ObjDesc = AcpiNsGetAttachedObject (Node);
735 * No object, create a new one (Device nodes do not always have
736 * an attached object)
738 ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_DEVICE);
741 Status = AE_NO_MEMORY;
745 Status = AcpiNsAttachObject (Node, ObjDesc, ACPI_TYPE_DEVICE);
747 /* Remove local reference to the object */
749 AcpiUtRemoveReference (ObjDesc);
750 if (ACPI_FAILURE (Status))
756 /* Now install the GPE block in the DeviceObject */
758 ObjDesc->Device.GpeBlock = GpeBlock;
762 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
763 return_ACPI_STATUS (Status);
766 ACPI_EXPORT_SYMBOL (AcpiInstallGpeBlock)
769 /*******************************************************************************
771 * FUNCTION: AcpiRemoveGpeBlock
773 * PARAMETERS: GpeDevice - Handle to the parent GPE Block Device
777 * DESCRIPTION: Remove a previously installed block of GPE registers
779 ******************************************************************************/
783 ACPI_HANDLE GpeDevice)
785 ACPI_OPERAND_OBJECT *ObjDesc;
787 ACPI_NAMESPACE_NODE *Node;
790 ACPI_FUNCTION_TRACE (AcpiRemoveGpeBlock);
795 return_ACPI_STATUS (AE_BAD_PARAMETER);
798 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
799 if (ACPI_FAILURE (Status))
804 Node = AcpiNsValidateHandle (GpeDevice);
807 Status = AE_BAD_PARAMETER;
811 /* Get the DeviceObject attached to the node */
813 ObjDesc = AcpiNsGetAttachedObject (Node);
815 !ObjDesc->Device.GpeBlock)
817 return_ACPI_STATUS (AE_NULL_OBJECT);
820 /* Delete the GPE block (but not the DeviceObject) */
822 Status = AcpiEvDeleteGpeBlock (ObjDesc->Device.GpeBlock);
823 if (ACPI_SUCCESS (Status))
825 ObjDesc->Device.GpeBlock = NULL;
829 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
830 return_ACPI_STATUS (Status);
833 ACPI_EXPORT_SYMBOL (AcpiRemoveGpeBlock)
836 /*******************************************************************************
838 * FUNCTION: AcpiGetGpeDevice
840 * PARAMETERS: Index - System GPE index (0-CurrentGpeCount)
841 * GpeDevice - Where the parent GPE Device is returned
845 * DESCRIPTION: Obtain the GPE device associated with the input index. A NULL
846 * gpe device indicates that the gpe number is contained in one of
847 * the FADT-defined gpe blocks. Otherwise, the GPE block device.
849 ******************************************************************************/
854 ACPI_HANDLE *GpeDevice)
856 ACPI_GPE_DEVICE_INFO Info;
860 ACPI_FUNCTION_TRACE (AcpiGetGpeDevice);
865 return_ACPI_STATUS (AE_BAD_PARAMETER);
868 if (Index >= AcpiCurrentGpeCount)
870 return_ACPI_STATUS (AE_NOT_EXIST);
873 /* Setup and walk the GPE list */
876 Info.Status = AE_NOT_EXIST;
877 Info.GpeDevice = NULL;
878 Info.NextBlockBaseIndex = 0;
880 Status = AcpiEvWalkGpeList (AcpiEvGetGpeDevice, &Info);
881 if (ACPI_FAILURE (Status))
883 return_ACPI_STATUS (Status);
886 *GpeDevice = ACPI_CAST_PTR (ACPI_HANDLE, Info.GpeDevice);
887 return_ACPI_STATUS (Info.Status);
890 ACPI_EXPORT_SYMBOL (AcpiGetGpeDevice)