dynamic.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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 "internals.h" /* only for activate_irq() damage.. */
  17. /*
  18. * The IRQ bitmap provides a global map of bound IRQ vectors for a
  19. * given platform. Allocation of IRQs are either static through the CPU
  20. * vector map, or dynamic in the case of board mux vectors or MSI.
  21. *
  22. * As this is a central point for all IRQ controllers on the system,
  23. * each of the available sources are mapped out here. This combined with
  24. * sparseirq makes it quite trivial to keep the vector map tightly packed
  25. * when dynamically creating IRQs, as well as tying in to otherwise
  26. * unused irq_desc positions in the sparse array.
  27. */
  28. /*
  29. * Dynamic IRQ allocation and deallocation
  30. */
  31. unsigned int create_irq_nr(unsigned int irq_want, int node)
  32. {
  33. int irq = irq_alloc_desc_at(irq_want, node);
  34. if (irq < 0)
  35. return 0;
  36. activate_irq(irq);
  37. return irq;
  38. }
  39. int create_irq(void)
  40. {
  41. int irq = irq_alloc_desc(numa_node_id());
  42. if (irq >= 0)
  43. activate_irq(irq);
  44. return irq;
  45. }
  46. void destroy_irq(unsigned int irq)
  47. {
  48. irq_free_desc(irq);
  49. }
  50. void reserve_intc_vectors(struct intc_vect *vectors, unsigned int nr_vecs)
  51. {
  52. int i;
  53. for (i = 0; i < nr_vecs; i++)
  54. irq_reserve_irq(evt2irq(vectors[i].vect));
  55. }