malta_int.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  1. /*
  2. * Carsten Langgaard, carstenl@mips.com
  3. * Copyright (C) 2000, 2001, 2004 MIPS Technologies, Inc.
  4. * Copyright (C) 2001 Ralf Baechle
  5. *
  6. * This program is free software; you can distribute it and/or modify it
  7. * under the terms of the GNU General Public License (Version 2) as
  8. * published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope it will be useful, but WITHOUT
  11. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  13. * for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along
  16. * with this program; if not, write to the Free Software Foundation, Inc.,
  17. * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
  18. *
  19. * Routines for generic manipulation of the interrupts found on the MIPS
  20. * Malta board.
  21. * The interrupt controller is located in the South Bridge a PIIX4 device
  22. * with two internal 82C95 interrupt controllers.
  23. */
  24. #include <linux/init.h>
  25. #include <linux/irq.h>
  26. #include <linux/sched.h>
  27. #include <linux/slab.h>
  28. #include <linux/interrupt.h>
  29. #include <linux/kernel_stat.h>
  30. #include <linux/random.h>
  31. #include <asm/i8259.h>
  32. #include <asm/irq_cpu.h>
  33. #include <asm/io.h>
  34. #include <asm/irq_regs.h>
  35. #include <asm/mips-boards/malta.h>
  36. #include <asm/mips-boards/maltaint.h>
  37. #include <asm/mips-boards/piix4.h>
  38. #include <asm/gt64120.h>
  39. #include <asm/mips-boards/generic.h>
  40. #include <asm/mips-boards/msc01_pci.h>
  41. #include <asm/msc01_ic.h>
  42. extern void mips_timer_interrupt(void);
  43. static DEFINE_SPINLOCK(mips_irq_lock);
  44. static inline int mips_pcibios_iack(void)
  45. {
  46. int irq;
  47. u32 dummy;
  48. /*
  49. * Determine highest priority pending interrupt by performing
  50. * a PCI Interrupt Acknowledge cycle.
  51. */
  52. switch(mips_revision_corid) {
  53. case MIPS_REVISION_CORID_CORE_MSC:
  54. case MIPS_REVISION_CORID_CORE_FPGA2:
  55. case MIPS_REVISION_CORID_CORE_FPGA3:
  56. case MIPS_REVISION_CORID_CORE_24K:
  57. case MIPS_REVISION_CORID_CORE_EMUL_MSC:
  58. MSC_READ(MSC01_PCI_IACK, irq);
  59. irq &= 0xff;
  60. break;
  61. case MIPS_REVISION_CORID_QED_RM5261:
  62. case MIPS_REVISION_CORID_CORE_LV:
  63. case MIPS_REVISION_CORID_CORE_FPGA:
  64. case MIPS_REVISION_CORID_CORE_FPGAR2:
  65. irq = GT_READ(GT_PCI0_IACK_OFS);
  66. irq &= 0xff;
  67. break;
  68. case MIPS_REVISION_CORID_BONITO64:
  69. case MIPS_REVISION_CORID_CORE_20K:
  70. case MIPS_REVISION_CORID_CORE_EMUL_BON:
  71. /* The following will generate a PCI IACK cycle on the
  72. * Bonito controller. It's a little bit kludgy, but it
  73. * was the easiest way to implement it in hardware at
  74. * the given time.
  75. */
  76. BONITO_PCIMAP_CFG = 0x20000;
  77. /* Flush Bonito register block */
  78. dummy = BONITO_PCIMAP_CFG;
  79. iob(); /* sync */
  80. irq = *(volatile u32 *)(_pcictrl_bonito_pcicfg);
  81. iob(); /* sync */
  82. irq &= 0xff;
  83. BONITO_PCIMAP_CFG = 0;
  84. break;
  85. default:
  86. printk("Unknown Core card, don't know the system controller.\n");
  87. return -1;
  88. }
  89. return irq;
  90. }
  91. static inline int get_int(void)
  92. {
  93. unsigned long flags;
  94. int irq;
  95. spin_lock_irqsave(&mips_irq_lock, flags);
  96. irq = mips_pcibios_iack();
  97. /*
  98. * The only way we can decide if an interrupt is spurious
  99. * is by checking the 8259 registers. This needs a spinlock
  100. * on an SMP system, so leave it up to the generic code...
  101. */
  102. spin_unlock_irqrestore(&mips_irq_lock, flags);
  103. return irq;
  104. }
  105. static void malta_hw0_irqdispatch(void)
  106. {
  107. int irq;
  108. irq = get_int();
  109. if (irq < 0) {
  110. return; /* interrupt has already been cleared */
  111. }
  112. do_IRQ(MALTA_INT_BASE + irq);
  113. }
  114. static void corehi_irqdispatch(void)
  115. {
  116. unsigned int intedge, intsteer, pcicmd, pcibadaddr;
  117. unsigned int pcimstat, intisr, inten, intpol;
  118. unsigned int intrcause,datalo,datahi;
  119. struct pt_regs *regs = get_irq_regs();
  120. printk("CoreHI interrupt, shouldn't happen, so we die here!!!\n");
  121. printk("epc : %08lx\nStatus: %08lx\n"
  122. "Cause : %08lx\nbadVaddr : %08lx\n",
  123. regs->cp0_epc, regs->cp0_status,
  124. regs->cp0_cause, regs->cp0_badvaddr);
  125. /* Read all the registers and then print them as there is a
  126. problem with interspersed printk's upsetting the Bonito controller.
  127. Do it for the others too.
  128. */
  129. switch(mips_revision_corid) {
  130. case MIPS_REVISION_CORID_CORE_MSC:
  131. case MIPS_REVISION_CORID_CORE_FPGA2:
  132. case MIPS_REVISION_CORID_CORE_FPGA3:
  133. case MIPS_REVISION_CORID_CORE_24K:
  134. case MIPS_REVISION_CORID_CORE_EMUL_MSC:
  135. ll_msc_irq();
  136. break;
  137. case MIPS_REVISION_CORID_QED_RM5261:
  138. case MIPS_REVISION_CORID_CORE_LV:
  139. case MIPS_REVISION_CORID_CORE_FPGA:
  140. case MIPS_REVISION_CORID_CORE_FPGAR2:
  141. intrcause = GT_READ(GT_INTRCAUSE_OFS);
  142. datalo = GT_READ(GT_CPUERR_ADDRLO_OFS);
  143. datahi = GT_READ(GT_CPUERR_ADDRHI_OFS);
  144. printk("GT_INTRCAUSE = %08x\n", intrcause);
  145. printk("GT_CPUERR_ADDR = %02x%08x\n", datahi, datalo);
  146. break;
  147. case MIPS_REVISION_CORID_BONITO64:
  148. case MIPS_REVISION_CORID_CORE_20K:
  149. case MIPS_REVISION_CORID_CORE_EMUL_BON:
  150. pcibadaddr = BONITO_PCIBADADDR;
  151. pcimstat = BONITO_PCIMSTAT;
  152. intisr = BONITO_INTISR;
  153. inten = BONITO_INTEN;
  154. intpol = BONITO_INTPOL;
  155. intedge = BONITO_INTEDGE;
  156. intsteer = BONITO_INTSTEER;
  157. pcicmd = BONITO_PCICMD;
  158. printk("BONITO_INTISR = %08x\n", intisr);
  159. printk("BONITO_INTEN = %08x\n", inten);
  160. printk("BONITO_INTPOL = %08x\n", intpol);
  161. printk("BONITO_INTEDGE = %08x\n", intedge);
  162. printk("BONITO_INTSTEER = %08x\n", intsteer);
  163. printk("BONITO_PCICMD = %08x\n", pcicmd);
  164. printk("BONITO_PCIBADADDR = %08x\n", pcibadaddr);
  165. printk("BONITO_PCIMSTAT = %08x\n", pcimstat);
  166. break;
  167. }
  168. /* We die here*/
  169. die("CoreHi interrupt", regs);
  170. }
  171. static inline int clz(unsigned long x)
  172. {
  173. __asm__ (
  174. " .set push \n"
  175. " .set mips32 \n"
  176. " clz %0, %1 \n"
  177. " .set pop \n"
  178. : "=r" (x)
  179. : "r" (x));
  180. return x;
  181. }
  182. /*
  183. * Version of ffs that only looks at bits 12..15.
  184. */
  185. static inline unsigned int irq_ffs(unsigned int pending)
  186. {
  187. #if defined(CONFIG_CPU_MIPS32) || defined(CONFIG_CPU_MIPS64)
  188. return -clz(pending) + 31 - CAUSEB_IP;
  189. #else
  190. unsigned int a0 = 7;
  191. unsigned int t0;
  192. t0 = pending & 0xf000;
  193. t0 = t0 < 1;
  194. t0 = t0 << 2;
  195. a0 = a0 - t0;
  196. pending = pending << t0;
  197. t0 = pending & 0xc000;
  198. t0 = t0 < 1;
  199. t0 = t0 << 1;
  200. a0 = a0 - t0;
  201. pending = pending << t0;
  202. t0 = pending & 0x8000;
  203. t0 = t0 < 1;
  204. //t0 = t0 << 2;
  205. a0 = a0 - t0;
  206. //pending = pending << t0;
  207. return a0;
  208. #endif
  209. }
  210. /*
  211. * IRQs on the Malta board look basically (barring software IRQs which we
  212. * don't use at all and all external interrupt sources are combined together
  213. * on hardware interrupt 0 (MIPS IRQ 2)) like:
  214. *
  215. * MIPS IRQ Source
  216. * -------- ------
  217. * 0 Software (ignored)
  218. * 1 Software (ignored)
  219. * 2 Combined hardware interrupt (hw0)
  220. * 3 Hardware (ignored)
  221. * 4 Hardware (ignored)
  222. * 5 Hardware (ignored)
  223. * 6 Hardware (ignored)
  224. * 7 R4k timer (what we use)
  225. *
  226. * We handle the IRQ according to _our_ priority which is:
  227. *
  228. * Highest ---- R4k Timer
  229. * Lowest ---- Combined hardware interrupt
  230. *
  231. * then we just return, if multiple IRQs are pending then we will just take
  232. * another exception, big deal.
  233. */
  234. asmlinkage void plat_irq_dispatch(void)
  235. {
  236. unsigned int pending = read_c0_cause() & read_c0_status() & ST0_IM;
  237. int irq;
  238. irq = irq_ffs(pending);
  239. if (irq == MIPSCPU_INT_I8259A)
  240. malta_hw0_irqdispatch();
  241. else if (irq > 0)
  242. do_IRQ(MIPSCPU_INT_BASE + irq);
  243. else
  244. spurious_interrupt();
  245. }
  246. static struct irqaction i8259irq = {
  247. .handler = no_action,
  248. .name = "XT-PIC cascade"
  249. };
  250. static struct irqaction corehi_irqaction = {
  251. .handler = no_action,
  252. .name = "CoreHi"
  253. };
  254. msc_irqmap_t __initdata msc_irqmap[] = {
  255. {MSC01C_INT_TMR, MSC01_IRQ_EDGE, 0},
  256. {MSC01C_INT_PCI, MSC01_IRQ_LEVEL, 0},
  257. };
  258. int __initdata msc_nr_irqs = sizeof(msc_irqmap)/sizeof(msc_irqmap_t);
  259. msc_irqmap_t __initdata msc_eicirqmap[] = {
  260. {MSC01E_INT_SW0, MSC01_IRQ_LEVEL, 0},
  261. {MSC01E_INT_SW1, MSC01_IRQ_LEVEL, 0},
  262. {MSC01E_INT_I8259A, MSC01_IRQ_LEVEL, 0},
  263. {MSC01E_INT_SMI, MSC01_IRQ_LEVEL, 0},
  264. {MSC01E_INT_COREHI, MSC01_IRQ_LEVEL, 0},
  265. {MSC01E_INT_CORELO, MSC01_IRQ_LEVEL, 0},
  266. {MSC01E_INT_TMR, MSC01_IRQ_EDGE, 0},
  267. {MSC01E_INT_PCI, MSC01_IRQ_LEVEL, 0},
  268. {MSC01E_INT_PERFCTR, MSC01_IRQ_LEVEL, 0},
  269. {MSC01E_INT_CPUCTR, MSC01_IRQ_LEVEL, 0}
  270. };
  271. int __initdata msc_nr_eicirqs = sizeof(msc_eicirqmap)/sizeof(msc_irqmap_t);
  272. void __init arch_init_irq(void)
  273. {
  274. init_i8259_irqs();
  275. if (!cpu_has_veic)
  276. mips_cpu_irq_init (MIPSCPU_INT_BASE);
  277. switch(mips_revision_corid) {
  278. case MIPS_REVISION_CORID_CORE_MSC:
  279. case MIPS_REVISION_CORID_CORE_FPGA2:
  280. case MIPS_REVISION_CORID_CORE_FPGA3:
  281. case MIPS_REVISION_CORID_CORE_24K:
  282. case MIPS_REVISION_CORID_CORE_EMUL_MSC:
  283. if (cpu_has_veic)
  284. init_msc_irqs (MSC01E_INT_BASE, msc_eicirqmap, msc_nr_eicirqs);
  285. else
  286. init_msc_irqs (MSC01C_INT_BASE, msc_irqmap, msc_nr_irqs);
  287. }
  288. if (cpu_has_veic) {
  289. set_vi_handler (MSC01E_INT_I8259A, malta_hw0_irqdispatch);
  290. set_vi_handler (MSC01E_INT_COREHI, corehi_irqdispatch);
  291. setup_irq (MSC01E_INT_BASE+MSC01E_INT_I8259A, &i8259irq);
  292. setup_irq (MSC01E_INT_BASE+MSC01E_INT_COREHI, &corehi_irqaction);
  293. }
  294. else if (cpu_has_vint) {
  295. set_vi_handler (MIPSCPU_INT_I8259A, malta_hw0_irqdispatch);
  296. set_vi_handler (MIPSCPU_INT_COREHI, corehi_irqdispatch);
  297. #ifdef CONFIG_MIPS_MT_SMTC
  298. setup_irq_smtc (MIPSCPU_INT_BASE+MIPSCPU_INT_I8259A, &i8259irq,
  299. (0x100 << MIPSCPU_INT_I8259A));
  300. setup_irq_smtc (MIPSCPU_INT_BASE+MIPSCPU_INT_COREHI,
  301. &corehi_irqaction, (0x100 << MIPSCPU_INT_COREHI));
  302. #else /* Not SMTC */
  303. setup_irq (MIPSCPU_INT_BASE+MIPSCPU_INT_I8259A, &i8259irq);
  304. setup_irq (MIPSCPU_INT_BASE+MIPSCPU_INT_COREHI, &corehi_irqaction);
  305. #endif /* CONFIG_MIPS_MT_SMTC */
  306. }
  307. else {
  308. setup_irq (MIPSCPU_INT_BASE+MIPSCPU_INT_I8259A, &i8259irq);
  309. setup_irq (MIPSCPU_INT_BASE+MIPSCPU_INT_COREHI, &corehi_irqaction);
  310. }
  311. }