evxfevnt.c 9.5 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 - 2013, 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
#include <linux/export.h>
L
Linus Torvalds 已提交
45
#include <acpi/acpi.h>
L
Len Brown 已提交
46 47
#include "accommon.h"
#include "actables.h"
L
Linus Torvalds 已提交
48 49

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

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

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

71 72 73 74 75 76 77 78
	/* ACPI tables must be present */

	if (!acpi_tb_tables_loaded()) {
		return_ACPI_STATUS(AE_NO_ACPI_TABLES);
	}

	/* Check current mode */

L
Linus Torvalds 已提交
79
	if (acpi_hw_get_mode() == ACPI_SYS_MODE_ACPI) {
L
Len Brown 已提交
80 81
		ACPI_DEBUG_PRINT((ACPI_DB_INIT,
				  "System is already in ACPI mode\n"));
L
Len Brown 已提交
82 83
		return_ACPI_STATUS(AE_OK);
	}
L
Linus Torvalds 已提交
84

L
Len Brown 已提交
85
	/* Transition to ACPI mode */
L
Linus Torvalds 已提交
86

L
Len Brown 已提交
87 88 89 90 91 92 93 94 95
	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 */

96 97 98 99 100 101 102 103
	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 已提交
104 105
	}

106 107
	ACPI_ERROR((AE_INFO, "Hardware did not enter ACPI mode"));
	return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);
L
Linus Torvalds 已提交
108 109
}

B
Bob Moore 已提交
110 111
ACPI_EXPORT_SYMBOL(acpi_enable)

L
Linus Torvalds 已提交
112 113 114 115 116 117 118 119
/*******************************************************************************
 *
 * FUNCTION:    acpi_disable
 *
 * PARAMETERS:  None
 *
 * RETURN:      Status
 *
R
Robert Moore 已提交
120
 * DESCRIPTION: Transfers the system into LEGACY (non-ACPI) mode.
L
Linus Torvalds 已提交
121 122
 *
 ******************************************************************************/
L
Len Brown 已提交
123
acpi_status acpi_disable(void)
L
Linus Torvalds 已提交
124
{
L
Len Brown 已提交
125
	acpi_status status = AE_OK;
L
Linus Torvalds 已提交
126

B
Bob Moore 已提交
127
	ACPI_FUNCTION_TRACE(acpi_disable);
L
Linus Torvalds 已提交
128 129

	if (acpi_hw_get_mode() == ACPI_SYS_MODE_LEGACY) {
L
Len Brown 已提交
130 131 132
		ACPI_DEBUG_PRINT((ACPI_DB_INIT,
				  "System is already in legacy (non-ACPI) mode\n"));
	} else {
L
Linus Torvalds 已提交
133 134
		/* Transition to LEGACY mode */

L
Len Brown 已提交
135
		status = acpi_hw_set_mode(ACPI_SYS_MODE_LEGACY);
L
Linus Torvalds 已提交
136

L
Len Brown 已提交
137
		if (ACPI_FAILURE(status)) {
B
Bob Moore 已提交
138 139
			ACPI_ERROR((AE_INFO,
				    "Could not exit ACPI mode to legacy mode"));
L
Len Brown 已提交
140
			return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
141 142
		}

L
Len Brown 已提交
143
		ACPI_DEBUG_PRINT((ACPI_DB_INIT, "ACPI mode disabled\n"));
L
Linus Torvalds 已提交
144 145
	}

L
Len Brown 已提交
146
	return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
147 148
}

B
Bob Moore 已提交
149 150
ACPI_EXPORT_SYMBOL(acpi_disable)

L
Linus Torvalds 已提交
151 152 153 154
/*******************************************************************************
 *
 * FUNCTION:    acpi_enable_event
 *
155 156
 * PARAMETERS:  event           - The fixed eventto be enabled
 *              flags           - Reserved
L
Linus Torvalds 已提交
157 158 159 160 161 162
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Enable an ACPI event (fixed)
 *
 ******************************************************************************/
L
Len Brown 已提交
163
acpi_status acpi_enable_event(u32 event, u32 flags)
L
Linus Torvalds 已提交
164
{
L
Len Brown 已提交
165 166
	acpi_status status = AE_OK;
	u32 value;
L
Linus Torvalds 已提交
167

B
Bob Moore 已提交
168
	ACPI_FUNCTION_TRACE(acpi_enable_event);
L
Linus Torvalds 已提交
169 170 171 172

	/* Decode the Fixed Event */

	if (event > ACPI_EVENT_MAX) {
L
Len Brown 已提交
173
		return_ACPI_STATUS(AE_BAD_PARAMETER);
L
Linus Torvalds 已提交
174 175 176
	}

	/*
177 178
	 * Enable the requested fixed event (by writing a one to the enable
	 * register bit)
L
Linus Torvalds 已提交
179
	 */
L
Len Brown 已提交
180
	status =
181
	    acpi_write_bit_register(acpi_gbl_fixed_event_info[event].
182
				    enable_register_id, ACPI_ENABLE_EVENT);
L
Len Brown 已提交
183 184
	if (ACPI_FAILURE(status)) {
		return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
185 186 187 188
	}

	/* Make sure that the hardware responded */

L
Len Brown 已提交
189
	status =
190 191
	    acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
				   enable_register_id, &value);
L
Len Brown 已提交
192 193
	if (ACPI_FAILURE(status)) {
		return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
194 195 196
	}

	if (value != 1) {
B
Bob Moore 已提交
197 198 199
		ACPI_ERROR((AE_INFO,
			    "Could not enable %s event",
			    acpi_ut_get_event_name(event)));
L
Len Brown 已提交
200
		return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);
L
Linus Torvalds 已提交
201 202
	}

L
Len Brown 已提交
203
	return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
204 205
}

B
Bob Moore 已提交
206
ACPI_EXPORT_SYMBOL(acpi_enable_event)
L
Linus Torvalds 已提交
207 208 209 210 211

/*******************************************************************************
 *
 * FUNCTION:    acpi_disable_event
 *
L
Lv Zheng 已提交
212 213
 * PARAMETERS:  event           - The fixed event to be disabled
 *              flags           - Reserved
L
Linus Torvalds 已提交
214 215 216 217 218 219
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Disable an ACPI event (fixed)
 *
 ******************************************************************************/
L
Len Brown 已提交
220
acpi_status acpi_disable_event(u32 event, u32 flags)
L
Linus Torvalds 已提交
221
{
L
Len Brown 已提交
222 223
	acpi_status status = AE_OK;
	u32 value;
L
Linus Torvalds 已提交
224

B
Bob Moore 已提交
225
	ACPI_FUNCTION_TRACE(acpi_disable_event);
L
Linus Torvalds 已提交
226 227 228 229

	/* Decode the Fixed Event */

	if (event > ACPI_EVENT_MAX) {
L
Len Brown 已提交
230
		return_ACPI_STATUS(AE_BAD_PARAMETER);
L
Linus Torvalds 已提交
231 232 233
	}

	/*
234 235
	 * Disable the requested fixed event (by writing a zero to the enable
	 * register bit)
L
Linus Torvalds 已提交
236
	 */
L
Len Brown 已提交
237
	status =
238
	    acpi_write_bit_register(acpi_gbl_fixed_event_info[event].
239
				    enable_register_id, ACPI_DISABLE_EVENT);
L
Len Brown 已提交
240 241
	if (ACPI_FAILURE(status)) {
		return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
242 243
	}

L
Len Brown 已提交
244
	status =
245 246
	    acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
				   enable_register_id, &value);
L
Len Brown 已提交
247 248
	if (ACPI_FAILURE(status)) {
		return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
249 250 251
	}

	if (value != 0) {
B
Bob Moore 已提交
252 253 254
		ACPI_ERROR((AE_INFO,
			    "Could not disable %s events",
			    acpi_ut_get_event_name(event)));
L
Len Brown 已提交
255
		return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);
L
Linus Torvalds 已提交
256 257
	}

L
Len Brown 已提交
258
	return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
259 260
}

B
Bob Moore 已提交
261
ACPI_EXPORT_SYMBOL(acpi_disable_event)
L
Linus Torvalds 已提交
262 263 264 265 266

/*******************************************************************************
 *
 * FUNCTION:    acpi_clear_event
 *
267
 * PARAMETERS:  event           - The fixed event to be cleared
L
Linus Torvalds 已提交
268 269 270 271 272 273
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Clear an ACPI event (fixed)
 *
 ******************************************************************************/
L
Len Brown 已提交
274
acpi_status acpi_clear_event(u32 event)
L
Linus Torvalds 已提交
275
{
L
Len Brown 已提交
276
	acpi_status status = AE_OK;
L
Linus Torvalds 已提交
277

B
Bob Moore 已提交
278
	ACPI_FUNCTION_TRACE(acpi_clear_event);
L
Linus Torvalds 已提交
279 280 281 282

	/* Decode the Fixed Event */

	if (event > ACPI_EVENT_MAX) {
L
Len Brown 已提交
283
		return_ACPI_STATUS(AE_BAD_PARAMETER);
L
Linus Torvalds 已提交
284 285 286
	}

	/*
287 288
	 * Clear the requested fixed event (By writing a one to the status
	 * register bit)
L
Linus Torvalds 已提交
289
	 */
L
Len Brown 已提交
290
	status =
291
	    acpi_write_bit_register(acpi_gbl_fixed_event_info[event].
292
				    status_register_id, ACPI_CLEAR_STATUS);
L
Linus Torvalds 已提交
293

L
Len Brown 已提交
294
	return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
295 296
}

B
Bob Moore 已提交
297
ACPI_EXPORT_SYMBOL(acpi_clear_event)
L
Linus Torvalds 已提交
298 299 300 301 302

/*******************************************************************************
 *
 * FUNCTION:    acpi_get_event_status
 *
303
 * PARAMETERS:  event           - The fixed event
R
Robert Moore 已提交
304
 *              event_status    - Where the current status of the event will
L
Linus Torvalds 已提交
305 306 307 308 309 310 311
 *                                be returned
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Obtains and returns the current status of the event
 *
 ******************************************************************************/
L
Len Brown 已提交
312
acpi_status acpi_get_event_status(u32 event, acpi_event_status * event_status)
L
Linus Torvalds 已提交
313
{
L
Len Brown 已提交
314
	acpi_status status = AE_OK;
315
	u32 value;
L
Linus Torvalds 已提交
316

B
Bob Moore 已提交
317
	ACPI_FUNCTION_TRACE(acpi_get_event_status);
L
Linus Torvalds 已提交
318 319

	if (!event_status) {
L
Len Brown 已提交
320
		return_ACPI_STATUS(AE_BAD_PARAMETER);
L
Linus Torvalds 已提交
321 322 323 324 325
	}

	/* Decode the Fixed Event */

	if (event > ACPI_EVENT_MAX) {
L
Len Brown 已提交
326
		return_ACPI_STATUS(AE_BAD_PARAMETER);
L
Linus Torvalds 已提交
327 328 329 330
	}

	/* Get the status of the requested fixed event */

L
Len Brown 已提交
331
	status =
332
	    acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
333 334 335 336 337 338 339
			      enable_register_id, &value);
	if (ACPI_FAILURE(status))
		return_ACPI_STATUS(status);

	*event_status = value;

	status =
340
	    acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
341 342 343 344 345 346
			      status_register_id, &value);
	if (ACPI_FAILURE(status))
		return_ACPI_STATUS(status);

	if (value)
		*event_status |= ACPI_EVENT_FLAG_SET;
L
Linus Torvalds 已提交
347

348 349 350
	if (acpi_gbl_fixed_event_handlers[event].handler)
		*event_status |= ACPI_EVENT_FLAG_HANDLE;

L
Len Brown 已提交
351
	return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
352 353
}

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