malta-int.c 19 KB

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