2 * This file contains work-arounds for x86 and x86_64 platform bugs.
9 #if defined(CONFIG_X86_IO_APIC) && defined(CONFIG_SMP) && defined(CONFIG_PCI)
11 static void quirk_intel_irqbalance(struct pci_dev *dev)
16 /* BIOS may enable hardware IRQ balancing for
17 * E7520/E7320/E7525(revision ID 0x9 and below)
19 * Disable SW irqbalance/affinity on those platforms.
21 if (dev->revision > 0x9)
24 /* enable access to config space*/
25 pci_read_config_byte(dev, 0xf4, &config);
26 pci_write_config_byte(dev, 0xf4, config|0x2);
29 * read xTPR register. We may not have a pci_dev for device 8
30 * because it might be hidden until the above write.
32 pci_bus_read_config_word(dev->bus, PCI_DEVFN(8, 0), 0x4c, &word);
34 if (!(word & (1 << 13))) {
35 dev_info(&dev->dev, "Intel E7520/7320/7525 detected; "
36 "disabling irq balancing and affinity\n");
43 /* put back the original value for config space*/
45 pci_write_config_byte(dev, 0xf4, config);
47 DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_E7320_MCH,
48 quirk_intel_irqbalance);
49 DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_E7525_MCH,
50 quirk_intel_irqbalance);
51 DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_E7520_MCH,
52 quirk_intel_irqbalance);
55 #if defined(CONFIG_HPET_TIMER)
56 unsigned long force_hpet_address;
59 NONE_FORCE_HPET_RESUME,
60 OLD_ICH_FORCE_HPET_RESUME,
61 ICH_FORCE_HPET_RESUME,
62 VT8237_FORCE_HPET_RESUME,
63 NVIDIA_FORCE_HPET_RESUME,
64 ATI_FORCE_HPET_RESUME,
65 } force_hpet_resume_type;
67 static void __iomem *rcba_base;
69 static void ich_force_hpet_resume(void)
73 if (!force_hpet_address)
76 BUG_ON(rcba_base == NULL);
78 /* read the Function Disable register, dword mode only */
79 val = readl(rcba_base + 0x3404);
81 /* HPET disabled in HPTC. Trying to enable */
82 writel(val | 0x80, rcba_base + 0x3404);
85 val = readl(rcba_base + 0x3404);
89 printk(KERN_DEBUG "Force enabled HPET at resume\n");
94 static void ich_force_enable_hpet(struct pci_dev *dev)
97 u32 uninitialized_var(rcba);
100 if (hpet_address || force_hpet_address)
103 pci_read_config_dword(dev, 0xF0, &rcba);
106 dev_printk(KERN_DEBUG, &dev->dev, "RCBA disabled; "
107 "cannot force enable HPET\n");
111 /* use bits 31:14, 16 kB aligned */
112 rcba_base = ioremap_nocache(rcba, 0x4000);
113 if (rcba_base == NULL) {
114 dev_printk(KERN_DEBUG, &dev->dev, "ioremap failed; "
115 "cannot force enable HPET\n");
119 /* read the Function Disable register, dword mode only */
120 val = readl(rcba_base + 0x3404);
123 /* HPET is enabled in HPTC. Just not reported by BIOS */
125 force_hpet_address = 0xFED00000 | (val << 12);
126 dev_printk(KERN_DEBUG, &dev->dev, "Force enabled HPET at "
127 "0x%lx\n", force_hpet_address);
132 /* HPET disabled in HPTC. Trying to enable */
133 writel(val | 0x80, rcba_base + 0x3404);
135 val = readl(rcba_base + 0x3404);
140 force_hpet_address = 0xFED00000 | (val << 12);
144 force_hpet_address = 0;
146 dev_printk(KERN_DEBUG, &dev->dev,
147 "Failed to force enable HPET\n");
149 force_hpet_resume_type = ICH_FORCE_HPET_RESUME;
150 dev_printk(KERN_DEBUG, &dev->dev, "Force enabled HPET at "
151 "0x%lx\n", force_hpet_address);
155 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ESB2_0,
156 ich_force_enable_hpet);
157 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH6_0,
158 ich_force_enable_hpet);
159 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH6_1,
160 ich_force_enable_hpet);
161 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH7_0,
162 ich_force_enable_hpet);
163 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH7_1,
164 ich_force_enable_hpet);
165 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH7_31,
166 ich_force_enable_hpet);
167 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH8_1,
168 ich_force_enable_hpet);
169 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH8_4,
170 ich_force_enable_hpet);
171 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH9_7,
172 ich_force_enable_hpet);
173 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x3a16, /* ICH10 */
174 ich_force_enable_hpet);
176 static struct pci_dev *cached_dev;
178 static void hpet_print_force_info(void)
180 printk(KERN_INFO "HPET not enabled in BIOS. "
181 "You might try hpet=force boot option\n");
184 static void old_ich_force_hpet_resume(void)
187 u32 uninitialized_var(gen_cntl);
189 if (!force_hpet_address || !cached_dev)
192 pci_read_config_dword(cached_dev, 0xD0, &gen_cntl);
193 gen_cntl &= (~(0x7 << 15));
194 gen_cntl |= (0x4 << 15);
196 pci_write_config_dword(cached_dev, 0xD0, gen_cntl);
197 pci_read_config_dword(cached_dev, 0xD0, &gen_cntl);
198 val = gen_cntl >> 15;
201 printk(KERN_DEBUG "Force enabled HPET at resume\n");
206 static void old_ich_force_enable_hpet(struct pci_dev *dev)
209 u32 uninitialized_var(gen_cntl);
211 if (hpet_address || force_hpet_address)
214 pci_read_config_dword(dev, 0xD0, &gen_cntl);
216 * Bit 17 is HPET enable bit.
217 * Bit 16:15 control the HPET base address.
219 val = gen_cntl >> 15;
223 force_hpet_address = 0xFED00000 | (val << 12);
224 dev_printk(KERN_DEBUG, &dev->dev, "HPET at 0x%lx\n",
230 * HPET is disabled. Trying enabling at FED00000 and check
233 gen_cntl &= (~(0x7 << 15));
234 gen_cntl |= (0x4 << 15);
235 pci_write_config_dword(dev, 0xD0, gen_cntl);
237 pci_read_config_dword(dev, 0xD0, &gen_cntl);
239 val = gen_cntl >> 15;
242 /* HPET is enabled in HPTC. Just not reported by BIOS */
244 force_hpet_address = 0xFED00000 | (val << 12);
245 dev_printk(KERN_DEBUG, &dev->dev, "Force enabled HPET at "
246 "0x%lx\n", force_hpet_address);
248 force_hpet_resume_type = OLD_ICH_FORCE_HPET_RESUME;
252 dev_printk(KERN_DEBUG, &dev->dev, "Failed to force enable HPET\n");
256 * Undocumented chipset features. Make sure that the user enforced
259 static void old_ich_force_enable_hpet_user(struct pci_dev *dev)
262 old_ich_force_enable_hpet(dev);
265 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ESB_1,
266 old_ich_force_enable_hpet_user);
267 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_0,
268 old_ich_force_enable_hpet_user);
269 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_12,
270 old_ich_force_enable_hpet_user);
271 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_0,
272 old_ich_force_enable_hpet_user);
273 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_12,
274 old_ich_force_enable_hpet_user);
275 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801EB_0,
276 old_ich_force_enable_hpet);
277 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801EB_12,
278 old_ich_force_enable_hpet);
281 static void vt8237_force_hpet_resume(void)
285 if (!force_hpet_address || !cached_dev)
288 val = 0xfed00000 | 0x80;
289 pci_write_config_dword(cached_dev, 0x68, val);
291 pci_read_config_dword(cached_dev, 0x68, &val);
293 printk(KERN_DEBUG "Force enabled HPET at resume\n");
298 static void vt8237_force_enable_hpet(struct pci_dev *dev)
300 u32 uninitialized_var(val);
302 if (hpet_address || force_hpet_address)
305 if (!hpet_force_user) {
306 hpet_print_force_info();
310 pci_read_config_dword(dev, 0x68, &val);
312 * Bit 7 is HPET enable bit.
313 * Bit 31:10 is HPET base address (contrary to what datasheet claims)
316 force_hpet_address = (val & ~0x3ff);
317 dev_printk(KERN_DEBUG, &dev->dev, "HPET at 0x%lx\n",
323 * HPET is disabled. Trying enabling at FED00000 and check
326 val = 0xfed00000 | 0x80;
327 pci_write_config_dword(dev, 0x68, val);
329 pci_read_config_dword(dev, 0x68, &val);
331 force_hpet_address = (val & ~0x3ff);
332 dev_printk(KERN_DEBUG, &dev->dev, "Force enabled HPET at "
333 "0x%lx\n", force_hpet_address);
335 force_hpet_resume_type = VT8237_FORCE_HPET_RESUME;
339 dev_printk(KERN_DEBUG, &dev->dev, "Failed to force enable HPET\n");
342 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8235,
343 vt8237_force_enable_hpet);
344 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8237,
345 vt8237_force_enable_hpet);
346 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_CX700,
347 vt8237_force_enable_hpet);
349 static void ati_force_hpet_resume(void)
351 pci_write_config_dword(cached_dev, 0x14, 0xfed00000);
352 printk(KERN_DEBUG "Force enabled HPET at resume\n");
355 static u32 ati_ixp4x0_rev(struct pci_dev *dev)
361 err = pci_read_config_byte(dev, 0xac, &b);
363 err |= pci_write_config_byte(dev, 0xac, b);
364 err |= pci_read_config_dword(dev, 0x70, &d);
366 err |= pci_write_config_dword(dev, 0x70, d);
367 err |= pci_read_config_dword(dev, 0x8, &d);
369 dev_printk(KERN_DEBUG, &dev->dev, "SB4X0 revision 0x%x\n", d);
376 static void ati_force_enable_hpet(struct pci_dev *dev)
381 if (hpet_address || force_hpet_address)
384 if (!hpet_force_user) {
385 hpet_print_force_info();
389 d = ati_ixp4x0_rev(dev);
394 pci_write_config_dword(dev, 0x14, 0xfed00000);
395 pci_read_config_dword(dev, 0x14, &val);
397 /* enable interrupt */
398 outb(0x72, 0xcd6); b = inb(0xcd7);
400 outb(0x72, 0xcd6); outb(b, 0xcd7);
401 outb(0x72, 0xcd6); b = inb(0xcd7);
404 pci_read_config_dword(dev, 0x64, &d);
406 pci_write_config_dword(dev, 0x64, d);
407 pci_read_config_dword(dev, 0x64, &d);
411 force_hpet_address = val;
412 force_hpet_resume_type = ATI_FORCE_HPET_RESUME;
413 dev_printk(KERN_DEBUG, &dev->dev, "Force enabled HPET at 0x%lx\n",
417 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP400_SMBUS,
418 ati_force_enable_hpet);
421 * Undocumented chipset feature taken from LinuxBIOS.
423 static void nvidia_force_hpet_resume(void)
425 pci_write_config_dword(cached_dev, 0x44, 0xfed00001);
426 printk(KERN_DEBUG "Force enabled HPET at resume\n");
429 static void nvidia_force_enable_hpet(struct pci_dev *dev)
431 u32 uninitialized_var(val);
433 if (hpet_address || force_hpet_address)
436 if (!hpet_force_user) {
437 hpet_print_force_info();
441 pci_write_config_dword(dev, 0x44, 0xfed00001);
442 pci_read_config_dword(dev, 0x44, &val);
443 force_hpet_address = val & 0xfffffffe;
444 force_hpet_resume_type = NVIDIA_FORCE_HPET_RESUME;
445 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);
515 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_E6XX_CU,
516 e6xx_force_enable_hpet);
519 * HPET MSI on some boards (ATI SB700/SB800) has side effect on
520 * floppy DMA. Disable HPET MSI on such platforms.
521 * See erratum #27 (Misinterpreted MSI Requests May Result in
522 * Corrupted LPC DMA Data) in AMD Publication #46837,
523 * "SB700 Family Product Errata", Rev. 1.0, March 2010.
525 static void force_disable_hpet_msi(struct pci_dev *unused)
527 hpet_msi_disable = true;
530 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_SBX00_SMBUS,
531 force_disable_hpet_msi);
535 #if defined(CONFIG_PCI) && defined(CONFIG_NUMA)
536 /* Set correct numa_node information for AMD NB functions */
537 static void quirk_amd_nb_node(struct pci_dev *dev)
539 struct pci_dev *nb_ht;
544 devfn = PCI_DEVFN(PCI_SLOT(dev->devfn), 0);
545 nb_ht = pci_get_slot(dev->bus, devfn);
549 pci_read_config_dword(nb_ht, 0x60, &val);
550 node = pcibus_to_node(dev->bus) | (val & 7);
552 * Some hardware may return an invalid node ID,
555 if (node_online(node))
556 set_dev_node(&dev->dev, node);
560 DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_K8_NB,
562 DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_K8_NB_ADDRMAP,
564 DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_K8_NB_MEMCTL,
566 DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_K8_NB_MISC,
568 DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_10H_NB_HT,
570 DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_10H_NB_MAP,
572 DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_10H_NB_DRAM,
574 DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_10H_NB_MISC,
576 DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_10H_NB_LINK,
578 DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_15H_NB_F0,
580 DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_15H_NB_F1,
582 DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_15H_NB_F2,
584 DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_15H_NB_F3,
586 DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_15H_NB_F4,
588 DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_15H_NB_F5,
595 * Processor does not ensure DRAM scrub read/write sequence
596 * is atomic wrt accesses to CC6 save state area. Therefore
597 * if a concurrent scrub read/write access is to same address
598 * the entry may appear as if it is not written. This quirk
599 * applies to Fam16h models 00h-0Fh
601 * See "Revision Guide" for AMD F16h models 00h-0fh,
602 * document 51810 rev. 3.04, Nov 2013
604 static void amd_disable_seq_and_redirect_scrub(struct pci_dev *dev)
609 * Suggested workaround:
610 * set D18F3x58[4:0] = 00h and set D18F3x5C[0] = 0b
612 pci_read_config_dword(dev, 0x58, &val);
615 pci_write_config_dword(dev, 0x58, val);
618 pci_read_config_dword(dev, 0x5C, &val);
621 pci_write_config_dword(dev, 0x5c, val);
625 DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_16H_NB_F3,
626 amd_disable_seq_and_redirect_scrub);
630 #if defined(CONFIG_X86_64) && defined(CONFIG_X86_MCE)
631 #include <linux/jump_label.h>
632 #include <asm/string_64.h>
634 /* Ivy Bridge, Haswell, Broadwell */
635 static void quirk_intel_brickland_xeon_ras_cap(struct pci_dev *pdev)
639 pci_read_config_dword(pdev, 0x84, &capid0);
642 static_branch_inc(&mcsafe_key);
646 static void quirk_intel_purley_xeon_ras_cap(struct pci_dev *pdev)
650 pci_read_config_dword(pdev, 0x84, &capid0);
652 if ((capid0 & 0xc0) == 0xc0)
653 static_branch_inc(&mcsafe_key);
655 DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL, 0x0ec3, quirk_intel_brickland_xeon_ras_cap);
656 DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL, 0x2fc0, quirk_intel_brickland_xeon_ras_cap);
657 DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL, 0x6fc0, quirk_intel_brickland_xeon_ras_cap);
658 DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL, 0x2083, quirk_intel_purley_xeon_ras_cap);