Sync ACPICA with Intel's version 20170831.
[dragonfly.git] / sys / contrib / dev / acpica / source / components / hardware / hwgpe.c
blob636639be03e63f3f8d300e4ff2e82e98d5b40d53
1 /******************************************************************************
3 * Module Name: hwgpe - Low level GPE enable/disable/clear functions
5 *****************************************************************************/
7 /******************************************************************************
9 * 1. Copyright Notice
11 * Some or all of this work - Copyright (c) 1999 - 2017, Intel Corp.
12 * All rights reserved.
14 * 2. License
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
19 * property rights.
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
38 * conditions are met:
40 * 3. Conditions
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
64 * make.
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
70 * distribution.
72 * 3.4. Intel retains all right, title, and interest in and to the Original
73 * Intel Code.
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
88 * PARTICULAR PURPOSE.
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
97 * LIMITED REMEDY.
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 *****************************************************************************
116 * Alternatively, you may choose to be licensed under the terms of the
117 * following license:
119 * Redistribution and use in source and binary forms, with or without
120 * modification, are permitted provided that the following conditions
121 * are met:
122 * 1. Redistributions of source code must retain the above copyright
123 * notice, this list of conditions, and the following disclaimer,
124 * without modification.
125 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
126 * substantially similar to the "NO WARRANTY" disclaimer below
127 * ("Disclaimer") and any redistribution must be conditioned upon
128 * including a substantially similar Disclaimer requirement for further
129 * binary redistribution.
130 * 3. Neither the names of the above-listed copyright holders nor the names
131 * of any contributors may be used to endorse or promote products derived
132 * from this software without specific prior written permission.
134 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
135 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
136 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
137 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
138 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
139 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
140 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
141 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
142 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
143 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
144 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
146 * Alternatively, you may choose to be licensed under the terms of the
147 * GNU General Public License ("GPL") version 2 as published by the Free
148 * Software Foundation.
150 *****************************************************************************/
152 #include "acpi.h"
153 #include "accommon.h"
154 #include "acevents.h"
156 #define _COMPONENT ACPI_HARDWARE
157 ACPI_MODULE_NAME ("hwgpe")
159 #if (!ACPI_REDUCED_HARDWARE) /* Entire module */
161 /* Local prototypes */
163 static ACPI_STATUS
164 AcpiHwEnableWakeupGpeBlock (
165 ACPI_GPE_XRUPT_INFO *GpeXruptInfo,
166 ACPI_GPE_BLOCK_INFO *GpeBlock,
167 void *Context);
169 static ACPI_STATUS
170 AcpiHwGpeEnableWrite (
171 UINT8 EnableMask,
172 ACPI_GPE_REGISTER_INFO *GpeRegisterInfo);
175 /******************************************************************************
177 * FUNCTION: AcpiHwGetGpeRegisterBit
179 * PARAMETERS: GpeEventInfo - Info block for the GPE
181 * RETURN: Register mask with a one in the GPE bit position
183 * DESCRIPTION: Compute the register mask for this GPE. One bit is set in the
184 * correct position for the input GPE.
186 ******************************************************************************/
188 UINT32
189 AcpiHwGetGpeRegisterBit (
190 ACPI_GPE_EVENT_INFO *GpeEventInfo)
193 return ((UINT32) 1 <<
194 (GpeEventInfo->GpeNumber - GpeEventInfo->RegisterInfo->BaseGpeNumber));
198 /******************************************************************************
200 * FUNCTION: AcpiHwLowSetGpe
202 * PARAMETERS: GpeEventInfo - Info block for the GPE to be disabled
203 * Action - Enable or disable
205 * RETURN: Status
207 * DESCRIPTION: Enable or disable a single GPE in the parent enable register.
208 * The EnableMask field of the involved GPE register must be
209 * updated by the caller if necessary.
211 ******************************************************************************/
213 ACPI_STATUS
214 AcpiHwLowSetGpe (
215 ACPI_GPE_EVENT_INFO *GpeEventInfo,
216 UINT32 Action)
218 ACPI_GPE_REGISTER_INFO *GpeRegisterInfo;
219 ACPI_STATUS Status = AE_OK;
220 UINT64 EnableMask;
221 UINT32 RegisterBit;
224 ACPI_FUNCTION_ENTRY ();
227 /* Get the info block for the entire GPE register */
229 GpeRegisterInfo = GpeEventInfo->RegisterInfo;
230 if (!GpeRegisterInfo)
232 return (AE_NOT_EXIST);
235 /* Get current value of the enable register that contains this GPE */
237 Status = AcpiHwRead (&EnableMask, &GpeRegisterInfo->EnableAddress);
238 if (ACPI_FAILURE (Status))
240 return (Status);
243 /* Set or clear just the bit that corresponds to this GPE */
245 RegisterBit = AcpiHwGetGpeRegisterBit (GpeEventInfo);
246 switch (Action)
248 case ACPI_GPE_CONDITIONAL_ENABLE:
250 /* Only enable if the corresponding EnableMask bit is set */
252 if (!(RegisterBit & GpeRegisterInfo->EnableMask))
254 return (AE_BAD_PARAMETER);
257 /*lint -fallthrough */
259 case ACPI_GPE_ENABLE:
261 ACPI_SET_BIT (EnableMask, RegisterBit);
262 break;
264 case ACPI_GPE_DISABLE:
266 ACPI_CLEAR_BIT (EnableMask, RegisterBit);
267 break;
269 default:
271 ACPI_ERROR ((AE_INFO, "Invalid GPE Action, %u", Action));
272 return (AE_BAD_PARAMETER);
275 if (!(RegisterBit & GpeRegisterInfo->MaskForRun))
277 /* Write the updated enable mask */
279 Status = AcpiHwWrite (EnableMask, &GpeRegisterInfo->EnableAddress);
281 return (Status);
285 /******************************************************************************
287 * FUNCTION: AcpiHwClearGpe
289 * PARAMETERS: GpeEventInfo - Info block for the GPE to be cleared
291 * RETURN: Status
293 * DESCRIPTION: Clear the status bit for a single GPE.
295 ******************************************************************************/
297 ACPI_STATUS
298 AcpiHwClearGpe (
299 ACPI_GPE_EVENT_INFO *GpeEventInfo)
301 ACPI_GPE_REGISTER_INFO *GpeRegisterInfo;
302 ACPI_STATUS Status;
303 UINT32 RegisterBit;
306 ACPI_FUNCTION_ENTRY ();
308 /* Get the info block for the entire GPE register */
310 GpeRegisterInfo = GpeEventInfo->RegisterInfo;
311 if (!GpeRegisterInfo)
313 return (AE_NOT_EXIST);
317 * Write a one to the appropriate bit in the status register to
318 * clear this GPE.
320 RegisterBit = AcpiHwGetGpeRegisterBit (GpeEventInfo);
322 Status = AcpiHwWrite (RegisterBit, &GpeRegisterInfo->StatusAddress);
323 return (Status);
327 /******************************************************************************
329 * FUNCTION: AcpiHwGetGpeStatus
331 * PARAMETERS: GpeEventInfo - Info block for the GPE to queried
332 * EventStatus - Where the GPE status is returned
334 * RETURN: Status
336 * DESCRIPTION: Return the status of a single GPE.
338 ******************************************************************************/
340 ACPI_STATUS
341 AcpiHwGetGpeStatus (
342 ACPI_GPE_EVENT_INFO *GpeEventInfo,
343 ACPI_EVENT_STATUS *EventStatus)
345 UINT64 InByte;
346 UINT32 RegisterBit;
347 ACPI_GPE_REGISTER_INFO *GpeRegisterInfo;
348 ACPI_EVENT_STATUS LocalEventStatus = 0;
349 ACPI_STATUS Status;
352 ACPI_FUNCTION_ENTRY ();
355 if (!EventStatus)
357 return (AE_BAD_PARAMETER);
360 /* GPE currently handled? */
362 if (ACPI_GPE_DISPATCH_TYPE (GpeEventInfo->Flags) !=
363 ACPI_GPE_DISPATCH_NONE)
365 LocalEventStatus |= ACPI_EVENT_FLAG_HAS_HANDLER;
368 /* Get the info block for the entire GPE register */
370 GpeRegisterInfo = GpeEventInfo->RegisterInfo;
372 /* Get the register bitmask for this GPE */
374 RegisterBit = AcpiHwGetGpeRegisterBit (GpeEventInfo);
376 /* GPE currently enabled? (enabled for runtime?) */
378 if (RegisterBit & GpeRegisterInfo->EnableForRun)
380 LocalEventStatus |= ACPI_EVENT_FLAG_ENABLED;
383 /* GPE currently masked? (masked for runtime?) */
385 if (RegisterBit & GpeRegisterInfo->MaskForRun)
387 LocalEventStatus |= ACPI_EVENT_FLAG_MASKED;
390 /* GPE enabled for wake? */
392 if (RegisterBit & GpeRegisterInfo->EnableForWake)
394 LocalEventStatus |= ACPI_EVENT_FLAG_WAKE_ENABLED;
397 /* GPE currently enabled (enable bit == 1)? */
399 Status = AcpiHwRead (&InByte, &GpeRegisterInfo->EnableAddress);
400 if (ACPI_FAILURE (Status))
402 return (Status);
405 if (RegisterBit & InByte)
407 LocalEventStatus |= ACPI_EVENT_FLAG_ENABLE_SET;
410 /* GPE currently active (status bit == 1)? */
412 Status = AcpiHwRead (&InByte, &GpeRegisterInfo->StatusAddress);
413 if (ACPI_FAILURE (Status))
415 return (Status);
418 if (RegisterBit & InByte)
420 LocalEventStatus |= ACPI_EVENT_FLAG_STATUS_SET;
423 /* Set return value */
425 (*EventStatus) = LocalEventStatus;
426 return (AE_OK);
430 /******************************************************************************
432 * FUNCTION: AcpiHwGpeEnableWrite
434 * PARAMETERS: EnableMask - Bit mask to write to the GPE register
435 * GpeRegisterInfo - Gpe Register info
437 * RETURN: Status
439 * DESCRIPTION: Write the enable mask byte to the given GPE register.
441 ******************************************************************************/
443 static ACPI_STATUS
444 AcpiHwGpeEnableWrite (
445 UINT8 EnableMask,
446 ACPI_GPE_REGISTER_INFO *GpeRegisterInfo)
448 ACPI_STATUS Status;
451 GpeRegisterInfo->EnableMask = EnableMask;
453 Status = AcpiHwWrite (EnableMask, &GpeRegisterInfo->EnableAddress);
454 return (Status);
458 /******************************************************************************
460 * FUNCTION: AcpiHwDisableGpeBlock
462 * PARAMETERS: GpeXruptInfo - GPE Interrupt info
463 * GpeBlock - Gpe Block info
465 * RETURN: Status
467 * DESCRIPTION: Disable all GPEs within a single GPE block
469 ******************************************************************************/
471 ACPI_STATUS
472 AcpiHwDisableGpeBlock (
473 ACPI_GPE_XRUPT_INFO *GpeXruptInfo,
474 ACPI_GPE_BLOCK_INFO *GpeBlock,
475 void *Context)
477 UINT32 i;
478 ACPI_STATUS Status;
481 /* Examine each GPE Register within the block */
483 for (i = 0; i < GpeBlock->RegisterCount; i++)
485 /* Disable all GPEs in this register */
487 Status = AcpiHwGpeEnableWrite (0x00, &GpeBlock->RegisterInfo[i]);
488 if (ACPI_FAILURE (Status))
490 return (Status);
494 return (AE_OK);
498 /******************************************************************************
500 * FUNCTION: AcpiHwClearGpeBlock
502 * PARAMETERS: GpeXruptInfo - GPE Interrupt info
503 * GpeBlock - Gpe Block info
505 * RETURN: Status
507 * DESCRIPTION: Clear status bits for all GPEs within a single GPE block
509 ******************************************************************************/
511 ACPI_STATUS
512 AcpiHwClearGpeBlock (
513 ACPI_GPE_XRUPT_INFO *GpeXruptInfo,
514 ACPI_GPE_BLOCK_INFO *GpeBlock,
515 void *Context)
517 UINT32 i;
518 ACPI_STATUS Status;
521 /* Examine each GPE Register within the block */
523 for (i = 0; i < GpeBlock->RegisterCount; i++)
525 /* Clear status on all GPEs in this register */
527 Status = AcpiHwWrite (0xFF, &GpeBlock->RegisterInfo[i].StatusAddress);
528 if (ACPI_FAILURE (Status))
530 return (Status);
534 return (AE_OK);
538 /******************************************************************************
540 * FUNCTION: AcpiHwEnableRuntimeGpeBlock
542 * PARAMETERS: GpeXruptInfo - GPE Interrupt info
543 * GpeBlock - Gpe Block info
545 * RETURN: Status
547 * DESCRIPTION: Enable all "runtime" GPEs within a single GPE block. Includes
548 * combination wake/run GPEs.
550 ******************************************************************************/
552 ACPI_STATUS
553 AcpiHwEnableRuntimeGpeBlock (
554 ACPI_GPE_XRUPT_INFO *GpeXruptInfo,
555 ACPI_GPE_BLOCK_INFO *GpeBlock,
556 void *Context)
558 UINT32 i;
559 ACPI_STATUS Status;
560 ACPI_GPE_REGISTER_INFO *GpeRegisterInfo;
561 UINT8 EnableMask;
564 /* NOTE: assumes that all GPEs are currently disabled */
566 /* Examine each GPE Register within the block */
568 for (i = 0; i < GpeBlock->RegisterCount; i++)
570 GpeRegisterInfo = &GpeBlock->RegisterInfo[i];
571 if (!GpeRegisterInfo->EnableForRun)
573 continue;
576 /* Enable all "runtime" GPEs in this register */
578 EnableMask = GpeRegisterInfo->EnableForRun &
579 ~GpeRegisterInfo->MaskForRun;
580 Status = AcpiHwGpeEnableWrite (EnableMask, GpeRegisterInfo);
581 if (ACPI_FAILURE (Status))
583 return (Status);
587 return (AE_OK);
591 /******************************************************************************
593 * FUNCTION: AcpiHwEnableWakeupGpeBlock
595 * PARAMETERS: GpeXruptInfo - GPE Interrupt info
596 * GpeBlock - Gpe Block info
598 * RETURN: Status
600 * DESCRIPTION: Enable all "wake" GPEs within a single GPE block. Includes
601 * combination wake/run GPEs.
603 ******************************************************************************/
605 static ACPI_STATUS
606 AcpiHwEnableWakeupGpeBlock (
607 ACPI_GPE_XRUPT_INFO *GpeXruptInfo,
608 ACPI_GPE_BLOCK_INFO *GpeBlock,
609 void *Context)
611 UINT32 i;
612 ACPI_STATUS Status;
613 ACPI_GPE_REGISTER_INFO *GpeRegisterInfo;
616 /* Examine each GPE Register within the block */
618 for (i = 0; i < GpeBlock->RegisterCount; i++)
620 GpeRegisterInfo = &GpeBlock->RegisterInfo[i];
623 * Enable all "wake" GPEs in this register and disable the
624 * remaining ones.
626 Status = AcpiHwGpeEnableWrite (GpeRegisterInfo->EnableForWake,
627 GpeRegisterInfo);
628 if (ACPI_FAILURE (Status))
630 return (Status);
634 return (AE_OK);
638 /******************************************************************************
640 * FUNCTION: AcpiHwDisableAllGpes
642 * PARAMETERS: None
644 * RETURN: Status
646 * DESCRIPTION: Disable and clear all GPEs in all GPE blocks
648 ******************************************************************************/
650 ACPI_STATUS
651 AcpiHwDisableAllGpes (
652 void)
654 ACPI_STATUS Status;
657 ACPI_FUNCTION_TRACE (HwDisableAllGpes);
660 Status = AcpiEvWalkGpeList (AcpiHwDisableGpeBlock, NULL);
661 Status = AcpiEvWalkGpeList (AcpiHwClearGpeBlock, NULL);
662 return_ACPI_STATUS (Status);
666 /******************************************************************************
668 * FUNCTION: AcpiHwEnableAllRuntimeGpes
670 * PARAMETERS: None
672 * RETURN: Status
674 * DESCRIPTION: Enable all "runtime" GPEs, in all GPE blocks
676 ******************************************************************************/
678 ACPI_STATUS
679 AcpiHwEnableAllRuntimeGpes (
680 void)
682 ACPI_STATUS Status;
685 ACPI_FUNCTION_TRACE (HwEnableAllRuntimeGpes);
688 Status = AcpiEvWalkGpeList (AcpiHwEnableRuntimeGpeBlock, NULL);
689 return_ACPI_STATUS (Status);
693 /******************************************************************************
695 * FUNCTION: AcpiHwEnableAllWakeupGpes
697 * PARAMETERS: None
699 * RETURN: Status
701 * DESCRIPTION: Enable all "wakeup" GPEs, in all GPE blocks
703 ******************************************************************************/
705 ACPI_STATUS
706 AcpiHwEnableAllWakeupGpes (
707 void)
709 ACPI_STATUS Status;
712 ACPI_FUNCTION_TRACE (HwEnableAllWakeupGpes);
715 Status = AcpiEvWalkGpeList (AcpiHwEnableWakeupGpeBlock, NULL);
716 return_ACPI_STATUS (Status);
719 #endif /* !ACPI_REDUCED_HARDWARE */