]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/contrib/dev/acpica/evxfevnt.c
Vendor import of the Intel ACPI CA 20010816 update.
[FreeBSD/FreeBSD.git] / sys / contrib / dev / acpica / evxfevnt.c
1 /******************************************************************************
2  *
3  * Module Name: evxfevnt - External Interfaces, ACPI event disable/enable
4  *              $Revision: 34 $
5  *
6  *****************************************************************************/
7
8 /******************************************************************************
9  *
10  * 1. Copyright Notice
11  *
12  * Some or all of this work - Copyright (c) 1999, 2000, 2001, 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 "achware.h"
122 #include "acnamesp.h"
123 #include "acevents.h"
124 #include "amlcode.h"
125 #include "acinterp.h"
126
127 #define _COMPONENT          ACPI_EVENTS
128         MODULE_NAME         ("evxfevnt")
129
130
131 /*******************************************************************************
132  *
133  * FUNCTION:    AcpiEnable
134  *
135  * PARAMETERS:  None
136  *
137  * RETURN:      Status
138  *
139  * DESCRIPTION: Transfers the system into ACPI mode.
140  *
141  ******************************************************************************/
142
143 ACPI_STATUS
144 AcpiEnable (void)
145 {
146     ACPI_STATUS             Status;
147
148
149     FUNCTION_TRACE ("AcpiEnable");
150
151
152     /* Make sure we've got ACPI tables */
153
154     if (!AcpiGbl_DSDT)
155     {
156         ACPI_DEBUG_PRINT ((ACPI_DB_WARN, "No ACPI tables present!\n"));
157         return_ACPI_STATUS (AE_NO_ACPI_TABLES);
158     }
159
160     /* Make sure the BIOS supports ACPI mode */
161
162     if (SYS_MODE_LEGACY == AcpiHwGetModeCapabilities())
163     {
164         ACPI_DEBUG_PRINT ((ACPI_DB_WARN, "Only legacy mode supported!\n"));
165         return_ACPI_STATUS (AE_ERROR);
166     }
167
168     /* Transition to ACPI mode */
169
170     Status = AcpiHwSetMode (SYS_MODE_ACPI);
171     if (ACPI_FAILURE (Status))
172     {
173         ACPI_DEBUG_PRINT ((ACPI_DB_FATAL, "Could not transition to ACPI mode.\n"));
174         return_ACPI_STATUS (Status);
175     }
176
177     ACPI_DEBUG_PRINT ((ACPI_DB_OK, "Transition to ACPI mode successful\n"));
178
179     return_ACPI_STATUS (Status);
180 }
181
182
183 /*******************************************************************************
184  *
185  * FUNCTION:    AcpiDisable
186  *
187  * PARAMETERS:  None
188  *
189  * RETURN:      Status
190  *
191  * DESCRIPTION: Returns the system to original ACPI/legacy mode, and
192  *              uninstalls the SCI interrupt handler.
193  *
194  ******************************************************************************/
195
196 ACPI_STATUS
197 AcpiDisable (void)
198 {
199     ACPI_STATUS             Status;
200
201
202     FUNCTION_TRACE ("AcpiDisable");
203
204
205     /* Ensure that ACPI has been initialized */
206
207     ACPI_IS_INITIALIZATION_COMPLETE (Status);
208     if (ACPI_FAILURE (Status))
209     {
210         return_ACPI_STATUS (Status);
211     }
212
213     /* Restore original mode  */
214
215     Status = AcpiHwSetMode (AcpiGbl_OriginalMode);
216     if (ACPI_FAILURE (Status))
217     {
218         ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Unable to transition to original mode"));
219         return_ACPI_STATUS (Status);
220     }
221
222     /* Unload the SCI interrupt handler  */
223
224     AcpiEvRemoveSciHandler ();
225     AcpiEvRestoreAcpiState ();
226
227     return_ACPI_STATUS (Status);
228 }
229
230
231 /*******************************************************************************
232  *
233  * FUNCTION:    AcpiEnableEvent
234  *
235  * PARAMETERS:  Event           - The fixed event or GPE to be enabled
236  *              Type            - The type of event
237  *
238  * RETURN:      Status
239  *
240  * DESCRIPTION: Enable an ACPI event (fixed and general purpose)
241  *
242  ******************************************************************************/
243
244 ACPI_STATUS
245 AcpiEnableEvent (
246     UINT32                  Event,
247     UINT32                  Type)
248 {
249     ACPI_STATUS             Status = AE_OK;
250     UINT32                  RegisterId;
251
252
253     FUNCTION_TRACE ("AcpiEnableEvent");
254
255
256     /* Ensure that ACPI has been initialized */
257
258     ACPI_IS_INITIALIZATION_COMPLETE (Status);
259     if (ACPI_FAILURE (Status))
260     {
261         return_ACPI_STATUS (Status);
262     }
263
264     /* The Type must be either Fixed AcpiEvent or GPE */
265
266     switch (Type)
267     {
268
269     case ACPI_EVENT_FIXED:
270
271         /* Decode the Fixed AcpiEvent */
272
273         switch (Event)
274         {
275         case ACPI_EVENT_PMTIMER:
276             RegisterId = TMR_EN;
277             break;
278
279         case ACPI_EVENT_GLOBAL:
280             RegisterId = GBL_EN;
281             break;
282
283         case ACPI_EVENT_POWER_BUTTON:
284             RegisterId = PWRBTN_EN;
285             break;
286
287         case ACPI_EVENT_SLEEP_BUTTON:
288             RegisterId = SLPBTN_EN;
289             break;
290
291         case ACPI_EVENT_RTC:
292             RegisterId = RTC_EN;
293             break;
294
295         default:
296             return_ACPI_STATUS (AE_BAD_PARAMETER);
297             break;
298         }
299
300         /*
301          * Enable the requested fixed event (by writing a one to the
302          * enable register bit)
303          */
304
305         AcpiHwRegisterBitAccess (ACPI_WRITE, ACPI_MTX_LOCK, RegisterId, 1);
306
307         if (1 != AcpiHwRegisterBitAccess(ACPI_READ, ACPI_MTX_LOCK, RegisterId))
308         {
309             ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, 
310                 "Fixed event bit clear when it should be set\n"));
311             return_ACPI_STATUS (AE_NO_HARDWARE_RESPONSE);
312         }
313
314         break;
315
316
317     case ACPI_EVENT_GPE:
318
319         /* Ensure that we have a valid GPE number */
320
321         if ((Event > ACPI_GPE_MAX) ||
322             (AcpiGbl_GpeValid[Event] == ACPI_GPE_INVALID))
323         {
324             return_ACPI_STATUS (AE_BAD_PARAMETER);
325         }
326
327
328         /* Enable the requested GPE number */
329
330         AcpiHwEnableGpe (Event);
331         break;
332
333
334     default:
335
336         Status = AE_BAD_PARAMETER;
337     }
338
339
340     return_ACPI_STATUS (Status);
341 }
342
343
344 /*******************************************************************************
345  *
346  * FUNCTION:    AcpiDisableEvent
347  *
348  * PARAMETERS:  Event           - The fixed event or GPE to be enabled
349  *              Type            - The type of event
350  *
351  * RETURN:      Status
352  *
353  * DESCRIPTION: Disable an ACPI event (fixed and general purpose)
354  *
355  ******************************************************************************/
356
357 ACPI_STATUS
358 AcpiDisableEvent (
359     UINT32                  Event,
360     UINT32                  Type)
361 {
362     ACPI_STATUS             Status = AE_OK;
363     UINT32                  RegisterId;
364
365
366     FUNCTION_TRACE ("AcpiDisableEvent");
367
368
369     /* Ensure that ACPI has been initialized */
370
371     ACPI_IS_INITIALIZATION_COMPLETE (Status);
372     if (ACPI_FAILURE (Status))
373     {
374         return_ACPI_STATUS (Status);
375     }
376
377     /* The Type must be either Fixed AcpiEvent or GPE */
378
379     switch (Type)
380     {
381
382     case ACPI_EVENT_FIXED:
383
384         /* Decode the Fixed AcpiEvent */
385
386         switch (Event)
387         {
388         case ACPI_EVENT_PMTIMER:
389             RegisterId = TMR_EN;
390             break;
391
392         case ACPI_EVENT_GLOBAL:
393             RegisterId = GBL_EN;
394             break;
395
396         case ACPI_EVENT_POWER_BUTTON:
397             RegisterId = PWRBTN_EN;
398             break;
399
400         case ACPI_EVENT_SLEEP_BUTTON:
401             RegisterId = SLPBTN_EN;
402             break;
403
404         case ACPI_EVENT_RTC:
405             RegisterId = RTC_EN;
406             break;
407
408         default:
409             return_ACPI_STATUS (AE_BAD_PARAMETER);
410             break;
411         }
412
413         /*
414          * Disable the requested fixed event (by writing a zero to the
415          * enable register bit)
416          */
417
418         AcpiHwRegisterBitAccess (ACPI_WRITE, ACPI_MTX_LOCK, RegisterId, 0);
419
420         if (0 != AcpiHwRegisterBitAccess(ACPI_READ, ACPI_MTX_LOCK, RegisterId))
421         {
422             ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, 
423                 "Fixed event bit set when it should be clear,\n"));
424             return_ACPI_STATUS (AE_NO_HARDWARE_RESPONSE);
425         }
426
427         break;
428
429
430     case ACPI_EVENT_GPE:
431
432         /* Ensure that we have a valid GPE number */
433
434         if ((Event > ACPI_GPE_MAX) ||
435             (AcpiGbl_GpeValid[Event] == ACPI_GPE_INVALID))
436         {
437             return_ACPI_STATUS (AE_BAD_PARAMETER);
438         }
439
440         /* Disable the requested GPE number */
441
442         AcpiHwDisableGpe (Event);
443         break;
444
445
446     default:
447         Status = AE_BAD_PARAMETER;
448     }
449
450     return_ACPI_STATUS (Status);
451 }
452
453
454 /*******************************************************************************
455  *
456  * FUNCTION:    AcpiClearEvent
457  *
458  * PARAMETERS:  Event           - The fixed event or GPE to be cleared
459  *              Type            - The type of event
460  *
461  * RETURN:      Status
462  *
463  * DESCRIPTION: Clear an ACPI event (fixed and general purpose)
464  *
465  ******************************************************************************/
466
467 ACPI_STATUS
468 AcpiClearEvent (
469     UINT32                  Event,
470     UINT32                  Type)
471 {
472     ACPI_STATUS             Status = AE_OK;
473     UINT32                  RegisterId;
474
475
476     FUNCTION_TRACE ("AcpiClearEvent");
477
478
479     /* Ensure that ACPI has been initialized */
480
481     ACPI_IS_INITIALIZATION_COMPLETE (Status);
482     if (ACPI_FAILURE (Status))
483     {
484         return_ACPI_STATUS (Status);
485     }
486
487     /* The Type must be either Fixed AcpiEvent or GPE */
488
489     switch (Type)
490     {
491
492     case ACPI_EVENT_FIXED:
493
494         /* Decode the Fixed AcpiEvent */
495
496         switch (Event)
497         {
498         case ACPI_EVENT_PMTIMER:
499             RegisterId = TMR_STS;
500             break;
501
502         case ACPI_EVENT_GLOBAL:
503             RegisterId = GBL_STS;
504             break;
505
506         case ACPI_EVENT_POWER_BUTTON:
507             RegisterId = PWRBTN_STS;
508             break;
509
510         case ACPI_EVENT_SLEEP_BUTTON:
511             RegisterId = SLPBTN_STS;
512             break;
513
514         case ACPI_EVENT_RTC:
515             RegisterId = RTC_STS;
516             break;
517
518         default:
519             return_ACPI_STATUS (AE_BAD_PARAMETER);
520             break;
521         }
522
523         /*
524          * Clear the requested fixed event (By writing a one to the
525          * status register bit)
526          */
527
528         AcpiHwRegisterBitAccess (ACPI_WRITE, ACPI_MTX_LOCK, RegisterId, 1);
529         break;
530
531
532     case ACPI_EVENT_GPE:
533
534         /* Ensure that we have a valid GPE number */
535
536         if ((Event > ACPI_GPE_MAX) ||
537             (AcpiGbl_GpeValid[Event] == ACPI_GPE_INVALID))
538         {
539             return_ACPI_STATUS (AE_BAD_PARAMETER);
540         }
541
542
543         AcpiHwClearGpe (Event);
544         break;
545
546
547     default:
548
549         Status = AE_BAD_PARAMETER;
550     }
551
552     return_ACPI_STATUS (Status);
553 }
554
555
556 /*******************************************************************************
557  *
558  * FUNCTION:    AcpiGetEventStatus
559  *
560  * PARAMETERS:  Event           - The fixed event or GPE
561  *              Type            - The type of event
562  *              Status          - Where the current status of the event will
563  *                                be returned
564  *
565  * RETURN:      Status
566  *
567  * DESCRIPTION: Obtains and returns the current status of the event
568  *
569  ******************************************************************************/
570
571
572 ACPI_STATUS
573 AcpiGetEventStatus (
574     UINT32                  Event,
575     UINT32                  Type,
576     ACPI_EVENT_STATUS       *EventStatus)
577 {
578     ACPI_STATUS             Status = AE_OK;
579     UINT32                  RegisterId;
580
581
582     FUNCTION_TRACE ("AcpiGetEventStatus");
583
584
585     /* Ensure that ACPI has been initialized */
586
587     ACPI_IS_INITIALIZATION_COMPLETE (Status);
588     if (ACPI_FAILURE (Status))
589     {
590         return_ACPI_STATUS (Status);
591     }
592
593     if (!EventStatus)
594     {
595         return_ACPI_STATUS (AE_BAD_PARAMETER);
596     }
597
598
599     /* The Type must be either Fixed AcpiEvent or GPE */
600
601     switch (Type)
602     {
603
604     case ACPI_EVENT_FIXED:
605
606         /* Decode the Fixed AcpiEvent */
607
608         switch (Event)
609         {
610         case ACPI_EVENT_PMTIMER:
611             RegisterId = TMR_STS;
612             break;
613
614         case ACPI_EVENT_GLOBAL:
615             RegisterId = GBL_STS;
616             break;
617
618         case ACPI_EVENT_POWER_BUTTON:
619             RegisterId = PWRBTN_STS;
620             break;
621
622         case ACPI_EVENT_SLEEP_BUTTON:
623             RegisterId = SLPBTN_STS;
624             break;
625
626         case ACPI_EVENT_RTC:
627             RegisterId = RTC_STS;
628             break;
629
630         default:
631             return_ACPI_STATUS (AE_BAD_PARAMETER);
632             break;
633         }
634
635         /* Get the status of the requested fixed event */
636
637         *EventStatus = AcpiHwRegisterBitAccess (ACPI_READ, ACPI_MTX_LOCK, RegisterId);
638         break;
639
640
641     case ACPI_EVENT_GPE:
642
643         /* Ensure that we have a valid GPE number */
644
645         if ((Event > ACPI_GPE_MAX) ||
646             (AcpiGbl_GpeValid[Event] == ACPI_GPE_INVALID))
647         {
648             return_ACPI_STATUS (AE_BAD_PARAMETER);
649         }
650
651
652         /* Obtain status on the requested GPE number */
653
654         AcpiHwGetGpeStatus (Event, EventStatus);
655         break;
656
657
658     default:
659         Status = AE_BAD_PARAMETER;
660     }
661
662
663     return_ACPI_STATUS (Status);
664 }
665