irq_ia64.c 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  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. #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. /*
  92. * Dynamic irq allocate and deallocation for MSI
  93. */
  94. int create_irq(void)
  95. {
  96. int vector = assign_irq_vector(AUTO_ASSIGN);
  97. if (vector >= 0)
  98. dynamic_irq_init(vector);
  99. return vector;
  100. }
  101. void destroy_irq(unsigned int irq)
  102. {
  103. dynamic_irq_cleanup(irq);
  104. free_irq_vector(irq);
  105. }
  106. #ifdef CONFIG_SMP
  107. # define IS_RESCHEDULE(vec) (vec == IA64_IPI_RESCHEDULE)
  108. #else
  109. # define IS_RESCHEDULE(vec) (0)
  110. #endif
  111. /*
  112. * That's where the IVT branches when we get an external
  113. * interrupt. This branches to the correct hardware IRQ handler via
  114. * function ptr.
  115. */
  116. void
  117. ia64_handle_irq (ia64_vector vector, struct pt_regs *regs)
  118. {
  119. struct pt_regs *old_regs = set_irq_regs(regs);
  120. unsigned long saved_tpr;
  121. #if IRQ_DEBUG
  122. {
  123. unsigned long bsp, sp;
  124. /*
  125. * Note: if the interrupt happened while executing in
  126. * the context switch routine (ia64_switch_to), we may
  127. * get a spurious stack overflow here. This is
  128. * because the register and the memory stack are not
  129. * switched atomically.
  130. */
  131. bsp = ia64_getreg(_IA64_REG_AR_BSP);
  132. sp = ia64_getreg(_IA64_REG_SP);
  133. if ((sp - bsp) < 1024) {
  134. static unsigned char count;
  135. static long last_time;
  136. if (jiffies - last_time > 5*HZ)
  137. count = 0;
  138. if (++count < 5) {
  139. last_time = jiffies;
  140. printk("ia64_handle_irq: DANGER: less than "
  141. "1KB of free stack space!!\n"
  142. "(bsp=0x%lx, sp=%lx)\n", bsp, sp);
  143. }
  144. }
  145. }
  146. #endif /* IRQ_DEBUG */
  147. /*
  148. * Always set TPR to limit maximum interrupt nesting depth to
  149. * 16 (without this, it would be ~240, which could easily lead
  150. * to kernel stack overflows).
  151. */
  152. irq_enter();
  153. saved_tpr = ia64_getreg(_IA64_REG_CR_TPR);
  154. ia64_srlz_d();
  155. while (vector != IA64_SPURIOUS_INT_VECTOR) {
  156. if (unlikely(IS_RESCHEDULE(vector)))
  157. kstat_this_cpu.irqs[vector]++;
  158. else {
  159. ia64_setreg(_IA64_REG_CR_TPR, vector);
  160. ia64_srlz_d();
  161. generic_handle_irq(local_vector_to_irq(vector));
  162. /*
  163. * Disable interrupts and send EOI:
  164. */
  165. local_irq_disable();
  166. ia64_setreg(_IA64_REG_CR_TPR, saved_tpr);
  167. }
  168. ia64_eoi();
  169. vector = ia64_get_ivr();
  170. }
  171. /*
  172. * This must be done *after* the ia64_eoi(). For example, the keyboard softirq
  173. * handler needs to be able to wait for further keyboard interrupts, which can't
  174. * come through until ia64_eoi() has been done.
  175. */
  176. irq_exit();
  177. set_irq_regs(old_regs);
  178. }
  179. #ifdef CONFIG_HOTPLUG_CPU
  180. /*
  181. * This function emulates a interrupt processing when a cpu is about to be
  182. * brought down.
  183. */
  184. void ia64_process_pending_intr(void)
  185. {
  186. ia64_vector vector;
  187. unsigned long saved_tpr;
  188. extern unsigned int vectors_in_migration[NR_IRQS];
  189. vector = ia64_get_ivr();
  190. irq_enter();
  191. saved_tpr = ia64_getreg(_IA64_REG_CR_TPR);
  192. ia64_srlz_d();
  193. /*
  194. * Perform normal interrupt style processing
  195. */
  196. while (vector != IA64_SPURIOUS_INT_VECTOR) {
  197. if (unlikely(IS_RESCHEDULE(vector)))
  198. kstat_this_cpu.irqs[vector]++;
  199. else {
  200. struct pt_regs *old_regs = set_irq_regs(NULL);
  201. ia64_setreg(_IA64_REG_CR_TPR, vector);
  202. ia64_srlz_d();
  203. /*
  204. * Now try calling normal ia64_handle_irq as it would have got called
  205. * from a real intr handler. Try passing null for pt_regs, hopefully
  206. * it will work. I hope it works!.
  207. * Probably could shared code.
  208. */
  209. vectors_in_migration[local_vector_to_irq(vector)]=0;
  210. generic_handle_irq(local_vector_to_irq(vector));
  211. set_irq_regs(old_regs);
  212. /*
  213. * Disable interrupts and send EOI
  214. */
  215. local_irq_disable();
  216. ia64_setreg(_IA64_REG_CR_TPR, saved_tpr);
  217. }
  218. ia64_eoi();
  219. vector = ia64_get_ivr();
  220. }
  221. irq_exit();
  222. }
  223. #endif
  224. #ifdef CONFIG_SMP
  225. extern irqreturn_t handle_IPI (int irq, void *dev_id);
  226. static irqreturn_t dummy_handler (int irq, void *dev_id)
  227. {
  228. BUG();
  229. }
  230. static struct irqaction ipi_irqaction = {
  231. .handler = handle_IPI,
  232. .flags = IRQF_DISABLED,
  233. .name = "IPI"
  234. };
  235. static struct irqaction resched_irqaction = {
  236. .handler = dummy_handler,
  237. .flags = IRQF_DISABLED,
  238. .name = "resched"
  239. };
  240. #endif
  241. void
  242. register_percpu_irq (ia64_vector vec, struct irqaction *action)
  243. {
  244. irq_desc_t *desc;
  245. unsigned int irq;
  246. for (irq = 0; irq < NR_IRQS; ++irq)
  247. if (irq_to_vector(irq) == vec) {
  248. desc = irq_desc + irq;
  249. desc->status |= IRQ_PER_CPU;
  250. desc->chip = &irq_type_ia64_lsapic;
  251. if (action)
  252. setup_irq(irq, action);
  253. }
  254. }
  255. void __init
  256. init_IRQ (void)
  257. {
  258. register_percpu_irq(IA64_SPURIOUS_INT_VECTOR, NULL);
  259. #ifdef CONFIG_SMP
  260. register_percpu_irq(IA64_IPI_VECTOR, &ipi_irqaction);
  261. register_percpu_irq(IA64_IPI_RESCHEDULE, &resched_irqaction);
  262. #endif
  263. #ifdef CONFIG_PERFMON
  264. pfm_init_percpu();
  265. #endif
  266. platform_irq_init();
  267. }
  268. void
  269. ia64_send_ipi (int cpu, int vector, int delivery_mode, int redirect)
  270. {
  271. void __iomem *ipi_addr;
  272. unsigned long ipi_data;
  273. unsigned long phys_cpu_id;
  274. #ifdef CONFIG_SMP
  275. phys_cpu_id = cpu_physical_id(cpu);
  276. #else
  277. phys_cpu_id = (ia64_getreg(_IA64_REG_CR_LID) >> 16) & 0xffff;
  278. #endif
  279. /*
  280. * cpu number is in 8bit ID and 8bit EID
  281. */
  282. ipi_data = (delivery_mode << 8) | (vector & 0xff);
  283. ipi_addr = ipi_base_addr + ((phys_cpu_id << 4) | ((redirect & 1) << 3));
  284. writeq(ipi_data, ipi_addr);
  285. }