1 /******************************************************************************
3 * Module Name: evxfevnt - External Interfaces, ACPI event disable/enable
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2015, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
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.
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.
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.
44 #define EXPORT_ACPI_INTERFACES
46 #include <contrib/dev/acpica/include/acpi.h>
47 #include <contrib/dev/acpica/include/accommon.h>
48 #include <contrib/dev/acpica/include/actables.h>
50 #define _COMPONENT ACPI_EVENTS
51 ACPI_MODULE_NAME ("evxfevnt")
54 #if (!ACPI_REDUCED_HARDWARE) /* Entire module */
55 /*******************************************************************************
57 * FUNCTION: AcpiEnable
63 * DESCRIPTION: Transfers the system into ACPI mode.
65 ******************************************************************************/
71 ACPI_STATUS Status = AE_OK;
74 ACPI_FUNCTION_TRACE (AcpiEnable);
77 /* ACPI tables must be present */
79 if (!AcpiTbTablesLoaded ())
81 return_ACPI_STATUS (AE_NO_ACPI_TABLES);
84 /* If the Hardware Reduced flag is set, machine is always in acpi mode */
86 if (AcpiGbl_ReducedHardware)
88 return_ACPI_STATUS (AE_OK);
91 /* Check current mode */
93 if (AcpiHwGetMode() == ACPI_SYS_MODE_ACPI)
95 ACPI_DEBUG_PRINT ((ACPI_DB_INIT, "System is already in ACPI mode\n"));
99 /* Transition to ACPI mode */
101 Status = AcpiHwSetMode (ACPI_SYS_MODE_ACPI);
102 if (ACPI_FAILURE (Status))
104 ACPI_ERROR ((AE_INFO, "Could not transition to ACPI mode"));
105 return_ACPI_STATUS (Status);
108 ACPI_DEBUG_PRINT ((ACPI_DB_INIT,
109 "Transition to ACPI mode successful\n"));
112 return_ACPI_STATUS (Status);
115 ACPI_EXPORT_SYMBOL (AcpiEnable)
118 /*******************************************************************************
120 * FUNCTION: AcpiDisable
126 * DESCRIPTION: Transfers the system into LEGACY (non-ACPI) mode.
128 ******************************************************************************/
134 ACPI_STATUS Status = AE_OK;
137 ACPI_FUNCTION_TRACE (AcpiDisable);
140 /* If the Hardware Reduced flag is set, machine is always in acpi mode */
142 if (AcpiGbl_ReducedHardware)
144 return_ACPI_STATUS (AE_OK);
147 if (AcpiHwGetMode() == ACPI_SYS_MODE_LEGACY)
149 ACPI_DEBUG_PRINT ((ACPI_DB_INIT,
150 "System is already in legacy (non-ACPI) mode\n"));
154 /* Transition to LEGACY mode */
156 Status = AcpiHwSetMode (ACPI_SYS_MODE_LEGACY);
158 if (ACPI_FAILURE (Status))
160 ACPI_ERROR ((AE_INFO,
161 "Could not exit ACPI mode to legacy mode"));
162 return_ACPI_STATUS (Status);
165 ACPI_DEBUG_PRINT ((ACPI_DB_INIT, "ACPI mode disabled\n"));
168 return_ACPI_STATUS (Status);
171 ACPI_EXPORT_SYMBOL (AcpiDisable)
174 /*******************************************************************************
176 * FUNCTION: AcpiEnableEvent
178 * PARAMETERS: Event - The fixed eventto be enabled
183 * DESCRIPTION: Enable an ACPI event (fixed)
185 ******************************************************************************/
192 ACPI_STATUS Status = AE_OK;
196 ACPI_FUNCTION_TRACE (AcpiEnableEvent);
199 /* Decode the Fixed Event */
201 if (Event > ACPI_EVENT_MAX)
203 return_ACPI_STATUS (AE_BAD_PARAMETER);
207 * Enable the requested fixed event (by writing a one to the enable
210 Status = AcpiWriteBitRegister (
211 AcpiGbl_FixedEventInfo[Event].EnableRegisterId,
213 if (ACPI_FAILURE (Status))
215 return_ACPI_STATUS (Status);
218 /* Make sure that the hardware responded */
220 Status = AcpiReadBitRegister (
221 AcpiGbl_FixedEventInfo[Event].EnableRegisterId, &Value);
222 if (ACPI_FAILURE (Status))
224 return_ACPI_STATUS (Status);
229 ACPI_ERROR ((AE_INFO,
230 "Could not enable %s event", AcpiUtGetEventName (Event)));
231 return_ACPI_STATUS (AE_NO_HARDWARE_RESPONSE);
234 return_ACPI_STATUS (Status);
237 ACPI_EXPORT_SYMBOL (AcpiEnableEvent)
240 /*******************************************************************************
242 * FUNCTION: AcpiDisableEvent
244 * PARAMETERS: Event - The fixed event to be disabled
249 * DESCRIPTION: Disable an ACPI event (fixed)
251 ******************************************************************************/
258 ACPI_STATUS Status = AE_OK;
262 ACPI_FUNCTION_TRACE (AcpiDisableEvent);
265 /* Decode the Fixed Event */
267 if (Event > ACPI_EVENT_MAX)
269 return_ACPI_STATUS (AE_BAD_PARAMETER);
273 * Disable the requested fixed event (by writing a zero to the enable
276 Status = AcpiWriteBitRegister (
277 AcpiGbl_FixedEventInfo[Event].EnableRegisterId,
279 if (ACPI_FAILURE (Status))
281 return_ACPI_STATUS (Status);
284 Status = AcpiReadBitRegister (
285 AcpiGbl_FixedEventInfo[Event].EnableRegisterId, &Value);
286 if (ACPI_FAILURE (Status))
288 return_ACPI_STATUS (Status);
293 ACPI_ERROR ((AE_INFO,
294 "Could not disable %s events", AcpiUtGetEventName (Event)));
295 return_ACPI_STATUS (AE_NO_HARDWARE_RESPONSE);
298 return_ACPI_STATUS (Status);
301 ACPI_EXPORT_SYMBOL (AcpiDisableEvent)
304 /*******************************************************************************
306 * FUNCTION: AcpiClearEvent
308 * PARAMETERS: Event - The fixed event to be cleared
312 * DESCRIPTION: Clear an ACPI event (fixed)
314 ******************************************************************************/
320 ACPI_STATUS Status = AE_OK;
323 ACPI_FUNCTION_TRACE (AcpiClearEvent);
326 /* Decode the Fixed Event */
328 if (Event > ACPI_EVENT_MAX)
330 return_ACPI_STATUS (AE_BAD_PARAMETER);
334 * Clear the requested fixed event (By writing a one to the status
337 Status = AcpiWriteBitRegister (
338 AcpiGbl_FixedEventInfo[Event].StatusRegisterId,
341 return_ACPI_STATUS (Status);
344 ACPI_EXPORT_SYMBOL (AcpiClearEvent)
347 /*******************************************************************************
349 * FUNCTION: AcpiGetEventStatus
351 * PARAMETERS: Event - The fixed event
352 * EventStatus - Where the current status of the event will
357 * DESCRIPTION: Obtains and returns the current status of the event
359 ******************************************************************************/
364 ACPI_EVENT_STATUS *EventStatus)
367 ACPI_EVENT_STATUS LocalEventStatus = 0;
371 ACPI_FUNCTION_TRACE (AcpiGetEventStatus);
376 return_ACPI_STATUS (AE_BAD_PARAMETER);
379 /* Decode the Fixed Event */
381 if (Event > ACPI_EVENT_MAX)
383 return_ACPI_STATUS (AE_BAD_PARAMETER);
386 /* Fixed event currently can be dispatched? */
388 if (AcpiGbl_FixedEventHandlers[Event].Handler)
390 LocalEventStatus |= ACPI_EVENT_FLAG_HAS_HANDLER;
393 /* Fixed event currently enabled? */
395 Status = AcpiReadBitRegister (
396 AcpiGbl_FixedEventInfo[Event].EnableRegisterId, &InByte);
397 if (ACPI_FAILURE (Status))
399 return_ACPI_STATUS (Status);
405 (ACPI_EVENT_FLAG_ENABLED | ACPI_EVENT_FLAG_ENABLE_SET);
408 /* Fixed event currently active? */
410 Status = AcpiReadBitRegister (
411 AcpiGbl_FixedEventInfo[Event].StatusRegisterId, &InByte);
412 if (ACPI_FAILURE (Status))
414 return_ACPI_STATUS (Status);
419 LocalEventStatus |= ACPI_EVENT_FLAG_STATUS_SET;
422 (*EventStatus) = LocalEventStatus;
423 return_ACPI_STATUS (AE_OK);
426 ACPI_EXPORT_SYMBOL (AcpiGetEventStatus)
428 #endif /* !ACPI_REDUCED_HARDWARE */