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