malta-int.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * Carsten Langgaard, carstenl@mips.com
  7. * Copyright (C) 2000, 2001, 2004 MIPS Technologies, Inc.
  8. * Copyright (C) 2001 Ralf Baechle
  9. * Copyright (C) 2013 Imagination Technologies Ltd.
  10. *
  11. * Routines for generic manipulation of the interrupts found on the MIPS
  12. * Malta board. The interrupt controller is located in the South Bridge
  13. * a PIIX4 device with two internal 82C95 interrupt controllers.
  14. */
  15. #include <linux/init.h>
  16. #include <linux/irq.h>
  17. #include <linux/irqchip.h>
  18. #include <linux/sched.h>
  19. #include <linux/smp.h>
  20. #include <linux/interrupt.h>
  21. #include <linux/io.h>
  22. #include <linux/of_irq.h>
  23. #include <linux/kernel_stat.h>
  24. #include <linux/kernel.h>
  25. #include <linux/random.h>
  26. #include <asm/traps.h>
  27. #include <asm/i8259.h>
  28. #include <asm/irq_cpu.h>
  29. #include <asm/irq_regs.h>
  30. #include <asm/mips-boards/malta.h>
  31. #include <asm/mips-boards/maltaint.h>
  32. #include <asm/mips-cps.h>
  33. #include <asm/gt64120.h>
  34. #include <asm/mips-boards/generic.h>
  35. #include <asm/mips-boards/msc01_pci.h>
  36. #include <asm/msc01_ic.h>
  37. #include <asm/setup.h>
  38. #include <asm/rtlx.h>
  39. static inline int mips_pcibios_iack(void)
  40. {
  41. int irq;
  42. /*
  43. * Determine highest priority pending interrupt by performing
  44. * a PCI Interrupt Acknowledge cycle.
  45. */
  46. switch (mips_revision_sconid) {
  47. case MIPS_REVISION_SCON_SOCIT:
  48. case MIPS_REVISION_SCON_ROCIT:
  49. case MIPS_REVISION_SCON_SOCITSC:
  50. case MIPS_REVISION_SCON_SOCITSCP:
  51. MSC_READ(MSC01_PCI_IACK, irq);
  52. irq &= 0xff;
  53. break;
  54. case MIPS_REVISION_SCON_GT64120:
  55. irq = GT_READ(GT_PCI0_IACK_OFS);
  56. irq &= 0xff;
  57. break;
  58. case MIPS_REVISION_SCON_BONITO:
  59. /* The following will generate a PCI IACK cycle on the
  60. * Bonito controller. It's a little bit kludgy, but it
  61. * was the easiest way to implement it in hardware at
  62. * the given time.
  63. */
  64. BONITO_PCIMAP_CFG = 0x20000;
  65. /* Flush Bonito register block */
  66. (void) BONITO_PCIMAP_CFG;
  67. iob(); /* sync */
  68. irq = __raw_readl((u32 *)_pcictrl_bonito_pcicfg);
  69. iob(); /* sync */
  70. irq &= 0xff;
  71. BONITO_PCIMAP_CFG = 0;
  72. break;
  73. default:
  74. pr_emerg("Unknown system controller.\n");
  75. return -1;
  76. }
  77. return irq;
  78. }
  79. static void corehi_irqdispatch(void)
  80. {
  81. unsigned int intedge, intsteer, pcicmd, pcibadaddr;
  82. unsigned int pcimstat, intisr, inten, intpol;
  83. unsigned int intrcause, datalo, datahi;
  84. struct pt_regs *regs = get_irq_regs();
  85. pr_emerg("CoreHI interrupt, shouldn't happen, we die here!\n");
  86. pr_emerg("epc : %08lx\nStatus: %08lx\n"
  87. "Cause : %08lx\nbadVaddr : %08lx\n",
  88. regs->cp0_epc, regs->cp0_status,
  89. regs->cp0_cause, regs->cp0_badvaddr);
  90. /* Read all the registers and then print them as there is a
  91. problem with interspersed printk's upsetting the Bonito controller.
  92. Do it for the others too.
  93. */
  94. switch (mips_revision_sconid) {
  95. case MIPS_REVISION_SCON_SOCIT:
  96. case MIPS_REVISION_SCON_ROCIT:
  97. case MIPS_REVISION_SCON_SOCITSC:
  98. case MIPS_REVISION_SCON_SOCITSCP:
  99. ll_msc_irq();
  100. break;
  101. case MIPS_REVISION_SCON_GT64120:
  102. intrcause = GT_READ(GT_INTRCAUSE_OFS);
  103. datalo = GT_READ(GT_CPUERR_ADDRLO_OFS);
  104. datahi = GT_READ(GT_CPUERR_ADDRHI_OFS);
  105. pr_emerg("GT_INTRCAUSE = %08x\n", intrcause);
  106. pr_emerg("GT_CPUERR_ADDR = %02x%08x\n",
  107. datahi, datalo);
  108. break;
  109. case MIPS_REVISION_SCON_BONITO:
  110. pcibadaddr = BONITO_PCIBADADDR;
  111. pcimstat = BONITO_PCIMSTAT;
  112. intisr = BONITO_INTISR;
  113. inten = BONITO_INTEN;
  114. intpol = BONITO_INTPOL;
  115. intedge = BONITO_INTEDGE;
  116. intsteer = BONITO_INTSTEER;
  117. pcicmd = BONITO_PCICMD;
  118. pr_emerg("BONITO_INTISR = %08x\n", intisr);
  119. pr_emerg("BONITO_INTEN = %08x\n", inten);
  120. pr_emerg("BONITO_INTPOL = %08x\n", intpol);
  121. pr_emerg("BONITO_INTEDGE = %08x\n", intedge);
  122. pr_emerg("BONITO_INTSTEER = %08x\n", intsteer);
  123. pr_emerg("BONITO_PCICMD = %08x\n", pcicmd);
  124. pr_emerg("BONITO_PCIBADADDR = %08x\n", pcibadaddr);
  125. pr_emerg("BONITO_PCIMSTAT = %08x\n", pcimstat);
  126. break;
  127. }
  128. die("CoreHi interrupt", regs);
  129. }
  130. static irqreturn_t corehi_handler(int irq, void *dev_id)
  131. {
  132. corehi_irqdispatch();
  133. return IRQ_HANDLED;
  134. }
  135. static struct irqaction corehi_irqaction = {
  136. .handler = corehi_handler,
  137. .name = "CoreHi",
  138. .flags = IRQF_NO_THREAD,
  139. };
  140. static msc_irqmap_t msc_irqmap[] __initdata = {
  141. {MSC01C_INT_TMR, MSC01_IRQ_EDGE, 0},
  142. {MSC01C_INT_PCI, MSC01_IRQ_LEVEL, 0},
  143. };
  144. static int msc_nr_irqs __initdata = ARRAY_SIZE(msc_irqmap);
  145. static msc_irqmap_t msc_eicirqmap[] __initdata = {
  146. {MSC01E_INT_SW0, MSC01_IRQ_LEVEL, 0},
  147. {MSC01E_INT_SW1, MSC01_IRQ_LEVEL, 0},
  148. {MSC01E_INT_I8259A, MSC01_IRQ_LEVEL, 0},
  149. {MSC01E_INT_SMI, MSC01_IRQ_LEVEL, 0},
  150. {MSC01E_INT_COREHI, MSC01_IRQ_LEVEL, 0},
  151. {MSC01E_INT_CORELO, MSC01_IRQ_LEVEL, 0},
  152. {MSC01E_INT_TMR, MSC01_IRQ_EDGE, 0},
  153. {MSC01E_INT_PCI, MSC01_IRQ_LEVEL, 0},
  154. {MSC01E_INT_PERFCTR, MSC01_IRQ_LEVEL, 0},
  155. {MSC01E_INT_CPUCTR, MSC01_IRQ_LEVEL, 0}
  156. };
  157. static int msc_nr_eicirqs __initdata = ARRAY_SIZE(msc_eicirqmap);
  158. void __init arch_init_irq(void)
  159. {
  160. int corehi_irq;
  161. /*
  162. * Preallocate the i8259's expected virq's here. Since irqchip_init()
  163. * will probe the irqchips in hierarchial order, i8259 is probed last.
  164. * If anything allocates a virq before the i8259 is probed, it will
  165. * be given one of the i8259's expected range and consequently setup
  166. * of the i8259 will fail.
  167. */
  168. WARN(irq_alloc_descs(I8259A_IRQ_BASE, I8259A_IRQ_BASE,
  169. 16, numa_node_id()) < 0,
  170. "Cannot reserve i8259 virqs at IRQ%d\n", I8259A_IRQ_BASE);
  171. i8259_set_poll(mips_pcibios_iack);
  172. irqchip_init();
  173. switch (mips_revision_sconid) {
  174. case MIPS_REVISION_SCON_SOCIT:
  175. case MIPS_REVISION_SCON_ROCIT:
  176. if (cpu_has_veic)
  177. init_msc_irqs(MIPS_MSC01_IC_REG_BASE,
  178. MSC01E_INT_BASE, msc_eicirqmap,
  179. msc_nr_eicirqs);
  180. else
  181. init_msc_irqs(MIPS_MSC01_IC_REG_BASE,
  182. MSC01C_INT_BASE, msc_irqmap,
  183. msc_nr_irqs);
  184. break;
  185. case MIPS_REVISION_SCON_SOCITSC:
  186. case MIPS_REVISION_SCON_SOCITSCP:
  187. if (cpu_has_veic)
  188. init_msc_irqs(MIPS_SOCITSC_IC_REG_BASE,
  189. MSC01E_INT_BASE, msc_eicirqmap,
  190. msc_nr_eicirqs);
  191. else
  192. init_msc_irqs(MIPS_SOCITSC_IC_REG_BASE,
  193. MSC01C_INT_BASE, msc_irqmap,
  194. msc_nr_irqs);
  195. }
  196. if (mips_gic_present()) {
  197. corehi_irq = MIPS_CPU_IRQ_BASE + MIPSCPU_INT_COREHI;
  198. } else if (cpu_has_veic) {
  199. set_vi_handler(MSC01E_INT_COREHI, corehi_irqdispatch);
  200. corehi_irq = MSC01E_INT_BASE + MSC01E_INT_COREHI;
  201. } else {
  202. corehi_irq = MIPS_CPU_IRQ_BASE + MIPSCPU_INT_COREHI;
  203. }
  204. setup_irq(corehi_irq, &corehi_irqaction);
  205. }