irq_32.c 8.6 KB

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