futex: futex_wake_op, fix sign_extend32 sign bits
[linux/fpc-iii.git] / kernel / irq / autoprobe.c
blob4e8089b319aedef183bef8e0131e0c5dafcb6d1b
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * linux/kernel/irq/autoprobe.c
5 * Copyright (C) 1992, 1998-2004 Linus Torvalds, Ingo Molnar
7 * This file contains the interrupt probing code and driver APIs.
8 */
10 #include <linux/irq.h>
11 #include <linux/module.h>
12 #include <linux/interrupt.h>
13 #include <linux/delay.h>
14 #include <linux/async.h>
16 #include "internals.h"
19 * Autodetection depends on the fact that any interrupt that
20 * comes in on to an unassigned handler will get stuck with
21 * "IRQS_WAITING" cleared and the interrupt disabled.
23 static DEFINE_MUTEX(probing_active);
25 /**
26 * probe_irq_on - begin an interrupt autodetect
28 * Commence probing for an interrupt. The interrupts are scanned
29 * and a mask of potential interrupt lines is returned.
32 unsigned long probe_irq_on(void)
34 struct irq_desc *desc;
35 unsigned long mask = 0;
36 int i;
39 * quiesce the kernel, or at least the asynchronous portion
41 async_synchronize_full();
42 mutex_lock(&probing_active);
44 * something may have generated an irq long ago and we want to
45 * flush such a longstanding irq before considering it as spurious.
47 for_each_irq_desc_reverse(i, desc) {
48 raw_spin_lock_irq(&desc->lock);
49 if (!desc->action && irq_settings_can_probe(desc)) {
51 * Some chips need to know about probing in
52 * progress:
54 if (desc->irq_data.chip->irq_set_type)
55 desc->irq_data.chip->irq_set_type(&desc->irq_data,
56 IRQ_TYPE_PROBE);
57 irq_activate_and_startup(desc, IRQ_NORESEND);
59 raw_spin_unlock_irq(&desc->lock);
62 /* Wait for longstanding interrupts to trigger. */
63 msleep(20);
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 raw_spin_lock_irq(&desc->lock);
72 if (!desc->action && irq_settings_can_probe(desc)) {
73 desc->istate |= IRQS_AUTODETECT | IRQS_WAITING;
74 if (irq_startup(desc, IRQ_NORESEND, IRQ_START_FORCE))
75 desc->istate |= IRQS_PENDING;
77 raw_spin_unlock_irq(&desc->lock);
81 * Wait for spurious interrupts to trigger
83 msleep(100);
86 * Now filter out any obviously spurious interrupts
88 for_each_irq_desc(i, desc) {
89 raw_spin_lock_irq(&desc->lock);
91 if (desc->istate & IRQS_AUTODETECT) {
92 /* It triggered already - consider it spurious. */
93 if (!(desc->istate & IRQS_WAITING)) {
94 desc->istate &= ~IRQS_AUTODETECT;
95 irq_shutdown(desc);
96 } else
97 if (i < 32)
98 mask |= 1 << i;
100 raw_spin_unlock_irq(&desc->lock);
103 return mask;
105 EXPORT_SYMBOL(probe_irq_on);
108 * probe_irq_mask - scan a bitmap of interrupt lines
109 * @val: mask of interrupts to consider
111 * Scan the interrupt lines and return a bitmap of active
112 * autodetect interrupts. The interrupt probe logic state
113 * is then returned to its previous value.
115 * Note: we need to scan all the irq's even though we will
116 * only return autodetect irq numbers - just so that we reset
117 * them all to a known state.
119 unsigned int probe_irq_mask(unsigned long val)
121 unsigned int mask = 0;
122 struct irq_desc *desc;
123 int i;
125 for_each_irq_desc(i, desc) {
126 raw_spin_lock_irq(&desc->lock);
127 if (desc->istate & IRQS_AUTODETECT) {
128 if (i < 16 && !(desc->istate & IRQS_WAITING))
129 mask |= 1 << i;
131 desc->istate &= ~IRQS_AUTODETECT;
132 irq_shutdown(desc);
134 raw_spin_unlock_irq(&desc->lock);
136 mutex_unlock(&probing_active);
138 return mask & val;
140 EXPORT_SYMBOL(probe_irq_mask);
143 * probe_irq_off - end an interrupt autodetect
144 * @val: mask of potential interrupts (unused)
146 * Scans the unused interrupt lines and returns the line which
147 * appears to have triggered the interrupt. If no interrupt was
148 * found then zero is returned. If more than one interrupt is
149 * found then minus the first candidate is returned to indicate
150 * their is doubt.
152 * The interrupt probe logic state is returned to its previous
153 * value.
155 * BUGS: When used in a module (which arguably shouldn't happen)
156 * nothing prevents two IRQ probe callers from overlapping. The
157 * results of this are non-optimal.
159 int probe_irq_off(unsigned long val)
161 int i, irq_found = 0, nr_of_irqs = 0;
162 struct irq_desc *desc;
164 for_each_irq_desc(i, desc) {
165 raw_spin_lock_irq(&desc->lock);
167 if (desc->istate & IRQS_AUTODETECT) {
168 if (!(desc->istate & IRQS_WAITING)) {
169 if (!nr_of_irqs)
170 irq_found = i;
171 nr_of_irqs++;
173 desc->istate &= ~IRQS_AUTODETECT;
174 irq_shutdown(desc);
176 raw_spin_unlock_irq(&desc->lock);
178 mutex_unlock(&probing_active);
180 if (nr_of_irqs > 1)
181 irq_found = -irq_found;
183 return irq_found;
185 EXPORT_SYMBOL(probe_irq_off);