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