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.
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.
100 * The EnableMask field of the involved GPE register must be
101 * updated by the caller if necessary.
103 ******************************************************************************/
107 ACPI_GPE_EVENT_INFO *GpeEventInfo,
110 ACPI_GPE_REGISTER_INFO *GpeRegisterInfo;
116 ACPI_FUNCTION_ENTRY ();
119 /* Get the info block for the entire GPE register */
121 GpeRegisterInfo = GpeEventInfo->RegisterInfo;
122 if (!GpeRegisterInfo)
124 return (AE_NOT_EXIST);
127 /* Get current value of the enable register that contains this GPE */
129 Status = AcpiHwRead (&EnableMask, &GpeRegisterInfo->EnableAddress);
130 if (ACPI_FAILURE (Status))
135 /* Set or clear just the bit that corresponds to this GPE */
137 RegisterBit = AcpiHwGetGpeRegisterBit (GpeEventInfo);
140 case ACPI_GPE_CONDITIONAL_ENABLE:
142 /* Only enable if the corresponding EnableMask bit is set */
144 if (!(RegisterBit & GpeRegisterInfo->EnableMask))
146 return (AE_BAD_PARAMETER);
149 /*lint -fallthrough */
151 case ACPI_GPE_ENABLE:
153 ACPI_SET_BIT (EnableMask, RegisterBit);
156 case ACPI_GPE_DISABLE:
158 ACPI_CLEAR_BIT (EnableMask, RegisterBit);
163 ACPI_ERROR ((AE_INFO, "Invalid GPE Action, %u", Action));
164 return (AE_BAD_PARAMETER);
167 /* Write the updated enable mask */
169 Status = AcpiHwWrite (EnableMask, &GpeRegisterInfo->EnableAddress);
174 /******************************************************************************
176 * FUNCTION: AcpiHwClearGpe
178 * PARAMETERS: GpeEventInfo - Info block for the GPE to be cleared
182 * DESCRIPTION: Clear the status bit for a single GPE.
184 ******************************************************************************/
188 ACPI_GPE_EVENT_INFO *GpeEventInfo)
190 ACPI_GPE_REGISTER_INFO *GpeRegisterInfo;
195 ACPI_FUNCTION_ENTRY ();
197 /* Get the info block for the entire GPE register */
199 GpeRegisterInfo = GpeEventInfo->RegisterInfo;
200 if (!GpeRegisterInfo)
202 return (AE_NOT_EXIST);
206 * Write a one to the appropriate bit in the status register to
209 RegisterBit = AcpiHwGetGpeRegisterBit (GpeEventInfo);
211 Status = AcpiHwWrite (RegisterBit, &GpeRegisterInfo->StatusAddress);
216 /******************************************************************************
218 * FUNCTION: AcpiHwGetGpeStatus
220 * PARAMETERS: GpeEventInfo - Info block for the GPE to queried
221 * EventStatus - Where the GPE status is returned
225 * DESCRIPTION: Return the status of a single GPE.
227 ******************************************************************************/
231 ACPI_GPE_EVENT_INFO *GpeEventInfo,
232 ACPI_EVENT_STATUS *EventStatus)
236 ACPI_GPE_REGISTER_INFO *GpeRegisterInfo;
237 ACPI_EVENT_STATUS LocalEventStatus = 0;
241 ACPI_FUNCTION_ENTRY ();
246 return (AE_BAD_PARAMETER);
249 /* GPE currently handled? */
251 if (ACPI_GPE_DISPATCH_TYPE (GpeEventInfo->Flags) !=
252 ACPI_GPE_DISPATCH_NONE)
254 LocalEventStatus |= ACPI_EVENT_FLAG_HAS_HANDLER;
257 /* Get the info block for the entire GPE register */
259 GpeRegisterInfo = GpeEventInfo->RegisterInfo;
261 /* Get the register bitmask for this GPE */
263 RegisterBit = AcpiHwGetGpeRegisterBit (GpeEventInfo);
265 /* GPE currently enabled? (enabled for runtime?) */
267 if (RegisterBit & GpeRegisterInfo->EnableForRun)
269 LocalEventStatus |= ACPI_EVENT_FLAG_ENABLED;
272 /* GPE enabled for wake? */
274 if (RegisterBit & GpeRegisterInfo->EnableForWake)
276 LocalEventStatus |= ACPI_EVENT_FLAG_WAKE_ENABLED;
279 /* GPE currently enabled (enable bit == 1)? */
281 Status = AcpiHwRead (&InByte, &GpeRegisterInfo->EnableAddress);
282 if (ACPI_FAILURE (Status))
287 if (RegisterBit & InByte)
289 LocalEventStatus |= ACPI_EVENT_FLAG_ENABLE_SET;
292 /* GPE currently active (status bit == 1)? */
294 Status = AcpiHwRead (&InByte, &GpeRegisterInfo->StatusAddress);
295 if (ACPI_FAILURE (Status))
300 if (RegisterBit & InByte)
302 LocalEventStatus |= ACPI_EVENT_FLAG_STATUS_SET;
305 /* Set return value */
307 (*EventStatus) = LocalEventStatus;
312 /******************************************************************************
314 * FUNCTION: AcpiHwGpeEnableWrite
316 * PARAMETERS: EnableMask - Bit mask to write to the GPE register
317 * GpeRegisterInfo - Gpe Register info
321 * DESCRIPTION: Write the enable mask byte to the given GPE register.
323 ******************************************************************************/
326 AcpiHwGpeEnableWrite (
328 ACPI_GPE_REGISTER_INFO *GpeRegisterInfo)
333 GpeRegisterInfo->EnableMask = EnableMask;
335 Status = AcpiHwWrite (EnableMask, &GpeRegisterInfo->EnableAddress);
340 /******************************************************************************
342 * FUNCTION: AcpiHwDisableGpeBlock
344 * PARAMETERS: GpeXruptInfo - GPE Interrupt info
345 * GpeBlock - Gpe Block info
349 * DESCRIPTION: Disable all GPEs within a single GPE block
351 ******************************************************************************/
354 AcpiHwDisableGpeBlock (
355 ACPI_GPE_XRUPT_INFO *GpeXruptInfo,
356 ACPI_GPE_BLOCK_INFO *GpeBlock,
363 /* Examine each GPE Register within the block */
365 for (i = 0; i < GpeBlock->RegisterCount; i++)
367 /* Disable all GPEs in this register */
369 Status = AcpiHwGpeEnableWrite (0x00, &GpeBlock->RegisterInfo[i]);
370 if (ACPI_FAILURE (Status))
380 /******************************************************************************
382 * FUNCTION: AcpiHwClearGpeBlock
384 * PARAMETERS: GpeXruptInfo - GPE Interrupt info
385 * GpeBlock - Gpe Block info
389 * DESCRIPTION: Clear status bits for all GPEs within a single GPE block
391 ******************************************************************************/
394 AcpiHwClearGpeBlock (
395 ACPI_GPE_XRUPT_INFO *GpeXruptInfo,
396 ACPI_GPE_BLOCK_INFO *GpeBlock,
403 /* Examine each GPE Register within the block */
405 for (i = 0; i < GpeBlock->RegisterCount; i++)
407 /* Clear status on all GPEs in this register */
409 Status = AcpiHwWrite (0xFF, &GpeBlock->RegisterInfo[i].StatusAddress);
410 if (ACPI_FAILURE (Status))
420 /******************************************************************************
422 * FUNCTION: AcpiHwEnableRuntimeGpeBlock
424 * PARAMETERS: GpeXruptInfo - GPE Interrupt info
425 * GpeBlock - Gpe Block info
429 * DESCRIPTION: Enable all "runtime" GPEs within a single GPE block. Includes
430 * combination wake/run GPEs.
432 ******************************************************************************/
435 AcpiHwEnableRuntimeGpeBlock (
436 ACPI_GPE_XRUPT_INFO *GpeXruptInfo,
437 ACPI_GPE_BLOCK_INFO *GpeBlock,
442 ACPI_GPE_REGISTER_INFO *GpeRegisterInfo;
445 /* NOTE: assumes that all GPEs are currently disabled */
447 /* Examine each GPE Register within the block */
449 for (i = 0; i < GpeBlock->RegisterCount; i++)
451 GpeRegisterInfo = &GpeBlock->RegisterInfo[i];
452 if (!GpeRegisterInfo->EnableForRun)
457 /* Enable all "runtime" GPEs in this register */
459 Status = AcpiHwGpeEnableWrite (GpeRegisterInfo->EnableForRun,
461 if (ACPI_FAILURE (Status))
471 /******************************************************************************
473 * FUNCTION: AcpiHwEnableWakeupGpeBlock
475 * PARAMETERS: GpeXruptInfo - GPE Interrupt info
476 * GpeBlock - Gpe Block info
480 * DESCRIPTION: Enable all "wake" GPEs within a single GPE block. Includes
481 * combination wake/run GPEs.
483 ******************************************************************************/
486 AcpiHwEnableWakeupGpeBlock (
487 ACPI_GPE_XRUPT_INFO *GpeXruptInfo,
488 ACPI_GPE_BLOCK_INFO *GpeBlock,
493 ACPI_GPE_REGISTER_INFO *GpeRegisterInfo;
496 /* Examine each GPE Register within the block */
498 for (i = 0; i < GpeBlock->RegisterCount; i++)
500 GpeRegisterInfo = &GpeBlock->RegisterInfo[i];
503 * Enable all "wake" GPEs in this register and disable the
506 Status = AcpiHwGpeEnableWrite (GpeRegisterInfo->EnableForWake,
508 if (ACPI_FAILURE (Status))
518 /******************************************************************************
520 * FUNCTION: AcpiHwDisableAllGpes
526 * DESCRIPTION: Disable and clear all GPEs in all GPE blocks
528 ******************************************************************************/
531 AcpiHwDisableAllGpes (
537 ACPI_FUNCTION_TRACE (HwDisableAllGpes);
540 Status = AcpiEvWalkGpeList (AcpiHwDisableGpeBlock, NULL);
541 Status = AcpiEvWalkGpeList (AcpiHwClearGpeBlock, NULL);
542 return_ACPI_STATUS (Status);
546 /******************************************************************************
548 * FUNCTION: AcpiHwEnableAllRuntimeGpes
554 * DESCRIPTION: Enable all "runtime" GPEs, in all GPE blocks
556 ******************************************************************************/
559 AcpiHwEnableAllRuntimeGpes (
565 ACPI_FUNCTION_TRACE (HwEnableAllRuntimeGpes);
568 Status = AcpiEvWalkGpeList (AcpiHwEnableRuntimeGpeBlock, NULL);
569 return_ACPI_STATUS (Status);
573 /******************************************************************************
575 * FUNCTION: AcpiHwEnableAllWakeupGpes
581 * DESCRIPTION: Enable all "wakeup" GPEs, in all GPE blocks
583 ******************************************************************************/
586 AcpiHwEnableAllWakeupGpes (
592 ACPI_FUNCTION_TRACE (HwEnableAllWakeupGpes);
595 Status = AcpiEvWalkGpeList (AcpiHwEnableWakeupGpeBlock, NULL);
596 return_ACPI_STATUS (Status);
599 #endif /* !ACPI_REDUCED_HARDWARE */