2 /******************************************************************************
4 * Module Name: hwgpe - Low level GPE enable/disable/clear functions
6 *****************************************************************************/
9 * Copyright (C) 2000 - 2011, Intel Corp.
10 * All rights reserved.
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions, and the following disclaimer,
17 * without modification.
18 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
19 * substantially similar to the "NO WARRANTY" disclaimer below
20 * ("Disclaimer") and any redistribution must be conditioned upon
21 * including a substantially similar Disclaimer requirement for further
22 * binary redistribution.
23 * 3. Neither the names of the above-listed copyright holders nor the names
24 * of any contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
27 * Alternatively, this software may be distributed under the terms of the
28 * GNU General Public License ("GPL") version 2 as published by the Free
29 * Software Foundation.
32 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
35 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
36 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
40 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
41 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42 * POSSIBILITY OF SUCH DAMAGES.
45 #include <contrib/dev/acpica/include/acpi.h>
46 #include <contrib/dev/acpica/include/accommon.h>
47 #include <contrib/dev/acpica/include/acevents.h>
49 #define _COMPONENT ACPI_HARDWARE
50 ACPI_MODULE_NAME ("hwgpe")
52 /* Local prototypes */
55 AcpiHwEnableWakeupGpeBlock (
56 ACPI_GPE_XRUPT_INFO *GpeXruptInfo,
57 ACPI_GPE_BLOCK_INFO *GpeBlock,
61 /******************************************************************************
63 * FUNCTION: AcpiHwGetGpeRegisterBit
65 * PARAMETERS: GpeEventInfo - Info block for the GPE
66 * GpeRegisterInfo - Info block for the GPE register
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,
78 ACPI_GPE_REGISTER_INFO *GpeRegisterInfo)
82 (GpeEventInfo->GpeNumber - GpeRegisterInfo->BaseGpeNumber));
86 /******************************************************************************
88 * FUNCTION: AcpiHwLowSetGpe
90 * PARAMETERS: GpeEventInfo - Info block for the GPE to be disabled
91 * Action - Enable or disable
95 * DESCRIPTION: Enable or disable a single GPE in the parent enable register.
97 ******************************************************************************/
101 ACPI_GPE_EVENT_INFO *GpeEventInfo,
104 ACPI_GPE_REGISTER_INFO *GpeRegisterInfo;
110 ACPI_FUNCTION_ENTRY ();
113 /* Get the info block for the entire GPE register */
115 GpeRegisterInfo = GpeEventInfo->RegisterInfo;
116 if (!GpeRegisterInfo)
118 return (AE_NOT_EXIST);
121 /* Get current value of the enable register that contains this GPE */
123 Status = AcpiHwRead (&EnableMask, &GpeRegisterInfo->EnableAddress);
124 if (ACPI_FAILURE (Status))
129 /* Set or clear just the bit that corresponds to this GPE */
131 RegisterBit = AcpiHwGetGpeRegisterBit (GpeEventInfo, GpeRegisterInfo);
134 case ACPI_GPE_CONDITIONAL_ENABLE:
136 /* Only enable if the EnableForRun bit is set */
138 if (!(RegisterBit & GpeRegisterInfo->EnableForRun))
140 return (AE_BAD_PARAMETER);
143 /*lint -fallthrough */
145 case ACPI_GPE_ENABLE:
146 ACPI_SET_BIT (EnableMask, RegisterBit);
149 case ACPI_GPE_DISABLE:
150 ACPI_CLEAR_BIT (EnableMask, RegisterBit);
154 ACPI_ERROR ((AE_INFO, "Invalid GPE Action, %u\n", Action));
155 return (AE_BAD_PARAMETER);
158 /* Write the updated enable mask */
160 Status = AcpiHwWrite (EnableMask, &GpeRegisterInfo->EnableAddress);
165 /******************************************************************************
167 * FUNCTION: AcpiHwClearGpe
169 * PARAMETERS: GpeEventInfo - Info block for the GPE to be cleared
173 * DESCRIPTION: Clear the status bit for a single GPE.
175 ******************************************************************************/
179 ACPI_GPE_EVENT_INFO *GpeEventInfo)
181 ACPI_GPE_REGISTER_INFO *GpeRegisterInfo;
186 ACPI_FUNCTION_ENTRY ();
188 /* Get the info block for the entire GPE register */
190 GpeRegisterInfo = GpeEventInfo->RegisterInfo;
191 if (!GpeRegisterInfo)
193 return (AE_NOT_EXIST);
197 * Write a one to the appropriate bit in the status register to
200 RegisterBit = AcpiHwGetGpeRegisterBit (GpeEventInfo, GpeRegisterInfo);
202 Status = AcpiHwWrite (RegisterBit,
203 &GpeRegisterInfo->StatusAddress);
209 /******************************************************************************
211 * FUNCTION: AcpiHwGetGpeStatus
213 * PARAMETERS: GpeEventInfo - Info block for the GPE to queried
214 * EventStatus - Where the GPE status is returned
218 * DESCRIPTION: Return the status of a single GPE.
220 ******************************************************************************/
224 ACPI_GPE_EVENT_INFO *GpeEventInfo,
225 ACPI_EVENT_STATUS *EventStatus)
229 ACPI_GPE_REGISTER_INFO *GpeRegisterInfo;
230 ACPI_EVENT_STATUS LocalEventStatus = 0;
234 ACPI_FUNCTION_ENTRY ();
239 return (AE_BAD_PARAMETER);
242 /* Get the info block for the entire GPE register */
244 GpeRegisterInfo = GpeEventInfo->RegisterInfo;
246 /* Get the register bitmask for this GPE */
248 RegisterBit = AcpiHwGetGpeRegisterBit (GpeEventInfo, GpeRegisterInfo);
250 /* GPE currently enabled? (enabled for runtime?) */
252 if (RegisterBit & GpeRegisterInfo->EnableForRun)
254 LocalEventStatus |= ACPI_EVENT_FLAG_ENABLED;
257 /* GPE enabled for wake? */
259 if (RegisterBit & GpeRegisterInfo->EnableForWake)
261 LocalEventStatus |= ACPI_EVENT_FLAG_WAKE_ENABLED;
264 /* GPE currently active (status bit == 1)? */
266 Status = AcpiHwRead (&InByte, &GpeRegisterInfo->StatusAddress);
267 if (ACPI_FAILURE (Status))
272 if (RegisterBit & InByte)
274 LocalEventStatus |= ACPI_EVENT_FLAG_SET;
277 /* Set return value */
279 (*EventStatus) = LocalEventStatus;
284 /******************************************************************************
286 * FUNCTION: AcpiHwDisableGpeBlock
288 * PARAMETERS: GpeXruptInfo - GPE Interrupt info
289 * GpeBlock - Gpe Block info
293 * DESCRIPTION: Disable all GPEs within a single GPE block
295 ******************************************************************************/
298 AcpiHwDisableGpeBlock (
299 ACPI_GPE_XRUPT_INFO *GpeXruptInfo,
300 ACPI_GPE_BLOCK_INFO *GpeBlock,
307 /* Examine each GPE Register within the block */
309 for (i = 0; i < GpeBlock->RegisterCount; i++)
311 /* Disable all GPEs in this register */
313 Status = AcpiHwWrite (0x00, &GpeBlock->RegisterInfo[i].EnableAddress);
314 if (ACPI_FAILURE (Status))
324 /******************************************************************************
326 * FUNCTION: AcpiHwClearGpeBlock
328 * PARAMETERS: GpeXruptInfo - GPE Interrupt info
329 * GpeBlock - Gpe Block info
333 * DESCRIPTION: Clear status bits for all GPEs within a single GPE block
335 ******************************************************************************/
338 AcpiHwClearGpeBlock (
339 ACPI_GPE_XRUPT_INFO *GpeXruptInfo,
340 ACPI_GPE_BLOCK_INFO *GpeBlock,
347 /* Examine each GPE Register within the block */
349 for (i = 0; i < GpeBlock->RegisterCount; i++)
351 /* Clear status on all GPEs in this register */
353 Status = AcpiHwWrite (0xFF, &GpeBlock->RegisterInfo[i].StatusAddress);
354 if (ACPI_FAILURE (Status))
364 /******************************************************************************
366 * FUNCTION: AcpiHwEnableRuntimeGpeBlock
368 * PARAMETERS: GpeXruptInfo - GPE Interrupt info
369 * GpeBlock - Gpe Block info
373 * DESCRIPTION: Enable all "runtime" GPEs within a single GPE block. Includes
374 * combination wake/run GPEs.
376 ******************************************************************************/
379 AcpiHwEnableRuntimeGpeBlock (
380 ACPI_GPE_XRUPT_INFO *GpeXruptInfo,
381 ACPI_GPE_BLOCK_INFO *GpeBlock,
388 /* NOTE: assumes that all GPEs are currently disabled */
390 /* Examine each GPE Register within the block */
392 for (i = 0; i < GpeBlock->RegisterCount; i++)
394 if (!GpeBlock->RegisterInfo[i].EnableForRun)
399 /* Enable all "runtime" GPEs in this register */
401 Status = AcpiHwWrite (GpeBlock->RegisterInfo[i].EnableForRun,
402 &GpeBlock->RegisterInfo[i].EnableAddress);
403 if (ACPI_FAILURE (Status))
413 /******************************************************************************
415 * FUNCTION: AcpiHwEnableWakeupGpeBlock
417 * PARAMETERS: GpeXruptInfo - GPE Interrupt info
418 * GpeBlock - Gpe Block info
422 * DESCRIPTION: Enable all "wake" GPEs within a single GPE block. Includes
423 * combination wake/run GPEs.
425 ******************************************************************************/
428 AcpiHwEnableWakeupGpeBlock (
429 ACPI_GPE_XRUPT_INFO *GpeXruptInfo,
430 ACPI_GPE_BLOCK_INFO *GpeBlock,
437 /* Examine each GPE Register within the block */
439 for (i = 0; i < GpeBlock->RegisterCount; i++)
441 if (!GpeBlock->RegisterInfo[i].EnableForWake)
446 /* Enable all "wake" GPEs in this register */
448 Status = AcpiHwWrite (GpeBlock->RegisterInfo[i].EnableForWake,
449 &GpeBlock->RegisterInfo[i].EnableAddress);
450 if (ACPI_FAILURE (Status))
460 /******************************************************************************
462 * FUNCTION: AcpiHwDisableAllGpes
468 * DESCRIPTION: Disable and clear all GPEs in all GPE blocks
470 ******************************************************************************/
473 AcpiHwDisableAllGpes (
479 ACPI_FUNCTION_TRACE (HwDisableAllGpes);
482 Status = AcpiEvWalkGpeList (AcpiHwDisableGpeBlock, NULL);
483 Status = AcpiEvWalkGpeList (AcpiHwClearGpeBlock, NULL);
484 return_ACPI_STATUS (Status);
488 /******************************************************************************
490 * FUNCTION: AcpiHwEnableAllRuntimeGpes
496 * DESCRIPTION: Enable all "runtime" GPEs, in all GPE blocks
498 ******************************************************************************/
501 AcpiHwEnableAllRuntimeGpes (
507 ACPI_FUNCTION_TRACE (HwEnableAllRuntimeGpes);
510 Status = AcpiEvWalkGpeList (AcpiHwEnableRuntimeGpeBlock, NULL);
511 return_ACPI_STATUS (Status);
515 /******************************************************************************
517 * FUNCTION: AcpiHwEnableAllWakeupGpes
523 * DESCRIPTION: Enable all "wakeup" GPEs, in all GPE blocks
525 ******************************************************************************/
528 AcpiHwEnableAllWakeupGpes (
534 ACPI_FUNCTION_TRACE (HwEnableAllWakeupGpes);
537 Status = AcpiEvWalkGpeList (AcpiHwEnableWakeupGpeBlock, NULL);
538 return_ACPI_STATUS (Status);