[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20190411184741.27540-4-tmurphy@arista.com>
Date: Thu, 11 Apr 2019 19:47:32 +0100
From: Tom Murphy <tmurphy@...sta.com>
To: iommu@...ts.linux-foundation.org
Cc: dima@...sta.com, jamessewart@...sta.com, murphyt7@....ie,
Tom Murphy <tmurphy@...sta.com>,
Joerg Roedel <joro@...tes.org>,
Will Deacon <will.deacon@....com>,
Robin Murphy <robin.murphy@....com>,
Marek Szyprowski <m.szyprowski@...sung.com>,
Kukjin Kim <kgene@...nel.org>,
Krzysztof Kozlowski <krzk@...nel.org>,
Matthias Brugger <matthias.bgg@...il.com>,
Andy Gross <andy.gross@...aro.org>,
David Brown <david.brown@...aro.org>,
Rob Clark <robdclark@...il.com>,
Heiko Stuebner <heiko@...ech.de>,
Marc Zyngier <marc.zyngier@....com>,
Thomas Gleixner <tglx@...utronix.de>,
linux-kernel@...r.kernel.org, linux-arm-kernel@...ts.infradead.org,
linux-samsung-soc@...r.kernel.org,
linux-mediatek@...ts.infradead.org, linux-arm-msm@...r.kernel.org,
linux-rockchip@...ts.infradead.org
Subject: [PATCH 3/9] iommu/dma-iommu: Add iommu_dma_copy_reserved_iova, iommu_dma_apply_resv_region to the dma-iommu api
To convert the AMD iommu driver to the dma-iommu we need to wrap some of
the iova reserve functions.
Signed-off-by: Tom Murphy <tmurphy@...sta.com>
---
drivers/iommu/dma-iommu.c | 27 +++++++++++++++++++++++++++
include/linux/dma-iommu.h | 7 +++++++
2 files changed, 34 insertions(+)
diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c
index cc5da30d6e58..613d181e78a9 100644
--- a/drivers/iommu/dma-iommu.c
+++ b/drivers/iommu/dma-iommu.c
@@ -162,6 +162,33 @@ void iommu_put_dma_cookie(struct iommu_domain *domain)
}
EXPORT_SYMBOL(iommu_put_dma_cookie);
+static struct iova *iommu_dma_reserve_iova(struct iommu_domain *domain,
+ dma_addr_t iova_lo, dma_addr_t iova_hi)
+{
+ struct iommu_dma_cookie *cookie = domain->iova_cookie;
+ struct iova_domain *iovad = &cookie->iovad;
+ unsigned long order = __ffs(domain->pgsize_bitmap);
+
+ return reserve_iova(iovad, iova_lo >> order, iova_hi >> order);
+}
+
+void iommu_dma_copy_reserved_iova(struct iova_domain *from,
+ struct iommu_domain *to)
+{
+ struct iommu_dma_cookie *cookie = to->iova_cookie;
+ struct iova_domain *to_iovad = &cookie->iovad;
+
+ copy_reserved_iova(from, to_iovad);
+}
+
+void iommu_dma_apply_resv_region(struct device *dev,
+ struct iommu_domain *domain, struct iommu_resv_region *region)
+{
+ dma_addr_t end = region->start + region->length - 1;
+
+ WARN_ON_ONCE(iommu_dma_reserve_iova(domain, region->start, end) == NULL);
+}
+
/**
* iommu_dma_get_resv_regions - Reserved region driver helper
* @dev: Device from iommu_get_resv_regions()
diff --git a/include/linux/dma-iommu.h b/include/linux/dma-iommu.h
index e760dc5d1fa8..c527ded5c41c 100644
--- a/include/linux/dma-iommu.h
+++ b/include/linux/dma-iommu.h
@@ -23,6 +23,7 @@
#ifdef CONFIG_IOMMU_DMA
#include <linux/dma-mapping.h>
#include <linux/iommu.h>
+#include <linux/iova.h>
#include <linux/msi.h>
int iommu_dma_init(void);
@@ -57,6 +58,12 @@ dma_addr_t iommu_dma_map_page(struct device *dev, struct page *page,
int iommu_dma_map_sg(struct device *dev, struct scatterlist *sg,
int nents, int prot);
+/* These are wrappers around some iova functions */
+void iommu_dma_apply_resv_region(struct device *dev,
+ struct iommu_domain *domain, struct iommu_resv_region *region);
+void iommu_dma_copy_reserved_iova(struct iova_domain *from,
+ struct iommu_domain *to);
+
/*
* Arch code with no special attribute handling may use these
* directly as DMA mapping callbacks for simplicity
--
2.17.1
Powered by blists - more mailing lists