diff options
author | Yu Zhao <yu.zhao@intel.com> | 2008-11-21 13:41:27 -0500 |
---|---|---|
committer | Jesse Barnes <jbarnes@virtuousgeek.org> | 2009-01-07 14:13:04 -0500 |
commit | 613e7ed6f72b1a115f7ece8ce1b66cf095de1348 (patch) | |
tree | 2af16f01cbf78f1de6b858788091a72fa57af6c8 /drivers | |
parent | 3789fa8a2e534523c896a32a9f27f78d52ad7d82 (diff) |
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>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/pci/pci.c | 22 | ||||
-rw-r--r-- | drivers/pci/pci.h | 2 | ||||
-rw-r--r-- | drivers/pci/setup-res.c | 13 |
3 files changed, 29 insertions, 8 deletions
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index deeab19d7d10..7e9c0f3936dd 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c | |||
@@ -2201,6 +2201,28 @@ int pci_select_bars(struct pci_dev *dev, unsigned long flags) | |||
2201 | return bars; | 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 | static void __devinit pci_no_domains(void) | 2226 | static void __devinit pci_no_domains(void) |
2205 | { | 2227 | { |
2206 | #ifdef CONFIG_PCI_DOMAINS | 2228 | #ifdef CONFIG_PCI_DOMAINS |
diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h index d881fde8bb82..c4f4a1e6ea28 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h | |||
@@ -171,6 +171,8 @@ enum pci_bar_type { | |||
171 | 171 | ||
172 | extern int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type, | 172 | extern int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type, |
173 | struct resource *res, unsigned int reg); | 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 | extern void pci_enable_ari(struct pci_dev *dev); | 176 | extern void pci_enable_ari(struct pci_dev *dev); |
175 | /** | 177 | /** |
176 | * pci_ari_enabled - query ARI forwarding status | 178 | * pci_ari_enabled - query ARI forwarding status |
diff --git a/drivers/pci/setup-res.c b/drivers/pci/setup-res.c index 3c5203ff53c7..32e8d88a4619 100644 --- a/drivers/pci/setup-res.c +++ b/drivers/pci/setup-res.c | |||
@@ -31,6 +31,7 @@ void pci_update_resource(struct pci_dev *dev, int resno) | |||
31 | struct pci_bus_region region; | 31 | struct pci_bus_region region; |
32 | u32 new, check, mask; | 32 | u32 new, check, mask; |
33 | int reg; | 33 | int reg; |
34 | enum pci_bar_type type; | ||
34 | struct resource *res = dev->resource + resno; | 35 | struct resource *res = dev->resource + resno; |
35 | 36 | ||
36 | /* | 37 | /* |
@@ -62,17 +63,13 @@ void pci_update_resource(struct pci_dev *dev, int resno) | |||
62 | else | 63 | else |
63 | mask = (u32)PCI_BASE_ADDRESS_MEM_MASK; | 64 | mask = (u32)PCI_BASE_ADDRESS_MEM_MASK; |
64 | 65 | ||
65 | if (resno < 6) { | 66 | reg = pci_resource_bar(dev, resno, &type); |
66 | reg = PCI_BASE_ADDRESS_0 + 4 * resno; | 67 | if (!reg) |
67 | } else if (resno == PCI_ROM_RESOURCE) { | 68 | return; |
69 | if (type != pci_bar_unknown) { | ||
68 | if (!(res->flags & IORESOURCE_ROM_ENABLE)) | 70 | if (!(res->flags & IORESOURCE_ROM_ENABLE)) |
69 | return; | 71 | return; |
70 | new |= PCI_ROM_ADDRESS_ENABLE; | 72 | new |= PCI_ROM_ADDRESS_ENABLE; |
71 | reg = dev->rom_base_reg; | ||
72 | } else { | ||
73 | /* Hmm, non-standard resource. */ | ||
74 | |||
75 | return; /* kill uninitialised var warning */ | ||
76 | } | 73 | } |
77 | 74 | ||
78 | pci_write_config_dword(dev, reg, new); | 75 | pci_write_config_dword(dev, reg, new); |