Commit 613e7ed6 authored by Yu Zhao's avatar Yu Zhao Committed by Jesse Barnes

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: default avatarYu Zhao <yu.zhao@intel.com>
Signed-off-by: default avatarJesse Barnes <jbarnes@virtuousgeek.org>
parent 3789fa8a
...@@ -2201,6 +2201,28 @@ int pci_select_bars(struct pci_dev *dev, unsigned long flags) ...@@ -2201,6 +2201,28 @@ int pci_select_bars(struct pci_dev *dev, unsigned long flags)
return bars; return bars;
} }
/**
* pci_resource_bar - get position of the BAR associated with a resource
* @dev: the PCI device
* @resno: the resource number
* @type: the BAR type to be filled in
*
* Returns BAR position in config space, or 0 if the BAR is invalid.
*/
int pci_resource_bar(struct pci_dev *dev, int resno, enum pci_bar_type *type)
{
if (resno < PCI_ROM_RESOURCE) {
*type = pci_bar_unknown;
return PCI_BASE_ADDRESS_0 + 4 * resno;
} else if (resno == PCI_ROM_RESOURCE) {
*type = pci_bar_mem32;
return dev->rom_base_reg;
}
dev_err(&dev->dev, "BAR: invalid resource #%d\n", resno);
return 0;
}
static void __devinit pci_no_domains(void) static void __devinit pci_no_domains(void)
{ {
#ifdef CONFIG_PCI_DOMAINS #ifdef CONFIG_PCI_DOMAINS
......
...@@ -171,6 +171,8 @@ enum pci_bar_type { ...@@ -171,6 +171,8 @@ enum pci_bar_type {
extern int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type, extern int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
struct resource *res, unsigned int reg); struct resource *res, unsigned int reg);
extern int pci_resource_bar(struct pci_dev *dev, int resno,
enum pci_bar_type *type);
extern void pci_enable_ari(struct pci_dev *dev); extern void pci_enable_ari(struct pci_dev *dev);
/** /**
* pci_ari_enabled - query ARI forwarding status * pci_ari_enabled - query ARI forwarding status
......
...@@ -31,6 +31,7 @@ void pci_update_resource(struct pci_dev *dev, int resno) ...@@ -31,6 +31,7 @@ void pci_update_resource(struct pci_dev *dev, int resno)
struct pci_bus_region region; struct pci_bus_region region;
u32 new, check, mask; u32 new, check, mask;
int reg; int reg;
enum pci_bar_type type;
struct resource *res = dev->resource + resno; struct resource *res = dev->resource + resno;
/* /*
...@@ -62,17 +63,13 @@ void pci_update_resource(struct pci_dev *dev, int resno) ...@@ -62,17 +63,13 @@ void pci_update_resource(struct pci_dev *dev, int resno)
else else
mask = (u32)PCI_BASE_ADDRESS_MEM_MASK; mask = (u32)PCI_BASE_ADDRESS_MEM_MASK;
if (resno < 6) { reg = pci_resource_bar(dev, resno, &type);
reg = PCI_BASE_ADDRESS_0 + 4 * resno; if (!reg)
} else if (resno == PCI_ROM_RESOURCE) { return;
if (type != pci_bar_unknown) {
if (!(res->flags & IORESOURCE_ROM_ENABLE)) if (!(res->flags & IORESOURCE_ROM_ENABLE))
return; return;
new |= PCI_ROM_ADDRESS_ENABLE; new |= PCI_ROM_ADDRESS_ENABLE;
reg = dev->rom_base_reg;
} else {
/* Hmm, non-standard resource. */
return; /* kill uninitialised var warning */
} }
pci_write_config_dword(dev, reg, new); pci_write_config_dword(dev, reg, new);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment