env_dpdk: add dpdk_pci_device_vtophys()

This moves the only references to the rte_pci_device
data structure from memory.c to pci.c.  This helps
prepare SPDK for possible changes to DPDK around
visibility of these DPDK data structures, making it
easier for SPDK to manage if only one file is
affected.

Signed-off-by: Jim Harris <james.r.harris@intel.com>
Change-Id: I26b1907fabd7a6c23701523811abd1ce12606683
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/14530
Community-CI: Mellanox Build Bot
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Changpeng Liu <changpeng.liu@intel.com>
Reviewed-by: Aleksey Marchuk <alexeymar@nvidia.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
This commit is contained in:
Jim Harris 2022-09-15 13:30:38 +00:00 committed by Tomasz Zawadzki
parent 92e63a9cc6
commit 2bb7185f1b
4 changed files with 26 additions and 13 deletions

View File

@ -52,6 +52,8 @@ void pci_env_fini(void);
int mem_map_init(bool legacy_mem); int mem_map_init(bool legacy_mem);
int vtophys_init(void); int vtophys_init(void);
uint64_t dpdk_pci_device_vtophys(struct rte_pci_device *dev, uint64_t vaddr);
/** /**
* Report a DMA-capable PCI device to the vtophys translation code. * Report a DMA-capable PCI device to the vtophys translation code.
* Increases the refcount of active DMA-capable devices managed by SPDK. * Increases the refcount of active DMA-capable devices managed by SPDK.

View File

@ -930,25 +930,16 @@ vtophys_get_paddr_pci(uint64_t vaddr)
struct spdk_vtophys_pci_device *vtophys_dev; struct spdk_vtophys_pci_device *vtophys_dev;
uintptr_t paddr; uintptr_t paddr;
struct rte_pci_device *dev; struct rte_pci_device *dev;
struct rte_mem_resource *res;
unsigned r;
pthread_mutex_lock(&g_vtophys_pci_devices_mutex); pthread_mutex_lock(&g_vtophys_pci_devices_mutex);
TAILQ_FOREACH(vtophys_dev, &g_vtophys_pci_devices, tailq) { TAILQ_FOREACH(vtophys_dev, &g_vtophys_pci_devices, tailq) {
dev = vtophys_dev->pci_device; dev = vtophys_dev->pci_device;
paddr = dpdk_pci_device_vtophys(dev, vaddr);
for (r = 0; r < PCI_MAX_RESOURCE; r++) { if (paddr != SPDK_VTOPHYS_ERROR) {
res = &dev->mem_resource[r];
if (res->phys_addr && vaddr >= (uint64_t)res->addr &&
vaddr < (uint64_t)res->addr + res->len) {
paddr = res->phys_addr + (vaddr - (uint64_t)res->addr);
DEBUG_PRINT("%s: %p -> %p\n", __func__, (void *)vaddr,
(void *)paddr);
pthread_mutex_unlock(&g_vtophys_pci_devices_mutex); pthread_mutex_unlock(&g_vtophys_pci_devices_mutex);
return paddr; return paddr;
} }
} }
}
pthread_mutex_unlock(&g_vtophys_pci_devices_mutex); pthread_mutex_unlock(&g_vtophys_pci_devices_mutex);
return SPDK_VTOPHYS_ERROR; return SPDK_VTOPHYS_ERROR;

View File

@ -1232,3 +1232,22 @@ spdk_pci_device_allow(struct spdk_pci_addr *pci_addr)
return 0; return 0;
} }
uint64_t
dpdk_pci_device_vtophys(struct rte_pci_device *dev, uint64_t vaddr)
{
struct rte_mem_resource *res;
uint64_t paddr;
unsigned r;
for (r = 0; r < PCI_MAX_RESOURCE; r++) {
res = &dev->mem_resource[r];
if (res->phys_addr && vaddr >= (uint64_t)res->addr &&
vaddr < (uint64_t)res->addr + res->len) {
paddr = res->phys_addr + (vaddr - (uint64_t)res->addr);
return paddr;
}
}
return SPDK_VTOPHYS_ERROR;
}

View File

@ -29,6 +29,7 @@ DEFINE_STUB(rte_vfio_noiommu_is_enabled, int, (void), 0);
DEFINE_STUB(rte_memseg_get_fd_thread_unsafe, int, (const struct rte_memseg *ms), 0); DEFINE_STUB(rte_memseg_get_fd_thread_unsafe, int, (const struct rte_memseg *ms), 0);
DEFINE_STUB(rte_memseg_get_fd_offset_thread_unsafe, int, DEFINE_STUB(rte_memseg_get_fd_offset_thread_unsafe, int,
(const struct rte_memseg *ms, size_t *offset), 0); (const struct rte_memseg *ms, size_t *offset), 0);
DEFINE_STUB(dpdk_pci_device_vtophys, uint64_t, (struct rte_pci_device *dev, uint64_t vaddr), 0);
static int static int
test_mem_map_notify(void *cb_ctx, struct spdk_mem_map *map, test_mem_map_notify(void *cb_ctx, struct spdk_mem_map *map,