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