PageRenderTime 27ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/release/src-rt/linux/linux-2.6/arch/ppc/syslib/mv64360_pic.c

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