[PATCH] hostap: Make hostap_tx_encrypt() static
[linux-2.6/suspend2-2.6.18.git] / kernel / irq / autoprobe.c
blob3467097ca61ae476a74a7eb1519950acc9a8ebcf
1 /*
2 * linux/kernel/irq/autoprobe.c
4 * Copyright (C) 1992, 1998-2004 Linus Torvalds, Ingo Molnar
6 * This file contains the interrupt probing code and driver APIs.
7 */
9 #include <linux/irq.h>
10 #include <linux/module.h>
11 #include <linux/interrupt.h>
12 #include <linux/delay.h>
15 * Autodetection depends on the fact that any interrupt that
16 * comes in on to an unassigned handler will get stuck with
17 * "IRQ_WAITING" cleared and the interrupt disabled.
19 static DECLARE_MUTEX(probe_sem);
21 /**
22 * probe_irq_on - begin an interrupt autodetect
24 * Commence probing for an interrupt. The interrupts are scanned
25 * and a mask of potential interrupt lines is returned.
28 unsigned long probe_irq_on(void)
30 unsigned long val;
31 irq_desc_t *desc;
32 unsigned int i;
34 down(&probe_sem);
36 * something may have generated an irq long ago and we want to
37 * flush such a longstanding irq before considering it as spurious.
39 for (i = NR_IRQS-1; i > 0; i--) {
40 desc = irq_desc + i;
42 spin_lock_irq(&desc->lock);
43 if (!irq_desc[i].action)
44 irq_desc[i].handler->startup(i);
45 spin_unlock_irq(&desc->lock);
48 /* Wait for longstanding interrupts to trigger. */
49 msleep(20);
52 * enable any unassigned irqs
53 * (we must startup again here because if a longstanding irq
54 * happened in the previous stage, it may have masked itself)
56 for (i = NR_IRQS-1; i > 0; i--) {
57 desc = irq_desc + i;
59 spin_lock_irq(&desc->lock);
60 if (!desc->action) {
61 desc->status |= IRQ_AUTODETECT | IRQ_WAITING;
62 if (desc->handler->startup(i))
63 desc->status |= IRQ_PENDING;
65 spin_unlock_irq(&desc->lock);
69 * Wait for spurious interrupts to trigger
71 msleep(100);
74 * Now filter out any obviously spurious interrupts
76 val = 0;
77 for (i = 0; i < NR_IRQS; i++) {
78 irq_desc_t *desc = irq_desc + i;
79 unsigned int status;
81 spin_lock_irq(&desc->lock);
82 status = desc->status;
84 if (status & IRQ_AUTODETECT) {
85 /* It triggered already - consider it spurious. */
86 if (!(status & IRQ_WAITING)) {
87 desc->status = status & ~IRQ_AUTODETECT;
88 desc->handler->shutdown(i);
89 } else
90 if (i < 32)
91 val |= 1 << i;
93 spin_unlock_irq(&desc->lock);
96 return val;
99 EXPORT_SYMBOL(probe_irq_on);
102 * probe_irq_mask - scan a bitmap of interrupt lines
103 * @val: mask of interrupts to consider
105 * Scan the interrupt lines and return a bitmap of active
106 * autodetect interrupts. The interrupt probe logic state
107 * is then returned to its previous value.
109 * Note: we need to scan all the irq's even though we will
110 * only return autodetect irq numbers - just so that we reset
111 * them all to a known state.
113 unsigned int probe_irq_mask(unsigned long val)
115 unsigned int mask;
116 int i;
118 mask = 0;
119 for (i = 0; i < NR_IRQS; i++) {
120 irq_desc_t *desc = irq_desc + i;
121 unsigned int status;
123 spin_lock_irq(&desc->lock);
124 status = desc->status;
126 if (status & IRQ_AUTODETECT) {
127 if (i < 16 && !(status & IRQ_WAITING))
128 mask |= 1 << i;
130 desc->status = status & ~IRQ_AUTODETECT;
131 desc->handler->shutdown(i);
133 spin_unlock_irq(&desc->lock);
135 up(&probe_sem);
137 return mask & val;
139 EXPORT_SYMBOL(probe_irq_mask);
142 * probe_irq_off - end an interrupt autodetect
143 * @val: mask of potential interrupts (unused)
145 * Scans the unused interrupt lines and returns the line which
146 * appears to have triggered the interrupt. If no interrupt was
147 * found then zero is returned. If more than one interrupt is
148 * found then minus the first candidate is returned to indicate
149 * their is doubt.
151 * The interrupt probe logic state is returned to its previous
152 * value.
154 * BUGS: When used in a module (which arguably shouldn't happen)
155 * nothing prevents two IRQ probe callers from overlapping. The
156 * results of this are non-optimal.
158 int probe_irq_off(unsigned long val)
160 int i, irq_found = 0, nr_irqs = 0;
162 for (i = 0; i < NR_IRQS; i++) {
163 irq_desc_t *desc = irq_desc + i;
164 unsigned int status;
166 spin_lock_irq(&desc->lock);
167 status = desc->status;
169 if (status & IRQ_AUTODETECT) {
170 if (!(status & IRQ_WAITING)) {
171 if (!nr_irqs)
172 irq_found = i;
173 nr_irqs++;
175 desc->status = status & ~IRQ_AUTODETECT;
176 desc->handler->shutdown(i);
178 spin_unlock_irq(&desc->lock);
180 up(&probe_sem);
182 if (nr_irqs > 1)
183 irq_found = -irq_found;
184 return irq_found;
187 EXPORT_SYMBOL(probe_irq_off);