From 035c6f8b2a7798a0ddcf15f597028b876a38f036 Mon Sep 17 00:00:00 2001 From: Daniel Krebs Date: Tue, 13 Feb 2018 10:29:16 +0100 Subject: [PATCH] lib/kernel/vfio: add function to get size of device memory region --- fpga/include/villas/kernel/vfio.h | 3 +++ fpga/lib/kernel/vfio.c | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/fpga/include/villas/kernel/vfio.h b/fpga/include/villas/kernel/vfio.h index 1b4a9c336..35a2465f9 100644 --- a/fpga/include/villas/kernel/vfio.h +++ b/fpga/include/villas/kernel/vfio.h @@ -104,6 +104,9 @@ void vfio_dump(struct vfio_container *c); /** Map a device memory region to the application address space (e.g. PCI BARs) */ void * vfio_map_region(struct vfio_device *d, int idx); +/** Get the size of a device memory region */ +size_t vfio_region_size(struct vfio_device *d, int idx); + /** Map VM to an IOVA, which is accessible by devices in the container */ int vfio_map_dma(struct vfio_container *c, uint64_t virt, uint64_t phys, size_t len); diff --git a/fpga/lib/kernel/vfio.c b/fpga/lib/kernel/vfio.c index 0c0de58d4..7103cc519 100644 --- a/fpga/lib/kernel/vfio.c +++ b/fpga/lib/kernel/vfio.c @@ -574,6 +574,14 @@ void * vfio_map_region(struct vfio_device *d, int idx) return d->mappings[idx]; } +size_t vfio_region_size(struct vfio_device *d, int idx) +{ + assert(d != NULL); + assert((size_t)idx < d->info.num_regions); + + return d->regions[idx].size; +} + int vfio_unmap_region(struct vfio_device *d, int idx) { int ret;