]> CyberLeo.Net >> Repos - FreeBSD/releng/9.2.git/blob - sys/contrib/dev/acpica/events/evxfevnt.c
- Copy stable/9 to releng/9.2 as part of the 9.2-RELEASE cycle.
[FreeBSD/releng/9.2.git] / sys / contrib / dev / acpica / events / evxfevnt.c
1 /******************************************************************************
2  *
3  * Module Name: evxfevnt - External Interfaces, ACPI event disable/enable
4  *
5  *****************************************************************************/
6
7 /*
8  * Copyright (C) 2000 - 2011, Intel Corp.
9  * All rights reserved.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  * 1. Redistributions of source code must retain the above copyright
15  *    notice, this list of conditions, and the following disclaimer,
16  *    without modification.
17  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18  *    substantially similar to the "NO WARRANTY" disclaimer below
19  *    ("Disclaimer") and any redistribution must be conditioned upon
20  *    including a substantially similar Disclaimer requirement for further
21  *    binary redistribution.
22  * 3. Neither the names of the above-listed copyright holders nor the names
23  *    of any contributors may be used to endorse or promote products derived
24  *    from this software without specific prior written permission.
25  *
26  * Alternatively, this software may be distributed under the terms of the
27  * GNU General Public License ("GPL") version 2 as published by the Free
28  * Software Foundation.
29  *
30  * NO WARRANTY
31  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41  * POSSIBILITY OF SUCH DAMAGES.
42  */
43
44
45 #define __EVXFEVNT_C__
46
47 #include <contrib/dev/acpica/include/acpi.h>
48 #include <contrib/dev/acpica/include/accommon.h>
49 #include <contrib/dev/acpica/include/actables.h>
50
51 #define _COMPONENT          ACPI_EVENTS
52         ACPI_MODULE_NAME    ("evxfevnt")
53
54
55 /*******************************************************************************
56  *
57  * FUNCTION:    AcpiEnable
58  *
59  * PARAMETERS:  None
60  *
61  * RETURN:      Status
62  *
63  * DESCRIPTION: Transfers the system into ACPI mode.
64  *
65  ******************************************************************************/
66
67 ACPI_STATUS
68 AcpiEnable (
69     void)
70 {
71     ACPI_STATUS             Status = AE_OK;
72
73
74     ACPI_FUNCTION_TRACE (AcpiEnable);
75
76
77     /* ACPI tables must be present */
78
79     if (!AcpiTbTablesLoaded ())
80     {
81         return_ACPI_STATUS (AE_NO_ACPI_TABLES);
82     }
83
84     /* Check current mode */
85
86     if (AcpiHwGetMode() == ACPI_SYS_MODE_ACPI)
87     {
88         ACPI_DEBUG_PRINT ((ACPI_DB_INIT, "System is already in ACPI mode\n"));
89     }
90     else
91     {
92         /* Transition to ACPI mode */
93
94         Status = AcpiHwSetMode (ACPI_SYS_MODE_ACPI);
95         if (ACPI_FAILURE (Status))
96         {
97             ACPI_ERROR ((AE_INFO, "Could not transition to ACPI mode"));
98             return_ACPI_STATUS (Status);
99         }
100
101         ACPI_DEBUG_PRINT ((ACPI_DB_INIT,
102             "Transition to ACPI mode successful\n"));
103     }
104
105     return_ACPI_STATUS (Status);
106 }
107
108 ACPI_EXPORT_SYMBOL (AcpiEnable)
109
110
111 /*******************************************************************************
112  *
113  * FUNCTION:    AcpiDisable
114  *
115  * PARAMETERS:  None
116  *
117  * RETURN:      Status
118  *
119  * DESCRIPTION: Transfers the system into LEGACY (non-ACPI) mode.
120  *
121  ******************************************************************************/
122
123 ACPI_STATUS
124 AcpiDisable (
125     void)
126 {
127     ACPI_STATUS             Status = AE_OK;
128
129
130     ACPI_FUNCTION_TRACE (AcpiDisable);
131
132
133     if (AcpiHwGetMode() == ACPI_SYS_MODE_LEGACY)
134     {
135         ACPI_DEBUG_PRINT ((ACPI_DB_INIT,
136             "System is already in legacy (non-ACPI) mode\n"));
137     }
138     else
139     {
140         /* Transition to LEGACY mode */
141
142         Status = AcpiHwSetMode (ACPI_SYS_MODE_LEGACY);
143
144         if (ACPI_FAILURE (Status))
145         {
146             ACPI_ERROR ((AE_INFO,
147                 "Could not exit ACPI mode to legacy mode"));
148             return_ACPI_STATUS (Status);
149         }
150
151         ACPI_DEBUG_PRINT ((ACPI_DB_INIT, "ACPI mode disabled\n"));
152     }
153
154     return_ACPI_STATUS (Status);
155 }
156
157 ACPI_EXPORT_SYMBOL (AcpiDisable)
158
159
160 /*******************************************************************************
161  *
162  * FUNCTION:    AcpiEnableEvent
163  *
164  * PARAMETERS:  Event           - The fixed eventto be enabled
165  *              Flags           - Reserved
166  *
167  * RETURN:      Status
168  *
169  * DESCRIPTION: Enable an ACPI event (fixed)
170  *
171  ******************************************************************************/
172
173 ACPI_STATUS
174 AcpiEnableEvent (
175     UINT32                  Event,
176     UINT32                  Flags)
177 {
178     ACPI_STATUS             Status = AE_OK;
179     UINT32                  Value;
180
181
182     ACPI_FUNCTION_TRACE (AcpiEnableEvent);
183
184
185     /* Decode the Fixed Event */
186
187     if (Event > ACPI_EVENT_MAX)
188     {
189         return_ACPI_STATUS (AE_BAD_PARAMETER);
190     }
191
192     /*
193      * Enable the requested fixed event (by writing a one to the enable
194      * register bit)
195      */
196     Status = AcpiWriteBitRegister (
197                 AcpiGbl_FixedEventInfo[Event].EnableRegisterId,
198                 ACPI_ENABLE_EVENT);
199     if (ACPI_FAILURE (Status))
200     {
201         return_ACPI_STATUS (Status);
202     }
203
204     /* Make sure that the hardware responded */
205
206     Status = AcpiReadBitRegister (
207                 AcpiGbl_FixedEventInfo[Event].EnableRegisterId, &Value);
208     if (ACPI_FAILURE (Status))
209     {
210         return_ACPI_STATUS (Status);
211     }
212
213     if (Value != 1)
214     {
215         ACPI_ERROR ((AE_INFO,
216             "Could not enable %s event", AcpiUtGetEventName (Event)));
217         return_ACPI_STATUS (AE_NO_HARDWARE_RESPONSE);
218     }
219
220     return_ACPI_STATUS (Status);
221 }
222
223 ACPI_EXPORT_SYMBOL (AcpiEnableEvent)
224
225
226 /*******************************************************************************
227  *
228  * FUNCTION:    AcpiDisableEvent
229  *
230  * PARAMETERS:  Event           - The fixed event to be disabled
231  *              Flags           - Reserved
232  *
233  * RETURN:      Status
234  *
235  * DESCRIPTION: Disable an ACPI event (fixed)
236  *
237  ******************************************************************************/
238
239 ACPI_STATUS
240 AcpiDisableEvent (
241     UINT32                  Event,
242     UINT32                  Flags)
243 {
244     ACPI_STATUS             Status = AE_OK;
245     UINT32                  Value;
246
247
248     ACPI_FUNCTION_TRACE (AcpiDisableEvent);
249
250
251     /* Decode the Fixed Event */
252
253     if (Event > ACPI_EVENT_MAX)
254     {
255         return_ACPI_STATUS (AE_BAD_PARAMETER);
256     }
257
258     /*
259      * Disable the requested fixed event (by writing a zero to the enable
260      * register bit)
261      */
262     Status = AcpiWriteBitRegister (
263                 AcpiGbl_FixedEventInfo[Event].EnableRegisterId,
264                 ACPI_DISABLE_EVENT);
265     if (ACPI_FAILURE (Status))
266     {
267         return_ACPI_STATUS (Status);
268     }
269
270     Status = AcpiReadBitRegister (
271                 AcpiGbl_FixedEventInfo[Event].EnableRegisterId, &Value);
272     if (ACPI_FAILURE (Status))
273     {
274         return_ACPI_STATUS (Status);
275     }
276
277     if (Value != 0)
278     {
279         ACPI_ERROR ((AE_INFO,
280             "Could not disable %s events", AcpiUtGetEventName (Event)));
281         return_ACPI_STATUS (AE_NO_HARDWARE_RESPONSE);
282     }
283
284     return_ACPI_STATUS (Status);
285 }
286
287 ACPI_EXPORT_SYMBOL (AcpiDisableEvent)
288
289
290 /*******************************************************************************
291  *
292  * FUNCTION:    AcpiClearEvent
293  *
294  * PARAMETERS:  Event           - The fixed event to be cleared
295  *
296  * RETURN:      Status
297  *
298  * DESCRIPTION: Clear an ACPI event (fixed)
299  *
300  ******************************************************************************/
301
302 ACPI_STATUS
303 AcpiClearEvent (
304     UINT32                  Event)
305 {
306     ACPI_STATUS             Status = AE_OK;
307
308
309     ACPI_FUNCTION_TRACE (AcpiClearEvent);
310
311
312     /* Decode the Fixed Event */
313
314     if (Event > ACPI_EVENT_MAX)
315     {
316         return_ACPI_STATUS (AE_BAD_PARAMETER);
317     }
318
319     /*
320      * Clear the requested fixed event (By writing a one to the status
321      * register bit)
322      */
323     Status = AcpiWriteBitRegister (
324                 AcpiGbl_FixedEventInfo[Event].StatusRegisterId,
325                 ACPI_CLEAR_STATUS);
326
327     return_ACPI_STATUS (Status);
328 }
329
330 ACPI_EXPORT_SYMBOL (AcpiClearEvent)
331
332
333 /*******************************************************************************
334  *
335  * FUNCTION:    AcpiGetEventStatus
336  *
337  * PARAMETERS:  Event           - The fixed event
338  *              EventStatus     - Where the current status of the event will
339  *                                be returned
340  *
341  * RETURN:      Status
342  *
343  * DESCRIPTION: Obtains and returns the current status of the event
344  *
345  ******************************************************************************/
346
347 ACPI_STATUS
348 AcpiGetEventStatus (
349     UINT32                  Event,
350     ACPI_EVENT_STATUS       *EventStatus)
351 {
352     ACPI_STATUS             Status = AE_OK;
353
354
355     ACPI_FUNCTION_TRACE (AcpiGetEventStatus);
356
357
358     if (!EventStatus)
359     {
360         return_ACPI_STATUS (AE_BAD_PARAMETER);
361     }
362
363     /* Decode the Fixed Event */
364
365     if (Event > ACPI_EVENT_MAX)
366     {
367         return_ACPI_STATUS (AE_BAD_PARAMETER);
368     }
369
370     /* Get the status of the requested fixed event */
371
372     Status = AcpiReadBitRegister (
373                 AcpiGbl_FixedEventInfo[Event].StatusRegisterId, EventStatus);
374
375     return_ACPI_STATUS (Status);
376 }
377
378 ACPI_EXPORT_SYMBOL (AcpiGetEventStatus)
379
380