7 #include <linux/types.h>
8 #include <linux/kernel.h>
20 #define PIRQ_SIGNATURE (('$' << 0) + ('P' << 8) + ('I' << 16) + ('R' << 24))
21 #define PIRQ_VERSION 0x0100
23 static int broken_hp_bios_irq9;
24 static int acer_tm360_irqrouting;
28 static int pirq_enable_irq(
struct pci_dev *
dev);
37 static int pirq_penalty[16] = {
38 1000000, 1000000, 1000000, 1000, 1000, 0, 1000, 1000,
39 0, 0, 0, 0, 1000, 100000, 100000, 100000
76 for (i = 0; i < rt->
size; i++)
79 DBG(
KERN_DEBUG "PCI: Interrupt Routing Table found at 0x%p\n",
103 for (addr = (
u8 *)
__va(0xf0000); addr < (
u8 *)
__va(0x100000); addr += 16) {
104 rt = pirq_check_routing_table(addr);
117 static void __init pirq_peer_trick(
void)
124 memset(busmap, 0,
sizeof(busmap));
131 for (j = 0; j < 4; j++)
132 DBG(
" %d:%02x/%04x", j, e->
irq[j].link, e->
irq[j].bitmap);
138 for (i = 1; i < 256; i++) {
142 node = get_mp_bus_to_node(i);
145 "bus %02x [IRQ]\n", i);
156 unsigned char mask = 1 << (irq & 7);
157 unsigned int port = 0x4d0 + (irq >> 3);
159 static u16 eisa_irq_mask;
161 if (irq >= 16 || (1 << irq) & eisa_irq_mask)
164 eisa_irq_mask |= (1 << irq);
169 outb(val | mask, port);
177 static unsigned int read_config_nybble(
struct pci_dev *router,
unsigned offset,
unsigned nr)
180 unsigned reg = offset + (nr >> 1);
182 pci_read_config_byte(router, reg, &x);
183 return (nr & 1) ? (x >> 4) : (x & 0xf);
186 static void write_config_nybble(
struct pci_dev *router,
unsigned offset,
187 unsigned nr,
unsigned int val)
190 unsigned reg = offset + (nr >> 1);
192 pci_read_config_byte(router, reg, &x);
193 x = (nr & 1) ? ((x & 0x0f) | (val << 4)) : ((x & 0xf0) | val);
194 pci_write_config_byte(router, reg, x);
204 static const unsigned char irqmap[16] = { 0, 9, 3, 10, 4, 5, 7, 6, 1, 11, 0, 12, 0, 14, 0, 15 };
207 return irqmap[read_config_nybble(router, 0x48, pirq-1)];
210 static int pirq_ali_set(
struct pci_dev *router,
struct pci_dev *
dev,
int pirq,
int irq)
212 static const unsigned char irqmap[16] = { 0, 8, 0, 2, 4, 5, 7, 6, 0, 1, 3, 9, 11, 0, 13, 15 };
213 unsigned int val = irqmap[irq];
217 write_config_nybble(router, 0x48, pirq-1, val);
227 static int pirq_piix_get(
struct pci_dev *router,
struct pci_dev *dev,
int pirq)
231 pci_read_config_byte(router, pirq, &x);
232 return (x < 16) ? x : 0;
235 static int pirq_piix_set(
struct pci_dev *router,
struct pci_dev *dev,
int pirq,
int irq)
237 pci_write_config_byte(router, pirq, irq);
246 static int pirq_via_get(
struct pci_dev *router,
struct pci_dev *dev,
int pirq)
248 return read_config_nybble(router, 0x55, pirq == 4 ? 5 : pirq);
251 static int pirq_via_set(
struct pci_dev *router,
struct pci_dev *dev,
int pirq,
int irq)
253 write_config_nybble(router, 0x55, pirq == 4 ? 5 : pirq, irq);
262 static int pirq_via586_get(
struct pci_dev *router,
struct pci_dev *dev,
int pirq)
264 static const unsigned int pirqmap[5] = { 3, 2, 5, 1, 1 };
267 return read_config_nybble(router, 0x55, pirqmap[pirq-1]);
270 static int pirq_via586_set(
struct pci_dev *router,
struct pci_dev *dev,
int pirq,
int irq)
272 static const unsigned int pirqmap[5] = { 3, 2, 5, 1, 1 };
275 write_config_nybble(router, 0x55, pirqmap[pirq-1], irq);
284 static int pirq_ite_get(
struct pci_dev *router,
struct pci_dev *dev,
int pirq)
286 static const unsigned char pirqmap[4] = { 1, 0, 2, 3 };
289 return read_config_nybble(router, 0x43, pirqmap[pirq-1]);
292 static int pirq_ite_set(
struct pci_dev *router,
struct pci_dev *dev,
int pirq,
int irq)
294 static const unsigned char pirqmap[4] = { 1, 0, 2, 3 };
297 write_config_nybble(router, 0x43, pirqmap[pirq-1], irq);
305 static int pirq_opti_get(
struct pci_dev *router,
struct pci_dev *dev,
int pirq)
307 return read_config_nybble(router, 0xb8, pirq >> 4);
310 static int pirq_opti_set(
struct pci_dev *router,
struct pci_dev *dev,
int pirq,
int irq)
312 write_config_nybble(router, 0xb8, pirq >> 4, irq);
321 static int pirq_cyrix_get(
struct pci_dev *router,
struct pci_dev *dev,
int pirq)
323 return read_config_nybble(router, 0x5C, (pirq-1)^1);
326 static int pirq_cyrix_set(
struct pci_dev *router,
struct pci_dev *dev,
int pirq,
int irq)
328 write_config_nybble(router, 0x5C, (pirq-1)^1, irq);
393 #define PIRQ_SIS_IRQ_MASK 0x0f
394 #define PIRQ_SIS_IRQ_DISABLE 0x80
395 #define PIRQ_SIS_USB_ENABLE 0x40
397 static int pirq_sis_get(
struct pci_dev *router,
struct pci_dev *dev,
int pirq)
403 if (reg >= 0x01 && reg <= 0x04)
405 pci_read_config_byte(router, reg, &x);
409 static int pirq_sis_set(
struct pci_dev *router,
struct pci_dev *dev,
int pirq,
int irq)
415 if (reg >= 0x01 && reg <= 0x04)
417 pci_read_config_byte(router, reg, &x);
420 pci_write_config_byte(router, reg, x);
433 static int pirq_vlsi_get(
struct pci_dev *router,
struct pci_dev *dev,
int pirq)
437 dev_info(&dev->
dev,
"VLSI router PIRQ escape (%d)\n", pirq);
440 return read_config_nybble(router, 0x74, pirq-1);
443 static int pirq_vlsi_set(
struct pci_dev *router,
struct pci_dev *dev,
int pirq,
int irq)
447 dev_info(&dev->
dev,
"VLSI router PIRQ escape (%d)\n", pirq);
450 write_config_nybble(router, 0x74, pirq-1, irq);
465 static int pirq_serverworks_get(
struct pci_dev *router,
struct pci_dev *dev,
int pirq)
468 return inb(0xc01) & 0xf;
471 static int pirq_serverworks_set(
struct pci_dev *router,
struct pci_dev *dev,
487 static int pirq_amd756_get(
struct pci_dev *router,
struct pci_dev *dev,
int pirq)
492 irq = read_config_nybble(router, 0x56, pirq - 1);
494 "AMD756: dev [%04x:%04x], router PIRQ %d get IRQ %d\n",
499 static int pirq_amd756_set(
struct pci_dev *router,
struct pci_dev *dev,
int pirq,
int irq)
502 "AMD756: dev [%04x:%04x], router PIRQ %d set IRQ %d\n",
505 write_config_nybble(router, 0x56, pirq - 1, irq);
512 static int pirq_pico_get(
struct pci_dev *router,
struct pci_dev *dev,
int pirq)
514 outb(0x10 + ((pirq - 1) >> 1), 0x24);
515 return ((pirq - 1) & 1) ? (
inb(0x26) >> 4) : (
inb(0x26) & 0xf);
518 static int pirq_pico_set(
struct pci_dev *router,
struct pci_dev *dev,
int pirq,
522 outb(0x10 + ((pirq - 1) >> 1), 0x24);
524 x = ((pirq - 1) & 1) ? ((x & 0x0f) | (irq << 4)) : ((x & 0xf0) | (irq));
529 #ifdef CONFIG_PCI_BIOS
531 static int pirq_bios_set(
struct pci_dev *router,
struct pci_dev *dev,
int pirq,
int irq)
594 r->
name =
"PIIX/ICH";
595 r->
get = pirq_piix_get;
596 r->
set = pirq_piix_set;
608 r->
name =
"PIIX/ICH";
609 r->
get = pirq_piix_get;
610 r->
set = pirq_piix_set;
654 r->
get = pirq_via586_get;
655 r->
set = pirq_via586_set;
665 r->
get = pirq_via_get;
666 r->
set = pirq_via_set;
676 r->
name =
"VLSI 82C534";
677 r->
get = pirq_vlsi_get;
678 r->
set = pirq_vlsi_set;
691 r->
name =
"ServerWorks";
692 r->
get = pirq_serverworks_get;
693 r->
set = pirq_serverworks_set;
705 r->
get = pirq_sis_get;
706 r->
set = pirq_sis_set;
715 r->
get = pirq_cyrix_get;
716 r->
set = pirq_cyrix_set;
727 r->
get = pirq_opti_get;
728 r->
set = pirq_opti_set;
739 r->
get = pirq_ite_get;
740 r->
set = pirq_ite_set;
752 r->
get = pirq_ali_get;
753 r->
set = pirq_ali_set;
774 r->
get = pirq_amd756_get;
775 r->
set = pirq_amd756_set;
783 r->
name =
"PicoPower PT86C523";
784 r->
get = pirq_pico_get;
785 r->
set = pirq_pico_set;
789 r->
name =
"PicoPower PT86C523 rev. BB+";
790 r->
get = pirq_pico_get;
791 r->
set = pirq_pico_set;
813 static struct pci_dev *pirq_router_dev;
826 #ifdef CONFIG_PCI_BIOS
829 r->
set = pirq_bios_set;
840 DBG(
KERN_DEBUG "PCI: Attempting to find IRQ router for [%04x:%04x]\n",
844 if (!pirq_router_dev) {
850 for (h = pirq_routers; h->
vendor; h++) {
857 h->
probe(r, pirq_router_dev, pirq_router_dev->
device))
860 dev_info(&pirq_router_dev->
dev,
"%s IRQ router [%04x:%04x]\n",
874 for (info = rt->
slots; entries--; info++)
875 if (info->
bus == dev->
bus->number &&
881 static int pcibios_lookup_irq(
struct pci_dev *dev,
int assign)
907 info = pirq_get_info(dev);
909 dev_dbg(&dev->
dev,
"PCI INT %c not found in routing table\n",
913 pirq = info->
irq[pin - 1].link;
914 mask = info->
irq[pin - 1].bitmap;
916 dev_dbg(&dev->
dev,
"PCI INT %c not routed\n",
'A' + pin - 1);
919 dev_dbg(&dev->
dev,
"PCI INT %c -> PIRQ %02x, mask %04x, excl %04x",
926 if (broken_hp_bios_irq9 && pirq == 0x59 && dev->
irq == 9) {
929 r->
set(pirq_router_dev, dev, pirq, 11);
933 if (acer_tm360_irqrouting && dev->
irq == 11 &&
937 dev->
irq = r->
get(pirq_router_dev, dev, pirq);
946 if (newirq && !((1 << newirq) & mask)) {
950 dev_warn(&dev->
dev,
"IRQ %d doesn't match PIRQ mask "
951 "%#x; try pci=usepirqmask\n", newirq, mask);
953 if (!newirq && assign) {
954 for (i = 0; i < 16; i++) {
955 if (!(mask & (1 << i)))
957 if (pirq_penalty[i] < pirq_penalty[newirq] &&
962 dev_dbg(&dev->
dev,
"PCI INT %c -> newirq %d",
'A' + pin - 1, newirq);
965 if ((pirq & 0xf0) == 0xf0) {
968 }
else if (r->
get && (irq = r->
get(pirq_router_dev, dev, pirq)) && \
972 }
else if (newirq && r->
set &&
974 if (r->
set(pirq_router_dev, dev, pirq, newirq)) {
982 if (newirq && mask == (1 << newirq)) {
986 dev_dbg(&dev->
dev,
"can't route interrupt\n");
990 dev_info(&dev->
dev,
"%s PCI INT %c -> IRQ %d\n", msg,
'A' + pin - 1, irq);
998 info = pirq_get_info(dev2);
1001 if (info->
irq[pin - 1].link == pirq) {
1006 if (dev2->
irq && dev2->
irq != irq && \
1008 ((1 << dev2->
irq) & mask))) {
1009 #ifndef CONFIG_PCI_MSI
1011 "have IRQ %d, want IRQ %d\n",
1017 pirq_penalty[
irq]++;
1020 irq, pci_name(dev2));
1038 if (dev->
irq >= 16) {
1046 if (pirq_penalty[dev->
irq] >= 100 &&
1047 pirq_penalty[dev->
irq] < 100000)
1048 pirq_penalty[dev->
irq] = 0;
1049 pirq_penalty[dev->
irq]++;
1065 pcibios_lookup_irq(dev, 0);
1075 if (!broken_hp_bios_irq9) {
1076 broken_hp_bios_irq9 = 1;
1089 if (!acer_tm360_irqrouting) {
1090 acer_tm360_irqrouting = 1;
1099 .callback = fix_broken_hp_bios_irq9,
1100 .ident =
"HP Pavilion N5400 Series Laptop",
1105 "HP Pavilion Notebook Model GE"),
1110 .callback = fix_acer_tm360_irqrouting,
1111 .ident =
"Acer TravelMate 36x Laptop",
1129 pirq_table = pirq_find_routing_table();
1131 #ifdef CONFIG_PCI_BIOS
1137 pirq_find_router(&pirq_router);
1140 for (i = 0; i < 16; i++)
1142 pirq_penalty[
i] += 100;
1161 printk(
KERN_INFO "PCI: Routing PCI interrupts for all devices because \"pci=routeirq\" specified\n");
1163 pirq_enable_irq(dev);
1167 static void pirq_penalize_isa_irq(
int irq,
int active)
1175 pirq_penalty[
irq] += 1000;
1177 pirq_penalty[
irq] += 100;
1188 pirq_penalize_isa_irq(irq, active);
1191 static int pirq_enable_irq(
struct pci_dev *dev)
1196 if (pin && !pcibios_lookup_irq(dev, 1)) {
1203 #ifdef CONFIG_X86_IO_APIC
1210 pin - 1, &irq_attr);
1218 while (irq < 0 && dev->
bus->parent) {
1224 pin - 1, &irq_attr);
1227 "INT %c to get IRQ %d\n",
1228 pci_name(bridge),
'A' + pin - 1,
1238 "INT %c -> IRQ %d\n",
'A' + pin - 1, irq);
1241 msg =
"; probably buggy MP table";
1246 msg =
"; please try using pci=biosirq";
1253 !(dev->
class & 0x5))
1256 dev_warn(&dev->
dev,
"can't find IRQ for PCI INT %c%s\n",
1257 'A' + pin - 1, msg);