]> git.hungrycats.org Git - linux/commitdiff
Merge penguin.transmeta.com:/home/penguin/torvalds/repositories/kernel/linux-2.5-pci
authorLinus Torvalds <torvalds@penguin.transmeta.com>
Wed, 8 May 2002 09:10:48 +0000 (02:10 -0700)
committerLinus Torvalds <torvalds@home.transmeta.com>
Wed, 8 May 2002 09:10:48 +0000 (02:10 -0700)
into penguin.transmeta.com:/home/penguin/torvalds/repositories/kernel/linux

1  2 
Makefile
arch/i386/kernel/Makefile
arch/i386/pci/fixup.c
arch/i386/pci/i386.c
arch/i386/pci/irq.c

diff --cc Makefile
index 1700158acd2a0818d37fddbe5c0cd99032e5bb32,a5cc0f55672424acb38d396dce03233d4a40ca35..28492b77d60fa5216ca614ae4bb5196a7f7279fd
+++ b/Makefile
@@@ -150,9 -158,12 +151,8 @@@ DRIVERS-y += drivers/cdrom/driver.
  endif
  
  DRIVERS-$(CONFIG_SOUND) += sound/sound.o
- DRIVERS-$(CONFIG_PCI) += drivers/pci/driver.o
  DRIVERS-$(CONFIG_MTD) += drivers/mtd/mtdlink.o
  DRIVERS-$(CONFIG_PCMCIA) += drivers/pcmcia/pcmcia.o
 -DRIVERS-$(CONFIG_NET_PCMCIA) += drivers/net/pcmcia/pcmcia_net.o
 -DRIVERS-$(CONFIG_NET_WIRELESS) += drivers/net/wireless/wireless_net.o
 -DRIVERS-$(CONFIG_NET_TULIP) += drivers/net/tulip/tulip_net.o
 -DRIVERS-$(CONFIG_PCMCIA_CHRDEV) += drivers/char/pcmcia/pcmcia_char.o
  DRIVERS-$(CONFIG_DIO) += drivers/dio/dio.a
  DRIVERS-$(CONFIG_SBUS) += drivers/sbus/sbus_all.o
  DRIVERS-$(CONFIG_ZORRO) += drivers/zorro/driver.o
index 0271fab4d583f1fdd857693aa1ee75b193767101,d1c3ad476f67415ffb5d05b60c7b43eaca4b2e23..0dc76663bff646aaa09db68aa641097a1c765796
@@@ -7,10 -7,10 +7,10 @@@
  #
  # Note 2! The CFLAGS definitions are now in the main makefile...
  
 -.S.o:
 -      $(CC) $(AFLAGS) -traditional -c $< -o $*.o
 +EXTRA_AFLAGS  := -traditional
 +USE_STANDARD_AS_RULE  := true
  
- all: first_rule kernel.o head.o init_task.o
+ all: kernel.o head.o init_task.o
  
  O_TARGET := kernel.o
  
index 0000000000000000000000000000000000000000,ca14f00c7abed1477c054b1cbbf1168b47886ab6..372f2f342a4fd74f6a5cd9f4310f0e858284f1a0
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,163 +1,183 @@@
 - * certain VIA Northbridges.  This bugfix is per VIA's specifications.
+ /*
+  * Exceptions for specific devices. Usually work-arounds for fatal design flaws.
+  */
+ #include <linux/pci.h>
+ #include "pci.h"
+ static void __devinit pci_fixup_i450nx(struct pci_dev *d)
+ {
+       /*
+        * i450NX -- Find and scan all secondary buses on all PXB's.
+        */
+       int pxb, reg;
+       u8 busno, suba, subb;
+       printk(KERN_WARNING "PCI: Searching for i450NX host bridges on %s\n", d->slot_name);
+       reg = 0xd0;
+       for(pxb=0; pxb<2; pxb++) {
+               pci_read_config_byte(d, reg++, &busno);
+               pci_read_config_byte(d, reg++, &suba);
+               pci_read_config_byte(d, reg++, &subb);
+               DBG("i450NX PXB %d: %02x/%02x/%02x\n", pxb, busno, suba, subb);
+               if (busno)
+                       pci_scan_bus(busno, pci_root_ops, NULL);        /* Bus A */
+               if (suba < subb)
+                       pci_scan_bus(suba+1, pci_root_ops, NULL);       /* Bus B */
+       }
+       pcibios_last_bus = -1;
+ }
+ static void __devinit pci_fixup_i450gx(struct pci_dev *d)
+ {
+       /*
+        * i450GX and i450KX -- Find and scan all secondary buses.
+        * (called separately for each PCI bridge found)
+        */
+       u8 busno;
+       pci_read_config_byte(d, 0x4a, &busno);
+       printk(KERN_INFO "PCI: i440KX/GX host bridge %s: secondary bus %02x\n", d->slot_name, busno);
+       pci_scan_bus(busno, pci_root_ops, NULL);
+       pcibios_last_bus = -1;
+ }
+ static void __devinit  pci_fixup_umc_ide(struct pci_dev *d)
+ {
+       /*
+        * UM8886BF IDE controller sets region type bits incorrectly,
+        * therefore they look like memory despite of them being I/O.
+        */
+       int i;
+       printk(KERN_WARNING "PCI: Fixing base address flags for device %s\n", d->slot_name);
+       for(i=0; i<4; i++)
+               d->resource[i].flags |= PCI_BASE_ADDRESS_SPACE_IO;
+ }
+ static void __devinit  pci_fixup_ncr53c810(struct pci_dev *d)
+ {
+       /*
+        * NCR 53C810 returns class code 0 (at least on some systems).
+        * Fix class to be PCI_CLASS_STORAGE_SCSI
+        */
+       if (!d->class) {
+               printk(KERN_WARNING "PCI: fixing NCR 53C810 class code for %s\n", d->slot_name);
+               d->class = PCI_CLASS_STORAGE_SCSI << 8;
+       }
+ }
+ static void __devinit pci_fixup_ide_bases(struct pci_dev *d)
+ {
+       int i;
+       /*
+        * PCI IDE controllers use non-standard I/O port decoding, respect it.
+        */
+       if ((d->class >> 8) != PCI_CLASS_STORAGE_IDE)
+               return;
+       DBG("PCI: IDE base address fixup for %s\n", d->slot_name);
+       for(i=0; i<4; i++) {
+               struct resource *r = &d->resource[i];
+               if ((r->start & ~0x80) == 0x374) {
+                       r->start |= 2;
+                       r->end = r->start;
+               }
+       }
+ }
+ static void __devinit  pci_fixup_ide_trash(struct pci_dev *d)
+ {
+       int i;
+       /*
+        * There exist PCI IDE controllers which have utter garbage
+        * in first four base registers. Ignore that.
+        */
+       DBG("PCI: IDE base address trash cleared for %s\n", d->slot_name);
+       for(i=0; i<4; i++)
+               d->resource[i].start = d->resource[i].end = d->resource[i].flags = 0;
+ }
+ static void __devinit  pci_fixup_latency(struct pci_dev *d)
+ {
+       /*
+        *  SiS 5597 and 5598 chipsets require latency timer set to
+        *  at most 32 to avoid lockups.
+        */
+       DBG("PCI: Setting max latency to 32\n");
+       pcibios_max_latency = 32;
+ }
+ static void __devinit pci_fixup_piix4_acpi(struct pci_dev *d)
+ {
+       /*
+        * PIIX4 ACPI device: hardwired IRQ9
+        */
+       d->irq = 9;
+ }
+ /*
+  * Addresses issues with problems in the memory write queue timer in
 -                                 different for the kt266x's: 0x95 not 0x55 */
++ * certain VIA Northbridges.  This bugfix is per VIA's specifications,
++ * except for the KL133/KM133: clearing bit 5 on those Northbridges seems
++ * to trigger a bug in its integrated ProSavage video card, which
++ * causes screen corruption.  We only clear bits 6 and 7 for that chipset,
++ * until VIA can provide us with definitive information on why screen
++ * corruption occurs, and what exactly those bits do.
+  *
+  * VIA 8363,8622,8361 Northbridges:
+  *  - bits  5, 6, 7 at offset 0x55 need to be turned off
+  * VIA 8367 (KT266x) Northbridges:
+  *  - bits  5, 6, 7 at offset 0x95 need to be turned off
++ * VIA 8363 rev 0x81/0x84 (KL133/KM133) Northbridges:
++ *  - bits     6, 7 at offset 0x55 need to be turned off
+  */
++
++#define VIA_8363_KL133_REVISION_ID 0x81
++#define VIA_8363_KM133_REVISION_ID 0x84
++
+ static void __init pci_fixup_via_northbridge_bug(struct pci_dev *d)
+ {
+       u8 v;
++      u8 revision;
+       int where = 0x55;
++      int mask = 0x1f; /* clear bits 5, 6, 7 by default */
++
++      pci_read_config_byte(d, PCI_REVISION_ID, &revision);
+       if (d->device == PCI_DEVICE_ID_VIA_8367_0) {
+               where = 0x95; /* the memory write queue timer register is 
 -      if (v & 0xe0) {
 -              printk(KERN_WARNING "Disabling broken memory write queue: [%02x] %02x->%02x\n",
 -                      where, v, v & 0x1f);
 -              v &= 0x1f; /* clear bits 5, 6, 7 */
++                              different for the KT266x's: 0x95 not 0x55 */
++      } else if (d->device == PCI_DEVICE_ID_VIA_8363_0 &&
++                      (revision == VIA_8363_KL133_REVISION_ID || 
++                      revision == VIA_8363_KM133_REVISION_ID)) {
++                      mask = 0x3f; /* clear only bits 6 and 7; clearing bit 5
++                                      causes screen corruption on the KL133/KM133 */
+       }
+         pci_read_config_byte(d, where, &v);
++      if (v & ~mask) {
++              printk(KERN_WARNING "Disabling VIA memory write queue (PCI ID %04x, rev %02x): [%02x] %02x & %02x -> %02x\n", \
++                      d->device, revision, where, v, mask, v & mask);
++              v &= mask;
+               pci_write_config_byte(d, where, v);
+       }
+ }
+ struct pci_fixup pcibios_fixups[] = {
+       { PCI_FIXUP_HEADER,     PCI_VENDOR_ID_INTEL,    PCI_DEVICE_ID_INTEL_82451NX,    pci_fixup_i450nx },
+       { PCI_FIXUP_HEADER,     PCI_VENDOR_ID_INTEL,    PCI_DEVICE_ID_INTEL_82454GX,    pci_fixup_i450gx },
+       { PCI_FIXUP_HEADER,     PCI_VENDOR_ID_UMC,      PCI_DEVICE_ID_UMC_UM8886BF,     pci_fixup_umc_ide },
+       { PCI_FIXUP_HEADER,     PCI_VENDOR_ID_SI,       PCI_DEVICE_ID_SI_5513,          pci_fixup_ide_trash },
+       { PCI_FIXUP_HEADER,     PCI_ANY_ID,             PCI_ANY_ID,                     pci_fixup_ide_bases },
+       { PCI_FIXUP_HEADER,     PCI_VENDOR_ID_SI,       PCI_DEVICE_ID_SI_5597,          pci_fixup_latency },
+       { PCI_FIXUP_HEADER,     PCI_VENDOR_ID_SI,       PCI_DEVICE_ID_SI_5598,          pci_fixup_latency },
+       { PCI_FIXUP_HEADER,     PCI_VENDOR_ID_INTEL,    PCI_DEVICE_ID_INTEL_82371AB_3,  pci_fixup_piix4_acpi },
+       { PCI_FIXUP_HEADER,     PCI_VENDOR_ID_VIA,      PCI_DEVICE_ID_VIA_8363_0,       pci_fixup_via_northbridge_bug },
+       { PCI_FIXUP_HEADER,     PCI_VENDOR_ID_VIA,      PCI_DEVICE_ID_VIA_8622,         pci_fixup_via_northbridge_bug },
+       { PCI_FIXUP_HEADER,     PCI_VENDOR_ID_VIA,      PCI_DEVICE_ID_VIA_8361,         pci_fixup_via_northbridge_bug },
+       { PCI_FIXUP_HEADER,     PCI_VENDOR_ID_VIA,      PCI_DEVICE_ID_VIA_8367_0,       pci_fixup_via_northbridge_bug },
+       { PCI_FIXUP_HEADER,     PCI_VENDOR_ID_NCR,      PCI_DEVICE_ID_NCR_53C810,       pci_fixup_ncr53c810 },
+       { 0 }
+ };
index 0000000000000000000000000000000000000000,27a14f0b317a1a06e9ef6027611bdb2444db23b0..830ea58c32c65f55f1246a212e1754b1b9675476
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,323 +1,324 @@@
 -pcibios_align_resource(void *data, struct resource *res, unsigned long size)
+ /*
+  *    Low-Level PCI Access for i386 machines
+  *
+  * Copyright 1993, 1994 Drew Eckhardt
+  *      Visionary Computing
+  *      (Unix and Linux consulting and custom programming)
+  *      Drew@Colorado.EDU
+  *      +1 (303) 786-7975
+  *
+  * Drew's work was sponsored by:
+  *    iX Multiuser Multitasking Magazine
+  *    Hannover, Germany
+  *    hm@ix.de
+  *
+  * Copyright 1997--2000 Martin Mares <mj@ucw.cz>
+  *
+  * For more information, please consult the following manuals (look at
+  * http://www.pcisig.com/ for how to get them):
+  *
+  * PCI BIOS Specification
+  * PCI Local Bus Specification
+  * PCI to PCI Bridge Specification
+  * PCI System Design Guide
+  *
+  */
+ #include <linux/types.h>
+ #include <linux/kernel.h>
+ #include <linux/pci.h>
+ #include <linux/init.h>
+ #include <linux/ioport.h>
+ #include <linux/errno.h>
+ #include "pci.h"
+ void
+ pcibios_update_resource(struct pci_dev *dev, struct resource *root,
+                       struct resource *res, int resource)
+ {
+       u32 new, check;
+       int reg;
+       new = res->start | (res->flags & PCI_REGION_FLAG_MASK);
+       if (resource < 6) {
+               reg = PCI_BASE_ADDRESS_0 + 4*resource;
+       } else if (resource == PCI_ROM_RESOURCE) {
+               res->flags |= PCI_ROM_ADDRESS_ENABLE;
+               new |= PCI_ROM_ADDRESS_ENABLE;
+               reg = dev->rom_base_reg;
+       } else {
+               /* Somebody might have asked allocation of a non-standard resource */
+               return;
+       }
+       
+       pci_write_config_dword(dev, reg, new);
+       pci_read_config_dword(dev, reg, &check);
+       if ((new ^ check) & ((new & PCI_BASE_ADDRESS_SPACE_IO) ? PCI_BASE_ADDRESS_IO_MASK : PCI_BASE_ADDRESS_MEM_MASK)) {
+               printk(KERN_ERR "PCI: Error while updating region "
+                      "%s/%d (%08x != %08x)\n", dev->slot_name, resource,
+                      new, check);
+       }
+ }
+ /*
+  * We need to avoid collisions with `mirrored' VGA ports
+  * and other strange ISA hardware, so we always want the
+  * addresses to be allocated in the 0x000-0x0ff region
+  * modulo 0x400.
+  *
+  * Why? Because some silly external IO cards only decode
+  * the low 10 bits of the IO address. The 0x00-0xff region
+  * is reserved for motherboard devices that decode all 16
+  * bits, so it's ok to allocate at, say, 0x2800-0x28ff,
+  * but we want to try to avoid allocating at 0x2900-0x2bff
+  * which might have be mirrored at 0x0100-0x03ff..
+  */
+ void
++pcibios_align_resource(void *data, struct resource *res,
++                     unsigned long size, unsigned long align)
+ {
+       if (res->flags & IORESOURCE_IO) {
+               unsigned long start = res->start;
+               if (start & 0x300) {
+                       start = (start + 0x3ff) & ~0x3ff;
+                       res->start = start;
+               }
+       }
+ }
+ /*
+  *  Handle resources of PCI devices.  If the world were perfect, we could
+  *  just allocate all the resource regions and do nothing more.  It isn't.
+  *  On the other hand, we cannot just re-allocate all devices, as it would
+  *  require us to know lots of host bridge internals.  So we attempt to
+  *  keep as much of the original configuration as possible, but tweak it
+  *  when it's found to be wrong.
+  *
+  *  Known BIOS problems we have to work around:
+  *    - I/O or memory regions not configured
+  *    - regions configured, but not enabled in the command register
+  *    - bogus I/O addresses above 64K used
+  *    - expansion ROMs left enabled (this may sound harmless, but given
+  *      the fact the PCI specs explicitly allow address decoders to be
+  *      shared between expansion ROMs and other resource regions, it's
+  *      at least dangerous)
+  *
+  *  Our solution:
+  *    (1) Allocate resources for all buses behind PCI-to-PCI bridges.
+  *        This gives us fixed barriers on where we can allocate.
+  *    (2) Allocate resources for all enabled devices.  If there is
+  *        a collision, just mark the resource as unallocated. Also
+  *        disable expansion ROMs during this step.
+  *    (3) Try to allocate resources for disabled devices.  If the
+  *        resources were assigned correctly, everything goes well,
+  *        if they weren't, they won't disturb allocation of other
+  *        resources.
+  *    (4) Assign new addresses to resources which were either
+  *        not configured at all or misconfigured.  If explicitly
+  *        requested by the user, configure expansion ROM address
+  *        as well.
+  */
+ static void __init pcibios_allocate_bus_resources(struct list_head *bus_list)
+ {
+       struct list_head *ln;
+       struct pci_bus *bus;
+       struct pci_dev *dev;
+       int idx;
+       struct resource *r, *pr;
+       /* Depth-First Search on bus tree */
+       for (ln=bus_list->next; ln != bus_list; ln=ln->next) {
+               bus = pci_bus_b(ln);
+               if ((dev = bus->self)) {
+                       for (idx = PCI_BRIDGE_RESOURCES; idx < PCI_NUM_RESOURCES; idx++) {
+                               r = &dev->resource[idx];
+                               if (!r->start)
+                                       continue;
+                               pr = pci_find_parent_resource(dev, r);
+                               if (!pr || request_resource(pr, r) < 0)
+                                       printk(KERN_ERR "PCI: Cannot allocate resource region %d of bridge %s\n", idx, dev->slot_name);
+                       }
+               }
+               pcibios_allocate_bus_resources(&bus->children);
+       }
+ }
+ static void __init pcibios_allocate_resources(int pass)
+ {
+       struct pci_dev *dev;
+       int idx, disabled;
+       u16 command;
+       struct resource *r, *pr;
+       pci_for_each_dev(dev) {
+               pci_read_config_word(dev, PCI_COMMAND, &command);
+               for(idx = 0; idx < 6; idx++) {
+                       r = &dev->resource[idx];
+                       if (r->parent)          /* Already allocated */
+                               continue;
+                       if (!r->start)          /* Address not assigned at all */
+                               continue;
+                       if (r->flags & IORESOURCE_IO)
+                               disabled = !(command & PCI_COMMAND_IO);
+                       else
+                               disabled = !(command & PCI_COMMAND_MEMORY);
+                       if (pass == disabled) {
+                               DBG("PCI: Resource %08lx-%08lx (f=%lx, d=%d, p=%d)\n",
+                                   r->start, r->end, r->flags, disabled, pass);
+                               pr = pci_find_parent_resource(dev, r);
+                               if (!pr || request_resource(pr, r) < 0) {
+                                       printk(KERN_ERR "PCI: Cannot allocate resource region %d of device %s\n", idx, dev->slot_name);
+                                       /* We'll assign a new address later */
+                                       r->end -= r->start;
+                                       r->start = 0;
+                               }
+                       }
+               }
+               if (!pass) {
+                       r = &dev->resource[PCI_ROM_RESOURCE];
+                       if (r->flags & PCI_ROM_ADDRESS_ENABLE) {
+                               /* Turn the ROM off, leave the resource region, but keep it unregistered. */
+                               u32 reg;
+                               DBG("PCI: Switching off ROM of %s\n", dev->slot_name);
+                               r->flags &= ~PCI_ROM_ADDRESS_ENABLE;
+                               pci_read_config_dword(dev, dev->rom_base_reg, &reg);
+                               pci_write_config_dword(dev, dev->rom_base_reg, reg & ~PCI_ROM_ADDRESS_ENABLE);
+                       }
+               }
+       }
+ }
+ static void __init pcibios_assign_resources(void)
+ {
+       struct pci_dev *dev;
+       int idx;
+       struct resource *r;
+       pci_for_each_dev(dev) {
+               int class = dev->class >> 8;
+               /* Don't touch classless devices and host bridges */
+               if (!class || class == PCI_CLASS_BRIDGE_HOST)
+                       continue;
+               for(idx=0; idx<6; idx++) {
+                       r = &dev->resource[idx];
+                       /*
+                        *  Don't touch IDE controllers and I/O ports of video cards!
+                        */
+                       if ((class == PCI_CLASS_STORAGE_IDE && idx < 4) ||
+                           (class == PCI_CLASS_DISPLAY_VGA && (r->flags & IORESOURCE_IO)))
+                               continue;
+                       /*
+                        *  We shall assign a new address to this resource, either because
+                        *  the BIOS forgot to do so or because we have decided the old
+                        *  address was unusable for some reason.
+                        */
+                       if (!r->start && r->end)
+                               pci_assign_resource(dev, idx);
+               }
+               if (pci_probe & PCI_ASSIGN_ROMS) {
+                       r = &dev->resource[PCI_ROM_RESOURCE];
+                       r->end -= r->start;
+                       r->start = 0;
+                       if (r->end)
+                               pci_assign_resource(dev, PCI_ROM_RESOURCE);
+               }
+       }
+ }
+ void __init pcibios_resource_survey(void)
+ {
+       DBG("PCI: Allocating resources\n");
+       pcibios_allocate_bus_resources(&pci_root_buses);
+       pcibios_allocate_resources(0);
+       pcibios_allocate_resources(1);
+       pcibios_assign_resources();
+ }
+ int pcibios_enable_resources(struct pci_dev *dev)
+ {
+       u16 cmd, old_cmd;
+       int idx;
+       struct resource *r;
+       pci_read_config_word(dev, PCI_COMMAND, &cmd);
+       old_cmd = cmd;
+       for(idx=0; idx<6; idx++) {
+               r = &dev->resource[idx];
+               if (!r->start && r->end) {
+                       printk(KERN_ERR "PCI: Device %s not available because of resource collisions\n", dev->slot_name);
+                       return -EINVAL;
+               }
+               if (r->flags & IORESOURCE_IO)
+                       cmd |= PCI_COMMAND_IO;
+               if (r->flags & IORESOURCE_MEM)
+                       cmd |= PCI_COMMAND_MEMORY;
+       }
+       if (dev->resource[PCI_ROM_RESOURCE].start)
+               cmd |= PCI_COMMAND_MEMORY;
+       if (cmd != old_cmd) {
+               printk("PCI: Enabling device %s (%04x -> %04x)\n", dev->slot_name, old_cmd, cmd);
+               pci_write_config_word(dev, PCI_COMMAND, cmd);
+       }
+       return 0;
+ }
+ /*
+  *  If we set up a device for bus mastering, we need to check the latency
+  *  timer as certain crappy BIOSes forget to set it properly.
+  */
+ unsigned int pcibios_max_latency = 255;
+ void pcibios_set_master(struct pci_dev *dev)
+ {
+       u8 lat;
+       pci_read_config_byte(dev, PCI_LATENCY_TIMER, &lat);
+       if (lat < 16)
+               lat = (64 <= pcibios_max_latency) ? 64 : pcibios_max_latency;
+       else if (lat > pcibios_max_latency)
+               lat = pcibios_max_latency;
+       else
+               return;
+       printk("PCI: Setting latency timer of device %s to %d\n", dev->slot_name, lat);
+       pci_write_config_byte(dev, PCI_LATENCY_TIMER, lat);
+ }
+ int pci_mmap_page_range(struct pci_dev *dev, struct vm_area_struct *vma,
+                       enum pci_mmap_state mmap_state, int write_combine)
+ {
+       unsigned long prot;
+       /* I/O space cannot be accessed via normal processor loads and
+        * stores on this platform.
+        */
+       if (mmap_state == pci_mmap_io)
+               return -EINVAL;
+       /* Leave vm_pgoff as-is, the PCI space address is the physical
+        * address on this platform.
+        */
+       vma->vm_flags |= (VM_SHM | VM_LOCKED | VM_IO);
+       prot = pgprot_val(vma->vm_page_prot);
+       if (boot_cpu_data.x86 > 3)
+               prot |= _PAGE_PCD | _PAGE_PWT;
+       vma->vm_page_prot = __pgprot(prot);
+       /* Write-combine setting is ignored, it is changed via the mtrr
+        * interfaces on this platform.
+        */
+       if (remap_page_range(vma, vma->vm_start, vma->vm_pgoff << PAGE_SHIFT,
+                            vma->vm_end - vma->vm_start,
+                            vma->vm_page_prot))
+               return -EAGAIN;
+       return 0;
+ }
index 0000000000000000000000000000000000000000,68eb183277f39cba471f65bd5666139e0a096ee2..81e82c82c740163b0cc17d670b53c1521dbece03
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,810 +1,812 @@@
+ /*
+  *    Low-Level PCI Support for PC -- Routing of Interrupts
+  *
+  *    (c) 1999--2000 Martin Mares <mj@ucw.cz>
+  */
+ #include <linux/config.h>
+ #include <linux/types.h>
+ #include <linux/kernel.h>
+ #include <linux/pci.h>
+ #include <linux/init.h>
+ #include <linux/slab.h>
+ #include <linux/interrupt.h>
+ #include <linux/irq.h>
+ #include <linux/acpi.h>
+ #include <asm/io.h>
+ #include <asm/smp.h>
+ #include <asm/io_apic.h>
+ #include "pci.h"
+ #define PIRQ_SIGNATURE        (('$' << 0) + ('P' << 8) + ('I' << 16) + ('R' << 24))
+ #define PIRQ_VERSION 0x0100
+ int pci_use_acpi_routing = 0;
+ int broken_hp_bios_irq9;
+ static struct irq_routing_table *pirq_table;
+ /*
+  * Never use: 0, 1, 2 (timer, keyboard, and cascade)
+  * Avoid using: 13, 14 and 15 (FP error and IDE).
+  * Penalize: 3, 4, 6, 7, 12 (known ISA uses: serial, floppy, parallel and mouse)
+  */
+ unsigned int pcibios_irq_mask = 0xfff8;
+ static int pirq_penalty[16] = {
+       1000000, 1000000, 1000000, 1000, 1000, 0, 1000, 1000,
+       0, 0, 0, 0, 1000, 100000, 100000, 100000
+ };
+ struct irq_router {
+       char *name;
+       u16 vendor, device;
+       int (*get)(struct pci_dev *router, struct pci_dev *dev, int pirq);
+       int (*set)(struct pci_dev *router, struct pci_dev *dev, int pirq, int new);
+ };
+ int (*pci_lookup_irq)(struct pci_dev * dev, int assign) = NULL;
+ /*
+  *  Search 0xf0000 -- 0xfffff for the PCI IRQ Routing Table.
+  */
+ static struct irq_routing_table * __init pirq_find_routing_table(void)
+ {
+       u8 *addr;
+       struct irq_routing_table *rt;
+       int i;
+       u8 sum;
+       for(addr = (u8 *) __va(0xf0000); addr < (u8 *) __va(0x100000); addr += 16) {
+               rt = (struct irq_routing_table *) addr;
+               if (rt->signature != PIRQ_SIGNATURE ||
+                   rt->version != PIRQ_VERSION ||
+                   rt->size % 16 ||
+                   rt->size < sizeof(struct irq_routing_table))
+                       continue;
+               sum = 0;
+               for(i=0; i<rt->size; i++)
+                       sum += addr[i];
+               if (!sum) {
+                       DBG("PCI: Interrupt Routing Table found at 0x%p\n", rt);
+                       return rt;
+               }
+       }
+       return NULL;
+ }
+ /*
+  *  If we have a IRQ routing table, use it to search for peer host
+  *  bridges.  It's a gross hack, but since there are no other known
+  *  ways how to get a list of buses, we have to go this way.
+  */
+ static void __init pirq_peer_trick(void)
+ {
+       struct irq_routing_table *rt = pirq_table;
+       u8 busmap[256];
+       int i;
+       struct irq_info *e;
+       memset(busmap, 0, sizeof(busmap));
+       for(i=0; i < (rt->size - sizeof(struct irq_routing_table)) / sizeof(struct irq_info); i++) {
+               e = &rt->slots[i];
+ #ifdef DEBUG
+               {
+                       int j;
+                       DBG("%02x:%02x slot=%02x", e->bus, e->devfn/8, e->slot);
+                       for(j=0; j<4; j++)
+                               DBG(" %d:%02x/%04x", j, e->irq[j].link, e->irq[j].bitmap);
+                       DBG("\n");
+               }
+ #endif
+               busmap[e->bus] = 1;
+       }
+       for(i=1; i<256; i++)
+               /*
+                *  It might be a secondary bus, but in this case its parent is already
+                *  known (ascending bus order) and therefore pci_scan_bus returns immediately.
+                */
+               if (busmap[i] && pci_scan_bus(i, pci_root_bus->ops, NULL))
+                       printk(KERN_INFO "PCI: Discovered primary peer bus %02x [IRQ]\n", i);
+       pcibios_last_bus = -1;
+ }
+ /*
+  *  Code for querying and setting of IRQ routes on various interrupt routers.
+  */
+ void eisa_set_level_irq(unsigned int irq)
+ {
+       unsigned char mask = 1 << (irq & 7);
+       unsigned int port = 0x4d0 + (irq >> 3);
+       unsigned char val = inb(port);
+       if (!(val & mask)) {
+               DBG(" -> edge");
+               outb(val | mask, port);
+       }
+ }
+ /*
+  * Common IRQ routing practice: nybbles in config space,
+  * offset by some magic constant.
+  */
+ static unsigned int read_config_nybble(struct pci_dev *router, unsigned offset, unsigned nr)
+ {
+       u8 x;
+       unsigned reg = offset + (nr >> 1);
+       pci_read_config_byte(router, reg, &x);
+       return (nr & 1) ? (x >> 4) : (x & 0xf);
+ }
+ static void write_config_nybble(struct pci_dev *router, unsigned offset, unsigned nr, unsigned int val)
+ {
+       u8 x;
+       unsigned reg = offset + (nr >> 1);
+       pci_read_config_byte(router, reg, &x);
+       x = (nr & 1) ? ((x & 0x0f) | (val << 4)) : ((x & 0xf0) | val);
+       pci_write_config_byte(router, reg, x);
+ }
+ /*
+  * ALI pirq entries are damn ugly, and completely undocumented.
+  * This has been figured out from pirq tables, and it's not a pretty
+  * picture.
+  */
+ static int pirq_ali_get(struct pci_dev *router, struct pci_dev *dev, int pirq)
+ {
+       static unsigned char irqmap[16] = { 0, 9, 3, 10, 4, 5, 7, 6, 1, 11, 0, 12, 0, 14, 0, 15 };
+       return irqmap[read_config_nybble(router, 0x48, pirq-1)];
+ }
+ static int pirq_ali_set(struct pci_dev *router, struct pci_dev *dev, int pirq, int irq)
+ {
+       static unsigned char irqmap[16] = { 0, 8, 0, 2, 4, 5, 7, 6, 0, 1, 3, 9, 11, 0, 13, 15 };
+       unsigned int val = irqmap[irq];
+               
+       if (val) {
+               write_config_nybble(router, 0x48, pirq-1, val);
+               return 1;
+       }
+       return 0;
+ }
+ /*
+  * The Intel PIIX4 pirq rules are fairly simple: "pirq" is
+  * just a pointer to the config space.
+  */
+ static int pirq_piix_get(struct pci_dev *router, struct pci_dev *dev, int pirq)
+ {
+       u8 x;
+       pci_read_config_byte(router, pirq, &x);
+       return (x < 16) ? x : 0;
+ }
+ static int pirq_piix_set(struct pci_dev *router, struct pci_dev *dev, int pirq, int irq)
+ {
+       pci_write_config_byte(router, pirq, irq);
+       return 1;
+ }
+ /*
+  * The VIA pirq rules are nibble-based, like ALI,
+  * but without the ugly irq number munging.
+  */
+ static int pirq_via_get(struct pci_dev *router, struct pci_dev *dev, int pirq)
+ {
+       return read_config_nybble(router, 0x55, pirq);
+ }
+ static int pirq_via_set(struct pci_dev *router, struct pci_dev *dev, int pirq, int irq)
+ {
+       write_config_nybble(router, 0x55, pirq, irq);
+       return 1;
+ }
+ /*
+  * ITE 8330G pirq rules are nibble-based
+  * FIXME: pirqmap may be { 1, 0, 3, 2 },
+  *      2+3 are both mapped to irq 9 on my system
+  */
+ static int pirq_ite_get(struct pci_dev *router, struct pci_dev *dev, int pirq)
+ {
+       static unsigned char pirqmap[4] = { 1, 0, 2, 3 };
+       return read_config_nybble(router,0x43, pirqmap[pirq-1]);
+ }
+ static int pirq_ite_set(struct pci_dev *router, struct pci_dev *dev, int pirq, int irq)
+ {
+       static unsigned char pirqmap[4] = { 1, 0, 2, 3 };
+       write_config_nybble(router, 0x43, pirqmap[pirq-1], irq);
+       return 1;
+ }
+ /*
+  * OPTI: high four bits are nibble pointer..
+  * I wonder what the low bits do?
+  */
+ static int pirq_opti_get(struct pci_dev *router, struct pci_dev *dev, int pirq)
+ {
+       return read_config_nybble(router, 0xb8, pirq >> 4);
+ }
+ static int pirq_opti_set(struct pci_dev *router, struct pci_dev *dev, int pirq, int irq)
+ {
+       write_config_nybble(router, 0xb8, pirq >> 4, irq);
+       return 1;
+ }
+ /*
+  * Cyrix: nibble offset 0x5C
++ * 0x5C bits 7:4 is INTB bits 3:0 is INTA 
++ * 0x5D bits 7:4 is INTD bits 3:0 is INTC
+  */
+ static int pirq_cyrix_get(struct pci_dev *router, struct pci_dev *dev, int pirq)
+ {
+       return read_config_nybble(router, 0x5C, (pirq-1)^1);
+ }
+ static int pirq_cyrix_set(struct pci_dev *router, struct pci_dev *dev, int pirq, int irq)
+ {
+       write_config_nybble(router, 0x5C, (pirq-1)^1, irq);
+       return 1;
+ }
+ /*
+  *    PIRQ routing for SiS 85C503 router used in several SiS chipsets
+  *    According to the SiS 5595 datasheet (preliminary V1.0, 12/24/1997)
+  *    the related registers work as follows:
+  *    
+  *    general: one byte per re-routable IRQ,
+  *             bit 7      IRQ mapping enabled (0) or disabled (1)
+  *             bits [6:4] reserved
+  *             bits [3:0] IRQ to map to
+  *                 allowed: 3-7, 9-12, 14-15
+  *                 reserved: 0, 1, 2, 8, 13
+  *
+  *    individual registers in device config space:
+  *
+  *    0x41/0x42/0x43/0x44:    PCI INT A/B/C/D - bits as in general case
+  *
+  *    0x61:                   IDEIRQ: bits as in general case - but:
+  *                            bits [6:5] must be written 01
+  *                            bit 4 channel-select primary (0), secondary (1)
+  *
+  *    0x62:                   USBIRQ: bits as in general case - but:
+  *                            bit 4 OHCI function disabled (0), enabled (1)
+  *    
+  *    0x6a:                   ACPI/SCI IRQ - bits as in general case
+  *
+  *    0x7e:                   Data Acq. Module IRQ - bits as in general case
+  *
+  *    Apparently there are systems implementing PCI routing table using both
+  *    link values 0x01-0x04 and 0x41-0x44 for PCI INTA..D, but register offsets
+  *    like 0x62 as link values for USBIRQ e.g. So there is no simple
+  *    "register = offset + pirq" relation.
+  *    Currently we support PCI INTA..D and USBIRQ and try our best to handle
+  *    both link mappings.
+  *    IDE/ACPI/DAQ mapping is currently unsupported (left untouched as set by BIOS).
+  */
+ static int pirq_sis_get(struct pci_dev *router, struct pci_dev *dev, int pirq)
+ {
+       u8 x;
+       int reg = pirq;
+       switch(pirq) {
+               case 0x01:
+               case 0x02:
+               case 0x03:
+               case 0x04:
+                       reg += 0x40;
+               case 0x41:
+               case 0x42:
+               case 0x43:
+               case 0x44:
+               case 0x62:
+                       pci_read_config_byte(router, reg, &x);
+                       if (reg != 0x62)
+                               break;
+                       if (!(x & 0x40))
+                               return 0;
+                       break;
+               case 0x61:
+               case 0x6a:
+               case 0x7e:
+                       printk(KERN_INFO "SiS pirq: advanced IDE/ACPI/DAQ mapping not yet implemented\n");
+                       return 0;
+               default:                        
+                       printk(KERN_INFO "SiS router pirq escape (%d)\n", pirq);
+                       return 0;
+       }
+       return (x & 0x80) ? 0 : (x & 0x0f);
+ }
+ static int pirq_sis_set(struct pci_dev *router, struct pci_dev *dev, int pirq, int irq)
+ {
+       u8 x;
+       int reg = pirq;
+       switch(pirq) {
+               case 0x01:
+               case 0x02:
+               case 0x03:
+               case 0x04:
+                       reg += 0x40;
+               case 0x41:
+               case 0x42:
+               case 0x43:
+               case 0x44:
+               case 0x62:
+                       x = (irq&0x0f) ? (irq&0x0f) : 0x80;
+                       if (reg != 0x62)
+                               break;
+                       /* always mark OHCI enabled, as nothing else knows about this */
+                       x |= 0x40;
+                       break;
+               case 0x61:
+               case 0x6a:
+               case 0x7e:
+                       printk(KERN_INFO "advanced SiS pirq mapping not yet implemented\n");
+                       return 0;
+               default:                        
+                       printk(KERN_INFO "SiS router pirq escape (%d)\n", pirq);
+                       return 0;
+       }
+       pci_write_config_byte(router, reg, x);
+       return 1;
+ }
+ /*
+  * VLSI: nibble offset 0x74 - educated guess due to routing table and
+  *       config space of VLSI 82C534 PCI-bridge/router (1004:0102)
+  *       Tested on HP OmniBook 800 covering PIRQ 1, 2, 4, 8 for onboard
+  *       devices, PIRQ 3 for non-pci(!) soundchip and (untested) PIRQ 6
+  *       for the busbridge to the docking station.
+  */
+ static int pirq_vlsi_get(struct pci_dev *router, struct pci_dev *dev, int pirq)
+ {
+       if (pirq > 8) {
+               printk(KERN_INFO "VLSI router pirq escape (%d)\n", pirq);
+               return 0;
+       }
+       return read_config_nybble(router, 0x74, pirq-1);
+ }
+ static int pirq_vlsi_set(struct pci_dev *router, struct pci_dev *dev, int pirq, int irq)
+ {
+       if (pirq > 8) {
+               printk(KERN_INFO "VLSI router pirq escape (%d)\n", pirq);
+               return 0;
+       }
+       write_config_nybble(router, 0x74, pirq-1, irq);
+       return 1;
+ }
+ /*
+  * ServerWorks: PCI interrupts mapped to system IRQ lines through Index
+  * and Redirect I/O registers (0x0c00 and 0x0c01).  The Index register
+  * format is (PCIIRQ## | 0x10), e.g.: PCIIRQ10=0x1a.  The Redirect
+  * register is a straight binary coding of desired PIC IRQ (low nibble).
+  *
+  * The 'link' value in the PIRQ table is already in the correct format
+  * for the Index register.  There are some special index values:
+  * 0x00 for ACPI (SCI), 0x01 for USB, 0x02 for IDE0, 0x04 for IDE1,
+  * and 0x03 for SMBus.
+  */
+ static int pirq_serverworks_get(struct pci_dev *router, struct pci_dev *dev, int pirq)
+ {
+       outb_p(pirq, 0xc00);
+       return inb(0xc01) & 0xf;
+ }
+ static int pirq_serverworks_set(struct pci_dev *router, struct pci_dev *dev, int pirq, int irq)
+ {
+       outb_p(pirq, 0xc00);
+       outb_p(irq, 0xc01);
+       return 1;
+ }
+ /* Support for AMD756 PCI IRQ Routing
+  * Jhon H. Caicedo <jhcaiced@osso.org.co>
+  * Jun/21/2001 0.2.0 Release, fixed to use "nybble" functions... (jhcaiced)
+  * Jun/19/2001 Alpha Release 0.1.0 (jhcaiced)
+  * The AMD756 pirq rules are nibble-based
+  * offset 0x56 0-3 PIRQA  4-7  PIRQB
+  * offset 0x57 0-3 PIRQC  4-7  PIRQD
+  */
+ static int pirq_amd756_get(struct pci_dev *router, struct pci_dev *dev, int pirq)
+ {
+       u8 irq;
+       irq = 0;
+       if (pirq <= 4)
+       {
+               irq = read_config_nybble(router, 0x56, pirq - 1);
+       }
+       printk(KERN_INFO "AMD756: dev %04x:%04x, router pirq : %d get irq : %2d\n",
+               dev->vendor, dev->device, pirq, irq);
+       return irq;
+ }
+ static int pirq_amd756_set(struct pci_dev *router, struct pci_dev *dev, int pirq, int irq)
+ {
+       printk(KERN_INFO "AMD756: dev %04x:%04x, router pirq : %d SET irq : %2d\n", 
+               dev->vendor, dev->device, pirq, irq);
+       if (pirq <= 4)
+       {
+               write_config_nybble(router, 0x56, pirq - 1, irq);
+       }
+       return 1;
+ }
+ #ifdef CONFIG_PCI_BIOS
+ static int pirq_bios_set(struct pci_dev *router, struct pci_dev *dev, int pirq, int irq)
+ {
+       struct pci_dev *bridge;
+       int pin = pci_get_interrupt_pin(dev, &bridge);
+       return pcibios_set_irq_routing(bridge, pin, irq);
+ }
+ static struct irq_router pirq_bios_router =
+       { "BIOS", 0, 0, NULL, pirq_bios_set };
+ #endif
+ static struct irq_router pirq_routers[] = {
+       { "PIIX", PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82371FB_0, pirq_piix_get, pirq_piix_set },
+       { "PIIX", PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82371SB_0, pirq_piix_get, pirq_piix_set },
+       { "PIIX", PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82371AB_0, pirq_piix_get, pirq_piix_set },
+       { "PIIX", PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82371MX,   pirq_piix_get, pirq_piix_set },
+       { "PIIX", PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443MX_0, pirq_piix_get, pirq_piix_set },
+       { "PIIX", PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AA_0, pirq_piix_get, pirq_piix_set },
+       { "PIIX", PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AB_0, pirq_piix_get, pirq_piix_set },
+       { "PIIX", PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_0, pirq_piix_get, pirq_piix_set },
+       { "PIIX", PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_10, pirq_piix_get, pirq_piix_set },
+       { "PIIX", PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_0, pirq_piix_get, pirq_piix_set },
+       { "PIIX", PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_12, pirq_piix_get, pirq_piix_set },
+       { "ALI", PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M1533, pirq_ali_get, pirq_ali_set },
+       { "ITE", PCI_VENDOR_ID_ITE, PCI_DEVICE_ID_ITE_IT8330G_0, pirq_ite_get, pirq_ite_set },
+       { "VIA", PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C586_0, pirq_via_get, pirq_via_set },
+       { "VIA", PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C596, pirq_via_get, pirq_via_set },
+       { "VIA", PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C686, pirq_via_get, pirq_via_set },
+       { "OPTI", PCI_VENDOR_ID_OPTI, PCI_DEVICE_ID_OPTI_82C700, pirq_opti_get, pirq_opti_set },
+       { "NatSemi", PCI_VENDOR_ID_CYRIX, PCI_DEVICE_ID_CYRIX_5520, pirq_cyrix_get, pirq_cyrix_set },
+       { "SIS", PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_503, pirq_sis_get, pirq_sis_set },
+       { "VLSI 82C534", PCI_VENDOR_ID_VLSI, PCI_DEVICE_ID_VLSI_82C534, pirq_vlsi_get, pirq_vlsi_set },
+       { "ServerWorks", PCI_VENDOR_ID_SERVERWORKS, PCI_DEVICE_ID_SERVERWORKS_OSB4,
+         pirq_serverworks_get, pirq_serverworks_set },
+       { "ServerWorks", PCI_VENDOR_ID_SERVERWORKS, PCI_DEVICE_ID_SERVERWORKS_CSB5,
+         pirq_serverworks_get, pirq_serverworks_set },
+       { "AMD756 VIPER", PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_VIPER_740B,
+               pirq_amd756_get, pirq_amd756_set },
+       { "default", 0, 0, NULL, NULL }
+ };
+ static struct irq_router *pirq_router;
+ static struct pci_dev *pirq_router_dev;
+ static void __init pirq_find_router(void)
+ {
+       struct irq_routing_table *rt = pirq_table;
+       struct irq_router *r;
+ #ifdef CONFIG_PCI_BIOS
+       if (!rt->signature) {
+               printk(KERN_INFO "PCI: Using BIOS for IRQ routing\n");
+               pirq_router = &pirq_bios_router;
+               return;
+       }
+ #endif
+       DBG("PCI: Attempting to find IRQ router for %04x:%04x\n",
+           rt->rtr_vendor, rt->rtr_device);
+       /* fall back to default router if nothing else found */
+       pirq_router = &pirq_routers[ARRAY_SIZE(pirq_routers) - 1];
+       pirq_router_dev = pci_find_slot(rt->rtr_bus, rt->rtr_devfn);
+       if (!pirq_router_dev) {
+               DBG("PCI: Interrupt router not found at %02x:%02x\n", rt->rtr_bus, rt->rtr_devfn);
+               return;
+       }
+       for(r=pirq_routers; r->vendor; r++) {
+               /* Exact match against router table entry? Use it! */
+               if (r->vendor == rt->rtr_vendor && r->device == rt->rtr_device) {
+                       pirq_router = r;
+                       break;
+               }
+               /* Match against router device entry? Use it as a fallback */
+               if (r->vendor == pirq_router_dev->vendor && r->device == pirq_router_dev->device) {
+                       pirq_router = r;
+               }
+       }
+       printk(KERN_INFO "PCI: Using IRQ router %s [%04x/%04x] at %s\n",
+               pirq_router->name,
+               pirq_router_dev->vendor,
+               pirq_router_dev->device,
+               pirq_router_dev->slot_name);
+ }
+ static struct irq_info *pirq_get_info(struct pci_dev *dev)
+ {
+       struct irq_routing_table *rt = pirq_table;
+       int entries = (rt->size - sizeof(struct irq_routing_table)) / sizeof(struct irq_info);
+       struct irq_info *info;
+       for (info = rt->slots; entries--; info++)
+               if (info->bus == dev->bus->number && PCI_SLOT(info->devfn) == PCI_SLOT(dev->devfn))
+                       return info;
+       return NULL;
+ }
+ static void pcibios_test_irq_handler(int irq, void *dev_id, struct pt_regs *regs)
+ {
+ }
+ static int pcibios_lookup_irq(struct pci_dev *dev, int assign)
+ {
+       u8 pin;
+       struct irq_info *info;
+       int i, pirq, newirq;
+       int irq = 0;
+       u32 mask;
+       struct irq_router *r = pirq_router;
+       struct pci_dev *dev2;
+       char *msg = NULL;
+       /* Find IRQ pin */
+       pci_read_config_byte(dev, PCI_INTERRUPT_PIN, &pin);
+       if (!pin) {
+               DBG(" -> no interrupt pin\n");
+               return 0;
+       }
+       pin = pin - 1;
+       /* Find IRQ routing entry */
+       if (!pirq_table)
+               return 0;
+       
+       DBG("IRQ for %s:%d", dev->slot_name, pin);
+       info = pirq_get_info(dev);
+       if (!info) {
+               DBG(" -> not found in routing table\n");
+               return 0;
+       }
+       pirq = info->irq[pin].link;
+       mask = info->irq[pin].bitmap;
+       if (!pirq) {
+               DBG(" -> not routed\n");
+               return 0;
+       }
+       DBG(" -> PIRQ %02x, mask %04x, excl %04x", pirq, mask, pirq_table->exclusive_irqs);
+       mask &= pcibios_irq_mask;
+       /* Work around broken HP Pavilion Notebooks which assign USB to
+          IRQ 9 even though it is actually wired to IRQ 11 */
+       if (broken_hp_bios_irq9 && pirq == 0x59 && dev->irq == 9) {
+               dev->irq = 11;
+               pci_write_config_byte(dev, PCI_INTERRUPT_LINE, 11);
+               r->set(pirq_router_dev, dev, pirq, 11);
+       }
+       /*
+        * Find the best IRQ to assign: use the one
+        * reported by the device if possible.
+        */
+       newirq = dev->irq;
+       if (!((1 << newirq) & mask)) {
+               if ( pci_probe & PCI_USE_PIRQ_MASK) newirq = 0;
+               else printk(KERN_WARNING "PCI: IRQ %i for device %s doesn't match PIRQ mask - try pci=usepirqmask\n", newirq, dev->slot_name);
+       }
+       if (!newirq && assign) {
+               for (i = 0; i < 16; i++) {
+                       if (!(mask & (1 << i)))
+                               continue;
+                       if (pirq_penalty[i] < pirq_penalty[newirq] &&
+                           !request_irq(i, pcibios_test_irq_handler, SA_SHIRQ, "pci-test", dev)) {
+                               free_irq(i, dev);
+                               newirq = i;
+                       }
+               }
+       }
+       DBG(" -> newirq=%d", newirq);
+       /* Check if it is hardcoded */
+       if ((pirq & 0xf0) == 0xf0) {
+               irq = pirq & 0xf;
+               DBG(" -> hardcoded IRQ %d\n", irq);
+               msg = "Hardcoded";
+       } else if ( r->get && (irq = r->get(pirq_router_dev, dev, pirq)) && \
+       ((!(pci_probe & PCI_USE_PIRQ_MASK)) || ((1 << irq) & mask)) ) {
+               DBG(" -> got IRQ %d\n", irq);
+               msg = "Found";
+       } else if (newirq && r->set && (dev->class >> 8) != PCI_CLASS_DISPLAY_VGA) {
+               DBG(" -> assigning IRQ %d", newirq);
+               if (r->set(pirq_router_dev, dev, pirq, newirq)) {
+                       eisa_set_level_irq(newirq);
+                       DBG(" ... OK\n");
+                       msg = "Assigned";
+                       irq = newirq;
+               }
+       }
+       if (!irq) {
+               DBG(" ... failed\n");
+               if (newirq && mask == (1 << newirq)) {
+                       msg = "Guessed";
+                       irq = newirq;
+               } else
+                       return 0;
+       }
+       printk(KERN_INFO "PCI: %s IRQ %d for device %s\n", msg, irq, dev->slot_name);
+       /* Update IRQ for all devices with the same pirq value */
+       pci_for_each_dev(dev2) {
+               pci_read_config_byte(dev2, PCI_INTERRUPT_PIN, &pin);
+               if (!pin)
+                       continue;
+               pin--;
+               info = pirq_get_info(dev2);
+               if (!info)
+                       continue;
+               if (info->irq[pin].link == pirq) {
+                       /* We refuse to override the dev->irq information. Give a warning! */
+                       if ( dev2->irq && dev2->irq != irq && \
+                       (!(pci_probe & PCI_USE_PIRQ_MASK) || \
+                       ((1 << dev2->irq) & mask)) ) {
+                               printk(KERN_INFO "IRQ routing conflict for %s, have irq %d, want irq %d\n",
+                                      dev2->slot_name, dev2->irq, irq);
+                               continue;
+                       }
+                       dev2->irq = irq;
+                       pirq_penalty[irq]++;
+                       if (dev != dev2)
+                               printk(KERN_INFO "PCI: Sharing IRQ %d with %s\n", irq, dev2->slot_name);
+               }
+       }
+       return 1;
+ }
+ static int __init pcibios_irq_init(void)
+ {
+       DBG("PCI: IRQ init\n");
+       if (pci_lookup_irq)
+               return 0;
+       pirq_table = pirq_find_routing_table();
+ #ifdef CONFIG_PCI_BIOS
+       if (!pirq_table && (pci_probe & PCI_BIOS_IRQ_SCAN))
+               pirq_table = pcibios_get_irq_routing_table();
+ #endif
+       if (pirq_table) {
+               pirq_peer_trick();
+               pirq_find_router();
+               if (pirq_table->exclusive_irqs) {
+                       int i;
+                       for (i=0; i<16; i++)
+                               if (!(pirq_table->exclusive_irqs & (1 << i)))
+                                       pirq_penalty[i] += 100;
+               }
+               /* If we're using the I/O APIC, avoid using the PCI IRQ routing table */
+               if (io_apic_assign_pci_irqs)
+                       pirq_table = NULL;
+       }
+       pci_lookup_irq = pcibios_lookup_irq;
+       pcibios_fixup_irqs();
+       return 0;
+ }
+ subsys_initcall(pcibios_irq_init);
+ void __init pcibios_fixup_irqs(void)
+ {
+       struct pci_dev *dev;
+       u8 pin;
+       DBG("PCI: IRQ fixup\n");
+       pci_for_each_dev(dev) {
+               /*
+                * If the BIOS has set an out of range IRQ number, just ignore it.
+                * Also keep track of which IRQ's are already in use.
+                */
+               if (dev->irq >= 16) {
+                       DBG("%s: ignoring bogus IRQ %d\n", dev->slot_name, dev->irq);
+                       dev->irq = 0;
+               }
+               /* If the IRQ is already assigned to a PCI device, ignore its ISA use penalty */
+               if (pirq_penalty[dev->irq] >= 100 && pirq_penalty[dev->irq] < 100000)
+                       pirq_penalty[dev->irq] = 0;
+               pirq_penalty[dev->irq]++;
+       }
+       pci_for_each_dev(dev) {
+               pci_read_config_byte(dev, PCI_INTERRUPT_PIN, &pin);
+ #ifdef CONFIG_X86_IO_APIC
+               /*
+                * Recalculate IRQ numbers if we use the I/O APIC.
+                */
+               if (io_apic_assign_pci_irqs)
+               {
+                       int irq;
+                       if (pin) {
+                               pin--;          /* interrupt pins are numbered starting from 1 */
+                               irq = IO_APIC_get_PCI_irq_vector(dev->bus->number, PCI_SLOT(dev->devfn), pin);
+       /*
+        * Busses behind bridges are typically not listed in the MP-table.
+        * In this case we have to look up the IRQ based on the parent bus,
+        * parent slot, and pin number. The SMP code detects such bridged
+        * busses itself so we should get into this branch reliably.
+        */
+                               if (irq < 0 && dev->bus->parent) { /* go back to the bridge */
+                                       struct pci_dev * bridge = dev->bus->self;
+                                       pin = (pin + PCI_SLOT(dev->devfn)) % 4;
+                                       irq = IO_APIC_get_PCI_irq_vector(bridge->bus->number, 
+                                                       PCI_SLOT(bridge->devfn), pin);
+                                       if (irq >= 0)
+                                               printk(KERN_WARNING "PCI: using PPB(B%d,I%d,P%d) to get irq %d\n", 
+                                                       bridge->bus->number, PCI_SLOT(bridge->devfn), pin, irq);
+                               }
+                               if (irq >= 0) {
+                                       printk(KERN_INFO "PCI->APIC IRQ transform: (B%d,I%d,P%d) -> %d\n",
+                                               dev->bus->number, PCI_SLOT(dev->devfn), pin, irq);
+                                       dev->irq = irq;
+                               }
+                       }
+               }
+ #endif
+               /*
+                * Still no IRQ? Try to lookup one...
+                */
+               if (pin && !dev->irq)
+                       pci_lookup_irq(dev, 0);
+       }
+ }
+ void pcibios_penalize_isa_irq(int irq)
+ {
+       /*
+        *  If any ISAPnP device reports an IRQ in its list of possible
+        *  IRQ's, we try to avoid assigning it to PCI devices.
+        */
+       pirq_penalty[irq] += 100;
+ }
+ void pcibios_enable_irq(struct pci_dev *dev)
+ {
+       u8 pin;
+       pci_read_config_byte(dev, PCI_INTERRUPT_PIN, &pin);
+       if (pin && !pci_lookup_irq(dev, 1) && !dev->irq) {
+               char *msg;
+               if (io_apic_assign_pci_irqs)
+                       msg = " Probably buggy MP table.";
+               else if (pci_probe & PCI_BIOS_IRQ_SCAN)
+                       msg = "";
+               else
+                       msg = " Please try using pci=biosirq.";
+               printk(KERN_WARNING "PCI: No IRQ known for interrupt pin %c of device %s.%s\n",
+                      'A' + pin - 1, dev->slot_name, msg);
+       }
+ }