evxfevnt.c 10.0 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5 6 7
/******************************************************************************
 *
 * Module Name: evxfevnt - External Interfaces, ACPI event disable/enable
 *
 *****************************************************************************/

/*
8
 * Copyright (C) 2000 - 2015, Intel Corp.
L
Linus Torvalds 已提交
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions, and the following disclaimer,
 *    without modification.
 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
 *    substantially similar to the "NO WARRANTY" disclaimer below
 *    ("Disclaimer") and any redistribution must be conditioned upon
 *    including a substantially similar Disclaimer requirement for further
 *    binary redistribution.
 * 3. Neither the names of the above-listed copyright holders nor the names
 *    of any contributors may be used to endorse or promote products derived
 *    from this software without specific prior written permission.
 *
 * Alternatively, this software may be distributed under the terms of the
 * GNU General Public License ("GPL") version 2 as published by the Free
 * Software Foundation.
 *
 * NO WARRANTY
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGES.
 */

44 45
#define EXPORT_ACPI_INTERFACES

L
Linus Torvalds 已提交
46
#include <acpi/acpi.h>
L
Len Brown 已提交
47 48
#include "accommon.h"
#include "actables.h"
L
Linus Torvalds 已提交
49 50

#define _COMPONENT          ACPI_EVENTS
L
Len Brown 已提交
51
ACPI_MODULE_NAME("evxfevnt")
L
Linus Torvalds 已提交
52

53
#if (!ACPI_REDUCED_HARDWARE)	/* Entire module */
L
Linus Torvalds 已提交
54 55 56 57 58 59 60 61 62 63 64
/*******************************************************************************
 *
 * FUNCTION:    acpi_enable
 *
 * PARAMETERS:  None
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Transfers the system into ACPI mode.
 *
 ******************************************************************************/
L
Len Brown 已提交
65
acpi_status acpi_enable(void)
L
Linus Torvalds 已提交
66
{
L
Len Brown 已提交
67
	acpi_status status;
68
	int retry;
L
Linus Torvalds 已提交
69

B
Bob Moore 已提交
70
	ACPI_FUNCTION_TRACE(acpi_enable);
L
Linus Torvalds 已提交
71

72 73
	/* ACPI tables must be present */

74
	if (acpi_gbl_fadt_index == ACPI_INVALID_TABLE_INDEX) {
75 76 77
		return_ACPI_STATUS(AE_NO_ACPI_TABLES);
	}

78 79 80 81 82 83
	/* If the Hardware Reduced flag is set, machine is always in acpi mode */

	if (acpi_gbl_reduced_hardware) {
		return_ACPI_STATUS(AE_OK);
	}

84 85
	/* Check current mode */

L
Linus Torvalds 已提交
86
	if (acpi_hw_get_mode() == ACPI_SYS_MODE_ACPI) {
L
Len Brown 已提交
87 88
		ACPI_DEBUG_PRINT((ACPI_DB_INIT,
				  "System is already in ACPI mode\n"));
L
Len Brown 已提交
89 90
		return_ACPI_STATUS(AE_OK);
	}
L
Linus Torvalds 已提交
91

L
Len Brown 已提交
92
	/* Transition to ACPI mode */
L
Linus Torvalds 已提交
93

L
Len Brown 已提交
94 95 96 97 98 99 100 101 102
	status = acpi_hw_set_mode(ACPI_SYS_MODE_ACPI);
	if (ACPI_FAILURE(status)) {
		ACPI_ERROR((AE_INFO,
			    "Could not transition to ACPI mode"));
		return_ACPI_STATUS(status);
	}

	/* Sanity check that transition succeeded */

103 104 105 106 107 108 109 110
	for (retry = 0; retry < 30000; ++retry) {
		if (acpi_hw_get_mode() == ACPI_SYS_MODE_ACPI) {
			if (retry != 0)
				ACPI_WARNING((AE_INFO,
				"Platform took > %d00 usec to enter ACPI mode", retry));
			return_ACPI_STATUS(AE_OK);
		}
		acpi_os_stall(100);	/* 100 usec */
L
Linus Torvalds 已提交
111 112
	}

113 114
	ACPI_ERROR((AE_INFO, "Hardware did not enter ACPI mode"));
	return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);
L
Linus Torvalds 已提交
115 116
}

B
Bob Moore 已提交
117 118
ACPI_EXPORT_SYMBOL(acpi_enable)

L
Linus Torvalds 已提交
119 120 121 122 123 124 125 126
/*******************************************************************************
 *
 * FUNCTION:    acpi_disable
 *
 * PARAMETERS:  None
 *
 * RETURN:      Status
 *
R
Robert Moore 已提交
127
 * DESCRIPTION: Transfers the system into LEGACY (non-ACPI) mode.
L
Linus Torvalds 已提交
128 129
 *
 ******************************************************************************/
L
Len Brown 已提交
130
acpi_status acpi_disable(void)
L
Linus Torvalds 已提交
131
{
L
Len Brown 已提交
132
	acpi_status status = AE_OK;
L
Linus Torvalds 已提交
133

B
Bob Moore 已提交
134
	ACPI_FUNCTION_TRACE(acpi_disable);
L
Linus Torvalds 已提交
135

136 137 138 139 140 141
	/* If the Hardware Reduced flag is set, machine is always in acpi mode */

	if (acpi_gbl_reduced_hardware) {
		return_ACPI_STATUS(AE_OK);
	}

L
Linus Torvalds 已提交
142
	if (acpi_hw_get_mode() == ACPI_SYS_MODE_LEGACY) {
L
Len Brown 已提交
143 144 145
		ACPI_DEBUG_PRINT((ACPI_DB_INIT,
				  "System is already in legacy (non-ACPI) mode\n"));
	} else {
L
Linus Torvalds 已提交
146 147
		/* Transition to LEGACY mode */

L
Len Brown 已提交
148
		status = acpi_hw_set_mode(ACPI_SYS_MODE_LEGACY);
L
Linus Torvalds 已提交
149

L
Len Brown 已提交
150
		if (ACPI_FAILURE(status)) {
B
Bob Moore 已提交
151 152
			ACPI_ERROR((AE_INFO,
				    "Could not exit ACPI mode to legacy mode"));
L
Len Brown 已提交
153
			return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
154 155
		}

L
Len Brown 已提交
156
		ACPI_DEBUG_PRINT((ACPI_DB_INIT, "ACPI mode disabled\n"));
L
Linus Torvalds 已提交
157 158
	}

L
Len Brown 已提交
159
	return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
160 161
}

B
Bob Moore 已提交
162 163
ACPI_EXPORT_SYMBOL(acpi_disable)

L
Linus Torvalds 已提交
164 165 166 167
/*******************************************************************************
 *
 * FUNCTION:    acpi_enable_event
 *
168 169
 * PARAMETERS:  event           - The fixed eventto be enabled
 *              flags           - Reserved
L
Linus Torvalds 已提交
170 171 172 173 174 175
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Enable an ACPI event (fixed)
 *
 ******************************************************************************/
L
Len Brown 已提交
176
acpi_status acpi_enable_event(u32 event, u32 flags)
L
Linus Torvalds 已提交
177
{
L
Len Brown 已提交
178 179
	acpi_status status = AE_OK;
	u32 value;
L
Linus Torvalds 已提交
180

B
Bob Moore 已提交
181
	ACPI_FUNCTION_TRACE(acpi_enable_event);
L
Linus Torvalds 已提交
182 183 184 185

	/* Decode the Fixed Event */

	if (event > ACPI_EVENT_MAX) {
L
Len Brown 已提交
186
		return_ACPI_STATUS(AE_BAD_PARAMETER);
L
Linus Torvalds 已提交
187 188 189
	}

	/*
190 191
	 * Enable the requested fixed event (by writing a one to the enable
	 * register bit)
L
Linus Torvalds 已提交
192
	 */
L
Len Brown 已提交
193
	status =
194
	    acpi_write_bit_register(acpi_gbl_fixed_event_info[event].
195
				    enable_register_id, ACPI_ENABLE_EVENT);
L
Len Brown 已提交
196 197
	if (ACPI_FAILURE(status)) {
		return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
198 199 200 201
	}

	/* Make sure that the hardware responded */

L
Len Brown 已提交
202
	status =
203 204
	    acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
				   enable_register_id, &value);
L
Len Brown 已提交
205 206
	if (ACPI_FAILURE(status)) {
		return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
207 208 209
	}

	if (value != 1) {
B
Bob Moore 已提交
210 211 212
		ACPI_ERROR((AE_INFO,
			    "Could not enable %s event",
			    acpi_ut_get_event_name(event)));
L
Len Brown 已提交
213
		return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);
L
Linus Torvalds 已提交
214 215
	}

L
Len Brown 已提交
216
	return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
217 218
}

B
Bob Moore 已提交
219
ACPI_EXPORT_SYMBOL(acpi_enable_event)
L
Linus Torvalds 已提交
220 221 222 223 224

/*******************************************************************************
 *
 * FUNCTION:    acpi_disable_event
 *
L
Lv Zheng 已提交
225 226
 * PARAMETERS:  event           - The fixed event to be disabled
 *              flags           - Reserved
L
Linus Torvalds 已提交
227 228 229 230 231 232
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Disable an ACPI event (fixed)
 *
 ******************************************************************************/
L
Len Brown 已提交
233
acpi_status acpi_disable_event(u32 event, u32 flags)
L
Linus Torvalds 已提交
234
{
L
Len Brown 已提交
235 236
	acpi_status status = AE_OK;
	u32 value;
L
Linus Torvalds 已提交
237

B
Bob Moore 已提交
238
	ACPI_FUNCTION_TRACE(acpi_disable_event);
L
Linus Torvalds 已提交
239 240 241 242

	/* Decode the Fixed Event */

	if (event > ACPI_EVENT_MAX) {
L
Len Brown 已提交
243
		return_ACPI_STATUS(AE_BAD_PARAMETER);
L
Linus Torvalds 已提交
244 245 246
	}

	/*
247 248
	 * Disable the requested fixed event (by writing a zero to the enable
	 * register bit)
L
Linus Torvalds 已提交
249
	 */
L
Len Brown 已提交
250
	status =
251
	    acpi_write_bit_register(acpi_gbl_fixed_event_info[event].
252
				    enable_register_id, ACPI_DISABLE_EVENT);
L
Len Brown 已提交
253 254
	if (ACPI_FAILURE(status)) {
		return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
255 256
	}

L
Len Brown 已提交
257
	status =
258 259
	    acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
				   enable_register_id, &value);
L
Len Brown 已提交
260 261
	if (ACPI_FAILURE(status)) {
		return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
262 263 264
	}

	if (value != 0) {
B
Bob Moore 已提交
265 266 267
		ACPI_ERROR((AE_INFO,
			    "Could not disable %s events",
			    acpi_ut_get_event_name(event)));
L
Len Brown 已提交
268
		return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);
L
Linus Torvalds 已提交
269 270
	}

L
Len Brown 已提交
271
	return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
272 273
}

B
Bob Moore 已提交
274
ACPI_EXPORT_SYMBOL(acpi_disable_event)
L
Linus Torvalds 已提交
275 276 277 278 279

/*******************************************************************************
 *
 * FUNCTION:    acpi_clear_event
 *
280
 * PARAMETERS:  event           - The fixed event to be cleared
L
Linus Torvalds 已提交
281 282 283 284 285 286
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Clear an ACPI event (fixed)
 *
 ******************************************************************************/
L
Len Brown 已提交
287
acpi_status acpi_clear_event(u32 event)
L
Linus Torvalds 已提交
288
{
L
Len Brown 已提交
289
	acpi_status status = AE_OK;
L
Linus Torvalds 已提交
290

B
Bob Moore 已提交
291
	ACPI_FUNCTION_TRACE(acpi_clear_event);
L
Linus Torvalds 已提交
292 293 294 295

	/* Decode the Fixed Event */

	if (event > ACPI_EVENT_MAX) {
L
Len Brown 已提交
296
		return_ACPI_STATUS(AE_BAD_PARAMETER);
L
Linus Torvalds 已提交
297 298 299
	}

	/*
300 301
	 * Clear the requested fixed event (By writing a one to the status
	 * register bit)
L
Linus Torvalds 已提交
302
	 */
L
Len Brown 已提交
303
	status =
304
	    acpi_write_bit_register(acpi_gbl_fixed_event_info[event].
305
				    status_register_id, ACPI_CLEAR_STATUS);
L
Linus Torvalds 已提交
306

L
Len Brown 已提交
307
	return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
308 309
}

B
Bob Moore 已提交
310
ACPI_EXPORT_SYMBOL(acpi_clear_event)
L
Linus Torvalds 已提交
311 312 313 314 315

/*******************************************************************************
 *
 * FUNCTION:    acpi_get_event_status
 *
316
 * PARAMETERS:  event           - The fixed event
R
Robert Moore 已提交
317
 *              event_status    - Where the current status of the event will
L
Linus Torvalds 已提交
318 319 320 321 322 323 324
 *                                be returned
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Obtains and returns the current status of the event
 *
 ******************************************************************************/
L
Len Brown 已提交
325
acpi_status acpi_get_event_status(u32 event, acpi_event_status * event_status)
L
Linus Torvalds 已提交
326
{
327 328 329
	acpi_status status;
	acpi_event_status local_event_status = 0;
	u32 in_byte;
L
Linus Torvalds 已提交
330

B
Bob Moore 已提交
331
	ACPI_FUNCTION_TRACE(acpi_get_event_status);
L
Linus Torvalds 已提交
332 333

	if (!event_status) {
L
Len Brown 已提交
334
		return_ACPI_STATUS(AE_BAD_PARAMETER);
L
Linus Torvalds 已提交
335 336 337 338 339
	}

	/* Decode the Fixed Event */

	if (event > ACPI_EVENT_MAX) {
L
Len Brown 已提交
340
		return_ACPI_STATUS(AE_BAD_PARAMETER);
L
Linus Torvalds 已提交
341 342
	}

343 344 345
	/* Fixed event currently can be dispatched? */

	if (acpi_gbl_fixed_event_handlers[event].handler) {
346
		local_event_status |= ACPI_EVENT_FLAG_HAS_HANDLER;
347 348 349
	}

	/* Fixed event currently enabled? */
L
Linus Torvalds 已提交
350

L
Len Brown 已提交
351
	status =
352
	    acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
353 354
				   enable_register_id, &in_byte);
	if (ACPI_FAILURE(status)) {
355
		return_ACPI_STATUS(status);
356
	}
357

358
	if (in_byte) {
359 360
		local_event_status |=
		    (ACPI_EVENT_FLAG_ENABLED | ACPI_EVENT_FLAG_ENABLE_SET);
361 362 363
	}

	/* Fixed event currently active? */
364 365

	status =
366
	    acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
367 368
				   status_register_id, &in_byte);
	if (ACPI_FAILURE(status)) {
369
		return_ACPI_STATUS(status);
370
	}
371

372
	if (in_byte) {
373
		local_event_status |= ACPI_EVENT_FLAG_STATUS_SET;
374
	}
375

376 377
	(*event_status) = local_event_status;
	return_ACPI_STATUS(AE_OK);
L
Linus Torvalds 已提交
378 379
}

B
Bob Moore 已提交
380
ACPI_EXPORT_SYMBOL(acpi_get_event_status)
381
#endif				/* !ACPI_REDUCED_HARDWARE */