irq_32.c 8.6 KB

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