These changes are the raw update to linux-4.4.6-rt14. Kernel sources
[kvmfornfv.git] / kernel / arch / mips / sgi-ip27 / ip27-irqno.c
1 /*
2  * This file is subject to the terms and conditions of the GNU General Public
3  * License.  See the file "COPYING" in the main directory of this archive
4  * for more details.
5  */
6 #include <linux/init.h>
7 #include <linux/irq.h>
8 #include <linux/types.h>
9
10 #include <asm/barrier.h>
11
12 static DECLARE_BITMAP(irq_map, NR_IRQS);
13
14 int allocate_irqno(void)
15 {
16         int irq;
17
18 again:
19         irq = find_first_zero_bit(irq_map, NR_IRQS);
20
21         if (irq >= NR_IRQS)
22                 return -ENOSPC;
23
24         if (test_and_set_bit(irq, irq_map))
25                 goto again;
26
27         return irq;
28 }
29
30 /*
31  * Allocate the 16 legacy interrupts for i8259 devices.  This happens early
32  * in the kernel initialization so treating allocation failure as BUG() is
33  * ok.
34  */
35 void __init alloc_legacy_irqno(void)
36 {
37         int i;
38
39         for (i = 0; i <= 16; i++)
40                 BUG_ON(test_and_set_bit(i, irq_map));
41 }
42
43 void free_irqno(unsigned int irq)
44 {
45         smp_mb__before_atomic();
46         clear_bit(irq, irq_map);
47         smp_mb__after_atomic();
48 }