1 /******************************************************************************
3 * Module Name: hwgpe - Low level GPE enable/disable/clear functions
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2014, 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 /******************************************************************************
64 * FUNCTION: AcpiHwGetGpeRegisterBit
66 * PARAMETERS: GpeEventInfo - Info block for the GPE
68 * RETURN: Register mask with a one in the GPE bit position
70 * DESCRIPTION: Compute the register mask for this GPE. One bit is set in the
71 * correct position for the input GPE.
73 ******************************************************************************/
76 AcpiHwGetGpeRegisterBit (
77 ACPI_GPE_EVENT_INFO *GpeEventInfo)
81 (GpeEventInfo->GpeNumber - GpeEventInfo->RegisterInfo->BaseGpeNumber));
85 /******************************************************************************
87 * FUNCTION: AcpiHwLowSetGpe
89 * PARAMETERS: GpeEventInfo - Info block for the GPE to be disabled
90 * Action - Enable or disable
94 * DESCRIPTION: Enable or disable a single GPE in the parent enable register.
96 ******************************************************************************/
100 ACPI_GPE_EVENT_INFO *GpeEventInfo,
103 ACPI_GPE_REGISTER_INFO *GpeRegisterInfo;
109 ACPI_FUNCTION_ENTRY ();
112 /* Get the info block for the entire GPE register */
114 GpeRegisterInfo = GpeEventInfo->RegisterInfo;
115 if (!GpeRegisterInfo)
117 return (AE_NOT_EXIST);
120 /* Get current value of the enable register that contains this GPE */
122 Status = AcpiHwRead (&EnableMask, &GpeRegisterInfo->EnableAddress);
123 if (ACPI_FAILURE (Status))
128 /* Set or clear just the bit that corresponds to this GPE */
130 RegisterBit = AcpiHwGetGpeRegisterBit (GpeEventInfo);
133 case ACPI_GPE_CONDITIONAL_ENABLE:
135 /* Only enable if the EnableForRun bit is set */
137 if (!(RegisterBit & GpeRegisterInfo->EnableForRun))
139 return (AE_BAD_PARAMETER);
142 /*lint -fallthrough */
144 case ACPI_GPE_ENABLE:
146 ACPI_SET_BIT (EnableMask, RegisterBit);
149 case ACPI_GPE_DISABLE:
151 ACPI_CLEAR_BIT (EnableMask, RegisterBit);
156 ACPI_ERROR ((AE_INFO, "Invalid GPE Action, %u", Action));
157 return (AE_BAD_PARAMETER);
160 /* Write the updated enable mask */
162 Status = AcpiHwWrite (EnableMask, &GpeRegisterInfo->EnableAddress);
167 /******************************************************************************
169 * FUNCTION: AcpiHwClearGpe
171 * PARAMETERS: GpeEventInfo - Info block for the GPE to be cleared
175 * DESCRIPTION: Clear the status bit for a single GPE.
177 ******************************************************************************/
181 ACPI_GPE_EVENT_INFO *GpeEventInfo)
183 ACPI_GPE_REGISTER_INFO *GpeRegisterInfo;
188 ACPI_FUNCTION_ENTRY ();
190 /* Get the info block for the entire GPE register */
192 GpeRegisterInfo = GpeEventInfo->RegisterInfo;
193 if (!GpeRegisterInfo)
195 return (AE_NOT_EXIST);
199 * Write a one to the appropriate bit in the status register to
202 RegisterBit = AcpiHwGetGpeRegisterBit (GpeEventInfo);
204 Status = AcpiHwWrite (RegisterBit,
205 &GpeRegisterInfo->StatusAddress);
211 /******************************************************************************
213 * FUNCTION: AcpiHwGetGpeStatus
215 * PARAMETERS: GpeEventInfo - Info block for the GPE to queried
216 * EventStatus - Where the GPE status is returned
220 * DESCRIPTION: Return the status of a single GPE.
222 ******************************************************************************/
226 ACPI_GPE_EVENT_INFO *GpeEventInfo,
227 ACPI_EVENT_STATUS *EventStatus)
231 ACPI_GPE_REGISTER_INFO *GpeRegisterInfo;
232 ACPI_EVENT_STATUS LocalEventStatus = 0;
236 ACPI_FUNCTION_ENTRY ();
241 return (AE_BAD_PARAMETER);
244 /* GPE currently handled? */
246 if ((GpeEventInfo->Flags & ACPI_GPE_DISPATCH_MASK) !=
247 ACPI_GPE_DISPATCH_NONE)
249 LocalEventStatus |= ACPI_EVENT_FLAG_HAS_HANDLER;
252 /* Get the info block for the entire GPE register */
254 GpeRegisterInfo = GpeEventInfo->RegisterInfo;
256 /* Get the register bitmask for this GPE */
258 RegisterBit = AcpiHwGetGpeRegisterBit (GpeEventInfo);
260 /* GPE currently enabled? (enabled for runtime?) */
262 if (RegisterBit & GpeRegisterInfo->EnableForRun)
264 LocalEventStatus |= ACPI_EVENT_FLAG_ENABLED;
267 /* GPE enabled for wake? */
269 if (RegisterBit & GpeRegisterInfo->EnableForWake)
271 LocalEventStatus |= ACPI_EVENT_FLAG_WAKE_ENABLED;
274 /* GPE currently active (status bit == 1)? */
276 Status = AcpiHwRead (&InByte, &GpeRegisterInfo->StatusAddress);
277 if (ACPI_FAILURE (Status))
282 if (RegisterBit & InByte)
284 LocalEventStatus |= ACPI_EVENT_FLAG_SET;
287 /* Set return value */
289 (*EventStatus) = LocalEventStatus;
294 /******************************************************************************
296 * FUNCTION: AcpiHwDisableGpeBlock
298 * PARAMETERS: GpeXruptInfo - GPE Interrupt info
299 * GpeBlock - Gpe Block info
303 * DESCRIPTION: Disable all GPEs within a single GPE block
305 ******************************************************************************/
308 AcpiHwDisableGpeBlock (
309 ACPI_GPE_XRUPT_INFO *GpeXruptInfo,
310 ACPI_GPE_BLOCK_INFO *GpeBlock,
317 /* Examine each GPE Register within the block */
319 for (i = 0; i < GpeBlock->RegisterCount; i++)
321 /* Disable all GPEs in this register */
323 Status = AcpiHwWrite (0x00, &GpeBlock->RegisterInfo[i].EnableAddress);
324 if (ACPI_FAILURE (Status))
334 /******************************************************************************
336 * FUNCTION: AcpiHwClearGpeBlock
338 * PARAMETERS: GpeXruptInfo - GPE Interrupt info
339 * GpeBlock - Gpe Block info
343 * DESCRIPTION: Clear status bits for all GPEs within a single GPE block
345 ******************************************************************************/
348 AcpiHwClearGpeBlock (
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 /* Clear status on all GPEs in this register */
363 Status = AcpiHwWrite (0xFF, &GpeBlock->RegisterInfo[i].StatusAddress);
364 if (ACPI_FAILURE (Status))
374 /******************************************************************************
376 * FUNCTION: AcpiHwEnableRuntimeGpeBlock
378 * PARAMETERS: GpeXruptInfo - GPE Interrupt info
379 * GpeBlock - Gpe Block info
383 * DESCRIPTION: Enable all "runtime" GPEs within a single GPE block. Includes
384 * combination wake/run GPEs.
386 ******************************************************************************/
389 AcpiHwEnableRuntimeGpeBlock (
390 ACPI_GPE_XRUPT_INFO *GpeXruptInfo,
391 ACPI_GPE_BLOCK_INFO *GpeBlock,
398 /* NOTE: assumes that all GPEs are currently disabled */
400 /* Examine each GPE Register within the block */
402 for (i = 0; i < GpeBlock->RegisterCount; i++)
404 if (!GpeBlock->RegisterInfo[i].EnableForRun)
409 /* Enable all "runtime" GPEs in this register */
411 Status = AcpiHwWrite (GpeBlock->RegisterInfo[i].EnableForRun,
412 &GpeBlock->RegisterInfo[i].EnableAddress);
413 if (ACPI_FAILURE (Status))
423 /******************************************************************************
425 * FUNCTION: AcpiHwEnableWakeupGpeBlock
427 * PARAMETERS: GpeXruptInfo - GPE Interrupt info
428 * GpeBlock - Gpe Block info
432 * DESCRIPTION: Enable all "wake" GPEs within a single GPE block. Includes
433 * combination wake/run GPEs.
435 ******************************************************************************/
438 AcpiHwEnableWakeupGpeBlock (
439 ACPI_GPE_XRUPT_INFO *GpeXruptInfo,
440 ACPI_GPE_BLOCK_INFO *GpeBlock,
447 /* Examine each GPE Register within the block */
449 for (i = 0; i < GpeBlock->RegisterCount; i++)
451 if (!GpeBlock->RegisterInfo[i].EnableForWake)
456 /* Enable all "wake" GPEs in this register */
458 Status = AcpiHwWrite (GpeBlock->RegisterInfo[i].EnableForWake,
459 &GpeBlock->RegisterInfo[i].EnableAddress);
460 if (ACPI_FAILURE (Status))
470 /******************************************************************************
472 * FUNCTION: AcpiHwDisableAllGpes
478 * DESCRIPTION: Disable and clear all GPEs in all GPE blocks
480 ******************************************************************************/
483 AcpiHwDisableAllGpes (
489 ACPI_FUNCTION_TRACE (HwDisableAllGpes);
492 Status = AcpiEvWalkGpeList (AcpiHwDisableGpeBlock, NULL);
493 Status = AcpiEvWalkGpeList (AcpiHwClearGpeBlock, NULL);
494 return_ACPI_STATUS (Status);
498 /******************************************************************************
500 * FUNCTION: AcpiHwEnableAllRuntimeGpes
506 * DESCRIPTION: Enable all "runtime" GPEs, in all GPE blocks
508 ******************************************************************************/
511 AcpiHwEnableAllRuntimeGpes (
517 ACPI_FUNCTION_TRACE (HwEnableAllRuntimeGpes);
520 Status = AcpiEvWalkGpeList (AcpiHwEnableRuntimeGpeBlock, NULL);
521 return_ACPI_STATUS (Status);
525 /******************************************************************************
527 * FUNCTION: AcpiHwEnableAllWakeupGpes
533 * DESCRIPTION: Enable all "wakeup" GPEs, in all GPE blocks
535 ******************************************************************************/
538 AcpiHwEnableAllWakeupGpes (
544 ACPI_FUNCTION_TRACE (HwEnableAllWakeupGpes);
547 Status = AcpiEvWalkGpeList (AcpiHwEnableWakeupGpeBlock, NULL);
548 return_ACPI_STATUS (Status);
551 #endif /* !ACPI_REDUCED_HARDWARE */