]> bbs.cooldavid.org Git - net-next-2.6.git/blame - kernel/irq/autoprobe.c
/proc/stat: fix scalability of irq sum of all cpu
[net-next-2.6.git] / kernel / irq / autoprobe.c
CommitLineData
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
20 * "IRQ_WAITING" cleared and the interrupt disabled.
21 */
74ffd553 22static 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 */
31unsigned long probe_irq_on(void)
32{
34ffdb72 33 struct irq_desc *desc;
10e58084
TG
34 unsigned long mask = 0;
35 unsigned int status;
36 int i;
1da177e4 37
22a9d645
AV
38 /*
39 * quiesce the kernel, or at least the asynchronous portion
40 */
41 async_synchronize_full();
74ffd553 42 mutex_lock(&probing_active);
1da177e4
LT
43 /*
44 * something may have generated an irq long ago and we want to
45 * flush such a longstanding irq before considering it as spurious.
46 */
10e58084 47 for_each_irq_desc_reverse(i, desc) {
239007b8 48 raw_spin_lock_irq(&desc->lock);
6a6de9ef 49 if (!desc->action && !(desc->status & IRQ_NOPROBE)) {
7a55713a
IM
50 /*
51 * An old-style architecture might still have
52 * the handle_bad_irq handler there:
53 */
54 compat_irq_chip_set_default_handler(desc);
55
6a6de9ef
TG
56 /*
57 * Some chips need to know about probing in
58 * progress:
59 */
b2ba2c30
TG
60 if (desc->irq_data.chip->irq_set_type)
61 desc->irq_data.chip->irq_set_type(&desc->irq_data,
62 IRQ_TYPE_PROBE);
37e12df7 63 desc->irq_data.chip->irq_startup(&desc->irq_data);
6a6de9ef 64 }
239007b8 65 raw_spin_unlock_irq(&desc->lock);
1da177e4
LT
66 }
67
68 /* Wait for longstanding interrupts to trigger. */
47f176fd 69 msleep(20);
1da177e4
LT
70
71 /*
72 * enable any unassigned irqs
73 * (we must startup again here because if a longstanding irq
74 * happened in the previous stage, it may have masked itself)
75 */
10e58084 76 for_each_irq_desc_reverse(i, desc) {
239007b8 77 raw_spin_lock_irq(&desc->lock);
3418d724 78 if (!desc->action && !(desc->status & IRQ_NOPROBE)) {
1da177e4 79 desc->status |= IRQ_AUTODETECT | IRQ_WAITING;
37e12df7 80 if (desc->irq_data.chip->irq_startup(&desc->irq_data))
1da177e4
LT
81 desc->status |= IRQ_PENDING;
82 }
239007b8 83 raw_spin_unlock_irq(&desc->lock);
1da177e4
LT
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) {
239007b8 95 raw_spin_lock_irq(&desc->lock);
1da177e4
LT
96 status = desc->status;
97
98 if (status & IRQ_AUTODETECT) {
99 /* It triggered already - consider it spurious. */
100 if (!(status & IRQ_WAITING)) {
101 desc->status = status & ~IRQ_AUTODETECT;
bc310dda 102 desc->irq_data.chip->irq_shutdown(&desc->irq_data);
1da177e4
LT
103 } else
104 if (i < 32)
06fcb0c6 105 mask |= 1 << i;
1da177e4 106 }
239007b8 107 raw_spin_unlock_irq(&desc->lock);
1da177e4
LT
108 }
109
06fcb0c6 110 return mask;
1da177e4 111}
1da177e4
LT
112EXPORT_SYMBOL(probe_irq_on);
113
114/**
115 * probe_irq_mask - scan a bitmap of interrupt lines
116 * @val: mask of interrupts to consider
117 *
118 * Scan the interrupt lines and return a bitmap of active
119 * autodetect interrupts. The interrupt probe logic state
120 * is then returned to its previous value.
121 *
122 * Note: we need to scan all the irq's even though we will
123 * only return autodetect irq numbers - just so that we reset
124 * them all to a known state.
125 */
126unsigned int probe_irq_mask(unsigned long val)
127{
10e58084
TG
128 unsigned int status, mask = 0;
129 struct irq_desc *desc;
1da177e4
LT
130 int i;
131
10e58084 132 for_each_irq_desc(i, desc) {
239007b8 133 raw_spin_lock_irq(&desc->lock);
1da177e4
LT
134 status = desc->status;
135
136 if (status & IRQ_AUTODETECT) {
137 if (i < 16 && !(status & IRQ_WAITING))
138 mask |= 1 << i;
139
140 desc->status = status & ~IRQ_AUTODETECT;
bc310dda 141 desc->irq_data.chip->irq_shutdown(&desc->irq_data);
1da177e4 142 }
239007b8 143 raw_spin_unlock_irq(&desc->lock);
1da177e4 144 }
74ffd553 145 mutex_unlock(&probing_active);
1da177e4
LT
146
147 return mask & val;
148}
149EXPORT_SYMBOL(probe_irq_mask);
150
151/**
152 * probe_irq_off - end an interrupt autodetect
153 * @val: mask of potential interrupts (unused)
154 *
155 * Scans the unused interrupt lines and returns the line which
156 * appears to have triggered the interrupt. If no interrupt was
157 * found then zero is returned. If more than one interrupt is
158 * found then minus the first candidate is returned to indicate
159 * their is doubt.
160 *
161 * The interrupt probe logic state is returned to its previous
162 * value.
163 *
164 * BUGS: When used in a module (which arguably shouldn't happen)
165 * nothing prevents two IRQ probe callers from overlapping. The
166 * results of this are non-optimal.
167 */
168int probe_irq_off(unsigned long val)
169{
63d659d5 170 int i, irq_found = 0, nr_of_irqs = 0;
10e58084
TG
171 struct irq_desc *desc;
172 unsigned int status;
1da177e4 173
10e58084 174 for_each_irq_desc(i, desc) {
239007b8 175 raw_spin_lock_irq(&desc->lock);
1da177e4
LT
176 status = desc->status;
177
178 if (status & IRQ_AUTODETECT) {
179 if (!(status & IRQ_WAITING)) {
63d659d5 180 if (!nr_of_irqs)
1da177e4 181 irq_found = i;
63d659d5 182 nr_of_irqs++;
1da177e4
LT
183 }
184 desc->status = status & ~IRQ_AUTODETECT;
bc310dda 185 desc->irq_data.chip->irq_shutdown(&desc->irq_data);
1da177e4 186 }
239007b8 187 raw_spin_unlock_irq(&desc->lock);
1da177e4 188 }
74ffd553 189 mutex_unlock(&probing_active);
1da177e4 190
63d659d5 191 if (nr_of_irqs > 1)
1da177e4 192 irq_found = -irq_found;
74ffd553 193
1da177e4
LT
194 return irq_found;
195}
1da177e4
LT
196EXPORT_SYMBOL(probe_irq_off);
197