Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2cc4cc28 authored by Patrick Daly's avatar Patrick Daly
Browse files

iommu/dma: Allow drivers to reserve an iova range



Some devices have a memory map which contains gaps or holes. In order for
the device to have as much iova space as possible, allow its driver to
inform the dma-iommu that it should not allocate addresses from these
holes.

Change-Id: I029d50c1f1e84ece48de30ef21b63cac8fe05257
Signed-off-by: default avatarPatrick Daly <pdaly@codeaurora.org>
parent 9e9032d1
Loading
Loading
Loading
Loading
+25 −0
Original line number Diff line number Diff line
@@ -316,6 +316,31 @@ int iommu_dma_init_domain(struct iommu_domain *domain, dma_addr_t base,
}
EXPORT_SYMBOL(iommu_dma_init_domain);

/*
 * Should be called prior to using dma-apis
 */
int iommu_dma_reserve_iova(struct device *dev, dma_addr_t base,
			   u64 size)
{
	struct iommu_domain *domain;
	struct iova_domain *iovad;
	unsigned long pfn_lo, pfn_hi;

	domain = iommu_get_domain_for_dev(dev);
	if (!domain || !domain->iova_cookie)
		return -EINVAL;

	iovad = &((struct iommu_dma_cookie *)domain->iova_cookie)->iovad;

	/* iova will be freed automatically by put_iova_domain() */
	pfn_lo = iova_pfn(iovad, base);
	pfn_hi = iova_pfn(iovad, base + size - 1);
	if (!reserve_iova(iovad, pfn_lo, pfn_hi))
		return -EINVAL;

	return 0;
}

/**
 * dma_info_to_prot - Translate DMA API directions and attributes to IOMMU API
 *                    page flags.
+9 −0
Original line number Diff line number Diff line
@@ -82,6 +82,9 @@ int iommu_dma_mapping_error(struct device *dev, dma_addr_t dma_addr);
void iommu_dma_map_msi_msg(int irq, struct msi_msg *msg);
void iommu_dma_get_resv_regions(struct device *dev, struct list_head *list);

int iommu_dma_reserve_iova(struct device *dev, dma_addr_t base,
			   u64 size);

#else

struct iommu_domain;
@@ -115,6 +118,12 @@ static inline void iommu_dma_get_resv_regions(struct device *dev, struct list_he
{
}

static inline int iommu_dma_reserve_iova(struct device *dev, dma_addr_t base,
					 u64 size)
{
	return -ENODEV;
}

#endif	/* CONFIG_IOMMU_DMA */
#endif	/* __KERNEL__ */
#endif	/* __DMA_IOMMU_H */