GUI: Fix Tomato RAF theme for all builds. Compilation typo.
[tomato.git] / release / src-rt-6.x.4708 / linux / linux-2.6.36 / drivers / acpi / acpica / evgpeutil.c
blob19a0e513ea48354fac1f1d48ddf135b3d79d6a39
1 /******************************************************************************
3 * Module Name: evgpeutil - GPE utilities
5 *****************************************************************************/
7 /*
8 * Copyright (C) 2000 - 2010, Intel Corp.
9 * All rights reserved.
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.
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.
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.
44 #include <acpi/acpi.h>
45 #include "accommon.h"
46 #include "acevents.h"
48 #define _COMPONENT ACPI_EVENTS
49 ACPI_MODULE_NAME("evgpeutil")
51 /*******************************************************************************
53 * FUNCTION: acpi_ev_walk_gpe_list
55 * PARAMETERS: gpe_walk_callback - Routine called for each GPE block
56 * Context - Value passed to callback
58 * RETURN: Status
60 * DESCRIPTION: Walk the GPE lists.
62 ******************************************************************************/
63 acpi_status
64 acpi_ev_walk_gpe_list(acpi_gpe_callback gpe_walk_callback, void *context)
66 struct acpi_gpe_block_info *gpe_block;
67 struct acpi_gpe_xrupt_info *gpe_xrupt_info;
68 acpi_status status = AE_OK;
69 acpi_cpu_flags flags;
71 ACPI_FUNCTION_TRACE(ev_walk_gpe_list);
73 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
75 /* Walk the interrupt level descriptor list */
77 gpe_xrupt_info = acpi_gbl_gpe_xrupt_list_head;
78 while (gpe_xrupt_info) {
80 /* Walk all Gpe Blocks attached to this interrupt level */
82 gpe_block = gpe_xrupt_info->gpe_block_list_head;
83 while (gpe_block) {
85 /* One callback per GPE block */
87 status =
88 gpe_walk_callback(gpe_xrupt_info, gpe_block,
89 context);
90 if (ACPI_FAILURE(status)) {
91 if (status == AE_CTRL_END) { /* Callback abort */
92 status = AE_OK;
94 goto unlock_and_exit;
97 gpe_block = gpe_block->next;
100 gpe_xrupt_info = gpe_xrupt_info->next;
103 unlock_and_exit:
104 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
105 return_ACPI_STATUS(status);
108 /*******************************************************************************
110 * FUNCTION: acpi_ev_valid_gpe_event
112 * PARAMETERS: gpe_event_info - Info for this GPE
114 * RETURN: TRUE if the gpe_event is valid
116 * DESCRIPTION: Validate a GPE event. DO NOT CALL FROM INTERRUPT LEVEL.
117 * Should be called only when the GPE lists are semaphore locked
118 * and not subject to change.
120 ******************************************************************************/
122 u8 acpi_ev_valid_gpe_event(struct acpi_gpe_event_info *gpe_event_info)
124 struct acpi_gpe_xrupt_info *gpe_xrupt_block;
125 struct acpi_gpe_block_info *gpe_block;
127 ACPI_FUNCTION_ENTRY();
129 /* No need for spin lock since we are not changing any list elements */
131 /* Walk the GPE interrupt levels */
133 gpe_xrupt_block = acpi_gbl_gpe_xrupt_list_head;
134 while (gpe_xrupt_block) {
135 gpe_block = gpe_xrupt_block->gpe_block_list_head;
137 /* Walk the GPE blocks on this interrupt level */
139 while (gpe_block) {
140 if ((&gpe_block->event_info[0] <= gpe_event_info) &&
141 (&gpe_block->event_info[gpe_block->gpe_count] >
142 gpe_event_info)) {
143 return (TRUE);
146 gpe_block = gpe_block->next;
149 gpe_xrupt_block = gpe_xrupt_block->next;
152 return (FALSE);
155 /*******************************************************************************
157 * FUNCTION: acpi_ev_get_gpe_xrupt_block
159 * PARAMETERS: interrupt_number - Interrupt for a GPE block
161 * RETURN: A GPE interrupt block
163 * DESCRIPTION: Get or Create a GPE interrupt block. There is one interrupt
164 * block per unique interrupt level used for GPEs. Should be
165 * called only when the GPE lists are semaphore locked and not
166 * subject to change.
168 ******************************************************************************/
170 struct acpi_gpe_xrupt_info *acpi_ev_get_gpe_xrupt_block(u32 interrupt_number)
172 struct acpi_gpe_xrupt_info *next_gpe_xrupt;
173 struct acpi_gpe_xrupt_info *gpe_xrupt;
174 acpi_status status;
175 acpi_cpu_flags flags;
177 ACPI_FUNCTION_TRACE(ev_get_gpe_xrupt_block);
179 /* No need for lock since we are not changing any list elements here */
181 next_gpe_xrupt = acpi_gbl_gpe_xrupt_list_head;
182 while (next_gpe_xrupt) {
183 if (next_gpe_xrupt->interrupt_number == interrupt_number) {
184 return_PTR(next_gpe_xrupt);
187 next_gpe_xrupt = next_gpe_xrupt->next;
190 /* Not found, must allocate a new xrupt descriptor */
192 gpe_xrupt = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_gpe_xrupt_info));
193 if (!gpe_xrupt) {
194 return_PTR(NULL);
197 gpe_xrupt->interrupt_number = interrupt_number;
199 /* Install new interrupt descriptor with spin lock */
201 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
202 if (acpi_gbl_gpe_xrupt_list_head) {
203 next_gpe_xrupt = acpi_gbl_gpe_xrupt_list_head;
204 while (next_gpe_xrupt->next) {
205 next_gpe_xrupt = next_gpe_xrupt->next;
208 next_gpe_xrupt->next = gpe_xrupt;
209 gpe_xrupt->previous = next_gpe_xrupt;
210 } else {
211 acpi_gbl_gpe_xrupt_list_head = gpe_xrupt;
213 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
215 /* Install new interrupt handler if not SCI_INT */
217 if (interrupt_number != acpi_gbl_FADT.sci_interrupt) {
218 status = acpi_os_install_interrupt_handler(interrupt_number,
219 acpi_ev_gpe_xrupt_handler,
220 gpe_xrupt);
221 if (ACPI_FAILURE(status)) {
222 ACPI_ERROR((AE_INFO,
223 "Could not install GPE interrupt handler at level 0x%X",
224 interrupt_number));
225 return_PTR(NULL);
229 return_PTR(gpe_xrupt);
232 /*******************************************************************************
234 * FUNCTION: acpi_ev_delete_gpe_xrupt
236 * PARAMETERS: gpe_xrupt - A GPE interrupt info block
238 * RETURN: Status
240 * DESCRIPTION: Remove and free a gpe_xrupt block. Remove an associated
241 * interrupt handler if not the SCI interrupt.
243 ******************************************************************************/
245 acpi_status acpi_ev_delete_gpe_xrupt(struct acpi_gpe_xrupt_info *gpe_xrupt)
247 acpi_status status;
248 acpi_cpu_flags flags;
250 ACPI_FUNCTION_TRACE(ev_delete_gpe_xrupt);
252 /* We never want to remove the SCI interrupt handler */
254 if (gpe_xrupt->interrupt_number == acpi_gbl_FADT.sci_interrupt) {
255 gpe_xrupt->gpe_block_list_head = NULL;
256 return_ACPI_STATUS(AE_OK);
259 /* Disable this interrupt */
261 status =
262 acpi_os_remove_interrupt_handler(gpe_xrupt->interrupt_number,
263 acpi_ev_gpe_xrupt_handler);
264 if (ACPI_FAILURE(status)) {
265 return_ACPI_STATUS(status);
268 /* Unlink the interrupt block with lock */
270 flags = acpi_os_acquire_lock(acpi_gbl_gpe_lock);
271 if (gpe_xrupt->previous) {
272 gpe_xrupt->previous->next = gpe_xrupt->next;
273 } else {
274 /* No previous, update list head */
276 acpi_gbl_gpe_xrupt_list_head = gpe_xrupt->next;
279 if (gpe_xrupt->next) {
280 gpe_xrupt->next->previous = gpe_xrupt->previous;
282 acpi_os_release_lock(acpi_gbl_gpe_lock, flags);
284 /* Free the block */
286 ACPI_FREE(gpe_xrupt);
287 return_ACPI_STATUS(AE_OK);
290 /*******************************************************************************
292 * FUNCTION: acpi_ev_delete_gpe_handlers
294 * PARAMETERS: gpe_xrupt_info - GPE Interrupt info
295 * gpe_block - Gpe Block info
297 * RETURN: Status
299 * DESCRIPTION: Delete all Handler objects found in the GPE data structs.
300 * Used only prior to termination.
302 ******************************************************************************/
304 acpi_status
305 acpi_ev_delete_gpe_handlers(struct acpi_gpe_xrupt_info *gpe_xrupt_info,
306 struct acpi_gpe_block_info *gpe_block,
307 void *context)
309 struct acpi_gpe_event_info *gpe_event_info;
310 u32 i;
311 u32 j;
313 ACPI_FUNCTION_TRACE(ev_delete_gpe_handlers);
315 /* Examine each GPE Register within the block */
317 for (i = 0; i < gpe_block->register_count; i++) {
319 /* Now look at the individual GPEs in this byte register */
321 for (j = 0; j < ACPI_GPE_REGISTER_WIDTH; j++) {
322 gpe_event_info = &gpe_block->event_info[((acpi_size) i *
323 ACPI_GPE_REGISTER_WIDTH)
324 + j];
326 if ((gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) ==
327 ACPI_GPE_DISPATCH_HANDLER) {
328 ACPI_FREE(gpe_event_info->dispatch.handler);
329 gpe_event_info->dispatch.handler = NULL;
330 gpe_event_info->flags &=
331 ~ACPI_GPE_DISPATCH_MASK;
336 return_ACPI_STATUS(AE_OK);