[PATCH] PCI: use the MCFG table to properly access pci devices (x86-64)

Now that we have access to the whole MCFG table, let's properly use it
for all pci device accesses (as that's what it is there for, some boxes
don't put all the busses into one entry.)

If, for some reason, the table is incorrect, we fallback to the "old
style" of mmconfig accesses, namely, we just assume the first entry in
the table is the one for us, and blindly use it.

Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

+48 -10
+48 -10
arch/x86_64/pci/mmconfig.c
··· 13 #define MMCONFIG_APER_SIZE (256*1024*1024) 14 15 /* Static virtual mapping of the MMCONFIG aperture */ 16 - static char *pci_mmcfg_virt; 17 18 - static inline char *pci_dev_base(unsigned int bus, unsigned int devfn) 19 { 20 - return pci_mmcfg_virt + ((bus << 20) | (devfn << 12)); 21 } 22 23 static int pci_mmcfg_read(unsigned int seg, unsigned int bus, 24 unsigned int devfn, int reg, int len, u32 *value) 25 { 26 - char *addr = pci_dev_base(bus, devfn); 27 28 if (unlikely(!value || (bus > 255) || (devfn > 255) || (reg > 4095))) 29 return -EINVAL; ··· 73 static int pci_mmcfg_write(unsigned int seg, unsigned int bus, 74 unsigned int devfn, int reg, int len, u32 value) 75 { 76 - char *addr = pci_dev_base(bus,devfn); 77 78 if (unlikely((bus > 255) || (devfn > 255) || (reg > 4095))) 79 return -EINVAL; ··· 100 101 static int __init pci_mmcfg_init(void) 102 { 103 if ((pci_probe & PCI_PROBE_MMCONF) == 0) 104 return 0; 105 ··· 119 return 0; 120 121 /* RED-PEN i386 doesn't do _nocache right now */ 122 - pci_mmcfg_virt = ioremap_nocache(pci_mmcfg_config[0].base_address, MMCONFIG_APER_SIZE); 123 - if (!pci_mmcfg_virt) { 124 - printk("PCI: Cannot map mmconfig aperture\n"); 125 return 0; 126 - } 127 128 - printk(KERN_INFO "PCI: Using MMCONFIG at %x\n", pci_mmcfg_config[0].base_address); 129 raw_pci_ops = &pci_mmcfg; 130 pci_probe = (pci_probe & ~PCI_PROBE_MASK) | PCI_PROBE_MMCONF; 131
··· 13 #define MMCONFIG_APER_SIZE (256*1024*1024) 14 15 /* Static virtual mapping of the MMCONFIG aperture */ 16 + struct mmcfg_virt { 17 + struct acpi_table_mcfg_config *cfg; 18 + char *virt; 19 + }; 20 + static struct mmcfg_virt *pci_mmcfg_virt; 21 22 + static char *get_virt(unsigned int seg, int bus) 23 { 24 + int cfg_num = -1; 25 + struct acpi_table_mcfg_config *cfg; 26 + 27 + while (1) { 28 + ++cfg_num; 29 + if (cfg_num >= pci_mmcfg_config_num) { 30 + /* something bad is going on, no cfg table is found. */ 31 + /* so we fall back to the old way we used to do this */ 32 + /* and just rely on the first entry to be correct. */ 33 + return pci_mmcfg_virt[0].virt; 34 + } 35 + cfg = pci_mmcfg_virt[cfg_num].cfg; 36 + if (cfg->pci_segment_group_number != seg) 37 + continue; 38 + if ((cfg->start_bus_number <= bus) && 39 + (cfg->end_bus_number >= bus)) 40 + return pci_mmcfg_virt[cfg_num].virt; 41 + } 42 + } 43 + 44 + static inline char *pci_dev_base(unsigned int seg, unsigned int bus, unsigned int devfn) 45 + { 46 + 47 + return get_virt(seg, bus) + ((bus << 20) | (devfn << 12)); 48 } 49 50 static int pci_mmcfg_read(unsigned int seg, unsigned int bus, 51 unsigned int devfn, int reg, int len, u32 *value) 52 { 53 + char *addr = pci_dev_base(seg, bus, devfn); 54 55 if (unlikely(!value || (bus > 255) || (devfn > 255) || (reg > 4095))) 56 return -EINVAL; ··· 46 static int pci_mmcfg_write(unsigned int seg, unsigned int bus, 47 unsigned int devfn, int reg, int len, u32 value) 48 { 49 + char *addr = pci_dev_base(seg, bus, devfn); 50 51 if (unlikely((bus > 255) || (devfn > 255) || (reg > 4095))) 52 return -EINVAL; ··· 73 74 static int __init pci_mmcfg_init(void) 75 { 76 + int i; 77 + 78 if ((pci_probe & PCI_PROBE_MMCONF) == 0) 79 return 0; 80 ··· 90 return 0; 91 92 /* RED-PEN i386 doesn't do _nocache right now */ 93 + pci_mmcfg_virt = kmalloc(sizeof(*pci_mmcfg_virt) * pci_mmcfg_config_num, GFP_KERNEL); 94 + if (pci_mmcfg_virt == NULL) { 95 + printk("PCI: Can not allocate memory for mmconfig structures\n"); 96 return 0; 97 + } 98 + for (i = 0; i < pci_mmcfg_config_num; ++i) { 99 + pci_mmcfg_virt[i].cfg = &pci_mmcfg_config[i]; 100 + pci_mmcfg_virt[i].virt = ioremap_nocache(pci_mmcfg_config[i].base_address, MMCONFIG_APER_SIZE); 101 + if (!pci_mmcfg_virt[i].virt) { 102 + printk("PCI: Cannot map mmconfig aperture for segment %d\n", 103 + pci_mmcfg_config[i].pci_segment_group_number); 104 + return 0; 105 + } 106 + printk(KERN_INFO "PCI: Using MMCONFIG at %x\n", pci_mmcfg_config[i].base_address); 107 + } 108 109 raw_pci_ops = &pci_mmcfg; 110 pci_probe = (pci_probe & ~PCI_PROBE_MASK) | PCI_PROBE_MMCONF; 111