diff options
author | Eugenio Pérez <eperezma@redhat.com> | 2022-03-14 18:34:48 +0100 |
---|---|---|
committer | Jason Wang <jasowang@redhat.com> | 2022-03-15 13:57:44 +0800 |
commit | 9376bde894e444ebe2d2ec236569b6e55faa4765 (patch) | |
tree | 7614e324760bf584f6f72fac5381cf7c260123d1 /include | |
parent | 100890f7cad502b6fa49465ffff287ba79fcf94b (diff) | |
download | qemu-9376bde894e444ebe2d2ec236569b6e55faa4765.zip qemu-9376bde894e444ebe2d2ec236569b6e55faa4765.tar.gz qemu-9376bde894e444ebe2d2ec236569b6e55faa4765.tar.bz2 |
util: Add iova_tree_alloc_map
This iova tree function allows it to look for a hole in allocated
regions and return a totally new translation for a given translated
address.
It's usage is mainly to allow devices to access qemu address space,
remapping guest's one into a new iova space where qemu can add chunks of
addresses.
Signed-off-by: Eugenio Pérez <eperezma@redhat.com>
Reviewed-by: Peter Xu <peterx@redhat.com>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Jason Wang <jasowang@redhat.com>
Diffstat (limited to 'include')
-rw-r--r-- | include/qemu/iova-tree.h | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/include/qemu/iova-tree.h b/include/qemu/iova-tree.h index 8249edd..d066400 100644 --- a/include/qemu/iova-tree.h +++ b/include/qemu/iova-tree.h @@ -29,6 +29,7 @@ #define IOVA_OK (0) #define IOVA_ERR_INVALID (-1) /* Invalid parameters */ #define IOVA_ERR_OVERLAP (-2) /* IOVA range overlapped */ +#define IOVA_ERR_NOMEM (-3) /* Cannot allocate */ typedef struct IOVATree IOVATree; typedef struct DMAMap { @@ -120,6 +121,23 @@ const DMAMap *iova_tree_find_address(const IOVATree *tree, hwaddr iova); void iova_tree_foreach(IOVATree *tree, iova_tree_iterator iterator); /** + * iova_tree_alloc_map: + * + * @tree: the iova tree to allocate from + * @map: the new map (as translated addr & size) to allocate in the iova region + * @iova_begin: the minimum address of the allocation + * @iova_end: the maximum addressable direction of the allocation + * + * Allocates a new region of a given size, between iova_min and iova_max. + * + * Return: Same as iova_tree_insert, but cannot overlap and can return error if + * iova tree is out of free contiguous range. The caller gets the assigned iova + * in map->iova. + */ +int iova_tree_alloc_map(IOVATree *tree, DMAMap *map, hwaddr iova_begin, + hwaddr iova_end); + +/** * iova_tree_destroy: * * @tree: the iova tree to destroy |