blob: 85ded1f2540d9d5fced0195f30d2dc1f7bfeeb54 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/******************************************************************************
2 *
3 * Module Name: evgpeblk - GPE block creation and initialization.
4 *
5 *****************************************************************************/
6
7/*
Bob Moorea8357b02010-01-22 19:07:36 +08008 * Copyright (C) 2000 - 2010, Intel Corp.
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 * 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>
Len Browne2f7a772009-01-09 00:30:03 -050045#include "accommon.h"
46#include "acevents.h"
47#include "acnamesp.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070048
49#define _COMPONENT ACPI_EVENTS
Len Brown4be44fc2005-08-05 00:44:28 -040050ACPI_MODULE_NAME("evgpeblk")
Linus Torvalds1da177e2005-04-16 15:20:36 -070051
Robert Moore44f6c012005-04-18 22:49:35 -040052/* Local prototypes */
Len Brown4be44fc2005-08-05 00:44:28 -040053static acpi_status
Lin Ming0f849d22010-04-06 14:52:37 +080054acpi_ev_match_gpe_method(acpi_handle obj_handle,
Len Brown4be44fc2005-08-05 00:44:28 -040055 u32 level, void *obj_desc, void **return_value);
Robert Moore44f6c012005-04-18 22:49:35 -040056
57static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -040058acpi_ev_match_prw_and_gpe(acpi_handle obj_handle,
59 u32 level, void *info, void **return_value);
60
61static struct acpi_gpe_xrupt_info *acpi_ev_get_gpe_xrupt_block(u32
62 interrupt_number);
Robert Moore44f6c012005-04-18 22:49:35 -040063
64static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -040065acpi_ev_delete_gpe_xrupt(struct acpi_gpe_xrupt_info *gpe_xrupt);
Robert Moore44f6c012005-04-18 22:49:35 -040066
67static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -040068acpi_ev_install_gpe_block(struct acpi_gpe_block_info *gpe_block,
69 u32 interrupt_number);
Robert Moore44f6c012005-04-18 22:49:35 -040070
71static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -040072acpi_ev_create_gpe_info_blocks(struct acpi_gpe_block_info *gpe_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -070073
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 *
Bob Moore96db2552005-11-02 00:00:00 -050082 * DESCRIPTION: Validate a GPE event. DO NOT CALL FROM INTERRUPT LEVEL.
Linus Torvalds1da177e2005-04-16 15:20:36 -070083 * Should be called only when the GPE lists are semaphore locked
84 * and not subject to change.
85 *
86 ******************************************************************************/
87
Len Brown4be44fc2005-08-05 00:44:28 -040088u8 acpi_ev_valid_gpe_event(struct acpi_gpe_event_info *gpe_event_info)
Linus Torvalds1da177e2005-04-16 15:20:36 -070089{
Len Brown4be44fc2005-08-05 00:44:28 -040090 struct acpi_gpe_xrupt_info *gpe_xrupt_block;
91 struct acpi_gpe_block_info *gpe_block;
Linus Torvalds1da177e2005-04-16 15:20:36 -070092
Len Brown4be44fc2005-08-05 00:44:28 -040093 ACPI_FUNCTION_ENTRY();
Linus Torvalds1da177e2005-04-16 15:20:36 -070094
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) &&
Lin Ming0f849d22010-04-06 14:52:37 +0800107 (&gpe_block->event_info[gpe_block->gpe_count] >
Len Brown4be44fc2005-08-05 00:44:28 -0400108 gpe_event_info)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109 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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121/*******************************************************************************
122 *
123 * FUNCTION: acpi_ev_walk_gpe_list
124 *
125 * PARAMETERS: gpe_walk_callback - Routine called for each GPE block
Bob Mooree97d6bf2008-12-30 09:45:17 +0800126 * Context - Value passed to callback
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 *
128 * RETURN: Status
129 *
130 * DESCRIPTION: Walk the GPE lists.
131 *
132 ******************************************************************************/
133
Bob Mooree97d6bf2008-12-30 09:45:17 +0800134acpi_status
135acpi_ev_walk_gpe_list(acpi_gpe_callback gpe_walk_callback, void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136{
Len Brown4be44fc2005-08-05 00:44:28 -0400137 struct acpi_gpe_block_info *gpe_block;
138 struct acpi_gpe_xrupt_info *gpe_xrupt_info;
139 acpi_status status = AE_OK;
Bob Mooreb8e4d892006-01-27 16:43:00 -0500140 acpi_cpu_flags flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141
Bob Mooreb229cf92006-04-21 17:15:00 -0400142 ACPI_FUNCTION_TRACE(ev_walk_gpe_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143
Len Brown4be44fc2005-08-05 00:44:28 -0400144 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145
146 /* Walk the interrupt level descriptor list */
147
148 gpe_xrupt_info = acpi_gbl_gpe_xrupt_list_head;
149 while (gpe_xrupt_info) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400150
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151 /* Walk all Gpe Blocks attached to this interrupt level */
152
153 gpe_block = gpe_xrupt_info->gpe_block_list_head;
154 while (gpe_block) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400155
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 /* One callback per GPE block */
157
Bob Mooree97d6bf2008-12-30 09:45:17 +0800158 status =
159 gpe_walk_callback(gpe_xrupt_info, gpe_block,
160 context);
Len Brown4be44fc2005-08-05 00:44:28 -0400161 if (ACPI_FAILURE(status)) {
Bob Mooree97d6bf2008-12-30 09:45:17 +0800162 if (status == AE_CTRL_END) { /* Callback abort */
163 status = AE_OK;
164 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165 goto unlock_and_exit;
166 }
167
168 gpe_block = gpe_block->next;
169 }
170
171 gpe_xrupt_info = gpe_xrupt_info->next;
172 }
173
Len Brown4be44fc2005-08-05 00:44:28 -0400174 unlock_and_exit:
175 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
176 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177}
178
Robert Moore44f6c012005-04-18 22:49:35 -0400179/*******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 *
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
Len Brown4be44fc2005-08-05 00:44:28 -0400194acpi_ev_delete_gpe_handlers(struct acpi_gpe_xrupt_info *gpe_xrupt_info,
Bob Mooree97d6bf2008-12-30 09:45:17 +0800195 struct acpi_gpe_block_info *gpe_block,
196 void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197{
Len Brown4be44fc2005-08-05 00:44:28 -0400198 struct acpi_gpe_event_info *gpe_event_info;
Bob Moore67a119f2008-06-10 13:42:13 +0800199 u32 i;
200 u32 j;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201
Bob Mooreb229cf92006-04-21 17:15:00 -0400202 ACPI_FUNCTION_TRACE(ev_delete_gpe_handlers);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203
204 /* Examine each GPE Register within the block */
205
206 for (i = 0; i < gpe_block->register_count; i++) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400207
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208 /* Now look at the individual GPEs in this byte register */
209
210 for (j = 0; j < ACPI_GPE_REGISTER_WIDTH; j++) {
Bob Moored4913dc2009-03-06 10:05:18 +0800211 gpe_event_info = &gpe_block->event_info[((acpi_size) i *
212 ACPI_GPE_REGISTER_WIDTH)
213 + j];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214
Robert Moore44f6c012005-04-18 22:49:35 -0400215 if ((gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) ==
Len Brown4be44fc2005-08-05 00:44:28 -0400216 ACPI_GPE_DISPATCH_HANDLER) {
Bob Moore83135242006-10-03 00:00:00 -0400217 ACPI_FREE(gpe_event_info->dispatch.handler);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218 gpe_event_info->dispatch.handler = NULL;
Len Brown4be44fc2005-08-05 00:44:28 -0400219 gpe_event_info->flags &=
220 ~ACPI_GPE_DISPATCH_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221 }
222 }
223 }
224
Len Brown4be44fc2005-08-05 00:44:28 -0400225 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226}
227
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228/*******************************************************************************
229 *
Lin Ming0f849d22010-04-06 14:52:37 +0800230 * FUNCTION: acpi_ev_match_gpe_method
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231 *
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:
Lin Ming0f849d22010-04-06 14:52:37 +0800242 * "_Lxx" or "_Exx", where:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243 * 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
Lin Ming0f849d22010-04-06 14:52:37 +0800250acpi_ev_match_gpe_method(acpi_handle obj_handle,
Len Brown4be44fc2005-08-05 00:44:28 -0400251 u32 level, void *obj_desc, void **return_value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252{
Lin Ming0f849d22010-04-06 14:52:37 +0800253 struct acpi_namespace_node *method_node =
254 ACPI_CAST_PTR(struct acpi_namespace_node, obj_handle);
Len Brown4be44fc2005-08-05 00:44:28 -0400255 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;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260
Bob Mooreb229cf92006-04-21 17:15:00 -0400261 ACPI_FUNCTION_TRACE(ev_save_method_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262
263 /*
Lin Ming0f849d22010-04-06 14:52:37 +0800264 * Match and decode the _Lxx and _Exx GPE method names
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265 *
Lin Ming0f849d22010-04-06 14:52:37 +0800266 * 1) Extract the method name and null terminate it
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 */
Lin Ming0f849d22010-04-06 14:52:37 +0800268 ACPI_MOVE_32_TO_32(name, &method_node->name.integer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269 name[ACPI_NAME_SIZE] = 0;
270
Lin Ming0f849d22010-04-06 14:52:37 +0800271 /* 2) Name must begin with an underscore */
272
273 if (name[0] != '_') {
274 return_ACPI_STATUS(AE_OK); /* Ignore this method */
275 }
276
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277 /*
Lin Ming0f849d22010-04-06 14:52:37 +0800278 * 3) Edge/Level determination is based on the 2nd character
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279 * of the method name
280 *
Lin Ming0f849d22010-04-06 14:52:37 +0800281 * 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.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283 */
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:
Lin Ming0f849d22010-04-06 14:52:37 +0800294 /* Unknown method type, just ignore it */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295
Bob Mooreb229cf92006-04-21 17:15:00 -0400296 ACPI_DEBUG_PRINT((ACPI_DB_LOAD,
Bob Moored4913dc2009-03-06 10:05:18 +0800297 "Ignoring unknown GPE method type: %s "
298 "(name not of form _Lxx or _Exx)", name));
Len Brown4be44fc2005-08-05 00:44:28 -0400299 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300 }
301
Lin Ming0f849d22010-04-06 14:52:37 +0800302 /* 4) The last two characters of the name are the hex GPE Number */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303
Len Brown4be44fc2005-08-05 00:44:28 -0400304 gpe_number = ACPI_STRTOUL(&name[2], NULL, 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305 if (gpe_number == ACPI_UINT32_MAX) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400306
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307 /* Conversion failed; invalid method, just ignore it */
308
Bob Mooreb229cf92006-04-21 17:15:00 -0400309 ACPI_DEBUG_PRINT((ACPI_DB_LOAD,
Bob Moored4913dc2009-03-06 10:05:18 +0800310 "Could not extract GPE number from name: %s "
311 "(name is not of form _Lxx or _Exx)", name));
Len Brown4be44fc2005-08-05 00:44:28 -0400312 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313 }
314
315 /* Ensure that we have a valid GPE number for this GPE block */
316
Lin Ming0f849d22010-04-06 14:52:37 +0800317 gpe_event_info = acpi_ev_low_get_gpe_info(gpe_number, gpe_block);
318 if (!gpe_event_info) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319 /*
Lin Ming0f849d22010-04-06 14:52:37 +0800320 * 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.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323 */
Len Brown4be44fc2005-08-05 00:44:28 -0400324 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325 }
326
327 /*
Lin Ming0f849d22010-04-06 14:52:37 +0800328 * Add the GPE information from above to the gpe_event_info block for
329 * use during dispatch of this GPE.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330 */
Lin Ming0f849d22010-04-06 14:52:37 +0800331 gpe_event_info->flags = (u8)(type | ACPI_GPE_DISPATCH_METHOD);
332 gpe_event_info->dispatch.method_node = method_node;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333
Len Brown4be44fc2005-08-05 00:44:28 -0400334 ACPI_DEBUG_PRINT((ACPI_DB_LOAD,
335 "Registered GPE method %s as GPE number 0x%.2X\n",
336 name, gpe_number));
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +0100337 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338}
339
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340/*******************************************************************************
341 *
342 * FUNCTION: acpi_ev_match_prw_and_gpe
343 *
344 * PARAMETERS: Callback from walk_namespace
345 *
Bob Moore96db2552005-11-02 00:00:00 -0500346 * RETURN: Status. NOTE: We ignore errors so that the _PRW walk is
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347 * not aborted on a single _PRW failure.
348 *
349 * DESCRIPTION: Called from acpi_walk_namespace. Expects each object to be a
Bob Moore96db2552005-11-02 00:00:00 -0500350 * Device. Run the _PRW method. If present, extract the GPE
Lin Ming0f849d22010-04-06 14:52:37 +0800351 * number and mark the GPE as a CAN_WAKE GPE.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352 *
353 ******************************************************************************/
354
355static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400356acpi_ev_match_prw_and_gpe(acpi_handle obj_handle,
357 u32 level, void *info, void **return_value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358{
Len Brown4be44fc2005-08-05 00:44:28 -0400359 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;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368
Bob Mooreb229cf92006-04-21 17:15:00 -0400369 ACPI_FUNCTION_TRACE(ev_match_prw_and_gpe);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370
371 /* Check for a _PRW method under this device */
372
Len Brown4be44fc2005-08-05 00:44:28 -0400373 status = acpi_ut_evaluate_object(obj_handle, METHOD_NAME__PRW,
374 ACPI_BTYPE_PACKAGE, &pkg_desc);
375 if (ACPI_FAILURE(status)) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400376
Lin Ming0f849d22010-04-06 14:52:37 +0800377 /* Ignore all errors from _PRW, we don't want to abort the walk */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378
Len Brown4be44fc2005-08-05 00:44:28 -0400379 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380 }
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 /*
Bob Moore9f15fc62008-11-12 16:01:56 +0800394 * The _PRW object must return a package, we are only interested in the
395 * first element
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396 */
397 obj_desc = pkg_desc->package.elements[0];
398
Bob Moore3371c192009-02-18 14:44:03 +0800399 if (obj_desc->common.type == ACPI_TYPE_INTEGER) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400400
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 /* 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;
Bob Moore3371c192009-02-18 14:44:03 +0800408 } else if (obj_desc->common.type == ACPI_TYPE_PACKAGE) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400409
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410 /* Package contains a GPE reference and GPE number within a GPE block */
411
412 if ((obj_desc->package.count < 2) ||
Bob Moore3371c192009-02-18 14:44:03 +0800413 ((obj_desc->package.elements[0])->common.type !=
Bob Moored4913dc2009-03-06 10:05:18 +0800414 ACPI_TYPE_LOCAL_REFERENCE) ||
415 ((obj_desc->package.elements[1])->common.type !=
416 ACPI_TYPE_INTEGER)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417 goto cleanup;
418 }
419
420 /* Get GPE block reference and decode */
421
Len Brown4be44fc2005-08-05 00:44:28 -0400422 target_gpe_device =
423 obj_desc->package.elements[0]->reference.node;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424 gpe_number = (u32) obj_desc->package.elements[1]->integer.value;
Len Brown4be44fc2005-08-05 00:44:28 -0400425 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426 /* Unknown type, just ignore it */
427
428 goto cleanup;
429 }
430
431 /*
432 * Is this GPE within this block?
433 *
Bob Moore9f15fc62008-11-12 16:01:56 +0800434 * TRUE if and only if these conditions are true:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435 * 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 */
Lin Ming0f849d22010-04-06 14:52:37 +0800439 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 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +0100447 gpe_event_info->flags |= ACPI_GPE_CAN_WAKE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448 }
449
Len Brown4be44fc2005-08-05 00:44:28 -0400450 cleanup:
451 acpi_ut_remove_reference(pkg_desc);
452 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453}
454
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455/*******************************************************************************
456 *
457 * FUNCTION: acpi_ev_get_gpe_xrupt_block
458 *
Robert Moore6f42ccf2005-05-13 00:00:00 -0400459 * PARAMETERS: interrupt_number - Interrupt for a GPE block
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460 *
461 * RETURN: A GPE interrupt block
462 *
Bob Moore96db2552005-11-02 00:00:00 -0500463 * DESCRIPTION: Get or Create a GPE interrupt block. There is one interrupt
Bob Moore9f15fc62008-11-12 16:01:56 +0800464 * 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.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467 *
468 ******************************************************************************/
469
Len Brown4be44fc2005-08-05 00:44:28 -0400470static struct acpi_gpe_xrupt_info *acpi_ev_get_gpe_xrupt_block(u32
471 interrupt_number)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472{
Len Brown4be44fc2005-08-05 00:44:28 -0400473 struct acpi_gpe_xrupt_info *next_gpe_xrupt;
474 struct acpi_gpe_xrupt_info *gpe_xrupt;
475 acpi_status status;
Bob Mooreb8e4d892006-01-27 16:43:00 -0500476 acpi_cpu_flags flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477
Bob Mooreb229cf92006-04-21 17:15:00 -0400478 ACPI_FUNCTION_TRACE(ev_get_gpe_xrupt_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479
Robert Moore44f6c012005-04-18 22:49:35 -0400480 /* No need for lock since we are not changing any list elements here */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481
482 next_gpe_xrupt = acpi_gbl_gpe_xrupt_list_head;
483 while (next_gpe_xrupt) {
Robert Moore6f42ccf2005-05-13 00:00:00 -0400484 if (next_gpe_xrupt->interrupt_number == interrupt_number) {
Len Brown4be44fc2005-08-05 00:44:28 -0400485 return_PTR(next_gpe_xrupt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486 }
487
488 next_gpe_xrupt = next_gpe_xrupt->next;
489 }
490
491 /* Not found, must allocate a new xrupt descriptor */
492
Bob Moore83135242006-10-03 00:00:00 -0400493 gpe_xrupt = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_gpe_xrupt_info));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494 if (!gpe_xrupt) {
Len Brown4be44fc2005-08-05 00:44:28 -0400495 return_PTR(NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 }
497
Robert Moore6f42ccf2005-05-13 00:00:00 -0400498 gpe_xrupt->interrupt_number = interrupt_number;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499
500 /* Install new interrupt descriptor with spin lock */
501
Len Brown4be44fc2005-08-05 00:44:28 -0400502 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503 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;
Len Brown4be44fc2005-08-05 00:44:28 -0400511 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512 acpi_gbl_gpe_xrupt_list_head = gpe_xrupt;
513 }
Len Brown4be44fc2005-08-05 00:44:28 -0400514 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515
516 /* Install new interrupt handler if not SCI_INT */
517
Bob Mooref3d2e782007-02-02 19:48:18 +0300518 if (interrupt_number != acpi_gbl_FADT.sci_interrupt) {
Len Brown4be44fc2005-08-05 00:44:28 -0400519 status = acpi_os_install_interrupt_handler(interrupt_number,
520 acpi_ev_gpe_xrupt_handler,
521 gpe_xrupt);
522 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500523 ACPI_ERROR((AE_INFO,
524 "Could not install GPE interrupt handler at level 0x%X",
525 interrupt_number));
Len Brown4be44fc2005-08-05 00:44:28 -0400526 return_PTR(NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527 }
528 }
529
Len Brown4be44fc2005-08-05 00:44:28 -0400530 return_PTR(gpe_xrupt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531}
532
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533/*******************************************************************************
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
Len Brown4be44fc2005-08-05 00:44:28 -0400547acpi_ev_delete_gpe_xrupt(struct acpi_gpe_xrupt_info *gpe_xrupt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548{
Len Brown4be44fc2005-08-05 00:44:28 -0400549 acpi_status status;
Bob Mooreb8e4d892006-01-27 16:43:00 -0500550 acpi_cpu_flags flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551
Bob Mooreb229cf92006-04-21 17:15:00 -0400552 ACPI_FUNCTION_TRACE(ev_delete_gpe_xrupt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553
554 /* We never want to remove the SCI interrupt handler */
555
Bob Mooref3d2e782007-02-02 19:48:18 +0300556 if (gpe_xrupt->interrupt_number == acpi_gbl_FADT.sci_interrupt) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 gpe_xrupt->gpe_block_list_head = NULL;
Len Brown4be44fc2005-08-05 00:44:28 -0400558 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559 }
560
561 /* Disable this interrupt */
562
Bob Moore96db2552005-11-02 00:00:00 -0500563 status =
564 acpi_os_remove_interrupt_handler(gpe_xrupt->interrupt_number,
565 acpi_ev_gpe_xrupt_handler);
Len Brown4be44fc2005-08-05 00:44:28 -0400566 if (ACPI_FAILURE(status)) {
567 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568 }
569
570 /* Unlink the interrupt block with lock */
571
Len Brown4be44fc2005-08-05 00:44:28 -0400572 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573 if (gpe_xrupt->previous) {
574 gpe_xrupt->previous->next = gpe_xrupt->next;
Bob Mooree0b910502007-04-03 20:00:29 -0400575 } else {
576 /* No previous, update list head */
577
578 acpi_gbl_gpe_xrupt_list_head = gpe_xrupt->next;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 }
580
581 if (gpe_xrupt->next) {
582 gpe_xrupt->next->previous = gpe_xrupt->previous;
583 }
Len Brown4be44fc2005-08-05 00:44:28 -0400584 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585
586 /* Free the block */
587
Bob Moore83135242006-10-03 00:00:00 -0400588 ACPI_FREE(gpe_xrupt);
Len Brown4be44fc2005-08-05 00:44:28 -0400589 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590}
591
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592/*******************************************************************************
593 *
594 * FUNCTION: acpi_ev_install_gpe_block
595 *
Bob Moore9f15fc62008-11-12 16:01:56 +0800596 * PARAMETERS: gpe_block - New GPE block
597 * interrupt_number - Xrupt to be associated with this
598 * GPE block
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 *
600 * RETURN: Status
601 *
602 * DESCRIPTION: Install new GPE block with mutex support
603 *
604 ******************************************************************************/
605
606static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400607acpi_ev_install_gpe_block(struct acpi_gpe_block_info *gpe_block,
608 u32 interrupt_number)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609{
Len Brown4be44fc2005-08-05 00:44:28 -0400610 struct acpi_gpe_block_info *next_gpe_block;
611 struct acpi_gpe_xrupt_info *gpe_xrupt_block;
612 acpi_status status;
Bob Mooreb8e4d892006-01-27 16:43:00 -0500613 acpi_cpu_flags flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614
Bob Mooreb229cf92006-04-21 17:15:00 -0400615 ACPI_FUNCTION_TRACE(ev_install_gpe_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616
Len Brown4be44fc2005-08-05 00:44:28 -0400617 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
618 if (ACPI_FAILURE(status)) {
619 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620 }
621
Len Brown4be44fc2005-08-05 00:44:28 -0400622 gpe_xrupt_block = acpi_ev_get_gpe_xrupt_block(interrupt_number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623 if (!gpe_xrupt_block) {
624 status = AE_NO_MEMORY;
625 goto unlock_and_exit;
626 }
627
Robert Moore44f6c012005-04-18 22:49:35 -0400628 /* Install the new block at the end of the list with lock */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629
Len Brown4be44fc2005-08-05 00:44:28 -0400630 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631 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;
Len Brown4be44fc2005-08-05 00:44:28 -0400639 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640 gpe_xrupt_block->gpe_block_list_head = gpe_block;
641 }
642
643 gpe_block->xrupt_block = gpe_xrupt_block;
Len Brown4be44fc2005-08-05 00:44:28 -0400644 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645
Len Brown4be44fc2005-08-05 00:44:28 -0400646 unlock_and_exit:
647 status = acpi_ut_release_mutex(ACPI_MTX_EVENTS);
648 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649}
650
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651/*******************************************************************************
652 *
653 * FUNCTION: acpi_ev_delete_gpe_block
654 *
Bob Moore9f15fc62008-11-12 16:01:56 +0800655 * PARAMETERS: gpe_block - Existing GPE block
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656 *
657 * RETURN: Status
658 *
659 * DESCRIPTION: Remove a GPE block
660 *
661 ******************************************************************************/
662
Len Brown4be44fc2005-08-05 00:44:28 -0400663acpi_status acpi_ev_delete_gpe_block(struct acpi_gpe_block_info *gpe_block)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664{
Len Brown4be44fc2005-08-05 00:44:28 -0400665 acpi_status status;
Bob Mooreb8e4d892006-01-27 16:43:00 -0500666 acpi_cpu_flags flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667
Bob Mooreb229cf92006-04-21 17:15:00 -0400668 ACPI_FUNCTION_TRACE(ev_install_gpe_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669
Len Brown4be44fc2005-08-05 00:44:28 -0400670 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
671 if (ACPI_FAILURE(status)) {
672 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673 }
674
675 /* Disable all GPEs in this block */
676
Bob Mooree97d6bf2008-12-30 09:45:17 +0800677 status =
678 acpi_hw_disable_gpe_block(gpe_block->xrupt_block, gpe_block, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679
680 if (!gpe_block->previous && !gpe_block->next) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400681
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682 /* This is the last gpe_block on this interrupt */
683
Len Brown4be44fc2005-08-05 00:44:28 -0400684 status = acpi_ev_delete_gpe_xrupt(gpe_block->xrupt_block);
685 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686 goto unlock_and_exit;
687 }
Len Brown4be44fc2005-08-05 00:44:28 -0400688 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689 /* Remove the block on this interrupt with lock */
690
Len Brown4be44fc2005-08-05 00:44:28 -0400691 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692 if (gpe_block->previous) {
693 gpe_block->previous->next = gpe_block->next;
Len Brown4be44fc2005-08-05 00:44:28 -0400694 } else {
695 gpe_block->xrupt_block->gpe_block_list_head =
696 gpe_block->next;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697 }
698
699 if (gpe_block->next) {
700 gpe_block->next->previous = gpe_block->previous;
701 }
Len Brown4be44fc2005-08-05 00:44:28 -0400702 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703 }
704
Lin Ming0f849d22010-04-06 14:52:37 +0800705 acpi_current_gpe_count -= gpe_block->gpe_count;
Bob Mooree97d6bf2008-12-30 09:45:17 +0800706
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707 /* Free the gpe_block */
708
Bob Moore83135242006-10-03 00:00:00 -0400709 ACPI_FREE(gpe_block->register_info);
710 ACPI_FREE(gpe_block->event_info);
711 ACPI_FREE(gpe_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712
Len Brown4be44fc2005-08-05 00:44:28 -0400713 unlock_and_exit:
714 status = acpi_ut_release_mutex(ACPI_MTX_EVENTS);
715 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716}
717
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718/*******************************************************************************
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
Len Brown4be44fc2005-08-05 00:44:28 -0400731acpi_ev_create_gpe_info_blocks(struct acpi_gpe_block_info *gpe_block)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732{
Len Brown4be44fc2005-08-05 00:44:28 -0400733 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;
Bob Moore67a119f2008-06-10 13:42:13 +0800737 u32 i;
738 u32 j;
Len Brown4be44fc2005-08-05 00:44:28 -0400739 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740
Bob Mooreb229cf92006-04-21 17:15:00 -0400741 ACPI_FUNCTION_TRACE(ev_create_gpe_info_blocks);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742
743 /* Allocate the GPE register information block */
744
Bob Moore83135242006-10-03 00:00:00 -0400745 gpe_register_info = ACPI_ALLOCATE_ZEROED((acpi_size) gpe_block->
746 register_count *
747 sizeof(struct
748 acpi_gpe_register_info));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749 if (!gpe_register_info) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500750 ACPI_ERROR((AE_INFO,
Bob Mooreb229cf92006-04-21 17:15:00 -0400751 "Could not allocate the GpeRegisterInfo table"));
Len Brown4be44fc2005-08-05 00:44:28 -0400752 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753 }
754
755 /*
756 * Allocate the GPE event_info block. There are eight distinct GPEs
Bob Moore96db2552005-11-02 00:00:00 -0500757 * per register. Initialization to zeros is sufficient.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758 */
Lin Ming0f849d22010-04-06 14:52:37 +0800759 gpe_event_info = ACPI_ALLOCATE_ZEROED((acpi_size) gpe_block->gpe_count *
Bob Moore83135242006-10-03 00:00:00 -0400760 sizeof(struct
761 acpi_gpe_event_info));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762 if (!gpe_event_info) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500763 ACPI_ERROR((AE_INFO,
Bob Mooreb229cf92006-04-21 17:15:00 -0400764 "Could not allocate the GpeEventInfo table"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765 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;
Len Brown4be44fc2005-08-05 00:44:28 -0400772 gpe_block->event_info = gpe_event_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773
774 /*
Bob Moore96db2552005-11-02 00:00:00 -0500775 * Initialize the GPE Register and Event structures. A goal of these
Bob Moore9f15fc62008-11-12 16:01:56 +0800776 * 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.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779 */
780 this_register = gpe_register_info;
Len Brown4be44fc2005-08-05 00:44:28 -0400781 this_event = gpe_event_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782
783 for (i = 0; i < gpe_block->register_count; i++) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400784
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785 /* Init the register_info for this GPE register (8 GPEs) */
786
Len Brown4be44fc2005-08-05 00:44:28 -0400787 this_register->base_gpe_number =
788 (u8) (gpe_block->block_base_number +
789 (i * ACPI_GPE_REGISTER_WIDTH));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790
Bob Moore59fa8502007-02-02 19:48:23 +0300791 this_register->status_address.address =
792 gpe_block->block_address.address + i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793
Bob Moore59fa8502007-02-02 19:48:23 +0300794 this_register->enable_address.address =
795 gpe_block->block_address.address + i +
796 gpe_block->register_count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797
Bob Mooref3d2e782007-02-02 19:48:18 +0300798 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 =
Len Brown4be44fc2005-08-05 00:44:28 -0400803 ACPI_GPE_REGISTER_WIDTH;
Bob Mooref3d2e782007-02-02 19:48:18 +0300804 this_register->enable_address.bit_width =
Len Brown4be44fc2005-08-05 00:44:28 -0400805 ACPI_GPE_REGISTER_WIDTH;
Bob Mooreecfbbc72008-12-31 02:55:32 +0800806 this_register->status_address.bit_offset = 0;
807 this_register->enable_address.bit_offset = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808
809 /* Init the event_info for each GPE within this register */
810
811 for (j = 0; j < ACPI_GPE_REGISTER_WIDTH; j++) {
Alexey Starikovskiy69874162007-02-02 19:48:19 +0300812 this_event->gpe_number =
813 (u8) (this_register->base_gpe_number + j);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814 this_event->register_info = this_register;
815 this_event++;
816 }
817
Bob Moore96db2552005-11-02 00:00:00 -0500818 /* Disable all GPEs within this register */
819
Bob Moorec6b57742009-06-24 09:44:06 +0800820 status = acpi_hw_write(0x00, &this_register->enable_address);
Len Brown4be44fc2005-08-05 00:44:28 -0400821 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822 goto error_exit;
823 }
824
Bob Moore96db2552005-11-02 00:00:00 -0500825 /* Clear any pending GPE events within this register */
826
Bob Moorec6b57742009-06-24 09:44:06 +0800827 status = acpi_hw_write(0xFF, &this_register->status_address);
Len Brown4be44fc2005-08-05 00:44:28 -0400828 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829 goto error_exit;
830 }
831
832 this_register++;
833 }
834
Len Brown4be44fc2005-08-05 00:44:28 -0400835 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836
Len Brown4be44fc2005-08-05 00:44:28 -0400837 error_exit:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838 if (gpe_register_info) {
Bob Moore83135242006-10-03 00:00:00 -0400839 ACPI_FREE(gpe_register_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700840 }
841 if (gpe_event_info) {
Bob Moore83135242006-10-03 00:00:00 -0400842 ACPI_FREE(gpe_event_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843 }
844
Len Brown4be44fc2005-08-05 00:44:28 -0400845 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846}
847
Linus Torvalds1da177e2005-04-16 15:20:36 -0700848/*******************************************************************************
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
Robert Moore6f42ccf2005-05-13 00:00:00 -0400856 * interrupt_number - H/W interrupt for the block
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857 * return_gpe_block - Where the new block descriptor is returned
858 *
859 * RETURN: Status
860 *
Bob Moore96db2552005-11-02 00:00:00 -0500861 * 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.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864 *
865 ******************************************************************************/
866
867acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400868acpi_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)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874{
Len Brown4be44fc2005-08-05 00:44:28 -0400875 acpi_status status;
Bob Moore96db2552005-11-02 00:00:00 -0500876 struct acpi_gpe_block_info *gpe_block;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877
Bob Mooreb229cf92006-04-21 17:15:00 -0400878 ACPI_FUNCTION_TRACE(ev_create_gpe_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879
880 if (!register_count) {
Len Brown4be44fc2005-08-05 00:44:28 -0400881 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882 }
883
884 /* Allocate a new GPE block */
885
Bob Moore83135242006-10-03 00:00:00 -0400886 gpe_block = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_gpe_block_info));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700887 if (!gpe_block) {
Len Brown4be44fc2005-08-05 00:44:28 -0400888 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889 }
890
891 /* Initialize the new GPE block */
892
Bob Moore96db2552005-11-02 00:00:00 -0500893 gpe_block->node = gpe_device;
Lin Ming0f849d22010-04-06 14:52:37 +0800894 gpe_block->gpe_count = (u16)(register_count * ACPI_GPE_REGISTER_WIDTH);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700895 gpe_block->register_count = register_count;
896 gpe_block->block_base_number = gpe_block_base_number;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700897
Len Brown4be44fc2005-08-05 00:44:28 -0400898 ACPI_MEMCPY(&gpe_block->block_address, gpe_block_address,
899 sizeof(struct acpi_generic_address));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700900
Bob Moore96db2552005-11-02 00:00:00 -0500901 /*
902 * Create the register_info and event_info sub-structures
903 * Note: disables and clears all GPEs in the block
904 */
Len Brown4be44fc2005-08-05 00:44:28 -0400905 status = acpi_ev_create_gpe_info_blocks(gpe_block);
906 if (ACPI_FAILURE(status)) {
Bob Moore83135242006-10-03 00:00:00 -0400907 ACPI_FREE(gpe_block);
Len Brown4be44fc2005-08-05 00:44:28 -0400908 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700909 }
910
Bob Moore96db2552005-11-02 00:00:00 -0500911 /* Install the new block in the global lists */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700912
Len Brown4be44fc2005-08-05 00:44:28 -0400913 status = acpi_ev_install_gpe_block(gpe_block, interrupt_number);
914 if (ACPI_FAILURE(status)) {
Bob Moore83135242006-10-03 00:00:00 -0400915 ACPI_FREE(gpe_block);
Len Brown4be44fc2005-08-05 00:44:28 -0400916 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917 }
918
919 /* Find all GPE methods (_Lxx, _Exx) for this block */
920
Len Brown4be44fc2005-08-05 00:44:28 -0400921 status = acpi_ns_walk_namespace(ACPI_TYPE_METHOD, gpe_device,
922 ACPI_UINT32_MAX, ACPI_NS_WALK_NO_UNLOCK,
Lin Ming0f849d22010-04-06 14:52:37 +0800923 acpi_ev_match_gpe_method, NULL,
Lin Ming22635762009-11-13 10:06:08 +0800924 gpe_block, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925
Bob Moore96db2552005-11-02 00:00:00 -0500926 /* 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 +
Lin Ming0f849d22010-04-06 14:52:37 +0800936 (gpe_block->gpe_count - 1)),
Bob Moore96db2552005-11-02 00:00:00 -0500937 gpe_device->name.ascii, gpe_block->register_count,
938 interrupt_number));
939
Bob Mooree97d6bf2008-12-30 09:45:17 +0800940 /* Update global count of currently available GPEs */
941
Lin Ming0f849d22010-04-06 14:52:37 +0800942 acpi_current_gpe_count += gpe_block->gpe_count;
Bob Moore96db2552005-11-02 00:00:00 -0500943 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{
Lin Ming0f849d22010-04-06 14:52:37 +0800966 acpi_status status;
Bob Moore96db2552005-11-02 00:00:00 -0500967 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;
Lin Ming0f849d22010-04-06 14:52:37 +0800971 u32 gpe_index;
972 u32 gpe_number;
Bob Moore67a119f2008-06-10 13:42:13 +0800973 u32 i;
974 u32 j;
Bob Moore96db2552005-11-02 00:00:00 -0500975
Bob Mooreb229cf92006-04-21 17:15:00 -0400976 ACPI_FUNCTION_TRACE(ev_initialize_gpe_block);
Bob Moore96db2552005-11-02 00:00:00 -0500977
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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700984 /*
Bob Moore96db2552005-11-02 00:00:00 -0500985 * 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.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700987 */
988 if (acpi_gbl_leave_wake_gpes_disabled) {
989 /*
Bob Moore96db2552005-11-02 00:00:00 -0500990 * 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.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994 */
995 gpe_info.gpe_block = gpe_block;
996 gpe_info.gpe_device = gpe_device;
997
Lin Ming0f849d22010-04-06 14:52:37 +0800998 status = acpi_ns_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,
Len Brown4be44fc2005-08-05 00:44:28 -0400999 ACPI_UINT32_MAX, ACPI_NS_WALK_UNLOCK,
Lin Ming22635762009-11-13 10:06:08 +08001000 acpi_ev_match_prw_and_gpe, NULL,
1001 &gpe_info, NULL);
Lin Ming0f849d22010-04-06 14:52:37 +08001002 if (ACPI_FAILURE(status)) {
1003 ACPI_EXCEPTION((AE_INFO, status,
1004 "While executing _PRW methods"));
1005 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001006 }
1007
1008 /*
Lin Ming0f849d22010-04-06 14:52:37 +08001009 * Enable all GPEs that have a corresponding method and are not
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +01001010 * capable of generating wakeups. Any other GPEs within this block
Lin Ming0f849d22010-04-06 14:52:37 +08001011 * must be enabled via the acpi_enable_gpe interface.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001012 */
1013 wake_gpe_count = 0;
1014 gpe_enabled_count = 0;
Lin Ming0f849d22010-04-06 14:52:37 +08001015
1016 if (gpe_device == acpi_gbl_fadt_gpe_device) {
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +01001017 gpe_device = NULL;
Lin Ming0f849d22010-04-06 14:52:37 +08001018 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001019
1020 for (i = 0; i < gpe_block->register_count; i++) {
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +01001021 for (j = 0; j < ACPI_GPE_REGISTER_WIDTH; j++) {
Bob Moore52fc0b02006-10-02 00:00:00 -04001022
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023 /* Get the info block for this particular GPE */
Lin Ming0f849d22010-04-06 14:52:37 +08001024
1025 gpe_index = (i * ACPI_GPE_REGISTER_WIDTH) + j;
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +01001026 gpe_event_info = &gpe_block->event_info[gpe_index];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +01001028 if (gpe_event_info->flags & ACPI_GPE_CAN_WAKE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001029 wake_gpe_count++;
Lin Ming0f849d22010-04-06 14:52:37 +08001030 if (acpi_gbl_leave_wake_gpes_disabled) {
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +01001031 continue;
Lin Ming0f849d22010-04-06 14:52:37 +08001032 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001033 }
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +01001034
Lin Ming0f849d22010-04-06 14:52:37 +08001035 /* Ignore GPEs that have no corresponding _Lxx/_Exx method */
1036
1037 if (!(gpe_event_info->flags & ACPI_GPE_DISPATCH_METHOD)) {
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +01001038 continue;
Lin Ming0f849d22010-04-06 14:52:37 +08001039 }
1040
1041 /* Enable this GPE */
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +01001042
1043 gpe_number = gpe_index + gpe_block->block_base_number;
1044 status = acpi_enable_gpe(gpe_device, gpe_number,
Lin Ming0f849d22010-04-06 14:52:37 +08001045 ACPI_GPE_TYPE_RUNTIME);
1046 if (ACPI_FAILURE(status)) {
1047 ACPI_EXCEPTION((AE_INFO, status,
1048 "Could not enable GPE 0x%02X",
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +01001049 gpe_number));
Lin Ming0f849d22010-04-06 14:52:37 +08001050 continue;
1051 }
1052
1053 gpe_enabled_count++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001054 }
1055 }
1056
Len Brown4be44fc2005-08-05 00:44:28 -04001057 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));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001060
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +01001061 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001062}
1063
Linus Torvalds1da177e2005-04-16 15:20:36 -07001064/*******************************************************************************
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
Len Brown4be44fc2005-08-05 00:44:28 -04001076acpi_status acpi_ev_gpe_initialize(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001077{
Len Brown4be44fc2005-08-05 00:44:28 -04001078 u32 register_count0 = 0;
1079 u32 register_count1 = 0;
1080 u32 gpe_number_max = 0;
1081 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001082
Bob Mooreb229cf92006-04-21 17:15:00 -04001083 ACPI_FUNCTION_TRACE(ev_gpe_initialize);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001084
Len Brown4be44fc2005-08-05 00:44:28 -04001085 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
1086 if (ACPI_FAILURE(status)) {
1087 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001088 }
1089
1090 /*
1091 * Initialize the GPE Block(s) defined in the FADT
1092 *
Bob Moored4913dc2009-03-06 10:05:18 +08001093 * Why the GPE register block lengths are divided by 2: From the ACPI
1094 * Spec, section "General-Purpose Event Registers", we have:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001095 *
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 */
Bob Mooref3d2e782007-02-02 19:48:18 +03001115 if (acpi_gbl_FADT.gpe0_block_length &&
1116 acpi_gbl_FADT.xgpe0_block.address) {
Bob Moore52fc0b02006-10-02 00:00:00 -04001117
Linus Torvalds1da177e2005-04-16 15:20:36 -07001118 /* GPE block 0 exists (has both length and address > 0) */
1119
Bob Mooref3d2e782007-02-02 19:48:18 +03001120 register_count0 = (u16) (acpi_gbl_FADT.gpe0_block_length / 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001121
Len Brown4be44fc2005-08-05 00:44:28 -04001122 gpe_number_max =
1123 (register_count0 * ACPI_GPE_REGISTER_WIDTH) - 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001124
1125 /* Install GPE Block 0 */
1126
Len Brown4be44fc2005-08-05 00:44:28 -04001127 status = acpi_ev_create_gpe_block(acpi_gbl_fadt_gpe_device,
Bob Mooref3d2e782007-02-02 19:48:18 +03001128 &acpi_gbl_FADT.xgpe0_block,
Len Brown4be44fc2005-08-05 00:44:28 -04001129 register_count0, 0,
Bob Mooref3d2e782007-02-02 19:48:18 +03001130 acpi_gbl_FADT.sci_interrupt,
Len Brown4be44fc2005-08-05 00:44:28 -04001131 &acpi_gbl_gpe_fadt_blocks[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001132
Len Brown4be44fc2005-08-05 00:44:28 -04001133 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -05001134 ACPI_EXCEPTION((AE_INFO, status,
1135 "Could not create GPE Block 0"));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001136 }
1137 }
1138
Bob Mooref3d2e782007-02-02 19:48:18 +03001139 if (acpi_gbl_FADT.gpe1_block_length &&
1140 acpi_gbl_FADT.xgpe1_block.address) {
Bob Moore52fc0b02006-10-02 00:00:00 -04001141
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142 /* GPE block 1 exists (has both length and address > 0) */
1143
Bob Mooref3d2e782007-02-02 19:48:18 +03001144 register_count1 = (u16) (acpi_gbl_FADT.gpe1_block_length / 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145
1146 /* Check for GPE0/GPE1 overlap (if both banks exist) */
1147
1148 if ((register_count0) &&
Bob Mooref3d2e782007-02-02 19:48:18 +03001149 (gpe_number_max >= acpi_gbl_FADT.gpe1_base)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -05001150 ACPI_ERROR((AE_INFO,
Bob Mooref6a22b02010-03-05 17:56:40 +08001151 "GPE0 block (GPE 0 to %u) overlaps the GPE1 block "
1152 "(GPE %u to %u) - Ignoring GPE1",
Bob Mooref3d2e782007-02-02 19:48:18 +03001153 gpe_number_max, acpi_gbl_FADT.gpe1_base,
1154 acpi_gbl_FADT.gpe1_base +
Bob Mooreb8e4d892006-01-27 16:43:00 -05001155 ((register_count1 *
1156 ACPI_GPE_REGISTER_WIDTH) - 1)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001157
1158 /* Ignore GPE1 block by setting the register count to zero */
1159
1160 register_count1 = 0;
Len Brown4be44fc2005-08-05 00:44:28 -04001161 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001162 /* Install GPE Block 1 */
1163
Len Brown4be44fc2005-08-05 00:44:28 -04001164 status =
1165 acpi_ev_create_gpe_block(acpi_gbl_fadt_gpe_device,
Bob Mooref3d2e782007-02-02 19:48:18 +03001166 &acpi_gbl_FADT.xgpe1_block,
Len Brown4be44fc2005-08-05 00:44:28 -04001167 register_count1,
Bob Mooref3d2e782007-02-02 19:48:18 +03001168 acpi_gbl_FADT.gpe1_base,
1169 acpi_gbl_FADT.
1170 sci_interrupt,
Len Brown4be44fc2005-08-05 00:44:28 -04001171 &acpi_gbl_gpe_fadt_blocks
1172 [1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001173
Len Brown4be44fc2005-08-05 00:44:28 -04001174 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -05001175 ACPI_EXCEPTION((AE_INFO, status,
1176 "Could not create GPE Block 1"));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001177 }
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 */
Bob Mooref3d2e782007-02-02 19:48:18 +03001183 gpe_number_max = acpi_gbl_FADT.gpe1_base +
Len Brown4be44fc2005-08-05 00:44:28 -04001184 ((register_count1 * ACPI_GPE_REGISTER_WIDTH) - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001185 }
1186 }
1187
1188 /* Exit if there are no GPE registers */
1189
1190 if ((register_count0 + register_count1) == 0) {
Bob Moore52fc0b02006-10-02 00:00:00 -04001191
Linus Torvalds1da177e2005-04-16 15:20:36 -07001192 /* GPEs are not required by ACPI, this is OK */
1193
Len Brown4be44fc2005-08-05 00:44:28 -04001194 ACPI_DEBUG_PRINT((ACPI_DB_INIT,
1195 "There are no GPE blocks defined in the FADT\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001196 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) {
Bob Mooreb8e4d892006-01-27 16:43:00 -05001203 ACPI_ERROR((AE_INFO,
1204 "Maximum GPE number from FADT is too large: 0x%X",
1205 gpe_number_max));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001206 status = AE_BAD_VALUE;
1207 goto cleanup;
1208 }
1209
Len Brown4be44fc2005-08-05 00:44:28 -04001210 cleanup:
1211 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
1212 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001213}