1 /******************************************************************************
2  *
3  * Module Name: evxfevnt - External Interfaces, ACPI event disable/enable
4  *
5  *****************************************************************************/
6 
7 /*
8  * Copyright (C) 2000 - 2015, 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 #define EXPORT_ACPI_INTERFACES
45 
46 #include "acpi.h"
47 #include "accommon.h"
48 #include "actables.h"
49 
50 #define _COMPONENT          ACPI_EVENTS
51         ACPI_MODULE_NAME    ("evxfevnt")
52 
53 
54 #if (!ACPI_REDUCED_HARDWARE) /* Entire module */
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     /* If the Hardware Reduced flag is set, machine is always in acpi mode */
85 
86     if (AcpiGbl_ReducedHardware)
87     {
88         return_ACPI_STATUS (AE_OK);
89     }
90 
91     /* Check current mode */
92 
93     if (AcpiHwGetMode() == ACPI_SYS_MODE_ACPI)
94     {
95         ACPI_DEBUG_PRINT ((ACPI_DB_INIT, "System is already in ACPI mode\n"));
96     }
97     else
98     {
99         /* Transition to ACPI mode */
100 
101         Status = AcpiHwSetMode (ACPI_SYS_MODE_ACPI);
102         if (ACPI_FAILURE (Status))
103         {
104             ACPI_ERROR ((AE_INFO, "Could not transition to ACPI mode"));
105             return_ACPI_STATUS (Status);
106         }
107 
108         ACPI_DEBUG_PRINT ((ACPI_DB_INIT,
109             "Transition to ACPI mode successful\n"));
110     }
111 
112     return_ACPI_STATUS (Status);
113 }
114 
115 ACPI_EXPORT_SYMBOL (AcpiEnable)
116 
117 
118 /*******************************************************************************
119  *
120  * FUNCTION:    AcpiDisable
121  *
122  * PARAMETERS:  None
123  *
124  * RETURN:      Status
125  *
126  * DESCRIPTION: Transfers the system into LEGACY (non-ACPI) mode.
127  *
128  ******************************************************************************/
129 
130 ACPI_STATUS
131 AcpiDisable (
132     void)
133 {
134     ACPI_STATUS             Status = AE_OK;
135 
136 
137     ACPI_FUNCTION_TRACE (AcpiDisable);
138 
139 
140     /* If the Hardware Reduced flag is set, machine is always in acpi mode */
141 
142     if (AcpiGbl_ReducedHardware)
143     {
144         return_ACPI_STATUS (AE_OK);
145     }
146 
147     if (AcpiHwGetMode() == ACPI_SYS_MODE_LEGACY)
148     {
149         ACPI_DEBUG_PRINT ((ACPI_DB_INIT,
150             "System is already in legacy (non-ACPI) mode\n"));
151     }
152     else
153     {
154         /* Transition to LEGACY mode */
155 
156         Status = AcpiHwSetMode (ACPI_SYS_MODE_LEGACY);
157 
158         if (ACPI_FAILURE (Status))
159         {
160             ACPI_ERROR ((AE_INFO,
161                 "Could not exit ACPI mode to legacy mode"));
162             return_ACPI_STATUS (Status);
163         }
164 
165         ACPI_DEBUG_PRINT ((ACPI_DB_INIT, "ACPI mode disabled\n"));
166     }
167 
168     return_ACPI_STATUS (Status);
169 }
170 
171 ACPI_EXPORT_SYMBOL (AcpiDisable)
172 
173 
174 /*******************************************************************************
175  *
176  * FUNCTION:    AcpiEnableEvent
177  *
178  * PARAMETERS:  Event           - The fixed eventto be enabled
179  *              Flags           - Reserved
180  *
181  * RETURN:      Status
182  *
183  * DESCRIPTION: Enable an ACPI event (fixed)
184  *
185  ******************************************************************************/
186 
187 ACPI_STATUS
188 AcpiEnableEvent (
189     UINT32                  Event,
190     UINT32                  Flags)
191 {
192     ACPI_STATUS             Status = AE_OK;
193     UINT32                  Value;
194 
195 
196     ACPI_FUNCTION_TRACE (AcpiEnableEvent);
197 
198 
199     /* Decode the Fixed Event */
200 
201     if (Event > ACPI_EVENT_MAX)
202     {
203         return_ACPI_STATUS (AE_BAD_PARAMETER);
204     }
205 
206     /*
207      * Enable the requested fixed event (by writing a one to the enable
208      * register bit)
209      */
210     Status = AcpiWriteBitRegister (
211                 AcpiGbl_FixedEventInfo[Event].EnableRegisterId,
212                 ACPI_ENABLE_EVENT);
213     if (ACPI_FAILURE (Status))
214     {
215         return_ACPI_STATUS (Status);
216     }
217 
218     /* Make sure that the hardware responded */
219 
220     Status = AcpiReadBitRegister (
221                 AcpiGbl_FixedEventInfo[Event].EnableRegisterId, &Value);
222     if (ACPI_FAILURE (Status))
223     {
224         return_ACPI_STATUS (Status);
225     }
226 
227     if (Value != 1)
228     {
229         ACPI_ERROR ((AE_INFO,
230             "Could not enable %s event", AcpiUtGetEventName (Event)));
231         return_ACPI_STATUS (AE_NO_HARDWARE_RESPONSE);
232     }
233 
234     return_ACPI_STATUS (Status);
235 }
236 
237 ACPI_EXPORT_SYMBOL (AcpiEnableEvent)
238 
239 
240 /*******************************************************************************
241  *
242  * FUNCTION:    AcpiDisableEvent
243  *
244  * PARAMETERS:  Event           - The fixed event to be disabled
245  *              Flags           - Reserved
246  *
247  * RETURN:      Status
248  *
249  * DESCRIPTION: Disable an ACPI event (fixed)
250  *
251  ******************************************************************************/
252 
253 ACPI_STATUS
254 AcpiDisableEvent (
255     UINT32                  Event,
256     UINT32                  Flags)
257 {
258     ACPI_STATUS             Status = AE_OK;
259     UINT32                  Value;
260 
261 
262     ACPI_FUNCTION_TRACE (AcpiDisableEvent);
263 
264 
265     /* Decode the Fixed Event */
266 
267     if (Event > ACPI_EVENT_MAX)
268     {
269         return_ACPI_STATUS (AE_BAD_PARAMETER);
270     }
271 
272     /*
273      * Disable the requested fixed event (by writing a zero to the enable
274      * register bit)
275      */
276     Status = AcpiWriteBitRegister (
277                 AcpiGbl_FixedEventInfo[Event].EnableRegisterId,
278                 ACPI_DISABLE_EVENT);
279     if (ACPI_FAILURE (Status))
280     {
281         return_ACPI_STATUS (Status);
282     }
283 
284     Status = AcpiReadBitRegister (
285                 AcpiGbl_FixedEventInfo[Event].EnableRegisterId, &Value);
286     if (ACPI_FAILURE (Status))
287     {
288         return_ACPI_STATUS (Status);
289     }
290 
291     if (Value != 0)
292     {
293         ACPI_ERROR ((AE_INFO,
294             "Could not disable %s events", AcpiUtGetEventName (Event)));
295         return_ACPI_STATUS (AE_NO_HARDWARE_RESPONSE);
296     }
297 
298     return_ACPI_STATUS (Status);
299 }
300 
301 ACPI_EXPORT_SYMBOL (AcpiDisableEvent)
302 
303 
304 /*******************************************************************************
305  *
306  * FUNCTION:    AcpiClearEvent
307  *
308  * PARAMETERS:  Event           - The fixed event to be cleared
309  *
310  * RETURN:      Status
311  *
312  * DESCRIPTION: Clear an ACPI event (fixed)
313  *
314  ******************************************************************************/
315 
316 ACPI_STATUS
317 AcpiClearEvent (
318     UINT32                  Event)
319 {
320     ACPI_STATUS             Status = AE_OK;
321 
322 
323     ACPI_FUNCTION_TRACE (AcpiClearEvent);
324 
325 
326     /* Decode the Fixed Event */
327 
328     if (Event > ACPI_EVENT_MAX)
329     {
330         return_ACPI_STATUS (AE_BAD_PARAMETER);
331     }
332 
333     /*
334      * Clear the requested fixed event (By writing a one to the status
335      * register bit)
336      */
337     Status = AcpiWriteBitRegister (
338                 AcpiGbl_FixedEventInfo[Event].StatusRegisterId,
339                 ACPI_CLEAR_STATUS);
340 
341     return_ACPI_STATUS (Status);
342 }
343 
344 ACPI_EXPORT_SYMBOL (AcpiClearEvent)
345 
346 
347 /*******************************************************************************
348  *
349  * FUNCTION:    AcpiGetEventStatus
350  *
351  * PARAMETERS:  Event           - The fixed event
352  *              EventStatus     - Where the current status of the event will
353  *                                be returned
354  *
355  * RETURN:      Status
356  *
357  * DESCRIPTION: Obtains and returns the current status of the event
358  *
359  ******************************************************************************/
360 
361 ACPI_STATUS
362 AcpiGetEventStatus (
363     UINT32                  Event,
364     ACPI_EVENT_STATUS       *EventStatus)
365 {
366     ACPI_STATUS             Status;
367     ACPI_EVENT_STATUS       LocalEventStatus = 0;
368     UINT32                  InByte;
369 
370 
371     ACPI_FUNCTION_TRACE (AcpiGetEventStatus);
372 
373 
374     if (!EventStatus)
375     {
376         return_ACPI_STATUS (AE_BAD_PARAMETER);
377     }
378 
379     /* Decode the Fixed Event */
380 
381     if (Event > ACPI_EVENT_MAX)
382     {
383         return_ACPI_STATUS (AE_BAD_PARAMETER);
384     }
385 
386     /* Fixed event currently can be dispatched? */
387 
388     if (AcpiGbl_FixedEventHandlers[Event].Handler)
389     {
390         LocalEventStatus |= ACPI_EVENT_FLAG_HAS_HANDLER;
391     }
392 
393     /* Fixed event currently enabled? */
394 
395     Status = AcpiReadBitRegister (
396                 AcpiGbl_FixedEventInfo[Event].EnableRegisterId, &InByte);
397     if (ACPI_FAILURE (Status))
398     {
399         return_ACPI_STATUS (Status);
400     }
401 
402     if (InByte)
403     {
404         LocalEventStatus |=
405             (ACPI_EVENT_FLAG_ENABLED | ACPI_EVENT_FLAG_ENABLE_SET);
406     }
407 
408     /* Fixed event currently active? */
409 
410     Status = AcpiReadBitRegister (
411                 AcpiGbl_FixedEventInfo[Event].StatusRegisterId, &InByte);
412     if (ACPI_FAILURE (Status))
413     {
414         return_ACPI_STATUS (Status);
415     }
416 
417     if (InByte)
418     {
419         LocalEventStatus |= ACPI_EVENT_FLAG_STATUS_SET;
420     }
421 
422     (*EventStatus) = LocalEventStatus;
423     return_ACPI_STATUS (AE_OK);
424 }
425 
426 ACPI_EXPORT_SYMBOL (AcpiGetEventStatus)
427 
428 #endif /* !ACPI_REDUCED_HARDWARE */
429