diff options
author | Yi Liu <yi.l.liu@intel.com> | 2022-11-10 18:57:01 -0800 |
---|---|---|
committer | Jason Gunthorpe <jgg@nvidia.com> | 2022-12-05 08:56:01 -0400 |
commit | 8da7a0e79f9b15330ae68d8532425399f4c27045 (patch) | |
tree | d08374512e4b256f706c14db3157a10744a78996 /drivers/vfio/vfio_main.c | |
parent | 1334e47ee798ac4715330a6ade0afc929cd54aff (diff) |
vfio: Refactor dma APIs for emulated devices
To use group helpers instead of opening group related code in the
API. This prepares moving group specific code out of vfio_main.c.
Link: https://lore.kernel.org/r/20221201145535.589687-10-yi.l.liu@intel.com
Reviewed-by: Kevin Tian <kevin.tian@intel.com>
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Reviewed-by: Alex Williamson <alex.williamson@redhat.com>
Tested-by: Lixiao Yang <lixiao.yang@intel.com>
Tested-by: Yu He <yu.he@intel.com>
Signed-off-by: Yi Liu <yi.l.liu@intel.com>
Signed-off-by: Nicolin Chen <nicolinc@nvidia.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
Diffstat (limited to 'drivers/vfio/vfio_main.c')
-rw-r--r-- | drivers/vfio/vfio_main.c | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/drivers/vfio/vfio_main.c b/drivers/vfio/vfio_main.c index e053998baffd..b7f94ace7b10 100644 --- a/drivers/vfio/vfio_main.c +++ b/drivers/vfio/vfio_main.c @@ -1938,6 +1938,11 @@ int vfio_set_irqs_validate_and_prepare(struct vfio_irq_set *hdr, int num_irqs, } EXPORT_SYMBOL(vfio_set_irqs_validate_and_prepare); +static bool vfio_device_has_container(struct vfio_device *device) +{ + return device->group->container; +} + /* * Pin contiguous user pages and return their associated host pages for local * domain only. @@ -1950,7 +1955,7 @@ EXPORT_SYMBOL(vfio_set_irqs_validate_and_prepare); * Return error or number of pages pinned. * * A driver may only call this function if the vfio_device was created - * by vfio_register_emulated_iommu_dev() due to vfio_container_pin_pages(). + * by vfio_register_emulated_iommu_dev() due to vfio_device_container_pin_pages(). */ int vfio_pin_pages(struct vfio_device *device, dma_addr_t iova, int npage, int prot, struct page **pages) @@ -1958,10 +1963,9 @@ int vfio_pin_pages(struct vfio_device *device, dma_addr_t iova, /* group->container cannot change while a vfio device is open */ if (!pages || !npage || WARN_ON(!vfio_assert_device_open(device))) return -EINVAL; - if (device->group->container) - return vfio_container_pin_pages(device->group->container, - device->group->iommu_group, - iova, npage, prot, pages); + if (vfio_device_has_container(device)) + return vfio_device_container_pin_pages(device, iova, + npage, prot, pages); if (device->iommufd_access) { int ret; @@ -1997,9 +2001,8 @@ void vfio_unpin_pages(struct vfio_device *device, dma_addr_t iova, int npage) if (WARN_ON(!vfio_assert_device_open(device))) return; - if (device->group->container) { - vfio_container_unpin_pages(device->group->container, iova, - npage); + if (vfio_device_has_container(device)) { + vfio_device_container_unpin_pages(device, iova, npage); return; } if (device->iommufd_access) { @@ -2036,9 +2039,9 @@ int vfio_dma_rw(struct vfio_device *device, dma_addr_t iova, void *data, if (!data || len <= 0 || !vfio_assert_device_open(device)) return -EINVAL; - if (device->group->container) - return vfio_container_dma_rw(device->group->container, iova, - data, len, write); + if (vfio_device_has_container(device)) + return vfio_device_container_dma_rw(device, iova, + data, len, write); if (device->iommufd_access) { unsigned int flags = 0; |