malta_int.c 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. /*
  2. * Carsten Langgaard, carstenl@mips.com
  3. * Copyright (C) 2000, 2001, 2004 MIPS Technologies, Inc.
  4. * Copyright (C) 2001 Ralf Baechle
  5. *
  6. * This program is free software; you can distribute it and/or modify it
  7. * under the terms of the GNU General Public License (Version 2) as
  8. * published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope it will be useful, but WITHOUT
  11. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  13. * for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along
  16. * with this program; if not, write to the Free Software Foundation, Inc.,
  17. * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
  18. *
  19. * Routines for generic manipulation of the interrupts found on the MIPS
  20. * Malta board.
  21. * The interrupt controller is located in the South Bridge a PIIX4 device
  22. * with two internal 82C95 interrupt controllers.
  23. */
  24. #include <linux/init.h>
  25. #include <linux/irq.h>
  26. #include <linux/sched.h>
  27. #include <linux/slab.h>
  28. #include <linux/interrupt.h>
  29. #include <linux/kernel_stat.h>
  30. #include <linux/random.h>
  31. #include <asm/i8259.h>
  32. #include <asm/irq_cpu.h>
  33. #include <asm/io.h>
  34. #include <asm/mips-boards/malta.h>
  35. #include <asm/mips-boards/maltaint.h>
  36. #include <asm/mips-boards/piix4.h>
  37. #include <asm/gt64120.h>
  38. #include <asm/mips-boards/generic.h>
  39. #include <asm/mips-boards/msc01_pci.h>
  40. #include <asm/msc01_ic.h>
  41. extern asmlinkage void mipsIRQ(void);
  42. extern void mips_timer_interrupt(void);
  43. static DEFINE_SPINLOCK(mips_irq_lock);
  44. static inline int mips_pcibios_iack(void)
  45. {
  46. int irq;
  47. u32 dummy;
  48. /*
  49. * Determine highest priority pending interrupt by performing
  50. * a PCI Interrupt Acknowledge cycle.
  51. */
  52. switch(mips_revision_corid) {
  53. case MIPS_REVISION_CORID_CORE_MSC:
  54. case MIPS_REVISION_CORID_CORE_FPGA2:
  55. case MIPS_REVISION_CORID_CORE_EMUL_MSC:
  56. MSC_READ(MSC01_PCI_IACK, irq);
  57. irq &= 0xff;
  58. break;
  59. case MIPS_REVISION_CORID_QED_RM5261:
  60. case MIPS_REVISION_CORID_CORE_LV:
  61. case MIPS_REVISION_CORID_CORE_FPGA:
  62. case MIPS_REVISION_CORID_CORE_FPGAR2:
  63. irq = GT_READ(GT_PCI0_IACK_OFS);
  64. irq &= 0xff;
  65. break;
  66. case MIPS_REVISION_CORID_BONITO64:
  67. case MIPS_REVISION_CORID_CORE_20K:
  68. case MIPS_REVISION_CORID_CORE_EMUL_BON:
  69. /* The following will generate a PCI IACK cycle on the
  70. * Bonito controller. It's a little bit kludgy, but it
  71. * was the easiest way to implement it in hardware at
  72. * the given time.
  73. */
  74. BONITO_PCIMAP_CFG = 0x20000;
  75. /* Flush Bonito register block */
  76. dummy = BONITO_PCIMAP_CFG;
  77. iob(); /* sync */
  78. irq = *(volatile u32 *)(_pcictrl_bonito_pcicfg);
  79. iob(); /* sync */
  80. irq &= 0xff;
  81. BONITO_PCIMAP_CFG = 0;
  82. break;
  83. default:
  84. printk("Unknown Core card, don't know the system controller.\n");
  85. return -1;
  86. }
  87. return irq;
  88. }
  89. static inline int get_int(void)
  90. {
  91. unsigned long flags;
  92. int irq;
  93. spin_lock_irqsave(&mips_irq_lock, flags);
  94. irq = mips_pcibios_iack();
  95. /*
  96. * IRQ7 is used to detect spurious interrupts.
  97. * The interrupt acknowledge cycle returns IRQ7, if no
  98. * interrupts is requested.
  99. * We can differentiate between this situation and a
  100. * "Normal" IRQ7 by reading the ISR.
  101. */
  102. if (irq == 7)
  103. {
  104. outb(PIIX4_OCW3_SEL | PIIX4_OCW3_ISR,
  105. PIIX4_ICTLR1_OCW3);
  106. if (!(inb(PIIX4_ICTLR1_OCW3) & (1 << 7))) {
  107. irq = -1; /* Spurious interrupt */
  108. printk("We got a spurious interrupt from PIIX4.\n");
  109. atomic_inc(&irq_err_count);
  110. }
  111. }
  112. spin_unlock_irqrestore(&mips_irq_lock, flags);
  113. return irq;
  114. }
  115. void malta_hw0_irqdispatch(struct pt_regs *regs)
  116. {
  117. int irq;
  118. irq = get_int();
  119. if (irq < 0)
  120. return; /* interrupt has already been cleared */
  121. do_IRQ(MALTA_INT_BASE+irq, regs);
  122. }
  123. void corehi_irqdispatch(struct pt_regs *regs)
  124. {
  125. unsigned int intrcause,datalo,datahi;
  126. unsigned int pcimstat, intisr, inten, intpol, intedge, intsteer, pcicmd, pcibadaddr;
  127. printk("CoreHI interrupt, shouldn't happen, so we die here!!!\n");
  128. printk("epc : %08lx\nStatus: %08lx\nCause : %08lx\nbadVaddr : %08lx\n"
  129. , regs->cp0_epc, regs->cp0_status, regs->cp0_cause, regs->cp0_badvaddr);
  130. /* Read all the registers and then print them as there is a
  131. problem with interspersed printk's upsetting the Bonito controller.
  132. Do it for the others too.
  133. */
  134. switch(mips_revision_corid) {
  135. case MIPS_REVISION_CORID_CORE_MSC:
  136. case MIPS_REVISION_CORID_CORE_FPGA2:
  137. case MIPS_REVISION_CORID_CORE_EMUL_MSC:
  138. ll_msc_irq(regs);
  139. break;
  140. case MIPS_REVISION_CORID_QED_RM5261:
  141. case MIPS_REVISION_CORID_CORE_LV:
  142. case MIPS_REVISION_CORID_CORE_FPGA:
  143. case MIPS_REVISION_CORID_CORE_FPGAR2:
  144. intrcause = GT_READ(GT_INTRCAUSE_OFS);
  145. datalo = GT_READ(GT_CPUERR_ADDRLO_OFS);
  146. datahi = GT_READ(GT_CPUERR_ADDRHI_OFS);
  147. printk("GT_INTRCAUSE = %08x\n", intrcause);
  148. printk("GT_CPUERR_ADDR = %02x%08x\n", datahi, datalo);
  149. break;
  150. case MIPS_REVISION_CORID_BONITO64:
  151. case MIPS_REVISION_CORID_CORE_20K:
  152. case MIPS_REVISION_CORID_CORE_EMUL_BON:
  153. pcibadaddr = BONITO_PCIBADADDR;
  154. pcimstat = BONITO_PCIMSTAT;
  155. intisr = BONITO_INTISR;
  156. inten = BONITO_INTEN;
  157. intpol = BONITO_INTPOL;
  158. intedge = BONITO_INTEDGE;
  159. intsteer = BONITO_INTSTEER;
  160. pcicmd = BONITO_PCICMD;
  161. printk("BONITO_INTISR = %08x\n", intisr);
  162. printk("BONITO_INTEN = %08x\n", inten);
  163. printk("BONITO_INTPOL = %08x\n", intpol);
  164. printk("BONITO_INTEDGE = %08x\n", intedge);
  165. printk("BONITO_INTSTEER = %08x\n", intsteer);
  166. printk("BONITO_PCICMD = %08x\n", pcicmd);
  167. printk("BONITO_PCIBADADDR = %08x\n", pcibadaddr);
  168. printk("BONITO_PCIMSTAT = %08x\n", pcimstat);
  169. break;
  170. }
  171. /* We die here*/
  172. die("CoreHi interrupt", regs);
  173. }
  174. static struct irqaction i8259irq = {
  175. .handler = no_action,
  176. .name = "XT-PIC cascade"
  177. };
  178. static struct irqaction corehi_irqaction = {
  179. .handler = no_action,
  180. .name = "CoreHi"
  181. };
  182. msc_irqmap_t __initdata msc_irqmap[] = {
  183. {MSC01C_INT_TMR, MSC01_IRQ_EDGE, 0},
  184. {MSC01C_INT_PCI, MSC01_IRQ_LEVEL, 0},
  185. };
  186. int __initdata msc_nr_irqs = sizeof(msc_irqmap)/sizeof(msc_irqmap_t);
  187. msc_irqmap_t __initdata msc_eicirqmap[] = {
  188. {MSC01E_INT_SW0, MSC01_IRQ_LEVEL, 0},
  189. {MSC01E_INT_SW1, MSC01_IRQ_LEVEL, 0},
  190. {MSC01E_INT_I8259A, MSC01_IRQ_LEVEL, 0},
  191. {MSC01E_INT_SMI, MSC01_IRQ_LEVEL, 0},
  192. {MSC01E_INT_COREHI, MSC01_IRQ_LEVEL, 0},
  193. {MSC01E_INT_CORELO, MSC01_IRQ_LEVEL, 0},
  194. {MSC01E_INT_TMR, MSC01_IRQ_EDGE, 0},
  195. {MSC01E_INT_PCI, MSC01_IRQ_LEVEL, 0},
  196. {MSC01E_INT_PERFCTR, MSC01_IRQ_LEVEL, 0},
  197. {MSC01E_INT_CPUCTR, MSC01_IRQ_LEVEL, 0}
  198. };
  199. int __initdata msc_nr_eicirqs = sizeof(msc_eicirqmap)/sizeof(msc_irqmap_t);
  200. void __init arch_init_irq(void)
  201. {
  202. set_except_vector(0, mipsIRQ);
  203. init_i8259_irqs();
  204. if (!cpu_has_veic)
  205. mips_cpu_irq_init (MIPSCPU_INT_BASE);
  206. switch(mips_revision_corid) {
  207. case MIPS_REVISION_CORID_CORE_MSC:
  208. case MIPS_REVISION_CORID_CORE_FPGA2:
  209. case MIPS_REVISION_CORID_CORE_EMUL_MSC:
  210. if (cpu_has_veic)
  211. init_msc_irqs (MSC01E_INT_BASE, msc_eicirqmap, msc_nr_eicirqs);
  212. else
  213. init_msc_irqs (MSC01C_INT_BASE, msc_irqmap, msc_nr_irqs);
  214. }
  215. if (cpu_has_veic) {
  216. set_vi_handler (MSC01E_INT_I8259A, malta_hw0_irqdispatch);
  217. set_vi_handler (MSC01E_INT_COREHI, corehi_irqdispatch);
  218. setup_irq (MSC01E_INT_BASE+MSC01E_INT_I8259A, &i8259irq);
  219. setup_irq (MSC01E_INT_BASE+MSC01E_INT_COREHI, &corehi_irqaction);
  220. }
  221. else if (cpu_has_vint) {
  222. set_vi_handler (MIPSCPU_INT_I8259A, malta_hw0_irqdispatch);
  223. set_vi_handler (MIPSCPU_INT_COREHI, corehi_irqdispatch);
  224. setup_irq (MIPSCPU_INT_BASE+MIPSCPU_INT_I8259A, &i8259irq);
  225. setup_irq (MIPSCPU_INT_BASE+MIPSCPU_INT_COREHI, &corehi_irqaction);
  226. }
  227. else {
  228. set_except_vector(0, mipsIRQ);
  229. setup_irq (MIPSCPU_INT_BASE+MIPSCPU_INT_I8259A, &i8259irq);
  230. setup_irq (MIPSCPU_INT_BASE+MIPSCPU_INT_COREHI, &corehi_irqaction);
  231. }
  232. }