blob: 6c4f01540833f3aa2c5e8e8e9bf6ba6097d612b3 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Andi Kleendfa46982006-09-26 10:52:30 +02002/* Various workarounds for chipset bugs.
3 This code runs very early and can't use the regular PCI subsystem
4 The entries are keyed to PCI bridges which usually identify chipsets
5 uniquely.
6 This is only for whole classes of chipsets with specific problems which
7 need early invasive action (e.g. before the timers are initialized).
8 Most PCI device specific workarounds can be done later and should be
9 in standard PCI quirks
10 Mainboard specific bugs should be handled by DMI entries.
11 CPU specific bugs in setup.c */
12
13#include <linux/pci.h>
14#include <linux/acpi.h>
Lukas Wunnerabb2baf2016-06-12 12:31:53 +020015#include <linux/delay.h>
Andi Kleendfa46982006-09-26 10:52:30 +020016#include <linux/pci_ids.h>
Lukas Wunnerabb2baf2016-06-12 12:31:53 +020017#include <linux/bcma/bcma.h>
18#include <linux/bcma/bcma_regs.h>
Lukas Wunner630b3af2017-08-01 14:10:41 +020019#include <linux/platform_data/x86/apple.h>
Jesse Barnes814c5f12013-07-26 13:32:52 -070020#include <drm/i915_drm.h>
Andi Kleendfa46982006-09-26 10:52:30 +020021#include <asm/pci-direct.h>
Andi Kleendfa46982006-09-26 10:52:30 +020022#include <asm/dma.h>
Andi Kleen54ef3402007-10-19 20:35:03 +020023#include <asm/io_apic.h>
24#include <asm/apic.h>
Feng Tang62187912014-04-24 16:18:18 +080025#include <asm/hpet.h>
FUJITA Tomonori46a7fa22008-07-11 10:23:42 +090026#include <asm/iommu.h>
Joerg Roedel1d9b16d2008-11-27 18:39:15 +010027#include <asm/gart.h>
Neil Horman03bbcb22013-04-16 16:38:32 -040028#include <asm/irq_remapping.h>
Lukas Wunnerabb2baf2016-06-12 12:31:53 +020029#include <asm/early_ioremap.h>
30
Neil Hormanc6b48322008-01-30 13:31:25 +010031static void __init fix_hypertransport_config(int num, int slot, int func)
32{
33 u32 htcfg;
34 /*
35 * we found a hypertransport bus
36 * make sure that we are broadcasting
37 * interrupts to all cpus on the ht bus
38 * if we're using extended apic ids
39 */
40 htcfg = read_pci_config(num, slot, func, 0x68);
41 if (htcfg & (1 << 18)) {
Neil Horman7bcbc782008-01-30 13:31:26 +010042 printk(KERN_INFO "Detected use of extended apic ids "
43 "on hypertransport bus\n");
Neil Hormanc6b48322008-01-30 13:31:25 +010044 if ((htcfg & (1 << 17)) == 0) {
Neil Horman7bcbc782008-01-30 13:31:26 +010045 printk(KERN_INFO "Enabling hypertransport extended "
46 "apic interrupt broadcast\n");
47 printk(KERN_INFO "Note this is a bios bug, "
48 "please contact your hw vendor\n");
Neil Hormanc6b48322008-01-30 13:31:25 +010049 htcfg |= (1 << 17);
50 write_pci_config(num, slot, func, 0x68, htcfg);
51 }
52 }
53
54
55}
56
57static void __init via_bugs(int num, int slot, int func)
Andi Kleendfa46982006-09-26 10:52:30 +020058{
Joerg Roedel966396d2007-10-24 12:49:48 +020059#ifdef CONFIG_GART_IOMMU
Yinghai Luc987d122008-06-24 22:14:09 -070060 if ((max_pfn > MAX_DMA32_PFN || force_iommu) &&
Joerg Roedel0440d4c2007-10-24 12:49:50 +020061 !gart_iommu_aperture_allowed) {
Andi Kleendfa46982006-09-26 10:52:30 +020062 printk(KERN_INFO
Andi Kleen54ef3402007-10-19 20:35:03 +020063 "Looks like a VIA chipset. Disabling IOMMU."
64 " Override with iommu=allowed\n");
Joerg Roedel0440d4c2007-10-24 12:49:50 +020065 gart_iommu_aperture_disabled = 1;
Andi Kleendfa46982006-09-26 10:52:30 +020066 }
67#endif
68}
69
70#ifdef CONFIG_ACPI
Jeff Garzik03d0d202007-10-27 20:57:43 +020071#ifdef CONFIG_X86_IO_APIC
Andi Kleendfa46982006-09-26 10:52:30 +020072
Alexey Starikovskiy15a58ed2007-02-02 19:48:22 +030073static int __init nvidia_hpet_check(struct acpi_table_header *header)
Andi Kleendfa46982006-09-26 10:52:30 +020074{
Andi Kleendfa46982006-09-26 10:52:30 +020075 return 0;
76}
Jeff Garzik03d0d202007-10-27 20:57:43 +020077#endif /* CONFIG_X86_IO_APIC */
78#endif /* CONFIG_ACPI */
Andi Kleendfa46982006-09-26 10:52:30 +020079
Neil Hormanc6b48322008-01-30 13:31:25 +010080static void __init nvidia_bugs(int num, int slot, int func)
Andi Kleendfa46982006-09-26 10:52:30 +020081{
82#ifdef CONFIG_ACPI
Andi Kleen54ef3402007-10-19 20:35:03 +020083#ifdef CONFIG_X86_IO_APIC
Andi Kleendfa46982006-09-26 10:52:30 +020084 /*
Lukas Wunner447d29d2016-06-12 12:31:53 +020085 * Only applies to Nvidia root ports (bus 0) and not to
86 * Nvidia graphics cards with PCI ports on secondary buses.
87 */
88 if (num)
89 return;
90
91 /*
Andi Kleendfa46982006-09-26 10:52:30 +020092 * All timer overrides on Nvidia are
93 * wrong unless HPET is enabled.
Andi Kleenfa18f472006-11-14 16:57:46 +010094 * Unfortunately that's not true on many Asus boards.
95 * We don't know yet how to detect this automatically, but
96 * at least allow a command line override.
Andi Kleendfa46982006-09-26 10:52:30 +020097 */
Andi Kleenfa18f472006-11-14 16:57:46 +010098 if (acpi_use_timer_override)
99 return;
100
Len Brownfe699332007-03-08 18:28:32 -0500101 if (acpi_table_parse(ACPI_SIG_HPET, nvidia_hpet_check)) {
Andi Kleendfa46982006-09-26 10:52:30 +0200102 acpi_skip_timer_override = 1;
103 printk(KERN_INFO "Nvidia board "
104 "detected. Ignoring ACPI "
105 "timer override.\n");
Andi Kleenfa18f472006-11-14 16:57:46 +0100106 printk(KERN_INFO "If you got timer trouble "
107 "try acpi_use_timer_override\n");
Andi Kleendfa46982006-09-26 10:52:30 +0200108 }
109#endif
Andi Kleen54ef3402007-10-19 20:35:03 +0200110#endif
Andi Kleendfa46982006-09-26 10:52:30 +0200111 /* RED-PEN skip them on mptables too? */
112
113}
114
Andreas Herrmann26adcfb2008-10-14 21:01:15 +0200115#if defined(CONFIG_ACPI) && defined(CONFIG_X86_IO_APIC)
116static u32 __init ati_ixp4x0_rev(int num, int slot, int func)
Andreas Herrmann33fb0e42008-10-07 00:11:22 +0200117{
118 u32 d;
119 u8 b;
120
121 b = read_pci_config_byte(num, slot, func, 0xac);
122 b &= ~(1<<5);
123 write_pci_config_byte(num, slot, func, 0xac, b);
124
125 d = read_pci_config(num, slot, func, 0x70);
126 d |= 1<<8;
127 write_pci_config(num, slot, func, 0x70, d);
128
129 d = read_pci_config(num, slot, func, 0x8);
130 d &= 0xff;
131 return d;
132}
133
134static void __init ati_bugs(int num, int slot, int func)
135{
Andreas Herrmann33fb0e42008-10-07 00:11:22 +0200136 u32 d;
137 u8 b;
138
139 if (acpi_use_timer_override)
140 return;
141
142 d = ati_ixp4x0_rev(num, slot, func);
143 if (d < 0x82)
144 acpi_skip_timer_override = 1;
145 else {
146 /* check for IRQ0 interrupt swap */
147 outb(0x72, 0xcd6); b = inb(0xcd7);
148 if (!(b & 0x2))
149 acpi_skip_timer_override = 1;
150 }
151
152 if (acpi_skip_timer_override) {
153 printk(KERN_INFO "SB4X0 revision 0x%x\n", d);
154 printk(KERN_INFO "Ignoring ACPI timer override.\n");
155 printk(KERN_INFO "If you got timer trouble "
156 "try acpi_use_timer_override\n");
157 }
Andreas Herrmann33fb0e42008-10-07 00:11:22 +0200158}
159
Andreas Herrmann26adcfb2008-10-14 21:01:15 +0200160static u32 __init ati_sbx00_rev(int num, int slot, int func)
161{
Andreas Herrmann7f74f8f2011-02-24 15:53:46 +0100162 u32 d;
Andreas Herrmann26adcfb2008-10-14 21:01:15 +0200163
Andreas Herrmann26adcfb2008-10-14 21:01:15 +0200164 d = read_pci_config(num, slot, func, 0x8);
165 d &= 0xff;
Andreas Herrmann26adcfb2008-10-14 21:01:15 +0200166
167 return d;
168}
169
170static void __init ati_bugs_contd(int num, int slot, int func)
171{
172 u32 d, rev;
173
Andreas Herrmann7f74f8f2011-02-24 15:53:46 +0100174 rev = ati_sbx00_rev(num, slot, func);
175 if (rev >= 0x40)
176 acpi_fix_pin2_polarity = 1;
177
Andreas Herrmann1d3e09a2011-03-15 15:31:37 +0100178 /*
179 * SB600: revisions 0x11, 0x12, 0x13, 0x14, ...
180 * SB700: revisions 0x39, 0x3a, ...
181 * SB800: revisions 0x40, 0x41, ...
182 */
183 if (rev >= 0x39)
Andreas Herrmann26adcfb2008-10-14 21:01:15 +0200184 return;
185
Andreas Herrmann7f74f8f2011-02-24 15:53:46 +0100186 if (acpi_use_timer_override)
Andreas Herrmann26adcfb2008-10-14 21:01:15 +0200187 return;
188
189 /* check for IRQ0 interrupt swap */
190 d = read_pci_config(num, slot, func, 0x64);
191 if (!(d & (1<<14)))
192 acpi_skip_timer_override = 1;
193
194 if (acpi_skip_timer_override) {
195 printk(KERN_INFO "SB600 revision 0x%x\n", rev);
196 printk(KERN_INFO "Ignoring ACPI timer override.\n");
197 printk(KERN_INFO "If you got timer trouble "
198 "try acpi_use_timer_override\n");
199 }
200}
201#else
202static void __init ati_bugs(int num, int slot, int func)
203{
204}
205
206static void __init ati_bugs_contd(int num, int slot, int func)
207{
208}
209#endif
210
Neil Horman03bbcb22013-04-16 16:38:32 -0400211static void __init intel_remapping_check(int num, int slot, int func)
212{
213 u8 revision;
Neil Horman803075d2013-07-17 07:13:59 -0400214 u16 device;
Neil Horman03bbcb22013-04-16 16:38:32 -0400215
Neil Horman803075d2013-07-17 07:13:59 -0400216 device = read_pci_config_16(num, slot, func, PCI_DEVICE_ID);
Neil Horman03bbcb22013-04-16 16:38:32 -0400217 revision = read_pci_config_byte(num, slot, func, PCI_REVISION_ID);
218
219 /*
Neil Horman6f8a1b32014-03-12 14:44:33 -0400220 * Revision <= 13 of all triggering devices id in this quirk
221 * have a problem draining interrupts when irq remapping is
222 * enabled, and should be flagged as broken. Additionally
223 * revision 0x22 of device id 0x3405 has this problem.
Neil Horman03bbcb22013-04-16 16:38:32 -0400224 */
Neil Horman6f8a1b32014-03-12 14:44:33 -0400225 if (revision <= 0x13)
Neil Horman03bbcb22013-04-16 16:38:32 -0400226 set_irq_remapping_broken();
Neil Horman6f8a1b32014-03-12 14:44:33 -0400227 else if (device == 0x3405 && revision == 0x22)
Neil Horman803075d2013-07-17 07:13:59 -0400228 set_irq_remapping_broken();
Neil Horman03bbcb22013-04-16 16:38:32 -0400229}
230
Jesse Barnes814c5f12013-07-26 13:32:52 -0700231/*
232 * Systems with Intel graphics controllers set aside memory exclusively
233 * for gfx driver use. This memory is not marked in the E820 as reserved
234 * or as RAM, and so is subject to overlap from E820 manipulation later
235 * in the boot process. On some systems, MMIO space is allocated on top,
236 * despite the efforts of the "RAM buffer" approach, which simply rounds
237 * memory boundaries up to 64M to try to catch space that may decode
238 * as RAM and so is not suitable for MMIO.
Jesse Barnes814c5f12013-07-26 13:32:52 -0700239 */
Jesse Barnes814c5f12013-07-26 13:32:52 -0700240
Ville Syrjälä86e58762014-04-13 12:45:03 +0300241#define KB(x) ((x) * 1024UL)
Jesse Barnes814c5f12013-07-26 13:32:52 -0700242#define MB(x) (KB (KB (x)))
Jesse Barnes814c5f12013-07-26 13:32:52 -0700243
Joonas Lahtinen6f9fa992017-12-11 15:18:14 +0000244static resource_size_t __init i830_tseg_size(void)
Ville Syrjäläa4dff762014-02-05 21:28:59 +0200245{
Joonas Lahtinenc0dd3462016-04-22 13:29:26 +0300246 u8 esmramc = read_pci_config_byte(0, 0, 0, I830_ESMRAMC);
Ville Syrjäläa4dff762014-02-05 21:28:59 +0200247
Joonas Lahtinenc0dd3462016-04-22 13:29:26 +0300248 if (!(esmramc & TSEG_ENABLE))
Ville Syrjäläa4dff762014-02-05 21:28:59 +0200249 return 0;
250
Joonas Lahtinenc0dd3462016-04-22 13:29:26 +0300251 if (esmramc & I830_TSEG_SIZE_1M)
Ville Syrjäläa4dff762014-02-05 21:28:59 +0200252 return MB(1);
253 else
254 return KB(512);
255}
256
Joonas Lahtinen6f9fa992017-12-11 15:18:14 +0000257static resource_size_t __init i845_tseg_size(void)
Ville Syrjäläa4dff762014-02-05 21:28:59 +0200258{
Joonas Lahtinenc0dd3462016-04-22 13:29:26 +0300259 u8 esmramc = read_pci_config_byte(0, 0, 0, I845_ESMRAMC);
260 u8 tseg_size = esmramc & I845_TSEG_SIZE_MASK;
Ville Syrjäläa4dff762014-02-05 21:28:59 +0200261
Joonas Lahtinenc0dd3462016-04-22 13:29:26 +0300262 if (!(esmramc & TSEG_ENABLE))
Ville Syrjäläa4dff762014-02-05 21:28:59 +0200263 return 0;
264
Joonas Lahtinenc0dd3462016-04-22 13:29:26 +0300265 switch (tseg_size) {
266 case I845_TSEG_SIZE_512K: return KB(512);
267 case I845_TSEG_SIZE_1M: return MB(1);
Ville Syrjäläa4dff762014-02-05 21:28:59 +0200268 default:
Joonas Lahtinenc0dd3462016-04-22 13:29:26 +0300269 WARN(1, "Unknown ESMRAMC value: %x!\n", esmramc);
Ville Syrjäläa4dff762014-02-05 21:28:59 +0200270 }
Joonas Lahtinenc0dd3462016-04-22 13:29:26 +0300271 return 0;
Ville Syrjäläa4dff762014-02-05 21:28:59 +0200272}
273
Joonas Lahtinen6f9fa992017-12-11 15:18:14 +0000274static resource_size_t __init i85x_tseg_size(void)
Ville Syrjäläa4dff762014-02-05 21:28:59 +0200275{
Joonas Lahtinenc0dd3462016-04-22 13:29:26 +0300276 u8 esmramc = read_pci_config_byte(0, 0, 0, I85X_ESMRAMC);
Ville Syrjäläa4dff762014-02-05 21:28:59 +0200277
Joonas Lahtinenc0dd3462016-04-22 13:29:26 +0300278 if (!(esmramc & TSEG_ENABLE))
Ville Syrjäläa4dff762014-02-05 21:28:59 +0200279 return 0;
280
281 return MB(1);
282}
283
Joonas Lahtinen6f9fa992017-12-11 15:18:14 +0000284static resource_size_t __init i830_mem_size(void)
Ville Syrjäläa4dff762014-02-05 21:28:59 +0200285{
286 return read_pci_config_byte(0, 0, 0, I830_DRB3) * MB(32);
287}
288
Joonas Lahtinen6f9fa992017-12-11 15:18:14 +0000289static resource_size_t __init i85x_mem_size(void)
Ville Syrjäläa4dff762014-02-05 21:28:59 +0200290{
291 return read_pci_config_byte(0, 0, 1, I85X_DRB3) * MB(32);
292}
293
294/*
295 * On 830/845/85x the stolen memory base isn't available in any
296 * register. We need to calculate it as TOM-TSEG_SIZE-stolen_size.
297 */
Joonas Lahtinen6f9fa992017-12-11 15:18:14 +0000298static resource_size_t __init i830_stolen_base(int num, int slot, int func,
299 resource_size_t stolen_size)
Ville Syrjäläa4dff762014-02-05 21:28:59 +0200300{
Joonas Lahtinen6f9fa992017-12-11 15:18:14 +0000301 return i830_mem_size() - i830_tseg_size() - stolen_size;
Ville Syrjäläa4dff762014-02-05 21:28:59 +0200302}
303
Joonas Lahtinen6f9fa992017-12-11 15:18:14 +0000304static resource_size_t __init i845_stolen_base(int num, int slot, int func,
305 resource_size_t stolen_size)
Ville Syrjäläa4dff762014-02-05 21:28:59 +0200306{
Joonas Lahtinen6f9fa992017-12-11 15:18:14 +0000307 return i830_mem_size() - i845_tseg_size() - stolen_size;
Ville Syrjäläa4dff762014-02-05 21:28:59 +0200308}
309
Joonas Lahtinen6f9fa992017-12-11 15:18:14 +0000310static resource_size_t __init i85x_stolen_base(int num, int slot, int func,
311 resource_size_t stolen_size)
Ville Syrjäläa4dff762014-02-05 21:28:59 +0200312{
Joonas Lahtinen6f9fa992017-12-11 15:18:14 +0000313 return i85x_mem_size() - i85x_tseg_size() - stolen_size;
Ville Syrjäläa4dff762014-02-05 21:28:59 +0200314}
315
Joonas Lahtinen6f9fa992017-12-11 15:18:14 +0000316static resource_size_t __init i865_stolen_base(int num, int slot, int func,
317 resource_size_t stolen_size)
Ville Syrjäläa4dff762014-02-05 21:28:59 +0200318{
Ville Syrjäläd721b022016-08-08 13:58:39 +0300319 u16 toud = 0;
Joonas Lahtinenc0dd3462016-04-22 13:29:26 +0300320
Joonas Lahtinenc0dd3462016-04-22 13:29:26 +0300321 toud = read_pci_config_16(0, 0, 0, I865_TOUD);
322
Joonas Lahtinen6f9fa992017-12-11 15:18:14 +0000323 return toud * KB(64) + i845_tseg_size();
Joonas Lahtinenc0dd3462016-04-22 13:29:26 +0300324}
325
Joonas Lahtinen6f9fa992017-12-11 15:18:14 +0000326static resource_size_t __init gen3_stolen_base(int num, int slot, int func,
327 resource_size_t stolen_size)
Joonas Lahtinenc0dd3462016-04-22 13:29:26 +0300328{
329 u32 bsm;
330
331 /* Almost universally we can find the Graphics Base of Stolen Memory
332 * at register BSM (0x5c) in the igfx configuration space. On a few
333 * (desktop) machines this is also mirrored in the bridge device at
334 * different locations, or in the MCHBAR.
335 */
336 bsm = read_pci_config(num, slot, func, INTEL_BSM);
337
Joonas Lahtinen6f9fa992017-12-11 15:18:14 +0000338 return bsm & INTEL_BSM_MASK;
Ville Syrjäläa4dff762014-02-05 21:28:59 +0200339}
340
Paulo Zanonidb0c8d82018-05-04 13:32:51 -0700341static resource_size_t __init gen11_stolen_base(int num, int slot, int func,
342 resource_size_t stolen_size)
343{
344 u64 bsm;
345
346 bsm = read_pci_config(num, slot, func, INTEL_GEN11_BSM_DW0);
347 bsm &= INTEL_BSM_MASK;
348 bsm |= (u64)read_pci_config(num, slot, func, INTEL_GEN11_BSM_DW1) << 32;
349
350 return bsm;
351}
352
Joonas Lahtinen6f9fa992017-12-11 15:18:14 +0000353static resource_size_t __init i830_stolen_size(int num, int slot, int func)
Ville Syrjäläa4dff762014-02-05 21:28:59 +0200354{
Ville Syrjäläa4dff762014-02-05 21:28:59 +0200355 u16 gmch_ctrl;
Joonas Lahtinenc0dd3462016-04-22 13:29:26 +0300356 u16 gms;
Ville Syrjäläa4dff762014-02-05 21:28:59 +0200357
358 gmch_ctrl = read_pci_config_16(0, 0, 0, I830_GMCH_CTRL);
Joonas Lahtinenc0dd3462016-04-22 13:29:26 +0300359 gms = gmch_ctrl & I830_GMCH_GMS_MASK;
Ville Syrjäläa4dff762014-02-05 21:28:59 +0200360
Joonas Lahtinenc0dd3462016-04-22 13:29:26 +0300361 switch (gms) {
362 case I830_GMCH_GMS_STOLEN_512: return KB(512);
363 case I830_GMCH_GMS_STOLEN_1024: return MB(1);
364 case I830_GMCH_GMS_STOLEN_8192: return MB(8);
365 /* local memory isn't part of the normal address space */
366 case I830_GMCH_GMS_LOCAL: return 0;
Ville Syrjäläa4dff762014-02-05 21:28:59 +0200367 default:
Joonas Lahtinenc0dd3462016-04-22 13:29:26 +0300368 WARN(1, "Unknown GMCH_CTRL value: %x!\n", gmch_ctrl);
Ville Syrjäläa4dff762014-02-05 21:28:59 +0200369 }
370
Joonas Lahtinenc0dd3462016-04-22 13:29:26 +0300371 return 0;
Ville Syrjäläa4dff762014-02-05 21:28:59 +0200372}
373
Joonas Lahtinen6f9fa992017-12-11 15:18:14 +0000374static resource_size_t __init gen3_stolen_size(int num, int slot, int func)
Jesse Barnes814c5f12013-07-26 13:32:52 -0700375{
Jesse Barnes814c5f12013-07-26 13:32:52 -0700376 u16 gmch_ctrl;
Joonas Lahtinenc0dd3462016-04-22 13:29:26 +0300377 u16 gms;
Jesse Barnes814c5f12013-07-26 13:32:52 -0700378
379 gmch_ctrl = read_pci_config_16(0, 0, 0, I830_GMCH_CTRL);
Joonas Lahtinenc0dd3462016-04-22 13:29:26 +0300380 gms = gmch_ctrl & I855_GMCH_GMS_MASK;
Jesse Barnes814c5f12013-07-26 13:32:52 -0700381
Joonas Lahtinenc0dd3462016-04-22 13:29:26 +0300382 switch (gms) {
383 case I855_GMCH_GMS_STOLEN_1M: return MB(1);
384 case I855_GMCH_GMS_STOLEN_4M: return MB(4);
385 case I855_GMCH_GMS_STOLEN_8M: return MB(8);
386 case I855_GMCH_GMS_STOLEN_16M: return MB(16);
387 case I855_GMCH_GMS_STOLEN_32M: return MB(32);
388 case I915_GMCH_GMS_STOLEN_48M: return MB(48);
389 case I915_GMCH_GMS_STOLEN_64M: return MB(64);
390 case G33_GMCH_GMS_STOLEN_128M: return MB(128);
391 case G33_GMCH_GMS_STOLEN_256M: return MB(256);
392 case INTEL_GMCH_GMS_STOLEN_96M: return MB(96);
393 case INTEL_GMCH_GMS_STOLEN_160M:return MB(160);
394 case INTEL_GMCH_GMS_STOLEN_224M:return MB(224);
395 case INTEL_GMCH_GMS_STOLEN_352M:return MB(352);
Jesse Barnes814c5f12013-07-26 13:32:52 -0700396 default:
Joonas Lahtinenc0dd3462016-04-22 13:29:26 +0300397 WARN(1, "Unknown GMCH_CTRL value: %x!\n", gmch_ctrl);
Jesse Barnes814c5f12013-07-26 13:32:52 -0700398 }
399
Joonas Lahtinenc0dd3462016-04-22 13:29:26 +0300400 return 0;
Jesse Barnes814c5f12013-07-26 13:32:52 -0700401}
402
Joonas Lahtinen6f9fa992017-12-11 15:18:14 +0000403static resource_size_t __init gen6_stolen_size(int num, int slot, int func)
Jesse Barnes814c5f12013-07-26 13:32:52 -0700404{
405 u16 gmch_ctrl;
Joonas Lahtinenc0dd3462016-04-22 13:29:26 +0300406 u16 gms;
Jesse Barnes814c5f12013-07-26 13:32:52 -0700407
408 gmch_ctrl = read_pci_config_16(num, slot, func, SNB_GMCH_CTRL);
Joonas Lahtinenc0dd3462016-04-22 13:29:26 +0300409 gms = (gmch_ctrl >> SNB_GMCH_GMS_SHIFT) & SNB_GMCH_GMS_MASK;
Jesse Barnes814c5f12013-07-26 13:32:52 -0700410
Joonas Lahtinen6f9fa992017-12-11 15:18:14 +0000411 return gms * MB(32);
Jesse Barnes814c5f12013-07-26 13:32:52 -0700412}
413
Joonas Lahtinen6f9fa992017-12-11 15:18:14 +0000414static resource_size_t __init gen8_stolen_size(int num, int slot, int func)
Ben Widawsky9459d252013-11-03 16:53:55 -0800415{
416 u16 gmch_ctrl;
Joonas Lahtinenc0dd3462016-04-22 13:29:26 +0300417 u16 gms;
Ben Widawsky9459d252013-11-03 16:53:55 -0800418
419 gmch_ctrl = read_pci_config_16(num, slot, func, SNB_GMCH_CTRL);
Joonas Lahtinenc0dd3462016-04-22 13:29:26 +0300420 gms = (gmch_ctrl >> BDW_GMCH_GMS_SHIFT) & BDW_GMCH_GMS_MASK;
421
Joonas Lahtinen6f9fa992017-12-11 15:18:14 +0000422 return gms * MB(32);
Ben Widawsky9459d252013-11-03 16:53:55 -0800423}
424
Joonas Lahtinen6f9fa992017-12-11 15:18:14 +0000425static resource_size_t __init chv_stolen_size(int num, int slot, int func)
Damien Lespiau3e3b2c32014-05-08 22:19:41 +0300426{
427 u16 gmch_ctrl;
Joonas Lahtinenc0dd3462016-04-22 13:29:26 +0300428 u16 gms;
Damien Lespiau3e3b2c32014-05-08 22:19:41 +0300429
430 gmch_ctrl = read_pci_config_16(num, slot, func, SNB_GMCH_CTRL);
Joonas Lahtinenc0dd3462016-04-22 13:29:26 +0300431 gms = (gmch_ctrl >> SNB_GMCH_GMS_SHIFT) & SNB_GMCH_GMS_MASK;
Damien Lespiau3e3b2c32014-05-08 22:19:41 +0300432
433 /*
434 * 0x0 to 0x10: 32MB increments starting at 0MB
435 * 0x11 to 0x16: 4MB increments starting at 8MB
436 * 0x17 to 0x1d: 4MB increments start at 36MB
437 */
Joonas Lahtinenc0dd3462016-04-22 13:29:26 +0300438 if (gms < 0x11)
Joonas Lahtinen6f9fa992017-12-11 15:18:14 +0000439 return gms * MB(32);
Joonas Lahtinenc0dd3462016-04-22 13:29:26 +0300440 else if (gms < 0x17)
Matthew Auld3b51b6f2017-12-11 15:18:16 +0000441 return (gms - 0x11) * MB(4) + MB(8);
Damien Lespiau3e3b2c32014-05-08 22:19:41 +0300442 else
Matthew Auld3b51b6f2017-12-11 15:18:16 +0000443 return (gms - 0x17) * MB(4) + MB(36);
Damien Lespiau3e3b2c32014-05-08 22:19:41 +0300444}
Ville Syrjälä52ca7042014-02-05 21:28:58 +0200445
Joonas Lahtinen6f9fa992017-12-11 15:18:14 +0000446static resource_size_t __init gen9_stolen_size(int num, int slot, int func)
Damien Lespiau66375012014-01-09 18:02:46 +0000447{
448 u16 gmch_ctrl;
Joonas Lahtinenc0dd3462016-04-22 13:29:26 +0300449 u16 gms;
Damien Lespiau66375012014-01-09 18:02:46 +0000450
451 gmch_ctrl = read_pci_config_16(num, slot, func, SNB_GMCH_CTRL);
Joonas Lahtinenc0dd3462016-04-22 13:29:26 +0300452 gms = (gmch_ctrl >> BDW_GMCH_GMS_SHIFT) & BDW_GMCH_GMS_MASK;
Damien Lespiau66375012014-01-09 18:02:46 +0000453
Joonas Lahtinenc0dd3462016-04-22 13:29:26 +0300454 /* 0x0 to 0xef: 32MB increments starting at 0MB */
455 /* 0xf0 to 0xfe: 4MB increments starting at 4MB */
456 if (gms < 0xf0)
Joonas Lahtinen6f9fa992017-12-11 15:18:14 +0000457 return gms * MB(32);
Damien Lespiau66375012014-01-09 18:02:46 +0000458 else
Matthew Auld3b51b6f2017-12-11 15:18:16 +0000459 return (gms - 0xf0) * MB(4) + MB(4);
Damien Lespiau66375012014-01-09 18:02:46 +0000460}
461
Joonas Lahtinenee0629c2016-04-22 13:45:49 +0300462struct intel_early_ops {
Joonas Lahtinen6f9fa992017-12-11 15:18:14 +0000463 resource_size_t (*stolen_size)(int num, int slot, int func);
464 resource_size_t (*stolen_base)(int num, int slot, int func,
465 resource_size_t size);
Ville Syrjäläa4dff762014-02-05 21:28:59 +0200466};
467
Joonas Lahtinenee0629c2016-04-22 13:45:49 +0300468static const struct intel_early_ops i830_early_ops __initconst = {
469 .stolen_base = i830_stolen_base,
470 .stolen_size = i830_stolen_size,
Ville Syrjäläa4dff762014-02-05 21:28:59 +0200471};
472
Joonas Lahtinenee0629c2016-04-22 13:45:49 +0300473static const struct intel_early_ops i845_early_ops __initconst = {
474 .stolen_base = i845_stolen_base,
475 .stolen_size = i830_stolen_size,
Ville Syrjäläa4dff762014-02-05 21:28:59 +0200476};
477
Joonas Lahtinenee0629c2016-04-22 13:45:49 +0300478static const struct intel_early_ops i85x_early_ops __initconst = {
479 .stolen_base = i85x_stolen_base,
480 .stolen_size = gen3_stolen_size,
Ville Syrjäläa4dff762014-02-05 21:28:59 +0200481};
482
Joonas Lahtinenee0629c2016-04-22 13:45:49 +0300483static const struct intel_early_ops i865_early_ops __initconst = {
484 .stolen_base = i865_stolen_base,
485 .stolen_size = gen3_stolen_size,
Ville Syrjälä52ca7042014-02-05 21:28:58 +0200486};
487
Joonas Lahtinenee0629c2016-04-22 13:45:49 +0300488static const struct intel_early_ops gen3_early_ops __initconst = {
489 .stolen_base = gen3_stolen_base,
490 .stolen_size = gen3_stolen_size,
Ville Syrjälä52ca7042014-02-05 21:28:58 +0200491};
492
Joonas Lahtinenee0629c2016-04-22 13:45:49 +0300493static const struct intel_early_ops gen6_early_ops __initconst = {
494 .stolen_base = gen3_stolen_base,
495 .stolen_size = gen6_stolen_size,
Ville Syrjälä52ca7042014-02-05 21:28:58 +0200496};
Jesse Barnes814c5f12013-07-26 13:32:52 -0700497
Joonas Lahtinenee0629c2016-04-22 13:45:49 +0300498static const struct intel_early_ops gen8_early_ops __initconst = {
499 .stolen_base = gen3_stolen_base,
500 .stolen_size = gen8_stolen_size,
Damien Lespiau66375012014-01-09 18:02:46 +0000501};
502
Joonas Lahtinenee0629c2016-04-22 13:45:49 +0300503static const struct intel_early_ops gen9_early_ops __initconst = {
504 .stolen_base = gen3_stolen_base,
505 .stolen_size = gen9_stolen_size,
Damien Lespiau3e3b2c32014-05-08 22:19:41 +0300506};
507
Joonas Lahtinenee0629c2016-04-22 13:45:49 +0300508static const struct intel_early_ops chv_early_ops __initconst = {
509 .stolen_base = gen3_stolen_base,
510 .stolen_size = chv_stolen_size,
Jesse Barnes814c5f12013-07-26 13:32:52 -0700511};
512
Paulo Zanonidb0c8d82018-05-04 13:32:51 -0700513static const struct intel_early_ops gen11_early_ops __initconst = {
514 .stolen_base = gen11_stolen_base,
515 .stolen_size = gen9_stolen_size,
516};
517
Joonas Lahtinenee0629c2016-04-22 13:45:49 +0300518static const struct pci_device_id intel_early_ids[] __initconst = {
519 INTEL_I830_IDS(&i830_early_ops),
520 INTEL_I845G_IDS(&i845_early_ops),
521 INTEL_I85X_IDS(&i85x_early_ops),
522 INTEL_I865G_IDS(&i865_early_ops),
523 INTEL_I915G_IDS(&gen3_early_ops),
524 INTEL_I915GM_IDS(&gen3_early_ops),
525 INTEL_I945G_IDS(&gen3_early_ops),
526 INTEL_I945GM_IDS(&gen3_early_ops),
Carlos Santa8d9c20e2016-08-17 12:30:37 -0700527 INTEL_VLV_IDS(&gen6_early_ops),
Tvrtko Ursulin86d35d42019-03-26 07:40:54 +0000528 INTEL_PINEVIEW_G_IDS(&gen3_early_ops),
529 INTEL_PINEVIEW_M_IDS(&gen3_early_ops),
Joonas Lahtinenee0629c2016-04-22 13:45:49 +0300530 INTEL_I965G_IDS(&gen3_early_ops),
531 INTEL_G33_IDS(&gen3_early_ops),
532 INTEL_I965GM_IDS(&gen3_early_ops),
533 INTEL_GM45_IDS(&gen3_early_ops),
534 INTEL_G45_IDS(&gen3_early_ops),
535 INTEL_IRONLAKE_D_IDS(&gen3_early_ops),
536 INTEL_IRONLAKE_M_IDS(&gen3_early_ops),
537 INTEL_SNB_D_IDS(&gen6_early_ops),
538 INTEL_SNB_M_IDS(&gen6_early_ops),
539 INTEL_IVB_M_IDS(&gen6_early_ops),
540 INTEL_IVB_D_IDS(&gen6_early_ops),
Carlos Santa8d9c20e2016-08-17 12:30:37 -0700541 INTEL_HSW_IDS(&gen6_early_ops),
542 INTEL_BDW_IDS(&gen8_early_ops),
Joonas Lahtinenee0629c2016-04-22 13:45:49 +0300543 INTEL_CHV_IDS(&chv_early_ops),
544 INTEL_SKL_IDS(&gen9_early_ops),
545 INTEL_BXT_IDS(&gen9_early_ops),
546 INTEL_KBL_IDS(&gen9_early_ops),
Lucas De Marchi33aa69e2017-12-13 12:04:25 -0800547 INTEL_CFL_IDS(&gen9_early_ops),
Paulo Zanonibc384c72017-01-24 16:47:22 -0200548 INTEL_GLK_IDS(&gen9_early_ops),
Paulo Zanoni2e1e9d42017-07-05 18:00:45 -0700549 INTEL_CNL_IDS(&gen9_early_ops),
Paulo Zanonidb0c8d82018-05-04 13:32:51 -0700550 INTEL_ICL_11_IDS(&gen11_early_ops),
Rodrigo Vivid53fef02019-03-15 12:19:38 -0700551 INTEL_EHL_IDS(&gen11_early_ops),
Joonas Lahtinenee0629c2016-04-22 13:45:49 +0300552};
553
Matthew Auld55f56fc2017-12-11 15:18:15 +0000554struct resource intel_graphics_stolen_res __ro_after_init = DEFINE_RES_MEM(0, 0);
555EXPORT_SYMBOL(intel_graphics_stolen_res);
556
Joonas Lahtinenee0629c2016-04-22 13:45:49 +0300557static void __init
558intel_graphics_stolen(int num, int slot, int func,
559 const struct intel_early_ops *early_ops)
Jesse Barnes814c5f12013-07-26 13:32:52 -0700560{
Joonas Lahtinen6f9fa992017-12-11 15:18:14 +0000561 resource_size_t base, size;
562 resource_size_t end;
Joonas Lahtinenee0629c2016-04-22 13:45:49 +0300563
564 size = early_ops->stolen_size(num, slot, func);
565 base = early_ops->stolen_base(num, slot, func, size);
566
567 if (!size || !base)
568 return;
569
Chris Wilson01e5d3b2016-05-09 17:39:42 +0100570 end = base + size - 1;
Matthew Auld55f56fc2017-12-11 15:18:15 +0000571
572 intel_graphics_stolen_res.start = base;
573 intel_graphics_stolen_res.end = end;
574
575 printk(KERN_INFO "Reserving Intel graphics memory at %pR\n",
576 &intel_graphics_stolen_res);
Joonas Lahtinenee0629c2016-04-22 13:45:49 +0300577
578 /* Mark this space as reserved */
Ingo Molnar09821ff2017-01-28 17:09:33 +0100579 e820__range_add(base, size, E820_TYPE_RESERVED);
Ingo Molnarf9748fa2017-01-28 18:00:35 +0100580 e820__update_table(e820_table);
Joonas Lahtinenee0629c2016-04-22 13:45:49 +0300581}
582
583static void __init intel_graphics_quirks(int num, int slot, int func)
584{
585 const struct intel_early_ops *early_ops;
586 u16 device;
Jesse Barnes814c5f12013-07-26 13:32:52 -0700587 int i;
Jesse Barnes814c5f12013-07-26 13:32:52 -0700588
589 device = read_pci_config_16(num, slot, func, PCI_DEVICE_ID);
Jesse Barnes814c5f12013-07-26 13:32:52 -0700590
Joonas Lahtinenee0629c2016-04-22 13:45:49 +0300591 for (i = 0; i < ARRAY_SIZE(intel_early_ids); i++) {
592 kernel_ulong_t driver_data = intel_early_ids[i].driver_data;
593
594 if (intel_early_ids[i].device != device)
595 continue;
596
597 early_ops = (typeof(early_ops))driver_data;
598
599 intel_graphics_stolen(num, slot, func, early_ops);
600
601 return;
Jesse Barnes814c5f12013-07-26 13:32:52 -0700602 }
603}
604
Feng Tang62187912014-04-24 16:18:18 +0800605static void __init force_disable_hpet(int num, int slot, int func)
606{
607#ifdef CONFIG_HPET_TIMER
Jan Beulich3d45ac42015-10-19 04:35:44 -0600608 boot_hpet_disable = true;
Feng Tang62187912014-04-24 16:18:18 +0800609 pr_info("x86/hpet: Will disable the HPET for this platform because it's not reliable\n");
610#endif
611}
612
Lukas Wunnerabb2baf2016-06-12 12:31:53 +0200613#define BCM4331_MMIO_SIZE 16384
614#define BCM4331_PM_CAP 0x40
615#define bcma_aread32(reg) ioread32(mmio + 1 * BCMA_CORE_SIZE + reg)
616#define bcma_awrite32(reg, val) iowrite32(val, mmio + 1 * BCMA_CORE_SIZE + reg)
617
618static void __init apple_airport_reset(int bus, int slot, int func)
619{
620 void __iomem *mmio;
621 u16 pmcsr;
622 u64 addr;
623 int i;
624
Lukas Wunner630b3af2017-08-01 14:10:41 +0200625 if (!x86_apple_machine)
Lukas Wunnerabb2baf2016-06-12 12:31:53 +0200626 return;
627
628 /* Card may have been put into PCI_D3hot by grub quirk */
629 pmcsr = read_pci_config_16(bus, slot, func, BCM4331_PM_CAP + PCI_PM_CTRL);
630
631 if ((pmcsr & PCI_PM_CTRL_STATE_MASK) != PCI_D0) {
632 pmcsr &= ~PCI_PM_CTRL_STATE_MASK;
633 write_pci_config_16(bus, slot, func, BCM4331_PM_CAP + PCI_PM_CTRL, pmcsr);
634 mdelay(10);
635
636 pmcsr = read_pci_config_16(bus, slot, func, BCM4331_PM_CAP + PCI_PM_CTRL);
637 if ((pmcsr & PCI_PM_CTRL_STATE_MASK) != PCI_D0) {
Joe Perchesa7a31532018-05-09 08:15:45 -0700638 pr_err("pci 0000:%02x:%02x.%d: Cannot power up Apple AirPort card\n",
639 bus, slot, func);
Lukas Wunnerabb2baf2016-06-12 12:31:53 +0200640 return;
641 }
642 }
643
644 addr = read_pci_config(bus, slot, func, PCI_BASE_ADDRESS_0);
645 addr |= (u64)read_pci_config(bus, slot, func, PCI_BASE_ADDRESS_1) << 32;
646 addr &= PCI_BASE_ADDRESS_MEM_MASK;
647
648 mmio = early_ioremap(addr, BCM4331_MMIO_SIZE);
649 if (!mmio) {
Joe Perchesa7a31532018-05-09 08:15:45 -0700650 pr_err("pci 0000:%02x:%02x.%d: Cannot iomap Apple AirPort card\n",
651 bus, slot, func);
Lukas Wunnerabb2baf2016-06-12 12:31:53 +0200652 return;
653 }
654
655 pr_info("Resetting Apple AirPort card (left enabled by EFI)\n");
656
657 for (i = 0; bcma_aread32(BCMA_RESET_ST) && i < 30; i++)
658 udelay(10);
659
660 bcma_awrite32(BCMA_RESET_CTL, BCMA_RESET_CTL_RESET);
661 bcma_aread32(BCMA_RESET_CTL);
662 udelay(1);
663
664 bcma_awrite32(BCMA_RESET_CTL, 0);
665 bcma_aread32(BCMA_RESET_CTL);
666 udelay(10);
667
668 early_iounmap(mmio, BCM4331_MMIO_SIZE);
669}
Feng Tang62187912014-04-24 16:18:18 +0800670
Neil Hormanc6b48322008-01-30 13:31:25 +0100671#define QFLAG_APPLY_ONCE 0x1
672#define QFLAG_APPLIED 0x2
673#define QFLAG_DONE (QFLAG_APPLY_ONCE|QFLAG_APPLIED)
Andi Kleendfa46982006-09-26 10:52:30 +0200674struct chipset {
Neil Hormanc6b48322008-01-30 13:31:25 +0100675 u32 vendor;
676 u32 device;
677 u32 class;
678 u32 class_mask;
679 u32 flags;
680 void (*f)(int num, int slot, int func);
Andi Kleendfa46982006-09-26 10:52:30 +0200681};
682
Andrew Mortonc993c732007-04-08 16:04:03 -0700683static struct chipset early_qrk[] __initdata = {
Neil Hormanc6b48322008-01-30 13:31:25 +0100684 { PCI_VENDOR_ID_NVIDIA, PCI_ANY_ID,
685 PCI_CLASS_BRIDGE_PCI, PCI_ANY_ID, QFLAG_APPLY_ONCE, nvidia_bugs },
686 { PCI_VENDOR_ID_VIA, PCI_ANY_ID,
687 PCI_CLASS_BRIDGE_PCI, PCI_ANY_ID, QFLAG_APPLY_ONCE, via_bugs },
Neil Hormanc6b48322008-01-30 13:31:25 +0100688 { PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_K8_NB,
689 PCI_CLASS_BRIDGE_HOST, PCI_ANY_ID, 0, fix_hypertransport_config },
Andreas Herrmann33fb0e42008-10-07 00:11:22 +0200690 { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP400_SMBUS,
691 PCI_CLASS_SERIAL_SMBUS, PCI_ANY_ID, 0, ati_bugs },
Andreas Herrmann26adcfb2008-10-14 21:01:15 +0200692 { PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_SBX00_SMBUS,
693 PCI_CLASS_SERIAL_SMBUS, PCI_ANY_ID, 0, ati_bugs_contd },
Neil Horman03bbcb22013-04-16 16:38:32 -0400694 { PCI_VENDOR_ID_INTEL, 0x3403, PCI_CLASS_BRIDGE_HOST,
695 PCI_BASE_CLASS_BRIDGE, 0, intel_remapping_check },
Neil Horman803075d2013-07-17 07:13:59 -0400696 { PCI_VENDOR_ID_INTEL, 0x3405, PCI_CLASS_BRIDGE_HOST,
697 PCI_BASE_CLASS_BRIDGE, 0, intel_remapping_check },
Neil Horman03bbcb22013-04-16 16:38:32 -0400698 { PCI_VENDOR_ID_INTEL, 0x3406, PCI_CLASS_BRIDGE_HOST,
699 PCI_BASE_CLASS_BRIDGE, 0, intel_remapping_check },
Jesse Barnes814c5f12013-07-26 13:32:52 -0700700 { PCI_VENDOR_ID_INTEL, PCI_ANY_ID, PCI_CLASS_DISPLAY_VGA, PCI_ANY_ID,
Joonas Lahtinenee0629c2016-04-22 13:45:49 +0300701 QFLAG_APPLY_ONCE, intel_graphics_quirks },
Feng Tang62187912014-04-24 16:18:18 +0800702 /*
Feng Tangb58d9302015-06-15 17:40:01 +0800703 * HPET on the current version of the Baytrail platform has accuracy
704 * problems: it will halt in deep idle state - so we disable it.
705 *
706 * More details can be found in section 18.10.1.3 of the datasheet:
707 *
708 * http://www.intel.com/content/dam/www/public/us/en/documents/datasheets/atom-z8000-datasheet-vol-1.pdf
Feng Tang62187912014-04-24 16:18:18 +0800709 */
710 { PCI_VENDOR_ID_INTEL, 0x0f00,
711 PCI_CLASS_BRIDGE_HOST, PCI_ANY_ID, 0, force_disable_hpet},
Lukas Wunnerabb2baf2016-06-12 12:31:53 +0200712 { PCI_VENDOR_ID_BROADCOM, 0x4331,
713 PCI_CLASS_NETWORK_OTHER, PCI_ANY_ID, 0, apple_airport_reset},
Andi Kleendfa46982006-09-26 10:52:30 +0200714 {}
715};
716
Lukas Wunner850c3212016-06-12 12:31:53 +0200717static void __init early_pci_scan_bus(int bus);
718
Jesse Barnes15650a22008-06-16 15:29:45 -0700719/**
720 * check_dev_quirk - apply early quirks to a given PCI device
721 * @num: bus number
722 * @slot: slot number
723 * @func: PCI function
724 *
725 * Check the vendor & device ID against the early quirks table.
726 *
Lukas Wunner850c3212016-06-12 12:31:53 +0200727 * If the device is single function, let early_pci_scan_bus() know so we don't
Jesse Barnes15650a22008-06-16 15:29:45 -0700728 * poke at this device again.
729 */
730static int __init check_dev_quirk(int num, int slot, int func)
Neil Horman7bcbc782008-01-30 13:31:26 +0100731{
732 u16 class;
733 u16 vendor;
734 u16 device;
735 u8 type;
Lukas Wunner850c3212016-06-12 12:31:53 +0200736 u8 sec;
Neil Horman7bcbc782008-01-30 13:31:26 +0100737 int i;
738
739 class = read_pci_config_16(num, slot, func, PCI_CLASS_DEVICE);
740
741 if (class == 0xffff)
Jesse Barnes15650a22008-06-16 15:29:45 -0700742 return -1; /* no class, treat as single function */
Neil Horman7bcbc782008-01-30 13:31:26 +0100743
744 vendor = read_pci_config_16(num, slot, func, PCI_VENDOR_ID);
745
746 device = read_pci_config_16(num, slot, func, PCI_DEVICE_ID);
747
748 for (i = 0; early_qrk[i].f != NULL; i++) {
749 if (((early_qrk[i].vendor == PCI_ANY_ID) ||
750 (early_qrk[i].vendor == vendor)) &&
751 ((early_qrk[i].device == PCI_ANY_ID) ||
752 (early_qrk[i].device == device)) &&
753 (!((early_qrk[i].class ^ class) &
754 early_qrk[i].class_mask))) {
755 if ((early_qrk[i].flags &
756 QFLAG_DONE) != QFLAG_DONE)
757 early_qrk[i].f(num, slot, func);
758 early_qrk[i].flags |= QFLAG_APPLIED;
759 }
760 }
761
762 type = read_pci_config_byte(num, slot, func,
763 PCI_HEADER_TYPE);
Lukas Wunner850c3212016-06-12 12:31:53 +0200764
765 if ((type & 0x7f) == PCI_HEADER_TYPE_BRIDGE) {
766 sec = read_pci_config_byte(num, slot, func, PCI_SECONDARY_BUS);
767 if (sec > num)
768 early_pci_scan_bus(sec);
769 }
770
Neil Horman7bcbc782008-01-30 13:31:26 +0100771 if (!(type & 0x80))
Jesse Barnes15650a22008-06-16 15:29:45 -0700772 return -1;
773
774 return 0;
Neil Horman7bcbc782008-01-30 13:31:26 +0100775}
776
Lukas Wunner850c3212016-06-12 12:31:53 +0200777static void __init early_pci_scan_bus(int bus)
Andi Kleendfa46982006-09-26 10:52:30 +0200778{
Andi Kleen8659c402009-01-09 12:17:39 -0800779 int slot, func;
Andi Kleen0637a702006-09-26 10:52:41 +0200780
Andi Kleendfa46982006-09-26 10:52:30 +0200781 /* Poor man's PCI discovery */
Andi Kleen8659c402009-01-09 12:17:39 -0800782 for (slot = 0; slot < 32; slot++)
783 for (func = 0; func < 8; func++) {
784 /* Only probe function 0 on single fn devices */
Lukas Wunner850c3212016-06-12 12:31:53 +0200785 if (check_dev_quirk(bus, slot, func))
Andi Kleen8659c402009-01-09 12:17:39 -0800786 break;
787 }
Andi Kleendfa46982006-09-26 10:52:30 +0200788}
Lukas Wunner850c3212016-06-12 12:31:53 +0200789
790void __init early_quirks(void)
791{
792 if (!early_pci_allowed())
793 return;
794
795 early_pci_scan_bus(0);
796}