ACPICA: Clarify/rename some root table descriptor fields
[deliverable/linux.git] / drivers / acpi / acpica / evgpeblk.c
CommitLineData
1da177e4
LT
1/******************************************************************************
2 *
3 * Module Name: evgpeblk - GPE block creation and initialization.
4 *
5 *****************************************************************************/
6
7/*
a8357b0c 8 * Copyright (C) 2000 - 2010, Intel Corp.
1da177e4
LT
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
29 *
30 * NO WARRANTY
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
42 */
43
44#include <acpi/acpi.h>
e2f7a777
LB
45#include "accommon.h"
46#include "acevents.h"
47#include "acnamesp.h"
1da177e4
LT
48
49#define _COMPONENT ACPI_EVENTS
4be44fcd 50ACPI_MODULE_NAME("evgpeblk")
1da177e4 51
44f6c012 52/* Local prototypes */
44f6c012 53static acpi_status
0f849d2c 54acpi_ev_match_gpe_method(acpi_handle obj_handle,
4be44fcd 55 u32 level, void *obj_desc, void **return_value);
44f6c012
RM
56
57static acpi_status
4be44fcd
LB
58acpi_ev_match_prw_and_gpe(acpi_handle obj_handle,
59 u32 level, void *info, void **return_value);
44f6c012 60
4be44fcd
LB
61static struct acpi_gpe_xrupt_info *acpi_ev_get_gpe_xrupt_block(u32
62 interrupt_number);
44f6c012
RM
63
64static acpi_status
4be44fcd 65acpi_ev_delete_gpe_xrupt(struct acpi_gpe_xrupt_info *gpe_xrupt);
44f6c012
RM
66
67static acpi_status
4be44fcd
LB
68acpi_ev_install_gpe_block(struct acpi_gpe_block_info *gpe_block,
69 u32 interrupt_number);
44f6c012
RM
70
71static acpi_status
4be44fcd 72acpi_ev_create_gpe_info_blocks(struct acpi_gpe_block_info *gpe_block);
1da177e4
LT
73
74/*******************************************************************************
75 *
76 * FUNCTION: acpi_ev_valid_gpe_event
77 *
78 * PARAMETERS: gpe_event_info - Info for this GPE
79 *
80 * RETURN: TRUE if the gpe_event is valid
81 *
96db255c 82 * DESCRIPTION: Validate a GPE event. DO NOT CALL FROM INTERRUPT LEVEL.
1da177e4
LT
83 * Should be called only when the GPE lists are semaphore locked
84 * and not subject to change.
85 *
86 ******************************************************************************/
87
4be44fcd 88u8 acpi_ev_valid_gpe_event(struct acpi_gpe_event_info *gpe_event_info)
1da177e4 89{
4be44fcd
LB
90 struct acpi_gpe_xrupt_info *gpe_xrupt_block;
91 struct acpi_gpe_block_info *gpe_block;
1da177e4 92
4be44fcd 93 ACPI_FUNCTION_ENTRY();
1da177e4
LT
94
95 /* No need for spin lock since we are not changing any list elements */
96
97 /* Walk the GPE interrupt levels */
98
99 gpe_xrupt_block = acpi_gbl_gpe_xrupt_list_head;
100 while (gpe_xrupt_block) {
101 gpe_block = gpe_xrupt_block->gpe_block_list_head;
102
103 /* Walk the GPE blocks on this interrupt level */
104
105 while (gpe_block) {
106 if ((&gpe_block->event_info[0] <= gpe_event_info) &&
0f849d2c 107 (&gpe_block->event_info[gpe_block->gpe_count] >
4be44fcd 108 gpe_event_info)) {
1da177e4
LT
109 return (TRUE);
110 }
111
112 gpe_block = gpe_block->next;
113 }
114
115 gpe_xrupt_block = gpe_xrupt_block->next;
116 }
117
118 return (FALSE);
119}
120
1da177e4
LT
121/*******************************************************************************
122 *
123 * FUNCTION: acpi_ev_walk_gpe_list
124 *
125 * PARAMETERS: gpe_walk_callback - Routine called for each GPE block
e97d6bf1 126 * Context - Value passed to callback
1da177e4
LT
127 *
128 * RETURN: Status
129 *
130 * DESCRIPTION: Walk the GPE lists.
131 *
132 ******************************************************************************/
133
e97d6bf1
BM
134acpi_status
135acpi_ev_walk_gpe_list(acpi_gpe_callback gpe_walk_callback, void *context)
1da177e4 136{
4be44fcd
LB
137 struct acpi_gpe_block_info *gpe_block;
138 struct acpi_gpe_xrupt_info *gpe_xrupt_info;
139 acpi_status status = AE_OK;
b8e4d893 140 acpi_cpu_flags flags;
1da177e4 141
b229cf92 142 ACPI_FUNCTION_TRACE(ev_walk_gpe_list);
1da177e4 143
4be44fcd 144 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
1da177e4
LT
145
146 /* Walk the interrupt level descriptor list */
147
148 gpe_xrupt_info = acpi_gbl_gpe_xrupt_list_head;
149 while (gpe_xrupt_info) {
52fc0b02 150
1da177e4
LT
151 /* Walk all Gpe Blocks attached to this interrupt level */
152
153 gpe_block = gpe_xrupt_info->gpe_block_list_head;
154 while (gpe_block) {
52fc0b02 155
1da177e4
LT
156 /* One callback per GPE block */
157
e97d6bf1
BM
158 status =
159 gpe_walk_callback(gpe_xrupt_info, gpe_block,
160 context);
4be44fcd 161 if (ACPI_FAILURE(status)) {
e97d6bf1
BM
162 if (status == AE_CTRL_END) { /* Callback abort */
163 status = AE_OK;
164 }
1da177e4
LT
165 goto unlock_and_exit;
166 }
167
168 gpe_block = gpe_block->next;
169 }
170
171 gpe_xrupt_info = gpe_xrupt_info->next;
172 }
173
4be44fcd
LB
174 unlock_and_exit:
175 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
176 return_ACPI_STATUS(status);
1da177e4
LT
177}
178
44f6c012 179/*******************************************************************************
1da177e4
LT
180 *
181 * FUNCTION: acpi_ev_delete_gpe_handlers
182 *
183 * PARAMETERS: gpe_xrupt_info - GPE Interrupt info
184 * gpe_block - Gpe Block info
185 *
186 * RETURN: Status
187 *
188 * DESCRIPTION: Delete all Handler objects found in the GPE data structs.
189 * Used only prior to termination.
190 *
191 ******************************************************************************/
192
193acpi_status
4be44fcd 194acpi_ev_delete_gpe_handlers(struct acpi_gpe_xrupt_info *gpe_xrupt_info,
e97d6bf1
BM
195 struct acpi_gpe_block_info *gpe_block,
196 void *context)
1da177e4 197{
4be44fcd 198 struct acpi_gpe_event_info *gpe_event_info;
67a119f9
BM
199 u32 i;
200 u32 j;
1da177e4 201
b229cf92 202 ACPI_FUNCTION_TRACE(ev_delete_gpe_handlers);
1da177e4
LT
203
204 /* Examine each GPE Register within the block */
205
206 for (i = 0; i < gpe_block->register_count; i++) {
52fc0b02 207
1da177e4
LT
208 /* Now look at the individual GPEs in this byte register */
209
210 for (j = 0; j < ACPI_GPE_REGISTER_WIDTH; j++) {
d4913dc6
BM
211 gpe_event_info = &gpe_block->event_info[((acpi_size) i *
212 ACPI_GPE_REGISTER_WIDTH)
213 + j];
1da177e4 214
44f6c012 215 if ((gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) ==
4be44fcd 216 ACPI_GPE_DISPATCH_HANDLER) {
8313524a 217 ACPI_FREE(gpe_event_info->dispatch.handler);
1da177e4 218 gpe_event_info->dispatch.handler = NULL;
4be44fcd
LB
219 gpe_event_info->flags &=
220 ~ACPI_GPE_DISPATCH_MASK;
1da177e4
LT
221 }
222 }
223 }
224
4be44fcd 225 return_ACPI_STATUS(AE_OK);
1da177e4
LT
226}
227
1da177e4
LT
228/*******************************************************************************
229 *
0f849d2c 230 * FUNCTION: acpi_ev_match_gpe_method
1da177e4
LT
231 *
232 * PARAMETERS: Callback from walk_namespace
233 *
234 * RETURN: Status
235 *
236 * DESCRIPTION: Called from acpi_walk_namespace. Expects each object to be a
237 * control method under the _GPE portion of the namespace.
238 * Extract the name and GPE type from the object, saving this
239 * information for quick lookup during GPE dispatch
240 *
241 * The name of each GPE control method is of the form:
0f849d2c 242 * "_Lxx" or "_Exx", where:
1da177e4
LT
243 * L - means that the GPE is level triggered
244 * E - means that the GPE is edge triggered
245 * xx - is the GPE number [in HEX]
246 *
247 ******************************************************************************/
248
249static acpi_status
0f849d2c 250acpi_ev_match_gpe_method(acpi_handle obj_handle,
4be44fcd 251 u32 level, void *obj_desc, void **return_value)
1da177e4 252{
0f849d2c
LM
253 struct acpi_namespace_node *method_node =
254 ACPI_CAST_PTR(struct acpi_namespace_node, obj_handle);
4be44fcd
LB
255 struct acpi_gpe_block_info *gpe_block = (void *)obj_desc;
256 struct acpi_gpe_event_info *gpe_event_info;
257 u32 gpe_number;
258 char name[ACPI_NAME_SIZE + 1];
259 u8 type;
1da177e4 260
b229cf92 261 ACPI_FUNCTION_TRACE(ev_save_method_info);
1da177e4
LT
262
263 /*
0f849d2c 264 * Match and decode the _Lxx and _Exx GPE method names
1da177e4 265 *
0f849d2c 266 * 1) Extract the method name and null terminate it
1da177e4 267 */
0f849d2c 268 ACPI_MOVE_32_TO_32(name, &method_node->name.integer);
1da177e4
LT
269 name[ACPI_NAME_SIZE] = 0;
270
0f849d2c
LM
271 /* 2) Name must begin with an underscore */
272
273 if (name[0] != '_') {
274 return_ACPI_STATUS(AE_OK); /* Ignore this method */
275 }
276
1da177e4 277 /*
0f849d2c 278 * 3) Edge/Level determination is based on the 2nd character
1da177e4
LT
279 * of the method name
280 *
0f849d2c
LM
281 * NOTE: Default GPE type is RUNTIME only. Later, if a _PRW object is
282 * found that points to this GPE, the ACPI_GPE_CAN_WAKE flag is set.
1da177e4
LT
283 */
284 switch (name[1]) {
285 case 'L':
286 type = ACPI_GPE_LEVEL_TRIGGERED;
287 break;
288
289 case 'E':
290 type = ACPI_GPE_EDGE_TRIGGERED;
291 break;
292
293 default:
0f849d2c 294 /* Unknown method type, just ignore it */
1da177e4 295
b229cf92 296 ACPI_DEBUG_PRINT((ACPI_DB_LOAD,
d4913dc6
BM
297 "Ignoring unknown GPE method type: %s "
298 "(name not of form _Lxx or _Exx)", name));
4be44fcd 299 return_ACPI_STATUS(AE_OK);
1da177e4
LT
300 }
301
0f849d2c 302 /* 4) The last two characters of the name are the hex GPE Number */
1da177e4 303
4be44fcd 304 gpe_number = ACPI_STRTOUL(&name[2], NULL, 16);
1da177e4 305 if (gpe_number == ACPI_UINT32_MAX) {
52fc0b02 306
1da177e4
LT
307 /* Conversion failed; invalid method, just ignore it */
308
b229cf92 309 ACPI_DEBUG_PRINT((ACPI_DB_LOAD,
d4913dc6
BM
310 "Could not extract GPE number from name: %s "
311 "(name is not of form _Lxx or _Exx)", name));
4be44fcd 312 return_ACPI_STATUS(AE_OK);
1da177e4
LT
313 }
314
315 /* Ensure that we have a valid GPE number for this GPE block */
316
0f849d2c
LM
317 gpe_event_info = acpi_ev_low_get_gpe_info(gpe_number, gpe_block);
318 if (!gpe_event_info) {
1da177e4 319 /*
0f849d2c
LM
320 * This gpe_number is not valid for this GPE block, just ignore it.
321 * However, it may be valid for a different GPE block, since GPE0
322 * and GPE1 methods both appear under \_GPE.
1da177e4 323 */
4be44fcd 324 return_ACPI_STATUS(AE_OK);
1da177e4
LT
325 }
326
327 /*
0f849d2c
LM
328 * Add the GPE information from above to the gpe_event_info block for
329 * use during dispatch of this GPE.
1da177e4 330 */
0f849d2c
LM
331 gpe_event_info->flags = (u8)(type | ACPI_GPE_DISPATCH_METHOD);
332 gpe_event_info->dispatch.method_node = method_node;
1da177e4 333
4be44fcd
LB
334 ACPI_DEBUG_PRINT((ACPI_DB_LOAD,
335 "Registered GPE method %s as GPE number 0x%.2X\n",
336 name, gpe_number));
9630bdd9 337 return_ACPI_STATUS(AE_OK);
1da177e4
LT
338}
339
1da177e4
LT
340/*******************************************************************************
341 *
342 * FUNCTION: acpi_ev_match_prw_and_gpe
343 *
344 * PARAMETERS: Callback from walk_namespace
345 *
96db255c 346 * RETURN: Status. NOTE: We ignore errors so that the _PRW walk is
1da177e4
LT
347 * not aborted on a single _PRW failure.
348 *
349 * DESCRIPTION: Called from acpi_walk_namespace. Expects each object to be a
96db255c 350 * Device. Run the _PRW method. If present, extract the GPE
0f849d2c 351 * number and mark the GPE as a CAN_WAKE GPE.
1da177e4
LT
352 *
353 ******************************************************************************/
354
355static acpi_status
4be44fcd
LB
356acpi_ev_match_prw_and_gpe(acpi_handle obj_handle,
357 u32 level, void *info, void **return_value)
1da177e4 358{
4be44fcd
LB
359 struct acpi_gpe_walk_info *gpe_info = (void *)info;
360 struct acpi_namespace_node *gpe_device;
361 struct acpi_gpe_block_info *gpe_block;
362 struct acpi_namespace_node *target_gpe_device;
363 struct acpi_gpe_event_info *gpe_event_info;
364 union acpi_operand_object *pkg_desc;
365 union acpi_operand_object *obj_desc;
366 u32 gpe_number;
367 acpi_status status;
368
b229cf92 369 ACPI_FUNCTION_TRACE(ev_match_prw_and_gpe);
1da177e4
LT
370
371 /* Check for a _PRW method under this device */
372
4be44fcd
LB
373 status = acpi_ut_evaluate_object(obj_handle, METHOD_NAME__PRW,
374 ACPI_BTYPE_PACKAGE, &pkg_desc);
375 if (ACPI_FAILURE(status)) {
52fc0b02 376
0f849d2c 377 /* Ignore all errors from _PRW, we don't want to abort the walk */
1da177e4 378
4be44fcd 379 return_ACPI_STATUS(AE_OK);
1da177e4
LT
380 }
381
382 /* The returned _PRW package must have at least two elements */
383
384 if (pkg_desc->package.count < 2) {
385 goto cleanup;
386 }
387
388 /* Extract pointers from the input context */
389
390 gpe_device = gpe_info->gpe_device;
391 gpe_block = gpe_info->gpe_block;
392
393 /*
9f15fc66
BM
394 * The _PRW object must return a package, we are only interested in the
395 * first element
1da177e4
LT
396 */
397 obj_desc = pkg_desc->package.elements[0];
398
3371c19c 399 if (obj_desc->common.type == ACPI_TYPE_INTEGER) {
52fc0b02 400
1da177e4
LT
401 /* Use FADT-defined GPE device (from definition of _PRW) */
402
403 target_gpe_device = acpi_gbl_fadt_gpe_device;
404
405 /* Integer is the GPE number in the FADT described GPE blocks */
406
407 gpe_number = (u32) obj_desc->integer.value;
3371c19c 408 } else if (obj_desc->common.type == ACPI_TYPE_PACKAGE) {
52fc0b02 409
1da177e4
LT
410 /* Package contains a GPE reference and GPE number within a GPE block */
411
412 if ((obj_desc->package.count < 2) ||
3371c19c 413 ((obj_desc->package.elements[0])->common.type !=
d4913dc6
BM
414 ACPI_TYPE_LOCAL_REFERENCE) ||
415 ((obj_desc->package.elements[1])->common.type !=
416 ACPI_TYPE_INTEGER)) {
1da177e4
LT
417 goto cleanup;
418 }
419
420 /* Get GPE block reference and decode */
421
4be44fcd
LB
422 target_gpe_device =
423 obj_desc->package.elements[0]->reference.node;
1da177e4 424 gpe_number = (u32) obj_desc->package.elements[1]->integer.value;
4be44fcd 425 } else {
1da177e4
LT
426 /* Unknown type, just ignore it */
427
428 goto cleanup;
429 }
430
431 /*
432 * Is this GPE within this block?
433 *
9f15fc66 434 * TRUE if and only if these conditions are true:
1da177e4
LT
435 * 1) The GPE devices match.
436 * 2) The GPE index(number) is within the range of the Gpe Block
437 * associated with the GPE device.
438 */
0f849d2c
LM
439 if (gpe_device != target_gpe_device) {
440 goto cleanup;
441 }
442
443 gpe_event_info = acpi_ev_low_get_gpe_info(gpe_number, gpe_block);
444 if (gpe_event_info) {
445 /* This GPE can wake the system */
1da177e4 446
9630bdd9 447 gpe_event_info->flags |= ACPI_GPE_CAN_WAKE;
1da177e4
LT
448 }
449
4be44fcd
LB
450 cleanup:
451 acpi_ut_remove_reference(pkg_desc);
452 return_ACPI_STATUS(AE_OK);
1da177e4
LT
453}
454
1da177e4
LT
455/*******************************************************************************
456 *
457 * FUNCTION: acpi_ev_get_gpe_xrupt_block
458 *
6f42ccf2 459 * PARAMETERS: interrupt_number - Interrupt for a GPE block
1da177e4
LT
460 *
461 * RETURN: A GPE interrupt block
462 *
96db255c 463 * DESCRIPTION: Get or Create a GPE interrupt block. There is one interrupt
9f15fc66
BM
464 * block per unique interrupt level used for GPEs. Should be
465 * called only when the GPE lists are semaphore locked and not
466 * subject to change.
1da177e4
LT
467 *
468 ******************************************************************************/
469
4be44fcd
LB
470static struct acpi_gpe_xrupt_info *acpi_ev_get_gpe_xrupt_block(u32
471 interrupt_number)
1da177e4 472{
4be44fcd
LB
473 struct acpi_gpe_xrupt_info *next_gpe_xrupt;
474 struct acpi_gpe_xrupt_info *gpe_xrupt;
475 acpi_status status;
b8e4d893 476 acpi_cpu_flags flags;
1da177e4 477
b229cf92 478 ACPI_FUNCTION_TRACE(ev_get_gpe_xrupt_block);
1da177e4 479
44f6c012 480 /* No need for lock since we are not changing any list elements here */
1da177e4
LT
481
482 next_gpe_xrupt = acpi_gbl_gpe_xrupt_list_head;
483 while (next_gpe_xrupt) {
6f42ccf2 484 if (next_gpe_xrupt->interrupt_number == interrupt_number) {
4be44fcd 485 return_PTR(next_gpe_xrupt);
1da177e4
LT
486 }
487
488 next_gpe_xrupt = next_gpe_xrupt->next;
489 }
490
491 /* Not found, must allocate a new xrupt descriptor */
492
8313524a 493 gpe_xrupt = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_gpe_xrupt_info));
1da177e4 494 if (!gpe_xrupt) {
4be44fcd 495 return_PTR(NULL);
1da177e4
LT
496 }
497
6f42ccf2 498 gpe_xrupt->interrupt_number = interrupt_number;
1da177e4
LT
499
500 /* Install new interrupt descriptor with spin lock */
501
4be44fcd 502 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
1da177e4
LT
503 if (acpi_gbl_gpe_xrupt_list_head) {
504 next_gpe_xrupt = acpi_gbl_gpe_xrupt_list_head;
505 while (next_gpe_xrupt->next) {
506 next_gpe_xrupt = next_gpe_xrupt->next;
507 }
508
509 next_gpe_xrupt->next = gpe_xrupt;
510 gpe_xrupt->previous = next_gpe_xrupt;
4be44fcd 511 } else {
1da177e4
LT
512 acpi_gbl_gpe_xrupt_list_head = gpe_xrupt;
513 }
4be44fcd 514 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
1da177e4
LT
515
516 /* Install new interrupt handler if not SCI_INT */
517
f3d2e786 518 if (interrupt_number != acpi_gbl_FADT.sci_interrupt) {
4be44fcd
LB
519 status = acpi_os_install_interrupt_handler(interrupt_number,
520 acpi_ev_gpe_xrupt_handler,
521 gpe_xrupt);
522 if (ACPI_FAILURE(status)) {
b8e4d893
BM
523 ACPI_ERROR((AE_INFO,
524 "Could not install GPE interrupt handler at level 0x%X",
525 interrupt_number));
4be44fcd 526 return_PTR(NULL);
1da177e4
LT
527 }
528 }
529
4be44fcd 530 return_PTR(gpe_xrupt);
1da177e4
LT
531}
532
1da177e4
LT
533/*******************************************************************************
534 *
535 * FUNCTION: acpi_ev_delete_gpe_xrupt
536 *
537 * PARAMETERS: gpe_xrupt - A GPE interrupt info block
538 *
539 * RETURN: Status
540 *
541 * DESCRIPTION: Remove and free a gpe_xrupt block. Remove an associated
542 * interrupt handler if not the SCI interrupt.
543 *
544 ******************************************************************************/
545
546static acpi_status
4be44fcd 547acpi_ev_delete_gpe_xrupt(struct acpi_gpe_xrupt_info *gpe_xrupt)
1da177e4 548{
4be44fcd 549 acpi_status status;
b8e4d893 550 acpi_cpu_flags flags;
1da177e4 551
b229cf92 552 ACPI_FUNCTION_TRACE(ev_delete_gpe_xrupt);
1da177e4
LT
553
554 /* We never want to remove the SCI interrupt handler */
555
f3d2e786 556 if (gpe_xrupt->interrupt_number == acpi_gbl_FADT.sci_interrupt) {
1da177e4 557 gpe_xrupt->gpe_block_list_head = NULL;
4be44fcd 558 return_ACPI_STATUS(AE_OK);
1da177e4
LT
559 }
560
561 /* Disable this interrupt */
562
96db255c
BM
563 status =
564 acpi_os_remove_interrupt_handler(gpe_xrupt->interrupt_number,
565 acpi_ev_gpe_xrupt_handler);
4be44fcd
LB
566 if (ACPI_FAILURE(status)) {
567 return_ACPI_STATUS(status);
1da177e4
LT
568 }
569
570 /* Unlink the interrupt block with lock */
571
4be44fcd 572 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
1da177e4
LT
573 if (gpe_xrupt->previous) {
574 gpe_xrupt->previous->next = gpe_xrupt->next;
e0b91050
BM
575 } else {
576 /* No previous, update list head */
577
578 acpi_gbl_gpe_xrupt_list_head = gpe_xrupt->next;
1da177e4
LT
579 }
580
581 if (gpe_xrupt->next) {
582 gpe_xrupt->next->previous = gpe_xrupt->previous;
583 }
4be44fcd 584 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
1da177e4
LT
585
586 /* Free the block */
587
8313524a 588 ACPI_FREE(gpe_xrupt);
4be44fcd 589 return_ACPI_STATUS(AE_OK);
1da177e4
LT
590}
591
1da177e4
LT
592/*******************************************************************************
593 *
594 * FUNCTION: acpi_ev_install_gpe_block
595 *
9f15fc66
BM
596 * PARAMETERS: gpe_block - New GPE block
597 * interrupt_number - Xrupt to be associated with this
598 * GPE block
1da177e4
LT
599 *
600 * RETURN: Status
601 *
602 * DESCRIPTION: Install new GPE block with mutex support
603 *
604 ******************************************************************************/
605
606static acpi_status
4be44fcd
LB
607acpi_ev_install_gpe_block(struct acpi_gpe_block_info *gpe_block,
608 u32 interrupt_number)
1da177e4 609{
4be44fcd
LB
610 struct acpi_gpe_block_info *next_gpe_block;
611 struct acpi_gpe_xrupt_info *gpe_xrupt_block;
612 acpi_status status;
b8e4d893 613 acpi_cpu_flags flags;
1da177e4 614
b229cf92 615 ACPI_FUNCTION_TRACE(ev_install_gpe_block);
1da177e4 616
4be44fcd
LB
617 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
618 if (ACPI_FAILURE(status)) {
619 return_ACPI_STATUS(status);
1da177e4
LT
620 }
621
4be44fcd 622 gpe_xrupt_block = acpi_ev_get_gpe_xrupt_block(interrupt_number);
1da177e4
LT
623 if (!gpe_xrupt_block) {
624 status = AE_NO_MEMORY;
625 goto unlock_and_exit;
626 }
627
44f6c012 628 /* Install the new block at the end of the list with lock */
1da177e4 629
4be44fcd 630 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
1da177e4
LT
631 if (gpe_xrupt_block->gpe_block_list_head) {
632 next_gpe_block = gpe_xrupt_block->gpe_block_list_head;
633 while (next_gpe_block->next) {
634 next_gpe_block = next_gpe_block->next;
635 }
636
637 next_gpe_block->next = gpe_block;
638 gpe_block->previous = next_gpe_block;
4be44fcd 639 } else {
1da177e4
LT
640 gpe_xrupt_block->gpe_block_list_head = gpe_block;
641 }
642
643 gpe_block->xrupt_block = gpe_xrupt_block;
4be44fcd 644 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
1da177e4 645
4be44fcd
LB
646 unlock_and_exit:
647 status = acpi_ut_release_mutex(ACPI_MTX_EVENTS);
648 return_ACPI_STATUS(status);
1da177e4
LT
649}
650
1da177e4
LT
651/*******************************************************************************
652 *
653 * FUNCTION: acpi_ev_delete_gpe_block
654 *
9f15fc66 655 * PARAMETERS: gpe_block - Existing GPE block
1da177e4
LT
656 *
657 * RETURN: Status
658 *
659 * DESCRIPTION: Remove a GPE block
660 *
661 ******************************************************************************/
662
4be44fcd 663acpi_status acpi_ev_delete_gpe_block(struct acpi_gpe_block_info *gpe_block)
1da177e4 664{
4be44fcd 665 acpi_status status;
b8e4d893 666 acpi_cpu_flags flags;
1da177e4 667
b229cf92 668 ACPI_FUNCTION_TRACE(ev_install_gpe_block);
1da177e4 669
4be44fcd
LB
670 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
671 if (ACPI_FAILURE(status)) {
672 return_ACPI_STATUS(status);
1da177e4
LT
673 }
674
675 /* Disable all GPEs in this block */
676
e97d6bf1
BM
677 status =
678 acpi_hw_disable_gpe_block(gpe_block->xrupt_block, gpe_block, NULL);
1da177e4
LT
679
680 if (!gpe_block->previous && !gpe_block->next) {
52fc0b02 681
1da177e4
LT
682 /* This is the last gpe_block on this interrupt */
683
4be44fcd
LB
684 status = acpi_ev_delete_gpe_xrupt(gpe_block->xrupt_block);
685 if (ACPI_FAILURE(status)) {
1da177e4
LT
686 goto unlock_and_exit;
687 }
4be44fcd 688 } else {
1da177e4
LT
689 /* Remove the block on this interrupt with lock */
690
4be44fcd 691 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
1da177e4
LT
692 if (gpe_block->previous) {
693 gpe_block->previous->next = gpe_block->next;
4be44fcd
LB
694 } else {
695 gpe_block->xrupt_block->gpe_block_list_head =
696 gpe_block->next;
1da177e4
LT
697 }
698
699 if (gpe_block->next) {
700 gpe_block->next->previous = gpe_block->previous;
701 }
4be44fcd 702 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
1da177e4
LT
703 }
704
0f849d2c 705 acpi_current_gpe_count -= gpe_block->gpe_count;
e97d6bf1 706
1da177e4
LT
707 /* Free the gpe_block */
708
8313524a
BM
709 ACPI_FREE(gpe_block->register_info);
710 ACPI_FREE(gpe_block->event_info);
711 ACPI_FREE(gpe_block);
1da177e4 712
4be44fcd
LB
713 unlock_and_exit:
714 status = acpi_ut_release_mutex(ACPI_MTX_EVENTS);
715 return_ACPI_STATUS(status);
1da177e4
LT
716}
717
1da177e4
LT
718/*******************************************************************************
719 *
720 * FUNCTION: acpi_ev_create_gpe_info_blocks
721 *
722 * PARAMETERS: gpe_block - New GPE block
723 *
724 * RETURN: Status
725 *
726 * DESCRIPTION: Create the register_info and event_info blocks for this GPE block
727 *
728 ******************************************************************************/
729
730static acpi_status
4be44fcd 731acpi_ev_create_gpe_info_blocks(struct acpi_gpe_block_info *gpe_block)
1da177e4 732{
4be44fcd
LB
733 struct acpi_gpe_register_info *gpe_register_info = NULL;
734 struct acpi_gpe_event_info *gpe_event_info = NULL;
735 struct acpi_gpe_event_info *this_event;
736 struct acpi_gpe_register_info *this_register;
67a119f9
BM
737 u32 i;
738 u32 j;
4be44fcd 739 acpi_status status;
1da177e4 740
b229cf92 741 ACPI_FUNCTION_TRACE(ev_create_gpe_info_blocks);
1da177e4
LT
742
743 /* Allocate the GPE register information block */
744
8313524a
BM
745 gpe_register_info = ACPI_ALLOCATE_ZEROED((acpi_size) gpe_block->
746 register_count *
747 sizeof(struct
748 acpi_gpe_register_info));
1da177e4 749 if (!gpe_register_info) {
b8e4d893 750 ACPI_ERROR((AE_INFO,
b229cf92 751 "Could not allocate the GpeRegisterInfo table"));
4be44fcd 752 return_ACPI_STATUS(AE_NO_MEMORY);
1da177e4
LT
753 }
754
755 /*
756 * Allocate the GPE event_info block. There are eight distinct GPEs
96db255c 757 * per register. Initialization to zeros is sufficient.
1da177e4 758 */
0f849d2c 759 gpe_event_info = ACPI_ALLOCATE_ZEROED((acpi_size) gpe_block->gpe_count *
8313524a
BM
760 sizeof(struct
761 acpi_gpe_event_info));
1da177e4 762 if (!gpe_event_info) {
b8e4d893 763 ACPI_ERROR((AE_INFO,
b229cf92 764 "Could not allocate the GpeEventInfo table"));
1da177e4
LT
765 status = AE_NO_MEMORY;
766 goto error_exit;
767 }
768
769 /* Save the new Info arrays in the GPE block */
770
771 gpe_block->register_info = gpe_register_info;
4be44fcd 772 gpe_block->event_info = gpe_event_info;
1da177e4
LT
773
774 /*
96db255c 775 * Initialize the GPE Register and Event structures. A goal of these
9f15fc66
BM
776 * tables is to hide the fact that there are two separate GPE register
777 * sets in a given GPE hardware block, the status registers occupy the
778 * first half, and the enable registers occupy the second half.
1da177e4
LT
779 */
780 this_register = gpe_register_info;
4be44fcd 781 this_event = gpe_event_info;
1da177e4
LT
782
783 for (i = 0; i < gpe_block->register_count; i++) {
52fc0b02 784
1da177e4
LT
785 /* Init the register_info for this GPE register (8 GPEs) */
786
4be44fcd
LB
787 this_register->base_gpe_number =
788 (u8) (gpe_block->block_base_number +
789 (i * ACPI_GPE_REGISTER_WIDTH));
790
59fa8505
BM
791 this_register->status_address.address =
792 gpe_block->block_address.address + i;
4be44fcd 793
59fa8505
BM
794 this_register->enable_address.address =
795 gpe_block->block_address.address + i +
796 gpe_block->register_count;
4be44fcd 797
f3d2e786
BM
798 this_register->status_address.space_id =
799 gpe_block->block_address.space_id;
800 this_register->enable_address.space_id =
801 gpe_block->block_address.space_id;
802 this_register->status_address.bit_width =
4be44fcd 803 ACPI_GPE_REGISTER_WIDTH;
f3d2e786 804 this_register->enable_address.bit_width =
4be44fcd 805 ACPI_GPE_REGISTER_WIDTH;
ecfbbc7b
BM
806 this_register->status_address.bit_offset = 0;
807 this_register->enable_address.bit_offset = 0;
1da177e4
LT
808
809 /* Init the event_info for each GPE within this register */
810
811 for (j = 0; j < ACPI_GPE_REGISTER_WIDTH; j++) {
69874165
AS
812 this_event->gpe_number =
813 (u8) (this_register->base_gpe_number + j);
1da177e4
LT
814 this_event->register_info = this_register;
815 this_event++;
816 }
817
96db255c
BM
818 /* Disable all GPEs within this register */
819
c6b5774c 820 status = acpi_hw_write(0x00, &this_register->enable_address);
4be44fcd 821 if (ACPI_FAILURE(status)) {
1da177e4
LT
822 goto error_exit;
823 }
824
96db255c
BM
825 /* Clear any pending GPE events within this register */
826
c6b5774c 827 status = acpi_hw_write(0xFF, &this_register->status_address);
4be44fcd 828 if (ACPI_FAILURE(status)) {
1da177e4
LT
829 goto error_exit;
830 }
831
832 this_register++;
833 }
834
4be44fcd 835 return_ACPI_STATUS(AE_OK);
1da177e4 836
4be44fcd 837 error_exit:
1da177e4 838 if (gpe_register_info) {
8313524a 839 ACPI_FREE(gpe_register_info);
1da177e4
LT
840 }
841 if (gpe_event_info) {
8313524a 842 ACPI_FREE(gpe_event_info);
1da177e4
LT
843 }
844
4be44fcd 845 return_ACPI_STATUS(status);
1da177e4
LT
846}
847
1da177e4
LT
848/*******************************************************************************
849 *
850 * FUNCTION: acpi_ev_create_gpe_block
851 *
852 * PARAMETERS: gpe_device - Handle to the parent GPE block
853 * gpe_block_address - Address and space_iD
854 * register_count - Number of GPE register pairs in the block
855 * gpe_block_base_number - Starting GPE number for the block
6f42ccf2 856 * interrupt_number - H/W interrupt for the block
1da177e4
LT
857 * return_gpe_block - Where the new block descriptor is returned
858 *
859 * RETURN: Status
860 *
96db255c
BM
861 * DESCRIPTION: Create and Install a block of GPE registers. All GPEs within
862 * the block are disabled at exit.
863 * Note: Assumes namespace is locked.
1da177e4
LT
864 *
865 ******************************************************************************/
866
867acpi_status
4be44fcd
LB
868acpi_ev_create_gpe_block(struct acpi_namespace_node *gpe_device,
869 struct acpi_generic_address *gpe_block_address,
870 u32 register_count,
871 u8 gpe_block_base_number,
872 u32 interrupt_number,
873 struct acpi_gpe_block_info **return_gpe_block)
1da177e4 874{
4be44fcd 875 acpi_status status;
96db255c 876 struct acpi_gpe_block_info *gpe_block;
1da177e4 877
b229cf92 878 ACPI_FUNCTION_TRACE(ev_create_gpe_block);
1da177e4
LT
879
880 if (!register_count) {
4be44fcd 881 return_ACPI_STATUS(AE_OK);
1da177e4
LT
882 }
883
884 /* Allocate a new GPE block */
885
8313524a 886 gpe_block = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_gpe_block_info));
1da177e4 887 if (!gpe_block) {
4be44fcd 888 return_ACPI_STATUS(AE_NO_MEMORY);
1da177e4
LT
889 }
890
891 /* Initialize the new GPE block */
892
96db255c 893 gpe_block->node = gpe_device;
0f849d2c 894 gpe_block->gpe_count = (u16)(register_count * ACPI_GPE_REGISTER_WIDTH);
1da177e4
LT
895 gpe_block->register_count = register_count;
896 gpe_block->block_base_number = gpe_block_base_number;
1da177e4 897
4be44fcd
LB
898 ACPI_MEMCPY(&gpe_block->block_address, gpe_block_address,
899 sizeof(struct acpi_generic_address));
1da177e4 900
96db255c
BM
901 /*
902 * Create the register_info and event_info sub-structures
903 * Note: disables and clears all GPEs in the block
904 */
4be44fcd
LB
905 status = acpi_ev_create_gpe_info_blocks(gpe_block);
906 if (ACPI_FAILURE(status)) {
8313524a 907 ACPI_FREE(gpe_block);
4be44fcd 908 return_ACPI_STATUS(status);
1da177e4
LT
909 }
910
96db255c 911 /* Install the new block in the global lists */
1da177e4 912
4be44fcd
LB
913 status = acpi_ev_install_gpe_block(gpe_block, interrupt_number);
914 if (ACPI_FAILURE(status)) {
8313524a 915 ACPI_FREE(gpe_block);
4be44fcd 916 return_ACPI_STATUS(status);
1da177e4
LT
917 }
918
919 /* Find all GPE methods (_Lxx, _Exx) for this block */
920
4be44fcd
LB
921 status = acpi_ns_walk_namespace(ACPI_TYPE_METHOD, gpe_device,
922 ACPI_UINT32_MAX, ACPI_NS_WALK_NO_UNLOCK,
0f849d2c 923 acpi_ev_match_gpe_method, NULL,
2263576c 924 gpe_block, NULL);
1da177e4 925
96db255c
BM
926 /* Return the new block */
927
928 if (return_gpe_block) {
929 (*return_gpe_block) = gpe_block;
930 }
931
932 ACPI_DEBUG_PRINT((ACPI_DB_INIT,
933 "GPE %02X to %02X [%4.4s] %u regs on int 0x%X\n",
934 (u32) gpe_block->block_base_number,
935 (u32) (gpe_block->block_base_number +
0f849d2c 936 (gpe_block->gpe_count - 1)),
96db255c
BM
937 gpe_device->name.ascii, gpe_block->register_count,
938 interrupt_number));
939
e97d6bf1
BM
940 /* Update global count of currently available GPEs */
941
0f849d2c 942 acpi_current_gpe_count += gpe_block->gpe_count;
96db255c
BM
943 return_ACPI_STATUS(AE_OK);
944}
945
946/*******************************************************************************
947 *
948 * FUNCTION: acpi_ev_initialize_gpe_block
949 *
950 * PARAMETERS: gpe_device - Handle to the parent GPE block
951 * gpe_block - Gpe Block info
952 *
953 * RETURN: Status
954 *
955 * DESCRIPTION: Initialize and enable a GPE block. First find and run any
956 * _PRT methods associated with the block, then enable the
957 * appropriate GPEs.
958 * Note: Assumes namespace is locked.
959 *
960 ******************************************************************************/
961
962acpi_status
963acpi_ev_initialize_gpe_block(struct acpi_namespace_node *gpe_device,
964 struct acpi_gpe_block_info *gpe_block)
965{
0f849d2c 966 acpi_status status;
96db255c
BM
967 struct acpi_gpe_event_info *gpe_event_info;
968 struct acpi_gpe_walk_info gpe_info;
969 u32 wake_gpe_count;
970 u32 gpe_enabled_count;
0f849d2c
LM
971 u32 gpe_index;
972 u32 gpe_number;
67a119f9
BM
973 u32 i;
974 u32 j;
96db255c 975
b229cf92 976 ACPI_FUNCTION_TRACE(ev_initialize_gpe_block);
96db255c
BM
977
978 /* Ignore a null GPE block (e.g., if no GPE block 1 exists) */
979
980 if (!gpe_block) {
981 return_ACPI_STATUS(AE_OK);
982 }
983
1da177e4 984 /*
96db255c
BM
985 * Runtime option: Should wake GPEs be enabled at runtime? The default
986 * is no, they should only be enabled just as the machine goes to sleep.
1da177e4
LT
987 */
988 if (acpi_gbl_leave_wake_gpes_disabled) {
989 /*
96db255c
BM
990 * Differentiate runtime vs wake GPEs, via the _PRW control methods.
991 * Each GPE that has one or more _PRWs that reference it is by
992 * definition a wake GPE and will not be enabled while the machine
993 * is running.
1da177e4
LT
994 */
995 gpe_info.gpe_block = gpe_block;
996 gpe_info.gpe_device = gpe_device;
997
0f849d2c 998 status = acpi_ns_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,
4be44fcd 999 ACPI_UINT32_MAX, ACPI_NS_WALK_UNLOCK,
2263576c
LM
1000 acpi_ev_match_prw_and_gpe, NULL,
1001 &gpe_info, NULL);
0f849d2c
LM
1002 if (ACPI_FAILURE(status)) {
1003 ACPI_EXCEPTION((AE_INFO, status,
1004 "While executing _PRW methods"));
1005 }
1da177e4
LT
1006 }
1007
1008 /*
0f849d2c 1009 * Enable all GPEs that have a corresponding method and are not
9630bdd9 1010 * capable of generating wakeups. Any other GPEs within this block
0f849d2c 1011 * must be enabled via the acpi_enable_gpe interface.
1da177e4
LT
1012 */
1013 wake_gpe_count = 0;
1014 gpe_enabled_count = 0;
0f849d2c
LM
1015
1016 if (gpe_device == acpi_gbl_fadt_gpe_device) {
9630bdd9 1017 gpe_device = NULL;
0f849d2c 1018 }
1da177e4
LT
1019
1020 for (i = 0; i < gpe_block->register_count; i++) {
9630bdd9 1021 for (j = 0; j < ACPI_GPE_REGISTER_WIDTH; j++) {
52fc0b02 1022
1da177e4 1023 /* Get the info block for this particular GPE */
0f849d2c
LM
1024
1025 gpe_index = (i * ACPI_GPE_REGISTER_WIDTH) + j;
9630bdd9 1026 gpe_event_info = &gpe_block->event_info[gpe_index];
1da177e4 1027
9630bdd9 1028 if (gpe_event_info->flags & ACPI_GPE_CAN_WAKE) {
1da177e4 1029 wake_gpe_count++;
0f849d2c 1030 if (acpi_gbl_leave_wake_gpes_disabled) {
9630bdd9 1031 continue;
0f849d2c 1032 }
1da177e4 1033 }
9630bdd9 1034
0f849d2c
LM
1035 /* Ignore GPEs that have no corresponding _Lxx/_Exx method */
1036
1037 if (!(gpe_event_info->flags & ACPI_GPE_DISPATCH_METHOD)) {
9630bdd9 1038 continue;
0f849d2c
LM
1039 }
1040
1041 /* Enable this GPE */
9630bdd9
RW
1042
1043 gpe_number = gpe_index + gpe_block->block_base_number;
1044 status = acpi_enable_gpe(gpe_device, gpe_number,
0f849d2c
LM
1045 ACPI_GPE_TYPE_RUNTIME);
1046 if (ACPI_FAILURE(status)) {
1047 ACPI_EXCEPTION((AE_INFO, status,
1048 "Could not enable GPE 0x%02X",
9630bdd9 1049 gpe_number));
0f849d2c
LM
1050 continue;
1051 }
1052
1053 gpe_enabled_count++;
1da177e4
LT
1054 }
1055 }
1056
4be44fcd
LB
1057 ACPI_DEBUG_PRINT((ACPI_DB_INIT,
1058 "Found %u Wake, Enabled %u Runtime GPEs in this block\n",
1059 wake_gpe_count, gpe_enabled_count));
1da177e4 1060
9630bdd9 1061 return_ACPI_STATUS(AE_OK);
1da177e4
LT
1062}
1063
1da177e4
LT
1064/*******************************************************************************
1065 *
1066 * FUNCTION: acpi_ev_gpe_initialize
1067 *
1068 * PARAMETERS: None
1069 *
1070 * RETURN: Status
1071 *
1072 * DESCRIPTION: Initialize the GPE data structures
1073 *
1074 ******************************************************************************/
1075
4be44fcd 1076acpi_status acpi_ev_gpe_initialize(void)
1da177e4 1077{
4be44fcd
LB
1078 u32 register_count0 = 0;
1079 u32 register_count1 = 0;
1080 u32 gpe_number_max = 0;
1081 acpi_status status;
1da177e4 1082
b229cf92 1083 ACPI_FUNCTION_TRACE(ev_gpe_initialize);
1da177e4 1084
4be44fcd
LB
1085 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
1086 if (ACPI_FAILURE(status)) {
1087 return_ACPI_STATUS(status);
1da177e4
LT
1088 }
1089
1090 /*
1091 * Initialize the GPE Block(s) defined in the FADT
1092 *
d4913dc6
BM
1093 * Why the GPE register block lengths are divided by 2: From the ACPI
1094 * Spec, section "General-Purpose Event Registers", we have:
1da177e4
LT
1095 *
1096 * "Each register block contains two registers of equal length
1097 * GPEx_STS and GPEx_EN (where x is 0 or 1). The length of the
1098 * GPE0_STS and GPE0_EN registers is equal to half the GPE0_LEN
1099 * The length of the GPE1_STS and GPE1_EN registers is equal to
1100 * half the GPE1_LEN. If a generic register block is not supported
1101 * then its respective block pointer and block length values in the
1102 * FADT table contain zeros. The GPE0_LEN and GPE1_LEN do not need
1103 * to be the same size."
1104 */
1105
1106 /*
1107 * Determine the maximum GPE number for this machine.
1108 *
1109 * Note: both GPE0 and GPE1 are optional, and either can exist without
1110 * the other.
1111 *
1112 * If EITHER the register length OR the block address are zero, then that
1113 * particular block is not supported.
1114 */
f3d2e786
BM
1115 if (acpi_gbl_FADT.gpe0_block_length &&
1116 acpi_gbl_FADT.xgpe0_block.address) {
52fc0b02 1117
1da177e4
LT
1118 /* GPE block 0 exists (has both length and address > 0) */
1119
f3d2e786 1120 register_count0 = (u16) (acpi_gbl_FADT.gpe0_block_length / 2);
1da177e4 1121
4be44fcd
LB
1122 gpe_number_max =
1123 (register_count0 * ACPI_GPE_REGISTER_WIDTH) - 1;
1da177e4
LT
1124
1125 /* Install GPE Block 0 */
1126
4be44fcd 1127 status = acpi_ev_create_gpe_block(acpi_gbl_fadt_gpe_device,
f3d2e786 1128 &acpi_gbl_FADT.xgpe0_block,
4be44fcd 1129 register_count0, 0,
f3d2e786 1130 acpi_gbl_FADT.sci_interrupt,
4be44fcd 1131 &acpi_gbl_gpe_fadt_blocks[0]);
1da177e4 1132
4be44fcd 1133 if (ACPI_FAILURE(status)) {
b8e4d893
BM
1134 ACPI_EXCEPTION((AE_INFO, status,
1135 "Could not create GPE Block 0"));
1da177e4
LT
1136 }
1137 }
1138
f3d2e786
BM
1139 if (acpi_gbl_FADT.gpe1_block_length &&
1140 acpi_gbl_FADT.xgpe1_block.address) {
52fc0b02 1141
1da177e4
LT
1142 /* GPE block 1 exists (has both length and address > 0) */
1143
f3d2e786 1144 register_count1 = (u16) (acpi_gbl_FADT.gpe1_block_length / 2);
1da177e4
LT
1145
1146 /* Check for GPE0/GPE1 overlap (if both banks exist) */
1147
1148 if ((register_count0) &&
f3d2e786 1149 (gpe_number_max >= acpi_gbl_FADT.gpe1_base)) {
b8e4d893 1150 ACPI_ERROR((AE_INFO,
f6a22b0b
BM
1151 "GPE0 block (GPE 0 to %u) overlaps the GPE1 block "
1152 "(GPE %u to %u) - Ignoring GPE1",
f3d2e786
BM
1153 gpe_number_max, acpi_gbl_FADT.gpe1_base,
1154 acpi_gbl_FADT.gpe1_base +
b8e4d893
BM
1155 ((register_count1 *
1156 ACPI_GPE_REGISTER_WIDTH) - 1)));
1da177e4
LT
1157
1158 /* Ignore GPE1 block by setting the register count to zero */
1159
1160 register_count1 = 0;
4be44fcd 1161 } else {
1da177e4
LT
1162 /* Install GPE Block 1 */
1163
4be44fcd
LB
1164 status =
1165 acpi_ev_create_gpe_block(acpi_gbl_fadt_gpe_device,
f3d2e786 1166 &acpi_gbl_FADT.xgpe1_block,
4be44fcd 1167 register_count1,
f3d2e786
BM
1168 acpi_gbl_FADT.gpe1_base,
1169 acpi_gbl_FADT.
1170 sci_interrupt,
4be44fcd
LB
1171 &acpi_gbl_gpe_fadt_blocks
1172 [1]);
1173
1174 if (ACPI_FAILURE(status)) {
b8e4d893
BM
1175 ACPI_EXCEPTION((AE_INFO, status,
1176 "Could not create GPE Block 1"));
1da177e4
LT
1177 }
1178
1179 /*
1180 * GPE0 and GPE1 do not have to be contiguous in the GPE number
1181 * space. However, GPE0 always starts at GPE number zero.
1182 */
f3d2e786 1183 gpe_number_max = acpi_gbl_FADT.gpe1_base +
4be44fcd 1184 ((register_count1 * ACPI_GPE_REGISTER_WIDTH) - 1);
1da177e4
LT
1185 }
1186 }
1187
1188 /* Exit if there are no GPE registers */
1189
1190 if ((register_count0 + register_count1) == 0) {
52fc0b02 1191
1da177e4
LT
1192 /* GPEs are not required by ACPI, this is OK */
1193
4be44fcd
LB
1194 ACPI_DEBUG_PRINT((ACPI_DB_INIT,
1195 "There are no GPE blocks defined in the FADT\n"));
1da177e4
LT
1196 status = AE_OK;
1197 goto cleanup;
1198 }
1199
1200 /* Check for Max GPE number out-of-range */
1201
1202 if (gpe_number_max > ACPI_GPE_MAX) {
b8e4d893
BM
1203 ACPI_ERROR((AE_INFO,
1204 "Maximum GPE number from FADT is too large: 0x%X",
1205 gpe_number_max));
1da177e4
LT
1206 status = AE_BAD_VALUE;
1207 goto cleanup;
1208 }
1209
4be44fcd
LB
1210 cleanup:
1211 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
1212 return_ACPI_STATUS(AE_OK);
1da177e4 1213}
This page took 0.477173 seconds and 5 git commands to generate.