dynamic.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. * Dynamic IRQ management
  3. *
  4. * Copyright (C) 2010 Paul Mundt
  5. *
  6. * Modelled after arch/x86/kernel/apic/io_apic.c
  7. *
  8. * This file is subject to the terms and conditions of the GNU General Public
  9. * License. See the file "COPYING" in the main directory of this archive
  10. * for more details.
  11. */
  12. #define pr_fmt(fmt) "intc: " fmt
  13. #include <linux/irq.h>
  14. #include <linux/bitmap.h>
  15. #include <linux/spinlock.h>
  16. #include <linux/module.h>
  17. #include "internals.h" /* only for activate_irq() damage.. */
  18. /*
  19. * The IRQ bitmap provides a global map of bound IRQ vectors for a
  20. * given platform. Allocation of IRQs are either static through the CPU
  21. * vector map, or dynamic in the case of board mux vectors or MSI.
  22. *
  23. * As this is a central point for all IRQ controllers on the system,
  24. * each of the available sources are mapped out here. This combined with
  25. * sparseirq makes it quite trivial to keep the vector map tightly packed
  26. * when dynamically creating IRQs, as well as tying in to otherwise
  27. * unused irq_desc positions in the sparse array.
  28. */
  29. /*
  30. * Dynamic IRQ allocation and deallocation
  31. */
  32. unsigned int create_irq_nr(unsigned int irq_want, int node)
  33. {
  34. int irq = irq_alloc_desc_at(irq_want, node);
  35. if (irq < 0)
  36. return 0;
  37. activate_irq(irq);
  38. return irq;
  39. }
  40. int create_irq(void)
  41. {
  42. int irq = irq_alloc_desc(numa_node_id());
  43. if (irq >= 0)
  44. activate_irq(irq);
  45. return irq;
  46. }
  47. void destroy_irq(unsigned int irq)
  48. {
  49. irq_free_desc(irq);
  50. }
  51. void reserve_intc_vectors(struct intc_vect *vectors, unsigned int nr_vecs)
  52. {
  53. int i;
  54. for (i = 0; i < nr_vecs; i++)
  55. irq_reserve_irq(evt2irq(vectors[i].vect));
  56. }