malta_int.c 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  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/io.h>
  30. #include <linux/kernel_stat.h>
  31. #include <linux/kernel.h>
  32. #include <linux/random.h>
  33. #include <asm/i8259.h>
  34. #include <asm/irq_cpu.h>
  35. #include <asm/irq_regs.h>
  36. #include <asm/mips-boards/malta.h>
  37. #include <asm/mips-boards/maltaint.h>
  38. #include <asm/mips-boards/piix4.h>
  39. #include <asm/gt64120.h>
  40. #include <asm/mips-boards/generic.h>
  41. #include <asm/mips-boards/msc01_pci.h>
  42. #include <asm/msc01_ic.h>
  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_sconid) {
  53. case MIPS_REVISION_SCON_SOCIT:
  54. case MIPS_REVISION_SCON_ROCIT:
  55. case MIPS_REVISION_SCON_SOCITSC:
  56. case MIPS_REVISION_SCON_SOCITSCP:
  57. MSC_READ(MSC01_PCI_IACK, irq);
  58. irq &= 0xff;
  59. break;
  60. case MIPS_REVISION_SCON_GT64120:
  61. irq = GT_READ(GT_PCI0_IACK_OFS);
  62. irq &= 0xff;
  63. break;
  64. case MIPS_REVISION_SCON_BONITO:
  65. /* The following will generate a PCI IACK cycle on the
  66. * Bonito controller. It's a little bit kludgy, but it
  67. * was the easiest way to implement it in hardware at
  68. * the given time.
  69. */
  70. BONITO_PCIMAP_CFG = 0x20000;
  71. /* Flush Bonito register block */
  72. dummy = BONITO_PCIMAP_CFG;
  73. iob(); /* sync */
  74. irq = readl((u32 *)_pcictrl_bonito_pcicfg);
  75. iob(); /* sync */
  76. irq &= 0xff;
  77. BONITO_PCIMAP_CFG = 0;
  78. break;
  79. default:
  80. printk(KERN_WARNING "Unknown system controller.\n");
  81. return -1;
  82. }
  83. return irq;
  84. }
  85. static inline int get_int(void)
  86. {
  87. unsigned long flags;
  88. int irq;
  89. spin_lock_irqsave(&mips_irq_lock, flags);
  90. irq = mips_pcibios_iack();
  91. /*
  92. * The only way we can decide if an interrupt is spurious
  93. * is by checking the 8259 registers. This needs a spinlock
  94. * on an SMP system, so leave it up to the generic code...
  95. */
  96. spin_unlock_irqrestore(&mips_irq_lock, flags);
  97. return irq;
  98. }
  99. static void malta_hw0_irqdispatch(void)
  100. {
  101. int irq;
  102. irq = get_int();
  103. if (irq < 0) {
  104. /* interrupt has already been cleared */
  105. return;
  106. }
  107. do_IRQ(MALTA_INT_BASE + irq);
  108. }
  109. static void corehi_irqdispatch(void)
  110. {
  111. unsigned int intedge, intsteer, pcicmd, pcibadaddr;
  112. unsigned int pcimstat, intisr, inten, intpol;
  113. unsigned int intrcause, datalo, datahi;
  114. struct pt_regs *regs = get_irq_regs();
  115. printk(KERN_EMERG "CoreHI interrupt, shouldn't happen, we die here!\n");
  116. printk(KERN_EMERG "epc : %08lx\nStatus: %08lx\n"
  117. "Cause : %08lx\nbadVaddr : %08lx\n",
  118. regs->cp0_epc, regs->cp0_status,
  119. regs->cp0_cause, regs->cp0_badvaddr);
  120. /* Read all the registers and then print them as there is a
  121. problem with interspersed printk's upsetting the Bonito controller.
  122. Do it for the others too.
  123. */
  124. switch (mips_revision_sconid) {
  125. case MIPS_REVISION_SCON_SOCIT:
  126. case MIPS_REVISION_SCON_ROCIT:
  127. case MIPS_REVISION_SCON_SOCITSC:
  128. case MIPS_REVISION_SCON_SOCITSCP:
  129. ll_msc_irq();
  130. break;
  131. case MIPS_REVISION_SCON_GT64120:
  132. intrcause = GT_READ(GT_INTRCAUSE_OFS);
  133. datalo = GT_READ(GT_CPUERR_ADDRLO_OFS);
  134. datahi = GT_READ(GT_CPUERR_ADDRHI_OFS);
  135. printk(KERN_EMERG "GT_INTRCAUSE = %08x\n", intrcause);
  136. printk(KERN_EMERG "GT_CPUERR_ADDR = %02x%08x\n",
  137. datahi, datalo);
  138. break;
  139. case MIPS_REVISION_SCON_BONITO:
  140. pcibadaddr = BONITO_PCIBADADDR;
  141. pcimstat = BONITO_PCIMSTAT;
  142. intisr = BONITO_INTISR;
  143. inten = BONITO_INTEN;
  144. intpol = BONITO_INTPOL;
  145. intedge = BONITO_INTEDGE;
  146. intsteer = BONITO_INTSTEER;
  147. pcicmd = BONITO_PCICMD;
  148. printk(KERN_EMERG "BONITO_INTISR = %08x\n", intisr);
  149. printk(KERN_EMERG "BONITO_INTEN = %08x\n", inten);
  150. printk(KERN_EMERG "BONITO_INTPOL = %08x\n", intpol);
  151. printk(KERN_EMERG "BONITO_INTEDGE = %08x\n", intedge);
  152. printk(KERN_EMERG "BONITO_INTSTEER = %08x\n", intsteer);
  153. printk(KERN_EMERG "BONITO_PCICMD = %08x\n", pcicmd);
  154. printk(KERN_EMERG "BONITO_PCIBADADDR = %08x\n", pcibadaddr);
  155. printk(KERN_EMERG "BONITO_PCIMSTAT = %08x\n", pcimstat);
  156. break;
  157. }
  158. die("CoreHi interrupt", regs);
  159. }
  160. static inline int clz(unsigned long x)
  161. {
  162. __asm__(
  163. " .set push \n"
  164. " .set mips32 \n"
  165. " clz %0, %1 \n"
  166. " .set pop \n"
  167. : "=r" (x)
  168. : "r" (x));
  169. return x;
  170. }
  171. /*
  172. * Version of ffs that only looks at bits 12..15.
  173. */
  174. static inline unsigned int irq_ffs(unsigned int pending)
  175. {
  176. #if defined(CONFIG_CPU_MIPS32) || defined(CONFIG_CPU_MIPS64)
  177. return -clz(pending) + 31 - CAUSEB_IP;
  178. #else
  179. unsigned int a0 = 7;
  180. unsigned int t0;
  181. t0 = pending & 0xf000;
  182. t0 = t0 < 1;
  183. t0 = t0 << 2;
  184. a0 = a0 - t0;
  185. pending = pending << t0;
  186. t0 = pending & 0xc000;
  187. t0 = t0 < 1;
  188. t0 = t0 << 1;
  189. a0 = a0 - t0;
  190. pending = pending << t0;
  191. t0 = pending & 0x8000;
  192. t0 = t0 < 1;
  193. /* t0 = t0 << 2; */
  194. a0 = a0 - t0;
  195. /* pending = pending << t0; */
  196. return a0;
  197. #endif
  198. }
  199. /*
  200. * IRQs on the Malta board look basically (barring software IRQs which we
  201. * don't use at all and all external interrupt sources are combined together
  202. * on hardware interrupt 0 (MIPS IRQ 2)) like:
  203. *
  204. * MIPS IRQ Source
  205. * -------- ------
  206. * 0 Software (ignored)
  207. * 1 Software (ignored)
  208. * 2 Combined hardware interrupt (hw0)
  209. * 3 Hardware (ignored)
  210. * 4 Hardware (ignored)
  211. * 5 Hardware (ignored)
  212. * 6 Hardware (ignored)
  213. * 7 R4k timer (what we use)
  214. *
  215. * We handle the IRQ according to _our_ priority which is:
  216. *
  217. * Highest ---- R4k Timer
  218. * Lowest ---- Combined hardware interrupt
  219. *
  220. * then we just return, if multiple IRQs are pending then we will just take
  221. * another exception, big deal.
  222. */
  223. asmlinkage void plat_irq_dispatch(void)
  224. {
  225. unsigned int pending = read_c0_cause() & read_c0_status() & ST0_IM;
  226. int irq;
  227. irq = irq_ffs(pending);
  228. if (irq == MIPSCPU_INT_I8259A)
  229. malta_hw0_irqdispatch();
  230. else if (irq >= 0)
  231. do_IRQ(MIPS_CPU_IRQ_BASE + irq);
  232. else
  233. spurious_interrupt();
  234. }
  235. static struct irqaction i8259irq = {
  236. .handler = no_action,
  237. .name = "XT-PIC cascade"
  238. };
  239. static struct irqaction corehi_irqaction = {
  240. .handler = no_action,
  241. .name = "CoreHi"
  242. };
  243. msc_irqmap_t __initdata msc_irqmap[] = {
  244. {MSC01C_INT_TMR, MSC01_IRQ_EDGE, 0},
  245. {MSC01C_INT_PCI, MSC01_IRQ_LEVEL, 0},
  246. };
  247. int __initdata msc_nr_irqs = ARRAY_SIZE(msc_irqmap);
  248. msc_irqmap_t __initdata msc_eicirqmap[] = {
  249. {MSC01E_INT_SW0, MSC01_IRQ_LEVEL, 0},
  250. {MSC01E_INT_SW1, MSC01_IRQ_LEVEL, 0},
  251. {MSC01E_INT_I8259A, MSC01_IRQ_LEVEL, 0},
  252. {MSC01E_INT_SMI, MSC01_IRQ_LEVEL, 0},
  253. {MSC01E_INT_COREHI, MSC01_IRQ_LEVEL, 0},
  254. {MSC01E_INT_CORELO, MSC01_IRQ_LEVEL, 0},
  255. {MSC01E_INT_TMR, MSC01_IRQ_EDGE, 0},
  256. {MSC01E_INT_PCI, MSC01_IRQ_LEVEL, 0},
  257. {MSC01E_INT_PERFCTR, MSC01_IRQ_LEVEL, 0},
  258. {MSC01E_INT_CPUCTR, MSC01_IRQ_LEVEL, 0}
  259. };
  260. int __initdata msc_nr_eicirqs = ARRAY_SIZE(msc_eicirqmap);
  261. void __init arch_init_irq(void)
  262. {
  263. init_i8259_irqs();
  264. if (!cpu_has_veic)
  265. mips_cpu_irq_init();
  266. switch (mips_revision_sconid) {
  267. case MIPS_REVISION_SCON_SOCIT:
  268. case MIPS_REVISION_SCON_ROCIT:
  269. if (cpu_has_veic)
  270. init_msc_irqs(MIPS_MSC01_IC_REG_BASE,
  271. MSC01E_INT_BASE, msc_eicirqmap,
  272. msc_nr_eicirqs);
  273. else
  274. init_msc_irqs(MIPS_MSC01_IC_REG_BASE,
  275. MSC01C_INT_BASE, msc_irqmap,
  276. msc_nr_irqs);
  277. break;
  278. case MIPS_REVISION_SCON_SOCITSC:
  279. case MIPS_REVISION_SCON_SOCITSCP:
  280. if (cpu_has_veic)
  281. init_msc_irqs(MIPS_SOCITSC_IC_REG_BASE,
  282. MSC01E_INT_BASE, msc_eicirqmap,
  283. msc_nr_eicirqs);
  284. else
  285. init_msc_irqs(MIPS_SOCITSC_IC_REG_BASE,
  286. MSC01C_INT_BASE, msc_irqmap,
  287. msc_nr_irqs);
  288. }
  289. if (cpu_has_veic) {
  290. set_vi_handler(MSC01E_INT_I8259A, malta_hw0_irqdispatch);
  291. set_vi_handler(MSC01E_INT_COREHI, corehi_irqdispatch);
  292. setup_irq(MSC01E_INT_BASE+MSC01E_INT_I8259A, &i8259irq);
  293. setup_irq(MSC01E_INT_BASE+MSC01E_INT_COREHI, &corehi_irqaction);
  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(MIPS_CPU_IRQ_BASE+MIPSCPU_INT_I8259A, &i8259irq,
  299. (0x100 << MIPSCPU_INT_I8259A));
  300. setup_irq_smtc(MIPS_CPU_IRQ_BASE+MIPSCPU_INT_COREHI,
  301. &corehi_irqaction, (0x100 << MIPSCPU_INT_COREHI));
  302. /*
  303. * Temporary hack to ensure that the subsidiary device
  304. * interrupts coing in via the i8259A, but associated
  305. * with low IRQ numbers, will restore the Status.IM
  306. * value associated with the i8259A.
  307. */
  308. {
  309. int i;
  310. for (i = 0; i < 16; i++)
  311. irq_hwmask[i] = (0x100 << MIPSCPU_INT_I8259A);
  312. }
  313. #else /* Not SMTC */
  314. setup_irq(MIPS_CPU_IRQ_BASE+MIPSCPU_INT_I8259A, &i8259irq);
  315. setup_irq(MIPS_CPU_IRQ_BASE+MIPSCPU_INT_COREHI,
  316. &corehi_irqaction);
  317. #endif /* CONFIG_MIPS_MT_SMTC */
  318. } else {
  319. setup_irq(MIPS_CPU_IRQ_BASE+MIPSCPU_INT_I8259A, &i8259irq);
  320. setup_irq(MIPS_CPU_IRQ_BASE+MIPSCPU_INT_COREHI,
  321. &corehi_irqaction);
  322. }
  323. }