mv64360_pic.c 13 KB

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