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;
33 unsigned long mask = 0;
37 mutex_lock(&probing_active);
39 * something may have generated an irq long ago and we want to
40 * flush such a longstanding irq before considering it as spurious.
42 for_each_irq_desc_reverse(i, desc) {
43 spin_lock_irq(&desc->lock);
44 if (!desc->action && !(desc->status & IRQ_NOPROBE)) {
46 * An old-style architecture might still have
47 * the handle_bad_irq handler there:
49 compat_irq_chip_set_default_handler(desc);
52 * Some chips need to know about probing in
55 if (desc->chip->set_type)
56 desc->chip->set_type(i, IRQ_TYPE_PROBE);
57 desc->chip->startup(i);
59 spin_unlock_irq(&desc->lock);
62 /* Wait for longstanding interrupts to trigger. */
66 * enable any unassigned irqs
67 * (we must startup again here because if a longstanding irq
68 * happened in the previous stage, it may have masked itself)
70 for_each_irq_desc_reverse(i, desc) {
71 spin_lock_irq(&desc->lock);
72 if (!desc->action && !(desc->status & IRQ_NOPROBE)) {
73 desc->status |= IRQ_AUTODETECT | IRQ_WAITING;
74 if (desc->chip->startup(i))
75 desc->status |= IRQ_PENDING;
77 spin_unlock_irq(&desc->lock);
81 * Wait for spurious interrupts to trigger
86 * Now filter out any obviously spurious interrupts
88 for_each_irq_desc(i, desc) {
89 spin_lock_irq(&desc->lock);
90 status = desc->status;
92 if (status & IRQ_AUTODETECT) {
93 /* It triggered already - consider it spurious. */
94 if (!(status & IRQ_WAITING)) {
95 desc->status = status & ~IRQ_AUTODETECT;
96 desc->chip->shutdown(i);
101 spin_unlock_irq(&desc->lock);
106 EXPORT_SYMBOL(probe_irq_on);
109 * probe_irq_mask - scan a bitmap of interrupt lines
110 * @val: mask of interrupts to consider
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.
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.
120 unsigned int probe_irq_mask(unsigned long val)
122 unsigned int status, mask = 0;
123 struct irq_desc *desc;
126 for_each_irq_desc(i, desc) {
127 spin_lock_irq(&desc->lock);
128 status = desc->status;
130 if (status & IRQ_AUTODETECT) {
131 if (i < 16 && !(status & IRQ_WAITING))
134 desc->status = status & ~IRQ_AUTODETECT;
135 desc->chip->shutdown(i);
137 spin_unlock_irq(&desc->lock);
139 mutex_unlock(&probing_active);
143 EXPORT_SYMBOL(probe_irq_mask);
146 * probe_irq_off - end an interrupt autodetect
147 * @val: mask of potential interrupts (unused)
149 * Scans the unused interrupt lines and returns the line which
150 * appears to have triggered the interrupt. If no interrupt was
151 * found then zero is returned. If more than one interrupt is
152 * found then minus the first candidate is returned to indicate
155 * The interrupt probe logic state is returned to its previous
158 * BUGS: When used in a module (which arguably shouldn't happen)
159 * nothing prevents two IRQ probe callers from overlapping. The
160 * results of this are non-optimal.
162 int probe_irq_off(unsigned long val)
164 int i, irq_found = 0, nr_of_irqs = 0;
165 struct irq_desc *desc;
168 for_each_irq_desc(i, desc) {
169 spin_lock_irq(&desc->lock);
170 status = desc->status;
172 if (status & IRQ_AUTODETECT) {
173 if (!(status & IRQ_WAITING)) {
178 desc->status = status & ~IRQ_AUTODETECT;
179 desc->chip->shutdown(i);
181 spin_unlock_irq(&desc->lock);
183 mutex_unlock(&probing_active);
186 irq_found = -irq_found;
190 EXPORT_SYMBOL(probe_irq_off);