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

/*
L
Len Brown 已提交
8
 * Copyright (C) 2000 - 2008, 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 47 48
#include "accommon.h"
#include "acevents.h"
#include "acnamesp.h"
#include "actables.h"
L
Linus Torvalds 已提交
49 50

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

53 54 55 56 57
/* Local prototypes */
acpi_status
acpi_ev_get_gpe_device(struct acpi_gpe_xrupt_info *gpe_xrupt_info,
		       struct acpi_gpe_block_info *gpe_block, void *context);

L
Linus Torvalds 已提交
58 59 60 61 62 63 64 65 66 67 68
/*******************************************************************************
 *
 * FUNCTION:    acpi_enable
 *
 * PARAMETERS:  None
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Transfers the system into ACPI mode.
 *
 ******************************************************************************/
69

L
Len Brown 已提交
70
acpi_status acpi_enable(void)
L
Linus Torvalds 已提交
71
{
L
Len Brown 已提交
72
	acpi_status status = AE_OK;
L
Linus Torvalds 已提交
73

B
Bob Moore 已提交
74
	ACPI_FUNCTION_TRACE(acpi_enable);
L
Linus Torvalds 已提交
75

76 77 78 79 80 81 82 83
	/* ACPI tables must be present */

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

	/* Check current mode */

L
Linus Torvalds 已提交
84
	if (acpi_hw_get_mode() == ACPI_SYS_MODE_ACPI) {
L
Len Brown 已提交
85 86 87
		ACPI_DEBUG_PRINT((ACPI_DB_INIT,
				  "System is already in ACPI mode\n"));
	} else {
L
Linus Torvalds 已提交
88 89
		/* Transition to ACPI mode */

L
Len Brown 已提交
90 91
		status = acpi_hw_set_mode(ACPI_SYS_MODE_ACPI);
		if (ACPI_FAILURE(status)) {
B
Bob Moore 已提交
92 93
			ACPI_ERROR((AE_INFO,
				    "Could not transition to ACPI mode"));
L
Len Brown 已提交
94
			return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
95 96
		}

L
Len Brown 已提交
97 98
		ACPI_DEBUG_PRINT((ACPI_DB_INIT,
				  "Transition to ACPI mode successful\n"));
L
Linus Torvalds 已提交
99 100
	}

L
Len Brown 已提交
101
	return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
102 103
}

B
Bob Moore 已提交
104 105
ACPI_EXPORT_SYMBOL(acpi_enable)

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

B
Bob Moore 已提交
121
	ACPI_FUNCTION_TRACE(acpi_disable);
L
Linus Torvalds 已提交
122 123

	if (acpi_hw_get_mode() == ACPI_SYS_MODE_LEGACY) {
L
Len Brown 已提交
124 125 126
		ACPI_DEBUG_PRINT((ACPI_DB_INIT,
				  "System is already in legacy (non-ACPI) mode\n"));
	} else {
L
Linus Torvalds 已提交
127 128
		/* Transition to LEGACY mode */

L
Len Brown 已提交
129
		status = acpi_hw_set_mode(ACPI_SYS_MODE_LEGACY);
L
Linus Torvalds 已提交
130

L
Len Brown 已提交
131
		if (ACPI_FAILURE(status)) {
B
Bob Moore 已提交
132 133
			ACPI_ERROR((AE_INFO,
				    "Could not exit ACPI mode to legacy mode"));
L
Len Brown 已提交
134
			return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
135 136
		}

L
Len Brown 已提交
137
		ACPI_DEBUG_PRINT((ACPI_DB_INIT, "ACPI mode disabled\n"));
L
Linus Torvalds 已提交
138 139
	}

L
Len Brown 已提交
140
	return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
141 142
}

B
Bob Moore 已提交
143 144
ACPI_EXPORT_SYMBOL(acpi_disable)

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

B
Bob Moore 已提交
162
	ACPI_FUNCTION_TRACE(acpi_enable_event);
L
Linus Torvalds 已提交
163 164 165 166

	/* Decode the Fixed Event */

	if (event > ACPI_EVENT_MAX) {
L
Len Brown 已提交
167
		return_ACPI_STATUS(AE_BAD_PARAMETER);
L
Linus Torvalds 已提交
168 169 170
	}

	/*
171 172
	 * Enable the requested fixed event (by writing a one to the enable
	 * register bit)
L
Linus Torvalds 已提交
173
	 */
L
Len Brown 已提交
174
	status =
175 176
	    acpi_write_bit_register(acpi_gbl_fixed_event_info[event].
				    enable_register_id, 1);
L
Len Brown 已提交
177 178
	if (ACPI_FAILURE(status)) {
		return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
179 180 181 182
	}

	/* Make sure that the hardware responded */

L
Len Brown 已提交
183
	status =
184 185
	    acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
				   enable_register_id, &value);
L
Len Brown 已提交
186 187
	if (ACPI_FAILURE(status)) {
		return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
188 189 190
	}

	if (value != 1) {
B
Bob Moore 已提交
191 192 193
		ACPI_ERROR((AE_INFO,
			    "Could not enable %s event",
			    acpi_ut_get_event_name(event)));
L
Len Brown 已提交
194
		return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);
L
Linus Torvalds 已提交
195 196
	}

L
Len Brown 已提交
197
	return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
198 199
}

B
Bob Moore 已提交
200
ACPI_EXPORT_SYMBOL(acpi_enable_event)
L
Linus Torvalds 已提交
201 202 203 204 205 206 207 208 209 210 211

/*******************************************************************************
 *
 * 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 已提交
212
 * DESCRIPTION: Set the type of an individual GPE
L
Linus Torvalds 已提交
213 214
 *
 ******************************************************************************/
L
Len Brown 已提交
215
acpi_status acpi_set_gpe_type(acpi_handle gpe_device, u32 gpe_number, u8 type)
L
Linus Torvalds 已提交
216
{
L
Len Brown 已提交
217 218
	acpi_status status = AE_OK;
	struct acpi_gpe_event_info *gpe_event_info;
L
Linus Torvalds 已提交
219

B
Bob Moore 已提交
220
	ACPI_FUNCTION_TRACE(acpi_set_gpe_type);
L
Linus Torvalds 已提交
221 222 223

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

L
Len Brown 已提交
224
	gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
L
Linus Torvalds 已提交
225 226 227 228 229 230
	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 已提交
231
		return_ACPI_STATUS(AE_OK);
L
Linus Torvalds 已提交
232 233 234 235
	}

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

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

L
Len Brown 已提交
238 239
      unlock_and_exit:
	return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
240 241
}

B
Bob Moore 已提交
242
ACPI_EXPORT_SYMBOL(acpi_set_gpe_type)
L
Linus Torvalds 已提交
243 244 245 246 247 248 249 250 251 252 253 254 255 256 257

/*******************************************************************************
 *
 * 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)
 *
 ******************************************************************************/
258
acpi_status acpi_enable_gpe(acpi_handle gpe_device, u32 gpe_number)
L
Linus Torvalds 已提交
259
{
L
Len Brown 已提交
260
	acpi_status status = AE_OK;
261
	acpi_cpu_flags flags;
L
Len Brown 已提交
262
	struct acpi_gpe_event_info *gpe_event_info;
L
Linus Torvalds 已提交
263

B
Bob Moore 已提交
264
	ACPI_FUNCTION_TRACE(acpi_enable_gpe);
L
Linus Torvalds 已提交
265

266
	flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
L
Linus Torvalds 已提交
267 268 269

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

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

	/* Perform the enable */

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

L
Len Brown 已提交
280
      unlock_and_exit:
281
	acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
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)
 *
 ******************************************************************************/
301
acpi_status acpi_disable_gpe(acpi_handle gpe_device, u32 gpe_number)
L
Linus Torvalds 已提交
302
{
L
Len Brown 已提交
303
	acpi_status status = AE_OK;
304
	acpi_cpu_flags flags;
L
Len Brown 已提交
305
	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
	flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
L
Linus Torvalds 已提交
310 311
	/* Ensure that we have a valid GPE number */

L
Len Brown 已提交
312
	gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
L
Linus Torvalds 已提交
313 314 315 316 317
	if (!gpe_event_info) {
		status = AE_BAD_PARAMETER;
		goto unlock_and_exit;
	}

L
Len Brown 已提交
318
	status = acpi_ev_disable_gpe(gpe_event_info);
L
Linus Torvalds 已提交
319

320 321
unlock_and_exit:
	acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
L
Len Brown 已提交
322
	return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
323 324
}

B
Bob Moore 已提交
325 326
ACPI_EXPORT_SYMBOL(acpi_disable_gpe)

L
Linus Torvalds 已提交
327 328 329 330 331 332 333 334 335 336 337 338
/*******************************************************************************
 *
 * FUNCTION:    acpi_disable_event
 *
 * PARAMETERS:  Event           - The fixed eventto be enabled
 *              Flags           - Reserved
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Disable an ACPI event (fixed)
 *
 ******************************************************************************/
L
Len Brown 已提交
339
acpi_status acpi_disable_event(u32 event, u32 flags)
L
Linus Torvalds 已提交
340
{
L
Len Brown 已提交
341 342
	acpi_status status = AE_OK;
	u32 value;
L
Linus Torvalds 已提交
343

B
Bob Moore 已提交
344
	ACPI_FUNCTION_TRACE(acpi_disable_event);
L
Linus Torvalds 已提交
345 346 347 348

	/* Decode the Fixed Event */

	if (event > ACPI_EVENT_MAX) {
L
Len Brown 已提交
349
		return_ACPI_STATUS(AE_BAD_PARAMETER);
L
Linus Torvalds 已提交
350 351 352
	}

	/*
353 354
	 * Disable the requested fixed event (by writing a zero to the enable
	 * register bit)
L
Linus Torvalds 已提交
355
	 */
L
Len Brown 已提交
356
	status =
357 358
	    acpi_write_bit_register(acpi_gbl_fixed_event_info[event].
				    enable_register_id, 0);
L
Len Brown 已提交
359 360
	if (ACPI_FAILURE(status)) {
		return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
361 362
	}

L
Len Brown 已提交
363
	status =
364 365
	    acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
				   enable_register_id, &value);
L
Len Brown 已提交
366 367
	if (ACPI_FAILURE(status)) {
		return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
368 369 370
	}

	if (value != 0) {
B
Bob Moore 已提交
371 372 373
		ACPI_ERROR((AE_INFO,
			    "Could not disable %s events",
			    acpi_ut_get_event_name(event)));
L
Len Brown 已提交
374
		return_ACPI_STATUS(AE_NO_HARDWARE_RESPONSE);
L
Linus Torvalds 已提交
375 376
	}

L
Len Brown 已提交
377
	return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
378 379
}

B
Bob Moore 已提交
380
ACPI_EXPORT_SYMBOL(acpi_disable_event)
L
Linus Torvalds 已提交
381 382 383 384 385 386 387 388 389 390 391 392

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

B
Bob Moore 已提交
397
	ACPI_FUNCTION_TRACE(acpi_clear_event);
L
Linus Torvalds 已提交
398 399 400 401

	/* Decode the Fixed Event */

	if (event > ACPI_EVENT_MAX) {
L
Len Brown 已提交
402
		return_ACPI_STATUS(AE_BAD_PARAMETER);
L
Linus Torvalds 已提交
403 404 405
	}

	/*
406 407
	 * Clear the requested fixed event (By writing a one to the status
	 * register bit)
L
Linus Torvalds 已提交
408
	 */
L
Len Brown 已提交
409
	status =
410 411
	    acpi_write_bit_register(acpi_gbl_fixed_event_info[event].
				    status_register_id, 1);
L
Linus Torvalds 已提交
412

L
Len Brown 已提交
413
	return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
414 415
}

B
Bob Moore 已提交
416
ACPI_EXPORT_SYMBOL(acpi_clear_event)
L
Linus Torvalds 已提交
417 418 419 420 421 422 423 424 425 426 427 428 429 430

/*******************************************************************************
 *
 * 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 已提交
431
acpi_status acpi_clear_gpe(acpi_handle gpe_device, u32 gpe_number, u32 flags)
L
Linus Torvalds 已提交
432
{
L
Len Brown 已提交
433 434
	acpi_status status = AE_OK;
	struct acpi_gpe_event_info *gpe_event_info;
L
Linus Torvalds 已提交
435

B
Bob Moore 已提交
436
	ACPI_FUNCTION_TRACE(acpi_clear_gpe);
L
Linus Torvalds 已提交
437 438 439 440

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

	if (flags & ACPI_NOT_ISR) {
L
Len Brown 已提交
441 442 443
		status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
		if (ACPI_FAILURE(status)) {
			return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
444 445 446 447 448
		}
	}

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

L
Len Brown 已提交
449
	gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
L
Linus Torvalds 已提交
450 451 452 453 454
	if (!gpe_event_info) {
		status = AE_BAD_PARAMETER;
		goto unlock_and_exit;
	}

L
Len Brown 已提交
455
	status = acpi_hw_clear_gpe(gpe_event_info);
L
Linus Torvalds 已提交
456

L
Len Brown 已提交
457
      unlock_and_exit:
L
Linus Torvalds 已提交
458
	if (flags & ACPI_NOT_ISR) {
L
Len Brown 已提交
459
		(void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
L
Linus Torvalds 已提交
460
	}
L
Len Brown 已提交
461
	return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
462 463
}

B
Bob Moore 已提交
464
ACPI_EXPORT_SYMBOL(acpi_clear_gpe)
L
Linus Torvalds 已提交
465 466 467 468 469
/*******************************************************************************
 *
 * FUNCTION:    acpi_get_event_status
 *
 * PARAMETERS:  Event           - The fixed event
R
Robert Moore 已提交
470
 *              event_status    - Where the current status of the event will
L
Linus Torvalds 已提交
471 472 473 474 475 476 477
 *                                be returned
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Obtains and returns the current status of the event
 *
 ******************************************************************************/
L
Len Brown 已提交
478
acpi_status acpi_get_event_status(u32 event, acpi_event_status * event_status)
L
Linus Torvalds 已提交
479
{
L
Len Brown 已提交
480
	acpi_status status = AE_OK;
481
	u32 value;
L
Linus Torvalds 已提交
482

B
Bob Moore 已提交
483
	ACPI_FUNCTION_TRACE(acpi_get_event_status);
L
Linus Torvalds 已提交
484 485

	if (!event_status) {
L
Len Brown 已提交
486
		return_ACPI_STATUS(AE_BAD_PARAMETER);
L
Linus Torvalds 已提交
487 488 489 490 491
	}

	/* Decode the Fixed Event */

	if (event > ACPI_EVENT_MAX) {
L
Len Brown 已提交
492
		return_ACPI_STATUS(AE_BAD_PARAMETER);
L
Linus Torvalds 已提交
493 494 495 496
	}

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

L
Len Brown 已提交
497
	status =
498
	    acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
499 500 501 502 503 504 505
			      enable_register_id, &value);
	if (ACPI_FAILURE(status))
		return_ACPI_STATUS(status);

	*event_status = value;

	status =
506
	    acpi_read_bit_register(acpi_gbl_fixed_event_info[event].
507 508 509 510 511 512
			      status_register_id, &value);
	if (ACPI_FAILURE(status))
		return_ACPI_STATUS(status);

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

514 515 516
	if (acpi_gbl_fixed_event_handlers[event].handler)
		*event_status |= ACPI_EVENT_FLAG_HANDLE;

L
Len Brown 已提交
517
	return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
518 519
}

B
Bob Moore 已提交
520 521
ACPI_EXPORT_SYMBOL(acpi_get_event_status)

L
Linus Torvalds 已提交
522 523 524 525 526 527 528
/*******************************************************************************
 *
 * 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 已提交
529
 *              event_status    - Where the current status of the event will
L
Linus Torvalds 已提交
530 531 532 533 534 535 536 537
 *                                be returned
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Get status of an event (general purpose)
 *
 ******************************************************************************/
acpi_status
L
Len Brown 已提交
538 539
acpi_get_gpe_status(acpi_handle gpe_device,
		    u32 gpe_number, u32 flags, acpi_event_status * event_status)
L
Linus Torvalds 已提交
540
{
L
Len Brown 已提交
541 542
	acpi_status status = AE_OK;
	struct acpi_gpe_event_info *gpe_event_info;
L
Linus Torvalds 已提交
543

B
Bob Moore 已提交
544
	ACPI_FUNCTION_TRACE(acpi_get_gpe_status);
L
Linus Torvalds 已提交
545 546 547 548

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

	if (flags & ACPI_NOT_ISR) {
L
Len Brown 已提交
549 550 551
		status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
		if (ACPI_FAILURE(status)) {
			return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
552 553 554 555 556
		}
	}

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

L
Len Brown 已提交
557
	gpe_event_info = acpi_ev_get_gpe_event_info(gpe_device, gpe_number);
L
Linus Torvalds 已提交
558 559 560 561 562 563 564
	if (!gpe_event_info) {
		status = AE_BAD_PARAMETER;
		goto unlock_and_exit;
	}

	/* Obtain status on the requested GPE number */

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

567 568 569
	if (gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK)
		*event_status |= ACPI_EVENT_FLAG_HANDLE;

L
Len Brown 已提交
570
      unlock_and_exit:
L
Linus Torvalds 已提交
571
	if (flags & ACPI_NOT_ISR) {
L
Len Brown 已提交
572
		(void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
L
Linus Torvalds 已提交
573
	}
L
Len Brown 已提交
574
	return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
575
}
B
Bob Moore 已提交
576 577

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

B
Bob Moore 已提交
602
	ACPI_FUNCTION_TRACE(acpi_install_gpe_block);
L
Linus Torvalds 已提交
603

L
Len Brown 已提交
604 605
	if ((!gpe_device) || (!gpe_block_address) || (!register_count)) {
		return_ACPI_STATUS(AE_BAD_PARAMETER);
L
Linus Torvalds 已提交
606 607
	}

L
Len Brown 已提交
608 609
	status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
	if (ACPI_FAILURE(status)) {
L
Linus Torvalds 已提交
610 611 612
		return (status);
	}

L
Len Brown 已提交
613
	node = acpi_ns_map_handle_to_node(gpe_device);
L
Linus Torvalds 已提交
614 615 616 617 618 619 620 621 622
	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 已提交
623 624 625 626
	status =
	    acpi_ev_create_gpe_block(node, gpe_block_address, register_count, 0,
				     interrupt_number, &gpe_block);
	if (ACPI_FAILURE(status)) {
L
Linus Torvalds 已提交
627 628 629
		goto unlock_and_exit;
	}

B
Bob Moore 已提交
630 631 632 633 634 635 636
	/* 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 已提交
637 638
	/* Get the device_object attached to the node */

L
Len Brown 已提交
639
	obj_desc = acpi_ns_get_attached_object(node);
L
Linus Torvalds 已提交
640
	if (!obj_desc) {
B
Bob Moore 已提交
641

L
Linus Torvalds 已提交
642 643
		/* No object, create a new one */

L
Len Brown 已提交
644
		obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_DEVICE);
L
Linus Torvalds 已提交
645 646 647 648 649
		if (!obj_desc) {
			status = AE_NO_MEMORY;
			goto unlock_and_exit;
		}

L
Len Brown 已提交
650 651
		status =
		    acpi_ns_attach_object(node, obj_desc, ACPI_TYPE_DEVICE);
L
Linus Torvalds 已提交
652 653 654

		/* Remove local reference to the object */

L
Len Brown 已提交
655
		acpi_ut_remove_reference(obj_desc);
L
Linus Torvalds 已提交
656

L
Len Brown 已提交
657
		if (ACPI_FAILURE(status)) {
L
Linus Torvalds 已提交
658 659 660 661 662 663 664 665
			goto unlock_and_exit;
		}
	}

	/* Install the GPE block in the device_object */

	obj_desc->device.gpe_block = gpe_block;

L
Len Brown 已提交
666 667 668
      unlock_and_exit:
	(void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
	return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
669 670
}

B
Bob Moore 已提交
671
ACPI_EXPORT_SYMBOL(acpi_install_gpe_block)
L
Linus Torvalds 已提交
672 673 674 675 676 677 678 679 680 681 682 683

/*******************************************************************************
 *
 * 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 已提交
684
acpi_status acpi_remove_gpe_block(acpi_handle gpe_device)
L
Linus Torvalds 已提交
685
{
L
Len Brown 已提交
686 687 688
	union acpi_operand_object *obj_desc;
	acpi_status status;
	struct acpi_namespace_node *node;
L
Linus Torvalds 已提交
689

B
Bob Moore 已提交
690
	ACPI_FUNCTION_TRACE(acpi_remove_gpe_block);
L
Linus Torvalds 已提交
691 692

	if (!gpe_device) {
L
Len Brown 已提交
693
		return_ACPI_STATUS(AE_BAD_PARAMETER);
L
Linus Torvalds 已提交
694 695
	}

L
Len Brown 已提交
696 697
	status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
	if (ACPI_FAILURE(status)) {
L
Linus Torvalds 已提交
698 699 700
		return (status);
	}

L
Len Brown 已提交
701
	node = acpi_ns_map_handle_to_node(gpe_device);
L
Linus Torvalds 已提交
702 703 704 705 706 707 708
	if (!node) {
		status = AE_BAD_PARAMETER;
		goto unlock_and_exit;
	}

	/* Get the device_object attached to the node */

L
Len Brown 已提交
709 710 711
	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 已提交
712 713 714 715
	}

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

L
Len Brown 已提交
716 717
	status = acpi_ev_delete_gpe_block(obj_desc->device.gpe_block);
	if (ACPI_SUCCESS(status)) {
L
Linus Torvalds 已提交
718 719 720
		obj_desc->device.gpe_block = NULL;
	}

L
Len Brown 已提交
721 722 723
      unlock_and_exit:
	(void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
	return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
724
}
R
Robert Moore 已提交
725

B
Bob Moore 已提交
726
ACPI_EXPORT_SYMBOL(acpi_remove_gpe_block)
727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813

/*******************************************************************************
 *
 * FUNCTION:    acpi_get_gpe_device
 *
 * PARAMETERS:  Index               - System GPE index (0-current_gpe_count)
 *              gpe_device          - Where the parent GPE Device is returned
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Obtain the GPE device associated with the input index. A NULL
 *              gpe device indicates that the gpe number is contained in one of
 *              the FADT-defined gpe blocks. Otherwise, the GPE block device.
 *
 ******************************************************************************/
acpi_status
acpi_get_gpe_device(u32 index, acpi_handle *gpe_device)
{
	struct acpi_gpe_device_info info;
	acpi_status status;

	ACPI_FUNCTION_TRACE(acpi_get_gpe_device);

	if (!gpe_device) {
		return_ACPI_STATUS(AE_BAD_PARAMETER);
	}

	if (index >= acpi_current_gpe_count) {
		return_ACPI_STATUS(AE_NOT_EXIST);
	}

	/* Setup and walk the GPE list */

	info.index = index;
	info.status = AE_NOT_EXIST;
	info.gpe_device = NULL;
	info.next_block_base_index = 0;

	status = acpi_ev_walk_gpe_list(acpi_ev_get_gpe_device, &info);
	if (ACPI_FAILURE(status)) {
		return_ACPI_STATUS(status);
	}

	*gpe_device = info.gpe_device;
	return_ACPI_STATUS(info.status);
}

ACPI_EXPORT_SYMBOL(acpi_get_gpe_device)

/*******************************************************************************
 *
 * FUNCTION:    acpi_ev_get_gpe_device
 *
 * PARAMETERS:  GPE_WALK_CALLBACK
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Matches the input GPE index (0-current_gpe_count) with a GPE
 *              block device. NULL if the GPE is one of the FADT-defined GPEs.
 *
 ******************************************************************************/
acpi_status
acpi_ev_get_gpe_device(struct acpi_gpe_xrupt_info *gpe_xrupt_info,
		       struct acpi_gpe_block_info *gpe_block, void *context)
{
	struct acpi_gpe_device_info *info = context;

	/* Increment Index by the number of GPEs in this block */

	info->next_block_base_index +=
	    (gpe_block->register_count * ACPI_GPE_REGISTER_WIDTH);

	if (info->index < info->next_block_base_index) {
		/*
		 * The GPE index is within this block, get the node. Leave the node
		 * NULL for the FADT-defined GPEs
		 */
		if ((gpe_block->node)->type == ACPI_TYPE_DEVICE) {
			info->gpe_device = gpe_block->node;
		}

		info->status = AE_OK;
		return (AE_CTRL_END);
	}

	return (AE_OK);
}
814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871

/******************************************************************************
 *
 * FUNCTION:    acpi_disable_all_gpes
 *
 * PARAMETERS:  None
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Disable and clear all GPEs in all GPE blocks
 *
 ******************************************************************************/

acpi_status acpi_disable_all_gpes(void)
{
	acpi_status status;

	ACPI_FUNCTION_TRACE(acpi_disable_all_gpes);

	status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
	if (ACPI_FAILURE(status)) {
		return_ACPI_STATUS(status);
	}

	status = acpi_hw_disable_all_gpes();
	(void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);

	return_ACPI_STATUS(status);
}

/******************************************************************************
 *
 * FUNCTION:    acpi_enable_all_runtime_gpes
 *
 * PARAMETERS:  None
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Enable all "runtime" GPEs, in all GPE blocks
 *
 ******************************************************************************/

acpi_status acpi_enable_all_runtime_gpes(void)
{
	acpi_status status;

	ACPI_FUNCTION_TRACE(acpi_enable_all_runtime_gpes);

	status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
	if (ACPI_FAILURE(status)) {
		return_ACPI_STATUS(status);
	}

	status = acpi_hw_enable_all_runtime_gpes();
	(void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);

	return_ACPI_STATUS(status);
}