dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / uts / intel / io / acpica / events / evxfevnt.c
blob9991751c679338241ade17ea10eab49aa26c560f
1 /******************************************************************************
3 * Module Name: evxfevnt - External Interfaces, ACPI event disable/enable
5 *****************************************************************************/
7 /*
8 * Copyright (C) 2000 - 2016, Intel Corp.
9 * All rights reserved.
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.
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.
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.
44 #define EXPORT_ACPI_INTERFACES
46 #include "acpi.h"
47 #include "accommon.h"
48 #include "actables.h"
50 #define _COMPONENT ACPI_EVENTS
51 ACPI_MODULE_NAME ("evxfevnt")
54 #if (!ACPI_REDUCED_HARDWARE) /* Entire module */
55 /*******************************************************************************
57 * FUNCTION: AcpiEnable
59 * PARAMETERS: None
61 * RETURN: Status
63 * DESCRIPTION: Transfers the system into ACPI mode.
65 ******************************************************************************/
67 ACPI_STATUS
68 AcpiEnable (
69 void)
71 ACPI_STATUS Status = AE_OK;
74 ACPI_FUNCTION_TRACE (AcpiEnable);
77 /* ACPI tables must be present */
79 if (AcpiGbl_FadtIndex == ACPI_INVALID_TABLE_INDEX)
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,
96 "System is already in ACPI mode\n"));
98 else
100 /* Transition to ACPI mode */
102 Status = AcpiHwSetMode (ACPI_SYS_MODE_ACPI);
103 if (ACPI_FAILURE (Status))
105 ACPI_ERROR ((AE_INFO, "Could not transition to ACPI mode"));
106 return_ACPI_STATUS (Status);
109 ACPI_DEBUG_PRINT ((ACPI_DB_INIT,
110 "Transition to ACPI mode successful\n"));
113 return_ACPI_STATUS (Status);
116 ACPI_EXPORT_SYMBOL (AcpiEnable)
119 /*******************************************************************************
121 * FUNCTION: AcpiDisable
123 * PARAMETERS: None
125 * RETURN: Status
127 * DESCRIPTION: Transfers the system into LEGACY (non-ACPI) mode.
129 ******************************************************************************/
131 ACPI_STATUS
132 AcpiDisable (
133 void)
135 ACPI_STATUS Status = AE_OK;
138 ACPI_FUNCTION_TRACE (AcpiDisable);
141 /* If the Hardware Reduced flag is set, machine is always in acpi mode */
143 if (AcpiGbl_ReducedHardware)
145 return_ACPI_STATUS (AE_OK);
148 if (AcpiHwGetMode() == ACPI_SYS_MODE_LEGACY)
150 ACPI_DEBUG_PRINT ((ACPI_DB_INIT,
151 "System is already in legacy (non-ACPI) mode\n"));
153 else
155 /* Transition to LEGACY mode */
157 Status = AcpiHwSetMode (ACPI_SYS_MODE_LEGACY);
159 if (ACPI_FAILURE (Status))
161 ACPI_ERROR ((AE_INFO,
162 "Could not exit ACPI mode to legacy mode"));
163 return_ACPI_STATUS (Status);
166 ACPI_DEBUG_PRINT ((ACPI_DB_INIT,
167 "ACPI mode disabled\n"));
170 return_ACPI_STATUS (Status);
173 ACPI_EXPORT_SYMBOL (AcpiDisable)
176 /*******************************************************************************
178 * FUNCTION: AcpiEnableEvent
180 * PARAMETERS: Event - The fixed eventto be enabled
181 * Flags - Reserved
183 * RETURN: Status
185 * DESCRIPTION: Enable an ACPI event (fixed)
187 ******************************************************************************/
189 ACPI_STATUS
190 AcpiEnableEvent (
191 UINT32 Event,
192 UINT32 Flags)
194 ACPI_STATUS Status = AE_OK;
195 UINT32 Value;
198 ACPI_FUNCTION_TRACE (AcpiEnableEvent);
201 /* Decode the Fixed Event */
203 if (Event > ACPI_EVENT_MAX)
205 return_ACPI_STATUS (AE_BAD_PARAMETER);
209 * Enable the requested fixed event (by writing a one to the enable
210 * register bit)
212 Status = AcpiWriteBitRegister (
213 AcpiGbl_FixedEventInfo[Event].EnableRegisterId,
214 ACPI_ENABLE_EVENT);
215 if (ACPI_FAILURE (Status))
217 return_ACPI_STATUS (Status);
220 /* Make sure that the hardware responded */
222 Status = AcpiReadBitRegister (
223 AcpiGbl_FixedEventInfo[Event].EnableRegisterId, &Value);
224 if (ACPI_FAILURE (Status))
226 return_ACPI_STATUS (Status);
229 if (Value != 1)
231 ACPI_ERROR ((AE_INFO,
232 "Could not enable %s event", AcpiUtGetEventName (Event)));
233 return_ACPI_STATUS (AE_NO_HARDWARE_RESPONSE);
236 return_ACPI_STATUS (Status);
239 ACPI_EXPORT_SYMBOL (AcpiEnableEvent)
242 /*******************************************************************************
244 * FUNCTION: AcpiDisableEvent
246 * PARAMETERS: Event - The fixed event to be disabled
247 * Flags - Reserved
249 * RETURN: Status
251 * DESCRIPTION: Disable an ACPI event (fixed)
253 ******************************************************************************/
255 ACPI_STATUS
256 AcpiDisableEvent (
257 UINT32 Event,
258 UINT32 Flags)
260 ACPI_STATUS Status = AE_OK;
261 UINT32 Value;
264 ACPI_FUNCTION_TRACE (AcpiDisableEvent);
267 /* Decode the Fixed Event */
269 if (Event > ACPI_EVENT_MAX)
271 return_ACPI_STATUS (AE_BAD_PARAMETER);
275 * Disable the requested fixed event (by writing a zero to the enable
276 * register bit)
278 Status = AcpiWriteBitRegister (
279 AcpiGbl_FixedEventInfo[Event].EnableRegisterId,
280 ACPI_DISABLE_EVENT);
281 if (ACPI_FAILURE (Status))
283 return_ACPI_STATUS (Status);
286 Status = AcpiReadBitRegister (
287 AcpiGbl_FixedEventInfo[Event].EnableRegisterId, &Value);
288 if (ACPI_FAILURE (Status))
290 return_ACPI_STATUS (Status);
293 if (Value != 0)
295 ACPI_ERROR ((AE_INFO,
296 "Could not disable %s events", AcpiUtGetEventName (Event)));
297 return_ACPI_STATUS (AE_NO_HARDWARE_RESPONSE);
300 return_ACPI_STATUS (Status);
303 ACPI_EXPORT_SYMBOL (AcpiDisableEvent)
306 /*******************************************************************************
308 * FUNCTION: AcpiClearEvent
310 * PARAMETERS: Event - The fixed event to be cleared
312 * RETURN: Status
314 * DESCRIPTION: Clear an ACPI event (fixed)
316 ******************************************************************************/
318 ACPI_STATUS
319 AcpiClearEvent (
320 UINT32 Event)
322 ACPI_STATUS Status = AE_OK;
325 ACPI_FUNCTION_TRACE (AcpiClearEvent);
328 /* Decode the Fixed Event */
330 if (Event > ACPI_EVENT_MAX)
332 return_ACPI_STATUS (AE_BAD_PARAMETER);
336 * Clear the requested fixed event (By writing a one to the status
337 * register bit)
339 Status = AcpiWriteBitRegister (
340 AcpiGbl_FixedEventInfo[Event].StatusRegisterId,
341 ACPI_CLEAR_STATUS);
343 return_ACPI_STATUS (Status);
346 ACPI_EXPORT_SYMBOL (AcpiClearEvent)
349 /*******************************************************************************
351 * FUNCTION: AcpiGetEventStatus
353 * PARAMETERS: Event - The fixed event
354 * EventStatus - Where the current status of the event will
355 * be returned
357 * RETURN: Status
359 * DESCRIPTION: Obtains and returns the current status of the event
361 ******************************************************************************/
363 ACPI_STATUS
364 AcpiGetEventStatus (
365 UINT32 Event,
366 ACPI_EVENT_STATUS *EventStatus)
368 ACPI_STATUS Status;
369 ACPI_EVENT_STATUS LocalEventStatus = 0;
370 UINT32 InByte;
373 ACPI_FUNCTION_TRACE (AcpiGetEventStatus);
376 if (!EventStatus)
378 return_ACPI_STATUS (AE_BAD_PARAMETER);
381 /* Decode the Fixed Event */
383 if (Event > ACPI_EVENT_MAX)
385 return_ACPI_STATUS (AE_BAD_PARAMETER);
388 /* Fixed event currently can be dispatched? */
390 if (AcpiGbl_FixedEventHandlers[Event].Handler)
392 LocalEventStatus |= ACPI_EVENT_FLAG_HAS_HANDLER;
395 /* Fixed event currently enabled? */
397 Status = AcpiReadBitRegister (
398 AcpiGbl_FixedEventInfo[Event].EnableRegisterId, &InByte);
399 if (ACPI_FAILURE (Status))
401 return_ACPI_STATUS (Status);
404 if (InByte)
406 LocalEventStatus |=
407 (ACPI_EVENT_FLAG_ENABLED | ACPI_EVENT_FLAG_ENABLE_SET);
410 /* Fixed event currently active? */
412 Status = AcpiReadBitRegister (
413 AcpiGbl_FixedEventInfo[Event].StatusRegisterId, &InByte);
414 if (ACPI_FAILURE (Status))
416 return_ACPI_STATUS (Status);
419 if (InByte)
421 LocalEventStatus |= ACPI_EVENT_FLAG_STATUS_SET;
424 (*EventStatus) = LocalEventStatus;
425 return_ACPI_STATUS (AE_OK);
428 ACPI_EXPORT_SYMBOL (AcpiGetEventStatus)
430 #endif /* !ACPI_REDUCED_HARDWARE */