xref: /titanic_44/usr/src/uts/intel/io/acpica/events/evxfevnt.c (revision 1e4c938b57d1656808e4112127ff1dce3eba5314)
1 /******************************************************************************
2  *
3  * Module Name: evxfevnt - External Interfaces, ACPI event disable/enable
4  *
5  *****************************************************************************/
6 
7 /******************************************************************************
8  *
9  * 1. Copyright Notice
10  *
11  * Some or all of this work - Copyright (c) 1999 - 2009, 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 
117 #define __EVXFEVNT_C__
118 
119 #include "acpi.h"
120 #include "accommon.h"
121 #include "acevents.h"
122 #include "acnamesp.h"
123 #include "actables.h"
124 
125 #define _COMPONENT          ACPI_EVENTS
126         ACPI_MODULE_NAME    ("evxfevnt")
127 
128 /* Local prototypes */
129 
130 static ACPI_STATUS
131 AcpiEvGetGpeDevice (
132     ACPI_GPE_XRUPT_INFO     *GpeXruptInfo,
133     ACPI_GPE_BLOCK_INFO     *GpeBlock,
134     void                    *Context);
135 
136 
137 /*******************************************************************************
138  *
139  * FUNCTION:    AcpiEnable
140  *
141  * PARAMETERS:  None
142  *
143  * RETURN:      Status
144  *
145  * DESCRIPTION: Transfers the system into ACPI mode.
146  *
147  ******************************************************************************/
148 
149 ACPI_STATUS
150 AcpiEnable (
151     void)
152 {
153     ACPI_STATUS             Status = AE_OK;
154 
155 
156     ACPI_FUNCTION_TRACE (AcpiEnable);
157 
158 
159     /* ACPI tables must be present */
160 
161     if (!AcpiTbTablesLoaded ())
162     {
163         return_ACPI_STATUS (AE_NO_ACPI_TABLES);
164     }
165 
166     /* Check current mode */
167 
168     if (AcpiHwGetMode() == ACPI_SYS_MODE_ACPI)
169     {
170         ACPI_DEBUG_PRINT ((ACPI_DB_INIT, "System is already in ACPI mode\n"));
171     }
172     else
173     {
174         /* Transition to ACPI mode */
175 
176         Status = AcpiHwSetMode (ACPI_SYS_MODE_ACPI);
177         if (ACPI_FAILURE (Status))
178         {
179             ACPI_ERROR ((AE_INFO, "Could not transition to ACPI mode"));
180             return_ACPI_STATUS (Status);
181         }
182 
183         ACPI_DEBUG_PRINT ((ACPI_DB_INIT,
184             "Transition to ACPI mode successful\n"));
185     }
186 
187     return_ACPI_STATUS (Status);
188 }
189 
190 ACPI_EXPORT_SYMBOL (AcpiEnable)
191 
192 
193 /*******************************************************************************
194  *
195  * FUNCTION:    AcpiDisable
196  *
197  * PARAMETERS:  None
198  *
199  * RETURN:      Status
200  *
201  * DESCRIPTION: Transfers the system into LEGACY (non-ACPI) mode.
202  *
203  ******************************************************************************/
204 
205 ACPI_STATUS
206 AcpiDisable (
207     void)
208 {
209     ACPI_STATUS             Status = AE_OK;
210 
211 
212     ACPI_FUNCTION_TRACE (AcpiDisable);
213 
214 
215     if (AcpiHwGetMode() == ACPI_SYS_MODE_LEGACY)
216     {
217         ACPI_DEBUG_PRINT ((ACPI_DB_INIT,
218             "System is already in legacy (non-ACPI) mode\n"));
219     }
220     else
221     {
222         /* Transition to LEGACY mode */
223 
224         Status = AcpiHwSetMode (ACPI_SYS_MODE_LEGACY);
225 
226         if (ACPI_FAILURE (Status))
227         {
228             ACPI_ERROR ((AE_INFO,
229                 "Could not exit ACPI mode to legacy mode"));
230             return_ACPI_STATUS (Status);
231         }
232 
233         ACPI_DEBUG_PRINT ((ACPI_DB_INIT, "ACPI mode disabled\n"));
234     }
235 
236     return_ACPI_STATUS (Status);
237 }
238 
239 ACPI_EXPORT_SYMBOL (AcpiDisable)
240 
241 
242 /*******************************************************************************
243  *
244  * FUNCTION:    AcpiEnableEvent
245  *
246  * PARAMETERS:  Event           - The fixed eventto be enabled
247  *              Flags           - Reserved
248  *
249  * RETURN:      Status
250  *
251  * DESCRIPTION: Enable an ACPI event (fixed)
252  *
253  ******************************************************************************/
254 
255 ACPI_STATUS
256 AcpiEnableEvent (
257     UINT32                  Event,
258     UINT32                  Flags)
259 {
260     ACPI_STATUS             Status = AE_OK;
261     UINT32                  Value;
262 
263 
264     ACPI_FUNCTION_TRACE (AcpiEnableEvent);
265 
266 
267     /* Decode the Fixed Event */
268 
269     if (Event > ACPI_EVENT_MAX)
270     {
271         return_ACPI_STATUS (AE_BAD_PARAMETER);
272     }
273 
274     /*
275      * Enable the requested fixed event (by writing a one to the enable
276      * register bit)
277      */
278     Status = AcpiWriteBitRegister (
279                 AcpiGbl_FixedEventInfo[Event].EnableRegisterId,
280                 ACPI_ENABLE_EVENT);
281     if (ACPI_FAILURE (Status))
282     {
283         return_ACPI_STATUS (Status);
284     }
285 
286     /* Make sure that the hardware responded */
287 
288     Status = AcpiReadBitRegister (
289                 AcpiGbl_FixedEventInfo[Event].EnableRegisterId, &Value);
290     if (ACPI_FAILURE (Status))
291     {
292         return_ACPI_STATUS (Status);
293     }
294 
295     if (Value != 1)
296     {
297         ACPI_ERROR ((AE_INFO,
298             "Could not enable %s event", AcpiUtGetEventName (Event)));
299         return_ACPI_STATUS (AE_NO_HARDWARE_RESPONSE);
300     }
301 
302     return_ACPI_STATUS (Status);
303 }
304 
305 ACPI_EXPORT_SYMBOL (AcpiEnableEvent)
306 
307 
308 /*******************************************************************************
309  *
310  * FUNCTION:    AcpiSetGpeType
311  *
312  * PARAMETERS:  GpeDevice       - Parent GPE Device
313  *              GpeNumber       - GPE level within the GPE block
314  *              Type            - New GPE type
315  *
316  * RETURN:      Status
317  *
318  * DESCRIPTION: Set the type of an individual GPE
319  *
320  ******************************************************************************/
321 
322 ACPI_STATUS
323 AcpiSetGpeType (
324     ACPI_HANDLE             GpeDevice,
325     UINT32                  GpeNumber,
326     UINT8                   Type)
327 {
328     ACPI_STATUS             Status = AE_OK;
329     ACPI_GPE_EVENT_INFO     *GpeEventInfo;
330 
331 
332     ACPI_FUNCTION_TRACE (AcpiSetGpeType);
333 
334 
335     /* Ensure that we have a valid GPE number */
336 
337     GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
338     if (!GpeEventInfo)
339     {
340         Status = AE_BAD_PARAMETER;
341         goto UnlockAndExit;
342     }
343 
344     if ((GpeEventInfo->Flags & ACPI_GPE_TYPE_MASK) == Type)
345     {
346         return_ACPI_STATUS (AE_OK);
347     }
348 
349     /* Set the new type (will disable GPE if currently enabled) */
350 
351     Status = AcpiEvSetGpeType (GpeEventInfo, Type);
352 
353 UnlockAndExit:
354     return_ACPI_STATUS (Status);
355 }
356 
357 ACPI_EXPORT_SYMBOL (AcpiSetGpeType)
358 
359 
360 /*******************************************************************************
361  *
362  * FUNCTION:    AcpiEnableGpe
363  *
364  * PARAMETERS:  GpeDevice       - Parent GPE Device
365  *              GpeNumber       - GPE level within the GPE block
366  *              Flags           - Just enable, or also wake enable?
367  *                                Called from ISR or not
368  *
369  * RETURN:      Status
370  *
371  * DESCRIPTION: Enable an ACPI event (general purpose)
372  *
373  ******************************************************************************/
374 
375 ACPI_STATUS
376 AcpiEnableGpe (
377     ACPI_HANDLE             GpeDevice,
378     UINT32                  GpeNumber,
379     UINT32                  Flags)
380 {
381     ACPI_STATUS             Status = AE_OK;
382     ACPI_GPE_EVENT_INFO     *GpeEventInfo;
383 
384 
385     ACPI_FUNCTION_TRACE (AcpiEnableGpe);
386 
387 
388     /* Use semaphore lock if not executing at interrupt level */
389 
390     if (Flags & ACPI_NOT_ISR)
391     {
392         Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
393         if (ACPI_FAILURE (Status))
394         {
395             return_ACPI_STATUS (Status);
396         }
397     }
398 
399     /* Ensure that we have a valid GPE number */
400 
401     GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
402     if (!GpeEventInfo)
403     {
404         Status = AE_BAD_PARAMETER;
405         goto UnlockAndExit;
406     }
407 
408     /* Perform the enable */
409 
410     Status = AcpiEvEnableGpe (GpeEventInfo, TRUE);
411 
412 UnlockAndExit:
413     if (Flags & ACPI_NOT_ISR)
414     {
415         (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
416     }
417     return_ACPI_STATUS (Status);
418 }
419 
420 ACPI_EXPORT_SYMBOL (AcpiEnableGpe)
421 
422 
423 /*******************************************************************************
424  *
425  * FUNCTION:    AcpiDisableGpe
426  *
427  * PARAMETERS:  GpeDevice       - Parent GPE Device
428  *              GpeNumber       - GPE level within the GPE block
429  *              Flags           - Just disable, or also wake disable?
430  *                                Called from ISR or not
431  *
432  * RETURN:      Status
433  *
434  * DESCRIPTION: Disable an ACPI event (general purpose)
435  *
436  ******************************************************************************/
437 
438 ACPI_STATUS
439 AcpiDisableGpe (
440     ACPI_HANDLE             GpeDevice,
441     UINT32                  GpeNumber,
442     UINT32                  Flags)
443 {
444     ACPI_STATUS             Status = AE_OK;
445     ACPI_GPE_EVENT_INFO     *GpeEventInfo;
446 
447 
448     ACPI_FUNCTION_TRACE (AcpiDisableGpe);
449 
450 
451     /* Use semaphore lock if not executing at interrupt level */
452 
453     if (Flags & ACPI_NOT_ISR)
454     {
455         Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
456         if (ACPI_FAILURE (Status))
457         {
458             return_ACPI_STATUS (Status);
459         }
460     }
461 
462     /* Ensure that we have a valid GPE number */
463 
464     GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
465     if (!GpeEventInfo)
466     {
467         Status = AE_BAD_PARAMETER;
468         goto UnlockAndExit;
469     }
470 
471     Status = AcpiEvDisableGpe (GpeEventInfo);
472 
473 UnlockAndExit:
474     if (Flags & ACPI_NOT_ISR)
475     {
476         (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
477     }
478     return_ACPI_STATUS (Status);
479 }
480 
481 ACPI_EXPORT_SYMBOL (AcpiDisableGpe)
482 
483 
484 /*******************************************************************************
485  *
486  * FUNCTION:    AcpiDisableEvent
487  *
488  * PARAMETERS:  Event           - The fixed eventto be enabled
489  *              Flags           - Reserved
490  *
491  * RETURN:      Status
492  *
493  * DESCRIPTION: Disable an ACPI event (fixed)
494  *
495  ******************************************************************************/
496 
497 ACPI_STATUS
498 AcpiDisableEvent (
499     UINT32                  Event,
500     UINT32                  Flags)
501 {
502     ACPI_STATUS             Status = AE_OK;
503     UINT32                  Value;
504 
505 
506     ACPI_FUNCTION_TRACE (AcpiDisableEvent);
507 
508 
509     /* Decode the Fixed Event */
510 
511     if (Event > ACPI_EVENT_MAX)
512     {
513         return_ACPI_STATUS (AE_BAD_PARAMETER);
514     }
515 
516     /*
517      * Disable the requested fixed event (by writing a zero to the enable
518      * register bit)
519      */
520     Status = AcpiWriteBitRegister (
521                 AcpiGbl_FixedEventInfo[Event].EnableRegisterId,
522                 ACPI_DISABLE_EVENT);
523     if (ACPI_FAILURE (Status))
524     {
525         return_ACPI_STATUS (Status);
526     }
527 
528     Status = AcpiReadBitRegister (
529                 AcpiGbl_FixedEventInfo[Event].EnableRegisterId, &Value);
530     if (ACPI_FAILURE (Status))
531     {
532         return_ACPI_STATUS (Status);
533     }
534 
535     if (Value != 0)
536     {
537         ACPI_ERROR ((AE_INFO,
538             "Could not disable %s events", AcpiUtGetEventName (Event)));
539         return_ACPI_STATUS (AE_NO_HARDWARE_RESPONSE);
540     }
541 
542     return_ACPI_STATUS (Status);
543 }
544 
545 ACPI_EXPORT_SYMBOL (AcpiDisableEvent)
546 
547 
548 /*******************************************************************************
549  *
550  * FUNCTION:    AcpiClearEvent
551  *
552  * PARAMETERS:  Event           - The fixed event to be cleared
553  *
554  * RETURN:      Status
555  *
556  * DESCRIPTION: Clear an ACPI event (fixed)
557  *
558  ******************************************************************************/
559 
560 ACPI_STATUS
561 AcpiClearEvent (
562     UINT32                  Event)
563 {
564     ACPI_STATUS             Status = AE_OK;
565 
566 
567     ACPI_FUNCTION_TRACE (AcpiClearEvent);
568 
569 
570     /* Decode the Fixed Event */
571 
572     if (Event > ACPI_EVENT_MAX)
573     {
574         return_ACPI_STATUS (AE_BAD_PARAMETER);
575     }
576 
577     /*
578      * Clear the requested fixed event (By writing a one to the status
579      * register bit)
580      */
581     Status = AcpiWriteBitRegister (
582                 AcpiGbl_FixedEventInfo[Event].StatusRegisterId,
583                 ACPI_CLEAR_STATUS);
584 
585     return_ACPI_STATUS (Status);
586 }
587 
588 ACPI_EXPORT_SYMBOL (AcpiClearEvent)
589 
590 
591 /*******************************************************************************
592  *
593  * FUNCTION:    AcpiClearGpe
594  *
595  * PARAMETERS:  GpeDevice       - Parent GPE Device
596  *              GpeNumber       - GPE level within the GPE block
597  *              Flags           - Called from an ISR or not
598  *
599  * RETURN:      Status
600  *
601  * DESCRIPTION: Clear an ACPI event (general purpose)
602  *
603  ******************************************************************************/
604 
605 ACPI_STATUS
606 AcpiClearGpe (
607     ACPI_HANDLE             GpeDevice,
608     UINT32                  GpeNumber,
609     UINT32                  Flags)
610 {
611     ACPI_STATUS             Status = AE_OK;
612     ACPI_GPE_EVENT_INFO     *GpeEventInfo;
613 
614 
615     ACPI_FUNCTION_TRACE (AcpiClearGpe);
616 
617 
618     /* Use semaphore lock if not executing at interrupt level */
619 
620     if (Flags & ACPI_NOT_ISR)
621     {
622         Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
623         if (ACPI_FAILURE (Status))
624         {
625             return_ACPI_STATUS (Status);
626         }
627     }
628 
629     /* Ensure that we have a valid GPE number */
630 
631     GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
632     if (!GpeEventInfo)
633     {
634         Status = AE_BAD_PARAMETER;
635         goto UnlockAndExit;
636     }
637 
638     Status = AcpiHwClearGpe (GpeEventInfo);
639 
640 UnlockAndExit:
641     if (Flags & ACPI_NOT_ISR)
642     {
643         (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
644     }
645     return_ACPI_STATUS (Status);
646 }
647 
648 ACPI_EXPORT_SYMBOL (AcpiClearGpe)
649 
650 
651 /*******************************************************************************
652  *
653  * FUNCTION:    AcpiGetEventStatus
654  *
655  * PARAMETERS:  Event           - The fixed event
656  *              EventStatus     - Where the current status of the event will
657  *                                be returned
658  *
659  * RETURN:      Status
660  *
661  * DESCRIPTION: Obtains and returns the current status of the event
662  *
663  ******************************************************************************/
664 
665 ACPI_STATUS
666 AcpiGetEventStatus (
667     UINT32                  Event,
668     ACPI_EVENT_STATUS       *EventStatus)
669 {
670     ACPI_STATUS             Status = AE_OK;
671 
672 
673     ACPI_FUNCTION_TRACE (AcpiGetEventStatus);
674 
675 
676     if (!EventStatus)
677     {
678         return_ACPI_STATUS (AE_BAD_PARAMETER);
679     }
680 
681     /* Decode the Fixed Event */
682 
683     if (Event > ACPI_EVENT_MAX)
684     {
685         return_ACPI_STATUS (AE_BAD_PARAMETER);
686     }
687 
688     /* Get the status of the requested fixed event */
689 
690     Status = AcpiReadBitRegister (
691                 AcpiGbl_FixedEventInfo[Event].StatusRegisterId, EventStatus);
692 
693     return_ACPI_STATUS (Status);
694 }
695 
696 ACPI_EXPORT_SYMBOL (AcpiGetEventStatus)
697 
698 
699 /*******************************************************************************
700  *
701  * FUNCTION:    AcpiGetGpeStatus
702  *
703  * PARAMETERS:  GpeDevice       - Parent GPE Device
704  *              GpeNumber       - GPE level within the GPE block
705  *              Flags           - Called from an ISR or not
706  *              EventStatus     - Where the current status of the event will
707  *                                be returned
708  *
709  * RETURN:      Status
710  *
711  * DESCRIPTION: Get status of an event (general purpose)
712  *
713  ******************************************************************************/
714 
715 ACPI_STATUS
716 AcpiGetGpeStatus (
717     ACPI_HANDLE             GpeDevice,
718     UINT32                  GpeNumber,
719     UINT32                  Flags,
720     ACPI_EVENT_STATUS       *EventStatus)
721 {
722     ACPI_STATUS             Status = AE_OK;
723     ACPI_GPE_EVENT_INFO     *GpeEventInfo;
724 
725 
726     ACPI_FUNCTION_TRACE (AcpiGetGpeStatus);
727 
728 
729     /* Use semaphore lock if not executing at interrupt level */
730 
731     if (Flags & ACPI_NOT_ISR)
732     {
733         Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
734         if (ACPI_FAILURE (Status))
735         {
736             return_ACPI_STATUS (Status);
737         }
738     }
739 
740     /* Ensure that we have a valid GPE number */
741 
742     GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
743     if (!GpeEventInfo)
744     {
745         Status = AE_BAD_PARAMETER;
746         goto UnlockAndExit;
747     }
748 
749     /* Obtain status on the requested GPE number */
750 
751     Status = AcpiHwGetGpeStatus (GpeEventInfo, EventStatus);
752 
753 UnlockAndExit:
754     if (Flags & ACPI_NOT_ISR)
755     {
756         (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
757     }
758     return_ACPI_STATUS (Status);
759 }
760 
761 ACPI_EXPORT_SYMBOL (AcpiGetGpeStatus)
762 
763 
764 /*******************************************************************************
765  *
766  * FUNCTION:    AcpiInstallGpeBlock
767  *
768  * PARAMETERS:  GpeDevice           - Handle to the parent GPE Block Device
769  *              GpeBlockAddress     - Address and SpaceID
770  *              RegisterCount       - Number of GPE register pairs in the block
771  *              InterruptNumber     - H/W interrupt for the block
772  *
773  * RETURN:      Status
774  *
775  * DESCRIPTION: Create and Install a block of GPE registers
776  *
777  ******************************************************************************/
778 
779 ACPI_STATUS
780 AcpiInstallGpeBlock (
781     ACPI_HANDLE             GpeDevice,
782     ACPI_GENERIC_ADDRESS    *GpeBlockAddress,
783     UINT32                  RegisterCount,
784     UINT32                  InterruptNumber)
785 {
786     ACPI_STATUS             Status;
787     ACPI_OPERAND_OBJECT     *ObjDesc;
788     ACPI_NAMESPACE_NODE     *Node;
789     ACPI_GPE_BLOCK_INFO     *GpeBlock;
790 
791 
792     ACPI_FUNCTION_TRACE (AcpiInstallGpeBlock);
793 
794 
795     if ((!GpeDevice)       ||
796         (!GpeBlockAddress) ||
797         (!RegisterCount))
798     {
799         return_ACPI_STATUS (AE_BAD_PARAMETER);
800     }
801 
802     Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
803     if (ACPI_FAILURE (Status))
804     {
805         return (Status);
806     }
807 
808     Node = AcpiNsMapHandleToNode (GpeDevice);
809     if (!Node)
810     {
811         Status = AE_BAD_PARAMETER;
812         goto UnlockAndExit;
813     }
814 
815     /*
816      * For user-installed GPE Block Devices, the GpeBlockBaseNumber
817      * is always zero
818      */
819     Status = AcpiEvCreateGpeBlock (Node, GpeBlockAddress, RegisterCount,
820                 0, InterruptNumber, &GpeBlock);
821     if (ACPI_FAILURE (Status))
822     {
823         goto UnlockAndExit;
824     }
825 
826     /* Run the _PRW methods and enable the GPEs */
827 
828     Status = AcpiEvInitializeGpeBlock (Node, GpeBlock);
829     if (ACPI_FAILURE (Status))
830     {
831         goto UnlockAndExit;
832     }
833 
834     /* Get the DeviceObject attached to the node */
835 
836     ObjDesc = AcpiNsGetAttachedObject (Node);
837     if (!ObjDesc)
838     {
839         /* No object, create a new one */
840 
841         ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_DEVICE);
842         if (!ObjDesc)
843         {
844             Status = AE_NO_MEMORY;
845             goto UnlockAndExit;
846         }
847 
848         Status = AcpiNsAttachObject (Node, ObjDesc, ACPI_TYPE_DEVICE);
849 
850         /* Remove local reference to the object */
851 
852         AcpiUtRemoveReference (ObjDesc);
853 
854         if (ACPI_FAILURE (Status))
855         {
856             goto UnlockAndExit;
857         }
858     }
859 
860     /* Install the GPE block in the DeviceObject */
861 
862     ObjDesc->Device.GpeBlock = GpeBlock;
863 
864 
865 UnlockAndExit:
866     (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
867     return_ACPI_STATUS (Status);
868 }
869 
870 ACPI_EXPORT_SYMBOL (AcpiInstallGpeBlock)
871 
872 
873 /*******************************************************************************
874  *
875  * FUNCTION:    AcpiRemoveGpeBlock
876  *
877  * PARAMETERS:  GpeDevice           - Handle to the parent GPE Block Device
878  *
879  * RETURN:      Status
880  *
881  * DESCRIPTION: Remove a previously installed block of GPE registers
882  *
883  ******************************************************************************/
884 
885 ACPI_STATUS
886 AcpiRemoveGpeBlock (
887     ACPI_HANDLE             GpeDevice)
888 {
889     ACPI_OPERAND_OBJECT     *ObjDesc;
890     ACPI_STATUS             Status;
891     ACPI_NAMESPACE_NODE     *Node;
892 
893 
894     ACPI_FUNCTION_TRACE (AcpiRemoveGpeBlock);
895 
896 
897     if (!GpeDevice)
898     {
899         return_ACPI_STATUS (AE_BAD_PARAMETER);
900     }
901 
902     Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
903     if (ACPI_FAILURE (Status))
904     {
905         return (Status);
906     }
907 
908     Node = AcpiNsMapHandleToNode (GpeDevice);
909     if (!Node)
910     {
911         Status = AE_BAD_PARAMETER;
912         goto UnlockAndExit;
913     }
914 
915     /* Get the DeviceObject attached to the node */
916 
917     ObjDesc = AcpiNsGetAttachedObject (Node);
918     if (!ObjDesc ||
919         !ObjDesc->Device.GpeBlock)
920     {
921         return_ACPI_STATUS (AE_NULL_OBJECT);
922     }
923 
924     /* Delete the GPE block (but not the DeviceObject) */
925 
926     Status = AcpiEvDeleteGpeBlock (ObjDesc->Device.GpeBlock);
927     if (ACPI_SUCCESS (Status))
928     {
929         ObjDesc->Device.GpeBlock = NULL;
930     }
931 
932 UnlockAndExit:
933     (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
934     return_ACPI_STATUS (Status);
935 }
936 
937 ACPI_EXPORT_SYMBOL (AcpiRemoveGpeBlock)
938 
939 
940 /*******************************************************************************
941  *
942  * FUNCTION:    AcpiGetGpeDevice
943  *
944  * PARAMETERS:  Index               - System GPE index (0-CurrentGpeCount)
945  *              GpeDevice           - Where the parent GPE Device is returned
946  *
947  * RETURN:      Status
948  *
949  * DESCRIPTION: Obtain the GPE device associated with the input index. A NULL
950  *              gpe device indicates that the gpe number is contained in one of
951  *              the FADT-defined gpe blocks. Otherwise, the GPE block device.
952  *
953  ******************************************************************************/
954 
955 ACPI_STATUS
956 AcpiGetGpeDevice (
957     UINT32                  Index,
958     ACPI_HANDLE             *GpeDevice)
959 {
960     ACPI_GPE_DEVICE_INFO    Info;
961     ACPI_STATUS             Status;
962 
963 
964     ACPI_FUNCTION_TRACE (AcpiGetGpeDevice);
965 
966 
967     if (!GpeDevice)
968     {
969         return_ACPI_STATUS (AE_BAD_PARAMETER);
970     }
971 
972     if (Index >= AcpiCurrentGpeCount)
973     {
974         return_ACPI_STATUS (AE_NOT_EXIST);
975     }
976 
977     /* Setup and walk the GPE list */
978 
979     Info.Index = Index;
980     Info.Status = AE_NOT_EXIST;
981     Info.GpeDevice = NULL;
982     Info.NextBlockBaseIndex = 0;
983 
984     Status = AcpiEvWalkGpeList (AcpiEvGetGpeDevice, &Info);
985     if (ACPI_FAILURE (Status))
986     {
987         return_ACPI_STATUS (Status);
988     }
989 
990     *GpeDevice = ACPI_CAST_PTR (ACPI_HANDLE, Info.GpeDevice);
991     return_ACPI_STATUS (Info.Status);
992 }
993 
994 ACPI_EXPORT_SYMBOL (AcpiGetGpeDevice)
995 
996 
997 /*******************************************************************************
998  *
999  * FUNCTION:    AcpiEvGetGpeDevice
1000  *
1001  * PARAMETERS:  GPE_WALK_CALLBACK
1002  *
1003  * RETURN:      Status
1004  *
1005  * DESCRIPTION: Matches the input GPE index (0-CurrentGpeCount) with a GPE
1006  *              block device. NULL if the GPE is one of the FADT-defined GPEs.
1007  *
1008  ******************************************************************************/
1009 
1010 static ACPI_STATUS
1011 AcpiEvGetGpeDevice (
1012     ACPI_GPE_XRUPT_INFO     *GpeXruptInfo,
1013     ACPI_GPE_BLOCK_INFO     *GpeBlock,
1014     void                    *Context)
1015 {
1016     ACPI_GPE_DEVICE_INFO    *Info = Context;
1017 
1018 
1019     /* Increment Index by the number of GPEs in this block */
1020 
1021     Info->NextBlockBaseIndex +=
1022         (GpeBlock->RegisterCount * ACPI_GPE_REGISTER_WIDTH);
1023 
1024     if (Info->Index < Info->NextBlockBaseIndex)
1025     {
1026         /*
1027          * The GPE index is within this block, get the node. Leave the node
1028          * NULL for the FADT-defined GPEs
1029          */
1030         if ((GpeBlock->Node)->Type == ACPI_TYPE_DEVICE)
1031         {
1032             Info->GpeDevice = GpeBlock->Node;
1033         }
1034 
1035         Info->Status = AE_OK;
1036         return (AE_CTRL_END);
1037     }
1038 
1039     return (AE_OK);
1040 }
1041 
1042 
1043 /******************************************************************************
1044  *
1045  * FUNCTION:    AcpiDisableAllGpes
1046  *
1047  * PARAMETERS:  None
1048  *
1049  * RETURN:      Status
1050  *
1051  * DESCRIPTION: Disable and clear all GPEs in all GPE blocks
1052  *
1053  ******************************************************************************/
1054 
1055 ACPI_STATUS
1056 AcpiDisableAllGpes (
1057     void)
1058 {
1059     ACPI_STATUS             Status;
1060 
1061 
1062     ACPI_FUNCTION_TRACE (AcpiDisableAllGpes);
1063 
1064 
1065     Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
1066     if (ACPI_FAILURE (Status))
1067     {
1068         return_ACPI_STATUS (Status);
1069     }
1070 
1071     Status = AcpiHwDisableAllGpes ();
1072     (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
1073 
1074     return_ACPI_STATUS (Status);
1075 }
1076 
1077 
1078 /******************************************************************************
1079  *
1080  * FUNCTION:    AcpiEnableAllRuntimeGpes
1081  *
1082  * PARAMETERS:  None
1083  *
1084  * RETURN:      Status
1085  *
1086  * DESCRIPTION: Enable all "runtime" GPEs, in all GPE blocks
1087  *
1088  ******************************************************************************/
1089 
1090 ACPI_STATUS
1091 AcpiEnableAllRuntimeGpes (
1092     void)
1093 {
1094     ACPI_STATUS             Status;
1095 
1096 
1097     ACPI_FUNCTION_TRACE (AcpiEnableAllRuntimeGpes);
1098 
1099 
1100     Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
1101     if (ACPI_FAILURE (Status))
1102     {
1103         return_ACPI_STATUS (Status);
1104     }
1105 
1106     Status = AcpiHwEnableAllRuntimeGpes ();
1107     (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
1108 
1109     return_ACPI_STATUS (Status);
1110 }
1111 
1112 
1113