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

/*
B
Bob Moore 已提交
8
 * Copyright (C) 2000 - 2006, R. Byron Moore
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 45 46 47 48
 * 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>
#include <acpi/acevents.h>
#include <acpi/acnamesp.h>

#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.
 *
 ******************************************************************************/
L
Len Brown 已提交
62
acpi_status acpi_enable(void)
L
Linus Torvalds 已提交
63
{
L
Len Brown 已提交
64
	acpi_status status = AE_OK;
L
Linus Torvalds 已提交
65

B
Bob Moore 已提交
66
	ACPI_FUNCTION_TRACE(acpi_enable);
L
Linus Torvalds 已提交
67

68 69 70 71 72 73 74 75
	/* ACPI tables must be present */

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

	/* Check current mode */

L
Linus Torvalds 已提交
76
	if (acpi_hw_get_mode() == ACPI_SYS_MODE_ACPI) {
L
Len Brown 已提交
77 78 79
		ACPI_DEBUG_PRINT((ACPI_DB_INIT,
				  "System is already in ACPI mode\n"));
	} else {
L
Linus Torvalds 已提交
80 81
		/* Transition to ACPI mode */

L
Len Brown 已提交
82 83
		status = acpi_hw_set_mode(ACPI_SYS_MODE_ACPI);
		if (ACPI_FAILURE(status)) {
B
Bob Moore 已提交
84 85
			ACPI_ERROR((AE_INFO,
				    "Could not transition to ACPI mode"));
L
Len Brown 已提交
86
			return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
87 88
		}

L
Len Brown 已提交
89 90
		ACPI_DEBUG_PRINT((ACPI_DB_INIT,
				  "Transition to ACPI mode successful\n"));
L
Linus Torvalds 已提交
91 92
	}

L
Len Brown 已提交
93
	return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
94 95
}

B
Bob Moore 已提交
96 97
ACPI_EXPORT_SYMBOL(acpi_enable)

L
Linus Torvalds 已提交
98 99 100 101 102 103 104 105
/*******************************************************************************
 *
 * FUNCTION:    acpi_disable
 *
 * PARAMETERS:  None
 *
 * RETURN:      Status
 *
R
Robert Moore 已提交
106
 * DESCRIPTION: Transfers the system into LEGACY (non-ACPI) mode.
L
Linus Torvalds 已提交
107 108
 *
 ******************************************************************************/
L
Len Brown 已提交
109
acpi_status acpi_disable(void)
L
Linus Torvalds 已提交
110
{
L
Len Brown 已提交
111
	acpi_status status = AE_OK;
L
Linus Torvalds 已提交
112

B
Bob Moore 已提交
113
	ACPI_FUNCTION_TRACE(acpi_disable);
L
Linus Torvalds 已提交
114 115

	if (acpi_hw_get_mode() == ACPI_SYS_MODE_LEGACY) {
L
Len Brown 已提交
116 117 118
		ACPI_DEBUG_PRINT((ACPI_DB_INIT,
				  "System is already in legacy (non-ACPI) mode\n"));
	} else {
L
Linus Torvalds 已提交
119 120
		/* Transition to LEGACY mode */

L
Len Brown 已提交
121
		status = acpi_hw_set_mode(ACPI_SYS_MODE_LEGACY);
L
Linus Torvalds 已提交
122

L
Len Brown 已提交
123
		if (ACPI_FAILURE(status)) {
B
Bob Moore 已提交
124 125
			ACPI_ERROR((AE_INFO,
				    "Could not exit ACPI mode to legacy mode"));
L
Len Brown 已提交
126
			return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
127 128
		}

L
Len Brown 已提交
129
		ACPI_DEBUG_PRINT((ACPI_DB_INIT, "ACPI mode disabled\n"));
L
Linus Torvalds 已提交
130 131
	}

L
Len Brown 已提交
132
	return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
133 134
}

B
Bob Moore 已提交
135 136
ACPI_EXPORT_SYMBOL(acpi_disable)

L
Linus Torvalds 已提交
137 138 139 140 141 142 143 144 145 146 147 148
/*******************************************************************************
 *
 * FUNCTION:    acpi_enable_event
 *
 * PARAMETERS:  Event           - The fixed eventto be enabled
 *              Flags           - Reserved
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Enable an ACPI event (fixed)
 *
 ******************************************************************************/
L
Len Brown 已提交
149
acpi_status acpi_enable_event(u32 event, u32 flags)
L
Linus Torvalds 已提交
150
{
L
Len Brown 已提交
151 152
	acpi_status status = AE_OK;
	u32 value;
L
Linus Torvalds 已提交
153

B
Bob Moore 已提交
154
	ACPI_FUNCTION_TRACE(acpi_enable_event);
L
Linus Torvalds 已提交
155 156 157 158

	/* Decode the Fixed Event */

	if (event > ACPI_EVENT_MAX) {
L
Len Brown 已提交
159
		return_ACPI_STATUS(AE_BAD_PARAMETER);
L
Linus Torvalds 已提交
160 161 162 163 164 165
	}

	/*
	 * Enable the requested fixed event (by writing a one to the
	 * enable register bit)
	 */
L
Len Brown 已提交
166 167
	status =
	    acpi_set_register(acpi_gbl_fixed_event_info[event].
168
			      enable_register_id, 1);
L
Len Brown 已提交
169 170
	if (ACPI_FAILURE(status)) {
		return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
171 172 173 174
	}

	/* Make sure that the hardware responded */

L
Len Brown 已提交
175 176
	status =
	    acpi_get_register(acpi_gbl_fixed_event_info[event].
177
			      enable_register_id, &value);
L
Len Brown 已提交
178 179
	if (ACPI_FAILURE(status)) {
		return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
180 181 182
	}

	if (value != 1) {
B
Bob Moore 已提交
183 184 185
		ACPI_ERROR((AE_INFO,
			    "Could not enable %s event",
			    acpi_ut_get_event_name(event)));
L
Len Brown 已提交
186
		return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);
L
Linus Torvalds 已提交
187 188
	}

L
Len Brown 已提交
189
	return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
190 191
}

B
Bob Moore 已提交
192
ACPI_EXPORT_SYMBOL(acpi_enable_event)
L
Linus Torvalds 已提交
193 194 195 196 197 198 199 200 201 202 203

/*******************************************************************************
 *
 * FUNCTION:    acpi_set_gpe_type
 *
 * PARAMETERS:  gpe_device      - Parent GPE Device
 *              gpe_number      - GPE level within the GPE block
 *              Type            - New GPE type
 *
 * RETURN:      Status
 *
R
Robert Moore 已提交
204
 * DESCRIPTION: Set the type of an individual GPE
L
Linus Torvalds 已提交
205 206
 *
 ******************************************************************************/
L
Len Brown 已提交
207
acpi_status acpi_set_gpe_type(acpi_handle gpe_device, u32 gpe_number, u8 type)
L
Linus Torvalds 已提交
208
{
L
Len Brown 已提交
209 210
	acpi_status status = AE_OK;
	struct acpi_gpe_event_info *gpe_event_info;
L
Linus Torvalds 已提交
211

B
Bob Moore 已提交
212
	ACPI_FUNCTION_TRACE(acpi_set_gpe_type);
L
Linus Torvalds 已提交
213 214 215

	/* Ensure that we have a valid GPE number */

L
Len Brown 已提交
216
	gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
L
Linus Torvalds 已提交
217 218 219 220 221 222
	if (!gpe_event_info) {
		status = AE_BAD_PARAMETER;
		goto unlock_and_exit;
	}

	if ((gpe_event_info->flags & ACPI_GPE_TYPE_MASK) == type) {
L
Len Brown 已提交
223
		return_ACPI_STATUS(AE_OK);
L
Linus Torvalds 已提交
224 225 226 227
	}

	/* Set the new type (will disable GPE if currently enabled) */

L
Len Brown 已提交
228
	status = acpi_ev_set_gpe_type(gpe_event_info, type);
L
Linus Torvalds 已提交
229

L
Len Brown 已提交
230 231
      unlock_and_exit:
	return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
232 233
}

B
Bob Moore 已提交
234
ACPI_EXPORT_SYMBOL(acpi_set_gpe_type)
L
Linus Torvalds 已提交
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249

/*******************************************************************************
 *
 * FUNCTION:    acpi_enable_gpe
 *
 * PARAMETERS:  gpe_device      - Parent GPE Device
 *              gpe_number      - GPE level within the GPE block
 *              Flags           - Just enable, or also wake enable?
 *                                Called from ISR or not
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Enable an ACPI event (general purpose)
 *
 ******************************************************************************/
L
Len Brown 已提交
250
acpi_status acpi_enable_gpe(acpi_handle gpe_device, u32 gpe_number, u32 flags)
L
Linus Torvalds 已提交
251
{
L
Len Brown 已提交
252 253
	acpi_status status = AE_OK;
	struct acpi_gpe_event_info *gpe_event_info;
L
Linus Torvalds 已提交
254

B
Bob Moore 已提交
255
	ACPI_FUNCTION_TRACE(acpi_enable_gpe);
L
Linus Torvalds 已提交
256 257 258 259

	/* Use semaphore lock if not executing at interrupt level */

	if (flags & ACPI_NOT_ISR) {
L
Len Brown 已提交
260 261 262
		status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
		if (ACPI_FAILURE(status)) {
			return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
263 264 265 266 267
		}
	}

	/* Ensure that we have a valid GPE number */

L
Len Brown 已提交
268
	gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
L
Linus Torvalds 已提交
269 270 271 272 273 274 275
	if (!gpe_event_info) {
		status = AE_BAD_PARAMETER;
		goto unlock_and_exit;
	}

	/* Perform the enable */

L
Len Brown 已提交
276
	status = acpi_ev_enable_gpe(gpe_event_info, TRUE);
L
Linus Torvalds 已提交
277

L
Len Brown 已提交
278
      unlock_and_exit:
L
Linus Torvalds 已提交
279
	if (flags & ACPI_NOT_ISR) {
L
Len Brown 已提交
280
		(void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
L
Linus Torvalds 已提交
281
	}
L
Len Brown 已提交
282
	return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
283 284
}

B
Bob Moore 已提交
285
ACPI_EXPORT_SYMBOL(acpi_enable_gpe)
L
Linus Torvalds 已提交
286 287 288 289 290 291 292 293 294 295 296 297 298 299 300

/*******************************************************************************
 *
 * FUNCTION:    acpi_disable_gpe
 *
 * PARAMETERS:  gpe_device      - Parent GPE Device
 *              gpe_number      - GPE level within the GPE block
 *              Flags           - Just disable, or also wake disable?
 *                                Called from ISR or not
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Disable an ACPI event (general purpose)
 *
 ******************************************************************************/
L
Len Brown 已提交
301
acpi_status acpi_disable_gpe(acpi_handle gpe_device, u32 gpe_number, u32 flags)
L
Linus Torvalds 已提交
302
{
L
Len Brown 已提交
303 304
	acpi_status status = AE_OK;
	struct acpi_gpe_event_info *gpe_event_info;
L
Linus Torvalds 已提交
305

B
Bob Moore 已提交
306
	ACPI_FUNCTION_TRACE(acpi_disable_gpe);
L
Linus Torvalds 已提交
307 308 309 310

	/* Use semaphore lock if not executing at interrupt level */

	if (flags & ACPI_NOT_ISR) {
L
Len Brown 已提交
311 312 313
		status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
		if (ACPI_FAILURE(status)) {
			return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
314 315 316 317 318
		}
	}

	/* Ensure that we have a valid GPE number */

L
Len Brown 已提交
319
	gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
L
Linus Torvalds 已提交
320 321 322 323 324
	if (!gpe_event_info) {
		status = AE_BAD_PARAMETER;
		goto unlock_and_exit;
	}

L
Len Brown 已提交
325
	status = acpi_ev_disable_gpe(gpe_event_info);
L
Linus Torvalds 已提交
326

L
Len Brown 已提交
327
      unlock_and_exit:
L
Linus Torvalds 已提交
328
	if (flags & ACPI_NOT_ISR) {
L
Len Brown 已提交
329
		(void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
L
Linus Torvalds 已提交
330
	}
L
Len Brown 已提交
331
	return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
332 333
}

B
Bob Moore 已提交
334 335
ACPI_EXPORT_SYMBOL(acpi_disable_gpe)

L
Linus Torvalds 已提交
336 337 338 339 340 341 342 343 344 345 346 347
/*******************************************************************************
 *
 * FUNCTION:    acpi_disable_event
 *
 * PARAMETERS:  Event           - The fixed eventto be enabled
 *              Flags           - Reserved
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Disable an ACPI event (fixed)
 *
 ******************************************************************************/
L
Len Brown 已提交
348
acpi_status acpi_disable_event(u32 event, u32 flags)
L
Linus Torvalds 已提交
349
{
L
Len Brown 已提交
350 351
	acpi_status status = AE_OK;
	u32 value;
L
Linus Torvalds 已提交
352

B
Bob Moore 已提交
353
	ACPI_FUNCTION_TRACE(acpi_disable_event);
L
Linus Torvalds 已提交
354 355 356 357

	/* Decode the Fixed Event */

	if (event > ACPI_EVENT_MAX) {
L
Len Brown 已提交
358
		return_ACPI_STATUS(AE_BAD_PARAMETER);
L
Linus Torvalds 已提交
359 360 361 362 363 364
	}

	/*
	 * Disable the requested fixed event (by writing a zero to the
	 * enable register bit)
	 */
L
Len Brown 已提交
365 366
	status =
	    acpi_set_register(acpi_gbl_fixed_event_info[event].
367
			      enable_register_id, 0);
L
Len Brown 已提交
368 369
	if (ACPI_FAILURE(status)) {
		return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
370 371
	}

L
Len Brown 已提交
372 373
	status =
	    acpi_get_register(acpi_gbl_fixed_event_info[event].
374
			      enable_register_id, &value);
L
Len Brown 已提交
375 376
	if (ACPI_FAILURE(status)) {
		return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
377 378 379
	}

	if (value != 0) {
B
Bob Moore 已提交
380 381 382
		ACPI_ERROR((AE_INFO,
			    "Could not disable %s events",
			    acpi_ut_get_event_name(event)));
L
Len Brown 已提交
383
		return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);
L
Linus Torvalds 已提交
384 385
	}

L
Len Brown 已提交
386
	return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
387 388
}

B
Bob Moore 已提交
389
ACPI_EXPORT_SYMBOL(acpi_disable_event)
L
Linus Torvalds 已提交
390 391 392 393 394 395 396 397 398 399 400 401

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

B
Bob Moore 已提交
406
	ACPI_FUNCTION_TRACE(acpi_clear_event);
L
Linus Torvalds 已提交
407 408 409 410

	/* Decode the Fixed Event */

	if (event > ACPI_EVENT_MAX) {
L
Len Brown 已提交
411
		return_ACPI_STATUS(AE_BAD_PARAMETER);
L
Linus Torvalds 已提交
412 413 414 415 416 417
	}

	/*
	 * Clear the requested fixed event (By writing a one to the
	 * status register bit)
	 */
L
Len Brown 已提交
418 419
	status =
	    acpi_set_register(acpi_gbl_fixed_event_info[event].
420
			      status_register_id, 1);
L
Linus Torvalds 已提交
421

L
Len Brown 已提交
422
	return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
423 424
}

B
Bob Moore 已提交
425
ACPI_EXPORT_SYMBOL(acpi_clear_event)
L
Linus Torvalds 已提交
426 427 428 429 430 431 432 433 434 435 436 437 438 439

/*******************************************************************************
 *
 * FUNCTION:    acpi_clear_gpe
 *
 * PARAMETERS:  gpe_device      - Parent GPE Device
 *              gpe_number      - GPE level within the GPE block
 *              Flags           - Called from an ISR or not
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Clear an ACPI event (general purpose)
 *
 ******************************************************************************/
L
Len Brown 已提交
440
acpi_status acpi_clear_gpe(acpi_handle gpe_device, u32 gpe_number, u32 flags)
L
Linus Torvalds 已提交
441
{
L
Len Brown 已提交
442 443
	acpi_status status = AE_OK;
	struct acpi_gpe_event_info *gpe_event_info;
L
Linus Torvalds 已提交
444

B
Bob Moore 已提交
445
	ACPI_FUNCTION_TRACE(acpi_clear_gpe);
L
Linus Torvalds 已提交
446 447 448 449

	/* Use semaphore lock if not executing at interrupt level */

	if (flags & ACPI_NOT_ISR) {
L
Len Brown 已提交
450 451 452
		status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
		if (ACPI_FAILURE(status)) {
			return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
453 454 455 456 457
		}
	}

	/* Ensure that we have a valid GPE number */

L
Len Brown 已提交
458
	gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
L
Linus Torvalds 已提交
459 460 461 462 463
	if (!gpe_event_info) {
		status = AE_BAD_PARAMETER;
		goto unlock_and_exit;
	}

L
Len Brown 已提交
464
	status = acpi_hw_clear_gpe(gpe_event_info);
L
Linus Torvalds 已提交
465

L
Len Brown 已提交
466
      unlock_and_exit:
L
Linus Torvalds 已提交
467
	if (flags & ACPI_NOT_ISR) {
L
Len Brown 已提交
468
		(void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
L
Linus Torvalds 已提交
469
	}
L
Len Brown 已提交
470
	return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
471 472
}

B
Bob Moore 已提交
473 474
ACPI_EXPORT_SYMBOL(acpi_clear_gpe)

L
Linus Torvalds 已提交
475 476 477 478 479 480
#ifdef ACPI_FUTURE_USAGE
/*******************************************************************************
 *
 * FUNCTION:    acpi_get_event_status
 *
 * PARAMETERS:  Event           - The fixed event
R
Robert Moore 已提交
481
 *              event_status    - Where the current status of the event will
L
Linus Torvalds 已提交
482 483 484 485 486 487 488
 *                                be returned
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Obtains and returns the current status of the event
 *
 ******************************************************************************/
L
Len Brown 已提交
489
acpi_status acpi_get_event_status(u32 event, acpi_event_status * event_status)
L
Linus Torvalds 已提交
490
{
L
Len Brown 已提交
491
	acpi_status status = AE_OK;
L
Linus Torvalds 已提交
492

B
Bob Moore 已提交
493
	ACPI_FUNCTION_TRACE(acpi_get_event_status);
L
Linus Torvalds 已提交
494 495

	if (!event_status) {
L
Len Brown 已提交
496
		return_ACPI_STATUS(AE_BAD_PARAMETER);
L
Linus Torvalds 已提交
497 498 499 500 501
	}

	/* Decode the Fixed Event */

	if (event > ACPI_EVENT_MAX) {
L
Len Brown 已提交
502
		return_ACPI_STATUS(AE_BAD_PARAMETER);
L
Linus Torvalds 已提交
503 504 505 506
	}

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

L
Len Brown 已提交
507 508
	status =
	    acpi_get_register(acpi_gbl_fixed_event_info[event].
509
			      status_register_id, event_status);
L
Linus Torvalds 已提交
510

L
Len Brown 已提交
511
	return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
512 513
}

B
Bob Moore 已提交
514 515
ACPI_EXPORT_SYMBOL(acpi_get_event_status)

L
Linus Torvalds 已提交
516 517 518 519 520 521 522
/*******************************************************************************
 *
 * FUNCTION:    acpi_get_gpe_status
 *
 * PARAMETERS:  gpe_device      - Parent GPE Device
 *              gpe_number      - GPE level within the GPE block
 *              Flags           - Called from an ISR or not
R
Robert Moore 已提交
523
 *              event_status    - Where the current status of the event will
L
Linus Torvalds 已提交
524 525 526 527 528 529 530 531
 *                                be returned
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Get status of an event (general purpose)
 *
 ******************************************************************************/
acpi_status
L
Len Brown 已提交
532 533
acpi_get_gpe_status(acpi_handle gpe_device,
		    u32 gpe_number, u32 flags, acpi_event_status * event_status)
L
Linus Torvalds 已提交
534
{
L
Len Brown 已提交
535 536
	acpi_status status = AE_OK;
	struct acpi_gpe_event_info *gpe_event_info;
L
Linus Torvalds 已提交
537

B
Bob Moore 已提交
538
	ACPI_FUNCTION_TRACE(acpi_get_gpe_status);
L
Linus Torvalds 已提交
539 540 541 542

	/* Use semaphore lock if not executing at interrupt level */

	if (flags & ACPI_NOT_ISR) {
L
Len Brown 已提交
543 544 545
		status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
		if (ACPI_FAILURE(status)) {
			return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
546 547 548 549 550
		}
	}

	/* Ensure that we have a valid GPE number */

L
Len Brown 已提交
551
	gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
L
Linus Torvalds 已提交
552 553 554 555 556 557 558
	if (!gpe_event_info) {
		status = AE_BAD_PARAMETER;
		goto unlock_and_exit;
	}

	/* Obtain status on the requested GPE number */

L
Len Brown 已提交
559
	status = acpi_hw_get_gpe_status(gpe_event_info, event_status);
L
Linus Torvalds 已提交
560

L
Len Brown 已提交
561
      unlock_and_exit:
L
Linus Torvalds 已提交
562
	if (flags & ACPI_NOT_ISR) {
L
Len Brown 已提交
563
		(void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
L
Linus Torvalds 已提交
564
	}
L
Len Brown 已提交
565
	return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
566
}
B
Bob Moore 已提交
567 568

ACPI_EXPORT_SYMBOL(acpi_get_gpe_status)
L
Len Brown 已提交
569
#endif				/*  ACPI_FUTURE_USAGE  */
L
Linus Torvalds 已提交
570 571 572 573 574 575 576 577

/*******************************************************************************
 *
 * FUNCTION:    acpi_install_gpe_block
 *
 * PARAMETERS:  gpe_device          - Handle to the parent GPE Block Device
 *              gpe_block_address   - Address and space_iD
 *              register_count      - Number of GPE register pairs in the block
578
 *              interrupt_number    - H/W interrupt for the block
L
Linus Torvalds 已提交
579 580 581 582 583 584 585
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Create and Install a block of GPE registers
 *
 ******************************************************************************/
acpi_status
L
Len Brown 已提交
586 587 588
acpi_install_gpe_block(acpi_handle gpe_device,
		       struct acpi_generic_address *gpe_block_address,
		       u32 register_count, u32 interrupt_number)
L
Linus Torvalds 已提交
589
{
L
Len Brown 已提交
590 591 592 593
	acpi_status status;
	union acpi_operand_object *obj_desc;
	struct acpi_namespace_node *node;
	struct acpi_gpe_block_info *gpe_block;
L
Linus Torvalds 已提交
594

B
Bob Moore 已提交
595
	ACPI_FUNCTION_TRACE(acpi_install_gpe_block);
L
Linus Torvalds 已提交
596

L
Len Brown 已提交
597 598
	if ((!gpe_device) || (!gpe_block_address) || (!register_count)) {
		return_ACPI_STATUS(AE_BAD_PARAMETER);
L
Linus Torvalds 已提交
599 600
	}

L
Len Brown 已提交
601 602
	status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
	if (ACPI_FAILURE(status)) {
L
Linus Torvalds 已提交
603 604 605
		return (status);
	}

L
Len Brown 已提交
606
	node = acpi_ns_map_handle_to_node(gpe_device);
L
Linus Torvalds 已提交
607 608 609 610 611 612 613 614 615
	if (!node) {
		status = AE_BAD_PARAMETER;
		goto unlock_and_exit;
	}

	/*
	 * For user-installed GPE Block Devices, the gpe_block_base_number
	 * is always zero
	 */
L
Len Brown 已提交
616 617 618 619
	status =
	    acpi_ev_create_gpe_block(node, gpe_block_address, register_count, 0,
				     interrupt_number, &gpe_block);
	if (ACPI_FAILURE(status)) {
L
Linus Torvalds 已提交
620 621 622
		goto unlock_and_exit;
	}

B
Bob Moore 已提交
623 624 625 626 627 628 629
	/* Run the _PRW methods and enable the GPEs */

	status = acpi_ev_initialize_gpe_block(node, gpe_block);
	if (ACPI_FAILURE(status)) {
		goto unlock_and_exit;
	}

L
Linus Torvalds 已提交
630 631
	/* Get the device_object attached to the node */

L
Len Brown 已提交
632
	obj_desc = acpi_ns_get_attached_object(node);
L
Linus Torvalds 已提交
633
	if (!obj_desc) {
B
Bob Moore 已提交
634

L
Linus Torvalds 已提交
635 636
		/* No object, create a new one */

L
Len Brown 已提交
637
		obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_DEVICE);
L
Linus Torvalds 已提交
638 639 640 641 642
		if (!obj_desc) {
			status = AE_NO_MEMORY;
			goto unlock_and_exit;
		}

L
Len Brown 已提交
643 644
		status =
		    acpi_ns_attach_object(node, obj_desc, ACPI_TYPE_DEVICE);
L
Linus Torvalds 已提交
645 646 647

		/* Remove local reference to the object */

L
Len Brown 已提交
648
		acpi_ut_remove_reference(obj_desc);
L
Linus Torvalds 已提交
649

L
Len Brown 已提交
650
		if (ACPI_FAILURE(status)) {
L
Linus Torvalds 已提交
651 652 653 654 655 656 657 658
			goto unlock_and_exit;
		}
	}

	/* Install the GPE block in the device_object */

	obj_desc->device.gpe_block = gpe_block;

L
Len Brown 已提交
659 660 661
      unlock_and_exit:
	(void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
	return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
662 663
}

B
Bob Moore 已提交
664
ACPI_EXPORT_SYMBOL(acpi_install_gpe_block)
L
Linus Torvalds 已提交
665 666 667 668 669 670 671 672 673 674 675 676

/*******************************************************************************
 *
 * FUNCTION:    acpi_remove_gpe_block
 *
 * PARAMETERS:  gpe_device          - Handle to the parent GPE Block Device
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Remove a previously installed block of GPE registers
 *
 ******************************************************************************/
L
Len Brown 已提交
677
acpi_status acpi_remove_gpe_block(acpi_handle gpe_device)
L
Linus Torvalds 已提交
678
{
L
Len Brown 已提交
679 680 681
	union acpi_operand_object *obj_desc;
	acpi_status status;
	struct acpi_namespace_node *node;
L
Linus Torvalds 已提交
682

B
Bob Moore 已提交
683
	ACPI_FUNCTION_TRACE(acpi_remove_gpe_block);
L
Linus Torvalds 已提交
684 685

	if (!gpe_device) {
L
Len Brown 已提交
686
		return_ACPI_STATUS(AE_BAD_PARAMETER);
L
Linus Torvalds 已提交
687 688
	}

L
Len Brown 已提交
689 690
	status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
	if (ACPI_FAILURE(status)) {
L
Linus Torvalds 已提交
691 692 693
		return (status);
	}

L
Len Brown 已提交
694
	node = acpi_ns_map_handle_to_node(gpe_device);
L
Linus Torvalds 已提交
695 696 697 698 699 700 701
	if (!node) {
		status = AE_BAD_PARAMETER;
		goto unlock_and_exit;
	}

	/* Get the device_object attached to the node */

L
Len Brown 已提交
702 703 704
	obj_desc = acpi_ns_get_attached_object(node);
	if (!obj_desc || !obj_desc->device.gpe_block) {
		return_ACPI_STATUS(AE_NULL_OBJECT);
L
Linus Torvalds 已提交
705 706 707 708
	}

	/* Delete the GPE block (but not the device_object) */

L
Len Brown 已提交
709 710
	status = acpi_ev_delete_gpe_block(obj_desc->device.gpe_block);
	if (ACPI_SUCCESS(status)) {
L
Linus Torvalds 已提交
711 712 713
		obj_desc->device.gpe_block = NULL;
	}

L
Len Brown 已提交
714 715 716
      unlock_and_exit:
	(void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
	return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
717
}
R
Robert Moore 已提交
718

B
Bob Moore 已提交
719
ACPI_EXPORT_SYMBOL(acpi_remove_gpe_block)