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>
This commit is contained in:
Eugenio Pérez 2022-03-14 18:34:48 +01:00 committed by Jason Wang
parent 100890f7ca
commit 9376bde894
2 changed files with 154 additions and 0 deletions

View file

@ -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 {
@ -119,6 +120,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:
*