diff options
| author | Cédric Le Goater <clg@redhat.com> | 2025-03-26 08:51:02 +0100 |
|---|---|---|
| committer | Cédric Le Goater <clg@redhat.com> | 2025-04-25 09:01:37 +0200 |
| commit | f6d7f5d02bbb57b5b469863afe89278d64598d81 (patch) | |
| tree | 1e3ec9765868f518950b26d9842e108b101261c8 /hw/vfio/helpers.c | |
| parent | ac28680d5e7a84943cd9f55a4aae245d6d7fdcae (diff) | |
| download | focaccia-qemu-f6d7f5d02bbb57b5b469863afe89278d64598d81.tar.gz focaccia-qemu-f6d7f5d02bbb57b5b469863afe89278d64598d81.zip | |
vfio: Move vfio_get_info_dma_avail() into helpers.c
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". Reviewed-by: John Levon <john.levon@nutanix.com> Link: https://lore.kernel.org/qemu-devel/20250318095415.670319-17-clg@redhat.com Reviewed-by: Zhenzhong Duan <zhenzhong.duan@intel.com> Link: https://lore.kernel.org/qemu-devel/20250326075122.1299361-18-clg@redhat.com Signed-off-by: Cédric Le Goater <clg@redhat.com>
Diffstat (limited to 'hw/vfio/helpers.c')
| -rw-r--r-- | hw/vfio/helpers.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/hw/vfio/helpers.c b/hw/vfio/helpers.c index 054ee6e31e..1a584ba5f0 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) { |