Skip to content

Commit 06cf56e

Browse files
committed
PCI: Add pci_bus_address() to get bus address of a BAR
We store BAR information as a struct resource, which contains the CPU address, not the bus address. Drivers often need the bus address, and there's currently no convenient way to get it, so they often read the BAR directly, or use the resource address (which doesn't work if there's any translation between CPU and bus addresses). Add pci_bus_address() to make this convenient. Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
1 parent fc27985 commit 06cf56e

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

include/linux/pci.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1077,6 +1077,14 @@ int __must_check pci_bus_alloc_resource(struct pci_bus *bus,
10771077
resource_size_t),
10781078
void *alignf_data);
10791079

1080+
static inline dma_addr_t pci_bus_address(struct pci_dev *pdev, int bar)
1081+
{
1082+
struct pci_bus_region region;
1083+
1084+
pcibios_resource_to_bus(pdev->bus, &region, &pdev->resource[bar]);
1085+
return region.start;
1086+
}
1087+
10801088
/* Proper probing supporting hot-pluggable devices */
10811089
int __must_check __pci_register_driver(struct pci_driver *, struct module *,
10821090
const char *mod_name);

0 commit comments

Comments
 (0)