2 * mmconfig.c - Low-level direct PCI config space access via MMCONFIG
4 * This is an 64bit optimized version that always keeps the full mmconfig
5 * space mapped. This allows lockless config space operation.
9 #include <linux/init.h>
12 #define MMCONFIG_APER_SIZE (256*1024*1024)
14 /* The physical address of the MMCONFIG aperture. Set from ACPI tables. */
15 u32 pci_mmcfg_base_addr;
17 /* Static virtual mapping of the MMCONFIG aperture */
20 static inline char *pci_dev_base(int bus, int devfn)
22 return pci_mmcfg_virt + ((bus << 20) | (devfn << 12));
25 static int pci_mmcfg_read(int seg, int bus, int devfn, int reg, int len, u32 *value)
27 char *addr = pci_dev_base(bus, devfn);
29 if (unlikely(!value || (bus > 255) || (devfn > 255) || (reg > 4095)))
34 *value = readb(addr + reg);
37 *value = readw(addr + reg);
40 *value = readl(addr + reg);
47 static int pci_mmcfg_write(int seg, int bus, int devfn, int reg, int len, u32 value)
49 char *addr = pci_dev_base(bus,devfn);
51 if (unlikely((bus > 255) || (devfn > 255) || (reg > 4095)))
56 writeb(value, addr + reg);
59 writew(value, addr + reg);
62 writel(value, addr + reg);
66 /* Dummy read to flush PCI write */
72 static struct pci_raw_ops pci_mmcfg = {
73 .read = pci_mmcfg_read,
74 .write = pci_mmcfg_write,
77 static int __init pci_mmcfg_init(void)
79 if ((pci_probe & PCI_PROBE_MMCONF) == 0)
81 if (!pci_mmcfg_base_addr)
84 /* RED-PEN i386 doesn't do _nocache right now */
85 pci_mmcfg_virt = ioremap_nocache(pci_mmcfg_base_addr, MMCONFIG_APER_SIZE);
86 if (!pci_mmcfg_virt) {
87 printk("PCI: Cannot map mmconfig aperture\n");
91 printk(KERN_INFO "PCI: Using MMCONFIG at %x\n", pci_mmcfg_base_addr);
92 raw_pci_ops = &pci_mmcfg;
93 pci_probe = (pci_probe & ~PCI_PROBE_MASK) | PCI_PROBE_MMCONF;
98 arch_initcall(pci_mmcfg_init);