mv64360_pic.c 13 KB

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