xref: /freebsd/sys/contrib/dev/acpica/components/hardware/hwgpe.c (revision 62cfcf62f627e5093fb37026a6d8c98e4d2ef04c)
1 /******************************************************************************
2  *
3  * Module Name: hwgpe - Low level GPE enable/disable/clear functions
4  *
5  *****************************************************************************/
6 
7 /******************************************************************************
8  *
9  * 1. Copyright Notice
10  *
11  * Some or all of this work - Copyright (c) 1999 - 2020, Intel Corp.
12  * All rights reserved.
13  *
14  * 2. License
15  *
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.
20  *
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
27  *
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;
36  *
37  * The above copyright and patent license is granted only if the following
38  * conditions are met:
39  *
40  * 3. Conditions
41  *
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.
53  *
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.
65  *
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.
71  *
72  * 3.4. Intel retains all right, title, and interest in and to the Original
73  * Intel Code.
74  *
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.
79  *
80  * 4. Disclaimer and Export Compliance
81  *
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.
89  *
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.
98  *
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.
113  *
114  *****************************************************************************
115  *
116  * Alternatively, you may choose to be licensed under the terms of the
117  * following license:
118  *
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.
133  *
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.
145  *
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.
149  *
150  *****************************************************************************/
151 
152 #include <contrib/dev/acpica/include/acpi.h>
153 #include <contrib/dev/acpica/include/accommon.h>
154 #include <contrib/dev/acpica/include/acevents.h>
155 
156 #define _COMPONENT          ACPI_HARDWARE
157         ACPI_MODULE_NAME    ("hwgpe")
158 
159 #if (!ACPI_REDUCED_HARDWARE) /* Entire module */
160 
161 /* Local prototypes */
162 
163 static ACPI_STATUS
164 AcpiHwEnableWakeupGpeBlock (
165     ACPI_GPE_XRUPT_INFO     *GpeXruptInfo,
166     ACPI_GPE_BLOCK_INFO     *GpeBlock,
167     void                    *Context);
168 
169 static ACPI_STATUS
170 AcpiHwGpeEnableWrite (
171     UINT8                   EnableMask,
172     ACPI_GPE_REGISTER_INFO  *GpeRegisterInfo);
173 
174 
175 /******************************************************************************
176  *
177  * FUNCTION:    AcpiHwGetGpeRegisterBit
178  *
179  * PARAMETERS:  GpeEventInfo        - Info block for the GPE
180  *
181  * RETURN:      Register mask with a one in the GPE bit position
182  *
183  * DESCRIPTION: Compute the register mask for this GPE. One bit is set in the
184  *              correct position for the input GPE.
185  *
186  ******************************************************************************/
187 
188 UINT32
189 AcpiHwGetGpeRegisterBit (
190     ACPI_GPE_EVENT_INFO     *GpeEventInfo)
191 {
192 
193     return ((UINT32) 1 <<
194         (GpeEventInfo->GpeNumber - GpeEventInfo->RegisterInfo->BaseGpeNumber));
195 }
196 
197 
198 /******************************************************************************
199  *
200  * FUNCTION:    AcpiHwLowSetGpe
201  *
202  * PARAMETERS:  GpeEventInfo        - Info block for the GPE to be disabled
203  *              Action              - Enable or disable
204  *
205  * RETURN:      Status
206  *
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.
210  *
211  ******************************************************************************/
212 
213 ACPI_STATUS
214 AcpiHwLowSetGpe (
215     ACPI_GPE_EVENT_INFO     *GpeEventInfo,
216     UINT32                  Action)
217 {
218     ACPI_GPE_REGISTER_INFO  *GpeRegisterInfo;
219     ACPI_STATUS             Status = AE_OK;
220     UINT64                  EnableMask;
221     UINT32                  RegisterBit;
222 
223 
224     ACPI_FUNCTION_ENTRY ();
225 
226 
227     /* Get the info block for the entire GPE register */
228 
229     GpeRegisterInfo = GpeEventInfo->RegisterInfo;
230     if (!GpeRegisterInfo)
231     {
232         return (AE_NOT_EXIST);
233     }
234 
235     /* Get current value of the enable register that contains this GPE */
236 
237     Status = AcpiHwRead (&EnableMask, &GpeRegisterInfo->EnableAddress);
238     if (ACPI_FAILURE (Status))
239     {
240         return (Status);
241     }
242 
243     /* Set or clear just the bit that corresponds to this GPE */
244 
245     RegisterBit = AcpiHwGetGpeRegisterBit (GpeEventInfo);
246     switch (Action)
247     {
248     case ACPI_GPE_CONDITIONAL_ENABLE:
249 
250         /* Only enable if the corresponding EnableMask bit is set */
251 
252         if (!(RegisterBit & GpeRegisterInfo->EnableMask))
253         {
254             return (AE_BAD_PARAMETER);
255         }
256 
257         /*lint -fallthrough */
258 
259     case ACPI_GPE_ENABLE:
260 
261         ACPI_SET_BIT (EnableMask, RegisterBit);
262         break;
263 
264     case ACPI_GPE_DISABLE:
265 
266         ACPI_CLEAR_BIT (EnableMask, RegisterBit);
267         break;
268 
269     default:
270 
271         ACPI_ERROR ((AE_INFO, "Invalid GPE Action, %u", Action));
272         return (AE_BAD_PARAMETER);
273     }
274 
275     if (!(RegisterBit & GpeRegisterInfo->MaskForRun))
276     {
277         /* Write the updated enable mask */
278 
279         Status = AcpiHwWrite (EnableMask, &GpeRegisterInfo->EnableAddress);
280     }
281     return (Status);
282 }
283 
284 
285 /******************************************************************************
286  *
287  * FUNCTION:    AcpiHwClearGpe
288  *
289  * PARAMETERS:  GpeEventInfo        - Info block for the GPE to be cleared
290  *
291  * RETURN:      Status
292  *
293  * DESCRIPTION: Clear the status bit for a single GPE.
294  *
295  ******************************************************************************/
296 
297 ACPI_STATUS
298 AcpiHwClearGpe (
299     ACPI_GPE_EVENT_INFO     *GpeEventInfo)
300 {
301     ACPI_GPE_REGISTER_INFO  *GpeRegisterInfo;
302     ACPI_STATUS             Status;
303     UINT32                  RegisterBit;
304 
305 
306     ACPI_FUNCTION_ENTRY ();
307 
308     /* Get the info block for the entire GPE register */
309 
310     GpeRegisterInfo = GpeEventInfo->RegisterInfo;
311     if (!GpeRegisterInfo)
312     {
313         return (AE_NOT_EXIST);
314     }
315 
316     /*
317      * Write a one to the appropriate bit in the status register to
318      * clear this GPE.
319      */
320     RegisterBit = AcpiHwGetGpeRegisterBit (GpeEventInfo);
321 
322     Status = AcpiHwWrite (RegisterBit, &GpeRegisterInfo->StatusAddress);
323     return (Status);
324 }
325 
326 
327 /******************************************************************************
328  *
329  * FUNCTION:    AcpiHwGetGpeStatus
330  *
331  * PARAMETERS:  GpeEventInfo        - Info block for the GPE to queried
332  *              EventStatus         - Where the GPE status is returned
333  *
334  * RETURN:      Status
335  *
336  * DESCRIPTION: Return the status of a single GPE.
337  *
338  ******************************************************************************/
339 
340 ACPI_STATUS
341 AcpiHwGetGpeStatus (
342     ACPI_GPE_EVENT_INFO     *GpeEventInfo,
343     ACPI_EVENT_STATUS       *EventStatus)
344 {
345     UINT64                  InByte;
346     UINT32                  RegisterBit;
347     ACPI_GPE_REGISTER_INFO  *GpeRegisterInfo;
348     ACPI_EVENT_STATUS       LocalEventStatus = 0;
349     ACPI_STATUS             Status;
350 
351 
352     ACPI_FUNCTION_ENTRY ();
353 
354 
355     if (!EventStatus)
356     {
357         return (AE_BAD_PARAMETER);
358     }
359 
360     /* GPE currently handled? */
361 
362     if (ACPI_GPE_DISPATCH_TYPE (GpeEventInfo->Flags) !=
363         ACPI_GPE_DISPATCH_NONE)
364     {
365         LocalEventStatus |= ACPI_EVENT_FLAG_HAS_HANDLER;
366     }
367 
368     /* Get the info block for the entire GPE register */
369 
370     GpeRegisterInfo = GpeEventInfo->RegisterInfo;
371 
372     /* Get the register bitmask for this GPE */
373 
374     RegisterBit = AcpiHwGetGpeRegisterBit (GpeEventInfo);
375 
376     /* GPE currently enabled? (enabled for runtime?) */
377 
378     if (RegisterBit & GpeRegisterInfo->EnableForRun)
379     {
380         LocalEventStatus |= ACPI_EVENT_FLAG_ENABLED;
381     }
382 
383     /* GPE currently masked? (masked for runtime?) */
384 
385     if (RegisterBit & GpeRegisterInfo->MaskForRun)
386     {
387         LocalEventStatus |= ACPI_EVENT_FLAG_MASKED;
388     }
389 
390     /* GPE enabled for wake? */
391 
392     if (RegisterBit & GpeRegisterInfo->EnableForWake)
393     {
394         LocalEventStatus |= ACPI_EVENT_FLAG_WAKE_ENABLED;
395     }
396 
397     /* GPE currently enabled (enable bit == 1)? */
398 
399     Status = AcpiHwRead (&InByte, &GpeRegisterInfo->EnableAddress);
400     if (ACPI_FAILURE (Status))
401     {
402         return (Status);
403     }
404 
405     if (RegisterBit & InByte)
406     {
407         LocalEventStatus |= ACPI_EVENT_FLAG_ENABLE_SET;
408     }
409 
410     /* GPE currently active (status bit == 1)? */
411 
412     Status = AcpiHwRead (&InByte, &GpeRegisterInfo->StatusAddress);
413     if (ACPI_FAILURE (Status))
414     {
415         return (Status);
416     }
417 
418     if (RegisterBit & InByte)
419     {
420         LocalEventStatus |= ACPI_EVENT_FLAG_STATUS_SET;
421     }
422 
423     /* Set return value */
424 
425     (*EventStatus) = LocalEventStatus;
426     return (AE_OK);
427 }
428 
429 
430 /******************************************************************************
431  *
432  * FUNCTION:    AcpiHwGpeEnableWrite
433  *
434  * PARAMETERS:  EnableMask          - Bit mask to write to the GPE register
435  *              GpeRegisterInfo     - Gpe Register info
436  *
437  * RETURN:      Status
438  *
439  * DESCRIPTION: Write the enable mask byte to the given GPE register.
440  *
441  ******************************************************************************/
442 
443 static ACPI_STATUS
444 AcpiHwGpeEnableWrite (
445     UINT8                   EnableMask,
446     ACPI_GPE_REGISTER_INFO  *GpeRegisterInfo)
447 {
448     ACPI_STATUS             Status;
449 
450 
451     GpeRegisterInfo->EnableMask = EnableMask;
452 
453     Status = AcpiHwWrite (EnableMask, &GpeRegisterInfo->EnableAddress);
454     return (Status);
455 }
456 
457 
458 /******************************************************************************
459  *
460  * FUNCTION:    AcpiHwDisableGpeBlock
461  *
462  * PARAMETERS:  GpeXruptInfo        - GPE Interrupt info
463  *              GpeBlock            - Gpe Block info
464  *
465  * RETURN:      Status
466  *
467  * DESCRIPTION: Disable all GPEs within a single GPE block
468  *
469  ******************************************************************************/
470 
471 ACPI_STATUS
472 AcpiHwDisableGpeBlock (
473     ACPI_GPE_XRUPT_INFO     *GpeXruptInfo,
474     ACPI_GPE_BLOCK_INFO     *GpeBlock,
475     void                    *Context)
476 {
477     UINT32                  i;
478     ACPI_STATUS             Status;
479 
480 
481     /* Examine each GPE Register within the block */
482 
483     for (i = 0; i < GpeBlock->RegisterCount; i++)
484     {
485         /* Disable all GPEs in this register */
486 
487         Status = AcpiHwGpeEnableWrite (0x00, &GpeBlock->RegisterInfo[i]);
488         if (ACPI_FAILURE (Status))
489         {
490             return (Status);
491         }
492     }
493 
494     return (AE_OK);
495 }
496 
497 
498 /******************************************************************************
499  *
500  * FUNCTION:    AcpiHwClearGpeBlock
501  *
502  * PARAMETERS:  GpeXruptInfo        - GPE Interrupt info
503  *              GpeBlock            - Gpe Block info
504  *
505  * RETURN:      Status
506  *
507  * DESCRIPTION: Clear status bits for all GPEs within a single GPE block
508  *
509  ******************************************************************************/
510 
511 ACPI_STATUS
512 AcpiHwClearGpeBlock (
513     ACPI_GPE_XRUPT_INFO     *GpeXruptInfo,
514     ACPI_GPE_BLOCK_INFO     *GpeBlock,
515     void                    *Context)
516 {
517     UINT32                  i;
518     ACPI_STATUS             Status;
519 
520 
521     /* Examine each GPE Register within the block */
522 
523     for (i = 0; i < GpeBlock->RegisterCount; i++)
524     {
525         /* Clear status on all GPEs in this register */
526 
527         Status = AcpiHwWrite (0xFF, &GpeBlock->RegisterInfo[i].StatusAddress);
528         if (ACPI_FAILURE (Status))
529         {
530             return (Status);
531         }
532     }
533 
534     return (AE_OK);
535 }
536 
537 
538 /******************************************************************************
539  *
540  * FUNCTION:    AcpiHwEnableRuntimeGpeBlock
541  *
542  * PARAMETERS:  GpeXruptInfo        - GPE Interrupt info
543  *              GpeBlock            - Gpe Block info
544  *
545  * RETURN:      Status
546  *
547  * DESCRIPTION: Enable all "runtime" GPEs within a single GPE block. Includes
548  *              combination wake/run GPEs.
549  *
550  ******************************************************************************/
551 
552 ACPI_STATUS
553 AcpiHwEnableRuntimeGpeBlock (
554     ACPI_GPE_XRUPT_INFO     *GpeXruptInfo,
555     ACPI_GPE_BLOCK_INFO     *GpeBlock,
556     void                    *Context)
557 {
558     UINT32                  i;
559     ACPI_STATUS             Status;
560     ACPI_GPE_REGISTER_INFO  *GpeRegisterInfo;
561     UINT8                   EnableMask;
562 
563 
564     /* NOTE: assumes that all GPEs are currently disabled */
565 
566     /* Examine each GPE Register within the block */
567 
568     for (i = 0; i < GpeBlock->RegisterCount; i++)
569     {
570         GpeRegisterInfo = &GpeBlock->RegisterInfo[i];
571         if (!GpeRegisterInfo->EnableForRun)
572         {
573             continue;
574         }
575 
576         /* Enable all "runtime" GPEs in this register */
577 
578         EnableMask = GpeRegisterInfo->EnableForRun &
579             ~GpeRegisterInfo->MaskForRun;
580         Status = AcpiHwGpeEnableWrite (EnableMask, GpeRegisterInfo);
581         if (ACPI_FAILURE (Status))
582         {
583             return (Status);
584         }
585     }
586 
587     return (AE_OK);
588 }
589 
590 
591 /******************************************************************************
592  *
593  * FUNCTION:    AcpiHwEnableWakeupGpeBlock
594  *
595  * PARAMETERS:  GpeXruptInfo        - GPE Interrupt info
596  *              GpeBlock            - Gpe Block info
597  *
598  * RETURN:      Status
599  *
600  * DESCRIPTION: Enable all "wake" GPEs within a single GPE block. Includes
601  *              combination wake/run GPEs.
602  *
603  ******************************************************************************/
604 
605 static ACPI_STATUS
606 AcpiHwEnableWakeupGpeBlock (
607     ACPI_GPE_XRUPT_INFO     *GpeXruptInfo,
608     ACPI_GPE_BLOCK_INFO     *GpeBlock,
609     void                    *Context)
610 {
611     UINT32                  i;
612     ACPI_STATUS             Status;
613     ACPI_GPE_REGISTER_INFO  *GpeRegisterInfo;
614 
615 
616     /* Examine each GPE Register within the block */
617 
618     for (i = 0; i < GpeBlock->RegisterCount; i++)
619     {
620         GpeRegisterInfo = &GpeBlock->RegisterInfo[i];
621 
622         /*
623          * Enable all "wake" GPEs in this register and disable the
624          * remaining ones.
625          */
626         Status = AcpiHwGpeEnableWrite (GpeRegisterInfo->EnableForWake,
627             GpeRegisterInfo);
628         if (ACPI_FAILURE (Status))
629         {
630             return (Status);
631         }
632     }
633 
634     return (AE_OK);
635 }
636 
637 
638 /******************************************************************************
639  *
640  * FUNCTION:    AcpiHwGetGpeBlockStatus
641  *
642  * PARAMETERS:  GpeXruptInfo    - GPE Interrupt info
643  *              GpeBlock        - Gpe Block info
644  *
645  * RETURN:      Success
646  *
647  * DESCRIPTION: Produce a combined GPE status bits mask for the given block.
648  *
649  ******************************************************************************/
650 
651 static ACPI_STATUS
652 AcpiHwGetGpeBlockStatus(
653     ACPI_GPE_XRUPT_INFO     *GpeXruptInfo,
654     ACPI_GPE_BLOCK_INFO     *GpeBlock,
655     void *RetPtr)
656 {
657     ACPI_GPE_REGISTER_INFO  *GpeRegisterInfo;
658     UINT64                  InEnable;
659     UINT64                  InStatus;
660     ACPI_STATUS             Status;
661     UINT8                   *Ret = RetPtr;
662     UINT32                  i;
663 
664 
665     /* Examine each GPE Register within the block */
666 
667     for (i = 0; i < GpeBlock->RegisterCount; i++)
668     {
669         GpeRegisterInfo = &GpeBlock->RegisterInfo[i];
670 
671         Status = AcpiHwRead (&InEnable, &GpeRegisterInfo->EnableAddress);
672         if (ACPI_FAILURE (Status))
673         {
674             continue;
675         }
676 
677         Status = AcpiHwRead (&InStatus, &GpeRegisterInfo->StatusAddress);
678         if (ACPI_FAILURE (Status))
679         {
680             continue;
681         }
682 
683         *Ret |= InEnable & InStatus;
684     }
685 
686     return (AE_OK);
687 }
688 
689 
690 /******************************************************************************
691  *
692  * FUNCTION:    AcpiHwDisableAllGpes
693  *
694  * PARAMETERS:  None
695  *
696  * RETURN:      Status
697  *
698  * DESCRIPTION: Disable and clear all GPEs in all GPE blocks
699  *
700  ******************************************************************************/
701 
702 ACPI_STATUS
703 AcpiHwDisableAllGpes (
704     void)
705 {
706     ACPI_STATUS             Status;
707 
708 
709     ACPI_FUNCTION_TRACE (HwDisableAllGpes);
710 
711 
712     Status = AcpiEvWalkGpeList (AcpiHwDisableGpeBlock, NULL);
713     return_ACPI_STATUS (Status);
714 }
715 
716 
717 /******************************************************************************
718  *
719  * FUNCTION:    AcpiHwEnableAllRuntimeGpes
720  *
721  * PARAMETERS:  None
722  *
723  * RETURN:      Status
724  *
725  * DESCRIPTION: Enable all "runtime" GPEs, in all GPE blocks
726  *
727  ******************************************************************************/
728 
729 ACPI_STATUS
730 AcpiHwEnableAllRuntimeGpes (
731     void)
732 {
733     ACPI_STATUS             Status;
734 
735 
736     ACPI_FUNCTION_TRACE (HwEnableAllRuntimeGpes);
737 
738 
739     Status = AcpiEvWalkGpeList (AcpiHwEnableRuntimeGpeBlock, NULL);
740     return_ACPI_STATUS (Status);
741 }
742 
743 
744 /******************************************************************************
745  *
746  * FUNCTION:    AcpiHwEnableAllWakeupGpes
747  *
748  * PARAMETERS:  None
749  *
750  * RETURN:      Status
751  *
752  * DESCRIPTION: Enable all "wakeup" GPEs, in all GPE blocks
753  *
754  ******************************************************************************/
755 
756 ACPI_STATUS
757 AcpiHwEnableAllWakeupGpes (
758     void)
759 {
760     ACPI_STATUS             Status;
761 
762 
763     ACPI_FUNCTION_TRACE (HwEnableAllWakeupGpes);
764 
765 
766     Status = AcpiEvWalkGpeList (AcpiHwEnableWakeupGpeBlock, NULL);
767     return_ACPI_STATUS (Status);
768 }
769 
770 
771 /******************************************************************************
772  *
773  * FUNCTION:    AcpiHwCheckAllGpes
774  *
775  * PARAMETERS:  None
776  *
777  * RETURN:      Combined status of all GPEs
778  *
779  * DESCRIPTION: Check all enabled GPEs in all GPE blocks and return TRUE if the
780  *              status bit is set for at least one of them of FALSE otherwise.
781  *
782  ******************************************************************************/
783 
784 UINT8
785 AcpiHwCheckAllGpes (
786     void)
787 {
788     UINT8                      Ret = 0;
789 
790 
791     ACPI_FUNCTION_TRACE (AcpiHwCheckAllGpes);
792 
793     (void) AcpiEvWalkGpeList (AcpiHwGetGpeBlockStatus, &Ret);
794     return (Ret != 0);
795 }
796 
797 #endif /* !ACPI_REDUCED_HARDWARE */
798