2 * mmconfig.c - Low-level direct PCI config space access via MMCONFIG
6 #include <linux/init.h>
9 /* The physical address of the MMCONFIG aperture. Set from ACPI tables. */
10 u32 pci_mmcfg_base_addr;
12 #define mmcfg_virt_addr (fix_to_virt(FIX_PCIE_MCFG))
14 /* The base address of the last MMCONFIG device accessed */
15 static u32 mmcfg_last_accessed_device;
18 * Functions for accessing PCI configuration space with MMCONFIG accesses
21 static inline void pci_exp_set_dev_base(int bus, int devfn)
23 u32 dev_base = pci_mmcfg_base_addr | (bus << 20) | (devfn << 12);
24 if (dev_base != mmcfg_last_accessed_device) {
25 mmcfg_last_accessed_device = dev_base;
26 set_fixmap(FIX_PCIE_MCFG, dev_base);
30 static int pci_mmcfg_read(int seg, int bus, int devfn, int reg, int len, u32 *value)
34 if (!value || (bus > 255) || (devfn > 255) || (reg > 4095))
37 spin_lock_irqsave(&pci_config_lock, flags);
39 pci_exp_set_dev_base(bus, devfn);
43 *value = readb(mmcfg_virt_addr + reg);
46 *value = readw(mmcfg_virt_addr + reg);
49 *value = readl(mmcfg_virt_addr + reg);
53 spin_unlock_irqrestore(&pci_config_lock, flags);
58 static int pci_mmcfg_write(int seg, int bus, int devfn, int reg, int len, u32 value)
62 if ((bus > 255) || (devfn > 255) || (reg > 4095))
65 spin_lock_irqsave(&pci_config_lock, flags);
67 pci_exp_set_dev_base(bus, devfn);
71 writeb(value, mmcfg_virt_addr + reg);
74 writew(value, mmcfg_virt_addr + reg);
77 writel(value, mmcfg_virt_addr + reg);
81 /* Dummy read to flush PCI write */
82 readl(mmcfg_virt_addr);
84 spin_unlock_irqrestore(&pci_config_lock, flags);
89 static struct pci_raw_ops pci_mmcfg = {
90 .read = pci_mmcfg_read,
91 .write = pci_mmcfg_write,
94 static int __init pci_mmcfg_init(void)
96 if ((pci_probe & PCI_PROBE_MMCONF) == 0)
98 if (!pci_mmcfg_base_addr)
101 printk(KERN_INFO "PCI: Using MMCONFIG\n");
102 raw_pci_ops = &pci_mmcfg;
103 pci_probe = (pci_probe & ~PCI_PROBE_MASK) | PCI_PROBE_MMCONF;
109 arch_initcall(pci_mmcfg_init);