1 /******************************************************************************
3 * Module Name: hwgpe - Low level GPE enable/disable/clear functions
5 *****************************************************************************/
7 /******************************************************************************
11 * Some or all of this work - Copyright (c) 1999 - 2015, Intel Corp.
12 * All rights reserved.
16 * 2.1. This is your license from Intel Corp. under its intellectual property
17 * rights. You may have additional license terms from the party that provided
18 * you this software, covering your right to use that party's intellectual
21 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22 * copy of the source code appearing in this file ("Covered Code") an
23 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24 * base code distributed originally by Intel ("Original Intel Code") to copy,
25 * make derivatives, distribute, use and display any portion of the Covered
26 * Code in any form, with the right to sublicense such rights; and
28 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29 * license (with the right to sublicense), under only those claims of Intel
30 * patents that are infringed by the Original Intel Code, to make, use, sell,
31 * offer to sell, and import the Covered Code and derivative works thereof
32 * solely to the minimum extent necessary to exercise the above copyright
33 * license, and in no event shall the patent license extend to any additions
34 * to or modifications of the Original Intel Code. No other license or right
35 * is granted directly or by implication, estoppel or otherwise;
37 * The above copyright and patent license is granted only if the following
42 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43 * Redistribution of source code of any substantial portion of the Covered
44 * Code or modification with rights to further distribute source must include
45 * the above Copyright Notice, the above License, this list of Conditions,
46 * and the following Disclaimer and Export Compliance provision. In addition,
47 * Licensee must cause all Covered Code to which Licensee contributes to
48 * contain a file documenting the changes Licensee made to create that Covered
49 * Code and the date of any change. Licensee must include in that file the
50 * documentation of any changes made by any predecessor Licensee. Licensee
51 * must include a prominent statement that the modification is derived,
52 * directly or indirectly, from Original Intel Code.
54 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55 * Redistribution of source code of any substantial portion of the Covered
56 * Code or modification without rights to further distribute source must
57 * include the following Disclaimer and Export Compliance provision in the
58 * documentation and/or other materials provided with distribution. In
59 * addition, Licensee may not authorize further sublicense of source of any
60 * portion of the Covered Code, and must include terms to the effect that the
61 * license from Licensee to its licensee is limited to the intellectual
62 * property embodied in the software Licensee provides to its licensee, and
63 * not to intellectual property embodied in modifications its licensee may
66 * 3.3. Redistribution of Executable. Redistribution in executable form of any
67 * substantial portion of the Covered Code or modification must reproduce the
68 * above Copyright Notice, and the following Disclaimer and Export Compliance
69 * provision in the documentation and/or other materials provided with the
72 * 3.4. Intel retains all right, title, and interest in and to the Original
75 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76 * Intel shall be used in advertising or otherwise to promote the sale, use or
77 * other dealings in products derived from or relating to the Covered Code
78 * without prior written authorization from Intel.
80 * 4. Disclaimer and Export Compliance
82 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
90 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
99 * 4.3. Licensee shall not export, either directly or indirectly, any of this
100 * software or system incorporating such software without first obtaining any
101 * required license or other approval from the U. S. Department of Commerce or
102 * any other agency or department of the United States Government. In the
103 * event Licensee exports any such software from the United States or
104 * re-exports any such software from a foreign destination, Licensee shall
105 * ensure that the distribution and export/re-export of the software is in
106 * compliance with all laws, regulations, orders, or other restrictions of the
107 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108 * any of its subsidiaries will export/re-export any technical data, process,
109 * software, or service, directly or indirectly, to any country for which the
110 * United States government or any agency thereof requires an export license,
111 * other governmental approval, or letter of assurance, without first obtaining
112 * such license, approval or letter.
114 *****************************************************************************/
117 #include "accommon.h"
118 #include "acevents.h"
120 #define _COMPONENT ACPI_HARDWARE
121 ACPI_MODULE_NAME ("hwgpe")
123 #if (!ACPI_REDUCED_HARDWARE) /* Entire module */
125 /* Local prototypes */
128 AcpiHwEnableWakeupGpeBlock (
129 ACPI_GPE_XRUPT_INFO *GpeXruptInfo,
130 ACPI_GPE_BLOCK_INFO *GpeBlock,
134 AcpiHwGpeEnableWrite (
136 ACPI_GPE_REGISTER_INFO *GpeRegisterInfo);
139 /******************************************************************************
141 * FUNCTION: AcpiHwGetGpeRegisterBit
143 * PARAMETERS: GpeEventInfo - Info block for the GPE
145 * RETURN: Register mask with a one in the GPE bit position
147 * DESCRIPTION: Compute the register mask for this GPE. One bit is set in the
148 * correct position for the input GPE.
150 ******************************************************************************/
153 AcpiHwGetGpeRegisterBit (
154 ACPI_GPE_EVENT_INFO *GpeEventInfo)
157 return ((UINT32) 1 <<
158 (GpeEventInfo->GpeNumber - GpeEventInfo->RegisterInfo->BaseGpeNumber));
162 /******************************************************************************
164 * FUNCTION: AcpiHwLowSetGpe
166 * PARAMETERS: GpeEventInfo - Info block for the GPE to be disabled
167 * Action - Enable or disable
171 * DESCRIPTION: Enable or disable a single GPE in the parent enable register.
173 ******************************************************************************/
177 ACPI_GPE_EVENT_INFO *GpeEventInfo,
180 ACPI_GPE_REGISTER_INFO *GpeRegisterInfo;
186 ACPI_FUNCTION_ENTRY ();
189 /* Get the info block for the entire GPE register */
191 GpeRegisterInfo = GpeEventInfo->RegisterInfo;
192 if (!GpeRegisterInfo)
194 return (AE_NOT_EXIST);
197 /* Get current value of the enable register that contains this GPE */
199 Status = AcpiHwRead (&EnableMask, &GpeRegisterInfo->EnableAddress);
200 if (ACPI_FAILURE (Status))
205 /* Set or clear just the bit that corresponds to this GPE */
207 RegisterBit = AcpiHwGetGpeRegisterBit (GpeEventInfo);
208 switch (Action & ~ACPI_GPE_SAVE_MASK)
210 case ACPI_GPE_CONDITIONAL_ENABLE:
212 /* Only enable if the corresponding EnableMask bit is set */
214 if (!(RegisterBit & GpeRegisterInfo->EnableMask))
216 return (AE_BAD_PARAMETER);
219 /*lint -fallthrough */
221 case ACPI_GPE_ENABLE:
223 ACPI_SET_BIT (EnableMask, RegisterBit);
226 case ACPI_GPE_DISABLE:
228 ACPI_CLEAR_BIT (EnableMask, RegisterBit);
233 ACPI_ERROR ((AE_INFO, "Invalid GPE Action, %u", Action));
234 return (AE_BAD_PARAMETER);
237 /* Write the updated enable mask */
239 Status = AcpiHwWrite (EnableMask, &GpeRegisterInfo->EnableAddress);
240 if (ACPI_SUCCESS (Status) && (Action & ACPI_GPE_SAVE_MASK))
242 GpeRegisterInfo->EnableMask = (UINT8) EnableMask;
248 /******************************************************************************
250 * FUNCTION: AcpiHwClearGpe
252 * PARAMETERS: GpeEventInfo - Info block for the GPE to be cleared
256 * DESCRIPTION: Clear the status bit for a single GPE.
258 ******************************************************************************/
262 ACPI_GPE_EVENT_INFO *GpeEventInfo)
264 ACPI_GPE_REGISTER_INFO *GpeRegisterInfo;
269 ACPI_FUNCTION_ENTRY ();
271 /* Get the info block for the entire GPE register */
273 GpeRegisterInfo = GpeEventInfo->RegisterInfo;
274 if (!GpeRegisterInfo)
276 return (AE_NOT_EXIST);
280 * Write a one to the appropriate bit in the status register to
283 RegisterBit = AcpiHwGetGpeRegisterBit (GpeEventInfo);
285 Status = AcpiHwWrite (RegisterBit,
286 &GpeRegisterInfo->StatusAddress);
292 /******************************************************************************
294 * FUNCTION: AcpiHwGetGpeStatus
296 * PARAMETERS: GpeEventInfo - Info block for the GPE to queried
297 * EventStatus - Where the GPE status is returned
301 * DESCRIPTION: Return the status of a single GPE.
303 ******************************************************************************/
307 ACPI_GPE_EVENT_INFO *GpeEventInfo,
308 ACPI_EVENT_STATUS *EventStatus)
312 ACPI_GPE_REGISTER_INFO *GpeRegisterInfo;
313 ACPI_EVENT_STATUS LocalEventStatus = 0;
317 ACPI_FUNCTION_ENTRY ();
322 return (AE_BAD_PARAMETER);
325 /* GPE currently handled? */
327 if (ACPI_GPE_DISPATCH_TYPE (GpeEventInfo->Flags) !=
328 ACPI_GPE_DISPATCH_NONE)
330 LocalEventStatus |= ACPI_EVENT_FLAG_HAS_HANDLER;
333 /* Get the info block for the entire GPE register */
335 GpeRegisterInfo = GpeEventInfo->RegisterInfo;
337 /* Get the register bitmask for this GPE */
339 RegisterBit = AcpiHwGetGpeRegisterBit (GpeEventInfo);
341 /* GPE currently enabled? (enabled for runtime?) */
343 if (RegisterBit & GpeRegisterInfo->EnableForRun)
345 LocalEventStatus |= ACPI_EVENT_FLAG_ENABLED;
348 /* GPE enabled for wake? */
350 if (RegisterBit & GpeRegisterInfo->EnableForWake)
352 LocalEventStatus |= ACPI_EVENT_FLAG_WAKE_ENABLED;
355 /* GPE currently enabled (enable bit == 1)? */
357 Status = AcpiHwRead (&InByte, &GpeRegisterInfo->EnableAddress);
358 if (ACPI_FAILURE (Status))
363 if (RegisterBit & InByte)
365 LocalEventStatus |= ACPI_EVENT_FLAG_ENABLE_SET;
368 /* GPE currently active (status bit == 1)? */
370 Status = AcpiHwRead (&InByte, &GpeRegisterInfo->StatusAddress);
371 if (ACPI_FAILURE (Status))
376 if (RegisterBit & InByte)
378 LocalEventStatus |= ACPI_EVENT_FLAG_STATUS_SET;
381 /* Set return value */
383 (*EventStatus) = LocalEventStatus;
388 /******************************************************************************
390 * FUNCTION: AcpiHwGpeEnableWrite
392 * PARAMETERS: EnableMask - Bit mask to write to the GPE register
393 * GpeRegisterInfo - Gpe Register info
397 * DESCRIPTION: Write the enable mask byte to the given GPE register.
399 ******************************************************************************/
402 AcpiHwGpeEnableWrite (
404 ACPI_GPE_REGISTER_INFO *GpeRegisterInfo)
409 Status = AcpiHwWrite (EnableMask, &GpeRegisterInfo->EnableAddress);
410 if (ACPI_SUCCESS (Status))
412 GpeRegisterInfo->EnableMask = EnableMask;
419 /******************************************************************************
421 * FUNCTION: AcpiHwDisableGpeBlock
423 * PARAMETERS: GpeXruptInfo - GPE Interrupt info
424 * GpeBlock - Gpe Block info
428 * DESCRIPTION: Disable all GPEs within a single GPE block
430 ******************************************************************************/
433 AcpiHwDisableGpeBlock (
434 ACPI_GPE_XRUPT_INFO *GpeXruptInfo,
435 ACPI_GPE_BLOCK_INFO *GpeBlock,
442 /* Examine each GPE Register within the block */
444 for (i = 0; i < GpeBlock->RegisterCount; i++)
446 /* Disable all GPEs in this register */
448 Status = AcpiHwGpeEnableWrite (0x00, &GpeBlock->RegisterInfo[i]);
449 if (ACPI_FAILURE (Status))
459 /******************************************************************************
461 * FUNCTION: AcpiHwClearGpeBlock
463 * PARAMETERS: GpeXruptInfo - GPE Interrupt info
464 * GpeBlock - Gpe Block info
468 * DESCRIPTION: Clear status bits for all GPEs within a single GPE block
470 ******************************************************************************/
473 AcpiHwClearGpeBlock (
474 ACPI_GPE_XRUPT_INFO *GpeXruptInfo,
475 ACPI_GPE_BLOCK_INFO *GpeBlock,
482 /* Examine each GPE Register within the block */
484 for (i = 0; i < GpeBlock->RegisterCount; i++)
486 /* Clear status on all GPEs in this register */
488 Status = AcpiHwWrite (0xFF, &GpeBlock->RegisterInfo[i].StatusAddress);
489 if (ACPI_FAILURE (Status))
499 /******************************************************************************
501 * FUNCTION: AcpiHwEnableRuntimeGpeBlock
503 * PARAMETERS: GpeXruptInfo - GPE Interrupt info
504 * GpeBlock - Gpe Block info
508 * DESCRIPTION: Enable all "runtime" GPEs within a single GPE block. Includes
509 * combination wake/run GPEs.
511 ******************************************************************************/
514 AcpiHwEnableRuntimeGpeBlock (
515 ACPI_GPE_XRUPT_INFO *GpeXruptInfo,
516 ACPI_GPE_BLOCK_INFO *GpeBlock,
521 ACPI_GPE_REGISTER_INFO *GpeRegisterInfo;
524 /* NOTE: assumes that all GPEs are currently disabled */
526 /* Examine each GPE Register within the block */
528 for (i = 0; i < GpeBlock->RegisterCount; i++)
530 GpeRegisterInfo = &GpeBlock->RegisterInfo[i];
531 if (!GpeRegisterInfo->EnableForRun)
536 /* Enable all "runtime" GPEs in this register */
538 Status = AcpiHwGpeEnableWrite (GpeRegisterInfo->EnableForRun,
540 if (ACPI_FAILURE (Status))
550 /******************************************************************************
552 * FUNCTION: AcpiHwEnableWakeupGpeBlock
554 * PARAMETERS: GpeXruptInfo - GPE Interrupt info
555 * GpeBlock - Gpe Block info
559 * DESCRIPTION: Enable all "wake" GPEs within a single GPE block. Includes
560 * combination wake/run GPEs.
562 ******************************************************************************/
565 AcpiHwEnableWakeupGpeBlock (
566 ACPI_GPE_XRUPT_INFO *GpeXruptInfo,
567 ACPI_GPE_BLOCK_INFO *GpeBlock,
572 ACPI_GPE_REGISTER_INFO *GpeRegisterInfo;
575 /* Examine each GPE Register within the block */
577 for (i = 0; i < GpeBlock->RegisterCount; i++)
579 GpeRegisterInfo = &GpeBlock->RegisterInfo[i];
582 * Enable all "wake" GPEs in this register and disable the
585 Status = AcpiHwGpeEnableWrite (GpeRegisterInfo->EnableForWake,
587 if (ACPI_FAILURE (Status))
597 /******************************************************************************
599 * FUNCTION: AcpiHwDisableAllGpes
605 * DESCRIPTION: Disable and clear all GPEs in all GPE blocks
607 ******************************************************************************/
610 AcpiHwDisableAllGpes (
616 ACPI_FUNCTION_TRACE (HwDisableAllGpes);
619 Status = AcpiEvWalkGpeList (AcpiHwDisableGpeBlock, NULL);
620 Status = AcpiEvWalkGpeList (AcpiHwClearGpeBlock, NULL);
621 return_ACPI_STATUS (Status);
625 /******************************************************************************
627 * FUNCTION: AcpiHwEnableAllRuntimeGpes
633 * DESCRIPTION: Enable all "runtime" GPEs, in all GPE blocks
635 ******************************************************************************/
638 AcpiHwEnableAllRuntimeGpes (
644 ACPI_FUNCTION_TRACE (HwEnableAllRuntimeGpes);
647 Status = AcpiEvWalkGpeList (AcpiHwEnableRuntimeGpeBlock, NULL);
648 return_ACPI_STATUS (Status);
652 /******************************************************************************
654 * FUNCTION: AcpiHwEnableAllWakeupGpes
660 * DESCRIPTION: Enable all "wakeup" GPEs, in all GPE blocks
662 ******************************************************************************/
665 AcpiHwEnableAllWakeupGpes (
671 ACPI_FUNCTION_TRACE (HwEnableAllWakeupGpes);
674 Status = AcpiEvWalkGpeList (AcpiHwEnableWakeupGpeBlock, NULL);
675 return_ACPI_STATUS (Status);
678 #endif /* !ACPI_REDUCED_HARDWARE */