Skip to content

Commit

Permalink
memory: Introduce memory_region_iommu_set_iova_ranges
Browse files Browse the repository at this point in the history
This helper will allow to convey information about valid
IOVA ranges to virtual IOMMUS.

Signed-off-by: Eric Auger <eric.auger@redhat.com>
Acked-by: Peter Xu <peterx@redhat.com>
Reviewed-by: "Michael S. Tsirkin" <mst@redhat.com>
[ clg: fixes in memory_region_iommu_set_iova_ranges() and
       iommu_set_iova_ranges() documentation ]
Signed-off-by: Cédric Le Goater <clg@redhat.com>
  • Loading branch information
eauger authored and legoater committed Nov 3, 2023
1 parent e8f433f commit 51478a8
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
32 changes: 32 additions & 0 deletions include/exec/memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,26 @@ struct IOMMUMemoryRegionClass {
int (*iommu_set_page_size_mask)(IOMMUMemoryRegion *iommu,
uint64_t page_size_mask,
Error **errp);
/**
* @iommu_set_iova_ranges:
*
* Propagate information about the usable IOVA ranges for a given IOMMU
* memory region. Used for example to propagate host physical device
* reserved memory region constraints to the virtual IOMMU.
*
* Optional method: if this method is not provided, then the default IOVA
* aperture is used.
*
* @iommu: the IOMMUMemoryRegion
*
* @iova_ranges: list of ordered IOVA ranges (at least one range)
*
* Returns 0 on success, or a negative error. In case of failure, the error
* object must be created.
*/
int (*iommu_set_iova_ranges)(IOMMUMemoryRegion *iommu,
GList *iova_ranges,
Error **errp);
};

typedef struct RamDiscardListener RamDiscardListener;
Expand Down Expand Up @@ -1856,6 +1876,18 @@ int memory_region_iommu_set_page_size_mask(IOMMUMemoryRegion *iommu_mr,
uint64_t page_size_mask,
Error **errp);

/**
* memory_region_iommu_set_iova_ranges - Set the usable IOVA ranges
* for a given IOMMU MR region
*
* @iommu: IOMMU memory region
* @iova_ranges: list of ordered IOVA ranges (at least one range)
* @errp: pointer to Error*, to store an error if it happens.
*/
int memory_region_iommu_set_iova_ranges(IOMMUMemoryRegion *iommu,
GList *iova_ranges,
Error **errp);

/**
* memory_region_name: get a memory region's name
*
Expand Down
13 changes: 13 additions & 0 deletions system/memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -1921,6 +1921,19 @@ int memory_region_iommu_set_page_size_mask(IOMMUMemoryRegion *iommu_mr,
return ret;
}

int memory_region_iommu_set_iova_ranges(IOMMUMemoryRegion *iommu_mr,
GList *iova_ranges,
Error **errp)
{
IOMMUMemoryRegionClass *imrc = IOMMU_MEMORY_REGION_GET_CLASS(iommu_mr);
int ret = 0;

if (imrc->iommu_set_iova_ranges) {
ret = imrc->iommu_set_iova_ranges(iommu_mr, iova_ranges, errp);
}
return ret;
}

int memory_region_register_iommu_notifier(MemoryRegion *mr,
IOMMUNotifier *n, Error **errp)
{
Expand Down

0 comments on commit 51478a8

Please sign in to comment.