xref: /titanic_41/usr/src/uts/intel/io/acpica/events/evxfevnt.c (revision 3125ebfc35130d243e775dc38a6a59be4df0b137)
1 /******************************************************************************
2  *
3  * Module Name: evxfevnt - External Interfaces, ACPI event disable/enable
4  *              $Revision: 1.88 $
5  *
6  *****************************************************************************/
7 
8 /******************************************************************************
9  *
10  * 1. Copyright Notice
11  *
12  * Some or all of this work - Copyright (c) 1999 - 2006, Intel Corp.
13  * All rights reserved.
14  *
15  * 2. License
16  *
17  * 2.1. This is your license from Intel Corp. under its intellectual property
18  * rights.  You may have additional license terms from the party that provided
19  * you this software, covering your right to use that party's intellectual
20  * property rights.
21  *
22  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
23  * copy of the source code appearing in this file ("Covered Code") an
24  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
25  * base code distributed originally by Intel ("Original Intel Code") to copy,
26  * make derivatives, distribute, use and display any portion of the Covered
27  * Code in any form, with the right to sublicense such rights; and
28  *
29  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
30  * license (with the right to sublicense), under only those claims of Intel
31  * patents that are infringed by the Original Intel Code, to make, use, sell,
32  * offer to sell, and import the Covered Code and derivative works thereof
33  * solely to the minimum extent necessary to exercise the above copyright
34  * license, and in no event shall the patent license extend to any additions
35  * to or modifications of the Original Intel Code.  No other license or right
36  * is granted directly or by implication, estoppel or otherwise;
37  *
38  * The above copyright and patent license is granted only if the following
39  * conditions are met:
40  *
41  * 3. Conditions
42  *
43  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
44  * Redistribution of source code of any substantial portion of the Covered
45  * Code or modification with rights to further distribute source must include
46  * the above Copyright Notice, the above License, this list of Conditions,
47  * and the following Disclaimer and Export Compliance provision.  In addition,
48  * Licensee must cause all Covered Code to which Licensee contributes to
49  * contain a file documenting the changes Licensee made to create that Covered
50  * Code and the date of any change.  Licensee must include in that file the
51  * documentation of any changes made by any predecessor Licensee.  Licensee
52  * must include a prominent statement that the modification is derived,
53  * directly or indirectly, from Original Intel Code.
54  *
55  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
56  * Redistribution of source code of any substantial portion of the Covered
57  * Code or modification without rights to further distribute source must
58  * include the following Disclaimer and Export Compliance provision in the
59  * documentation and/or other materials provided with distribution.  In
60  * addition, Licensee may not authorize further sublicense of source of any
61  * portion of the Covered Code, and must include terms to the effect that the
62  * license from Licensee to its licensee is limited to the intellectual
63  * property embodied in the software Licensee provides to its licensee, and
64  * not to intellectual property embodied in modifications its licensee may
65  * make.
66  *
67  * 3.3. Redistribution of Executable. Redistribution in executable form of any
68  * substantial portion of the Covered Code or modification must reproduce the
69  * above Copyright Notice, and the following Disclaimer and Export Compliance
70  * provision in the documentation and/or other materials provided with the
71  * distribution.
72  *
73  * 3.4. Intel retains all right, title, and interest in and to the Original
74  * Intel Code.
75  *
76  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
77  * Intel shall be used in advertising or otherwise to promote the sale, use or
78  * other dealings in products derived from or relating to the Covered Code
79  * without prior written authorization from Intel.
80  *
81  * 4. Disclaimer and Export Compliance
82  *
83  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
84  * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
85  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
86  * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
87  * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
88  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
89  * PARTICULAR PURPOSE.
90  *
91  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
92  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
93  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
94  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
95  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
96  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
97  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
98  * LIMITED REMEDY.
99  *
100  * 4.3. Licensee shall not export, either directly or indirectly, any of this
101  * software or system incorporating such software without first obtaining any
102  * required license or other approval from the U. S. Department of Commerce or
103  * any other agency or department of the United States Government.  In the
104  * event Licensee exports any such software from the United States or
105  * re-exports any such software from a foreign destination, Licensee shall
106  * ensure that the distribution and export/re-export of the software is in
107  * compliance with all laws, regulations, orders, or other restrictions of the
108  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
109  * any of its subsidiaries will export/re-export any technical data, process,
110  * software, or service, directly or indirectly, to any country for which the
111  * United States government or any agency thereof requires an export license,
112  * other governmental approval, or letter of assurance, without first obtaining
113  * such license, approval or letter.
114  *
115  *****************************************************************************/
116 
117 
118 #define __EVXFEVNT_C__
119 
120 #include "acpi.h"
121 #include "acevents.h"
122 #include "acnamesp.h"
123 
124 #define _COMPONENT          ACPI_EVENTS
125         ACPI_MODULE_NAME    ("evxfevnt")
126 
127 
128 /*******************************************************************************
129  *
130  * FUNCTION:    AcpiEnable
131  *
132  * PARAMETERS:  None
133  *
134  * RETURN:      Status
135  *
136  * DESCRIPTION: Transfers the system into ACPI mode.
137  *
138  ******************************************************************************/
139 
140 ACPI_STATUS
141 AcpiEnable (
142     void)
143 {
144     ACPI_STATUS             Status = AE_OK;
145 
146 
147     ACPI_FUNCTION_TRACE (AcpiEnable);
148 
149 
150     /* Make sure we have the FADT */
151 
152     if (!AcpiGbl_FADT)
153     {
154         ACPI_WARNING ((AE_INFO, "No FADT information present!"));
155         return_ACPI_STATUS (AE_NO_ACPI_TABLES);
156     }
157 
158     if (AcpiHwGetMode() == ACPI_SYS_MODE_ACPI)
159     {
160         ACPI_DEBUG_PRINT ((ACPI_DB_INIT, "System is already in ACPI mode\n"));
161     }
162     else
163     {
164         /* Transition to ACPI mode */
165 
166         Status = AcpiHwSetMode (ACPI_SYS_MODE_ACPI);
167         if (ACPI_FAILURE (Status))
168         {
169             ACPI_ERROR ((AE_INFO, "Could not transition to ACPI mode"));
170             return_ACPI_STATUS (Status);
171         }
172 
173         ACPI_DEBUG_PRINT ((ACPI_DB_INIT,
174             "Transition to ACPI mode successful\n"));
175     }
176 
177     return_ACPI_STATUS (Status);
178 }
179 
180 ACPI_EXPORT_SYMBOL (AcpiEnable)
181 
182 
183 /*******************************************************************************
184  *
185  * FUNCTION:    AcpiDisable
186  *
187  * PARAMETERS:  None
188  *
189  * RETURN:      Status
190  *
191  * DESCRIPTION: Transfers the system into LEGACY (non-ACPI) mode.
192  *
193  ******************************************************************************/
194 
195 ACPI_STATUS
196 AcpiDisable (
197     void)
198 {
199     ACPI_STATUS             Status = AE_OK;
200 
201 
202     ACPI_FUNCTION_TRACE (AcpiDisable);
203 
204 
205     if (!AcpiGbl_FADT)
206     {
207         ACPI_WARNING ((AE_INFO, "No FADT information present!"));
208         return_ACPI_STATUS (AE_NO_ACPI_TABLES);
209     }
210 
211     if (AcpiHwGetMode() == ACPI_SYS_MODE_LEGACY)
212     {
213         ACPI_DEBUG_PRINT ((ACPI_DB_INIT,
214             "System is already in legacy (non-ACPI) mode\n"));
215     }
216     else
217     {
218         /* Transition to LEGACY mode */
219 
220         Status = AcpiHwSetMode (ACPI_SYS_MODE_LEGACY);
221 
222         if (ACPI_FAILURE (Status))
223         {
224             ACPI_ERROR ((AE_INFO,
225                 "Could not exit ACPI mode to legacy mode"));
226             return_ACPI_STATUS (Status);
227         }
228 
229         ACPI_DEBUG_PRINT ((ACPI_DB_INIT, "ACPI mode disabled\n"));
230     }
231 
232     return_ACPI_STATUS (Status);
233 }
234 
235 ACPI_EXPORT_SYMBOL (AcpiDisable)
236 
237 
238 /*******************************************************************************
239  *
240  * FUNCTION:    AcpiEnableEvent
241  *
242  * PARAMETERS:  Event           - The fixed eventto be enabled
243  *              Flags           - Reserved
244  *
245  * RETURN:      Status
246  *
247  * DESCRIPTION: Enable an ACPI event (fixed)
248  *
249  ******************************************************************************/
250 
251 ACPI_STATUS
252 AcpiEnableEvent (
253     UINT32                  Event,
254     UINT32                  Flags)
255 {
256     ACPI_STATUS             Status = AE_OK;
257     UINT32                  Value;
258 
259 
260     ACPI_FUNCTION_TRACE (AcpiEnableEvent);
261 
262 
263     /* Decode the Fixed Event */
264 
265     if (Event > ACPI_EVENT_MAX)
266     {
267         return_ACPI_STATUS (AE_BAD_PARAMETER);
268     }
269 
270     /*
271      * Enable the requested fixed event (by writing a one to the
272      * enable register bit)
273      */
274     Status = AcpiSetRegister (AcpiGbl_FixedEventInfo[Event].EnableRegisterId,
275                 1, ACPI_MTX_LOCK);
276     if (ACPI_FAILURE (Status))
277     {
278         return_ACPI_STATUS (Status);
279     }
280 
281     /* Make sure that the hardware responded */
282 
283     Status = AcpiGetRegister (AcpiGbl_FixedEventInfo[Event].EnableRegisterId,
284                     &Value, ACPI_MTX_LOCK);
285     if (ACPI_FAILURE (Status))
286     {
287         return_ACPI_STATUS (Status);
288     }
289 
290     if (Value != 1)
291     {
292         ACPI_ERROR ((AE_INFO,
293             "Could not enable %s event", AcpiUtGetEventName (Event)));
294         return_ACPI_STATUS (AE_NO_HARDWARE_RESPONSE);
295     }
296 
297     return_ACPI_STATUS (Status);
298 }
299 
300 ACPI_EXPORT_SYMBOL (AcpiEnableEvent)
301 
302 
303 /*******************************************************************************
304  *
305  * FUNCTION:    AcpiSetGpeType
306  *
307  * PARAMETERS:  GpeDevice       - Parent GPE Device
308  *              GpeNumber       - GPE level within the GPE block
309  *              Type            - New GPE type
310  *
311  * RETURN:      Status
312  *
313  * DESCRIPTION: Set the type of an individual GPE
314  *
315  ******************************************************************************/
316 
317 ACPI_STATUS
318 AcpiSetGpeType (
319     ACPI_HANDLE             GpeDevice,
320     UINT32                  GpeNumber,
321     UINT8                   Type)
322 {
323     ACPI_STATUS             Status = AE_OK;
324     ACPI_GPE_EVENT_INFO     *GpeEventInfo;
325 
326 
327     ACPI_FUNCTION_TRACE (AcpiSetGpeType);
328 
329 
330     /* Ensure that we have a valid GPE number */
331 
332     GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
333     if (!GpeEventInfo)
334     {
335         Status = AE_BAD_PARAMETER;
336         goto UnlockAndExit;
337     }
338 
339     if ((GpeEventInfo->Flags & ACPI_GPE_TYPE_MASK) == Type)
340     {
341         return_ACPI_STATUS (AE_OK);
342     }
343 
344     /* Set the new type (will disable GPE if currently enabled) */
345 
346     Status = AcpiEvSetGpeType (GpeEventInfo, Type);
347 
348 UnlockAndExit:
349     return_ACPI_STATUS (Status);
350 }
351 
352 ACPI_EXPORT_SYMBOL (AcpiSetGpeType)
353 
354 
355 /*******************************************************************************
356  *
357  * FUNCTION:    AcpiEnableGpe
358  *
359  * PARAMETERS:  GpeDevice       - Parent GPE Device
360  *              GpeNumber       - GPE level within the GPE block
361  *              Flags           - Just enable, or also wake enable?
362  *                                Called from ISR or not
363  *
364  * RETURN:      Status
365  *
366  * DESCRIPTION: Enable an ACPI event (general purpose)
367  *
368  ******************************************************************************/
369 
370 ACPI_STATUS
371 AcpiEnableGpe (
372     ACPI_HANDLE             GpeDevice,
373     UINT32                  GpeNumber,
374     UINT32                  Flags)
375 {
376     ACPI_STATUS             Status = AE_OK;
377     ACPI_GPE_EVENT_INFO     *GpeEventInfo;
378 
379 
380     ACPI_FUNCTION_TRACE (AcpiEnableGpe);
381 
382 
383     /* Use semaphore lock if not executing at interrupt level */
384 
385     if (Flags & ACPI_NOT_ISR)
386     {
387         Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
388         if (ACPI_FAILURE (Status))
389         {
390             return_ACPI_STATUS (Status);
391         }
392     }
393 
394     /* Ensure that we have a valid GPE number */
395 
396     GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
397     if (!GpeEventInfo)
398     {
399         Status = AE_BAD_PARAMETER;
400         goto UnlockAndExit;
401     }
402 
403     /* Perform the enable */
404 
405     Status = AcpiEvEnableGpe (GpeEventInfo, TRUE);
406 
407 UnlockAndExit:
408     if (Flags & ACPI_NOT_ISR)
409     {
410         (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
411     }
412     return_ACPI_STATUS (Status);
413 }
414 
415 ACPI_EXPORT_SYMBOL (AcpiEnableGpe)
416 
417 
418 /*******************************************************************************
419  *
420  * FUNCTION:    AcpiDisableGpe
421  *
422  * PARAMETERS:  GpeDevice       - Parent GPE Device
423  *              GpeNumber       - GPE level within the GPE block
424  *              Flags           - Just disable, or also wake disable?
425  *                                Called from ISR or not
426  *
427  * RETURN:      Status
428  *
429  * DESCRIPTION: Disable an ACPI event (general purpose)
430  *
431  ******************************************************************************/
432 
433 ACPI_STATUS
434 AcpiDisableGpe (
435     ACPI_HANDLE             GpeDevice,
436     UINT32                  GpeNumber,
437     UINT32                  Flags)
438 {
439     ACPI_STATUS             Status = AE_OK;
440     ACPI_GPE_EVENT_INFO     *GpeEventInfo;
441 
442 
443     ACPI_FUNCTION_TRACE (AcpiDisableGpe);
444 
445 
446     /* Use semaphore lock if not executing at interrupt level */
447 
448     if (Flags & ACPI_NOT_ISR)
449     {
450         Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
451         if (ACPI_FAILURE (Status))
452         {
453             return_ACPI_STATUS (Status);
454         }
455     }
456 
457     /* Ensure that we have a valid GPE number */
458 
459     GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
460     if (!GpeEventInfo)
461     {
462         Status = AE_BAD_PARAMETER;
463         goto UnlockAndExit;
464     }
465 
466     Status = AcpiEvDisableGpe (GpeEventInfo);
467 
468 UnlockAndExit:
469     if (Flags & ACPI_NOT_ISR)
470     {
471         (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
472     }
473     return_ACPI_STATUS (Status);
474 }
475 
476 ACPI_EXPORT_SYMBOL (AcpiDisableGpe)
477 
478 
479 /*******************************************************************************
480  *
481  * FUNCTION:    AcpiDisableEvent
482  *
483  * PARAMETERS:  Event           - The fixed eventto be enabled
484  *              Flags           - Reserved
485  *
486  * RETURN:      Status
487  *
488  * DESCRIPTION: Disable an ACPI event (fixed)
489  *
490  ******************************************************************************/
491 
492 ACPI_STATUS
493 AcpiDisableEvent (
494     UINT32                  Event,
495     UINT32                  Flags)
496 {
497     ACPI_STATUS             Status = AE_OK;
498     UINT32                  Value;
499 
500 
501     ACPI_FUNCTION_TRACE (AcpiDisableEvent);
502 
503 
504     /* Decode the Fixed Event */
505 
506     if (Event > ACPI_EVENT_MAX)
507     {
508         return_ACPI_STATUS (AE_BAD_PARAMETER);
509     }
510 
511     /*
512      * Disable the requested fixed event (by writing a zero to the
513      * enable register bit)
514      */
515     Status = AcpiSetRegister (AcpiGbl_FixedEventInfo[Event].EnableRegisterId,
516                 0, ACPI_MTX_LOCK);
517     if (ACPI_FAILURE (Status))
518     {
519         return_ACPI_STATUS (Status);
520     }
521 
522     Status = AcpiGetRegister (AcpiGbl_FixedEventInfo[Event].EnableRegisterId,
523                 &Value, ACPI_MTX_LOCK);
524     if (ACPI_FAILURE (Status))
525     {
526         return_ACPI_STATUS (Status);
527     }
528 
529     if (Value != 0)
530     {
531         ACPI_ERROR ((AE_INFO,
532             "Could not disable %s events", AcpiUtGetEventName (Event)));
533         return_ACPI_STATUS (AE_NO_HARDWARE_RESPONSE);
534     }
535 
536     return_ACPI_STATUS (Status);
537 }
538 
539 ACPI_EXPORT_SYMBOL (AcpiDisableEvent)
540 
541 
542 /*******************************************************************************
543  *
544  * FUNCTION:    AcpiClearEvent
545  *
546  * PARAMETERS:  Event           - The fixed event to be cleared
547  *
548  * RETURN:      Status
549  *
550  * DESCRIPTION: Clear an ACPI event (fixed)
551  *
552  ******************************************************************************/
553 
554 ACPI_STATUS
555 AcpiClearEvent (
556     UINT32                  Event)
557 {
558     ACPI_STATUS             Status = AE_OK;
559 
560 
561     ACPI_FUNCTION_TRACE (AcpiClearEvent);
562 
563 
564     /* Decode the Fixed Event */
565 
566     if (Event > ACPI_EVENT_MAX)
567     {
568         return_ACPI_STATUS (AE_BAD_PARAMETER);
569     }
570 
571     /*
572      * Clear the requested fixed event (By writing a one to the
573      * status register bit)
574      */
575     Status = AcpiSetRegister (AcpiGbl_FixedEventInfo[Event].StatusRegisterId,
576             1, ACPI_MTX_LOCK);
577 
578     return_ACPI_STATUS (Status);
579 }
580 
581 ACPI_EXPORT_SYMBOL (AcpiClearEvent)
582 
583 
584 /*******************************************************************************
585  *
586  * FUNCTION:    AcpiClearGpe
587  *
588  * PARAMETERS:  GpeDevice       - Parent GPE Device
589  *              GpeNumber       - GPE level within the GPE block
590  *              Flags           - Called from an ISR or not
591  *
592  * RETURN:      Status
593  *
594  * DESCRIPTION: Clear an ACPI event (general purpose)
595  *
596  ******************************************************************************/
597 
598 ACPI_STATUS
599 AcpiClearGpe (
600     ACPI_HANDLE             GpeDevice,
601     UINT32                  GpeNumber,
602     UINT32                  Flags)
603 {
604     ACPI_STATUS             Status = AE_OK;
605     ACPI_GPE_EVENT_INFO     *GpeEventInfo;
606 
607 
608     ACPI_FUNCTION_TRACE (AcpiClearGpe);
609 
610 
611     /* Use semaphore lock if not executing at interrupt level */
612 
613     if (Flags & ACPI_NOT_ISR)
614     {
615         Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
616         if (ACPI_FAILURE (Status))
617         {
618             return_ACPI_STATUS (Status);
619         }
620     }
621 
622     /* Ensure that we have a valid GPE number */
623 
624     GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
625     if (!GpeEventInfo)
626     {
627         Status = AE_BAD_PARAMETER;
628         goto UnlockAndExit;
629     }
630 
631     Status = AcpiHwClearGpe (GpeEventInfo);
632 
633 UnlockAndExit:
634     if (Flags & ACPI_NOT_ISR)
635     {
636         (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
637     }
638     return_ACPI_STATUS (Status);
639 }
640 
641 ACPI_EXPORT_SYMBOL (AcpiClearGpe)
642 
643 
644 /*******************************************************************************
645  *
646  * FUNCTION:    AcpiGetEventStatus
647  *
648  * PARAMETERS:  Event           - The fixed event
649  *              EventStatus     - Where the current status of the event will
650  *                                be returned
651  *
652  * RETURN:      Status
653  *
654  * DESCRIPTION: Obtains and returns the current status of the event
655  *
656  ******************************************************************************/
657 
658 ACPI_STATUS
659 AcpiGetEventStatus (
660     UINT32                  Event,
661     ACPI_EVENT_STATUS       *EventStatus)
662 {
663     ACPI_STATUS             Status = AE_OK;
664 
665 
666     ACPI_FUNCTION_TRACE (AcpiGetEventStatus);
667 
668 
669     if (!EventStatus)
670     {
671         return_ACPI_STATUS (AE_BAD_PARAMETER);
672     }
673 
674     /* Decode the Fixed Event */
675 
676     if (Event > ACPI_EVENT_MAX)
677     {
678         return_ACPI_STATUS (AE_BAD_PARAMETER);
679     }
680 
681     /* Get the status of the requested fixed event */
682 
683     Status = AcpiGetRegister (AcpiGbl_FixedEventInfo[Event].StatusRegisterId,
684                     EventStatus, ACPI_MTX_LOCK);
685 
686     return_ACPI_STATUS (Status);
687 }
688 
689 ACPI_EXPORT_SYMBOL (AcpiGetEventStatus)
690 
691 
692 /*******************************************************************************
693  *
694  * FUNCTION:    AcpiGetGpeStatus
695  *
696  * PARAMETERS:  GpeDevice       - Parent GPE Device
697  *              GpeNumber       - GPE level within the GPE block
698  *              Flags           - Called from an ISR or not
699  *              EventStatus     - Where the current status of the event will
700  *                                be returned
701  *
702  * RETURN:      Status
703  *
704  * DESCRIPTION: Get status of an event (general purpose)
705  *
706  ******************************************************************************/
707 
708 ACPI_STATUS
709 AcpiGetGpeStatus (
710     ACPI_HANDLE             GpeDevice,
711     UINT32                  GpeNumber,
712     UINT32                  Flags,
713     ACPI_EVENT_STATUS       *EventStatus)
714 {
715     ACPI_STATUS             Status = AE_OK;
716     ACPI_GPE_EVENT_INFO     *GpeEventInfo;
717 
718 
719     ACPI_FUNCTION_TRACE (AcpiGetGpeStatus);
720 
721 
722     /* Use semaphore lock if not executing at interrupt level */
723 
724     if (Flags & ACPI_NOT_ISR)
725     {
726         Status = AcpiUtAcquireMutex (ACPI_MTX_EVENTS);
727         if (ACPI_FAILURE (Status))
728         {
729             return_ACPI_STATUS (Status);
730         }
731     }
732 
733     /* Ensure that we have a valid GPE number */
734 
735     GpeEventInfo = AcpiEvGetGpeEventInfo (GpeDevice, GpeNumber);
736     if (!GpeEventInfo)
737     {
738         Status = AE_BAD_PARAMETER;
739         goto UnlockAndExit;
740     }
741 
742     /* Obtain status on the requested GPE number */
743 
744     Status = AcpiHwGetGpeStatus (GpeEventInfo, EventStatus);
745 
746 UnlockAndExit:
747     if (Flags & ACPI_NOT_ISR)
748     {
749         (void) AcpiUtReleaseMutex (ACPI_MTX_EVENTS);
750     }
751     return_ACPI_STATUS (Status);
752 }
753 
754 ACPI_EXPORT_SYMBOL (AcpiGetGpeStatus)
755 
756 
757 /*******************************************************************************
758  *
759  * FUNCTION:    AcpiInstallGpeBlock
760  *
761  * PARAMETERS:  GpeDevice           - Handle to the parent GPE Block Device
762  *              GpeBlockAddress     - Address and SpaceID
763  *              RegisterCount       - Number of GPE register pairs in the block
764  *              InterruptNumber     - H/W interrupt for the block
765  *
766  * RETURN:      Status
767  *
768  * DESCRIPTION: Create and Install a block of GPE registers
769  *
770  ******************************************************************************/
771 
772 ACPI_STATUS
773 AcpiInstallGpeBlock (
774     ACPI_HANDLE             GpeDevice,
775     ACPI_GENERIC_ADDRESS    *GpeBlockAddress,
776     UINT32                  RegisterCount,
777     UINT32                  InterruptNumber)
778 {
779     ACPI_STATUS             Status;
780     ACPI_OPERAND_OBJECT     *ObjDesc;
781     ACPI_NAMESPACE_NODE     *Node;
782     ACPI_GPE_BLOCK_INFO     *GpeBlock;
783 
784 
785     ACPI_FUNCTION_TRACE (AcpiInstallGpeBlock);
786 
787 
788     if ((!GpeDevice)       ||
789         (!GpeBlockAddress) ||
790         (!RegisterCount))
791     {
792         return_ACPI_STATUS (AE_BAD_PARAMETER);
793     }
794 
795     Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
796     if (ACPI_FAILURE (Status))
797     {
798         return (Status);
799     }
800 
801     Node = AcpiNsMapHandleToNode (GpeDevice);
802     if (!Node)
803     {
804         Status = AE_BAD_PARAMETER;
805         goto UnlockAndExit;
806     }
807 
808     /*
809      * For user-installed GPE Block Devices, the GpeBlockBaseNumber
810      * is always zero
811      */
812     Status = AcpiEvCreateGpeBlock (Node, GpeBlockAddress, RegisterCount,
813                     0, InterruptNumber, &GpeBlock);
814     if (ACPI_FAILURE (Status))
815     {
816         goto UnlockAndExit;
817     }
818 
819     /* Run the _PRW methods and enable the GPEs */
820 
821     Status = AcpiEvInitializeGpeBlock (Node, GpeBlock);
822     if (ACPI_FAILURE (Status))
823     {
824         goto UnlockAndExit;
825     }
826 
827     /* Get the DeviceObject attached to the node */
828 
829     ObjDesc = AcpiNsGetAttachedObject (Node);
830     if (!ObjDesc)
831     {
832         /* No object, create a new one */
833 
834         ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_DEVICE);
835         if (!ObjDesc)
836         {
837             Status = AE_NO_MEMORY;
838             goto UnlockAndExit;
839         }
840 
841         Status = AcpiNsAttachObject (Node, ObjDesc, ACPI_TYPE_DEVICE);
842 
843         /* Remove local reference to the object */
844 
845         AcpiUtRemoveReference (ObjDesc);
846 
847         if (ACPI_FAILURE (Status))
848         {
849             goto UnlockAndExit;
850         }
851     }
852 
853     /* Install the GPE block in the DeviceObject */
854 
855     ObjDesc->Device.GpeBlock = GpeBlock;
856 
857 
858 UnlockAndExit:
859     (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
860     return_ACPI_STATUS (Status);
861 }
862 
863 ACPI_EXPORT_SYMBOL (AcpiInstallGpeBlock)
864 
865 
866 /*******************************************************************************
867  *
868  * FUNCTION:    AcpiRemoveGpeBlock
869  *
870  * PARAMETERS:  GpeDevice           - Handle to the parent GPE Block Device
871  *
872  * RETURN:      Status
873  *
874  * DESCRIPTION: Remove a previously installed block of GPE registers
875  *
876  ******************************************************************************/
877 
878 ACPI_STATUS
879 AcpiRemoveGpeBlock (
880     ACPI_HANDLE             GpeDevice)
881 {
882     ACPI_OPERAND_OBJECT     *ObjDesc;
883     ACPI_STATUS             Status;
884     ACPI_NAMESPACE_NODE     *Node;
885 
886 
887     ACPI_FUNCTION_TRACE (AcpiRemoveGpeBlock);
888 
889 
890     if (!GpeDevice)
891     {
892         return_ACPI_STATUS (AE_BAD_PARAMETER);
893     }
894 
895     Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
896     if (ACPI_FAILURE (Status))
897     {
898         return (Status);
899     }
900 
901     Node = AcpiNsMapHandleToNode (GpeDevice);
902     if (!Node)
903     {
904         Status = AE_BAD_PARAMETER;
905         goto UnlockAndExit;
906     }
907 
908     /* Get the DeviceObject attached to the node */
909 
910     ObjDesc = AcpiNsGetAttachedObject (Node);
911     if (!ObjDesc ||
912         !ObjDesc->Device.GpeBlock)
913     {
914         return_ACPI_STATUS (AE_NULL_OBJECT);
915     }
916 
917     /* Delete the GPE block (but not the DeviceObject) */
918 
919     Status = AcpiEvDeleteGpeBlock (ObjDesc->Device.GpeBlock);
920     if (ACPI_SUCCESS (Status))
921     {
922         ObjDesc->Device.GpeBlock = NULL;
923     }
924 
925 UnlockAndExit:
926     (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
927     return_ACPI_STATUS (Status);
928 }
929 
930 ACPI_EXPORT_SYMBOL (AcpiRemoveGpeBlock)
931 
932