]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blame - drivers/pci/quirks.c
UBUNTU: [Config] Set CONFIG_PWM_PCA9685=m for amd64 and i386
[mirror_ubuntu-zesty-kernel.git] / drivers / pci / quirks.c
CommitLineData
1da177e4
LT
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 *
7586269c
DB
10 * Init/reset quirks for USB host controllers should be in the
11 * USB quirks file, where their drivers can access reuse it.
1da177e4
LT
12 */
13
1da177e4
LT
14#include <linux/types.h>
15#include <linux/kernel.h>
363c75db 16#include <linux/export.h>
1da177e4
LT
17#include <linux/pci.h>
18#include <linux/init.h>
19#include <linux/delay.h>
25be5e6c 20#include <linux/acpi.h>
9f23ed3b 21#include <linux/kallsyms.h>
75e07fc3 22#include <linux/dmi.h>
649426ef 23#include <linux/pci-aspm.h>
32a9a682 24#include <linux/ioport.h>
3209874a
AV
25#include <linux/sched.h>
26#include <linux/ktime.h>
9fe373f9 27#include <linux/mm.h>
93177a74 28#include <asm/dma.h> /* isa_dma_bridge_buggy */
bc56b9e0 29#include "pci.h"
1da177e4 30
253d2e54
JP
31/*
32 * Decoding should be disabled for a PCI device during BAR sizing to avoid
33 * conflict. But doing so may cause problems on host bridge and perhaps other
34 * key system devices. For devices that need to have mmio decoding always-on,
35 * we need to set the dev->mmio_always_on bit.
36 */
15856ad5 37static void quirk_mmio_always_on(struct pci_dev *dev)
253d2e54 38{
52d21b5e 39 dev->mmio_always_on = 1;
253d2e54 40}
52d21b5e
YL
41DECLARE_PCI_FIXUP_CLASS_EARLY(PCI_ANY_ID, PCI_ANY_ID,
42 PCI_CLASS_BRIDGE_HOST, 8, quirk_mmio_always_on);
253d2e54 43
4dce04ea
XY
44/* The BAR0 ~ BAR4 of Marvell 9125 device can't be accessed
45* by IO resource file, and need to skip the files
46*/
47static void quirk_marvell_mask_bar(struct pci_dev *dev)
48{
49 int i;
50
51 for (i = 0; i < 5; i++)
52 if (dev->resource[i].start)
53 dev->resource[i].start =
54 dev->resource[i].end = 0;
55}
56DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_MARVELL_EXT, 0x9125,
57 quirk_marvell_mask_bar);
58
bd8481e1
DT
59/* The Mellanox Tavor device gives false positive parity errors
60 * Mark this device with a broken_parity_status, to allow
61 * PCI scanning code to "skip" this now blacklisted device.
62 */
15856ad5 63static void quirk_mellanox_tavor(struct pci_dev *dev)
bd8481e1
DT
64{
65 dev->broken_parity_status = 1; /* This device gives false positives */
66}
3c78bc61
RD
67DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_MELLANOX, PCI_DEVICE_ID_MELLANOX_TAVOR, quirk_mellanox_tavor);
68DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_MELLANOX, PCI_DEVICE_ID_MELLANOX_TAVOR_BRIDGE, quirk_mellanox_tavor);
bd8481e1 69
f7625980 70/* Deal with broken BIOSes that neglect to enable passive release,
1da177e4 71 which can cause problems in combination with the 82441FX/PPro MTRRs */
1597cacb 72static void quirk_passive_release(struct pci_dev *dev)
1da177e4
LT
73{
74 struct pci_dev *d = NULL;
75 unsigned char dlc;
76
77 /* We have to make sure a particular bit is set in the PIIX3
78 ISA bridge, so we have to go out and find it. */
79 while ((d = pci_get_device(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82371SB_0, d))) {
80 pci_read_config_byte(d, 0x82, &dlc);
81 if (!(dlc & 1<<1)) {
999da9fd 82 dev_info(&d->dev, "PIIX3: Enabling Passive Release\n");
1da177e4
LT
83 dlc |= 1<<1;
84 pci_write_config_byte(d, 0x82, dlc);
85 }
86 }
87}
652c538e
AM
88DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82441, quirk_passive_release);
89DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82441, quirk_passive_release);
1da177e4
LT
90
91/* The VIA VP2/VP3/MVP3 seem to have some 'features'. There may be a workaround
92 but VIA don't answer queries. If you happen to have good contacts at VIA
f7625980
BH
93 ask them for me please -- Alan
94
95 This appears to be BIOS not version dependent. So presumably there is a
1da177e4 96 chipset level fix */
f7625980 97
15856ad5 98static void quirk_isa_dma_hangs(struct pci_dev *dev)
1da177e4
LT
99{
100 if (!isa_dma_bridge_buggy) {
3c78bc61 101 isa_dma_bridge_buggy = 1;
f0fda801 102 dev_info(&dev->dev, "Activating ISA DMA hang workarounds\n");
1da177e4
LT
103 }
104}
105 /*
106 * Its not totally clear which chipsets are the problematic ones
107 * We know 82C586 and 82C596 variants are affected.
108 */
652c538e
AM
109DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C586_0, quirk_isa_dma_hangs);
110DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C596, quirk_isa_dma_hangs);
111DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82371SB_0, quirk_isa_dma_hangs);
f7625980 112DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M1533, quirk_isa_dma_hangs);
652c538e
AM
113DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_NEC, PCI_DEVICE_ID_NEC_CBUS_1, quirk_isa_dma_hangs);
114DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_NEC, PCI_DEVICE_ID_NEC_CBUS_2, quirk_isa_dma_hangs);
115DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_NEC, PCI_DEVICE_ID_NEC_CBUS_3, quirk_isa_dma_hangs);
1da177e4 116
4731fdcf
LB
117/*
118 * Intel NM10 "TigerPoint" LPC PM1a_STS.BM_STS must be clear
119 * for some HT machines to use C4 w/o hanging.
120 */
15856ad5 121static void quirk_tigerpoint_bm_sts(struct pci_dev *dev)
4731fdcf
LB
122{
123 u32 pmbase;
124 u16 pm1a;
125
126 pci_read_config_dword(dev, 0x40, &pmbase);
127 pmbase = pmbase & 0xff80;
128 pm1a = inw(pmbase);
129
130 if (pm1a & 0x10) {
131 dev_info(&dev->dev, FW_BUG "TigerPoint LPC.BM_STS cleared\n");
132 outw(0x10, pmbase);
133 }
134}
135DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_TGP_LPC, quirk_tigerpoint_bm_sts);
136
1da177e4
LT
137/*
138 * Chipsets where PCI->PCI transfers vanish or hang
139 */
15856ad5 140static void quirk_nopcipci(struct pci_dev *dev)
1da177e4 141{
3c78bc61 142 if ((pci_pci_problems & PCIPCI_FAIL) == 0) {
f0fda801 143 dev_info(&dev->dev, "Disabling direct PCI/PCI transfers\n");
1da177e4
LT
144 pci_pci_problems |= PCIPCI_FAIL;
145 }
146}
652c538e
AM
147DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_5597, quirk_nopcipci);
148DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_496, quirk_nopcipci);
236561e5 149
15856ad5 150static void quirk_nopciamd(struct pci_dev *dev)
236561e5
AC
151{
152 u8 rev;
153 pci_read_config_byte(dev, 0x08, &rev);
154 if (rev == 0x13) {
155 /* Erratum 24 */
f0fda801 156 dev_info(&dev->dev, "Chipset erratum: Disabling direct PCI/AGP transfers\n");
236561e5
AC
157 pci_pci_problems |= PCIAGP_FAIL;
158 }
159}
652c538e 160DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_8151_0, quirk_nopciamd);
1da177e4
LT
161
162/*
163 * Triton requires workarounds to be used by the drivers
164 */
15856ad5 165static void quirk_triton(struct pci_dev *dev)
1da177e4 166{
3c78bc61 167 if ((pci_pci_problems&PCIPCI_TRITON) == 0) {
f0fda801 168 dev_info(&dev->dev, "Limiting direct PCI/PCI transfers\n");
1da177e4
LT
169 pci_pci_problems |= PCIPCI_TRITON;
170 }
171}
f7625980
BH
172DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82437, quirk_triton);
173DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82437VX, quirk_triton);
174DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82439, quirk_triton);
175DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82439TX, quirk_triton);
1da177e4
LT
176
177/*
178 * VIA Apollo KT133 needs PCI latency patch
179 * Made according to a windows driver based patch by George E. Breese
180 * see PCI Latency Adjust on http://www.viahardware.com/download/viatweak.shtm
3c78bc61
RD
181 * Also see http://www.au-ja.org/review-kt133a-1-en.phtml for
182 * the info on which Mr Breese based his work.
1da177e4
LT
183 *
184 * Updated based on further information from the site and also on
f7625980 185 * information provided by VIA
1da177e4 186 */
1597cacb 187static void quirk_vialatency(struct pci_dev *dev)
1da177e4
LT
188{
189 struct pci_dev *p;
1da177e4
LT
190 u8 busarb;
191 /* Ok we have a potential problem chipset here. Now see if we have
192 a buggy southbridge */
f7625980 193
1da177e4 194 p = pci_get_device(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C686, NULL);
3c78bc61 195 if (p != NULL) {
1da177e4
LT
196 /* 0x40 - 0x4f == 686B, 0x10 - 0x2f == 686A; thanks Dan Hollis */
197 /* Check for buggy part revisions */
2b1afa87 198 if (p->revision < 0x40 || p->revision > 0x42)
1da177e4
LT
199 goto exit;
200 } else {
201 p = pci_get_device(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8231, NULL);
3c78bc61 202 if (p == NULL) /* No problem parts */
1da177e4 203 goto exit;
1da177e4 204 /* Check for buggy part revisions */
2b1afa87 205 if (p->revision < 0x10 || p->revision > 0x12)
1da177e4
LT
206 goto exit;
207 }
f7625980 208
1da177e4 209 /*
f7625980 210 * Ok we have the problem. Now set the PCI master grant to
1da177e4
LT
211 * occur every master grant. The apparent bug is that under high
212 * PCI load (quite common in Linux of course) you can get data
213 * loss when the CPU is held off the bus for 3 bus master requests
214 * This happens to include the IDE controllers....
215 *
216 * VIA only apply this fix when an SB Live! is present but under
25985edc 217 * both Linux and Windows this isn't enough, and we have seen
1da177e4
LT
218 * corruption without SB Live! but with things like 3 UDMA IDE
219 * controllers. So we ignore that bit of the VIA recommendation..
220 */
221
222 pci_read_config_byte(dev, 0x76, &busarb);
f7625980 223 /* Set bit 4 and bi 5 of byte 76 to 0x01
1da177e4
LT
224 "Master priority rotation on every PCI master grant */
225 busarb &= ~(1<<5);
226 busarb |= (1<<4);
227 pci_write_config_byte(dev, 0x76, busarb);
f0fda801 228 dev_info(&dev->dev, "Applying VIA southbridge workaround\n");
1da177e4
LT
229exit:
230 pci_dev_put(p);
231}
652c538e
AM
232DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8363_0, quirk_vialatency);
233DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8371_1, quirk_vialatency);
234DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8361, quirk_vialatency);
1597cacb 235/* Must restore this on a resume from RAM */
652c538e
AM
236DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8363_0, quirk_vialatency);
237DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8371_1, quirk_vialatency);
238DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8361, quirk_vialatency);
1da177e4
LT
239
240/*
241 * VIA Apollo VP3 needs ETBF on BT848/878
242 */
15856ad5 243static void quirk_viaetbf(struct pci_dev *dev)
1da177e4 244{
3c78bc61 245 if ((pci_pci_problems&PCIPCI_VIAETBF) == 0) {
f0fda801 246 dev_info(&dev->dev, "Limiting direct PCI/PCI transfers\n");
1da177e4
LT
247 pci_pci_problems |= PCIPCI_VIAETBF;
248 }
249}
652c538e 250DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C597_0, quirk_viaetbf);
1da177e4 251
15856ad5 252static void quirk_vsfx(struct pci_dev *dev)
1da177e4 253{
3c78bc61 254 if ((pci_pci_problems&PCIPCI_VSFX) == 0) {
f0fda801 255 dev_info(&dev->dev, "Limiting direct PCI/PCI transfers\n");
1da177e4
LT
256 pci_pci_problems |= PCIPCI_VSFX;
257 }
258}
652c538e 259DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C576, quirk_vsfx);
1da177e4
LT
260
261/*
262 * Ali Magik requires workarounds to be used by the drivers
263 * that DMA to AGP space. Latency must be set to 0xA and triton
264 * workaround applied too
265 * [Info kindly provided by ALi]
f7625980 266 */
15856ad5 267static void quirk_alimagik(struct pci_dev *dev)
1da177e4 268{
3c78bc61 269 if ((pci_pci_problems&PCIPCI_ALIMAGIK) == 0) {
f0fda801 270 dev_info(&dev->dev, "Limiting direct PCI/PCI transfers\n");
1da177e4
LT
271 pci_pci_problems |= PCIPCI_ALIMAGIK|PCIPCI_TRITON;
272 }
273}
f7625980
BH
274DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M1647, quirk_alimagik);
275DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M1651, quirk_alimagik);
1da177e4
LT
276
277/*
278 * Natoma has some interesting boundary conditions with Zoran stuff
279 * at least
280 */
15856ad5 281static void quirk_natoma(struct pci_dev *dev)
1da177e4 282{
3c78bc61 283 if ((pci_pci_problems&PCIPCI_NATOMA) == 0) {
f0fda801 284 dev_info(&dev->dev, "Limiting direct PCI/PCI transfers\n");
1da177e4
LT
285 pci_pci_problems |= PCIPCI_NATOMA;
286 }
287}
f7625980
BH
288DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82441, quirk_natoma);
289DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443LX_0, quirk_natoma);
290DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443LX_1, quirk_natoma);
291DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443BX_0, quirk_natoma);
292DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443BX_1, quirk_natoma);
293DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443BX_2, quirk_natoma);
1da177e4
LT
294
295/*
296 * This chip can cause PCI parity errors if config register 0xA0 is read
297 * while DMAs are occurring.
298 */
15856ad5 299static void quirk_citrine(struct pci_dev *dev)
1da177e4
LT
300{
301 dev->cfg_size = 0xA0;
302}
652c538e 303DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE, quirk_citrine);
1da177e4 304
9f33a2ae
JM
305/*
306 * This chip can cause bus lockups if config addresses above 0x600
307 * are read or written.
308 */
309static void quirk_nfp6000(struct pci_dev *dev)
310{
311 dev->cfg_size = 0x600;
312}
c2e771b0 313DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_NETRONOME, PCI_DEVICE_ID_NETRONOME_NFP4000, quirk_nfp6000);
9f33a2ae
JM
314DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_NETRONOME, PCI_DEVICE_ID_NETRONOME_NFP6000, quirk_nfp6000);
315DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_NETRONOME, PCI_DEVICE_ID_NETRONOME_NFP6000_VF, quirk_nfp6000);
316
9fe373f9
DL
317/* On IBM Crocodile ipr SAS adapters, expand BAR to system page size */
318static void quirk_extend_bar_to_page(struct pci_dev *dev)
319{
320 int i;
321
322 for (i = 0; i < PCI_STD_RESOURCE_END; i++) {
323 struct resource *r = &dev->resource[i];
324
325 if (r->flags & IORESOURCE_MEM && resource_size(r) < PAGE_SIZE) {
326 r->end = PAGE_SIZE - 1;
327 r->start = 0;
328 r->flags |= IORESOURCE_UNSET;
329 dev_info(&dev->dev, "expanded BAR %d to page size: %pR\n",
330 i, r);
331 }
332 }
333}
334DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_IBM, 0x034a, quirk_extend_bar_to_page);
335
1da177e4
LT
336/*
337 * S3 868 and 968 chips report region size equal to 32M, but they decode 64M.
338 * If it's needed, re-allocate the region.
339 */
15856ad5 340static void quirk_s3_64M(struct pci_dev *dev)
1da177e4
LT
341{
342 struct resource *r = &dev->resource[0];
343
344 if ((r->start & 0x3ffffff) || r->end != r->start + 0x3ffffff) {
bd064f0a 345 r->flags |= IORESOURCE_UNSET;
1da177e4
LT
346 r->start = 0;
347 r->end = 0x3ffffff;
348 }
349}
652c538e
AM
350DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_S3, PCI_DEVICE_ID_S3_868, quirk_s3_64M);
351DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_S3, PCI_DEVICE_ID_S3_968, quirk_s3_64M);
1da177e4 352
06cf35f9
MS
353static void quirk_io(struct pci_dev *dev, int pos, unsigned size,
354 const char *name)
355{
356 u32 region;
357 struct pci_bus_region bus_region;
358 struct resource *res = dev->resource + pos;
359
360 pci_read_config_dword(dev, PCI_BASE_ADDRESS_0 + (pos << 2), &region);
361
362 if (!region)
363 return;
364
365 res->name = pci_name(dev);
366 res->flags = region & ~PCI_BASE_ADDRESS_IO_MASK;
367 res->flags |=
368 (IORESOURCE_IO | IORESOURCE_PCI_FIXED | IORESOURCE_SIZEALIGN);
369 region &= ~(size - 1);
370
371 /* Convert from PCI bus to resource space */
372 bus_region.start = region;
373 bus_region.end = region + size - 1;
374 pcibios_bus_to_resource(dev->bus, res, &bus_region);
375
376 dev_info(&dev->dev, FW_BUG "%s quirk: reg 0x%x: %pR\n",
377 name, PCI_BASE_ADDRESS_0 + (pos << 2), res);
378}
379
73d2eaac
AS
380/*
381 * Some CS5536 BIOSes (for example, the Soekris NET5501 board w/ comBIOS
382 * ver. 1.33 20070103) don't set the correct ISA PCI region header info.
383 * BAR0 should be 8 bytes; instead, it may be set to something like 8k
384 * (which conflicts w/ BAR1's memory range).
06cf35f9
MS
385 *
386 * CS553x's ISA PCI BARs may also be read-only (ref:
387 * https://bugzilla.kernel.org/show_bug.cgi?id=85991 - Comment #4 forward).
73d2eaac 388 */
15856ad5 389static void quirk_cs5536_vsa(struct pci_dev *dev)
73d2eaac 390{
06cf35f9
MS
391 static char *name = "CS5536 ISA bridge";
392
73d2eaac 393 if (pci_resource_len(dev, 0) != 8) {
06cf35f9
MS
394 quirk_io(dev, 0, 8, name); /* SMB */
395 quirk_io(dev, 1, 256, name); /* GPIO */
396 quirk_io(dev, 2, 64, name); /* MFGPT */
397 dev_info(&dev->dev, "%s bug detected (incorrect header); workaround applied\n",
398 name);
73d2eaac
AS
399 }
400}
401DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_CS5536_ISA, quirk_cs5536_vsa);
402
65195c76
YL
403static void quirk_io_region(struct pci_dev *dev, int port,
404 unsigned size, int nr, const char *name)
405{
406 u16 region;
407 struct pci_bus_region bus_region;
408 struct resource *res = dev->resource + nr;
409
410 pci_read_config_word(dev, port, &region);
411 region &= ~(size - 1);
412
413 if (!region)
414 return;
415
416 res->name = pci_name(dev);
417 res->flags = IORESOURCE_IO;
418
419 /* Convert from PCI bus to resource space */
420 bus_region.start = region;
421 bus_region.end = region + size - 1;
fc279850 422 pcibios_bus_to_resource(dev->bus, res, &bus_region);
65195c76
YL
423
424 if (!pci_claim_resource(dev, nr))
425 dev_info(&dev->dev, "quirk: %pR claimed by %s\n", res, name);
426}
1da177e4
LT
427
428/*
429 * ATI Northbridge setups MCE the processor if you even
430 * read somewhere between 0x3b0->0x3bb or read 0x3d3
431 */
15856ad5 432static void quirk_ati_exploding_mce(struct pci_dev *dev)
1da177e4 433{
f0fda801 434 dev_info(&dev->dev, "ATI Northbridge, reserving I/O ports 0x3b0 to 0x3bb\n");
1da177e4
LT
435 /* Mae rhaid i ni beidio ag edrych ar y lleoliadiau I/O hyn */
436 request_region(0x3b0, 0x0C, "RadeonIGP");
437 request_region(0x3d3, 0x01, "RadeonIGP");
438}
652c538e 439DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RS100, quirk_ati_exploding_mce);
1da177e4 440
be6646bf
HR
441/*
442 * In the AMD NL platform, this device ([1022:7912]) has a class code of
443 * PCI_CLASS_SERIAL_USB_XHCI (0x0c0330), which means the xhci driver will
444 * claim it.
445 * But the dwc3 driver is a more specific driver for this device, and we'd
446 * prefer to use it instead of xhci. To prevent xhci from claiming the
447 * device, change the class code to 0x0c03fe, which the PCI r3.0 spec
448 * defines as "USB device (not host controller)". The dwc3 driver can then
449 * claim it based on its Vendor and Device ID.
450 */
451static void quirk_amd_nl_class(struct pci_dev *pdev)
452{
cd76d10b
BH
453 u32 class = pdev->class;
454
455 /* Use "USB Device (not host controller)" class */
7b78f48a 456 pdev->class = PCI_CLASS_SERIAL_USB_DEVICE;
cd76d10b
BH
457 dev_info(&pdev->dev, "PCI class overridden (%#08x -> %#08x) so dwc3 driver can claim this instead of xhci\n",
458 class, pdev->class);
be6646bf
HR
459}
460DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_NL_USB,
461 quirk_amd_nl_class);
462
1da177e4
LT
463/*
464 * Let's make the southbridge information explicit instead
465 * of having to worry about people probing the ACPI areas,
466 * for example.. (Yes, it happens, and if you read the wrong
467 * ACPI register it will put the machine to sleep with no
468 * way of waking it up again. Bummer).
469 *
470 * ALI M7101: Two IO regions pointed to by words at
471 * 0xE0 (64 bytes of ACPI registers)
472 * 0xE2 (32 bytes of SMB registers)
473 */
15856ad5 474static void quirk_ali7101_acpi(struct pci_dev *dev)
1da177e4 475{
65195c76
YL
476 quirk_io_region(dev, 0xE0, 64, PCI_BRIDGE_RESOURCES, "ali7101 ACPI");
477 quirk_io_region(dev, 0xE2, 32, PCI_BRIDGE_RESOURCES+1, "ali7101 SMB");
1da177e4 478}
652c538e 479DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M7101, quirk_ali7101_acpi);
1da177e4 480
6693e74a
LT
481static void piix4_io_quirk(struct pci_dev *dev, const char *name, unsigned int port, unsigned int enable)
482{
483 u32 devres;
484 u32 mask, size, base;
485
486 pci_read_config_dword(dev, port, &devres);
487 if ((devres & enable) != enable)
488 return;
489 mask = (devres >> 16) & 15;
490 base = devres & 0xffff;
491 size = 16;
492 for (;;) {
493 unsigned bit = size >> 1;
494 if ((bit & mask) == bit)
495 break;
496 size = bit;
497 }
498 /*
499 * For now we only print it out. Eventually we'll want to
500 * reserve it (at least if it's in the 0x1000+ range), but
f7625980 501 * let's get enough confirmation reports first.
6693e74a
LT
502 */
503 base &= -size;
227f0647
RD
504 dev_info(&dev->dev, "%s PIO at %04x-%04x\n", name, base,
505 base + size - 1);
6693e74a
LT
506}
507
508static void piix4_mem_quirk(struct pci_dev *dev, const char *name, unsigned int port, unsigned int enable)
509{
510 u32 devres;
511 u32 mask, size, base;
512
513 pci_read_config_dword(dev, port, &devres);
514 if ((devres & enable) != enable)
515 return;
516 base = devres & 0xffff0000;
517 mask = (devres & 0x3f) << 16;
518 size = 128 << 16;
519 for (;;) {
520 unsigned bit = size >> 1;
521 if ((bit & mask) == bit)
522 break;
523 size = bit;
524 }
525 /*
526 * For now we only print it out. Eventually we'll want to
f7625980 527 * reserve it, but let's get enough confirmation reports first.
6693e74a
LT
528 */
529 base &= -size;
227f0647
RD
530 dev_info(&dev->dev, "%s MMIO at %04x-%04x\n", name, base,
531 base + size - 1);
6693e74a
LT
532}
533
1da177e4
LT
534/*
535 * PIIX4 ACPI: Two IO regions pointed to by longwords at
536 * 0x40 (64 bytes of ACPI registers)
08db2a70 537 * 0x90 (16 bytes of SMB registers)
6693e74a 538 * and a few strange programmable PIIX4 device resources.
1da177e4 539 */
15856ad5 540static void quirk_piix4_acpi(struct pci_dev *dev)
1da177e4 541{
65195c76 542 u32 res_a;
1da177e4 543
65195c76
YL
544 quirk_io_region(dev, 0x40, 64, PCI_BRIDGE_RESOURCES, "PIIX4 ACPI");
545 quirk_io_region(dev, 0x90, 16, PCI_BRIDGE_RESOURCES+1, "PIIX4 SMB");
6693e74a
LT
546
547 /* Device resource A has enables for some of the other ones */
548 pci_read_config_dword(dev, 0x5c, &res_a);
549
550 piix4_io_quirk(dev, "PIIX4 devres B", 0x60, 3 << 21);
551 piix4_io_quirk(dev, "PIIX4 devres C", 0x64, 3 << 21);
552
553 /* Device resource D is just bitfields for static resources */
554
555 /* Device 12 enabled? */
556 if (res_a & (1 << 29)) {
557 piix4_io_quirk(dev, "PIIX4 devres E", 0x68, 1 << 20);
558 piix4_mem_quirk(dev, "PIIX4 devres F", 0x6c, 1 << 7);
559 }
560 /* Device 13 enabled? */
561 if (res_a & (1 << 30)) {
562 piix4_io_quirk(dev, "PIIX4 devres G", 0x70, 1 << 20);
563 piix4_mem_quirk(dev, "PIIX4 devres H", 0x74, 1 << 7);
564 }
565 piix4_io_quirk(dev, "PIIX4 devres I", 0x78, 1 << 20);
566 piix4_io_quirk(dev, "PIIX4 devres J", 0x7c, 1 << 20);
1da177e4 567}
652c538e
AM
568DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82371AB_3, quirk_piix4_acpi);
569DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443MX_3, quirk_piix4_acpi);
1da177e4 570
cdb97558
JS
571#define ICH_PMBASE 0x40
572#define ICH_ACPI_CNTL 0x44
573#define ICH4_ACPI_EN 0x10
574#define ICH6_ACPI_EN 0x80
575#define ICH4_GPIOBASE 0x58
576#define ICH4_GPIO_CNTL 0x5c
577#define ICH4_GPIO_EN 0x10
578#define ICH6_GPIOBASE 0x48
579#define ICH6_GPIO_CNTL 0x4c
580#define ICH6_GPIO_EN 0x10
581
1da177e4
LT
582/*
583 * ICH4, ICH4-M, ICH5, ICH5-M ACPI: Three IO regions pointed to by longwords at
584 * 0x40 (128 bytes of ACPI, GPIO & TCO registers)
585 * 0x58 (64 bytes of GPIO I/O space)
586 */
15856ad5 587static void quirk_ich4_lpc_acpi(struct pci_dev *dev)
1da177e4 588{
cdb97558 589 u8 enable;
1da177e4 590
87e3dc38
JS
591 /*
592 * The check for PCIBIOS_MIN_IO is to ensure we won't create a conflict
593 * with low legacy (and fixed) ports. We don't know the decoding
594 * priority and can't tell whether the legacy device or the one created
595 * here is really at that address. This happens on boards with broken
596 * BIOSes.
597 */
598
cdb97558 599 pci_read_config_byte(dev, ICH_ACPI_CNTL, &enable);
65195c76
YL
600 if (enable & ICH4_ACPI_EN)
601 quirk_io_region(dev, ICH_PMBASE, 128, PCI_BRIDGE_RESOURCES,
602 "ICH4 ACPI/GPIO/TCO");
1da177e4 603
cdb97558 604 pci_read_config_byte(dev, ICH4_GPIO_CNTL, &enable);
65195c76
YL
605 if (enable & ICH4_GPIO_EN)
606 quirk_io_region(dev, ICH4_GPIOBASE, 64, PCI_BRIDGE_RESOURCES+1,
607 "ICH4 GPIO");
1da177e4 608}
652c538e
AM
609DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AA_0, quirk_ich4_lpc_acpi);
610DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AB_0, quirk_ich4_lpc_acpi);
611DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_0, quirk_ich4_lpc_acpi);
612DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_10, quirk_ich4_lpc_acpi);
613DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_0, quirk_ich4_lpc_acpi);
614DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_12, quirk_ich4_lpc_acpi);
615DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_0, quirk_ich4_lpc_acpi);
616DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_12, quirk_ich4_lpc_acpi);
617DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801EB_0, quirk_ich4_lpc_acpi);
618DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ESB_1, quirk_ich4_lpc_acpi);
1da177e4 619
15856ad5 620static void ich6_lpc_acpi_gpio(struct pci_dev *dev)
2cea752f 621{
cdb97558 622 u8 enable;
2cea752f 623
cdb97558 624 pci_read_config_byte(dev, ICH_ACPI_CNTL, &enable);
65195c76
YL
625 if (enable & ICH6_ACPI_EN)
626 quirk_io_region(dev, ICH_PMBASE, 128, PCI_BRIDGE_RESOURCES,
627 "ICH6 ACPI/GPIO/TCO");
2cea752f 628
cdb97558 629 pci_read_config_byte(dev, ICH6_GPIO_CNTL, &enable);
65195c76
YL
630 if (enable & ICH6_GPIO_EN)
631 quirk_io_region(dev, ICH6_GPIOBASE, 64, PCI_BRIDGE_RESOURCES+1,
632 "ICH6 GPIO");
2cea752f 633}
894886e5 634
15856ad5 635static void ich6_lpc_generic_decode(struct pci_dev *dev, unsigned reg, const char *name, int dynsize)
894886e5
LT
636{
637 u32 val;
638 u32 size, base;
639
640 pci_read_config_dword(dev, reg, &val);
641
642 /* Enabled? */
643 if (!(val & 1))
644 return;
645 base = val & 0xfffc;
646 if (dynsize) {
647 /*
648 * This is not correct. It is 16, 32 or 64 bytes depending on
649 * register D31:F0:ADh bits 5:4.
650 *
651 * But this gets us at least _part_ of it.
652 */
653 size = 16;
654 } else {
655 size = 128;
656 }
657 base &= ~(size-1);
658
659 /* Just print it out for now. We should reserve it after more debugging */
660 dev_info(&dev->dev, "%s PIO at %04x-%04x\n", name, base, base+size-1);
661}
662
15856ad5 663static void quirk_ich6_lpc(struct pci_dev *dev)
894886e5
LT
664{
665 /* Shared ACPI/GPIO decode with all ICH6+ */
666 ich6_lpc_acpi_gpio(dev);
667
668 /* ICH6-specific generic IO decode */
669 ich6_lpc_generic_decode(dev, 0x84, "LPC Generic IO decode 1", 0);
670 ich6_lpc_generic_decode(dev, 0x88, "LPC Generic IO decode 2", 1);
671}
672DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH6_0, quirk_ich6_lpc);
673DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH6_1, quirk_ich6_lpc);
674
15856ad5 675static void ich7_lpc_generic_decode(struct pci_dev *dev, unsigned reg, const char *name)
894886e5
LT
676{
677 u32 val;
678 u32 mask, base;
679
680 pci_read_config_dword(dev, reg, &val);
681
682 /* Enabled? */
683 if (!(val & 1))
684 return;
685
686 /*
687 * IO base in bits 15:2, mask in bits 23:18, both
688 * are dword-based
689 */
690 base = val & 0xfffc;
691 mask = (val >> 16) & 0xfc;
692 mask |= 3;
693
694 /* Just print it out for now. We should reserve it after more debugging */
695 dev_info(&dev->dev, "%s PIO at %04x (mask %04x)\n", name, base, mask);
696}
697
698/* ICH7-10 has the same common LPC generic IO decode registers */
15856ad5 699static void quirk_ich7_lpc(struct pci_dev *dev)
894886e5 700{
5d9c0a79 701 /* We share the common ACPI/GPIO decode with ICH6 */
894886e5
LT
702 ich6_lpc_acpi_gpio(dev);
703
704 /* And have 4 ICH7+ generic decodes */
705 ich7_lpc_generic_decode(dev, 0x84, "ICH7 LPC Generic IO decode 1");
706 ich7_lpc_generic_decode(dev, 0x88, "ICH7 LPC Generic IO decode 2");
707 ich7_lpc_generic_decode(dev, 0x8c, "ICH7 LPC Generic IO decode 3");
708 ich7_lpc_generic_decode(dev, 0x90, "ICH7 LPC Generic IO decode 4");
709}
710DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH7_0, quirk_ich7_lpc);
711DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH7_1, quirk_ich7_lpc);
712DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH7_31, quirk_ich7_lpc);
713DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH8_0, quirk_ich7_lpc);
714DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH8_2, quirk_ich7_lpc);
715DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH8_3, quirk_ich7_lpc);
716DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH8_1, quirk_ich7_lpc);
717DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH8_4, quirk_ich7_lpc);
718DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH9_2, quirk_ich7_lpc);
719DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH9_4, quirk_ich7_lpc);
720DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH9_7, quirk_ich7_lpc);
721DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH9_8, quirk_ich7_lpc);
722DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH10_1, quirk_ich7_lpc);
2cea752f 723
1da177e4
LT
724/*
725 * VIA ACPI: One IO region pointed to by longword at
726 * 0x48 or 0x20 (256 bytes of ACPI registers)
727 */
15856ad5 728static void quirk_vt82c586_acpi(struct pci_dev *dev)
1da177e4 729{
65195c76
YL
730 if (dev->revision & 0x10)
731 quirk_io_region(dev, 0x48, 256, PCI_BRIDGE_RESOURCES,
732 "vt82c586 ACPI");
1da177e4 733}
652c538e 734DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C586_3, quirk_vt82c586_acpi);
1da177e4
LT
735
736/*
737 * VIA VT82C686 ACPI: Three IO region pointed to by (long)words at
738 * 0x48 (256 bytes of ACPI registers)
739 * 0x70 (128 bytes of hardware monitoring register)
740 * 0x90 (16 bytes of SMB registers)
741 */
15856ad5 742static void quirk_vt82c686_acpi(struct pci_dev *dev)
1da177e4 743{
1da177e4
LT
744 quirk_vt82c586_acpi(dev);
745
65195c76
YL
746 quirk_io_region(dev, 0x70, 128, PCI_BRIDGE_RESOURCES+1,
747 "vt82c686 HW-mon");
1da177e4 748
65195c76 749 quirk_io_region(dev, 0x90, 16, PCI_BRIDGE_RESOURCES+2, "vt82c686 SMB");
1da177e4 750}
652c538e 751DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C686_4, quirk_vt82c686_acpi);
1da177e4 752
6d85f29b
IK
753/*
754 * VIA VT8235 ISA Bridge: Two IO regions pointed to by words at
755 * 0x88 (128 bytes of power management registers)
756 * 0xd0 (16 bytes of SMB registers)
757 */
15856ad5 758static void quirk_vt8235_acpi(struct pci_dev *dev)
6d85f29b 759{
65195c76
YL
760 quirk_io_region(dev, 0x88, 128, PCI_BRIDGE_RESOURCES, "vt8235 PM");
761 quirk_io_region(dev, 0xd0, 16, PCI_BRIDGE_RESOURCES+1, "vt8235 SMB");
6d85f29b
IK
762}
763DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8235, quirk_vt8235_acpi);
764
1f56f4a2
GB
765/*
766 * TI XIO2000a PCIe-PCI Bridge erroneously reports it supports fast back-to-back:
767 * Disable fast back-to-back on the secondary bus segment
768 */
15856ad5 769static void quirk_xio2000a(struct pci_dev *dev)
1f56f4a2
GB
770{
771 struct pci_dev *pdev;
772 u16 command;
773
227f0647 774 dev_warn(&dev->dev, "TI XIO2000a quirk detected; secondary bus fast back-to-back transfers disabled\n");
1f56f4a2
GB
775 list_for_each_entry(pdev, &dev->subordinate->devices, bus_list) {
776 pci_read_config_word(pdev, PCI_COMMAND, &command);
777 if (command & PCI_COMMAND_FAST_BACK)
778 pci_write_config_word(pdev, PCI_COMMAND, command & ~PCI_COMMAND_FAST_BACK);
779 }
780}
781DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_XIO2000A,
782 quirk_xio2000a);
1da177e4 783
f7625980 784#ifdef CONFIG_X86_IO_APIC
1da177e4
LT
785
786#include <asm/io_apic.h>
787
788/*
789 * VIA 686A/B: If an IO-APIC is active, we need to route all on-chip
790 * devices to the external APIC.
791 *
792 * TODO: When we have device-specific interrupt routers,
793 * this code will go away from quirks.
794 */
1597cacb 795static void quirk_via_ioapic(struct pci_dev *dev)
1da177e4
LT
796{
797 u8 tmp;
f7625980 798
1da177e4
LT
799 if (nr_ioapics < 1)
800 tmp = 0; /* nothing routed to external APIC */
801 else
802 tmp = 0x1f; /* all known bits (4-0) routed to external APIC */
f7625980 803
f0fda801 804 dev_info(&dev->dev, "%sbling VIA external APIC routing\n",
1da177e4
LT
805 tmp == 0 ? "Disa" : "Ena");
806
807 /* Offset 0x58: External APIC IRQ output control */
3c78bc61 808 pci_write_config_byte(dev, 0x58, tmp);
1da177e4 809}
652c538e 810DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C686, quirk_via_ioapic);
e1a2a51e 811DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C686, quirk_via_ioapic);
1da177e4 812
a1740913 813/*
f7625980 814 * VIA 8237: Some BIOSes don't set the 'Bypass APIC De-Assert Message' Bit.
a1740913
KW
815 * This leads to doubled level interrupt rates.
816 * Set this bit to get rid of cycle wastage.
817 * Otherwise uncritical.
818 */
1597cacb 819static void quirk_via_vt8237_bypass_apic_deassert(struct pci_dev *dev)
a1740913
KW
820{
821 u8 misc_control2;
822#define BYPASS_APIC_DEASSERT 8
823
824 pci_read_config_byte(dev, 0x5B, &misc_control2);
825 if (!(misc_control2 & BYPASS_APIC_DEASSERT)) {
f0fda801 826 dev_info(&dev->dev, "Bypassing VIA 8237 APIC De-Assert Message\n");
a1740913
KW
827 pci_write_config_byte(dev, 0x5B, misc_control2|BYPASS_APIC_DEASSERT);
828 }
829}
830DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8237, quirk_via_vt8237_bypass_apic_deassert);
e1a2a51e 831DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8237, quirk_via_vt8237_bypass_apic_deassert);
a1740913 832
1da177e4
LT
833/*
834 * The AMD io apic can hang the box when an apic irq is masked.
835 * We check all revs >= B0 (yet not in the pre production!) as the bug
836 * is currently marked NoFix
837 *
838 * We have multiple reports of hangs with this chipset that went away with
236561e5 839 * noapic specified. For the moment we assume it's the erratum. We may be wrong
1da177e4
LT
840 * of course. However the advice is demonstrably good even if so..
841 */
15856ad5 842static void quirk_amd_ioapic(struct pci_dev *dev)
1da177e4 843{
44c10138 844 if (dev->revision >= 0x02) {
f0fda801 845 dev_warn(&dev->dev, "I/O APIC: AMD Erratum #22 may be present. In the event of instability try\n");
846 dev_warn(&dev->dev, " : booting with the \"noapic\" option\n");
1da177e4
LT
847 }
848}
652c538e 849DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_VIPER_7410, quirk_amd_ioapic);
1da177e4
LT
850#endif /* CONFIG_X86_IO_APIC */
851
0bec9057 852#if defined(CONFIG_ARM64) && defined(CONFIG_PCI_ATS)
21b5b8ee
AJ
853
854static void quirk_cavium_sriov_rnm_link(struct pci_dev *dev)
855{
856 /* Fix for improper SRIOV configuration on Cavium cn88xx RNM device */
857 if (dev->subsystem_device == 0xa118)
858 dev->sriov->link = dev->devfn;
859}
860DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_CAVIUM, 0xa018, quirk_cavium_sriov_rnm_link);
861#endif
862
d556ad4b
PO
863/*
864 * Some settings of MMRBC can lead to data corruption so block changes.
865 * See AMD 8131 HyperTransport PCI-X Tunnel Revision Guide
866 */
15856ad5 867static void quirk_amd_8131_mmrbc(struct pci_dev *dev)
d556ad4b 868{
aa288d4d 869 if (dev->subordinate && dev->revision <= 0x12) {
227f0647
RD
870 dev_info(&dev->dev, "AMD8131 rev %x detected; disabling PCI-X MMRBC\n",
871 dev->revision);
d556ad4b
PO
872 dev->subordinate->bus_flags |= PCI_BUS_FLAGS_NO_MMRBC;
873 }
874}
875DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_8131_BRIDGE, quirk_amd_8131_mmrbc);
1da177e4 876
1da177e4
LT
877/*
878 * FIXME: it is questionable that quirk_via_acpi
879 * is needed. It shows up as an ISA bridge, and does not
880 * support the PCI_INTERRUPT_LINE register at all. Therefore
881 * it seems like setting the pci_dev's 'irq' to the
882 * value of the ACPI SCI interrupt is only done for convenience.
883 * -jgarzik
884 */
15856ad5 885static void quirk_via_acpi(struct pci_dev *d)
1da177e4
LT
886{
887 /*
888 * VIA ACPI device: SCI IRQ line in PCI config byte 0x42
889 */
890 u8 irq;
891 pci_read_config_byte(d, 0x42, &irq);
892 irq &= 0xf;
893 if (irq && (irq != 2))
894 d->irq = irq;
895}
652c538e
AM
896DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C586_3, quirk_via_acpi);
897DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C686_4, quirk_via_acpi);
1da177e4 898
09d6029f
DD
899
900/*
1597cacb 901 * VIA bridges which have VLink
09d6029f 902 */
1597cacb 903
c06bb5d4
JD
904static int via_vlink_dev_lo = -1, via_vlink_dev_hi = 18;
905
906static void quirk_via_bridge(struct pci_dev *dev)
907{
908 /* See what bridge we have and find the device ranges */
909 switch (dev->device) {
910 case PCI_DEVICE_ID_VIA_82C686:
cb7468ef
JD
911 /* The VT82C686 is special, it attaches to PCI and can have
912 any device number. All its subdevices are functions of
913 that single device. */
914 via_vlink_dev_lo = PCI_SLOT(dev->devfn);
915 via_vlink_dev_hi = PCI_SLOT(dev->devfn);
c06bb5d4
JD
916 break;
917 case PCI_DEVICE_ID_VIA_8237:
918 case PCI_DEVICE_ID_VIA_8237A:
919 via_vlink_dev_lo = 15;
920 break;
921 case PCI_DEVICE_ID_VIA_8235:
922 via_vlink_dev_lo = 16;
923 break;
924 case PCI_DEVICE_ID_VIA_8231:
925 case PCI_DEVICE_ID_VIA_8233_0:
926 case PCI_DEVICE_ID_VIA_8233A:
927 case PCI_DEVICE_ID_VIA_8233C_0:
928 via_vlink_dev_lo = 17;
929 break;
930 }
931}
932DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C686, quirk_via_bridge);
933DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8231, quirk_via_bridge);
934DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8233_0, quirk_via_bridge);
935DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8233A, quirk_via_bridge);
936DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8233C_0, quirk_via_bridge);
937DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8235, quirk_via_bridge);
938DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8237, quirk_via_bridge);
939DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8237A, quirk_via_bridge);
09d6029f 940
1597cacb
AC
941/**
942 * quirk_via_vlink - VIA VLink IRQ number update
943 * @dev: PCI device
944 *
945 * If the device we are dealing with is on a PIC IRQ we need to
946 * ensure that the IRQ line register which usually is not relevant
947 * for PCI cards, is actually written so that interrupts get sent
c06bb5d4
JD
948 * to the right place.
949 * We only do this on systems where a VIA south bridge was detected,
950 * and only for VIA devices on the motherboard (see quirk_via_bridge
951 * above).
1597cacb
AC
952 */
953
954static void quirk_via_vlink(struct pci_dev *dev)
25be5e6c
LB
955{
956 u8 irq, new_irq;
957
c06bb5d4
JD
958 /* Check if we have VLink at all */
959 if (via_vlink_dev_lo == -1)
09d6029f
DD
960 return;
961
962 new_irq = dev->irq;
963
964 /* Don't quirk interrupts outside the legacy IRQ range */
965 if (!new_irq || new_irq > 15)
966 return;
967
1597cacb 968 /* Internal device ? */
c06bb5d4
JD
969 if (dev->bus->number != 0 || PCI_SLOT(dev->devfn) > via_vlink_dev_hi ||
970 PCI_SLOT(dev->devfn) < via_vlink_dev_lo)
1597cacb
AC
971 return;
972
973 /* This is an internal VLink device on a PIC interrupt. The BIOS
974 ought to have set this but may not have, so we redo it */
975
25be5e6c
LB
976 pci_read_config_byte(dev, PCI_INTERRUPT_LINE, &irq);
977 if (new_irq != irq) {
f0fda801 978 dev_info(&dev->dev, "VIA VLink IRQ fixup, from %d to %d\n",
979 irq, new_irq);
25be5e6c
LB
980 udelay(15); /* unknown if delay really needed */
981 pci_write_config_byte(dev, PCI_INTERRUPT_LINE, new_irq);
982 }
983}
1597cacb 984DECLARE_PCI_FIXUP_ENABLE(PCI_VENDOR_ID_VIA, PCI_ANY_ID, quirk_via_vlink);
25be5e6c 985
1da177e4
LT
986/*
987 * VIA VT82C598 has its device ID settable and many BIOSes
988 * set it to the ID of VT82C597 for backward compatibility.
989 * We need to switch it off to be able to recognize the real
990 * type of the chip.
991 */
15856ad5 992static void quirk_vt82c598_id(struct pci_dev *dev)
1da177e4
LT
993{
994 pci_write_config_byte(dev, 0xfc, 0);
995 pci_read_config_word(dev, PCI_DEVICE_ID, &dev->device);
996}
652c538e 997DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C597_0, quirk_vt82c598_id);
1da177e4
LT
998
999/*
1000 * CardBus controllers have a legacy base address that enables them
1001 * to respond as i82365 pcmcia controllers. We don't want them to
1002 * do this even if the Linux CardBus driver is not loaded, because
1003 * the Linux i82365 driver does not (and should not) handle CardBus.
1004 */
1597cacb 1005static void quirk_cardbus_legacy(struct pci_dev *dev)
1da177e4 1006{
1da177e4
LT
1007 pci_write_config_dword(dev, PCI_CB_LEGACY_MODE_BASE, 0);
1008}
ae9de56b
YL
1009DECLARE_PCI_FIXUP_CLASS_FINAL(PCI_ANY_ID, PCI_ANY_ID,
1010 PCI_CLASS_BRIDGE_CARDBUS, 8, quirk_cardbus_legacy);
1011DECLARE_PCI_FIXUP_CLASS_RESUME_EARLY(PCI_ANY_ID, PCI_ANY_ID,
1012 PCI_CLASS_BRIDGE_CARDBUS, 8, quirk_cardbus_legacy);
1da177e4
LT
1013
1014/*
1015 * Following the PCI ordering rules is optional on the AMD762. I'm not
1016 * sure what the designers were smoking but let's not inhale...
1017 *
1018 * To be fair to AMD, it follows the spec by default, its BIOS people
1019 * who turn it off!
1020 */
1597cacb 1021static void quirk_amd_ordering(struct pci_dev *dev)
1da177e4
LT
1022{
1023 u32 pcic;
1024 pci_read_config_dword(dev, 0x4C, &pcic);
3c78bc61 1025 if ((pcic & 6) != 6) {
1da177e4 1026 pcic |= 6;
f0fda801 1027 dev_warn(&dev->dev, "BIOS failed to enable PCI standards compliance; fixing this error\n");
1da177e4
LT
1028 pci_write_config_dword(dev, 0x4C, pcic);
1029 pci_read_config_dword(dev, 0x84, &pcic);
3c78bc61 1030 pcic |= (1 << 23); /* Required in this mode */
1da177e4
LT
1031 pci_write_config_dword(dev, 0x84, pcic);
1032 }
1033}
652c538e 1034DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_FE_GATE_700C, quirk_amd_ordering);
e1a2a51e 1035DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_FE_GATE_700C, quirk_amd_ordering);
1da177e4
LT
1036
1037/*
1038 * DreamWorks provided workaround for Dunord I-3000 problem
1039 *
1040 * This card decodes and responds to addresses not apparently
1041 * assigned to it. We force a larger allocation to ensure that
1042 * nothing gets put too close to it.
1043 */
15856ad5 1044static void quirk_dunord(struct pci_dev *dev)
1da177e4 1045{
3c78bc61 1046 struct resource *r = &dev->resource[1];
bd064f0a
BH
1047
1048 r->flags |= IORESOURCE_UNSET;
1da177e4
LT
1049 r->start = 0;
1050 r->end = 0xffffff;
1051}
652c538e 1052DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_DUNORD, PCI_DEVICE_ID_DUNORD_I3000, quirk_dunord);
1da177e4
LT
1053
1054/*
1055 * i82380FB mobile docking controller: its PCI-to-PCI bridge
1056 * is subtractive decoding (transparent), and does indicate this
1057 * in the ProgIf. Unfortunately, the ProgIf value is wrong - 0x80
1058 * instead of 0x01.
1059 */
15856ad5 1060static void quirk_transparent_bridge(struct pci_dev *dev)
1da177e4
LT
1061{
1062 dev->transparent = 1;
1063}
652c538e
AM
1064DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82380FB, quirk_transparent_bridge);
1065DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_TOSHIBA, 0x605, quirk_transparent_bridge);
1da177e4
LT
1066
1067/*
1068 * Common misconfiguration of the MediaGX/Geode PCI master that will
1069 * reduce PCI bandwidth from 70MB/s to 25MB/s. See the GXM/GXLV/GX1
631dd1a8 1070 * datasheets found at http://www.national.com/analog for info on what
1da177e4
LT
1071 * these bits do. <christer@weinigel.se>
1072 */
1597cacb 1073static void quirk_mediagx_master(struct pci_dev *dev)
1da177e4
LT
1074{
1075 u8 reg;
3c78bc61 1076
1da177e4
LT
1077 pci_read_config_byte(dev, 0x41, &reg);
1078 if (reg & 2) {
1079 reg &= ~2;
227f0647
RD
1080 dev_info(&dev->dev, "Fixup for MediaGX/Geode Slave Disconnect Boundary (0x41=0x%02x)\n",
1081 reg);
3c78bc61 1082 pci_write_config_byte(dev, 0x41, reg);
1da177e4
LT
1083 }
1084}
652c538e
AM
1085DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_CYRIX, PCI_DEVICE_ID_CYRIX_PCI_MASTER, quirk_mediagx_master);
1086DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_CYRIX, PCI_DEVICE_ID_CYRIX_PCI_MASTER, quirk_mediagx_master);
1da177e4 1087
1da177e4
LT
1088/*
1089 * Ensure C0 rev restreaming is off. This is normally done by
1090 * the BIOS but in the odd case it is not the results are corruption
1091 * hence the presence of a Linux check
1092 */
1597cacb 1093static void quirk_disable_pxb(struct pci_dev *pdev)
1da177e4
LT
1094{
1095 u16 config;
f7625980 1096
44c10138 1097 if (pdev->revision != 0x04) /* Only C0 requires this */
1da177e4
LT
1098 return;
1099 pci_read_config_word(pdev, 0x40, &config);
1100 if (config & (1<<6)) {
1101 config &= ~(1<<6);
1102 pci_write_config_word(pdev, 0x40, config);
f0fda801 1103 dev_info(&pdev->dev, "C0 revision 450NX. Disabling PCI restreaming\n");
1da177e4
LT
1104 }
1105}
652c538e 1106DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82454NX, quirk_disable_pxb);
e1a2a51e 1107DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82454NX, quirk_disable_pxb);
1da177e4 1108
25e742b2 1109static void quirk_amd_ide_mode(struct pci_dev *pdev)
ab17443a 1110{
5deab536 1111 /* set SBX00/Hudson-2 SATA in IDE mode to AHCI mode */
05a7d22b 1112 u8 tmp;
ab17443a 1113
05a7d22b
CC
1114 pci_read_config_byte(pdev, PCI_CLASS_DEVICE, &tmp);
1115 if (tmp == 0x01) {
ab17443a
CH
1116 pci_read_config_byte(pdev, 0x40, &tmp);
1117 pci_write_config_byte(pdev, 0x40, tmp|1);
1118 pci_write_config_byte(pdev, 0x9, 1);
1119 pci_write_config_byte(pdev, 0xa, 6);
1120 pci_write_config_byte(pdev, 0x40, tmp);
1121
c9f89475 1122 pdev->class = PCI_CLASS_STORAGE_SATA_AHCI;
05a7d22b 1123 dev_info(&pdev->dev, "set SATA to AHCI mode\n");
ab17443a
CH
1124 }
1125}
05a7d22b 1126DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP600_SATA, quirk_amd_ide_mode);
e1a2a51e 1127DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP600_SATA, quirk_amd_ide_mode);
05a7d22b 1128DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP700_SATA, quirk_amd_ide_mode);
e1a2a51e 1129DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP700_SATA, quirk_amd_ide_mode);
5deab536
SH
1130DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_HUDSON2_SATA_IDE, quirk_amd_ide_mode);
1131DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_HUDSON2_SATA_IDE, quirk_amd_ide_mode);
fafe5c3d
SH
1132DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_AMD, 0x7900, quirk_amd_ide_mode);
1133DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_AMD, 0x7900, quirk_amd_ide_mode);
ab17443a 1134
1da177e4
LT
1135/*
1136 * Serverworks CSB5 IDE does not fully support native mode
1137 */
15856ad5 1138static void quirk_svwks_csb5ide(struct pci_dev *pdev)
1da177e4
LT
1139{
1140 u8 prog;
1141 pci_read_config_byte(pdev, PCI_CLASS_PROG, &prog);
1142 if (prog & 5) {
1143 prog &= ~5;
1144 pdev->class &= ~5;
1145 pci_write_config_byte(pdev, PCI_CLASS_PROG, prog);
368c73d4 1146 /* PCI layer will sort out resources */
1da177e4
LT
1147 }
1148}
652c538e 1149DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_SERVERWORKS, PCI_DEVICE_ID_SERVERWORKS_CSB5IDE, quirk_svwks_csb5ide);
1da177e4
LT
1150
1151/*
1152 * Intel 82801CAM ICH3-M datasheet says IDE modes must be the same
1153 */
15856ad5 1154static void quirk_ide_samemode(struct pci_dev *pdev)
1da177e4
LT
1155{
1156 u8 prog;
1157
1158 pci_read_config_byte(pdev, PCI_CLASS_PROG, &prog);
1159
1160 if (((prog & 1) && !(prog & 4)) || ((prog & 4) && !(prog & 1))) {
f0fda801 1161 dev_info(&pdev->dev, "IDE mode mismatch; forcing legacy mode\n");
1da177e4
LT
1162 prog &= ~5;
1163 pdev->class &= ~5;
1164 pci_write_config_byte(pdev, PCI_CLASS_PROG, prog);
1da177e4
LT
1165 }
1166}
368c73d4 1167DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_10, quirk_ide_samemode);
1da177e4 1168
979b1791
AC
1169/*
1170 * Some ATA devices break if put into D3
1171 */
1172
15856ad5 1173static void quirk_no_ata_d3(struct pci_dev *pdev)
979b1791 1174{
faa738bb 1175 pdev->dev_flags |= PCI_DEV_FLAGS_NO_D3;
979b1791 1176}
faa738bb
YL
1177/* Quirk the legacy ATA devices only. The AHCI ones are ok */
1178DECLARE_PCI_FIXUP_CLASS_EARLY(PCI_VENDOR_ID_SERVERWORKS, PCI_ANY_ID,
1179 PCI_CLASS_STORAGE_IDE, 8, quirk_no_ata_d3);
1180DECLARE_PCI_FIXUP_CLASS_EARLY(PCI_VENDOR_ID_ATI, PCI_ANY_ID,
1181 PCI_CLASS_STORAGE_IDE, 8, quirk_no_ata_d3);
7a661c6f 1182/* ALi loses some register settings that we cannot then restore */
faa738bb
YL
1183DECLARE_PCI_FIXUP_CLASS_EARLY(PCI_VENDOR_ID_AL, PCI_ANY_ID,
1184 PCI_CLASS_STORAGE_IDE, 8, quirk_no_ata_d3);
7a661c6f
AC
1185/* VIA comes back fine but we need to keep it alive or ACPI GTM failures
1186 occur when mode detecting */
faa738bb
YL
1187DECLARE_PCI_FIXUP_CLASS_EARLY(PCI_VENDOR_ID_VIA, PCI_ANY_ID,
1188 PCI_CLASS_STORAGE_IDE, 8, quirk_no_ata_d3);
979b1791 1189
1da177e4
LT
1190/* This was originally an Alpha specific thing, but it really fits here.
1191 * The i82375 PCI/EISA bridge appears as non-classified. Fix that.
1192 */
15856ad5 1193static void quirk_eisa_bridge(struct pci_dev *dev)
1da177e4
LT
1194{
1195 dev->class = PCI_CLASS_BRIDGE_EISA << 8;
1196}
652c538e 1197DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82375, quirk_eisa_bridge);
1da177e4 1198
7daa0c4f 1199
1da177e4
LT
1200/*
1201 * On ASUS P4B boards, the SMBus PCI Device within the ICH2/4 southbridge
1202 * is not activated. The myth is that Asus said that they do not want the
1203 * users to be irritated by just another PCI Device in the Win98 device
f7625980 1204 * manager. (see the file prog/hotplug/README.p4b in the lm_sensors
1da177e4
LT
1205 * package 2.7.0 for details)
1206 *
f7625980
BH
1207 * The SMBus PCI Device can be activated by setting a bit in the ICH LPC
1208 * bridge. Unfortunately, this device has no subvendor/subdevice ID. So it
d7698edc 1209 * becomes necessary to do this tweak in two steps -- the chosen trigger
1210 * is either the Host bridge (preferred) or on-board VGA controller.
9208ee82
JD
1211 *
1212 * Note that we used to unhide the SMBus that way on Toshiba laptops
1213 * (Satellite A40 and Tecra M2) but then found that the thermal management
1214 * was done by SMM code, which could cause unsynchronized concurrent
1215 * accesses to the SMBus registers, with potentially bad effects. Thus you
1216 * should be very careful when adding new entries: if SMM is accessing the
1217 * Intel SMBus, this is a very good reason to leave it hidden.
a99acc83
JD
1218 *
1219 * Likewise, many recent laptops use ACPI for thermal management. If the
1220 * ACPI DSDT code accesses the SMBus, then Linux should not access it
1221 * natively, and keeping the SMBus hidden is the right thing to do. If you
1222 * are about to add an entry in the table below, please first disassemble
1223 * the DSDT and double-check that there is no code accessing the SMBus.
1da177e4 1224 */
9d24a81e 1225static int asus_hides_smbus;
1da177e4 1226
15856ad5 1227static void asus_hides_smbus_hostbridge(struct pci_dev *dev)
1da177e4
LT
1228{
1229 if (unlikely(dev->subsystem_vendor == PCI_VENDOR_ID_ASUSTEK)) {
1230 if (dev->device == PCI_DEVICE_ID_INTEL_82845_HB)
3c78bc61 1231 switch (dev->subsystem_device) {
a00db371 1232 case 0x8025: /* P4B-LX */
1da177e4
LT
1233 case 0x8070: /* P4B */
1234 case 0x8088: /* P4B533 */
1235 case 0x1626: /* L3C notebook */
1236 asus_hides_smbus = 1;
1237 }
2f2d39d2 1238 else if (dev->device == PCI_DEVICE_ID_INTEL_82845G_HB)
3c78bc61 1239 switch (dev->subsystem_device) {
1da177e4
LT
1240 case 0x80b1: /* P4GE-V */
1241 case 0x80b2: /* P4PE */
1242 case 0x8093: /* P4B533-V */
1243 asus_hides_smbus = 1;
1244 }
2f2d39d2 1245 else if (dev->device == PCI_DEVICE_ID_INTEL_82850_HB)
3c78bc61 1246 switch (dev->subsystem_device) {
1da177e4
LT
1247 case 0x8030: /* P4T533 */
1248 asus_hides_smbus = 1;
1249 }
2f2d39d2 1250 else if (dev->device == PCI_DEVICE_ID_INTEL_7205_0)
1da177e4
LT
1251 switch (dev->subsystem_device) {
1252 case 0x8070: /* P4G8X Deluxe */
1253 asus_hides_smbus = 1;
1254 }
2f2d39d2 1255 else if (dev->device == PCI_DEVICE_ID_INTEL_E7501_MCH)
321311af
JD
1256 switch (dev->subsystem_device) {
1257 case 0x80c9: /* PU-DLS */
1258 asus_hides_smbus = 1;
1259 }
2f2d39d2 1260 else if (dev->device == PCI_DEVICE_ID_INTEL_82855GM_HB)
1da177e4
LT
1261 switch (dev->subsystem_device) {
1262 case 0x1751: /* M2N notebook */
1263 case 0x1821: /* M5N notebook */
4096ed0f 1264 case 0x1897: /* A6L notebook */
1da177e4
LT
1265 asus_hides_smbus = 1;
1266 }
2f2d39d2 1267 else if (dev->device == PCI_DEVICE_ID_INTEL_82855PM_HB)
1da177e4
LT
1268 switch (dev->subsystem_device) {
1269 case 0x184b: /* W1N notebook */
1270 case 0x186a: /* M6Ne notebook */
1271 asus_hides_smbus = 1;
1272 }
2f2d39d2 1273 else if (dev->device == PCI_DEVICE_ID_INTEL_82865_HB)
2e45785c
JD
1274 switch (dev->subsystem_device) {
1275 case 0x80f2: /* P4P800-X */
1276 asus_hides_smbus = 1;
1277 }
2f2d39d2 1278 else if (dev->device == PCI_DEVICE_ID_INTEL_82915GM_HB)
acc06632
RM
1279 switch (dev->subsystem_device) {
1280 case 0x1882: /* M6V notebook */
2d1e1c75 1281 case 0x1977: /* A6VA notebook */
acc06632
RM
1282 asus_hides_smbus = 1;
1283 }
1da177e4
LT
1284 } else if (unlikely(dev->subsystem_vendor == PCI_VENDOR_ID_HP)) {
1285 if (dev->device == PCI_DEVICE_ID_INTEL_82855PM_HB)
3c78bc61 1286 switch (dev->subsystem_device) {
1da177e4
LT
1287 case 0x088C: /* HP Compaq nc8000 */
1288 case 0x0890: /* HP Compaq nc6000 */
1289 asus_hides_smbus = 1;
1290 }
2f2d39d2 1291 else if (dev->device == PCI_DEVICE_ID_INTEL_82865_HB)
1da177e4
LT
1292 switch (dev->subsystem_device) {
1293 case 0x12bc: /* HP D330L */
e3b1bd57 1294 case 0x12bd: /* HP D530 */
74c57428 1295 case 0x006a: /* HP Compaq nx9500 */
1da177e4
LT
1296 asus_hides_smbus = 1;
1297 }
677cc644
JD
1298 else if (dev->device == PCI_DEVICE_ID_INTEL_82875_HB)
1299 switch (dev->subsystem_device) {
1300 case 0x12bf: /* HP xw4100 */
1301 asus_hides_smbus = 1;
1302 }
3c78bc61
RD
1303 } else if (unlikely(dev->subsystem_vendor == PCI_VENDOR_ID_SAMSUNG)) {
1304 if (dev->device == PCI_DEVICE_ID_INTEL_82855PM_HB)
1305 switch (dev->subsystem_device) {
1306 case 0xC00C: /* Samsung P35 notebook */
1307 asus_hides_smbus = 1;
1308 }
c87f883e
RIZ
1309 } else if (unlikely(dev->subsystem_vendor == PCI_VENDOR_ID_COMPAQ)) {
1310 if (dev->device == PCI_DEVICE_ID_INTEL_82855PM_HB)
3c78bc61 1311 switch (dev->subsystem_device) {
c87f883e
RIZ
1312 case 0x0058: /* Compaq Evo N620c */
1313 asus_hides_smbus = 1;
1314 }
d7698edc 1315 else if (dev->device == PCI_DEVICE_ID_INTEL_82810_IG3)
3c78bc61 1316 switch (dev->subsystem_device) {
d7698edc 1317 case 0xB16C: /* Compaq Deskpro EP 401963-001 (PCA# 010174) */
1318 /* Motherboard doesn't have Host bridge
1319 * subvendor/subdevice IDs, therefore checking
1320 * its on-board VGA controller */
1321 asus_hides_smbus = 1;
1322 }
8293b0f6 1323 else if (dev->device == PCI_DEVICE_ID_INTEL_82801DB_2)
3c78bc61 1324 switch (dev->subsystem_device) {
10260d9a
JD
1325 case 0x00b8: /* Compaq Evo D510 CMT */
1326 case 0x00b9: /* Compaq Evo D510 SFF */
6b5096e4 1327 case 0x00ba: /* Compaq Evo D510 USDT */
8293b0f6
DS
1328 /* Motherboard doesn't have Host bridge
1329 * subvendor/subdevice IDs and on-board VGA
1330 * controller is disabled if an AGP card is
1331 * inserted, therefore checking USB UHCI
1332 * Controller #1 */
10260d9a
JD
1333 asus_hides_smbus = 1;
1334 }
27e46859
KH
1335 else if (dev->device == PCI_DEVICE_ID_INTEL_82815_CGC)
1336 switch (dev->subsystem_device) {
1337 case 0x001A: /* Compaq Deskpro EN SSF P667 815E */
1338 /* Motherboard doesn't have host bridge
1339 * subvendor/subdevice IDs, therefore checking
1340 * its on-board VGA controller */
1341 asus_hides_smbus = 1;
1342 }
1da177e4
LT
1343 }
1344}
652c538e
AM
1345DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82845_HB, asus_hides_smbus_hostbridge);
1346DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82845G_HB, asus_hides_smbus_hostbridge);
1347DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82850_HB, asus_hides_smbus_hostbridge);
1348DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82865_HB, asus_hides_smbus_hostbridge);
677cc644 1349DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82875_HB, asus_hides_smbus_hostbridge);
652c538e
AM
1350DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_7205_0, asus_hides_smbus_hostbridge);
1351DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_E7501_MCH, asus_hides_smbus_hostbridge);
1352DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82855PM_HB, asus_hides_smbus_hostbridge);
1353DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82855GM_HB, asus_hides_smbus_hostbridge);
1354DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82915GM_HB, asus_hides_smbus_hostbridge);
1355
1356DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82810_IG3, asus_hides_smbus_hostbridge);
8293b0f6 1357DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_2, asus_hides_smbus_hostbridge);
27e46859 1358DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82815_CGC, asus_hides_smbus_hostbridge);
d7698edc 1359
1597cacb 1360static void asus_hides_smbus_lpc(struct pci_dev *dev)
1da177e4
LT
1361{
1362 u16 val;
f7625980 1363
1da177e4
LT
1364 if (likely(!asus_hides_smbus))
1365 return;
1366
1367 pci_read_config_word(dev, 0xF2, &val);
1368 if (val & 0x8) {
1369 pci_write_config_word(dev, 0xF2, val & (~0x8));
1370 pci_read_config_word(dev, 0xF2, &val);
1371 if (val & 0x8)
227f0647
RD
1372 dev_info(&dev->dev, "i801 SMBus device continues to play 'hide and seek'! 0x%x\n",
1373 val);
1da177e4 1374 else
f0fda801 1375 dev_info(&dev->dev, "Enabled i801 SMBus device\n");
1da177e4
LT
1376 }
1377}
652c538e
AM
1378DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AA_0, asus_hides_smbus_lpc);
1379DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_0, asus_hides_smbus_lpc);
1380DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_0, asus_hides_smbus_lpc);
1381DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_0, asus_hides_smbus_lpc);
1382DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_12, asus_hides_smbus_lpc);
1383DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_12, asus_hides_smbus_lpc);
1384DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801EB_0, asus_hides_smbus_lpc);
e1a2a51e
RW
1385DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AA_0, asus_hides_smbus_lpc);
1386DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_0, asus_hides_smbus_lpc);
1387DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_0, asus_hides_smbus_lpc);
1388DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_0, asus_hides_smbus_lpc);
1389DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_12, asus_hides_smbus_lpc);
1390DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_12, asus_hides_smbus_lpc);
1391DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801EB_0, asus_hides_smbus_lpc);
1597cacb 1392
e1a2a51e
RW
1393/* It appears we just have one such device. If not, we have a warning */
1394static void __iomem *asus_rcba_base;
1395static void asus_hides_smbus_lpc_ich6_suspend(struct pci_dev *dev)
acc06632 1396{
e1a2a51e 1397 u32 rcba;
acc06632
RM
1398
1399 if (likely(!asus_hides_smbus))
1400 return;
e1a2a51e
RW
1401 WARN_ON(asus_rcba_base);
1402
acc06632 1403 pci_read_config_dword(dev, 0xF0, &rcba);
e1a2a51e
RW
1404 /* use bits 31:14, 16 kB aligned */
1405 asus_rcba_base = ioremap_nocache(rcba & 0xFFFFC000, 0x4000);
1406 if (asus_rcba_base == NULL)
1407 return;
1408}
1409
1410static void asus_hides_smbus_lpc_ich6_resume_early(struct pci_dev *dev)
1411{
1412 u32 val;
1413
1414 if (likely(!asus_hides_smbus || !asus_rcba_base))
1415 return;
1416 /* read the Function Disable register, dword mode only */
1417 val = readl(asus_rcba_base + 0x3418);
1418 writel(val & 0xFFFFFFF7, asus_rcba_base + 0x3418); /* enable the SMBus device */
1419}
1420
1421static void asus_hides_smbus_lpc_ich6_resume(struct pci_dev *dev)
1422{
1423 if (likely(!asus_hides_smbus || !asus_rcba_base))
1424 return;
1425 iounmap(asus_rcba_base);
1426 asus_rcba_base = NULL;
f0fda801 1427 dev_info(&dev->dev, "Enabled ICH6/i801 SMBus device\n");
acc06632 1428}
e1a2a51e
RW
1429
1430static void asus_hides_smbus_lpc_ich6(struct pci_dev *dev)
1431{
1432 asus_hides_smbus_lpc_ich6_suspend(dev);
1433 asus_hides_smbus_lpc_ich6_resume_early(dev);
1434 asus_hides_smbus_lpc_ich6_resume(dev);
1435}
652c538e 1436DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH6_1, asus_hides_smbus_lpc_ich6);
e1a2a51e
RW
1437DECLARE_PCI_FIXUP_SUSPEND(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH6_1, asus_hides_smbus_lpc_ich6_suspend);
1438DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH6_1, asus_hides_smbus_lpc_ich6_resume);
1439DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH6_1, asus_hides_smbus_lpc_ich6_resume_early);
ce007ea5 1440
1da177e4
LT
1441/*
1442 * SiS 96x south bridge: BIOS typically hides SMBus device...
1443 */
1597cacb 1444static void quirk_sis_96x_smbus(struct pci_dev *dev)
1da177e4
LT
1445{
1446 u8 val = 0;
1da177e4 1447 pci_read_config_byte(dev, 0x77, &val);
2f5c33b3 1448 if (val & 0x10) {
f0fda801 1449 dev_info(&dev->dev, "Enabling SiS 96x SMBus\n");
2f5c33b3
MH
1450 pci_write_config_byte(dev, 0x77, val & ~0x10);
1451 }
1da177e4 1452}
652c538e
AM
1453DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_961, quirk_sis_96x_smbus);
1454DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_962, quirk_sis_96x_smbus);
1455DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_963, quirk_sis_96x_smbus);
1456DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_LPC, quirk_sis_96x_smbus);
e1a2a51e
RW
1457DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_961, quirk_sis_96x_smbus);
1458DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_962, quirk_sis_96x_smbus);
1459DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_963, quirk_sis_96x_smbus);
1460DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_LPC, quirk_sis_96x_smbus);
1da177e4 1461
1da177e4
LT
1462/*
1463 * ... This is further complicated by the fact that some SiS96x south
1464 * bridges pretend to be 85C503/5513 instead. In that case see if we
1465 * spotted a compatible north bridge to make sure.
1466 * (pci_find_device doesn't work yet)
1467 *
1468 * We can also enable the sis96x bit in the discovery register..
1469 */
1da177e4
LT
1470#define SIS_DETECT_REGISTER 0x40
1471
1597cacb 1472static void quirk_sis_503(struct pci_dev *dev)
1da177e4
LT
1473{
1474 u8 reg;
1475 u16 devid;
1476
1477 pci_read_config_byte(dev, SIS_DETECT_REGISTER, &reg);
1478 pci_write_config_byte(dev, SIS_DETECT_REGISTER, reg | (1 << 6));
1479 pci_read_config_word(dev, PCI_DEVICE_ID, &devid);
1480 if (((devid & 0xfff0) != 0x0960) && (devid != 0x0018)) {
1481 pci_write_config_byte(dev, SIS_DETECT_REGISTER, reg);
1482 return;
1483 }
1484
1da177e4 1485 /*
2f5c33b3
MH
1486 * Ok, it now shows up as a 96x.. run the 96x quirk by
1487 * hand in case it has already been processed.
1488 * (depends on link order, which is apparently not guaranteed)
1da177e4
LT
1489 */
1490 dev->device = devid;
2f5c33b3 1491 quirk_sis_96x_smbus(dev);
1da177e4 1492}
652c538e 1493DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_503, quirk_sis_503);
e1a2a51e 1494DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_503, quirk_sis_503);
1da177e4 1495
1da177e4 1496
e5548e96
BJD
1497/*
1498 * On ASUS A8V and A8V Deluxe boards, the onboard AC97 audio controller
1499 * and MC97 modem controller are disabled when a second PCI soundcard is
1500 * present. This patch, tweaking the VT8237 ISA bridge, enables them.
1501 * -- bjd
1502 */
1597cacb 1503static void asus_hides_ac97_lpc(struct pci_dev *dev)
e5548e96
BJD
1504{
1505 u8 val;
1506 int asus_hides_ac97 = 0;
1507
1508 if (likely(dev->subsystem_vendor == PCI_VENDOR_ID_ASUSTEK)) {
1509 if (dev->device == PCI_DEVICE_ID_VIA_8237)
1510 asus_hides_ac97 = 1;
1511 }
1512
1513 if (!asus_hides_ac97)
1514 return;
1515
1516 pci_read_config_byte(dev, 0x50, &val);
1517 if (val & 0xc0) {
1518 pci_write_config_byte(dev, 0x50, val & (~0xc0));
1519 pci_read_config_byte(dev, 0x50, &val);
1520 if (val & 0xc0)
227f0647
RD
1521 dev_info(&dev->dev, "Onboard AC97/MC97 devices continue to play 'hide and seek'! 0x%x\n",
1522 val);
e5548e96 1523 else
f0fda801 1524 dev_info(&dev->dev, "Enabled onboard AC97/MC97 devices\n");
e5548e96
BJD
1525 }
1526}
652c538e 1527DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8237, asus_hides_ac97_lpc);
e1a2a51e 1528DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8237, asus_hides_ac97_lpc);
1597cacb 1529
77967052 1530#if defined(CONFIG_ATA) || defined(CONFIG_ATA_MODULE)
15e0c694
AC
1531
1532/*
1533 * If we are using libata we can drive this chip properly but must
1534 * do this early on to make the additional device appear during
1535 * the PCI scanning.
1536 */
5ee2ae7f 1537static void quirk_jmicron_ata(struct pci_dev *pdev)
15e0c694 1538{
e34bb370 1539 u32 conf1, conf5, class;
15e0c694
AC
1540 u8 hdr;
1541
1542 /* Only poke fn 0 */
1543 if (PCI_FUNC(pdev->devfn))
1544 return;
1545
5ee2ae7f
TH
1546 pci_read_config_dword(pdev, 0x40, &conf1);
1547 pci_read_config_dword(pdev, 0x80, &conf5);
15e0c694 1548
5ee2ae7f
TH
1549 conf1 &= ~0x00CFF302; /* Clear bit 1, 8, 9, 12-19, 22, 23 */
1550 conf5 &= ~(1 << 24); /* Clear bit 24 */
1551
1552 switch (pdev->device) {
4daedcfe
TH
1553 case PCI_DEVICE_ID_JMICRON_JMB360: /* SATA single port */
1554 case PCI_DEVICE_ID_JMICRON_JMB362: /* SATA dual ports */
5b6ae5ba 1555 case PCI_DEVICE_ID_JMICRON_JMB364: /* SATA dual ports */
5ee2ae7f
TH
1556 /* The controller should be in single function ahci mode */
1557 conf1 |= 0x0002A100; /* Set 8, 13, 15, 17 */
1558 break;
1559
1560 case PCI_DEVICE_ID_JMICRON_JMB365:
1561 case PCI_DEVICE_ID_JMICRON_JMB366:
1562 /* Redirect IDE second PATA port to the right spot */
1563 conf5 |= (1 << 24);
1564 /* Fall through */
1565 case PCI_DEVICE_ID_JMICRON_JMB361:
1566 case PCI_DEVICE_ID_JMICRON_JMB363:
5b6ae5ba 1567 case PCI_DEVICE_ID_JMICRON_JMB369:
5ee2ae7f
TH
1568 /* Enable dual function mode, AHCI on fn 0, IDE fn1 */
1569 /* Set the class codes correctly and then direct IDE 0 */
3a9e3a51 1570 conf1 |= 0x00C2A1B3; /* Set 0, 1, 4, 5, 7, 8, 13, 15, 17, 22, 23 */
5ee2ae7f
TH
1571 break;
1572
1573 case PCI_DEVICE_ID_JMICRON_JMB368:
1574 /* The controller should be in single function IDE mode */
1575 conf1 |= 0x00C00000; /* Set 22, 23 */
1576 break;
15e0c694 1577 }
5ee2ae7f
TH
1578
1579 pci_write_config_dword(pdev, 0x40, conf1);
1580 pci_write_config_dword(pdev, 0x80, conf5);
1581
1582 /* Update pdev accordingly */
1583 pci_read_config_byte(pdev, PCI_HEADER_TYPE, &hdr);
1584 pdev->hdr_type = hdr & 0x7f;
1585 pdev->multifunction = !!(hdr & 0x80);
e34bb370
TH
1586
1587 pci_read_config_dword(pdev, PCI_CLASS_REVISION, &class);
1588 pdev->class = class >> 8;
15e0c694 1589}
5ee2ae7f
TH
1590DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB360, quirk_jmicron_ata);
1591DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB361, quirk_jmicron_ata);
4daedcfe 1592DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB362, quirk_jmicron_ata);
5ee2ae7f 1593DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB363, quirk_jmicron_ata);
5b6ae5ba 1594DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB364, quirk_jmicron_ata);
5ee2ae7f
TH
1595DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB365, quirk_jmicron_ata);
1596DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB366, quirk_jmicron_ata);
1597DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB368, quirk_jmicron_ata);
5b6ae5ba 1598DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB369, quirk_jmicron_ata);
e1a2a51e
RW
1599DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB360, quirk_jmicron_ata);
1600DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB361, quirk_jmicron_ata);
4daedcfe 1601DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB362, quirk_jmicron_ata);
e1a2a51e 1602DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB363, quirk_jmicron_ata);
5b6ae5ba 1603DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB364, quirk_jmicron_ata);
e1a2a51e
RW
1604DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB365, quirk_jmicron_ata);
1605DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB366, quirk_jmicron_ata);
1606DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB368, quirk_jmicron_ata);
5b6ae5ba 1607DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB369, quirk_jmicron_ata);
15e0c694
AC
1608
1609#endif
1610
91f15fb3
ZR
1611static void quirk_jmicron_async_suspend(struct pci_dev *dev)
1612{
1613 if (dev->multifunction) {
1614 device_disable_async_suspend(&dev->dev);
1615 dev_info(&dev->dev, "async suspend disabled to avoid multi-function power-on ordering issue\n");
1616 }
1617}
1618DECLARE_PCI_FIXUP_CLASS_FINAL(PCI_VENDOR_ID_JMICRON, PCI_ANY_ID, PCI_CLASS_STORAGE_IDE, 8, quirk_jmicron_async_suspend);
1619DECLARE_PCI_FIXUP_CLASS_FINAL(PCI_VENDOR_ID_JMICRON, PCI_ANY_ID, PCI_CLASS_STORAGE_SATA_AHCI, 0, quirk_jmicron_async_suspend);
1620DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_JMICRON, 0x2362, quirk_jmicron_async_suspend);
1621DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_JMICRON, 0x236f, quirk_jmicron_async_suspend);
1622
1da177e4 1623#ifdef CONFIG_X86_IO_APIC
15856ad5 1624static void quirk_alder_ioapic(struct pci_dev *pdev)
1da177e4
LT
1625{
1626 int i;
1627
1628 if ((pdev->class >> 8) != 0xff00)
1629 return;
1630
1631 /* the first BAR is the location of the IO APIC...we must
1632 * not touch this (and it's already covered by the fixmap), so
1633 * forcibly insert it into the resource tree */
1634 if (pci_resource_start(pdev, 0) && pci_resource_len(pdev, 0))
1635 insert_resource(&iomem_resource, &pdev->resource[0]);
1636
1637 /* The next five BARs all seem to be rubbish, so just clean
1638 * them out */
3c78bc61 1639 for (i = 1; i < 6; i++)
1da177e4 1640 memset(&pdev->resource[i], 0, sizeof(pdev->resource[i]));
1da177e4 1641}
652c538e 1642DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_EESSC, quirk_alder_ioapic);
1da177e4
LT
1643#endif
1644
15856ad5 1645static void quirk_pcie_mch(struct pci_dev *pdev)
1da177e4 1646{
0ba379ec 1647 pdev->no_msi = 1;
1da177e4 1648}
652c538e
AM
1649DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_E7520_MCH, quirk_pcie_mch);
1650DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_E7320_MCH, quirk_pcie_mch);
1651DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_E7525_MCH, quirk_pcie_mch);
1da177e4 1652
4602b88d
KA
1653
1654/*
1655 * It's possible for the MSI to get corrupted if shpc and acpi
1656 * are used together on certain PXH-based systems.
1657 */
15856ad5 1658static void quirk_pcie_pxh(struct pci_dev *dev)
4602b88d 1659{
4602b88d 1660 dev->no_msi = 1;
f0fda801 1661 dev_warn(&dev->dev, "PXH quirk detected; SHPC device MSI disabled\n");
4602b88d
KA
1662}
1663DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PXHD_0, quirk_pcie_pxh);
1664DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PXHD_1, quirk_pcie_pxh);
1665DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PXH_0, quirk_pcie_pxh);
1666DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PXH_1, quirk_pcie_pxh);
1667DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PXHV, quirk_pcie_pxh);
1668
ffadcc2f
KCA
1669/*
1670 * Some Intel PCI Express chipsets have trouble with downstream
1671 * device power management.
1672 */
3c78bc61 1673static void quirk_intel_pcie_pm(struct pci_dev *dev)
ffadcc2f
KCA
1674{
1675 pci_pm_d3_delay = 120;
1676 dev->no_d1d2 = 1;
1677}
1678
1679DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x25e2, quirk_intel_pcie_pm);
1680DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x25e3, quirk_intel_pcie_pm);
1681DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x25e4, quirk_intel_pcie_pm);
1682DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x25e5, quirk_intel_pcie_pm);
1683DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x25e6, quirk_intel_pcie_pm);
1684DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x25e7, quirk_intel_pcie_pm);
1685DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x25f7, quirk_intel_pcie_pm);
1686DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x25f8, quirk_intel_pcie_pm);
1687DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x25f9, quirk_intel_pcie_pm);
1688DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x25fa, quirk_intel_pcie_pm);
1689DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x2601, quirk_intel_pcie_pm);
1690DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x2602, quirk_intel_pcie_pm);
1691DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x2603, quirk_intel_pcie_pm);
1692DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x2604, quirk_intel_pcie_pm);
1693DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x2605, quirk_intel_pcie_pm);
1694DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x2606, quirk_intel_pcie_pm);
1695DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x2607, quirk_intel_pcie_pm);
1696DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x2608, quirk_intel_pcie_pm);
1697DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x2609, quirk_intel_pcie_pm);
1698DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x260a, quirk_intel_pcie_pm);
1699DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x260b, quirk_intel_pcie_pm);
4602b88d 1700
426b3b8d 1701#ifdef CONFIG_X86_IO_APIC
e1d3a908
SA
1702/*
1703 * Boot interrupts on some chipsets cannot be turned off. For these chipsets,
1704 * remap the original interrupt in the linux kernel to the boot interrupt, so
1705 * that a PCI device's interrupt handler is installed on the boot interrupt
1706 * line instead.
1707 */
1708static void quirk_reroute_to_boot_interrupts_intel(struct pci_dev *dev)
1709{
41b9eb26 1710 if (noioapicquirk || noioapicreroute)
e1d3a908
SA
1711 return;
1712
1713 dev->irq_reroute_variant = INTEL_IRQ_REROUTE_VARIANT;
fdcdaf6c
BH
1714 dev_info(&dev->dev, "rerouting interrupts for [%04x:%04x]\n",
1715 dev->vendor, dev->device);
e1d3a908 1716}
88d1dce3
OD
1717DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_80333_0, quirk_reroute_to_boot_interrupts_intel);
1718DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_80333_1, quirk_reroute_to_boot_interrupts_intel);
1719DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ESB2_0, quirk_reroute_to_boot_interrupts_intel);
1720DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PXH_0, quirk_reroute_to_boot_interrupts_intel);
1721DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PXH_1, quirk_reroute_to_boot_interrupts_intel);
1722DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PXHV, quirk_reroute_to_boot_interrupts_intel);
1723DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_80332_0, quirk_reroute_to_boot_interrupts_intel);
1724DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_80332_1, quirk_reroute_to_boot_interrupts_intel);
1725DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_80333_0, quirk_reroute_to_boot_interrupts_intel);
1726DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_80333_1, quirk_reroute_to_boot_interrupts_intel);
1727DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ESB2_0, quirk_reroute_to_boot_interrupts_intel);
1728DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PXH_0, quirk_reroute_to_boot_interrupts_intel);
1729DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PXH_1, quirk_reroute_to_boot_interrupts_intel);
1730DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PXHV, quirk_reroute_to_boot_interrupts_intel);
1731DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_80332_0, quirk_reroute_to_boot_interrupts_intel);
1732DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_80332_1, quirk_reroute_to_boot_interrupts_intel);
e1d3a908 1733
426b3b8d
SA
1734/*
1735 * On some chipsets we can disable the generation of legacy INTx boot
1736 * interrupts.
1737 */
1738
1739/*
1740 * IO-APIC1 on 6300ESB generates boot interrupts, see intel order no
1741 * 300641-004US, section 5.7.3.
1742 */
1743#define INTEL_6300_IOAPIC_ABAR 0x40
1744#define INTEL_6300_DISABLE_BOOT_IRQ (1<<14)
1745
1746static void quirk_disable_intel_boot_interrupt(struct pci_dev *dev)
1747{
1748 u16 pci_config_word;
1749
1750 if (noioapicquirk)
1751 return;
1752
1753 pci_read_config_word(dev, INTEL_6300_IOAPIC_ABAR, &pci_config_word);
1754 pci_config_word |= INTEL_6300_DISABLE_BOOT_IRQ;
1755 pci_write_config_word(dev, INTEL_6300_IOAPIC_ABAR, pci_config_word);
1756
fdcdaf6c
BH
1757 dev_info(&dev->dev, "disabled boot interrupts on device [%04x:%04x]\n",
1758 dev->vendor, dev->device);
426b3b8d 1759}
f7625980
BH
1760DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ESB_10, quirk_disable_intel_boot_interrupt);
1761DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ESB_10, quirk_disable_intel_boot_interrupt);
77251188
OD
1762
1763/*
1764 * disable boot interrupts on HT-1000
1765 */
1766#define BC_HT1000_FEATURE_REG 0x64
1767#define BC_HT1000_PIC_REGS_ENABLE (1<<0)
1768#define BC_HT1000_MAP_IDX 0xC00
1769#define BC_HT1000_MAP_DATA 0xC01
1770
1771static void quirk_disable_broadcom_boot_interrupt(struct pci_dev *dev)
1772{
1773 u32 pci_config_dword;
1774 u8 irq;
1775
1776 if (noioapicquirk)
1777 return;
1778
1779 pci_read_config_dword(dev, BC_HT1000_FEATURE_REG, &pci_config_dword);
1780 pci_write_config_dword(dev, BC_HT1000_FEATURE_REG, pci_config_dword |
1781 BC_HT1000_PIC_REGS_ENABLE);
1782
1783 for (irq = 0x10; irq < 0x10 + 32; irq++) {
1784 outb(irq, BC_HT1000_MAP_IDX);
1785 outb(0x00, BC_HT1000_MAP_DATA);
1786 }
1787
1788 pci_write_config_dword(dev, BC_HT1000_FEATURE_REG, pci_config_dword);
1789
fdcdaf6c
BH
1790 dev_info(&dev->dev, "disabled boot interrupts on device [%04x:%04x]\n",
1791 dev->vendor, dev->device);
77251188 1792}
f7625980
BH
1793DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_SERVERWORKS, PCI_DEVICE_ID_SERVERWORKS_HT1000SB, quirk_disable_broadcom_boot_interrupt);
1794DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_SERVERWORKS, PCI_DEVICE_ID_SERVERWORKS_HT1000SB, quirk_disable_broadcom_boot_interrupt);
542622da
OD
1795
1796/*
1797 * disable boot interrupts on AMD and ATI chipsets
1798 */
1799/*
1800 * NOIOAMODE needs to be disabled to disable "boot interrupts". For AMD 8131
1801 * rev. A0 and B0, NOIOAMODE needs to be disabled anyway to fix IO-APIC mode
1802 * (due to an erratum).
1803 */
1804#define AMD_813X_MISC 0x40
1805#define AMD_813X_NOIOAMODE (1<<0)
4fd8bdc5 1806#define AMD_813X_REV_B1 0x12
bbe19443 1807#define AMD_813X_REV_B2 0x13
542622da
OD
1808
1809static void quirk_disable_amd_813x_boot_interrupt(struct pci_dev *dev)
1810{
1811 u32 pci_config_dword;
1812
1813 if (noioapicquirk)
1814 return;
4fd8bdc5
SA
1815 if ((dev->revision == AMD_813X_REV_B1) ||
1816 (dev->revision == AMD_813X_REV_B2))
bbe19443 1817 return;
542622da
OD
1818
1819 pci_read_config_dword(dev, AMD_813X_MISC, &pci_config_dword);
1820 pci_config_dword &= ~AMD_813X_NOIOAMODE;
1821 pci_write_config_dword(dev, AMD_813X_MISC, pci_config_dword);
1822
fdcdaf6c
BH
1823 dev_info(&dev->dev, "disabled boot interrupts on device [%04x:%04x]\n",
1824 dev->vendor, dev->device);
542622da 1825}
4fd8bdc5
SA
1826DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_8131_BRIDGE, quirk_disable_amd_813x_boot_interrupt);
1827DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_8131_BRIDGE, quirk_disable_amd_813x_boot_interrupt);
1828DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_8132_BRIDGE, quirk_disable_amd_813x_boot_interrupt);
1829DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_8132_BRIDGE, quirk_disable_amd_813x_boot_interrupt);
542622da
OD
1830
1831#define AMD_8111_PCI_IRQ_ROUTING 0x56
1832
1833static void quirk_disable_amd_8111_boot_interrupt(struct pci_dev *dev)
1834{
1835 u16 pci_config_word;
1836
1837 if (noioapicquirk)
1838 return;
1839
1840 pci_read_config_word(dev, AMD_8111_PCI_IRQ_ROUTING, &pci_config_word);
1841 if (!pci_config_word) {
227f0647
RD
1842 dev_info(&dev->dev, "boot interrupts on device [%04x:%04x] already disabled\n",
1843 dev->vendor, dev->device);
542622da
OD
1844 return;
1845 }
1846 pci_write_config_word(dev, AMD_8111_PCI_IRQ_ROUTING, 0);
fdcdaf6c
BH
1847 dev_info(&dev->dev, "disabled boot interrupts on device [%04x:%04x]\n",
1848 dev->vendor, dev->device);
542622da 1849}
f7625980
BH
1850DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_8111_SMBUS, quirk_disable_amd_8111_boot_interrupt);
1851DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_8111_SMBUS, quirk_disable_amd_8111_boot_interrupt);
426b3b8d
SA
1852#endif /* CONFIG_X86_IO_APIC */
1853
33dced2e
SS
1854/*
1855 * Toshiba TC86C001 IDE controller reports the standard 8-byte BAR0 size
1856 * but the PIO transfers won't work if BAR0 falls at the odd 8 bytes.
1857 * Re-allocate the region if needed...
1858 */
15856ad5 1859static void quirk_tc86c001_ide(struct pci_dev *dev)
33dced2e
SS
1860{
1861 struct resource *r = &dev->resource[0];
1862
1863 if (r->start & 0x8) {
bd064f0a 1864 r->flags |= IORESOURCE_UNSET;
33dced2e
SS
1865 r->start = 0;
1866 r->end = 0xf;
1867 }
1868}
1869DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_TOSHIBA_2,
1870 PCI_DEVICE_ID_TOSHIBA_TC86C001_IDE,
1871 quirk_tc86c001_ide);
1872
21c5fd97
IA
1873/*
1874 * PLX PCI 9050 PCI Target bridge controller has an errata that prevents the
1875 * local configuration registers accessible via BAR0 (memory) or BAR1 (i/o)
1876 * being read correctly if bit 7 of the base address is set.
1877 * The BAR0 or BAR1 region may be disabled (size 0) or enabled (size 128).
1878 * Re-allocate the regions to a 256-byte boundary if necessary.
1879 */
193c0d68 1880static void quirk_plx_pci9050(struct pci_dev *dev)
21c5fd97
IA
1881{
1882 unsigned int bar;
1883
1884 /* Fixed in revision 2 (PCI 9052). */
1885 if (dev->revision >= 2)
1886 return;
1887 for (bar = 0; bar <= 1; bar++)
1888 if (pci_resource_len(dev, bar) == 0x80 &&
1889 (pci_resource_start(dev, bar) & 0x80)) {
1890 struct resource *r = &dev->resource[bar];
227f0647 1891 dev_info(&dev->dev, "Re-allocating PLX PCI 9050 BAR %u to length 256 to avoid bit 7 bug\n",
21c5fd97 1892 bar);
bd064f0a 1893 r->flags |= IORESOURCE_UNSET;
21c5fd97
IA
1894 r->start = 0;
1895 r->end = 0xff;
1896 }
1897}
1898DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_9050,
1899 quirk_plx_pci9050);
2794bb28
IA
1900/*
1901 * The following Meilhaus (vendor ID 0x1402) device IDs (amongst others)
1902 * may be using the PLX PCI 9050: 0x0630, 0x0940, 0x0950, 0x0960, 0x100b,
1903 * 0x1400, 0x140a, 0x140b, 0x14e0, 0x14ea, 0x14eb, 0x1604, 0x1608, 0x160c,
1904 * 0x168f, 0x2000, 0x2600, 0x3000, 0x810a, 0x810b.
1905 *
1906 * Currently, device IDs 0x2000 and 0x2600 are used by the Comedi "me_daq"
1907 * driver.
1908 */
1909DECLARE_PCI_FIXUP_HEADER(0x1402, 0x2000, quirk_plx_pci9050);
1910DECLARE_PCI_FIXUP_HEADER(0x1402, 0x2600, quirk_plx_pci9050);
21c5fd97 1911
15856ad5 1912static void quirk_netmos(struct pci_dev *dev)
1da177e4
LT
1913{
1914 unsigned int num_parallel = (dev->subsystem_device & 0xf0) >> 4;
1915 unsigned int num_serial = dev->subsystem_device & 0xf;
1916
1917 /*
1918 * These Netmos parts are multiport serial devices with optional
1919 * parallel ports. Even when parallel ports are present, they
1920 * are identified as class SERIAL, which means the serial driver
1921 * will claim them. To prevent this, mark them as class OTHER.
1922 * These combo devices should be claimed by parport_serial.
1923 *
1924 * The subdevice ID is of the form 0x00PS, where <P> is the number
1925 * of parallel ports and <S> is the number of serial ports.
1926 */
1927 switch (dev->device) {
4c9c1686
JS
1928 case PCI_DEVICE_ID_NETMOS_9835:
1929 /* Well, this rule doesn't hold for the following 9835 device */
1930 if (dev->subsystem_vendor == PCI_VENDOR_ID_IBM &&
1931 dev->subsystem_device == 0x0299)
1932 return;
1da177e4
LT
1933 case PCI_DEVICE_ID_NETMOS_9735:
1934 case PCI_DEVICE_ID_NETMOS_9745:
1da177e4
LT
1935 case PCI_DEVICE_ID_NETMOS_9845:
1936 case PCI_DEVICE_ID_NETMOS_9855:
08803efe 1937 if (num_parallel) {
227f0647 1938 dev_info(&dev->dev, "Netmos %04x (%u parallel, %u serial); changing class SERIAL to OTHER (use parport_serial)\n",
1da177e4
LT
1939 dev->device, num_parallel, num_serial);
1940 dev->class = (PCI_CLASS_COMMUNICATION_OTHER << 8) |
1941 (dev->class & 0xff);
1942 }
1943 }
1944}
08803efe
YL
1945DECLARE_PCI_FIXUP_CLASS_HEADER(PCI_VENDOR_ID_NETMOS, PCI_ANY_ID,
1946 PCI_CLASS_COMMUNICATION_SERIAL, 8, quirk_netmos);
1da177e4 1947
da2d03ea
AW
1948/*
1949 * Quirk non-zero PCI functions to route VPD access through function 0 for
1950 * devices that share VPD resources between functions. The functions are
1951 * expected to be identical devices.
1952 */
7aa6ca4d
MR
1953static void quirk_f0_vpd_link(struct pci_dev *dev)
1954{
da2d03ea
AW
1955 struct pci_dev *f0;
1956
1957 if (!PCI_FUNC(dev->devfn))
7aa6ca4d 1958 return;
da2d03ea
AW
1959
1960 f0 = pci_get_slot(dev->bus, PCI_DEVFN(PCI_SLOT(dev->devfn), 0));
1961 if (!f0)
1962 return;
1963
1964 if (f0->vpd && dev->class == f0->class &&
1965 dev->vendor == f0->vendor && dev->device == f0->device)
1966 dev->dev_flags |= PCI_DEV_FLAGS_VPD_REF_F0;
1967
1968 pci_dev_put(f0);
7aa6ca4d
MR
1969}
1970DECLARE_PCI_FIXUP_CLASS_EARLY(PCI_VENDOR_ID_INTEL, PCI_ANY_ID,
1971 PCI_CLASS_NETWORK_ETHERNET, 8, quirk_f0_vpd_link);
1972
15856ad5 1973static void quirk_e100_interrupt(struct pci_dev *dev)
16a74744 1974{
e64aeccb 1975 u16 command, pmcsr;
16a74744
BH
1976 u8 __iomem *csr;
1977 u8 cmd_hi;
1978
1979 switch (dev->device) {
1980 /* PCI IDs taken from drivers/net/e100.c */
1981 case 0x1029:
1982 case 0x1030 ... 0x1034:
1983 case 0x1038 ... 0x103E:
1984 case 0x1050 ... 0x1057:
1985 case 0x1059:
1986 case 0x1064 ... 0x106B:
1987 case 0x1091 ... 0x1095:
1988 case 0x1209:
1989 case 0x1229:
1990 case 0x2449:
1991 case 0x2459:
1992 case 0x245D:
1993 case 0x27DC:
1994 break;
1995 default:
1996 return;
1997 }
1998
1999 /*
2000 * Some firmware hands off the e100 with interrupts enabled,
2001 * which can cause a flood of interrupts if packets are
2002 * received before the driver attaches to the device. So
2003 * disable all e100 interrupts here. The driver will
2004 * re-enable them when it's ready.
2005 */
2006 pci_read_config_word(dev, PCI_COMMAND, &command);
16a74744 2007
1bef7dc0 2008 if (!(command & PCI_COMMAND_MEMORY) || !pci_resource_start(dev, 0))
16a74744
BH
2009 return;
2010
e64aeccb
IK
2011 /*
2012 * Check that the device is in the D0 power state. If it's not,
2013 * there is no point to look any further.
2014 */
728cdb75
YW
2015 if (dev->pm_cap) {
2016 pci_read_config_word(dev, dev->pm_cap + PCI_PM_CTRL, &pmcsr);
e64aeccb
IK
2017 if ((pmcsr & PCI_PM_CTRL_STATE_MASK) != PCI_D0)
2018 return;
2019 }
2020
1bef7dc0
BH
2021 /* Convert from PCI bus to resource space. */
2022 csr = ioremap(pci_resource_start(dev, 0), 8);
16a74744 2023 if (!csr) {
f0fda801 2024 dev_warn(&dev->dev, "Can't map e100 registers\n");
16a74744
BH
2025 return;
2026 }
2027
2028 cmd_hi = readb(csr + 3);
2029 if (cmd_hi == 0) {
227f0647 2030 dev_warn(&dev->dev, "Firmware left e100 interrupts enabled; disabling\n");
16a74744
BH
2031 writeb(1, csr + 3);
2032 }
2033
2034 iounmap(csr);
2035}
4c5b28e2
YL
2036DECLARE_PCI_FIXUP_CLASS_FINAL(PCI_VENDOR_ID_INTEL, PCI_ANY_ID,
2037 PCI_CLASS_NETWORK_ETHERNET, 8, quirk_e100_interrupt);
a5312e28 2038
649426ef
AD
2039/*
2040 * The 82575 and 82598 may experience data corruption issues when transitioning
2041 * out of L0S. To prevent this we need to disable L0S on the pci-e link
2042 */
15856ad5 2043static void quirk_disable_aspm_l0s(struct pci_dev *dev)
649426ef
AD
2044{
2045 dev_info(&dev->dev, "Disabling L0s\n");
2046 pci_disable_link_state(dev, PCIE_LINK_STATE_L0S);
2047}
2048DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x10a7, quirk_disable_aspm_l0s);
2049DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x10a9, quirk_disable_aspm_l0s);
2050DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x10b6, quirk_disable_aspm_l0s);
2051DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x10c6, quirk_disable_aspm_l0s);
2052DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x10c7, quirk_disable_aspm_l0s);
2053DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x10c8, quirk_disable_aspm_l0s);
2054DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x10d6, quirk_disable_aspm_l0s);
2055DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x10db, quirk_disable_aspm_l0s);
2056DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x10dd, quirk_disable_aspm_l0s);
2057DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x10e1, quirk_disable_aspm_l0s);
2058DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x10ec, quirk_disable_aspm_l0s);
2059DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x10f1, quirk_disable_aspm_l0s);
2060DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x10f4, quirk_disable_aspm_l0s);
2061DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x1508, quirk_disable_aspm_l0s);
2062
15856ad5 2063static void fixup_rev1_53c810(struct pci_dev *dev)
a5312e28 2064{
e6323e3c
BH
2065 u32 class = dev->class;
2066
2067 /*
2068 * rev 1 ncr53c810 chips don't set the class at all which means
a5312e28
IK
2069 * they don't get their resources remapped. Fix that here.
2070 */
e6323e3c
BH
2071 if (class)
2072 return;
a5312e28 2073
e6323e3c
BH
2074 dev->class = PCI_CLASS_STORAGE_SCSI << 8;
2075 dev_info(&dev->dev, "NCR 53c810 rev 1 PCI class overridden (%#08x -> %#08x)\n",
2076 class, dev->class);
a5312e28
IK
2077}
2078DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_NCR, PCI_DEVICE_ID_NCR_53C810, fixup_rev1_53c810);
2079
9d265124 2080/* Enable 1k I/O space granularity on the Intel P64H2 */
15856ad5 2081static void quirk_p64h2_1k_io(struct pci_dev *dev)
9d265124
DY
2082{
2083 u16 en1k;
9d265124
DY
2084
2085 pci_read_config_word(dev, 0x40, &en1k);
2086
2087 if (en1k & 0x200) {
f0fda801 2088 dev_info(&dev->dev, "Enable I/O Space to 1KB granularity\n");
2b28ae19 2089 dev->io_window_1k = 1;
9d265124
DY
2090 }
2091}
2092DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x1460, quirk_p64h2_1k_io);
2093
cf34a8e0
BG
2094/* Under some circumstances, AER is not linked with extended capabilities.
2095 * Force it to be linked by setting the corresponding control bit in the
2096 * config space.
2097 */
1597cacb 2098static void quirk_nvidia_ck804_pcie_aer_ext_cap(struct pci_dev *dev)
cf34a8e0
BG
2099{
2100 uint8_t b;
2101 if (pci_read_config_byte(dev, 0xf41, &b) == 0) {
2102 if (!(b & 0x20)) {
2103 pci_write_config_byte(dev, 0xf41, b | 0x20);
227f0647 2104 dev_info(&dev->dev, "Linking AER extended capability\n");
cf34a8e0
BG
2105 }
2106 }
2107}
2108DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_CK804_PCIE,
2109 quirk_nvidia_ck804_pcie_aer_ext_cap);
e1a2a51e 2110DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_CK804_PCIE,
1597cacb 2111 quirk_nvidia_ck804_pcie_aer_ext_cap);
cf34a8e0 2112
15856ad5 2113static void quirk_via_cx700_pci_parking_caching(struct pci_dev *dev)
53a9bf42
TY
2114{
2115 /*
2116 * Disable PCI Bus Parking and PCI Master read caching on CX700
2117 * which causes unspecified timing errors with a VT6212L on the PCI
ca846392
TY
2118 * bus leading to USB2.0 packet loss.
2119 *
2120 * This quirk is only enabled if a second (on the external PCI bus)
2121 * VT6212L is found -- the CX700 core itself also contains a USB
2122 * host controller with the same PCI ID as the VT6212L.
53a9bf42
TY
2123 */
2124
ca846392
TY
2125 /* Count VT6212L instances */
2126 struct pci_dev *p = pci_get_device(PCI_VENDOR_ID_VIA,
2127 PCI_DEVICE_ID_VIA_8235_USB_2, NULL);
53a9bf42 2128 uint8_t b;
ca846392
TY
2129
2130 /* p should contain the first (internal) VT6212L -- see if we have
2131 an external one by searching again */
2132 p = pci_get_device(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8235_USB_2, p);
2133 if (!p)
2134 return;
2135 pci_dev_put(p);
2136
53a9bf42
TY
2137 if (pci_read_config_byte(dev, 0x76, &b) == 0) {
2138 if (b & 0x40) {
2139 /* Turn off PCI Bus Parking */
2140 pci_write_config_byte(dev, 0x76, b ^ 0x40);
2141
227f0647 2142 dev_info(&dev->dev, "Disabling VIA CX700 PCI parking\n");
bc043274
TY
2143 }
2144 }
2145
2146 if (pci_read_config_byte(dev, 0x72, &b) == 0) {
2147 if (b != 0) {
53a9bf42
TY
2148 /* Turn off PCI Master read caching */
2149 pci_write_config_byte(dev, 0x72, 0x0);
bc043274
TY
2150
2151 /* Set PCI Master Bus time-out to "1x16 PCLK" */
53a9bf42 2152 pci_write_config_byte(dev, 0x75, 0x1);
bc043274
TY
2153
2154 /* Disable "Read FIFO Timer" */
53a9bf42
TY
2155 pci_write_config_byte(dev, 0x77, 0x0);
2156
227f0647 2157 dev_info(&dev->dev, "Disabling VIA CX700 PCI caching\n");
53a9bf42
TY
2158 }
2159 }
2160}
ca846392 2161DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_VIA, 0x324e, quirk_via_cx700_pci_parking_caching);
53a9bf42 2162
7c20078a
BM
2163/*
2164 * If a device follows the VPD format spec, the PCI core will not read or
2165 * write past the VPD End Tag. But some vendors do not follow the VPD
2166 * format spec, so we can't tell how much data is safe to access. Devices
2167 * may behave unpredictably if we access too much. Blacklist these devices
2168 * so we don't touch VPD at all.
2169 */
2170static void quirk_blacklist_vpd(struct pci_dev *dev)
2171{
2172 if (dev->vpd) {
2173 dev->vpd->len = 0;
044bc425 2174 dev_warn(&dev->dev, FW_BUG "disabling VPD access (can't determine size of non-standard VPD format)\n");
7c20078a
BM
2175 }
2176}
2177
2178DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_LSI_LOGIC, 0x0060, quirk_blacklist_vpd);
2179DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_LSI_LOGIC, 0x007c, quirk_blacklist_vpd);
2180DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_LSI_LOGIC, 0x0413, quirk_blacklist_vpd);
2181DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_LSI_LOGIC, 0x0078, quirk_blacklist_vpd);
2182DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_LSI_LOGIC, 0x0079, quirk_blacklist_vpd);
2183DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_LSI_LOGIC, 0x0073, quirk_blacklist_vpd);
2184DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_LSI_LOGIC, 0x0071, quirk_blacklist_vpd);
2185DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_LSI_LOGIC, 0x005b, quirk_blacklist_vpd);
2186DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_LSI_LOGIC, 0x002f, quirk_blacklist_vpd);
2187DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_LSI_LOGIC, 0x005d, quirk_blacklist_vpd);
2188DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_LSI_LOGIC, 0x005f, quirk_blacklist_vpd);
2189DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_ATTANSIC, PCI_ANY_ID,
2190 quirk_blacklist_vpd);
2191
99cb233d
BL
2192/*
2193 * For Broadcom 5706, 5708, 5709 rev. A nics, any read beyond the
2194 * VPD end tag will hang the device. This problem was initially
2195 * observed when a vpd entry was created in sysfs
2196 * ('/sys/bus/pci/devices/<id>/vpd'). A read to this sysfs entry
2197 * will dump 32k of data. Reading a full 32k will cause an access
2198 * beyond the VPD end tag causing the device to hang. Once the device
2199 * is hung, the bnx2 driver will not be able to reset the device.
2200 * We believe that it is legal to read beyond the end tag and
2201 * therefore the solution is to limit the read/write length.
2202 */
15856ad5 2203static void quirk_brcm_570x_limit_vpd(struct pci_dev *dev)
99cb233d 2204{
9d82d8ea 2205 /*
35405f25
DH
2206 * Only disable the VPD capability for 5706, 5706S, 5708,
2207 * 5708S and 5709 rev. A
9d82d8ea 2208 */
99cb233d 2209 if ((dev->device == PCI_DEVICE_ID_NX2_5706) ||
35405f25 2210 (dev->device == PCI_DEVICE_ID_NX2_5706S) ||
99cb233d 2211 (dev->device == PCI_DEVICE_ID_NX2_5708) ||
9d82d8ea 2212 (dev->device == PCI_DEVICE_ID_NX2_5708S) ||
99cb233d
BL
2213 ((dev->device == PCI_DEVICE_ID_NX2_5709) &&
2214 (dev->revision & 0xf0) == 0x0)) {
2215 if (dev->vpd)
2216 dev->vpd->len = 0x80;
2217 }
2218}
2219
bffadffd
YZ
2220DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_BROADCOM,
2221 PCI_DEVICE_ID_NX2_5706,
2222 quirk_brcm_570x_limit_vpd);
2223DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_BROADCOM,
2224 PCI_DEVICE_ID_NX2_5706S,
2225 quirk_brcm_570x_limit_vpd);
2226DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_BROADCOM,
2227 PCI_DEVICE_ID_NX2_5708,
2228 quirk_brcm_570x_limit_vpd);
2229DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_BROADCOM,
2230 PCI_DEVICE_ID_NX2_5708S,
2231 quirk_brcm_570x_limit_vpd);
2232DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_BROADCOM,
2233 PCI_DEVICE_ID_NX2_5709,
2234 quirk_brcm_570x_limit_vpd);
2235DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_BROADCOM,
2236 PCI_DEVICE_ID_NX2_5709S,
2237 quirk_brcm_570x_limit_vpd);
99cb233d 2238
25e742b2 2239static void quirk_brcm_5719_limit_mrrs(struct pci_dev *dev)
0b471506
MC
2240{
2241 u32 rev;
2242
2243 pci_read_config_dword(dev, 0xf4, &rev);
2244
2245 /* Only CAP the MRRS if the device is a 5719 A0 */
2246 if (rev == 0x05719000) {
2247 int readrq = pcie_get_readrq(dev);
2248 if (readrq > 2048)
2249 pcie_set_readrq(dev, 2048);
2250 }
2251}
2252
2253DECLARE_PCI_FIXUP_ENABLE(PCI_VENDOR_ID_BROADCOM,
2254 PCI_DEVICE_ID_TIGON3_5719,
2255 quirk_brcm_5719_limit_mrrs);
2256
26c56dc0
MM
2257/* Originally in EDAC sources for i82875P:
2258 * Intel tells BIOS developers to hide device 6 which
2259 * configures the overflow device access containing
2260 * the DRBs - this is where we expose device 6.
2261 * http://www.x86-secret.com/articles/tweak/pat/patsecrets-2.htm
2262 */
15856ad5 2263static void quirk_unhide_mch_dev6(struct pci_dev *dev)
26c56dc0
MM
2264{
2265 u8 reg;
2266
2267 if (pci_read_config_byte(dev, 0xF4, &reg) == 0 && !(reg & 0x02)) {
2268 dev_info(&dev->dev, "Enabling MCH 'Overflow' Device\n");
2269 pci_write_config_byte(dev, 0xF4, reg | 0x02);
2270 }
2271}
2272
2273DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82865_HB,
2274 quirk_unhide_mch_dev6);
2275DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82875_HB,
2276 quirk_unhide_mch_dev6);
2277
12962267 2278#ifdef CONFIG_TILEPRO
f02cbbe6 2279/*
12962267 2280 * The Tilera TILEmpower tilepro platform needs to set the link speed
f02cbbe6
CM
2281 * to 2.5GT(Giga-Transfers)/s (Gen 1). The default link speed
2282 * setting is 5GT/s (Gen 2). 0x98 is the Link Control2 PCIe
2283 * capability register of the PEX8624 PCIe switch. The switch
2284 * supports link speed auto negotiation, but falsely sets
2285 * the link speed to 5GT/s.
2286 */
15856ad5 2287static void quirk_tile_plx_gen1(struct pci_dev *dev)
f02cbbe6
CM
2288{
2289 if (tile_plx_gen1) {
2290 pci_write_config_dword(dev, 0x98, 0x1);
2291 mdelay(50);
2292 }
2293}
2294DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_PLX, 0x8624, quirk_tile_plx_gen1);
12962267 2295#endif /* CONFIG_TILEPRO */
26c56dc0 2296
3f79e107 2297#ifdef CONFIG_PCI_MSI
ebdf7d39
TH
2298/* Some chipsets do not support MSI. We cannot easily rely on setting
2299 * PCI_BUS_FLAGS_NO_MSI in its bus flags because there are actually
f7625980
BH
2300 * some other buses controlled by the chipset even if Linux is not
2301 * aware of it. Instead of setting the flag on all buses in the
ebdf7d39 2302 * machine, simply disable MSI globally.
3f79e107 2303 */
15856ad5 2304static void quirk_disable_all_msi(struct pci_dev *dev)
3f79e107 2305{
88187dfa 2306 pci_no_msi();
f0fda801 2307 dev_warn(&dev->dev, "MSI quirk detected; MSI disabled\n");
3f79e107 2308}
ebdf7d39
TH
2309DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_SERVERWORKS, PCI_DEVICE_ID_SERVERWORKS_GCNB_LE, quirk_disable_all_msi);
2310DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RS400_200, quirk_disable_all_msi);
2311DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RS480, quirk_disable_all_msi);
66d715c9 2312DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_VT3336, quirk_disable_all_msi);
184b812f 2313DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_VT3351, quirk_disable_all_msi);
162dedd3 2314DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_VT3364, quirk_disable_all_msi);
549e1561 2315DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8380_0, quirk_disable_all_msi);
10b4ad1a 2316DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_SI, 0x0761, quirk_disable_all_msi);
3f79e107
BG
2317
2318/* Disable MSI on chipsets that are known to not support it */
15856ad5 2319static void quirk_disable_msi(struct pci_dev *dev)
3f79e107
BG
2320{
2321 if (dev->subordinate) {
227f0647 2322 dev_warn(&dev->dev, "MSI quirk detected; subordinate MSI disabled\n");
3f79e107
BG
2323 dev->subordinate->bus_flags |= PCI_BUS_FLAGS_NO_MSI;
2324 }
2325}
2326DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_8131_BRIDGE, quirk_disable_msi);
134b3450 2327DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_VIA, 0xa238, quirk_disable_msi);
9313ff45 2328DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_ATI, 0x5a3f, quirk_disable_msi);
6397c75c 2329
aff61369
CL
2330/*
2331 * The APC bridge device in AMD 780 family northbridges has some random
2332 * OEM subsystem ID in its vendor ID register (erratum 18), so instead
2333 * we use the possible vendor/device IDs of the host bridge for the
2334 * declared quirk, and search for the APC bridge by slot number.
2335 */
15856ad5 2336static void quirk_amd_780_apc_msi(struct pci_dev *host_bridge)
aff61369
CL
2337{
2338 struct pci_dev *apc_bridge;
2339
2340 apc_bridge = pci_get_slot(host_bridge->bus, PCI_DEVFN(1, 0));
2341 if (apc_bridge) {
2342 if (apc_bridge->device == 0x9602)
2343 quirk_disable_msi(apc_bridge);
2344 pci_dev_put(apc_bridge);
2345 }
2346}
2347DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AMD, 0x9600, quirk_amd_780_apc_msi);
2348DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AMD, 0x9601, quirk_amd_780_apc_msi);
2349
6397c75c
BG
2350/* Go through the list of Hypertransport capabilities and
2351 * return 1 if a HT MSI capability is found and enabled */
25e742b2 2352static int msi_ht_cap_enabled(struct pci_dev *dev)
6397c75c 2353{
fff905f3 2354 int pos, ttl = PCI_FIND_CAP_TTL;
7a380507
ME
2355
2356 pos = pci_find_ht_capability(dev, HT_CAPTYPE_MSI_MAPPING);
2357 while (pos && ttl--) {
2358 u8 flags;
2359
2360 if (pci_read_config_byte(dev, pos + HT_MSI_FLAGS,
3c78bc61 2361 &flags) == 0) {
f0fda801 2362 dev_info(&dev->dev, "Found %s HT MSI Mapping\n",
7a380507 2363 flags & HT_MSI_FLAGS_ENABLE ?
f0fda801 2364 "enabled" : "disabled");
7a380507 2365 return (flags & HT_MSI_FLAGS_ENABLE) != 0;
6397c75c 2366 }
7a380507
ME
2367
2368 pos = pci_find_next_ht_capability(dev, pos,
2369 HT_CAPTYPE_MSI_MAPPING);
6397c75c
BG
2370 }
2371 return 0;
2372}
2373
2374/* Check the hypertransport MSI mapping to know whether MSI is enabled or not */
25e742b2 2375static void quirk_msi_ht_cap(struct pci_dev *dev)
6397c75c
BG
2376{
2377 if (dev->subordinate && !msi_ht_cap_enabled(dev)) {
227f0647 2378 dev_warn(&dev->dev, "MSI quirk detected; subordinate MSI disabled\n");
6397c75c
BG
2379 dev->subordinate->bus_flags |= PCI_BUS_FLAGS_NO_MSI;
2380 }
2381}
2382DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_SERVERWORKS, PCI_DEVICE_ID_SERVERWORKS_HT2000_PCIE,
2383 quirk_msi_ht_cap);
6bae1d96 2384
6397c75c
BG
2385/* The nVidia CK804 chipset may have 2 HT MSI mappings.
2386 * MSI are supported if the MSI capability set in any of these mappings.
2387 */
25e742b2 2388static void quirk_nvidia_ck804_msi_ht_cap(struct pci_dev *dev)
6397c75c
BG
2389{
2390 struct pci_dev *pdev;
2391
2392 if (!dev->subordinate)
2393 return;
2394
2395 /* check HT MSI cap on this chipset and the root one.
2396 * a single one having MSI is enough to be sure that MSI are supported.
2397 */
11f242f0 2398 pdev = pci_get_slot(dev->bus, 0);
9ac0ce85
JJ
2399 if (!pdev)
2400 return;
0c875c28 2401 if (!msi_ht_cap_enabled(dev) && !msi_ht_cap_enabled(pdev)) {
227f0647 2402 dev_warn(&dev->dev, "MSI quirk detected; subordinate MSI disabled\n");
6397c75c
BG
2403 dev->subordinate->bus_flags |= PCI_BUS_FLAGS_NO_MSI;
2404 }
11f242f0 2405 pci_dev_put(pdev);
6397c75c
BG
2406}
2407DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_CK804_PCIE,
2408 quirk_nvidia_ck804_msi_ht_cap);
ba698ad4 2409
415b6d0e 2410/* Force enable MSI mapping capability on HT bridges */
25e742b2 2411static void ht_enable_msi_mapping(struct pci_dev *dev)
9dc625e7 2412{
fff905f3 2413 int pos, ttl = PCI_FIND_CAP_TTL;
9dc625e7
PC
2414
2415 pos = pci_find_ht_capability(dev, HT_CAPTYPE_MSI_MAPPING);
2416 while (pos && ttl--) {
2417 u8 flags;
2418
2419 if (pci_read_config_byte(dev, pos + HT_MSI_FLAGS,
2420 &flags) == 0) {
2421 dev_info(&dev->dev, "Enabling HT MSI Mapping\n");
2422
2423 pci_write_config_byte(dev, pos + HT_MSI_FLAGS,
2424 flags | HT_MSI_FLAGS_ENABLE);
2425 }
2426 pos = pci_find_next_ht_capability(dev, pos,
2427 HT_CAPTYPE_MSI_MAPPING);
2428 }
2429}
415b6d0e
BH
2430DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SERVERWORKS,
2431 PCI_DEVICE_ID_SERVERWORKS_HT1000_PXB,
2432 ht_enable_msi_mapping);
9dc625e7 2433
e0ae4f55
YL
2434DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_8132_BRIDGE,
2435 ht_enable_msi_mapping);
2436
e4146bb9 2437/* The P5N32-SLI motherboards from Asus have a problem with msi
75e07fc3
AP
2438 * for the MCP55 NIC. It is not yet determined whether the msi problem
2439 * also affects other devices. As for now, turn off msi for this device.
2440 */
15856ad5 2441static void nvenet_msi_disable(struct pci_dev *dev)
75e07fc3 2442{
9251bac9
JD
2443 const char *board_name = dmi_get_system_info(DMI_BOARD_NAME);
2444
2445 if (board_name &&
2446 (strstr(board_name, "P5N32-SLI PREMIUM") ||
2447 strstr(board_name, "P5N32-E SLI"))) {
227f0647 2448 dev_info(&dev->dev, "Disabling msi for MCP55 NIC on P5N32-SLI\n");
75e07fc3
AP
2449 dev->no_msi = 1;
2450 }
2451}
2452DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_NVIDIA,
2453 PCI_DEVICE_ID_NVIDIA_NVENET_15,
2454 nvenet_msi_disable);
2455
66db60ea 2456/*
f7625980
BH
2457 * Some versions of the MCP55 bridge from Nvidia have a legacy IRQ routing
2458 * config register. This register controls the routing of legacy
2459 * interrupts from devices that route through the MCP55. If this register
2460 * is misprogrammed, interrupts are only sent to the BSP, unlike
2461 * conventional systems where the IRQ is broadcast to all online CPUs. Not
2462 * having this register set properly prevents kdump from booting up
2463 * properly, so let's make sure that we have it set correctly.
2464 * Note that this is an undocumented register.
66db60ea 2465 */
15856ad5 2466static void nvbridge_check_legacy_irq_routing(struct pci_dev *dev)
66db60ea
NH
2467{
2468 u32 cfg;
2469
49c2fa08
NH
2470 if (!pci_find_capability(dev, PCI_CAP_ID_HT))
2471 return;
2472
66db60ea
NH
2473 pci_read_config_dword(dev, 0x74, &cfg);
2474
2475 if (cfg & ((1 << 2) | (1 << 15))) {
2476 printk(KERN_INFO "Rewriting irq routing register on MCP55\n");
2477 cfg &= ~((1 << 2) | (1 << 15));
2478 pci_write_config_dword(dev, 0x74, cfg);
2479 }
2480}
2481
2482DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_NVIDIA,
2483 PCI_DEVICE_ID_NVIDIA_MCP55_BRIDGE_V0,
2484 nvbridge_check_legacy_irq_routing);
2485
2486DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_NVIDIA,
2487 PCI_DEVICE_ID_NVIDIA_MCP55_BRIDGE_V4,
2488 nvbridge_check_legacy_irq_routing);
2489
25e742b2 2490static int ht_check_msi_mapping(struct pci_dev *dev)
de745306 2491{
fff905f3 2492 int pos, ttl = PCI_FIND_CAP_TTL;
de745306
YL
2493 int found = 0;
2494
2495 /* check if there is HT MSI cap or enabled on this device */
2496 pos = pci_find_ht_capability(dev, HT_CAPTYPE_MSI_MAPPING);
2497 while (pos && ttl--) {
2498 u8 flags;
2499
2500 if (found < 1)
2501 found = 1;
2502 if (pci_read_config_byte(dev, pos + HT_MSI_FLAGS,
2503 &flags) == 0) {
2504 if (flags & HT_MSI_FLAGS_ENABLE) {
2505 if (found < 2) {
2506 found = 2;
2507 break;
2508 }
2509 }
2510 }
2511 pos = pci_find_next_ht_capability(dev, pos,
2512 HT_CAPTYPE_MSI_MAPPING);
2513 }
2514
2515 return found;
2516}
2517
25e742b2 2518static int host_bridge_with_leaf(struct pci_dev *host_bridge)
de745306
YL
2519{
2520 struct pci_dev *dev;
2521 int pos;
2522 int i, dev_no;
2523 int found = 0;
2524
2525 dev_no = host_bridge->devfn >> 3;
2526 for (i = dev_no + 1; i < 0x20; i++) {
2527 dev = pci_get_slot(host_bridge->bus, PCI_DEVFN(i, 0));
2528 if (!dev)
2529 continue;
2530
2531 /* found next host bridge ?*/
2532 pos = pci_find_ht_capability(dev, HT_CAPTYPE_SLAVE);
2533 if (pos != 0) {
2534 pci_dev_put(dev);
2535 break;
2536 }
2537
2538 if (ht_check_msi_mapping(dev)) {
2539 found = 1;
2540 pci_dev_put(dev);
2541 break;
2542 }
2543 pci_dev_put(dev);
2544 }
2545
2546 return found;
2547}
2548
eeafda70
YL
2549#define PCI_HT_CAP_SLAVE_CTRL0 4 /* link control */
2550#define PCI_HT_CAP_SLAVE_CTRL1 8 /* link control to */
2551
25e742b2 2552static int is_end_of_ht_chain(struct pci_dev *dev)
eeafda70
YL
2553{
2554 int pos, ctrl_off;
2555 int end = 0;
2556 u16 flags, ctrl;
2557
2558 pos = pci_find_ht_capability(dev, HT_CAPTYPE_SLAVE);
2559
2560 if (!pos)
2561 goto out;
2562
2563 pci_read_config_word(dev, pos + PCI_CAP_FLAGS, &flags);
2564
2565 ctrl_off = ((flags >> 10) & 1) ?
2566 PCI_HT_CAP_SLAVE_CTRL0 : PCI_HT_CAP_SLAVE_CTRL1;
2567 pci_read_config_word(dev, pos + ctrl_off, &ctrl);
2568
2569 if (ctrl & (1 << 6))
2570 end = 1;
2571
2572out:
2573 return end;
2574}
2575
25e742b2 2576static void nv_ht_enable_msi_mapping(struct pci_dev *dev)
9dc625e7
PC
2577{
2578 struct pci_dev *host_bridge;
1dec6b05
YL
2579 int pos;
2580 int i, dev_no;
2581 int found = 0;
2582
2583 dev_no = dev->devfn >> 3;
2584 for (i = dev_no; i >= 0; i--) {
2585 host_bridge = pci_get_slot(dev->bus, PCI_DEVFN(i, 0));
2586 if (!host_bridge)
2587 continue;
2588
2589 pos = pci_find_ht_capability(host_bridge, HT_CAPTYPE_SLAVE);
2590 if (pos != 0) {
2591 found = 1;
2592 break;
2593 }
2594 pci_dev_put(host_bridge);
2595 }
2596
2597 if (!found)
2598 return;
2599
eeafda70
YL
2600 /* don't enable end_device/host_bridge with leaf directly here */
2601 if (host_bridge == dev && is_end_of_ht_chain(host_bridge) &&
2602 host_bridge_with_leaf(host_bridge))
de745306
YL
2603 goto out;
2604
1dec6b05
YL
2605 /* root did that ! */
2606 if (msi_ht_cap_enabled(host_bridge))
2607 goto out;
2608
2609 ht_enable_msi_mapping(dev);
2610
2611out:
2612 pci_dev_put(host_bridge);
2613}
2614
25e742b2 2615static void ht_disable_msi_mapping(struct pci_dev *dev)
1dec6b05 2616{
fff905f3 2617 int pos, ttl = PCI_FIND_CAP_TTL;
1dec6b05
YL
2618
2619 pos = pci_find_ht_capability(dev, HT_CAPTYPE_MSI_MAPPING);
2620 while (pos && ttl--) {
2621 u8 flags;
2622
2623 if (pci_read_config_byte(dev, pos + HT_MSI_FLAGS,
2624 &flags) == 0) {
6a958d5b 2625 dev_info(&dev->dev, "Disabling HT MSI Mapping\n");
1dec6b05
YL
2626
2627 pci_write_config_byte(dev, pos + HT_MSI_FLAGS,
2628 flags & ~HT_MSI_FLAGS_ENABLE);
2629 }
2630 pos = pci_find_next_ht_capability(dev, pos,
2631 HT_CAPTYPE_MSI_MAPPING);
2632 }
2633}
2634
25e742b2 2635static void __nv_msi_ht_cap_quirk(struct pci_dev *dev, int all)
1dec6b05
YL
2636{
2637 struct pci_dev *host_bridge;
2638 int pos;
2639 int found;
2640
3d2a5318
RW
2641 if (!pci_msi_enabled())
2642 return;
2643
1dec6b05
YL
2644 /* check if there is HT MSI cap or enabled on this device */
2645 found = ht_check_msi_mapping(dev);
2646
2647 /* no HT MSI CAP */
2648 if (found == 0)
2649 return;
9dc625e7
PC
2650
2651 /*
2652 * HT MSI mapping should be disabled on devices that are below
2653 * a non-Hypertransport host bridge. Locate the host bridge...
2654 */
2655 host_bridge = pci_get_bus_and_slot(0, PCI_DEVFN(0, 0));
2656 if (host_bridge == NULL) {
227f0647 2657 dev_warn(&dev->dev, "nv_msi_ht_cap_quirk didn't locate host bridge\n");
9dc625e7
PC
2658 return;
2659 }
2660
2661 pos = pci_find_ht_capability(host_bridge, HT_CAPTYPE_SLAVE);
2662 if (pos != 0) {
2663 /* Host bridge is to HT */
1dec6b05
YL
2664 if (found == 1) {
2665 /* it is not enabled, try to enable it */
de745306
YL
2666 if (all)
2667 ht_enable_msi_mapping(dev);
2668 else
2669 nv_ht_enable_msi_mapping(dev);
1dec6b05 2670 }
dff3aef7 2671 goto out;
9dc625e7
PC
2672 }
2673
1dec6b05
YL
2674 /* HT MSI is not enabled */
2675 if (found == 1)
dff3aef7 2676 goto out;
9dc625e7 2677
1dec6b05
YL
2678 /* Host bridge is not to HT, disable HT MSI mapping on this device */
2679 ht_disable_msi_mapping(dev);
dff3aef7
MS
2680
2681out:
2682 pci_dev_put(host_bridge);
9dc625e7 2683}
de745306 2684
25e742b2 2685static void nv_msi_ht_cap_quirk_all(struct pci_dev *dev)
de745306
YL
2686{
2687 return __nv_msi_ht_cap_quirk(dev, 1);
2688}
2689
25e742b2 2690static void nv_msi_ht_cap_quirk_leaf(struct pci_dev *dev)
de745306
YL
2691{
2692 return __nv_msi_ht_cap_quirk(dev, 0);
2693}
2694
2695DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_NVIDIA, PCI_ANY_ID, nv_msi_ht_cap_quirk_leaf);
6dab62ee 2696DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_NVIDIA, PCI_ANY_ID, nv_msi_ht_cap_quirk_leaf);
de745306
YL
2697
2698DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AL, PCI_ANY_ID, nv_msi_ht_cap_quirk_all);
6dab62ee 2699DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_AL, PCI_ANY_ID, nv_msi_ht_cap_quirk_all);
9dc625e7 2700
15856ad5 2701static void quirk_msi_intx_disable_bug(struct pci_dev *dev)
ba698ad4
DM
2702{
2703 dev->dev_flags |= PCI_DEV_FLAGS_MSI_INTX_DISABLE_BUG;
2704}
15856ad5 2705static void quirk_msi_intx_disable_ati_bug(struct pci_dev *dev)
4600c9d7
SH
2706{
2707 struct pci_dev *p;
2708
2709 /* SB700 MSI issue will be fixed at HW level from revision A21,
2710 * we need check PCI REVISION ID of SMBus controller to get SB700
2711 * revision.
2712 */
2713 p = pci_get_device(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_SBX00_SMBUS,
2714 NULL);
2715 if (!p)
2716 return;
2717
2718 if ((p->revision < 0x3B) && (p->revision >= 0x30))
2719 dev->dev_flags |= PCI_DEV_FLAGS_MSI_INTX_DISABLE_BUG;
2720 pci_dev_put(p);
2721}
70588818
XH
2722static void quirk_msi_intx_disable_qca_bug(struct pci_dev *dev)
2723{
2724 /* AR816X/AR817X/E210X MSI is fixed at HW level from revision 0x18 */
2725 if (dev->revision < 0x18) {
2726 dev_info(&dev->dev, "set MSI_INTX_DISABLE_BUG flag\n");
2727 dev->dev_flags |= PCI_DEV_FLAGS_MSI_INTX_DISABLE_BUG;
2728 }
2729}
ba698ad4
DM
2730DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_BROADCOM,
2731 PCI_DEVICE_ID_TIGON3_5780,
2732 quirk_msi_intx_disable_bug);
2733DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_BROADCOM,
2734 PCI_DEVICE_ID_TIGON3_5780S,
2735 quirk_msi_intx_disable_bug);
2736DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_BROADCOM,
2737 PCI_DEVICE_ID_TIGON3_5714,
2738 quirk_msi_intx_disable_bug);
2739DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_BROADCOM,
2740 PCI_DEVICE_ID_TIGON3_5714S,
2741 quirk_msi_intx_disable_bug);
2742DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_BROADCOM,
2743 PCI_DEVICE_ID_TIGON3_5715,
2744 quirk_msi_intx_disable_bug);
2745DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_BROADCOM,
2746 PCI_DEVICE_ID_TIGON3_5715S,
2747 quirk_msi_intx_disable_bug);
2748
bc38b411 2749DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_ATI, 0x4390,
4600c9d7 2750 quirk_msi_intx_disable_ati_bug);
bc38b411 2751DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_ATI, 0x4391,
4600c9d7 2752 quirk_msi_intx_disable_ati_bug);
bc38b411 2753DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_ATI, 0x4392,
4600c9d7 2754 quirk_msi_intx_disable_ati_bug);
bc38b411 2755DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_ATI, 0x4393,
4600c9d7 2756 quirk_msi_intx_disable_ati_bug);
bc38b411 2757DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_ATI, 0x4394,
4600c9d7 2758 quirk_msi_intx_disable_ati_bug);
bc38b411
DM
2759
2760DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_ATI, 0x4373,
2761 quirk_msi_intx_disable_bug);
2762DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_ATI, 0x4374,
2763 quirk_msi_intx_disable_bug);
2764DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_ATI, 0x4375,
2765 quirk_msi_intx_disable_bug);
2766
7cb6a291
HX
2767DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_ATTANSIC, 0x1062,
2768 quirk_msi_intx_disable_bug);
2769DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_ATTANSIC, 0x1063,
2770 quirk_msi_intx_disable_bug);
2771DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_ATTANSIC, 0x2060,
2772 quirk_msi_intx_disable_bug);
2773DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_ATTANSIC, 0x2062,
2774 quirk_msi_intx_disable_bug);
2775DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_ATTANSIC, 0x1073,
2776 quirk_msi_intx_disable_bug);
2777DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_ATTANSIC, 0x1083,
2778 quirk_msi_intx_disable_bug);
70588818
XH
2779DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_ATTANSIC, 0x1090,
2780 quirk_msi_intx_disable_qca_bug);
2781DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_ATTANSIC, 0x1091,
2782 quirk_msi_intx_disable_qca_bug);
2783DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_ATTANSIC, 0x10a0,
2784 quirk_msi_intx_disable_qca_bug);
2785DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_ATTANSIC, 0x10a1,
2786 quirk_msi_intx_disable_qca_bug);
2787DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_ATTANSIC, 0xe091,
2788 quirk_msi_intx_disable_qca_bug);
3f79e107 2789#endif /* CONFIG_PCI_MSI */
3d137310 2790
3322340a
FR
2791/* Allow manual resource allocation for PCI hotplug bridges
2792 * via pci=hpmemsize=nnM and pci=hpiosize=nnM parameters. For
2793 * some PCI-PCI hotplug bridges, like PLX 6254 (former HINT HB6),
f7625980 2794 * kernel fails to allocate resources when hotplug device is
3322340a
FR
2795 * inserted and PCI bus is rescanned.
2796 */
15856ad5 2797static void quirk_hotplug_bridge(struct pci_dev *dev)
3322340a
FR
2798{
2799 dev->is_hotplug_bridge = 1;
2800}
2801
2802DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_HINT, 0x0020, quirk_hotplug_bridge);
2803
c51689b3
CY
2804/*
2805 * Apple: Avoid programming the memory/io aperture of 00:1c.0
2806 *
2807 * BIOS does not declare any resource for 00:1c.0, but with
2808 * hotplug flag set, thus the OS allocates:
2809 * [mem 0x7fa00000 - 0x7fbfffff]
2810 * [mem 0x7fc00000-0x7fdfffff 64bit pref]
2811 * which is conflict with an unreported device, which
2812 * causes unpredictable result such as accessing io port.
2813 * So clear the hotplug flag to work around it.
2814 */
2815static void quirk_apple_mbp_poweroff(struct pci_dev *dev)
2816{
2817 if (dmi_match(DMI_PRODUCT_NAME, "MacBookPro11,4") ||
2818 dmi_match(DMI_PRODUCT_NAME, "MacBookPro11,5"))
2819 dev->is_hotplug_bridge = 0;
2820}
2821
2822DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x8c10, quirk_apple_mbp_poweroff);
2823
03cd8f7e
ML
2824/*
2825 * This is a quirk for the Ricoh MMC controller found as a part of
2826 * some mulifunction chips.
2827
25985edc 2828 * This is very similar and based on the ricoh_mmc driver written by
03cd8f7e
ML
2829 * Philip Langdale. Thank you for these magic sequences.
2830 *
2831 * These chips implement the four main memory card controllers (SD, MMC, MS, xD)
2832 * and one or both of cardbus or firewire.
2833 *
2834 * It happens that they implement SD and MMC
2835 * support as separate controllers (and PCI functions). The linux SDHCI
2836 * driver supports MMC cards but the chip detects MMC cards in hardware
2837 * and directs them to the MMC controller - so the SDHCI driver never sees
2838 * them.
2839 *
2840 * To get around this, we must disable the useless MMC controller.
2841 * At that point, the SDHCI controller will start seeing them
2842 * It seems to be the case that the relevant PCI registers to deactivate the
2843 * MMC controller live on PCI function 0, which might be the cardbus controller
2844 * or the firewire controller, depending on the particular chip in question
2845 *
2846 * This has to be done early, because as soon as we disable the MMC controller
2847 * other pci functions shift up one level, e.g. function #2 becomes function
2848 * #1, and this will confuse the pci core.
2849 */
2850
2851#ifdef CONFIG_MMC_RICOH_MMC
2852static void ricoh_mmc_fixup_rl5c476(struct pci_dev *dev)
2853{
2854 /* disable via cardbus interface */
2855 u8 write_enable;
2856 u8 write_target;
2857 u8 disable;
2858
2859 /* disable must be done via function #0 */
2860 if (PCI_FUNC(dev->devfn))
2861 return;
2862
2863 pci_read_config_byte(dev, 0xB7, &disable);
2864 if (disable & 0x02)
2865 return;
2866
2867 pci_read_config_byte(dev, 0x8E, &write_enable);
2868 pci_write_config_byte(dev, 0x8E, 0xAA);
2869 pci_read_config_byte(dev, 0x8D, &write_target);
2870 pci_write_config_byte(dev, 0x8D, 0xB7);
2871 pci_write_config_byte(dev, 0xB7, disable | 0x02);
2872 pci_write_config_byte(dev, 0x8E, write_enable);
2873 pci_write_config_byte(dev, 0x8D, write_target);
2874
2875 dev_notice(&dev->dev, "proprietary Ricoh MMC controller disabled (via cardbus function)\n");
2876 dev_notice(&dev->dev, "MMC cards are now supported by standard SDHCI controller\n");
2877}
2878DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_RICOH, PCI_DEVICE_ID_RICOH_RL5C476, ricoh_mmc_fixup_rl5c476);
2879DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_RICOH, PCI_DEVICE_ID_RICOH_RL5C476, ricoh_mmc_fixup_rl5c476);
2880
2881static void ricoh_mmc_fixup_r5c832(struct pci_dev *dev)
2882{
2883 /* disable via firewire interface */
2884 u8 write_enable;
2885 u8 disable;
2886
2887 /* disable must be done via function #0 */
2888 if (PCI_FUNC(dev->devfn))
2889 return;
15bed0f2 2890 /*
812089e0 2891 * RICOH 0xe822 and 0xe823 SD/MMC card readers fail to recognize
15bed0f2
MI
2892 * certain types of SD/MMC cards. Lowering the SD base
2893 * clock frequency from 200Mhz to 50Mhz fixes this issue.
2894 *
2895 * 0x150 - SD2.0 mode enable for changing base clock
2896 * frequency to 50Mhz
2897 * 0xe1 - Base clock frequency
2898 * 0x32 - 50Mhz new clock frequency
2899 * 0xf9 - Key register for 0x150
2900 * 0xfc - key register for 0xe1
2901 */
812089e0
AL
2902 if (dev->device == PCI_DEVICE_ID_RICOH_R5CE822 ||
2903 dev->device == PCI_DEVICE_ID_RICOH_R5CE823) {
15bed0f2
MI
2904 pci_write_config_byte(dev, 0xf9, 0xfc);
2905 pci_write_config_byte(dev, 0x150, 0x10);
2906 pci_write_config_byte(dev, 0xf9, 0x00);
2907 pci_write_config_byte(dev, 0xfc, 0x01);
2908 pci_write_config_byte(dev, 0xe1, 0x32);
2909 pci_write_config_byte(dev, 0xfc, 0x00);
2910
2911 dev_notice(&dev->dev, "MMC controller base frequency changed to 50Mhz.\n");
2912 }
3e309cdf
JB
2913
2914 pci_read_config_byte(dev, 0xCB, &disable);
2915
2916 if (disable & 0x02)
2917 return;
2918
2919 pci_read_config_byte(dev, 0xCA, &write_enable);
2920 pci_write_config_byte(dev, 0xCA, 0x57);
2921 pci_write_config_byte(dev, 0xCB, disable | 0x02);
2922 pci_write_config_byte(dev, 0xCA, write_enable);
2923
2924 dev_notice(&dev->dev, "proprietary Ricoh MMC controller disabled (via firewire function)\n");
2925 dev_notice(&dev->dev, "MMC cards are now supported by standard SDHCI controller\n");
2926
03cd8f7e
ML
2927}
2928DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_RICOH, PCI_DEVICE_ID_RICOH_R5C832, ricoh_mmc_fixup_r5c832);
2929DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_RICOH, PCI_DEVICE_ID_RICOH_R5C832, ricoh_mmc_fixup_r5c832);
812089e0
AL
2930DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_RICOH, PCI_DEVICE_ID_RICOH_R5CE822, ricoh_mmc_fixup_r5c832);
2931DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_RICOH, PCI_DEVICE_ID_RICOH_R5CE822, ricoh_mmc_fixup_r5c832);
be98ca65
MI
2932DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_RICOH, PCI_DEVICE_ID_RICOH_R5CE823, ricoh_mmc_fixup_r5c832);
2933DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_RICOH, PCI_DEVICE_ID_RICOH_R5CE823, ricoh_mmc_fixup_r5c832);
03cd8f7e
ML
2934#endif /*CONFIG_MMC_RICOH_MMC*/
2935
d3f13810 2936#ifdef CONFIG_DMAR_TABLE
254e4200
SS
2937#define VTUNCERRMSK_REG 0x1ac
2938#define VTD_MSK_SPEC_ERRORS (1 << 31)
2939/*
2940 * This is a quirk for masking vt-d spec defined errors to platform error
2941 * handling logic. With out this, platforms using Intel 7500, 5500 chipsets
2942 * (and the derivative chipsets like X58 etc) seem to generate NMI/SMI (based
2943 * on the RAS config settings of the platform) when a vt-d fault happens.
2944 * The resulting SMI caused the system to hang.
2945 *
2946 * VT-d spec related errors are already handled by the VT-d OS code, so no
2947 * need to report the same error through other channels.
2948 */
2949static void vtd_mask_spec_errors(struct pci_dev *dev)
2950{
2951 u32 word;
2952
2953 pci_read_config_dword(dev, VTUNCERRMSK_REG, &word);
2954 pci_write_config_dword(dev, VTUNCERRMSK_REG, word | VTD_MSK_SPEC_ERRORS);
2955}
2956DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL, 0x342e, vtd_mask_spec_errors);
2957DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL, 0x3c28, vtd_mask_spec_errors);
2958#endif
03cd8f7e 2959
15856ad5 2960static void fixup_ti816x_class(struct pci_dev *dev)
63c44080 2961{
d1541dc9
BH
2962 u32 class = dev->class;
2963
63c44080 2964 /* TI 816x devices do not have class code set when in PCIe boot mode */
d1541dc9
BH
2965 dev->class = PCI_CLASS_MULTIMEDIA_VIDEO << 8;
2966 dev_info(&dev->dev, "PCI class overridden (%#08x -> %#08x)\n",
2967 class, dev->class);
63c44080 2968}
40c96236 2969DECLARE_PCI_FIXUP_CLASS_EARLY(PCI_VENDOR_ID_TI, 0xb800,
2b4aed1d 2970 PCI_CLASS_NOT_DEFINED, 8, fixup_ti816x_class);
63c44080 2971
a94d072b
BH
2972/* Some PCIe devices do not work reliably with the claimed maximum
2973 * payload size supported.
2974 */
15856ad5 2975static void fixup_mpss_256(struct pci_dev *dev)
a94d072b
BH
2976{
2977 dev->pcie_mpss = 1; /* 256 bytes */
2978}
2979DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SOLARFLARE,
2980 PCI_DEVICE_ID_SOLARFLARE_SFC4000A_0, fixup_mpss_256);
2981DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SOLARFLARE,
2982 PCI_DEVICE_ID_SOLARFLARE_SFC4000A_1, fixup_mpss_256);
2983DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SOLARFLARE,
2984 PCI_DEVICE_ID_SOLARFLARE_SFC4000B, fixup_mpss_256);
2985
d387a8d6
JM
2986/* Intel 5000 and 5100 Memory controllers have an errata with read completion
2987 * coalescing (which is enabled by default on some BIOSes) and MPS of 256B.
2988 * Since there is no way of knowing what the PCIE MPS on each fabric will be
2989 * until all of the devices are discovered and buses walked, read completion
2990 * coalescing must be disabled. Unfortunately, it cannot be re-enabled because
2991 * it is possible to hotplug a device with MPS of 256B.
2992 */
15856ad5 2993static void quirk_intel_mc_errata(struct pci_dev *dev)
d387a8d6
JM
2994{
2995 int err;
2996 u16 rcc;
2997
27d868b5
KB
2998 if (pcie_bus_config == PCIE_BUS_TUNE_OFF ||
2999 pcie_bus_config == PCIE_BUS_DEFAULT)
d387a8d6
JM
3000 return;
3001
3002 /* Intel errata specifies bits to change but does not say what they are.
3003 * Keeping them magical until such time as the registers and values can
3004 * be explained.
3005 */
3006 err = pci_read_config_word(dev, 0x48, &rcc);
3007 if (err) {
227f0647 3008 dev_err(&dev->dev, "Error attempting to read the read completion coalescing register\n");
d387a8d6
JM
3009 return;
3010 }
3011
3012 if (!(rcc & (1 << 10)))
3013 return;
3014
3015 rcc &= ~(1 << 10);
3016
3017 err = pci_write_config_word(dev, 0x48, rcc);
3018 if (err) {
227f0647 3019 dev_err(&dev->dev, "Error attempting to write the read completion coalescing register\n");
d387a8d6
JM
3020 return;
3021 }
3022
227f0647 3023 pr_info_once("Read completion coalescing disabled due to hardware errata relating to 256B MPS\n");
d387a8d6
JM
3024}
3025/* Intel 5000 series memory controllers and ports 2-7 */
3026DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x25c0, quirk_intel_mc_errata);
3027DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x25d0, quirk_intel_mc_errata);
3028DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x25d4, quirk_intel_mc_errata);
3029DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x25d8, quirk_intel_mc_errata);
3030DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x25e2, quirk_intel_mc_errata);
3031DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x25e3, quirk_intel_mc_errata);
3032DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x25e4, quirk_intel_mc_errata);
3033DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x25e5, quirk_intel_mc_errata);
3034DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x25e6, quirk_intel_mc_errata);
3035DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x25e7, quirk_intel_mc_errata);
3036DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x25f7, quirk_intel_mc_errata);
3037DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x25f8, quirk_intel_mc_errata);
3038DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x25f9, quirk_intel_mc_errata);
3039DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x25fa, quirk_intel_mc_errata);
3040/* Intel 5100 series memory controllers and ports 2-7 */
3041DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x65c0, quirk_intel_mc_errata);
3042DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x65e2, quirk_intel_mc_errata);
3043DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x65e3, quirk_intel_mc_errata);
3044DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x65e4, quirk_intel_mc_errata);
3045DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x65e5, quirk_intel_mc_errata);
3046DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x65e6, quirk_intel_mc_errata);
3047DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x65e7, quirk_intel_mc_errata);
3048DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x65f7, quirk_intel_mc_errata);
3049DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x65f8, quirk_intel_mc_errata);
3050DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x65f9, quirk_intel_mc_errata);
3051DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x65fa, quirk_intel_mc_errata);
3052
3209874a 3053
12b03188
JM
3054/*
3055 * Ivytown NTB BAR sizes are misreported by the hardware due to an erratum. To
3056 * work around this, query the size it should be configured to by the device and
3057 * modify the resource end to correspond to this new size.
3058 */
3059static void quirk_intel_ntb(struct pci_dev *dev)
3060{
3061 int rc;
3062 u8 val;
3063
3064 rc = pci_read_config_byte(dev, 0x00D0, &val);
3065 if (rc)
3066 return;
3067
3068 dev->resource[2].end = dev->resource[2].start + ((u64) 1 << val) - 1;
3069
3070 rc = pci_read_config_byte(dev, 0x00D1, &val);
3071 if (rc)
3072 return;
3073
3074 dev->resource[4].end = dev->resource[4].start + ((u64) 1 << val) - 1;
3075}
3076DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x0e08, quirk_intel_ntb);
3077DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x0e0d, quirk_intel_ntb);
3078
2729d5b1
MS
3079static ktime_t fixup_debug_start(struct pci_dev *dev,
3080 void (*fn)(struct pci_dev *dev))
3209874a 3081{
8b0e1953 3082 ktime_t calltime = 0;
2729d5b1
MS
3083
3084 dev_dbg(&dev->dev, "calling %pF\n", fn);
3085 if (initcall_debug) {
3086 pr_debug("calling %pF @ %i for %s\n",
3087 fn, task_pid_nr(current), dev_name(&dev->dev));
3088 calltime = ktime_get();
3089 }
3090
3091 return calltime;
3092}
3093
3094static void fixup_debug_report(struct pci_dev *dev, ktime_t calltime,
3095 void (*fn)(struct pci_dev *dev))
3209874a 3096{
2729d5b1 3097 ktime_t delta, rettime;
3209874a
AV
3098 unsigned long long duration;
3099
2729d5b1
MS
3100 if (initcall_debug) {
3101 rettime = ktime_get();
3102 delta = ktime_sub(rettime, calltime);
3103 duration = (unsigned long long) ktime_to_ns(delta) >> 10;
3104 pr_debug("pci fixup %pF returned after %lld usecs for %s\n",
3105 fn, duration, dev_name(&dev->dev));
3106 }
3209874a
AV
3107}
3108
f67fd55f
TJ
3109/*
3110 * Some BIOS implementations leave the Intel GPU interrupts enabled,
3111 * even though no one is handling them (f.e. i915 driver is never loaded).
3112 * Additionally the interrupt destination is not set up properly
3113 * and the interrupt ends up -somewhere-.
3114 *
3115 * These spurious interrupts are "sticky" and the kernel disables
3116 * the (shared) interrupt line after 100.000+ generated interrupts.
3117 *
3118 * Fix it by disabling the still enabled interrupts.
3119 * This resolves crashes often seen on monitor unplug.
3120 */
3121#define I915_DEIER_REG 0x4400c
15856ad5 3122static void disable_igfx_irq(struct pci_dev *dev)
f67fd55f
TJ
3123{
3124 void __iomem *regs = pci_iomap(dev, 0, 0);
3125 if (regs == NULL) {
3126 dev_warn(&dev->dev, "igfx quirk: Can't iomap PCI device\n");
3127 return;
3128 }
3129
3130 /* Check if any interrupt line is still enabled */
3131 if (readl(regs + I915_DEIER_REG) != 0) {
227f0647 3132 dev_warn(&dev->dev, "BIOS left Intel GPU interrupts enabled; disabling\n");
f67fd55f
TJ
3133
3134 writel(0, regs + I915_DEIER_REG);
3135 }
3136
3137 pci_iounmap(dev, regs);
3138}
3139DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x0102, disable_igfx_irq);
3140DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x010a, disable_igfx_irq);
7c82126a 3141DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x0152, disable_igfx_irq);
f67fd55f 3142
b8cac70a
TB
3143/*
3144 * PCI devices which are on Intel chips can skip the 10ms delay
3145 * before entering D3 mode.
3146 */
3147static void quirk_remove_d3_delay(struct pci_dev *dev)
3148{
3149 dev->d3_delay = 0;
3150}
3151DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x0c00, quirk_remove_d3_delay);
3152DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x0412, quirk_remove_d3_delay);
3153DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x0c0c, quirk_remove_d3_delay);
3154DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x8c31, quirk_remove_d3_delay);
3155DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x8c3a, quirk_remove_d3_delay);
3156DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x8c3d, quirk_remove_d3_delay);
3157DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x8c2d, quirk_remove_d3_delay);
3158DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x8c20, quirk_remove_d3_delay);
3159DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x8c18, quirk_remove_d3_delay);
3160DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x8c1c, quirk_remove_d3_delay);
3161DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x8c26, quirk_remove_d3_delay);
3162DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x8c4e, quirk_remove_d3_delay);
3163DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x8c02, quirk_remove_d3_delay);
3164DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x8c22, quirk_remove_d3_delay);
4a118753
SK
3165/* Intel Cherrytrail devices do not need 10ms d3_delay */
3166DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x2280, quirk_remove_d3_delay);
3167DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x22b0, quirk_remove_d3_delay);
3168DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x22b8, quirk_remove_d3_delay);
3169DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x22d8, quirk_remove_d3_delay);
3170DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x22dc, quirk_remove_d3_delay);
3171DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x22b5, quirk_remove_d3_delay);
3172DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x22b7, quirk_remove_d3_delay);
3173DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x2298, quirk_remove_d3_delay);
3174DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x229c, quirk_remove_d3_delay);
d76d2fe0 3175
fbebb9fd 3176/*
d76d2fe0 3177 * Some devices may pass our check in pci_intx_mask_supported() if
fbebb9fd
BH
3178 * PCI_COMMAND_INTX_DISABLE works though they actually do not properly
3179 * support this feature.
3180 */
15856ad5 3181static void quirk_broken_intx_masking(struct pci_dev *dev)
fbebb9fd
BH
3182{
3183 dev->broken_intx_masking = 1;
3184}
b88214ce
NO
3185DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_CHELSIO, 0x0030,
3186 quirk_broken_intx_masking);
3187DECLARE_PCI_FIXUP_FINAL(0x1814, 0x0601, /* Ralink RT2800 802.11n PCI */
3188 quirk_broken_intx_masking);
d76d2fe0 3189
3cb30b73
AW
3190/*
3191 * Realtek RTL8169 PCI Gigabit Ethernet Controller (rev 10)
3192 * Subsystem: Realtek RTL8169/8110 Family PCI Gigabit Ethernet NIC
3193 *
3194 * RTL8110SC - Fails under PCI device assignment using DisINTx masking.
3195 */
b88214ce
NO
3196DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_REALTEK, 0x8169,
3197 quirk_broken_intx_masking);
fbebb9fd 3198
8bcf4525
AW
3199/*
3200 * Intel i40e (XL710/X710) 10/20/40GbE NICs all have broken INTx masking,
3201 * DisINTx can be set but the interrupt status bit is non-functional.
3202 */
b88214ce
NO
3203DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x1572,
3204 quirk_broken_intx_masking);
3205DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x1574,
3206 quirk_broken_intx_masking);
3207DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x1580,
3208 quirk_broken_intx_masking);
3209DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x1581,
3210 quirk_broken_intx_masking);
3211DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x1583,
3212 quirk_broken_intx_masking);
3213DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x1584,
3214 quirk_broken_intx_masking);
3215DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x1585,
3216 quirk_broken_intx_masking);
3217DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x1586,
3218 quirk_broken_intx_masking);
3219DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x1587,
3220 quirk_broken_intx_masking);
3221DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x1588,
3222 quirk_broken_intx_masking);
3223DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x1589,
3224 quirk_broken_intx_masking);
3225DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x37d0,
3226 quirk_broken_intx_masking);
3227DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x37d1,
3228 quirk_broken_intx_masking);
3229DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x37d2,
3230 quirk_broken_intx_masking);
8bcf4525 3231
d76d2fe0
NO
3232static u16 mellanox_broken_intx_devs[] = {
3233 PCI_DEVICE_ID_MELLANOX_HERMON_SDR,
3234 PCI_DEVICE_ID_MELLANOX_HERMON_DDR,
3235 PCI_DEVICE_ID_MELLANOX_HERMON_QDR,
3236 PCI_DEVICE_ID_MELLANOX_HERMON_DDR_GEN2,
3237 PCI_DEVICE_ID_MELLANOX_HERMON_QDR_GEN2,
3238 PCI_DEVICE_ID_MELLANOX_HERMON_EN,
3239 PCI_DEVICE_ID_MELLANOX_HERMON_EN_GEN2,
3240 PCI_DEVICE_ID_MELLANOX_CONNECTX_EN,
3241 PCI_DEVICE_ID_MELLANOX_CONNECTX_EN_T_GEN2,
3242 PCI_DEVICE_ID_MELLANOX_CONNECTX_EN_GEN2,
3243 PCI_DEVICE_ID_MELLANOX_CONNECTX_EN_5_GEN2,
3244 PCI_DEVICE_ID_MELLANOX_CONNECTX2,
3245 PCI_DEVICE_ID_MELLANOX_CONNECTX3,
3246 PCI_DEVICE_ID_MELLANOX_CONNECTX3_PRO,
d76d2fe0
NO
3247};
3248
1600f625
NO
3249#define CONNECTX_4_CURR_MAX_MINOR 99
3250#define CONNECTX_4_INTX_SUPPORT_MINOR 14
3251
3252/*
3253 * Check ConnectX-4/LX FW version to see if it supports legacy interrupts.
3254 * If so, don't mark it as broken.
3255 * FW minor > 99 means older FW version format and no INTx masking support.
3256 * FW minor < 14 means new FW version format and no INTx masking support.
3257 */
d76d2fe0
NO
3258static void mellanox_check_broken_intx_masking(struct pci_dev *pdev)
3259{
1600f625
NO
3260 __be32 __iomem *fw_ver;
3261 u16 fw_major;
3262 u16 fw_minor;
3263 u16 fw_subminor;
3264 u32 fw_maj_min;
3265 u32 fw_sub_min;
d76d2fe0
NO
3266 int i;
3267
3268 for (i = 0; i < ARRAY_SIZE(mellanox_broken_intx_devs); i++) {
3269 if (pdev->device == mellanox_broken_intx_devs[i]) {
3270 pdev->broken_intx_masking = 1;
3271 return;
3272 }
3273 }
1600f625
NO
3274
3275 /* Getting here means Connect-IB cards and up. Connect-IB has no INTx
3276 * support so shouldn't be checked further
3277 */
3278 if (pdev->device == PCI_DEVICE_ID_MELLANOX_CONNECTIB)
3279 return;
3280
3281 if (pdev->device != PCI_DEVICE_ID_MELLANOX_CONNECTX4 &&
3282 pdev->device != PCI_DEVICE_ID_MELLANOX_CONNECTX4_LX)
3283 return;
3284
3285 /* For ConnectX-4 and ConnectX-4LX, need to check FW support */
3286 if (pci_enable_device_mem(pdev)) {
3287 dev_warn(&pdev->dev, "Can't enable device memory\n");
3288 return;
3289 }
3290
3291 fw_ver = ioremap(pci_resource_start(pdev, 0), 4);
3292 if (!fw_ver) {
3293 dev_warn(&pdev->dev, "Can't map ConnectX-4 initialization segment\n");
3294 goto out;
3295 }
3296
3297 /* Reading from resource space should be 32b aligned */
3298 fw_maj_min = ioread32be(fw_ver);
3299 fw_sub_min = ioread32be(fw_ver + 1);
3300 fw_major = fw_maj_min & 0xffff;
3301 fw_minor = fw_maj_min >> 16;
3302 fw_subminor = fw_sub_min & 0xffff;
3303 if (fw_minor > CONNECTX_4_CURR_MAX_MINOR ||
3304 fw_minor < CONNECTX_4_INTX_SUPPORT_MINOR) {
3305 dev_warn(&pdev->dev, "ConnectX-4: FW %u.%u.%u doesn't support INTx masking, disabling. Please upgrade FW to %d.14.1100 and up for INTx support\n",
3306 fw_major, fw_minor, fw_subminor, pdev->device ==
3307 PCI_DEVICE_ID_MELLANOX_CONNECTX4 ? 12 : 14);
3308 pdev->broken_intx_masking = 1;
3309 }
3310
3311 iounmap(fw_ver);
3312
3313out:
3314 pci_disable_device(pdev);
d76d2fe0
NO
3315}
3316DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_MELLANOX, PCI_ANY_ID,
3317 mellanox_check_broken_intx_masking);
8bcf4525 3318
c3e59ee4
AW
3319static void quirk_no_bus_reset(struct pci_dev *dev)
3320{
3321 dev->dev_flags |= PCI_DEV_FLAGS_NO_BUS_RESET;
3322}
3323
3324/*
9ac0108c
CB
3325 * Some Atheros AR9xxx and QCA988x chips do not behave after a bus reset.
3326 * The device will throw a Link Down error on AER-capable systems and
3327 * regardless of AER, config space of the device is never accessible again
3328 * and typically causes the system to hang or reset when access is attempted.
c3e59ee4
AW
3329 * http://www.spinics.net/lists/linux-pci/msg34797.html
3330 */
3331DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_ATHEROS, 0x0030, quirk_no_bus_reset);
9ac0108c
CB
3332DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_ATHEROS, 0x0032, quirk_no_bus_reset);
3333DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_ATHEROS, 0x003c, quirk_no_bus_reset);
8e2e0317 3334DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_ATHEROS, 0x0033, quirk_no_bus_reset);
c3e59ee4 3335
d84f3174
AW
3336static void quirk_no_pm_reset(struct pci_dev *dev)
3337{
3338 /*
3339 * We can't do a bus reset on root bus devices, but an ineffective
3340 * PM reset may be better than nothing.
3341 */
3342 if (!pci_is_root_bus(dev->bus))
3343 dev->dev_flags |= PCI_DEV_FLAGS_NO_PM_RESET;
3344}
3345
3346/*
3347 * Some AMD/ATI GPUS (HD8570 - Oland) report that a D3hot->D0 transition
3348 * causes a reset (i.e., they advertise NoSoftRst-). This transition seems
3349 * to have no effect on the device: it retains the framebuffer contents and
3350 * monitor sync. Advertising this support makes other layers, like VFIO,
3351 * assume pci_reset_function() is viable for this device. Mark it as
3352 * unavailable to skip it when testing reset methods.
3353 */
3354DECLARE_PCI_FIXUP_CLASS_HEADER(PCI_VENDOR_ID_ATI, PCI_ANY_ID,
3355 PCI_CLASS_DISPLAY_VGA, 8, quirk_no_pm_reset);
3356
19bf4d4f
LW
3357/*
3358 * Thunderbolt controllers with broken MSI hotplug signaling:
3359 * Entire 1st generation (Light Ridge, Eagle Ridge, Light Peak) and part
3360 * of the 2nd generation (Cactus Ridge 4C up to revision 1, Port Ridge).
3361 */
3362static void quirk_thunderbolt_hotplug_msi(struct pci_dev *pdev)
3363{
3364 if (pdev->is_hotplug_bridge &&
3365 (pdev->device != PCI_DEVICE_ID_INTEL_CACTUS_RIDGE_4C ||
3366 pdev->revision <= 1))
3367 pdev->no_msi = 1;
3368}
3369DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_LIGHT_RIDGE,
3370 quirk_thunderbolt_hotplug_msi);
3371DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_EAGLE_RIDGE,
3372 quirk_thunderbolt_hotplug_msi);
3373DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_LIGHT_PEAK,
3374 quirk_thunderbolt_hotplug_msi);
3375DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_CACTUS_RIDGE_4C,
3376 quirk_thunderbolt_hotplug_msi);
3377DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PORT_RIDGE,
3378 quirk_thunderbolt_hotplug_msi);
3379
1c7de2b4
AK
3380static void quirk_chelsio_extend_vpd(struct pci_dev *dev)
3381{
3382 pci_set_vpd_size(dev, 8192);
3383}
3384
3385DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_CHELSIO, 0x20, quirk_chelsio_extend_vpd);
3386DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_CHELSIO, 0x21, quirk_chelsio_extend_vpd);
3387DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_CHELSIO, 0x22, quirk_chelsio_extend_vpd);
3388DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_CHELSIO, 0x23, quirk_chelsio_extend_vpd);
3389DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_CHELSIO, 0x24, quirk_chelsio_extend_vpd);
3390DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_CHELSIO, 0x25, quirk_chelsio_extend_vpd);
3391DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_CHELSIO, 0x26, quirk_chelsio_extend_vpd);
3392DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_CHELSIO, 0x30, quirk_chelsio_extend_vpd);
3393DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_CHELSIO, 0x31, quirk_chelsio_extend_vpd);
3394DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_CHELSIO, 0x32, quirk_chelsio_extend_vpd);
3395DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_CHELSIO, 0x35, quirk_chelsio_extend_vpd);
3396DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_CHELSIO, 0x36, quirk_chelsio_extend_vpd);
3397DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_CHELSIO, 0x37, quirk_chelsio_extend_vpd);
3398
1df5172c
AN
3399#ifdef CONFIG_ACPI
3400/*
3401 * Apple: Shutdown Cactus Ridge Thunderbolt controller.
3402 *
3403 * On Apple hardware the Cactus Ridge Thunderbolt controller needs to be
3404 * shutdown before suspend. Otherwise the native host interface (NHI) will not
3405 * be present after resume if a device was plugged in before suspend.
3406 *
3407 * The thunderbolt controller consists of a pcie switch with downstream
3408 * bridges leading to the NHI and to the tunnel pci bridges.
3409 *
3410 * This quirk cuts power to the whole chip. Therefore we have to apply it
3411 * during suspend_noirq of the upstream bridge.
3412 *
3413 * Power is automagically restored before resume. No action is needed.
3414 */
3415static void quirk_apple_poweroff_thunderbolt(struct pci_dev *dev)
3416{
3417 acpi_handle bridge, SXIO, SXFP, SXLV;
3418
3419 if (!dmi_match(DMI_BOARD_VENDOR, "Apple Inc."))
3420 return;
3421 if (pci_pcie_type(dev) != PCI_EXP_TYPE_UPSTREAM)
3422 return;
3423 bridge = ACPI_HANDLE(&dev->dev);
3424 if (!bridge)
3425 return;
3426 /*
3427 * SXIO and SXLV are present only on machines requiring this quirk.
3428 * TB bridges in external devices might have the same device id as those
3429 * on the host, but they will not have the associated ACPI methods. This
3430 * implicitly checks that we are at the right bridge.
3431 */
3432 if (ACPI_FAILURE(acpi_get_handle(bridge, "DSB0.NHI0.SXIO", &SXIO))
3433 || ACPI_FAILURE(acpi_get_handle(bridge, "DSB0.NHI0.SXFP", &SXFP))
3434 || ACPI_FAILURE(acpi_get_handle(bridge, "DSB0.NHI0.SXLV", &SXLV)))
3435 return;
3436 dev_info(&dev->dev, "quirk: cutting power to thunderbolt controller...\n");
3437
3438 /* magic sequence */
3439 acpi_execute_simple_method(SXIO, NULL, 1);
3440 acpi_execute_simple_method(SXFP, NULL, 0);
3441 msleep(300);
3442 acpi_execute_simple_method(SXLV, NULL, 0);
3443 acpi_execute_simple_method(SXIO, NULL, 0);
3444 acpi_execute_simple_method(SXLV, NULL, 0);
3445}
1d111406
LW
3446DECLARE_PCI_FIXUP_SUSPEND_LATE(PCI_VENDOR_ID_INTEL,
3447 PCI_DEVICE_ID_INTEL_CACTUS_RIDGE_4C,
1df5172c
AN
3448 quirk_apple_poweroff_thunderbolt);
3449
3450/*
3451 * Apple: Wait for the thunderbolt controller to reestablish pci tunnels.
3452 *
3453 * During suspend the thunderbolt controller is reset and all pci
3454 * tunnels are lost. The NHI driver will try to reestablish all tunnels
3455 * during resume. We have to manually wait for the NHI since there is
3456 * no parent child relationship between the NHI and the tunneled
3457 * bridges.
3458 */
3459static void quirk_apple_wait_for_thunderbolt(struct pci_dev *dev)
3460{
3461 struct pci_dev *sibling = NULL;
3462 struct pci_dev *nhi = NULL;
3463
3464 if (!dmi_match(DMI_BOARD_VENDOR, "Apple Inc."))
3465 return;
3466 if (pci_pcie_type(dev) != PCI_EXP_TYPE_DOWNSTREAM)
3467 return;
3468 /*
3469 * Find the NHI and confirm that we are a bridge on the tb host
3470 * controller and not on a tb endpoint.
3471 */
3472 sibling = pci_get_slot(dev->bus, 0x0);
3473 if (sibling == dev)
3474 goto out; /* we are the downstream bridge to the NHI */
3475 if (!sibling || !sibling->subordinate)
3476 goto out;
3477 nhi = pci_get_slot(sibling->subordinate, 0x0);
3478 if (!nhi)
3479 goto out;
3480 if (nhi->vendor != PCI_VENDOR_ID_INTEL
19bf4d4f
LW
3481 || (nhi->device != PCI_DEVICE_ID_INTEL_LIGHT_RIDGE &&
3482 nhi->device != PCI_DEVICE_ID_INTEL_CACTUS_RIDGE_4C &&
82a6a81c 3483 nhi->device != PCI_DEVICE_ID_INTEL_FALCON_RIDGE_2C_NHI &&
1d111406 3484 nhi->device != PCI_DEVICE_ID_INTEL_FALCON_RIDGE_4C_NHI)
25eb7e5c 3485 || nhi->class != PCI_CLASS_SYSTEM_OTHER << 8)
1df5172c 3486 goto out;
c89ac443 3487 dev_info(&dev->dev, "quirk: waiting for thunderbolt to reestablish PCI tunnels...\n");
1df5172c
AN
3488 device_pm_wait_for_dev(&dev->dev, &nhi->dev);
3489out:
3490 pci_dev_put(nhi);
3491 pci_dev_put(sibling);
3492}
19bf4d4f
LW
3493DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_INTEL,
3494 PCI_DEVICE_ID_INTEL_LIGHT_RIDGE,
1df5172c 3495 quirk_apple_wait_for_thunderbolt);
1d111406
LW
3496DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_INTEL,
3497 PCI_DEVICE_ID_INTEL_CACTUS_RIDGE_4C,
1df5172c 3498 quirk_apple_wait_for_thunderbolt);
82a6a81c
XG
3499DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_INTEL,
3500 PCI_DEVICE_ID_INTEL_FALCON_RIDGE_2C_BRIDGE,
3501 quirk_apple_wait_for_thunderbolt);
1d111406
LW
3502DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_INTEL,
3503 PCI_DEVICE_ID_INTEL_FALCON_RIDGE_4C_BRIDGE,
1df5172c
AN
3504 quirk_apple_wait_for_thunderbolt);
3505#endif
3506
bfb0f330
JB
3507static void pci_do_fixups(struct pci_dev *dev, struct pci_fixup *f,
3508 struct pci_fixup *end)
3d137310 3509{
2729d5b1
MS
3510 ktime_t calltime;
3511
f4ca5c6a
YL
3512 for (; f < end; f++)
3513 if ((f->class == (u32) (dev->class >> f->class_shift) ||
3514 f->class == (u32) PCI_ANY_ID) &&
3515 (f->vendor == dev->vendor ||
3516 f->vendor == (u16) PCI_ANY_ID) &&
3517 (f->device == dev->device ||
3518 f->device == (u16) PCI_ANY_ID)) {
2729d5b1
MS
3519 calltime = fixup_debug_start(dev, f->hook);
3520 f->hook(dev);
3521 fixup_debug_report(dev, calltime, f->hook);
3d137310 3522 }
3d137310
TP
3523}
3524
3525extern struct pci_fixup __start_pci_fixups_early[];
3526extern struct pci_fixup __end_pci_fixups_early[];
3527extern struct pci_fixup __start_pci_fixups_header[];
3528extern struct pci_fixup __end_pci_fixups_header[];
3529extern struct pci_fixup __start_pci_fixups_final[];
3530extern struct pci_fixup __end_pci_fixups_final[];
3531extern struct pci_fixup __start_pci_fixups_enable[];
3532extern struct pci_fixup __end_pci_fixups_enable[];
3533extern struct pci_fixup __start_pci_fixups_resume[];
3534extern struct pci_fixup __end_pci_fixups_resume[];
3535extern struct pci_fixup __start_pci_fixups_resume_early[];
3536extern struct pci_fixup __end_pci_fixups_resume_early[];
3537extern struct pci_fixup __start_pci_fixups_suspend[];
3538extern struct pci_fixup __end_pci_fixups_suspend[];
7d2a01b8
AN
3539extern struct pci_fixup __start_pci_fixups_suspend_late[];
3540extern struct pci_fixup __end_pci_fixups_suspend_late[];
3d137310 3541
95df8b87 3542static bool pci_apply_fixup_final_quirks;
3d137310
TP
3543
3544void pci_fixup_device(enum pci_fixup_pass pass, struct pci_dev *dev)
3545{
3546 struct pci_fixup *start, *end;
3547
3c78bc61 3548 switch (pass) {
3d137310
TP
3549 case pci_fixup_early:
3550 start = __start_pci_fixups_early;
3551 end = __end_pci_fixups_early;
3552 break;
3553
3554 case pci_fixup_header:
3555 start = __start_pci_fixups_header;
3556 end = __end_pci_fixups_header;
3557 break;
3558
3559 case pci_fixup_final:
95df8b87
MS
3560 if (!pci_apply_fixup_final_quirks)
3561 return;
3d137310
TP
3562 start = __start_pci_fixups_final;
3563 end = __end_pci_fixups_final;
3564 break;
3565
3566 case pci_fixup_enable:
3567 start = __start_pci_fixups_enable;
3568 end = __end_pci_fixups_enable;
3569 break;
3570
3571 case pci_fixup_resume:
3572 start = __start_pci_fixups_resume;
3573 end = __end_pci_fixups_resume;
3574 break;
3575
3576 case pci_fixup_resume_early:
3577 start = __start_pci_fixups_resume_early;
3578 end = __end_pci_fixups_resume_early;
3579 break;
3580
3581 case pci_fixup_suspend:
3582 start = __start_pci_fixups_suspend;
3583 end = __end_pci_fixups_suspend;
3584 break;
3585
7d2a01b8
AN
3586 case pci_fixup_suspend_late:
3587 start = __start_pci_fixups_suspend_late;
3588 end = __end_pci_fixups_suspend_late;
3589 break;
3590
3d137310
TP
3591 default:
3592 /* stupid compiler warning, you would think with an enum... */
3593 return;
3594 }
3595 pci_do_fixups(dev, start, end);
3596}
93177a74 3597EXPORT_SYMBOL(pci_fixup_device);
8d86fb2c 3598
735bff10 3599
00010268 3600static int __init pci_apply_final_quirks(void)
8d86fb2c
DW
3601{
3602 struct pci_dev *dev = NULL;
ac1aa47b
JB
3603 u8 cls = 0;
3604 u8 tmp;
3605
3606 if (pci_cache_line_size)
3607 printk(KERN_DEBUG "PCI: CLS %u bytes\n",
3608 pci_cache_line_size << 2);
8d86fb2c 3609
95df8b87 3610 pci_apply_fixup_final_quirks = true;
4e344b1c 3611 for_each_pci_dev(dev) {
8d86fb2c 3612 pci_fixup_device(pci_fixup_final, dev);
ac1aa47b
JB
3613 /*
3614 * If arch hasn't set it explicitly yet, use the CLS
3615 * value shared by all PCI devices. If there's a
3616 * mismatch, fall back to the default value.
3617 */
3618 if (!pci_cache_line_size) {
3619 pci_read_config_byte(dev, PCI_CACHE_LINE_SIZE, &tmp);
3620 if (!cls)
3621 cls = tmp;
3622 if (!tmp || cls == tmp)
3623 continue;
3624
227f0647
RD
3625 printk(KERN_DEBUG "PCI: CLS mismatch (%u != %u), using %u bytes\n",
3626 cls << 2, tmp << 2,
ac1aa47b
JB
3627 pci_dfl_cache_line_size << 2);
3628 pci_cache_line_size = pci_dfl_cache_line_size;
3629 }
3630 }
735bff10 3631
ac1aa47b
JB
3632 if (!pci_cache_line_size) {
3633 printk(KERN_DEBUG "PCI: CLS %u bytes, default %u\n",
3634 cls << 2, pci_dfl_cache_line_size << 2);
2820f333 3635 pci_cache_line_size = cls ? cls : pci_dfl_cache_line_size;
8d86fb2c
DW
3636 }
3637
3638 return 0;
3639}
3640
cf6f3bf7 3641fs_initcall_sync(pci_apply_final_quirks);
b9c3b266
DC
3642
3643/*
3644 * Followings are device-specific reset methods which can be used to
3645 * reset a single function if other methods (e.g. FLR, PM D0->D3) are
3646 * not available.
3647 */
c763e7b5
DC
3648static int reset_intel_82599_sfp_virtfn(struct pci_dev *dev, int probe)
3649{
76b57c67
BH
3650 /*
3651 * http://www.intel.com/content/dam/doc/datasheet/82599-10-gbe-controller-datasheet.pdf
3652 *
3653 * The 82599 supports FLR on VFs, but FLR support is reported only
3654 * in the PF DEVCAP (sec 9.3.10.4), not in the VF DEVCAP (sec 9.5).
3655 * Therefore, we can't use pcie_flr(), which checks the VF DEVCAP.
3656 */
3657
c763e7b5
DC
3658 if (probe)
3659 return 0;
3660
4d708ab0
CL
3661 if (!pci_wait_for_pending_transaction(dev))
3662 dev_err(&dev->dev, "transaction is not cleared; proceeding with reset anyway\n");
76b57c67 3663
76b57c67
BH
3664 pcie_capability_set_word(dev, PCI_EXP_DEVCTL, PCI_EXP_DEVCTL_BCR_FLR);
3665
c763e7b5
DC
3666 msleep(100);
3667
3668 return 0;
3669}
3670
aba72ddc
VS
3671#define SOUTH_CHICKEN2 0xc2004
3672#define PCH_PP_STATUS 0xc7200
3673#define PCH_PP_CONTROL 0xc7204
df558de1
XH
3674#define MSG_CTL 0x45010
3675#define NSDE_PWR_STATE 0xd0100
3676#define IGD_OPERATION_TIMEOUT 10000 /* set timeout 10 seconds */
3677
3678static int reset_ivb_igd(struct pci_dev *dev, int probe)
3679{
3680 void __iomem *mmio_base;
3681 unsigned long timeout;
3682 u32 val;
3683
3684 if (probe)
3685 return 0;
3686
3687 mmio_base = pci_iomap(dev, 0, 0);
3688 if (!mmio_base)
3689 return -ENOMEM;
3690
3691 iowrite32(0x00000002, mmio_base + MSG_CTL);
3692
3693 /*
3694 * Clobbering SOUTH_CHICKEN2 register is fine only if the next
3695 * driver loaded sets the right bits. However, this's a reset and
3696 * the bits have been set by i915 previously, so we clobber
3697 * SOUTH_CHICKEN2 register directly here.
3698 */
3699 iowrite32(0x00000005, mmio_base + SOUTH_CHICKEN2);
3700
3701 val = ioread32(mmio_base + PCH_PP_CONTROL) & 0xfffffffe;
3702 iowrite32(val, mmio_base + PCH_PP_CONTROL);
3703
3704 timeout = jiffies + msecs_to_jiffies(IGD_OPERATION_TIMEOUT);
3705 do {
3706 val = ioread32(mmio_base + PCH_PP_STATUS);
3707 if ((val & 0xb0000000) == 0)
3708 goto reset_complete;
3709 msleep(10);
3710 } while (time_before(jiffies, timeout));
3711 dev_warn(&dev->dev, "timeout during reset\n");
3712
3713reset_complete:
3714 iowrite32(0x00000002, mmio_base + NSDE_PWR_STATE);
3715
3716 pci_iounmap(dev, mmio_base);
3717 return 0;
3718}
3719
2c6217e0
CL
3720/*
3721 * Device-specific reset method for Chelsio T4-based adapters.
3722 */
3723static int reset_chelsio_generic_dev(struct pci_dev *dev, int probe)
3724{
3725 u16 old_command;
3726 u16 msix_flags;
3727
3728 /*
3729 * If this isn't a Chelsio T4-based device, return -ENOTTY indicating
3730 * that we have no device-specific reset method.
3731 */
3732 if ((dev->device & 0xf000) != 0x4000)
3733 return -ENOTTY;
3734
3735 /*
3736 * If this is the "probe" phase, return 0 indicating that we can
3737 * reset this device.
3738 */
3739 if (probe)
3740 return 0;
3741
3742 /*
3743 * T4 can wedge if there are DMAs in flight within the chip and Bus
3744 * Master has been disabled. We need to have it on till the Function
3745 * Level Reset completes. (BUS_MASTER is disabled in
3746 * pci_reset_function()).
3747 */
3748 pci_read_config_word(dev, PCI_COMMAND, &old_command);
3749 pci_write_config_word(dev, PCI_COMMAND,
3750 old_command | PCI_COMMAND_MASTER);
3751
3752 /*
3753 * Perform the actual device function reset, saving and restoring
3754 * configuration information around the reset.
3755 */
3756 pci_save_state(dev);
3757
3758 /*
3759 * T4 also suffers a Head-Of-Line blocking problem if MSI-X interrupts
3760 * are disabled when an MSI-X interrupt message needs to be delivered.
3761 * So we briefly re-enable MSI-X interrupts for the duration of the
3762 * FLR. The pci_restore_state() below will restore the original
3763 * MSI-X state.
3764 */
3765 pci_read_config_word(dev, dev->msix_cap+PCI_MSIX_FLAGS, &msix_flags);
3766 if ((msix_flags & PCI_MSIX_FLAGS_ENABLE) == 0)
3767 pci_write_config_word(dev, dev->msix_cap+PCI_MSIX_FLAGS,
3768 msix_flags |
3769 PCI_MSIX_FLAGS_ENABLE |
3770 PCI_MSIX_FLAGS_MASKALL);
3771
3772 /*
3773 * Start of pcie_flr() code sequence. This reset code is a copy of
3774 * the guts of pcie_flr() because that's not an exported function.
3775 */
3776
3777 if (!pci_wait_for_pending_transaction(dev))
3778 dev_err(&dev->dev, "transaction is not cleared; proceeding with reset anyway\n");
3779
3780 pcie_capability_set_word(dev, PCI_EXP_DEVCTL, PCI_EXP_DEVCTL_BCR_FLR);
3781 msleep(100);
3782
3783 /*
3784 * End of pcie_flr() code sequence.
3785 */
3786
3787 /*
3788 * Restore the configuration information (BAR values, etc.) including
3789 * the original PCI Configuration Space Command word, and return
3790 * success.
3791 */
3792 pci_restore_state(dev);
3793 pci_write_config_word(dev, PCI_COMMAND, old_command);
3794 return 0;
3795}
3796
c763e7b5 3797#define PCI_DEVICE_ID_INTEL_82599_SFP_VF 0x10ed
df558de1
XH
3798#define PCI_DEVICE_ID_INTEL_IVB_M_VGA 0x0156
3799#define PCI_DEVICE_ID_INTEL_IVB_M2_VGA 0x0166
c763e7b5 3800
5b889bf2 3801static const struct pci_dev_reset_methods pci_dev_reset_methods[] = {
c763e7b5
DC
3802 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82599_SFP_VF,
3803 reset_intel_82599_sfp_virtfn },
df558de1
XH
3804 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_IVB_M_VGA,
3805 reset_ivb_igd },
3806 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_IVB_M2_VGA,
3807 reset_ivb_igd },
2c6217e0
CL
3808 { PCI_VENDOR_ID_CHELSIO, PCI_ANY_ID,
3809 reset_chelsio_generic_dev },
b9c3b266
DC
3810 { 0 }
3811};
5b889bf2 3812
df558de1
XH
3813/*
3814 * These device-specific reset methods are here rather than in a driver
3815 * because when a host assigns a device to a guest VM, the host may need
3816 * to reset the device but probably doesn't have a driver for it.
3817 */
5b889bf2
RW
3818int pci_dev_specific_reset(struct pci_dev *dev, int probe)
3819{
df9d1e8a 3820 const struct pci_dev_reset_methods *i;
5b889bf2
RW
3821
3822 for (i = pci_dev_reset_methods; i->reset; i++) {
3823 if ((i->vendor == dev->vendor ||
3824 i->vendor == (u16)PCI_ANY_ID) &&
3825 (i->device == dev->device ||
3826 i->device == (u16)PCI_ANY_ID))
3827 return i->reset(dev, probe);
3828 }
3829
3830 return -ENOTTY;
3831}
12ea6cad 3832
ec637fb2
AW
3833static void quirk_dma_func0_alias(struct pci_dev *dev)
3834{
f0af9593
BH
3835 if (PCI_FUNC(dev->devfn) != 0)
3836 pci_add_dma_alias(dev, PCI_DEVFN(PCI_SLOT(dev->devfn), 0));
ec637fb2
AW
3837}
3838
3839/*
3840 * https://bugzilla.redhat.com/show_bug.cgi?id=605888
3841 *
3842 * Some Ricoh devices use function 0 as the PCIe requester ID for DMA.
3843 */
3844DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_RICOH, 0xe832, quirk_dma_func0_alias);
3845DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_RICOH, 0xe476, quirk_dma_func0_alias);
3846
cc346a47
AW
3847static void quirk_dma_func1_alias(struct pci_dev *dev)
3848{
f0af9593
BH
3849 if (PCI_FUNC(dev->devfn) != 1)
3850 pci_add_dma_alias(dev, PCI_DEVFN(PCI_SLOT(dev->devfn), 1));
cc346a47
AW
3851}
3852
3853/*
3854 * Marvell 88SE9123 uses function 1 as the requester ID for DMA. In some
3855 * SKUs function 1 is present and is a legacy IDE controller, in other
3856 * SKUs this function is not present, making this a ghost requester.
3857 * https://bugzilla.kernel.org/show_bug.cgi?id=42679
3858 */
247de694
SA
3859DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_MARVELL_EXT, 0x9120,
3860 quirk_dma_func1_alias);
cc346a47
AW
3861DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_MARVELL_EXT, 0x9123,
3862 quirk_dma_func1_alias);
3863/* https://bugzilla.kernel.org/show_bug.cgi?id=42679#c14 */
3864DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_MARVELL_EXT, 0x9130,
3865 quirk_dma_func1_alias);
3866/* https://bugzilla.kernel.org/show_bug.cgi?id=42679#c47 + c57 */
3867DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_MARVELL_EXT, 0x9172,
3868 quirk_dma_func1_alias);
3869/* https://bugzilla.kernel.org/show_bug.cgi?id=42679#c59 */
3870DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_MARVELL_EXT, 0x917a,
3871 quirk_dma_func1_alias);
00456b35
AS
3872/* https://bugzilla.kernel.org/show_bug.cgi?id=42679#c78 */
3873DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_MARVELL_EXT, 0x9182,
3874 quirk_dma_func1_alias);
cc346a47
AW
3875/* https://bugzilla.kernel.org/show_bug.cgi?id=42679#c46 */
3876DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_MARVELL_EXT, 0x91a0,
3877 quirk_dma_func1_alias);
3878/* https://bugzilla.kernel.org/show_bug.cgi?id=42679#c49 */
3879DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_MARVELL_EXT, 0x9230,
3880 quirk_dma_func1_alias);
c2e0fb96
JC
3881DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_TTI, 0x0642,
3882 quirk_dma_func1_alias);
cc346a47
AW
3883/* https://bugs.gentoo.org/show_bug.cgi?id=497630 */
3884DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_JMICRON,
3885 PCI_DEVICE_ID_JMICRON_JMB388_ESD,
3886 quirk_dma_func1_alias);
8b9b963e
TS
3887/* https://bugzilla.kernel.org/show_bug.cgi?id=42679#c117 */
3888DECLARE_PCI_FIXUP_HEADER(0x1c28, /* Lite-On */
3889 0x0122, /* Plextor M6E (Marvell 88SS9183)*/
3890 quirk_dma_func1_alias);
cc346a47 3891
d3d2ab43
AW
3892/*
3893 * Some devices DMA with the wrong devfn, not just the wrong function.
3894 * quirk_fixed_dma_alias() uses this table to create fixed aliases, where
3895 * the alias is "fixed" and independent of the device devfn.
3896 *
3897 * For example, the Adaptec 3405 is a PCIe card with an Intel 80333 I/O
3898 * processor. To software, this appears as a PCIe-to-PCI/X bridge with a
3899 * single device on the secondary bus. In reality, the single exposed
3900 * device at 0e.0 is the Address Translation Unit (ATU) of the controller
3901 * that provides a bridge to the internal bus of the I/O processor. The
3902 * controller supports private devices, which can be hidden from PCI config
3903 * space. In the case of the Adaptec 3405, a private device at 01.0
3904 * appears to be the DMA engine, which therefore needs to become a DMA
3905 * alias for the device.
3906 */
3907static const struct pci_device_id fixed_dma_alias_tbl[] = {
3908 { PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2, 0x0285,
3909 PCI_VENDOR_ID_ADAPTEC2, 0x02bb), /* Adaptec 3405 */
3910 .driver_data = PCI_DEVFN(1, 0) },
db83f87b
AW
3911 { PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2, 0x0285,
3912 PCI_VENDOR_ID_ADAPTEC2, 0x02bc), /* Adaptec 3805 */
3913 .driver_data = PCI_DEVFN(1, 0) },
d3d2ab43
AW
3914 { 0 }
3915};
3916
3917static void quirk_fixed_dma_alias(struct pci_dev *dev)
3918{
3919 const struct pci_device_id *id;
3920
3921 id = pci_match_id(fixed_dma_alias_tbl, dev);
48c83080 3922 if (id)
f0af9593 3923 pci_add_dma_alias(dev, id->driver_data);
d3d2ab43
AW
3924}
3925
3926DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_ADAPTEC2, 0x0285, quirk_fixed_dma_alias);
3927
ebdb51eb
AW
3928/*
3929 * A few PCIe-to-PCI bridges fail to expose a PCIe capability, resulting in
3930 * using the wrong DMA alias for the device. Some of these devices can be
3931 * used as either forward or reverse bridges, so we need to test whether the
3932 * device is operating in the correct mode. We could probably apply this
3933 * quirk to PCI_ANY_ID, but for now we'll just use known offenders. The test
3934 * is for a non-root, non-PCIe bridge where the upstream device is PCIe and
3935 * is not a PCIe-to-PCI bridge, then @pdev is actually a PCIe-to-PCI bridge.
3936 */
3937static void quirk_use_pcie_bridge_dma_alias(struct pci_dev *pdev)
3938{
3939 if (!pci_is_root_bus(pdev->bus) &&
3940 pdev->hdr_type == PCI_HEADER_TYPE_BRIDGE &&
3941 !pci_is_pcie(pdev) && pci_is_pcie(pdev->bus->self) &&
3942 pci_pcie_type(pdev->bus->self) != PCI_EXP_TYPE_PCI_BRIDGE)
3943 pdev->dev_flags |= PCI_DEV_FLAG_PCIE_BRIDGE_ALIAS;
3944}
3945/* ASM1083/1085, https://bugzilla.kernel.org/show_bug.cgi?id=44881#c46 */
3946DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_ASMEDIA, 0x1080,
3947 quirk_use_pcie_bridge_dma_alias);
3948/* Tundra 8113, https://bugzilla.kernel.org/show_bug.cgi?id=44881#c43 */
3949DECLARE_PCI_FIXUP_HEADER(0x10e3, 0x8113, quirk_use_pcie_bridge_dma_alias);
98ca50db
AW
3950/* ITE 8892, https://bugzilla.kernel.org/show_bug.cgi?id=73551 */
3951DECLARE_PCI_FIXUP_HEADER(0x1283, 0x8892, quirk_use_pcie_bridge_dma_alias);
8ab4abbe
AW
3952/* Intel 82801, https://bugzilla.kernel.org/show_bug.cgi?id=44881#c49 */
3953DECLARE_PCI_FIXUP_HEADER(0x8086, 0x244e, quirk_use_pcie_bridge_dma_alias);
ebdb51eb 3954
b1a928cd
JL
3955/*
3956 * MIC x200 NTB forwards PCIe traffic using multiple alien RIDs. They have to
3957 * be added as aliases to the DMA device in order to allow buffer access
3958 * when IOMMU is enabled. Following devfns have to match RIT-LUT table
3959 * programmed in the EEPROM.
3960 */
3961static void quirk_mic_x200_dma_alias(struct pci_dev *pdev)
3962{
3963 pci_add_dma_alias(pdev, PCI_DEVFN(0x10, 0x0));
3964 pci_add_dma_alias(pdev, PCI_DEVFN(0x11, 0x0));
3965 pci_add_dma_alias(pdev, PCI_DEVFN(0x12, 0x3));
3966}
3967DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x2260, quirk_mic_x200_dma_alias);
3968DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x2264, quirk_mic_x200_dma_alias);
3969
3657cebd
KHC
3970/*
3971 * Intersil/Techwell TW686[4589]-based video capture cards have an empty (zero)
3972 * class code. Fix it.
3973 */
3974static void quirk_tw686x_class(struct pci_dev *pdev)
3975{
3976 u32 class = pdev->class;
3977
3978 /* Use "Multimedia controller" class */
3979 pdev->class = (PCI_CLASS_MULTIMEDIA_OTHER << 8) | 0x01;
3980 dev_info(&pdev->dev, "TW686x PCI class overridden (%#08x -> %#08x)\n",
3981 class, pdev->class);
3982}
2b4aed1d 3983DECLARE_PCI_FIXUP_CLASS_EARLY(0x1797, 0x6864, PCI_CLASS_NOT_DEFINED, 8,
3657cebd 3984 quirk_tw686x_class);
2b4aed1d 3985DECLARE_PCI_FIXUP_CLASS_EARLY(0x1797, 0x6865, PCI_CLASS_NOT_DEFINED, 8,
3657cebd 3986 quirk_tw686x_class);
2b4aed1d 3987DECLARE_PCI_FIXUP_CLASS_EARLY(0x1797, 0x6868, PCI_CLASS_NOT_DEFINED, 8,
3657cebd 3988 quirk_tw686x_class);
2b4aed1d 3989DECLARE_PCI_FIXUP_CLASS_EARLY(0x1797, 0x6869, PCI_CLASS_NOT_DEFINED, 8,
3657cebd
KHC
3990 quirk_tw686x_class);
3991
c56d4450
HS
3992/*
3993 * Per PCIe r3.0, sec 2.2.9, "Completion headers must supply the same
3994 * values for the Attribute as were supplied in the header of the
3995 * corresponding Request, except as explicitly allowed when IDO is used."
3996 *
3997 * If a non-compliant device generates a completion with a different
3998 * attribute than the request, the receiver may accept it (which itself
3999 * seems non-compliant based on sec 2.3.2), or it may handle it as a
4000 * Malformed TLP or an Unexpected Completion, which will probably lead to a
4001 * device access timeout.
4002 *
4003 * If the non-compliant device generates completions with zero attributes
4004 * (instead of copying the attributes from the request), we can work around
4005 * this by disabling the "Relaxed Ordering" and "No Snoop" attributes in
4006 * upstream devices so they always generate requests with zero attributes.
4007 *
4008 * This affects other devices under the same Root Port, but since these
4009 * attributes are performance hints, there should be no functional problem.
4010 *
4011 * Note that Configuration Space accesses are never supposed to have TLP
4012 * Attributes, so we're safe waiting till after any Configuration Space
4013 * accesses to do the Root Port fixup.
4014 */
4015static void quirk_disable_root_port_attributes(struct pci_dev *pdev)
4016{
4017 struct pci_dev *root_port = pci_find_pcie_root_port(pdev);
4018
4019 if (!root_port) {
4020 dev_warn(&pdev->dev, "PCIe Completion erratum may cause device errors\n");
4021 return;
4022 }
4023
4024 dev_info(&root_port->dev, "Disabling No Snoop/Relaxed Ordering Attributes to avoid PCIe Completion erratum in %s\n",
4025 dev_name(&pdev->dev));
4026 pcie_capability_clear_and_set_word(root_port, PCI_EXP_DEVCTL,
4027 PCI_EXP_DEVCTL_RELAX_EN |
4028 PCI_EXP_DEVCTL_NOSNOOP_EN, 0);
4029}
4030
4031/*
4032 * The Chelsio T5 chip fails to copy TLP Attributes from a Request to the
4033 * Completion it generates.
4034 */
4035static void quirk_chelsio_T5_disable_root_port_attributes(struct pci_dev *pdev)
4036{
4037 /*
4038 * This mask/compare operation selects for Physical Function 4 on a
4039 * T5. We only need to fix up the Root Port once for any of the
4040 * PFs. PF[0..3] have PCI Device IDs of 0x50xx, but PF4 is uniquely
4041 * 0x54xx so we use that one,
4042 */
4043 if ((pdev->device & 0xff00) == 0x5400)
4044 quirk_disable_root_port_attributes(pdev);
4045}
4046DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_CHELSIO, PCI_ANY_ID,
4047 quirk_chelsio_T5_disable_root_port_attributes);
4048
15b100df
AW
4049/*
4050 * AMD has indicated that the devices below do not support peer-to-peer
4051 * in any system where they are found in the southbridge with an AMD
4052 * IOMMU in the system. Multifunction devices that do not support
4053 * peer-to-peer between functions can claim to support a subset of ACS.
4054 * Such devices effectively enable request redirect (RR) and completion
4055 * redirect (CR) since all transactions are redirected to the upstream
4056 * root complex.
4057 *
4058 * http://permalink.gmane.org/gmane.comp.emulators.kvm.devel/94086
4059 * http://permalink.gmane.org/gmane.comp.emulators.kvm.devel/94102
4060 * http://permalink.gmane.org/gmane.comp.emulators.kvm.devel/99402
4061 *
4062 * 1002:4385 SBx00 SMBus Controller
4063 * 1002:439c SB7x0/SB8x0/SB9x0 IDE Controller
4064 * 1002:4383 SBx00 Azalia (Intel HDA)
4065 * 1002:439d SB7x0/SB8x0/SB9x0 LPC host controller
4066 * 1002:4384 SBx00 PCI to PCI Bridge
4067 * 1002:4399 SB7x0/SB8x0/SB9x0 USB OHCI2 Controller
3587e625
MR
4068 *
4069 * https://bugzilla.kernel.org/show_bug.cgi?id=81841#c15
4070 *
4071 * 1022:780f [AMD] FCH PCI Bridge
4072 * 1022:7809 [AMD] FCH USB OHCI Controller
15b100df
AW
4073 */
4074static int pci_quirk_amd_sb_acs(struct pci_dev *dev, u16 acs_flags)
4075{
4076#ifdef CONFIG_ACPI
4077 struct acpi_table_header *header = NULL;
4078 acpi_status status;
4079
4080 /* Targeting multifunction devices on the SB (appears on root bus) */
4081 if (!dev->multifunction || !pci_is_root_bus(dev->bus))
4082 return -ENODEV;
4083
4084 /* The IVRS table describes the AMD IOMMU */
4085 status = acpi_get_table("IVRS", 0, &header);
4086 if (ACPI_FAILURE(status))
4087 return -ENODEV;
4088
4089 /* Filter out flags not applicable to multifunction */
4090 acs_flags &= (PCI_ACS_RR | PCI_ACS_CR | PCI_ACS_EC | PCI_ACS_DT);
4091
4092 return acs_flags & ~(PCI_ACS_RR | PCI_ACS_CR) ? 0 : 1;
4093#else
4094 return -ENODEV;
4095#endif
4096}
4097
b404bcfb
MJ
4098static int pci_quirk_cavium_acs(struct pci_dev *dev, u16 acs_flags)
4099{
4100 /*
4101 * Cavium devices matching this quirk do not perform peer-to-peer
4102 * with other functions, allowing masking out these bits as if they
4103 * were unimplemented in the ACS capability.
4104 */
4105 acs_flags &= ~(PCI_ACS_SV | PCI_ACS_TB | PCI_ACS_RR |
4106 PCI_ACS_CR | PCI_ACS_UF | PCI_ACS_DT);
4107
4108 return acs_flags ? 0 : 1;
4109}
4110
d99321b6
AW
4111/*
4112 * Many Intel PCH root ports do provide ACS-like features to disable peer
4113 * transactions and validate bus numbers in requests, but do not provide an
4114 * actual PCIe ACS capability. This is the list of device IDs known to fall
4115 * into that category as provided by Intel in Red Hat bugzilla 1037684.
4116 */
4117static const u16 pci_quirk_intel_pch_acs_ids[] = {
4118 /* Ibexpeak PCH */
4119 0x3b42, 0x3b43, 0x3b44, 0x3b45, 0x3b46, 0x3b47, 0x3b48, 0x3b49,
4120 0x3b4a, 0x3b4b, 0x3b4c, 0x3b4d, 0x3b4e, 0x3b4f, 0x3b50, 0x3b51,
4121 /* Cougarpoint PCH */
4122 0x1c10, 0x1c11, 0x1c12, 0x1c13, 0x1c14, 0x1c15, 0x1c16, 0x1c17,
4123 0x1c18, 0x1c19, 0x1c1a, 0x1c1b, 0x1c1c, 0x1c1d, 0x1c1e, 0x1c1f,
4124 /* Pantherpoint PCH */
4125 0x1e10, 0x1e11, 0x1e12, 0x1e13, 0x1e14, 0x1e15, 0x1e16, 0x1e17,
4126 0x1e18, 0x1e19, 0x1e1a, 0x1e1b, 0x1e1c, 0x1e1d, 0x1e1e, 0x1e1f,
4127 /* Lynxpoint-H PCH */
4128 0x8c10, 0x8c11, 0x8c12, 0x8c13, 0x8c14, 0x8c15, 0x8c16, 0x8c17,
4129 0x8c18, 0x8c19, 0x8c1a, 0x8c1b, 0x8c1c, 0x8c1d, 0x8c1e, 0x8c1f,
4130 /* Lynxpoint-LP PCH */
4131 0x9c10, 0x9c11, 0x9c12, 0x9c13, 0x9c14, 0x9c15, 0x9c16, 0x9c17,
4132 0x9c18, 0x9c19, 0x9c1a, 0x9c1b,
4133 /* Wildcat PCH */
4134 0x9c90, 0x9c91, 0x9c92, 0x9c93, 0x9c94, 0x9c95, 0x9c96, 0x9c97,
4135 0x9c98, 0x9c99, 0x9c9a, 0x9c9b,
1a30fd0d
AW
4136 /* Patsburg (X79) PCH */
4137 0x1d10, 0x1d12, 0x1d14, 0x1d16, 0x1d18, 0x1d1a, 0x1d1c, 0x1d1e,
78e88358
AW
4138 /* Wellsburg (X99) PCH */
4139 0x8d10, 0x8d11, 0x8d12, 0x8d13, 0x8d14, 0x8d15, 0x8d16, 0x8d17,
4140 0x8d18, 0x8d19, 0x8d1a, 0x8d1b, 0x8d1c, 0x8d1d, 0x8d1e,
dca230d1
AW
4141 /* Lynx Point (9 series) PCH */
4142 0x8c90, 0x8c92, 0x8c94, 0x8c96, 0x8c98, 0x8c9a, 0x8c9c, 0x8c9e,
d99321b6
AW
4143};
4144
4145static bool pci_quirk_intel_pch_acs_match(struct pci_dev *dev)
4146{
4147 int i;
4148
4149 /* Filter out a few obvious non-matches first */
4150 if (!pci_is_pcie(dev) || pci_pcie_type(dev) != PCI_EXP_TYPE_ROOT_PORT)
4151 return false;
4152
4153 for (i = 0; i < ARRAY_SIZE(pci_quirk_intel_pch_acs_ids); i++)
4154 if (pci_quirk_intel_pch_acs_ids[i] == dev->device)
4155 return true;
4156
4157 return false;
4158}
4159
4160#define INTEL_PCH_ACS_FLAGS (PCI_ACS_RR | PCI_ACS_CR | PCI_ACS_UF | PCI_ACS_SV)
4161
4162static int pci_quirk_intel_pch_acs(struct pci_dev *dev, u16 acs_flags)
4163{
4164 u16 flags = dev->dev_flags & PCI_DEV_FLAGS_ACS_ENABLED_QUIRK ?
4165 INTEL_PCH_ACS_FLAGS : 0;
4166
4167 if (!pci_quirk_intel_pch_acs_match(dev))
4168 return -ENOTTY;
4169
4170 return acs_flags & ~flags ? 0 : 1;
4171}
4172
1bf2bf22
AW
4173/*
4174 * Sunrise Point PCH root ports implement ACS, but unfortunately as shown in
4175 * the datasheet (Intel 100 Series Chipset Family PCH Datasheet, Vol. 2,
4176 * 12.1.46, 12.1.47)[1] this chipset uses dwords for the ACS capability and
4177 * control registers whereas the PCIe spec packs them into words (Rev 3.0,
4178 * 7.16 ACS Extended Capability). The bit definitions are correct, but the
4179 * control register is at offset 8 instead of 6 and we should probably use
4180 * dword accesses to them. This applies to the following PCI Device IDs, as
4181 * found in volume 1 of the datasheet[2]:
4182 *
4183 * 0xa110-0xa11f Sunrise Point-H PCI Express Root Port #{0-16}
4184 * 0xa167-0xa16a Sunrise Point-H PCI Express Root Port #{17-20}
4185 *
4186 * N.B. This doesn't fix what lspci shows.
4187 *
4188 * [1] http://www.intel.com/content/www/us/en/chipsets/100-series-chipset-datasheet-vol-2.html
4189 * [2] http://www.intel.com/content/www/us/en/chipsets/100-series-chipset-datasheet-vol-1.html
4190 */
4191static bool pci_quirk_intel_spt_pch_acs_match(struct pci_dev *dev)
4192{
4193 return pci_is_pcie(dev) &&
4194 pci_pcie_type(dev) == PCI_EXP_TYPE_ROOT_PORT &&
4195 ((dev->device & ~0xf) == 0xa110 ||
4196 (dev->device >= 0xa167 && dev->device <= 0xa16a));
4197}
4198
4199#define INTEL_SPT_ACS_CTRL (PCI_ACS_CAP + 4)
4200
4201static int pci_quirk_intel_spt_pch_acs(struct pci_dev *dev, u16 acs_flags)
4202{
4203 int pos;
4204 u32 cap, ctrl;
4205
4206 if (!pci_quirk_intel_spt_pch_acs_match(dev))
4207 return -ENOTTY;
4208
4209 pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ACS);
4210 if (!pos)
4211 return -ENOTTY;
4212
4213 /* see pci_acs_flags_enabled() */
4214 pci_read_config_dword(dev, pos + PCI_ACS_CAP, &cap);
4215 acs_flags &= (cap | PCI_ACS_EC);
4216
4217 pci_read_config_dword(dev, pos + INTEL_SPT_ACS_CTRL, &ctrl);
4218
4219 return acs_flags & ~ctrl ? 0 : 1;
4220}
4221
100ebb2c 4222static int pci_quirk_mf_endpoint_acs(struct pci_dev *dev, u16 acs_flags)
89b51cb5
AW
4223{
4224 /*
4225 * SV, TB, and UF are not relevant to multifunction endpoints.
4226 *
100ebb2c
AW
4227 * Multifunction devices are only required to implement RR, CR, and DT
4228 * in their ACS capability if they support peer-to-peer transactions.
4229 * Devices matching this quirk have been verified by the vendor to not
4230 * perform peer-to-peer with other functions, allowing us to mask out
4231 * these bits as if they were unimplemented in the ACS capability.
89b51cb5
AW
4232 */
4233 acs_flags &= ~(PCI_ACS_SV | PCI_ACS_TB | PCI_ACS_RR |
4234 PCI_ACS_CR | PCI_ACS_UF | PCI_ACS_DT);
4235
4236 return acs_flags ? 0 : 1;
4237}
4238
ad805758
AW
4239static const struct pci_dev_acs_enabled {
4240 u16 vendor;
4241 u16 device;
4242 int (*acs_enabled)(struct pci_dev *dev, u16 acs_flags);
4243} pci_dev_acs_enabled[] = {
15b100df
AW
4244 { PCI_VENDOR_ID_ATI, 0x4385, pci_quirk_amd_sb_acs },
4245 { PCI_VENDOR_ID_ATI, 0x439c, pci_quirk_amd_sb_acs },
4246 { PCI_VENDOR_ID_ATI, 0x4383, pci_quirk_amd_sb_acs },
4247 { PCI_VENDOR_ID_ATI, 0x439d, pci_quirk_amd_sb_acs },
4248 { PCI_VENDOR_ID_ATI, 0x4384, pci_quirk_amd_sb_acs },
4249 { PCI_VENDOR_ID_ATI, 0x4399, pci_quirk_amd_sb_acs },
3587e625
MR
4250 { PCI_VENDOR_ID_AMD, 0x780f, pci_quirk_amd_sb_acs },
4251 { PCI_VENDOR_ID_AMD, 0x7809, pci_quirk_amd_sb_acs },
100ebb2c
AW
4252 { PCI_VENDOR_ID_SOLARFLARE, 0x0903, pci_quirk_mf_endpoint_acs },
4253 { PCI_VENDOR_ID_SOLARFLARE, 0x0923, pci_quirk_mf_endpoint_acs },
9fad4012 4254 { PCI_VENDOR_ID_SOLARFLARE, 0x0A03, pci_quirk_mf_endpoint_acs },
100ebb2c
AW
4255 { PCI_VENDOR_ID_INTEL, 0x10C6, pci_quirk_mf_endpoint_acs },
4256 { PCI_VENDOR_ID_INTEL, 0x10DB, pci_quirk_mf_endpoint_acs },
4257 { PCI_VENDOR_ID_INTEL, 0x10DD, pci_quirk_mf_endpoint_acs },
4258 { PCI_VENDOR_ID_INTEL, 0x10E1, pci_quirk_mf_endpoint_acs },
4259 { PCI_VENDOR_ID_INTEL, 0x10F1, pci_quirk_mf_endpoint_acs },
4260 { PCI_VENDOR_ID_INTEL, 0x10F7, pci_quirk_mf_endpoint_acs },
4261 { PCI_VENDOR_ID_INTEL, 0x10F8, pci_quirk_mf_endpoint_acs },
4262 { PCI_VENDOR_ID_INTEL, 0x10F9, pci_quirk_mf_endpoint_acs },
4263 { PCI_VENDOR_ID_INTEL, 0x10FA, pci_quirk_mf_endpoint_acs },
4264 { PCI_VENDOR_ID_INTEL, 0x10FB, pci_quirk_mf_endpoint_acs },
4265 { PCI_VENDOR_ID_INTEL, 0x10FC, pci_quirk_mf_endpoint_acs },
4266 { PCI_VENDOR_ID_INTEL, 0x1507, pci_quirk_mf_endpoint_acs },
4267 { PCI_VENDOR_ID_INTEL, 0x1514, pci_quirk_mf_endpoint_acs },
4268 { PCI_VENDOR_ID_INTEL, 0x151C, pci_quirk_mf_endpoint_acs },
4269 { PCI_VENDOR_ID_INTEL, 0x1529, pci_quirk_mf_endpoint_acs },
4270 { PCI_VENDOR_ID_INTEL, 0x152A, pci_quirk_mf_endpoint_acs },
4271 { PCI_VENDOR_ID_INTEL, 0x154D, pci_quirk_mf_endpoint_acs },
4272 { PCI_VENDOR_ID_INTEL, 0x154F, pci_quirk_mf_endpoint_acs },
4273 { PCI_VENDOR_ID_INTEL, 0x1551, pci_quirk_mf_endpoint_acs },
4274 { PCI_VENDOR_ID_INTEL, 0x1558, pci_quirk_mf_endpoint_acs },
d748804f
AW
4275 /* 82580 */
4276 { PCI_VENDOR_ID_INTEL, 0x1509, pci_quirk_mf_endpoint_acs },
4277 { PCI_VENDOR_ID_INTEL, 0x150E, pci_quirk_mf_endpoint_acs },
4278 { PCI_VENDOR_ID_INTEL, 0x150F, pci_quirk_mf_endpoint_acs },
4279 { PCI_VENDOR_ID_INTEL, 0x1510, pci_quirk_mf_endpoint_acs },
4280 { PCI_VENDOR_ID_INTEL, 0x1511, pci_quirk_mf_endpoint_acs },
4281 { PCI_VENDOR_ID_INTEL, 0x1516, pci_quirk_mf_endpoint_acs },
4282 { PCI_VENDOR_ID_INTEL, 0x1527, pci_quirk_mf_endpoint_acs },
4283 /* 82576 */
4284 { PCI_VENDOR_ID_INTEL, 0x10C9, pci_quirk_mf_endpoint_acs },
4285 { PCI_VENDOR_ID_INTEL, 0x10E6, pci_quirk_mf_endpoint_acs },
4286 { PCI_VENDOR_ID_INTEL, 0x10E7, pci_quirk_mf_endpoint_acs },
4287 { PCI_VENDOR_ID_INTEL, 0x10E8, pci_quirk_mf_endpoint_acs },
4288 { PCI_VENDOR_ID_INTEL, 0x150A, pci_quirk_mf_endpoint_acs },
4289 { PCI_VENDOR_ID_INTEL, 0x150D, pci_quirk_mf_endpoint_acs },
4290 { PCI_VENDOR_ID_INTEL, 0x1518, pci_quirk_mf_endpoint_acs },
4291 { PCI_VENDOR_ID_INTEL, 0x1526, pci_quirk_mf_endpoint_acs },
4292 /* 82575 */
4293 { PCI_VENDOR_ID_INTEL, 0x10A7, pci_quirk_mf_endpoint_acs },
4294 { PCI_VENDOR_ID_INTEL, 0x10A9, pci_quirk_mf_endpoint_acs },
4295 { PCI_VENDOR_ID_INTEL, 0x10D6, pci_quirk_mf_endpoint_acs },
4296 /* I350 */
4297 { PCI_VENDOR_ID_INTEL, 0x1521, pci_quirk_mf_endpoint_acs },
4298 { PCI_VENDOR_ID_INTEL, 0x1522, pci_quirk_mf_endpoint_acs },
4299 { PCI_VENDOR_ID_INTEL, 0x1523, pci_quirk_mf_endpoint_acs },
4300 { PCI_VENDOR_ID_INTEL, 0x1524, pci_quirk_mf_endpoint_acs },
4301 /* 82571 (Quads omitted due to non-ACS switch) */
4302 { PCI_VENDOR_ID_INTEL, 0x105E, pci_quirk_mf_endpoint_acs },
4303 { PCI_VENDOR_ID_INTEL, 0x105F, pci_quirk_mf_endpoint_acs },
4304 { PCI_VENDOR_ID_INTEL, 0x1060, pci_quirk_mf_endpoint_acs },
4305 { PCI_VENDOR_ID_INTEL, 0x10D9, pci_quirk_mf_endpoint_acs },
95e16587
AW
4306 /* I219 */
4307 { PCI_VENDOR_ID_INTEL, 0x15b7, pci_quirk_mf_endpoint_acs },
4308 { PCI_VENDOR_ID_INTEL, 0x15b8, pci_quirk_mf_endpoint_acs },
d748804f 4309 /* Intel PCH root ports */
d99321b6 4310 { PCI_VENDOR_ID_INTEL, PCI_ANY_ID, pci_quirk_intel_pch_acs },
1bf2bf22 4311 { PCI_VENDOR_ID_INTEL, PCI_ANY_ID, pci_quirk_intel_spt_pch_acs },
6a3763d1
VV
4312 { 0x19a2, 0x710, pci_quirk_mf_endpoint_acs }, /* Emulex BE3-R */
4313 { 0x10df, 0x720, pci_quirk_mf_endpoint_acs }, /* Emulex Skyhawk-R */
b404bcfb
MJ
4314 /* Cavium ThunderX */
4315 { PCI_VENDOR_ID_CAVIUM, PCI_ANY_ID, pci_quirk_cavium_acs },
ad805758
AW
4316 { 0 }
4317};
4318
4319int pci_dev_specific_acs_enabled(struct pci_dev *dev, u16 acs_flags)
4320{
4321 const struct pci_dev_acs_enabled *i;
4322 int ret;
4323
4324 /*
4325 * Allow devices that do not expose standard PCIe ACS capabilities
4326 * or control to indicate their support here. Multi-function express
4327 * devices which do not allow internal peer-to-peer between functions,
4328 * but do not implement PCIe ACS may wish to return true here.
4329 */
4330 for (i = pci_dev_acs_enabled; i->acs_enabled; i++) {
4331 if ((i->vendor == dev->vendor ||
4332 i->vendor == (u16)PCI_ANY_ID) &&
4333 (i->device == dev->device ||
4334 i->device == (u16)PCI_ANY_ID)) {
4335 ret = i->acs_enabled(dev, acs_flags);
4336 if (ret >= 0)
4337 return ret;
4338 }
4339 }
4340
4341 return -ENOTTY;
4342}
2c744244 4343
d99321b6
AW
4344/* Config space offset of Root Complex Base Address register */
4345#define INTEL_LPC_RCBA_REG 0xf0
4346/* 31:14 RCBA address */
4347#define INTEL_LPC_RCBA_MASK 0xffffc000
4348/* RCBA Enable */
4349#define INTEL_LPC_RCBA_ENABLE (1 << 0)
4350
4351/* Backbone Scratch Pad Register */
4352#define INTEL_BSPR_REG 0x1104
4353/* Backbone Peer Non-Posted Disable */
4354#define INTEL_BSPR_REG_BPNPD (1 << 8)
4355/* Backbone Peer Posted Disable */
4356#define INTEL_BSPR_REG_BPPD (1 << 9)
4357
4358/* Upstream Peer Decode Configuration Register */
4359#define INTEL_UPDCR_REG 0x1114
4360/* 5:0 Peer Decode Enable bits */
4361#define INTEL_UPDCR_REG_MASK 0x3f
4362
4363static int pci_quirk_enable_intel_lpc_acs(struct pci_dev *dev)
4364{
4365 u32 rcba, bspr, updcr;
4366 void __iomem *rcba_mem;
4367
4368 /*
4369 * Read the RCBA register from the LPC (D31:F0). PCH root ports
4370 * are D28:F* and therefore get probed before LPC, thus we can't
4371 * use pci_get_slot/pci_read_config_dword here.
4372 */
4373 pci_bus_read_config_dword(dev->bus, PCI_DEVFN(31, 0),
4374 INTEL_LPC_RCBA_REG, &rcba);
4375 if (!(rcba & INTEL_LPC_RCBA_ENABLE))
4376 return -EINVAL;
4377
4378 rcba_mem = ioremap_nocache(rcba & INTEL_LPC_RCBA_MASK,
4379 PAGE_ALIGN(INTEL_UPDCR_REG));
4380 if (!rcba_mem)
4381 return -ENOMEM;
4382
4383 /*
4384 * The BSPR can disallow peer cycles, but it's set by soft strap and
4385 * therefore read-only. If both posted and non-posted peer cycles are
4386 * disallowed, we're ok. If either are allowed, then we need to use
4387 * the UPDCR to disable peer decodes for each port. This provides the
4388 * PCIe ACS equivalent of PCI_ACS_RR | PCI_ACS_CR | PCI_ACS_UF
4389 */
4390 bspr = readl(rcba_mem + INTEL_BSPR_REG);
4391 bspr &= INTEL_BSPR_REG_BPNPD | INTEL_BSPR_REG_BPPD;
4392 if (bspr != (INTEL_BSPR_REG_BPNPD | INTEL_BSPR_REG_BPPD)) {
4393 updcr = readl(rcba_mem + INTEL_UPDCR_REG);
4394 if (updcr & INTEL_UPDCR_REG_MASK) {
4395 dev_info(&dev->dev, "Disabling UPDCR peer decodes\n");
4396 updcr &= ~INTEL_UPDCR_REG_MASK;
4397 writel(updcr, rcba_mem + INTEL_UPDCR_REG);
4398 }
4399 }
4400
4401 iounmap(rcba_mem);
4402 return 0;
4403}
4404
4405/* Miscellaneous Port Configuration register */
4406#define INTEL_MPC_REG 0xd8
4407/* MPC: Invalid Receive Bus Number Check Enable */
4408#define INTEL_MPC_REG_IRBNCE (1 << 26)
4409
4410static void pci_quirk_enable_intel_rp_mpc_acs(struct pci_dev *dev)
4411{
4412 u32 mpc;
4413
4414 /*
4415 * When enabled, the IRBNCE bit of the MPC register enables the
4416 * equivalent of PCI ACS Source Validation (PCI_ACS_SV), which
4417 * ensures that requester IDs fall within the bus number range
4418 * of the bridge. Enable if not already.
4419 */
4420 pci_read_config_dword(dev, INTEL_MPC_REG, &mpc);
4421 if (!(mpc & INTEL_MPC_REG_IRBNCE)) {
4422 dev_info(&dev->dev, "Enabling MPC IRBNCE\n");
4423 mpc |= INTEL_MPC_REG_IRBNCE;
4424 pci_write_config_word(dev, INTEL_MPC_REG, mpc);
4425 }
4426}
4427
4428static int pci_quirk_enable_intel_pch_acs(struct pci_dev *dev)
4429{
4430 if (!pci_quirk_intel_pch_acs_match(dev))
4431 return -ENOTTY;
4432
4433 if (pci_quirk_enable_intel_lpc_acs(dev)) {
4434 dev_warn(&dev->dev, "Failed to enable Intel PCH ACS quirk\n");
4435 return 0;
4436 }
4437
4438 pci_quirk_enable_intel_rp_mpc_acs(dev);
4439
4440 dev->dev_flags |= PCI_DEV_FLAGS_ACS_ENABLED_QUIRK;
4441
4442 dev_info(&dev->dev, "Intel PCH root port ACS workaround enabled\n");
4443
4444 return 0;
4445}
4446
1bf2bf22
AW
4447static int pci_quirk_enable_intel_spt_pch_acs(struct pci_dev *dev)
4448{
4449 int pos;
4450 u32 cap, ctrl;
4451
4452 if (!pci_quirk_intel_spt_pch_acs_match(dev))
4453 return -ENOTTY;
4454
4455 pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ACS);
4456 if (!pos)
4457 return -ENOTTY;
4458
4459 pci_read_config_dword(dev, pos + PCI_ACS_CAP, &cap);
4460 pci_read_config_dword(dev, pos + INTEL_SPT_ACS_CTRL, &ctrl);
4461
4462 ctrl |= (cap & PCI_ACS_SV);
4463 ctrl |= (cap & PCI_ACS_RR);
4464 ctrl |= (cap & PCI_ACS_CR);
4465 ctrl |= (cap & PCI_ACS_UF);
4466
4467 pci_write_config_dword(dev, pos + INTEL_SPT_ACS_CTRL, ctrl);
4468
4469 dev_info(&dev->dev, "Intel SPT PCH root port ACS workaround enabled\n");
4470
4471 return 0;
4472}
4473
2c744244
AW
4474static const struct pci_dev_enable_acs {
4475 u16 vendor;
4476 u16 device;
4477 int (*enable_acs)(struct pci_dev *dev);
4478} pci_dev_enable_acs[] = {
d99321b6 4479 { PCI_VENDOR_ID_INTEL, PCI_ANY_ID, pci_quirk_enable_intel_pch_acs },
1bf2bf22 4480 { PCI_VENDOR_ID_INTEL, PCI_ANY_ID, pci_quirk_enable_intel_spt_pch_acs },
2c744244
AW
4481 { 0 }
4482};
4483
c1d61c9b 4484int pci_dev_specific_enable_acs(struct pci_dev *dev)
2c744244
AW
4485{
4486 const struct pci_dev_enable_acs *i;
4487 int ret;
4488
4489 for (i = pci_dev_enable_acs; i->enable_acs; i++) {
4490 if ((i->vendor == dev->vendor ||
4491 i->vendor == (u16)PCI_ANY_ID) &&
4492 (i->device == dev->device ||
4493 i->device == (u16)PCI_ANY_ID)) {
4494 ret = i->enable_acs(dev);
4495 if (ret >= 0)
c1d61c9b 4496 return ret;
2c744244
AW
4497 }
4498 }
c1d61c9b
AW
4499
4500 return -ENOTTY;
2c744244 4501}
3388a614
TS
4502
4503/*
4504 * The PCI capabilities list for Intel DH895xCC VFs (device id 0x0443) with
4505 * QuickAssist Technology (QAT) is prematurely terminated in hardware. The
4506 * Next Capability pointer in the MSI Capability Structure should point to
4507 * the PCIe Capability Structure but is incorrectly hardwired as 0 terminating
4508 * the list.
4509 */
4510static void quirk_intel_qat_vf_cap(struct pci_dev *pdev)
4511{
4512 int pos, i = 0;
4513 u8 next_cap;
4514 u16 reg16, *cap;
4515 struct pci_cap_saved_state *state;
4516
4517 /* Bail if the hardware bug is fixed */
4518 if (pdev->pcie_cap || pci_find_capability(pdev, PCI_CAP_ID_EXP))
4519 return;
4520
4521 /* Bail if MSI Capability Structure is not found for some reason */
4522 pos = pci_find_capability(pdev, PCI_CAP_ID_MSI);
4523 if (!pos)
4524 return;
4525
4526 /*
4527 * Bail if Next Capability pointer in the MSI Capability Structure
4528 * is not the expected incorrect 0x00.
4529 */
4530 pci_read_config_byte(pdev, pos + 1, &next_cap);
4531 if (next_cap)
4532 return;
4533
4534 /*
4535 * PCIe Capability Structure is expected to be at 0x50 and should
4536 * terminate the list (Next Capability pointer is 0x00). Verify
4537 * Capability Id and Next Capability pointer is as expected.
4538 * Open-code some of set_pcie_port_type() and pci_cfg_space_size_ext()
4539 * to correctly set kernel data structures which have already been
4540 * set incorrectly due to the hardware bug.
4541 */
4542 pos = 0x50;
4543 pci_read_config_word(pdev, pos, &reg16);
4544 if (reg16 == (0x0000 | PCI_CAP_ID_EXP)) {
4545 u32 status;
4546#ifndef PCI_EXP_SAVE_REGS
4547#define PCI_EXP_SAVE_REGS 7
4548#endif
4549 int size = PCI_EXP_SAVE_REGS * sizeof(u16);
4550
4551 pdev->pcie_cap = pos;
4552 pci_read_config_word(pdev, pos + PCI_EXP_FLAGS, &reg16);
4553 pdev->pcie_flags_reg = reg16;
4554 pci_read_config_word(pdev, pos + PCI_EXP_DEVCAP, &reg16);
4555 pdev->pcie_mpss = reg16 & PCI_EXP_DEVCAP_PAYLOAD;
4556
4557 pdev->cfg_size = PCI_CFG_SPACE_EXP_SIZE;
4558 if (pci_read_config_dword(pdev, PCI_CFG_SPACE_SIZE, &status) !=
4559 PCIBIOS_SUCCESSFUL || (status == 0xffffffff))
4560 pdev->cfg_size = PCI_CFG_SPACE_SIZE;
4561
4562 if (pci_find_saved_cap(pdev, PCI_CAP_ID_EXP))
4563 return;
4564
4565 /*
4566 * Save PCIE cap
4567 */
4568 state = kzalloc(sizeof(*state) + size, GFP_KERNEL);
4569 if (!state)
4570 return;
4571
4572 state->cap.cap_nr = PCI_CAP_ID_EXP;
4573 state->cap.cap_extended = 0;
4574 state->cap.size = size;
4575 cap = (u16 *)&state->cap.data[0];
4576 pcie_capability_read_word(pdev, PCI_EXP_DEVCTL, &cap[i++]);
4577 pcie_capability_read_word(pdev, PCI_EXP_LNKCTL, &cap[i++]);
4578 pcie_capability_read_word(pdev, PCI_EXP_SLTCTL, &cap[i++]);
4579 pcie_capability_read_word(pdev, PCI_EXP_RTCTL, &cap[i++]);
4580 pcie_capability_read_word(pdev, PCI_EXP_DEVCTL2, &cap[i++]);
4581 pcie_capability_read_word(pdev, PCI_EXP_LNKCTL2, &cap[i++]);
4582 pcie_capability_read_word(pdev, PCI_EXP_SLTCTL2, &cap[i++]);
4583 hlist_add_head(&state->next, &pdev->saved_cap_space);
4584 }
4585}
4586DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL, 0x443, quirk_intel_qat_vf_cap);
443b40ba
JD
4587
4588/*
4589 * VMD-enabled root ports will change the source ID for all messages
4590 * to the VMD device. Rather than doing device matching with the source
4591 * ID, the AER driver should traverse the child device tree, reading
4592 * AER registers to find the faulting device.
4593 */
4594static void quirk_no_aersid(struct pci_dev *pdev)
4595{
4596 /* VMD Domain */
4597 if (pdev->bus->sysdata && pci_domain_nr(pdev->bus) >= 0x10000)
4598 pdev->bus->bus_flags |= PCI_BUS_FLAGS_NO_AERSID;
4599}
4600DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL, 0x2030, quirk_no_aersid);
4601DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL, 0x2031, quirk_no_aersid);
4602DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL, 0x2032, quirk_no_aersid);
4603DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL, 0x2033, quirk_no_aersid);