irq_ia64.c 8.1 KB

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