DMA Mapping
-
enum iommu_map_flags
Flags for DMA mapping
Constants
IOMMU_MAP_FIXED_IOVA
If cleared, an appropriate IOVA will be allocated
IOMMU_MAP_EPHEMERAL
If set, the mapping is considered temporary
IOMMU_MAP_NOWRITE
DMA is not allowed to write to this mapping
IOMMU_MAP_NOREAD
DMA is not allowed to read from this mapping
Description
IOMMU_MAP_EPHEMERAL may change how the iova is allocated. I.e., currently, the vfio-based backend will allocate an IOVA from a reserved range of 64k. The iommufd-based backend has no such restrictions.
-
int iommu_map_vaddr(struct iommu_ctx *ctx, void *vaddr, size_t len, uint64_t *iova, unsigned long flags)
Map a virtual memory address to an I/O virtual address
Parameters
struct iommu_ctx *ctx
struct iommu_ctx
void *vaddr
virtual memory address to map
size_t len
number of bytes to map
uint64_t *iova
output parameter for mapped I/O virtual address
unsigned long flags
combination of enum iommu_map_flags
Description
Allocate an I/O virtual address (iova) and program the IOMMU to create a
mapping to the virtual memory address in vaddr. If iova is not NULL
,
store the allocated iova in the pointee.
If vaddr falls within an already mapped area, calculate the corresponding iova instead.
Note that, for the vfio backend, the allocated IOVA is not recycled when the mapping is removed; the IOVA will never be allocated again.
Return
0
on success, -1
on error and sets errno
.
-
int iommu_unmap_vaddr(struct iommu_ctx *ctx, void *vaddr, size_t *len)
Unmap a virtual memory address in the IOMMU
Parameters
struct iommu_ctx *ctx
struct iommu_ctx
void *vaddr
virtual memory address to unmap
size_t *len
output parameter for length of mapping
Description
Remove the mapping associated with vaddr. This can only be used with mappings created using iommu_map_vaddr(). If len is not NULL, the length of the mapping will be written to the pointee.
Return
0
on success, -1
on error and sets errno
.
-
int iommu_unmap_all(struct iommu_ctx *ctx)
Unmap all virtual memory address in the IOMMU
Parameters
struct iommu_ctx *ctx
struct iommu_ctx
Description
Remove all mappings.
Return
0
on success, -1
on error and sets errno
.
-
bool iommu_translate_vaddr(struct iommu_ctx *ctx, void *vaddr, uint64_t *iova)
Translate a virtual address into an iova
Parameters
struct iommu_ctx *ctx
struct iommu_ctx
void *vaddr
virtual memory address to translate
uint64_t *iova
output parameter
Description
Use the iova map within the iommu context to lookup and translate the given virtual address into an I/O virtual address.
Return
true
on success, false
if no mapping was found.
-
int iommu_get_iova_ranges(struct iommu_ctx *ctx, struct iommu_iova_range **ranges)
Get iova ranges
Parameters
struct iommu_ctx *ctx
struct iommu_ctx
struct iommu_iova_range **ranges
output parameter
Description
Store the address of an array into ranges and return the number of elements.
Return
the number of elements in the array pointed to.