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 - 2012, 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.
 *
 ******************************************************************************/
64

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 74 75 76 77 78 79
	/* ACPI tables must be present */

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

	/* Check current mode */

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	/* Decode the Fixed Event */

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

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

	/* Make sure that the hardware responded */

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

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

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

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

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

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

	/* Decode the Fixed Event */

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

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

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

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

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

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

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

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

	/* Decode the Fixed Event */

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

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

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

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

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

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

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

	/* Decode the Fixed Event */

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

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

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

	*event_status = value;

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

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

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

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

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