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