irq_ia64.c 6.9 KB

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