Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Low-Level PCI Support for PC -- Routing of Interrupts |
| 3 | * |
| 4 | * (c) 1999--2000 Martin Mares <mj@ucw.cz> |
| 5 | */ |
| 6 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | #include <linux/types.h> |
| 8 | #include <linux/kernel.h> |
| 9 | #include <linux/pci.h> |
| 10 | #include <linux/init.h> |
| 11 | #include <linux/slab.h> |
| 12 | #include <linux/interrupt.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | #include <linux/dmi.h> |
Miklos Vajna | 273c112 | 2008-05-13 18:38:56 +0200 | [diff] [blame^] | 14 | #include <linux/io.h> |
| 15 | #include <linux/smp.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | #include <asm/io_apic.h> |
Nick Piggin | b33fa1f | 2005-10-01 02:34:42 +1000 | [diff] [blame] | 17 | #include <linux/irq.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | #include <linux/acpi.h> |
| 19 | |
| 20 | #include "pci.h" |
| 21 | |
| 22 | #define PIRQ_SIGNATURE (('$' << 0) + ('P' << 8) + ('I' << 16) + ('R' << 24)) |
| 23 | #define PIRQ_VERSION 0x0100 |
| 24 | |
| 25 | static int broken_hp_bios_irq9; |
| 26 | static int acer_tm360_irqrouting; |
| 27 | |
| 28 | static struct irq_routing_table *pirq_table; |
| 29 | |
| 30 | static int pirq_enable_irq(struct pci_dev *dev); |
| 31 | |
| 32 | /* |
| 33 | * Never use: 0, 1, 2 (timer, keyboard, and cascade) |
| 34 | * Avoid using: 13, 14 and 15 (FP error and IDE). |
| 35 | * Penalize: 3, 4, 6, 7, 12 (known ISA uses: serial, floppy, parallel and mouse) |
| 36 | */ |
| 37 | unsigned int pcibios_irq_mask = 0xfff8; |
| 38 | |
| 39 | static int pirq_penalty[16] = { |
| 40 | 1000000, 1000000, 1000000, 1000, 1000, 0, 1000, 1000, |
| 41 | 0, 0, 0, 0, 1000, 100000, 100000, 100000 |
| 42 | }; |
| 43 | |
| 44 | struct irq_router { |
| 45 | char *name; |
| 46 | u16 vendor, device; |
| 47 | int (*get)(struct pci_dev *router, struct pci_dev *dev, int pirq); |
Miklos Vajna | 273c112 | 2008-05-13 18:38:56 +0200 | [diff] [blame^] | 48 | int (*set)(struct pci_dev *router, struct pci_dev *dev, int pirq, |
| 49 | int new); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | }; |
| 51 | |
| 52 | struct irq_router_handler { |
| 53 | u16 vendor; |
| 54 | int (*probe)(struct irq_router *r, struct pci_dev *router, u16 device); |
| 55 | }; |
| 56 | |
| 57 | int (*pcibios_enable_irq)(struct pci_dev *dev) = NULL; |
David Shaohua Li | 87bec66 | 2005-07-27 23:02:00 -0400 | [diff] [blame] | 58 | void (*pcibios_disable_irq)(struct pci_dev *dev) = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | |
| 60 | /* |
jayalk@intworks.biz | 120bb42 | 2005-03-21 20:20:42 -0800 | [diff] [blame] | 61 | * Check passed address for the PCI IRQ Routing Table signature |
| 62 | * and perform checksum verification. |
| 63 | */ |
| 64 | |
Miklos Vajna | 273c112 | 2008-05-13 18:38:56 +0200 | [diff] [blame^] | 65 | static inline struct irq_routing_table *pirq_check_routing_table(u8 *addr) |
jayalk@intworks.biz | 120bb42 | 2005-03-21 20:20:42 -0800 | [diff] [blame] | 66 | { |
| 67 | struct irq_routing_table *rt; |
| 68 | int i; |
| 69 | u8 sum; |
| 70 | |
| 71 | rt = (struct irq_routing_table *) addr; |
| 72 | if (rt->signature != PIRQ_SIGNATURE || |
| 73 | rt->version != PIRQ_VERSION || |
| 74 | rt->size % 16 || |
| 75 | rt->size < sizeof(struct irq_routing_table)) |
| 76 | return NULL; |
| 77 | sum = 0; |
Miklos Vajna | 273c112 | 2008-05-13 18:38:56 +0200 | [diff] [blame^] | 78 | for (i = 0; i < rt->size; i++) |
jayalk@intworks.biz | 120bb42 | 2005-03-21 20:20:42 -0800 | [diff] [blame] | 79 | sum += addr[i]; |
| 80 | if (!sum) { |
Miklos Vajna | 273c112 | 2008-05-13 18:38:56 +0200 | [diff] [blame^] | 81 | DBG(KERN_DEBUG "PCI: Interrupt Routing Table found at 0x%p\n", |
| 82 | rt); |
jayalk@intworks.biz | 120bb42 | 2005-03-21 20:20:42 -0800 | [diff] [blame] | 83 | return rt; |
| 84 | } |
| 85 | return NULL; |
| 86 | } |
| 87 | |
| 88 | |
| 89 | |
| 90 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | * Search 0xf0000 -- 0xfffff for the PCI IRQ Routing Table. |
| 92 | */ |
| 93 | |
| 94 | static struct irq_routing_table * __init pirq_find_routing_table(void) |
| 95 | { |
| 96 | u8 *addr; |
| 97 | struct irq_routing_table *rt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | |
jayalk@intworks.biz | 120bb42 | 2005-03-21 20:20:42 -0800 | [diff] [blame] | 99 | if (pirq_table_addr) { |
| 100 | rt = pirq_check_routing_table((u8 *) __va(pirq_table_addr)); |
| 101 | if (rt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | return rt; |
jayalk@intworks.biz | 120bb42 | 2005-03-21 20:20:42 -0800 | [diff] [blame] | 103 | printk(KERN_WARNING "PCI: PIRQ table NOT found at pirqaddr\n"); |
| 104 | } |
Miklos Vajna | 273c112 | 2008-05-13 18:38:56 +0200 | [diff] [blame^] | 105 | for (addr = (u8 *) __va(0xf0000); addr < (u8 *) __va(0x100000); |
| 106 | addr += 16) { |
jayalk@intworks.biz | 120bb42 | 2005-03-21 20:20:42 -0800 | [diff] [blame] | 107 | rt = pirq_check_routing_table(addr); |
| 108 | if (rt) |
| 109 | return rt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | } |
| 111 | return NULL; |
| 112 | } |
| 113 | |
| 114 | /* |
| 115 | * If we have a IRQ routing table, use it to search for peer host |
| 116 | * bridges. It's a gross hack, but since there are no other known |
| 117 | * ways how to get a list of buses, we have to go this way. |
| 118 | */ |
| 119 | |
| 120 | static void __init pirq_peer_trick(void) |
| 121 | { |
| 122 | struct irq_routing_table *rt = pirq_table; |
| 123 | u8 busmap[256]; |
| 124 | int i; |
| 125 | struct irq_info *e; |
| 126 | |
| 127 | memset(busmap, 0, sizeof(busmap)); |
Miklos Vajna | 273c112 | 2008-05-13 18:38:56 +0200 | [diff] [blame^] | 128 | for (i = 0; i < (rt->size - sizeof(struct irq_routing_table)) / |
| 129 | sizeof(struct irq_info); i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | e = &rt->slots[i]; |
| 131 | #ifdef DEBUG |
| 132 | { |
| 133 | int j; |
Miklos Vajna | 273c112 | 2008-05-13 18:38:56 +0200 | [diff] [blame^] | 134 | DBG(KERN_DEBUG "%02x:%02x slot=%02x", e->bus, |
| 135 | e->devfn/8, e->slot); |
| 136 | for (j = 0; j < 4; j++) |
| 137 | DBG(" %d:%02x/%04x", j, e->irq[j].link, |
| 138 | e->irq[j].bitmap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | DBG("\n"); |
| 140 | } |
| 141 | #endif |
| 142 | busmap[e->bus] = 1; |
| 143 | } |
Miklos Vajna | 273c112 | 2008-05-13 18:38:56 +0200 | [diff] [blame^] | 144 | for (i = 1; i < 256; i++) { |
Yinghai Lu | 871d5f8 | 2008-02-19 03:20:09 -0800 | [diff] [blame] | 145 | int node; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | if (!busmap[i] || pci_find_bus(0, i)) |
| 147 | continue; |
Yinghai Lu | 871d5f8 | 2008-02-19 03:20:09 -0800 | [diff] [blame] | 148 | node = get_mp_bus_to_node(i); |
| 149 | if (pci_scan_bus_on_node(i, &pci_root_ops, node)) |
Muli Ben-Yehuda | 73c59af | 2007-08-10 13:01:19 -0700 | [diff] [blame] | 150 | printk(KERN_INFO "PCI: Discovered primary peer " |
| 151 | "bus %02x [IRQ]\n", i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | } |
| 153 | pcibios_last_bus = -1; |
| 154 | } |
| 155 | |
| 156 | /* |
| 157 | * Code for querying and setting of IRQ routes on various interrupt routers. |
| 158 | */ |
| 159 | |
| 160 | void eisa_set_level_irq(unsigned int irq) |
| 161 | { |
| 162 | unsigned char mask = 1 << (irq & 7); |
| 163 | unsigned int port = 0x4d0 + (irq >> 3); |
| 164 | unsigned char val; |
| 165 | static u16 eisa_irq_mask; |
| 166 | |
| 167 | if (irq >= 16 || (1 << irq) & eisa_irq_mask) |
| 168 | return; |
| 169 | |
| 170 | eisa_irq_mask |= (1 << irq); |
Daniel Marjamäki | 8174551 | 2005-12-01 18:01:28 +0100 | [diff] [blame] | 171 | printk(KERN_DEBUG "PCI: setting IRQ %u as level-triggered\n", irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | val = inb(port); |
| 173 | if (!(val & mask)) { |
Daniel Marjamäki | 8174551 | 2005-12-01 18:01:28 +0100 | [diff] [blame] | 174 | DBG(KERN_DEBUG " -> edge"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | outb(val | mask, port); |
| 176 | } |
| 177 | } |
| 178 | |
| 179 | /* |
Simon Arlott | 27b46d7 | 2007-10-20 01:13:56 +0200 | [diff] [blame] | 180 | * Common IRQ routing practice: nibbles in config space, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | * offset by some magic constant. |
| 182 | */ |
Miklos Vajna | 273c112 | 2008-05-13 18:38:56 +0200 | [diff] [blame^] | 183 | static unsigned int |
| 184 | read_config_nybble(struct pci_dev *router, unsigned offset, unsigned nr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | { |
| 186 | u8 x; |
| 187 | unsigned reg = offset + (nr >> 1); |
| 188 | |
| 189 | pci_read_config_byte(router, reg, &x); |
| 190 | return (nr & 1) ? (x >> 4) : (x & 0xf); |
| 191 | } |
| 192 | |
Miklos Vajna | 273c112 | 2008-05-13 18:38:56 +0200 | [diff] [blame^] | 193 | static void write_config_nybble(struct pci_dev *router, unsigned offset, |
| 194 | unsigned nr, unsigned int val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | { |
| 196 | u8 x; |
| 197 | unsigned reg = offset + (nr >> 1); |
| 198 | |
| 199 | pci_read_config_byte(router, reg, &x); |
| 200 | x = (nr & 1) ? ((x & 0x0f) | (val << 4)) : ((x & 0xf0) | val); |
| 201 | pci_write_config_byte(router, reg, x); |
| 202 | } |
| 203 | |
| 204 | /* |
| 205 | * ALI pirq entries are damn ugly, and completely undocumented. |
| 206 | * This has been figured out from pirq tables, and it's not a pretty |
| 207 | * picture. |
| 208 | */ |
| 209 | static int pirq_ali_get(struct pci_dev *router, struct pci_dev *dev, int pirq) |
| 210 | { |
Miklos Vajna | 273c112 | 2008-05-13 18:38:56 +0200 | [diff] [blame^] | 211 | static const unsigned char irqmap[16] = { 0, 9, 3, 10, 4, 5, 7, 6, 1, |
| 212 | 11, 0, 12, 0, 14, 0, 15 }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | |
Björn Steinbrink | 223ac2f | 2008-03-31 04:22:53 +0200 | [diff] [blame] | 214 | WARN_ON_ONCE(pirq > 16); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | return irqmap[read_config_nybble(router, 0x48, pirq-1)]; |
| 216 | } |
| 217 | |
Miklos Vajna | 273c112 | 2008-05-13 18:38:56 +0200 | [diff] [blame^] | 218 | static int |
| 219 | pirq_ali_set(struct pci_dev *router, struct pci_dev *dev, int pirq, int irq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | { |
Miklos Vajna | 273c112 | 2008-05-13 18:38:56 +0200 | [diff] [blame^] | 221 | static const unsigned char irqmap[16] = { 0, 8, 0, 2, 4, 5, 7, 6, 0, 1, |
| 222 | 3, 9, 11, 0, 13, 15 }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | unsigned int val = irqmap[irq]; |
Ingo Molnar | 7d409d6 | 2008-01-30 13:32:00 +0100 | [diff] [blame] | 224 | |
Björn Steinbrink | 223ac2f | 2008-03-31 04:22:53 +0200 | [diff] [blame] | 225 | WARN_ON_ONCE(pirq > 16); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | if (val) { |
| 227 | write_config_nybble(router, 0x48, pirq-1, val); |
| 228 | return 1; |
| 229 | } |
| 230 | return 0; |
| 231 | } |
| 232 | |
| 233 | /* |
| 234 | * The Intel PIIX4 pirq rules are fairly simple: "pirq" is |
| 235 | * just a pointer to the config space. |
| 236 | */ |
| 237 | static int pirq_piix_get(struct pci_dev *router, struct pci_dev *dev, int pirq) |
| 238 | { |
| 239 | u8 x; |
| 240 | |
| 241 | pci_read_config_byte(router, pirq, &x); |
| 242 | return (x < 16) ? x : 0; |
| 243 | } |
| 244 | |
Miklos Vajna | 273c112 | 2008-05-13 18:38:56 +0200 | [diff] [blame^] | 245 | static int |
| 246 | pirq_piix_set(struct pci_dev *router, struct pci_dev *dev, int pirq, int irq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | { |
| 248 | pci_write_config_byte(router, pirq, irq); |
| 249 | return 1; |
| 250 | } |
| 251 | |
| 252 | /* |
| 253 | * The VIA pirq rules are nibble-based, like ALI, |
| 254 | * but without the ugly irq number munging. |
| 255 | * However, PIRQD is in the upper instead of lower 4 bits. |
| 256 | */ |
| 257 | static int pirq_via_get(struct pci_dev *router, struct pci_dev *dev, int pirq) |
| 258 | { |
| 259 | return read_config_nybble(router, 0x55, pirq == 4 ? 5 : pirq); |
| 260 | } |
| 261 | |
Miklos Vajna | 273c112 | 2008-05-13 18:38:56 +0200 | [diff] [blame^] | 262 | static int |
| 263 | pirq_via_set(struct pci_dev *router, struct pci_dev *dev, int pirq, int irq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | { |
| 265 | write_config_nybble(router, 0x55, pirq == 4 ? 5 : pirq, irq); |
| 266 | return 1; |
| 267 | } |
| 268 | |
| 269 | /* |
Aleksey Gorelov | 80bb82a | 2005-06-23 00:08:29 -0700 | [diff] [blame] | 270 | * The VIA pirq rules are nibble-based, like ALI, |
| 271 | * but without the ugly irq number munging. |
| 272 | * However, for 82C586, nibble map is different . |
| 273 | */ |
Miklos Vajna | 273c112 | 2008-05-13 18:38:56 +0200 | [diff] [blame^] | 274 | static int |
| 275 | pirq_via586_get(struct pci_dev *router, struct pci_dev *dev, int pirq) |
Aleksey Gorelov | 80bb82a | 2005-06-23 00:08:29 -0700 | [diff] [blame] | 276 | { |
Daniel Ritz | f3ac843 | 2006-11-14 02:03:25 -0800 | [diff] [blame] | 277 | static const unsigned int pirqmap[5] = { 3, 2, 5, 1, 1 }; |
Ingo Molnar | 7d409d6 | 2008-01-30 13:32:00 +0100 | [diff] [blame] | 278 | |
Björn Steinbrink | 223ac2f | 2008-03-31 04:22:53 +0200 | [diff] [blame] | 279 | WARN_ON_ONCE(pirq > 5); |
Aleksey Gorelov | 80bb82a | 2005-06-23 00:08:29 -0700 | [diff] [blame] | 280 | return read_config_nybble(router, 0x55, pirqmap[pirq-1]); |
| 281 | } |
| 282 | |
Miklos Vajna | 273c112 | 2008-05-13 18:38:56 +0200 | [diff] [blame^] | 283 | static int |
| 284 | pirq_via586_set(struct pci_dev *router, struct pci_dev *dev, int pirq, int irq) |
Aleksey Gorelov | 80bb82a | 2005-06-23 00:08:29 -0700 | [diff] [blame] | 285 | { |
Daniel Ritz | f3ac843 | 2006-11-14 02:03:25 -0800 | [diff] [blame] | 286 | static const unsigned int pirqmap[5] = { 3, 2, 5, 1, 1 }; |
Ingo Molnar | 7d409d6 | 2008-01-30 13:32:00 +0100 | [diff] [blame] | 287 | |
Björn Steinbrink | 223ac2f | 2008-03-31 04:22:53 +0200 | [diff] [blame] | 288 | WARN_ON_ONCE(pirq > 5); |
Aleksey Gorelov | 80bb82a | 2005-06-23 00:08:29 -0700 | [diff] [blame] | 289 | write_config_nybble(router, 0x55, pirqmap[pirq-1], irq); |
| 290 | return 1; |
| 291 | } |
| 292 | |
| 293 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | * ITE 8330G pirq rules are nibble-based |
| 295 | * FIXME: pirqmap may be { 1, 0, 3, 2 }, |
| 296 | * 2+3 are both mapped to irq 9 on my system |
| 297 | */ |
| 298 | static int pirq_ite_get(struct pci_dev *router, struct pci_dev *dev, int pirq) |
| 299 | { |
Andreas Mohr | a0de1f0 | 2006-06-23 02:04:28 -0700 | [diff] [blame] | 300 | static const unsigned char pirqmap[4] = { 1, 0, 2, 3 }; |
Ingo Molnar | 7d409d6 | 2008-01-30 13:32:00 +0100 | [diff] [blame] | 301 | |
Björn Steinbrink | 223ac2f | 2008-03-31 04:22:53 +0200 | [diff] [blame] | 302 | WARN_ON_ONCE(pirq > 4); |
Miklos Vajna | 273c112 | 2008-05-13 18:38:56 +0200 | [diff] [blame^] | 303 | return read_config_nybble(router, 0x43, pirqmap[pirq-1]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | } |
| 305 | |
Miklos Vajna | 273c112 | 2008-05-13 18:38:56 +0200 | [diff] [blame^] | 306 | static int |
| 307 | pirq_ite_set(struct pci_dev *router, struct pci_dev *dev, int pirq, int irq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | { |
Andreas Mohr | a0de1f0 | 2006-06-23 02:04:28 -0700 | [diff] [blame] | 309 | static const unsigned char pirqmap[4] = { 1, 0, 2, 3 }; |
Ingo Molnar | 7d409d6 | 2008-01-30 13:32:00 +0100 | [diff] [blame] | 310 | |
Björn Steinbrink | 223ac2f | 2008-03-31 04:22:53 +0200 | [diff] [blame] | 311 | WARN_ON_ONCE(pirq > 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | write_config_nybble(router, 0x43, pirqmap[pirq-1], irq); |
| 313 | return 1; |
| 314 | } |
| 315 | |
| 316 | /* |
| 317 | * OPTI: high four bits are nibble pointer.. |
| 318 | * I wonder what the low bits do? |
| 319 | */ |
| 320 | static int pirq_opti_get(struct pci_dev *router, struct pci_dev *dev, int pirq) |
| 321 | { |
| 322 | return read_config_nybble(router, 0xb8, pirq >> 4); |
| 323 | } |
| 324 | |
Miklos Vajna | 273c112 | 2008-05-13 18:38:56 +0200 | [diff] [blame^] | 325 | static int |
| 326 | pirq_opti_set(struct pci_dev *router, struct pci_dev *dev, int pirq, int irq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | { |
| 328 | write_config_nybble(router, 0xb8, pirq >> 4, irq); |
| 329 | return 1; |
| 330 | } |
| 331 | |
| 332 | /* |
| 333 | * Cyrix: nibble offset 0x5C |
Miklos Vajna | 273c112 | 2008-05-13 18:38:56 +0200 | [diff] [blame^] | 334 | * 0x5C bits 7:4 is INTB bits 3:0 is INTA |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | * 0x5D bits 7:4 is INTD bits 3:0 is INTC |
| 336 | */ |
| 337 | static int pirq_cyrix_get(struct pci_dev *router, struct pci_dev *dev, int pirq) |
| 338 | { |
| 339 | return read_config_nybble(router, 0x5C, (pirq-1)^1); |
| 340 | } |
| 341 | |
Miklos Vajna | 273c112 | 2008-05-13 18:38:56 +0200 | [diff] [blame^] | 342 | static int |
| 343 | pirq_cyrix_set(struct pci_dev *router, struct pci_dev *dev, int pirq, int irq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | { |
| 345 | write_config_nybble(router, 0x5C, (pirq-1)^1, irq); |
| 346 | return 1; |
| 347 | } |
| 348 | |
| 349 | /* |
| 350 | * PIRQ routing for SiS 85C503 router used in several SiS chipsets. |
| 351 | * We have to deal with the following issues here: |
| 352 | * - vendors have different ideas about the meaning of link values |
| 353 | * - some onboard devices (integrated in the chipset) have special |
| 354 | * links and are thus routed differently (i.e. not via PCI INTA-INTD) |
| 355 | * - different revision of the router have a different layout for |
| 356 | * the routing registers, particularly for the onchip devices |
| 357 | * |
| 358 | * For all routing registers the common thing is we have one byte |
| 359 | * per routeable link which is defined as: |
| 360 | * bit 7 IRQ mapping enabled (0) or disabled (1) |
| 361 | * bits [6:4] reserved (sometimes used for onchip devices) |
| 362 | * bits [3:0] IRQ to map to |
| 363 | * allowed: 3-7, 9-12, 14-15 |
| 364 | * reserved: 0, 1, 2, 8, 13 |
| 365 | * |
| 366 | * The config-space registers located at 0x41/0x42/0x43/0x44 are |
| 367 | * always used to route the normal PCI INT A/B/C/D respectively. |
| 368 | * Apparently there are systems implementing PCI routing table using |
| 369 | * link values 0x01-0x04 and others using 0x41-0x44 for PCI INTA..D. |
| 370 | * We try our best to handle both link mappings. |
Miklos Vajna | 273c112 | 2008-05-13 18:38:56 +0200 | [diff] [blame^] | 371 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | * Currently (2003-05-21) it appears most SiS chipsets follow the |
| 373 | * definition of routing registers from the SiS-5595 southbridge. |
| 374 | * According to the SiS 5595 datasheets the revision id's of the |
| 375 | * router (ISA-bridge) should be 0x01 or 0xb0. |
| 376 | * |
| 377 | * Furthermore we've also seen lspci dumps with revision 0x00 and 0xb1. |
| 378 | * Looks like these are used in a number of SiS 5xx/6xx/7xx chipsets. |
| 379 | * They seem to work with the current routing code. However there is |
| 380 | * some concern because of the two USB-OHCI HCs (original SiS 5595 |
| 381 | * had only one). YMMV. |
| 382 | * |
| 383 | * Onchip routing for router rev-id 0x01/0xb0 and probably 0x00/0xb1: |
| 384 | * |
| 385 | * 0x61: IDEIRQ: |
| 386 | * bits [6:5] must be written 01 |
| 387 | * bit 4 channel-select primary (0), secondary (1) |
| 388 | * |
| 389 | * 0x62: USBIRQ: |
| 390 | * bit 6 OHCI function disabled (0), enabled (1) |
Miklos Vajna | 273c112 | 2008-05-13 18:38:56 +0200 | [diff] [blame^] | 391 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | * 0x6a: ACPI/SCI IRQ: bits 4-6 reserved |
| 393 | * |
| 394 | * 0x7e: Data Acq. Module IRQ - bits 4-6 reserved |
| 395 | * |
| 396 | * We support USBIRQ (in addition to INTA-INTD) and keep the |
| 397 | * IDE, ACPI and DAQ routing untouched as set by the BIOS. |
| 398 | * |
| 399 | * Currently the only reported exception is the new SiS 65x chipset |
| 400 | * which includes the SiS 69x southbridge. Here we have the 85C503 |
| 401 | * router revision 0x04 and there are changes in the register layout |
| 402 | * mostly related to the different USB HCs with USB 2.0 support. |
| 403 | * |
| 404 | * Onchip routing for router rev-id 0x04 (try-and-error observation) |
| 405 | * |
| 406 | * 0x60/0x61/0x62/0x63: 1xEHCI and 3xOHCI (companion) USB-HCs |
| 407 | * bit 6-4 are probably unused, not like 5595 |
| 408 | */ |
| 409 | |
| 410 | #define PIRQ_SIS_IRQ_MASK 0x0f |
| 411 | #define PIRQ_SIS_IRQ_DISABLE 0x80 |
| 412 | #define PIRQ_SIS_USB_ENABLE 0x40 |
| 413 | |
| 414 | static int pirq_sis_get(struct pci_dev *router, struct pci_dev *dev, int pirq) |
| 415 | { |
| 416 | u8 x; |
| 417 | int reg; |
| 418 | |
| 419 | reg = pirq; |
| 420 | if (reg >= 0x01 && reg <= 0x04) |
| 421 | reg += 0x40; |
| 422 | pci_read_config_byte(router, reg, &x); |
| 423 | return (x & PIRQ_SIS_IRQ_DISABLE) ? 0 : (x & PIRQ_SIS_IRQ_MASK); |
| 424 | } |
| 425 | |
Miklos Vajna | 273c112 | 2008-05-13 18:38:56 +0200 | [diff] [blame^] | 426 | static int |
| 427 | pirq_sis_set(struct pci_dev *router, struct pci_dev *dev, int pirq, int irq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | { |
| 429 | u8 x; |
| 430 | int reg; |
| 431 | |
| 432 | reg = pirq; |
| 433 | if (reg >= 0x01 && reg <= 0x04) |
| 434 | reg += 0x40; |
| 435 | pci_read_config_byte(router, reg, &x); |
| 436 | x &= ~(PIRQ_SIS_IRQ_MASK | PIRQ_SIS_IRQ_DISABLE); |
| 437 | x |= irq ? irq: PIRQ_SIS_IRQ_DISABLE; |
| 438 | pci_write_config_byte(router, reg, x); |
| 439 | return 1; |
| 440 | } |
| 441 | |
| 442 | |
| 443 | /* |
| 444 | * VLSI: nibble offset 0x74 - educated guess due to routing table and |
| 445 | * config space of VLSI 82C534 PCI-bridge/router (1004:0102) |
| 446 | * Tested on HP OmniBook 800 covering PIRQ 1, 2, 4, 8 for onboard |
| 447 | * devices, PIRQ 3 for non-pci(!) soundchip and (untested) PIRQ 6 |
| 448 | * for the busbridge to the docking station. |
| 449 | */ |
| 450 | |
| 451 | static int pirq_vlsi_get(struct pci_dev *router, struct pci_dev *dev, int pirq) |
| 452 | { |
Ingo Molnar | 7d409d6 | 2008-01-30 13:32:00 +0100 | [diff] [blame] | 453 | WARN_ON_ONCE(pirq >= 9); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 454 | if (pirq > 8) { |
| 455 | printk(KERN_INFO "VLSI router pirq escape (%d)\n", pirq); |
| 456 | return 0; |
| 457 | } |
| 458 | return read_config_nybble(router, 0x74, pirq-1); |
| 459 | } |
| 460 | |
Miklos Vajna | 273c112 | 2008-05-13 18:38:56 +0200 | [diff] [blame^] | 461 | static int |
| 462 | pirq_vlsi_set(struct pci_dev *router, struct pci_dev *dev, int pirq, int irq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 463 | { |
Ingo Molnar | 7d409d6 | 2008-01-30 13:32:00 +0100 | [diff] [blame] | 464 | WARN_ON_ONCE(pirq >= 9); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 | if (pirq > 8) { |
| 466 | printk(KERN_INFO "VLSI router pirq escape (%d)\n", pirq); |
| 467 | return 0; |
| 468 | } |
| 469 | write_config_nybble(router, 0x74, pirq-1, irq); |
| 470 | return 1; |
| 471 | } |
| 472 | |
| 473 | /* |
| 474 | * ServerWorks: PCI interrupts mapped to system IRQ lines through Index |
| 475 | * and Redirect I/O registers (0x0c00 and 0x0c01). The Index register |
| 476 | * format is (PCIIRQ## | 0x10), e.g.: PCIIRQ10=0x1a. The Redirect |
| 477 | * register is a straight binary coding of desired PIC IRQ (low nibble). |
| 478 | * |
| 479 | * The 'link' value in the PIRQ table is already in the correct format |
| 480 | * for the Index register. There are some special index values: |
| 481 | * 0x00 for ACPI (SCI), 0x01 for USB, 0x02 for IDE0, 0x04 for IDE1, |
| 482 | * and 0x03 for SMBus. |
| 483 | */ |
Miklos Vajna | 273c112 | 2008-05-13 18:38:56 +0200 | [diff] [blame^] | 484 | static int |
| 485 | pirq_serverworks_get(struct pci_dev *router, struct pci_dev *dev, int pirq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 486 | { |
Alan Cox | c11b68b | 2008-01-30 13:33:14 +0100 | [diff] [blame] | 487 | outb(pirq, 0xc00); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 488 | return inb(0xc01) & 0xf; |
| 489 | } |
| 490 | |
Miklos Vajna | 273c112 | 2008-05-13 18:38:56 +0200 | [diff] [blame^] | 491 | static int pirq_serverworks_set(struct pci_dev *router, struct pci_dev *dev, |
| 492 | int pirq, int irq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 493 | { |
Alan Cox | c11b68b | 2008-01-30 13:33:14 +0100 | [diff] [blame] | 494 | outb(pirq, 0xc00); |
| 495 | outb(irq, 0xc01); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 496 | return 1; |
| 497 | } |
| 498 | |
| 499 | /* Support for AMD756 PCI IRQ Routing |
| 500 | * Jhon H. Caicedo <jhcaiced@osso.org.co> |
| 501 | * Jun/21/2001 0.2.0 Release, fixed to use "nybble" functions... (jhcaiced) |
| 502 | * Jun/19/2001 Alpha Release 0.1.0 (jhcaiced) |
| 503 | * The AMD756 pirq rules are nibble-based |
| 504 | * offset 0x56 0-3 PIRQA 4-7 PIRQB |
| 505 | * offset 0x57 0-3 PIRQC 4-7 PIRQD |
| 506 | */ |
Miklos Vajna | 273c112 | 2008-05-13 18:38:56 +0200 | [diff] [blame^] | 507 | static int |
| 508 | pirq_amd756_get(struct pci_dev *router, struct pci_dev *dev, int pirq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 509 | { |
| 510 | u8 irq; |
| 511 | irq = 0; |
| 512 | if (pirq <= 4) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | irq = read_config_nybble(router, 0x56, pirq - 1); |
Miklos Vajna | 273c112 | 2008-05-13 18:38:56 +0200 | [diff] [blame^] | 514 | printk(KERN_INFO |
| 515 | "AMD756: dev %04x:%04x, router pirq : %d get irq : %2d\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 516 | dev->vendor, dev->device, pirq, irq); |
| 517 | return irq; |
| 518 | } |
| 519 | |
Miklos Vajna | 273c112 | 2008-05-13 18:38:56 +0200 | [diff] [blame^] | 520 | static int |
| 521 | pirq_amd756_set(struct pci_dev *router, struct pci_dev *dev, int pirq, int irq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 522 | { |
Miklos Vajna | 273c112 | 2008-05-13 18:38:56 +0200 | [diff] [blame^] | 523 | printk(KERN_INFO |
| 524 | "AMD756: dev %04x:%04x, router pirq : %d SET irq : %2d\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 525 | dev->vendor, dev->device, pirq, irq); |
| 526 | if (pirq <= 4) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 527 | write_config_nybble(router, 0x56, pirq - 1, irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 528 | return 1; |
| 529 | } |
| 530 | |
Thomas Backlund | b205f6b | 2007-08-10 14:42:15 -0700 | [diff] [blame] | 531 | /* |
| 532 | * PicoPower PT86C523 |
| 533 | */ |
| 534 | static int pirq_pico_get(struct pci_dev *router, struct pci_dev *dev, int pirq) |
| 535 | { |
| 536 | outb(0x10 + ((pirq - 1) >> 1), 0x24); |
| 537 | return ((pirq - 1) & 1) ? (inb(0x26) >> 4) : (inb(0x26) & 0xf); |
| 538 | } |
| 539 | |
| 540 | static int pirq_pico_set(struct pci_dev *router, struct pci_dev *dev, int pirq, |
| 541 | int irq) |
| 542 | { |
| 543 | unsigned int x; |
| 544 | outb(0x10 + ((pirq - 1) >> 1), 0x24); |
| 545 | x = inb(0x26); |
| 546 | x = ((pirq - 1) & 1) ? ((x & 0x0f) | (irq << 4)) : ((x & 0xf0) | (irq)); |
| 547 | outb(x, 0x26); |
| 548 | return 1; |
| 549 | } |
| 550 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 551 | #ifdef CONFIG_PCI_BIOS |
| 552 | |
Miklos Vajna | 273c112 | 2008-05-13 18:38:56 +0200 | [diff] [blame^] | 553 | static int |
| 554 | pirq_bios_set(struct pci_dev *router, struct pci_dev *dev, int pirq, int irq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 555 | { |
| 556 | struct pci_dev *bridge; |
| 557 | int pin = pci_get_interrupt_pin(dev, &bridge); |
| 558 | return pcibios_set_irq_routing(bridge, pin, irq); |
| 559 | } |
| 560 | |
| 561 | #endif |
| 562 | |
Miklos Vajna | 273c112 | 2008-05-13 18:38:56 +0200 | [diff] [blame^] | 563 | static __init int |
| 564 | intel_router_probe(struct irq_router *r, struct pci_dev *router, u16 device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 565 | { |
Andreas Mohr | a0de1f0 | 2006-06-23 02:04:28 -0700 | [diff] [blame] | 566 | static struct pci_device_id __initdata pirq_440gx[] = { |
Miklos Vajna | 273c112 | 2008-05-13 18:38:56 +0200 | [diff] [blame^] | 567 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, |
| 568 | PCI_DEVICE_ID_INTEL_82443GX_0) }, |
| 569 | { PCI_DEVICE(PCI_VENDOR_ID_INTEL, |
| 570 | PCI_DEVICE_ID_INTEL_82443GX_2) }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 571 | { }, |
| 572 | }; |
| 573 | |
| 574 | /* 440GX has a proprietary PIRQ router -- don't use it */ |
| 575 | if (pci_dev_present(pirq_440gx)) |
| 576 | return 0; |
| 577 | |
Miklos Vajna | 273c112 | 2008-05-13 18:38:56 +0200 | [diff] [blame^] | 578 | switch (device) { |
| 579 | case PCI_DEVICE_ID_INTEL_82371FB_0: |
| 580 | case PCI_DEVICE_ID_INTEL_82371SB_0: |
| 581 | case PCI_DEVICE_ID_INTEL_82371AB_0: |
| 582 | case PCI_DEVICE_ID_INTEL_82371MX: |
| 583 | case PCI_DEVICE_ID_INTEL_82443MX_0: |
| 584 | case PCI_DEVICE_ID_INTEL_82801AA_0: |
| 585 | case PCI_DEVICE_ID_INTEL_82801AB_0: |
| 586 | case PCI_DEVICE_ID_INTEL_82801BA_0: |
| 587 | case PCI_DEVICE_ID_INTEL_82801BA_10: |
| 588 | case PCI_DEVICE_ID_INTEL_82801CA_0: |
| 589 | case PCI_DEVICE_ID_INTEL_82801CA_12: |
| 590 | case PCI_DEVICE_ID_INTEL_82801DB_0: |
| 591 | case PCI_DEVICE_ID_INTEL_82801E_0: |
| 592 | case PCI_DEVICE_ID_INTEL_82801EB_0: |
| 593 | case PCI_DEVICE_ID_INTEL_ESB_1: |
| 594 | case PCI_DEVICE_ID_INTEL_ICH6_0: |
| 595 | case PCI_DEVICE_ID_INTEL_ICH6_1: |
| 596 | case PCI_DEVICE_ID_INTEL_ICH7_0: |
| 597 | case PCI_DEVICE_ID_INTEL_ICH7_1: |
| 598 | case PCI_DEVICE_ID_INTEL_ICH7_30: |
| 599 | case PCI_DEVICE_ID_INTEL_ICH7_31: |
| 600 | case PCI_DEVICE_ID_INTEL_ESB2_0: |
| 601 | case PCI_DEVICE_ID_INTEL_ICH8_0: |
| 602 | case PCI_DEVICE_ID_INTEL_ICH8_1: |
| 603 | case PCI_DEVICE_ID_INTEL_ICH8_2: |
| 604 | case PCI_DEVICE_ID_INTEL_ICH8_3: |
| 605 | case PCI_DEVICE_ID_INTEL_ICH8_4: |
| 606 | case PCI_DEVICE_ID_INTEL_ICH9_0: |
| 607 | case PCI_DEVICE_ID_INTEL_ICH9_1: |
| 608 | case PCI_DEVICE_ID_INTEL_ICH9_2: |
| 609 | case PCI_DEVICE_ID_INTEL_ICH9_3: |
| 610 | case PCI_DEVICE_ID_INTEL_ICH9_4: |
| 611 | case PCI_DEVICE_ID_INTEL_ICH9_5: |
| 612 | case PCI_DEVICE_ID_INTEL_TOLAPAI_0: |
| 613 | case PCI_DEVICE_ID_INTEL_ICH10_0: |
| 614 | case PCI_DEVICE_ID_INTEL_ICH10_1: |
| 615 | case PCI_DEVICE_ID_INTEL_ICH10_2: |
| 616 | case PCI_DEVICE_ID_INTEL_ICH10_3: |
| 617 | r->name = "PIIX/ICH"; |
| 618 | r->get = pirq_piix_get; |
| 619 | r->set = pirq_piix_set; |
| 620 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 621 | } |
| 622 | return 0; |
| 623 | } |
| 624 | |
aleksey_gorelov@phoenix.com | 750deaa | 2005-10-30 14:59:36 -0800 | [diff] [blame] | 625 | static __init int via_router_probe(struct irq_router *r, |
| 626 | struct pci_dev *router, u16 device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 627 | { |
| 628 | /* FIXME: We should move some of the quirk fixup stuff here */ |
Giancarlo Formicuccia | ac12259 | 2005-07-28 01:07:33 -0700 | [diff] [blame] | 629 | |
aleksey_gorelov@phoenix.com | 750deaa | 2005-10-30 14:59:36 -0800 | [diff] [blame] | 630 | /* |
Simon Arlott | 27b46d7 | 2007-10-20 01:13:56 +0200 | [diff] [blame] | 631 | * workarounds for some buggy BIOSes |
aleksey_gorelov@phoenix.com | 750deaa | 2005-10-30 14:59:36 -0800 | [diff] [blame] | 632 | */ |
| 633 | if (device == PCI_DEVICE_ID_VIA_82C586_0) { |
Miklos Vajna | 273c112 | 2008-05-13 18:38:56 +0200 | [diff] [blame^] | 634 | switch (router->device) { |
aleksey_gorelov@phoenix.com | 750deaa | 2005-10-30 14:59:36 -0800 | [diff] [blame] | 635 | case PCI_DEVICE_ID_VIA_82C686: |
| 636 | /* |
| 637 | * Asus k7m bios wrongly reports 82C686A |
| 638 | * as 586-compatible |
| 639 | */ |
| 640 | device = PCI_DEVICE_ID_VIA_82C686; |
| 641 | break; |
| 642 | case PCI_DEVICE_ID_VIA_8235: |
| 643 | /** |
| 644 | * Asus a7v-x bios wrongly reports 8235 |
| 645 | * as 586-compatible |
| 646 | */ |
| 647 | device = PCI_DEVICE_ID_VIA_8235; |
| 648 | break; |
Bertram Felgenhauer | 9f67fd5 | 2008-06-05 15:31:22 -0700 | [diff] [blame] | 649 | case PCI_DEVICE_ID_VIA_8237: |
| 650 | /** |
| 651 | * Asus a7v600 bios wrongly reports 8237 |
| 652 | * as 586-compatible |
| 653 | */ |
| 654 | device = PCI_DEVICE_ID_VIA_8237; |
| 655 | break; |
aleksey_gorelov@phoenix.com | 750deaa | 2005-10-30 14:59:36 -0800 | [diff] [blame] | 656 | } |
Giancarlo Formicuccia | ac12259 | 2005-07-28 01:07:33 -0700 | [diff] [blame] | 657 | } |
| 658 | |
Miklos Vajna | 273c112 | 2008-05-13 18:38:56 +0200 | [diff] [blame^] | 659 | switch (device) { |
aleksey_gorelov@phoenix.com | 750deaa | 2005-10-30 14:59:36 -0800 | [diff] [blame] | 660 | case PCI_DEVICE_ID_VIA_82C586_0: |
| 661 | r->name = "VIA"; |
| 662 | r->get = pirq_via586_get; |
| 663 | r->set = pirq_via586_set; |
| 664 | return 1; |
| 665 | case PCI_DEVICE_ID_VIA_82C596: |
| 666 | case PCI_DEVICE_ID_VIA_82C686: |
| 667 | case PCI_DEVICE_ID_VIA_8231: |
Grzegorz Janoszka | 40d8b89 | 2006-03-21 11:57:19 +0100 | [diff] [blame] | 668 | case PCI_DEVICE_ID_VIA_8233A: |
aleksey_gorelov@phoenix.com | 750deaa | 2005-10-30 14:59:36 -0800 | [diff] [blame] | 669 | case PCI_DEVICE_ID_VIA_8235: |
Grzegorz Janoszka | 40d8b89 | 2006-03-21 11:57:19 +0100 | [diff] [blame] | 670 | case PCI_DEVICE_ID_VIA_8237: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 671 | /* FIXME: add new ones for 8233/5 */ |
aleksey_gorelov@phoenix.com | 750deaa | 2005-10-30 14:59:36 -0800 | [diff] [blame] | 672 | r->name = "VIA"; |
| 673 | r->get = pirq_via_get; |
| 674 | r->set = pirq_via_set; |
| 675 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 676 | } |
| 677 | return 0; |
| 678 | } |
| 679 | |
Miklos Vajna | 273c112 | 2008-05-13 18:38:56 +0200 | [diff] [blame^] | 680 | static __init int |
| 681 | vlsi_router_probe(struct irq_router *r, struct pci_dev *router, u16 device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 682 | { |
Miklos Vajna | 273c112 | 2008-05-13 18:38:56 +0200 | [diff] [blame^] | 683 | switch (device) { |
| 684 | case PCI_DEVICE_ID_VLSI_82C534: |
| 685 | r->name = "VLSI 82C534"; |
| 686 | r->get = pirq_vlsi_get; |
| 687 | r->set = pirq_vlsi_set; |
| 688 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 689 | } |
| 690 | return 0; |
| 691 | } |
| 692 | |
| 693 | |
Miklos Vajna | 273c112 | 2008-05-13 18:38:56 +0200 | [diff] [blame^] | 694 | static __init int serverworks_router_probe(struct irq_router *r, |
| 695 | struct pci_dev *router, u16 device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 696 | { |
Miklos Vajna | 273c112 | 2008-05-13 18:38:56 +0200 | [diff] [blame^] | 697 | switch (device) { |
| 698 | case PCI_DEVICE_ID_SERVERWORKS_OSB4: |
| 699 | case PCI_DEVICE_ID_SERVERWORKS_CSB5: |
| 700 | r->name = "ServerWorks"; |
| 701 | r->get = pirq_serverworks_get; |
| 702 | r->set = pirq_serverworks_set; |
| 703 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 704 | } |
| 705 | return 0; |
| 706 | } |
| 707 | |
Miklos Vajna | 273c112 | 2008-05-13 18:38:56 +0200 | [diff] [blame^] | 708 | static __init int |
| 709 | sis_router_probe(struct irq_router *r, struct pci_dev *router, u16 device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 710 | { |
| 711 | if (device != PCI_DEVICE_ID_SI_503) |
| 712 | return 0; |
Miklos Vajna | 273c112 | 2008-05-13 18:38:56 +0200 | [diff] [blame^] | 713 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 714 | r->name = "SIS"; |
| 715 | r->get = pirq_sis_get; |
| 716 | r->set = pirq_sis_set; |
| 717 | return 1; |
| 718 | } |
| 719 | |
Miklos Vajna | 273c112 | 2008-05-13 18:38:56 +0200 | [diff] [blame^] | 720 | static __init int |
| 721 | cyrix_router_probe(struct irq_router *r, struct pci_dev *router, u16 device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 722 | { |
Miklos Vajna | 273c112 | 2008-05-13 18:38:56 +0200 | [diff] [blame^] | 723 | switch (device) { |
| 724 | case PCI_DEVICE_ID_CYRIX_5520: |
| 725 | r->name = "NatSemi"; |
| 726 | r->get = pirq_cyrix_get; |
| 727 | r->set = pirq_cyrix_set; |
| 728 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 729 | } |
| 730 | return 0; |
| 731 | } |
| 732 | |
Miklos Vajna | 273c112 | 2008-05-13 18:38:56 +0200 | [diff] [blame^] | 733 | static __init int |
| 734 | opti_router_probe(struct irq_router *r, struct pci_dev *router, u16 device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 735 | { |
Miklos Vajna | 273c112 | 2008-05-13 18:38:56 +0200 | [diff] [blame^] | 736 | switch (device) { |
| 737 | case PCI_DEVICE_ID_OPTI_82C700: |
| 738 | r->name = "OPTI"; |
| 739 | r->get = pirq_opti_get; |
| 740 | r->set = pirq_opti_set; |
| 741 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 742 | } |
| 743 | return 0; |
| 744 | } |
| 745 | |
Miklos Vajna | 273c112 | 2008-05-13 18:38:56 +0200 | [diff] [blame^] | 746 | static __init int |
| 747 | ite_router_probe(struct irq_router *r, struct pci_dev *router, u16 device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 748 | { |
Miklos Vajna | 273c112 | 2008-05-13 18:38:56 +0200 | [diff] [blame^] | 749 | switch (device) { |
| 750 | case PCI_DEVICE_ID_ITE_IT8330G_0: |
| 751 | r->name = "ITE"; |
| 752 | r->get = pirq_ite_get; |
| 753 | r->set = pirq_ite_set; |
| 754 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 755 | } |
| 756 | return 0; |
| 757 | } |
| 758 | |
Miklos Vajna | 273c112 | 2008-05-13 18:38:56 +0200 | [diff] [blame^] | 759 | static __init int |
| 760 | ali_router_probe(struct irq_router *r, struct pci_dev *router, u16 device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 761 | { |
Miklos Vajna | 273c112 | 2008-05-13 18:38:56 +0200 | [diff] [blame^] | 762 | switch (device) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 763 | case PCI_DEVICE_ID_AL_M1533: |
| 764 | case PCI_DEVICE_ID_AL_M1563: |
Daniel Marjamäki | 8174551 | 2005-12-01 18:01:28 +0100 | [diff] [blame] | 765 | printk(KERN_DEBUG "PCI: Using ALI IRQ Router\n"); |
| 766 | r->name = "ALI"; |
| 767 | r->get = pirq_ali_get; |
| 768 | r->set = pirq_ali_set; |
| 769 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 770 | } |
| 771 | return 0; |
| 772 | } |
| 773 | |
Miklos Vajna | 273c112 | 2008-05-13 18:38:56 +0200 | [diff] [blame^] | 774 | static __init int |
| 775 | amd_router_probe(struct irq_router *r, struct pci_dev *router, u16 device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 776 | { |
Miklos Vajna | 273c112 | 2008-05-13 18:38:56 +0200 | [diff] [blame^] | 777 | switch (device) { |
| 778 | case PCI_DEVICE_ID_AMD_VIPER_740B: |
| 779 | r->name = "AMD756"; |
| 780 | break; |
| 781 | case PCI_DEVICE_ID_AMD_VIPER_7413: |
| 782 | r->name = "AMD766"; |
| 783 | break; |
| 784 | case PCI_DEVICE_ID_AMD_VIPER_7443: |
| 785 | r->name = "AMD768"; |
| 786 | break; |
| 787 | default: |
| 788 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 789 | } |
| 790 | r->get = pirq_amd756_get; |
| 791 | r->set = pirq_amd756_set; |
| 792 | return 1; |
| 793 | } |
Miklos Vajna | 273c112 | 2008-05-13 18:38:56 +0200 | [diff] [blame^] | 794 | |
| 795 | static __init int |
| 796 | pico_router_probe(struct irq_router *r, struct pci_dev *router, u16 device) |
Thomas Backlund | b205f6b | 2007-08-10 14:42:15 -0700 | [diff] [blame] | 797 | { |
| 798 | switch (device) { |
| 799 | case PCI_DEVICE_ID_PICOPOWER_PT86C523: |
| 800 | r->name = "PicoPower PT86C523"; |
| 801 | r->get = pirq_pico_get; |
| 802 | r->set = pirq_pico_set; |
| 803 | return 1; |
| 804 | |
| 805 | case PCI_DEVICE_ID_PICOPOWER_PT86C523BBP: |
| 806 | r->name = "PicoPower PT86C523 rev. BB+"; |
| 807 | r->get = pirq_pico_get; |
| 808 | r->set = pirq_pico_set; |
| 809 | return 1; |
| 810 | } |
| 811 | return 0; |
| 812 | } |
| 813 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 814 | static __initdata struct irq_router_handler pirq_routers[] = { |
| 815 | { PCI_VENDOR_ID_INTEL, intel_router_probe }, |
| 816 | { PCI_VENDOR_ID_AL, ali_router_probe }, |
| 817 | { PCI_VENDOR_ID_ITE, ite_router_probe }, |
| 818 | { PCI_VENDOR_ID_VIA, via_router_probe }, |
| 819 | { PCI_VENDOR_ID_OPTI, opti_router_probe }, |
| 820 | { PCI_VENDOR_ID_SI, sis_router_probe }, |
| 821 | { PCI_VENDOR_ID_CYRIX, cyrix_router_probe }, |
| 822 | { PCI_VENDOR_ID_VLSI, vlsi_router_probe }, |
| 823 | { PCI_VENDOR_ID_SERVERWORKS, serverworks_router_probe }, |
| 824 | { PCI_VENDOR_ID_AMD, amd_router_probe }, |
Thomas Backlund | b205f6b | 2007-08-10 14:42:15 -0700 | [diff] [blame] | 825 | { PCI_VENDOR_ID_PICOPOWER, pico_router_probe }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 826 | /* Someone with docs needs to add the ATI Radeon IGP */ |
| 827 | { 0, NULL } |
| 828 | }; |
| 829 | static struct irq_router pirq_router; |
| 830 | static struct pci_dev *pirq_router_dev; |
| 831 | |
| 832 | |
| 833 | /* |
| 834 | * FIXME: should we have an option to say "generic for |
| 835 | * chipset" ? |
| 836 | */ |
Miklos Vajna | 273c112 | 2008-05-13 18:38:56 +0200 | [diff] [blame^] | 837 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 838 | static void __init pirq_find_router(struct irq_router *r) |
| 839 | { |
| 840 | struct irq_routing_table *rt = pirq_table; |
| 841 | struct irq_router_handler *h; |
| 842 | |
| 843 | #ifdef CONFIG_PCI_BIOS |
| 844 | if (!rt->signature) { |
| 845 | printk(KERN_INFO "PCI: Using BIOS for IRQ routing\n"); |
| 846 | r->set = pirq_bios_set; |
| 847 | r->name = "BIOS"; |
| 848 | return; |
| 849 | } |
| 850 | #endif |
| 851 | |
| 852 | /* Default unless a driver reloads it */ |
| 853 | r->name = "default"; |
| 854 | r->get = NULL; |
| 855 | r->set = NULL; |
Miklos Vajna | 273c112 | 2008-05-13 18:38:56 +0200 | [diff] [blame^] | 856 | |
Daniel Marjamäki | 8174551 | 2005-12-01 18:01:28 +0100 | [diff] [blame] | 857 | DBG(KERN_DEBUG "PCI: Attempting to find IRQ router for %04x:%04x\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 858 | rt->rtr_vendor, rt->rtr_device); |
| 859 | |
Alan Cox | 7cd8b68 | 2006-12-07 02:14:03 +0100 | [diff] [blame] | 860 | pirq_router_dev = pci_get_bus_and_slot(rt->rtr_bus, rt->rtr_devfn); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 861 | if (!pirq_router_dev) { |
Daniel Marjamäki | 8174551 | 2005-12-01 18:01:28 +0100 | [diff] [blame] | 862 | DBG(KERN_DEBUG "PCI: Interrupt router not found at " |
| 863 | "%02x:%02x\n", rt->rtr_bus, rt->rtr_devfn); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 864 | return; |
| 865 | } |
| 866 | |
Miklos Vajna | 273c112 | 2008-05-13 18:38:56 +0200 | [diff] [blame^] | 867 | for (h = pirq_routers; h->vendor; h++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 868 | /* First look for a router match */ |
Miklos Vajna | 273c112 | 2008-05-13 18:38:56 +0200 | [diff] [blame^] | 869 | if (rt->rtr_vendor == h->vendor && |
| 870 | h->probe(r, pirq_router_dev, rt->rtr_device)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 871 | break; |
| 872 | /* Fall back to a device match */ |
Miklos Vajna | 273c112 | 2008-05-13 18:38:56 +0200 | [diff] [blame^] | 873 | if (pirq_router_dev->vendor == h->vendor && |
| 874 | h->probe(r, pirq_router_dev, pirq_router_dev->device)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 875 | break; |
| 876 | } |
| 877 | printk(KERN_INFO "PCI: Using IRQ router %s [%04x/%04x] at %s\n", |
| 878 | pirq_router.name, |
| 879 | pirq_router_dev->vendor, |
| 880 | pirq_router_dev->device, |
| 881 | pci_name(pirq_router_dev)); |
Alan Cox | 7cd8b68 | 2006-12-07 02:14:03 +0100 | [diff] [blame] | 882 | |
| 883 | /* The device remains referenced for the kernel lifetime */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 884 | } |
| 885 | |
| 886 | static struct irq_info *pirq_get_info(struct pci_dev *dev) |
| 887 | { |
| 888 | struct irq_routing_table *rt = pirq_table; |
Miklos Vajna | 273c112 | 2008-05-13 18:38:56 +0200 | [diff] [blame^] | 889 | int entries = (rt->size - sizeof(struct irq_routing_table)) / |
| 890 | sizeof(struct irq_info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 891 | struct irq_info *info; |
| 892 | |
| 893 | for (info = rt->slots; entries--; info++) |
Miklos Vajna | 273c112 | 2008-05-13 18:38:56 +0200 | [diff] [blame^] | 894 | if (info->bus == dev->bus->number && |
| 895 | PCI_SLOT(info->devfn) == PCI_SLOT(dev->devfn)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 896 | return info; |
| 897 | return NULL; |
| 898 | } |
| 899 | |
| 900 | static int pcibios_lookup_irq(struct pci_dev *dev, int assign) |
| 901 | { |
| 902 | u8 pin; |
| 903 | struct irq_info *info; |
| 904 | int i, pirq, newirq; |
| 905 | int irq = 0; |
| 906 | u32 mask; |
| 907 | struct irq_router *r = &pirq_router; |
| 908 | struct pci_dev *dev2 = NULL; |
| 909 | char *msg = NULL; |
| 910 | |
| 911 | /* Find IRQ pin */ |
| 912 | pci_read_config_byte(dev, PCI_INTERRUPT_PIN, &pin); |
| 913 | if (!pin) { |
Daniel Marjamäki | 8174551 | 2005-12-01 18:01:28 +0100 | [diff] [blame] | 914 | DBG(KERN_DEBUG " -> no interrupt pin\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 915 | return 0; |
| 916 | } |
| 917 | pin = pin - 1; |
| 918 | |
| 919 | /* Find IRQ routing entry */ |
| 920 | |
| 921 | if (!pirq_table) |
| 922 | return 0; |
Miklos Vajna | 273c112 | 2008-05-13 18:38:56 +0200 | [diff] [blame^] | 923 | |
Daniel Marjamäki | 8174551 | 2005-12-01 18:01:28 +0100 | [diff] [blame] | 924 | DBG(KERN_DEBUG "IRQ for %s[%c]", pci_name(dev), 'A' + pin); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 925 | info = pirq_get_info(dev); |
| 926 | if (!info) { |
Daniel Marjamäki | 8174551 | 2005-12-01 18:01:28 +0100 | [diff] [blame] | 927 | DBG(" -> not found in routing table\n" KERN_DEBUG); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 928 | return 0; |
| 929 | } |
| 930 | pirq = info->irq[pin].link; |
| 931 | mask = info->irq[pin].bitmap; |
| 932 | if (!pirq) { |
Daniel Marjamäki | 8174551 | 2005-12-01 18:01:28 +0100 | [diff] [blame] | 933 | DBG(" -> not routed\n" KERN_DEBUG); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 934 | return 0; |
| 935 | } |
Miklos Vajna | 273c112 | 2008-05-13 18:38:56 +0200 | [diff] [blame^] | 936 | DBG(" -> PIRQ %02x, mask %04x, excl %04x", pirq, mask, |
| 937 | pirq_table->exclusive_irqs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 938 | mask &= pcibios_irq_mask; |
| 939 | |
| 940 | /* Work around broken HP Pavilion Notebooks which assign USB to |
| 941 | IRQ 9 even though it is actually wired to IRQ 11 */ |
| 942 | |
| 943 | if (broken_hp_bios_irq9 && pirq == 0x59 && dev->irq == 9) { |
| 944 | dev->irq = 11; |
| 945 | pci_write_config_byte(dev, PCI_INTERRUPT_LINE, 11); |
| 946 | r->set(pirq_router_dev, dev, pirq, 11); |
| 947 | } |
| 948 | |
| 949 | /* same for Acer Travelmate 360, but with CB and irq 11 -> 10 */ |
Miklos Vajna | 273c112 | 2008-05-13 18:38:56 +0200 | [diff] [blame^] | 950 | if (acer_tm360_irqrouting && dev->irq == 11 && |
| 951 | dev->vendor == PCI_VENDOR_ID_O2) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 952 | pirq = 0x68; |
| 953 | mask = 0x400; |
| 954 | dev->irq = r->get(pirq_router_dev, dev, pirq); |
| 955 | pci_write_config_byte(dev, PCI_INTERRUPT_LINE, dev->irq); |
| 956 | } |
| 957 | |
| 958 | /* |
| 959 | * Find the best IRQ to assign: use the one |
| 960 | * reported by the device if possible. |
| 961 | */ |
| 962 | newirq = dev->irq; |
Linus Torvalds | 7ed40918 | 2006-01-06 08:43:16 -0800 | [diff] [blame] | 963 | if (newirq && !((1 << newirq) & mask)) { |
Miklos Vajna | 273c112 | 2008-05-13 18:38:56 +0200 | [diff] [blame^] | 964 | if (pci_probe & PCI_USE_PIRQ_MASK) |
| 965 | newirq = 0; |
| 966 | else |
| 967 | printk("\n" KERN_WARNING |
| 968 | "PCI: IRQ %i for device %s doesn't match PIRQ mask - try pci=usepirqmask\n" |
| 969 | KERN_DEBUG, newirq, |
| 970 | pci_name(dev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 971 | } |
| 972 | if (!newirq && assign) { |
| 973 | for (i = 0; i < 16; i++) { |
| 974 | if (!(mask & (1 << i))) |
| 975 | continue; |
Miklos Vajna | 273c112 | 2008-05-13 18:38:56 +0200 | [diff] [blame^] | 976 | if (pirq_penalty[i] < pirq_penalty[newirq] && |
| 977 | can_request_irq(i, IRQF_SHARED)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 978 | newirq = i; |
| 979 | } |
| 980 | } |
| 981 | DBG(" -> newirq=%d", newirq); |
| 982 | |
| 983 | /* Check if it is hardcoded */ |
| 984 | if ((pirq & 0xf0) == 0xf0) { |
| 985 | irq = pirq & 0xf; |
| 986 | DBG(" -> hardcoded IRQ %d\n", irq); |
| 987 | msg = "Hardcoded"; |
Miklos Vajna | 273c112 | 2008-05-13 18:38:56 +0200 | [diff] [blame^] | 988 | } else if (r->get && (irq = r->get(pirq_router_dev, dev, pirq)) && \ |
| 989 | ((!(pci_probe & PCI_USE_PIRQ_MASK)) || ((1 << irq) & mask))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 990 | DBG(" -> got IRQ %d\n", irq); |
| 991 | msg = "Found"; |
Linus Torvalds | afa024c | 2006-06-23 02:04:21 -0700 | [diff] [blame] | 992 | eisa_set_level_irq(irq); |
Miklos Vajna | 273c112 | 2008-05-13 18:38:56 +0200 | [diff] [blame^] | 993 | } else if (newirq && r->set && |
| 994 | (dev->class >> 8) != PCI_CLASS_DISPLAY_VGA) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 995 | DBG(" -> assigning IRQ %d", newirq); |
| 996 | if (r->set(pirq_router_dev, dev, pirq, newirq)) { |
| 997 | eisa_set_level_irq(newirq); |
| 998 | DBG(" ... OK\n"); |
| 999 | msg = "Assigned"; |
| 1000 | irq = newirq; |
| 1001 | } |
| 1002 | } |
| 1003 | |
| 1004 | if (!irq) { |
| 1005 | DBG(" ... failed\n"); |
| 1006 | if (newirq && mask == (1 << newirq)) { |
| 1007 | msg = "Guessed"; |
| 1008 | irq = newirq; |
| 1009 | } else |
| 1010 | return 0; |
| 1011 | } |
Miklos Vajna | 273c112 | 2008-05-13 18:38:56 +0200 | [diff] [blame^] | 1012 | printk(KERN_INFO "PCI: %s IRQ %d for device %s\n", msg, irq, |
| 1013 | pci_name(dev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1014 | |
| 1015 | /* Update IRQ for all devices with the same pirq value */ |
| 1016 | while ((dev2 = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, dev2)) != NULL) { |
| 1017 | pci_read_config_byte(dev2, PCI_INTERRUPT_PIN, &pin); |
| 1018 | if (!pin) |
| 1019 | continue; |
| 1020 | pin--; |
| 1021 | info = pirq_get_info(dev2); |
| 1022 | if (!info) |
| 1023 | continue; |
| 1024 | if (info->irq[pin].link == pirq) { |
Miklos Vajna | 273c112 | 2008-05-13 18:38:56 +0200 | [diff] [blame^] | 1025 | /* |
| 1026 | * We refuse to override the dev->irq |
| 1027 | * information. Give a warning! |
| 1028 | */ |
| 1029 | if (dev2->irq && dev2->irq != irq && \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1030 | (!(pci_probe & PCI_USE_PIRQ_MASK) || \ |
Miklos Vajna | 273c112 | 2008-05-13 18:38:56 +0200 | [diff] [blame^] | 1031 | ((1 << dev2->irq) & mask))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1032 | #ifndef CONFIG_PCI_MSI |
Miklos Vajna | 273c112 | 2008-05-13 18:38:56 +0200 | [diff] [blame^] | 1033 | printk(KERN_INFO |
| 1034 | "IRQ routing conflict for %s, have irq %d, want irq %d\n", |
| 1035 | pci_name(dev2), dev2->irq, irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1036 | #endif |
Miklos Vajna | 273c112 | 2008-05-13 18:38:56 +0200 | [diff] [blame^] | 1037 | continue; |
| 1038 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1039 | dev2->irq = irq; |
| 1040 | pirq_penalty[irq]++; |
| 1041 | if (dev != dev2) |
Miklos Vajna | 273c112 | 2008-05-13 18:38:56 +0200 | [diff] [blame^] | 1042 | printk(KERN_INFO |
| 1043 | "PCI: Sharing IRQ %d with %s\n", |
| 1044 | irq, pci_name(dev2)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1045 | } |
| 1046 | } |
| 1047 | return 1; |
| 1048 | } |
| 1049 | |
| 1050 | static void __init pcibios_fixup_irqs(void) |
| 1051 | { |
| 1052 | struct pci_dev *dev = NULL; |
| 1053 | u8 pin; |
| 1054 | |
Daniel Marjamäki | 8174551 | 2005-12-01 18:01:28 +0100 | [diff] [blame] | 1055 | DBG(KERN_DEBUG "PCI: IRQ fixup\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1056 | while ((dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, dev)) != NULL) { |
| 1057 | /* |
Miklos Vajna | 273c112 | 2008-05-13 18:38:56 +0200 | [diff] [blame^] | 1058 | * If the BIOS has set an out of range IRQ number, just |
| 1059 | * ignore it. Also keep track of which IRQ's are |
| 1060 | * already in use. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1061 | */ |
| 1062 | if (dev->irq >= 16) { |
Miklos Vajna | 273c112 | 2008-05-13 18:38:56 +0200 | [diff] [blame^] | 1063 | DBG(KERN_DEBUG "%s: ignoring bogus IRQ %d\n", |
| 1064 | pci_name(dev), dev->irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1065 | dev->irq = 0; |
| 1066 | } |
Miklos Vajna | 273c112 | 2008-05-13 18:38:56 +0200 | [diff] [blame^] | 1067 | /* |
| 1068 | * If the IRQ is already assigned to a PCI device, |
| 1069 | * ignore its ISA use penalty |
| 1070 | */ |
| 1071 | if (pirq_penalty[dev->irq] >= 100 && |
| 1072 | pirq_penalty[dev->irq] < 100000) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1073 | pirq_penalty[dev->irq] = 0; |
| 1074 | pirq_penalty[dev->irq]++; |
| 1075 | } |
| 1076 | |
| 1077 | dev = NULL; |
| 1078 | while ((dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, dev)) != NULL) { |
| 1079 | pci_read_config_byte(dev, PCI_INTERRUPT_PIN, &pin); |
| 1080 | #ifdef CONFIG_X86_IO_APIC |
| 1081 | /* |
| 1082 | * Recalculate IRQ numbers if we use the I/O APIC. |
| 1083 | */ |
Miklos Vajna | 273c112 | 2008-05-13 18:38:56 +0200 | [diff] [blame^] | 1084 | if (io_apic_assign_pci_irqs) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1085 | int irq; |
| 1086 | |
| 1087 | if (pin) { |
Miklos Vajna | 273c112 | 2008-05-13 18:38:56 +0200 | [diff] [blame^] | 1088 | /* |
| 1089 | * interrupt pins are numbered starting |
| 1090 | * from 1 |
| 1091 | */ |
| 1092 | pin--; |
| 1093 | irq = IO_APIC_get_PCI_irq_vector(dev->bus->number, |
| 1094 | PCI_SLOT(dev->devfn), pin); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1095 | /* |
| 1096 | * Busses behind bridges are typically not listed in the MP-table. |
| 1097 | * In this case we have to look up the IRQ based on the parent bus, |
| 1098 | * parent slot, and pin number. The SMP code detects such bridged |
| 1099 | * busses itself so we should get into this branch reliably. |
| 1100 | */ |
Miklos Vajna | 273c112 | 2008-05-13 18:38:56 +0200 | [diff] [blame^] | 1101 | if (irq < 0 && dev->bus->parent) { |
| 1102 | /* go back to the bridge */ |
| 1103 | struct pci_dev *bridge = dev->bus->self; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1104 | |
| 1105 | pin = (pin + PCI_SLOT(dev->devfn)) % 4; |
Miklos Vajna | 273c112 | 2008-05-13 18:38:56 +0200 | [diff] [blame^] | 1106 | irq = IO_APIC_get_PCI_irq_vector(bridge->bus->number, |
| 1107 | PCI_SLOT(bridge->devfn), |
| 1108 | pin); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1109 | if (irq >= 0) |
Miklos Vajna | 273c112 | 2008-05-13 18:38:56 +0200 | [diff] [blame^] | 1110 | printk(KERN_WARNING |
| 1111 | "PCI: using PPB %s[%c] to get irq %d\n", |
| 1112 | pci_name(bridge), |
| 1113 | 'A' + pin, irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1114 | } |
| 1115 | if (irq >= 0) { |
Miklos Vajna | 273c112 | 2008-05-13 18:38:56 +0200 | [diff] [blame^] | 1116 | printk(KERN_INFO |
| 1117 | "PCI->APIC IRQ transform: %s[%c] -> IRQ %d\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1118 | pci_name(dev), 'A' + pin, irq); |
| 1119 | dev->irq = irq; |
| 1120 | } |
| 1121 | } |
| 1122 | } |
| 1123 | #endif |
| 1124 | /* |
| 1125 | * Still no IRQ? Try to lookup one... |
| 1126 | */ |
| 1127 | if (pin && !dev->irq) |
| 1128 | pcibios_lookup_irq(dev, 0); |
| 1129 | } |
| 1130 | } |
| 1131 | |
| 1132 | /* |
| 1133 | * Work around broken HP Pavilion Notebooks which assign USB to |
| 1134 | * IRQ 9 even though it is actually wired to IRQ 11 |
| 1135 | */ |
Jeff Garzik | 1855256 | 2007-10-03 15:15:40 -0400 | [diff] [blame] | 1136 | static int __init fix_broken_hp_bios_irq9(const struct dmi_system_id *d) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1137 | { |
| 1138 | if (!broken_hp_bios_irq9) { |
| 1139 | broken_hp_bios_irq9 = 1; |
Miklos Vajna | 273c112 | 2008-05-13 18:38:56 +0200 | [diff] [blame^] | 1140 | printk(KERN_INFO "%s detected - fixing broken IRQ routing\n", |
| 1141 | d->ident); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1142 | } |
| 1143 | return 0; |
| 1144 | } |
| 1145 | |
| 1146 | /* |
| 1147 | * Work around broken Acer TravelMate 360 Notebooks which assign |
| 1148 | * Cardbus to IRQ 11 even though it is actually wired to IRQ 10 |
| 1149 | */ |
Jeff Garzik | 1855256 | 2007-10-03 15:15:40 -0400 | [diff] [blame] | 1150 | static int __init fix_acer_tm360_irqrouting(const struct dmi_system_id *d) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1151 | { |
| 1152 | if (!acer_tm360_irqrouting) { |
| 1153 | acer_tm360_irqrouting = 1; |
Miklos Vajna | 273c112 | 2008-05-13 18:38:56 +0200 | [diff] [blame^] | 1154 | printk(KERN_INFO "%s detected - fixing broken IRQ routing\n", |
| 1155 | d->ident); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1156 | } |
| 1157 | return 0; |
| 1158 | } |
| 1159 | |
| 1160 | static struct dmi_system_id __initdata pciirq_dmi_table[] = { |
| 1161 | { |
| 1162 | .callback = fix_broken_hp_bios_irq9, |
| 1163 | .ident = "HP Pavilion N5400 Series Laptop", |
| 1164 | .matches = { |
| 1165 | DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"), |
| 1166 | DMI_MATCH(DMI_BIOS_VERSION, "GE.M1.03"), |
Miklos Vajna | 273c112 | 2008-05-13 18:38:56 +0200 | [diff] [blame^] | 1167 | DMI_MATCH(DMI_PRODUCT_VERSION, |
| 1168 | "HP Pavilion Notebook Model GE"), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1169 | DMI_MATCH(DMI_BOARD_VERSION, "OmniBook N32N-736"), |
| 1170 | }, |
| 1171 | }, |
| 1172 | { |
| 1173 | .callback = fix_acer_tm360_irqrouting, |
| 1174 | .ident = "Acer TravelMate 36x Laptop", |
| 1175 | .matches = { |
| 1176 | DMI_MATCH(DMI_SYS_VENDOR, "Acer"), |
| 1177 | DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 360"), |
| 1178 | }, |
| 1179 | }, |
| 1180 | { } |
| 1181 | }; |
| 1182 | |
| 1183 | static int __init pcibios_irq_init(void) |
| 1184 | { |
Daniel Marjamäki | 8174551 | 2005-12-01 18:01:28 +0100 | [diff] [blame] | 1185 | DBG(KERN_DEBUG "PCI: IRQ init\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1186 | |
| 1187 | if (pcibios_enable_irq || raw_pci_ops == NULL) |
| 1188 | return 0; |
| 1189 | |
| 1190 | dmi_check_system(pciirq_dmi_table); |
| 1191 | |
| 1192 | pirq_table = pirq_find_routing_table(); |
| 1193 | |
| 1194 | #ifdef CONFIG_PCI_BIOS |
| 1195 | if (!pirq_table && (pci_probe & PCI_BIOS_IRQ_SCAN)) |
| 1196 | pirq_table = pcibios_get_irq_routing_table(); |
| 1197 | #endif |
| 1198 | if (pirq_table) { |
| 1199 | pirq_peer_trick(); |
| 1200 | pirq_find_router(&pirq_router); |
| 1201 | if (pirq_table->exclusive_irqs) { |
| 1202 | int i; |
Miklos Vajna | 273c112 | 2008-05-13 18:38:56 +0200 | [diff] [blame^] | 1203 | for (i = 0; i < 16; i++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1204 | if (!(pirq_table->exclusive_irqs & (1 << i))) |
| 1205 | pirq_penalty[i] += 100; |
| 1206 | } |
Miklos Vajna | 273c112 | 2008-05-13 18:38:56 +0200 | [diff] [blame^] | 1207 | /* |
| 1208 | * If we're using the I/O APIC, avoid using the PCI IRQ |
| 1209 | * routing table |
| 1210 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1211 | if (io_apic_assign_pci_irqs) |
| 1212 | pirq_table = NULL; |
| 1213 | } |
| 1214 | |
| 1215 | pcibios_enable_irq = pirq_enable_irq; |
| 1216 | |
| 1217 | pcibios_fixup_irqs(); |
| 1218 | return 0; |
| 1219 | } |
| 1220 | |
| 1221 | subsys_initcall(pcibios_irq_init); |
| 1222 | |
| 1223 | |
David Shaohua Li | c9c3e45 | 2005-04-01 00:07:31 -0500 | [diff] [blame] | 1224 | static void pirq_penalize_isa_irq(int irq, int active) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1225 | { |
| 1226 | /* |
| 1227 | * If any ISAPnP device reports an IRQ in its list of possible |
| 1228 | * IRQ's, we try to avoid assigning it to PCI devices. |
| 1229 | */ |
David Shaohua Li | c9c3e45 | 2005-04-01 00:07:31 -0500 | [diff] [blame] | 1230 | if (irq < 16) { |
| 1231 | if (active) |
| 1232 | pirq_penalty[irq] += 1000; |
| 1233 | else |
| 1234 | pirq_penalty[irq] += 100; |
| 1235 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1236 | } |
| 1237 | |
David Shaohua Li | c9c3e45 | 2005-04-01 00:07:31 -0500 | [diff] [blame] | 1238 | void pcibios_penalize_isa_irq(int irq, int active) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1239 | { |
Len Brown | 6153df7b | 2005-08-25 12:27:09 -0400 | [diff] [blame] | 1240 | #ifdef CONFIG_ACPI |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1241 | if (!acpi_noirq) |
David Shaohua Li | c9c3e45 | 2005-04-01 00:07:31 -0500 | [diff] [blame] | 1242 | acpi_penalize_isa_irq(irq, active); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1243 | else |
| 1244 | #endif |
David Shaohua Li | c9c3e45 | 2005-04-01 00:07:31 -0500 | [diff] [blame] | 1245 | pirq_penalize_isa_irq(irq, active); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1246 | } |
| 1247 | |
| 1248 | static int pirq_enable_irq(struct pci_dev *dev) |
| 1249 | { |
| 1250 | u8 pin; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1251 | struct pci_dev *temp_dev; |
| 1252 | |
| 1253 | pci_read_config_byte(dev, PCI_INTERRUPT_PIN, &pin); |
| 1254 | if (pin && !pcibios_lookup_irq(dev, 1) && !dev->irq) { |
| 1255 | char *msg = ""; |
| 1256 | |
Miklos Vajna | 273c112 | 2008-05-13 18:38:56 +0200 | [diff] [blame^] | 1257 | pin--; /* interrupt pins are numbered starting from 1 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1258 | |
| 1259 | if (io_apic_assign_pci_irqs) { |
| 1260 | int irq; |
| 1261 | |
Miklos Vajna | 273c112 | 2008-05-13 18:38:56 +0200 | [diff] [blame^] | 1262 | irq = IO_APIC_get_PCI_irq_vector(dev->bus->number, |
| 1263 | PCI_SLOT(dev->devfn), pin); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1264 | /* |
Miklos Vajna | 273c112 | 2008-05-13 18:38:56 +0200 | [diff] [blame^] | 1265 | * Busses behind bridges are typically not |
| 1266 | * listed in the MP-table. In this case we have |
| 1267 | * to look up the IRQ based on the parent bus, |
| 1268 | * parent slot, and pin number. The SMP code |
| 1269 | * detects such bridged busses itself so we |
| 1270 | * should get into this branch reliably. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1271 | */ |
| 1272 | temp_dev = dev; |
Miklos Vajna | 273c112 | 2008-05-13 18:38:56 +0200 | [diff] [blame^] | 1273 | while (irq < 0 && dev->bus->parent) { |
| 1274 | /* go back to the bridge */ |
| 1275 | struct pci_dev *bridge = dev->bus->self; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1276 | |
| 1277 | pin = (pin + PCI_SLOT(dev->devfn)) % 4; |
Miklos Vajna | 273c112 | 2008-05-13 18:38:56 +0200 | [diff] [blame^] | 1278 | irq = IO_APIC_get_PCI_irq_vector(bridge->bus->number, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1279 | PCI_SLOT(bridge->devfn), pin); |
| 1280 | if (irq >= 0) |
Miklos Vajna | 273c112 | 2008-05-13 18:38:56 +0200 | [diff] [blame^] | 1281 | printk(KERN_WARNING |
| 1282 | "PCI: using PPB %s[%c] to get irq %d\n", |
| 1283 | pci_name(bridge), |
| 1284 | 'A' + pin, irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1285 | dev = bridge; |
| 1286 | } |
| 1287 | dev = temp_dev; |
| 1288 | if (irq >= 0) { |
Miklos Vajna | 273c112 | 2008-05-13 18:38:56 +0200 | [diff] [blame^] | 1289 | printk(KERN_INFO |
| 1290 | "PCI->APIC IRQ transform: %s[%c] -> IRQ %d\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1291 | pci_name(dev), 'A' + pin, irq); |
| 1292 | dev->irq = irq; |
| 1293 | return 0; |
| 1294 | } else |
| 1295 | msg = " Probably buggy MP table."; |
| 1296 | } else if (pci_probe & PCI_BIOS_IRQ_SCAN) |
| 1297 | msg = ""; |
| 1298 | else |
| 1299 | msg = " Please try using pci=biosirq."; |
| 1300 | |
Miklos Vajna | 273c112 | 2008-05-13 18:38:56 +0200 | [diff] [blame^] | 1301 | /* |
| 1302 | * With IDE legacy devices the IRQ lookup failure is not |
| 1303 | * a problem.. |
| 1304 | */ |
| 1305 | if (dev->class >> 8 == PCI_CLASS_STORAGE_IDE && |
| 1306 | !(dev->class & 0x5)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1307 | return 0; |
| 1308 | |
Miklos Vajna | 273c112 | 2008-05-13 18:38:56 +0200 | [diff] [blame^] | 1309 | printk(KERN_WARNING |
| 1310 | "PCI: No IRQ known for interrupt pin %c of device %s.%s\n", |
| 1311 | 'A' + pin, pci_name(dev), msg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1312 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1313 | return 0; |
| 1314 | } |