blob: 73c058e2f5c213b9aa3b8e01f958bc7f81b52d26 [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/*
Len Brown75a44ce2008-04-23 23:00:13 -04008 * Copyright (C) 2000 - 2008, 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>
45#include <acpi/acevents.h>
46#include <acpi/acnamesp.h>
47
48#define _COMPONENT ACPI_EVENTS
Len Brown4be44fc2005-08-05 00:44:28 -040049ACPI_MODULE_NAME("evgpeblk")
Linus Torvalds1da177e2005-04-16 15:20:36 -070050
Robert Moore44f6c012005-04-18 22:49:35 -040051/* Local prototypes */
Len Brown4be44fc2005-08-05 00:44:28 -040052static acpi_status
53acpi_ev_save_method_info(acpi_handle obj_handle,
54 u32 level, void *obj_desc, void **return_value);
Robert Moore44f6c012005-04-18 22:49:35 -040055
56static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -040057acpi_ev_match_prw_and_gpe(acpi_handle obj_handle,
58 u32 level, void *info, void **return_value);
59
60static struct acpi_gpe_xrupt_info *acpi_ev_get_gpe_xrupt_block(u32
61 interrupt_number);
Robert Moore44f6c012005-04-18 22:49:35 -040062
63static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -040064acpi_ev_delete_gpe_xrupt(struct acpi_gpe_xrupt_info *gpe_xrupt);
Robert Moore44f6c012005-04-18 22:49:35 -040065
66static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -040067acpi_ev_install_gpe_block(struct acpi_gpe_block_info *gpe_block,
68 u32 interrupt_number);
Robert Moore44f6c012005-04-18 22:49:35 -040069
70static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -040071acpi_ev_create_gpe_info_blocks(struct acpi_gpe_block_info *gpe_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -070072
73/*******************************************************************************
74 *
75 * FUNCTION: acpi_ev_valid_gpe_event
76 *
77 * PARAMETERS: gpe_event_info - Info for this GPE
78 *
79 * RETURN: TRUE if the gpe_event is valid
80 *
Bob Moore96db2552005-11-02 00:00:00 -050081 * DESCRIPTION: Validate a GPE event. DO NOT CALL FROM INTERRUPT LEVEL.
Linus Torvalds1da177e2005-04-16 15:20:36 -070082 * Should be called only when the GPE lists are semaphore locked
83 * and not subject to change.
84 *
85 ******************************************************************************/
86
Len Brown4be44fc2005-08-05 00:44:28 -040087u8 acpi_ev_valid_gpe_event(struct acpi_gpe_event_info *gpe_event_info)
Linus Torvalds1da177e2005-04-16 15:20:36 -070088{
Len Brown4be44fc2005-08-05 00:44:28 -040089 struct acpi_gpe_xrupt_info *gpe_xrupt_block;
90 struct acpi_gpe_block_info *gpe_block;
Linus Torvalds1da177e2005-04-16 15:20:36 -070091
Len Brown4be44fc2005-08-05 00:44:28 -040092 ACPI_FUNCTION_ENTRY();
Linus Torvalds1da177e2005-04-16 15:20:36 -070093
94 /* No need for spin lock since we are not changing any list elements */
95
96 /* Walk the GPE interrupt levels */
97
98 gpe_xrupt_block = acpi_gbl_gpe_xrupt_list_head;
99 while (gpe_xrupt_block) {
100 gpe_block = gpe_xrupt_block->gpe_block_list_head;
101
102 /* Walk the GPE blocks on this interrupt level */
103
104 while (gpe_block) {
105 if ((&gpe_block->event_info[0] <= gpe_event_info) &&
Len Brown4be44fc2005-08-05 00:44:28 -0400106 (&gpe_block->
107 event_info[((acpi_size) gpe_block->
108 register_count) * 8] >
109 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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 *
128 * RETURN: Status
129 *
130 * DESCRIPTION: Walk the GPE lists.
131 *
132 ******************************************************************************/
133
Bob Moore61686122006-03-17 16:44:00 -0500134acpi_status acpi_ev_walk_gpe_list(acpi_gpe_callback gpe_walk_callback)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135{
Len Brown4be44fc2005-08-05 00:44:28 -0400136 struct acpi_gpe_block_info *gpe_block;
137 struct acpi_gpe_xrupt_info *gpe_xrupt_info;
138 acpi_status status = AE_OK;
Bob Mooreb8e4d892006-01-27 16:43:00 -0500139 acpi_cpu_flags flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140
Bob Mooreb229cf92006-04-21 17:15:00 -0400141 ACPI_FUNCTION_TRACE(ev_walk_gpe_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142
Len Brown4be44fc2005-08-05 00:44:28 -0400143 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144
145 /* Walk the interrupt level descriptor list */
146
147 gpe_xrupt_info = acpi_gbl_gpe_xrupt_list_head;
148 while (gpe_xrupt_info) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400149
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150 /* Walk all Gpe Blocks attached to this interrupt level */
151
152 gpe_block = gpe_xrupt_info->gpe_block_list_head;
153 while (gpe_block) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400154
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155 /* One callback per GPE block */
156
Len Brown4be44fc2005-08-05 00:44:28 -0400157 status = gpe_walk_callback(gpe_xrupt_info, gpe_block);
158 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159 goto unlock_and_exit;
160 }
161
162 gpe_block = gpe_block->next;
163 }
164
165 gpe_xrupt_info = gpe_xrupt_info->next;
166 }
167
Len Brown4be44fc2005-08-05 00:44:28 -0400168 unlock_and_exit:
169 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
170 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171}
172
Robert Moore44f6c012005-04-18 22:49:35 -0400173/*******************************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174 *
175 * FUNCTION: acpi_ev_delete_gpe_handlers
176 *
177 * PARAMETERS: gpe_xrupt_info - GPE Interrupt info
178 * gpe_block - Gpe Block info
179 *
180 * RETURN: Status
181 *
182 * DESCRIPTION: Delete all Handler objects found in the GPE data structs.
183 * Used only prior to termination.
184 *
185 ******************************************************************************/
186
187acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400188acpi_ev_delete_gpe_handlers(struct acpi_gpe_xrupt_info *gpe_xrupt_info,
189 struct acpi_gpe_block_info *gpe_block)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190{
Len Brown4be44fc2005-08-05 00:44:28 -0400191 struct acpi_gpe_event_info *gpe_event_info;
Bob Moore67a119f2008-06-10 13:42:13 +0800192 u32 i;
193 u32 j;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194
Bob Mooreb229cf92006-04-21 17:15:00 -0400195 ACPI_FUNCTION_TRACE(ev_delete_gpe_handlers);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196
197 /* Examine each GPE Register within the block */
198
199 for (i = 0; i < gpe_block->register_count; i++) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400200
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201 /* Now look at the individual GPEs in this byte register */
202
203 for (j = 0; j < ACPI_GPE_REGISTER_WIDTH; j++) {
Len Brown4be44fc2005-08-05 00:44:28 -0400204 gpe_event_info =
205 &gpe_block->
Bob Moore67a119f2008-06-10 13:42:13 +0800206 event_info[((acpi_size) i *
207 ACPI_GPE_REGISTER_WIDTH) + j];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208
Robert Moore44f6c012005-04-18 22:49:35 -0400209 if ((gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) ==
Len Brown4be44fc2005-08-05 00:44:28 -0400210 ACPI_GPE_DISPATCH_HANDLER) {
Bob Moore83135242006-10-03 00:00:00 -0400211 ACPI_FREE(gpe_event_info->dispatch.handler);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212 gpe_event_info->dispatch.handler = NULL;
Len Brown4be44fc2005-08-05 00:44:28 -0400213 gpe_event_info->flags &=
214 ~ACPI_GPE_DISPATCH_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215 }
216 }
217 }
218
Len Brown4be44fc2005-08-05 00:44:28 -0400219 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220}
221
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222/*******************************************************************************
223 *
224 * FUNCTION: acpi_ev_save_method_info
225 *
226 * PARAMETERS: Callback from walk_namespace
227 *
228 * RETURN: Status
229 *
230 * DESCRIPTION: Called from acpi_walk_namespace. Expects each object to be a
231 * control method under the _GPE portion of the namespace.
232 * Extract the name and GPE type from the object, saving this
233 * information for quick lookup during GPE dispatch
234 *
235 * The name of each GPE control method is of the form:
236 * "_Lxx" or "_Exx"
237 * Where:
238 * L - means that the GPE is level triggered
239 * E - means that the GPE is edge triggered
240 * xx - is the GPE number [in HEX]
241 *
242 ******************************************************************************/
243
244static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400245acpi_ev_save_method_info(acpi_handle obj_handle,
246 u32 level, void *obj_desc, void **return_value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247{
Len Brown4be44fc2005-08-05 00:44:28 -0400248 struct acpi_gpe_block_info *gpe_block = (void *)obj_desc;
249 struct acpi_gpe_event_info *gpe_event_info;
250 u32 gpe_number;
251 char name[ACPI_NAME_SIZE + 1];
252 u8 type;
253 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254
Bob Mooreb229cf92006-04-21 17:15:00 -0400255 ACPI_FUNCTION_TRACE(ev_save_method_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256
257 /*
258 * _Lxx and _Exx GPE method support
259 *
260 * 1) Extract the name from the object and convert to a string
261 */
Len Brown4be44fc2005-08-05 00:44:28 -0400262 ACPI_MOVE_32_TO_32(name,
263 &((struct acpi_namespace_node *)obj_handle)->name.
264 integer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265 name[ACPI_NAME_SIZE] = 0;
266
267 /*
268 * 2) Edge/Level determination is based on the 2nd character
269 * of the method name
270 *
Bob Moore96db2552005-11-02 00:00:00 -0500271 * NOTE: Default GPE type is RUNTIME. May be changed later to WAKE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272 * if a _PRW object is found that points to this GPE.
273 */
274 switch (name[1]) {
275 case 'L':
276 type = ACPI_GPE_LEVEL_TRIGGERED;
277 break;
278
279 case 'E':
280 type = ACPI_GPE_EDGE_TRIGGERED;
281 break;
282
283 default:
284 /* Unknown method type, just ignore it! */
285
Bob Mooreb229cf92006-04-21 17:15:00 -0400286 ACPI_DEBUG_PRINT((ACPI_DB_LOAD,
287 "Ignoring unknown GPE method type: %s (name not of form _Lxx or _Exx)",
288 name));
Len Brown4be44fc2005-08-05 00:44:28 -0400289 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290 }
291
292 /* Convert the last two characters of the name to the GPE Number */
293
Len Brown4be44fc2005-08-05 00:44:28 -0400294 gpe_number = ACPI_STRTOUL(&name[2], NULL, 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 if (gpe_number == ACPI_UINT32_MAX) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400296
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297 /* Conversion failed; invalid method, just ignore it */
298
Bob Mooreb229cf92006-04-21 17:15:00 -0400299 ACPI_DEBUG_PRINT((ACPI_DB_LOAD,
300 "Could not extract GPE number from name: %s (name is not of form _Lxx or _Exx)",
301 name));
Len Brown4be44fc2005-08-05 00:44:28 -0400302 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303 }
304
305 /* Ensure that we have a valid GPE number for this GPE block */
306
307 if ((gpe_number < gpe_block->block_base_number) ||
Len Brown4be44fc2005-08-05 00:44:28 -0400308 (gpe_number >=
309 (gpe_block->block_base_number +
310 (gpe_block->register_count * 8)))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311 /*
312 * Not valid for this GPE block, just ignore it
313 * However, it may be valid for a different GPE block, since GPE0 and GPE1
314 * methods both appear under \_GPE.
315 */
Len Brown4be44fc2005-08-05 00:44:28 -0400316 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317 }
318
319 /*
320 * Now we can add this information to the gpe_event_info block
Bob Moore96db2552005-11-02 00:00:00 -0500321 * for use during dispatch of this GPE. Default type is RUNTIME, although
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322 * this may change when the _PRW methods are executed later.
323 */
Len Brown4be44fc2005-08-05 00:44:28 -0400324 gpe_event_info =
325 &gpe_block->event_info[gpe_number - gpe_block->block_base_number];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326
Bob Moore96db2552005-11-02 00:00:00 -0500327 gpe_event_info->flags = (u8)
328 (type | ACPI_GPE_DISPATCH_METHOD | ACPI_GPE_TYPE_RUNTIME);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329
Len Brown4be44fc2005-08-05 00:44:28 -0400330 gpe_event_info->dispatch.method_node =
331 (struct acpi_namespace_node *)obj_handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332
333 /* Update enable mask, but don't enable the HW GPE as of yet */
334
Len Brown4be44fc2005-08-05 00:44:28 -0400335 status = acpi_ev_enable_gpe(gpe_event_info, FALSE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336
Len Brown4be44fc2005-08-05 00:44:28 -0400337 ACPI_DEBUG_PRINT((ACPI_DB_LOAD,
338 "Registered GPE method %s as GPE number 0x%.2X\n",
339 name, gpe_number));
340 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341}
342
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343/*******************************************************************************
344 *
345 * FUNCTION: acpi_ev_match_prw_and_gpe
346 *
347 * PARAMETERS: Callback from walk_namespace
348 *
Bob Moore96db2552005-11-02 00:00:00 -0500349 * RETURN: Status. NOTE: We ignore errors so that the _PRW walk is
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350 * not aborted on a single _PRW failure.
351 *
352 * DESCRIPTION: Called from acpi_walk_namespace. Expects each object to be a
Bob Moore96db2552005-11-02 00:00:00 -0500353 * Device. Run the _PRW method. If present, extract the GPE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354 * number and mark the GPE as a WAKE GPE.
355 *
356 ******************************************************************************/
357
358static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400359acpi_ev_match_prw_and_gpe(acpi_handle obj_handle,
360 u32 level, void *info, void **return_value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361{
Len Brown4be44fc2005-08-05 00:44:28 -0400362 struct acpi_gpe_walk_info *gpe_info = (void *)info;
363 struct acpi_namespace_node *gpe_device;
364 struct acpi_gpe_block_info *gpe_block;
365 struct acpi_namespace_node *target_gpe_device;
366 struct acpi_gpe_event_info *gpe_event_info;
367 union acpi_operand_object *pkg_desc;
368 union acpi_operand_object *obj_desc;
369 u32 gpe_number;
370 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371
Bob Mooreb229cf92006-04-21 17:15:00 -0400372 ACPI_FUNCTION_TRACE(ev_match_prw_and_gpe);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373
374 /* Check for a _PRW method under this device */
375
Len Brown4be44fc2005-08-05 00:44:28 -0400376 status = acpi_ut_evaluate_object(obj_handle, METHOD_NAME__PRW,
377 ACPI_BTYPE_PACKAGE, &pkg_desc);
378 if (ACPI_FAILURE(status)) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400379
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380 /* Ignore all errors from _PRW, we don't want to abort the subsystem */
381
Len Brown4be44fc2005-08-05 00:44:28 -0400382 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383 }
384
385 /* The returned _PRW package must have at least two elements */
386
387 if (pkg_desc->package.count < 2) {
388 goto cleanup;
389 }
390
391 /* Extract pointers from the input context */
392
393 gpe_device = gpe_info->gpe_device;
394 gpe_block = gpe_info->gpe_block;
395
396 /*
397 * The _PRW object must return a package, we are only interested
398 * in the first element
399 */
400 obj_desc = pkg_desc->package.elements[0];
401
Len Brown4be44fc2005-08-05 00:44:28 -0400402 if (ACPI_GET_OBJECT_TYPE(obj_desc) == ACPI_TYPE_INTEGER) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400403
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 /* Use FADT-defined GPE device (from definition of _PRW) */
405
406 target_gpe_device = acpi_gbl_fadt_gpe_device;
407
408 /* Integer is the GPE number in the FADT described GPE blocks */
409
410 gpe_number = (u32) obj_desc->integer.value;
Len Brown4be44fc2005-08-05 00:44:28 -0400411 } else if (ACPI_GET_OBJECT_TYPE(obj_desc) == ACPI_TYPE_PACKAGE) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400412
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413 /* Package contains a GPE reference and GPE number within a GPE block */
414
415 if ((obj_desc->package.count < 2) ||
Len Brown4be44fc2005-08-05 00:44:28 -0400416 (ACPI_GET_OBJECT_TYPE(obj_desc->package.elements[0]) !=
417 ACPI_TYPE_LOCAL_REFERENCE)
418 || (ACPI_GET_OBJECT_TYPE(obj_desc->package.elements[1]) !=
419 ACPI_TYPE_INTEGER)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420 goto cleanup;
421 }
422
423 /* Get GPE block reference and decode */
424
Len Brown4be44fc2005-08-05 00:44:28 -0400425 target_gpe_device =
426 obj_desc->package.elements[0]->reference.node;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427 gpe_number = (u32) obj_desc->package.elements[1]->integer.value;
Len Brown4be44fc2005-08-05 00:44:28 -0400428 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 /* Unknown type, just ignore it */
430
431 goto cleanup;
432 }
433
434 /*
435 * Is this GPE within this block?
436 *
437 * TRUE iff these conditions are true:
438 * 1) The GPE devices match.
439 * 2) The GPE index(number) is within the range of the Gpe Block
440 * associated with the GPE device.
441 */
442 if ((gpe_device == target_gpe_device) &&
Len Brown4be44fc2005-08-05 00:44:28 -0400443 (gpe_number >= gpe_block->block_base_number) &&
444 (gpe_number <
445 gpe_block->block_base_number + (gpe_block->register_count * 8))) {
446 gpe_event_info =
447 &gpe_block->event_info[gpe_number -
448 gpe_block->block_base_number];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449
450 /* Mark GPE for WAKE-ONLY but WAKE_DISABLED */
451
Len Brown4be44fc2005-08-05 00:44:28 -0400452 gpe_event_info->flags &=
453 ~(ACPI_GPE_WAKE_ENABLED | ACPI_GPE_RUN_ENABLED);
Bob Moore96db2552005-11-02 00:00:00 -0500454
Len Brown4be44fc2005-08-05 00:44:28 -0400455 status =
456 acpi_ev_set_gpe_type(gpe_event_info, ACPI_GPE_TYPE_WAKE);
457 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458 goto cleanup;
459 }
Len Brown4be44fc2005-08-05 00:44:28 -0400460 status =
461 acpi_ev_update_gpe_enable_masks(gpe_event_info,
462 ACPI_GPE_DISABLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463 }
464
Len Brown4be44fc2005-08-05 00:44:28 -0400465 cleanup:
466 acpi_ut_remove_reference(pkg_desc);
467 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468}
469
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470/*******************************************************************************
471 *
472 * FUNCTION: acpi_ev_get_gpe_xrupt_block
473 *
Robert Moore6f42ccf2005-05-13 00:00:00 -0400474 * PARAMETERS: interrupt_number - Interrupt for a GPE block
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475 *
476 * RETURN: A GPE interrupt block
477 *
Bob Moore96db2552005-11-02 00:00:00 -0500478 * DESCRIPTION: Get or Create a GPE interrupt block. There is one interrupt
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479 * block per unique interrupt level used for GPEs.
480 * Should be called only when the GPE lists are semaphore locked
481 * and not subject to change.
482 *
483 ******************************************************************************/
484
Len Brown4be44fc2005-08-05 00:44:28 -0400485static struct acpi_gpe_xrupt_info *acpi_ev_get_gpe_xrupt_block(u32
486 interrupt_number)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487{
Len Brown4be44fc2005-08-05 00:44:28 -0400488 struct acpi_gpe_xrupt_info *next_gpe_xrupt;
489 struct acpi_gpe_xrupt_info *gpe_xrupt;
490 acpi_status status;
Bob Mooreb8e4d892006-01-27 16:43:00 -0500491 acpi_cpu_flags flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492
Bob Mooreb229cf92006-04-21 17:15:00 -0400493 ACPI_FUNCTION_TRACE(ev_get_gpe_xrupt_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494
Robert Moore44f6c012005-04-18 22:49:35 -0400495 /* No need for lock since we are not changing any list elements here */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496
497 next_gpe_xrupt = acpi_gbl_gpe_xrupt_list_head;
498 while (next_gpe_xrupt) {
Robert Moore6f42ccf2005-05-13 00:00:00 -0400499 if (next_gpe_xrupt->interrupt_number == interrupt_number) {
Len Brown4be44fc2005-08-05 00:44:28 -0400500 return_PTR(next_gpe_xrupt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 }
502
503 next_gpe_xrupt = next_gpe_xrupt->next;
504 }
505
506 /* Not found, must allocate a new xrupt descriptor */
507
Bob Moore83135242006-10-03 00:00:00 -0400508 gpe_xrupt = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_gpe_xrupt_info));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 if (!gpe_xrupt) {
Len Brown4be44fc2005-08-05 00:44:28 -0400510 return_PTR(NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511 }
512
Robert Moore6f42ccf2005-05-13 00:00:00 -0400513 gpe_xrupt->interrupt_number = interrupt_number;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514
515 /* Install new interrupt descriptor with spin lock */
516
Len Brown4be44fc2005-08-05 00:44:28 -0400517 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518 if (acpi_gbl_gpe_xrupt_list_head) {
519 next_gpe_xrupt = acpi_gbl_gpe_xrupt_list_head;
520 while (next_gpe_xrupt->next) {
521 next_gpe_xrupt = next_gpe_xrupt->next;
522 }
523
524 next_gpe_xrupt->next = gpe_xrupt;
525 gpe_xrupt->previous = next_gpe_xrupt;
Len Brown4be44fc2005-08-05 00:44:28 -0400526 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527 acpi_gbl_gpe_xrupt_list_head = gpe_xrupt;
528 }
Len Brown4be44fc2005-08-05 00:44:28 -0400529 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530
531 /* Install new interrupt handler if not SCI_INT */
532
Bob Mooref3d2e782007-02-02 19:48:18 +0300533 if (interrupt_number != acpi_gbl_FADT.sci_interrupt) {
Len Brown4be44fc2005-08-05 00:44:28 -0400534 status = acpi_os_install_interrupt_handler(interrupt_number,
535 acpi_ev_gpe_xrupt_handler,
536 gpe_xrupt);
537 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500538 ACPI_ERROR((AE_INFO,
539 "Could not install GPE interrupt handler at level 0x%X",
540 interrupt_number));
Len Brown4be44fc2005-08-05 00:44:28 -0400541 return_PTR(NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542 }
543 }
544
Len Brown4be44fc2005-08-05 00:44:28 -0400545 return_PTR(gpe_xrupt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546}
547
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548/*******************************************************************************
549 *
550 * FUNCTION: acpi_ev_delete_gpe_xrupt
551 *
552 * PARAMETERS: gpe_xrupt - A GPE interrupt info block
553 *
554 * RETURN: Status
555 *
556 * DESCRIPTION: Remove and free a gpe_xrupt block. Remove an associated
557 * interrupt handler if not the SCI interrupt.
558 *
559 ******************************************************************************/
560
561static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400562acpi_ev_delete_gpe_xrupt(struct acpi_gpe_xrupt_info *gpe_xrupt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563{
Len Brown4be44fc2005-08-05 00:44:28 -0400564 acpi_status status;
Bob Mooreb8e4d892006-01-27 16:43:00 -0500565 acpi_cpu_flags flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566
Bob Mooreb229cf92006-04-21 17:15:00 -0400567 ACPI_FUNCTION_TRACE(ev_delete_gpe_xrupt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568
569 /* We never want to remove the SCI interrupt handler */
570
Bob Mooref3d2e782007-02-02 19:48:18 +0300571 if (gpe_xrupt->interrupt_number == acpi_gbl_FADT.sci_interrupt) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572 gpe_xrupt->gpe_block_list_head = NULL;
Len Brown4be44fc2005-08-05 00:44:28 -0400573 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574 }
575
576 /* Disable this interrupt */
577
Bob Moore96db2552005-11-02 00:00:00 -0500578 status =
579 acpi_os_remove_interrupt_handler(gpe_xrupt->interrupt_number,
580 acpi_ev_gpe_xrupt_handler);
Len Brown4be44fc2005-08-05 00:44:28 -0400581 if (ACPI_FAILURE(status)) {
582 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583 }
584
585 /* Unlink the interrupt block with lock */
586
Len Brown4be44fc2005-08-05 00:44:28 -0400587 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588 if (gpe_xrupt->previous) {
589 gpe_xrupt->previous->next = gpe_xrupt->next;
Bob Mooree0b91052007-04-03 20:00:29 -0400590 } else {
591 /* No previous, update list head */
592
593 acpi_gbl_gpe_xrupt_list_head = gpe_xrupt->next;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594 }
595
596 if (gpe_xrupt->next) {
597 gpe_xrupt->next->previous = gpe_xrupt->previous;
598 }
Len Brown4be44fc2005-08-05 00:44:28 -0400599 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600
601 /* Free the block */
602
Bob Moore83135242006-10-03 00:00:00 -0400603 ACPI_FREE(gpe_xrupt);
Len Brown4be44fc2005-08-05 00:44:28 -0400604 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605}
606
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607/*******************************************************************************
608 *
609 * FUNCTION: acpi_ev_install_gpe_block
610 *
611 * PARAMETERS: gpe_block - New GPE block
Robert Moore6f42ccf2005-05-13 00:00:00 -0400612 * interrupt_number - Xrupt to be associated with this GPE block
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 *
614 * RETURN: Status
615 *
616 * DESCRIPTION: Install new GPE block with mutex support
617 *
618 ******************************************************************************/
619
620static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400621acpi_ev_install_gpe_block(struct acpi_gpe_block_info *gpe_block,
622 u32 interrupt_number)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623{
Len Brown4be44fc2005-08-05 00:44:28 -0400624 struct acpi_gpe_block_info *next_gpe_block;
625 struct acpi_gpe_xrupt_info *gpe_xrupt_block;
626 acpi_status status;
Bob Mooreb8e4d892006-01-27 16:43:00 -0500627 acpi_cpu_flags flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628
Bob Mooreb229cf92006-04-21 17:15:00 -0400629 ACPI_FUNCTION_TRACE(ev_install_gpe_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630
Len Brown4be44fc2005-08-05 00:44:28 -0400631 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
632 if (ACPI_FAILURE(status)) {
633 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634 }
635
Len Brown4be44fc2005-08-05 00:44:28 -0400636 gpe_xrupt_block = acpi_ev_get_gpe_xrupt_block(interrupt_number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637 if (!gpe_xrupt_block) {
638 status = AE_NO_MEMORY;
639 goto unlock_and_exit;
640 }
641
Robert Moore44f6c012005-04-18 22:49:35 -0400642 /* Install the new block at the end of the list with lock */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643
Len Brown4be44fc2005-08-05 00:44:28 -0400644 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645 if (gpe_xrupt_block->gpe_block_list_head) {
646 next_gpe_block = gpe_xrupt_block->gpe_block_list_head;
647 while (next_gpe_block->next) {
648 next_gpe_block = next_gpe_block->next;
649 }
650
651 next_gpe_block->next = gpe_block;
652 gpe_block->previous = next_gpe_block;
Len Brown4be44fc2005-08-05 00:44:28 -0400653 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654 gpe_xrupt_block->gpe_block_list_head = gpe_block;
655 }
656
657 gpe_block->xrupt_block = gpe_xrupt_block;
Len Brown4be44fc2005-08-05 00:44:28 -0400658 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659
Len Brown4be44fc2005-08-05 00:44:28 -0400660 unlock_and_exit:
661 status = acpi_ut_release_mutex(ACPI_MTX_EVENTS);
662 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663}
664
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665/*******************************************************************************
666 *
667 * FUNCTION: acpi_ev_delete_gpe_block
668 *
669 * PARAMETERS: gpe_block - Existing GPE block
670 *
671 * RETURN: Status
672 *
673 * DESCRIPTION: Remove a GPE block
674 *
675 ******************************************************************************/
676
Len Brown4be44fc2005-08-05 00:44:28 -0400677acpi_status acpi_ev_delete_gpe_block(struct acpi_gpe_block_info *gpe_block)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678{
Len Brown4be44fc2005-08-05 00:44:28 -0400679 acpi_status status;
Bob Mooreb8e4d892006-01-27 16:43:00 -0500680 acpi_cpu_flags flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681
Bob Mooreb229cf92006-04-21 17:15:00 -0400682 ACPI_FUNCTION_TRACE(ev_install_gpe_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683
Len Brown4be44fc2005-08-05 00:44:28 -0400684 status = acpi_ut_acquire_mutex(ACPI_MTX_EVENTS);
685 if (ACPI_FAILURE(status)) {
686 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687 }
688
689 /* Disable all GPEs in this block */
690
Len Brown4be44fc2005-08-05 00:44:28 -0400691 status = acpi_hw_disable_gpe_block(gpe_block->xrupt_block, gpe_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692
693 if (!gpe_block->previous && !gpe_block->next) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400694
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695 /* This is the last gpe_block on this interrupt */
696
Len Brown4be44fc2005-08-05 00:44:28 -0400697 status = acpi_ev_delete_gpe_xrupt(gpe_block->xrupt_block);
698 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699 goto unlock_and_exit;
700 }
Len Brown4be44fc2005-08-05 00:44:28 -0400701 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702 /* Remove the block on this interrupt with lock */
703
Len Brown4be44fc2005-08-05 00:44:28 -0400704 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705 if (gpe_block->previous) {
706 gpe_block->previous->next = gpe_block->next;
Len Brown4be44fc2005-08-05 00:44:28 -0400707 } else {
708 gpe_block->xrupt_block->gpe_block_list_head =
709 gpe_block->next;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710 }
711
712 if (gpe_block->next) {
713 gpe_block->next->previous = gpe_block->previous;
714 }
Len Brown4be44fc2005-08-05 00:44:28 -0400715 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716 }
717
718 /* Free the gpe_block */
719
Bob Moore83135242006-10-03 00:00:00 -0400720 ACPI_FREE(gpe_block->register_info);
721 ACPI_FREE(gpe_block->event_info);
722 ACPI_FREE(gpe_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723
Len Brown4be44fc2005-08-05 00:44:28 -0400724 unlock_and_exit:
725 status = acpi_ut_release_mutex(ACPI_MTX_EVENTS);
726 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727}
728
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729/*******************************************************************************
730 *
731 * FUNCTION: acpi_ev_create_gpe_info_blocks
732 *
733 * PARAMETERS: gpe_block - New GPE block
734 *
735 * RETURN: Status
736 *
737 * DESCRIPTION: Create the register_info and event_info blocks for this GPE block
738 *
739 ******************************************************************************/
740
741static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400742acpi_ev_create_gpe_info_blocks(struct acpi_gpe_block_info *gpe_block)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743{
Len Brown4be44fc2005-08-05 00:44:28 -0400744 struct acpi_gpe_register_info *gpe_register_info = NULL;
745 struct acpi_gpe_event_info *gpe_event_info = NULL;
746 struct acpi_gpe_event_info *this_event;
747 struct acpi_gpe_register_info *this_register;
Bob Moore67a119f2008-06-10 13:42:13 +0800748 u32 i;
749 u32 j;
Len Brown4be44fc2005-08-05 00:44:28 -0400750 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751
Bob Mooreb229cf92006-04-21 17:15:00 -0400752 ACPI_FUNCTION_TRACE(ev_create_gpe_info_blocks);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753
754 /* Allocate the GPE register information block */
755
Bob Moore83135242006-10-03 00:00:00 -0400756 gpe_register_info = ACPI_ALLOCATE_ZEROED((acpi_size) gpe_block->
757 register_count *
758 sizeof(struct
759 acpi_gpe_register_info));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760 if (!gpe_register_info) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500761 ACPI_ERROR((AE_INFO,
Bob Mooreb229cf92006-04-21 17:15:00 -0400762 "Could not allocate the GpeRegisterInfo table"));
Len Brown4be44fc2005-08-05 00:44:28 -0400763 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764 }
765
766 /*
767 * Allocate the GPE event_info block. There are eight distinct GPEs
Bob Moore96db2552005-11-02 00:00:00 -0500768 * per register. Initialization to zeros is sufficient.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769 */
Bob Moore83135242006-10-03 00:00:00 -0400770 gpe_event_info = ACPI_ALLOCATE_ZEROED(((acpi_size) gpe_block->
771 register_count *
772 ACPI_GPE_REGISTER_WIDTH) *
773 sizeof(struct
774 acpi_gpe_event_info));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775 if (!gpe_event_info) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500776 ACPI_ERROR((AE_INFO,
Bob Mooreb229cf92006-04-21 17:15:00 -0400777 "Could not allocate the GpeEventInfo table"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778 status = AE_NO_MEMORY;
779 goto error_exit;
780 }
781
782 /* Save the new Info arrays in the GPE block */
783
784 gpe_block->register_info = gpe_register_info;
Len Brown4be44fc2005-08-05 00:44:28 -0400785 gpe_block->event_info = gpe_event_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786
787 /*
Bob Moore96db2552005-11-02 00:00:00 -0500788 * Initialize the GPE Register and Event structures. A goal of these
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789 * tables is to hide the fact that there are two separate GPE register sets
Bob Moore96db2552005-11-02 00:00:00 -0500790 * in a given GPE hardware block, the status registers occupy the first half,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791 * and the enable registers occupy the second half.
792 */
793 this_register = gpe_register_info;
Len Brown4be44fc2005-08-05 00:44:28 -0400794 this_event = gpe_event_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795
796 for (i = 0; i < gpe_block->register_count; i++) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400797
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798 /* Init the register_info for this GPE register (8 GPEs) */
799
Len Brown4be44fc2005-08-05 00:44:28 -0400800 this_register->base_gpe_number =
801 (u8) (gpe_block->block_base_number +
802 (i * ACPI_GPE_REGISTER_WIDTH));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803
Bob Moore59fa8502007-02-02 19:48:23 +0300804 this_register->status_address.address =
805 gpe_block->block_address.address + i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806
Bob Moore59fa8502007-02-02 19:48:23 +0300807 this_register->enable_address.address =
808 gpe_block->block_address.address + i +
809 gpe_block->register_count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810
Bob Mooref3d2e782007-02-02 19:48:18 +0300811 this_register->status_address.space_id =
812 gpe_block->block_address.space_id;
813 this_register->enable_address.space_id =
814 gpe_block->block_address.space_id;
815 this_register->status_address.bit_width =
Len Brown4be44fc2005-08-05 00:44:28 -0400816 ACPI_GPE_REGISTER_WIDTH;
Bob Mooref3d2e782007-02-02 19:48:18 +0300817 this_register->enable_address.bit_width =
Len Brown4be44fc2005-08-05 00:44:28 -0400818 ACPI_GPE_REGISTER_WIDTH;
Bob Mooref3d2e782007-02-02 19:48:18 +0300819 this_register->status_address.bit_offset =
Len Brown4be44fc2005-08-05 00:44:28 -0400820 ACPI_GPE_REGISTER_WIDTH;
Bob Mooref3d2e782007-02-02 19:48:18 +0300821 this_register->enable_address.bit_offset =
Len Brown4be44fc2005-08-05 00:44:28 -0400822 ACPI_GPE_REGISTER_WIDTH;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823
824 /* Init the event_info for each GPE within this register */
825
826 for (j = 0; j < ACPI_GPE_REGISTER_WIDTH; j++) {
Alexey Starikovskiy69874162007-02-02 19:48:19 +0300827 this_event->gpe_number =
828 (u8) (this_register->base_gpe_number + j);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829 this_event->register_info = this_register;
830 this_event++;
831 }
832
Bob Moore96db2552005-11-02 00:00:00 -0500833 /* Disable all GPEs within this register */
834
Len Brown4be44fc2005-08-05 00:44:28 -0400835 status = acpi_hw_low_level_write(ACPI_GPE_REGISTER_WIDTH, 0x00,
836 &this_register->
837 enable_address);
838 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839 goto error_exit;
840 }
841
Bob Moore96db2552005-11-02 00:00:00 -0500842 /* Clear any pending GPE events within this register */
843
Len Brown4be44fc2005-08-05 00:44:28 -0400844 status = acpi_hw_low_level_write(ACPI_GPE_REGISTER_WIDTH, 0xFF,
845 &this_register->
846 status_address);
847 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700848 goto error_exit;
849 }
850
851 this_register++;
852 }
853
Len Brown4be44fc2005-08-05 00:44:28 -0400854 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855
Len Brown4be44fc2005-08-05 00:44:28 -0400856 error_exit:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857 if (gpe_register_info) {
Bob Moore83135242006-10-03 00:00:00 -0400858 ACPI_FREE(gpe_register_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859 }
860 if (gpe_event_info) {
Bob Moore83135242006-10-03 00:00:00 -0400861 ACPI_FREE(gpe_event_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862 }
863
Len Brown4be44fc2005-08-05 00:44:28 -0400864 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865}
866
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867/*******************************************************************************
868 *
869 * FUNCTION: acpi_ev_create_gpe_block
870 *
871 * PARAMETERS: gpe_device - Handle to the parent GPE block
872 * gpe_block_address - Address and space_iD
873 * register_count - Number of GPE register pairs in the block
874 * gpe_block_base_number - Starting GPE number for the block
Robert Moore6f42ccf2005-05-13 00:00:00 -0400875 * interrupt_number - H/W interrupt for the block
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876 * return_gpe_block - Where the new block descriptor is returned
877 *
878 * RETURN: Status
879 *
Bob Moore96db2552005-11-02 00:00:00 -0500880 * DESCRIPTION: Create and Install a block of GPE registers. All GPEs within
881 * the block are disabled at exit.
882 * Note: Assumes namespace is locked.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700883 *
884 ******************************************************************************/
885
886acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400887acpi_ev_create_gpe_block(struct acpi_namespace_node *gpe_device,
888 struct acpi_generic_address *gpe_block_address,
889 u32 register_count,
890 u8 gpe_block_base_number,
891 u32 interrupt_number,
892 struct acpi_gpe_block_info **return_gpe_block)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893{
Len Brown4be44fc2005-08-05 00:44:28 -0400894 acpi_status status;
Bob Moore96db2552005-11-02 00:00:00 -0500895 struct acpi_gpe_block_info *gpe_block;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896
Bob Mooreb229cf92006-04-21 17:15:00 -0400897 ACPI_FUNCTION_TRACE(ev_create_gpe_block);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898
899 if (!register_count) {
Len Brown4be44fc2005-08-05 00:44:28 -0400900 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901 }
902
903 /* Allocate a new GPE block */
904
Bob Moore83135242006-10-03 00:00:00 -0400905 gpe_block = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_gpe_block_info));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700906 if (!gpe_block) {
Len Brown4be44fc2005-08-05 00:44:28 -0400907 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700908 }
909
910 /* Initialize the new GPE block */
911
Bob Moore96db2552005-11-02 00:00:00 -0500912 gpe_block->node = gpe_device;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700913 gpe_block->register_count = register_count;
914 gpe_block->block_base_number = gpe_block_base_number;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915
Len Brown4be44fc2005-08-05 00:44:28 -0400916 ACPI_MEMCPY(&gpe_block->block_address, gpe_block_address,
917 sizeof(struct acpi_generic_address));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918
Bob Moore96db2552005-11-02 00:00:00 -0500919 /*
920 * Create the register_info and event_info sub-structures
921 * Note: disables and clears all GPEs in the block
922 */
Len Brown4be44fc2005-08-05 00:44:28 -0400923 status = acpi_ev_create_gpe_info_blocks(gpe_block);
924 if (ACPI_FAILURE(status)) {
Bob Moore83135242006-10-03 00:00:00 -0400925 ACPI_FREE(gpe_block);
Len Brown4be44fc2005-08-05 00:44:28 -0400926 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927 }
928
Bob Moore96db2552005-11-02 00:00:00 -0500929 /* Install the new block in the global lists */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930
Len Brown4be44fc2005-08-05 00:44:28 -0400931 status = acpi_ev_install_gpe_block(gpe_block, interrupt_number);
932 if (ACPI_FAILURE(status)) {
Bob Moore83135242006-10-03 00:00:00 -0400933 ACPI_FREE(gpe_block);
Len Brown4be44fc2005-08-05 00:44:28 -0400934 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935 }
936
937 /* Find all GPE methods (_Lxx, _Exx) for this block */
938
Len Brown4be44fc2005-08-05 00:44:28 -0400939 status = acpi_ns_walk_namespace(ACPI_TYPE_METHOD, gpe_device,
940 ACPI_UINT32_MAX, ACPI_NS_WALK_NO_UNLOCK,
941 acpi_ev_save_method_info, gpe_block,
942 NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943
Bob Moore96db2552005-11-02 00:00:00 -0500944 /* Return the new block */
945
946 if (return_gpe_block) {
947 (*return_gpe_block) = gpe_block;
948 }
949
950 ACPI_DEBUG_PRINT((ACPI_DB_INIT,
951 "GPE %02X to %02X [%4.4s] %u regs on int 0x%X\n",
952 (u32) gpe_block->block_base_number,
953 (u32) (gpe_block->block_base_number +
954 ((gpe_block->register_count *
955 ACPI_GPE_REGISTER_WIDTH) - 1)),
956 gpe_device->name.ascii, gpe_block->register_count,
957 interrupt_number));
958
959 return_ACPI_STATUS(AE_OK);
960}
961
962/*******************************************************************************
963 *
964 * FUNCTION: acpi_ev_initialize_gpe_block
965 *
966 * PARAMETERS: gpe_device - Handle to the parent GPE block
967 * gpe_block - Gpe Block info
968 *
969 * RETURN: Status
970 *
971 * DESCRIPTION: Initialize and enable a GPE block. First find and run any
972 * _PRT methods associated with the block, then enable the
973 * appropriate GPEs.
974 * Note: Assumes namespace is locked.
975 *
976 ******************************************************************************/
977
978acpi_status
979acpi_ev_initialize_gpe_block(struct acpi_namespace_node *gpe_device,
980 struct acpi_gpe_block_info *gpe_block)
981{
982 acpi_status status;
983 struct acpi_gpe_event_info *gpe_event_info;
984 struct acpi_gpe_walk_info gpe_info;
985 u32 wake_gpe_count;
986 u32 gpe_enabled_count;
Bob Moore67a119f2008-06-10 13:42:13 +0800987 u32 i;
988 u32 j;
Bob Moore96db2552005-11-02 00:00:00 -0500989
Bob Mooreb229cf92006-04-21 17:15:00 -0400990 ACPI_FUNCTION_TRACE(ev_initialize_gpe_block);
Bob Moore96db2552005-11-02 00:00:00 -0500991
992 /* Ignore a null GPE block (e.g., if no GPE block 1 exists) */
993
994 if (!gpe_block) {
995 return_ACPI_STATUS(AE_OK);
996 }
997
Linus Torvalds1da177e2005-04-16 15:20:36 -0700998 /*
Bob Moore96db2552005-11-02 00:00:00 -0500999 * Runtime option: Should wake GPEs be enabled at runtime? The default
1000 * is no, they should only be enabled just as the machine goes to sleep.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001001 */
1002 if (acpi_gbl_leave_wake_gpes_disabled) {
1003 /*
Bob Moore96db2552005-11-02 00:00:00 -05001004 * Differentiate runtime vs wake GPEs, via the _PRW control methods.
1005 * Each GPE that has one or more _PRWs that reference it is by
1006 * definition a wake GPE and will not be enabled while the machine
1007 * is running.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008 */
1009 gpe_info.gpe_block = gpe_block;
1010 gpe_info.gpe_device = gpe_device;
1011
Len Brown4be44fc2005-08-05 00:44:28 -04001012 status =
1013 acpi_ns_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,
1014 ACPI_UINT32_MAX, ACPI_NS_WALK_UNLOCK,
1015 acpi_ev_match_prw_and_gpe, &gpe_info,
1016 NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001017 }
1018
1019 /*
Bob Moore96db2552005-11-02 00:00:00 -05001020 * Enable all GPEs in this block that have these attributes:
1021 * 1) are "runtime" or "run/wake" GPEs, and
1022 * 2) have a corresponding _Lxx or _Exx method
1023 *
1024 * Any other GPEs within this block must be enabled via the acpi_enable_gpe()
1025 * external interface.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001026 */
1027 wake_gpe_count = 0;
1028 gpe_enabled_count = 0;
1029
1030 for (i = 0; i < gpe_block->register_count; i++) {
1031 for (j = 0; j < 8; j++) {
Bob Moore52fc0b02006-10-02 00:00:00 -04001032
Linus Torvalds1da177e2005-04-16 15:20:36 -07001033 /* Get the info block for this particular GPE */
1034
Len Brown4be44fc2005-08-05 00:44:28 -04001035 gpe_event_info =
1036 &gpe_block->
Bob Moore67a119f2008-06-10 13:42:13 +08001037 event_info[((acpi_size) i *
1038 ACPI_GPE_REGISTER_WIDTH) + j];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039
Len Brown4be44fc2005-08-05 00:44:28 -04001040 if (((gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) ==
1041 ACPI_GPE_DISPATCH_METHOD)
Len Brownfd350942007-05-09 23:34:35 -04001042 && (gpe_event_info->flags & ACPI_GPE_TYPE_RUNTIME)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001043 gpe_enabled_count++;
1044 }
1045
1046 if (gpe_event_info->flags & ACPI_GPE_TYPE_WAKE) {
1047 wake_gpe_count++;
1048 }
1049 }
1050 }
1051
Len Brown4be44fc2005-08-05 00:44:28 -04001052 ACPI_DEBUG_PRINT((ACPI_DB_INIT,
1053 "Found %u Wake, Enabled %u Runtime GPEs in this block\n",
1054 wake_gpe_count, gpe_enabled_count));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001055
Bob Moore96db2552005-11-02 00:00:00 -05001056 /* Enable all valid runtime GPEs found above */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057
Bob Moore96db2552005-11-02 00:00:00 -05001058 status = acpi_hw_enable_runtime_gpe_block(NULL, gpe_block);
1059 if (ACPI_FAILURE(status)) {
Bob Mooreb229cf92006-04-21 17:15:00 -04001060 ACPI_ERROR((AE_INFO, "Could not enable GPEs in GpeBlock %p",
Bob Mooreb8e4d892006-01-27 16:43:00 -05001061 gpe_block));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001062 }
1063
Bob Moore96db2552005-11-02 00:00:00 -05001064 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001065}
1066
Linus Torvalds1da177e2005-04-16 15:20:36 -07001067/*******************************************************************************
1068 *
1069 * FUNCTION: acpi_ev_gpe_initialize
1070 *
1071 * PARAMETERS: None
1072 *
1073 * RETURN: Status
1074 *
1075 * DESCRIPTION: Initialize the GPE data structures
1076 *
1077 ******************************************************************************/
1078
Len Brown4be44fc2005-08-05 00:44:28 -04001079acpi_status acpi_ev_gpe_initialize(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001080{
Len Brown4be44fc2005-08-05 00:44:28 -04001081 u32 register_count0 = 0;
1082 u32 register_count1 = 0;
1083 u32 gpe_number_max = 0;
1084 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001085
Bob Mooreb229cf92006-04-21 17:15:00 -04001086 ACPI_FUNCTION_TRACE(ev_gpe_initialize);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001087
Len Brown4be44fc2005-08-05 00:44:28 -04001088 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
1089 if (ACPI_FAILURE(status)) {
1090 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091 }
1092
1093 /*
1094 * Initialize the GPE Block(s) defined in the FADT
1095 *
1096 * Why the GPE register block lengths are divided by 2: From the ACPI Spec,
1097 * section "General-Purpose Event Registers", we have:
1098 *
1099 * "Each register block contains two registers of equal length
1100 * GPEx_STS and GPEx_EN (where x is 0 or 1). The length of the
1101 * GPE0_STS and GPE0_EN registers is equal to half the GPE0_LEN
1102 * The length of the GPE1_STS and GPE1_EN registers is equal to
1103 * half the GPE1_LEN. If a generic register block is not supported
1104 * then its respective block pointer and block length values in the
1105 * FADT table contain zeros. The GPE0_LEN and GPE1_LEN do not need
1106 * to be the same size."
1107 */
1108
1109 /*
1110 * Determine the maximum GPE number for this machine.
1111 *
1112 * Note: both GPE0 and GPE1 are optional, and either can exist without
1113 * the other.
1114 *
1115 * If EITHER the register length OR the block address are zero, then that
1116 * particular block is not supported.
1117 */
Bob Mooref3d2e782007-02-02 19:48:18 +03001118 if (acpi_gbl_FADT.gpe0_block_length &&
1119 acpi_gbl_FADT.xgpe0_block.address) {
Bob Moore52fc0b02006-10-02 00:00:00 -04001120
Linus Torvalds1da177e2005-04-16 15:20:36 -07001121 /* GPE block 0 exists (has both length and address > 0) */
1122
Bob Mooref3d2e782007-02-02 19:48:18 +03001123 register_count0 = (u16) (acpi_gbl_FADT.gpe0_block_length / 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001124
Len Brown4be44fc2005-08-05 00:44:28 -04001125 gpe_number_max =
1126 (register_count0 * ACPI_GPE_REGISTER_WIDTH) - 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001127
1128 /* Install GPE Block 0 */
1129
Len Brown4be44fc2005-08-05 00:44:28 -04001130 status = acpi_ev_create_gpe_block(acpi_gbl_fadt_gpe_device,
Bob Mooref3d2e782007-02-02 19:48:18 +03001131 &acpi_gbl_FADT.xgpe0_block,
Len Brown4be44fc2005-08-05 00:44:28 -04001132 register_count0, 0,
Bob Mooref3d2e782007-02-02 19:48:18 +03001133 acpi_gbl_FADT.sci_interrupt,
Len Brown4be44fc2005-08-05 00:44:28 -04001134 &acpi_gbl_gpe_fadt_blocks[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135
Len Brown4be44fc2005-08-05 00:44:28 -04001136 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -05001137 ACPI_EXCEPTION((AE_INFO, status,
1138 "Could not create GPE Block 0"));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001139 }
1140 }
1141
Bob Mooref3d2e782007-02-02 19:48:18 +03001142 if (acpi_gbl_FADT.gpe1_block_length &&
1143 acpi_gbl_FADT.xgpe1_block.address) {
Bob Moore52fc0b02006-10-02 00:00:00 -04001144
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145 /* GPE block 1 exists (has both length and address > 0) */
1146
Bob Mooref3d2e782007-02-02 19:48:18 +03001147 register_count1 = (u16) (acpi_gbl_FADT.gpe1_block_length / 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001148
1149 /* Check for GPE0/GPE1 overlap (if both banks exist) */
1150
1151 if ((register_count0) &&
Bob Mooref3d2e782007-02-02 19:48:18 +03001152 (gpe_number_max >= acpi_gbl_FADT.gpe1_base)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -05001153 ACPI_ERROR((AE_INFO,
1154 "GPE0 block (GPE 0 to %d) overlaps the GPE1 block (GPE %d to %d) - Ignoring GPE1",
Bob Mooref3d2e782007-02-02 19:48:18 +03001155 gpe_number_max, acpi_gbl_FADT.gpe1_base,
1156 acpi_gbl_FADT.gpe1_base +
Bob Mooreb8e4d892006-01-27 16:43:00 -05001157 ((register_count1 *
1158 ACPI_GPE_REGISTER_WIDTH) - 1)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001159
1160 /* Ignore GPE1 block by setting the register count to zero */
1161
1162 register_count1 = 0;
Len Brown4be44fc2005-08-05 00:44:28 -04001163 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001164 /* Install GPE Block 1 */
1165
Len Brown4be44fc2005-08-05 00:44:28 -04001166 status =
1167 acpi_ev_create_gpe_block(acpi_gbl_fadt_gpe_device,
Bob Mooref3d2e782007-02-02 19:48:18 +03001168 &acpi_gbl_FADT.xgpe1_block,
Len Brown4be44fc2005-08-05 00:44:28 -04001169 register_count1,
Bob Mooref3d2e782007-02-02 19:48:18 +03001170 acpi_gbl_FADT.gpe1_base,
1171 acpi_gbl_FADT.
1172 sci_interrupt,
Len Brown4be44fc2005-08-05 00:44:28 -04001173 &acpi_gbl_gpe_fadt_blocks
1174 [1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001175
Len Brown4be44fc2005-08-05 00:44:28 -04001176 if (ACPI_FAILURE(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -05001177 ACPI_EXCEPTION((AE_INFO, status,
1178 "Could not create GPE Block 1"));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001179 }
1180
1181 /*
1182 * GPE0 and GPE1 do not have to be contiguous in the GPE number
1183 * space. However, GPE0 always starts at GPE number zero.
1184 */
Bob Mooref3d2e782007-02-02 19:48:18 +03001185 gpe_number_max = acpi_gbl_FADT.gpe1_base +
Len Brown4be44fc2005-08-05 00:44:28 -04001186 ((register_count1 * ACPI_GPE_REGISTER_WIDTH) - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001187 }
1188 }
1189
1190 /* Exit if there are no GPE registers */
1191
1192 if ((register_count0 + register_count1) == 0) {
Bob Moore52fc0b02006-10-02 00:00:00 -04001193
Linus Torvalds1da177e2005-04-16 15:20:36 -07001194 /* GPEs are not required by ACPI, this is OK */
1195
Len Brown4be44fc2005-08-05 00:44:28 -04001196 ACPI_DEBUG_PRINT((ACPI_DB_INIT,
1197 "There are no GPE blocks defined in the FADT\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001198 status = AE_OK;
1199 goto cleanup;
1200 }
1201
1202 /* Check for Max GPE number out-of-range */
1203
1204 if (gpe_number_max > ACPI_GPE_MAX) {
Bob Mooreb8e4d892006-01-27 16:43:00 -05001205 ACPI_ERROR((AE_INFO,
1206 "Maximum GPE number from FADT is too large: 0x%X",
1207 gpe_number_max));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001208 status = AE_BAD_VALUE;
1209 goto cleanup;
1210 }
1211
Len Brown4be44fc2005-08-05 00:44:28 -04001212 cleanup:
1213 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
1214 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001215}