irq_32.c 8.7 KB

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