vfio_get_info_dma_avail() is a low level routine similar to the other routines extracting capabilities from 'struct vfio_iommu_type1_info'. It belongs to file "helpers.c".
Signed-off-by: Cédric Le Goater <c...@redhat.com> --- hw/vfio/helpers.h | 5 ++++- include/hw/vfio/vfio-common.h | 2 -- hw/vfio/container.c | 31 ------------------------------- hw/vfio/helpers.c | 31 +++++++++++++++++++++++++++++++ 4 files changed, 35 insertions(+), 34 deletions(-) diff --git a/hw/vfio/helpers.h b/hw/vfio/helpers.h index b70f7082562dedff9d97db80d2eecc7ddf71e2af..c70eef4fd6f98fc1df9bc8ecbf72fa1ea484e3c0 100644 --- a/hw/vfio/helpers.h +++ b/hw/vfio/helpers.h @@ -18,7 +18,10 @@ struct vfio_info_cap_header * vfio_get_device_info_cap(struct vfio_device_info *info, uint16_t id); struct vfio_info_cap_header * vfio_get_region_info_cap(struct vfio_region_info *info, uint16_t id); - +struct vfio_info_cap_header * +vfio_get_iommu_type1_info_cap(struct vfio_iommu_type1_info *info, uint16_t id); +bool vfio_get_info_dma_avail(struct vfio_iommu_type1_info *info, + unsigned int *avail); #endif int vfio_bitmap_alloc(VFIOBitmap *vbmap, hwaddr size); diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h index 0fe424633c9cb94195c08d0b62ca4fb8ffccd79c..b7c1f049582c07aefdc2a0cef2805e7b478ffe84 100644 --- a/include/hw/vfio/vfio-common.h +++ b/include/hw/vfio/vfio-common.h @@ -146,8 +146,6 @@ int vfio_get_region_info(VFIODevice *vbasedev, int index, int vfio_get_dev_region_info(VFIODevice *vbasedev, uint32_t type, uint32_t subtype, struct vfio_region_info **info); bool vfio_has_region_cap(VFIODevice *vbasedev, int region, uint16_t cap_type); -bool vfio_get_info_dma_avail(struct vfio_iommu_type1_info *info, - unsigned int *avail); #endif bool vfio_devices_all_dirty_tracking_started( diff --git a/hw/vfio/container.c b/hw/vfio/container.c index a6f7359faefc02b01ca05f76b4c1f8a9934a9091..e1b06e71c47ab8d24e7da878f801020b22936430 100644 --- a/hw/vfio/container.c +++ b/hw/vfio/container.c @@ -278,37 +278,6 @@ static int vfio_legacy_query_dirty_bitmap(const VFIOContainerBase *bcontainer, return ret; } -static struct vfio_info_cap_header * -vfio_get_iommu_type1_info_cap(struct vfio_iommu_type1_info *info, uint16_t id) -{ - if (!(info->flags & VFIO_IOMMU_INFO_CAPS)) { - return NULL; - } - - return vfio_get_cap((void *)info, info->cap_offset, id); -} - -bool vfio_get_info_dma_avail(struct vfio_iommu_type1_info *info, - unsigned int *avail) -{ - struct vfio_info_cap_header *hdr; - struct vfio_iommu_type1_info_dma_avail *cap; - - /* If the capability cannot be found, assume no DMA limiting */ - hdr = vfio_get_iommu_type1_info_cap(info, - VFIO_IOMMU_TYPE1_INFO_DMA_AVAIL); - if (!hdr) { - return false; - } - - if (avail != NULL) { - cap = (void *) hdr; - *avail = cap->avail; - } - - return true; -} - static bool vfio_get_info_iova_range(struct vfio_iommu_type1_info *info, VFIOContainerBase *bcontainer) { diff --git a/hw/vfio/helpers.c b/hw/vfio/helpers.c index 9d635c18156d3271bad824b74fbc5b6f1f810a95..f42dcf82c58c978a45975eb1d015d64f4e39b3cf 100644 --- a/hw/vfio/helpers.c +++ b/hw/vfio/helpers.c @@ -222,6 +222,37 @@ retry: return 0; } +struct vfio_info_cap_header * +vfio_get_iommu_type1_info_cap(struct vfio_iommu_type1_info *info, uint16_t id) +{ + if (!(info->flags & VFIO_IOMMU_INFO_CAPS)) { + return NULL; + } + + return vfio_get_cap((void *)info, info->cap_offset, id); +} + +bool vfio_get_info_dma_avail(struct vfio_iommu_type1_info *info, + unsigned int *avail) +{ + struct vfio_info_cap_header *hdr; + struct vfio_iommu_type1_info_dma_avail *cap; + + /* If the capability cannot be found, assume no DMA limiting */ + hdr = vfio_get_iommu_type1_info_cap(info, + VFIO_IOMMU_TYPE1_INFO_DMA_AVAIL); + if (!hdr) { + return false; + } + + if (avail != NULL) { + cap = (void *) hdr; + *avail = cap->avail; + } + + return true; +} + int vfio_get_dev_region_info(VFIODevice *vbasedev, uint32_t type, uint32_t subtype, struct vfio_region_info **info) { -- 2.48.1