Add support for closing raw device allocated during platform probe. Signed-off-by: Tomasz Duszynski <tduszyn...@marvell.com> --- drivers/raw/vfio_platform/vfio_platform.c | 49 +++++++++++++++++++++++ 1 file changed, 49 insertions(+)
diff --git a/drivers/raw/vfio_platform/vfio_platform.c b/drivers/raw/vfio_platform/vfio_platform.c index b056041892..ae0572dc99 100644 --- a/drivers/raw/vfio_platform/vfio_platform.c +++ b/drivers/raw/vfio_platform/vfio_platform.c @@ -3,6 +3,8 @@ */ #include <errno.h> +#include <sys/mman.h> +#include <unistd.h> #include <rte_bus_platform.h> #include <rte_common.h> @@ -17,6 +19,8 @@ #include "vfio_platform.h" +#define VFIO_PLATFORM_SYSFS_BASE "/sys/bus/platform/devices" + static struct { int container_fd; int refcnt; @@ -52,6 +56,12 @@ container_get(int index) container_tbl[index].refcnt++; } +static int +container_fd(int index) +{ + return container_tbl[index].container_fd; +} + int rte_pmd_vfio_platform_container_create(void) { @@ -82,7 +92,46 @@ rte_pmd_vfio_platform_container_destroy(int container) return 0; } +static void +device_release_maps(struct vfio_platform *plat) +{ + struct vfio_platform_resource *res; + int i; + + for (i = 0; i < plat->num_resource; i++) { + res = &plat->resource[i]; + munmap(res->mem.addr, res->mem.len); + free((void *)(size_t)res->name); + } + + free(plat->resource); + plat->resource = NULL; + plat->num_resource = 0; +} + +static void +device_release(struct vfio_platform *plat) +{ + device_release_maps(plat); + rte_vfio_release_device(VFIO_PLATFORM_SYSFS_BASE, plat->device->name, plat->dev_fd); + rte_vfio_container_group_unbind(container_fd(plat->container), plat->group); + close(plat->group_fd); + rte_vfio_clear_group(plat->group_fd); + container_put(plat->container); +} + +static int +vfio_rawdev_dev_close(struct rte_rawdev *dev) +{ + struct vfio_platform *plat = dev->dev_private; + + device_release(plat); + + return 0; +} + static const struct rte_rawdev_ops vfio_platform_rawdev_ops = { + .dev_close = vfio_rawdev_dev_close, }; static int -- 2.25.1