irq_32.c 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  1. /*
  2. * Interrupt request handling routines. On the
  3. * Sparc the IRQs are basically 'cast in stone'
  4. * and you are supposed to probe the prom's device
  5. * node trees to find out who's got which IRQ.
  6. *
  7. * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
  8. * Copyright (C) 1995 Miguel de Icaza (miguel@nuclecu.unam.mx)
  9. * Copyright (C) 1995,2002 Pete A. Zaitcev (zaitcev@yahoo.com)
  10. * Copyright (C) 1996 Dave Redman (djhr@tadpole.co.uk)
  11. * Copyright (C) 1998-2000 Anton Blanchard (anton@samba.org)
  12. */
  13. #include <linux/kernel_stat.h>
  14. #include <linux/seq_file.h>
  15. #include <asm/cacheflush.h>
  16. #include <asm/cpudata.h>
  17. #include <asm/pcic.h>
  18. #include <asm/leon.h>
  19. #include "kernel.h"
  20. #include "irq.h"
  21. #ifdef CONFIG_SMP
  22. #define SMP_NOP2 "nop; nop;\n\t"
  23. #define SMP_NOP3 "nop; nop; nop;\n\t"
  24. #else
  25. #define SMP_NOP2
  26. #define SMP_NOP3
  27. #endif /* SMP */
  28. /* platform specific irq setup */
  29. struct sparc_irq_config sparc_irq_config;
  30. unsigned long arch_local_irq_save(void)
  31. {
  32. unsigned long retval;
  33. unsigned long tmp;
  34. __asm__ __volatile__(
  35. "rd %%psr, %0\n\t"
  36. SMP_NOP3 /* Sun4m + Cypress + SMP bug */
  37. "or %0, %2, %1\n\t"
  38. "wr %1, 0, %%psr\n\t"
  39. "nop; nop; nop\n"
  40. : "=&r" (retval), "=r" (tmp)
  41. : "i" (PSR_PIL)
  42. : "memory");
  43. return retval;
  44. }
  45. EXPORT_SYMBOL(arch_local_irq_save);
  46. void arch_local_irq_enable(void)
  47. {
  48. unsigned long tmp;
  49. __asm__ __volatile__(
  50. "rd %%psr, %0\n\t"
  51. SMP_NOP3 /* Sun4m + Cypress + SMP bug */
  52. "andn %0, %1, %0\n\t"
  53. "wr %0, 0, %%psr\n\t"
  54. "nop; nop; nop\n"
  55. : "=&r" (tmp)
  56. : "i" (PSR_PIL)
  57. : "memory");
  58. }
  59. EXPORT_SYMBOL(arch_local_irq_enable);
  60. void arch_local_irq_restore(unsigned long old_psr)
  61. {
  62. unsigned long tmp;
  63. __asm__ __volatile__(
  64. "rd %%psr, %0\n\t"
  65. "and %2, %1, %2\n\t"
  66. SMP_NOP2 /* Sun4m + Cypress + SMP bug */
  67. "andn %0, %1, %0\n\t"
  68. "wr %0, %2, %%psr\n\t"
  69. "nop; nop; nop\n"
  70. : "=&r" (tmp)
  71. : "i" (PSR_PIL), "r" (old_psr)
  72. : "memory");
  73. }
  74. EXPORT_SYMBOL(arch_local_irq_restore);
  75. /*
  76. * Dave Redman (djhr@tadpole.co.uk)
  77. *
  78. * IRQ numbers.. These are no longer restricted to 15..
  79. *
  80. * this is done to enable SBUS cards and onboard IO to be masked
  81. * correctly. using the interrupt level isn't good enough.
  82. *
  83. * For example:
  84. * A device interrupting at sbus level6 and the Floppy both come in
  85. * at IRQ11, but enabling and disabling them requires writing to
  86. * different bits in the SLAVIO/SEC.
  87. *
  88. * As a result of these changes sun4m machines could now support
  89. * directed CPU interrupts using the existing enable/disable irq code
  90. * with tweaks.
  91. *
  92. * Sun4d complicates things even further. IRQ numbers are arbitrary
  93. * 32-bit values in that case. Since this is similar to sparc64,
  94. * we adopt a virtual IRQ numbering scheme as is done there.
  95. * Virutal interrupt numbers are allocated by build_irq(). So NR_IRQS
  96. * just becomes a limit of how many interrupt sources we can handle in
  97. * a single system. Even fully loaded SS2000 machines top off at
  98. * about 32 interrupt sources or so, therefore a NR_IRQS value of 64
  99. * is more than enough.
  100. *
  101. * We keep a map of per-PIL enable interrupts. These get wired
  102. * up via the irq_chip->startup() method which gets invoked by
  103. * the generic IRQ layer during request_irq().
  104. */
  105. /* Table of allocated irqs. Unused entries has irq == 0 */
  106. static struct irq_bucket irq_table[NR_IRQS];
  107. /* Protect access to irq_table */
  108. static DEFINE_SPINLOCK(irq_table_lock);
  109. /* Map between the irq identifier used in hw to the irq_bucket. */
  110. struct irq_bucket *irq_map[SUN4D_MAX_IRQ];
  111. /* Protect access to irq_map */
  112. static DEFINE_SPINLOCK(irq_map_lock);
  113. /* Allocate a new irq from the irq_table */
  114. unsigned int irq_alloc(unsigned int real_irq, unsigned int pil)
  115. {
  116. unsigned long flags;
  117. unsigned int i;
  118. spin_lock_irqsave(&irq_table_lock, flags);
  119. for (i = 1; i < NR_IRQS; i++) {
  120. if (irq_table[i].real_irq == real_irq && irq_table[i].pil == pil)
  121. goto found;
  122. }
  123. for (i = 1; i < NR_IRQS; i++) {
  124. if (!irq_table[i].irq)
  125. break;
  126. }
  127. if (i < NR_IRQS) {
  128. irq_table[i].real_irq = real_irq;
  129. irq_table[i].irq = i;
  130. irq_table[i].pil = pil;
  131. } else {
  132. printk(KERN_ERR "IRQ: Out of virtual IRQs.\n");
  133. i = 0;
  134. }
  135. found:
  136. spin_unlock_irqrestore(&irq_table_lock, flags);
  137. return i;
  138. }
  139. /* Based on a single pil handler_irq may need to call several
  140. * interrupt handlers. Use irq_map as entry to irq_table,
  141. * and let each entry in irq_table point to the next entry.
  142. */
  143. void irq_link(unsigned int irq)
  144. {
  145. struct irq_bucket *p;
  146. unsigned long flags;
  147. unsigned int pil;
  148. BUG_ON(irq >= NR_IRQS);
  149. spin_lock_irqsave(&irq_map_lock, flags);
  150. p = &irq_table[irq];
  151. pil = p->pil;
  152. BUG_ON(pil > SUN4D_MAX_IRQ);
  153. p->next = irq_map[pil];
  154. irq_map[pil] = p;
  155. spin_unlock_irqrestore(&irq_map_lock, flags);
  156. }
  157. void irq_unlink(unsigned int irq)
  158. {
  159. struct irq_bucket *p, **pnext;
  160. unsigned long flags;
  161. BUG_ON(irq >= NR_IRQS);
  162. spin_lock_irqsave(&irq_map_lock, flags);
  163. p = &irq_table[irq];
  164. BUG_ON(p->pil > SUN4D_MAX_IRQ);
  165. pnext = &irq_map[p->pil];
  166. while (*pnext != p)
  167. pnext = &(*pnext)->next;
  168. *pnext = p->next;
  169. spin_unlock_irqrestore(&irq_map_lock, flags);
  170. }
  171. /* /proc/interrupts printing */
  172. int arch_show_interrupts(struct seq_file *p, int prec)
  173. {
  174. int j;
  175. #ifdef CONFIG_SMP
  176. seq_printf(p, "RES: ");
  177. for_each_online_cpu(j)
  178. seq_printf(p, "%10u ", cpu_data(j).irq_resched_count);
  179. seq_printf(p, " IPI rescheduling interrupts\n");
  180. seq_printf(p, "CAL: ");
  181. for_each_online_cpu(j)
  182. seq_printf(p, "%10u ", cpu_data(j).irq_call_count);
  183. seq_printf(p, " IPI function call interrupts\n");
  184. #endif
  185. seq_printf(p, "NMI: ");
  186. for_each_online_cpu(j)
  187. seq_printf(p, "%10u ", cpu_data(j).counter);
  188. seq_printf(p, " Non-maskable interrupts\n");
  189. return 0;
  190. }
  191. void handler_irq(unsigned int pil, struct pt_regs *regs)
  192. {
  193. struct pt_regs *old_regs;
  194. struct irq_bucket *p;
  195. BUG_ON(pil > 15);
  196. old_regs = set_irq_regs(regs);
  197. irq_enter();
  198. p = irq_map[pil];
  199. while (p) {
  200. struct irq_bucket *next = p->next;
  201. generic_handle_irq(p->irq);
  202. p = next;
  203. }
  204. irq_exit();
  205. set_irq_regs(old_regs);
  206. }
  207. #if defined(CONFIG_BLK_DEV_FD) || defined(CONFIG_BLK_DEV_FD_MODULE)
  208. static unsigned int floppy_irq;
  209. int sparc_floppy_request_irq(unsigned int irq, irq_handler_t irq_handler)
  210. {
  211. unsigned int cpu_irq;
  212. int err;
  213. #if defined CONFIG_SMP && !defined CONFIG_SPARC_LEON
  214. struct tt_entry *trap_table;
  215. #endif
  216. err = request_irq(irq, irq_handler, 0, "floppy", NULL);
  217. if (err)
  218. return -1;
  219. /* Save for later use in floppy interrupt handler */
  220. floppy_irq = irq;
  221. cpu_irq = (irq & (NR_IRQS - 1));
  222. /* Dork with trap table if we get this far. */
  223. #define INSTANTIATE(table) \
  224. table[SP_TRAP_IRQ1+(cpu_irq-1)].inst_one = SPARC_RD_PSR_L0; \
  225. table[SP_TRAP_IRQ1+(cpu_irq-1)].inst_two = \
  226. SPARC_BRANCH((unsigned long) floppy_hardint, \
  227. (unsigned long) &table[SP_TRAP_IRQ1+(cpu_irq-1)].inst_two);\
  228. table[SP_TRAP_IRQ1+(cpu_irq-1)].inst_three = SPARC_RD_WIM_L3; \
  229. table[SP_TRAP_IRQ1+(cpu_irq-1)].inst_four = SPARC_NOP;
  230. INSTANTIATE(sparc_ttable)
  231. #if defined CONFIG_SMP && !defined CONFIG_SPARC_LEON
  232. trap_table = &trapbase_cpu1;
  233. INSTANTIATE(trap_table)
  234. trap_table = &trapbase_cpu2;
  235. INSTANTIATE(trap_table)
  236. trap_table = &trapbase_cpu3;
  237. INSTANTIATE(trap_table)
  238. #endif
  239. #undef INSTANTIATE
  240. /*
  241. * XXX Correct thing whould be to flush only I- and D-cache lines
  242. * which contain the handler in question. But as of time of the
  243. * writing we have no CPU-neutral interface to fine-grained flushes.
  244. */
  245. flush_cache_all();
  246. return 0;
  247. }
  248. EXPORT_SYMBOL(sparc_floppy_request_irq);
  249. /*
  250. * These variables are used to access state from the assembler
  251. * interrupt handler, floppy_hardint, so we cannot put these in
  252. * the floppy driver image because that would not work in the
  253. * modular case.
  254. */
  255. volatile unsigned char *fdc_status;
  256. EXPORT_SYMBOL(fdc_status);
  257. char *pdma_vaddr;
  258. EXPORT_SYMBOL(pdma_vaddr);
  259. unsigned long pdma_size;
  260. EXPORT_SYMBOL(pdma_size);
  261. volatile int doing_pdma;
  262. EXPORT_SYMBOL(doing_pdma);
  263. char *pdma_base;
  264. EXPORT_SYMBOL(pdma_base);
  265. unsigned long pdma_areasize;
  266. EXPORT_SYMBOL(pdma_areasize);
  267. /* Use the generic irq support to call floppy_interrupt
  268. * which was setup using request_irq() in sparc_floppy_request_irq().
  269. * We only have one floppy interrupt so we do not need to check
  270. * for additional handlers being wired up by irq_link()
  271. */
  272. void sparc_floppy_irq(int irq, void *dev_id, struct pt_regs *regs)
  273. {
  274. struct pt_regs *old_regs;
  275. old_regs = set_irq_regs(regs);
  276. irq_enter();
  277. generic_handle_irq(floppy_irq);
  278. irq_exit();
  279. set_irq_regs(old_regs);
  280. }
  281. #endif
  282. /* djhr
  283. * This could probably be made indirect too and assigned in the CPU
  284. * bits of the code. That would be much nicer I think and would also
  285. * fit in with the idea of being able to tune your kernel for your machine
  286. * by removing unrequired machine and device support.
  287. *
  288. */
  289. void __init init_IRQ(void)
  290. {
  291. switch (sparc_cpu_model) {
  292. case sun4c:
  293. case sun4:
  294. sun4c_init_IRQ();
  295. break;
  296. case sun4m:
  297. pcic_probe();
  298. if (pcic_present())
  299. sun4m_pci_init_IRQ();
  300. else
  301. sun4m_init_IRQ();
  302. break;
  303. case sun4d:
  304. sun4d_init_IRQ();
  305. break;
  306. case sparc_leon:
  307. leon_init_IRQ();
  308. break;
  309. default:
  310. prom_printf("Cannot initialize IRQs on this Sun machine...");
  311. break;
  312. }
  313. btfixup();
  314. }