1 // SPDX-License-Identifier: GPL-2.0
3 * This file contains work-arounds for x86 and x86_64 platform bugs.
10 #include <asm/setup.h>
12 #if defined(CONFIG_X86_IO_APIC) && defined(CONFIG_SMP) && defined(CONFIG_PCI)
14 static void quirk_intel_irqbalance(struct pci_dev *dev)
19 /* BIOS may enable hardware IRQ balancing for
20 * E7520/E7320/E7525(revision ID 0x9 and below)
22 * Disable SW irqbalance/affinity on those platforms.
24 if (dev->revision > 0x9)
27 /* enable access to config space*/
28 pci_read_config_byte(dev, 0xf4, &config);
29 pci_write_config_byte(dev, 0xf4, config|0x2);
32 * read xTPR register. We may not have a pci_dev for device 8
33 * because it might be hidden until the above write.
35 pci_bus_read_config_word(dev->bus, PCI_DEVFN(8, 0), 0x4c, &word);
37 if (!(word & (1 << 13))) {
38 dev_info(&dev->dev, "Intel E7520/7320/7525 detected; "
39 "disabling irq balancing and affinity\n");
46 /* put back the original value for config space*/
48 pci_write_config_byte(dev, 0xf4, config);
50 DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_E7320_MCH,
51 quirk_intel_irqbalance);
52 DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_E7525_MCH,
53 quirk_intel_irqbalance);
54 DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_E7520_MCH,
55 quirk_intel_irqbalance);
58 #if defined(CONFIG_HPET_TIMER)
59 unsigned long force_hpet_address;
62 NONE_FORCE_HPET_RESUME,
63 OLD_ICH_FORCE_HPET_RESUME,
64 ICH_FORCE_HPET_RESUME,
65 VT8237_FORCE_HPET_RESUME,
66 NVIDIA_FORCE_HPET_RESUME,
67 ATI_FORCE_HPET_RESUME,
68 } force_hpet_resume_type;
70 static void __iomem *rcba_base;
72 static void ich_force_hpet_resume(void)
76 if (!force_hpet_address)
79 BUG_ON(rcba_base == NULL);
81 /* read the Function Disable register, dword mode only */
82 val = readl(rcba_base + 0x3404);
84 /* HPET disabled in HPTC. Trying to enable */
85 writel(val | 0x80, rcba_base + 0x3404);
88 val = readl(rcba_base + 0x3404);
92 printk(KERN_DEBUG "Force enabled HPET at resume\n");
95 static void ich_force_enable_hpet(struct pci_dev *dev)
101 if (hpet_address || force_hpet_address)
104 pci_read_config_dword(dev, 0xF0, &rcba);
107 dev_printk(KERN_DEBUG, &dev->dev, "RCBA disabled; "
108 "cannot force enable HPET\n");
112 /* use bits 31:14, 16 kB aligned */
113 rcba_base = ioremap(rcba, 0x4000);
114 if (rcba_base == NULL) {
115 dev_printk(KERN_DEBUG, &dev->dev, "ioremap failed; "
116 "cannot force enable HPET\n");
120 /* read the Function Disable register, dword mode only */
121 val = readl(rcba_base + 0x3404);
124 /* HPET is enabled in HPTC. Just not reported by BIOS */
126 force_hpet_address = 0xFED00000 | (val << 12);
127 dev_printk(KERN_DEBUG, &dev->dev, "Force enabled HPET at "
128 "0x%lx\n", force_hpet_address);
133 /* HPET disabled in HPTC. Trying to enable */
134 writel(val | 0x80, rcba_base + 0x3404);
136 val = readl(rcba_base + 0x3404);
141 force_hpet_address = 0xFED00000 | (val << 12);
145 force_hpet_address = 0;
147 dev_printk(KERN_DEBUG, &dev->dev,
148 "Failed to force enable HPET\n");
150 force_hpet_resume_type = ICH_FORCE_HPET_RESUME;
151 dev_printk(KERN_DEBUG, &dev->dev, "Force enabled HPET at "
152 "0x%lx\n", force_hpet_address);
156 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ESB2_0,
157 ich_force_enable_hpet);
158 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH6_0,
159 ich_force_enable_hpet);
160 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH6_1,
161 ich_force_enable_hpet);
162 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH7_0,
163 ich_force_enable_hpet);
164 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH7_1,
165 ich_force_enable_hpet);
166 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH7_31,
167 ich_force_enable_hpet);
168 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH8_1,
169 ich_force_enable_hpet);
170 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH8_4,
171 ich_force_enable_hpet);
172 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH9_7,
173 ich_force_enable_hpet);
174 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x3a16, /* ICH10 */
175 ich_force_enable_hpet);
177 static struct pci_dev *cached_dev;
179 static void hpet_print_force_info(void)
181 printk(KERN_INFO "HPET not enabled in BIOS. "
182 "You might try hpet=force boot option\n");
185 static void old_ich_force_hpet_resume(void)
190 if (!force_hpet_address || !cached_dev)
193 pci_read_config_dword(cached_dev, 0xD0, &gen_cntl);
194 gen_cntl &= (~(0x7 << 15));
195 gen_cntl |= (0x4 << 15);
197 pci_write_config_dword(cached_dev, 0xD0, gen_cntl);
198 pci_read_config_dword(cached_dev, 0xD0, &gen_cntl);
199 val = gen_cntl >> 15;
202 printk(KERN_DEBUG "Force enabled HPET at resume\n");
207 static void old_ich_force_enable_hpet(struct pci_dev *dev)
212 if (hpet_address || force_hpet_address)
215 pci_read_config_dword(dev, 0xD0, &gen_cntl);
217 * Bit 17 is HPET enable bit.
218 * Bit 16:15 control the HPET base address.
220 val = gen_cntl >> 15;
224 force_hpet_address = 0xFED00000 | (val << 12);
225 dev_printk(KERN_DEBUG, &dev->dev, "HPET at 0x%lx\n",
231 * HPET is disabled. Trying enabling at FED00000 and check
234 gen_cntl &= (~(0x7 << 15));
235 gen_cntl |= (0x4 << 15);
236 pci_write_config_dword(dev, 0xD0, gen_cntl);
238 pci_read_config_dword(dev, 0xD0, &gen_cntl);
240 val = gen_cntl >> 15;
243 /* HPET is enabled in HPTC. Just not reported by BIOS */
245 force_hpet_address = 0xFED00000 | (val << 12);
246 dev_printk(KERN_DEBUG, &dev->dev, "Force enabled HPET at "
247 "0x%lx\n", force_hpet_address);
249 force_hpet_resume_type = OLD_ICH_FORCE_HPET_RESUME;
253 dev_printk(KERN_DEBUG, &dev->dev, "Failed to force enable HPET\n");
257 * Undocumented chipset features. Make sure that the user enforced
260 static void old_ich_force_enable_hpet_user(struct pci_dev *dev)
263 old_ich_force_enable_hpet(dev);
266 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ESB_1,
267 old_ich_force_enable_hpet_user);
268 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_0,
269 old_ich_force_enable_hpet_user);
270 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_12,
271 old_ich_force_enable_hpet_user);
272 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_0,
273 old_ich_force_enable_hpet_user);
274 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_12,
275 old_ich_force_enable_hpet_user);
276 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801EB_0,
277 old_ich_force_enable_hpet);
278 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801EB_12,
279 old_ich_force_enable_hpet);
282 static void vt8237_force_hpet_resume(void)
286 if (!force_hpet_address || !cached_dev)
289 val = 0xfed00000 | 0x80;
290 pci_write_config_dword(cached_dev, 0x68, val);
292 pci_read_config_dword(cached_dev, 0x68, &val);
294 printk(KERN_DEBUG "Force enabled HPET at resume\n");
299 static void vt8237_force_enable_hpet(struct pci_dev *dev)
303 if (hpet_address || force_hpet_address)
306 if (!hpet_force_user) {
307 hpet_print_force_info();
311 pci_read_config_dword(dev, 0x68, &val);
313 * Bit 7 is HPET enable bit.
314 * Bit 31:10 is HPET base address (contrary to what datasheet claims)
317 force_hpet_address = (val & ~0x3ff);
318 dev_printk(KERN_DEBUG, &dev->dev, "HPET at 0x%lx\n",
324 * HPET is disabled. Trying enabling at FED00000 and check
327 val = 0xfed00000 | 0x80;
328 pci_write_config_dword(dev, 0x68, val);
330 pci_read_config_dword(dev, 0x68, &val);
332 force_hpet_address = (val & ~0x3ff);
333 dev_printk(KERN_DEBUG, &dev->dev, "Force enabled HPET at "
334 "0x%lx\n", force_hpet_address);
336 force_hpet_resume_type = VT8237_FORCE_HPET_RESUME;
340 dev_printk(KERN_DEBUG, &dev->dev, "Failed to force enable HPET\n");
343 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8235,
344 vt8237_force_enable_hpet);
345 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8237,
346 vt8237_force_enable_hpet);
347 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_CX700,
348 vt8237_force_enable_hpet);
350 static void ati_force_hpet_resume(void)
352 pci_write_config_dword(cached_dev, 0x14, 0xfed00000);
353 printk(KERN_DEBUG "Force enabled HPET at resume\n");
356 static u32 ati_ixp4x0_rev(struct pci_dev *dev)
362 err = pci_read_config_byte(dev, 0xac, &b);
364 err |= pci_write_config_byte(dev, 0xac, b);
365 err |= pci_read_config_dword(dev, 0x70, &d);
367 err |= pci_write_config_dword(dev, 0x70, d);
368 err |= pci_read_config_dword(dev, 0x8, &d);
370 dev_printk(KERN_DEBUG, &dev->dev, "SB4X0 revision 0x%x\n", d);
377 static void ati_force_enable_hpet(struct pci_dev *dev)
382 if (hpet_address || force_hpet_address)
385 if (!hpet_force_user) {
386 hpet_print_force_info();
390 d = ati_ixp4x0_rev(dev);
395 pci_write_config_dword(dev, 0x14, 0xfed00000);
396 pci_read_config_dword(dev, 0x14, &val);
398 /* enable interrupt */
399 outb(0x72, 0xcd6); b = inb(0xcd7);
401 outb(0x72, 0xcd6); outb(b, 0xcd7);
402 outb(0x72, 0xcd6); b = inb(0xcd7);
405 pci_read_config_dword(dev, 0x64, &d);
407 pci_write_config_dword(dev, 0x64, d);
408 pci_read_config_dword(dev, 0x64, &d);
412 force_hpet_address = val;
413 force_hpet_resume_type = ATI_FORCE_HPET_RESUME;
414 dev_printk(KERN_DEBUG, &dev->dev, "Force enabled HPET at 0x%lx\n",
418 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP400_SMBUS,
419 ati_force_enable_hpet);
422 * Undocumented chipset feature taken from LinuxBIOS.
424 static void nvidia_force_hpet_resume(void)
426 pci_write_config_dword(cached_dev, 0x44, 0xfed00001);
427 printk(KERN_DEBUG "Force enabled HPET at resume\n");
430 static void nvidia_force_enable_hpet(struct pci_dev *dev)
434 if (hpet_address || force_hpet_address)
437 if (!hpet_force_user) {
438 hpet_print_force_info();
442 pci_write_config_dword(dev, 0x44, 0xfed00001);
443 pci_read_config_dword(dev, 0x44, &val);
444 force_hpet_address = val & 0xfffffffe;
445 force_hpet_resume_type = NVIDIA_FORCE_HPET_RESUME;
446 dev_printk(KERN_DEBUG, &dev->dev, "Force enabled HPET at 0x%lx\n",
452 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_NVIDIA, 0x0050,
453 nvidia_force_enable_hpet);
454 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_NVIDIA, 0x0051,
455 nvidia_force_enable_hpet);
458 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_NVIDIA, 0x0260,
459 nvidia_force_enable_hpet);
460 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_NVIDIA, 0x0360,
461 nvidia_force_enable_hpet);
462 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_NVIDIA, 0x0361,
463 nvidia_force_enable_hpet);
464 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_NVIDIA, 0x0362,
465 nvidia_force_enable_hpet);
466 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_NVIDIA, 0x0363,
467 nvidia_force_enable_hpet);
468 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_NVIDIA, 0x0364,
469 nvidia_force_enable_hpet);
470 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_NVIDIA, 0x0365,
471 nvidia_force_enable_hpet);
472 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_NVIDIA, 0x0366,
473 nvidia_force_enable_hpet);
474 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_NVIDIA, 0x0367,
475 nvidia_force_enable_hpet);
477 void force_hpet_resume(void)
479 switch (force_hpet_resume_type) {
480 case ICH_FORCE_HPET_RESUME:
481 ich_force_hpet_resume();
483 case OLD_ICH_FORCE_HPET_RESUME:
484 old_ich_force_hpet_resume();
486 case VT8237_FORCE_HPET_RESUME:
487 vt8237_force_hpet_resume();
489 case NVIDIA_FORCE_HPET_RESUME:
490 nvidia_force_hpet_resume();
492 case ATI_FORCE_HPET_RESUME:
493 ati_force_hpet_resume();
501 * According to the datasheet e6xx systems have the HPET hardwired to
504 static void e6xx_force_enable_hpet(struct pci_dev *dev)
506 if (hpet_address || force_hpet_address)
509 force_hpet_address = 0xFED00000;
510 force_hpet_resume_type = NONE_FORCE_HPET_RESUME;
511 dev_printk(KERN_DEBUG, &dev->dev, "Force enabled HPET at "
512 "0x%lx\n", force_hpet_address);
514 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_E6XX_CU,
515 e6xx_force_enable_hpet);
518 * HPET MSI on some boards (ATI SB700/SB800) has side effect on
519 * floppy DMA. Disable HPET MSI on such platforms.
520 * See erratum #27 (Misinterpreted MSI Requests May Result in
521 * Corrupted LPC DMA Data) in AMD Publication #46837,
522 * "SB700 Family Product Errata", Rev. 1.0, March 2010.
524 static void force_disable_hpet_msi(struct pci_dev *unused)
526 hpet_msi_disable = true;
529 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_SBX00_SMBUS,
530 force_disable_hpet_msi);
534 #if defined(CONFIG_PCI) && defined(CONFIG_NUMA)
535 /* Set correct numa_node information for AMD NB functions */
536 static void quirk_amd_nb_node(struct pci_dev *dev)
538 struct pci_dev *nb_ht;
543 devfn = PCI_DEVFN(PCI_SLOT(dev->devfn), 0);
544 nb_ht = pci_get_slot(dev->bus, devfn);
548 pci_read_config_dword(nb_ht, 0x60, &val);
549 node = pcibus_to_node(dev->bus) | (val & 7);
551 * Some hardware may return an invalid node ID,
554 if (node_online(node))
555 set_dev_node(&dev->dev, node);
559 DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_K8_NB,
561 DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_K8_NB_ADDRMAP,
563 DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_K8_NB_MEMCTL,
565 DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_K8_NB_MISC,
567 DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_10H_NB_HT,
569 DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_10H_NB_MAP,
571 DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_10H_NB_DRAM,
573 DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_10H_NB_MISC,
575 DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_10H_NB_LINK,
577 DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_15H_NB_F0,
579 DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_15H_NB_F1,
581 DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_15H_NB_F2,
583 DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_15H_NB_F3,
585 DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_15H_NB_F4,
587 DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_15H_NB_F5,
594 * Processor does not ensure DRAM scrub read/write sequence
595 * is atomic wrt accesses to CC6 save state area. Therefore
596 * if a concurrent scrub read/write access is to same address
597 * the entry may appear as if it is not written. This quirk
598 * applies to Fam16h models 00h-0Fh
600 * See "Revision Guide" for AMD F16h models 00h-0fh,
601 * document 51810 rev. 3.04, Nov 2013
603 static void amd_disable_seq_and_redirect_scrub(struct pci_dev *dev)
608 * Suggested workaround:
609 * set D18F3x58[4:0] = 00h and set D18F3x5C[0] = 0b
611 pci_read_config_dword(dev, 0x58, &val);
614 pci_write_config_dword(dev, 0x58, val);
617 pci_read_config_dword(dev, 0x5C, &val);
620 pci_write_config_dword(dev, 0x5c, val);
624 DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_16H_NB_F3,
625 amd_disable_seq_and_redirect_scrub);
627 #if defined(CONFIG_X86_64) && defined(CONFIG_X86_MCE)
628 #include <linux/jump_label.h>
629 #include <asm/string_64.h>
631 /* Ivy Bridge, Haswell, Broadwell */
632 static void quirk_intel_brickland_xeon_ras_cap(struct pci_dev *pdev)
636 pci_read_config_dword(pdev, 0x84, &capid0);
639 static_branch_inc(&mcsafe_key);
643 static void quirk_intel_purley_xeon_ras_cap(struct pci_dev *pdev)
647 pci_read_config_dword(pdev, 0x84, &capid0);
648 pci_read_config_dword(pdev, 0x98, &capid5);
651 * CAPID0{7:6} indicate whether this is an advanced RAS SKU
652 * CAPID5{8:5} indicate that various NVDIMM usage modes are
653 * enabled, so memory machine check recovery is also enabled.
655 if ((capid0 & 0xc0) == 0xc0 || (capid5 & 0x1e0))
656 static_branch_inc(&mcsafe_key);
659 DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL, 0x0ec3, quirk_intel_brickland_xeon_ras_cap);
660 DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL, 0x2fc0, quirk_intel_brickland_xeon_ras_cap);
661 DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL, 0x6fc0, quirk_intel_brickland_xeon_ras_cap);
662 DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL, 0x2083, quirk_intel_purley_xeon_ras_cap);
666 bool x86_apple_machine;
667 EXPORT_SYMBOL(x86_apple_machine);
669 void __init early_platform_quirks(void)
671 x86_apple_machine = dmi_match(DMI_SYS_VENDOR, "Apple Inc.") ||
672 dmi_match(DMI_SYS_VENDOR, "Apple Computer, Inc.");