uv_irq.c 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  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. * SGI UV IRQ functions
  7. *
  8. * Copyright (C) 2008 Silicon Graphics, Inc. All rights reserved.
  9. */
  10. #include <linux/module.h>
  11. #include <linux/rbtree.h>
  12. #include <linux/slab.h>
  13. #include <linux/irq.h>
  14. #include <asm/apic.h>
  15. #include <asm/uv/uv_irq.h>
  16. #include <asm/uv/uv_hub.h>
  17. /* MMR offset and pnode of hub sourcing interrupts for a given irq */
  18. struct uv_irq_2_mmr_pnode{
  19. struct rb_node list;
  20. unsigned long offset;
  21. int pnode;
  22. int irq;
  23. };
  24. static DEFINE_SPINLOCK(uv_irq_lock);
  25. static struct rb_root uv_irq_root;
  26. static int uv_set_irq_affinity(struct irq_data *, const struct cpumask *, bool);
  27. static void uv_noop(struct irq_data *data) { }
  28. static void uv_ack_apic(struct irq_data *data)
  29. {
  30. ack_APIC_irq();
  31. }
  32. static struct irq_chip uv_irq_chip = {
  33. .name = "UV-CORE",
  34. .irq_mask = uv_noop,
  35. .irq_unmask = uv_noop,
  36. .irq_eoi = uv_ack_apic,
  37. .irq_set_affinity = uv_set_irq_affinity,
  38. };
  39. /*
  40. * Add offset and pnode information of the hub sourcing interrupts to the
  41. * rb tree for a specific irq.
  42. */
  43. static int uv_set_irq_2_mmr_info(int irq, unsigned long offset, unsigned blade)
  44. {
  45. struct rb_node **link = &uv_irq_root.rb_node;
  46. struct rb_node *parent = NULL;
  47. struct uv_irq_2_mmr_pnode *n;
  48. struct uv_irq_2_mmr_pnode *e;
  49. unsigned long irqflags;
  50. n = kmalloc_node(sizeof(struct uv_irq_2_mmr_pnode), GFP_KERNEL,
  51. uv_blade_to_memory_nid(blade));
  52. if (!n)
  53. return -ENOMEM;
  54. n->irq = irq;
  55. n->offset = offset;
  56. n->pnode = uv_blade_to_pnode(blade);
  57. spin_lock_irqsave(&uv_irq_lock, irqflags);
  58. /* Find the right place in the rbtree: */
  59. while (*link) {
  60. parent = *link;
  61. e = rb_entry(parent, struct uv_irq_2_mmr_pnode, list);
  62. if (unlikely(irq == e->irq)) {
  63. /* irq entry exists */
  64. e->pnode = uv_blade_to_pnode(blade);
  65. e->offset = offset;
  66. spin_unlock_irqrestore(&uv_irq_lock, irqflags);
  67. kfree(n);
  68. return 0;
  69. }
  70. if (irq < e->irq)
  71. link = &(*link)->rb_left;
  72. else
  73. link = &(*link)->rb_right;
  74. }
  75. /* Insert the node into the rbtree. */
  76. rb_link_node(&n->list, parent, link);
  77. rb_insert_color(&n->list, &uv_irq_root);
  78. spin_unlock_irqrestore(&uv_irq_lock, irqflags);
  79. return 0;
  80. }
  81. /* Retrieve offset and pnode information from the rb tree for a specific irq */
  82. int uv_irq_2_mmr_info(int irq, unsigned long *offset, int *pnode)
  83. {
  84. struct uv_irq_2_mmr_pnode *e;
  85. struct rb_node *n;
  86. unsigned long irqflags;
  87. spin_lock_irqsave(&uv_irq_lock, irqflags);
  88. n = uv_irq_root.rb_node;
  89. while (n) {
  90. e = rb_entry(n, struct uv_irq_2_mmr_pnode, list);
  91. if (e->irq == irq) {
  92. *offset = e->offset;
  93. *pnode = e->pnode;
  94. spin_unlock_irqrestore(&uv_irq_lock, irqflags);
  95. return 0;
  96. }
  97. if (irq < e->irq)
  98. n = n->rb_left;
  99. else
  100. n = n->rb_right;
  101. }
  102. spin_unlock_irqrestore(&uv_irq_lock, irqflags);
  103. return -1;
  104. }
  105. /*
  106. * Re-target the irq to the specified CPU and enable the specified MMR located
  107. * on the specified blade to allow the sending of MSIs to the specified CPU.
  108. */
  109. static int
  110. arch_enable_uv_irq(char *irq_name, unsigned int irq, int cpu, int mmr_blade,
  111. unsigned long mmr_offset, int limit)
  112. {
  113. const struct cpumask *eligible_cpu = cpumask_of(cpu);
  114. struct irq_cfg *cfg = irq_get_chip_data(irq);
  115. unsigned long mmr_value;
  116. struct uv_IO_APIC_route_entry *entry;
  117. int mmr_pnode, err;
  118. BUILD_BUG_ON(sizeof(struct uv_IO_APIC_route_entry) !=
  119. sizeof(unsigned long));
  120. err = assign_irq_vector(irq, cfg, eligible_cpu);
  121. if (err != 0)
  122. return err;
  123. if (limit == UV_AFFINITY_CPU)
  124. irq_set_status_flags(irq, IRQ_NO_BALANCING);
  125. else
  126. irq_set_status_flags(irq, IRQ_MOVE_PCNTXT);
  127. irq_set_chip_and_handler_name(irq, &uv_irq_chip, handle_percpu_irq,
  128. irq_name);
  129. mmr_value = 0;
  130. entry = (struct uv_IO_APIC_route_entry *)&mmr_value;
  131. entry->vector = cfg->vector;
  132. entry->delivery_mode = apic->irq_delivery_mode;
  133. entry->dest_mode = apic->irq_dest_mode;
  134. entry->polarity = 0;
  135. entry->trigger = 0;
  136. entry->mask = 0;
  137. entry->dest = apic->cpu_mask_to_apicid(eligible_cpu);
  138. mmr_pnode = uv_blade_to_pnode(mmr_blade);
  139. uv_write_global_mmr64(mmr_pnode, mmr_offset, mmr_value);
  140. if (cfg->move_in_progress)
  141. send_cleanup_vector(cfg);
  142. return irq;
  143. }
  144. /*
  145. * Disable the specified MMR located on the specified blade so that MSIs are
  146. * longer allowed to be sent.
  147. */
  148. static void arch_disable_uv_irq(int mmr_pnode, unsigned long mmr_offset)
  149. {
  150. unsigned long mmr_value;
  151. struct uv_IO_APIC_route_entry *entry;
  152. BUILD_BUG_ON(sizeof(struct uv_IO_APIC_route_entry) !=
  153. sizeof(unsigned long));
  154. mmr_value = 0;
  155. entry = (struct uv_IO_APIC_route_entry *)&mmr_value;
  156. entry->mask = 1;
  157. uv_write_global_mmr64(mmr_pnode, mmr_offset, mmr_value);
  158. }
  159. static int
  160. uv_set_irq_affinity(struct irq_data *data, const struct cpumask *mask,
  161. bool force)
  162. {
  163. struct irq_cfg *cfg = data->chip_data;
  164. unsigned int dest;
  165. unsigned long mmr_value, mmr_offset;
  166. struct uv_IO_APIC_route_entry *entry;
  167. int mmr_pnode;
  168. if (__ioapic_set_affinity(data, mask, &dest))
  169. return -1;
  170. mmr_value = 0;
  171. entry = (struct uv_IO_APIC_route_entry *)&mmr_value;
  172. entry->vector = cfg->vector;
  173. entry->delivery_mode = apic->irq_delivery_mode;
  174. entry->dest_mode = apic->irq_dest_mode;
  175. entry->polarity = 0;
  176. entry->trigger = 0;
  177. entry->mask = 0;
  178. entry->dest = dest;
  179. /* Get previously stored MMR and pnode of hub sourcing interrupts */
  180. if (uv_irq_2_mmr_info(data->irq, &mmr_offset, &mmr_pnode))
  181. return -1;
  182. uv_write_global_mmr64(mmr_pnode, mmr_offset, mmr_value);
  183. if (cfg->move_in_progress)
  184. send_cleanup_vector(cfg);
  185. return 0;
  186. }
  187. /*
  188. * Set up a mapping of an available irq and vector, and enable the specified
  189. * MMR that defines the MSI that is to be sent to the specified CPU when an
  190. * interrupt is raised.
  191. */
  192. int uv_setup_irq(char *irq_name, int cpu, int mmr_blade,
  193. unsigned long mmr_offset, int limit)
  194. {
  195. int irq, ret;
  196. irq = create_irq_nr(NR_IRQS_LEGACY, uv_blade_to_memory_nid(mmr_blade));
  197. if (irq <= 0)
  198. return -EBUSY;
  199. ret = arch_enable_uv_irq(irq_name, irq, cpu, mmr_blade, mmr_offset,
  200. limit);
  201. if (ret == irq)
  202. uv_set_irq_2_mmr_info(irq, mmr_offset, mmr_blade);
  203. else
  204. destroy_irq(irq);
  205. return ret;
  206. }
  207. EXPORT_SYMBOL_GPL(uv_setup_irq);
  208. /*
  209. * Tear down a mapping of an irq and vector, and disable the specified MMR that
  210. * defined the MSI that was to be sent to the specified CPU when an interrupt
  211. * was raised.
  212. *
  213. * Set mmr_blade and mmr_offset to what was passed in on uv_setup_irq().
  214. */
  215. void uv_teardown_irq(unsigned int irq)
  216. {
  217. struct uv_irq_2_mmr_pnode *e;
  218. struct rb_node *n;
  219. unsigned long irqflags;
  220. spin_lock_irqsave(&uv_irq_lock, irqflags);
  221. n = uv_irq_root.rb_node;
  222. while (n) {
  223. e = rb_entry(n, struct uv_irq_2_mmr_pnode, list);
  224. if (e->irq == irq) {
  225. arch_disable_uv_irq(e->pnode, e->offset);
  226. rb_erase(n, &uv_irq_root);
  227. kfree(e);
  228. break;
  229. }
  230. if (irq < e->irq)
  231. n = n->rb_left;
  232. else
  233. n = n->rb_right;
  234. }
  235. spin_unlock_irqrestore(&uv_irq_lock, irqflags);
  236. destroy_irq(irq);
  237. }
  238. EXPORT_SYMBOL_GPL(uv_teardown_irq);