Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

PCI: add a new function to map BAR offsets

Add a function to map a given resource number to a corresponding
register so drivers can get the offset and type of device specific BARs.

Signed-off-by: Yu Zhao <yu.zhao@intel.com>
Signed-off-by: Jesse Barnes <jbarnes@virtuousgeek.org>

authored by

Yu Zhao and committed by
Jesse Barnes
613e7ed6 3789fa8a

+29 -8
+22
drivers/pci/pci.c
··· 2201 2201 return bars; 2202 2202 } 2203 2203 2204 + /** 2205 + * pci_resource_bar - get position of the BAR associated with a resource 2206 + * @dev: the PCI device 2207 + * @resno: the resource number 2208 + * @type: the BAR type to be filled in 2209 + * 2210 + * Returns BAR position in config space, or 0 if the BAR is invalid. 2211 + */ 2212 + int pci_resource_bar(struct pci_dev *dev, int resno, enum pci_bar_type *type) 2213 + { 2214 + if (resno < PCI_ROM_RESOURCE) { 2215 + *type = pci_bar_unknown; 2216 + return PCI_BASE_ADDRESS_0 + 4 * resno; 2217 + } else if (resno == PCI_ROM_RESOURCE) { 2218 + *type = pci_bar_mem32; 2219 + return dev->rom_base_reg; 2220 + } 2221 + 2222 + dev_err(&dev->dev, "BAR: invalid resource #%d\n", resno); 2223 + return 0; 2224 + } 2225 + 2204 2226 static void __devinit pci_no_domains(void) 2205 2227 { 2206 2228 #ifdef CONFIG_PCI_DOMAINS
+2
drivers/pci/pci.h
··· 171 171 172 172 extern int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type, 173 173 struct resource *res, unsigned int reg); 174 + extern int pci_resource_bar(struct pci_dev *dev, int resno, 175 + enum pci_bar_type *type); 174 176 extern void pci_enable_ari(struct pci_dev *dev); 175 177 /** 176 178 * pci_ari_enabled - query ARI forwarding status
+5 -8
drivers/pci/setup-res.c
··· 31 31 struct pci_bus_region region; 32 32 u32 new, check, mask; 33 33 int reg; 34 + enum pci_bar_type type; 34 35 struct resource *res = dev->resource + resno; 35 36 36 37 /* ··· 63 62 else 64 63 mask = (u32)PCI_BASE_ADDRESS_MEM_MASK; 65 64 66 - if (resno < 6) { 67 - reg = PCI_BASE_ADDRESS_0 + 4 * resno; 68 - } else if (resno == PCI_ROM_RESOURCE) { 65 + reg = pci_resource_bar(dev, resno, &type); 66 + if (!reg) 67 + return; 68 + if (type != pci_bar_unknown) { 69 69 if (!(res->flags & IORESOURCE_ROM_ENABLE)) 70 70 return; 71 71 new |= PCI_ROM_ADDRESS_ENABLE; 72 - reg = dev->rom_base_reg; 73 - } else { 74 - /* Hmm, non-standard resource. */ 75 - 76 - return; /* kill uninitialised var warning */ 77 72 } 78 73 79 74 pci_write_config_dword(dev, reg, new);