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 - 2007, 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
 * 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>
B
Bob Moore 已提交
47
#include <acpi/actables.h>
L
Linus Torvalds 已提交
48 49

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

/*******************************************************************************
 *
 * FUNCTION:    acpi_enable
 *
 * PARAMETERS:  None
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Transfers the system into ACPI mode.
 *
 ******************************************************************************/
L
Len Brown 已提交
63
acpi_status acpi_enable(void)
L
Linus Torvalds 已提交
64
{
L
Len Brown 已提交
65
	acpi_status status = AE_OK;
L
Linus Torvalds 已提交
66

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

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

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

	/* Check current mode */

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	/* Decode the Fixed Event */

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

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

	/* Make sure that the hardware responded */

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

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

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

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

/*******************************************************************************
 *
 * 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 已提交
205
 * DESCRIPTION: Set the type of an individual GPE
L
Linus Torvalds 已提交
206 207
 *
 ******************************************************************************/
L
Len Brown 已提交
208
acpi_status acpi_set_gpe_type(acpi_handle gpe_device, u32 gpe_number, u8 type)
L
Linus Torvalds 已提交
209
{
L
Len Brown 已提交
210 211
	acpi_status status = AE_OK;
	struct acpi_gpe_event_info *gpe_event_info;
L
Linus Torvalds 已提交
212

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

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

L
Len Brown 已提交
217
	gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
L
Linus Torvalds 已提交
218 219 220 221 222 223
	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 已提交
224
		return_ACPI_STATUS(AE_OK);
L
Linus Torvalds 已提交
225 226 227 228
	}

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

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

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

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

/*******************************************************************************
 *
 * 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 已提交
251
acpi_status acpi_enable_gpe(acpi_handle gpe_device, u32 gpe_number, u32 flags)
L
Linus Torvalds 已提交
252
{
L
Len Brown 已提交
253 254
	acpi_status status = AE_OK;
	struct acpi_gpe_event_info *gpe_event_info;
L
Linus Torvalds 已提交
255

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

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

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

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

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

	/* Perform the enable */

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

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

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

/*******************************************************************************
 *
 * 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 已提交
302
acpi_status acpi_disable_gpe(acpi_handle gpe_device, u32 gpe_number, u32 flags)
L
Linus Torvalds 已提交
303
{
L
Len Brown 已提交
304 305
	acpi_status status = AE_OK;
	struct acpi_gpe_event_info *gpe_event_info;
L
Linus Torvalds 已提交
306

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

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

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

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

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

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

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

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

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

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

	/* Decode the Fixed Event */

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

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

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

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

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

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

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

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

	/* Decode the Fixed Event */

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

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

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

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

/*******************************************************************************
 *
 * 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 已提交
441
acpi_status acpi_clear_gpe(acpi_handle gpe_device, u32 gpe_number, u32 flags)
L
Linus Torvalds 已提交
442
{
L
Len Brown 已提交
443 444
	acpi_status status = AE_OK;
	struct acpi_gpe_event_info *gpe_event_info;
L
Linus Torvalds 已提交
445

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

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

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

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

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

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

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

B
Bob Moore 已提交
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
/*******************************************************************************
 *
 * 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
577
 *              interrupt_number    - H/W interrupt for the block
L
Linus Torvalds 已提交
578 579 580 581 582 583 584
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Create and Install a block of GPE registers
 *
 ******************************************************************************/
acpi_status
L
Len Brown 已提交
585 586 587
acpi_install_gpe_block(acpi_handle gpe_device,
		       struct acpi_generic_address *gpe_block_address,
		       u32 register_count, u32 interrupt_number)
L
Linus Torvalds 已提交
588
{
L
Len Brown 已提交
589 590 591 592
	acpi_status status;
	union acpi_operand_object *obj_desc;
	struct acpi_namespace_node *node;
	struct acpi_gpe_block_info *gpe_block;
L
Linus Torvalds 已提交
593

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

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

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

L
Len Brown 已提交
605
	node = acpi_ns_map_handle_to_node(gpe_device);
L
Linus Torvalds 已提交
606 607 608 609 610 611 612 613 614
	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 已提交
615 616 617 618
	status =
	    acpi_ev_create_gpe_block(node, gpe_block_address, register_count, 0,
				     interrupt_number, &gpe_block);
	if (ACPI_FAILURE(status)) {
L
Linus Torvalds 已提交
619 620 621
		goto unlock_and_exit;
	}

B
Bob Moore 已提交
622 623 624 625 626 627 628
	/* 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 已提交
629 630
	/* Get the device_object attached to the node */

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

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

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

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

		/* Remove local reference to the object */

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

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

	/* Install the GPE block in the device_object */

	obj_desc->device.gpe_block = gpe_block;

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

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

/*******************************************************************************
 *
 * 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 已提交
676
acpi_status acpi_remove_gpe_block(acpi_handle gpe_device)
L
Linus Torvalds 已提交
677
{
L
Len Brown 已提交
678 679 680
	union acpi_operand_object *obj_desc;
	acpi_status status;
	struct acpi_namespace_node *node;
L
Linus Torvalds 已提交
681

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

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

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

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

	/* Get the device_object attached to the node */

L
Len Brown 已提交
701 702 703
	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 已提交
704 705 706 707
	}

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

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

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

B
Bob Moore 已提交
718
ACPI_EXPORT_SYMBOL(acpi_remove_gpe_block)