malta-int.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712
  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/traps.h>
  34. #include <asm/i8259.h>
  35. #include <asm/irq_cpu.h>
  36. #include <asm/irq_regs.h>
  37. #include <asm/mips-boards/malta.h>
  38. #include <asm/mips-boards/maltaint.h>
  39. #include <asm/mips-boards/piix4.h>
  40. #include <asm/gt64120.h>
  41. #include <asm/mips-boards/generic.h>
  42. #include <asm/mips-boards/msc01_pci.h>
  43. #include <asm/msc01_ic.h>
  44. #include <asm/gic.h>
  45. #include <asm/gcmpregs.h>
  46. int gcmp_present = -1;
  47. int gic_present;
  48. static unsigned long _msc01_biu_base;
  49. static unsigned long _gcmp_base;
  50. static unsigned int ipi_map[NR_CPUS];
  51. static DEFINE_SPINLOCK(mips_irq_lock);
  52. static inline int mips_pcibios_iack(void)
  53. {
  54. int irq;
  55. u32 dummy;
  56. /*
  57. * Determine highest priority pending interrupt by performing
  58. * a PCI Interrupt Acknowledge cycle.
  59. */
  60. switch (mips_revision_sconid) {
  61. case MIPS_REVISION_SCON_SOCIT:
  62. case MIPS_REVISION_SCON_ROCIT:
  63. case MIPS_REVISION_SCON_SOCITSC:
  64. case MIPS_REVISION_SCON_SOCITSCP:
  65. MSC_READ(MSC01_PCI_IACK, irq);
  66. irq &= 0xff;
  67. break;
  68. case MIPS_REVISION_SCON_GT64120:
  69. irq = GT_READ(GT_PCI0_IACK_OFS);
  70. irq &= 0xff;
  71. break;
  72. case MIPS_REVISION_SCON_BONITO:
  73. /* The following will generate a PCI IACK cycle on the
  74. * Bonito controller. It's a little bit kludgy, but it
  75. * was the easiest way to implement it in hardware at
  76. * the given time.
  77. */
  78. BONITO_PCIMAP_CFG = 0x20000;
  79. /* Flush Bonito register block */
  80. dummy = BONITO_PCIMAP_CFG;
  81. iob(); /* sync */
  82. irq = readl((u32 *)_pcictrl_bonito_pcicfg);
  83. iob(); /* sync */
  84. irq &= 0xff;
  85. BONITO_PCIMAP_CFG = 0;
  86. break;
  87. default:
  88. printk(KERN_WARNING "Unknown system controller.\n");
  89. return -1;
  90. }
  91. return irq;
  92. }
  93. static inline int get_int(void)
  94. {
  95. unsigned long flags;
  96. int irq;
  97. spin_lock_irqsave(&mips_irq_lock, flags);
  98. irq = mips_pcibios_iack();
  99. /*
  100. * The only way we can decide if an interrupt is spurious
  101. * is by checking the 8259 registers. This needs a spinlock
  102. * on an SMP system, so leave it up to the generic code...
  103. */
  104. spin_unlock_irqrestore(&mips_irq_lock, flags);
  105. return irq;
  106. }
  107. static void malta_hw0_irqdispatch(void)
  108. {
  109. int irq;
  110. irq = get_int();
  111. if (irq < 0) {
  112. /* interrupt has already been cleared */
  113. return;
  114. }
  115. do_IRQ(MALTA_INT_BASE + irq);
  116. }
  117. static void malta_ipi_irqdispatch(void)
  118. {
  119. int irq;
  120. irq = gic_get_int();
  121. if (irq < 0)
  122. return; /* interrupt has already been cleared */
  123. do_IRQ(MIPS_GIC_IRQ_BASE + irq);
  124. }
  125. static void corehi_irqdispatch(void)
  126. {
  127. unsigned int intedge, intsteer, pcicmd, pcibadaddr;
  128. unsigned int pcimstat, intisr, inten, intpol;
  129. unsigned int intrcause, datalo, datahi;
  130. struct pt_regs *regs = get_irq_regs();
  131. printk(KERN_EMERG "CoreHI interrupt, shouldn't happen, we die here!\n");
  132. printk(KERN_EMERG "epc : %08lx\nStatus: %08lx\n"
  133. "Cause : %08lx\nbadVaddr : %08lx\n",
  134. regs->cp0_epc, regs->cp0_status,
  135. regs->cp0_cause, regs->cp0_badvaddr);
  136. /* Read all the registers and then print them as there is a
  137. problem with interspersed printk's upsetting the Bonito controller.
  138. Do it for the others too.
  139. */
  140. switch (mips_revision_sconid) {
  141. case MIPS_REVISION_SCON_SOCIT:
  142. case MIPS_REVISION_SCON_ROCIT:
  143. case MIPS_REVISION_SCON_SOCITSC:
  144. case MIPS_REVISION_SCON_SOCITSCP:
  145. ll_msc_irq();
  146. break;
  147. case MIPS_REVISION_SCON_GT64120:
  148. intrcause = GT_READ(GT_INTRCAUSE_OFS);
  149. datalo = GT_READ(GT_CPUERR_ADDRLO_OFS);
  150. datahi = GT_READ(GT_CPUERR_ADDRHI_OFS);
  151. printk(KERN_EMERG "GT_INTRCAUSE = %08x\n", intrcause);
  152. printk(KERN_EMERG "GT_CPUERR_ADDR = %02x%08x\n",
  153. datahi, datalo);
  154. break;
  155. case MIPS_REVISION_SCON_BONITO:
  156. pcibadaddr = BONITO_PCIBADADDR;
  157. pcimstat = BONITO_PCIMSTAT;
  158. intisr = BONITO_INTISR;
  159. inten = BONITO_INTEN;
  160. intpol = BONITO_INTPOL;
  161. intedge = BONITO_INTEDGE;
  162. intsteer = BONITO_INTSTEER;
  163. pcicmd = BONITO_PCICMD;
  164. printk(KERN_EMERG "BONITO_INTISR = %08x\n", intisr);
  165. printk(KERN_EMERG "BONITO_INTEN = %08x\n", inten);
  166. printk(KERN_EMERG "BONITO_INTPOL = %08x\n", intpol);
  167. printk(KERN_EMERG "BONITO_INTEDGE = %08x\n", intedge);
  168. printk(KERN_EMERG "BONITO_INTSTEER = %08x\n", intsteer);
  169. printk(KERN_EMERG "BONITO_PCICMD = %08x\n", pcicmd);
  170. printk(KERN_EMERG "BONITO_PCIBADADDR = %08x\n", pcibadaddr);
  171. printk(KERN_EMERG "BONITO_PCIMSTAT = %08x\n", pcimstat);
  172. break;
  173. }
  174. die("CoreHi interrupt", regs);
  175. }
  176. static inline int clz(unsigned long x)
  177. {
  178. __asm__(
  179. " .set push \n"
  180. " .set mips32 \n"
  181. " clz %0, %1 \n"
  182. " .set pop \n"
  183. : "=r" (x)
  184. : "r" (x));
  185. return x;
  186. }
  187. /*
  188. * Version of ffs that only looks at bits 12..15.
  189. */
  190. static inline unsigned int irq_ffs(unsigned int pending)
  191. {
  192. #if defined(CONFIG_CPU_MIPS32) || defined(CONFIG_CPU_MIPS64)
  193. return -clz(pending) + 31 - CAUSEB_IP;
  194. #else
  195. unsigned int a0 = 7;
  196. unsigned int t0;
  197. t0 = pending & 0xf000;
  198. t0 = t0 < 1;
  199. t0 = t0 << 2;
  200. a0 = a0 - t0;
  201. pending = pending << t0;
  202. t0 = pending & 0xc000;
  203. t0 = t0 < 1;
  204. t0 = t0 << 1;
  205. a0 = a0 - t0;
  206. pending = pending << t0;
  207. t0 = pending & 0x8000;
  208. t0 = t0 < 1;
  209. /* t0 = t0 << 2; */
  210. a0 = a0 - t0;
  211. /* pending = pending << t0; */
  212. return a0;
  213. #endif
  214. }
  215. /*
  216. * IRQs on the Malta board look basically (barring software IRQs which we
  217. * don't use at all and all external interrupt sources are combined together
  218. * on hardware interrupt 0 (MIPS IRQ 2)) like:
  219. *
  220. * MIPS IRQ Source
  221. * -------- ------
  222. * 0 Software (ignored)
  223. * 1 Software (ignored)
  224. * 2 Combined hardware interrupt (hw0)
  225. * 3 Hardware (ignored)
  226. * 4 Hardware (ignored)
  227. * 5 Hardware (ignored)
  228. * 6 Hardware (ignored)
  229. * 7 R4k timer (what we use)
  230. *
  231. * We handle the IRQ according to _our_ priority which is:
  232. *
  233. * Highest ---- R4k Timer
  234. * Lowest ---- Combined hardware interrupt
  235. *
  236. * then we just return, if multiple IRQs are pending then we will just take
  237. * another exception, big deal.
  238. */
  239. asmlinkage void plat_irq_dispatch(void)
  240. {
  241. unsigned int pending = read_c0_cause() & read_c0_status() & ST0_IM;
  242. int irq;
  243. irq = irq_ffs(pending);
  244. if (irq == MIPSCPU_INT_I8259A)
  245. malta_hw0_irqdispatch();
  246. else if (gic_present && ((1 << irq) & ipi_map[smp_processor_id()]))
  247. malta_ipi_irqdispatch();
  248. else if (irq >= 0)
  249. do_IRQ(MIPS_CPU_IRQ_BASE + irq);
  250. else
  251. spurious_interrupt();
  252. }
  253. #ifdef CONFIG_MIPS_MT_SMP
  254. #define GIC_MIPS_CPU_IPI_RESCHED_IRQ 3
  255. #define GIC_MIPS_CPU_IPI_CALL_IRQ 4
  256. #define MIPS_CPU_IPI_RESCHED_IRQ 0 /* SW int 0 for resched */
  257. #define C_RESCHED C_SW0
  258. #define MIPS_CPU_IPI_CALL_IRQ 1 /* SW int 1 for resched */
  259. #define C_CALL C_SW1
  260. static int cpu_ipi_resched_irq, cpu_ipi_call_irq;
  261. static void ipi_resched_dispatch(void)
  262. {
  263. do_IRQ(MIPS_CPU_IRQ_BASE + MIPS_CPU_IPI_RESCHED_IRQ);
  264. }
  265. static void ipi_call_dispatch(void)
  266. {
  267. do_IRQ(MIPS_CPU_IRQ_BASE + MIPS_CPU_IPI_CALL_IRQ);
  268. }
  269. static irqreturn_t ipi_resched_interrupt(int irq, void *dev_id)
  270. {
  271. return IRQ_HANDLED;
  272. }
  273. static irqreturn_t ipi_call_interrupt(int irq, void *dev_id)
  274. {
  275. smp_call_function_interrupt();
  276. return IRQ_HANDLED;
  277. }
  278. static struct irqaction irq_resched = {
  279. .handler = ipi_resched_interrupt,
  280. .flags = IRQF_DISABLED|IRQF_PERCPU,
  281. .name = "IPI_resched"
  282. };
  283. static struct irqaction irq_call = {
  284. .handler = ipi_call_interrupt,
  285. .flags = IRQF_DISABLED|IRQF_PERCPU,
  286. .name = "IPI_call"
  287. };
  288. #endif /* CONFIG_MIPS_MT_SMP */
  289. static struct irqaction i8259irq = {
  290. .handler = no_action,
  291. .name = "XT-PIC cascade"
  292. };
  293. static struct irqaction corehi_irqaction = {
  294. .handler = no_action,
  295. .name = "CoreHi"
  296. };
  297. static msc_irqmap_t __initdata msc_irqmap[] = {
  298. {MSC01C_INT_TMR, MSC01_IRQ_EDGE, 0},
  299. {MSC01C_INT_PCI, MSC01_IRQ_LEVEL, 0},
  300. };
  301. static int __initdata msc_nr_irqs = ARRAY_SIZE(msc_irqmap);
  302. static msc_irqmap_t __initdata msc_eicirqmap[] = {
  303. {MSC01E_INT_SW0, MSC01_IRQ_LEVEL, 0},
  304. {MSC01E_INT_SW1, MSC01_IRQ_LEVEL, 0},
  305. {MSC01E_INT_I8259A, MSC01_IRQ_LEVEL, 0},
  306. {MSC01E_INT_SMI, MSC01_IRQ_LEVEL, 0},
  307. {MSC01E_INT_COREHI, MSC01_IRQ_LEVEL, 0},
  308. {MSC01E_INT_CORELO, MSC01_IRQ_LEVEL, 0},
  309. {MSC01E_INT_TMR, MSC01_IRQ_EDGE, 0},
  310. {MSC01E_INT_PCI, MSC01_IRQ_LEVEL, 0},
  311. {MSC01E_INT_PERFCTR, MSC01_IRQ_LEVEL, 0},
  312. {MSC01E_INT_CPUCTR, MSC01_IRQ_LEVEL, 0}
  313. };
  314. static int __initdata msc_nr_eicirqs = ARRAY_SIZE(msc_eicirqmap);
  315. #if defined(CONFIG_MIPS_MT_SMP)
  316. /*
  317. * This GIC specific tabular array defines the association between External
  318. * Interrupts and CPUs/Core Interrupts. The nature of the External
  319. * Interrupts is also defined here - polarity/trigger.
  320. */
  321. static struct gic_intr_map gic_intr_map[] = {
  322. { GIC_EXT_INTR(0), X, X, X, X, 0 },
  323. { GIC_EXT_INTR(1), X, X, X, X, 0 },
  324. { GIC_EXT_INTR(2), X, X, X, X, 0 },
  325. { GIC_EXT_INTR(3), 0, GIC_CPU_INT0, GIC_POL_POS, GIC_TRIG_LEVEL, 0 },
  326. { GIC_EXT_INTR(4), 0, GIC_CPU_INT1, GIC_POL_POS, GIC_TRIG_LEVEL, 0 },
  327. { GIC_EXT_INTR(5), 0, GIC_CPU_INT2, GIC_POL_POS, GIC_TRIG_LEVEL, 0 },
  328. { GIC_EXT_INTR(6), 0, GIC_CPU_INT3, GIC_POL_POS, GIC_TRIG_LEVEL, 0 },
  329. { GIC_EXT_INTR(7), 0, GIC_CPU_INT4, GIC_POL_POS, GIC_TRIG_LEVEL, 0 },
  330. { GIC_EXT_INTR(8), 0, GIC_CPU_INT3, GIC_POL_POS, GIC_TRIG_LEVEL, 0 },
  331. { GIC_EXT_INTR(9), 0, GIC_CPU_INT3, GIC_POL_POS, GIC_TRIG_LEVEL, 0 },
  332. { GIC_EXT_INTR(10), X, X, X, X, 0 },
  333. { GIC_EXT_INTR(11), X, X, X, X, 0 },
  334. { GIC_EXT_INTR(12), 0, GIC_CPU_INT3, GIC_POL_POS, GIC_TRIG_LEVEL, 0 },
  335. { GIC_EXT_INTR(13), 0, GIC_MAP_TO_NMI_MSK, GIC_POL_POS, GIC_TRIG_LEVEL, 0 },
  336. { GIC_EXT_INTR(14), 0, GIC_MAP_TO_NMI_MSK, GIC_POL_POS, GIC_TRIG_LEVEL, 0 },
  337. { GIC_EXT_INTR(15), X, X, X, X, 0 },
  338. { GIC_EXT_INTR(16), 0, GIC_CPU_INT1, GIC_POL_POS, GIC_TRIG_EDGE, 1 },
  339. { GIC_EXT_INTR(17), 0, GIC_CPU_INT2, GIC_POL_POS, GIC_TRIG_EDGE, 1 },
  340. { GIC_EXT_INTR(18), 1, GIC_CPU_INT1, GIC_POL_POS, GIC_TRIG_EDGE, 1 },
  341. { GIC_EXT_INTR(19), 1, GIC_CPU_INT2, GIC_POL_POS, GIC_TRIG_EDGE, 1 },
  342. { GIC_EXT_INTR(20), 2, GIC_CPU_INT1, GIC_POL_POS, GIC_TRIG_EDGE, 1 },
  343. { GIC_EXT_INTR(21), 2, GIC_CPU_INT2, GIC_POL_POS, GIC_TRIG_EDGE, 1 },
  344. { GIC_EXT_INTR(22), 3, GIC_CPU_INT1, GIC_POL_POS, GIC_TRIG_EDGE, 1 },
  345. { GIC_EXT_INTR(23), 3, GIC_CPU_INT2, GIC_POL_POS, GIC_TRIG_EDGE, 1 },
  346. };
  347. #endif
  348. /*
  349. * GCMP needs to be detected before any SMP initialisation
  350. */
  351. static int __init gcmp_probe(unsigned long addr, unsigned long size)
  352. {
  353. if (gcmp_present >= 0)
  354. return gcmp_present;
  355. _gcmp_base = (unsigned long) ioremap_nocache(GCMP_BASE_ADDR, GCMP_ADDRSPACE_SZ);
  356. _msc01_biu_base = (unsigned long) ioremap_nocache(MSC01_BIU_REG_BASE, MSC01_BIU_ADDRSPACE_SZ);
  357. gcmp_present = (GCMPGCB(GCMPB) & GCMP_GCB_GCMPB_GCMPBASE_MSK) == GCMP_BASE_ADDR;
  358. if (gcmp_present)
  359. printk(KERN_DEBUG "GCMP present\n");
  360. return gcmp_present;
  361. }
  362. #if defined(CONFIG_MIPS_MT_SMP)
  363. static void __init fill_ipi_map(void)
  364. {
  365. int i;
  366. for (i = 0; i < ARRAY_SIZE(gic_intr_map); i++) {
  367. if (gic_intr_map[i].ipiflag && (gic_intr_map[i].cpunum != X))
  368. ipi_map[gic_intr_map[i].cpunum] |=
  369. (1 << (gic_intr_map[i].pin + 2));
  370. }
  371. }
  372. #endif
  373. void __init arch_init_irq(void)
  374. {
  375. int gic_present, gcmp_present;
  376. init_i8259_irqs();
  377. if (!cpu_has_veic)
  378. mips_cpu_irq_init();
  379. gcmp_present = gcmp_probe(GCMP_BASE_ADDR, GCMP_ADDRSPACE_SZ);
  380. if (gcmp_present) {
  381. GCMPGCB(GICBA) = GIC_BASE_ADDR | GCMP_GCB_GICBA_EN_MSK;
  382. gic_present = 1;
  383. } else {
  384. _msc01_biu_base = (unsigned long) ioremap_nocache(MSC01_BIU_REG_BASE, MSC01_BIU_ADDRSPACE_SZ);
  385. gic_present = (REG(_msc01_biu_base, MSC01_SC_CFG) &
  386. MSC01_SC_CFG_GICPRES_MSK) >> MSC01_SC_CFG_GICPRES_SHF;
  387. }
  388. if (gic_present)
  389. printk(KERN_DEBUG "GIC present\n");
  390. switch (mips_revision_sconid) {
  391. case MIPS_REVISION_SCON_SOCIT:
  392. case MIPS_REVISION_SCON_ROCIT:
  393. if (cpu_has_veic)
  394. init_msc_irqs(MIPS_MSC01_IC_REG_BASE,
  395. MSC01E_INT_BASE, msc_eicirqmap,
  396. msc_nr_eicirqs);
  397. else
  398. init_msc_irqs(MIPS_MSC01_IC_REG_BASE,
  399. MSC01C_INT_BASE, msc_irqmap,
  400. msc_nr_irqs);
  401. break;
  402. case MIPS_REVISION_SCON_SOCITSC:
  403. case MIPS_REVISION_SCON_SOCITSCP:
  404. if (cpu_has_veic)
  405. init_msc_irqs(MIPS_SOCITSC_IC_REG_BASE,
  406. MSC01E_INT_BASE, msc_eicirqmap,
  407. msc_nr_eicirqs);
  408. else
  409. init_msc_irqs(MIPS_SOCITSC_IC_REG_BASE,
  410. MSC01C_INT_BASE, msc_irqmap,
  411. msc_nr_irqs);
  412. }
  413. if (cpu_has_veic) {
  414. set_vi_handler(MSC01E_INT_I8259A, malta_hw0_irqdispatch);
  415. set_vi_handler(MSC01E_INT_COREHI, corehi_irqdispatch);
  416. setup_irq(MSC01E_INT_BASE+MSC01E_INT_I8259A, &i8259irq);
  417. setup_irq(MSC01E_INT_BASE+MSC01E_INT_COREHI, &corehi_irqaction);
  418. } else if (cpu_has_vint) {
  419. set_vi_handler(MIPSCPU_INT_I8259A, malta_hw0_irqdispatch);
  420. set_vi_handler(MIPSCPU_INT_COREHI, corehi_irqdispatch);
  421. #ifdef CONFIG_MIPS_MT_SMTC
  422. setup_irq_smtc(MIPS_CPU_IRQ_BASE+MIPSCPU_INT_I8259A, &i8259irq,
  423. (0x100 << MIPSCPU_INT_I8259A));
  424. setup_irq_smtc(MIPS_CPU_IRQ_BASE+MIPSCPU_INT_COREHI,
  425. &corehi_irqaction, (0x100 << MIPSCPU_INT_COREHI));
  426. /*
  427. * Temporary hack to ensure that the subsidiary device
  428. * interrupts coing in via the i8259A, but associated
  429. * with low IRQ numbers, will restore the Status.IM
  430. * value associated with the i8259A.
  431. */
  432. {
  433. int i;
  434. for (i = 0; i < 16; i++)
  435. irq_hwmask[i] = (0x100 << MIPSCPU_INT_I8259A);
  436. }
  437. #else /* Not SMTC */
  438. setup_irq(MIPS_CPU_IRQ_BASE+MIPSCPU_INT_I8259A, &i8259irq);
  439. setup_irq(MIPS_CPU_IRQ_BASE+MIPSCPU_INT_COREHI,
  440. &corehi_irqaction);
  441. #endif /* CONFIG_MIPS_MT_SMTC */
  442. } else {
  443. setup_irq(MIPS_CPU_IRQ_BASE+MIPSCPU_INT_I8259A, &i8259irq);
  444. setup_irq(MIPS_CPU_IRQ_BASE+MIPSCPU_INT_COREHI,
  445. &corehi_irqaction);
  446. }
  447. #if defined(CONFIG_MIPS_MT_SMP)
  448. if (gic_present) {
  449. /* FIXME */
  450. int i;
  451. struct {
  452. unsigned int resched;
  453. unsigned int call;
  454. } ipiirq[] = {
  455. {
  456. .resched = GIC_IPI_EXT_INTR_RESCHED_VPE0,
  457. .call = GIC_IPI_EXT_INTR_CALLFNC_VPE0},
  458. {
  459. .resched = GIC_IPI_EXT_INTR_RESCHED_VPE1,
  460. .call = GIC_IPI_EXT_INTR_CALLFNC_VPE1
  461. }, {
  462. .resched = GIC_IPI_EXT_INTR_RESCHED_VPE2,
  463. .call = GIC_IPI_EXT_INTR_CALLFNC_VPE2
  464. }, {
  465. .resched = GIC_IPI_EXT_INTR_RESCHED_VPE3,
  466. .call = GIC_IPI_EXT_INTR_CALLFNC_VPE3
  467. }
  468. };
  469. fill_ipi_map();
  470. gic_init(GIC_BASE_ADDR, GIC_ADDRSPACE_SZ, gic_intr_map, ARRAY_SIZE(gic_intr_map), MIPS_GIC_IRQ_BASE);
  471. if (!gcmp_present) {
  472. /* Enable the GIC */
  473. i = REG(_msc01_biu_base, MSC01_SC_CFG);
  474. REG(_msc01_biu_base, MSC01_SC_CFG) =
  475. (i | (0x1 << MSC01_SC_CFG_GICENA_SHF));
  476. pr_debug("GIC Enabled\n");
  477. }
  478. /* set up ipi interrupts */
  479. if (cpu_has_vint) {
  480. set_vi_handler(MIPSCPU_INT_IPI0, malta_ipi_irqdispatch);
  481. set_vi_handler(MIPSCPU_INT_IPI1, malta_ipi_irqdispatch);
  482. }
  483. /* Argh.. this really needs sorting out.. */
  484. printk("CPU%d: status register was %08x\n", smp_processor_id(), read_c0_status());
  485. write_c0_status(read_c0_status() | STATUSF_IP3 | STATUSF_IP4);
  486. printk("CPU%d: status register now %08x\n", smp_processor_id(), read_c0_status());
  487. write_c0_status(0x1100dc00);
  488. printk("CPU%d: status register frc %08x\n", smp_processor_id(), read_c0_status());
  489. for (i = 0; i < ARRAY_SIZE(ipiirq); i++) {
  490. setup_irq(MIPS_GIC_IRQ_BASE + ipiirq[i].resched, &irq_resched);
  491. setup_irq(MIPS_GIC_IRQ_BASE + ipiirq[i].call, &irq_call);
  492. set_irq_handler(MIPS_GIC_IRQ_BASE + ipiirq[i].resched, handle_percpu_irq);
  493. set_irq_handler(MIPS_GIC_IRQ_BASE + ipiirq[i].call, handle_percpu_irq);
  494. }
  495. } else {
  496. /* set up ipi interrupts */
  497. if (cpu_has_veic) {
  498. set_vi_handler (MSC01E_INT_SW0, ipi_resched_dispatch);
  499. set_vi_handler (MSC01E_INT_SW1, ipi_call_dispatch);
  500. cpu_ipi_resched_irq = MSC01E_INT_SW0;
  501. cpu_ipi_call_irq = MSC01E_INT_SW1;
  502. } else {
  503. if (cpu_has_vint) {
  504. set_vi_handler (MIPS_CPU_IPI_RESCHED_IRQ, ipi_resched_dispatch);
  505. set_vi_handler (MIPS_CPU_IPI_CALL_IRQ, ipi_call_dispatch);
  506. }
  507. cpu_ipi_resched_irq = MIPS_CPU_IRQ_BASE + MIPS_CPU_IPI_RESCHED_IRQ;
  508. cpu_ipi_call_irq = MIPS_CPU_IRQ_BASE + MIPS_CPU_IPI_CALL_IRQ;
  509. }
  510. setup_irq(cpu_ipi_resched_irq, &irq_resched);
  511. setup_irq(cpu_ipi_call_irq, &irq_call);
  512. set_irq_handler(cpu_ipi_resched_irq, handle_percpu_irq);
  513. set_irq_handler(cpu_ipi_call_irq, handle_percpu_irq);
  514. }
  515. #endif
  516. }
  517. void malta_be_init(void)
  518. {
  519. if (gcmp_present) {
  520. /* Could change CM error mask register */
  521. }
  522. }
  523. static char *tr[8] = {
  524. "mem", "gcr", "gic", "mmio",
  525. "0x04", "0x05", "0x06", "0x07"
  526. };
  527. static char *mcmd[32] = {
  528. [0x00] = "0x00",
  529. [0x01] = "Legacy Write",
  530. [0x02] = "Legacy Read",
  531. [0x03] = "0x03",
  532. [0x04] = "0x04",
  533. [0x05] = "0x05",
  534. [0x06] = "0x06",
  535. [0x07] = "0x07",
  536. [0x08] = "Coherent Read Own",
  537. [0x09] = "Coherent Read Share",
  538. [0x0a] = "Coherent Read Discard",
  539. [0x0b] = "Coherent Ready Share Always",
  540. [0x0c] = "Coherent Upgrade",
  541. [0x0d] = "Coherent Writeback",
  542. [0x0e] = "0x0e",
  543. [0x0f] = "0x0f",
  544. [0x10] = "Coherent Copyback",
  545. [0x11] = "Coherent Copyback Invalidate",
  546. [0x12] = "Coherent Invalidate",
  547. [0x13] = "Coherent Write Invalidate",
  548. [0x14] = "Coherent Completion Sync",
  549. [0x15] = "0x15",
  550. [0x16] = "0x16",
  551. [0x17] = "0x17",
  552. [0x18] = "0x18",
  553. [0x19] = "0x19",
  554. [0x1a] = "0x1a",
  555. [0x1b] = "0x1b",
  556. [0x1c] = "0x1c",
  557. [0x1d] = "0x1d",
  558. [0x1e] = "0x1e",
  559. [0x1f] = "0x1f"
  560. };
  561. static char *core[8] = {
  562. "Invalid/OK", "Invalid/Data",
  563. "Shared/OK", "Shared/Data",
  564. "Modified/OK", "Modified/Data",
  565. "Exclusive/OK", "Exclusive/Data"
  566. };
  567. static char *causes[32] = {
  568. "None", "GC_WR_ERR", "GC_RD_ERR", "COH_WR_ERR",
  569. "COH_RD_ERR", "MMIO_WR_ERR", "MMIO_RD_ERR", "0x07",
  570. "0x08", "0x09", "0x0a", "0x0b",
  571. "0x0c", "0x0d", "0x0e", "0x0f",
  572. "0x10", "0x11", "0x12", "0x13",
  573. "0x14", "0x15", "0x16", "INTVN_WR_ERR",
  574. "INTVN_RD_ERR", "0x19", "0x1a", "0x1b",
  575. "0x1c", "0x1d", "0x1e", "0x1f"
  576. };
  577. int malta_be_handler(struct pt_regs *regs, int is_fixup)
  578. {
  579. /* This duplicates the handling in do_be which seems wrong */
  580. int retval = is_fixup ? MIPS_BE_FIXUP : MIPS_BE_FATAL;
  581. if (gcmp_present) {
  582. unsigned long cm_error = GCMPGCB(GCMEC);
  583. unsigned long cm_addr = GCMPGCB(GCMEA);
  584. unsigned long cm_other = GCMPGCB(GCMEO);
  585. unsigned long cause, ocause;
  586. char buf[256];
  587. cause = (cm_error & GCMP_GCB_GMEC_ERROR_TYPE_MSK);
  588. if (cause != 0) {
  589. cause >>= GCMP_GCB_GMEC_ERROR_TYPE_SHF;
  590. if (cause < 16) {
  591. unsigned long cca_bits = (cm_error >> 15) & 7;
  592. unsigned long tr_bits = (cm_error >> 12) & 7;
  593. unsigned long mcmd_bits = (cm_error >> 7) & 0x1f;
  594. unsigned long stag_bits = (cm_error >> 3) & 15;
  595. unsigned long sport_bits = (cm_error >> 0) & 7;
  596. snprintf(buf, sizeof(buf),
  597. "CCA=%lu TR=%s MCmd=%s STag=%lu "
  598. "SPort=%lu\n",
  599. cca_bits, tr[tr_bits], mcmd[mcmd_bits],
  600. stag_bits, sport_bits);
  601. } else {
  602. /* glob state & sresp together */
  603. unsigned long c3_bits = (cm_error >> 18) & 7;
  604. unsigned long c2_bits = (cm_error >> 15) & 7;
  605. unsigned long c1_bits = (cm_error >> 12) & 7;
  606. unsigned long c0_bits = (cm_error >> 9) & 7;
  607. unsigned long sc_bit = (cm_error >> 8) & 1;
  608. unsigned long mcmd_bits = (cm_error >> 3) & 0x1f;
  609. unsigned long sport_bits = (cm_error >> 0) & 7;
  610. snprintf(buf, sizeof(buf),
  611. "C3=%s C2=%s C1=%s C0=%s SC=%s "
  612. "MCmd=%s SPort=%lu\n",
  613. core[c3_bits], core[c2_bits],
  614. core[c1_bits], core[c0_bits],
  615. sc_bit ? "True" : "False",
  616. mcmd[mcmd_bits], sport_bits);
  617. }
  618. ocause = (cm_other & GCMP_GCB_GMEO_ERROR_2ND_MSK) >>
  619. GCMP_GCB_GMEO_ERROR_2ND_SHF;
  620. printk("CM_ERROR=%08lx %s <%s>\n", cm_error,
  621. causes[cause], buf);
  622. printk("CM_ADDR =%08lx\n", cm_addr);
  623. printk("CM_OTHER=%08lx %s\n", cm_other, causes[ocause]);
  624. /* reprime cause register */
  625. GCMPGCB(GCMEC) = 0;
  626. }
  627. }
  628. return retval;
  629. }