2 /******************************************************************************
4 * Module Name: hwgpe - Low level GPE enable/disable/clear functions
6 *****************************************************************************/
9 * Copyright (C) 2000 - 2012, 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 #if (!ACPI_REDUCED_HARDWARE) /* Entire module */
54 /* Local prototypes */
57 AcpiHwEnableWakeupGpeBlock (
58 ACPI_GPE_XRUPT_INFO *GpeXruptInfo,
59 ACPI_GPE_BLOCK_INFO *GpeBlock,
63 /******************************************************************************
65 * FUNCTION: AcpiHwGetGpeRegisterBit
67 * PARAMETERS: GpeEventInfo - Info block for the GPE
68 * GpeRegisterInfo - Info block for the GPE register
70 * RETURN: Register mask with a one in the GPE bit position
72 * DESCRIPTION: Compute the register mask for this GPE. One bit is set in the
73 * correct position for the input GPE.
75 ******************************************************************************/
78 AcpiHwGetGpeRegisterBit (
79 ACPI_GPE_EVENT_INFO *GpeEventInfo,
80 ACPI_GPE_REGISTER_INFO *GpeRegisterInfo)
84 (GpeEventInfo->GpeNumber - GpeRegisterInfo->BaseGpeNumber));
88 /******************************************************************************
90 * FUNCTION: AcpiHwLowSetGpe
92 * PARAMETERS: GpeEventInfo - Info block for the GPE to be disabled
93 * Action - Enable or disable
97 * DESCRIPTION: Enable or disable a single GPE in the parent enable register.
99 ******************************************************************************/
103 ACPI_GPE_EVENT_INFO *GpeEventInfo,
106 ACPI_GPE_REGISTER_INFO *GpeRegisterInfo;
112 ACPI_FUNCTION_ENTRY ();
115 /* Get the info block for the entire GPE register */
117 GpeRegisterInfo = GpeEventInfo->RegisterInfo;
118 if (!GpeRegisterInfo)
120 return (AE_NOT_EXIST);
123 /* Get current value of the enable register that contains this GPE */
125 Status = AcpiHwRead (&EnableMask, &GpeRegisterInfo->EnableAddress);
126 if (ACPI_FAILURE (Status))
131 /* Set or clear just the bit that corresponds to this GPE */
133 RegisterBit = AcpiHwGetGpeRegisterBit (GpeEventInfo, GpeRegisterInfo);
136 case ACPI_GPE_CONDITIONAL_ENABLE:
138 /* Only enable if the EnableForRun bit is set */
140 if (!(RegisterBit & GpeRegisterInfo->EnableForRun))
142 return (AE_BAD_PARAMETER);
145 /*lint -fallthrough */
147 case ACPI_GPE_ENABLE:
148 ACPI_SET_BIT (EnableMask, RegisterBit);
151 case ACPI_GPE_DISABLE:
152 ACPI_CLEAR_BIT (EnableMask, RegisterBit);
156 ACPI_ERROR ((AE_INFO, "Invalid GPE Action, %u\n", 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, GpeRegisterInfo);
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 /* Get the info block for the entire GPE register */
246 GpeRegisterInfo = GpeEventInfo->RegisterInfo;
248 /* Get the register bitmask for this GPE */
250 RegisterBit = AcpiHwGetGpeRegisterBit (GpeEventInfo, GpeRegisterInfo);
252 /* GPE currently enabled? (enabled for runtime?) */
254 if (RegisterBit & GpeRegisterInfo->EnableForRun)
256 LocalEventStatus |= ACPI_EVENT_FLAG_ENABLED;
259 /* GPE enabled for wake? */
261 if (RegisterBit & GpeRegisterInfo->EnableForWake)
263 LocalEventStatus |= ACPI_EVENT_FLAG_WAKE_ENABLED;
266 /* GPE currently active (status bit == 1)? */
268 Status = AcpiHwRead (&InByte, &GpeRegisterInfo->StatusAddress);
269 if (ACPI_FAILURE (Status))
274 if (RegisterBit & InByte)
276 LocalEventStatus |= ACPI_EVENT_FLAG_SET;
279 /* Set return value */
281 (*EventStatus) = LocalEventStatus;
286 /******************************************************************************
288 * FUNCTION: AcpiHwDisableGpeBlock
290 * PARAMETERS: GpeXruptInfo - GPE Interrupt info
291 * GpeBlock - Gpe Block info
295 * DESCRIPTION: Disable all GPEs within a single GPE block
297 ******************************************************************************/
300 AcpiHwDisableGpeBlock (
301 ACPI_GPE_XRUPT_INFO *GpeXruptInfo,
302 ACPI_GPE_BLOCK_INFO *GpeBlock,
309 /* Examine each GPE Register within the block */
311 for (i = 0; i < GpeBlock->RegisterCount; i++)
313 /* Disable all GPEs in this register */
315 Status = AcpiHwWrite (0x00, &GpeBlock->RegisterInfo[i].EnableAddress);
316 if (ACPI_FAILURE (Status))
326 /******************************************************************************
328 * FUNCTION: AcpiHwClearGpeBlock
330 * PARAMETERS: GpeXruptInfo - GPE Interrupt info
331 * GpeBlock - Gpe Block info
335 * DESCRIPTION: Clear status bits for all GPEs within a single GPE block
337 ******************************************************************************/
340 AcpiHwClearGpeBlock (
341 ACPI_GPE_XRUPT_INFO *GpeXruptInfo,
342 ACPI_GPE_BLOCK_INFO *GpeBlock,
349 /* Examine each GPE Register within the block */
351 for (i = 0; i < GpeBlock->RegisterCount; i++)
353 /* Clear status on all GPEs in this register */
355 Status = AcpiHwWrite (0xFF, &GpeBlock->RegisterInfo[i].StatusAddress);
356 if (ACPI_FAILURE (Status))
366 /******************************************************************************
368 * FUNCTION: AcpiHwEnableRuntimeGpeBlock
370 * PARAMETERS: GpeXruptInfo - GPE Interrupt info
371 * GpeBlock - Gpe Block info
375 * DESCRIPTION: Enable all "runtime" GPEs within a single GPE block. Includes
376 * combination wake/run GPEs.
378 ******************************************************************************/
381 AcpiHwEnableRuntimeGpeBlock (
382 ACPI_GPE_XRUPT_INFO *GpeXruptInfo,
383 ACPI_GPE_BLOCK_INFO *GpeBlock,
390 /* NOTE: assumes that all GPEs are currently disabled */
392 /* Examine each GPE Register within the block */
394 for (i = 0; i < GpeBlock->RegisterCount; i++)
396 if (!GpeBlock->RegisterInfo[i].EnableForRun)
401 /* Enable all "runtime" GPEs in this register */
403 Status = AcpiHwWrite (GpeBlock->RegisterInfo[i].EnableForRun,
404 &GpeBlock->RegisterInfo[i].EnableAddress);
405 if (ACPI_FAILURE (Status))
415 /******************************************************************************
417 * FUNCTION: AcpiHwEnableWakeupGpeBlock
419 * PARAMETERS: GpeXruptInfo - GPE Interrupt info
420 * GpeBlock - Gpe Block info
424 * DESCRIPTION: Enable all "wake" GPEs within a single GPE block. Includes
425 * combination wake/run GPEs.
427 ******************************************************************************/
430 AcpiHwEnableWakeupGpeBlock (
431 ACPI_GPE_XRUPT_INFO *GpeXruptInfo,
432 ACPI_GPE_BLOCK_INFO *GpeBlock,
439 /* Examine each GPE Register within the block */
441 for (i = 0; i < GpeBlock->RegisterCount; i++)
443 if (!GpeBlock->RegisterInfo[i].EnableForWake)
448 /* Enable all "wake" GPEs in this register */
450 Status = AcpiHwWrite (GpeBlock->RegisterInfo[i].EnableForWake,
451 &GpeBlock->RegisterInfo[i].EnableAddress);
452 if (ACPI_FAILURE (Status))
462 /******************************************************************************
464 * FUNCTION: AcpiHwDisableAllGpes
470 * DESCRIPTION: Disable and clear all GPEs in all GPE blocks
472 ******************************************************************************/
475 AcpiHwDisableAllGpes (
481 ACPI_FUNCTION_TRACE (HwDisableAllGpes);
484 Status = AcpiEvWalkGpeList (AcpiHwDisableGpeBlock, NULL);
485 Status = AcpiEvWalkGpeList (AcpiHwClearGpeBlock, NULL);
486 return_ACPI_STATUS (Status);
490 /******************************************************************************
492 * FUNCTION: AcpiHwEnableAllRuntimeGpes
498 * DESCRIPTION: Enable all "runtime" GPEs, in all GPE blocks
500 ******************************************************************************/
503 AcpiHwEnableAllRuntimeGpes (
509 ACPI_FUNCTION_TRACE (HwEnableAllRuntimeGpes);
512 Status = AcpiEvWalkGpeList (AcpiHwEnableRuntimeGpeBlock, NULL);
513 return_ACPI_STATUS (Status);
517 /******************************************************************************
519 * FUNCTION: AcpiHwEnableAllWakeupGpes
525 * DESCRIPTION: Enable all "wakeup" GPEs, in all GPE blocks
527 ******************************************************************************/
530 AcpiHwEnableAllWakeupGpes (
536 ACPI_FUNCTION_TRACE (HwEnableAllWakeupGpes);
539 Status = AcpiEvWalkGpeList (AcpiHwEnableWakeupGpeBlock, NULL);
540 return_ACPI_STATUS (Status);
543 #endif /* !ACPI_REDUCED_HARDWARE */