Commit 2bb7185f authored by Jim Harris's avatar Jim Harris Committed by Tomasz Zawadzki
Browse files

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: default avatarJim 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: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarChangpeng Liu <changpeng.liu@intel.com>
Reviewed-by: default avatarAleksey Marchuk <alexeymar@nvidia.com>
Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
parent 92e63a9c
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -52,6 +52,8 @@ void pci_env_fini(void);
int mem_map_init(bool legacy_mem);
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.
 * Increases the refcount of active DMA-capable devices managed by SPDK.
+4 −13
Original line number Diff line number Diff line
@@ -930,25 +930,16 @@ vtophys_get_paddr_pci(uint64_t vaddr)
	struct spdk_vtophys_pci_device *vtophys_dev;
	uintptr_t paddr;
	struct rte_pci_device	*dev;
	struct rte_mem_resource *res;
	unsigned r;

	pthread_mutex_lock(&g_vtophys_pci_devices_mutex);
	TAILQ_FOREACH(vtophys_dev, &g_vtophys_pci_devices, tailq) {
		dev = vtophys_dev->pci_device;

		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);
				DEBUG_PRINT("%s: %p -> %p\n", __func__, (void *)vaddr,
					    (void *)paddr);
		paddr = dpdk_pci_device_vtophys(dev, vaddr);
		if (paddr != SPDK_VTOPHYS_ERROR) {
			pthread_mutex_unlock(&g_vtophys_pci_devices_mutex);
			return paddr;
		}
	}
	}
	pthread_mutex_unlock(&g_vtophys_pci_devices_mutex);

	return  SPDK_VTOPHYS_ERROR;
+19 −0
Original line number Diff line number Diff line
@@ -1232,3 +1232,22 @@ spdk_pci_device_allow(struct spdk_pci_addr *pci_addr)

	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;
}
+1 −0
Original line number Diff line number Diff line
@@ -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_offset_thread_unsafe, int,
	    (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
test_mem_map_notify(void *cb_ctx, struct spdk_mem_map *map,