]>
git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blob - kernel/irq/autoprobe.c
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.
10 #include <linux/module.h>
11 #include <linux/interrupt.h>
12 #include <linux/delay.h>
13 #include <linux/async.h>
15 #include "internals.h"
18 * Autodetection depends on the fact that any interrupt that
19 * comes in on to an unassigned handler will get stuck with
20 * "IRQS_WAITING" cleared and the interrupt disabled.
22 static DEFINE_MUTEX(probing_active
);
25 * probe_irq_on - begin an interrupt autodetect
27 * Commence probing for an interrupt. The interrupts are scanned
28 * and a mask of potential interrupt lines is returned.
31 unsigned long probe_irq_on(void)
33 struct irq_desc
*desc
;
34 unsigned long mask
= 0;
38 * quiesce the kernel, or at least the asynchronous portion
40 async_synchronize_full();
41 mutex_lock(&probing_active
);
43 * something may have generated an irq long ago and we want to
44 * flush such a longstanding irq before considering it as spurious.
46 for_each_irq_desc_reverse(i
, desc
) {
47 raw_spin_lock_irq(&desc
->lock
);
48 if (!desc
->action
&& irq_settings_can_probe(desc
)) {
50 * Some chips need to know about probing in
53 if (desc
->irq_data
.chip
->irq_set_type
)
54 desc
->irq_data
.chip
->irq_set_type(&desc
->irq_data
,
56 irq_startup(desc
, false);
58 raw_spin_unlock_irq(&desc
->lock
);
61 /* Wait for longstanding interrupts to trigger. */
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)
69 for_each_irq_desc_reverse(i
, desc
) {
70 raw_spin_lock_irq(&desc
->lock
);
71 if (!desc
->action
&& irq_settings_can_probe(desc
)) {
72 desc
->istate
|= IRQS_AUTODETECT
| IRQS_WAITING
;
73 if (irq_startup(desc
, false))
74 desc
->istate
|= IRQS_PENDING
;
76 raw_spin_unlock_irq(&desc
->lock
);
80 * Wait for spurious interrupts to trigger
85 * Now filter out any obviously spurious interrupts
87 for_each_irq_desc(i
, desc
) {
88 raw_spin_lock_irq(&desc
->lock
);
90 if (desc
->istate
& IRQS_AUTODETECT
) {
91 /* It triggered already - consider it spurious. */
92 if (!(desc
->istate
& IRQS_WAITING
)) {
93 desc
->istate
&= ~IRQS_AUTODETECT
;
99 raw_spin_unlock_irq(&desc
->lock
);
104 EXPORT_SYMBOL(probe_irq_on
);
107 * probe_irq_mask - scan a bitmap of interrupt lines
108 * @val: mask of interrupts to consider
110 * Scan the interrupt lines and return a bitmap of active
111 * autodetect interrupts. The interrupt probe logic state
112 * is then returned to its previous value.
114 * Note: we need to scan all the irq's even though we will
115 * only return autodetect irq numbers - just so that we reset
116 * them all to a known state.
118 unsigned int probe_irq_mask(unsigned long val
)
120 unsigned int mask
= 0;
121 struct irq_desc
*desc
;
124 for_each_irq_desc(i
, desc
) {
125 raw_spin_lock_irq(&desc
->lock
);
126 if (desc
->istate
& IRQS_AUTODETECT
) {
127 if (i
< 16 && !(desc
->istate
& IRQS_WAITING
))
130 desc
->istate
&= ~IRQS_AUTODETECT
;
133 raw_spin_unlock_irq(&desc
->lock
);
135 mutex_unlock(&probing_active
);
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
151 * The interrupt probe logic state is returned to its previous
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_of_irqs
= 0;
161 struct irq_desc
*desc
;
163 for_each_irq_desc(i
, desc
) {
164 raw_spin_lock_irq(&desc
->lock
);
166 if (desc
->istate
& IRQS_AUTODETECT
) {
167 if (!(desc
->istate
& IRQS_WAITING
)) {
172 desc
->istate
&= ~IRQS_AUTODETECT
;
175 raw_spin_unlock_irq(&desc
->lock
);
177 mutex_unlock(&probing_active
);
180 irq_found
= -irq_found
;
184 EXPORT_SYMBOL(probe_irq_off
);