malta-int.c 20 KB

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