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.
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 active (status bit == 1)? */
285 Status = AcpiHwRead (&InByte, &GpeRegisterInfo->StatusAddress);
286 if (ACPI_FAILURE (Status))
291 if (RegisterBit & InByte)
293 LocalEventStatus |= ACPI_EVENT_FLAG_SET;
296 /* Set return value */
298 (*EventStatus) = LocalEventStatus;
303 /******************************************************************************
305 * FUNCTION: AcpiHwGpeEnableWrite
307 * PARAMETERS: EnableMask - Bit mask to write to the GPE register
308 * GpeRegisterInfo - Gpe Register info
312 * DESCRIPTION: Write the enable mask byte to the given GPE register.
314 ******************************************************************************/
317 AcpiHwGpeEnableWrite (
319 ACPI_GPE_REGISTER_INFO *GpeRegisterInfo)
324 Status = AcpiHwWrite (EnableMask, &GpeRegisterInfo->EnableAddress);
325 if (ACPI_SUCCESS (Status))
327 GpeRegisterInfo->EnableMask = EnableMask;
334 /******************************************************************************
336 * FUNCTION: AcpiHwDisableGpeBlock
338 * PARAMETERS: GpeXruptInfo - GPE Interrupt info
339 * GpeBlock - Gpe Block info
343 * DESCRIPTION: Disable all GPEs within a single GPE block
345 ******************************************************************************/
348 AcpiHwDisableGpeBlock (
349 ACPI_GPE_XRUPT_INFO *GpeXruptInfo,
350 ACPI_GPE_BLOCK_INFO *GpeBlock,
357 /* Examine each GPE Register within the block */
359 for (i = 0; i < GpeBlock->RegisterCount; i++)
361 /* Disable all GPEs in this register */
363 Status = AcpiHwGpeEnableWrite (0x00, &GpeBlock->RegisterInfo[i]);
364 if (ACPI_FAILURE (Status))
374 /******************************************************************************
376 * FUNCTION: AcpiHwClearGpeBlock
378 * PARAMETERS: GpeXruptInfo - GPE Interrupt info
379 * GpeBlock - Gpe Block info
383 * DESCRIPTION: Clear status bits for all GPEs within a single GPE block
385 ******************************************************************************/
388 AcpiHwClearGpeBlock (
389 ACPI_GPE_XRUPT_INFO *GpeXruptInfo,
390 ACPI_GPE_BLOCK_INFO *GpeBlock,
397 /* Examine each GPE Register within the block */
399 for (i = 0; i < GpeBlock->RegisterCount; i++)
401 /* Clear status on all GPEs in this register */
403 Status = AcpiHwWrite (0xFF, &GpeBlock->RegisterInfo[i].StatusAddress);
404 if (ACPI_FAILURE (Status))
414 /******************************************************************************
416 * FUNCTION: AcpiHwEnableRuntimeGpeBlock
418 * PARAMETERS: GpeXruptInfo - GPE Interrupt info
419 * GpeBlock - Gpe Block info
423 * DESCRIPTION: Enable all "runtime" GPEs within a single GPE block. Includes
424 * combination wake/run GPEs.
426 ******************************************************************************/
429 AcpiHwEnableRuntimeGpeBlock (
430 ACPI_GPE_XRUPT_INFO *GpeXruptInfo,
431 ACPI_GPE_BLOCK_INFO *GpeBlock,
436 ACPI_GPE_REGISTER_INFO *GpeRegisterInfo;
439 /* NOTE: assumes that all GPEs are currently disabled */
441 /* Examine each GPE Register within the block */
443 for (i = 0; i < GpeBlock->RegisterCount; i++)
445 GpeRegisterInfo = &GpeBlock->RegisterInfo[i];
446 if (!GpeRegisterInfo->EnableForRun)
451 /* Enable all "runtime" GPEs in this register */
453 Status = AcpiHwGpeEnableWrite (GpeRegisterInfo->EnableForRun,
455 if (ACPI_FAILURE (Status))
465 /******************************************************************************
467 * FUNCTION: AcpiHwEnableWakeupGpeBlock
469 * PARAMETERS: GpeXruptInfo - GPE Interrupt info
470 * GpeBlock - Gpe Block info
474 * DESCRIPTION: Enable all "wake" GPEs within a single GPE block. Includes
475 * combination wake/run GPEs.
477 ******************************************************************************/
480 AcpiHwEnableWakeupGpeBlock (
481 ACPI_GPE_XRUPT_INFO *GpeXruptInfo,
482 ACPI_GPE_BLOCK_INFO *GpeBlock,
487 ACPI_GPE_REGISTER_INFO *GpeRegisterInfo;
490 /* Examine each GPE Register within the block */
492 for (i = 0; i < GpeBlock->RegisterCount; i++)
494 GpeRegisterInfo = &GpeBlock->RegisterInfo[i];
497 * Enable all "wake" GPEs in this register and disable the
500 Status = AcpiHwGpeEnableWrite (GpeRegisterInfo->EnableForWake,
502 if (ACPI_FAILURE (Status))
512 /******************************************************************************
514 * FUNCTION: AcpiHwDisableAllGpes
520 * DESCRIPTION: Disable and clear all GPEs in all GPE blocks
522 ******************************************************************************/
525 AcpiHwDisableAllGpes (
531 ACPI_FUNCTION_TRACE (HwDisableAllGpes);
534 Status = AcpiEvWalkGpeList (AcpiHwDisableGpeBlock, NULL);
535 Status = AcpiEvWalkGpeList (AcpiHwClearGpeBlock, NULL);
536 return_ACPI_STATUS (Status);
540 /******************************************************************************
542 * FUNCTION: AcpiHwEnableAllRuntimeGpes
548 * DESCRIPTION: Enable all "runtime" GPEs, in all GPE blocks
550 ******************************************************************************/
553 AcpiHwEnableAllRuntimeGpes (
559 ACPI_FUNCTION_TRACE (HwEnableAllRuntimeGpes);
562 Status = AcpiEvWalkGpeList (AcpiHwEnableRuntimeGpeBlock, NULL);
563 return_ACPI_STATUS (Status);
567 /******************************************************************************
569 * FUNCTION: AcpiHwEnableAllWakeupGpes
575 * DESCRIPTION: Enable all "wakeup" GPEs, in all GPE blocks
577 ******************************************************************************/
580 AcpiHwEnableAllWakeupGpes (
586 ACPI_FUNCTION_TRACE (HwEnableAllWakeupGpes);
589 Status = AcpiEvWalkGpeList (AcpiHwEnableWakeupGpeBlock, NULL);
590 return_ACPI_STATUS (Status);
593 #endif /* !ACPI_REDUCED_HARDWARE */