blob: 970e940bdb17f1dde47763e2913c9c57d815b9f6 [file] [log] [blame]
Erik Schmauss95857632018-03-14 16:13:07 -07001// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/******************************************************************************
3 *
4 * Module Name: evxfevnt - External Interfaces, ACPI event disable/enable
5 *
Bob Mooreda6f8322018-01-04 10:06:38 -08006 * Copyright (C) 2000 - 2018, Intel Corp.
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 *
Erik Schmauss95857632018-03-14 16:13:07 -07008 *****************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07009
Lv Zheng839e9282013-10-29 09:29:51 +080010#define EXPORT_ACPI_INTERFACES
11
Linus Torvalds1da177e2005-04-16 15:20:36 -070012#include <acpi/acpi.h>
Len Browne2f7a772009-01-09 00:30:03 -050013#include "accommon.h"
Len Browne2f7a772009-01-09 00:30:03 -050014#include "actables.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070015
16#define _COMPONENT ACPI_EVENTS
Len Brown4be44fc2005-08-05 00:44:28 -040017ACPI_MODULE_NAME("evxfevnt")
Linus Torvalds1da177e2005-04-16 15:20:36 -070018
Bob Moore33620c52012-02-14 18:14:27 +080019#if (!ACPI_REDUCED_HARDWARE) /* Entire module */
Linus Torvalds1da177e2005-04-16 15:20:36 -070020/*******************************************************************************
21 *
22 * FUNCTION: acpi_enable
23 *
24 * PARAMETERS: None
25 *
26 * RETURN: Status
27 *
28 * DESCRIPTION: Transfers the system into ACPI mode.
29 *
30 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -040031acpi_status acpi_enable(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070032{
Len Brownb430acb2010-05-06 17:41:08 -040033 acpi_status status;
Len Brown3d695832010-06-28 20:55:01 -040034 int retry;
Linus Torvalds1da177e2005-04-16 15:20:36 -070035
Bob Mooreb229cf92006-04-21 17:15:00 -040036 ACPI_FUNCTION_TRACE(acpi_enable);
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
Bob Moorec8573032007-02-02 19:48:23 +030038 /* ACPI tables must be present */
39
Lv Zheng62fcce92015-10-14 13:53:57 +080040 if (acpi_gbl_fadt_index == ACPI_INVALID_TABLE_INDEX) {
Bob Moorec8573032007-02-02 19:48:23 +030041 return_ACPI_STATUS(AE_NO_ACPI_TABLES);
42 }
43
Bob Moorec39660b2013-03-08 09:22:14 +000044 /* 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
Bob Moorec8573032007-02-02 19:48:23 +030050 /* Check current mode */
51
Linus Torvalds1da177e2005-04-16 15:20:36 -070052 if (acpi_hw_get_mode() == ACPI_SYS_MODE_ACPI) {
Len Brown4be44fc2005-08-05 00:44:28 -040053 ACPI_DEBUG_PRINT((ACPI_DB_INIT,
54 "System is already in ACPI mode\n"));
Len Brownb430acb2010-05-06 17:41:08 -040055 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -070056 }
57
Len Brownb430acb2010-05-06 17:41:08 -040058 /* Transition to ACPI mode */
59
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
Len Brown3d695832010-06-28 20:55:01 -040069 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 */
Len Brownb430acb2010-05-06 17:41:08 -040077 }
78
Len Brown3d695832010-06-28 20:55:01 -040079 ACPI_ERROR((AE_INFO, "Hardware did not enter ACPI mode"));
80 return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);
Linus Torvalds1da177e2005-04-16 15:20:36 -070081}
82
Bob Moore83135242006-10-03 00:00:00 -040083ACPI_EXPORT_SYMBOL(acpi_enable)
84
Linus Torvalds1da177e2005-04-16 15:20:36 -070085/*******************************************************************************
86 *
87 * FUNCTION: acpi_disable
88 *
89 * PARAMETERS: None
90 *
91 * RETURN: Status
92 *
Robert Moore44f6c012005-04-18 22:49:35 -040093 * DESCRIPTION: Transfers the system into LEGACY (non-ACPI) mode.
Linus Torvalds1da177e2005-04-16 15:20:36 -070094 *
95 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -040096acpi_status acpi_disable(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070097{
Len Brown4be44fc2005-08-05 00:44:28 -040098 acpi_status status = AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -070099
Bob Mooreb229cf92006-04-21 17:15:00 -0400100 ACPI_FUNCTION_TRACE(acpi_disable);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101
Bob Moorec39660b2013-03-08 09:22:14 +0000102 /* 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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108 if (acpi_hw_get_mode() == ACPI_SYS_MODE_LEGACY) {
Len Brown4be44fc2005-08-05 00:44:28 -0400109 ACPI_DEBUG_PRINT((ACPI_DB_INIT,
110 "System is already in legacy (non-ACPI) mode\n"));
111 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112 /* Transition to LEGACY mode */
113
Len Brown4be44fc2005-08-05 00:44:28 -0400114 status = acpi_hw_set_mode(ACPI_SYS_MODE_LEGACY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115
Len Brown4be44fc2005-08-05 00:44:28 -0400116 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500117 ACPI_ERROR((AE_INFO,
118 "Could not exit ACPI mode to legacy mode"));
Len Brown4be44fc2005-08-05 00:44:28 -0400119 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 }
121
Len Brown4be44fc2005-08-05 00:44:28 -0400122 ACPI_DEBUG_PRINT((ACPI_DB_INIT, "ACPI mode disabled\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123 }
124
Len Brown4be44fc2005-08-05 00:44:28 -0400125 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126}
127
Bob Moore83135242006-10-03 00:00:00 -0400128ACPI_EXPORT_SYMBOL(acpi_disable)
129
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130/*******************************************************************************
131 *
132 * FUNCTION: acpi_enable_event
133 *
Bob Mooreba494be2012-07-12 09:40:10 +0800134 * PARAMETERS: event - The fixed eventto be enabled
135 * flags - Reserved
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136 *
137 * RETURN: Status
138 *
139 * DESCRIPTION: Enable an ACPI event (fixed)
140 *
141 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -0400142acpi_status acpi_enable_event(u32 event, u32 flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143{
Len Brown4be44fc2005-08-05 00:44:28 -0400144 acpi_status status = AE_OK;
145 u32 value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146
Bob Mooreb229cf92006-04-21 17:15:00 -0400147 ACPI_FUNCTION_TRACE(acpi_enable_event);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148
Lv Zheng861ba632017-06-05 16:40:02 +0800149 /* 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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155 /* Decode the Fixed Event */
156
157 if (event > ACPI_EVENT_MAX) {
Len Brown4be44fc2005-08-05 00:44:28 -0400158 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159 }
160
161 /*
Bob Moore9f15fc62008-11-12 16:01:56 +0800162 * Enable the requested fixed event (by writing a one to the enable
163 * register bit)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164 */
Len Brown4be44fc2005-08-05 00:44:28 -0400165 status =
Bob Moore50ffba12009-02-23 15:02:07 +0800166 acpi_write_bit_register(acpi_gbl_fixed_event_info[event].
Bob Moore768aaaf2009-03-06 09:49:25 +0800167 enable_register_id, ACPI_ENABLE_EVENT);
Len Brown4be44fc2005-08-05 00:44:28 -0400168 if (ACPI_FAILURE(status)) {
169 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170 }
171
172 /* Make sure that the hardware responded */
173
Len Brown4be44fc2005-08-05 00:44:28 -0400174 status =
Bob Moore50ffba12009-02-23 15:02:07 +0800175 acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
176 enable_register_id, &value);
Len Brown4be44fc2005-08-05 00:44:28 -0400177 if (ACPI_FAILURE(status)) {
178 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179 }
180
181 if (value != 1) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500182 ACPI_ERROR((AE_INFO,
183 "Could not enable %s event",
184 acpi_ut_get_event_name(event)));
Len Brown4be44fc2005-08-05 00:44:28 -0400185 return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186 }
187
Len Brown4be44fc2005-08-05 00:44:28 -0400188 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190
Bob Moore83135242006-10-03 00:00:00 -0400191ACPI_EXPORT_SYMBOL(acpi_enable_event)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192
193/*******************************************************************************
194 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195 * FUNCTION: acpi_disable_event
196 *
Lv Zheng75c80442012-12-19 05:36:49 +0000197 * PARAMETERS: event - The fixed event to be disabled
198 * flags - Reserved
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199 *
200 * RETURN: Status
201 *
202 * DESCRIPTION: Disable an ACPI event (fixed)
203 *
204 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -0400205acpi_status acpi_disable_event(u32 event, u32 flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206{
Len Brown4be44fc2005-08-05 00:44:28 -0400207 acpi_status status = AE_OK;
208 u32 value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209
Bob Mooreb229cf92006-04-21 17:15:00 -0400210 ACPI_FUNCTION_TRACE(acpi_disable_event);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211
Lv Zheng861ba632017-06-05 16:40:02 +0800212 /* 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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218 /* Decode the Fixed Event */
219
220 if (event > ACPI_EVENT_MAX) {
Len Brown4be44fc2005-08-05 00:44:28 -0400221 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222 }
223
224 /*
Bob Moore9f15fc62008-11-12 16:01:56 +0800225 * Disable the requested fixed event (by writing a zero to the enable
226 * register bit)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 */
Len Brown4be44fc2005-08-05 00:44:28 -0400228 status =
Bob Moore50ffba12009-02-23 15:02:07 +0800229 acpi_write_bit_register(acpi_gbl_fixed_event_info[event].
Bob Moore768aaaf2009-03-06 09:49:25 +0800230 enable_register_id, ACPI_DISABLE_EVENT);
Len Brown4be44fc2005-08-05 00:44:28 -0400231 if (ACPI_FAILURE(status)) {
232 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233 }
234
Len Brown4be44fc2005-08-05 00:44:28 -0400235 status =
Bob Moore50ffba12009-02-23 15:02:07 +0800236 acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
237 enable_register_id, &value);
Len Brown4be44fc2005-08-05 00:44:28 -0400238 if (ACPI_FAILURE(status)) {
239 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240 }
241
242 if (value != 0) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500243 ACPI_ERROR((AE_INFO,
244 "Could not disable %s events",
245 acpi_ut_get_event_name(event)));
Len Brown4be44fc2005-08-05 00:44:28 -0400246 return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247 }
248
Len Brown4be44fc2005-08-05 00:44:28 -0400249 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251
Bob Moore83135242006-10-03 00:00:00 -0400252ACPI_EXPORT_SYMBOL(acpi_disable_event)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253
254/*******************************************************************************
255 *
256 * FUNCTION: acpi_clear_event
257 *
Bob Mooreba494be2012-07-12 09:40:10 +0800258 * PARAMETERS: event - The fixed event to be cleared
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259 *
260 * RETURN: Status
261 *
262 * DESCRIPTION: Clear an ACPI event (fixed)
263 *
264 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -0400265acpi_status acpi_clear_event(u32 event)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266{
Len Brown4be44fc2005-08-05 00:44:28 -0400267 acpi_status status = AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268
Bob Mooreb229cf92006-04-21 17:15:00 -0400269 ACPI_FUNCTION_TRACE(acpi_clear_event);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270
Lv Zheng861ba632017-06-05 16:40:02 +0800271 /* 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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277 /* Decode the Fixed Event */
278
279 if (event > ACPI_EVENT_MAX) {
Len Brown4be44fc2005-08-05 00:44:28 -0400280 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281 }
282
283 /*
Bob Moore9f15fc62008-11-12 16:01:56 +0800284 * Clear the requested fixed event (By writing a one to the status
285 * register bit)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286 */
Len Brown4be44fc2005-08-05 00:44:28 -0400287 status =
Bob Moore50ffba12009-02-23 15:02:07 +0800288 acpi_write_bit_register(acpi_gbl_fixed_event_info[event].
Bob Moore768aaaf2009-03-06 09:49:25 +0800289 status_register_id, ACPI_CLEAR_STATUS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290
Len Brown4be44fc2005-08-05 00:44:28 -0400291 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293
Bob Moore83135242006-10-03 00:00:00 -0400294ACPI_EXPORT_SYMBOL(acpi_clear_event)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295
296/*******************************************************************************
297 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298 * FUNCTION: acpi_get_event_status
299 *
Bob Mooreba494be2012-07-12 09:40:10 +0800300 * PARAMETERS: event - The fixed event
Robert Moore44f6c012005-04-18 22:49:35 -0400301 * event_status - Where the current status of the event will
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302 * be returned
303 *
304 * RETURN: Status
305 *
306 * DESCRIPTION: Obtains and returns the current status of the event
307 *
308 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -0400309acpi_status acpi_get_event_status(u32 event, acpi_event_status * event_status)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310{
Lv Zhenga08f8132014-10-10 10:39:57 +0800311 acpi_status status;
312 acpi_event_status local_event_status = 0;
313 u32 in_byte;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314
Bob Mooreb229cf92006-04-21 17:15:00 -0400315 ACPI_FUNCTION_TRACE(acpi_get_event_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316
317 if (!event_status) {
Len Brown4be44fc2005-08-05 00:44:28 -0400318 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319 }
320
321 /* Decode the Fixed Event */
322
323 if (event > ACPI_EVENT_MAX) {
Len Brown4be44fc2005-08-05 00:44:28 -0400324 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325 }
326
Lv Zhenga08f8132014-10-10 10:39:57 +0800327 /* Fixed event currently can be dispatched? */
328
329 if (acpi_gbl_fixed_event_handlers[event].handler) {
Lv Zheng2f857232014-10-10 10:40:05 +0800330 local_event_status |= ACPI_EVENT_FLAG_HAS_HANDLER;
Lv Zhenga08f8132014-10-10 10:39:57 +0800331 }
332
333 /* Fixed event currently enabled? */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334
Len Brown4be44fc2005-08-05 00:44:28 -0400335 status =
Bob Moore50ffba12009-02-23 15:02:07 +0800336 acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
Lv Zhenga08f8132014-10-10 10:39:57 +0800337 enable_register_id, &in_byte);
338 if (ACPI_FAILURE(status)) {
Zhang Rui71b58cb2008-06-20 09:42:47 +0800339 return_ACPI_STATUS(status);
Lv Zhenga08f8132014-10-10 10:39:57 +0800340 }
Zhang Rui71b58cb2008-06-20 09:42:47 +0800341
Lv Zhenga08f8132014-10-10 10:39:57 +0800342 if (in_byte) {
Lv Zheng09af8e82015-04-13 11:49:13 +0800343 local_event_status |=
344 (ACPI_EVENT_FLAG_ENABLED | ACPI_EVENT_FLAG_ENABLE_SET);
Lv Zhenga08f8132014-10-10 10:39:57 +0800345 }
346
347 /* Fixed event currently active? */
Zhang Rui71b58cb2008-06-20 09:42:47 +0800348
349 status =
Bob Moore50ffba12009-02-23 15:02:07 +0800350 acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
Lv Zhenga08f8132014-10-10 10:39:57 +0800351 status_register_id, &in_byte);
352 if (ACPI_FAILURE(status)) {
Zhang Rui71b58cb2008-06-20 09:42:47 +0800353 return_ACPI_STATUS(status);
Lv Zhenga08f8132014-10-10 10:39:57 +0800354 }
Zhang Rui71b58cb2008-06-20 09:42:47 +0800355
Lv Zhenga08f8132014-10-10 10:39:57 +0800356 if (in_byte) {
Lv Zheng09af8e82015-04-13 11:49:13 +0800357 local_event_status |= ACPI_EVENT_FLAG_STATUS_SET;
Lv Zhenga08f8132014-10-10 10:39:57 +0800358 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359
Lv Zhenga08f8132014-10-10 10:39:57 +0800360 (*event_status) = local_event_status;
361 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362}
363
Bob Moore83135242006-10-03 00:00:00 -0400364ACPI_EXPORT_SYMBOL(acpi_get_event_status)
Bob Moore33620c52012-02-14 18:14:27 +0800365#endif /* !ACPI_REDUCED_HARDWARE */