mv64360_pic.c 13 KB

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