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); |
1ccb4e61 | 48 | if (!desc->action && irq_settings_can_probe(desc)) { |
6a6de9ef TG |
49 | /* |
50 | * Some chips need to know about probing in | |
51 | * progress: | |
52 | */ | |
b2ba2c30 TG |
53 | if (desc->irq_data.chip->irq_set_type) |
54 | desc->irq_data.chip->irq_set_type(&desc->irq_data, | |
55 | IRQ_TYPE_PROBE); | |
46999238 | 56 | irq_startup(desc); |
6a6de9ef | 57 | } |
239007b8 | 58 | raw_spin_unlock_irq(&desc->lock); |
1da177e4 LT |
59 | } |
60 | ||
61 | /* Wait for longstanding interrupts to trigger. */ | |
47f176fd | 62 | msleep(20); |
1da177e4 LT |
63 | |
64 | /* | |
65 | * enable any unassigned irqs | |
66 | * (we must startup again here because if a longstanding irq | |
67 | * happened in the previous stage, it may have masked itself) | |
68 | */ | |
10e58084 | 69 | for_each_irq_desc_reverse(i, desc) { |
239007b8 | 70 | raw_spin_lock_irq(&desc->lock); |
1ccb4e61 | 71 | if (!desc->action && irq_settings_can_probe(desc)) { |
163ef309 | 72 | desc->istate |= IRQS_AUTODETECT | IRQS_WAITING; |
2a0d6fb3 TG |
73 | if (irq_startup(desc)) { |
74 | irq_compat_set_pending(desc); | |
75 | desc->istate |= IRQS_PENDING; | |
76 | } | |
1da177e4 | 77 | } |
239007b8 | 78 | raw_spin_unlock_irq(&desc->lock); |
1da177e4 LT |
79 | } |
80 | ||
81 | /* | |
82 | * Wait for spurious interrupts to trigger | |
83 | */ | |
47f176fd | 84 | msleep(100); |
1da177e4 LT |
85 | |
86 | /* | |
87 | * Now filter out any obviously spurious interrupts | |
88 | */ | |
10e58084 | 89 | for_each_irq_desc(i, desc) { |
239007b8 | 90 | raw_spin_lock_irq(&desc->lock); |
1da177e4 | 91 | |
bd062e76 | 92 | if (desc->istate & IRQS_AUTODETECT) { |
1da177e4 | 93 | /* It triggered already - consider it spurious. */ |
163ef309 | 94 | if (!(desc->istate & IRQS_WAITING)) { |
bd062e76 | 95 | desc->istate &= ~IRQS_AUTODETECT; |
46999238 | 96 | irq_shutdown(desc); |
1da177e4 LT |
97 | } else |
98 | if (i < 32) | |
06fcb0c6 | 99 | mask |= 1 << i; |
1da177e4 | 100 | } |
239007b8 | 101 | raw_spin_unlock_irq(&desc->lock); |
1da177e4 LT |
102 | } |
103 | ||
06fcb0c6 | 104 | return mask; |
1da177e4 | 105 | } |
1da177e4 LT |
106 | EXPORT_SYMBOL(probe_irq_on); |
107 | ||
108 | /** | |
109 | * probe_irq_mask - scan a bitmap of interrupt lines | |
110 | * @val: mask of interrupts to consider | |
111 | * | |
112 | * Scan the interrupt lines and return a bitmap of active | |
113 | * autodetect interrupts. The interrupt probe logic state | |
114 | * is then returned to its previous value. | |
115 | * | |
116 | * Note: we need to scan all the irq's even though we will | |
117 | * only return autodetect irq numbers - just so that we reset | |
118 | * them all to a known state. | |
119 | */ | |
120 | unsigned int probe_irq_mask(unsigned long val) | |
121 | { | |
bd062e76 | 122 | unsigned int mask = 0; |
10e58084 | 123 | struct irq_desc *desc; |
1da177e4 LT |
124 | int i; |
125 | ||
10e58084 | 126 | for_each_irq_desc(i, desc) { |
239007b8 | 127 | raw_spin_lock_irq(&desc->lock); |
bd062e76 | 128 | if (desc->istate & IRQS_AUTODETECT) { |
163ef309 | 129 | if (i < 16 && !(desc->istate & IRQS_WAITING)) |
1da177e4 LT |
130 | mask |= 1 << i; |
131 | ||
bd062e76 | 132 | desc->istate &= ~IRQS_AUTODETECT; |
46999238 | 133 | irq_shutdown(desc); |
1da177e4 | 134 | } |
239007b8 | 135 | raw_spin_unlock_irq(&desc->lock); |
1da177e4 | 136 | } |
74ffd553 | 137 | mutex_unlock(&probing_active); |
1da177e4 LT |
138 | |
139 | return mask & val; | |
140 | } | |
141 | EXPORT_SYMBOL(probe_irq_mask); | |
142 | ||
143 | /** | |
144 | * probe_irq_off - end an interrupt autodetect | |
145 | * @val: mask of potential interrupts (unused) | |
146 | * | |
147 | * Scans the unused interrupt lines and returns the line which | |
148 | * appears to have triggered the interrupt. If no interrupt was | |
149 | * found then zero is returned. If more than one interrupt is | |
150 | * found then minus the first candidate is returned to indicate | |
151 | * their is doubt. | |
152 | * | |
153 | * The interrupt probe logic state is returned to its previous | |
154 | * value. | |
155 | * | |
156 | * BUGS: When used in a module (which arguably shouldn't happen) | |
157 | * nothing prevents two IRQ probe callers from overlapping. The | |
158 | * results of this are non-optimal. | |
159 | */ | |
160 | int probe_irq_off(unsigned long val) | |
161 | { | |
63d659d5 | 162 | int i, irq_found = 0, nr_of_irqs = 0; |
10e58084 | 163 | struct irq_desc *desc; |
1da177e4 | 164 | |
10e58084 | 165 | for_each_irq_desc(i, desc) { |
239007b8 | 166 | raw_spin_lock_irq(&desc->lock); |
1da177e4 | 167 | |
bd062e76 | 168 | if (desc->istate & IRQS_AUTODETECT) { |
163ef309 | 169 | if (!(desc->istate & IRQS_WAITING)) { |
63d659d5 | 170 | if (!nr_of_irqs) |
1da177e4 | 171 | irq_found = i; |
63d659d5 | 172 | nr_of_irqs++; |
1da177e4 | 173 | } |
bd062e76 | 174 | desc->istate &= ~IRQS_AUTODETECT; |
46999238 | 175 | irq_shutdown(desc); |
1da177e4 | 176 | } |
239007b8 | 177 | raw_spin_unlock_irq(&desc->lock); |
1da177e4 | 178 | } |
74ffd553 | 179 | mutex_unlock(&probing_active); |
1da177e4 | 180 | |
63d659d5 | 181 | if (nr_of_irqs > 1) |
1da177e4 | 182 | irq_found = -irq_found; |
74ffd553 | 183 | |
1da177e4 LT |
184 | return irq_found; |
185 | } | |
1da177e4 LT |
186 | EXPORT_SYMBOL(probe_irq_off); |
187 |