]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * linux/kernel/irq/autoprobe.c | |
3 | * | |
4 | * Copyright (C) 1992, 1998-2004 Linus Torvalds, Ingo Molnar | |
5 | * | |
6 | * This file contains the interrupt probing code and driver APIs. | |
7 | */ | |
8 | ||
9 | #include <linux/irq.h> | |
10 | #include <linux/module.h> | |
11 | #include <linux/interrupt.h> | |
47f176fd | 12 | #include <linux/delay.h> |
22a9d645 | 13 | #include <linux/async.h> |
1da177e4 | 14 | |
7a55713a IM |
15 | #include "internals.h" |
16 | ||
1da177e4 LT |
17 | /* |
18 | * Autodetection depends on the fact that any interrupt that | |
19 | * comes in on to an unassigned handler will get stuck with | |
163ef309 | 20 | * "IRQS_WAITING" cleared and the interrupt disabled. |
1da177e4 | 21 | */ |
74ffd553 | 22 | static DEFINE_MUTEX(probing_active); |
1da177e4 LT |
23 | |
24 | /** | |
25 | * probe_irq_on - begin an interrupt autodetect | |
26 | * | |
27 | * Commence probing for an interrupt. The interrupts are scanned | |
28 | * and a mask of potential interrupt lines is returned. | |
29 | * | |
30 | */ | |
31 | unsigned long probe_irq_on(void) | |
32 | { | |
34ffdb72 | 33 | struct irq_desc *desc; |
10e58084 | 34 | unsigned long mask = 0; |
10e58084 | 35 | int i; |
1da177e4 | 36 | |
22a9d645 AV |
37 | /* |
38 | * quiesce the kernel, or at least the asynchronous portion | |
39 | */ | |
40 | async_synchronize_full(); | |
74ffd553 | 41 | mutex_lock(&probing_active); |
1da177e4 LT |
42 | /* |
43 | * something may have generated an irq long ago and we want to | |
44 | * flush such a longstanding irq before considering it as spurious. | |
45 | */ | |
10e58084 | 46 | for_each_irq_desc_reverse(i, desc) { |
239007b8 | 47 | raw_spin_lock_irq(&desc->lock); |
6a6de9ef | 48 | if (!desc->action && !(desc->status & IRQ_NOPROBE)) { |
7a55713a IM |
49 | /* |
50 | * An old-style architecture might still have | |
51 | * the handle_bad_irq handler there: | |
52 | */ | |
53 | compat_irq_chip_set_default_handler(desc); | |
54 | ||
6a6de9ef TG |
55 | /* |
56 | * Some chips need to know about probing in | |
57 | * progress: | |
58 | */ | |
b2ba2c30 TG |
59 | if (desc->irq_data.chip->irq_set_type) |
60 | desc->irq_data.chip->irq_set_type(&desc->irq_data, | |
61 | IRQ_TYPE_PROBE); | |
46999238 | 62 | irq_startup(desc); |
6a6de9ef | 63 | } |
239007b8 | 64 | raw_spin_unlock_irq(&desc->lock); |
1da177e4 LT |
65 | } |
66 | ||
67 | /* Wait for longstanding interrupts to trigger. */ | |
47f176fd | 68 | msleep(20); |
1da177e4 LT |
69 | |
70 | /* | |
71 | * enable any unassigned irqs | |
72 | * (we must startup again here because if a longstanding irq | |
73 | * happened in the previous stage, it may have masked itself) | |
74 | */ | |
10e58084 | 75 | for_each_irq_desc_reverse(i, desc) { |
239007b8 | 76 | raw_spin_lock_irq(&desc->lock); |
3418d724 | 77 | if (!desc->action && !(desc->status & IRQ_NOPROBE)) { |
163ef309 | 78 | desc->istate |= IRQS_AUTODETECT | IRQS_WAITING; |
2a0d6fb3 TG |
79 | if (irq_startup(desc)) { |
80 | irq_compat_set_pending(desc); | |
81 | desc->istate |= IRQS_PENDING; | |
82 | } | |
1da177e4 | 83 | } |
239007b8 | 84 | raw_spin_unlock_irq(&desc->lock); |
1da177e4 LT |
85 | } |
86 | ||
87 | /* | |
88 | * Wait for spurious interrupts to trigger | |
89 | */ | |
47f176fd | 90 | msleep(100); |
1da177e4 LT |
91 | |
92 | /* | |
93 | * Now filter out any obviously spurious interrupts | |
94 | */ | |
10e58084 | 95 | for_each_irq_desc(i, desc) { |
239007b8 | 96 | raw_spin_lock_irq(&desc->lock); |
1da177e4 | 97 | |
bd062e76 | 98 | if (desc->istate & IRQS_AUTODETECT) { |
1da177e4 | 99 | /* It triggered already - consider it spurious. */ |
163ef309 | 100 | if (!(desc->istate & IRQS_WAITING)) { |
bd062e76 | 101 | desc->istate &= ~IRQS_AUTODETECT; |
46999238 | 102 | irq_shutdown(desc); |
1da177e4 LT |
103 | } else |
104 | if (i < 32) | |
06fcb0c6 | 105 | mask |= 1 << i; |
1da177e4 | 106 | } |
239007b8 | 107 | raw_spin_unlock_irq(&desc->lock); |
1da177e4 LT |
108 | } |
109 | ||
06fcb0c6 | 110 | return mask; |
1da177e4 | 111 | } |
1da177e4 LT |
112 | EXPORT_SYMBOL(probe_irq_on); |
113 | ||
114 | /** | |
115 | * probe_irq_mask - scan a bitmap of interrupt lines | |
116 | * @val: mask of interrupts to consider | |
117 | * | |
118 | * Scan the interrupt lines and return a bitmap of active | |
119 | * autodetect interrupts. The interrupt probe logic state | |
120 | * is then returned to its previous value. | |
121 | * | |
122 | * Note: we need to scan all the irq's even though we will | |
123 | * only return autodetect irq numbers - just so that we reset | |
124 | * them all to a known state. | |
125 | */ | |
126 | unsigned int probe_irq_mask(unsigned long val) | |
127 | { | |
bd062e76 | 128 | unsigned int mask = 0; |
10e58084 | 129 | struct irq_desc *desc; |
1da177e4 LT |
130 | int i; |
131 | ||
10e58084 | 132 | for_each_irq_desc(i, desc) { |
239007b8 | 133 | raw_spin_lock_irq(&desc->lock); |
bd062e76 | 134 | if (desc->istate & IRQS_AUTODETECT) { |
163ef309 | 135 | if (i < 16 && !(desc->istate & IRQS_WAITING)) |
1da177e4 LT |
136 | mask |= 1 << i; |
137 | ||
bd062e76 | 138 | desc->istate &= ~IRQS_AUTODETECT; |
46999238 | 139 | irq_shutdown(desc); |
1da177e4 | 140 | } |
239007b8 | 141 | raw_spin_unlock_irq(&desc->lock); |
1da177e4 | 142 | } |
74ffd553 | 143 | mutex_unlock(&probing_active); |
1da177e4 LT |
144 | |
145 | return mask & val; | |
146 | } | |
147 | EXPORT_SYMBOL(probe_irq_mask); | |
148 | ||
149 | /** | |
150 | * probe_irq_off - end an interrupt autodetect | |
151 | * @val: mask of potential interrupts (unused) | |
152 | * | |
153 | * Scans the unused interrupt lines and returns the line which | |
154 | * appears to have triggered the interrupt. If no interrupt was | |
155 | * found then zero is returned. If more than one interrupt is | |
156 | * found then minus the first candidate is returned to indicate | |
157 | * their is doubt. | |
158 | * | |
159 | * The interrupt probe logic state is returned to its previous | |
160 | * value. | |
161 | * | |
162 | * BUGS: When used in a module (which arguably shouldn't happen) | |
163 | * nothing prevents two IRQ probe callers from overlapping. The | |
164 | * results of this are non-optimal. | |
165 | */ | |
166 | int probe_irq_off(unsigned long val) | |
167 | { | |
63d659d5 | 168 | int i, irq_found = 0, nr_of_irqs = 0; |
10e58084 | 169 | struct irq_desc *desc; |
1da177e4 | 170 | |
10e58084 | 171 | for_each_irq_desc(i, desc) { |
239007b8 | 172 | raw_spin_lock_irq(&desc->lock); |
1da177e4 | 173 | |
bd062e76 | 174 | if (desc->istate & IRQS_AUTODETECT) { |
163ef309 | 175 | if (!(desc->istate & IRQS_WAITING)) { |
63d659d5 | 176 | if (!nr_of_irqs) |
1da177e4 | 177 | irq_found = i; |
63d659d5 | 178 | nr_of_irqs++; |
1da177e4 | 179 | } |
bd062e76 | 180 | desc->istate &= ~IRQS_AUTODETECT; |
46999238 | 181 | irq_shutdown(desc); |
1da177e4 | 182 | } |
239007b8 | 183 | raw_spin_unlock_irq(&desc->lock); |
1da177e4 | 184 | } |
74ffd553 | 185 | mutex_unlock(&probing_active); |
1da177e4 | 186 | |
63d659d5 | 187 | if (nr_of_irqs > 1) |
1da177e4 | 188 | irq_found = -irq_found; |
74ffd553 | 189 | |
1da177e4 LT |
190 | return irq_found; |
191 | } | |
1da177e4 LT |
192 | EXPORT_SYMBOL(probe_irq_off); |
193 |