evgpe.c 21.0 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5 6 7
/******************************************************************************
 *
 * Module Name: evgpe - General Purpose Event handling and dispatch
 *
 *****************************************************************************/

/*
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("evgpe")
L
Linus Torvalds 已提交
50

R
Robert Moore 已提交
51
/* Local prototypes */
L
Len Brown 已提交
52
static void ACPI_SYSTEM_XFACE acpi_ev_asynch_execute_gpe_method(void *context);
L
Linus Torvalds 已提交
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67

/*******************************************************************************
 *
 * FUNCTION:    acpi_ev_set_gpe_type
 *
 * PARAMETERS:  gpe_event_info          - GPE to set
 *              Type                    - New type
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Sets the new type for the GPE (wake, run, or wake/run)
 *
 ******************************************************************************/

acpi_status
L
Len Brown 已提交
68
acpi_ev_set_gpe_type(struct acpi_gpe_event_info *gpe_event_info, u8 type)
L
Linus Torvalds 已提交
69
{
L
Len Brown 已提交
70
	acpi_status status;
L
Linus Torvalds 已提交
71

B
Bob Moore 已提交
72
	ACPI_FUNCTION_TRACE(ev_set_gpe_type);
L
Linus Torvalds 已提交
73 74 75 76 77 78 79 80 81 82

	/* Validate type and update register enable masks */

	switch (type) {
	case ACPI_GPE_TYPE_WAKE:
	case ACPI_GPE_TYPE_RUNTIME:
	case ACPI_GPE_TYPE_WAKE_RUN:
		break;

	default:
L
Len Brown 已提交
83
		return_ACPI_STATUS(AE_BAD_PARAMETER);
L
Linus Torvalds 已提交
84 85 86 87
	}

	/* Disable the GPE if currently enabled */

L
Len Brown 已提交
88
	status = acpi_ev_disable_gpe(gpe_event_info);
L
Linus Torvalds 已提交
89 90 91

	/* Type was validated above */

L
Len Brown 已提交
92 93 94
	gpe_event_info->flags &= ~ACPI_GPE_TYPE_MASK;	/* Clear type bits */
	gpe_event_info->flags |= type;	/* Insert type */
	return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
}

/*******************************************************************************
 *
 * FUNCTION:    acpi_ev_update_gpe_enable_masks
 *
 * PARAMETERS:  gpe_event_info          - GPE to update
 *              Type                    - What to do: ACPI_GPE_DISABLE or
 *                                        ACPI_GPE_ENABLE
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Updates GPE register enable masks based on the GPE type
 *
 ******************************************************************************/

acpi_status
L
Len Brown 已提交
112 113
acpi_ev_update_gpe_enable_masks(struct acpi_gpe_event_info *gpe_event_info,
				u8 type)
L
Linus Torvalds 已提交
114
{
L
Len Brown 已提交
115 116
	struct acpi_gpe_register_info *gpe_register_info;
	u8 register_bit;
L
Linus Torvalds 已提交
117

B
Bob Moore 已提交
118
	ACPI_FUNCTION_TRACE(ev_update_gpe_enable_masks);
L
Linus Torvalds 已提交
119 120 121

	gpe_register_info = gpe_event_info->register_info;
	if (!gpe_register_info) {
L
Len Brown 已提交
122
		return_ACPI_STATUS(AE_NOT_EXIST);
L
Linus Torvalds 已提交
123 124 125 126 127 128
	}
	register_bit = gpe_event_info->register_bit;

	/* 1) Disable case.  Simply clear all enable bits */

	if (type == ACPI_GPE_DISABLE) {
L
Len Brown 已提交
129 130 131 132
		ACPI_CLEAR_BIT(gpe_register_info->enable_for_wake,
			       register_bit);
		ACPI_CLEAR_BIT(gpe_register_info->enable_for_run, register_bit);
		return_ACPI_STATUS(AE_OK);
L
Linus Torvalds 已提交
133 134 135 136 137 138
	}

	/* 2) Enable case.  Set/Clear the appropriate enable bits */

	switch (gpe_event_info->flags & ACPI_GPE_TYPE_MASK) {
	case ACPI_GPE_TYPE_WAKE:
L
Len Brown 已提交
139 140
		ACPI_SET_BIT(gpe_register_info->enable_for_wake, register_bit);
		ACPI_CLEAR_BIT(gpe_register_info->enable_for_run, register_bit);
L
Linus Torvalds 已提交
141 142 143
		break;

	case ACPI_GPE_TYPE_RUNTIME:
L
Len Brown 已提交
144 145 146
		ACPI_CLEAR_BIT(gpe_register_info->enable_for_wake,
			       register_bit);
		ACPI_SET_BIT(gpe_register_info->enable_for_run, register_bit);
L
Linus Torvalds 已提交
147 148 149
		break;

	case ACPI_GPE_TYPE_WAKE_RUN:
L
Len Brown 已提交
150 151
		ACPI_SET_BIT(gpe_register_info->enable_for_wake, register_bit);
		ACPI_SET_BIT(gpe_register_info->enable_for_run, register_bit);
L
Linus Torvalds 已提交
152 153 154
		break;

	default:
L
Len Brown 已提交
155
		return_ACPI_STATUS(AE_BAD_PARAMETER);
L
Linus Torvalds 已提交
156 157
	}

L
Len Brown 已提交
158
	return_ACPI_STATUS(AE_OK);
L
Linus Torvalds 已提交
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
}

/*******************************************************************************
 *
 * FUNCTION:    acpi_ev_enable_gpe
 *
 * PARAMETERS:  gpe_event_info          - GPE to enable
 *              write_to_hardware       - Enable now, or just mark data structs
 *                                        (WAKE GPEs should be deferred)
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Enable a GPE based on the GPE type
 *
 ******************************************************************************/

acpi_status
L
Len Brown 已提交
176 177
acpi_ev_enable_gpe(struct acpi_gpe_event_info *gpe_event_info,
		   u8 write_to_hardware)
L
Linus Torvalds 已提交
178
{
L
Len Brown 已提交
179
	acpi_status status;
L
Linus Torvalds 已提交
180

B
Bob Moore 已提交
181
	ACPI_FUNCTION_TRACE(ev_enable_gpe);
L
Linus Torvalds 已提交
182 183 184

	/* Make sure HW enable masks are updated */

L
Len Brown 已提交
185 186 187 188
	status =
	    acpi_ev_update_gpe_enable_masks(gpe_event_info, ACPI_GPE_ENABLE);
	if (ACPI_FAILURE(status)) {
		return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
189 190 191 192 193 194 195
	}

	/* Mark wake-enabled or HW enable, or both */

	switch (gpe_event_info->flags & ACPI_GPE_TYPE_MASK) {
	case ACPI_GPE_TYPE_WAKE:

L
Len Brown 已提交
196
		ACPI_SET_BIT(gpe_event_info->flags, ACPI_GPE_WAKE_ENABLED);
L
Linus Torvalds 已提交
197 198 199 200
		break;

	case ACPI_GPE_TYPE_WAKE_RUN:

L
Len Brown 已提交
201
		ACPI_SET_BIT(gpe_event_info->flags, ACPI_GPE_WAKE_ENABLED);
L
Linus Torvalds 已提交
202 203 204 205 206

		/*lint -fallthrough */

	case ACPI_GPE_TYPE_RUNTIME:

L
Len Brown 已提交
207
		ACPI_SET_BIT(gpe_event_info->flags, ACPI_GPE_RUN_ENABLED);
L
Linus Torvalds 已提交
208 209

		if (write_to_hardware) {
B
Bob Moore 已提交
210

L
Linus Torvalds 已提交
211 212
			/* Clear the GPE (of stale events), then enable it */

L
Len Brown 已提交
213 214 215
			status = acpi_hw_clear_gpe(gpe_event_info);
			if (ACPI_FAILURE(status)) {
				return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
216 217 218 219
			}

			/* Enable the requested runtime GPE */

L
Len Brown 已提交
220
			status = acpi_hw_write_gpe_enable_reg(gpe_event_info);
L
Linus Torvalds 已提交
221 222 223 224
		}
		break;

	default:
L
Len Brown 已提交
225
		return_ACPI_STATUS(AE_BAD_PARAMETER);
L
Linus Torvalds 已提交
226 227
	}

L
Len Brown 已提交
228
	return_ACPI_STATUS(AE_OK);
L
Linus Torvalds 已提交
229 230 231 232 233 234 235 236 237 238 239 240 241 242
}

/*******************************************************************************
 *
 * FUNCTION:    acpi_ev_disable_gpe
 *
 * PARAMETERS:  gpe_event_info          - GPE to disable
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Disable a GPE based on the GPE type
 *
 ******************************************************************************/

L
Len Brown 已提交
243
acpi_status acpi_ev_disable_gpe(struct acpi_gpe_event_info *gpe_event_info)
L
Linus Torvalds 已提交
244
{
L
Len Brown 已提交
245
	acpi_status status;
L
Linus Torvalds 已提交
246

B
Bob Moore 已提交
247
	ACPI_FUNCTION_TRACE(ev_disable_gpe);
L
Linus Torvalds 已提交
248 249

	if (!(gpe_event_info->flags & ACPI_GPE_ENABLE_MASK)) {
L
Len Brown 已提交
250
		return_ACPI_STATUS(AE_OK);
L
Linus Torvalds 已提交
251 252 253 254
	}

	/* Make sure HW enable masks are updated */

L
Len Brown 已提交
255 256 257 258
	status =
	    acpi_ev_update_gpe_enable_masks(gpe_event_info, ACPI_GPE_DISABLE);
	if (ACPI_FAILURE(status)) {
		return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
259 260 261 262 263 264
	}

	/* Mark wake-disabled or HW disable, or both */

	switch (gpe_event_info->flags & ACPI_GPE_TYPE_MASK) {
	case ACPI_GPE_TYPE_WAKE:
L
Len Brown 已提交
265
		ACPI_CLEAR_BIT(gpe_event_info->flags, ACPI_GPE_WAKE_ENABLED);
L
Linus Torvalds 已提交
266 267 268
		break;

	case ACPI_GPE_TYPE_WAKE_RUN:
L
Len Brown 已提交
269
		ACPI_CLEAR_BIT(gpe_event_info->flags, ACPI_GPE_WAKE_ENABLED);
L
Linus Torvalds 已提交
270 271 272 273 274 275 276

		/*lint -fallthrough */

	case ACPI_GPE_TYPE_RUNTIME:

		/* Disable the requested runtime GPE */

L
Len Brown 已提交
277 278
		ACPI_CLEAR_BIT(gpe_event_info->flags, ACPI_GPE_RUN_ENABLED);
		status = acpi_hw_write_gpe_enable_reg(gpe_event_info);
L
Linus Torvalds 已提交
279 280 281
		break;

	default:
L
Len Brown 已提交
282
		return_ACPI_STATUS(AE_BAD_PARAMETER);
L
Linus Torvalds 已提交
283 284
	}

L
Len Brown 已提交
285
	return_ACPI_STATUS(AE_OK);
L
Linus Torvalds 已提交
286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304
}

/*******************************************************************************
 *
 * FUNCTION:    acpi_ev_get_gpe_event_info
 *
 * PARAMETERS:  gpe_device          - Device node.  NULL for GPE0/GPE1
 *              gpe_number          - Raw GPE number
 *
 * RETURN:      A GPE event_info struct. NULL if not a valid GPE
 *
 * DESCRIPTION: Returns the event_info struct associated with this GPE.
 *              Validates the gpe_block and the gpe_number
 *
 *              Should be called only when the GPE lists are semaphore locked
 *              and not subject to change.
 *
 ******************************************************************************/

L
Len Brown 已提交
305 306
struct acpi_gpe_event_info *acpi_ev_get_gpe_event_info(acpi_handle gpe_device,
						       u32 gpe_number)
L
Linus Torvalds 已提交
307
{
L
Len Brown 已提交
308 309 310
	union acpi_operand_object *obj_desc;
	struct acpi_gpe_block_info *gpe_block;
	acpi_native_uint i;
L
Linus Torvalds 已提交
311

L
Len Brown 已提交
312
	ACPI_FUNCTION_ENTRY();
L
Linus Torvalds 已提交
313 314 315 316

	/* A NULL gpe_block means use the FADT-defined GPE block(s) */

	if (!gpe_device) {
B
Bob Moore 已提交
317

L
Linus Torvalds 已提交
318 319 320 321 322
		/* Examine GPE Block 0 and 1 (These blocks are permanent) */

		for (i = 0; i < ACPI_MAX_GPE_BLOCKS; i++) {
			gpe_block = acpi_gbl_gpe_fadt_blocks[i];
			if (gpe_block) {
L
Len Brown 已提交
323 324 325 326 327 328 329 330
				if ((gpe_number >= gpe_block->block_base_number)
				    && (gpe_number <
					gpe_block->block_base_number +
					(gpe_block->register_count * 8))) {
					return (&gpe_block->
						event_info[gpe_number -
							   gpe_block->
							   block_base_number]);
L
Linus Torvalds 已提交
331 332 333 334 335 336 337 338 339 340 341
				}
			}
		}

		/* The gpe_number was not in the range of either FADT GPE block */

		return (NULL);
	}

	/* A Non-NULL gpe_device means this is a GPE Block Device */

L
Len Brown 已提交
342 343 344 345
	obj_desc =
	    acpi_ns_get_attached_object((struct acpi_namespace_node *)
					gpe_device);
	if (!obj_desc || !obj_desc->device.gpe_block) {
L
Linus Torvalds 已提交
346 347 348 349 350 351
		return (NULL);
	}

	gpe_block = obj_desc->device.gpe_block;

	if ((gpe_number >= gpe_block->block_base_number) &&
L
Len Brown 已提交
352 353 354 355
	    (gpe_number <
	     gpe_block->block_base_number + (gpe_block->register_count * 8))) {
		return (&gpe_block->
			event_info[gpe_number - gpe_block->block_base_number]);
L
Linus Torvalds 已提交
356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374
	}

	return (NULL);
}

/*******************************************************************************
 *
 * FUNCTION:    acpi_ev_gpe_detect
 *
 * PARAMETERS:  gpe_xrupt_list      - Interrupt block for this interrupt.
 *                                    Can have multiple GPE blocks attached.
 *
 * RETURN:      INTERRUPT_HANDLED or INTERRUPT_NOT_HANDLED
 *
 * DESCRIPTION: Detect if any GP events have occurred.  This function is
 *              executed at interrupt level.
 *
 ******************************************************************************/

L
Len Brown 已提交
375
u32 acpi_ev_gpe_detect(struct acpi_gpe_xrupt_info * gpe_xrupt_list)
L
Linus Torvalds 已提交
376
{
B
Bob Moore 已提交
377 378 379
	acpi_status status;
	struct acpi_gpe_block_info *gpe_block;
	struct acpi_gpe_register_info *gpe_register_info;
L
Len Brown 已提交
380 381 382 383
	u32 int_status = ACPI_INTERRUPT_NOT_HANDLED;
	u8 enabled_status_byte;
	u32 status_reg;
	u32 enable_reg;
B
Bob Moore 已提交
384
	acpi_cpu_flags flags;
L
Len Brown 已提交
385 386 387
	acpi_native_uint i;
	acpi_native_uint j;

B
Bob Moore 已提交
388
	ACPI_FUNCTION_NAME(ev_gpe_detect);
L
Linus Torvalds 已提交
389 390 391 392 393 394 395 396 397

	/* Check for the case where there are no GPEs */

	if (!gpe_xrupt_list) {
		return (int_status);
	}

	/* Examine all GPE blocks attached to this interrupt level */

L
Len Brown 已提交
398
	flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
L
Linus Torvalds 已提交
399 400 401 402 403 404 405 406
	gpe_block = gpe_xrupt_list->gpe_block_list_head;
	while (gpe_block) {
		/*
		 * Read all of the 8-bit GPE status and enable registers
		 * in this GPE block, saving all of them.
		 * Find all currently active GP events.
		 */
		for (i = 0; i < gpe_block->register_count; i++) {
B
Bob Moore 已提交
407

L
Linus Torvalds 已提交
408 409 410 411 412 413
			/* Get the next status/enable pair */

			gpe_register_info = &gpe_block->register_info[i];

			/* Read the Status Register */

L
Len Brown 已提交
414 415 416 417 418 419
			status =
			    acpi_hw_low_level_read(ACPI_GPE_REGISTER_WIDTH,
						   &status_reg,
						   &gpe_register_info->
						   status_address);
			if (ACPI_FAILURE(status)) {
L
Linus Torvalds 已提交
420 421 422 423 424
				goto unlock_and_exit;
			}

			/* Read the Enable Register */

L
Len Brown 已提交
425 426 427 428 429 430
			status =
			    acpi_hw_low_level_read(ACPI_GPE_REGISTER_WIDTH,
						   &enable_reg,
						   &gpe_register_info->
						   enable_address);
			if (ACPI_FAILURE(status)) {
L
Linus Torvalds 已提交
431 432 433
				goto unlock_and_exit;
			}

L
Len Brown 已提交
434 435 436 437
			ACPI_DEBUG_PRINT((ACPI_DB_INTERRUPTS,
					  "Read GPE Register at GPE%X: Status=%02X, Enable=%02X\n",
					  gpe_register_info->base_gpe_number,
					  status_reg, enable_reg));
L
Linus Torvalds 已提交
438

R
Robert Moore 已提交
439
			/* Check if there is anything active at all in this register */
L
Linus Torvalds 已提交
440 441 442

			enabled_status_byte = (u8) (status_reg & enable_reg);
			if (!enabled_status_byte) {
B
Bob Moore 已提交
443

L
Linus Torvalds 已提交
444 445 446 447 448 449 450 451
				/* No active GPEs in this register, move on */

				continue;
			}

			/* Now look at the individual GPEs in this byte register */

			for (j = 0; j < ACPI_GPE_REGISTER_WIDTH; j++) {
B
Bob Moore 已提交
452

L
Linus Torvalds 已提交
453 454
				/* Examine one GPE bit */

L
Len Brown 已提交
455 456
				if (enabled_status_byte &
				    acpi_gbl_decode_to8bit[j]) {
L
Linus Torvalds 已提交
457 458 459 460
					/*
					 * Found an active GPE. Dispatch the event to a handler
					 * or method.
					 */
L
Len Brown 已提交
461 462 463 464 465 466 467 468 469
					int_status |=
					    acpi_ev_gpe_dispatch(&gpe_block->
								 event_info[(i *
									     ACPI_GPE_REGISTER_WIDTH)
									    +
									    j],
								 (u32) j +
								 gpe_register_info->
								 base_gpe_number);
L
Linus Torvalds 已提交
470 471 472 473 474 475 476
				}
			}
		}

		gpe_block = gpe_block->next;
	}

L
Len Brown 已提交
477
      unlock_and_exit:
L
Linus Torvalds 已提交
478

L
Len Brown 已提交
479
	acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
L
Linus Torvalds 已提交
480 481 482 483 484 485 486 487 488 489 490 491
	return (int_status);
}

/*******************************************************************************
 *
 * FUNCTION:    acpi_ev_asynch_execute_gpe_method
 *
 * PARAMETERS:  Context (gpe_event_info) - Info for this GPE
 *
 * RETURN:      None
 *
 * DESCRIPTION: Perform the actual execution of a GPE control method.  This
B
Bob Moore 已提交
492
 *              function is called from an invocation of acpi_os_exece
L
Linus Torvalds 已提交
493 494 495 496 497 498
 *              (and therefore does NOT execute at interrupt level) so that
 *              the control method itself is not executed in the context of
 *              an interrupt handler.
 *
 ******************************************************************************/

L
Len Brown 已提交
499
static void ACPI_SYSTEM_XFACE acpi_ev_asynch_execute_gpe_method(void *context)
L
Linus Torvalds 已提交
500
{
L
Len Brown 已提交
501 502 503 504 505
	struct acpi_gpe_event_info *gpe_event_info = (void *)context;
	u32 gpe_number = 0;
	acpi_status status;
	struct acpi_gpe_event_info local_gpe_event_info;
	struct acpi_parameter_info info;
L
Linus Torvalds 已提交
506

B
Bob Moore 已提交
507
	ACPI_FUNCTION_TRACE(ev_asynch_execute_gpe_method);
L
Linus Torvalds 已提交
508

L
Len Brown 已提交
509 510
	status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
	if (ACPI_FAILURE(status)) {
L
Linus Torvalds 已提交
511 512 513 514 515
		return_VOID;
	}

	/* Must revalidate the gpe_number/gpe_block */

L
Len Brown 已提交
516 517
	if (!acpi_ev_valid_gpe_event(gpe_event_info)) {
		status = acpi_ut_release_mutex(ACPI_MTX_EVENTS);
L
Linus Torvalds 已提交
518 519 520 521 522
		return_VOID;
	}

	/* Set the GPE flags for return to enabled state */

L
Len Brown 已提交
523
	(void)acpi_ev_enable_gpe(gpe_event_info, FALSE);
L
Linus Torvalds 已提交
524 525 526 527 528

	/*
	 * Take a snapshot of the GPE info for this level - we copy the
	 * info to prevent a race condition with remove_handler/remove_block.
	 */
L
Len Brown 已提交
529 530
	ACPI_MEMCPY(&local_gpe_event_info, gpe_event_info,
		    sizeof(struct acpi_gpe_event_info));
L
Linus Torvalds 已提交
531

L
Len Brown 已提交
532 533
	status = acpi_ut_release_mutex(ACPI_MTX_EVENTS);
	if (ACPI_FAILURE(status)) {
L
Linus Torvalds 已提交
534 535 536 537 538 539 540
		return_VOID;
	}

	/*
	 * Must check for control method type dispatch one more
	 * time to avoid race with ev_gpe_install_handler
	 */
R
Robert Moore 已提交
541
	if ((local_gpe_event_info.flags & ACPI_GPE_DISPATCH_MASK) ==
L
Len Brown 已提交
542
	    ACPI_GPE_DISPATCH_METHOD) {
L
Linus Torvalds 已提交
543 544 545 546 547
		/*
		 * Invoke the GPE Method (_Lxx, _Exx) i.e., evaluate the _Lxx/_Exx
		 * control method that corresponds to this GPE
		 */
		info.node = local_gpe_event_info.dispatch.method_node;
L
Len Brown 已提交
548 549
		info.parameters =
		    ACPI_CAST_PTR(union acpi_operand_object *, gpe_event_info);
L
Linus Torvalds 已提交
550 551
		info.parameter_type = ACPI_PARAM_GPE;

L
Len Brown 已提交
552 553
		status = acpi_ns_evaluate_by_handle(&info);
		if (ACPI_FAILURE(status)) {
B
Bob Moore 已提交
554 555 556 557 558
			ACPI_EXCEPTION((AE_INFO, status,
					"While evaluating method [%4.4s] for GPE[%2X]",
					acpi_ut_get_node_name
					(local_gpe_event_info.dispatch.
					 method_node), gpe_number));
L
Linus Torvalds 已提交
559 560 561
		}
	}

R
Robert Moore 已提交
562
	if ((local_gpe_event_info.flags & ACPI_GPE_XRUPT_TYPE_MASK) ==
L
Len Brown 已提交
563
	    ACPI_GPE_LEVEL_TRIGGERED) {
L
Linus Torvalds 已提交
564 565 566 567
		/*
		 * GPE is level-triggered, we clear the GPE status bit after
		 * handling the event.
		 */
L
Len Brown 已提交
568 569
		status = acpi_hw_clear_gpe(&local_gpe_event_info);
		if (ACPI_FAILURE(status)) {
L
Linus Torvalds 已提交
570 571 572 573 574 575
			return_VOID;
		}
	}

	/* Enable this GPE */

L
Len Brown 已提交
576
	(void)acpi_hw_write_gpe_enable_reg(&local_gpe_event_info);
L
Linus Torvalds 已提交
577 578 579 580 581 582 583
	return_VOID;
}

/*******************************************************************************
 *
 * FUNCTION:    acpi_ev_gpe_dispatch
 *
R
Robert Moore 已提交
584
 * PARAMETERS:  gpe_event_info  - Info for this GPE
L
Linus Torvalds 已提交
585 586 587 588 589 590 591 592 593 594 595 596
 *              gpe_number      - Number relative to the parent GPE block
 *
 * RETURN:      INTERRUPT_HANDLED or INTERRUPT_NOT_HANDLED
 *
 * DESCRIPTION: Dispatch a General Purpose Event to either a function (e.g. EC)
 *              or method (e.g. _Lxx/_Exx) handler.
 *
 *              This function executes at interrupt level.
 *
 ******************************************************************************/

u32
L
Len Brown 已提交
597
acpi_ev_gpe_dispatch(struct acpi_gpe_event_info *gpe_event_info, u32 gpe_number)
L
Linus Torvalds 已提交
598
{
L
Len Brown 已提交
599
	acpi_status status;
L
Linus Torvalds 已提交
600

B
Bob Moore 已提交
601
	ACPI_FUNCTION_TRACE(ev_gpe_dispatch);
L
Linus Torvalds 已提交
602 603 604 605 606

	/*
	 * If edge-triggered, clear the GPE status bit now.  Note that
	 * level-triggered events are cleared after the GPE is serviced.
	 */
R
Robert Moore 已提交
607
	if ((gpe_event_info->flags & ACPI_GPE_XRUPT_TYPE_MASK) ==
L
Len Brown 已提交
608 609 610
	    ACPI_GPE_EDGE_TRIGGERED) {
		status = acpi_hw_clear_gpe(gpe_event_info);
		if (ACPI_FAILURE(status)) {
B
Bob Moore 已提交
611 612 613
			ACPI_EXCEPTION((AE_INFO, status,
					"Unable to clear GPE[%2X]",
					gpe_number));
B
Bob Moore 已提交
614
			return_UINT32(ACPI_INTERRUPT_NOT_HANDLED);
L
Linus Torvalds 已提交
615 616 617 618 619 620
		}
	}

	/* Save current system state */

	if (acpi_gbl_system_awake_and_running) {
L
Len Brown 已提交
621 622 623
		ACPI_SET_BIT(gpe_event_info->flags, ACPI_GPE_SYSTEM_RUNNING);
	} else {
		ACPI_CLEAR_BIT(gpe_event_info->flags, ACPI_GPE_SYSTEM_RUNNING);
L
Linus Torvalds 已提交
624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639
	}

	/*
	 * Dispatch the GPE to either an installed handler, or the control
	 * method associated with this GPE (_Lxx or _Exx).
	 * If a handler exists, we invoke it and do not attempt to run the method.
	 * If there is neither a handler nor a method, we disable the level to
	 * prevent further events from coming in here.
	 */
	switch (gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) {
	case ACPI_GPE_DISPATCH_HANDLER:

		/*
		 * Invoke the installed handler (at interrupt level)
		 * Ignore return status for now.  TBD: leave GPE disabled on error?
		 */
L
Len Brown 已提交
640 641 642 643
		(void)gpe_event_info->dispatch.handler->address(gpe_event_info->
								dispatch.
								handler->
								context);
L
Linus Torvalds 已提交
644 645 646

		/* It is now safe to clear level-triggered events. */

R
Robert Moore 已提交
647
		if ((gpe_event_info->flags & ACPI_GPE_XRUPT_TYPE_MASK) ==
L
Len Brown 已提交
648 649 650
		    ACPI_GPE_LEVEL_TRIGGERED) {
			status = acpi_hw_clear_gpe(gpe_event_info);
			if (ACPI_FAILURE(status)) {
B
Bob Moore 已提交
651 652 653
				ACPI_EXCEPTION((AE_INFO, status,
						"Unable to clear GPE[%2X]",
						gpe_number));
B
Bob Moore 已提交
654
				return_UINT32(ACPI_INTERRUPT_NOT_HANDLED);
L
Linus Torvalds 已提交
655 656 657 658 659 660 661 662 663 664
			}
		}
		break;

	case ACPI_GPE_DISPATCH_METHOD:

		/*
		 * Disable GPE, so it doesn't keep firing before the method has a
		 * chance to run.
		 */
L
Len Brown 已提交
665 666
		status = acpi_ev_disable_gpe(gpe_event_info);
		if (ACPI_FAILURE(status)) {
B
Bob Moore 已提交
667 668 669
			ACPI_EXCEPTION((AE_INFO, status,
					"Unable to disable GPE[%2X]",
					gpe_number));
B
Bob Moore 已提交
670
			return_UINT32(ACPI_INTERRUPT_NOT_HANDLED);
L
Linus Torvalds 已提交
671 672 673 674 675 676
		}

		/*
		 * Execute the method associated with the GPE
		 * NOTE: Level-triggered GPEs are cleared after the method completes.
		 */
B
Bob Moore 已提交
677 678 679
		status = acpi_os_execute(OSL_GPE_HANDLER,
					 acpi_ev_asynch_execute_gpe_method,
					 gpe_event_info);
L
Len Brown 已提交
680
		if (ACPI_FAILURE(status)) {
B
Bob Moore 已提交
681 682 683
			ACPI_EXCEPTION((AE_INFO, status,
					"Unable to queue handler for GPE[%2X] - event disabled",
					gpe_number));
L
Linus Torvalds 已提交
684 685 686 687 688 689 690
		}
		break;

	default:

		/* No handler or method to run! */

B
Bob Moore 已提交
691 692 693
		ACPI_ERROR((AE_INFO,
			    "No handler or method for GPE[%2X], disabling event",
			    gpe_number));
L
Linus Torvalds 已提交
694 695 696 697 698

		/*
		 * Disable the GPE.  The GPE will remain disabled until the ACPI
		 * Core Subsystem is restarted, or a handler is installed.
		 */
L
Len Brown 已提交
699 700
		status = acpi_ev_disable_gpe(gpe_event_info);
		if (ACPI_FAILURE(status)) {
B
Bob Moore 已提交
701 702 703
			ACPI_EXCEPTION((AE_INFO, status,
					"Unable to disable GPE[%2X]",
					gpe_number));
B
Bob Moore 已提交
704
			return_UINT32(ACPI_INTERRUPT_NOT_HANDLED);
L
Linus Torvalds 已提交
705 706 707 708
		}
		break;
	}

B
Bob Moore 已提交
709
	return_UINT32(ACPI_INTERRUPT_HANDLED);
L
Linus Torvalds 已提交
710 711 712 713 714 715 716 717 718 719 720 721 722 723
}

#ifdef ACPI_GPE_NOTIFY_CHECK
/*******************************************************************************
 * TBD: NOT USED, PROTOTYPE ONLY AND WILL PROBABLY BE REMOVED
 *
 * FUNCTION:    acpi_ev_check_for_wake_only_gpe
 *
 * PARAMETERS:  gpe_event_info  - info for this GPE
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Determine if a a GPE is "wake-only".
 *
B
Bob Moore 已提交
724
 *              Called from Notify() code in interpreter when a "DeviceWake"
L
Linus Torvalds 已提交
725 726 727 728 729
 *              Notify comes in.
 *
 ******************************************************************************/

acpi_status
L
Len Brown 已提交
730
acpi_ev_check_for_wake_only_gpe(struct acpi_gpe_event_info *gpe_event_info)
L
Linus Torvalds 已提交
731
{
L
Len Brown 已提交
732
	acpi_status status;
L
Linus Torvalds 已提交
733

B
Bob Moore 已提交
734
	ACPI_FUNCTION_TRACE(ev_check_for_wake_only_gpe);
L
Linus Torvalds 已提交
735

L
Len Brown 已提交
736 737
	if ((gpe_event_info) &&	/* Only >0 for _Lxx/_Exx */
	    ((gpe_event_info->flags & ACPI_GPE_SYSTEM_MASK) == ACPI_GPE_SYSTEM_RUNNING)) {	/* System state at GPE time */
L
Linus Torvalds 已提交
738 739
		/* This must be a wake-only GPE, disable it */

L
Len Brown 已提交
740
		status = acpi_ev_disable_gpe(gpe_event_info);
L
Linus Torvalds 已提交
741 742 743

		/* Set GPE to wake-only.  Do not change wake disabled/enabled status */

L
Len Brown 已提交
744
		acpi_ev_set_gpe_type(gpe_event_info, ACPI_GPE_TYPE_WAKE);
L
Linus Torvalds 已提交
745

B
Bob Moore 已提交
746 747 748
		ACPI_INFO((AE_INFO,
			   "GPE %p was updated from wake/run to wake-only",
			   gpe_event_info));
L
Linus Torvalds 已提交
749 750 751

		/* This was a wake-only GPE */

L
Len Brown 已提交
752
		return_ACPI_STATUS(AE_WAKE_ONLY_GPE);
L
Linus Torvalds 已提交
753 754
	}

L
Len Brown 已提交
755
	return_ACPI_STATUS(AE_OK);
L
Linus Torvalds 已提交
756 757
}
#endif