ACPICA: adding SPDX headers
[linux-2.6-block.git] / drivers / acpi / acpica / evxfevnt.c
CommitLineData
95857638 1// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
1da177e4
LT
2/******************************************************************************
3 *
4 * Module Name: evxfevnt - External Interfaces, ACPI event disable/enable
5 *
da6f8320 6 * Copyright (C) 2000 - 2018, Intel Corp.
1da177e4 7 *
95857638 8 *****************************************************************************/
1da177e4 9
839e928f
LZ
10#define EXPORT_ACPI_INTERFACES
11
1da177e4 12#include <acpi/acpi.h>
e2f7a777 13#include "accommon.h"
e2f7a777 14#include "actables.h"
1da177e4
LT
15
16#define _COMPONENT ACPI_EVENTS
4be44fcd 17ACPI_MODULE_NAME("evxfevnt")
1da177e4 18
33620c54 19#if (!ACPI_REDUCED_HARDWARE) /* Entire module */
1da177e4
LT
20/*******************************************************************************
21 *
22 * FUNCTION: acpi_enable
23 *
24 * PARAMETERS: None
25 *
26 * RETURN: Status
27 *
28 * DESCRIPTION: Transfers the system into ACPI mode.
29 *
30 ******************************************************************************/
4be44fcd 31acpi_status acpi_enable(void)
1da177e4 32{
b430acbd 33 acpi_status status;
3d695839 34 int retry;
1da177e4 35
b229cf92 36 ACPI_FUNCTION_TRACE(acpi_enable);
1da177e4 37
c857303a
BM
38 /* ACPI tables must be present */
39
62fcce91 40 if (acpi_gbl_fadt_index == ACPI_INVALID_TABLE_INDEX) {
c857303a
BM
41 return_ACPI_STATUS(AE_NO_ACPI_TABLES);
42 }
43
c39660b2
BM
44 /* If the Hardware Reduced flag is set, machine is always in acpi mode */
45
46 if (acpi_gbl_reduced_hardware) {
47 return_ACPI_STATUS(AE_OK);
48 }
49
c857303a
BM
50 /* Check current mode */
51
1da177e4 52 if (acpi_hw_get_mode() == ACPI_SYS_MODE_ACPI) {
4be44fcd
LB
53 ACPI_DEBUG_PRINT((ACPI_DB_INIT,
54 "System is already in ACPI mode\n"));
b430acbd
LB
55 return_ACPI_STATUS(AE_OK);
56 }
1da177e4 57
b430acbd 58 /* Transition to ACPI mode */
1da177e4 59
b430acbd
LB
60 status = acpi_hw_set_mode(ACPI_SYS_MODE_ACPI);
61 if (ACPI_FAILURE(status)) {
62 ACPI_ERROR((AE_INFO,
63 "Could not transition to ACPI mode"));
64 return_ACPI_STATUS(status);
65 }
66
67 /* Sanity check that transition succeeded */
68
3d695839
LB
69 for (retry = 0; retry < 30000; ++retry) {
70 if (acpi_hw_get_mode() == ACPI_SYS_MODE_ACPI) {
71 if (retry != 0)
72 ACPI_WARNING((AE_INFO,
73 "Platform took > %d00 usec to enter ACPI mode", retry));
74 return_ACPI_STATUS(AE_OK);
75 }
76 acpi_os_stall(100); /* 100 usec */
1da177e4
LT
77 }
78
3d695839
LB
79 ACPI_ERROR((AE_INFO, "Hardware did not enter ACPI mode"));
80 return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);
1da177e4
LT
81}
82
8313524a
BM
83ACPI_EXPORT_SYMBOL(acpi_enable)
84
1da177e4
LT
85/*******************************************************************************
86 *
87 * FUNCTION: acpi_disable
88 *
89 * PARAMETERS: None
90 *
91 * RETURN: Status
92 *
44f6c012 93 * DESCRIPTION: Transfers the system into LEGACY (non-ACPI) mode.
1da177e4
LT
94 *
95 ******************************************************************************/
4be44fcd 96acpi_status acpi_disable(void)
1da177e4 97{
4be44fcd 98 acpi_status status = AE_OK;
1da177e4 99
b229cf92 100 ACPI_FUNCTION_TRACE(acpi_disable);
1da177e4 101
c39660b2
BM
102 /* If the Hardware Reduced flag is set, machine is always in acpi mode */
103
104 if (acpi_gbl_reduced_hardware) {
105 return_ACPI_STATUS(AE_OK);
106 }
107
1da177e4 108 if (acpi_hw_get_mode() == ACPI_SYS_MODE_LEGACY) {
4be44fcd
LB
109 ACPI_DEBUG_PRINT((ACPI_DB_INIT,
110 "System is already in legacy (non-ACPI) mode\n"));
111 } else {
1da177e4
LT
112 /* Transition to LEGACY mode */
113
4be44fcd 114 status = acpi_hw_set_mode(ACPI_SYS_MODE_LEGACY);
1da177e4 115
4be44fcd 116 if (ACPI_FAILURE(status)) {
b8e4d893
BM
117 ACPI_ERROR((AE_INFO,
118 "Could not exit ACPI mode to legacy mode"));
4be44fcd 119 return_ACPI_STATUS(status);
1da177e4
LT
120 }
121
4be44fcd 122 ACPI_DEBUG_PRINT((ACPI_DB_INIT, "ACPI mode disabled\n"));
1da177e4
LT
123 }
124
4be44fcd 125 return_ACPI_STATUS(status);
1da177e4
LT
126}
127
8313524a
BM
128ACPI_EXPORT_SYMBOL(acpi_disable)
129
1da177e4
LT
130/*******************************************************************************
131 *
132 * FUNCTION: acpi_enable_event
133 *
ba494bee
BM
134 * PARAMETERS: event - The fixed eventto be enabled
135 * flags - Reserved
1da177e4
LT
136 *
137 * RETURN: Status
138 *
139 * DESCRIPTION: Enable an ACPI event (fixed)
140 *
141 ******************************************************************************/
4be44fcd 142acpi_status acpi_enable_event(u32 event, u32 flags)
1da177e4 143{
4be44fcd
LB
144 acpi_status status = AE_OK;
145 u32 value;
1da177e4 146
b229cf92 147 ACPI_FUNCTION_TRACE(acpi_enable_event);
1da177e4 148
861ba635
LZ
149 /* If Hardware Reduced flag is set, there are no fixed events */
150
151 if (acpi_gbl_reduced_hardware) {
152 return_ACPI_STATUS(AE_OK);
153 }
154
1da177e4
LT
155 /* Decode the Fixed Event */
156
157 if (event > ACPI_EVENT_MAX) {
4be44fcd 158 return_ACPI_STATUS(AE_BAD_PARAMETER);
1da177e4
LT
159 }
160
161 /*
9f15fc66
BM
162 * Enable the requested fixed event (by writing a one to the enable
163 * register bit)
1da177e4 164 */
4be44fcd 165 status =
50ffba1b 166 acpi_write_bit_register(acpi_gbl_fixed_event_info[event].
768aaaf1 167 enable_register_id, ACPI_ENABLE_EVENT);
4be44fcd
LB
168 if (ACPI_FAILURE(status)) {
169 return_ACPI_STATUS(status);
1da177e4
LT
170 }
171
172 /* Make sure that the hardware responded */
173
4be44fcd 174 status =
50ffba1b
BM
175 acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
176 enable_register_id, &value);
4be44fcd
LB
177 if (ACPI_FAILURE(status)) {
178 return_ACPI_STATUS(status);
1da177e4
LT
179 }
180
181 if (value != 1) {
b8e4d893
BM
182 ACPI_ERROR((AE_INFO,
183 "Could not enable %s event",
184 acpi_ut_get_event_name(event)));
4be44fcd 185 return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);
1da177e4
LT
186 }
187
4be44fcd 188 return_ACPI_STATUS(status);
1da177e4 189}
1da177e4 190
8313524a 191ACPI_EXPORT_SYMBOL(acpi_enable_event)
1da177e4 192
1da177e4
LT
193/*******************************************************************************
194 *
195 * FUNCTION: acpi_disable_event
196 *
75c8044f
LZ
197 * PARAMETERS: event - The fixed event to be disabled
198 * flags - Reserved
1da177e4
LT
199 *
200 * RETURN: Status
201 *
202 * DESCRIPTION: Disable an ACPI event (fixed)
203 *
204 ******************************************************************************/
4be44fcd 205acpi_status acpi_disable_event(u32 event, u32 flags)
1da177e4 206{
4be44fcd
LB
207 acpi_status status = AE_OK;
208 u32 value;
1da177e4 209
b229cf92 210 ACPI_FUNCTION_TRACE(acpi_disable_event);
1da177e4 211
861ba635
LZ
212 /* If Hardware Reduced flag is set, there are no fixed events */
213
214 if (acpi_gbl_reduced_hardware) {
215 return_ACPI_STATUS(AE_OK);
216 }
217
1da177e4
LT
218 /* Decode the Fixed Event */
219
220 if (event > ACPI_EVENT_MAX) {
4be44fcd 221 return_ACPI_STATUS(AE_BAD_PARAMETER);
1da177e4
LT
222 }
223
224 /*
9f15fc66
BM
225 * Disable the requested fixed event (by writing a zero to the enable
226 * register bit)
1da177e4 227 */
4be44fcd 228 status =
50ffba1b 229 acpi_write_bit_register(acpi_gbl_fixed_event_info[event].
768aaaf1 230 enable_register_id, ACPI_DISABLE_EVENT);
4be44fcd
LB
231 if (ACPI_FAILURE(status)) {
232 return_ACPI_STATUS(status);
1da177e4
LT
233 }
234
4be44fcd 235 status =
50ffba1b
BM
236 acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
237 enable_register_id, &value);
4be44fcd
LB
238 if (ACPI_FAILURE(status)) {
239 return_ACPI_STATUS(status);
1da177e4
LT
240 }
241
242 if (value != 0) {
b8e4d893
BM
243 ACPI_ERROR((AE_INFO,
244 "Could not disable %s events",
245 acpi_ut_get_event_name(event)));
4be44fcd 246 return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);
1da177e4
LT
247 }
248
4be44fcd 249 return_ACPI_STATUS(status);
1da177e4 250}
1da177e4 251
8313524a 252ACPI_EXPORT_SYMBOL(acpi_disable_event)
1da177e4
LT
253
254/*******************************************************************************
255 *
256 * FUNCTION: acpi_clear_event
257 *
ba494bee 258 * PARAMETERS: event - The fixed event to be cleared
1da177e4
LT
259 *
260 * RETURN: Status
261 *
262 * DESCRIPTION: Clear an ACPI event (fixed)
263 *
264 ******************************************************************************/
4be44fcd 265acpi_status acpi_clear_event(u32 event)
1da177e4 266{
4be44fcd 267 acpi_status status = AE_OK;
1da177e4 268
b229cf92 269 ACPI_FUNCTION_TRACE(acpi_clear_event);
1da177e4 270
861ba635
LZ
271 /* If Hardware Reduced flag is set, there are no fixed events */
272
273 if (acpi_gbl_reduced_hardware) {
274 return_ACPI_STATUS(AE_OK);
275 }
276
1da177e4
LT
277 /* Decode the Fixed Event */
278
279 if (event > ACPI_EVENT_MAX) {
4be44fcd 280 return_ACPI_STATUS(AE_BAD_PARAMETER);
1da177e4
LT
281 }
282
283 /*
9f15fc66
BM
284 * Clear the requested fixed event (By writing a one to the status
285 * register bit)
1da177e4 286 */
4be44fcd 287 status =
50ffba1b 288 acpi_write_bit_register(acpi_gbl_fixed_event_info[event].
768aaaf1 289 status_register_id, ACPI_CLEAR_STATUS);
1da177e4 290
4be44fcd 291 return_ACPI_STATUS(status);
1da177e4 292}
1da177e4 293
8313524a 294ACPI_EXPORT_SYMBOL(acpi_clear_event)
1da177e4 295
1da177e4
LT
296/*******************************************************************************
297 *
298 * FUNCTION: acpi_get_event_status
299 *
ba494bee 300 * PARAMETERS: event - The fixed event
44f6c012 301 * event_status - Where the current status of the event will
1da177e4
LT
302 * be returned
303 *
304 * RETURN: Status
305 *
306 * DESCRIPTION: Obtains and returns the current status of the event
307 *
308 ******************************************************************************/
4be44fcd 309acpi_status acpi_get_event_status(u32 event, acpi_event_status * event_status)
1da177e4 310{
a08f813e
LZ
311 acpi_status status;
312 acpi_event_status local_event_status = 0;
313 u32 in_byte;
1da177e4 314
b229cf92 315 ACPI_FUNCTION_TRACE(acpi_get_event_status);
1da177e4
LT
316
317 if (!event_status) {
4be44fcd 318 return_ACPI_STATUS(AE_BAD_PARAMETER);
1da177e4
LT
319 }
320
321 /* Decode the Fixed Event */
322
323 if (event > ACPI_EVENT_MAX) {
4be44fcd 324 return_ACPI_STATUS(AE_BAD_PARAMETER);
1da177e4
LT
325 }
326
a08f813e
LZ
327 /* Fixed event currently can be dispatched? */
328
329 if (acpi_gbl_fixed_event_handlers[event].handler) {
2f857234 330 local_event_status |= ACPI_EVENT_FLAG_HAS_HANDLER;
a08f813e
LZ
331 }
332
333 /* Fixed event currently enabled? */
1da177e4 334
4be44fcd 335 status =
50ffba1b 336 acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
a08f813e
LZ
337 enable_register_id, &in_byte);
338 if (ACPI_FAILURE(status)) {
71b58cbb 339 return_ACPI_STATUS(status);
a08f813e 340 }
71b58cbb 341
a08f813e 342 if (in_byte) {
09af8e82
LZ
343 local_event_status |=
344 (ACPI_EVENT_FLAG_ENABLED | ACPI_EVENT_FLAG_ENABLE_SET);
a08f813e
LZ
345 }
346
347 /* Fixed event currently active? */
71b58cbb
ZR
348
349 status =
50ffba1b 350 acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
a08f813e
LZ
351 status_register_id, &in_byte);
352 if (ACPI_FAILURE(status)) {
71b58cbb 353 return_ACPI_STATUS(status);
a08f813e 354 }
71b58cbb 355
a08f813e 356 if (in_byte) {
09af8e82 357 local_event_status |= ACPI_EVENT_FLAG_STATUS_SET;
a08f813e 358 }
ed206fac 359
a08f813e
LZ
360 (*event_status) = local_event_status;
361 return_ACPI_STATUS(AE_OK);
1da177e4
LT
362}
363
8313524a 364ACPI_EXPORT_SYMBOL(acpi_get_event_status)
33620c54 365#endif /* !ACPI_REDUCED_HARDWARE */