diff options
-rw-r--r-- | api/vfio_api.c | 23 | ||||
-rw-r--r-- | include/vfio_api.h | 1 | ||||
-rw-r--r-- | src/userspace_io.c | 4 |
3 files changed, 28 insertions, 0 deletions
diff --git a/api/vfio_api.c b/api/vfio_api.c index dbe8a64..b7cdc21 100644 --- a/api/vfio_api.c +++ b/api/vfio_api.c @@ -322,6 +322,29 @@ int iomem_alloc_dma(int device, unsigned int size, void **iomem_current, return 0; } +int iomem_free_dma(int device, struct iomem *iomem) +{ + struct vfio_iommu_type1_dma_unmap dma_unmap; + int ret; + + memset(&dma_unmap, 0, sizeof(dma_unmap)); + dma_unmap.argsz = sizeof(dma_unmap); + dma_unmap.iova = iomem->iova; + dma_unmap.size = iomem->size; + dma_unmap.flags = VFIO_DMA_MAP_FLAG_READ | VFIO_DMA_MAP_FLAG_WRITE; + + printf("iomem_free: VA(%llx) -> physmem(%lldKB) <- IOVA(%llx)\n", + iomem->vaddr, iomem->size/1024, iomem->iova); + + ret = ioctl(device, VFIO_IOMMU_UNMAP_DMA, &dma_unmap); + if (ret < 0) { + printf("iomem_free: unmap failed\n"); + return -EFAULT; + } + + return 0; +} + /** * Initialize VFIO variables. * set IOMMU and get device regions diff --git a/include/vfio_api.h b/include/vfio_api.h index 9b2399a..e567824 100644 --- a/include/vfio_api.h +++ b/include/vfio_api.h @@ -12,4 +12,5 @@ int vfio_get_region(int device, struct vfio_region_info *reg_info, __u32 region) void *vfio_mmap_region(int device, __u32 region, size_t *len); int iomem_alloc_dma(int device, unsigned int size, void **iomem_curent, struct iomem *iomem); +int iomem_free_dma(int device, struct iomem *iomem); #endif diff --git a/src/userspace_io.c b/src/userspace_io.c index 1ca7a6a..f8a617a 100644 --- a/src/userspace_io.c +++ b/src/userspace_io.c @@ -168,9 +168,13 @@ int main(int argc, char *argv[]) } ioctl(device, 500, NULL); + uio_xmit(exec_ops, txring, tx_data, mmio); uio_recv(exec_ops, rxring, rx_buff, mmio); + iomem_free_dma(device, &tx_data); + iomem_free_dma(device, &rx_data); + out: if (iobase) iomem_free(iobase); |