linux/drivers/pci/quirks.c
<<
>>
Prefs
   1/*
   2 *  This file contains work-arounds for many known PCI hardware
   3 *  bugs.  Devices present only on certain architectures (host
   4 *  bridges et cetera) should be handled in arch-specific code.
   5 *
   6 *  Note: any quirks for hotpluggable devices must _NOT_ be declared __init.
   7 *
   8 *  Copyright (c) 1999 Martin Mares <mj@ucw.cz>
   9 *
  10 *  Init/reset quirks for USB host controllers should be in the
  11 *  USB quirks file, where their drivers can access reuse it.
  12 *
  13 *  The bridge optimization stuff has been removed. If you really
  14 *  have a silly BIOS which is unable to set your host bridge right,
  15 *  use the PowerTweak utility (see http://powertweak.sourceforge.net).
  16 */
  17
  18#include <linux/types.h>
  19#include <linux/kernel.h>
  20#include <linux/pci.h>
  21#include <linux/init.h>
  22#include <linux/delay.h>
  23#include <linux/acpi.h>
  24#include <linux/kallsyms.h>
  25#include <linux/pci-aspm.h>
  26#include "pci.h"
  27
  28/* The Mellanox Tavor device gives false positive parity errors
  29 * Mark this device with a broken_parity_status, to allow
  30 * PCI scanning code to "skip" this now blacklisted device.
  31 */
  32static void __devinit quirk_mellanox_tavor(struct pci_dev *dev)
  33{
  34        dev->broken_parity_status = 1;  /* This device gives false positives */
  35}
  36DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_MELLANOX,PCI_DEVICE_ID_MELLANOX_TAVOR,quirk_mellanox_tavor);
  37DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_MELLANOX,PCI_DEVICE_ID_MELLANOX_TAVOR_BRIDGE,quirk_mellanox_tavor);
  38
  39/* Deal with broken BIOS'es that neglect to enable passive release,
  40   which can cause problems in combination with the 82441FX/PPro MTRRs */
  41static void quirk_passive_release(struct pci_dev *dev)
  42{
  43        struct pci_dev *d = NULL;
  44        unsigned char dlc;
  45
  46        /* We have to make sure a particular bit is set in the PIIX3
  47           ISA bridge, so we have to go out and find it. */
  48        while ((d = pci_get_device(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82371SB_0, d))) {
  49                pci_read_config_byte(d, 0x82, &dlc);
  50                if (!(dlc & 1<<1)) {
  51                        dev_err(&d->dev, "PIIX3: Enabling Passive Release\n");
  52                        dlc |= 1<<1;
  53                        pci_write_config_byte(d, 0x82, dlc);
  54                }
  55        }
  56}
  57DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL,    PCI_DEVICE_ID_INTEL_82441,      quirk_passive_release);
  58DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_INTEL,   PCI_DEVICE_ID_INTEL_82441,      quirk_passive_release);
  59
  60/*  The VIA VP2/VP3/MVP3 seem to have some 'features'. There may be a workaround
  61    but VIA don't answer queries. If you happen to have good contacts at VIA
  62    ask them for me please -- Alan 
  63    
  64    This appears to be BIOS not version dependent. So presumably there is a 
  65    chipset level fix */
  66int isa_dma_bridge_buggy;
  67EXPORT_SYMBOL(isa_dma_bridge_buggy);
  68    
  69static void __devinit quirk_isa_dma_hangs(struct pci_dev *dev)
  70{
  71        if (!isa_dma_bridge_buggy) {
  72                isa_dma_bridge_buggy=1;
  73                dev_info(&dev->dev, "Activating ISA DMA hang workarounds\n");
  74        }
  75}
  76        /*
  77         * Its not totally clear which chipsets are the problematic ones
  78         * We know 82C586 and 82C596 variants are affected.
  79         */
  80DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_VIA,      PCI_DEVICE_ID_VIA_82C586_0,     quirk_isa_dma_hangs);
  81DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_VIA,      PCI_DEVICE_ID_VIA_82C596,       quirk_isa_dma_hangs);
  82DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL,    PCI_DEVICE_ID_INTEL_82371SB_0,  quirk_isa_dma_hangs);
  83DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AL,       PCI_DEVICE_ID_AL_M1533,         quirk_isa_dma_hangs);
  84DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_NEC,      PCI_DEVICE_ID_NEC_CBUS_1,       quirk_isa_dma_hangs);
  85DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_NEC,      PCI_DEVICE_ID_NEC_CBUS_2,       quirk_isa_dma_hangs);
  86DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_NEC,      PCI_DEVICE_ID_NEC_CBUS_3,       quirk_isa_dma_hangs);
  87
  88int pci_pci_problems;
  89EXPORT_SYMBOL(pci_pci_problems);
  90
  91/*
  92 *      Chipsets where PCI->PCI transfers vanish or hang
  93 */
  94static void __devinit quirk_nopcipci(struct pci_dev *dev)
  95{
  96        if ((pci_pci_problems & PCIPCI_FAIL)==0) {
  97                dev_info(&dev->dev, "Disabling direct PCI/PCI transfers\n");
  98                pci_pci_problems |= PCIPCI_FAIL;
  99        }
 100}
 101DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_SI,       PCI_DEVICE_ID_SI_5597,          quirk_nopcipci);
 102DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_SI,       PCI_DEVICE_ID_SI_496,           quirk_nopcipci);
 103
 104static void __devinit quirk_nopciamd(struct pci_dev *dev)
 105{
 106        u8 rev;
 107        pci_read_config_byte(dev, 0x08, &rev);
 108        if (rev == 0x13) {
 109                /* Erratum 24 */
 110                dev_info(&dev->dev, "Chipset erratum: Disabling direct PCI/AGP transfers\n");
 111                pci_pci_problems |= PCIAGP_FAIL;
 112        }
 113}
 114DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AMD,      PCI_DEVICE_ID_AMD_8151_0,       quirk_nopciamd);
 115
 116/*
 117 *      Triton requires workarounds to be used by the drivers
 118 */
 119static void __devinit quirk_triton(struct pci_dev *dev)
 120{
 121        if ((pci_pci_problems&PCIPCI_TRITON)==0) {
 122                dev_info(&dev->dev, "Limiting direct PCI/PCI transfers\n");
 123                pci_pci_problems |= PCIPCI_TRITON;
 124        }
 125}
 126DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL,    PCI_DEVICE_ID_INTEL_82437,      quirk_triton);
 127DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL,    PCI_DEVICE_ID_INTEL_82437VX,    quirk_triton);
 128DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL,    PCI_DEVICE_ID_INTEL_82439,      quirk_triton);
 129DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL,    PCI_DEVICE_ID_INTEL_82439TX,    quirk_triton);
 130
 131/*
 132 *      VIA Apollo KT133 needs PCI latency patch
 133 *      Made according to a windows driver based patch by George E. Breese
 134 *      see PCI Latency Adjust on http://www.viahardware.com/download/viatweak.shtm
 135 *      Also see http://www.au-ja.org/review-kt133a-1-en.phtml for
 136 *      the info on which Mr Breese based his work.
 137 *
 138 *      Updated based on further information from the site and also on
 139 *      information provided by VIA 
 140 */
 141static void quirk_vialatency(struct pci_dev *dev)
 142{
 143        struct pci_dev *p;
 144        u8 busarb;
 145        /* Ok we have a potential problem chipset here. Now see if we have
 146           a buggy southbridge */
 147           
 148        p = pci_get_device(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C686, NULL);
 149        if (p!=NULL) {
 150                /* 0x40 - 0x4f == 686B, 0x10 - 0x2f == 686A; thanks Dan Hollis */
 151                /* Check for buggy part revisions */
 152                if (p->revision < 0x40 || p->revision > 0x42)
 153                        goto exit;
 154        } else {
 155                p = pci_get_device(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8231, NULL);
 156                if (p==NULL)    /* No problem parts */
 157                        goto exit;
 158                /* Check for buggy part revisions */
 159                if (p->revision < 0x10 || p->revision > 0x12)
 160                        goto exit;
 161        }
 162        
 163        /*
 164         *      Ok we have the problem. Now set the PCI master grant to 
 165         *      occur every master grant. The apparent bug is that under high
 166         *      PCI load (quite common in Linux of course) you can get data
 167         *      loss when the CPU is held off the bus for 3 bus master requests
 168         *      This happens to include the IDE controllers....
 169         *
 170         *      VIA only apply this fix when an SB Live! is present but under
 171         *      both Linux and Windows this isnt enough, and we have seen
 172         *      corruption without SB Live! but with things like 3 UDMA IDE
 173         *      controllers. So we ignore that bit of the VIA recommendation..
 174         */
 175
 176        pci_read_config_byte(dev, 0x76, &busarb);
 177        /* Set bit 4 and bi 5 of byte 76 to 0x01 
 178           "Master priority rotation on every PCI master grant */
 179        busarb &= ~(1<<5);
 180        busarb |= (1<<4);
 181        pci_write_config_byte(dev, 0x76, busarb);
 182        dev_info(&dev->dev, "Applying VIA southbridge workaround\n");
 183exit:
 184        pci_dev_put(p);
 185}
 186DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_VIA,      PCI_DEVICE_ID_VIA_8363_0,       quirk_vialatency);
 187DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_VIA,      PCI_DEVICE_ID_VIA_8371_1,       quirk_vialatency);
 188DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_VIA,      PCI_DEVICE_ID_VIA_8361,         quirk_vialatency);
 189/* Must restore this on a resume from RAM */
 190DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_VIA,     PCI_DEVICE_ID_VIA_8363_0,       quirk_vialatency);
 191DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_VIA,     PCI_DEVICE_ID_VIA_8371_1,       quirk_vialatency);
 192DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_VIA,     PCI_DEVICE_ID_VIA_8361,         quirk_vialatency);
 193
 194/*
 195 *      VIA Apollo VP3 needs ETBF on BT848/878
 196 */
 197static void __devinit quirk_viaetbf(struct pci_dev *dev)
 198{
 199        if ((pci_pci_problems&PCIPCI_VIAETBF)==0) {
 200                dev_info(&dev->dev, "Limiting direct PCI/PCI transfers\n");
 201                pci_pci_problems |= PCIPCI_VIAETBF;
 202        }
 203}
 204DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_VIA,      PCI_DEVICE_ID_VIA_82C597_0,     quirk_viaetbf);
 205
 206static void __devinit quirk_vsfx(struct pci_dev *dev)
 207{
 208        if ((pci_pci_problems&PCIPCI_VSFX)==0) {
 209                dev_info(&dev->dev, "Limiting direct PCI/PCI transfers\n");
 210                pci_pci_problems |= PCIPCI_VSFX;
 211        }
 212}
 213DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_VIA,      PCI_DEVICE_ID_VIA_82C576,       quirk_vsfx);
 214
 215/*
 216 *      Ali Magik requires workarounds to be used by the drivers
 217 *      that DMA to AGP space. Latency must be set to 0xA and triton
 218 *      workaround applied too
 219 *      [Info kindly provided by ALi]
 220 */     
 221static void __init quirk_alimagik(struct pci_dev *dev)
 222{
 223        if ((pci_pci_problems&PCIPCI_ALIMAGIK)==0) {
 224                dev_info(&dev->dev, "Limiting direct PCI/PCI transfers\n");
 225                pci_pci_problems |= PCIPCI_ALIMAGIK|PCIPCI_TRITON;
 226        }
 227}
 228DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AL,       PCI_DEVICE_ID_AL_M1647,         quirk_alimagik);
 229DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AL,       PCI_DEVICE_ID_AL_M1651,         quirk_alimagik);
 230
 231/*
 232 *      Natoma has some interesting boundary conditions with Zoran stuff
 233 *      at least
 234 */
 235static void __devinit quirk_natoma(struct pci_dev *dev)
 236{
 237        if ((pci_pci_problems&PCIPCI_NATOMA)==0) {
 238                dev_info(&dev->dev, "Limiting direct PCI/PCI transfers\n");
 239                pci_pci_problems |= PCIPCI_NATOMA;
 240        }
 241}
 242DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL,    PCI_DEVICE_ID_INTEL_82441,      quirk_natoma);
 243DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL,    PCI_DEVICE_ID_INTEL_82443LX_0,  quirk_natoma);
 244DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL,    PCI_DEVICE_ID_INTEL_82443LX_1,  quirk_natoma);
 245DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL,    PCI_DEVICE_ID_INTEL_82443BX_0,  quirk_natoma);
 246DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL,    PCI_DEVICE_ID_INTEL_82443BX_1,  quirk_natoma);
 247DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL,    PCI_DEVICE_ID_INTEL_82443BX_2,  quirk_natoma);
 248
 249/*
 250 *  This chip can cause PCI parity errors if config register 0xA0 is read
 251 *  while DMAs are occurring.
 252 */
 253static void __devinit quirk_citrine(struct pci_dev *dev)
 254{
 255        dev->cfg_size = 0xA0;
 256}
 257DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_IBM,     PCI_DEVICE_ID_IBM_CITRINE,      quirk_citrine);
 258
 259/*
 260 *  S3 868 and 968 chips report region size equal to 32M, but they decode 64M.
 261 *  If it's needed, re-allocate the region.
 262 */
 263static void __devinit quirk_s3_64M(struct pci_dev *dev)
 264{
 265        struct resource *r = &dev->resource[0];
 266
 267        if ((r->start & 0x3ffffff) || r->end != r->start + 0x3ffffff) {
 268                r->start = 0;
 269                r->end = 0x3ffffff;
 270        }
 271}
 272DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_S3,      PCI_DEVICE_ID_S3_868,           quirk_s3_64M);
 273DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_S3,      PCI_DEVICE_ID_S3_968,           quirk_s3_64M);
 274
 275static void __devinit quirk_io_region(struct pci_dev *dev, unsigned region,
 276        unsigned size, int nr, const char *name)
 277{
 278        region &= ~(size-1);
 279        if (region) {
 280                struct pci_bus_region bus_region;
 281                struct resource *res = dev->resource + nr;
 282
 283                res->name = pci_name(dev);
 284                res->start = region;
 285                res->end = region + size - 1;
 286                res->flags = IORESOURCE_IO;
 287
 288                /* Convert from PCI bus to resource space.  */
 289                bus_region.start = res->start;
 290                bus_region.end = res->end;
 291                pcibios_bus_to_resource(dev, res, &bus_region);
 292
 293                pci_claim_resource(dev, nr);
 294                dev_info(&dev->dev, "quirk: region %04x-%04x claimed by %s\n", region, region + size - 1, name);
 295        }
 296}       
 297
 298/*
 299 *      ATI Northbridge setups MCE the processor if you even
 300 *      read somewhere between 0x3b0->0x3bb or read 0x3d3
 301 */
 302static void __devinit quirk_ati_exploding_mce(struct pci_dev *dev)
 303{
 304        dev_info(&dev->dev, "ATI Northbridge, reserving I/O ports 0x3b0 to 0x3bb\n");
 305        /* Mae rhaid i ni beidio ag edrych ar y lleoliadiau I/O hyn */
 306        request_region(0x3b0, 0x0C, "RadeonIGP");
 307        request_region(0x3d3, 0x01, "RadeonIGP");
 308}
 309DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_ATI,      PCI_DEVICE_ID_ATI_RS100,   quirk_ati_exploding_mce);
 310
 311/*
 312 * Let's make the southbridge information explicit instead
 313 * of having to worry about people probing the ACPI areas,
 314 * for example.. (Yes, it happens, and if you read the wrong
 315 * ACPI register it will put the machine to sleep with no
 316 * way of waking it up again. Bummer).
 317 *
 318 * ALI M7101: Two IO regions pointed to by words at
 319 *      0xE0 (64 bytes of ACPI registers)
 320 *      0xE2 (32 bytes of SMB registers)
 321 */
 322static void __devinit quirk_ali7101_acpi(struct pci_dev *dev)
 323{
 324        u16 region;
 325
 326        pci_read_config_word(dev, 0xE0, &region);
 327        quirk_io_region(dev, region, 64, PCI_BRIDGE_RESOURCES, "ali7101 ACPI");
 328        pci_read_config_word(dev, 0xE2, &region);
 329        quirk_io_region(dev, region, 32, PCI_BRIDGE_RESOURCES+1, "ali7101 SMB");
 330}
 331DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_AL,      PCI_DEVICE_ID_AL_M7101,         quirk_ali7101_acpi);
 332
 333static void piix4_io_quirk(struct pci_dev *dev, const char *name, unsigned int port, unsigned int enable)
 334{
 335        u32 devres;
 336        u32 mask, size, base;
 337
 338        pci_read_config_dword(dev, port, &devres);
 339        if ((devres & enable) != enable)
 340                return;
 341        mask = (devres >> 16) & 15;
 342        base = devres & 0xffff;
 343        size = 16;
 344        for (;;) {
 345                unsigned bit = size >> 1;
 346                if ((bit & mask) == bit)
 347                        break;
 348                size = bit;
 349        }
 350        /*
 351         * For now we only print it out. Eventually we'll want to
 352         * reserve it (at least if it's in the 0x1000+ range), but
 353         * let's get enough confirmation reports first. 
 354         */
 355        base &= -size;
 356        dev_info(&dev->dev, "%s PIO at %04x-%04x\n", name, base, base + size - 1);
 357}
 358
 359static void piix4_mem_quirk(struct pci_dev *dev, const char *name, unsigned int port, unsigned int enable)
 360{
 361        u32 devres;
 362        u32 mask, size, base;
 363
 364        pci_read_config_dword(dev, port, &devres);
 365        if ((devres & enable) != enable)
 366                return;
 367        base = devres & 0xffff0000;
 368        mask = (devres & 0x3f) << 16;
 369        size = 128 << 16;
 370        for (;;) {
 371                unsigned bit = size >> 1;
 372                if ((bit & mask) == bit)
 373                        break;
 374                size = bit;
 375        }
 376        /*
 377         * For now we only print it out. Eventually we'll want to
 378         * reserve it, but let's get enough confirmation reports first. 
 379         */
 380        base &= -size;
 381        dev_info(&dev->dev, "%s MMIO at %04x-%04x\n", name, base, base + size - 1);
 382}
 383
 384/*
 385 * PIIX4 ACPI: Two IO regions pointed to by longwords at
 386 *      0x40 (64 bytes of ACPI registers)
 387 *      0x90 (16 bytes of SMB registers)
 388 * and a few strange programmable PIIX4 device resources.
 389 */
 390static void __devinit quirk_piix4_acpi(struct pci_dev *dev)
 391{
 392        u32 region, res_a;
 393
 394        pci_read_config_dword(dev, 0x40, &region);
 395        quirk_io_region(dev, region, 64, PCI_BRIDGE_RESOURCES, "PIIX4 ACPI");
 396        pci_read_config_dword(dev, 0x90, &region);
 397        quirk_io_region(dev, region, 16, PCI_BRIDGE_RESOURCES+1, "PIIX4 SMB");
 398
 399        /* Device resource A has enables for some of the other ones */
 400        pci_read_config_dword(dev, 0x5c, &res_a);
 401
 402        piix4_io_quirk(dev, "PIIX4 devres B", 0x60, 3 << 21);
 403        piix4_io_quirk(dev, "PIIX4 devres C", 0x64, 3 << 21);
 404
 405        /* Device resource D is just bitfields for static resources */
 406
 407        /* Device 12 enabled? */
 408        if (res_a & (1 << 29)) {
 409                piix4_io_quirk(dev, "PIIX4 devres E", 0x68, 1 << 20);
 410                piix4_mem_quirk(dev, "PIIX4 devres F", 0x6c, 1 << 7);
 411        }
 412        /* Device 13 enabled? */
 413        if (res_a & (1 << 30)) {
 414                piix4_io_quirk(dev, "PIIX4 devres G", 0x70, 1 << 20);
 415                piix4_mem_quirk(dev, "PIIX4 devres H", 0x74, 1 << 7);
 416        }
 417        piix4_io_quirk(dev, "PIIX4 devres I", 0x78, 1 << 20);
 418        piix4_io_quirk(dev, "PIIX4 devres J", 0x7c, 1 << 20);
 419}
 420DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,   PCI_DEVICE_ID_INTEL_82371AB_3,  quirk_piix4_acpi);
 421DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,   PCI_DEVICE_ID_INTEL_82443MX_3,  quirk_piix4_acpi);
 422
 423#define ICH_PMBASE      0x40
 424#define ICH_ACPI_CNTL   0x44
 425#define  ICH4_ACPI_EN   0x10
 426#define  ICH6_ACPI_EN   0x80
 427#define ICH4_GPIOBASE   0x58
 428#define ICH4_GPIO_CNTL  0x5c
 429#define  ICH4_GPIO_EN   0x10
 430#define ICH6_GPIOBASE   0x48
 431#define ICH6_GPIO_CNTL  0x4c
 432#define  ICH6_GPIO_EN   0x10
 433
 434/*
 435 * ICH4, ICH4-M, ICH5, ICH5-M ACPI: Three IO regions pointed to by longwords at
 436 *      0x40 (128 bytes of ACPI, GPIO & TCO registers)
 437 *      0x58 (64 bytes of GPIO I/O space)
 438 */
 439static void __devinit quirk_ich4_lpc_acpi(struct pci_dev *dev)
 440{
 441        u32 region;
 442        u8 enable;
 443
 444        /*
 445         * The check for PCIBIOS_MIN_IO is to ensure we won't create a conflict
 446         * with low legacy (and fixed) ports. We don't know the decoding
 447         * priority and can't tell whether the legacy device or the one created
 448         * here is really at that address.  This happens on boards with broken
 449         * BIOSes.
 450        */
 451
 452        pci_read_config_byte(dev, ICH_ACPI_CNTL, &enable);
 453        if (enable & ICH4_ACPI_EN) {
 454                pci_read_config_dword(dev, ICH_PMBASE, &region);
 455                region &= PCI_BASE_ADDRESS_IO_MASK;
 456                if (region >= PCIBIOS_MIN_IO)
 457                        quirk_io_region(dev, region, 128, PCI_BRIDGE_RESOURCES,
 458                                        "ICH4 ACPI/GPIO/TCO");
 459        }
 460
 461        pci_read_config_byte(dev, ICH4_GPIO_CNTL, &enable);
 462        if (enable & ICH4_GPIO_EN) {
 463                pci_read_config_dword(dev, ICH4_GPIOBASE, &region);
 464                region &= PCI_BASE_ADDRESS_IO_MASK;
 465                if (region >= PCIBIOS_MIN_IO)
 466                        quirk_io_region(dev, region, 64,
 467                                        PCI_BRIDGE_RESOURCES + 1, "ICH4 GPIO");
 468        }
 469}
 470DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,    PCI_DEVICE_ID_INTEL_82801AA_0,         quirk_ich4_lpc_acpi);
 471DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,    PCI_DEVICE_ID_INTEL_82801AB_0,         quirk_ich4_lpc_acpi);
 472DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,    PCI_DEVICE_ID_INTEL_82801BA_0,         quirk_ich4_lpc_acpi);
 473DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,    PCI_DEVICE_ID_INTEL_82801BA_10,        quirk_ich4_lpc_acpi);
 474DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,    PCI_DEVICE_ID_INTEL_82801CA_0,         quirk_ich4_lpc_acpi);
 475DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,    PCI_DEVICE_ID_INTEL_82801CA_12,        quirk_ich4_lpc_acpi);
 476DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,    PCI_DEVICE_ID_INTEL_82801DB_0,         quirk_ich4_lpc_acpi);
 477DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,    PCI_DEVICE_ID_INTEL_82801DB_12,        quirk_ich4_lpc_acpi);
 478DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,    PCI_DEVICE_ID_INTEL_82801EB_0,         quirk_ich4_lpc_acpi);
 479DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,    PCI_DEVICE_ID_INTEL_ESB_1,             quirk_ich4_lpc_acpi);
 480
 481static void __devinit quirk_ich6_lpc_acpi(struct pci_dev *dev)
 482{
 483        u32 region;
 484        u8 enable;
 485
 486        pci_read_config_byte(dev, ICH_ACPI_CNTL, &enable);
 487        if (enable & ICH6_ACPI_EN) {
 488                pci_read_config_dword(dev, ICH_PMBASE, &region);
 489                region &= PCI_BASE_ADDRESS_IO_MASK;
 490                if (region >= PCIBIOS_MIN_IO)
 491                        quirk_io_region(dev, region, 128, PCI_BRIDGE_RESOURCES,
 492                                        "ICH6 ACPI/GPIO/TCO");
 493        }
 494
 495        pci_read_config_byte(dev, ICH6_GPIO_CNTL, &enable);
 496        if (enable & ICH4_GPIO_EN) {
 497                pci_read_config_dword(dev, ICH6_GPIOBASE, &region);
 498                region &= PCI_BASE_ADDRESS_IO_MASK;
 499                if (region >= PCIBIOS_MIN_IO)
 500                        quirk_io_region(dev, region, 64,
 501                                        PCI_BRIDGE_RESOURCES + 1, "ICH6 GPIO");
 502        }
 503}
 504DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,   PCI_DEVICE_ID_INTEL_ICH6_0, quirk_ich6_lpc_acpi);
 505DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,   PCI_DEVICE_ID_INTEL_ICH6_1, quirk_ich6_lpc_acpi);
 506DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,   PCI_DEVICE_ID_INTEL_ICH7_0, quirk_ich6_lpc_acpi);
 507DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,   PCI_DEVICE_ID_INTEL_ICH7_1, quirk_ich6_lpc_acpi);
 508DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,   PCI_DEVICE_ID_INTEL_ICH7_31, quirk_ich6_lpc_acpi);
 509DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,   PCI_DEVICE_ID_INTEL_ICH8_0, quirk_ich6_lpc_acpi);
 510DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,   PCI_DEVICE_ID_INTEL_ICH8_2, quirk_ich6_lpc_acpi);
 511DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,   PCI_DEVICE_ID_INTEL_ICH8_3, quirk_ich6_lpc_acpi);
 512DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,   PCI_DEVICE_ID_INTEL_ICH8_1, quirk_ich6_lpc_acpi);
 513DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,   PCI_DEVICE_ID_INTEL_ICH8_4, quirk_ich6_lpc_acpi);
 514DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,   PCI_DEVICE_ID_INTEL_ICH9_2, quirk_ich6_lpc_acpi);
 515DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,   PCI_DEVICE_ID_INTEL_ICH9_4, quirk_ich6_lpc_acpi);
 516DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,   PCI_DEVICE_ID_INTEL_ICH9_7, quirk_ich6_lpc_acpi);
 517DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,   PCI_DEVICE_ID_INTEL_ICH9_8, quirk_ich6_lpc_acpi);
 518
 519/*
 520 * VIA ACPI: One IO region pointed to by longword at
 521 *      0x48 or 0x20 (256 bytes of ACPI registers)
 522 */
 523static void __devinit quirk_vt82c586_acpi(struct pci_dev *dev)
 524{
 525        u32 region;
 526
 527        if (dev->revision & 0x10) {
 528                pci_read_config_dword(dev, 0x48, &region);
 529                region &= PCI_BASE_ADDRESS_IO_MASK;
 530                quirk_io_region(dev, region, 256, PCI_BRIDGE_RESOURCES, "vt82c586 ACPI");
 531        }
 532}
 533DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA,     PCI_DEVICE_ID_VIA_82C586_3,     quirk_vt82c586_acpi);
 534
 535/*
 536 * VIA VT82C686 ACPI: Three IO region pointed to by (long)words at
 537 *      0x48 (256 bytes of ACPI registers)
 538 *      0x70 (128 bytes of hardware monitoring register)
 539 *      0x90 (16 bytes of SMB registers)
 540 */
 541static void __devinit quirk_vt82c686_acpi(struct pci_dev *dev)
 542{
 543        u16 hm;
 544        u32 smb;
 545
 546        quirk_vt82c586_acpi(dev);
 547
 548        pci_read_config_word(dev, 0x70, &hm);
 549        hm &= PCI_BASE_ADDRESS_IO_MASK;
 550        quirk_io_region(dev, hm, 128, PCI_BRIDGE_RESOURCES + 1, "vt82c686 HW-mon");
 551
 552        pci_read_config_dword(dev, 0x90, &smb);
 553        smb &= PCI_BASE_ADDRESS_IO_MASK;
 554        quirk_io_region(dev, smb, 16, PCI_BRIDGE_RESOURCES + 2, "vt82c686 SMB");
 555}
 556DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA,     PCI_DEVICE_ID_VIA_82C686_4,     quirk_vt82c686_acpi);
 557
 558/*
 559 * VIA VT8235 ISA Bridge: Two IO regions pointed to by words at
 560 *      0x88 (128 bytes of power management registers)
 561 *      0xd0 (16 bytes of SMB registers)
 562 */
 563static void __devinit quirk_vt8235_acpi(struct pci_dev *dev)
 564{
 565        u16 pm, smb;
 566
 567        pci_read_config_word(dev, 0x88, &pm);
 568        pm &= PCI_BASE_ADDRESS_IO_MASK;
 569        quirk_io_region(dev, pm, 128, PCI_BRIDGE_RESOURCES, "vt8235 PM");
 570
 571        pci_read_config_word(dev, 0xd0, &smb);
 572        smb &= PCI_BASE_ADDRESS_IO_MASK;
 573        quirk_io_region(dev, smb, 16, PCI_BRIDGE_RESOURCES + 1, "vt8235 SMB");
 574}
 575DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA,     PCI_DEVICE_ID_VIA_8235, quirk_vt8235_acpi);
 576
 577
 578#ifdef CONFIG_X86_IO_APIC 
 579
 580#include <asm/io_apic.h>
 581
 582/*
 583 * VIA 686A/B: If an IO-APIC is active, we need to route all on-chip
 584 * devices to the external APIC.
 585 *
 586 * TODO: When we have device-specific interrupt routers,
 587 * this code will go away from quirks.
 588 */
 589static void quirk_via_ioapic(struct pci_dev *dev)
 590{
 591        u8 tmp;
 592        
 593        if (nr_ioapics < 1)
 594                tmp = 0;    /* nothing routed to external APIC */
 595        else
 596                tmp = 0x1f; /* all known bits (4-0) routed to external APIC */
 597                
 598        dev_info(&dev->dev, "%sbling VIA external APIC routing\n",
 599               tmp == 0 ? "Disa" : "Ena");
 600
 601        /* Offset 0x58: External APIC IRQ output control */
 602        pci_write_config_byte (dev, 0x58, tmp);
 603}
 604DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_VIA,      PCI_DEVICE_ID_VIA_82C686,       quirk_via_ioapic);
 605DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_VIA,       PCI_DEVICE_ID_VIA_82C686,       quirk_via_ioapic);
 606
 607/*
 608 * VIA 8237: Some BIOSs don't set the 'Bypass APIC De-Assert Message' Bit.
 609 * This leads to doubled level interrupt rates.
 610 * Set this bit to get rid of cycle wastage.
 611 * Otherwise uncritical.
 612 */
 613static void quirk_via_vt8237_bypass_apic_deassert(struct pci_dev *dev)
 614{
 615        u8 misc_control2;
 616#define BYPASS_APIC_DEASSERT 8
 617
 618        pci_read_config_byte(dev, 0x5B, &misc_control2);
 619        if (!(misc_control2 & BYPASS_APIC_DEASSERT)) {
 620                dev_info(&dev->dev, "Bypassing VIA 8237 APIC De-Assert Message\n");
 621                pci_write_config_byte(dev, 0x5B, misc_control2|BYPASS_APIC_DEASSERT);
 622        }
 623}
 624DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_VIA,      PCI_DEVICE_ID_VIA_8237,         quirk_via_vt8237_bypass_apic_deassert);
 625DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_VIA,       PCI_DEVICE_ID_VIA_8237,         quirk_via_vt8237_bypass_apic_deassert);
 626
 627/*
 628 * The AMD io apic can hang the box when an apic irq is masked.
 629 * We check all revs >= B0 (yet not in the pre production!) as the bug
 630 * is currently marked NoFix
 631 *
 632 * We have multiple reports of hangs with this chipset that went away with
 633 * noapic specified. For the moment we assume it's the erratum. We may be wrong
 634 * of course. However the advice is demonstrably good even if so..
 635 */
 636static void __devinit quirk_amd_ioapic(struct pci_dev *dev)
 637{
 638        if (dev->revision >= 0x02) {
 639                dev_warn(&dev->dev, "I/O APIC: AMD Erratum #22 may be present. In the event of instability try\n");
 640                dev_warn(&dev->dev, "        : booting with the \"noapic\" option\n");
 641        }
 642}
 643DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AMD,      PCI_DEVICE_ID_AMD_VIPER_7410,   quirk_amd_ioapic);
 644
 645static void __init quirk_ioapic_rmw(struct pci_dev *dev)
 646{
 647        if (dev->devfn == 0 && dev->bus->number == 0)
 648                sis_apic_bug = 1;
 649}
 650DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_SI,       PCI_ANY_ID,                     quirk_ioapic_rmw);
 651
 652#define AMD8131_revA0        0x01
 653#define AMD8131_revB0        0x11
 654#define AMD8131_MISC         0x40
 655#define AMD8131_NIOAMODE_BIT 0
 656static void quirk_amd_8131_ioapic(struct pci_dev *dev)
 657{ 
 658        unsigned char tmp;
 659        
 660        if (nr_ioapics == 0) 
 661                return;
 662
 663        if (dev->revision == AMD8131_revA0 || dev->revision == AMD8131_revB0) {
 664                dev_info(&dev->dev, "Fixing up AMD8131 IOAPIC mode\n");
 665                pci_read_config_byte( dev, AMD8131_MISC, &tmp);
 666                tmp &= ~(1 << AMD8131_NIOAMODE_BIT);
 667                pci_write_config_byte( dev, AMD8131_MISC, tmp);
 668        }
 669} 
 670DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_8131_BRIDGE, quirk_amd_8131_ioapic);
 671DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_8131_BRIDGE, quirk_amd_8131_ioapic);
 672#endif /* CONFIG_X86_IO_APIC */
 673
 674/*
 675 * Some settings of MMRBC can lead to data corruption so block changes.
 676 * See AMD 8131 HyperTransport PCI-X Tunnel Revision Guide
 677 */
 678static void __init quirk_amd_8131_mmrbc(struct pci_dev *dev)
 679{
 680        if (dev->subordinate && dev->revision <= 0x12) {
 681                dev_info(&dev->dev, "AMD8131 rev %x detected; "
 682                        "disabling PCI-X MMRBC\n", dev->revision);
 683                dev->subordinate->bus_flags |= PCI_BUS_FLAGS_NO_MMRBC;
 684        }
 685}
 686DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_8131_BRIDGE, quirk_amd_8131_mmrbc);
 687
 688/*
 689 * FIXME: it is questionable that quirk_via_acpi
 690 * is needed.  It shows up as an ISA bridge, and does not
 691 * support the PCI_INTERRUPT_LINE register at all.  Therefore
 692 * it seems like setting the pci_dev's 'irq' to the
 693 * value of the ACPI SCI interrupt is only done for convenience.
 694 *      -jgarzik
 695 */
 696static void __devinit quirk_via_acpi(struct pci_dev *d)
 697{
 698        /*
 699         * VIA ACPI device: SCI IRQ line in PCI config byte 0x42
 700         */
 701        u8 irq;
 702        pci_read_config_byte(d, 0x42, &irq);
 703        irq &= 0xf;
 704        if (irq && (irq != 2))
 705                d->irq = irq;
 706}
 707DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA,     PCI_DEVICE_ID_VIA_82C586_3,     quirk_via_acpi);
 708DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA,     PCI_DEVICE_ID_VIA_82C686_4,     quirk_via_acpi);
 709
 710
 711/*
 712 *      VIA bridges which have VLink
 713 */
 714
 715static int via_vlink_dev_lo = -1, via_vlink_dev_hi = 18;
 716
 717static void quirk_via_bridge(struct pci_dev *dev)
 718{
 719        /* See what bridge we have and find the device ranges */
 720        switch (dev->device) {
 721        case PCI_DEVICE_ID_VIA_82C686:
 722                /* The VT82C686 is special, it attaches to PCI and can have
 723                   any device number. All its subdevices are functions of
 724                   that single device. */
 725                via_vlink_dev_lo = PCI_SLOT(dev->devfn);
 726                via_vlink_dev_hi = PCI_SLOT(dev->devfn);
 727                break;
 728        case PCI_DEVICE_ID_VIA_8237:
 729        case PCI_DEVICE_ID_VIA_8237A:
 730                via_vlink_dev_lo = 15;
 731                break;
 732        case PCI_DEVICE_ID_VIA_8235:
 733                via_vlink_dev_lo = 16;
 734                break;
 735        case PCI_DEVICE_ID_VIA_8231:
 736        case PCI_DEVICE_ID_VIA_8233_0:
 737        case PCI_DEVICE_ID_VIA_8233A:
 738        case PCI_DEVICE_ID_VIA_8233C_0:
 739                via_vlink_dev_lo = 17;
 740                break;
 741        }
 742}
 743DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA,     PCI_DEVICE_ID_VIA_82C686,       quirk_via_bridge);
 744DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA,     PCI_DEVICE_ID_VIA_8231,         quirk_via_bridge);
 745DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA,     PCI_DEVICE_ID_VIA_8233_0,       quirk_via_bridge);
 746DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA,     PCI_DEVICE_ID_VIA_8233A,        quirk_via_bridge);
 747DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA,     PCI_DEVICE_ID_VIA_8233C_0,      quirk_via_bridge);
 748DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA,     PCI_DEVICE_ID_VIA_8235,         quirk_via_bridge);
 749DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA,     PCI_DEVICE_ID_VIA_8237,         quirk_via_bridge);
 750DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA,     PCI_DEVICE_ID_VIA_8237A,        quirk_via_bridge);
 751
 752/**
 753 *      quirk_via_vlink         -       VIA VLink IRQ number update
 754 *      @dev: PCI device
 755 *
 756 *      If the device we are dealing with is on a PIC IRQ we need to
 757 *      ensure that the IRQ line register which usually is not relevant
 758 *      for PCI cards, is actually written so that interrupts get sent
 759 *      to the right place.
 760 *      We only do this on systems where a VIA south bridge was detected,
 761 *      and only for VIA devices on the motherboard (see quirk_via_bridge
 762 *      above).
 763 */
 764
 765static void quirk_via_vlink(struct pci_dev *dev)
 766{
 767        u8 irq, new_irq;
 768
 769        /* Check if we have VLink at all */
 770        if (via_vlink_dev_lo == -1)
 771                return;
 772
 773        new_irq = dev->irq;
 774
 775        /* Don't quirk interrupts outside the legacy IRQ range */
 776        if (!new_irq || new_irq > 15)
 777                return;
 778
 779        /* Internal device ? */
 780        if (dev->bus->number != 0 || PCI_SLOT(dev->devfn) > via_vlink_dev_hi ||
 781            PCI_SLOT(dev->devfn) < via_vlink_dev_lo)
 782                return;
 783
 784        /* This is an internal VLink device on a PIC interrupt. The BIOS
 785           ought to have set this but may not have, so we redo it */
 786
 787        pci_read_config_byte(dev, PCI_INTERRUPT_LINE, &irq);
 788        if (new_irq != irq) {
 789                dev_info(&dev->dev, "VIA VLink IRQ fixup, from %d to %d\n",
 790                        irq, new_irq);
 791                udelay(15);     /* unknown if delay really needed */
 792                pci_write_config_byte(dev, PCI_INTERRUPT_LINE, new_irq);
 793        }
 794}
 795DECLARE_PCI_FIXUP_ENABLE(PCI_VENDOR_ID_VIA, PCI_ANY_ID, quirk_via_vlink);
 796
 797/*
 798 * VIA VT82C598 has its device ID settable and many BIOSes
 799 * set it to the ID of VT82C597 for backward compatibility.
 800 * We need to switch it off to be able to recognize the real
 801 * type of the chip.
 802 */
 803static void __devinit quirk_vt82c598_id(struct pci_dev *dev)
 804{
 805        pci_write_config_byte(dev, 0xfc, 0);
 806        pci_read_config_word(dev, PCI_DEVICE_ID, &dev->device);
 807}
 808DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA,     PCI_DEVICE_ID_VIA_82C597_0,     quirk_vt82c598_id);
 809
 810/*
 811 * CardBus controllers have a legacy base address that enables them
 812 * to respond as i82365 pcmcia controllers.  We don't want them to
 813 * do this even if the Linux CardBus driver is not loaded, because
 814 * the Linux i82365 driver does not (and should not) handle CardBus.
 815 */
 816static void quirk_cardbus_legacy(struct pci_dev *dev)
 817{
 818        if ((PCI_CLASS_BRIDGE_CARDBUS << 8) ^ dev->class)
 819                return;
 820        pci_write_config_dword(dev, PCI_CB_LEGACY_MODE_BASE, 0);
 821}
 822DECLARE_PCI_FIXUP_FINAL(PCI_ANY_ID, PCI_ANY_ID, quirk_cardbus_legacy);
 823DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_ANY_ID, PCI_ANY_ID, quirk_cardbus_legacy);
 824
 825/*
 826 * Following the PCI ordering rules is optional on the AMD762. I'm not
 827 * sure what the designers were smoking but let's not inhale...
 828 *
 829 * To be fair to AMD, it follows the spec by default, its BIOS people
 830 * who turn it off!
 831 */
 832static void quirk_amd_ordering(struct pci_dev *dev)
 833{
 834        u32 pcic;
 835        pci_read_config_dword(dev, 0x4C, &pcic);
 836        if ((pcic&6)!=6) {
 837                pcic |= 6;
 838                dev_warn(&dev->dev, "BIOS failed to enable PCI standards compliance; fixing this error\n");
 839                pci_write_config_dword(dev, 0x4C, pcic);
 840                pci_read_config_dword(dev, 0x84, &pcic);
 841                pcic |= (1<<23);        /* Required in this mode */
 842                pci_write_config_dword(dev, 0x84, pcic);
 843        }
 844}
 845DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AMD,      PCI_DEVICE_ID_AMD_FE_GATE_700C, quirk_amd_ordering);
 846DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_AMD,       PCI_DEVICE_ID_AMD_FE_GATE_700C, quirk_amd_ordering);
 847
 848/*
 849 *      DreamWorks provided workaround for Dunord I-3000 problem
 850 *
 851 *      This card decodes and responds to addresses not apparently
 852 *      assigned to it. We force a larger allocation to ensure that
 853 *      nothing gets put too close to it.
 854 */
 855static void __devinit quirk_dunord ( struct pci_dev * dev )
 856{
 857        struct resource *r = &dev->resource [1];
 858        r->start = 0;
 859        r->end = 0xffffff;
 860}
 861DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_DUNORD,  PCI_DEVICE_ID_DUNORD_I3000,     quirk_dunord);
 862
 863/*
 864 * i82380FB mobile docking controller: its PCI-to-PCI bridge
 865 * is subtractive decoding (transparent), and does indicate this
 866 * in the ProgIf. Unfortunately, the ProgIf value is wrong - 0x80
 867 * instead of 0x01.
 868 */
 869static void __devinit quirk_transparent_bridge(struct pci_dev *dev)
 870{
 871        dev->transparent = 1;
 872}
 873DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,   PCI_DEVICE_ID_INTEL_82380FB,    quirk_transparent_bridge);
 874DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_TOSHIBA, 0x605,  quirk_transparent_bridge);
 875
 876/*
 877 * Common misconfiguration of the MediaGX/Geode PCI master that will
 878 * reduce PCI bandwidth from 70MB/s to 25MB/s.  See the GXM/GXLV/GX1
 879 * datasheets found at http://www.national.com/ds/GX for info on what
 880 * these bits do.  <christer@weinigel.se>
 881 */
 882static void quirk_mediagx_master(struct pci_dev *dev)
 883{
 884        u8 reg;
 885        pci_read_config_byte(dev, 0x41, &reg);
 886        if (reg & 2) {
 887                reg &= ~2;
 888                dev_info(&dev->dev, "Fixup for MediaGX/Geode Slave Disconnect Boundary (0x41=0x%02x)\n", reg);
 889                pci_write_config_byte(dev, 0x41, reg);
 890        }
 891}
 892DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_CYRIX,    PCI_DEVICE_ID_CYRIX_PCI_MASTER, quirk_mediagx_master);
 893DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_CYRIX,   PCI_DEVICE_ID_CYRIX_PCI_MASTER, quirk_mediagx_master);
 894
 895/*
 896 *      Ensure C0 rev restreaming is off. This is normally done by
 897 *      the BIOS but in the odd case it is not the results are corruption
 898 *      hence the presence of a Linux check
 899 */
 900static void quirk_disable_pxb(struct pci_dev *pdev)
 901{
 902        u16 config;
 903        
 904        if (pdev->revision != 0x04)             /* Only C0 requires this */
 905                return;
 906        pci_read_config_word(pdev, 0x40, &config);
 907        if (config & (1<<6)) {
 908                config &= ~(1<<6);
 909                pci_write_config_word(pdev, 0x40, config);
 910                dev_info(&pdev->dev, "C0 revision 450NX. Disabling PCI restreaming\n");
 911        }
 912}
 913DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL,    PCI_DEVICE_ID_INTEL_82454NX,    quirk_disable_pxb);
 914DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_INTEL,     PCI_DEVICE_ID_INTEL_82454NX,    quirk_disable_pxb);
 915
 916static void __devinit quirk_amd_ide_mode(struct pci_dev *pdev)
 917{
 918        /* set sb600/sb700/sb800 sata to ahci mode */
 919        u8 tmp;
 920
 921        pci_read_config_byte(pdev, PCI_CLASS_DEVICE, &tmp);
 922        if (tmp == 0x01) {
 923                pci_read_config_byte(pdev, 0x40, &tmp);
 924                pci_write_config_byte(pdev, 0x40, tmp|1);
 925                pci_write_config_byte(pdev, 0x9, 1);
 926                pci_write_config_byte(pdev, 0xa, 6);
 927                pci_write_config_byte(pdev, 0x40, tmp);
 928
 929                pdev->class = PCI_CLASS_STORAGE_SATA_AHCI;
 930                dev_info(&pdev->dev, "set SATA to AHCI mode\n");
 931        }
 932}
 933DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP600_SATA, quirk_amd_ide_mode);
 934DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP600_SATA, quirk_amd_ide_mode);
 935DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP700_SATA, quirk_amd_ide_mode);
 936DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP700_SATA, quirk_amd_ide_mode);
 937
 938/*
 939 *      Serverworks CSB5 IDE does not fully support native mode
 940 */
 941static void __devinit quirk_svwks_csb5ide(struct pci_dev *pdev)
 942{
 943        u8 prog;
 944        pci_read_config_byte(pdev, PCI_CLASS_PROG, &prog);
 945        if (prog & 5) {
 946                prog &= ~5;
 947                pdev->class &= ~5;
 948                pci_write_config_byte(pdev, PCI_CLASS_PROG, prog);
 949                /* PCI layer will sort out resources */
 950        }
 951}
 952DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_SERVERWORKS, PCI_DEVICE_ID_SERVERWORKS_CSB5IDE, quirk_svwks_csb5ide);
 953
 954/*
 955 *      Intel 82801CAM ICH3-M datasheet says IDE modes must be the same
 956 */
 957static void __init quirk_ide_samemode(struct pci_dev *pdev)
 958{
 959        u8 prog;
 960
 961        pci_read_config_byte(pdev, PCI_CLASS_PROG, &prog);
 962
 963        if (((prog & 1) && !(prog & 4)) || ((prog & 4) && !(prog & 1))) {
 964                dev_info(&pdev->dev, "IDE mode mismatch; forcing legacy mode\n");
 965                prog &= ~5;
 966                pdev->class &= ~5;
 967                pci_write_config_byte(pdev, PCI_CLASS_PROG, prog);
 968        }
 969}
 970DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_10, quirk_ide_samemode);
 971
 972/*
 973 * Some ATA devices break if put into D3
 974 */
 975
 976static void __devinit quirk_no_ata_d3(struct pci_dev *pdev)
 977{
 978        /* Quirk the legacy ATA devices only. The AHCI ones are ok */
 979        if ((pdev->class >> 8) == PCI_CLASS_STORAGE_IDE)
 980                pdev->dev_flags |= PCI_DEV_FLAGS_NO_D3;
 981}
 982DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_SERVERWORKS, PCI_ANY_ID, quirk_no_ata_d3);
 983DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_ATI, PCI_ANY_ID, quirk_no_ata_d3);
 984
 985/* This was originally an Alpha specific thing, but it really fits here.
 986 * The i82375 PCI/EISA bridge appears as non-classified. Fix that.
 987 */
 988static void __init quirk_eisa_bridge(struct pci_dev *dev)
 989{
 990        dev->class = PCI_CLASS_BRIDGE_EISA << 8;
 991}
 992DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,   PCI_DEVICE_ID_INTEL_82375,      quirk_eisa_bridge);
 993
 994
 995/*
 996 * On ASUS P4B boards, the SMBus PCI Device within the ICH2/4 southbridge
 997 * is not activated. The myth is that Asus said that they do not want the
 998 * users to be irritated by just another PCI Device in the Win98 device
 999 * manager. (see the file prog/hotplug/README.p4b in the lm_sensors 
1000 * package 2.7.0 for details)
1001 *
1002 * The SMBus PCI Device can be activated by setting a bit in the ICH LPC 
1003 * bridge. Unfortunately, this device has no subvendor/subdevice ID. So it 
1004 * becomes necessary to do this tweak in two steps -- the chosen trigger
1005 * is either the Host bridge (preferred) or on-board VGA controller.
1006 *
1007 * Note that we used to unhide the SMBus that way on Toshiba laptops
1008 * (Satellite A40 and Tecra M2) but then found that the thermal management
1009 * was done by SMM code, which could cause unsynchronized concurrent
1010 * accesses to the SMBus registers, with potentially bad effects. Thus you
1011 * should be very careful when adding new entries: if SMM is accessing the
1012 * Intel SMBus, this is a very good reason to leave it hidden.
1013 *
1014 * Likewise, many recent laptops use ACPI for thermal management. If the
1015 * ACPI DSDT code accesses the SMBus, then Linux should not access it
1016 * natively, and keeping the SMBus hidden is the right thing to do. If you
1017 * are about to add an entry in the table below, please first disassemble
1018 * the DSDT and double-check that there is no code accessing the SMBus.
1019 */
1020static int asus_hides_smbus;
1021
1022static void __init asus_hides_smbus_hostbridge(struct pci_dev *dev)
1023{
1024        if (unlikely(dev->subsystem_vendor == PCI_VENDOR_ID_ASUSTEK)) {
1025                if (dev->device == PCI_DEVICE_ID_INTEL_82845_HB)
1026                        switch(dev->subsystem_device) {
1027                        case 0x8025: /* P4B-LX */
1028                        case 0x8070: /* P4B */
1029                        case 0x8088: /* P4B533 */
1030                        case 0x1626: /* L3C notebook */
1031                                asus_hides_smbus = 1;
1032                        }
1033                else if (dev->device == PCI_DEVICE_ID_INTEL_82845G_HB)
1034                        switch(dev->subsystem_device) {
1035                        case 0x80b1: /* P4GE-V */
1036                        case 0x80b2: /* P4PE */
1037                        case 0x8093: /* P4B533-V */
1038                                asus_hides_smbus = 1;
1039                        }
1040                else if (dev->device == PCI_DEVICE_ID_INTEL_82850_HB)
1041                        switch(dev->subsystem_device) {
1042                        case 0x8030: /* P4T533 */
1043                                asus_hides_smbus = 1;
1044                        }
1045                else if (dev->device == PCI_DEVICE_ID_INTEL_7205_0)
1046                        switch (dev->subsystem_device) {
1047                        case 0x8070: /* P4G8X Deluxe */
1048                                asus_hides_smbus = 1;
1049                        }
1050                else if (dev->device == PCI_DEVICE_ID_INTEL_E7501_MCH)
1051                        switch (dev->subsystem_device) {
1052                        case 0x80c9: /* PU-DLS */
1053                                asus_hides_smbus = 1;
1054                        }
1055                else if (dev->device == PCI_DEVICE_ID_INTEL_82855GM_HB)
1056                        switch (dev->subsystem_device) {
1057                        case 0x1751: /* M2N notebook */
1058                        case 0x1821: /* M5N notebook */
1059                                asus_hides_smbus = 1;
1060                        }
1061                else if (dev->device == PCI_DEVICE_ID_INTEL_82855PM_HB)
1062                        switch (dev->subsystem_device) {
1063                        case 0x184b: /* W1N notebook */
1064                        case 0x186a: /* M6Ne notebook */
1065                                asus_hides_smbus = 1;
1066                        }
1067                else if (dev->device == PCI_DEVICE_ID_INTEL_82865_HB)
1068                        switch (dev->subsystem_device) {
1069                        case 0x80f2: /* P4P800-X */
1070                                asus_hides_smbus = 1;
1071                        }
1072                else if (dev->device == PCI_DEVICE_ID_INTEL_82915GM_HB)
1073                        switch (dev->subsystem_device) {
1074                        case 0x1882: /* M6V notebook */
1075                        case 0x1977: /* A6VA notebook */
1076                                asus_hides_smbus = 1;
1077                        }
1078        } else if (unlikely(dev->subsystem_vendor == PCI_VENDOR_ID_HP)) {
1079                if (dev->device ==  PCI_DEVICE_ID_INTEL_82855PM_HB)
1080                        switch(dev->subsystem_device) {
1081                        case 0x088C: /* HP Compaq nc8000 */
1082                        case 0x0890: /* HP Compaq nc6000 */
1083                                asus_hides_smbus = 1;
1084                        }
1085                else if (dev->device == PCI_DEVICE_ID_INTEL_82865_HB)
1086                        switch (dev->subsystem_device) {
1087                        case 0x12bc: /* HP D330L */
1088                        case 0x12bd: /* HP D530 */
1089                                asus_hides_smbus = 1;
1090                        }
1091                else if (dev->device == PCI_DEVICE_ID_INTEL_82875_HB)
1092                        switch (dev->subsystem_device) {
1093                        case 0x12bf: /* HP xw4100 */
1094                                asus_hides_smbus = 1;
1095                        }
1096       } else if (unlikely(dev->subsystem_vendor == PCI_VENDOR_ID_SAMSUNG)) {
1097               if (dev->device ==  PCI_DEVICE_ID_INTEL_82855PM_HB)
1098                       switch(dev->subsystem_device) {
1099                       case 0xC00C: /* Samsung P35 notebook */
1100                               asus_hides_smbus = 1;
1101                       }
1102        } else if (unlikely(dev->subsystem_vendor == PCI_VENDOR_ID_COMPAQ)) {
1103                if (dev->device == PCI_DEVICE_ID_INTEL_82855PM_HB)
1104                        switch(dev->subsystem_device) {
1105                        case 0x0058: /* Compaq Evo N620c */
1106                                asus_hides_smbus = 1;
1107                        }
1108                else if (dev->device == PCI_DEVICE_ID_INTEL_82810_IG3)
1109                        switch(dev->subsystem_device) {
1110                        case 0xB16C: /* Compaq Deskpro EP 401963-001 (PCA# 010174) */
1111                                /* Motherboard doesn't have Host bridge
1112                                 * subvendor/subdevice IDs, therefore checking
1113                                 * its on-board VGA controller */
1114                                asus_hides_smbus = 1;
1115                        }
1116                else if (dev->device == PCI_DEVICE_ID_INTEL_82845G_IG)
1117                        switch(dev->subsystem_device) {
1118                        case 0x00b8: /* Compaq Evo D510 CMT */
1119                        case 0x00b9: /* Compaq Evo D510 SFF */
1120                                asus_hides_smbus = 1;
1121                        }
1122                else if (dev->device == PCI_DEVICE_ID_INTEL_82815_CGC)
1123                        switch (dev->subsystem_device) {
1124                        case 0x001A: /* Compaq Deskpro EN SSF P667 815E */
1125                                /* Motherboard doesn't have host bridge
1126                                 * subvendor/subdevice IDs, therefore checking
1127                                 * its on-board VGA controller */
1128                                asus_hides_smbus = 1;
1129                        }
1130        }
1131}
1132DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,   PCI_DEVICE_ID_INTEL_82845_HB,   asus_hides_smbus_hostbridge);
1133DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,   PCI_DEVICE_ID_INTEL_82845G_HB,  asus_hides_smbus_hostbridge);
1134DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,   PCI_DEVICE_ID_INTEL_82850_HB,   asus_hides_smbus_hostbridge);
1135DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,   PCI_DEVICE_ID_INTEL_82865_HB,   asus_hides_smbus_hostbridge);
1136DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,   PCI_DEVICE_ID_INTEL_82875_HB,   asus_hides_smbus_hostbridge);
1137DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,   PCI_DEVICE_ID_INTEL_7205_0,     asus_hides_smbus_hostbridge);
1138DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,   PCI_DEVICE_ID_INTEL_E7501_MCH,  asus_hides_smbus_hostbridge);
1139DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,   PCI_DEVICE_ID_INTEL_82855PM_HB, asus_hides_smbus_hostbridge);
1140DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,   PCI_DEVICE_ID_INTEL_82855GM_HB, asus_hides_smbus_hostbridge);
1141DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,   PCI_DEVICE_ID_INTEL_82915GM_HB, asus_hides_smbus_hostbridge);
1142
1143DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,   PCI_DEVICE_ID_INTEL_82810_IG3,  asus_hides_smbus_hostbridge);
1144DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,   PCI_DEVICE_ID_INTEL_82845G_IG,  asus_hides_smbus_hostbridge);
1145DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,   PCI_DEVICE_ID_INTEL_82815_CGC,  asus_hides_smbus_hostbridge);
1146
1147static void asus_hides_smbus_lpc(struct pci_dev *dev)
1148{
1149        u16 val;
1150        
1151        if (likely(!asus_hides_smbus))
1152                return;
1153
1154        pci_read_config_word(dev, 0xF2, &val);
1155        if (val & 0x8) {
1156                pci_write_config_word(dev, 0xF2, val & (~0x8));
1157                pci_read_config_word(dev, 0xF2, &val);
1158                if (val & 0x8)
1159                        dev_info(&dev->dev, "i801 SMBus device continues to play 'hide and seek'! 0x%x\n", val);
1160                else
1161                        dev_info(&dev->dev, "Enabled i801 SMBus device\n");
1162        }
1163}
1164DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,   PCI_DEVICE_ID_INTEL_82801AA_0,  asus_hides_smbus_lpc);
1165DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,   PCI_DEVICE_ID_INTEL_82801DB_0,  asus_hides_smbus_lpc);
1166DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,   PCI_DEVICE_ID_INTEL_82801BA_0,  asus_hides_smbus_lpc);
1167DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,   PCI_DEVICE_ID_INTEL_82801CA_0,  asus_hides_smbus_lpc);
1168DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,   PCI_DEVICE_ID_INTEL_82801CA_12, asus_hides_smbus_lpc);
1169DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,   PCI_DEVICE_ID_INTEL_82801DB_12, asus_hides_smbus_lpc);
1170DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,   PCI_DEVICE_ID_INTEL_82801EB_0,  asus_hides_smbus_lpc);
1171DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_INTEL,     PCI_DEVICE_ID_INTEL_82801AA_0,  asus_hides_smbus_lpc);
1172DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_INTEL,     PCI_DEVICE_ID_INTEL_82801DB_0,  asus_hides_smbus_lpc);
1173DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_INTEL,     PCI_DEVICE_ID_INTEL_82801BA_0,  asus_hides_smbus_lpc);
1174DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_INTEL,     PCI_DEVICE_ID_INTEL_82801CA_0,  asus_hides_smbus_lpc);
1175DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_INTEL,     PCI_DEVICE_ID_INTEL_82801CA_12, asus_hides_smbus_lpc);
1176DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_INTEL,     PCI_DEVICE_ID_INTEL_82801DB_12, asus_hides_smbus_lpc);
1177DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_INTEL,     PCI_DEVICE_ID_INTEL_82801EB_0,  asus_hides_smbus_lpc);
1178
1179/* It appears we just have one such device. If not, we have a warning */
1180static void __iomem *asus_rcba_base;
1181static void asus_hides_smbus_lpc_ich6_suspend(struct pci_dev *dev)
1182{
1183        u32 rcba;
1184
1185        if (likely(!asus_hides_smbus))
1186                return;
1187        WARN_ON(asus_rcba_base);
1188
1189        pci_read_config_dword(dev, 0xF0, &rcba);
1190        /* use bits 31:14, 16 kB aligned */
1191        asus_rcba_base = ioremap_nocache(rcba & 0xFFFFC000, 0x4000);
1192        if (asus_rcba_base == NULL)
1193                return;
1194}
1195
1196static void asus_hides_smbus_lpc_ich6_resume_early(struct pci_dev *dev)
1197{
1198        u32 val;
1199
1200        if (likely(!asus_hides_smbus || !asus_rcba_base))
1201                return;
1202        /* read the Function Disable register, dword mode only */
1203        val = readl(asus_rcba_base + 0x3418);
1204        writel(val & 0xFFFFFFF7, asus_rcba_base + 0x3418); /* enable the SMBus device */
1205}
1206
1207static void asus_hides_smbus_lpc_ich6_resume(struct pci_dev *dev)
1208{
1209        if (likely(!asus_hides_smbus || !asus_rcba_base))
1210                return;
1211        iounmap(asus_rcba_base);
1212        asus_rcba_base = NULL;
1213        dev_info(&dev->dev, "Enabled ICH6/i801 SMBus device\n");
1214}
1215
1216static void asus_hides_smbus_lpc_ich6(struct pci_dev *dev)
1217{
1218        asus_hides_smbus_lpc_ich6_suspend(dev);
1219        asus_hides_smbus_lpc_ich6_resume_early(dev);
1220        asus_hides_smbus_lpc_ich6_resume(dev);
1221}
1222DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,   PCI_DEVICE_ID_INTEL_ICH6_1,     asus_hides_smbus_lpc_ich6);
1223DECLARE_PCI_FIXUP_SUSPEND(PCI_VENDOR_ID_INTEL,  PCI_DEVICE_ID_INTEL_ICH6_1,     asus_hides_smbus_lpc_ich6_suspend);
1224DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_INTEL,   PCI_DEVICE_ID_INTEL_ICH6_1,     asus_hides_smbus_lpc_ich6_resume);
1225DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_INTEL,     PCI_DEVICE_ID_INTEL_ICH6_1,     asus_hides_smbus_lpc_ich6_resume_early);
1226
1227/*
1228 * SiS 96x south bridge: BIOS typically hides SMBus device...
1229 */
1230static void quirk_sis_96x_smbus(struct pci_dev *dev)
1231{
1232        u8 val = 0;
1233        pci_read_config_byte(dev, 0x77, &val);
1234        if (val & 0x10) {
1235                dev_info(&dev->dev, "Enabling SiS 96x SMBus\n");
1236                pci_write_config_byte(dev, 0x77, val & ~0x10);
1237        }
1238}
1239DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SI,      PCI_DEVICE_ID_SI_961,           quirk_sis_96x_smbus);
1240DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SI,      PCI_DEVICE_ID_SI_962,           quirk_sis_96x_smbus);
1241DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SI,      PCI_DEVICE_ID_SI_963,           quirk_sis_96x_smbus);
1242DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SI,      PCI_DEVICE_ID_SI_LPC,           quirk_sis_96x_smbus);
1243DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_SI,        PCI_DEVICE_ID_SI_961,           quirk_sis_96x_smbus);
1244DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_SI,        PCI_DEVICE_ID_SI_962,           quirk_sis_96x_smbus);
1245DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_SI,        PCI_DEVICE_ID_SI_963,           quirk_sis_96x_smbus);
1246DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_SI,        PCI_DEVICE_ID_SI_LPC,           quirk_sis_96x_smbus);
1247
1248/*
1249 * ... This is further complicated by the fact that some SiS96x south
1250 * bridges pretend to be 85C503/5513 instead.  In that case see if we
1251 * spotted a compatible north bridge to make sure.
1252 * (pci_find_device doesn't work yet)
1253 *
1254 * We can also enable the sis96x bit in the discovery register..
1255 */
1256#define SIS_DETECT_REGISTER 0x40
1257
1258static void quirk_sis_503(struct pci_dev *dev)
1259{
1260        u8 reg;
1261        u16 devid;
1262
1263        pci_read_config_byte(dev, SIS_DETECT_REGISTER, &reg);
1264        pci_write_config_byte(dev, SIS_DETECT_REGISTER, reg | (1 << 6));
1265        pci_read_config_word(dev, PCI_DEVICE_ID, &devid);
1266        if (((devid & 0xfff0) != 0x0960) && (devid != 0x0018)) {
1267                pci_write_config_byte(dev, SIS_DETECT_REGISTER, reg);
1268                return;
1269        }
1270
1271        /*
1272         * Ok, it now shows up as a 96x.. run the 96x quirk by
1273         * hand in case it has already been processed.
1274         * (depends on link order, which is apparently not guaranteed)
1275         */
1276        dev->device = devid;
1277        quirk_sis_96x_smbus(dev);
1278}
1279DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SI,      PCI_DEVICE_ID_SI_503,           quirk_sis_503);
1280DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_SI,        PCI_DEVICE_ID_SI_503,           quirk_sis_503);
1281
1282
1283/*
1284 * On ASUS A8V and A8V Deluxe boards, the onboard AC97 audio controller
1285 * and MC97 modem controller are disabled when a second PCI soundcard is
1286 * present. This patch, tweaking the VT8237 ISA bridge, enables them.
1287 * -- bjd
1288 */
1289static void asus_hides_ac97_lpc(struct pci_dev *dev)
1290{
1291        u8 val;
1292        int asus_hides_ac97 = 0;
1293
1294        if (likely(dev->subsystem_vendor == PCI_VENDOR_ID_ASUSTEK)) {
1295                if (dev->device == PCI_DEVICE_ID_VIA_8237)
1296                        asus_hides_ac97 = 1;
1297        }
1298
1299        if (!asus_hides_ac97)
1300                return;
1301
1302        pci_read_config_byte(dev, 0x50, &val);
1303        if (val & 0xc0) {
1304                pci_write_config_byte(dev, 0x50, val & (~0xc0));
1305                pci_read_config_byte(dev, 0x50, &val);
1306                if (val & 0xc0)
1307                        dev_info(&dev->dev, "Onboard AC97/MC97 devices continue to play 'hide and seek'! 0x%x\n", val);
1308                else
1309                        dev_info(&dev->dev, "Enabled onboard AC97/MC97 devices\n");
1310        }
1311}
1312DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA,     PCI_DEVICE_ID_VIA_8237, asus_hides_ac97_lpc);
1313DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_VIA,       PCI_DEVICE_ID_VIA_8237, asus_hides_ac97_lpc);
1314
1315#if defined(CONFIG_ATA) || defined(CONFIG_ATA_MODULE)
1316
1317/*
1318 *      If we are using libata we can drive this chip properly but must
1319 *      do this early on to make the additional device appear during
1320 *      the PCI scanning.
1321 */
1322static void quirk_jmicron_ata(struct pci_dev *pdev)
1323{
1324        u32 conf1, conf5, class;
1325        u8 hdr;
1326
1327        /* Only poke fn 0 */
1328        if (PCI_FUNC(pdev->devfn))
1329                return;
1330
1331        pci_read_config_dword(pdev, 0x40, &conf1);
1332        pci_read_config_dword(pdev, 0x80, &conf5);
1333
1334        conf1 &= ~0x00CFF302; /* Clear bit 1, 8, 9, 12-19, 22, 23 */
1335        conf5 &= ~(1 << 24);  /* Clear bit 24 */
1336
1337        switch (pdev->device) {
1338        case PCI_DEVICE_ID_JMICRON_JMB360:
1339                /* The controller should be in single function ahci mode */
1340                conf1 |= 0x0002A100; /* Set 8, 13, 15, 17 */
1341                break;
1342
1343        case PCI_DEVICE_ID_JMICRON_JMB365:
1344        case PCI_DEVICE_ID_JMICRON_JMB366:
1345                /* Redirect IDE second PATA port to the right spot */
1346                conf5 |= (1 << 24);
1347                /* Fall through */
1348        case PCI_DEVICE_ID_JMICRON_JMB361:
1349        case PCI_DEVICE_ID_JMICRON_JMB363:
1350                /* Enable dual function mode, AHCI on fn 0, IDE fn1 */
1351                /* Set the class codes correctly and then direct IDE 0 */
1352                conf1 |= 0x00C2A1B3; /* Set 0, 1, 4, 5, 7, 8, 13, 15, 17, 22, 23 */
1353                break;
1354
1355        case PCI_DEVICE_ID_JMICRON_JMB368:
1356                /* The controller should be in single function IDE mode */
1357                conf1 |= 0x00C00000; /* Set 22, 23 */
1358                break;
1359        }
1360
1361        pci_write_config_dword(pdev, 0x40, conf1);
1362        pci_write_config_dword(pdev, 0x80, conf5);
1363
1364        /* Update pdev accordingly */
1365        pci_read_config_byte(pdev, PCI_HEADER_TYPE, &hdr);
1366        pdev->hdr_type = hdr & 0x7f;
1367        pdev->multifunction = !!(hdr & 0x80);
1368
1369        pci_read_config_dword(pdev, PCI_CLASS_REVISION, &class);
1370        pdev->class = class >> 8;
1371}
1372DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB360, quirk_jmicron_ata);
1373DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB361, quirk_jmicron_ata);
1374DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB363, quirk_jmicron_ata);
1375DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB365, quirk_jmicron_ata);
1376DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB366, quirk_jmicron_ata);
1377DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB368, quirk_jmicron_ata);
1378DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB360, quirk_jmicron_ata);
1379DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB361, quirk_jmicron_ata);
1380DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB363, quirk_jmicron_ata);
1381DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB365, quirk_jmicron_ata);
1382DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB366, quirk_jmicron_ata);
1383DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB368, quirk_jmicron_ata);
1384
1385#endif
1386
1387#ifdef CONFIG_X86_IO_APIC
1388static void __init quirk_alder_ioapic(struct pci_dev *pdev)
1389{
1390        int i;
1391
1392        if ((pdev->class >> 8) != 0xff00)
1393                return;
1394
1395        /* the first BAR is the location of the IO APIC...we must
1396         * not touch this (and it's already covered by the fixmap), so
1397         * forcibly insert it into the resource tree */
1398        if (pci_resource_start(pdev, 0) && pci_resource_len(pdev, 0))
1399                insert_resource(&iomem_resource, &pdev->resource[0]);
1400
1401        /* The next five BARs all seem to be rubbish, so just clean
1402         * them out */
1403        for (i=1; i < 6; i++) {
1404                memset(&pdev->resource[i], 0, sizeof(pdev->resource[i]));
1405        }
1406
1407}
1408DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,   PCI_DEVICE_ID_INTEL_EESSC,      quirk_alder_ioapic);
1409#endif
1410
1411int pcie_mch_quirk;
1412EXPORT_SYMBOL(pcie_mch_quirk);
1413
1414static void __devinit quirk_pcie_mch(struct pci_dev *pdev)
1415{
1416        pcie_mch_quirk = 1;
1417}
1418DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL,    PCI_DEVICE_ID_INTEL_E7520_MCH,  quirk_pcie_mch);
1419DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL,    PCI_DEVICE_ID_INTEL_E7320_MCH,  quirk_pcie_mch);
1420DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL,    PCI_DEVICE_ID_INTEL_E7525_MCH,  quirk_pcie_mch);
1421
1422
1423/*
1424 * It's possible for the MSI to get corrupted if shpc and acpi
1425 * are used together on certain PXH-based systems.
1426 */
1427static void __devinit quirk_pcie_pxh(struct pci_dev *dev)
1428{
1429        pci_msi_off(dev);
1430        dev->no_msi = 1;
1431        dev_warn(&dev->dev, "PXH quirk detected; SHPC device MSI disabled\n");
1432}
1433DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL,    PCI_DEVICE_ID_INTEL_PXHD_0,     quirk_pcie_pxh);
1434DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL,    PCI_DEVICE_ID_INTEL_PXHD_1,     quirk_pcie_pxh);
1435DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL,    PCI_DEVICE_ID_INTEL_PXH_0,      quirk_pcie_pxh);
1436DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL,    PCI_DEVICE_ID_INTEL_PXH_1,      quirk_pcie_pxh);
1437DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL,    PCI_DEVICE_ID_INTEL_PXHV,       quirk_pcie_pxh);
1438
1439/*
1440 * Some Intel PCI Express chipsets have trouble with downstream
1441 * device power management.
1442 */
1443static void quirk_intel_pcie_pm(struct pci_dev * dev)
1444{
1445        pci_pm_d3_delay = 120;
1446        dev->no_d1d2 = 1;
1447}
1448
1449DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL,    0x25e2, quirk_intel_pcie_pm);
1450DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL,    0x25e3, quirk_intel_pcie_pm);
1451DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL,    0x25e4, quirk_intel_pcie_pm);
1452DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL,    0x25e5, quirk_intel_pcie_pm);
1453DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL,    0x25e6, quirk_intel_pcie_pm);
1454DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL,    0x25e7, quirk_intel_pcie_pm);
1455DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL,    0x25f7, quirk_intel_pcie_pm);
1456DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL,    0x25f8, quirk_intel_pcie_pm);
1457DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL,    0x25f9, quirk_intel_pcie_pm);
1458DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL,    0x25fa, quirk_intel_pcie_pm);
1459DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL,    0x2601, quirk_intel_pcie_pm);
1460DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL,    0x2602, quirk_intel_pcie_pm);
1461DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL,    0x2603, quirk_intel_pcie_pm);
1462DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL,    0x2604, quirk_intel_pcie_pm);
1463DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL,    0x2605, quirk_intel_pcie_pm);
1464DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL,    0x2606, quirk_intel_pcie_pm);
1465DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL,    0x2607, quirk_intel_pcie_pm);
1466DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL,    0x2608, quirk_intel_pcie_pm);
1467DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL,    0x2609, quirk_intel_pcie_pm);
1468DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL,    0x260a, quirk_intel_pcie_pm);
1469DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL,    0x260b, quirk_intel_pcie_pm);
1470
1471/*
1472 * Toshiba TC86C001 IDE controller reports the standard 8-byte BAR0 size
1473 * but the PIO transfers won't work if BAR0 falls at the odd 8 bytes.
1474 * Re-allocate the region if needed...
1475 */
1476static void __init quirk_tc86c001_ide(struct pci_dev *dev)
1477{
1478        struct resource *r = &dev->resource[0];
1479
1480        if (r->start & 0x8) {
1481                r->start = 0;
1482                r->end = 0xf;
1483        }
1484}
1485DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_TOSHIBA_2,
1486                         PCI_DEVICE_ID_TOSHIBA_TC86C001_IDE,
1487                         quirk_tc86c001_ide);
1488
1489static void __devinit quirk_netmos(struct pci_dev *dev)
1490{
1491        unsigned int num_parallel = (dev->subsystem_device & 0xf0) >> 4;
1492        unsigned int num_serial = dev->subsystem_device & 0xf;
1493
1494        /*
1495         * These Netmos parts are multiport serial devices with optional
1496         * parallel ports.  Even when parallel ports are present, they
1497         * are identified as class SERIAL, which means the serial driver
1498         * will claim them.  To prevent this, mark them as class OTHER.
1499         * These combo devices should be claimed by parport_serial.
1500         *
1501         * The subdevice ID is of the form 0x00PS, where <P> is the number
1502         * of parallel ports and <S> is the number of serial ports.
1503         */
1504        switch (dev->device) {
1505        case PCI_DEVICE_ID_NETMOS_9735:
1506        case PCI_DEVICE_ID_NETMOS_9745:
1507        case PCI_DEVICE_ID_NETMOS_9835:
1508        case PCI_DEVICE_ID_NETMOS_9845:
1509        case PCI_DEVICE_ID_NETMOS_9855:
1510                if ((dev->class >> 8) == PCI_CLASS_COMMUNICATION_SERIAL &&
1511                    num_parallel) {
1512                        dev_info(&dev->dev, "Netmos %04x (%u parallel, "
1513                                "%u serial); changing class SERIAL to OTHER "
1514                                "(use parport_serial)\n",
1515                                dev->device, num_parallel, num_serial);
1516                        dev->class = (PCI_CLASS_COMMUNICATION_OTHER << 8) |
1517                            (dev->class & 0xff);
1518                }
1519        }
1520}
1521DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_NETMOS, PCI_ANY_ID, quirk_netmos);
1522
1523static void __devinit quirk_e100_interrupt(struct pci_dev *dev)
1524{
1525        u16 command, pmcsr;
1526        u8 __iomem *csr;
1527        u8 cmd_hi;
1528        int pm;
1529
1530        switch (dev->device) {
1531        /* PCI IDs taken from drivers/net/e100.c */
1532        case 0x1029:
1533        case 0x1030 ... 0x1034:
1534        case 0x1038 ... 0x103E:
1535        case 0x1050 ... 0x1057:
1536        case 0x1059:
1537        case 0x1064 ... 0x106B:
1538        case 0x1091 ... 0x1095:
1539        case 0x1209:
1540        case 0x1229:
1541        case 0x2449:
1542        case 0x2459:
1543        case 0x245D:
1544        case 0x27DC:
1545                break;
1546        default:
1547                return;
1548        }
1549
1550        /*
1551         * Some firmware hands off the e100 with interrupts enabled,
1552         * which can cause a flood of interrupts if packets are
1553         * received before the driver attaches to the device.  So
1554         * disable all e100 interrupts here.  The driver will
1555         * re-enable them when it's ready.
1556         */
1557        pci_read_config_word(dev, PCI_COMMAND, &command);
1558
1559        if (!(command & PCI_COMMAND_MEMORY) || !pci_resource_start(dev, 0))
1560                return;
1561
1562        /*
1563         * Check that the device is in the D0 power state. If it's not,
1564         * there is no point to look any further.
1565         */
1566        pm = pci_find_capability(dev, PCI_CAP_ID_PM);
1567        if (pm) {
1568                pci_read_config_word(dev, pm + PCI_PM_CTRL, &pmcsr);
1569                if ((pmcsr & PCI_PM_CTRL_STATE_MASK) != PCI_D0)
1570                        return;
1571        }
1572
1573        /* Convert from PCI bus to resource space.  */
1574        csr = ioremap(pci_resource_start(dev, 0), 8);
1575        if (!csr) {
1576                dev_warn(&dev->dev, "Can't map e100 registers\n");
1577                return;
1578        }
1579
1580        cmd_hi = readb(csr + 3);
1581        if (cmd_hi == 0) {
1582                dev_warn(&dev->dev, "Firmware left e100 interrupts enabled; "
1583                        "disabling\n");
1584                writeb(1, csr + 3);
1585        }
1586
1587        iounmap(csr);
1588}
1589DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, PCI_ANY_ID, quirk_e100_interrupt);
1590
1591/*
1592 * The 82575 and 82598 may experience data corruption issues when transitioning
1593 * out of L0S.  To prevent this we need to disable L0S on the pci-e link
1594 */
1595static void __devinit quirk_disable_aspm_l0s(struct pci_dev *dev)
1596{
1597        dev_info(&dev->dev, "Disabling L0s\n");
1598        pci_disable_link_state(dev, PCIE_LINK_STATE_L0S);
1599}
1600DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x10a7, quirk_disable_aspm_l0s);
1601DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x10a9, quirk_disable_aspm_l0s);
1602DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x10b6, quirk_disable_aspm_l0s);
1603DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x10c6, quirk_disable_aspm_l0s);
1604DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x10c7, quirk_disable_aspm_l0s);
1605DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x10c8, quirk_disable_aspm_l0s);
1606DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x10d6, quirk_disable_aspm_l0s);
1607DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x10db, quirk_disable_aspm_l0s);
1608DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x10dd, quirk_disable_aspm_l0s);
1609DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x10e1, quirk_disable_aspm_l0s);
1610DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x10ec, quirk_disable_aspm_l0s);
1611DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x10f1, quirk_disable_aspm_l0s);
1612DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x10f4, quirk_disable_aspm_l0s);
1613DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x1508, quirk_disable_aspm_l0s);
1614
1615static void __devinit fixup_rev1_53c810(struct pci_dev* dev)
1616{
1617        /* rev 1 ncr53c810 chips don't set the class at all which means
1618         * they don't get their resources remapped. Fix that here.
1619         */
1620
1621        if (dev->class == PCI_CLASS_NOT_DEFINED) {
1622                dev_info(&dev->dev, "NCR 53c810 rev 1 detected; setting PCI class\n");
1623                dev->class = PCI_CLASS_STORAGE_SCSI;
1624        }
1625}
1626DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_NCR, PCI_DEVICE_ID_NCR_53C810, fixup_rev1_53c810);
1627
1628static void pci_do_fixups(struct pci_dev *dev, struct pci_fixup *f, struct pci_fixup *end)
1629{
1630        while (f < end) {
1631                if ((f->vendor == dev->vendor || f->vendor == (u16) PCI_ANY_ID) &&
1632                    (f->device == dev->device || f->device == (u16) PCI_ANY_ID)) {
1633#ifdef DEBUG
1634                        dev_dbg(&dev->dev, "calling ");
1635                        print_fn_descriptor_symbol("%s\n", f->hook);
1636#endif
1637                        f->hook(dev);
1638                }
1639                f++;
1640        }
1641}
1642
1643extern struct pci_fixup __start_pci_fixups_early[];
1644extern struct pci_fixup __end_pci_fixups_early[];
1645extern struct pci_fixup __start_pci_fixups_header[];
1646extern struct pci_fixup __end_pci_fixups_header[];
1647extern struct pci_fixup __start_pci_fixups_final[];
1648extern struct pci_fixup __end_pci_fixups_final[];
1649extern struct pci_fixup __start_pci_fixups_enable[];
1650extern struct pci_fixup __end_pci_fixups_enable[];
1651extern struct pci_fixup __start_pci_fixups_resume[];
1652extern struct pci_fixup __end_pci_fixups_resume[];
1653extern struct pci_fixup __start_pci_fixups_resume_early[];
1654extern struct pci_fixup __end_pci_fixups_resume_early[];
1655extern struct pci_fixup __start_pci_fixups_suspend[];
1656extern struct pci_fixup __end_pci_fixups_suspend[];
1657
1658
1659void pci_fixup_device(enum pci_fixup_pass pass, struct pci_dev *dev)
1660{
1661        struct pci_fixup *start, *end;
1662
1663        switch(pass) {
1664        case pci_fixup_early:
1665                start = __start_pci_fixups_early;
1666                end = __end_pci_fixups_early;
1667                break;
1668
1669        case pci_fixup_header:
1670                start = __start_pci_fixups_header;
1671                end = __end_pci_fixups_header;
1672                break;
1673
1674        case pci_fixup_final:
1675                start = __start_pci_fixups_final;
1676                end = __end_pci_fixups_final;
1677                break;
1678
1679        case pci_fixup_enable:
1680                start = __start_pci_fixups_enable;
1681                end = __end_pci_fixups_enable;
1682                break;
1683
1684        case pci_fixup_resume:
1685                start = __start_pci_fixups_resume;
1686                end = __end_pci_fixups_resume;
1687                break;
1688
1689        case pci_fixup_resume_early:
1690                start = __start_pci_fixups_resume_early;
1691                end = __end_pci_fixups_resume_early;
1692                break;
1693
1694        case pci_fixup_suspend:
1695                start = __start_pci_fixups_suspend;
1696                end = __end_pci_fixups_suspend;
1697                break;
1698
1699        default:
1700                /* stupid compiler warning, you would think with an enum... */
1701                return;
1702        }
1703        pci_do_fixups(dev, start, end);
1704}
1705EXPORT_SYMBOL(pci_fixup_device);
1706
1707/* Enable 1k I/O space granularity on the Intel P64H2 */
1708static void __devinit quirk_p64h2_1k_io(struct pci_dev *dev)
1709{
1710        u16 en1k;
1711        u8 io_base_lo, io_limit_lo;
1712        unsigned long base, limit;
1713        struct resource *res = dev->resource + PCI_BRIDGE_RESOURCES;
1714
1715        pci_read_config_word(dev, 0x40, &en1k);
1716
1717        if (en1k & 0x200) {
1718                dev_info(&dev->dev, "Enable I/O Space to 1KB granularity\n");
1719
1720                pci_read_config_byte(dev, PCI_IO_BASE, &io_base_lo);
1721                pci_read_config_byte(dev, PCI_IO_LIMIT, &io_limit_lo);
1722                base = (io_base_lo & (PCI_IO_RANGE_MASK | 0x0c)) << 8;
1723                limit = (io_limit_lo & (PCI_IO_RANGE_MASK | 0x0c)) << 8;
1724
1725                if (base <= limit) {
1726                        res->start = base;
1727                        res->end = limit + 0x3ff;
1728                }
1729        }
1730}
1731DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL,   0x1460,         quirk_p64h2_1k_io);
1732
1733/* Fix the IOBL_ADR for 1k I/O space granularity on the Intel P64H2
1734 * The IOBL_ADR gets re-written to 4k boundaries in pci_setup_bridge()
1735 * in drivers/pci/setup-bus.c
1736 */
1737static void __devinit quirk_p64h2_1k_io_fix_iobl(struct pci_dev *dev)
1738{
1739        u16 en1k, iobl_adr, iobl_adr_1k;
1740        struct resource *res = dev->resource + PCI_BRIDGE_RESOURCES;
1741
1742        pci_read_config_word(dev, 0x40, &en1k);
1743
1744        if (en1k & 0x200) {
1745                pci_read_config_word(dev, PCI_IO_BASE, &iobl_adr);
1746
1747                iobl_adr_1k = iobl_adr | (res->start >> 8) | (res->end & 0xfc00);
1748
1749                if (iobl_adr != iobl_adr_1k) {
1750                        dev_info(&dev->dev, "Fixing P64H2 IOBL_ADR from 0x%x to 0x%x for 1KB granularity\n",
1751                                iobl_adr,iobl_adr_1k);
1752                        pci_write_config_word(dev, PCI_IO_BASE, iobl_adr_1k);
1753                }
1754        }
1755}
1756DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL,    0x1460,         quirk_p64h2_1k_io_fix_iobl);
1757
1758/* Under some circumstances, AER is not linked with extended capabilities.
1759 * Force it to be linked by setting the corresponding control bit in the
1760 * config space.
1761 */
1762static void quirk_nvidia_ck804_pcie_aer_ext_cap(struct pci_dev *dev)
1763{
1764        uint8_t b;
1765        if (pci_read_config_byte(dev, 0xf41, &b) == 0) {
1766                if (!(b & 0x20)) {
1767                        pci_write_config_byte(dev, 0xf41, b | 0x20);
1768                        dev_info(&dev->dev,
1769                               "Linking AER extended capability\n");
1770                }
1771        }
1772}
1773DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_NVIDIA,  PCI_DEVICE_ID_NVIDIA_CK804_PCIE,
1774                        quirk_nvidia_ck804_pcie_aer_ext_cap);
1775DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_NVIDIA,  PCI_DEVICE_ID_NVIDIA_CK804_PCIE,
1776                        quirk_nvidia_ck804_pcie_aer_ext_cap);
1777
1778static void __devinit quirk_via_cx700_pci_parking_caching(struct pci_dev *dev)
1779{
1780        /*
1781         * Disable PCI Bus Parking and PCI Master read caching on CX700
1782         * which causes unspecified timing errors with a VT6212L on the PCI
1783         * bus leading to USB2.0 packet loss. The defaults are that these
1784         * features are turned off but some BIOSes turn them on.
1785         */
1786
1787        uint8_t b;
1788        if (pci_read_config_byte(dev, 0x76, &b) == 0) {
1789                if (b & 0x40) {
1790                        /* Turn off PCI Bus Parking */
1791                        pci_write_config_byte(dev, 0x76, b ^ 0x40);
1792
1793                        dev_info(&dev->dev,
1794                                "Disabling VIA CX700 PCI parking\n");
1795                }
1796        }
1797
1798        if (pci_read_config_byte(dev, 0x72, &b) == 0) {
1799                if (b != 0) {
1800                        /* Turn off PCI Master read caching */
1801                        pci_write_config_byte(dev, 0x72, 0x0);
1802
1803                        /* Set PCI Master Bus time-out to "1x16 PCLK" */
1804                        pci_write_config_byte(dev, 0x75, 0x1);
1805
1806                        /* Disable "Read FIFO Timer" */
1807                        pci_write_config_byte(dev, 0x77, 0x0);
1808
1809                        dev_info(&dev->dev,
1810                                "Disabling VIA CX700 PCI caching\n");
1811                }
1812        }
1813}
1814DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_VIA, 0x324e, quirk_via_cx700_pci_parking_caching);
1815
1816/*
1817 * For Broadcom 5706, 5708, 5709 rev. A nics, any read beyond the
1818 * VPD end tag will hang the device.  This problem was initially
1819 * observed when a vpd entry was created in sysfs
1820 * ('/sys/bus/pci/devices/<id>/vpd').   A read to this sysfs entry
1821 * will dump 32k of data.  Reading a full 32k will cause an access
1822 * beyond the VPD end tag causing the device to hang.  Once the device
1823 * is hung, the bnx2 driver will not be able to reset the device.
1824 * We believe that it is legal to read beyond the end tag and
1825 * therefore the solution is to limit the read/write length.
1826 */
1827static void __devinit quirk_brcm_570x_limit_vpd(struct pci_dev *dev)
1828{
1829        /*
1830         * Only disable the VPD capability for 5706, 5706S, 5708,
1831         * 5708S and 5709 rev. A
1832         */
1833        if ((dev->device == PCI_DEVICE_ID_NX2_5706) ||
1834            (dev->device == PCI_DEVICE_ID_NX2_5706S) ||
1835            (dev->device == PCI_DEVICE_ID_NX2_5708) ||
1836            (dev->device == PCI_DEVICE_ID_NX2_5708S) ||
1837            ((dev->device == PCI_DEVICE_ID_NX2_5709) &&
1838             (dev->revision & 0xf0) == 0x0)) {
1839                if (dev->vpd)
1840                        dev->vpd->len = 0x80;
1841        }
1842}
1843
1844DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_BROADCOM,
1845                         PCI_DEVICE_ID_NX2_5706,
1846                         quirk_brcm_570x_limit_vpd);
1847DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_BROADCOM,
1848                         PCI_DEVICE_ID_NX2_5706S,
1849                         quirk_brcm_570x_limit_vpd);
1850DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_BROADCOM,
1851                         PCI_DEVICE_ID_NX2_5708,
1852                         quirk_brcm_570x_limit_vpd);
1853DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_BROADCOM,
1854                         PCI_DEVICE_ID_NX2_5708S,
1855                         quirk_brcm_570x_limit_vpd);
1856DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_BROADCOM,
1857                         PCI_DEVICE_ID_NX2_5709,
1858                         quirk_brcm_570x_limit_vpd);
1859DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_BROADCOM,
1860                         PCI_DEVICE_ID_NX2_5709S,
1861                         quirk_brcm_570x_limit_vpd);
1862
1863#ifdef CONFIG_PCI_MSI
1864/* Some chipsets do not support MSI. We cannot easily rely on setting
1865 * PCI_BUS_FLAGS_NO_MSI in its bus flags because there are actually
1866 * some other busses controlled by the chipset even if Linux is not
1867 * aware of it.  Instead of setting the flag on all busses in the
1868 * machine, simply disable MSI globally.
1869 */
1870static void __init quirk_disable_all_msi(struct pci_dev *dev)
1871{
1872        pci_no_msi();
1873        dev_warn(&dev->dev, "MSI quirk detected; MSI disabled\n");
1874}
1875DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_SERVERWORKS, PCI_DEVICE_ID_SERVERWORKS_GCNB_LE, quirk_disable_all_msi);
1876DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RS400_200, quirk_disable_all_msi);
1877DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RS480, quirk_disable_all_msi);
1878DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_VT3336, quirk_disable_all_msi);
1879DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_VT3351, quirk_disable_all_msi);
1880DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_VT3364, quirk_disable_all_msi);
1881DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8380_0, quirk_disable_all_msi);
1882
1883/* Disable MSI on chipsets that are known to not support it */
1884static void __devinit quirk_disable_msi(struct pci_dev *dev)
1885{
1886        if (dev->subordinate) {
1887                dev_warn(&dev->dev, "MSI quirk detected; "
1888                        "subordinate MSI disabled\n");
1889                dev->subordinate->bus_flags |= PCI_BUS_FLAGS_NO_MSI;
1890        }
1891}
1892DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_8131_BRIDGE, quirk_disable_msi);
1893
1894/* Go through the list of Hypertransport capabilities and
1895 * return 1 if a HT MSI capability is found and enabled */
1896static int __devinit msi_ht_cap_enabled(struct pci_dev *dev)
1897{
1898        int pos, ttl = 48;
1899
1900        pos = pci_find_ht_capability(dev, HT_CAPTYPE_MSI_MAPPING);
1901        while (pos && ttl--) {
1902                u8 flags;
1903
1904                if (pci_read_config_byte(dev, pos + HT_MSI_FLAGS,
1905                                         &flags) == 0)
1906                {
1907                        dev_info(&dev->dev, "Found %s HT MSI Mapping\n",
1908                                flags & HT_MSI_FLAGS_ENABLE ?
1909                                "enabled" : "disabled");
1910                        return (flags & HT_MSI_FLAGS_ENABLE) != 0;
1911                }
1912
1913                pos = pci_find_next_ht_capability(dev, pos,
1914                                                  HT_CAPTYPE_MSI_MAPPING);
1915        }
1916        return 0;
1917}
1918
1919/* Check the hypertransport MSI mapping to know whether MSI is enabled or not */
1920static void __devinit quirk_msi_ht_cap(struct pci_dev *dev)
1921{
1922        if (dev->subordinate && !msi_ht_cap_enabled(dev)) {
1923                dev_warn(&dev->dev, "MSI quirk detected; "
1924                        "subordinate MSI disabled\n");
1925                dev->subordinate->bus_flags |= PCI_BUS_FLAGS_NO_MSI;
1926        }
1927}
1928DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_SERVERWORKS, PCI_DEVICE_ID_SERVERWORKS_HT2000_PCIE,
1929                        quirk_msi_ht_cap);
1930
1931/* The nVidia CK804 chipset may have 2 HT MSI mappings.
1932 * MSI are supported if the MSI capability set in any of these mappings.
1933 */
1934static void __devinit quirk_nvidia_ck804_msi_ht_cap(struct pci_dev *dev)
1935{
1936        struct pci_dev *pdev;
1937
1938        if (!dev->subordinate)
1939                return;
1940
1941        /* check HT MSI cap on this chipset and the root one.
1942         * a single one having MSI is enough to be sure that MSI are supported.
1943         */
1944        pdev = pci_get_slot(dev->bus, 0);
1945        if (!pdev)
1946                return;
1947        if (!msi_ht_cap_enabled(dev) && !msi_ht_cap_enabled(pdev)) {
1948                dev_warn(&dev->dev, "MSI quirk detected; "
1949                        "subordinate MSI disabled\n");
1950                dev->subordinate->bus_flags |= PCI_BUS_FLAGS_NO_MSI;
1951        }
1952        pci_dev_put(pdev);
1953}
1954DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_CK804_PCIE,
1955                        quirk_nvidia_ck804_msi_ht_cap);
1956
1957/* Force enable MSI mapping capability on HT bridges */
1958static void __devinit ht_enable_msi_mapping(struct pci_dev *dev)
1959{
1960        int pos, ttl = 48;
1961
1962        pos = pci_find_ht_capability(dev, HT_CAPTYPE_MSI_MAPPING);
1963        while (pos && ttl--) {
1964                u8 flags;
1965
1966                if (pci_read_config_byte(dev, pos + HT_MSI_FLAGS,
1967                                         &flags) == 0) {
1968                        dev_info(&dev->dev, "Enabling HT MSI Mapping\n");
1969
1970                        pci_write_config_byte(dev, pos + HT_MSI_FLAGS,
1971                                              flags | HT_MSI_FLAGS_ENABLE);
1972                }
1973                pos = pci_find_next_ht_capability(dev, pos,
1974                                                  HT_CAPTYPE_MSI_MAPPING);
1975        }
1976}
1977DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SERVERWORKS,
1978                         PCI_DEVICE_ID_SERVERWORKS_HT1000_PXB,
1979                         ht_enable_msi_mapping);
1980
1981DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_8132_BRIDGE,
1982                         ht_enable_msi_mapping);
1983
1984static void __devinit nv_msi_ht_cap_quirk(struct pci_dev *dev)
1985{
1986        struct pci_dev *host_bridge;
1987        int pos, ttl = 48;
1988
1989        /*
1990         * HT MSI mapping should be disabled on devices that are below
1991         * a non-Hypertransport host bridge. Locate the host bridge...
1992         */
1993        host_bridge = pci_get_bus_and_slot(0, PCI_DEVFN(0, 0));
1994        if (host_bridge == NULL) {
1995                dev_warn(&dev->dev,
1996                         "nv_msi_ht_cap_quirk didn't locate host bridge\n");
1997                return;
1998        }
1999
2000        pos = pci_find_ht_capability(host_bridge, HT_CAPTYPE_SLAVE);
2001        if (pos != 0) {
2002                /* Host bridge is to HT */
2003                ht_enable_msi_mapping(dev);
2004                return;
2005        }
2006
2007        /* Host bridge is not to HT, disable HT MSI mapping on this device */
2008        pos = pci_find_ht_capability(dev, HT_CAPTYPE_MSI_MAPPING);
2009        while (pos && ttl--) {
2010                u8 flags;
2011
2012                if (pci_read_config_byte(dev, pos + HT_MSI_FLAGS,
2013                                         &flags) == 0) {
2014                        dev_info(&dev->dev, "Disabling HT MSI mapping");
2015                        pci_write_config_byte(dev, pos + HT_MSI_FLAGS,
2016                                              flags & ~HT_MSI_FLAGS_ENABLE);
2017                }
2018                pos = pci_find_next_ht_capability(dev, pos,
2019                                                  HT_CAPTYPE_MSI_MAPPING);
2020        }
2021}
2022DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_NVIDIA, PCI_ANY_ID, nv_msi_ht_cap_quirk);
2023DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AL, PCI_ANY_ID, nv_msi_ht_cap_quirk);
2024
2025static void __devinit quirk_msi_intx_disable_bug(struct pci_dev *dev)
2026{
2027        dev->dev_flags |= PCI_DEV_FLAGS_MSI_INTX_DISABLE_BUG;
2028}
2029static void __devinit quirk_msi_intx_disable_ati_bug(struct pci_dev *dev)
2030{
2031        struct pci_dev *p;
2032
2033        /* SB700 MSI issue will be fixed at HW level from revision A21,
2034         * we need check PCI REVISION ID of SMBus controller to get SB700
2035         * revision.
2036         */
2037        p = pci_get_device(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_SBX00_SMBUS,
2038                           NULL);
2039        if (!p)
2040                return;
2041
2042        if ((p->revision < 0x3B) && (p->revision >= 0x30))
2043                dev->dev_flags |= PCI_DEV_FLAGS_MSI_INTX_DISABLE_BUG;
2044        pci_dev_put(p);
2045}
2046DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_BROADCOM,
2047                        PCI_DEVICE_ID_TIGON3_5780,
2048                        quirk_msi_intx_disable_bug);
2049DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_BROADCOM,
2050                        PCI_DEVICE_ID_TIGON3_5780S,
2051                        quirk_msi_intx_disable_bug);
2052DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_BROADCOM,
2053                        PCI_DEVICE_ID_TIGON3_5714,
2054                        quirk_msi_intx_disable_bug);
2055DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_BROADCOM,
2056                        PCI_DEVICE_ID_TIGON3_5714S,
2057                        quirk_msi_intx_disable_bug);
2058DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_BROADCOM,
2059                        PCI_DEVICE_ID_TIGON3_5715,
2060                        quirk_msi_intx_disable_bug);
2061DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_BROADCOM,
2062                        PCI_DEVICE_ID_TIGON3_5715S,
2063                        quirk_msi_intx_disable_bug);
2064
2065DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_ATI, 0x4390,
2066                        quirk_msi_intx_disable_ati_bug);
2067DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_ATI, 0x4391,
2068                        quirk_msi_intx_disable_ati_bug);
2069DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_ATI, 0x4392,
2070                        quirk_msi_intx_disable_ati_bug);
2071DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_ATI, 0x4393,
2072                        quirk_msi_intx_disable_ati_bug);
2073DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_ATI, 0x4394,
2074                        quirk_msi_intx_disable_ati_bug);
2075
2076DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_ATI, 0x4373,
2077                        quirk_msi_intx_disable_bug);
2078DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_ATI, 0x4374,
2079                        quirk_msi_intx_disable_bug);
2080DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_ATI, 0x4375,
2081                        quirk_msi_intx_disable_bug);
2082
2083#endif /* CONFIG_PCI_MSI */
2084