evgpeblk.c 15.7 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5 6 7
/******************************************************************************
 *
 * Module Name: evgpeblk - GPE block creation and initialization.
 *
 *****************************************************************************/

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

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

R
Robert Moore 已提交
52 53
/* Local prototypes */
static acpi_status
L
Len Brown 已提交
54 55
acpi_ev_install_gpe_block(struct acpi_gpe_block_info *gpe_block,
			  u32 interrupt_number);
R
Robert Moore 已提交
56 57

static acpi_status
L
Len Brown 已提交
58
acpi_ev_create_gpe_info_blocks(struct acpi_gpe_block_info *gpe_block);
L
Linus Torvalds 已提交
59 60 61 62 63

/*******************************************************************************
 *
 * FUNCTION:    acpi_ev_install_gpe_block
 *
64 65 66
 * PARAMETERS:  gpe_block               - New GPE block
 *              interrupt_number        - Xrupt to be associated with this
 *                                        GPE block
L
Linus Torvalds 已提交
67 68 69 70 71 72 73 74
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Install new GPE block with mutex support
 *
 ******************************************************************************/

static acpi_status
L
Len Brown 已提交
75 76
acpi_ev_install_gpe_block(struct acpi_gpe_block_info *gpe_block,
			  u32 interrupt_number)
L
Linus Torvalds 已提交
77
{
L
Len Brown 已提交
78 79 80
	struct acpi_gpe_block_info *next_gpe_block;
	struct acpi_gpe_xrupt_info *gpe_xrupt_block;
	acpi_status status;
B
Bob Moore 已提交
81
	acpi_cpu_flags flags;
L
Linus Torvalds 已提交
82

B
Bob Moore 已提交
83
	ACPI_FUNCTION_TRACE(ev_install_gpe_block);
L
Linus Torvalds 已提交
84

L
Len Brown 已提交
85 86 87
	status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
	if (ACPI_FAILURE(status)) {
		return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
88 89
	}

L
Len Brown 已提交
90
	gpe_xrupt_block = acpi_ev_get_gpe_xrupt_block(interrupt_number);
L
Linus Torvalds 已提交
91 92 93 94 95
	if (!gpe_xrupt_block) {
		status = AE_NO_MEMORY;
		goto unlock_and_exit;
	}

R
Robert Moore 已提交
96
	/* Install the new block at the end of the list with lock */
L
Linus Torvalds 已提交
97

L
Len Brown 已提交
98
	flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
L
Linus Torvalds 已提交
99 100 101 102 103 104 105 106
	if (gpe_xrupt_block->gpe_block_list_head) {
		next_gpe_block = gpe_xrupt_block->gpe_block_list_head;
		while (next_gpe_block->next) {
			next_gpe_block = next_gpe_block->next;
		}

		next_gpe_block->next = gpe_block;
		gpe_block->previous = next_gpe_block;
L
Len Brown 已提交
107
	} else {
L
Linus Torvalds 已提交
108 109 110 111
		gpe_xrupt_block->gpe_block_list_head = gpe_block;
	}

	gpe_block->xrupt_block = gpe_xrupt_block;
L
Len Brown 已提交
112
	acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
L
Linus Torvalds 已提交
113

L
Len Brown 已提交
114 115 116
      unlock_and_exit:
	status = acpi_ut_release_mutex(ACPI_MTX_EVENTS);
	return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
117 118 119 120 121 122
}

/*******************************************************************************
 *
 * FUNCTION:    acpi_ev_delete_gpe_block
 *
123
 * PARAMETERS:  gpe_block           - Existing GPE block
L
Linus Torvalds 已提交
124 125 126 127 128 129 130
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Remove a GPE block
 *
 ******************************************************************************/

L
Len Brown 已提交
131
acpi_status acpi_ev_delete_gpe_block(struct acpi_gpe_block_info *gpe_block)
L
Linus Torvalds 已提交
132
{
L
Len Brown 已提交
133
	acpi_status status;
B
Bob Moore 已提交
134
	acpi_cpu_flags flags;
L
Linus Torvalds 已提交
135

B
Bob Moore 已提交
136
	ACPI_FUNCTION_TRACE(ev_install_gpe_block);
L
Linus Torvalds 已提交
137

L
Len Brown 已提交
138 139 140
	status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
	if (ACPI_FAILURE(status)) {
		return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
141 142 143 144
	}

	/* Disable all GPEs in this block */

145 146
	status =
	    acpi_hw_disable_gpe_block(gpe_block->xrupt_block, gpe_block, NULL);
L
Linus Torvalds 已提交
147 148

	if (!gpe_block->previous && !gpe_block->next) {
B
Bob Moore 已提交
149

L
Linus Torvalds 已提交
150 151
		/* This is the last gpe_block on this interrupt */

L
Len Brown 已提交
152 153
		status = acpi_ev_delete_gpe_xrupt(gpe_block->xrupt_block);
		if (ACPI_FAILURE(status)) {
L
Linus Torvalds 已提交
154 155
			goto unlock_and_exit;
		}
L
Len Brown 已提交
156
	} else {
L
Linus Torvalds 已提交
157 158
		/* Remove the block on this interrupt with lock */

L
Len Brown 已提交
159
		flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
L
Linus Torvalds 已提交
160 161
		if (gpe_block->previous) {
			gpe_block->previous->next = gpe_block->next;
L
Len Brown 已提交
162 163 164
		} else {
			gpe_block->xrupt_block->gpe_block_list_head =
			    gpe_block->next;
L
Linus Torvalds 已提交
165 166 167 168 169
		}

		if (gpe_block->next) {
			gpe_block->next->previous = gpe_block->previous;
		}
L
Len Brown 已提交
170
		acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
L
Linus Torvalds 已提交
171 172
	}

173
	acpi_current_gpe_count -= gpe_block->gpe_count;
174

L
Linus Torvalds 已提交
175 176
	/* Free the gpe_block */

B
Bob Moore 已提交
177 178 179
	ACPI_FREE(gpe_block->register_info);
	ACPI_FREE(gpe_block->event_info);
	ACPI_FREE(gpe_block);
L
Linus Torvalds 已提交
180

L
Len Brown 已提交
181 182 183
      unlock_and_exit:
	status = acpi_ut_release_mutex(ACPI_MTX_EVENTS);
	return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198
}

/*******************************************************************************
 *
 * FUNCTION:    acpi_ev_create_gpe_info_blocks
 *
 * PARAMETERS:  gpe_block   - New GPE block
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Create the register_info and event_info blocks for this GPE block
 *
 ******************************************************************************/

static acpi_status
L
Len Brown 已提交
199
acpi_ev_create_gpe_info_blocks(struct acpi_gpe_block_info *gpe_block)
L
Linus Torvalds 已提交
200
{
L
Len Brown 已提交
201 202 203 204
	struct acpi_gpe_register_info *gpe_register_info = NULL;
	struct acpi_gpe_event_info *gpe_event_info = NULL;
	struct acpi_gpe_event_info *this_event;
	struct acpi_gpe_register_info *this_register;
205 206
	u32 i;
	u32 j;
L
Len Brown 已提交
207
	acpi_status status;
L
Linus Torvalds 已提交
208

B
Bob Moore 已提交
209
	ACPI_FUNCTION_TRACE(ev_create_gpe_info_blocks);
L
Linus Torvalds 已提交
210 211 212

	/* Allocate the GPE register information block */

B
Bob Moore 已提交
213 214 215 216
	gpe_register_info = ACPI_ALLOCATE_ZEROED((acpi_size) gpe_block->
						 register_count *
						 sizeof(struct
							acpi_gpe_register_info));
L
Linus Torvalds 已提交
217
	if (!gpe_register_info) {
B
Bob Moore 已提交
218
		ACPI_ERROR((AE_INFO,
B
Bob Moore 已提交
219
			    "Could not allocate the GpeRegisterInfo table"));
L
Len Brown 已提交
220
		return_ACPI_STATUS(AE_NO_MEMORY);
L
Linus Torvalds 已提交
221 222 223 224
	}

	/*
	 * Allocate the GPE event_info block. There are eight distinct GPEs
B
Bob Moore 已提交
225
	 * per register. Initialization to zeros is sufficient.
L
Linus Torvalds 已提交
226
	 */
227
	gpe_event_info = ACPI_ALLOCATE_ZEROED((acpi_size) gpe_block->gpe_count *
B
Bob Moore 已提交
228 229
					      sizeof(struct
						     acpi_gpe_event_info));
L
Linus Torvalds 已提交
230
	if (!gpe_event_info) {
B
Bob Moore 已提交
231
		ACPI_ERROR((AE_INFO,
B
Bob Moore 已提交
232
			    "Could not allocate the GpeEventInfo table"));
L
Linus Torvalds 已提交
233 234 235 236 237 238 239
		status = AE_NO_MEMORY;
		goto error_exit;
	}

	/* Save the new Info arrays in the GPE block */

	gpe_block->register_info = gpe_register_info;
L
Len Brown 已提交
240
	gpe_block->event_info = gpe_event_info;
L
Linus Torvalds 已提交
241 242

	/*
B
Bob Moore 已提交
243
	 * Initialize the GPE Register and Event structures. A goal of these
244 245 246
	 * tables is to hide the fact that there are two separate GPE register
	 * sets in a given GPE hardware block, the status registers occupy the
	 * first half, and the enable registers occupy the second half.
L
Linus Torvalds 已提交
247 248
	 */
	this_register = gpe_register_info;
L
Len Brown 已提交
249
	this_event = gpe_event_info;
L
Linus Torvalds 已提交
250 251

	for (i = 0; i < gpe_block->register_count; i++) {
B
Bob Moore 已提交
252

L
Linus Torvalds 已提交
253 254
		/* Init the register_info for this GPE register (8 GPEs) */

L
Len Brown 已提交
255 256 257 258
		this_register->base_gpe_number =
		    (u8) (gpe_block->block_base_number +
			  (i * ACPI_GPE_REGISTER_WIDTH));

B
Bob Moore 已提交
259 260
		this_register->status_address.address =
		    gpe_block->block_address.address + i;
L
Len Brown 已提交
261

B
Bob Moore 已提交
262 263 264
		this_register->enable_address.address =
		    gpe_block->block_address.address + i +
		    gpe_block->register_count;
L
Len Brown 已提交
265

266 267 268 269 270
		this_register->status_address.space_id =
		    gpe_block->block_address.space_id;
		this_register->enable_address.space_id =
		    gpe_block->block_address.space_id;
		this_register->status_address.bit_width =
L
Len Brown 已提交
271
		    ACPI_GPE_REGISTER_WIDTH;
272
		this_register->enable_address.bit_width =
L
Len Brown 已提交
273
		    ACPI_GPE_REGISTER_WIDTH;
274 275
		this_register->status_address.bit_offset = 0;
		this_register->enable_address.bit_offset = 0;
L
Linus Torvalds 已提交
276 277 278 279

		/* Init the event_info for each GPE within this register */

		for (j = 0; j < ACPI_GPE_REGISTER_WIDTH; j++) {
280 281
			this_event->gpe_number =
			    (u8) (this_register->base_gpe_number + j);
L
Linus Torvalds 已提交
282 283 284 285
			this_event->register_info = this_register;
			this_event++;
		}

B
Bob Moore 已提交
286 287
		/* Disable all GPEs within this register */

288
		status = acpi_hw_write(0x00, &this_register->enable_address);
L
Len Brown 已提交
289
		if (ACPI_FAILURE(status)) {
L
Linus Torvalds 已提交
290 291 292
			goto error_exit;
		}

B
Bob Moore 已提交
293 294
		/* Clear any pending GPE events within this register */

295
		status = acpi_hw_write(0xFF, &this_register->status_address);
L
Len Brown 已提交
296
		if (ACPI_FAILURE(status)) {
L
Linus Torvalds 已提交
297 298 299 300 301 302
			goto error_exit;
		}

		this_register++;
	}

L
Len Brown 已提交
303
	return_ACPI_STATUS(AE_OK);
L
Linus Torvalds 已提交
304

L
Len Brown 已提交
305
      error_exit:
L
Linus Torvalds 已提交
306
	if (gpe_register_info) {
B
Bob Moore 已提交
307
		ACPI_FREE(gpe_register_info);
L
Linus Torvalds 已提交
308 309
	}
	if (gpe_event_info) {
B
Bob Moore 已提交
310
		ACPI_FREE(gpe_event_info);
L
Linus Torvalds 已提交
311 312
	}

L
Len Brown 已提交
313
	return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
314 315 316 317 318 319 320 321 322 323
}

/*******************************************************************************
 *
 * FUNCTION:    acpi_ev_create_gpe_block
 *
 * PARAMETERS:  gpe_device          - Handle to the parent GPE block
 *              gpe_block_address   - Address and space_iD
 *              register_count      - Number of GPE register pairs in the block
 *              gpe_block_base_number - Starting GPE number for the block
324
 *              interrupt_number    - H/W interrupt for the block
L
Linus Torvalds 已提交
325 326 327 328
 *              return_gpe_block    - Where the new block descriptor is returned
 *
 * RETURN:      Status
 *
B
Bob Moore 已提交
329 330 331
 * DESCRIPTION: Create and Install a block of GPE registers. All GPEs within
 *              the block are disabled at exit.
 *              Note: Assumes namespace is locked.
L
Linus Torvalds 已提交
332 333 334 335
 *
 ******************************************************************************/

acpi_status
L
Len Brown 已提交
336 337 338 339 340 341
acpi_ev_create_gpe_block(struct acpi_namespace_node *gpe_device,
			 struct acpi_generic_address *gpe_block_address,
			 u32 register_count,
			 u8 gpe_block_base_number,
			 u32 interrupt_number,
			 struct acpi_gpe_block_info **return_gpe_block)
L
Linus Torvalds 已提交
342
{
L
Len Brown 已提交
343
	acpi_status status;
B
Bob Moore 已提交
344
	struct acpi_gpe_block_info *gpe_block;
345
	struct acpi_gpe_walk_info walk_info;
L
Linus Torvalds 已提交
346

B
Bob Moore 已提交
347
	ACPI_FUNCTION_TRACE(ev_create_gpe_block);
L
Linus Torvalds 已提交
348 349

	if (!register_count) {
L
Len Brown 已提交
350
		return_ACPI_STATUS(AE_OK);
L
Linus Torvalds 已提交
351 352 353 354
	}

	/* Allocate a new GPE block */

B
Bob Moore 已提交
355
	gpe_block = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_gpe_block_info));
L
Linus Torvalds 已提交
356
	if (!gpe_block) {
L
Len Brown 已提交
357
		return_ACPI_STATUS(AE_NO_MEMORY);
L
Linus Torvalds 已提交
358 359 360 361
	}

	/* Initialize the new GPE block */

B
Bob Moore 已提交
362
	gpe_block->node = gpe_device;
363
	gpe_block->gpe_count = (u16)(register_count * ACPI_GPE_REGISTER_WIDTH);
L
Linus Torvalds 已提交
364 365 366
	gpe_block->register_count = register_count;
	gpe_block->block_base_number = gpe_block_base_number;

L
Len Brown 已提交
367 368
	ACPI_MEMCPY(&gpe_block->block_address, gpe_block_address,
		    sizeof(struct acpi_generic_address));
L
Linus Torvalds 已提交
369

B
Bob Moore 已提交
370 371 372 373
	/*
	 * Create the register_info and event_info sub-structures
	 * Note: disables and clears all GPEs in the block
	 */
L
Len Brown 已提交
374 375
	status = acpi_ev_create_gpe_info_blocks(gpe_block);
	if (ACPI_FAILURE(status)) {
B
Bob Moore 已提交
376
		ACPI_FREE(gpe_block);
L
Len Brown 已提交
377
		return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
378 379
	}

B
Bob Moore 已提交
380
	/* Install the new block in the global lists */
L
Linus Torvalds 已提交
381

L
Len Brown 已提交
382 383
	status = acpi_ev_install_gpe_block(gpe_block, interrupt_number);
	if (ACPI_FAILURE(status)) {
B
Bob Moore 已提交
384
		ACPI_FREE(gpe_block);
L
Len Brown 已提交
385
		return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
386 387
	}

388 389 390 391 392 393
	/* Find all GPE methods (_Lxx or_Exx) for this block */

	walk_info.gpe_block = gpe_block;
	walk_info.gpe_device = gpe_device;
	walk_info.enable_this_gpe = FALSE;
	walk_info.execute_by_owner_id = FALSE;
L
Linus Torvalds 已提交
394

L
Len Brown 已提交
395 396
	status = acpi_ns_walk_namespace(ACPI_TYPE_METHOD, gpe_device,
					ACPI_UINT32_MAX, ACPI_NS_WALK_NO_UNLOCK,
397
					acpi_ev_match_gpe_method, NULL,
398
					&walk_info, NULL);
L
Linus Torvalds 已提交
399

B
Bob Moore 已提交
400 401 402 403 404 405 406 407 408 409
	/* Return the new block */

	if (return_gpe_block) {
		(*return_gpe_block) = gpe_block;
	}

	ACPI_DEBUG_PRINT((ACPI_DB_INIT,
			  "GPE %02X to %02X [%4.4s] %u regs on int 0x%X\n",
			  (u32) gpe_block->block_base_number,
			  (u32) (gpe_block->block_base_number +
410
				(gpe_block->gpe_count - 1)),
B
Bob Moore 已提交
411 412 413
			  gpe_device->name.ascii, gpe_block->register_count,
			  interrupt_number));

414 415
	/* Update global count of currently available GPEs */

416
	acpi_current_gpe_count += gpe_block->gpe_count;
B
Bob Moore 已提交
417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439
	return_ACPI_STATUS(AE_OK);
}

/*******************************************************************************
 *
 * FUNCTION:    acpi_ev_initialize_gpe_block
 *
 * PARAMETERS:  gpe_device          - Handle to the parent GPE block
 *              gpe_block           - Gpe Block info
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Initialize and enable a GPE block. First find and run any
 *              _PRT methods associated with the block, then enable the
 *              appropriate GPEs.
 *              Note: Assumes namespace is locked.
 *
 ******************************************************************************/

acpi_status
acpi_ev_initialize_gpe_block(struct acpi_namespace_node *gpe_device,
			     struct acpi_gpe_block_info *gpe_block)
{
440
	acpi_status status;
B
Bob Moore 已提交
441
	struct acpi_gpe_event_info *gpe_event_info;
442
	struct acpi_gpe_walk_info walk_info;
B
Bob Moore 已提交
443 444
	u32 wake_gpe_count;
	u32 gpe_enabled_count;
445 446
	u32 gpe_index;
	u32 gpe_number;
447 448
	u32 i;
	u32 j;
B
Bob Moore 已提交
449

B
Bob Moore 已提交
450
	ACPI_FUNCTION_TRACE(ev_initialize_gpe_block);
B
Bob Moore 已提交
451 452 453 454 455 456 457

	/* Ignore a null GPE block (e.g., if no GPE block 1 exists) */

	if (!gpe_block) {
		return_ACPI_STATUS(AE_OK);
	}

L
Linus Torvalds 已提交
458
	/*
B
Bob Moore 已提交
459 460
	 * Runtime option: Should wake GPEs be enabled at runtime?  The default
	 * is no, they should only be enabled just as the machine goes to sleep.
L
Linus Torvalds 已提交
461 462 463
	 */
	if (acpi_gbl_leave_wake_gpes_disabled) {
		/*
B
Bob Moore 已提交
464 465 466 467
		 * Differentiate runtime vs wake GPEs, via the _PRW control methods.
		 * Each GPE that has one or more _PRWs that reference it is by
		 * definition a wake GPE and will not be enabled while the machine
		 * is running.
L
Linus Torvalds 已提交
468
		 */
469 470 471
		walk_info.gpe_block = gpe_block;
		walk_info.gpe_device = gpe_device;
		walk_info.execute_by_owner_id = FALSE;
L
Linus Torvalds 已提交
472

473 474
		status =
		    acpi_ns_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,
L
Len Brown 已提交
475
					   ACPI_UINT32_MAX, ACPI_NS_WALK_UNLOCK,
476
					   acpi_ev_match_prw_and_gpe, NULL,
477
					   &walk_info, NULL);
478 479 480 481
		if (ACPI_FAILURE(status)) {
			ACPI_EXCEPTION((AE_INFO, status,
					"While executing _PRW methods"));
		}
L
Linus Torvalds 已提交
482 483 484
	}

	/*
485
	 * Enable all GPEs that have a corresponding method and are not
486
	 * capable of generating wakeups. Any other GPEs within this block
487
	 * must be enabled via the acpi_enable_gpe interface.
L
Linus Torvalds 已提交
488 489 490
	 */
	wake_gpe_count = 0;
	gpe_enabled_count = 0;
491 492

	if (gpe_device == acpi_gbl_fadt_gpe_device) {
493
		gpe_device = NULL;
494
	}
L
Linus Torvalds 已提交
495 496

	for (i = 0; i < gpe_block->register_count; i++) {
497
		for (j = 0; j < ACPI_GPE_REGISTER_WIDTH; j++) {
B
Bob Moore 已提交
498

L
Linus Torvalds 已提交
499
			/* Get the info block for this particular GPE */
500 501

			gpe_index = (i * ACPI_GPE_REGISTER_WIDTH) + j;
502
			gpe_event_info = &gpe_block->event_info[gpe_index];
L
Linus Torvalds 已提交
503

504
			if (gpe_event_info->flags & ACPI_GPE_CAN_WAKE) {
L
Linus Torvalds 已提交
505
				wake_gpe_count++;
506
				if (acpi_gbl_leave_wake_gpes_disabled) {
507
					continue;
508
				}
L
Linus Torvalds 已提交
509
			}
510

511 512 513
			/* Ignore GPEs that have no corresponding _Lxx/_Exx method */

			if (!(gpe_event_info->flags & ACPI_GPE_DISPATCH_METHOD)) {
514
				continue;
515 516 517
			}

			/* Enable this GPE */
518 519 520

			gpe_number = gpe_index + gpe_block->block_base_number;
			status = acpi_enable_gpe(gpe_device, gpe_number,
521 522 523 524
						 ACPI_GPE_TYPE_RUNTIME);
			if (ACPI_FAILURE(status)) {
				ACPI_EXCEPTION((AE_INFO, status,
						"Could not enable GPE 0x%02X",
525
						gpe_number));
526 527 528 529
				continue;
			}

			gpe_enabled_count++;
L
Linus Torvalds 已提交
530 531 532
		}
	}

533 534 535 536 537
	if (gpe_enabled_count || wake_gpe_count) {
		ACPI_DEBUG_PRINT((ACPI_DB_INIT,
				  "Enabled %u Runtime GPEs, added %u Wake GPEs in this block\n",
				  gpe_enabled_count, wake_gpe_count));
	}
L
Linus Torvalds 已提交
538

539
	return_ACPI_STATUS(AE_OK);
L
Linus Torvalds 已提交
540
}