ip27-irqno.c 919 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. #include <asm/barrier.h>
  10. static DECLARE_BITMAP(irq_map, NR_IRQS);
  11. int allocate_irqno(void)
  12. {
  13. int irq;
  14. again:
  15. irq = find_first_zero_bit(irq_map, NR_IRQS);
  16. if (irq >= NR_IRQS)
  17. return -ENOSPC;
  18. if (test_and_set_bit(irq, irq_map))
  19. goto again;
  20. return irq;
  21. }
  22. /*
  23. * Allocate the 16 legacy interrupts for i8259 devices. This happens early
  24. * in the kernel initialization so treating allocation failure as BUG() is
  25. * ok.
  26. */
  27. void __init alloc_legacy_irqno(void)
  28. {
  29. int i;
  30. for (i = 0; i <= 16; i++)
  31. BUG_ON(test_and_set_bit(i, irq_map));
  32. }
  33. void free_irqno(unsigned int irq)
  34. {
  35. smp_mb__before_atomic();
  36. clear_bit(irq, irq_map);
  37. smp_mb__after_atomic();
  38. }