evxfevnt.c 9.3 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 - 2011, 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 44
 * 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.
 */

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

#define _COMPONENT          ACPI_EVENTS
L
Len Brown 已提交
49
ACPI_MODULE_NAME("evxfevnt")
L
Linus Torvalds 已提交
50 51 52 53 54 55 56 57 58 59 60 61

/*******************************************************************************
 *
 * FUNCTION:    acpi_enable
 *
 * PARAMETERS:  None
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Transfers the system into ACPI mode.
 *
 ******************************************************************************/
62

L
Len Brown 已提交
63
acpi_status acpi_enable(void)
L
Linus Torvalds 已提交
64
{
L
Len Brown 已提交
65
	acpi_status status;
66
	int retry;
L
Linus Torvalds 已提交
67

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

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

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

	/* Check current mode */

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	/* Decode the Fixed Event */

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

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

	/* Make sure that the hardware responded */

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

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

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

B
Bob Moore 已提交
205
ACPI_EXPORT_SYMBOL(acpi_enable_event)
L
Linus Torvalds 已提交
206 207 208 209 210 211 212 213 214 215 216 217 218

/*******************************************************************************
 *
 * FUNCTION:    acpi_disable_event
 *
 * PARAMETERS:  Event           - The fixed eventto be enabled
 *              Flags           - Reserved
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Disable an ACPI event (fixed)
 *
 ******************************************************************************/
L
Len Brown 已提交
219
acpi_status acpi_disable_event(u32 event, u32 flags)
L
Linus Torvalds 已提交
220
{
L
Len Brown 已提交
221 222
	acpi_status status = AE_OK;
	u32 value;
L
Linus Torvalds 已提交
223

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

	/* Decode the Fixed Event */

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

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

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

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

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

B
Bob Moore 已提交
260
ACPI_EXPORT_SYMBOL(acpi_disable_event)
L
Linus Torvalds 已提交
261 262 263 264 265 266 267 268 269 270 271 272

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

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

	/* Decode the Fixed Event */

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

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

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

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

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

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

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

	/* Decode the Fixed Event */

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

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

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

	*event_status = value;

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

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

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

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

B
Bob Moore 已提交
353
ACPI_EXPORT_SYMBOL(acpi_get_event_status)