Skip to content

Commit fa564ad

Browse files
ChristianKoenigAMDbjorn-helgaas
authored andcommitted
x86/PCI: Enable a 64bit BAR on AMD Family 15h (Models 00-1f, 30-3f, 60-7f)
Manually enable a 64GB 64-bit BAR so we have enough room for graphics devices with large framebuffers. Most BIOSes don't enable this for compatibility reasons. Signed-off-by: Christian König <[email protected]> Signed-off-by: Bjorn Helgaas <[email protected]> Reviewed-by: Andy Shevchenko <[email protected]>
1 parent 8bb705e commit fa564ad

File tree

1 file changed

+85
-0
lines changed

1 file changed

+85
-0
lines changed

arch/x86/pci/fixup.c

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -635,3 +635,88 @@ DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL, 0x2030, quirk_no_aersid);
635635
DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL, 0x2031, quirk_no_aersid);
636636
DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL, 0x2032, quirk_no_aersid);
637637
DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL, 0x2033, quirk_no_aersid);
638+
639+
#ifdef CONFIG_PHYS_ADDR_T_64BIT
640+
641+
#define AMD_141b_MMIO_BASE(x) (0x80 + (x) * 0x8)
642+
#define AMD_141b_MMIO_BASE_RE_MASK BIT(0)
643+
#define AMD_141b_MMIO_BASE_WE_MASK BIT(1)
644+
#define AMD_141b_MMIO_BASE_MMIOBASE_MASK GENMASK(31,8)
645+
646+
#define AMD_141b_MMIO_LIMIT(x) (0x84 + (x) * 0x8)
647+
#define AMD_141b_MMIO_LIMIT_MMIOLIMIT_MASK GENMASK(31,8)
648+
649+
#define AMD_141b_MMIO_HIGH(x) (0x180 + (x) * 0x4)
650+
#define AMD_141b_MMIO_HIGH_MMIOBASE_MASK GENMASK(7,0)
651+
#define AMD_141b_MMIO_HIGH_MMIOLIMIT_SHIFT 16
652+
#define AMD_141b_MMIO_HIGH_MMIOLIMIT_MASK GENMASK(23,16)
653+
654+
/*
655+
* The PCI Firmware Spec, rev 3.2, notes that ACPI should optionally allow
656+
* configuring host bridge windows using the _PRS and _SRS methods.
657+
*
658+
* But this is rarely implemented, so we manually enable a large 64bit BAR for
659+
* PCIe device on AMD Family 15h (Models 00h-1fh, 30h-3fh, 60h-7fh) Processors
660+
* here.
661+
*/
662+
static void pci_amd_enable_64bit_bar(struct pci_dev *dev)
663+
{
664+
unsigned i;
665+
u32 base, limit, high;
666+
struct resource *res, *conflict;
667+
668+
for (i = 0; i < 8; i++) {
669+
pci_read_config_dword(dev, AMD_141b_MMIO_BASE(i), &base);
670+
pci_read_config_dword(dev, AMD_141b_MMIO_HIGH(i), &high);
671+
672+
/* Is this slot free? */
673+
if (!(base & (AMD_141b_MMIO_BASE_RE_MASK |
674+
AMD_141b_MMIO_BASE_WE_MASK)))
675+
break;
676+
677+
base >>= 8;
678+
base |= high << 24;
679+
680+
/* Abort if a slot already configures a 64bit BAR. */
681+
if (base > 0x10000)
682+
return;
683+
}
684+
if (i == 8)
685+
return;
686+
687+
res = kzalloc(sizeof(*res), GFP_KERNEL);
688+
if (!res)
689+
return;
690+
691+
res->name = "PCI Bus 0000:00";
692+
res->flags = IORESOURCE_PREFETCH | IORESOURCE_MEM |
693+
IORESOURCE_MEM_64 | IORESOURCE_WINDOW;
694+
res->start = 0x100000000ull;
695+
res->end = 0xfd00000000ull - 1;
696+
697+
/* Just grab the free area behind system memory for this */
698+
while ((conflict = request_resource_conflict(&iomem_resource, res)))
699+
res->start = conflict->end + 1;
700+
701+
dev_info(&dev->dev, "adding root bus resource %pR\n", res);
702+
703+
base = ((res->start >> 8) & AMD_141b_MMIO_BASE_MMIOBASE_MASK) |
704+
AMD_141b_MMIO_BASE_RE_MASK | AMD_141b_MMIO_BASE_WE_MASK;
705+
limit = ((res->end + 1) >> 8) & AMD_141b_MMIO_LIMIT_MMIOLIMIT_MASK;
706+
high = ((res->start >> 40) & AMD_141b_MMIO_HIGH_MMIOBASE_MASK) |
707+
((((res->end + 1) >> 40) << AMD_141b_MMIO_HIGH_MMIOLIMIT_SHIFT)
708+
& AMD_141b_MMIO_HIGH_MMIOLIMIT_MASK);
709+
710+
pci_write_config_dword(dev, AMD_141b_MMIO_HIGH(i), high);
711+
pci_write_config_dword(dev, AMD_141b_MMIO_LIMIT(i), limit);
712+
pci_write_config_dword(dev, AMD_141b_MMIO_BASE(i), base);
713+
714+
pci_bus_add_resource(dev->bus, res, 0);
715+
}
716+
DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_AMD, 0x1401, pci_amd_enable_64bit_bar);
717+
DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_AMD, 0x141b, pci_amd_enable_64bit_bar);
718+
DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_AMD, 0x1571, pci_amd_enable_64bit_bar);
719+
DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_AMD, 0x15b1, pci_amd_enable_64bit_bar);
720+
DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_AMD, 0x1601, pci_amd_enable_64bit_bar);
721+
722+
#endif

0 commit comments

Comments
 (0)