Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | * Copyright (C) 1992 Linus Torvalds |
| 7 | * Copyright (C) 1994 - 2000 Ralf Baechle |
| 8 | */ |
| 9 | #include <linux/delay.h> |
| 10 | #include <linux/init.h> |
| 11 | #include <linux/interrupt.h> |
| 12 | #include <linux/irq.h> |
| 13 | #include <linux/kernel.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | |
| 15 | #include <asm/i8259.h> |
| 16 | #include <asm/io.h> |
| 17 | #include <asm/sni.h> |
| 18 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | static void enable_pciasic_irq(unsigned int irq) |
| 20 | { |
| 21 | unsigned int mask = 1 << (irq - PCIMT_IRQ_INT2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | *(volatile u8 *) PCIMT_IRQSEL |= mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | } |
| 25 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | void disable_pciasic_irq(unsigned int irq) |
| 27 | { |
| 28 | unsigned int mask = ~(1 << (irq - PCIMT_IRQ_INT2)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | *(volatile u8 *) PCIMT_IRQSEL &= mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | } |
| 32 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | static void end_pciasic_irq(unsigned int irq) |
| 34 | { |
| 35 | if (!(irq_desc[irq].status & (IRQ_DISABLED|IRQ_INPROGRESS))) |
| 36 | enable_pciasic_irq(irq); |
| 37 | } |
| 38 | |
Ralf Baechle | 94dee17 | 2006-07-02 14:41:42 +0100 | [diff] [blame] | 39 | static struct irq_chip pciasic_irq_type = { |
Atsushi Nemoto | 70d21cd | 2007-01-15 00:07:25 +0900 | [diff] [blame] | 40 | .name = "ASIC-PCI", |
Atsushi Nemoto | 1603b5a | 2006-11-02 02:08:36 +0900 | [diff] [blame] | 41 | .ack = disable_pciasic_irq, |
| 42 | .mask = disable_pciasic_irq, |
| 43 | .mask_ack = disable_pciasic_irq, |
| 44 | .unmask = enable_pciasic_irq, |
Ralf Baechle | 8ab00b9 | 2005-02-28 13:39:57 +0000 | [diff] [blame] | 45 | .end = end_pciasic_irq, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | }; |
| 47 | |
| 48 | /* |
| 49 | * hwint0 should deal with MP agent, ASIC PCI, EISA NMI and debug |
| 50 | * button interrupts. Later ... |
| 51 | */ |
Ralf Baechle | 937a801 | 2006-10-07 19:44:33 +0100 | [diff] [blame] | 52 | static void pciasic_hwint0(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | { |
| 54 | panic("Received int0 but no handler yet ..."); |
| 55 | } |
| 56 | |
| 57 | /* This interrupt was used for the com1 console on the first prototypes. */ |
Ralf Baechle | 937a801 | 2006-10-07 19:44:33 +0100 | [diff] [blame] | 58 | static void pciasic_hwint2(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | { |
| 60 | /* I think this shouldn't happen on production machines. */ |
| 61 | panic("hwint2 and no handler yet"); |
| 62 | } |
| 63 | |
| 64 | /* hwint5 is the r4k count / compare interrupt */ |
Ralf Baechle | 937a801 | 2006-10-07 19:44:33 +0100 | [diff] [blame] | 65 | static void pciasic_hwint5(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | { |
| 67 | panic("hwint5 and no handler yet"); |
| 68 | } |
| 69 | |
| 70 | static unsigned int ls1bit8(unsigned int x) |
| 71 | { |
| 72 | int b = 7, s; |
| 73 | |
| 74 | s = 4; if ((x & 0x0f) == 0) s = 0; b -= s; x <<= s; |
| 75 | s = 2; if ((x & 0x30) == 0) s = 0; b -= s; x <<= s; |
| 76 | s = 1; if ((x & 0x40) == 0) s = 0; b -= s; |
| 77 | |
| 78 | return b; |
| 79 | } |
| 80 | |
| 81 | /* |
| 82 | * hwint 1 deals with EISA and SCSI interrupts, |
Ralf Baechle | 42a3b4f | 2005-09-03 15:56:17 -0700 | [diff] [blame] | 83 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | * The EISA_INT bit in CSITPEND is high active, all others are low active. |
| 85 | */ |
Ralf Baechle | 937a801 | 2006-10-07 19:44:33 +0100 | [diff] [blame] | 86 | static void pciasic_hwint1(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | { |
| 88 | u8 pend = *(volatile char *)PCIMT_CSITPEND; |
| 89 | unsigned long flags; |
| 90 | |
| 91 | if (pend & IT_EISA) { |
| 92 | int irq; |
| 93 | /* |
| 94 | * Note: ASIC PCI's builtin interrupt achknowledge feature is |
| 95 | * broken. Using it may result in loss of some or all i8259 |
| 96 | * interupts, so don't use PCIMT_INT_ACKNOWLEDGE ... |
| 97 | */ |
| 98 | irq = i8259_irq(); |
| 99 | if (unlikely(irq < 0)) |
| 100 | return; |
| 101 | |
Ralf Baechle | 937a801 | 2006-10-07 19:44:33 +0100 | [diff] [blame] | 102 | do_IRQ(irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | if (!(pend & IT_SCSI)) { |
| 106 | flags = read_c0_status(); |
| 107 | clear_c0_status(ST0_IM); |
Ralf Baechle | 937a801 | 2006-10-07 19:44:33 +0100 | [diff] [blame] | 108 | do_IRQ(PCIMT_IRQ_SCSI); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | write_c0_status(flags); |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | /* |
| 114 | * hwint 3 should deal with the PCI A - D interrupts, |
| 115 | */ |
Ralf Baechle | 937a801 | 2006-10-07 19:44:33 +0100 | [diff] [blame] | 116 | static void pciasic_hwint3(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | { |
| 118 | u8 pend = *(volatile char *)PCIMT_CSITPEND; |
| 119 | int irq; |
| 120 | |
| 121 | pend &= (IT_INTA | IT_INTB | IT_INTC | IT_INTD); |
| 122 | clear_c0_status(IE_IRQ3); |
| 123 | irq = PCIMT_IRQ_INT2 + ls1bit8(pend); |
Ralf Baechle | 937a801 | 2006-10-07 19:44:33 +0100 | [diff] [blame] | 124 | do_IRQ(irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | set_c0_status(IE_IRQ3); |
| 126 | } |
| 127 | |
| 128 | /* |
| 129 | * hwint 4 is used for only the onboard PCnet 32. |
| 130 | */ |
Ralf Baechle | 937a801 | 2006-10-07 19:44:33 +0100 | [diff] [blame] | 131 | static void pciasic_hwint4(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | { |
| 133 | clear_c0_status(IE_IRQ4); |
Ralf Baechle | 937a801 | 2006-10-07 19:44:33 +0100 | [diff] [blame] | 134 | do_IRQ(PCIMT_IRQ_ETHERNET); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | set_c0_status(IE_IRQ4); |
| 136 | } |
| 137 | |
Ralf Baechle | 937a801 | 2006-10-07 19:44:33 +0100 | [diff] [blame] | 138 | asmlinkage void plat_irq_dispatch(void) |
Ralf Baechle | e4ac58a | 2006-04-03 17:56:36 +0100 | [diff] [blame] | 139 | { |
| 140 | unsigned int pending = read_c0_status() & read_c0_cause(); |
| 141 | static unsigned char led_cache; |
| 142 | |
| 143 | *(volatile unsigned char *) PCIMT_CSLED = ++led_cache; |
| 144 | |
| 145 | if (pending & 0x0800) |
Ralf Baechle | 937a801 | 2006-10-07 19:44:33 +0100 | [diff] [blame] | 146 | pciasic_hwint1(); |
Ralf Baechle | e4ac58a | 2006-04-03 17:56:36 +0100 | [diff] [blame] | 147 | else if (pending & 0x4000) |
Ralf Baechle | 937a801 | 2006-10-07 19:44:33 +0100 | [diff] [blame] | 148 | pciasic_hwint4(); |
Ralf Baechle | e4ac58a | 2006-04-03 17:56:36 +0100 | [diff] [blame] | 149 | else if (pending & 0x2000) |
Ralf Baechle | 937a801 | 2006-10-07 19:44:33 +0100 | [diff] [blame] | 150 | pciasic_hwint3(); |
Ralf Baechle | e4ac58a | 2006-04-03 17:56:36 +0100 | [diff] [blame] | 151 | else if (pending & 0x1000) |
Ralf Baechle | 937a801 | 2006-10-07 19:44:33 +0100 | [diff] [blame] | 152 | pciasic_hwint2(); |
Ralf Baechle | e4ac58a | 2006-04-03 17:56:36 +0100 | [diff] [blame] | 153 | else if (pending & 0x8000) |
Ralf Baechle | 937a801 | 2006-10-07 19:44:33 +0100 | [diff] [blame] | 154 | pciasic_hwint5(); |
Ralf Baechle | e4ac58a | 2006-04-03 17:56:36 +0100 | [diff] [blame] | 155 | else if (pending & 0x0400) |
Ralf Baechle | 937a801 | 2006-10-07 19:44:33 +0100 | [diff] [blame] | 156 | pciasic_hwint0(); |
Ralf Baechle | e4ac58a | 2006-04-03 17:56:36 +0100 | [diff] [blame] | 157 | } |
| 158 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | void __init init_pciasic(void) |
| 160 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | * (volatile u8 *) PCIMT_IRQSEL = |
| 162 | IT_EISA | IT_INTA | IT_INTB | IT_INTC | IT_INTD; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | /* |
| 166 | * On systems with i8259-style interrupt controllers we assume for |
| 167 | * driver compatibility reasons interrupts 0 - 15 to be the i8295 |
| 168 | * interrupts even if the hardware uses a different interrupt numbering. |
| 169 | */ |
| 170 | void __init arch_init_irq(void) |
| 171 | { |
| 172 | int i; |
| 173 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | init_i8259_irqs(); /* Integrated i8259 */ |
| 175 | init_pciasic(); |
| 176 | |
| 177 | /* Actually we've got more interrupts to handle ... */ |
Atsushi Nemoto | 1603b5a | 2006-11-02 02:08:36 +0900 | [diff] [blame] | 178 | for (i = PCIMT_IRQ_INT2; i <= PCIMT_IRQ_ETHERNET; i++) |
| 179 | set_irq_chip(i, &pciasic_irq_type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | |
| 181 | change_c0_status(ST0_IM, IE_IRQ1|IE_IRQ2|IE_IRQ3|IE_IRQ4); |
| 182 | } |