ACPICA: Additional 2016 copyright changes
[deliverable/linux.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/*
c8100dc4 8 * Copyright (C) 2000 - 2016, 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
LT
182
183 /* Decode the Fixed Event */
184
185 if (event > ACPI_EVENT_MAX) {
4be44fcd 186 return_ACPI_STATUS(AE_BAD_PARAMETER);
1da177e4
LT
187 }
188
189 /*
9f15fc66
BM
190 * Enable the requested fixed event (by writing a one to the enable
191 * register bit)
1da177e4 192 */
4be44fcd 193 status =
50ffba1b 194 acpi_write_bit_register(acpi_gbl_fixed_event_info[event].
768aaaf1 195 enable_register_id, ACPI_ENABLE_EVENT);
4be44fcd
LB
196 if (ACPI_FAILURE(status)) {
197 return_ACPI_STATUS(status);
1da177e4
LT
198 }
199
200 /* Make sure that the hardware responded */
201
4be44fcd 202 status =
50ffba1b
BM
203 acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
204 enable_register_id, &value);
4be44fcd
LB
205 if (ACPI_FAILURE(status)) {
206 return_ACPI_STATUS(status);
1da177e4
LT
207 }
208
209 if (value != 1) {
b8e4d893
BM
210 ACPI_ERROR((AE_INFO,
211 "Could not enable %s event",
212 acpi_ut_get_event_name(event)));
4be44fcd 213 return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);
1da177e4
LT
214 }
215
4be44fcd 216 return_ACPI_STATUS(status);
1da177e4 217}
1da177e4 218
8313524a 219ACPI_EXPORT_SYMBOL(acpi_enable_event)
1da177e4 220
1da177e4
LT
221/*******************************************************************************
222 *
223 * FUNCTION: acpi_disable_event
224 *
75c8044f
LZ
225 * PARAMETERS: event - The fixed event to be disabled
226 * flags - Reserved
1da177e4
LT
227 *
228 * RETURN: Status
229 *
230 * DESCRIPTION: Disable an ACPI event (fixed)
231 *
232 ******************************************************************************/
4be44fcd 233acpi_status acpi_disable_event(u32 event, u32 flags)
1da177e4 234{
4be44fcd
LB
235 acpi_status status = AE_OK;
236 u32 value;
1da177e4 237
b229cf92 238 ACPI_FUNCTION_TRACE(acpi_disable_event);
1da177e4
LT
239
240 /* Decode the Fixed Event */
241
242 if (event > ACPI_EVENT_MAX) {
4be44fcd 243 return_ACPI_STATUS(AE_BAD_PARAMETER);
1da177e4
LT
244 }
245
246 /*
9f15fc66
BM
247 * Disable the requested fixed event (by writing a zero to the enable
248 * register bit)
1da177e4 249 */
4be44fcd 250 status =
50ffba1b 251 acpi_write_bit_register(acpi_gbl_fixed_event_info[event].
768aaaf1 252 enable_register_id, ACPI_DISABLE_EVENT);
4be44fcd
LB
253 if (ACPI_FAILURE(status)) {
254 return_ACPI_STATUS(status);
1da177e4
LT
255 }
256
4be44fcd 257 status =
50ffba1b
BM
258 acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
259 enable_register_id, &value);
4be44fcd
LB
260 if (ACPI_FAILURE(status)) {
261 return_ACPI_STATUS(status);
1da177e4
LT
262 }
263
264 if (value != 0) {
b8e4d893
BM
265 ACPI_ERROR((AE_INFO,
266 "Could not disable %s events",
267 acpi_ut_get_event_name(event)));
4be44fcd 268 return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);
1da177e4
LT
269 }
270
4be44fcd 271 return_ACPI_STATUS(status);
1da177e4 272}
1da177e4 273
8313524a 274ACPI_EXPORT_SYMBOL(acpi_disable_event)
1da177e4
LT
275
276/*******************************************************************************
277 *
278 * FUNCTION: acpi_clear_event
279 *
ba494bee 280 * PARAMETERS: event - The fixed event to be cleared
1da177e4
LT
281 *
282 * RETURN: Status
283 *
284 * DESCRIPTION: Clear an ACPI event (fixed)
285 *
286 ******************************************************************************/
4be44fcd 287acpi_status acpi_clear_event(u32 event)
1da177e4 288{
4be44fcd 289 acpi_status status = AE_OK;
1da177e4 290
b229cf92 291 ACPI_FUNCTION_TRACE(acpi_clear_event);
1da177e4
LT
292
293 /* Decode the Fixed Event */
294
295 if (event > ACPI_EVENT_MAX) {
4be44fcd 296 return_ACPI_STATUS(AE_BAD_PARAMETER);
1da177e4
LT
297 }
298
299 /*
9f15fc66
BM
300 * Clear the requested fixed event (By writing a one to the status
301 * register bit)
1da177e4 302 */
4be44fcd 303 status =
50ffba1b 304 acpi_write_bit_register(acpi_gbl_fixed_event_info[event].
768aaaf1 305 status_register_id, ACPI_CLEAR_STATUS);
1da177e4 306
4be44fcd 307 return_ACPI_STATUS(status);
1da177e4 308}
1da177e4 309
8313524a 310ACPI_EXPORT_SYMBOL(acpi_clear_event)
1da177e4 311
1da177e4
LT
312/*******************************************************************************
313 *
314 * FUNCTION: acpi_get_event_status
315 *
ba494bee 316 * PARAMETERS: event - The fixed event
44f6c012 317 * event_status - Where the current status of the event will
1da177e4
LT
318 * be returned
319 *
320 * RETURN: Status
321 *
322 * DESCRIPTION: Obtains and returns the current status of the event
323 *
324 ******************************************************************************/
4be44fcd 325acpi_status acpi_get_event_status(u32 event, acpi_event_status * event_status)
1da177e4 326{
a08f813e
LZ
327 acpi_status status;
328 acpi_event_status local_event_status = 0;
329 u32 in_byte;
1da177e4 330
b229cf92 331 ACPI_FUNCTION_TRACE(acpi_get_event_status);
1da177e4
LT
332
333 if (!event_status) {
4be44fcd 334 return_ACPI_STATUS(AE_BAD_PARAMETER);
1da177e4
LT
335 }
336
337 /* Decode the Fixed Event */
338
339 if (event > ACPI_EVENT_MAX) {
4be44fcd 340 return_ACPI_STATUS(AE_BAD_PARAMETER);
1da177e4
LT
341 }
342
a08f813e
LZ
343 /* Fixed event currently can be dispatched? */
344
345 if (acpi_gbl_fixed_event_handlers[event].handler) {
2f857234 346 local_event_status |= ACPI_EVENT_FLAG_HAS_HANDLER;
a08f813e
LZ
347 }
348
349 /* Fixed event currently enabled? */
1da177e4 350
4be44fcd 351 status =
50ffba1b 352 acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
a08f813e
LZ
353 enable_register_id, &in_byte);
354 if (ACPI_FAILURE(status)) {
71b58cbb 355 return_ACPI_STATUS(status);
a08f813e 356 }
71b58cbb 357
a08f813e 358 if (in_byte) {
09af8e82
LZ
359 local_event_status |=
360 (ACPI_EVENT_FLAG_ENABLED | ACPI_EVENT_FLAG_ENABLE_SET);
a08f813e
LZ
361 }
362
363 /* Fixed event currently active? */
71b58cbb
ZR
364
365 status =
50ffba1b 366 acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
a08f813e
LZ
367 status_register_id, &in_byte);
368 if (ACPI_FAILURE(status)) {
71b58cbb 369 return_ACPI_STATUS(status);
a08f813e 370 }
71b58cbb 371
a08f813e 372 if (in_byte) {
09af8e82 373 local_event_status |= ACPI_EVENT_FLAG_STATUS_SET;
a08f813e 374 }
ed206fac 375
a08f813e
LZ
376 (*event_status) = local_event_status;
377 return_ACPI_STATUS(AE_OK);
1da177e4
LT
378}
379
8313524a 380ACPI_EXPORT_SYMBOL(acpi_get_event_status)
33620c54 381#endif /* !ACPI_REDUCED_HARDWARE */
This page took 0.693161 seconds and 5 git commands to generate.