blob: 3341d1dfe78a8fc5ad1bb9a2832008506c20e54b [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"
Bob Moore186c3072010-04-27 11:32:28 +080048#include "acinterp.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
50#define _COMPONENT ACPI_EVENTS
Len Brown4be44fc2005-08-05 00:44:28 -040051ACPI_MODULE_NAME("evgpeblk")
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
Robert Moore44f6c012005-04-18 22:49:35 -040053/* Local prototypes */
Len Brown4be44fc2005-08-05 00:44:28 -040054static acpi_status
Lin Ming0f849d22010-04-06 14:52:37 +080055acpi_ev_match_gpe_method(acpi_handle obj_handle,
Len Brown4be44fc2005-08-05 00:44:28 -040056 u32 level, void *obj_desc, void **return_value);
Robert Moore44f6c012005-04-18 22:49:35 -040057
58static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -040059acpi_ev_match_prw_and_gpe(acpi_handle obj_handle,
60 u32 level, void *info, void **return_value);
61
62static struct acpi_gpe_xrupt_info *acpi_ev_get_gpe_xrupt_block(u32
63 interrupt_number);
Robert Moore44f6c012005-04-18 22:49:35 -040064
65static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -040066acpi_ev_delete_gpe_xrupt(struct acpi_gpe_xrupt_info *gpe_xrupt);
Robert Moore44f6c012005-04-18 22:49:35 -040067
68static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -040069acpi_ev_install_gpe_block(struct acpi_gpe_block_info *gpe_block,
70 u32 interrupt_number);
Robert Moore44f6c012005-04-18 22:49:35 -040071
72static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -040073acpi_ev_create_gpe_info_blocks(struct acpi_gpe_block_info *gpe_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -070074
75/*******************************************************************************
76 *
77 * FUNCTION: acpi_ev_valid_gpe_event
78 *
79 * PARAMETERS: gpe_event_info - Info for this GPE
80 *
81 * RETURN: TRUE if the gpe_event is valid
82 *
Bob Moore96db2552005-11-02 00:00:00 -050083 * DESCRIPTION: Validate a GPE event. DO NOT CALL FROM INTERRUPT LEVEL.
Linus Torvalds1da177e2005-04-16 15:20:36 -070084 * Should be called only when the GPE lists are semaphore locked
85 * and not subject to change.
86 *
87 ******************************************************************************/
88
Len Brown4be44fc2005-08-05 00:44:28 -040089u8 acpi_ev_valid_gpe_event(struct acpi_gpe_event_info *gpe_event_info)
Linus Torvalds1da177e2005-04-16 15:20:36 -070090{
Len Brown4be44fc2005-08-05 00:44:28 -040091 struct acpi_gpe_xrupt_info *gpe_xrupt_block;
92 struct acpi_gpe_block_info *gpe_block;
Linus Torvalds1da177e2005-04-16 15:20:36 -070093
Len Brown4be44fc2005-08-05 00:44:28 -040094 ACPI_FUNCTION_ENTRY();
Linus Torvalds1da177e2005-04-16 15:20:36 -070095
96 /* No need for spin lock since we are not changing any list elements */
97
98 /* Walk the GPE interrupt levels */
99
100 gpe_xrupt_block = acpi_gbl_gpe_xrupt_list_head;
101 while (gpe_xrupt_block) {
102 gpe_block = gpe_xrupt_block->gpe_block_list_head;
103
104 /* Walk the GPE blocks on this interrupt level */
105
106 while (gpe_block) {
107 if ((&gpe_block->event_info[0] <= gpe_event_info) &&
Lin Ming0f849d22010-04-06 14:52:37 +0800108 (&gpe_block->event_info[gpe_block->gpe_count] >
Len Brown4be44fc2005-08-05 00:44:28 -0400109 gpe_event_info)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110 return (TRUE);
111 }
112
113 gpe_block = gpe_block->next;
114 }
115
116 gpe_xrupt_block = gpe_xrupt_block->next;
117 }
118
119 return (FALSE);
120}
121
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122/*******************************************************************************
123 *
124 * FUNCTION: acpi_ev_walk_gpe_list
125 *
126 * PARAMETERS: gpe_walk_callback - Routine called for each GPE block
Bob Mooree97d6bf2008-12-30 09:45:17 +0800127 * Context - Value passed to callback
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 *
129 * RETURN: Status
130 *
131 * DESCRIPTION: Walk the GPE lists.
132 *
133 ******************************************************************************/
134
Bob Mooree97d6bf2008-12-30 09:45:17 +0800135acpi_status
136acpi_ev_walk_gpe_list(acpi_gpe_callback gpe_walk_callback, void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137{
Len Brown4be44fc2005-08-05 00:44:28 -0400138 struct acpi_gpe_block_info *gpe_block;
139 struct acpi_gpe_xrupt_info *gpe_xrupt_info;
140 acpi_status status = AE_OK;
Bob Mooreb8e4d892006-01-27 16:43:00 -0500141 acpi_cpu_flags flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142
Bob Mooreb229cf92006-04-21 17:15:00 -0400143 ACPI_FUNCTION_TRACE(ev_walk_gpe_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144
Len Brown4be44fc2005-08-05 00:44:28 -0400145 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146
147 /* Walk the interrupt level descriptor list */
148
149 gpe_xrupt_info = acpi_gbl_gpe_xrupt_list_head;
150 while (gpe_xrupt_info) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400151
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152 /* Walk all Gpe Blocks attached to this interrupt level */
153
154 gpe_block = gpe_xrupt_info->gpe_block_list_head;
155 while (gpe_block) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400156
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157 /* One callback per GPE block */
158
Bob Mooree97d6bf2008-12-30 09:45:17 +0800159 status =
160 gpe_walk_callback(gpe_xrupt_info, gpe_block,
161 context);
Len Brown4be44fc2005-08-05 00:44:28 -0400162 if (ACPI_FAILURE(status)) {
Bob Mooree97d6bf2008-12-30 09:45:17 +0800163 if (status == AE_CTRL_END) { /* Callback abort */
164 status = AE_OK;
165 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166 goto unlock_and_exit;
167 }
168
169 gpe_block = gpe_block->next;
170 }
171
172 gpe_xrupt_info = gpe_xrupt_info->next;
173 }
174
Len Brown4be44fc2005-08-05 00:44:28 -0400175 unlock_and_exit:
176 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
177 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178}
179
Robert Moore44f6c012005-04-18 22:49:35 -0400180/*******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181 *
182 * FUNCTION: acpi_ev_delete_gpe_handlers
183 *
184 * PARAMETERS: gpe_xrupt_info - GPE Interrupt info
185 * gpe_block - Gpe Block info
186 *
187 * RETURN: Status
188 *
189 * DESCRIPTION: Delete all Handler objects found in the GPE data structs.
190 * Used only prior to termination.
191 *
192 ******************************************************************************/
193
194acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400195acpi_ev_delete_gpe_handlers(struct acpi_gpe_xrupt_info *gpe_xrupt_info,
Bob Mooree97d6bf2008-12-30 09:45:17 +0800196 struct acpi_gpe_block_info *gpe_block,
197 void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198{
Len Brown4be44fc2005-08-05 00:44:28 -0400199 struct acpi_gpe_event_info *gpe_event_info;
Bob Moore67a119f2008-06-10 13:42:13 +0800200 u32 i;
201 u32 j;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202
Bob Mooreb229cf92006-04-21 17:15:00 -0400203 ACPI_FUNCTION_TRACE(ev_delete_gpe_handlers);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204
205 /* Examine each GPE Register within the block */
206
207 for (i = 0; i < gpe_block->register_count; i++) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400208
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209 /* Now look at the individual GPEs in this byte register */
210
211 for (j = 0; j < ACPI_GPE_REGISTER_WIDTH; j++) {
Bob Moored4913dc2009-03-06 10:05:18 +0800212 gpe_event_info = &gpe_block->event_info[((acpi_size) i *
213 ACPI_GPE_REGISTER_WIDTH)
214 + j];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215
Robert Moore44f6c012005-04-18 22:49:35 -0400216 if ((gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) ==
Len Brown4be44fc2005-08-05 00:44:28 -0400217 ACPI_GPE_DISPATCH_HANDLER) {
Bob Moore83135242006-10-03 00:00:00 -0400218 ACPI_FREE(gpe_event_info->dispatch.handler);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219 gpe_event_info->dispatch.handler = NULL;
Len Brown4be44fc2005-08-05 00:44:28 -0400220 gpe_event_info->flags &=
221 ~ACPI_GPE_DISPATCH_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222 }
223 }
224 }
225
Len Brown4be44fc2005-08-05 00:44:28 -0400226 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227}
228
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229/*******************************************************************************
230 *
Lin Ming0f849d22010-04-06 14:52:37 +0800231 * FUNCTION: acpi_ev_match_gpe_method
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232 *
233 * PARAMETERS: Callback from walk_namespace
234 *
235 * RETURN: Status
236 *
237 * DESCRIPTION: Called from acpi_walk_namespace. Expects each object to be a
238 * control method under the _GPE portion of the namespace.
239 * Extract the name and GPE type from the object, saving this
Bob Moore186c3072010-04-27 11:32:28 +0800240 * information for quick lookup during GPE dispatch. Allows a
241 * per-owner_id evaluation if execute_by_owner_id is TRUE in the
242 * walk_info parameter block.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243 *
244 * The name of each GPE control method is of the form:
Lin Ming0f849d22010-04-06 14:52:37 +0800245 * "_Lxx" or "_Exx", where:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246 * L - means that the GPE is level triggered
247 * E - means that the GPE is edge triggered
248 * xx - is the GPE number [in HEX]
249 *
Bob Moore186c3072010-04-27 11:32:28 +0800250 * If walk_info->execute_by_owner_id is TRUE, we only execute examine GPE methods
251 * with that owner.
252 * If walk_info->enable_this_gpe is TRUE, the GPE that is referred to by a GPE
253 * method is immediately enabled (Used for Load/load_table operators)
254 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255 ******************************************************************************/
256
257static acpi_status
Lin Ming0f849d22010-04-06 14:52:37 +0800258acpi_ev_match_gpe_method(acpi_handle obj_handle,
Bob Moore186c3072010-04-27 11:32:28 +0800259 u32 level, void *context, void **return_value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260{
Lin Ming0f849d22010-04-06 14:52:37 +0800261 struct acpi_namespace_node *method_node =
262 ACPI_CAST_PTR(struct acpi_namespace_node, obj_handle);
Bob Moore186c3072010-04-27 11:32:28 +0800263 struct acpi_gpe_walk_info *walk_info =
264 ACPI_CAST_PTR(struct acpi_gpe_walk_info, context);
Len Brown4be44fc2005-08-05 00:44:28 -0400265 struct acpi_gpe_event_info *gpe_event_info;
Bob Moore186c3072010-04-27 11:32:28 +0800266 struct acpi_namespace_node *gpe_device;
267 acpi_status status;
Len Brown4be44fc2005-08-05 00:44:28 -0400268 u32 gpe_number;
269 char name[ACPI_NAME_SIZE + 1];
270 u8 type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271
Bob Moore186c3072010-04-27 11:32:28 +0800272 ACPI_FUNCTION_TRACE(ev_match_gpe_method);
273
274 /* Check if requested owner_id matches this owner_id */
275
276 if ((walk_info->execute_by_owner_id) &&
277 (method_node->owner_id != walk_info->owner_id)) {
278 return_ACPI_STATUS(AE_OK);
279 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280
281 /*
Lin Ming0f849d22010-04-06 14:52:37 +0800282 * Match and decode the _Lxx and _Exx GPE method names
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283 *
Lin Ming0f849d22010-04-06 14:52:37 +0800284 * 1) Extract the method name and null terminate it
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285 */
Lin Ming0f849d22010-04-06 14:52:37 +0800286 ACPI_MOVE_32_TO_32(name, &method_node->name.integer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287 name[ACPI_NAME_SIZE] = 0;
288
Lin Ming0f849d22010-04-06 14:52:37 +0800289 /* 2) Name must begin with an underscore */
290
291 if (name[0] != '_') {
292 return_ACPI_STATUS(AE_OK); /* Ignore this method */
293 }
294
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 /*
Lin Ming0f849d22010-04-06 14:52:37 +0800296 * 3) Edge/Level determination is based on the 2nd character
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297 * of the method name
298 *
Lin Ming0f849d22010-04-06 14:52:37 +0800299 * NOTE: Default GPE type is RUNTIME only. Later, if a _PRW object is
300 * found that points to this GPE, the ACPI_GPE_CAN_WAKE flag is set.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301 */
302 switch (name[1]) {
303 case 'L':
304 type = ACPI_GPE_LEVEL_TRIGGERED;
305 break;
306
307 case 'E':
308 type = ACPI_GPE_EDGE_TRIGGERED;
309 break;
310
311 default:
Lin Ming0f849d22010-04-06 14:52:37 +0800312 /* Unknown method type, just ignore it */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313
Bob Mooreb229cf92006-04-21 17:15:00 -0400314 ACPI_DEBUG_PRINT((ACPI_DB_LOAD,
Bob Moored4913dc2009-03-06 10:05:18 +0800315 "Ignoring unknown GPE method type: %s "
316 "(name not of form _Lxx or _Exx)", name));
Len Brown4be44fc2005-08-05 00:44:28 -0400317 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318 }
319
Lin Ming0f849d22010-04-06 14:52:37 +0800320 /* 4) The last two characters of the name are the hex GPE Number */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321
Len Brown4be44fc2005-08-05 00:44:28 -0400322 gpe_number = ACPI_STRTOUL(&name[2], NULL, 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323 if (gpe_number == ACPI_UINT32_MAX) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400324
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325 /* Conversion failed; invalid method, just ignore it */
326
Bob Mooreb229cf92006-04-21 17:15:00 -0400327 ACPI_DEBUG_PRINT((ACPI_DB_LOAD,
Bob Moored4913dc2009-03-06 10:05:18 +0800328 "Could not extract GPE number from name: %s "
329 "(name is not of form _Lxx or _Exx)", name));
Len Brown4be44fc2005-08-05 00:44:28 -0400330 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331 }
332
333 /* Ensure that we have a valid GPE number for this GPE block */
334
Bob Moore186c3072010-04-27 11:32:28 +0800335 gpe_event_info =
336 acpi_ev_low_get_gpe_info(gpe_number, walk_info->gpe_block);
Lin Ming0f849d22010-04-06 14:52:37 +0800337 if (!gpe_event_info) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338 /*
Lin Ming0f849d22010-04-06 14:52:37 +0800339 * This gpe_number is not valid for this GPE block, just ignore it.
340 * However, it may be valid for a different GPE block, since GPE0
341 * and GPE1 methods both appear under \_GPE.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342 */
Len Brown4be44fc2005-08-05 00:44:28 -0400343 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 }
345
Bob Moore186c3072010-04-27 11:32:28 +0800346 if ((gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) ==
347 ACPI_GPE_DISPATCH_HANDLER) {
348
349 /* If there is already a handler, ignore this GPE method */
350
351 return_ACPI_STATUS(AE_OK);
352 }
353
354 if ((gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) ==
355 ACPI_GPE_DISPATCH_METHOD) {
356 /*
357 * If there is already a method, ignore this method. But check
358 * for a type mismatch (if both the _Lxx AND _Exx exist)
359 */
360 if (type != (gpe_event_info->flags & ACPI_GPE_XRUPT_TYPE_MASK)) {
361 ACPI_ERROR((AE_INFO,
362 "For GPE 0x%.2X, found both _L%2.2X and _E%2.2X methods",
363 gpe_number, gpe_number, gpe_number));
364 }
365 return_ACPI_STATUS(AE_OK);
366 }
367
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368 /*
Lin Ming0f849d22010-04-06 14:52:37 +0800369 * Add the GPE information from above to the gpe_event_info block for
370 * use during dispatch of this GPE.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371 */
Bob Moore186c3072010-04-27 11:32:28 +0800372 gpe_event_info->flags |= (u8)(type | ACPI_GPE_DISPATCH_METHOD);
Lin Ming0f849d22010-04-06 14:52:37 +0800373 gpe_event_info->dispatch.method_node = method_node;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374
Bob Moore186c3072010-04-27 11:32:28 +0800375 /*
376 * Enable this GPE if requested. This only happens when during the
377 * execution of a Load or load_table operator. We have found a new
378 * GPE method and want to immediately enable the GPE if it is a
379 * runtime GPE.
380 */
381 if (walk_info->enable_this_gpe) {
382
383 /* Ignore GPEs that can wake the system */
384
385 if (!(gpe_event_info->flags & ACPI_GPE_CAN_WAKE) ||
386 !acpi_gbl_leave_wake_gpes_disabled) {
387 walk_info->count++;
388 gpe_device = walk_info->gpe_device;
389
390 if (gpe_device == acpi_gbl_fadt_gpe_device) {
391 gpe_device = NULL;
392 }
393
394 status = acpi_enable_gpe(gpe_device, gpe_number,
395 ACPI_GPE_TYPE_RUNTIME);
396 if (ACPI_FAILURE(status)) {
397 ACPI_EXCEPTION((AE_INFO, status,
398 "Could not enable GPE 0x%02X",
399 gpe_number));
400 }
401 }
402 }
403
Len Brown4be44fc2005-08-05 00:44:28 -0400404 ACPI_DEBUG_PRINT((ACPI_DB_LOAD,
405 "Registered GPE method %s as GPE number 0x%.2X\n",
406 name, gpe_number));
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +0100407 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408}
409
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410/*******************************************************************************
411 *
412 * FUNCTION: acpi_ev_match_prw_and_gpe
413 *
414 * PARAMETERS: Callback from walk_namespace
415 *
Bob Moore96db2552005-11-02 00:00:00 -0500416 * RETURN: Status. NOTE: We ignore errors so that the _PRW walk is
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417 * not aborted on a single _PRW failure.
418 *
419 * DESCRIPTION: Called from acpi_walk_namespace. Expects each object to be a
Bob Moore96db2552005-11-02 00:00:00 -0500420 * Device. Run the _PRW method. If present, extract the GPE
Bob Moore186c3072010-04-27 11:32:28 +0800421 * number and mark the GPE as a CAN_WAKE GPE. Allows a
422 * per-owner_id execution if execute_by_owner_id is TRUE in the
423 * walk_info parameter block.
424 *
425 * If walk_info->execute_by_owner_id is TRUE, we only execute _PRWs with that
426 * owner.
427 * If walk_info->gpe_device is NULL, we execute every _PRW found. Otherwise,
428 * we only execute _PRWs that refer to the input gpe_device.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 *
430 ******************************************************************************/
431
432static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400433acpi_ev_match_prw_and_gpe(acpi_handle obj_handle,
Bob Moore186c3072010-04-27 11:32:28 +0800434 u32 level, void *context, void **return_value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435{
Bob Moore186c3072010-04-27 11:32:28 +0800436 struct acpi_gpe_walk_info *walk_info =
437 ACPI_CAST_PTR(struct acpi_gpe_walk_info, context);
Len Brown4be44fc2005-08-05 00:44:28 -0400438 struct acpi_namespace_node *gpe_device;
439 struct acpi_gpe_block_info *gpe_block;
440 struct acpi_namespace_node *target_gpe_device;
Bob Moore186c3072010-04-27 11:32:28 +0800441 struct acpi_namespace_node *prw_node;
Len Brown4be44fc2005-08-05 00:44:28 -0400442 struct acpi_gpe_event_info *gpe_event_info;
443 union acpi_operand_object *pkg_desc;
444 union acpi_operand_object *obj_desc;
445 u32 gpe_number;
446 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447
Bob Mooreb229cf92006-04-21 17:15:00 -0400448 ACPI_FUNCTION_TRACE(ev_match_prw_and_gpe);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449
450 /* Check for a _PRW method under this device */
451
Bob Moore186c3072010-04-27 11:32:28 +0800452 status = acpi_ns_get_node(obj_handle, METHOD_NAME__PRW,
453 ACPI_NS_NO_UPSEARCH, &prw_node);
454 if (ACPI_FAILURE(status)) {
455 return_ACPI_STATUS(AE_OK);
456 }
457
458 /* Check if requested owner_id matches this owner_id */
459
460 if ((walk_info->execute_by_owner_id) &&
461 (prw_node->owner_id != walk_info->owner_id)) {
462 return_ACPI_STATUS(AE_OK);
463 }
464
465 /* Execute the _PRW */
466
467 status = acpi_ut_evaluate_object(prw_node, NULL,
Len Brown4be44fc2005-08-05 00:44:28 -0400468 ACPI_BTYPE_PACKAGE, &pkg_desc);
469 if (ACPI_FAILURE(status)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400470 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471 }
472
473 /* The returned _PRW package must have at least two elements */
474
475 if (pkg_desc->package.count < 2) {
476 goto cleanup;
477 }
478
479 /* Extract pointers from the input context */
480
Bob Moore186c3072010-04-27 11:32:28 +0800481 gpe_device = walk_info->gpe_device;
482 gpe_block = walk_info->gpe_block;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483
484 /*
Bob Moore186c3072010-04-27 11:32:28 +0800485 * The _PRW object must return a package, we are only interested
486 * in the first element
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487 */
488 obj_desc = pkg_desc->package.elements[0];
489
Bob Moore3371c192009-02-18 14:44:03 +0800490 if (obj_desc->common.type == ACPI_TYPE_INTEGER) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400491
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492 /* Use FADT-defined GPE device (from definition of _PRW) */
493
Bob Moore186c3072010-04-27 11:32:28 +0800494 target_gpe_device = NULL;
495 if (gpe_device) {
496 target_gpe_device = acpi_gbl_fadt_gpe_device;
497 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498
499 /* Integer is the GPE number in the FADT described GPE blocks */
500
501 gpe_number = (u32) obj_desc->integer.value;
Bob Moore3371c192009-02-18 14:44:03 +0800502 } else if (obj_desc->common.type == ACPI_TYPE_PACKAGE) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400503
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504 /* Package contains a GPE reference and GPE number within a GPE block */
505
506 if ((obj_desc->package.count < 2) ||
Bob Moore3371c192009-02-18 14:44:03 +0800507 ((obj_desc->package.elements[0])->common.type !=
Bob Moored4913dc2009-03-06 10:05:18 +0800508 ACPI_TYPE_LOCAL_REFERENCE) ||
509 ((obj_desc->package.elements[1])->common.type !=
510 ACPI_TYPE_INTEGER)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511 goto cleanup;
512 }
513
514 /* Get GPE block reference and decode */
515
Len Brown4be44fc2005-08-05 00:44:28 -0400516 target_gpe_device =
517 obj_desc->package.elements[0]->reference.node;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518 gpe_number = (u32) obj_desc->package.elements[1]->integer.value;
Len Brown4be44fc2005-08-05 00:44:28 -0400519 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520 /* Unknown type, just ignore it */
521
522 goto cleanup;
523 }
524
Bob Moore186c3072010-04-27 11:32:28 +0800525 /* Get the gpe_event_info for this GPE */
526
527 if (gpe_device) {
528 /*
529 * Is this GPE within this block?
530 *
531 * TRUE if and only if these conditions are true:
532 * 1) The GPE devices match.
533 * 2) The GPE index(number) is within the range of the Gpe Block
534 * associated with the GPE device.
535 */
536 if (gpe_device != target_gpe_device) {
537 goto cleanup;
538 }
539
540 gpe_event_info =
541 acpi_ev_low_get_gpe_info(gpe_number, gpe_block);
542 } else {
543 /* gpe_device is NULL, just match the target_device and gpe_number */
544
545 gpe_event_info =
546 acpi_ev_get_gpe_event_info(target_gpe_device, gpe_number);
Lin Ming0f849d22010-04-06 14:52:37 +0800547 }
548
Lin Ming0f849d22010-04-06 14:52:37 +0800549 if (gpe_event_info) {
Bob Moore186c3072010-04-27 11:32:28 +0800550 if (!(gpe_event_info->flags & ACPI_GPE_CAN_WAKE)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551
Bob Moore186c3072010-04-27 11:32:28 +0800552 /* This GPE can wake the system */
553
554 gpe_event_info->flags |= ACPI_GPE_CAN_WAKE;
555 walk_info->count++;
556 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 }
558
Len Brown4be44fc2005-08-05 00:44:28 -0400559 cleanup:
560 acpi_ut_remove_reference(pkg_desc);
561 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562}
563
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564/*******************************************************************************
565 *
566 * FUNCTION: acpi_ev_get_gpe_xrupt_block
567 *
Robert Moore6f42ccf2005-05-13 00:00:00 -0400568 * PARAMETERS: interrupt_number - Interrupt for a GPE block
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569 *
570 * RETURN: A GPE interrupt block
571 *
Bob Moore96db2552005-11-02 00:00:00 -0500572 * DESCRIPTION: Get or Create a GPE interrupt block. There is one interrupt
Bob Moore9f15fc62008-11-12 16:01:56 +0800573 * block per unique interrupt level used for GPEs. Should be
574 * called only when the GPE lists are semaphore locked and not
575 * subject to change.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576 *
577 ******************************************************************************/
578
Len Brown4be44fc2005-08-05 00:44:28 -0400579static struct acpi_gpe_xrupt_info *acpi_ev_get_gpe_xrupt_block(u32
580 interrupt_number)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581{
Len Brown4be44fc2005-08-05 00:44:28 -0400582 struct acpi_gpe_xrupt_info *next_gpe_xrupt;
583 struct acpi_gpe_xrupt_info *gpe_xrupt;
584 acpi_status status;
Bob Mooreb8e4d892006-01-27 16:43:00 -0500585 acpi_cpu_flags flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586
Bob Mooreb229cf92006-04-21 17:15:00 -0400587 ACPI_FUNCTION_TRACE(ev_get_gpe_xrupt_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588
Robert Moore44f6c012005-04-18 22:49:35 -0400589 /* No need for lock since we are not changing any list elements here */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590
591 next_gpe_xrupt = acpi_gbl_gpe_xrupt_list_head;
592 while (next_gpe_xrupt) {
Robert Moore6f42ccf2005-05-13 00:00:00 -0400593 if (next_gpe_xrupt->interrupt_number == interrupt_number) {
Len Brown4be44fc2005-08-05 00:44:28 -0400594 return_PTR(next_gpe_xrupt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595 }
596
597 next_gpe_xrupt = next_gpe_xrupt->next;
598 }
599
600 /* Not found, must allocate a new xrupt descriptor */
601
Bob Moore83135242006-10-03 00:00:00 -0400602 gpe_xrupt = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_gpe_xrupt_info));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 if (!gpe_xrupt) {
Len Brown4be44fc2005-08-05 00:44:28 -0400604 return_PTR(NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605 }
606
Robert Moore6f42ccf2005-05-13 00:00:00 -0400607 gpe_xrupt->interrupt_number = interrupt_number;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608
609 /* Install new interrupt descriptor with spin lock */
610
Len Brown4be44fc2005-08-05 00:44:28 -0400611 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612 if (acpi_gbl_gpe_xrupt_list_head) {
613 next_gpe_xrupt = acpi_gbl_gpe_xrupt_list_head;
614 while (next_gpe_xrupt->next) {
615 next_gpe_xrupt = next_gpe_xrupt->next;
616 }
617
618 next_gpe_xrupt->next = gpe_xrupt;
619 gpe_xrupt->previous = next_gpe_xrupt;
Len Brown4be44fc2005-08-05 00:44:28 -0400620 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621 acpi_gbl_gpe_xrupt_list_head = gpe_xrupt;
622 }
Len Brown4be44fc2005-08-05 00:44:28 -0400623 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624
625 /* Install new interrupt handler if not SCI_INT */
626
Bob Mooref3d2e782007-02-02 19:48:18 +0300627 if (interrupt_number != acpi_gbl_FADT.sci_interrupt) {
Len Brown4be44fc2005-08-05 00:44:28 -0400628 status = acpi_os_install_interrupt_handler(interrupt_number,
629 acpi_ev_gpe_xrupt_handler,
630 gpe_xrupt);
631 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500632 ACPI_ERROR((AE_INFO,
633 "Could not install GPE interrupt handler at level 0x%X",
634 interrupt_number));
Len Brown4be44fc2005-08-05 00:44:28 -0400635 return_PTR(NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636 }
637 }
638
Len Brown4be44fc2005-08-05 00:44:28 -0400639 return_PTR(gpe_xrupt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640}
641
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642/*******************************************************************************
643 *
644 * FUNCTION: acpi_ev_delete_gpe_xrupt
645 *
646 * PARAMETERS: gpe_xrupt - A GPE interrupt info block
647 *
648 * RETURN: Status
649 *
650 * DESCRIPTION: Remove and free a gpe_xrupt block. Remove an associated
651 * interrupt handler if not the SCI interrupt.
652 *
653 ******************************************************************************/
654
655static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400656acpi_ev_delete_gpe_xrupt(struct acpi_gpe_xrupt_info *gpe_xrupt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657{
Len Brown4be44fc2005-08-05 00:44:28 -0400658 acpi_status status;
Bob Mooreb8e4d892006-01-27 16:43:00 -0500659 acpi_cpu_flags flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660
Bob Mooreb229cf92006-04-21 17:15:00 -0400661 ACPI_FUNCTION_TRACE(ev_delete_gpe_xrupt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662
663 /* We never want to remove the SCI interrupt handler */
664
Bob Mooref3d2e782007-02-02 19:48:18 +0300665 if (gpe_xrupt->interrupt_number == acpi_gbl_FADT.sci_interrupt) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666 gpe_xrupt->gpe_block_list_head = NULL;
Len Brown4be44fc2005-08-05 00:44:28 -0400667 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668 }
669
670 /* Disable this interrupt */
671
Bob Moore96db2552005-11-02 00:00:00 -0500672 status =
673 acpi_os_remove_interrupt_handler(gpe_xrupt->interrupt_number,
674 acpi_ev_gpe_xrupt_handler);
Len Brown4be44fc2005-08-05 00:44:28 -0400675 if (ACPI_FAILURE(status)) {
676 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 }
678
679 /* Unlink the interrupt block with lock */
680
Len Brown4be44fc2005-08-05 00:44:28 -0400681 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682 if (gpe_xrupt->previous) {
683 gpe_xrupt->previous->next = gpe_xrupt->next;
Bob Mooree0b910502007-04-03 20:00:29 -0400684 } else {
685 /* No previous, update list head */
686
687 acpi_gbl_gpe_xrupt_list_head = gpe_xrupt->next;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688 }
689
690 if (gpe_xrupt->next) {
691 gpe_xrupt->next->previous = gpe_xrupt->previous;
692 }
Len Brown4be44fc2005-08-05 00:44:28 -0400693 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694
695 /* Free the block */
696
Bob Moore83135242006-10-03 00:00:00 -0400697 ACPI_FREE(gpe_xrupt);
Len Brown4be44fc2005-08-05 00:44:28 -0400698 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699}
700
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701/*******************************************************************************
702 *
703 * FUNCTION: acpi_ev_install_gpe_block
704 *
Bob Moore9f15fc62008-11-12 16:01:56 +0800705 * PARAMETERS: gpe_block - New GPE block
706 * interrupt_number - Xrupt to be associated with this
707 * GPE block
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708 *
709 * RETURN: Status
710 *
711 * DESCRIPTION: Install new GPE block with mutex support
712 *
713 ******************************************************************************/
714
715static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400716acpi_ev_install_gpe_block(struct acpi_gpe_block_info *gpe_block,
717 u32 interrupt_number)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718{
Len Brown4be44fc2005-08-05 00:44:28 -0400719 struct acpi_gpe_block_info *next_gpe_block;
720 struct acpi_gpe_xrupt_info *gpe_xrupt_block;
721 acpi_status status;
Bob Mooreb8e4d892006-01-27 16:43:00 -0500722 acpi_cpu_flags flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723
Bob Mooreb229cf92006-04-21 17:15:00 -0400724 ACPI_FUNCTION_TRACE(ev_install_gpe_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725
Len Brown4be44fc2005-08-05 00:44:28 -0400726 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
727 if (ACPI_FAILURE(status)) {
728 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729 }
730
Len Brown4be44fc2005-08-05 00:44:28 -0400731 gpe_xrupt_block = acpi_ev_get_gpe_xrupt_block(interrupt_number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732 if (!gpe_xrupt_block) {
733 status = AE_NO_MEMORY;
734 goto unlock_and_exit;
735 }
736
Robert Moore44f6c012005-04-18 22:49:35 -0400737 /* Install the new block at the end of the list with lock */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738
Len Brown4be44fc2005-08-05 00:44:28 -0400739 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740 if (gpe_xrupt_block->gpe_block_list_head) {
741 next_gpe_block = gpe_xrupt_block->gpe_block_list_head;
742 while (next_gpe_block->next) {
743 next_gpe_block = next_gpe_block->next;
744 }
745
746 next_gpe_block->next = gpe_block;
747 gpe_block->previous = next_gpe_block;
Len Brown4be44fc2005-08-05 00:44:28 -0400748 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749 gpe_xrupt_block->gpe_block_list_head = gpe_block;
750 }
751
752 gpe_block->xrupt_block = gpe_xrupt_block;
Len Brown4be44fc2005-08-05 00:44:28 -0400753 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754
Len Brown4be44fc2005-08-05 00:44:28 -0400755 unlock_and_exit:
756 status = acpi_ut_release_mutex(ACPI_MTX_EVENTS);
757 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758}
759
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760/*******************************************************************************
761 *
762 * FUNCTION: acpi_ev_delete_gpe_block
763 *
Bob Moore9f15fc62008-11-12 16:01:56 +0800764 * PARAMETERS: gpe_block - Existing GPE block
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765 *
766 * RETURN: Status
767 *
768 * DESCRIPTION: Remove a GPE block
769 *
770 ******************************************************************************/
771
Len Brown4be44fc2005-08-05 00:44:28 -0400772acpi_status acpi_ev_delete_gpe_block(struct acpi_gpe_block_info *gpe_block)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773{
Len Brown4be44fc2005-08-05 00:44:28 -0400774 acpi_status status;
Bob Mooreb8e4d892006-01-27 16:43:00 -0500775 acpi_cpu_flags flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776
Bob Mooreb229cf92006-04-21 17:15:00 -0400777 ACPI_FUNCTION_TRACE(ev_install_gpe_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778
Len Brown4be44fc2005-08-05 00:44:28 -0400779 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
780 if (ACPI_FAILURE(status)) {
781 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782 }
783
784 /* Disable all GPEs in this block */
785
Bob Mooree97d6bf2008-12-30 09:45:17 +0800786 status =
787 acpi_hw_disable_gpe_block(gpe_block->xrupt_block, gpe_block, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788
789 if (!gpe_block->previous && !gpe_block->next) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400790
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791 /* This is the last gpe_block on this interrupt */
792
Len Brown4be44fc2005-08-05 00:44:28 -0400793 status = acpi_ev_delete_gpe_xrupt(gpe_block->xrupt_block);
794 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795 goto unlock_and_exit;
796 }
Len Brown4be44fc2005-08-05 00:44:28 -0400797 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798 /* Remove the block on this interrupt with lock */
799
Len Brown4be44fc2005-08-05 00:44:28 -0400800 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801 if (gpe_block->previous) {
802 gpe_block->previous->next = gpe_block->next;
Len Brown4be44fc2005-08-05 00:44:28 -0400803 } else {
804 gpe_block->xrupt_block->gpe_block_list_head =
805 gpe_block->next;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806 }
807
808 if (gpe_block->next) {
809 gpe_block->next->previous = gpe_block->previous;
810 }
Len Brown4be44fc2005-08-05 00:44:28 -0400811 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812 }
813
Lin Ming0f849d22010-04-06 14:52:37 +0800814 acpi_current_gpe_count -= gpe_block->gpe_count;
Bob Mooree97d6bf2008-12-30 09:45:17 +0800815
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816 /* Free the gpe_block */
817
Bob Moore83135242006-10-03 00:00:00 -0400818 ACPI_FREE(gpe_block->register_info);
819 ACPI_FREE(gpe_block->event_info);
820 ACPI_FREE(gpe_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821
Len Brown4be44fc2005-08-05 00:44:28 -0400822 unlock_and_exit:
823 status = acpi_ut_release_mutex(ACPI_MTX_EVENTS);
824 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825}
826
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827/*******************************************************************************
828 *
829 * FUNCTION: acpi_ev_create_gpe_info_blocks
830 *
831 * PARAMETERS: gpe_block - New GPE block
832 *
833 * RETURN: Status
834 *
835 * DESCRIPTION: Create the register_info and event_info blocks for this GPE block
836 *
837 ******************************************************************************/
838
839static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400840acpi_ev_create_gpe_info_blocks(struct acpi_gpe_block_info *gpe_block)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841{
Len Brown4be44fc2005-08-05 00:44:28 -0400842 struct acpi_gpe_register_info *gpe_register_info = NULL;
843 struct acpi_gpe_event_info *gpe_event_info = NULL;
844 struct acpi_gpe_event_info *this_event;
845 struct acpi_gpe_register_info *this_register;
Bob Moore67a119f2008-06-10 13:42:13 +0800846 u32 i;
847 u32 j;
Len Brown4be44fc2005-08-05 00:44:28 -0400848 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849
Bob Mooreb229cf92006-04-21 17:15:00 -0400850 ACPI_FUNCTION_TRACE(ev_create_gpe_info_blocks);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851
852 /* Allocate the GPE register information block */
853
Bob Moore83135242006-10-03 00:00:00 -0400854 gpe_register_info = ACPI_ALLOCATE_ZEROED((acpi_size) gpe_block->
855 register_count *
856 sizeof(struct
857 acpi_gpe_register_info));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858 if (!gpe_register_info) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500859 ACPI_ERROR((AE_INFO,
Bob Mooreb229cf92006-04-21 17:15:00 -0400860 "Could not allocate the GpeRegisterInfo table"));
Len Brown4be44fc2005-08-05 00:44:28 -0400861 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862 }
863
864 /*
865 * Allocate the GPE event_info block. There are eight distinct GPEs
Bob Moore96db2552005-11-02 00:00:00 -0500866 * per register. Initialization to zeros is sufficient.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867 */
Lin Ming0f849d22010-04-06 14:52:37 +0800868 gpe_event_info = ACPI_ALLOCATE_ZEROED((acpi_size) gpe_block->gpe_count *
Bob Moore83135242006-10-03 00:00:00 -0400869 sizeof(struct
870 acpi_gpe_event_info));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871 if (!gpe_event_info) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500872 ACPI_ERROR((AE_INFO,
Bob Mooreb229cf92006-04-21 17:15:00 -0400873 "Could not allocate the GpeEventInfo table"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874 status = AE_NO_MEMORY;
875 goto error_exit;
876 }
877
878 /* Save the new Info arrays in the GPE block */
879
880 gpe_block->register_info = gpe_register_info;
Len Brown4be44fc2005-08-05 00:44:28 -0400881 gpe_block->event_info = gpe_event_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882
883 /*
Bob Moore96db2552005-11-02 00:00:00 -0500884 * Initialize the GPE Register and Event structures. A goal of these
Bob Moore9f15fc62008-11-12 16:01:56 +0800885 * tables is to hide the fact that there are two separate GPE register
886 * sets in a given GPE hardware block, the status registers occupy the
887 * first half, and the enable registers occupy the second half.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700888 */
889 this_register = gpe_register_info;
Len Brown4be44fc2005-08-05 00:44:28 -0400890 this_event = gpe_event_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700891
892 for (i = 0; i < gpe_block->register_count; i++) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400893
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894 /* Init the register_info for this GPE register (8 GPEs) */
895
Len Brown4be44fc2005-08-05 00:44:28 -0400896 this_register->base_gpe_number =
897 (u8) (gpe_block->block_base_number +
898 (i * ACPI_GPE_REGISTER_WIDTH));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700899
Bob Moore59fa8502007-02-02 19:48:23 +0300900 this_register->status_address.address =
901 gpe_block->block_address.address + i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902
Bob Moore59fa8502007-02-02 19:48:23 +0300903 this_register->enable_address.address =
904 gpe_block->block_address.address + i +
905 gpe_block->register_count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700906
Bob Mooref3d2e782007-02-02 19:48:18 +0300907 this_register->status_address.space_id =
908 gpe_block->block_address.space_id;
909 this_register->enable_address.space_id =
910 gpe_block->block_address.space_id;
911 this_register->status_address.bit_width =
Len Brown4be44fc2005-08-05 00:44:28 -0400912 ACPI_GPE_REGISTER_WIDTH;
Bob Mooref3d2e782007-02-02 19:48:18 +0300913 this_register->enable_address.bit_width =
Len Brown4be44fc2005-08-05 00:44:28 -0400914 ACPI_GPE_REGISTER_WIDTH;
Bob Mooreecfbbc72008-12-31 02:55:32 +0800915 this_register->status_address.bit_offset = 0;
916 this_register->enable_address.bit_offset = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917
918 /* Init the event_info for each GPE within this register */
919
920 for (j = 0; j < ACPI_GPE_REGISTER_WIDTH; j++) {
Alexey Starikovskiy69874162007-02-02 19:48:19 +0300921 this_event->gpe_number =
922 (u8) (this_register->base_gpe_number + j);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923 this_event->register_info = this_register;
924 this_event++;
925 }
926
Bob Moore96db2552005-11-02 00:00:00 -0500927 /* Disable all GPEs within this register */
928
Bob Moorec6b57742009-06-24 09:44:06 +0800929 status = acpi_hw_write(0x00, &this_register->enable_address);
Len Brown4be44fc2005-08-05 00:44:28 -0400930 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700931 goto error_exit;
932 }
933
Bob Moore96db2552005-11-02 00:00:00 -0500934 /* Clear any pending GPE events within this register */
935
Bob Moorec6b57742009-06-24 09:44:06 +0800936 status = acpi_hw_write(0xFF, &this_register->status_address);
Len Brown4be44fc2005-08-05 00:44:28 -0400937 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938 goto error_exit;
939 }
940
941 this_register++;
942 }
943
Len Brown4be44fc2005-08-05 00:44:28 -0400944 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700945
Len Brown4be44fc2005-08-05 00:44:28 -0400946 error_exit:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947 if (gpe_register_info) {
Bob Moore83135242006-10-03 00:00:00 -0400948 ACPI_FREE(gpe_register_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700949 }
950 if (gpe_event_info) {
Bob Moore83135242006-10-03 00:00:00 -0400951 ACPI_FREE(gpe_event_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952 }
953
Len Brown4be44fc2005-08-05 00:44:28 -0400954 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700955}
956
Linus Torvalds1da177e2005-04-16 15:20:36 -0700957/*******************************************************************************
958 *
959 * FUNCTION: acpi_ev_create_gpe_block
960 *
961 * PARAMETERS: gpe_device - Handle to the parent GPE block
962 * gpe_block_address - Address and space_iD
963 * register_count - Number of GPE register pairs in the block
964 * gpe_block_base_number - Starting GPE number for the block
Robert Moore6f42ccf2005-05-13 00:00:00 -0400965 * interrupt_number - H/W interrupt for the block
Linus Torvalds1da177e2005-04-16 15:20:36 -0700966 * return_gpe_block - Where the new block descriptor is returned
967 *
968 * RETURN: Status
969 *
Bob Moore96db2552005-11-02 00:00:00 -0500970 * DESCRIPTION: Create and Install a block of GPE registers. All GPEs within
971 * the block are disabled at exit.
972 * Note: Assumes namespace is locked.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700973 *
974 ******************************************************************************/
975
976acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400977acpi_ev_create_gpe_block(struct acpi_namespace_node *gpe_device,
978 struct acpi_generic_address *gpe_block_address,
979 u32 register_count,
980 u8 gpe_block_base_number,
981 u32 interrupt_number,
982 struct acpi_gpe_block_info **return_gpe_block)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983{
Len Brown4be44fc2005-08-05 00:44:28 -0400984 acpi_status status;
Bob Moore96db2552005-11-02 00:00:00 -0500985 struct acpi_gpe_block_info *gpe_block;
Bob Moore186c3072010-04-27 11:32:28 +0800986 struct acpi_gpe_walk_info walk_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700987
Bob Mooreb229cf92006-04-21 17:15:00 -0400988 ACPI_FUNCTION_TRACE(ev_create_gpe_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700989
990 if (!register_count) {
Len Brown4be44fc2005-08-05 00:44:28 -0400991 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700992 }
993
994 /* Allocate a new GPE block */
995
Bob Moore83135242006-10-03 00:00:00 -0400996 gpe_block = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_gpe_block_info));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700997 if (!gpe_block) {
Len Brown4be44fc2005-08-05 00:44:28 -0400998 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700999 }
1000
1001 /* Initialize the new GPE block */
1002
Bob Moore96db2552005-11-02 00:00:00 -05001003 gpe_block->node = gpe_device;
Lin Ming0f849d22010-04-06 14:52:37 +08001004 gpe_block->gpe_count = (u16)(register_count * ACPI_GPE_REGISTER_WIDTH);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001005 gpe_block->register_count = register_count;
1006 gpe_block->block_base_number = gpe_block_base_number;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001007
Len Brown4be44fc2005-08-05 00:44:28 -04001008 ACPI_MEMCPY(&gpe_block->block_address, gpe_block_address,
1009 sizeof(struct acpi_generic_address));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001010
Bob Moore96db2552005-11-02 00:00:00 -05001011 /*
1012 * Create the register_info and event_info sub-structures
1013 * Note: disables and clears all GPEs in the block
1014 */
Len Brown4be44fc2005-08-05 00:44:28 -04001015 status = acpi_ev_create_gpe_info_blocks(gpe_block);
1016 if (ACPI_FAILURE(status)) {
Bob Moore83135242006-10-03 00:00:00 -04001017 ACPI_FREE(gpe_block);
Len Brown4be44fc2005-08-05 00:44:28 -04001018 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001019 }
1020
Bob Moore96db2552005-11-02 00:00:00 -05001021 /* Install the new block in the global lists */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001022
Len Brown4be44fc2005-08-05 00:44:28 -04001023 status = acpi_ev_install_gpe_block(gpe_block, interrupt_number);
1024 if (ACPI_FAILURE(status)) {
Bob Moore83135242006-10-03 00:00:00 -04001025 ACPI_FREE(gpe_block);
Len Brown4be44fc2005-08-05 00:44:28 -04001026 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027 }
1028
Bob Moore186c3072010-04-27 11:32:28 +08001029 /* Find all GPE methods (_Lxx or_Exx) for this block */
1030
1031 walk_info.gpe_block = gpe_block;
1032 walk_info.gpe_device = gpe_device;
1033 walk_info.enable_this_gpe = FALSE;
1034 walk_info.execute_by_owner_id = FALSE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001035
Len Brown4be44fc2005-08-05 00:44:28 -04001036 status = acpi_ns_walk_namespace(ACPI_TYPE_METHOD, gpe_device,
1037 ACPI_UINT32_MAX, ACPI_NS_WALK_NO_UNLOCK,
Lin Ming0f849d22010-04-06 14:52:37 +08001038 acpi_ev_match_gpe_method, NULL,
Bob Moore186c3072010-04-27 11:32:28 +08001039 &walk_info, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001040
Bob Moore96db2552005-11-02 00:00:00 -05001041 /* Return the new block */
1042
1043 if (return_gpe_block) {
1044 (*return_gpe_block) = gpe_block;
1045 }
1046
1047 ACPI_DEBUG_PRINT((ACPI_DB_INIT,
1048 "GPE %02X to %02X [%4.4s] %u regs on int 0x%X\n",
1049 (u32) gpe_block->block_base_number,
1050 (u32) (gpe_block->block_base_number +
Lin Ming0f849d22010-04-06 14:52:37 +08001051 (gpe_block->gpe_count - 1)),
Bob Moore96db2552005-11-02 00:00:00 -05001052 gpe_device->name.ascii, gpe_block->register_count,
1053 interrupt_number));
1054
Bob Mooree97d6bf2008-12-30 09:45:17 +08001055 /* Update global count of currently available GPEs */
1056
Lin Ming0f849d22010-04-06 14:52:37 +08001057 acpi_current_gpe_count += gpe_block->gpe_count;
Bob Moore96db2552005-11-02 00:00:00 -05001058 return_ACPI_STATUS(AE_OK);
1059}
1060
1061/*******************************************************************************
1062 *
Bob Moore186c3072010-04-27 11:32:28 +08001063 * FUNCTION: acpi_ev_update_gpes
1064 *
1065 * PARAMETERS: table_owner_id - ID of the newly-loaded ACPI table
1066 *
1067 * RETURN: None
1068 *
1069 * DESCRIPTION: Check for new GPE methods (_Lxx/_Exx) made available as a
1070 * result of a Load() or load_table() operation. If new GPE
1071 * methods have been installed, register the new methods and
1072 * enable and runtime GPEs that are associated with them. Also,
1073 * run any newly loaded _PRW methods in order to discover any
1074 * new CAN_WAKE GPEs.
1075 *
1076 ******************************************************************************/
1077
1078void acpi_ev_update_gpes(acpi_owner_id table_owner_id)
1079{
1080 struct acpi_gpe_xrupt_info *gpe_xrupt_info;
1081 struct acpi_gpe_block_info *gpe_block;
1082 struct acpi_gpe_walk_info walk_info;
1083 acpi_status status = AE_OK;
1084 u32 new_wake_gpe_count = 0;
1085
1086 /* We will examine only _PRW/_Lxx/_Exx methods owned by this table */
1087
1088 walk_info.owner_id = table_owner_id;
1089 walk_info.execute_by_owner_id = TRUE;
1090 walk_info.count = 0;
1091
1092 if (acpi_gbl_leave_wake_gpes_disabled) {
1093 /*
1094 * 1) Run any newly-loaded _PRW methods to find any GPEs that
1095 * can now be marked as CAN_WAKE GPEs. Note: We must run the
1096 * _PRW methods before we process the _Lxx/_Exx methods because
1097 * we will enable all runtime GPEs associated with the new
1098 * _Lxx/_Exx methods at the time we process those methods.
1099 *
1100 * Unlock interpreter so that we can run the _PRW methods.
1101 */
1102 walk_info.gpe_block = NULL;
1103 walk_info.gpe_device = NULL;
1104
1105 acpi_ex_exit_interpreter();
1106
1107 status =
1108 acpi_ns_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,
1109 ACPI_UINT32_MAX,
1110 ACPI_NS_WALK_NO_UNLOCK,
1111 acpi_ev_match_prw_and_gpe, NULL,
1112 &walk_info, NULL);
1113 if (ACPI_FAILURE(status)) {
1114 ACPI_EXCEPTION((AE_INFO, status,
1115 "While executing _PRW methods"));
1116 }
1117
1118 acpi_ex_enter_interpreter();
1119 new_wake_gpe_count = walk_info.count;
1120 }
1121
1122 /*
1123 * 2) Find any _Lxx/_Exx GPE methods that have just been loaded.
1124 *
1125 * Any GPEs that correspond to new _Lxx/_Exx methods and are not
1126 * marked as CAN_WAKE are immediately enabled.
1127 *
1128 * Examine the namespace underneath each gpe_device within the
1129 * gpe_block lists.
1130 */
1131 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
1132 if (ACPI_FAILURE(status)) {
1133 return;
1134 }
1135
1136 walk_info.count = 0;
1137 walk_info.enable_this_gpe = TRUE;
1138
1139 /* Walk the interrupt level descriptor list */
1140
1141 gpe_xrupt_info = acpi_gbl_gpe_xrupt_list_head;
1142 while (gpe_xrupt_info) {
1143
1144 /* Walk all Gpe Blocks attached to this interrupt level */
1145
1146 gpe_block = gpe_xrupt_info->gpe_block_list_head;
1147 while (gpe_block) {
1148 walk_info.gpe_block = gpe_block;
1149 walk_info.gpe_device = gpe_block->node;
1150
1151 status = acpi_ns_walk_namespace(ACPI_TYPE_METHOD,
1152 walk_info.gpe_device,
1153 ACPI_UINT32_MAX,
1154 ACPI_NS_WALK_NO_UNLOCK,
1155 acpi_ev_match_gpe_method,
1156 NULL, &walk_info, NULL);
1157 if (ACPI_FAILURE(status)) {
1158 ACPI_EXCEPTION((AE_INFO, status,
1159 "While decoding _Lxx/_Exx methods"));
1160 }
1161
1162 gpe_block = gpe_block->next;
1163 }
1164
1165 gpe_xrupt_info = gpe_xrupt_info->next;
1166 }
1167
1168 if (walk_info.count || new_wake_gpe_count) {
1169 ACPI_INFO((AE_INFO,
1170 "Enabled %u new runtime GPEs, added %u new wakeup GPEs",
1171 walk_info.count, new_wake_gpe_count));
1172 }
1173
1174 (void)acpi_ut_release_mutex(ACPI_MTX_EVENTS);
1175 return;
1176}
1177
1178/*******************************************************************************
1179 *
Bob Moore96db2552005-11-02 00:00:00 -05001180 * FUNCTION: acpi_ev_initialize_gpe_block
1181 *
1182 * PARAMETERS: gpe_device - Handle to the parent GPE block
1183 * gpe_block - Gpe Block info
1184 *
1185 * RETURN: Status
1186 *
1187 * DESCRIPTION: Initialize and enable a GPE block. First find and run any
1188 * _PRT methods associated with the block, then enable the
1189 * appropriate GPEs.
1190 * Note: Assumes namespace is locked.
1191 *
1192 ******************************************************************************/
1193
1194acpi_status
1195acpi_ev_initialize_gpe_block(struct acpi_namespace_node *gpe_device,
1196 struct acpi_gpe_block_info *gpe_block)
1197{
Lin Ming0f849d22010-04-06 14:52:37 +08001198 acpi_status status;
Bob Moore96db2552005-11-02 00:00:00 -05001199 struct acpi_gpe_event_info *gpe_event_info;
Bob Moore186c3072010-04-27 11:32:28 +08001200 struct acpi_gpe_walk_info walk_info;
Bob Moore96db2552005-11-02 00:00:00 -05001201 u32 wake_gpe_count;
1202 u32 gpe_enabled_count;
Lin Ming0f849d22010-04-06 14:52:37 +08001203 u32 gpe_index;
1204 u32 gpe_number;
Bob Moore67a119f2008-06-10 13:42:13 +08001205 u32 i;
1206 u32 j;
Bob Moore96db2552005-11-02 00:00:00 -05001207
Bob Mooreb229cf92006-04-21 17:15:00 -04001208 ACPI_FUNCTION_TRACE(ev_initialize_gpe_block);
Bob Moore96db2552005-11-02 00:00:00 -05001209
1210 /* Ignore a null GPE block (e.g., if no GPE block 1 exists) */
1211
1212 if (!gpe_block) {
1213 return_ACPI_STATUS(AE_OK);
1214 }
1215
Linus Torvalds1da177e2005-04-16 15:20:36 -07001216 /*
Bob Moore96db2552005-11-02 00:00:00 -05001217 * Runtime option: Should wake GPEs be enabled at runtime? The default
1218 * is no, they should only be enabled just as the machine goes to sleep.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001219 */
1220 if (acpi_gbl_leave_wake_gpes_disabled) {
1221 /*
Bob Moore96db2552005-11-02 00:00:00 -05001222 * Differentiate runtime vs wake GPEs, via the _PRW control methods.
1223 * Each GPE that has one or more _PRWs that reference it is by
1224 * definition a wake GPE and will not be enabled while the machine
1225 * is running.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001226 */
Bob Moore186c3072010-04-27 11:32:28 +08001227 walk_info.gpe_block = gpe_block;
1228 walk_info.gpe_device = gpe_device;
1229 walk_info.execute_by_owner_id = FALSE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001230
Bob Moore186c3072010-04-27 11:32:28 +08001231 status =
1232 acpi_ns_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,
Len Brown4be44fc2005-08-05 00:44:28 -04001233 ACPI_UINT32_MAX, ACPI_NS_WALK_UNLOCK,
Lin Ming22635762009-11-13 10:06:08 +08001234 acpi_ev_match_prw_and_gpe, NULL,
Bob Moore186c3072010-04-27 11:32:28 +08001235 &walk_info, NULL);
Lin Ming0f849d22010-04-06 14:52:37 +08001236 if (ACPI_FAILURE(status)) {
1237 ACPI_EXCEPTION((AE_INFO, status,
1238 "While executing _PRW methods"));
1239 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001240 }
1241
1242 /*
Lin Ming0f849d22010-04-06 14:52:37 +08001243 * Enable all GPEs that have a corresponding method and are not
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +01001244 * capable of generating wakeups. Any other GPEs within this block
Lin Ming0f849d22010-04-06 14:52:37 +08001245 * must be enabled via the acpi_enable_gpe interface.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001246 */
1247 wake_gpe_count = 0;
1248 gpe_enabled_count = 0;
Lin Ming0f849d22010-04-06 14:52:37 +08001249
1250 if (gpe_device == acpi_gbl_fadt_gpe_device) {
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +01001251 gpe_device = NULL;
Lin Ming0f849d22010-04-06 14:52:37 +08001252 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001253
1254 for (i = 0; i < gpe_block->register_count; i++) {
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +01001255 for (j = 0; j < ACPI_GPE_REGISTER_WIDTH; j++) {
Bob Moore52fc0b02006-10-02 00:00:00 -04001256
Linus Torvalds1da177e2005-04-16 15:20:36 -07001257 /* Get the info block for this particular GPE */
Lin Ming0f849d22010-04-06 14:52:37 +08001258
1259 gpe_index = (i * ACPI_GPE_REGISTER_WIDTH) + j;
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +01001260 gpe_event_info = &gpe_block->event_info[gpe_index];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001261
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +01001262 if (gpe_event_info->flags & ACPI_GPE_CAN_WAKE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001263 wake_gpe_count++;
Lin Ming0f849d22010-04-06 14:52:37 +08001264 if (acpi_gbl_leave_wake_gpes_disabled) {
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +01001265 continue;
Lin Ming0f849d22010-04-06 14:52:37 +08001266 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001267 }
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +01001268
Lin Ming0f849d22010-04-06 14:52:37 +08001269 /* Ignore GPEs that have no corresponding _Lxx/_Exx method */
1270
1271 if (!(gpe_event_info->flags & ACPI_GPE_DISPATCH_METHOD)) {
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +01001272 continue;
Lin Ming0f849d22010-04-06 14:52:37 +08001273 }
1274
1275 /* Enable this GPE */
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +01001276
1277 gpe_number = gpe_index + gpe_block->block_base_number;
1278 status = acpi_enable_gpe(gpe_device, gpe_number,
Lin Ming0f849d22010-04-06 14:52:37 +08001279 ACPI_GPE_TYPE_RUNTIME);
1280 if (ACPI_FAILURE(status)) {
1281 ACPI_EXCEPTION((AE_INFO, status,
1282 "Could not enable GPE 0x%02X",
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +01001283 gpe_number));
Lin Ming0f849d22010-04-06 14:52:37 +08001284 continue;
1285 }
1286
1287 gpe_enabled_count++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001288 }
1289 }
1290
Bob Moore186c3072010-04-27 11:32:28 +08001291 if (gpe_enabled_count || wake_gpe_count) {
1292 ACPI_DEBUG_PRINT((ACPI_DB_INIT,
1293 "Enabled %u Runtime GPEs, added %u Wake GPEs in this block\n",
1294 gpe_enabled_count, wake_gpe_count));
1295 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001296
Rafael J. Wysocki9630bdd2010-02-17 23:41:07 +01001297 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001298}
1299
Linus Torvalds1da177e2005-04-16 15:20:36 -07001300/*******************************************************************************
1301 *
1302 * FUNCTION: acpi_ev_gpe_initialize
1303 *
1304 * PARAMETERS: None
1305 *
1306 * RETURN: Status
1307 *
1308 * DESCRIPTION: Initialize the GPE data structures
1309 *
1310 ******************************************************************************/
1311
Len Brown4be44fc2005-08-05 00:44:28 -04001312acpi_status acpi_ev_gpe_initialize(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001313{
Len Brown4be44fc2005-08-05 00:44:28 -04001314 u32 register_count0 = 0;
1315 u32 register_count1 = 0;
1316 u32 gpe_number_max = 0;
1317 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001318
Bob Mooreb229cf92006-04-21 17:15:00 -04001319 ACPI_FUNCTION_TRACE(ev_gpe_initialize);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001320
Len Brown4be44fc2005-08-05 00:44:28 -04001321 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
1322 if (ACPI_FAILURE(status)) {
1323 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001324 }
1325
1326 /*
1327 * Initialize the GPE Block(s) defined in the FADT
1328 *
Bob Moored4913dc2009-03-06 10:05:18 +08001329 * Why the GPE register block lengths are divided by 2: From the ACPI
1330 * Spec, section "General-Purpose Event Registers", we have:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001331 *
1332 * "Each register block contains two registers of equal length
1333 * GPEx_STS and GPEx_EN (where x is 0 or 1). The length of the
1334 * GPE0_STS and GPE0_EN registers is equal to half the GPE0_LEN
1335 * The length of the GPE1_STS and GPE1_EN registers is equal to
1336 * half the GPE1_LEN. If a generic register block is not supported
1337 * then its respective block pointer and block length values in the
1338 * FADT table contain zeros. The GPE0_LEN and GPE1_LEN do not need
1339 * to be the same size."
1340 */
1341
1342 /*
1343 * Determine the maximum GPE number for this machine.
1344 *
1345 * Note: both GPE0 and GPE1 are optional, and either can exist without
1346 * the other.
1347 *
1348 * If EITHER the register length OR the block address are zero, then that
1349 * particular block is not supported.
1350 */
Bob Mooref3d2e782007-02-02 19:48:18 +03001351 if (acpi_gbl_FADT.gpe0_block_length &&
1352 acpi_gbl_FADT.xgpe0_block.address) {
Bob Moore52fc0b02006-10-02 00:00:00 -04001353
Linus Torvalds1da177e2005-04-16 15:20:36 -07001354 /* GPE block 0 exists (has both length and address > 0) */
1355
Bob Mooref3d2e782007-02-02 19:48:18 +03001356 register_count0 = (u16) (acpi_gbl_FADT.gpe0_block_length / 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001357
Len Brown4be44fc2005-08-05 00:44:28 -04001358 gpe_number_max =
1359 (register_count0 * ACPI_GPE_REGISTER_WIDTH) - 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001360
1361 /* Install GPE Block 0 */
1362
Len Brown4be44fc2005-08-05 00:44:28 -04001363 status = acpi_ev_create_gpe_block(acpi_gbl_fadt_gpe_device,
Bob Mooref3d2e782007-02-02 19:48:18 +03001364 &acpi_gbl_FADT.xgpe0_block,
Len Brown4be44fc2005-08-05 00:44:28 -04001365 register_count0, 0,
Bob Mooref3d2e782007-02-02 19:48:18 +03001366 acpi_gbl_FADT.sci_interrupt,
Len Brown4be44fc2005-08-05 00:44:28 -04001367 &acpi_gbl_gpe_fadt_blocks[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001368
Len Brown4be44fc2005-08-05 00:44:28 -04001369 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -05001370 ACPI_EXCEPTION((AE_INFO, status,
1371 "Could not create GPE Block 0"));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001372 }
1373 }
1374
Bob Mooref3d2e782007-02-02 19:48:18 +03001375 if (acpi_gbl_FADT.gpe1_block_length &&
1376 acpi_gbl_FADT.xgpe1_block.address) {
Bob Moore52fc0b02006-10-02 00:00:00 -04001377
Linus Torvalds1da177e2005-04-16 15:20:36 -07001378 /* GPE block 1 exists (has both length and address > 0) */
1379
Bob Mooref3d2e782007-02-02 19:48:18 +03001380 register_count1 = (u16) (acpi_gbl_FADT.gpe1_block_length / 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001381
1382 /* Check for GPE0/GPE1 overlap (if both banks exist) */
1383
1384 if ((register_count0) &&
Bob Mooref3d2e782007-02-02 19:48:18 +03001385 (gpe_number_max >= acpi_gbl_FADT.gpe1_base)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -05001386 ACPI_ERROR((AE_INFO,
Bob Mooref6a22b02010-03-05 17:56:40 +08001387 "GPE0 block (GPE 0 to %u) overlaps the GPE1 block "
1388 "(GPE %u to %u) - Ignoring GPE1",
Bob Mooref3d2e782007-02-02 19:48:18 +03001389 gpe_number_max, acpi_gbl_FADT.gpe1_base,
1390 acpi_gbl_FADT.gpe1_base +
Bob Mooreb8e4d892006-01-27 16:43:00 -05001391 ((register_count1 *
1392 ACPI_GPE_REGISTER_WIDTH) - 1)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001393
1394 /* Ignore GPE1 block by setting the register count to zero */
1395
1396 register_count1 = 0;
Len Brown4be44fc2005-08-05 00:44:28 -04001397 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001398 /* Install GPE Block 1 */
1399
Len Brown4be44fc2005-08-05 00:44:28 -04001400 status =
1401 acpi_ev_create_gpe_block(acpi_gbl_fadt_gpe_device,
Bob Mooref3d2e782007-02-02 19:48:18 +03001402 &acpi_gbl_FADT.xgpe1_block,
Len Brown4be44fc2005-08-05 00:44:28 -04001403 register_count1,
Bob Mooref3d2e782007-02-02 19:48:18 +03001404 acpi_gbl_FADT.gpe1_base,
1405 acpi_gbl_FADT.
1406 sci_interrupt,
Len Brown4be44fc2005-08-05 00:44:28 -04001407 &acpi_gbl_gpe_fadt_blocks
1408 [1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001409
Len Brown4be44fc2005-08-05 00:44:28 -04001410 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -05001411 ACPI_EXCEPTION((AE_INFO, status,
1412 "Could not create GPE Block 1"));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001413 }
1414
1415 /*
1416 * GPE0 and GPE1 do not have to be contiguous in the GPE number
1417 * space. However, GPE0 always starts at GPE number zero.
1418 */
Bob Mooref3d2e782007-02-02 19:48:18 +03001419 gpe_number_max = acpi_gbl_FADT.gpe1_base +
Len Brown4be44fc2005-08-05 00:44:28 -04001420 ((register_count1 * ACPI_GPE_REGISTER_WIDTH) - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001421 }
1422 }
1423
1424 /* Exit if there are no GPE registers */
1425
1426 if ((register_count0 + register_count1) == 0) {
Bob Moore52fc0b02006-10-02 00:00:00 -04001427
Linus Torvalds1da177e2005-04-16 15:20:36 -07001428 /* GPEs are not required by ACPI, this is OK */
1429
Len Brown4be44fc2005-08-05 00:44:28 -04001430 ACPI_DEBUG_PRINT((ACPI_DB_INIT,
1431 "There are no GPE blocks defined in the FADT\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001432 status = AE_OK;
1433 goto cleanup;
1434 }
1435
1436 /* Check for Max GPE number out-of-range */
1437
1438 if (gpe_number_max > ACPI_GPE_MAX) {
Bob Mooreb8e4d892006-01-27 16:43:00 -05001439 ACPI_ERROR((AE_INFO,
1440 "Maximum GPE number from FADT is too large: 0x%X",
1441 gpe_number_max));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001442 status = AE_BAD_VALUE;
1443 goto cleanup;
1444 }
1445
Len Brown4be44fc2005-08-05 00:44:28 -04001446 cleanup:
1447 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
1448 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001449}