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>
14 #include "internals.h"
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.
21 static DEFINE_MUTEX(probing_active);
24 * probe_irq_on - begin an interrupt autodetect
26 * Commence probing for an interrupt. The interrupts are scanned
27 * and a mask of potential interrupt lines is returned.
30 unsigned long probe_irq_on(void)
32 struct irq_desc *desc;
36 mutex_lock(&probing_active);
38 * something may have generated an irq long ago and we want to
39 * flush such a longstanding irq before considering it as spurious.
41 for (i = NR_IRQS-1; i > 0; i--) {
44 spin_lock_irq(&desc->lock);
45 if (!desc->action && !(desc->status & IRQ_NOPROBE)) {
47 * An old-style architecture might still have
48 * the handle_bad_irq handler there:
50 compat_irq_chip_set_default_handler(desc);
53 * Some chips need to know about probing in
56 if (desc->chip->set_type)
57 desc->chip->set_type(i, IRQ_TYPE_PROBE);
58 desc->chip->startup(i);
60 spin_unlock_irq(&desc->lock);
63 /* Wait for longstanding interrupts to trigger. */
67 * enable any unassigned irqs
68 * (we must startup again here because if a longstanding irq
69 * happened in the previous stage, it may have masked itself)
71 for (i = NR_IRQS-1; i > 0; i--) {
74 spin_lock_irq(&desc->lock);
75 if (!desc->action && !(desc->status & IRQ_NOPROBE)) {
76 desc->status |= IRQ_AUTODETECT | IRQ_WAITING;
77 if (desc->chip->startup(i))
78 desc->status |= IRQ_PENDING;
80 spin_unlock_irq(&desc->lock);
84 * Wait for spurious interrupts to trigger
89 * Now filter out any obviously spurious interrupts
92 for (i = 0; i < NR_IRQS; i++) {
96 spin_lock_irq(&desc->lock);
97 status = desc->status;
99 if (status & IRQ_AUTODETECT) {
100 /* It triggered already - consider it spurious. */
101 if (!(status & IRQ_WAITING)) {
102 desc->status = status & ~IRQ_AUTODETECT;
103 desc->chip->shutdown(i);
108 spin_unlock_irq(&desc->lock);
113 EXPORT_SYMBOL(probe_irq_on);
116 * probe_irq_mask - scan a bitmap of interrupt lines
117 * @val: mask of interrupts to consider
119 * Scan the interrupt lines and return a bitmap of active
120 * autodetect interrupts. The interrupt probe logic state
121 * is then returned to its previous value.
123 * Note: we need to scan all the irq's even though we will
124 * only return autodetect irq numbers - just so that we reset
125 * them all to a known state.
127 unsigned int probe_irq_mask(unsigned long val)
133 for (i = 0; i < NR_IRQS; i++) {
134 struct irq_desc *desc = irq_desc + i;
137 spin_lock_irq(&desc->lock);
138 status = desc->status;
140 if (status & IRQ_AUTODETECT) {
141 if (i < 16 && !(status & IRQ_WAITING))
144 desc->status = status & ~IRQ_AUTODETECT;
145 desc->chip->shutdown(i);
147 spin_unlock_irq(&desc->lock);
149 mutex_unlock(&probing_active);
153 EXPORT_SYMBOL(probe_irq_mask);
156 * probe_irq_off - end an interrupt autodetect
157 * @val: mask of potential interrupts (unused)
159 * Scans the unused interrupt lines and returns the line which
160 * appears to have triggered the interrupt. If no interrupt was
161 * found then zero is returned. If more than one interrupt is
162 * found then minus the first candidate is returned to indicate
165 * The interrupt probe logic state is returned to its previous
168 * BUGS: When used in a module (which arguably shouldn't happen)
169 * nothing prevents two IRQ probe callers from overlapping. The
170 * results of this are non-optimal.
172 int probe_irq_off(unsigned long val)
174 int i, irq_found = 0, nr_irqs = 0;
176 for (i = 0; i < NR_IRQS; i++) {
177 struct irq_desc *desc = irq_desc + i;
180 spin_lock_irq(&desc->lock);
181 status = desc->status;
183 if (status & IRQ_AUTODETECT) {
184 if (!(status & IRQ_WAITING)) {
189 desc->status = status & ~IRQ_AUTODETECT;
190 desc->chip->shutdown(i);
192 spin_unlock_irq(&desc->lock);
194 mutex_unlock(&probing_active);
197 irq_found = -irq_found;
201 EXPORT_SYMBOL(probe_irq_off);