mv64360_pic.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428
  1. /*
  2. * Interrupt controller support for Marvell's MV64360.
  3. *
  4. * Author: Rabeeh Khoury <rabeeh@galileo.co.il>
  5. * Based on MV64360 PIC written by
  6. * Chris Zankel <chris@mvista.com>
  7. * Mark A. Greer <mgreer@mvista.com>
  8. *
  9. * Copyright 2004 MontaVista Software, Inc.
  10. *
  11. * This program is free software; you can redistribute it and/or modify it
  12. * under the terms of the GNU General Public License as published by the
  13. * Free Software Foundation; either version 2 of the License, or (at your
  14. * option) any later version.
  15. */
  16. /*
  17. * This file contains the specific functions to support the MV64360
  18. * interrupt controller.
  19. *
  20. * The MV64360 has two main interrupt registers (high and low) that
  21. * summarizes the interrupts generated by the units of the MV64360.
  22. * Each bit is assigned to an interrupt number, where the low register
  23. * are assigned from IRQ0 to IRQ31 and the high cause register
  24. * from IRQ32 to IRQ63
  25. * The GPP (General Purpose Pins) interrupts are assigned from IRQ64 (GPP0)
  26. * to IRQ95 (GPP31).
  27. * get_irq() returns the lowest interrupt number that is currently asserted.
  28. *
  29. * Note:
  30. * - This driver does not initialize the GPP when used as an interrupt
  31. * input.
  32. */
  33. #include <linux/stddef.h>
  34. #include <linux/init.h>
  35. #include <linux/sched.h>
  36. #include <linux/signal.h>
  37. #include <linux/stddef.h>
  38. #include <linux/delay.h>
  39. #include <linux/irq.h>
  40. #include <linux/interrupt.h>
  41. #include <asm/io.h>
  42. #include <asm/processor.h>
  43. #include <asm/system.h>
  44. #include <asm/irq.h>
  45. #include <asm/mv64x60.h>
  46. #include <asm/machdep.h>
  47. #ifdef CONFIG_IRQ_ALL_CPUS
  48. #error "The mv64360 does not support distribution of IRQs on all CPUs"
  49. #endif
  50. /* ========================== forward declaration ========================== */
  51. static void mv64360_unmask_irq(unsigned int);
  52. static void mv64360_mask_irq(unsigned int);
  53. static irqreturn_t mv64360_cpu_error_int_handler(int, void *, struct pt_regs *);
  54. static irqreturn_t mv64360_sram_error_int_handler(int, void *,
  55. struct pt_regs *);
  56. static irqreturn_t mv64360_pci_error_int_handler(int, void *, struct pt_regs *);
  57. /* ========================== local declarations =========================== */
  58. struct hw_interrupt_type mv64360_pic = {
  59. .typename = " mv64360 ",
  60. .enable = mv64360_unmask_irq,
  61. .disable = mv64360_mask_irq,
  62. .ack = mv64360_mask_irq,
  63. .end = mv64360_unmask_irq,
  64. };
  65. #define CPU_INTR_STR "mv64360 cpu interface error"
  66. #define SRAM_INTR_STR "mv64360 internal sram error"
  67. #define PCI0_INTR_STR "mv64360 pci 0 error"
  68. #define PCI1_INTR_STR "mv64360 pci 1 error"
  69. static struct mv64x60_handle bh;
  70. u32 mv64360_irq_base = 0; /* MV64360 handles the next 96 IRQs from here */
  71. /* mv64360_init_irq()
  72. *
  73. * This function initializes the interrupt controller. It assigns
  74. * all interrupts from IRQ0 to IRQ95 to the mv64360 interrupt controller.
  75. *
  76. * Input Variable(s):
  77. * None.
  78. *
  79. * Outpu. Variable(s):
  80. * None.
  81. *
  82. * Returns:
  83. * void
  84. *
  85. * Note:
  86. * We register all GPP inputs as interrupt source, but disable them.
  87. */
  88. void __init
  89. mv64360_init_irq(void)
  90. {
  91. int i;
  92. if (ppc_md.progress)
  93. ppc_md.progress("mv64360_init_irq: enter", 0x0);
  94. bh.v_base = mv64x60_get_bridge_vbase();
  95. ppc_cached_irq_mask[0] = 0;
  96. ppc_cached_irq_mask[1] = 0x0f000000; /* Enable GPP intrs */
  97. ppc_cached_irq_mask[2] = 0;
  98. /* disable all interrupts and clear current interrupts */
  99. mv64x60_write(&bh, MV64x60_GPP_INTR_CAUSE, 0);
  100. mv64x60_write(&bh, MV64x60_GPP_INTR_MASK, ppc_cached_irq_mask[2]);
  101. mv64x60_write(&bh, MV64360_IC_CPU0_INTR_MASK_LO,ppc_cached_irq_mask[0]);
  102. mv64x60_write(&bh, MV64360_IC_CPU0_INTR_MASK_HI,ppc_cached_irq_mask[1]);
  103. /* All interrupts are level interrupts */
  104. for (i = mv64360_irq_base; i < (mv64360_irq_base + 96); i++) {
  105. irq_desc[i].status |= IRQ_LEVEL;
  106. irq_desc[i].handler = &mv64360_pic;
  107. }
  108. if (ppc_md.progress)
  109. ppc_md.progress("mv64360_init_irq: exit", 0x0);
  110. }
  111. /* mv64360_get_irq()
  112. *
  113. * This function returns the lowest interrupt number of all interrupts that
  114. * are currently asserted.
  115. *
  116. * Input Variable(s):
  117. * struct pt_regs* not used
  118. *
  119. * Output Variable(s):
  120. * None.
  121. *
  122. * Returns:
  123. * int <interrupt number> or -2 (bogus interrupt)
  124. *
  125. */
  126. int
  127. mv64360_get_irq(struct pt_regs *regs)
  128. {
  129. int irq;
  130. int irq_gpp;
  131. #ifdef CONFIG_SMP
  132. /*
  133. * Second CPU gets only doorbell (message) interrupts.
  134. * The doorbell interrupt is BIT28 in the main interrupt low cause reg.
  135. */
  136. int cpu_nr = smp_processor_id();
  137. if (cpu_nr == 1) {
  138. if (!(mv64x60_read(&bh, MV64360_IC_MAIN_CAUSE_LO) &
  139. (1 << MV64x60_IRQ_DOORBELL)))
  140. return -1;
  141. return mv64360_irq_base + MV64x60_IRQ_DOORBELL;
  142. }
  143. #endif
  144. irq = mv64x60_read(&bh, MV64360_IC_MAIN_CAUSE_LO);
  145. irq = __ilog2((irq & 0x3dfffffe) & ppc_cached_irq_mask[0]);
  146. if (irq == -1) {
  147. irq = mv64x60_read(&bh, MV64360_IC_MAIN_CAUSE_HI);
  148. irq = __ilog2((irq & 0x1f0003f7) & ppc_cached_irq_mask[1]);
  149. if (irq == -1)
  150. irq = -2; /* bogus interrupt, should never happen */
  151. else {
  152. if ((irq >= 24) && (irq < MV64x60_IRQ_DOORBELL)) {
  153. irq_gpp = mv64x60_read(&bh,
  154. MV64x60_GPP_INTR_CAUSE);
  155. irq_gpp = __ilog2(irq_gpp &
  156. ppc_cached_irq_mask[2]);
  157. if (irq_gpp == -1)
  158. irq = -2;
  159. else {
  160. irq = irq_gpp + 64;
  161. mv64x60_write(&bh,
  162. MV64x60_GPP_INTR_CAUSE,
  163. ~(1 << (irq - 64)));
  164. }
  165. }
  166. else
  167. irq += 32;
  168. }
  169. }
  170. (void)mv64x60_read(&bh, MV64x60_GPP_INTR_CAUSE);
  171. if (irq < 0)
  172. return (irq);
  173. else
  174. return (mv64360_irq_base + irq);
  175. }
  176. /* mv64360_unmask_irq()
  177. *
  178. * This function enables an interrupt.
  179. *
  180. * Input Variable(s):
  181. * unsigned int interrupt number (IRQ0...IRQ95).
  182. *
  183. * Output Variable(s):
  184. * None.
  185. *
  186. * Returns:
  187. * void
  188. */
  189. static void
  190. mv64360_unmask_irq(unsigned int irq)
  191. {
  192. #ifdef CONFIG_SMP
  193. /* second CPU gets only doorbell interrupts */
  194. if ((irq - mv64360_irq_base) == MV64x60_IRQ_DOORBELL) {
  195. mv64x60_set_bits(&bh, MV64360_IC_CPU1_INTR_MASK_LO,
  196. (1 << MV64x60_IRQ_DOORBELL));
  197. return;
  198. }
  199. #endif
  200. irq -= mv64360_irq_base;
  201. if (irq > 31) {
  202. if (irq > 63) /* unmask GPP irq */
  203. mv64x60_write(&bh, MV64x60_GPP_INTR_MASK,
  204. ppc_cached_irq_mask[2] |= (1 << (irq - 64)));
  205. else /* mask high interrupt register */
  206. mv64x60_write(&bh, MV64360_IC_CPU0_INTR_MASK_HI,
  207. ppc_cached_irq_mask[1] |= (1 << (irq - 32)));
  208. }
  209. else /* mask low interrupt register */
  210. mv64x60_write(&bh, MV64360_IC_CPU0_INTR_MASK_LO,
  211. ppc_cached_irq_mask[0] |= (1 << irq));
  212. (void)mv64x60_read(&bh, MV64x60_GPP_INTR_MASK);
  213. return;
  214. }
  215. /* mv64360_mask_irq()
  216. *
  217. * This function disables the requested interrupt.
  218. *
  219. * Input Variable(s):
  220. * unsigned int interrupt number (IRQ0...IRQ95).
  221. *
  222. * Output Variable(s):
  223. * None.
  224. *
  225. * Returns:
  226. * void
  227. */
  228. static void
  229. mv64360_mask_irq(unsigned int irq)
  230. {
  231. #ifdef CONFIG_SMP
  232. if ((irq - mv64360_irq_base) == MV64x60_IRQ_DOORBELL) {
  233. mv64x60_clr_bits(&bh, MV64360_IC_CPU1_INTR_MASK_LO,
  234. (1 << MV64x60_IRQ_DOORBELL));
  235. return;
  236. }
  237. #endif
  238. irq -= mv64360_irq_base;
  239. if (irq > 31) {
  240. if (irq > 63) /* mask GPP irq */
  241. mv64x60_write(&bh, MV64x60_GPP_INTR_MASK,
  242. ppc_cached_irq_mask[2] &= ~(1 << (irq - 64)));
  243. else /* mask high interrupt register */
  244. mv64x60_write(&bh, MV64360_IC_CPU0_INTR_MASK_HI,
  245. ppc_cached_irq_mask[1] &= ~(1 << (irq - 32)));
  246. }
  247. else /* mask low interrupt register */
  248. mv64x60_write(&bh, MV64360_IC_CPU0_INTR_MASK_LO,
  249. ppc_cached_irq_mask[0] &= ~(1 << irq));
  250. (void)mv64x60_read(&bh, MV64x60_GPP_INTR_MASK);
  251. return;
  252. }
  253. static irqreturn_t
  254. mv64360_cpu_error_int_handler(int irq, void *dev_id, struct pt_regs *regs)
  255. {
  256. printk(KERN_ERR "mv64360_cpu_error_int_handler: %s 0x%08x\n",
  257. "Error on CPU interface - Cause regiser",
  258. mv64x60_read(&bh, MV64x60_CPU_ERR_CAUSE));
  259. printk(KERN_ERR "\tCPU error register dump:\n");
  260. printk(KERN_ERR "\tAddress low 0x%08x\n",
  261. mv64x60_read(&bh, MV64x60_CPU_ERR_ADDR_LO));
  262. printk(KERN_ERR "\tAddress high 0x%08x\n",
  263. mv64x60_read(&bh, MV64x60_CPU_ERR_ADDR_HI));
  264. printk(KERN_ERR "\tData low 0x%08x\n",
  265. mv64x60_read(&bh, MV64x60_CPU_ERR_DATA_LO));
  266. printk(KERN_ERR "\tData high 0x%08x\n",
  267. mv64x60_read(&bh, MV64x60_CPU_ERR_DATA_HI));
  268. printk(KERN_ERR "\tParity 0x%08x\n",
  269. mv64x60_read(&bh, MV64x60_CPU_ERR_PARITY));
  270. mv64x60_write(&bh, MV64x60_CPU_ERR_CAUSE, 0);
  271. return IRQ_HANDLED;
  272. }
  273. static irqreturn_t
  274. mv64360_sram_error_int_handler(int irq, void *dev_id, struct pt_regs *regs)
  275. {
  276. printk(KERN_ERR "mv64360_sram_error_int_handler: %s 0x%08x\n",
  277. "Error in internal SRAM - Cause register",
  278. mv64x60_read(&bh, MV64360_SRAM_ERR_CAUSE));
  279. printk(KERN_ERR "\tSRAM error register dump:\n");
  280. printk(KERN_ERR "\tAddress Low 0x%08x\n",
  281. mv64x60_read(&bh, MV64360_SRAM_ERR_ADDR_LO));
  282. printk(KERN_ERR "\tAddress High 0x%08x\n",
  283. mv64x60_read(&bh, MV64360_SRAM_ERR_ADDR_HI));
  284. printk(KERN_ERR "\tData Low 0x%08x\n",
  285. mv64x60_read(&bh, MV64360_SRAM_ERR_DATA_LO));
  286. printk(KERN_ERR "\tData High 0x%08x\n",
  287. mv64x60_read(&bh, MV64360_SRAM_ERR_DATA_HI));
  288. printk(KERN_ERR "\tParity 0x%08x\n",
  289. mv64x60_read(&bh, MV64360_SRAM_ERR_PARITY));
  290. mv64x60_write(&bh, MV64360_SRAM_ERR_CAUSE, 0);
  291. return IRQ_HANDLED;
  292. }
  293. static irqreturn_t
  294. mv64360_pci_error_int_handler(int irq, void *dev_id, struct pt_regs *regs)
  295. {
  296. u32 val;
  297. unsigned int pci_bus = (unsigned int)dev_id;
  298. if (pci_bus == 0) { /* Error on PCI 0 */
  299. val = mv64x60_read(&bh, MV64x60_PCI0_ERR_CAUSE);
  300. printk(KERN_ERR "%s: Error in PCI %d Interface\n",
  301. "mv64360_pci_error_int_handler", pci_bus);
  302. printk(KERN_ERR "\tPCI %d error register dump:\n", pci_bus);
  303. printk(KERN_ERR "\tCause register 0x%08x\n", val);
  304. printk(KERN_ERR "\tAddress Low 0x%08x\n",
  305. mv64x60_read(&bh, MV64x60_PCI0_ERR_ADDR_LO));
  306. printk(KERN_ERR "\tAddress High 0x%08x\n",
  307. mv64x60_read(&bh, MV64x60_PCI0_ERR_ADDR_HI));
  308. printk(KERN_ERR "\tAttribute 0x%08x\n",
  309. mv64x60_read(&bh, MV64x60_PCI0_ERR_DATA_LO));
  310. printk(KERN_ERR "\tCommand 0x%08x\n",
  311. mv64x60_read(&bh, MV64x60_PCI0_ERR_CMD));
  312. mv64x60_write(&bh, MV64x60_PCI0_ERR_CAUSE, ~val);
  313. }
  314. if (pci_bus == 1) { /* Error on PCI 1 */
  315. val = mv64x60_read(&bh, MV64x60_PCI1_ERR_CAUSE);
  316. printk(KERN_ERR "%s: Error in PCI %d Interface\n",
  317. "mv64360_pci_error_int_handler", pci_bus);
  318. printk(KERN_ERR "\tPCI %d error register dump:\n", pci_bus);
  319. printk(KERN_ERR "\tCause register 0x%08x\n", val);
  320. printk(KERN_ERR "\tAddress Low 0x%08x\n",
  321. mv64x60_read(&bh, MV64x60_PCI1_ERR_ADDR_LO));
  322. printk(KERN_ERR "\tAddress High 0x%08x\n",
  323. mv64x60_read(&bh, MV64x60_PCI1_ERR_ADDR_HI));
  324. printk(KERN_ERR "\tAttribute 0x%08x\n",
  325. mv64x60_read(&bh, MV64x60_PCI1_ERR_DATA_LO));
  326. printk(KERN_ERR "\tCommand 0x%08x\n",
  327. mv64x60_read(&bh, MV64x60_PCI1_ERR_CMD));
  328. mv64x60_write(&bh, MV64x60_PCI1_ERR_CAUSE, ~val);
  329. }
  330. return IRQ_HANDLED;
  331. }
  332. /*
  333. * Bit 0 of MV64x60_PCIx_ERR_MASK does not exist on the 64360 and because of
  334. * errata FEr-#11 and FEr-##16 for the 64460, it should be 0 on that chip as
  335. * well. IOW, don't set bit 0.
  336. */
  337. #define MV64360_PCI0_ERR_MASK_VAL 0x00a50c24
  338. static int __init
  339. mv64360_register_hdlrs(void)
  340. {
  341. int rc;
  342. /* Clear old errors and register CPU interface error intr handler */
  343. mv64x60_write(&bh, MV64x60_CPU_ERR_CAUSE, 0);
  344. if ((rc = request_irq(MV64x60_IRQ_CPU_ERR + mv64360_irq_base,
  345. mv64360_cpu_error_int_handler, SA_INTERRUPT, CPU_INTR_STR, 0)))
  346. printk(KERN_WARNING "Can't register cpu error handler: %d", rc);
  347. mv64x60_write(&bh, MV64x60_CPU_ERR_MASK, 0);
  348. mv64x60_write(&bh, MV64x60_CPU_ERR_MASK, 0x000000ff);
  349. /* Clear old errors and register internal SRAM error intr handler */
  350. mv64x60_write(&bh, MV64360_SRAM_ERR_CAUSE, 0);
  351. if ((rc = request_irq(MV64360_IRQ_SRAM_PAR_ERR + mv64360_irq_base,
  352. mv64360_sram_error_int_handler,SA_INTERRUPT,SRAM_INTR_STR, 0)))
  353. printk(KERN_WARNING "Can't register SRAM error handler: %d",rc);
  354. /* Clear old errors and register PCI 0 error intr handler */
  355. mv64x60_write(&bh, MV64x60_PCI0_ERR_CAUSE, 0);
  356. if ((rc = request_irq(MV64360_IRQ_PCI0 + mv64360_irq_base,
  357. mv64360_pci_error_int_handler,
  358. SA_INTERRUPT, PCI0_INTR_STR, (void *)0)))
  359. printk(KERN_WARNING "Can't register pci 0 error handler: %d",
  360. rc);
  361. mv64x60_write(&bh, MV64x60_PCI0_ERR_MASK, 0);
  362. mv64x60_write(&bh, MV64x60_PCI0_ERR_MASK, MV64360_PCI0_ERR_MASK_VAL);
  363. /* Erratum FEr PCI-#16 says to clear bit 0 of PCI SERRn Mask reg. */
  364. mv64x60_write(&bh, MV64x60_PCI0_ERR_SERR_MASK,
  365. mv64x60_read(&bh, MV64x60_PCI0_ERR_SERR_MASK) & ~0x1UL);
  366. /* Clear old errors and register PCI 1 error intr handler */
  367. mv64x60_write(&bh, MV64x60_PCI1_ERR_CAUSE, 0);
  368. if ((rc = request_irq(MV64360_IRQ_PCI1 + mv64360_irq_base,
  369. mv64360_pci_error_int_handler,
  370. SA_INTERRUPT, PCI1_INTR_STR, (void *)1)))
  371. printk(KERN_WARNING "Can't register pci 1 error handler: %d",
  372. rc);
  373. mv64x60_write(&bh, MV64x60_PCI1_ERR_MASK, 0);
  374. mv64x60_write(&bh, MV64x60_PCI1_ERR_MASK, MV64360_PCI0_ERR_MASK_VAL);
  375. /* Erratum FEr PCI-#16 says to clear bit 0 of PCI Intr Mask reg. */
  376. mv64x60_write(&bh, MV64x60_PCI1_ERR_SERR_MASK,
  377. mv64x60_read(&bh, MV64x60_PCI1_ERR_SERR_MASK) & ~0x1UL);
  378. return 0;
  379. }
  380. arch_initcall(mv64360_register_hdlrs);