[PATCH 4/6] iommu: Add iommu_dma_set_opt_size()

From: John Garry
Date: Fri Mar 19 2021 - 09:31:14 EST


Add a function which allows the max optimised IOMMU DMA size to be set.

Signed-off-by: John Garry <john.garry@xxxxxxxxxx>
---
drivers/iommu/dma-iommu.c | 15 +++++++++++++++
1 file changed, 15 insertions(+)

diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c
index 15b7270a5c2a..a5dfbd6c0496 100644
--- a/drivers/iommu/dma-iommu.c
+++ b/drivers/iommu/dma-iommu.c
@@ -447,6 +447,21 @@ static dma_addr_t iommu_dma_alloc_iova(struct iommu_domain *domain,
return (dma_addr_t)iova << shift;
}

+__maybe_unused
+static void iommu_dma_set_opt_size(struct device *dev, size_t size)
+{
+ struct iommu_domain *domain = iommu_get_dma_domain(dev);
+ struct iommu_dma_cookie *cookie = domain->iova_cookie;
+ struct iova_domain *iovad = &cookie->iovad;
+ unsigned long shift, iova_len;
+
+ shift = iova_shift(iovad);
+ iova_len = size >> shift;
+ iova_len = roundup_pow_of_two(iova_len);
+
+ iova_rcache_set_upper_limit(iovad, iova_len);
+}
+
static void iommu_dma_free_iova(struct iommu_dma_cookie *cookie,
dma_addr_t iova, size_t size, struct page *freelist)
{
--
2.26.2