1 /******************************************************************************
3 * Module Name: hwgpe - Low level GPE enable/disable/clear functions
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2015, 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.
44 #include <contrib/dev/acpica/include/acpi.h>
45 #include <contrib/dev/acpica/include/accommon.h>
46 #include <contrib/dev/acpica/include/acevents.h>
48 #define _COMPONENT ACPI_HARDWARE
49 ACPI_MODULE_NAME ("hwgpe")
51 #if (!ACPI_REDUCED_HARDWARE) /* Entire module */
53 /* Local prototypes */
56 AcpiHwEnableWakeupGpeBlock (
57 ACPI_GPE_XRUPT_INFO *GpeXruptInfo,
58 ACPI_GPE_BLOCK_INFO *GpeBlock,
62 AcpiHwGpeEnableWrite (
64 ACPI_GPE_REGISTER_INFO *GpeRegisterInfo);
67 /******************************************************************************
69 * FUNCTION: AcpiHwGetGpeRegisterBit
71 * PARAMETERS: GpeEventInfo - Info block for the GPE
73 * RETURN: Register mask with a one in the GPE bit position
75 * DESCRIPTION: Compute the register mask for this GPE. One bit is set in the
76 * correct position for the input GPE.
78 ******************************************************************************/
81 AcpiHwGetGpeRegisterBit (
82 ACPI_GPE_EVENT_INFO *GpeEventInfo)
86 (GpeEventInfo->GpeNumber - GpeEventInfo->RegisterInfo->BaseGpeNumber));
90 /******************************************************************************
92 * FUNCTION: AcpiHwLowSetGpe
94 * PARAMETERS: GpeEventInfo - Info block for the GPE to be disabled
95 * Action - Enable or disable
99 * DESCRIPTION: Enable or disable a single GPE in the parent enable register.
101 ******************************************************************************/
105 ACPI_GPE_EVENT_INFO *GpeEventInfo,
108 ACPI_GPE_REGISTER_INFO *GpeRegisterInfo;
114 ACPI_FUNCTION_ENTRY ();
117 /* Get the info block for the entire GPE register */
119 GpeRegisterInfo = GpeEventInfo->RegisterInfo;
120 if (!GpeRegisterInfo)
122 return (AE_NOT_EXIST);
125 /* Get current value of the enable register that contains this GPE */
127 Status = AcpiHwRead (&EnableMask, &GpeRegisterInfo->EnableAddress);
128 if (ACPI_FAILURE (Status))
133 /* Set or clear just the bit that corresponds to this GPE */
135 RegisterBit = AcpiHwGetGpeRegisterBit (GpeEventInfo);
136 switch (Action & ~ACPI_GPE_SAVE_MASK)
138 case ACPI_GPE_CONDITIONAL_ENABLE:
140 /* Only enable if the corresponding EnableMask bit is set */
142 if (!(RegisterBit & GpeRegisterInfo->EnableMask))
144 return (AE_BAD_PARAMETER);
147 /*lint -fallthrough */
149 case ACPI_GPE_ENABLE:
151 ACPI_SET_BIT (EnableMask, RegisterBit);
154 case ACPI_GPE_DISABLE:
156 ACPI_CLEAR_BIT (EnableMask, RegisterBit);
161 ACPI_ERROR ((AE_INFO, "Invalid GPE Action, %u", Action));
162 return (AE_BAD_PARAMETER);
165 /* Write the updated enable mask */
167 Status = AcpiHwWrite (EnableMask, &GpeRegisterInfo->EnableAddress);
168 if (ACPI_SUCCESS (Status) && (Action & ACPI_GPE_SAVE_MASK))
170 GpeRegisterInfo->EnableMask = (UINT8) EnableMask;
176 /******************************************************************************
178 * FUNCTION: AcpiHwClearGpe
180 * PARAMETERS: GpeEventInfo - Info block for the GPE to be cleared
184 * DESCRIPTION: Clear the status bit for a single GPE.
186 ******************************************************************************/
190 ACPI_GPE_EVENT_INFO *GpeEventInfo)
192 ACPI_GPE_REGISTER_INFO *GpeRegisterInfo;
197 ACPI_FUNCTION_ENTRY ();
199 /* Get the info block for the entire GPE register */
201 GpeRegisterInfo = GpeEventInfo->RegisterInfo;
202 if (!GpeRegisterInfo)
204 return (AE_NOT_EXIST);
208 * Write a one to the appropriate bit in the status register to
211 RegisterBit = AcpiHwGetGpeRegisterBit (GpeEventInfo);
213 Status = AcpiHwWrite (RegisterBit,
214 &GpeRegisterInfo->StatusAddress);
220 /******************************************************************************
222 * FUNCTION: AcpiHwGetGpeStatus
224 * PARAMETERS: GpeEventInfo - Info block for the GPE to queried
225 * EventStatus - Where the GPE status is returned
229 * DESCRIPTION: Return the status of a single GPE.
231 ******************************************************************************/
235 ACPI_GPE_EVENT_INFO *GpeEventInfo,
236 ACPI_EVENT_STATUS *EventStatus)
240 ACPI_GPE_REGISTER_INFO *GpeRegisterInfo;
241 ACPI_EVENT_STATUS LocalEventStatus = 0;
245 ACPI_FUNCTION_ENTRY ();
250 return (AE_BAD_PARAMETER);
253 /* GPE currently handled? */
255 if (ACPI_GPE_DISPATCH_TYPE (GpeEventInfo->Flags) !=
256 ACPI_GPE_DISPATCH_NONE)
258 LocalEventStatus |= ACPI_EVENT_FLAG_HAS_HANDLER;
261 /* Get the info block for the entire GPE register */
263 GpeRegisterInfo = GpeEventInfo->RegisterInfo;
265 /* Get the register bitmask for this GPE */
267 RegisterBit = AcpiHwGetGpeRegisterBit (GpeEventInfo);
269 /* GPE currently enabled? (enabled for runtime?) */
271 if (RegisterBit & GpeRegisterInfo->EnableForRun)
273 LocalEventStatus |= ACPI_EVENT_FLAG_ENABLED;
276 /* GPE enabled for wake? */
278 if (RegisterBit & GpeRegisterInfo->EnableForWake)
280 LocalEventStatus |= ACPI_EVENT_FLAG_WAKE_ENABLED;
283 /* GPE currently enabled (enable bit == 1)? */
285 Status = AcpiHwRead (&InByte, &GpeRegisterInfo->EnableAddress);
286 if (ACPI_FAILURE (Status))
291 if (RegisterBit & InByte)
293 LocalEventStatus |= ACPI_EVENT_FLAG_ENABLE_SET;
296 /* GPE currently active (status bit == 1)? */
298 Status = AcpiHwRead (&InByte, &GpeRegisterInfo->StatusAddress);
299 if (ACPI_FAILURE (Status))
304 if (RegisterBit & InByte)
306 LocalEventStatus |= ACPI_EVENT_FLAG_STATUS_SET;
309 /* Set return value */
311 (*EventStatus) = LocalEventStatus;
316 /******************************************************************************
318 * FUNCTION: AcpiHwGpeEnableWrite
320 * PARAMETERS: EnableMask - Bit mask to write to the GPE register
321 * GpeRegisterInfo - Gpe Register info
325 * DESCRIPTION: Write the enable mask byte to the given GPE register.
327 ******************************************************************************/
330 AcpiHwGpeEnableWrite (
332 ACPI_GPE_REGISTER_INFO *GpeRegisterInfo)
337 Status = AcpiHwWrite (EnableMask, &GpeRegisterInfo->EnableAddress);
338 if (ACPI_SUCCESS (Status))
340 GpeRegisterInfo->EnableMask = EnableMask;
347 /******************************************************************************
349 * FUNCTION: AcpiHwDisableGpeBlock
351 * PARAMETERS: GpeXruptInfo - GPE Interrupt info
352 * GpeBlock - Gpe Block info
356 * DESCRIPTION: Disable all GPEs within a single GPE block
358 ******************************************************************************/
361 AcpiHwDisableGpeBlock (
362 ACPI_GPE_XRUPT_INFO *GpeXruptInfo,
363 ACPI_GPE_BLOCK_INFO *GpeBlock,
370 /* Examine each GPE Register within the block */
372 for (i = 0; i < GpeBlock->RegisterCount; i++)
374 /* Disable all GPEs in this register */
376 Status = AcpiHwGpeEnableWrite (0x00, &GpeBlock->RegisterInfo[i]);
377 if (ACPI_FAILURE (Status))
387 /******************************************************************************
389 * FUNCTION: AcpiHwClearGpeBlock
391 * PARAMETERS: GpeXruptInfo - GPE Interrupt info
392 * GpeBlock - Gpe Block info
396 * DESCRIPTION: Clear status bits for all GPEs within a single GPE block
398 ******************************************************************************/
401 AcpiHwClearGpeBlock (
402 ACPI_GPE_XRUPT_INFO *GpeXruptInfo,
403 ACPI_GPE_BLOCK_INFO *GpeBlock,
410 /* Examine each GPE Register within the block */
412 for (i = 0; i < GpeBlock->RegisterCount; i++)
414 /* Clear status on all GPEs in this register */
416 Status = AcpiHwWrite (0xFF, &GpeBlock->RegisterInfo[i].StatusAddress);
417 if (ACPI_FAILURE (Status))
427 /******************************************************************************
429 * FUNCTION: AcpiHwEnableRuntimeGpeBlock
431 * PARAMETERS: GpeXruptInfo - GPE Interrupt info
432 * GpeBlock - Gpe Block info
436 * DESCRIPTION: Enable all "runtime" GPEs within a single GPE block. Includes
437 * combination wake/run GPEs.
439 ******************************************************************************/
442 AcpiHwEnableRuntimeGpeBlock (
443 ACPI_GPE_XRUPT_INFO *GpeXruptInfo,
444 ACPI_GPE_BLOCK_INFO *GpeBlock,
449 ACPI_GPE_REGISTER_INFO *GpeRegisterInfo;
452 /* NOTE: assumes that all GPEs are currently disabled */
454 /* Examine each GPE Register within the block */
456 for (i = 0; i < GpeBlock->RegisterCount; i++)
458 GpeRegisterInfo = &GpeBlock->RegisterInfo[i];
459 if (!GpeRegisterInfo->EnableForRun)
464 /* Enable all "runtime" GPEs in this register */
466 Status = AcpiHwGpeEnableWrite (GpeRegisterInfo->EnableForRun,
468 if (ACPI_FAILURE (Status))
478 /******************************************************************************
480 * FUNCTION: AcpiHwEnableWakeupGpeBlock
482 * PARAMETERS: GpeXruptInfo - GPE Interrupt info
483 * GpeBlock - Gpe Block info
487 * DESCRIPTION: Enable all "wake" GPEs within a single GPE block. Includes
488 * combination wake/run GPEs.
490 ******************************************************************************/
493 AcpiHwEnableWakeupGpeBlock (
494 ACPI_GPE_XRUPT_INFO *GpeXruptInfo,
495 ACPI_GPE_BLOCK_INFO *GpeBlock,
500 ACPI_GPE_REGISTER_INFO *GpeRegisterInfo;
503 /* Examine each GPE Register within the block */
505 for (i = 0; i < GpeBlock->RegisterCount; i++)
507 GpeRegisterInfo = &GpeBlock->RegisterInfo[i];
510 * Enable all "wake" GPEs in this register and disable the
513 Status = AcpiHwGpeEnableWrite (GpeRegisterInfo->EnableForWake,
515 if (ACPI_FAILURE (Status))
525 /******************************************************************************
527 * FUNCTION: AcpiHwDisableAllGpes
533 * DESCRIPTION: Disable and clear all GPEs in all GPE blocks
535 ******************************************************************************/
538 AcpiHwDisableAllGpes (
544 ACPI_FUNCTION_TRACE (HwDisableAllGpes);
547 Status = AcpiEvWalkGpeList (AcpiHwDisableGpeBlock, NULL);
548 Status = AcpiEvWalkGpeList (AcpiHwClearGpeBlock, NULL);
549 return_ACPI_STATUS (Status);
553 /******************************************************************************
555 * FUNCTION: AcpiHwEnableAllRuntimeGpes
561 * DESCRIPTION: Enable all "runtime" GPEs, in all GPE blocks
563 ******************************************************************************/
566 AcpiHwEnableAllRuntimeGpes (
572 ACPI_FUNCTION_TRACE (HwEnableAllRuntimeGpes);
575 Status = AcpiEvWalkGpeList (AcpiHwEnableRuntimeGpeBlock, NULL);
576 return_ACPI_STATUS (Status);
580 /******************************************************************************
582 * FUNCTION: AcpiHwEnableAllWakeupGpes
588 * DESCRIPTION: Enable all "wakeup" GPEs, in all GPE blocks
590 ******************************************************************************/
593 AcpiHwEnableAllWakeupGpes (
599 ACPI_FUNCTION_TRACE (HwEnableAllWakeupGpes);
602 Status = AcpiEvWalkGpeList (AcpiHwEnableWakeupGpeBlock, NULL);
603 return_ACPI_STATUS (Status);
606 #endif /* !ACPI_REDUCED_HARDWARE */