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