1b2441318SGreg Kroah-Hartman // SPDX-License-Identifier: GPL-2.0
2fb9aa6f1SThomas Gleixner /*
3fb9aa6f1SThomas Gleixner * Exceptions for specific devices. Usually work-arounds for fatal design flaws.
4fb9aa6f1SThomas Gleixner */
5fb9aa6f1SThomas Gleixner
63f6154cbSMario Limonciello #include <linux/bitfield.h>
7fb9aa6f1SThomas Gleixner #include <linux/delay.h>
8fb9aa6f1SThomas Gleixner #include <linux/dmi.h>
9fb9aa6f1SThomas Gleixner #include <linux/pci.h>
103f6154cbSMario Limonciello #include <linux/suspend.h>
11db2e034dSDave Airlie #include <linux/vgaarb.h>
12f195fc1eSBasavaraj Natikar #include <asm/amd_nb.h>
1344c8bdbeSBjorn Helgaas #include <asm/hpet.h>
1482487711SJaswinder Singh Rajput #include <asm/pci_x86.h>
15fb9aa6f1SThomas Gleixner
pci_fixup_i450nx(struct pci_dev * d)16a18e3690SGreg Kroah-Hartman static void pci_fixup_i450nx(struct pci_dev *d)
17fb9aa6f1SThomas Gleixner {
18fb9aa6f1SThomas Gleixner /*
19fb9aa6f1SThomas Gleixner * i450NX -- Find and scan all secondary buses on all PXB's.
20fb9aa6f1SThomas Gleixner */
21fb9aa6f1SThomas Gleixner int pxb, reg;
22fb9aa6f1SThomas Gleixner u8 busno, suba, subb;
23fb9aa6f1SThomas Gleixner
249ed88554Sbjorn.helgaas@hp.com dev_warn(&d->dev, "Searching for i450NX host bridges\n");
25fb9aa6f1SThomas Gleixner reg = 0xd0;
26fb9aa6f1SThomas Gleixner for(pxb = 0; pxb < 2; pxb++) {
27fb9aa6f1SThomas Gleixner pci_read_config_byte(d, reg++, &busno);
28fb9aa6f1SThomas Gleixner pci_read_config_byte(d, reg++, &suba);
29fb9aa6f1SThomas Gleixner pci_read_config_byte(d, reg++, &subb);
3012c0b20fSBjorn Helgaas dev_dbg(&d->dev, "i450NX PXB %d: %02x/%02x/%02x\n", pxb, busno,
3112c0b20fSBjorn Helgaas suba, subb);
32fb9aa6f1SThomas Gleixner if (busno)
338d7d8186SBjorn Helgaas pcibios_scan_root(busno); /* Bus A */
34fb9aa6f1SThomas Gleixner if (suba < subb)
358d7d8186SBjorn Helgaas pcibios_scan_root(suba+1); /* Bus B */
36fb9aa6f1SThomas Gleixner }
37fb9aa6f1SThomas Gleixner pcibios_last_bus = -1;
38fb9aa6f1SThomas Gleixner }
39fb9aa6f1SThomas Gleixner DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82451NX, pci_fixup_i450nx);
40fb9aa6f1SThomas Gleixner
pci_fixup_i450gx(struct pci_dev * d)41a18e3690SGreg Kroah-Hartman static void pci_fixup_i450gx(struct pci_dev *d)
42fb9aa6f1SThomas Gleixner {
43fb9aa6f1SThomas Gleixner /*
44fb9aa6f1SThomas Gleixner * i450GX and i450KX -- Find and scan all secondary buses.
45fb9aa6f1SThomas Gleixner * (called separately for each PCI bridge found)
46fb9aa6f1SThomas Gleixner */
47fb9aa6f1SThomas Gleixner u8 busno;
48fb9aa6f1SThomas Gleixner pci_read_config_byte(d, 0x4a, &busno);
499ed88554Sbjorn.helgaas@hp.com dev_info(&d->dev, "i440KX/GX host bridge; secondary bus %02x\n", busno);
508d7d8186SBjorn Helgaas pcibios_scan_root(busno);
51fb9aa6f1SThomas Gleixner pcibios_last_bus = -1;
52fb9aa6f1SThomas Gleixner }
53fb9aa6f1SThomas Gleixner DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82454GX, pci_fixup_i450gx);
54fb9aa6f1SThomas Gleixner
pci_fixup_umc_ide(struct pci_dev * d)55a18e3690SGreg Kroah-Hartman static void pci_fixup_umc_ide(struct pci_dev *d)
56fb9aa6f1SThomas Gleixner {
57fb9aa6f1SThomas Gleixner /*
58fb9aa6f1SThomas Gleixner * UM8886BF IDE controller sets region type bits incorrectly,
59fb9aa6f1SThomas Gleixner * therefore they look like memory despite of them being I/O.
60fb9aa6f1SThomas Gleixner */
61fb9aa6f1SThomas Gleixner int i;
62fb9aa6f1SThomas Gleixner
639ed88554Sbjorn.helgaas@hp.com dev_warn(&d->dev, "Fixing base address flags\n");
64fb9aa6f1SThomas Gleixner for(i = 0; i < 4; i++)
65fb9aa6f1SThomas Gleixner d->resource[i].flags |= PCI_BASE_ADDRESS_SPACE_IO;
66fb9aa6f1SThomas Gleixner }
67fb9aa6f1SThomas Gleixner DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_UMC, PCI_DEVICE_ID_UMC_UM8886BF, pci_fixup_umc_ide);
68fb9aa6f1SThomas Gleixner
pci_fixup_latency(struct pci_dev * d)69a18e3690SGreg Kroah-Hartman static void pci_fixup_latency(struct pci_dev *d)
70fb9aa6f1SThomas Gleixner {
71fb9aa6f1SThomas Gleixner /*
72fb9aa6f1SThomas Gleixner * SiS 5597 and 5598 chipsets require latency timer set to
73fb9aa6f1SThomas Gleixner * at most 32 to avoid lockups.
74fb9aa6f1SThomas Gleixner */
759ed88554Sbjorn.helgaas@hp.com dev_dbg(&d->dev, "Setting max latency to 32\n");
76fb9aa6f1SThomas Gleixner pcibios_max_latency = 32;
77fb9aa6f1SThomas Gleixner }
78fb9aa6f1SThomas Gleixner DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_5597, pci_fixup_latency);
79fb9aa6f1SThomas Gleixner DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_5598, pci_fixup_latency);
80fb9aa6f1SThomas Gleixner
pci_fixup_piix4_acpi(struct pci_dev * d)81a18e3690SGreg Kroah-Hartman static void pci_fixup_piix4_acpi(struct pci_dev *d)
82fb9aa6f1SThomas Gleixner {
83fb9aa6f1SThomas Gleixner /*
84fb9aa6f1SThomas Gleixner * PIIX4 ACPI device: hardwired IRQ9
85fb9aa6f1SThomas Gleixner */
86fb9aa6f1SThomas Gleixner d->irq = 9;
87fb9aa6f1SThomas Gleixner }
88fb9aa6f1SThomas Gleixner DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82371AB_3, pci_fixup_piix4_acpi);
89fb9aa6f1SThomas Gleixner
90fb9aa6f1SThomas Gleixner /*
91fb9aa6f1SThomas Gleixner * Addresses issues with problems in the memory write queue timer in
92fb9aa6f1SThomas Gleixner * certain VIA Northbridges. This bugfix is per VIA's specifications,
93fb9aa6f1SThomas Gleixner * except for the KL133/KM133: clearing bit 5 on those Northbridges seems
94fb9aa6f1SThomas Gleixner * to trigger a bug in its integrated ProSavage video card, which
95fb9aa6f1SThomas Gleixner * causes screen corruption. We only clear bits 6 and 7 for that chipset,
96fb9aa6f1SThomas Gleixner * until VIA can provide us with definitive information on why screen
97fb9aa6f1SThomas Gleixner * corruption occurs, and what exactly those bits do.
98fb9aa6f1SThomas Gleixner *
99fb9aa6f1SThomas Gleixner * VIA 8363,8622,8361 Northbridges:
100fb9aa6f1SThomas Gleixner * - bits 5, 6, 7 at offset 0x55 need to be turned off
101fb9aa6f1SThomas Gleixner * VIA 8367 (KT266x) Northbridges:
102fb9aa6f1SThomas Gleixner * - bits 5, 6, 7 at offset 0x95 need to be turned off
103fb9aa6f1SThomas Gleixner * VIA 8363 rev 0x81/0x84 (KL133/KM133) Northbridges:
104fb9aa6f1SThomas Gleixner * - bits 6, 7 at offset 0x55 need to be turned off
105fb9aa6f1SThomas Gleixner */
106fb9aa6f1SThomas Gleixner
107fb9aa6f1SThomas Gleixner #define VIA_8363_KL133_REVISION_ID 0x81
108fb9aa6f1SThomas Gleixner #define VIA_8363_KM133_REVISION_ID 0x84
109fb9aa6f1SThomas Gleixner
pci_fixup_via_northbridge_bug(struct pci_dev * d)110fb9aa6f1SThomas Gleixner static void pci_fixup_via_northbridge_bug(struct pci_dev *d)
111fb9aa6f1SThomas Gleixner {
112fb9aa6f1SThomas Gleixner u8 v;
113fb9aa6f1SThomas Gleixner int where = 0x55;
114fb9aa6f1SThomas Gleixner int mask = 0x1f; /* clear bits 5, 6, 7 by default */
115fb9aa6f1SThomas Gleixner
116fb9aa6f1SThomas Gleixner if (d->device == PCI_DEVICE_ID_VIA_8367_0) {
117fb9aa6f1SThomas Gleixner /* fix pci bus latency issues resulted by NB bios error
118fb9aa6f1SThomas Gleixner it appears on bug free^Wreduced kt266x's bios forces
119fb9aa6f1SThomas Gleixner NB latency to zero */
120fb9aa6f1SThomas Gleixner pci_write_config_byte(d, PCI_LATENCY_TIMER, 0);
121fb9aa6f1SThomas Gleixner
122fb9aa6f1SThomas Gleixner where = 0x95; /* the memory write queue timer register is
123fb9aa6f1SThomas Gleixner different for the KT266x's: 0x95 not 0x55 */
124fb9aa6f1SThomas Gleixner } else if (d->device == PCI_DEVICE_ID_VIA_8363_0 &&
125fb9aa6f1SThomas Gleixner (d->revision == VIA_8363_KL133_REVISION_ID ||
126fb9aa6f1SThomas Gleixner d->revision == VIA_8363_KM133_REVISION_ID)) {
127fb9aa6f1SThomas Gleixner mask = 0x3f; /* clear only bits 6 and 7; clearing bit 5
128fb9aa6f1SThomas Gleixner causes screen corruption on the KL133/KM133 */
129fb9aa6f1SThomas Gleixner }
130fb9aa6f1SThomas Gleixner
131fb9aa6f1SThomas Gleixner pci_read_config_byte(d, where, &v);
132fb9aa6f1SThomas Gleixner if (v & ~mask) {
1339ed88554Sbjorn.helgaas@hp.com dev_warn(&d->dev, "Disabling VIA memory write queue (PCI ID %04x, rev %02x): [%02x] %02x & %02x -> %02x\n", \
134fb9aa6f1SThomas Gleixner d->device, d->revision, where, v, mask, v & mask);
135fb9aa6f1SThomas Gleixner v &= mask;
136fb9aa6f1SThomas Gleixner pci_write_config_byte(d, where, v);
137fb9aa6f1SThomas Gleixner }
138fb9aa6f1SThomas Gleixner }
139fb9aa6f1SThomas Gleixner DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8363_0, pci_fixup_via_northbridge_bug);
140fb9aa6f1SThomas Gleixner DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8622, pci_fixup_via_northbridge_bug);
141fb9aa6f1SThomas Gleixner DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8361, pci_fixup_via_northbridge_bug);
142fb9aa6f1SThomas Gleixner DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8367_0, pci_fixup_via_northbridge_bug);
143fb9aa6f1SThomas Gleixner DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8363_0, pci_fixup_via_northbridge_bug);
144fb9aa6f1SThomas Gleixner DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8622, pci_fixup_via_northbridge_bug);
145fb9aa6f1SThomas Gleixner DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8361, pci_fixup_via_northbridge_bug);
146fb9aa6f1SThomas Gleixner DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8367_0, pci_fixup_via_northbridge_bug);
147fb9aa6f1SThomas Gleixner
148fb9aa6f1SThomas Gleixner /*
149fb9aa6f1SThomas Gleixner * For some reasons Intel decided that certain parts of their
150fb9aa6f1SThomas Gleixner * 815, 845 and some other chipsets must look like PCI-to-PCI bridges
151fb9aa6f1SThomas Gleixner * while they are obviously not. The 82801 family (AA, AB, BAM/CAM,
152fb9aa6f1SThomas Gleixner * BA/CA/DB and E) PCI bridges are actually HUB-to-PCI ones, according
153fb9aa6f1SThomas Gleixner * to Intel terminology. These devices do forward all addresses from
154fb9aa6f1SThomas Gleixner * system to PCI bus no matter what are their window settings, so they are
155fb9aa6f1SThomas Gleixner * "transparent" (or subtractive decoding) from programmers point of view.
156fb9aa6f1SThomas Gleixner */
pci_fixup_transparent_bridge(struct pci_dev * dev)157a18e3690SGreg Kroah-Hartman static void pci_fixup_transparent_bridge(struct pci_dev *dev)
158fb9aa6f1SThomas Gleixner {
1594082cf2dSYinghai Lu if ((dev->device & 0xff00) == 0x2400)
160fb9aa6f1SThomas Gleixner dev->transparent = 1;
161fb9aa6f1SThomas Gleixner }
1624082cf2dSYinghai Lu DECLARE_PCI_FIXUP_CLASS_HEADER(PCI_VENDOR_ID_INTEL, PCI_ANY_ID,
1634082cf2dSYinghai Lu PCI_CLASS_BRIDGE_PCI, 8, pci_fixup_transparent_bridge);
164fb9aa6f1SThomas Gleixner
165fb9aa6f1SThomas Gleixner /*
166fb9aa6f1SThomas Gleixner * Fixup for C1 Halt Disconnect problem on nForce2 systems.
167fb9aa6f1SThomas Gleixner *
168fb9aa6f1SThomas Gleixner * From information provided by "Allen Martin" <AMartin@nvidia.com>:
169fb9aa6f1SThomas Gleixner *
170fb9aa6f1SThomas Gleixner * A hang is caused when the CPU generates a very fast CONNECT/HALT cycle
171fb9aa6f1SThomas Gleixner * sequence. Workaround is to set the SYSTEM_IDLE_TIMEOUT to 80 ns.
172fb9aa6f1SThomas Gleixner * This allows the state-machine and timer to return to a proper state within
173fb9aa6f1SThomas Gleixner * 80 ns of the CONNECT and probe appearing together. Since the CPU will not
174fb9aa6f1SThomas Gleixner * issue another HALT within 80 ns of the initial HALT, the failure condition
175fb9aa6f1SThomas Gleixner * is avoided.
176fb9aa6f1SThomas Gleixner */
pci_fixup_nforce2(struct pci_dev * dev)177fb9aa6f1SThomas Gleixner static void pci_fixup_nforce2(struct pci_dev *dev)
178fb9aa6f1SThomas Gleixner {
179fb9aa6f1SThomas Gleixner u32 val;
180fb9aa6f1SThomas Gleixner
181fb9aa6f1SThomas Gleixner /*
182fb9aa6f1SThomas Gleixner * Chip Old value New value
183fb9aa6f1SThomas Gleixner * C17 0x1F0FFF01 0x1F01FF01
184fb9aa6f1SThomas Gleixner * C18D 0x9F0FFF01 0x9F01FF01
185fb9aa6f1SThomas Gleixner *
186fb9aa6f1SThomas Gleixner * Northbridge chip version may be determined by
187fb9aa6f1SThomas Gleixner * reading the PCI revision ID (0xC1 or greater is C18D).
188fb9aa6f1SThomas Gleixner */
189fb9aa6f1SThomas Gleixner pci_read_config_dword(dev, 0x6c, &val);
190fb9aa6f1SThomas Gleixner
191fb9aa6f1SThomas Gleixner /*
192fb9aa6f1SThomas Gleixner * Apply fixup if needed, but don't touch disconnect state
193fb9aa6f1SThomas Gleixner */
194fb9aa6f1SThomas Gleixner if ((val & 0x00FF0000) != 0x00010000) {
1959ed88554Sbjorn.helgaas@hp.com dev_warn(&dev->dev, "nForce2 C1 Halt Disconnect fixup\n");
196fb9aa6f1SThomas Gleixner pci_write_config_dword(dev, 0x6c, (val & 0xFF00FFFF) | 0x00010000);
197fb9aa6f1SThomas Gleixner }
198fb9aa6f1SThomas Gleixner }
199fb9aa6f1SThomas Gleixner DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE2, pci_fixup_nforce2);
200fb9aa6f1SThomas Gleixner DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE2, pci_fixup_nforce2);
201fb9aa6f1SThomas Gleixner
202fb9aa6f1SThomas Gleixner /* Max PCI Express root ports */
203fb9aa6f1SThomas Gleixner #define MAX_PCIEROOT 6
204fb9aa6f1SThomas Gleixner static int quirk_aspm_offset[MAX_PCIEROOT << 3];
205fb9aa6f1SThomas Gleixner
206fb9aa6f1SThomas Gleixner #define GET_INDEX(a, b) ((((a) - PCI_DEVICE_ID_INTEL_MCH_PA) << 3) + ((b) & 7))
207fb9aa6f1SThomas Gleixner
quirk_pcie_aspm_read(struct pci_bus * bus,unsigned int devfn,int where,int size,u32 * value)208fb9aa6f1SThomas Gleixner static int quirk_pcie_aspm_read(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 *value)
209fb9aa6f1SThomas Gleixner {
210b6ce068aSMatthew Wilcox return raw_pci_read(pci_domain_nr(bus), bus->number,
211b6ce068aSMatthew Wilcox devfn, where, size, value);
212fb9aa6f1SThomas Gleixner }
213fb9aa6f1SThomas Gleixner
214fb9aa6f1SThomas Gleixner /*
215fb9aa6f1SThomas Gleixner * Replace the original pci bus ops for write with a new one that will filter
216fb9aa6f1SThomas Gleixner * the request to insure ASPM cannot be enabled.
217fb9aa6f1SThomas Gleixner */
quirk_pcie_aspm_write(struct pci_bus * bus,unsigned int devfn,int where,int size,u32 value)218fb9aa6f1SThomas Gleixner static int quirk_pcie_aspm_write(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 value)
219fb9aa6f1SThomas Gleixner {
220fb9aa6f1SThomas Gleixner u8 offset;
221fb9aa6f1SThomas Gleixner
222fb9aa6f1SThomas Gleixner offset = quirk_aspm_offset[GET_INDEX(bus->self->device, devfn)];
223fb9aa6f1SThomas Gleixner
224fb9aa6f1SThomas Gleixner if ((offset) && (where == offset))
225f8a26fe6SYijing Wang value = value & ~PCI_EXP_LNKCTL_ASPMC;
226fb9aa6f1SThomas Gleixner
227b6ce068aSMatthew Wilcox return raw_pci_write(pci_domain_nr(bus), bus->number,
228b6ce068aSMatthew Wilcox devfn, where, size, value);
229fb9aa6f1SThomas Gleixner }
230fb9aa6f1SThomas Gleixner
231fb9aa6f1SThomas Gleixner static struct pci_ops quirk_pcie_aspm_ops = {
232fb9aa6f1SThomas Gleixner .read = quirk_pcie_aspm_read,
233fb9aa6f1SThomas Gleixner .write = quirk_pcie_aspm_write,
234fb9aa6f1SThomas Gleixner };
235fb9aa6f1SThomas Gleixner
236fb9aa6f1SThomas Gleixner /*
237fb9aa6f1SThomas Gleixner * Prevents PCI Express ASPM (Active State Power Management) being enabled.
238fb9aa6f1SThomas Gleixner *
239fb9aa6f1SThomas Gleixner * Save the register offset, where the ASPM control bits are located,
240fb9aa6f1SThomas Gleixner * for each PCI Express device that is in the device list of
241fb9aa6f1SThomas Gleixner * the root port in an array for fast indexing. Replace the bus ops
242fb9aa6f1SThomas Gleixner * with the modified one.
243fb9aa6f1SThomas Gleixner */
pcie_rootport_aspm_quirk(struct pci_dev * pdev)244fb9aa6f1SThomas Gleixner static void pcie_rootport_aspm_quirk(struct pci_dev *pdev)
245fb9aa6f1SThomas Gleixner {
246f8a26fe6SYijing Wang int i;
247fb9aa6f1SThomas Gleixner struct pci_bus *pbus;
248fb9aa6f1SThomas Gleixner struct pci_dev *dev;
249fb9aa6f1SThomas Gleixner
250fb9aa6f1SThomas Gleixner if ((pbus = pdev->subordinate) == NULL)
251fb9aa6f1SThomas Gleixner return;
252fb9aa6f1SThomas Gleixner
253fb9aa6f1SThomas Gleixner /*
254fb9aa6f1SThomas Gleixner * Check if the DID of pdev matches one of the six root ports. This
255fb9aa6f1SThomas Gleixner * check is needed in the case this function is called directly by the
256fb9aa6f1SThomas Gleixner * hot-plug driver.
257fb9aa6f1SThomas Gleixner */
258fb9aa6f1SThomas Gleixner if ((pdev->device < PCI_DEVICE_ID_INTEL_MCH_PA) ||
259fb9aa6f1SThomas Gleixner (pdev->device > PCI_DEVICE_ID_INTEL_MCH_PC1))
260fb9aa6f1SThomas Gleixner return;
261fb9aa6f1SThomas Gleixner
262fb9aa6f1SThomas Gleixner if (list_empty(&pbus->devices)) {
263fb9aa6f1SThomas Gleixner /*
264fb9aa6f1SThomas Gleixner * If no device is attached to the root port at power-up or
265fb9aa6f1SThomas Gleixner * after hot-remove, the pbus->devices is empty and this code
266fb9aa6f1SThomas Gleixner * will set the offsets to zero and the bus ops to parent's bus
267fb9aa6f1SThomas Gleixner * ops, which is unmodified.
268fb9aa6f1SThomas Gleixner */
269fb9aa6f1SThomas Gleixner for (i = GET_INDEX(pdev->device, 0); i <= GET_INDEX(pdev->device, 7); ++i)
270fb9aa6f1SThomas Gleixner quirk_aspm_offset[i] = 0;
271fb9aa6f1SThomas Gleixner
272f8a26fe6SYijing Wang pci_bus_set_ops(pbus, pbus->parent->ops);
273fb9aa6f1SThomas Gleixner } else {
274fb9aa6f1SThomas Gleixner /*
275fb9aa6f1SThomas Gleixner * If devices are attached to the root port at power-up or
276fb9aa6f1SThomas Gleixner * after hot-add, the code loops through the device list of
277fb9aa6f1SThomas Gleixner * each root port to save the register offsets and replace the
278fb9aa6f1SThomas Gleixner * bus ops.
279fb9aa6f1SThomas Gleixner */
280f8a26fe6SYijing Wang list_for_each_entry(dev, &pbus->devices, bus_list)
281fb9aa6f1SThomas Gleixner /* There are 0 to 8 devices attached to this bus */
282f8a26fe6SYijing Wang quirk_aspm_offset[GET_INDEX(pdev->device, dev->devfn)] =
283f8a26fe6SYijing Wang dev->pcie_cap + PCI_EXP_LNKCTL;
284f8a26fe6SYijing Wang
285f8a26fe6SYijing Wang pci_bus_set_ops(pbus, &quirk_pcie_aspm_ops);
286f8a26fe6SYijing Wang dev_info(&pbus->dev, "writes to ASPM control bits will be ignored\n");
287fb9aa6f1SThomas Gleixner }
288f8a26fe6SYijing Wang
289fb9aa6f1SThomas Gleixner }
290fb9aa6f1SThomas Gleixner DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_MCH_PA, pcie_rootport_aspm_quirk);
291fb9aa6f1SThomas Gleixner DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_MCH_PA1, pcie_rootport_aspm_quirk);
292fb9aa6f1SThomas Gleixner DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_MCH_PB, pcie_rootport_aspm_quirk);
293fb9aa6f1SThomas Gleixner DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_MCH_PB1, pcie_rootport_aspm_quirk);
294fb9aa6f1SThomas Gleixner DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_MCH_PC, pcie_rootport_aspm_quirk);
295fb9aa6f1SThomas Gleixner DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_MCH_PC1, pcie_rootport_aspm_quirk);
296fb9aa6f1SThomas Gleixner
297fb9aa6f1SThomas Gleixner /*
298fb9aa6f1SThomas Gleixner * Fixup to mark boot BIOS video selected by BIOS before it changes
299fb9aa6f1SThomas Gleixner *
300fb9aa6f1SThomas Gleixner * From information provided by "Jon Smirl" <jonsmirl@gmail.com>
301fb9aa6f1SThomas Gleixner *
302fb9aa6f1SThomas Gleixner * The standard boot ROM sequence for an x86 machine uses the BIOS
303fb9aa6f1SThomas Gleixner * to select an initial video card for boot display. This boot video
3040c0e0736SBjorn Helgaas * card will have its BIOS copied to 0xC0000 in system RAM.
305fb9aa6f1SThomas Gleixner * IORESOURCE_ROM_SHADOW is used to associate the boot video
306fb9aa6f1SThomas Gleixner * card with this copy. On laptops this copy has to be used since
307fb9aa6f1SThomas Gleixner * the main ROM may be compressed or combined with another image.
308d8801e4dSSander Eikelenboom * See pci_map_rom() for use of this flag. Before marking the device
309d8801e4dSSander Eikelenboom * with IORESOURCE_ROM_SHADOW check if a vga_default_device is already set
3100c0e0736SBjorn Helgaas * by either arch code or vga-arbitration; if so only apply the fixup to this
3110c0e0736SBjorn Helgaas * already-determined primary video card.
312fb9aa6f1SThomas Gleixner */
313fb9aa6f1SThomas Gleixner
pci_fixup_video(struct pci_dev * pdev)314a18e3690SGreg Kroah-Hartman static void pci_fixup_video(struct pci_dev *pdev)
315fb9aa6f1SThomas Gleixner {
316fb9aa6f1SThomas Gleixner struct pci_dev *bridge;
317fb9aa6f1SThomas Gleixner struct pci_bus *bus;
318fb9aa6f1SThomas Gleixner u16 config;
3190c0e0736SBjorn Helgaas struct resource *res;
320fb9aa6f1SThomas Gleixner
321fb9aa6f1SThomas Gleixner /* Is VGA routed to us? */
322fb9aa6f1SThomas Gleixner bus = pdev->bus;
323fb9aa6f1SThomas Gleixner while (bus) {
324fb9aa6f1SThomas Gleixner bridge = bus->self;
325fb9aa6f1SThomas Gleixner
326fb9aa6f1SThomas Gleixner /*
327fb9aa6f1SThomas Gleixner * From information provided by
328fb9aa6f1SThomas Gleixner * "David Miller" <davem@davemloft.net>
329fb9aa6f1SThomas Gleixner * The bridge control register is valid for PCI header
330fb9aa6f1SThomas Gleixner * type BRIDGE, or CARDBUS. Host to PCI controllers use
331fb9aa6f1SThomas Gleixner * PCI header type NORMAL.
332fb9aa6f1SThomas Gleixner */
33356a41f99SYijing Wang if (bridge && (pci_is_bridge(bridge))) {
334fb9aa6f1SThomas Gleixner pci_read_config_word(bridge, PCI_BRIDGE_CONTROL,
335fb9aa6f1SThomas Gleixner &config);
336fb9aa6f1SThomas Gleixner if (!(config & PCI_BRIDGE_CTL_VGA))
337fb9aa6f1SThomas Gleixner return;
338fb9aa6f1SThomas Gleixner }
339fb9aa6f1SThomas Gleixner bus = bus->parent;
340fb9aa6f1SThomas Gleixner }
341d8801e4dSSander Eikelenboom if (!vga_default_device() || pdev == vga_default_device()) {
342fb9aa6f1SThomas Gleixner pci_read_config_word(pdev, PCI_COMMAND, &config);
343fb9aa6f1SThomas Gleixner if (config & (PCI_COMMAND_IO | PCI_COMMAND_MEMORY)) {
3440c0e0736SBjorn Helgaas res = &pdev->resource[PCI_ROM_RESOURCE];
3450c0e0736SBjorn Helgaas
3460c0e0736SBjorn Helgaas pci_disable_rom(pdev);
3470c0e0736SBjorn Helgaas if (res->parent)
3480c0e0736SBjorn Helgaas release_resource(res);
3490c0e0736SBjorn Helgaas
3500c0e0736SBjorn Helgaas res->start = 0xC0000;
3510c0e0736SBjorn Helgaas res->end = res->start + 0x20000 - 1;
3520c0e0736SBjorn Helgaas res->flags = IORESOURCE_MEM | IORESOURCE_ROM_SHADOW |
35363e22924SBjorn Helgaas IORESOURCE_PCI_FIXED;
3540c0e0736SBjorn Helgaas dev_info(&pdev->dev, "Video device with shadowed ROM at %pR\n",
3550c0e0736SBjorn Helgaas res);
356fb9aa6f1SThomas Gleixner }
357fb9aa6f1SThomas Gleixner }
358d8801e4dSSander Eikelenboom }
35966d28b21SBjorn Helgaas DECLARE_PCI_FIXUP_CLASS_HEADER(PCI_ANY_ID, PCI_ANY_ID,
36073e3b590SYinghai Lu PCI_CLASS_DISPLAY_VGA, 8, pci_fixup_video);
361fb9aa6f1SThomas Gleixner
362346ca04dSJohannes Goecke
363a18e3690SGreg Kroah-Hartman static const struct dmi_system_id msi_k8t_dmi_table[] = {
364346ca04dSJohannes Goecke {
365346ca04dSJohannes Goecke .ident = "MSI-K8T-Neo2Fir",
366346ca04dSJohannes Goecke .matches = {
367346ca04dSJohannes Goecke DMI_MATCH(DMI_SYS_VENDOR, "MSI"),
368346ca04dSJohannes Goecke DMI_MATCH(DMI_PRODUCT_NAME, "MS-6702E"),
369346ca04dSJohannes Goecke },
370346ca04dSJohannes Goecke },
371346ca04dSJohannes Goecke {}
372346ca04dSJohannes Goecke };
373346ca04dSJohannes Goecke
374346ca04dSJohannes Goecke /*
375346ca04dSJohannes Goecke * The AMD-Athlon64 board MSI "K8T Neo2-FIR" disables the onboard sound
376346ca04dSJohannes Goecke * card if a PCI-soundcard is added.
377346ca04dSJohannes Goecke *
378346ca04dSJohannes Goecke * The BIOS only gives options "DISABLED" and "AUTO". This code sets
379346ca04dSJohannes Goecke * the corresponding register-value to enable the soundcard.
380346ca04dSJohannes Goecke *
381d9f6e12fSIngo Molnar * The soundcard is only enabled, if the mainboard is identified
382346ca04dSJohannes Goecke * via DMI-tables and the soundcard is detected to be off.
383346ca04dSJohannes Goecke */
pci_fixup_msi_k8t_onboard_sound(struct pci_dev * dev)384a18e3690SGreg Kroah-Hartman static void pci_fixup_msi_k8t_onboard_sound(struct pci_dev *dev)
385346ca04dSJohannes Goecke {
386346ca04dSJohannes Goecke unsigned char val;
387346ca04dSJohannes Goecke if (!dmi_check_system(msi_k8t_dmi_table))
388346ca04dSJohannes Goecke return; /* only applies to MSI K8T Neo2-FIR */
389346ca04dSJohannes Goecke
390346ca04dSJohannes Goecke pci_read_config_byte(dev, 0x50, &val);
391346ca04dSJohannes Goecke if (val & 0x40) {
392346ca04dSJohannes Goecke pci_write_config_byte(dev, 0x50, val & (~0x40));
393346ca04dSJohannes Goecke
394346ca04dSJohannes Goecke /* verify the change for status output */
395346ca04dSJohannes Goecke pci_read_config_byte(dev, 0x50, &val);
396346ca04dSJohannes Goecke if (val & 0x40)
3979ed88554Sbjorn.helgaas@hp.com dev_info(&dev->dev, "Detected MSI K8T Neo2-FIR; "
398346ca04dSJohannes Goecke "can't enable onboard soundcard!\n");
399346ca04dSJohannes Goecke else
4009ed88554Sbjorn.helgaas@hp.com dev_info(&dev->dev, "Detected MSI K8T Neo2-FIR; "
4019ed88554Sbjorn.helgaas@hp.com "enabled onboard soundcard\n");
402346ca04dSJohannes Goecke }
403346ca04dSJohannes Goecke }
404346ca04dSJohannes Goecke DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8237,
405346ca04dSJohannes Goecke pci_fixup_msi_k8t_onboard_sound);
406346ca04dSJohannes Goecke DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8237,
407346ca04dSJohannes Goecke pci_fixup_msi_k8t_onboard_sound);
408346ca04dSJohannes Goecke
409fb9aa6f1SThomas Gleixner /*
410fb9aa6f1SThomas Gleixner * Some Toshiba laptops need extra code to enable their TI TSB43AB22/A.
411fb9aa6f1SThomas Gleixner *
412fb9aa6f1SThomas Gleixner * We pretend to bring them out of full D3 state, and restore the proper
413fb9aa6f1SThomas Gleixner * IRQ, PCI cache line size, and BARs, otherwise the device won't function
414fb9aa6f1SThomas Gleixner * properly. In some cases, the device will generate an interrupt on
415fb9aa6f1SThomas Gleixner * the wrong IRQ line, causing any devices sharing the line it's
416fb9aa6f1SThomas Gleixner * *supposed* to use to be disabled by the kernel's IRQ debug code.
417fb9aa6f1SThomas Gleixner */
418fb9aa6f1SThomas Gleixner static u16 toshiba_line_size;
419fb9aa6f1SThomas Gleixner
420a18e3690SGreg Kroah-Hartman static const struct dmi_system_id toshiba_ohci1394_dmi_table[] = {
421fb9aa6f1SThomas Gleixner {
422fb9aa6f1SThomas Gleixner .ident = "Toshiba PS5 based laptop",
423fb9aa6f1SThomas Gleixner .matches = {
424fb9aa6f1SThomas Gleixner DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
425fb9aa6f1SThomas Gleixner DMI_MATCH(DMI_PRODUCT_VERSION, "PS5"),
426fb9aa6f1SThomas Gleixner },
427fb9aa6f1SThomas Gleixner },
428fb9aa6f1SThomas Gleixner {
429fb9aa6f1SThomas Gleixner .ident = "Toshiba PSM4 based laptop",
430fb9aa6f1SThomas Gleixner .matches = {
431fb9aa6f1SThomas Gleixner DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
432fb9aa6f1SThomas Gleixner DMI_MATCH(DMI_PRODUCT_VERSION, "PSM4"),
433fb9aa6f1SThomas Gleixner },
434fb9aa6f1SThomas Gleixner },
435fb9aa6f1SThomas Gleixner {
436fb9aa6f1SThomas Gleixner .ident = "Toshiba A40 based laptop",
437fb9aa6f1SThomas Gleixner .matches = {
438fb9aa6f1SThomas Gleixner DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
439fb9aa6f1SThomas Gleixner DMI_MATCH(DMI_PRODUCT_VERSION, "PSA40U"),
440fb9aa6f1SThomas Gleixner },
441fb9aa6f1SThomas Gleixner },
442fb9aa6f1SThomas Gleixner { }
443fb9aa6f1SThomas Gleixner };
444fb9aa6f1SThomas Gleixner
pci_pre_fixup_toshiba_ohci1394(struct pci_dev * dev)445a18e3690SGreg Kroah-Hartman static void pci_pre_fixup_toshiba_ohci1394(struct pci_dev *dev)
446fb9aa6f1SThomas Gleixner {
447fb9aa6f1SThomas Gleixner if (!dmi_check_system(toshiba_ohci1394_dmi_table))
448fb9aa6f1SThomas Gleixner return; /* only applies to certain Toshibas (so far) */
449fb9aa6f1SThomas Gleixner
450fb9aa6f1SThomas Gleixner dev->current_state = PCI_D3cold;
451fb9aa6f1SThomas Gleixner pci_read_config_word(dev, PCI_CACHE_LINE_SIZE, &toshiba_line_size);
452fb9aa6f1SThomas Gleixner }
453fb9aa6f1SThomas Gleixner DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_TI, 0x8032,
454fb9aa6f1SThomas Gleixner pci_pre_fixup_toshiba_ohci1394);
455fb9aa6f1SThomas Gleixner
pci_post_fixup_toshiba_ohci1394(struct pci_dev * dev)456a18e3690SGreg Kroah-Hartman static void pci_post_fixup_toshiba_ohci1394(struct pci_dev *dev)
457fb9aa6f1SThomas Gleixner {
458fb9aa6f1SThomas Gleixner if (!dmi_check_system(toshiba_ohci1394_dmi_table))
459fb9aa6f1SThomas Gleixner return; /* only applies to certain Toshibas (so far) */
460fb9aa6f1SThomas Gleixner
461fb9aa6f1SThomas Gleixner /* Restore config space on Toshiba laptops */
462fb9aa6f1SThomas Gleixner pci_write_config_word(dev, PCI_CACHE_LINE_SIZE, toshiba_line_size);
463fb9aa6f1SThomas Gleixner pci_read_config_byte(dev, PCI_INTERRUPT_LINE, (u8 *)&dev->irq);
464fb9aa6f1SThomas Gleixner pci_write_config_dword(dev, PCI_BASE_ADDRESS_0,
465fb9aa6f1SThomas Gleixner pci_resource_start(dev, 0));
466fb9aa6f1SThomas Gleixner pci_write_config_dword(dev, PCI_BASE_ADDRESS_1,
467fb9aa6f1SThomas Gleixner pci_resource_start(dev, 1));
468fb9aa6f1SThomas Gleixner }
469fb9aa6f1SThomas Gleixner DECLARE_PCI_FIXUP_ENABLE(PCI_VENDOR_ID_TI, 0x8032,
470fb9aa6f1SThomas Gleixner pci_post_fixup_toshiba_ohci1394);
471fb9aa6f1SThomas Gleixner
472fb9aa6f1SThomas Gleixner
473fb9aa6f1SThomas Gleixner /*
474fb9aa6f1SThomas Gleixner * Prevent the BIOS trapping accesses to the Cyrix CS5530A video device
475fb9aa6f1SThomas Gleixner * configuration space.
476fb9aa6f1SThomas Gleixner */
pci_early_fixup_cyrix_5530(struct pci_dev * dev)477fb9aa6f1SThomas Gleixner static void pci_early_fixup_cyrix_5530(struct pci_dev *dev)
478fb9aa6f1SThomas Gleixner {
479fb9aa6f1SThomas Gleixner u8 r;
480fb9aa6f1SThomas Gleixner /* clear 'F4 Video Configuration Trap' bit */
481fb9aa6f1SThomas Gleixner pci_read_config_byte(dev, 0x42, &r);
482fb9aa6f1SThomas Gleixner r &= 0xfd;
483fb9aa6f1SThomas Gleixner pci_write_config_byte(dev, 0x42, r);
484fb9aa6f1SThomas Gleixner }
485fb9aa6f1SThomas Gleixner DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_CYRIX, PCI_DEVICE_ID_CYRIX_5530_LEGACY,
486fb9aa6f1SThomas Gleixner pci_early_fixup_cyrix_5530);
487fb9aa6f1SThomas Gleixner DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_CYRIX, PCI_DEVICE_ID_CYRIX_5530_LEGACY,
488fb9aa6f1SThomas Gleixner pci_early_fixup_cyrix_5530);
489fb9aa6f1SThomas Gleixner
490fb9aa6f1SThomas Gleixner /*
491fb9aa6f1SThomas Gleixner * Siemens Nixdorf AG FSC Multiprocessor Interrupt Controller:
492fb9aa6f1SThomas Gleixner * prevent update of the BAR0, which doesn't look like a normal BAR.
493fb9aa6f1SThomas Gleixner */
pci_siemens_interrupt_controller(struct pci_dev * dev)494a18e3690SGreg Kroah-Hartman static void pci_siemens_interrupt_controller(struct pci_dev *dev)
495fb9aa6f1SThomas Gleixner {
496fb9aa6f1SThomas Gleixner dev->resource[0].flags |= IORESOURCE_PCI_FIXED;
497fb9aa6f1SThomas Gleixner }
498fb9aa6f1SThomas Gleixner DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SIEMENS, 0x0015,
499fb9aa6f1SThomas Gleixner pci_siemens_interrupt_controller);
50057741a77SYinghai Lu
50157741a77SYinghai Lu /*
502d7451fcaSJordan Crouse * SB600: Disable BAR1 on device 14.0 to avoid HPET resources from
503d7451fcaSJordan Crouse * confusing the PCI engine:
504d7451fcaSJordan Crouse */
sb600_disable_hpet_bar(struct pci_dev * dev)505d7451fcaSJordan Crouse static void sb600_disable_hpet_bar(struct pci_dev *dev)
506d7451fcaSJordan Crouse {
507d7451fcaSJordan Crouse u8 val;
508d7451fcaSJordan Crouse
509d7451fcaSJordan Crouse /*
510d7451fcaSJordan Crouse * The SB600 and SB700 both share the same device
511d7451fcaSJordan Crouse * ID, but the PM register 0x55 does something different
512d7451fcaSJordan Crouse * for the SB700, so make sure we are dealing with the
513d7451fcaSJordan Crouse * SB600 before touching the bit:
514d7451fcaSJordan Crouse */
515d7451fcaSJordan Crouse
516d7451fcaSJordan Crouse pci_read_config_byte(dev, 0x08, &val);
517d7451fcaSJordan Crouse
518d7451fcaSJordan Crouse if (val < 0x2F) {
519d7451fcaSJordan Crouse outb(0x55, 0xCD6);
520d7451fcaSJordan Crouse val = inb(0xCD7);
521d7451fcaSJordan Crouse
522d7451fcaSJordan Crouse /* Set bit 7 in PM register 0x55 */
523d7451fcaSJordan Crouse outb(0x55, 0xCD6);
524d7451fcaSJordan Crouse outb(val | 0x80, 0xCD7);
525d7451fcaSJordan Crouse }
526d7451fcaSJordan Crouse }
527d7451fcaSJordan Crouse DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_ATI, 0x4385, sb600_disable_hpet_bar);
52880b3e557SAlan Cox
52944c8bdbeSBjorn Helgaas #ifdef CONFIG_HPET_TIMER
sb600_hpet_quirk(struct pci_dev * dev)53044c8bdbeSBjorn Helgaas static void sb600_hpet_quirk(struct pci_dev *dev)
53144c8bdbeSBjorn Helgaas {
53244c8bdbeSBjorn Helgaas struct resource *r = &dev->resource[1];
53344c8bdbeSBjorn Helgaas
53444c8bdbeSBjorn Helgaas if (r->flags & IORESOURCE_MEM && r->start == hpet_address) {
53544c8bdbeSBjorn Helgaas r->flags |= IORESOURCE_PCI_FIXED;
53644c8bdbeSBjorn Helgaas dev_info(&dev->dev, "reg 0x14 contains HPET; making it immovable\n");
53744c8bdbeSBjorn Helgaas }
53844c8bdbeSBjorn Helgaas }
53944c8bdbeSBjorn Helgaas DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_ATI, 0x4385, sb600_hpet_quirk);
54044c8bdbeSBjorn Helgaas #endif
54144c8bdbeSBjorn Helgaas
54280b3e557SAlan Cox /*
54380b3e557SAlan Cox * Twinhead H12Y needs us to block out a region otherwise we map devices
54480b3e557SAlan Cox * there and any access kills the box.
54580b3e557SAlan Cox *
54680b3e557SAlan Cox * See: https://bugzilla.kernel.org/show_bug.cgi?id=10231
54780b3e557SAlan Cox *
54880b3e557SAlan Cox * Match off the LPC and svid/sdid (older kernels lose the bridge subvendor)
54980b3e557SAlan Cox */
twinhead_reserve_killing_zone(struct pci_dev * dev)550a18e3690SGreg Kroah-Hartman static void twinhead_reserve_killing_zone(struct pci_dev *dev)
55180b3e557SAlan Cox {
55280b3e557SAlan Cox if (dev->subsystem_vendor == 0x14FF && dev->subsystem_device == 0xA003) {
55380b3e557SAlan Cox pr_info("Reserving memory on Twinhead H12Y\n");
55480b3e557SAlan Cox request_mem_region(0xFFB00000, 0x100000, "twinhead");
55580b3e557SAlan Cox }
55680b3e557SAlan Cox }
55780b3e557SAlan Cox DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x27B9, twinhead_reserve_killing_zone);
558b8941571SBjorn Helgaas
559da77b671SPrarit Bhargava /*
5606af7e4f7SBjorn Helgaas * Device [8086:2fc0]
5616af7e4f7SBjorn Helgaas * Erratum HSE43
5626af7e4f7SBjorn Helgaas * CONFIG_TDP_NOMINAL CSR Implemented at Incorrect Offset
5637ecd4a81SAlexander A. Klimov * https://www.intel.com/content/www/us/en/processors/xeon/xeon-e5-v3-spec-update.html
564da77b671SPrarit Bhargava *
5656af7e4f7SBjorn Helgaas * Devices [8086:6f60,6fa0,6fc0]
5666af7e4f7SBjorn Helgaas * Erratum BDF2
5676af7e4f7SBjorn Helgaas * PCI BARs in the Home Agent Will Return Non-Zero Values During Enumeration
5687ecd4a81SAlexander A. Klimov * https://www.intel.com/content/www/us/en/processors/xeon/xeon-e5-v4-spec-update.html
569da77b671SPrarit Bhargava */
pci_invalid_bar(struct pci_dev * dev)5706af7e4f7SBjorn Helgaas static void pci_invalid_bar(struct pci_dev *dev)
571b8941571SBjorn Helgaas {
572b8941571SBjorn Helgaas dev->non_compliant_bars = 1;
573b8941571SBjorn Helgaas }
5746af7e4f7SBjorn Helgaas DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL, 0x2fc0, pci_invalid_bar);
5756af7e4f7SBjorn Helgaas DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL, 0x6f60, pci_invalid_bar);
5766af7e4f7SBjorn Helgaas DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL, 0x6fa0, pci_invalid_bar);
5776af7e4f7SBjorn Helgaas DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL, 0x6fc0, pci_invalid_bar);
5781574051eSXiaochun Lee DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL, 0xa1ec, pci_invalid_bar);
5791574051eSXiaochun Lee DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL, 0xa1ed, pci_invalid_bar);
5801574051eSXiaochun Lee DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL, 0xa26c, pci_invalid_bar);
5811574051eSXiaochun Lee DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL, 0xa26d, pci_invalid_bar);
5820bf3730bSKai-Heng Feng
5830bf3730bSKai-Heng Feng /*
5840bf3730bSKai-Heng Feng * Device [1022:7808]
5850bf3730bSKai-Heng Feng * 23. USB Wake on Connect/Disconnect with Low Speed Devices
5860bf3730bSKai-Heng Feng * https://support.amd.com/TechDocs/46837.pdf
5870bf3730bSKai-Heng Feng * Appendix A2
5880bf3730bSKai-Heng Feng * https://support.amd.com/TechDocs/42413.pdf
5890bf3730bSKai-Heng Feng */
pci_fixup_amd_ehci_pme(struct pci_dev * dev)5900bf3730bSKai-Heng Feng static void pci_fixup_amd_ehci_pme(struct pci_dev *dev)
5910bf3730bSKai-Heng Feng {
5920bf3730bSKai-Heng Feng dev_info(&dev->dev, "PME# does not work under D3, disabling it\n");
5933789af9aSKrzysztof Wilczyński dev->pme_support &= ~((PCI_PM_CAP_PME_D3hot | PCI_PM_CAP_PME_D3cold)
5940bf3730bSKai-Heng Feng >> PCI_PM_CAP_PME_SHIFT);
5950bf3730bSKai-Heng Feng }
5960bf3730bSKai-Heng Feng DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AMD, 0x7808, pci_fixup_amd_ehci_pme);
5978cd93850SBjorn Helgaas
5988cd93850SBjorn Helgaas /*
5997e8ce0e2SKai-Heng Feng * Device [1022:7914]
6007e8ce0e2SKai-Heng Feng * When in D0, PME# doesn't get asserted when plugging USB 2.0 device.
6017e8ce0e2SKai-Heng Feng */
pci_fixup_amd_fch_xhci_pme(struct pci_dev * dev)6027e8ce0e2SKai-Heng Feng static void pci_fixup_amd_fch_xhci_pme(struct pci_dev *dev)
6037e8ce0e2SKai-Heng Feng {
6047e8ce0e2SKai-Heng Feng dev_info(&dev->dev, "PME# does not work under D0, disabling it\n");
6057e8ce0e2SKai-Heng Feng dev->pme_support &= ~(PCI_PM_CAP_PME_D0 >> PCI_PM_CAP_PME_SHIFT);
6067e8ce0e2SKai-Heng Feng }
6077e8ce0e2SKai-Heng Feng DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AMD, 0x7914, pci_fixup_amd_fch_xhci_pme);
6087e8ce0e2SKai-Heng Feng
6097e8ce0e2SKai-Heng Feng /*
61013cfc732SBjorn Helgaas * Apple MacBook Pro: Avoid [mem 0x7fa00000-0x7fbfffff]
61113cfc732SBjorn Helgaas *
61213cfc732SBjorn Helgaas * Using the [mem 0x7fa00000-0x7fbfffff] region, e.g., by assigning it to
61313cfc732SBjorn Helgaas * the 00:1c.0 Root Port, causes a conflict with [io 0x1804], which is used
61413cfc732SBjorn Helgaas * for soft poweroff and suspend-to-RAM.
61513cfc732SBjorn Helgaas *
61613cfc732SBjorn Helgaas * As far as we know, this is related to the address space, not to the Root
61713cfc732SBjorn Helgaas * Port itself. Attaching the quirk to the Root Port is a convenience, but
61813cfc732SBjorn Helgaas * it could probably also be a standalone DMI quirk.
61913cfc732SBjorn Helgaas *
62013cfc732SBjorn Helgaas * https://bugzilla.kernel.org/show_bug.cgi?id=103211
62113cfc732SBjorn Helgaas */
quirk_apple_mbp_poweroff(struct pci_dev * pdev)62213cfc732SBjorn Helgaas static void quirk_apple_mbp_poweroff(struct pci_dev *pdev)
62313cfc732SBjorn Helgaas {
62413cfc732SBjorn Helgaas struct device *dev = &pdev->dev;
62513cfc732SBjorn Helgaas struct resource *res;
62613cfc732SBjorn Helgaas
62713cfc732SBjorn Helgaas if ((!dmi_match(DMI_PRODUCT_NAME, "MacBookPro11,4") &&
62813cfc732SBjorn Helgaas !dmi_match(DMI_PRODUCT_NAME, "MacBookPro11,5")) ||
62913cfc732SBjorn Helgaas pdev->bus->number != 0 || pdev->devfn != PCI_DEVFN(0x1c, 0))
63013cfc732SBjorn Helgaas return;
63113cfc732SBjorn Helgaas
63213cfc732SBjorn Helgaas res = request_mem_region(0x7fa00000, 0x200000,
63313cfc732SBjorn Helgaas "MacBook Pro poweroff workaround");
63413cfc732SBjorn Helgaas if (res)
63513cfc732SBjorn Helgaas dev_info(dev, "claimed %s %pR\n", res->name, res);
63613cfc732SBjorn Helgaas else
63713cfc732SBjorn Helgaas dev_info(dev, "can't work around MacBook Pro poweroff issue\n");
63813cfc732SBjorn Helgaas }
63913cfc732SBjorn Helgaas DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x8c10, quirk_apple_mbp_poweroff);
640f1b0e54eSJon Derrick
641f1b0e54eSJon Derrick /*
642f1b0e54eSJon Derrick * VMD-enabled root ports will change the source ID for all messages
643f1b0e54eSJon Derrick * to the VMD device. Rather than doing device matching with the source
644f1b0e54eSJon Derrick * ID, the AER driver should traverse the child device tree, reading
645f1b0e54eSJon Derrick * AER registers to find the faulting device.
646f1b0e54eSJon Derrick */
quirk_no_aersid(struct pci_dev * pdev)647f1b0e54eSJon Derrick static void quirk_no_aersid(struct pci_dev *pdev)
648f1b0e54eSJon Derrick {
649f1b0e54eSJon Derrick /* VMD Domain */
6504f475e8eSJon Derrick if (is_vmd(pdev->bus) && pci_is_root_bus(pdev->bus))
651f1b0e54eSJon Derrick pdev->bus->bus_flags |= PCI_BUS_FLAGS_NO_AERSID;
652f1b0e54eSJon Derrick }
6534f475e8eSJon Derrick DECLARE_PCI_FIXUP_CLASS_EARLY(PCI_VENDOR_ID_INTEL, PCI_ANY_ID,
6544f475e8eSJon Derrick PCI_CLASS_BRIDGE_PCI, 8, quirk_no_aersid);
655fa564ad9SChristian König
quirk_intel_th_dnv(struct pci_dev * dev)6562e095ce7SAlexander Shishkin static void quirk_intel_th_dnv(struct pci_dev *dev)
6572e095ce7SAlexander Shishkin {
6582e095ce7SAlexander Shishkin struct resource *r = &dev->resource[4];
6592e095ce7SAlexander Shishkin
6602e095ce7SAlexander Shishkin /*
6612e095ce7SAlexander Shishkin * Denverton reports 2k of RTIT_BAR (intel_th resource 4), which
6622e095ce7SAlexander Shishkin * appears to be 4 MB in reality.
6632e095ce7SAlexander Shishkin */
6642e095ce7SAlexander Shishkin if (r->end == r->start + 0x7ff) {
6652e095ce7SAlexander Shishkin r->start = 0;
6662e095ce7SAlexander Shishkin r->end = 0x3fffff;
6672e095ce7SAlexander Shishkin r->flags |= IORESOURCE_UNSET;
6682e095ce7SAlexander Shishkin }
6692e095ce7SAlexander Shishkin }
6702e095ce7SAlexander Shishkin DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x19e1, quirk_intel_th_dnv);
6712e095ce7SAlexander Shishkin
672fa564ad9SChristian König #ifdef CONFIG_PHYS_ADDR_T_64BIT
673fa564ad9SChristian König
674fa564ad9SChristian König #define AMD_141b_MMIO_BASE(x) (0x80 + (x) * 0x8)
675fa564ad9SChristian König #define AMD_141b_MMIO_BASE_RE_MASK BIT(0)
676fa564ad9SChristian König #define AMD_141b_MMIO_BASE_WE_MASK BIT(1)
677fa564ad9SChristian König #define AMD_141b_MMIO_BASE_MMIOBASE_MASK GENMASK(31,8)
678fa564ad9SChristian König
679fa564ad9SChristian König #define AMD_141b_MMIO_LIMIT(x) (0x84 + (x) * 0x8)
680fa564ad9SChristian König #define AMD_141b_MMIO_LIMIT_MMIOLIMIT_MASK GENMASK(31,8)
681fa564ad9SChristian König
682fa564ad9SChristian König #define AMD_141b_MMIO_HIGH(x) (0x180 + (x) * 0x4)
683fa564ad9SChristian König #define AMD_141b_MMIO_HIGH_MMIOBASE_MASK GENMASK(7,0)
684fa564ad9SChristian König #define AMD_141b_MMIO_HIGH_MMIOLIMIT_SHIFT 16
685fa564ad9SChristian König #define AMD_141b_MMIO_HIGH_MMIOLIMIT_MASK GENMASK(23,16)
686fa564ad9SChristian König
687fa564ad9SChristian König /*
688fa564ad9SChristian König * The PCI Firmware Spec, rev 3.2, notes that ACPI should optionally allow
689fa564ad9SChristian König * configuring host bridge windows using the _PRS and _SRS methods.
690fa564ad9SChristian König *
691fa564ad9SChristian König * But this is rarely implemented, so we manually enable a large 64bit BAR for
692fa564ad9SChristian König * PCIe device on AMD Family 15h (Models 00h-1fh, 30h-3fh, 60h-7fh) Processors
693fa564ad9SChristian König * here.
694fa564ad9SChristian König */
pci_amd_enable_64bit_bar(struct pci_dev * dev)695fa564ad9SChristian König static void pci_amd_enable_64bit_bar(struct pci_dev *dev)
696fa564ad9SChristian König {
697838cda36S=?UTF-8?q?Christian=20K=C3=B6nig?= static const char *name = "PCI Bus 0000:00";
698838cda36S=?UTF-8?q?Christian=20K=C3=B6nig?= struct resource *res, *conflict;
699fa564ad9SChristian König u32 base, limit, high;
700a19e2696SChristian König struct pci_dev *other;
70103a55173S=?UTF-8?q?Christian=20K=C3=B6nig?= unsigned i;
702a19e2696SChristian König
703f32ab754S=?UTF-8?q?Christian=20K=C3=B6nig?= if (!(pci_probe & PCI_BIG_ROOT_WINDOW))
704f32ab754S=?UTF-8?q?Christian=20K=C3=B6nig?= return;
705f32ab754S=?UTF-8?q?Christian=20K=C3=B6nig?=
706a19e2696SChristian König /* Check that we are the only device of that type */
707a19e2696SChristian König other = pci_get_device(dev->vendor, dev->device, NULL);
708a19e2696SChristian König if (other != dev ||
709a19e2696SChristian König (other = pci_get_device(dev->vendor, dev->device, other))) {
710a19e2696SChristian König /* This is a multi-socket system, don't touch it for now */
711a19e2696SChristian König pci_dev_put(other);
712a19e2696SChristian König return;
713a19e2696SChristian König }
714fa564ad9SChristian König
715fa564ad9SChristian König for (i = 0; i < 8; i++) {
716fa564ad9SChristian König pci_read_config_dword(dev, AMD_141b_MMIO_BASE(i), &base);
717fa564ad9SChristian König pci_read_config_dword(dev, AMD_141b_MMIO_HIGH(i), &high);
718fa564ad9SChristian König
719fa564ad9SChristian König /* Is this slot free? */
720fa564ad9SChristian König if (!(base & (AMD_141b_MMIO_BASE_RE_MASK |
721fa564ad9SChristian König AMD_141b_MMIO_BASE_WE_MASK)))
722fa564ad9SChristian König break;
723fa564ad9SChristian König
724fa564ad9SChristian König base >>= 8;
725fa564ad9SChristian König base |= high << 24;
726fa564ad9SChristian König
727fa564ad9SChristian König /* Abort if a slot already configures a 64bit BAR. */
728fa564ad9SChristian König if (base > 0x10000)
729fa564ad9SChristian König return;
730fa564ad9SChristian König }
731fa564ad9SChristian König if (i == 8)
732fa564ad9SChristian König return;
733fa564ad9SChristian König
734fa564ad9SChristian König res = kzalloc(sizeof(*res), GFP_KERNEL);
735fa564ad9SChristian König if (!res)
736fa564ad9SChristian König return;
737fa564ad9SChristian König
73803a55173S=?UTF-8?q?Christian=20K=C3=B6nig?= /*
73903a55173S=?UTF-8?q?Christian=20K=C3=B6nig?= * Allocate a 256GB window directly below the 0xfd00000000 hardware
74003a55173S=?UTF-8?q?Christian=20K=C3=B6nig?= * limit (see AMD Family 15h Models 30h-3Fh BKDG, sec 2.4.6).
74103a55173S=?UTF-8?q?Christian=20K=C3=B6nig?= */
742838cda36S=?UTF-8?q?Christian=20K=C3=B6nig?= res->name = name;
743fa564ad9SChristian König res->flags = IORESOURCE_PREFETCH | IORESOURCE_MEM |
744fa564ad9SChristian König IORESOURCE_MEM_64 | IORESOURCE_WINDOW;
74503a55173S=?UTF-8?q?Christian=20K=C3=B6nig?= res->start = 0xbd00000000ull;
746fa564ad9SChristian König res->end = 0xfd00000000ull - 1;
747fa564ad9SChristian König
748838cda36S=?UTF-8?q?Christian=20K=C3=B6nig?= conflict = request_resource_conflict(&iomem_resource, res);
749838cda36S=?UTF-8?q?Christian=20K=C3=B6nig?= if (conflict) {
750470195f8SChristian König kfree(res);
751838cda36S=?UTF-8?q?Christian=20K=C3=B6nig?= if (conflict->name != name)
752470195f8SChristian König return;
753fa564ad9SChristian König
754838cda36S=?UTF-8?q?Christian=20K=C3=B6nig?= /* We are resuming from suspend; just reenable the window */
755838cda36S=?UTF-8?q?Christian=20K=C3=B6nig?= res = conflict;
756838cda36S=?UTF-8?q?Christian=20K=C3=B6nig?= } else {
757f32ab754S=?UTF-8?q?Christian=20K=C3=B6nig?= dev_info(&dev->dev, "adding root bus resource %pR (tainting kernel)\n",
758f32ab754S=?UTF-8?q?Christian=20K=C3=B6nig?= res);
759f32ab754S=?UTF-8?q?Christian=20K=C3=B6nig?= add_taint(TAINT_FIRMWARE_WORKAROUND, LOCKDEP_STILL_OK);
760838cda36S=?UTF-8?q?Christian=20K=C3=B6nig?= pci_bus_add_resource(dev->bus, res, 0);
761838cda36S=?UTF-8?q?Christian=20K=C3=B6nig?= }
762fa564ad9SChristian König
763fa564ad9SChristian König base = ((res->start >> 8) & AMD_141b_MMIO_BASE_MMIOBASE_MASK) |
764fa564ad9SChristian König AMD_141b_MMIO_BASE_RE_MASK | AMD_141b_MMIO_BASE_WE_MASK;
765fa564ad9SChristian König limit = ((res->end + 1) >> 8) & AMD_141b_MMIO_LIMIT_MMIOLIMIT_MASK;
766fa564ad9SChristian König high = ((res->start >> 40) & AMD_141b_MMIO_HIGH_MMIOBASE_MASK) |
767fa564ad9SChristian König ((((res->end + 1) >> 40) << AMD_141b_MMIO_HIGH_MMIOLIMIT_SHIFT)
768fa564ad9SChristian König & AMD_141b_MMIO_HIGH_MMIOLIMIT_MASK);
769fa564ad9SChristian König
770fa564ad9SChristian König pci_write_config_dword(dev, AMD_141b_MMIO_HIGH(i), high);
771fa564ad9SChristian König pci_write_config_dword(dev, AMD_141b_MMIO_LIMIT(i), limit);
772fa564ad9SChristian König pci_write_config_dword(dev, AMD_141b_MMIO_BASE(i), base);
773fa564ad9SChristian König }
774a19e2696SChristian König DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AMD, 0x1401, pci_amd_enable_64bit_bar);
775a19e2696SChristian König DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AMD, 0x141b, pci_amd_enable_64bit_bar);
776a19e2696SChristian König DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AMD, 0x1571, pci_amd_enable_64bit_bar);
777a19e2696SChristian König DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AMD, 0x15b1, pci_amd_enable_64bit_bar);
778a19e2696SChristian König DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AMD, 0x1601, pci_amd_enable_64bit_bar);
779838cda36S=?UTF-8?q?Christian=20K=C3=B6nig?= DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_AMD, 0x1401, pci_amd_enable_64bit_bar);
780838cda36S=?UTF-8?q?Christian=20K=C3=B6nig?= DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_AMD, 0x141b, pci_amd_enable_64bit_bar);
781838cda36S=?UTF-8?q?Christian=20K=C3=B6nig?= DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_AMD, 0x1571, pci_amd_enable_64bit_bar);
782838cda36S=?UTF-8?q?Christian=20K=C3=B6nig?= DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_AMD, 0x15b1, pci_amd_enable_64bit_bar);
783838cda36S=?UTF-8?q?Christian=20K=C3=B6nig?= DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_AMD, 0x1601, pci_amd_enable_64bit_bar);
784fa564ad9SChristian König
785cacf994aSMikel Rychliski #define RS690_LOWER_TOP_OF_DRAM2 0x30
786cacf994aSMikel Rychliski #define RS690_LOWER_TOP_OF_DRAM2_VALID 0x1
787cacf994aSMikel Rychliski #define RS690_UPPER_TOP_OF_DRAM2 0x31
788cacf994aSMikel Rychliski #define RS690_HTIU_NB_INDEX 0xA8
789cacf994aSMikel Rychliski #define RS690_HTIU_NB_INDEX_WR_ENABLE 0x100
790cacf994aSMikel Rychliski #define RS690_HTIU_NB_DATA 0xAC
791cacf994aSMikel Rychliski
792cacf994aSMikel Rychliski /*
793cacf994aSMikel Rychliski * Some BIOS implementations support RAM above 4GB, but do not configure the
794cacf994aSMikel Rychliski * PCI host to respond to bus master accesses for these addresses. These
795cacf994aSMikel Rychliski * implementations set the TOP_OF_DRAM_SLOT1 register correctly, so PCI DMA
796cacf994aSMikel Rychliski * works as expected for addresses below 4GB.
797cacf994aSMikel Rychliski *
798cacf994aSMikel Rychliski * Reference: "AMD RS690 ASIC Family Register Reference Guide" (pg. 2-57)
799cacf994aSMikel Rychliski * https://www.amd.com/system/files/TechDocs/43372_rs690_rrg_3.00o.pdf
800cacf994aSMikel Rychliski */
rs690_fix_64bit_dma(struct pci_dev * pdev)801cacf994aSMikel Rychliski static void rs690_fix_64bit_dma(struct pci_dev *pdev)
802cacf994aSMikel Rychliski {
803cacf994aSMikel Rychliski u32 val = 0;
804cacf994aSMikel Rychliski phys_addr_t top_of_dram = __pa(high_memory - 1) + 1;
805cacf994aSMikel Rychliski
806cacf994aSMikel Rychliski if (top_of_dram <= (1ULL << 32))
807cacf994aSMikel Rychliski return;
808cacf994aSMikel Rychliski
809cacf994aSMikel Rychliski pci_write_config_dword(pdev, RS690_HTIU_NB_INDEX,
810cacf994aSMikel Rychliski RS690_LOWER_TOP_OF_DRAM2);
811cacf994aSMikel Rychliski pci_read_config_dword(pdev, RS690_HTIU_NB_DATA, &val);
812cacf994aSMikel Rychliski
813cacf994aSMikel Rychliski if (val)
814cacf994aSMikel Rychliski return;
815cacf994aSMikel Rychliski
816cacf994aSMikel Rychliski pci_info(pdev, "Adjusting top of DRAM to %pa for 64-bit DMA support\n", &top_of_dram);
817cacf994aSMikel Rychliski
818cacf994aSMikel Rychliski pci_write_config_dword(pdev, RS690_HTIU_NB_INDEX,
819cacf994aSMikel Rychliski RS690_UPPER_TOP_OF_DRAM2 | RS690_HTIU_NB_INDEX_WR_ENABLE);
820cacf994aSMikel Rychliski pci_write_config_dword(pdev, RS690_HTIU_NB_DATA, top_of_dram >> 32);
821cacf994aSMikel Rychliski
822cacf994aSMikel Rychliski pci_write_config_dword(pdev, RS690_HTIU_NB_INDEX,
823cacf994aSMikel Rychliski RS690_LOWER_TOP_OF_DRAM2 | RS690_HTIU_NB_INDEX_WR_ENABLE);
824cacf994aSMikel Rychliski pci_write_config_dword(pdev, RS690_HTIU_NB_DATA,
825cacf994aSMikel Rychliski top_of_dram | RS690_LOWER_TOP_OF_DRAM2_VALID);
826cacf994aSMikel Rychliski }
827cacf994aSMikel Rychliski DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_ATI, 0x7910, rs690_fix_64bit_dma);
828cacf994aSMikel Rychliski
829fa564ad9SChristian König #endif
830f195fc1eSBasavaraj Natikar
831f195fc1eSBasavaraj Natikar #ifdef CONFIG_AMD_NB
832f195fc1eSBasavaraj Natikar
833f195fc1eSBasavaraj Natikar #define AMD_15B8_RCC_DEV2_EPF0_STRAP2 0x10136008
834f195fc1eSBasavaraj Natikar #define AMD_15B8_RCC_DEV2_EPF0_STRAP2_NO_SOFT_RESET_DEV2_F0_MASK 0x00000080L
835f195fc1eSBasavaraj Natikar
quirk_clear_strap_no_soft_reset_dev2_f0(struct pci_dev * dev)836f195fc1eSBasavaraj Natikar static void quirk_clear_strap_no_soft_reset_dev2_f0(struct pci_dev *dev)
837f195fc1eSBasavaraj Natikar {
838f195fc1eSBasavaraj Natikar u32 data;
839f195fc1eSBasavaraj Natikar
840f195fc1eSBasavaraj Natikar if (!amd_smn_read(0, AMD_15B8_RCC_DEV2_EPF0_STRAP2, &data)) {
841f195fc1eSBasavaraj Natikar data &= ~AMD_15B8_RCC_DEV2_EPF0_STRAP2_NO_SOFT_RESET_DEV2_F0_MASK;
842f195fc1eSBasavaraj Natikar if (amd_smn_write(0, AMD_15B8_RCC_DEV2_EPF0_STRAP2, data))
843f195fc1eSBasavaraj Natikar pci_err(dev, "Failed to write data 0x%x\n", data);
844f195fc1eSBasavaraj Natikar } else {
845f195fc1eSBasavaraj Natikar pci_err(dev, "Failed to read data\n");
846f195fc1eSBasavaraj Natikar }
847f195fc1eSBasavaraj Natikar }
848f195fc1eSBasavaraj Natikar DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AMD, 0x15b8, quirk_clear_strap_no_soft_reset_dev2_f0);
849f195fc1eSBasavaraj Natikar #endif
85034b62f18SLinus Torvalds
851606012ddSRon Lee /*
852606012ddSRon Lee * When returning from D3cold to D0, firmware on some Google Coral and Reef
853606012ddSRon Lee * family Chromebooks with Intel Apollo Lake SoC clobbers the headers of
854606012ddSRon Lee * both the L1 PM Substates capability and the previous capability for the
855606012ddSRon Lee * "Celeron N3350/Pentium N4200/Atom E3900 Series PCI Express Port B #1".
856606012ddSRon Lee *
857606012ddSRon Lee * Save those values at enumeration-time and restore them at resume.
858606012ddSRon Lee */
859606012ddSRon Lee
860606012ddSRon Lee static u16 prev_cap, l1ss_cap;
861606012ddSRon Lee static u32 prev_header, l1ss_header;
862606012ddSRon Lee
chromeos_save_apl_pci_l1ss_capability(struct pci_dev * dev)863606012ddSRon Lee static void chromeos_save_apl_pci_l1ss_capability(struct pci_dev *dev)
864606012ddSRon Lee {
865606012ddSRon Lee int pos = PCI_CFG_SPACE_SIZE, prev = 0;
866606012ddSRon Lee u32 header, pheader = 0;
867606012ddSRon Lee
868606012ddSRon Lee while (pos) {
869606012ddSRon Lee pci_read_config_dword(dev, pos, &header);
870606012ddSRon Lee if (PCI_EXT_CAP_ID(header) == PCI_EXT_CAP_ID_L1SS) {
871606012ddSRon Lee prev_cap = prev;
872606012ddSRon Lee prev_header = pheader;
873606012ddSRon Lee l1ss_cap = pos;
874606012ddSRon Lee l1ss_header = header;
875606012ddSRon Lee return;
876606012ddSRon Lee }
877606012ddSRon Lee
878606012ddSRon Lee prev = pos;
879606012ddSRon Lee pheader = header;
880606012ddSRon Lee pos = PCI_EXT_CAP_NEXT(header);
881606012ddSRon Lee }
882606012ddSRon Lee }
883606012ddSRon Lee
chromeos_fixup_apl_pci_l1ss_capability(struct pci_dev * dev)884606012ddSRon Lee static void chromeos_fixup_apl_pci_l1ss_capability(struct pci_dev *dev)
885606012ddSRon Lee {
886606012ddSRon Lee u32 header;
887606012ddSRon Lee
888606012ddSRon Lee if (!prev_cap || !prev_header || !l1ss_cap || !l1ss_header)
889606012ddSRon Lee return;
890606012ddSRon Lee
891606012ddSRon Lee /* Fixup the header of L1SS Capability if missing */
892606012ddSRon Lee pci_read_config_dword(dev, l1ss_cap, &header);
893606012ddSRon Lee if (header != l1ss_header) {
894606012ddSRon Lee pci_write_config_dword(dev, l1ss_cap, l1ss_header);
895606012ddSRon Lee pci_info(dev, "restore L1SS Capability header (was %#010x now %#010x)\n",
896606012ddSRon Lee header, l1ss_header);
897606012ddSRon Lee }
898606012ddSRon Lee
899606012ddSRon Lee /* Fixup the link to L1SS Capability if missing */
900606012ddSRon Lee pci_read_config_dword(dev, prev_cap, &header);
901606012ddSRon Lee if (header != prev_header) {
902606012ddSRon Lee pci_write_config_dword(dev, prev_cap, prev_header);
903606012ddSRon Lee pci_info(dev, "restore previous Capability header (was %#010x now %#010x)\n",
904606012ddSRon Lee header, prev_header);
905606012ddSRon Lee }
906606012ddSRon Lee }
907606012ddSRon Lee DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x5ad6, chromeos_save_apl_pci_l1ss_capability);
908606012ddSRon Lee DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_INTEL, 0x5ad6, chromeos_fixup_apl_pci_l1ss_capability);
9093f6154cbSMario Limonciello
91084661129SDaniel Drake /*
91184661129SDaniel Drake * Disable D3cold on Asus B1400 PCI-NVMe bridge
91284661129SDaniel Drake *
91384661129SDaniel Drake * On this platform with VMD off, the NVMe device cannot successfully power
91484661129SDaniel Drake * back on from D3cold. This appears to be an untested transition by the
91584661129SDaniel Drake * vendor: Windows leaves the NVMe and parent bridge in D0 during suspend.
91684661129SDaniel Drake *
91784661129SDaniel Drake * We disable D3cold on the parent bridge for simplicity, and the fact that
91884661129SDaniel Drake * both parent bridge and NVMe device share the same power resource.
91984661129SDaniel Drake *
92084661129SDaniel Drake * This is only needed on BIOS versions before 308; the newer versions flip
92184661129SDaniel Drake * StorageD3Enable from 1 to 0.
92284661129SDaniel Drake */
92384661129SDaniel Drake static const struct dmi_system_id asus_nvme_broken_d3cold_table[] = {
92484661129SDaniel Drake {
92584661129SDaniel Drake .matches = {
92684661129SDaniel Drake DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
92784661129SDaniel Drake DMI_MATCH(DMI_BIOS_VERSION, "B1400CEAE.304"),
92884661129SDaniel Drake },
92984661129SDaniel Drake },
93084661129SDaniel Drake {
93184661129SDaniel Drake .matches = {
93284661129SDaniel Drake DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
93384661129SDaniel Drake DMI_MATCH(DMI_BIOS_VERSION, "B1400CEAE.305"),
93484661129SDaniel Drake },
93584661129SDaniel Drake },
93684661129SDaniel Drake {
93784661129SDaniel Drake .matches = {
93884661129SDaniel Drake DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
93984661129SDaniel Drake DMI_MATCH(DMI_BIOS_VERSION, "B1400CEAE.306"),
94084661129SDaniel Drake },
94184661129SDaniel Drake },
94284661129SDaniel Drake {
94384661129SDaniel Drake .matches = {
94484661129SDaniel Drake DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
94584661129SDaniel Drake DMI_MATCH(DMI_BIOS_VERSION, "B1400CEAE.307"),
94684661129SDaniel Drake },
94784661129SDaniel Drake },
94884661129SDaniel Drake {}
94984661129SDaniel Drake };
95084661129SDaniel Drake
asus_disable_nvme_d3cold(struct pci_dev * pdev)95184661129SDaniel Drake static void asus_disable_nvme_d3cold(struct pci_dev *pdev)
95284661129SDaniel Drake {
95384661129SDaniel Drake if (dmi_check_system(asus_nvme_broken_d3cold_table) > 0)
95484661129SDaniel Drake pci_d3cold_disable(pdev);
95584661129SDaniel Drake }
95684661129SDaniel Drake DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x9a09, asus_disable_nvme_d3cold);
95784661129SDaniel Drake
9583f6154cbSMario Limonciello #ifdef CONFIG_SUSPEND
9593f6154cbSMario Limonciello /*
9603f6154cbSMario Limonciello * Root Ports on some AMD SoCs advertise PME_Support for D3hot and D3cold, but
9613f6154cbSMario Limonciello * if the SoC is put into a hardware sleep state by the amd-pmc driver, the
9623f6154cbSMario Limonciello * Root Ports don't generate wakeup interrupts for USB devices.
9633f6154cbSMario Limonciello *
9643f6154cbSMario Limonciello * When suspending, remove D3hot and D3cold from the PME_Support advertised
9653f6154cbSMario Limonciello * by the Root Port so we don't use those states if we're expecting wakeup
9663f6154cbSMario Limonciello * interrupts. Restore the advertised PME_Support when resuming.
9673f6154cbSMario Limonciello */
amd_rp_pme_suspend(struct pci_dev * dev)9683f6154cbSMario Limonciello static void amd_rp_pme_suspend(struct pci_dev *dev)
9693f6154cbSMario Limonciello {
9703f6154cbSMario Limonciello struct pci_dev *rp;
9713f6154cbSMario Limonciello
9723f6154cbSMario Limonciello /*
9733f6154cbSMario Limonciello * PM_SUSPEND_ON means we're doing runtime suspend, which means
9743f6154cbSMario Limonciello * amd-pmc will not be involved so PMEs during D3 work as advertised.
9753f6154cbSMario Limonciello *
9763f6154cbSMario Limonciello * The PMEs *do* work if amd-pmc doesn't put the SoC in the hardware
9773f6154cbSMario Limonciello * sleep state, but we assume amd-pmc is always present.
9783f6154cbSMario Limonciello */
9793f6154cbSMario Limonciello if (pm_suspend_target_state == PM_SUSPEND_ON)
9803f6154cbSMario Limonciello return;
9813f6154cbSMario Limonciello
9823f6154cbSMario Limonciello rp = pcie_find_root_port(dev);
983e39cc0c3SSamasth Norway Ananda if (!rp || !rp->pm_cap)
9843f6154cbSMario Limonciello return;
9853f6154cbSMario Limonciello
9863f6154cbSMario Limonciello rp->pme_support &= ~((PCI_PM_CAP_PME_D3hot|PCI_PM_CAP_PME_D3cold) >>
9873f6154cbSMario Limonciello PCI_PM_CAP_PME_SHIFT);
9883f6154cbSMario Limonciello dev_info_once(&rp->dev, "quirk: disabling D3cold for suspend\n");
9893f6154cbSMario Limonciello }
9903f6154cbSMario Limonciello
amd_rp_pme_resume(struct pci_dev * dev)9913f6154cbSMario Limonciello static void amd_rp_pme_resume(struct pci_dev *dev)
9923f6154cbSMario Limonciello {
9933f6154cbSMario Limonciello struct pci_dev *rp;
9943f6154cbSMario Limonciello u16 pmc;
9953f6154cbSMario Limonciello
9963f6154cbSMario Limonciello rp = pcie_find_root_port(dev);
997e39cc0c3SSamasth Norway Ananda if (!rp || !rp->pm_cap)
9983f6154cbSMario Limonciello return;
9993f6154cbSMario Limonciello
10003f6154cbSMario Limonciello pci_read_config_word(rp, rp->pm_cap + PCI_PM_PMC, &pmc);
10013f6154cbSMario Limonciello rp->pme_support = FIELD_GET(PCI_PM_CAP_PME_MASK, pmc);
10023f6154cbSMario Limonciello }
10033f6154cbSMario Limonciello /* Rembrandt (yellow_carp) */
10043f6154cbSMario Limonciello DECLARE_PCI_FIXUP_SUSPEND(PCI_VENDOR_ID_AMD, 0x162e, amd_rp_pme_suspend);
10053f6154cbSMario Limonciello DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_AMD, 0x162e, amd_rp_pme_resume);
10063f6154cbSMario Limonciello DECLARE_PCI_FIXUP_SUSPEND(PCI_VENDOR_ID_AMD, 0x162f, amd_rp_pme_suspend);
10073f6154cbSMario Limonciello DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_AMD, 0x162f, amd_rp_pme_resume);
10083f6154cbSMario Limonciello /* Phoenix (pink_sardine) */
10093f6154cbSMario Limonciello DECLARE_PCI_FIXUP_SUSPEND(PCI_VENDOR_ID_AMD, 0x1668, amd_rp_pme_suspend);
10103f6154cbSMario Limonciello DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_AMD, 0x1668, amd_rp_pme_resume);
10113f6154cbSMario Limonciello DECLARE_PCI_FIXUP_SUSPEND(PCI_VENDOR_ID_AMD, 0x1669, amd_rp_pme_suspend);
10123f6154cbSMario Limonciello DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_AMD, 0x1669, amd_rp_pme_resume);
1013*8852e056SWerner Sembach
1014*8852e056SWerner Sembach /*
1015*8852e056SWerner Sembach * Putting PCIe root ports on Ryzen SoCs with USB4 controllers into D3hot
1016*8852e056SWerner Sembach * may cause problems when the system attempts wake up from s2idle.
1017*8852e056SWerner Sembach *
1018*8852e056SWerner Sembach * On the TUXEDO Sirius 16 Gen 1 with a specific old BIOS this manifests as
1019*8852e056SWerner Sembach * a system hang.
1020*8852e056SWerner Sembach */
1021*8852e056SWerner Sembach static const struct dmi_system_id quirk_tuxeo_rp_d3_dmi_table[] = {
1022*8852e056SWerner Sembach {
1023*8852e056SWerner Sembach .matches = {
1024*8852e056SWerner Sembach DMI_EXACT_MATCH(DMI_SYS_VENDOR, "TUXEDO"),
1025*8852e056SWerner Sembach DMI_EXACT_MATCH(DMI_BOARD_NAME, "APX958"),
1026*8852e056SWerner Sembach DMI_EXACT_MATCH(DMI_BIOS_VERSION, "V1.00A00_20240108"),
1027*8852e056SWerner Sembach },
1028*8852e056SWerner Sembach },
1029*8852e056SWerner Sembach {}
1030*8852e056SWerner Sembach };
1031*8852e056SWerner Sembach
quirk_tuxeo_rp_d3(struct pci_dev * pdev)1032*8852e056SWerner Sembach static void quirk_tuxeo_rp_d3(struct pci_dev *pdev)
1033*8852e056SWerner Sembach {
1034*8852e056SWerner Sembach struct pci_dev *root_pdev;
1035*8852e056SWerner Sembach
1036*8852e056SWerner Sembach if (dmi_check_system(quirk_tuxeo_rp_d3_dmi_table)) {
1037*8852e056SWerner Sembach root_pdev = pcie_find_root_port(pdev);
1038*8852e056SWerner Sembach if (root_pdev)
1039*8852e056SWerner Sembach root_pdev->dev_flags |= PCI_DEV_FLAGS_NO_D3;
1040*8852e056SWerner Sembach }
1041*8852e056SWerner Sembach }
1042*8852e056SWerner Sembach DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AMD, 0x1502, quirk_tuxeo_rp_d3);
10433f6154cbSMario Limonciello #endif /* CONFIG_SUSPEND */
1044