1 // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
2 /******************************************************************************
4 * Module Name: evxfevnt - External Interfaces, ACPI event disable/enable
6 * Copyright (C) 2000 - 2020, Intel Corp.
8 *****************************************************************************/
10 #define EXPORT_ACPI_INTERFACES
12 #include <acpi/acpi.h>
16 #define _COMPONENT ACPI_EVENTS
17 ACPI_MODULE_NAME("evxfevnt")
19 #if (!ACPI_REDUCED_HARDWARE) /* Entire module */
20 /*******************************************************************************
22 * FUNCTION: acpi_enable
28 * DESCRIPTION: Transfers the system into ACPI mode.
30 ******************************************************************************/
31 acpi_status
acpi_enable(void)
36 ACPI_FUNCTION_TRACE(acpi_enable
);
38 /* ACPI tables must be present */
40 if (acpi_gbl_fadt_index
== ACPI_INVALID_TABLE_INDEX
) {
41 return_ACPI_STATUS(AE_NO_ACPI_TABLES
);
44 /* If the Hardware Reduced flag is set, machine is always in acpi mode */
46 if (acpi_gbl_reduced_hardware
) {
47 return_ACPI_STATUS(AE_OK
);
50 /* Check current mode */
52 if (acpi_hw_get_mode() == ACPI_SYS_MODE_ACPI
) {
53 ACPI_DEBUG_PRINT((ACPI_DB_INIT
,
54 "System is already in ACPI mode\n"));
55 return_ACPI_STATUS(AE_OK
);
58 /* Transition to ACPI mode */
60 status
= acpi_hw_set_mode(ACPI_SYS_MODE_ACPI
);
61 if (ACPI_FAILURE(status
)) {
63 "Could not transition to ACPI mode"));
64 return_ACPI_STATUS(status
);
67 /* Sanity check that transition succeeded */
69 for (retry
= 0; retry
< 30000; ++retry
) {
70 if (acpi_hw_get_mode() == ACPI_SYS_MODE_ACPI
) {
72 ACPI_WARNING((AE_INFO
,
73 "Platform took > %d00 usec to enter ACPI mode", retry
));
74 return_ACPI_STATUS(AE_OK
);
76 acpi_os_stall(100); /* 100 usec */
79 ACPI_ERROR((AE_INFO
, "Hardware did not enter ACPI mode"));
80 return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE
);
83 ACPI_EXPORT_SYMBOL(acpi_enable
)
85 /*******************************************************************************
87 * FUNCTION: acpi_disable
93 * DESCRIPTION: Transfers the system into LEGACY (non-ACPI) mode.
95 ******************************************************************************/
96 acpi_status
acpi_disable(void)
98 acpi_status status
= AE_OK
;
100 ACPI_FUNCTION_TRACE(acpi_disable
);
102 /* If the Hardware Reduced flag is set, machine is always in acpi mode */
104 if (acpi_gbl_reduced_hardware
) {
105 return_ACPI_STATUS(AE_OK
);
108 if (acpi_hw_get_mode() == ACPI_SYS_MODE_LEGACY
) {
109 ACPI_DEBUG_PRINT((ACPI_DB_INIT
,
110 "System is already in legacy (non-ACPI) mode\n"));
112 /* Transition to LEGACY mode */
114 status
= acpi_hw_set_mode(ACPI_SYS_MODE_LEGACY
);
116 if (ACPI_FAILURE(status
)) {
118 "Could not exit ACPI mode to legacy mode"));
119 return_ACPI_STATUS(status
);
122 ACPI_DEBUG_PRINT((ACPI_DB_INIT
, "ACPI mode disabled\n"));
125 return_ACPI_STATUS(status
);
128 ACPI_EXPORT_SYMBOL(acpi_disable
)
130 /*******************************************************************************
132 * FUNCTION: acpi_enable_event
134 * PARAMETERS: event - The fixed eventto be enabled
139 * DESCRIPTION: Enable an ACPI event (fixed)
141 ******************************************************************************/
142 acpi_status
acpi_enable_event(u32 event
, u32 flags
)
144 acpi_status status
= AE_OK
;
147 ACPI_FUNCTION_TRACE(acpi_enable_event
);
149 /* If Hardware Reduced flag is set, there are no fixed events */
151 if (acpi_gbl_reduced_hardware
) {
152 return_ACPI_STATUS(AE_OK
);
155 /* Decode the Fixed Event */
157 if (event
> ACPI_EVENT_MAX
) {
158 return_ACPI_STATUS(AE_BAD_PARAMETER
);
162 * Enable the requested fixed event (by writing a one to the enable
166 acpi_write_bit_register(acpi_gbl_fixed_event_info
[event
].
167 enable_register_id
, ACPI_ENABLE_EVENT
);
168 if (ACPI_FAILURE(status
)) {
169 return_ACPI_STATUS(status
);
172 /* Make sure that the hardware responded */
175 acpi_read_bit_register(acpi_gbl_fixed_event_info
[event
].
176 enable_register_id
, &value
);
177 if (ACPI_FAILURE(status
)) {
178 return_ACPI_STATUS(status
);
183 "Could not enable %s event",
184 acpi_ut_get_event_name(event
)));
185 return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE
);
188 return_ACPI_STATUS(status
);
191 ACPI_EXPORT_SYMBOL(acpi_enable_event
)
193 /*******************************************************************************
195 * FUNCTION: acpi_disable_event
197 * PARAMETERS: event - The fixed event to be disabled
202 * DESCRIPTION: Disable an ACPI event (fixed)
204 ******************************************************************************/
205 acpi_status
acpi_disable_event(u32 event
, u32 flags
)
207 acpi_status status
= AE_OK
;
210 ACPI_FUNCTION_TRACE(acpi_disable_event
);
212 /* If Hardware Reduced flag is set, there are no fixed events */
214 if (acpi_gbl_reduced_hardware
) {
215 return_ACPI_STATUS(AE_OK
);
218 /* Decode the Fixed Event */
220 if (event
> ACPI_EVENT_MAX
) {
221 return_ACPI_STATUS(AE_BAD_PARAMETER
);
225 * Disable the requested fixed event (by writing a zero to the enable
229 acpi_write_bit_register(acpi_gbl_fixed_event_info
[event
].
230 enable_register_id
, ACPI_DISABLE_EVENT
);
231 if (ACPI_FAILURE(status
)) {
232 return_ACPI_STATUS(status
);
236 acpi_read_bit_register(acpi_gbl_fixed_event_info
[event
].
237 enable_register_id
, &value
);
238 if (ACPI_FAILURE(status
)) {
239 return_ACPI_STATUS(status
);
244 "Could not disable %s events",
245 acpi_ut_get_event_name(event
)));
246 return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE
);
249 return_ACPI_STATUS(status
);
252 ACPI_EXPORT_SYMBOL(acpi_disable_event
)
254 /*******************************************************************************
256 * FUNCTION: acpi_clear_event
258 * PARAMETERS: event - The fixed event to be cleared
262 * DESCRIPTION: Clear an ACPI event (fixed)
264 ******************************************************************************/
265 acpi_status
acpi_clear_event(u32 event
)
267 acpi_status status
= AE_OK
;
269 ACPI_FUNCTION_TRACE(acpi_clear_event
);
271 /* If Hardware Reduced flag is set, there are no fixed events */
273 if (acpi_gbl_reduced_hardware
) {
274 return_ACPI_STATUS(AE_OK
);
277 /* Decode the Fixed Event */
279 if (event
> ACPI_EVENT_MAX
) {
280 return_ACPI_STATUS(AE_BAD_PARAMETER
);
284 * Clear the requested fixed event (By writing a one to the status
288 acpi_write_bit_register(acpi_gbl_fixed_event_info
[event
].
289 status_register_id
, ACPI_CLEAR_STATUS
);
291 return_ACPI_STATUS(status
);
294 ACPI_EXPORT_SYMBOL(acpi_clear_event
)
296 /*******************************************************************************
298 * FUNCTION: acpi_get_event_status
300 * PARAMETERS: event - The fixed event
301 * event_status - Where the current status of the event will
306 * DESCRIPTION: Obtains and returns the current status of the event
308 ******************************************************************************/
309 acpi_status
acpi_get_event_status(u32 event
, acpi_event_status
* event_status
)
312 acpi_event_status local_event_status
= 0;
315 ACPI_FUNCTION_TRACE(acpi_get_event_status
);
318 return_ACPI_STATUS(AE_BAD_PARAMETER
);
321 /* Decode the Fixed Event */
323 if (event
> ACPI_EVENT_MAX
) {
324 return_ACPI_STATUS(AE_BAD_PARAMETER
);
327 /* Fixed event currently can be dispatched? */
329 if (acpi_gbl_fixed_event_handlers
[event
].handler
) {
330 local_event_status
|= ACPI_EVENT_FLAG_HAS_HANDLER
;
333 /* Fixed event currently enabled? */
336 acpi_read_bit_register(acpi_gbl_fixed_event_info
[event
].
337 enable_register_id
, &in_byte
);
338 if (ACPI_FAILURE(status
)) {
339 return_ACPI_STATUS(status
);
343 local_event_status
|=
344 (ACPI_EVENT_FLAG_ENABLED
| ACPI_EVENT_FLAG_ENABLE_SET
);
347 /* Fixed event currently active? */
350 acpi_read_bit_register(acpi_gbl_fixed_event_info
[event
].
351 status_register_id
, &in_byte
);
352 if (ACPI_FAILURE(status
)) {
353 return_ACPI_STATUS(status
);
357 local_event_status
|= ACPI_EVENT_FLAG_STATUS_SET
;
360 (*event_status
) = local_event_status
;
361 return_ACPI_STATUS(AE_OK
);
364 ACPI_EXPORT_SYMBOL(acpi_get_event_status
)
365 #endif /* !ACPI_REDUCED_HARDWARE */