irq_ia64.c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. /*
  2. * linux/arch/ia64/kernel/irq.c
  3. *
  4. * Copyright (C) 1998-2001 Hewlett-Packard Co
  5. * Stephane Eranian <eranian@hpl.hp.com>
  6. * David Mosberger-Tang <davidm@hpl.hp.com>
  7. *
  8. * 6/10/99: Updated to bring in sync with x86 version to facilitate
  9. * support for SMP and different interrupt controllers.
  10. *
  11. * 09/15/00 Goutham Rao <goutham.rao@intel.com> Implemented pci_irq_to_vector
  12. * PCI to vector allocation routine.
  13. * 04/14/2004 Ashok Raj <ashok.raj@intel.com>
  14. * Added CPU Hotplug handling for IPF.
  15. */
  16. #include <linux/config.h>
  17. #include <linux/module.h>
  18. #include <linux/jiffies.h>
  19. #include <linux/errno.h>
  20. #include <linux/init.h>
  21. #include <linux/interrupt.h>
  22. #include <linux/ioport.h>
  23. #include <linux/kernel_stat.h>
  24. #include <linux/slab.h>
  25. #include <linux/ptrace.h>
  26. #include <linux/random.h> /* for rand_initialize_irq() */
  27. #include <linux/signal.h>
  28. #include <linux/smp.h>
  29. #include <linux/smp_lock.h>
  30. #include <linux/threads.h>
  31. #include <linux/bitops.h>
  32. #include <asm/delay.h>
  33. #include <asm/intrinsics.h>
  34. #include <asm/io.h>
  35. #include <asm/hw_irq.h>
  36. #include <asm/machvec.h>
  37. #include <asm/pgtable.h>
  38. #include <asm/system.h>
  39. #ifdef CONFIG_PERFMON
  40. # include <asm/perfmon.h>
  41. #endif
  42. #define IRQ_DEBUG 0
  43. /* default base addr of IPI table */
  44. void __iomem *ipi_base_addr = ((void __iomem *)
  45. (__IA64_UNCACHED_OFFSET | IA64_IPI_DEFAULT_BASE_ADDR));
  46. /*
  47. * Legacy IRQ to IA-64 vector translation table.
  48. */
  49. __u8 isa_irq_to_vector_map[16] = {
  50. /* 8259 IRQ translation, first 16 entries */
  51. 0x2f, 0x20, 0x2e, 0x2d, 0x2c, 0x2b, 0x2a, 0x29,
  52. 0x28, 0x27, 0x26, 0x25, 0x24, 0x23, 0x22, 0x21
  53. };
  54. EXPORT_SYMBOL(isa_irq_to_vector_map);
  55. static unsigned long ia64_vector_mask[BITS_TO_LONGS(IA64_NUM_DEVICE_VECTORS)];
  56. int
  57. assign_irq_vector_nopanic (int irq)
  58. {
  59. int pos, vector;
  60. again:
  61. pos = find_first_zero_bit(ia64_vector_mask, IA64_NUM_DEVICE_VECTORS);
  62. vector = IA64_FIRST_DEVICE_VECTOR + pos;
  63. if (vector > IA64_LAST_DEVICE_VECTOR)
  64. return -1;
  65. if (test_and_set_bit(pos, ia64_vector_mask))
  66. goto again;
  67. return vector;
  68. }
  69. int
  70. assign_irq_vector (int irq)
  71. {
  72. int vector = assign_irq_vector_nopanic(irq);
  73. if (vector < 0)
  74. panic("assign_irq_vector: out of interrupt vectors!");
  75. return vector;
  76. }
  77. void
  78. free_irq_vector (int vector)
  79. {
  80. int pos;
  81. if (vector < IA64_FIRST_DEVICE_VECTOR || vector > IA64_LAST_DEVICE_VECTOR)
  82. return;
  83. pos = vector - IA64_FIRST_DEVICE_VECTOR;
  84. if (!test_and_clear_bit(pos, ia64_vector_mask))
  85. printk(KERN_WARNING "%s: double free!\n", __FUNCTION__);
  86. }
  87. #ifdef CONFIG_SMP
  88. # define IS_RESCHEDULE(vec) (vec == IA64_IPI_RESCHEDULE)
  89. #else
  90. # define IS_RESCHEDULE(vec) (0)
  91. #endif
  92. /*
  93. * That's where the IVT branches when we get an external
  94. * interrupt. This branches to the correct hardware IRQ handler via
  95. * function ptr.
  96. */
  97. void
  98. ia64_handle_irq (ia64_vector vector, struct pt_regs *regs)
  99. {
  100. unsigned long saved_tpr;
  101. #if IRQ_DEBUG
  102. {
  103. unsigned long bsp, sp;
  104. /*
  105. * Note: if the interrupt happened while executing in
  106. * the context switch routine (ia64_switch_to), we may
  107. * get a spurious stack overflow here. This is
  108. * because the register and the memory stack are not
  109. * switched atomically.
  110. */
  111. bsp = ia64_getreg(_IA64_REG_AR_BSP);
  112. sp = ia64_getreg(_IA64_REG_SP);
  113. if ((sp - bsp) < 1024) {
  114. static unsigned char count;
  115. static long last_time;
  116. if (jiffies - last_time > 5*HZ)
  117. count = 0;
  118. if (++count < 5) {
  119. last_time = jiffies;
  120. printk("ia64_handle_irq: DANGER: less than "
  121. "1KB of free stack space!!\n"
  122. "(bsp=0x%lx, sp=%lx)\n", bsp, sp);
  123. }
  124. }
  125. }
  126. #endif /* IRQ_DEBUG */
  127. /*
  128. * Always set TPR to limit maximum interrupt nesting depth to
  129. * 16 (without this, it would be ~240, which could easily lead
  130. * to kernel stack overflows).
  131. */
  132. irq_enter();
  133. saved_tpr = ia64_getreg(_IA64_REG_CR_TPR);
  134. ia64_srlz_d();
  135. while (vector != IA64_SPURIOUS_INT_VECTOR) {
  136. if (!IS_RESCHEDULE(vector)) {
  137. ia64_setreg(_IA64_REG_CR_TPR, vector);
  138. ia64_srlz_d();
  139. __do_IRQ(local_vector_to_irq(vector), regs);
  140. /*
  141. * Disable interrupts and send EOI:
  142. */
  143. local_irq_disable();
  144. ia64_setreg(_IA64_REG_CR_TPR, saved_tpr);
  145. }
  146. ia64_eoi();
  147. vector = ia64_get_ivr();
  148. }
  149. /*
  150. * This must be done *after* the ia64_eoi(). For example, the keyboard softirq
  151. * handler needs to be able to wait for further keyboard interrupts, which can't
  152. * come through until ia64_eoi() has been done.
  153. */
  154. irq_exit();
  155. }
  156. #ifdef CONFIG_HOTPLUG_CPU
  157. /*
  158. * This function emulates a interrupt processing when a cpu is about to be
  159. * brought down.
  160. */
  161. void ia64_process_pending_intr(void)
  162. {
  163. ia64_vector vector;
  164. unsigned long saved_tpr;
  165. extern unsigned int vectors_in_migration[NR_IRQS];
  166. vector = ia64_get_ivr();
  167. irq_enter();
  168. saved_tpr = ia64_getreg(_IA64_REG_CR_TPR);
  169. ia64_srlz_d();
  170. /*
  171. * Perform normal interrupt style processing
  172. */
  173. while (vector != IA64_SPURIOUS_INT_VECTOR) {
  174. if (!IS_RESCHEDULE(vector)) {
  175. ia64_setreg(_IA64_REG_CR_TPR, vector);
  176. ia64_srlz_d();
  177. /*
  178. * Now try calling normal ia64_handle_irq as it would have got called
  179. * from a real intr handler. Try passing null for pt_regs, hopefully
  180. * it will work. I hope it works!.
  181. * Probably could shared code.
  182. */
  183. vectors_in_migration[local_vector_to_irq(vector)]=0;
  184. __do_IRQ(local_vector_to_irq(vector), NULL);
  185. /*
  186. * Disable interrupts and send EOI
  187. */
  188. local_irq_disable();
  189. ia64_setreg(_IA64_REG_CR_TPR, saved_tpr);
  190. }
  191. ia64_eoi();
  192. vector = ia64_get_ivr();
  193. }
  194. irq_exit();
  195. }
  196. #endif
  197. #ifdef CONFIG_SMP
  198. extern irqreturn_t handle_IPI (int irq, void *dev_id, struct pt_regs *regs);
  199. static struct irqaction ipi_irqaction = {
  200. .handler = handle_IPI,
  201. .flags = SA_INTERRUPT,
  202. .name = "IPI"
  203. };
  204. #endif
  205. void
  206. register_percpu_irq (ia64_vector vec, struct irqaction *action)
  207. {
  208. irq_desc_t *desc;
  209. unsigned int irq;
  210. for (irq = 0; irq < NR_IRQS; ++irq)
  211. if (irq_to_vector(irq) == vec) {
  212. desc = irq_descp(irq);
  213. desc->status |= IRQ_PER_CPU;
  214. desc->handler = &irq_type_ia64_lsapic;
  215. if (action)
  216. setup_irq(irq, action);
  217. }
  218. }
  219. void __init
  220. init_IRQ (void)
  221. {
  222. register_percpu_irq(IA64_SPURIOUS_INT_VECTOR, NULL);
  223. #ifdef CONFIG_SMP
  224. register_percpu_irq(IA64_IPI_VECTOR, &ipi_irqaction);
  225. #endif
  226. #ifdef CONFIG_PERFMON
  227. pfm_init_percpu();
  228. #endif
  229. platform_irq_init();
  230. }
  231. void
  232. ia64_send_ipi (int cpu, int vector, int delivery_mode, int redirect)
  233. {
  234. void __iomem *ipi_addr;
  235. unsigned long ipi_data;
  236. unsigned long phys_cpu_id;
  237. #ifdef CONFIG_SMP
  238. phys_cpu_id = cpu_physical_id(cpu);
  239. #else
  240. phys_cpu_id = (ia64_getreg(_IA64_REG_CR_LID) >> 16) & 0xffff;
  241. #endif
  242. /*
  243. * cpu number is in 8bit ID and 8bit EID
  244. */
  245. ipi_data = (delivery_mode << 8) | (vector & 0xff);
  246. ipi_addr = ipi_base_addr + ((phys_cpu_id << 4) | ((redirect & 1) << 3));
  247. writeq(ipi_data, ipi_addr);
  248. }