Message ID | 20190411184741.27540-4-tmurphy@arista.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | iommu/amd: Convert the AMD iommu driver to the dma-iommu api | expand |
On Thu, Apr 11, 2019 at 07:47:32PM +0100, Tom Murphy via iommu wrote: > + > + WARN_ON_ONCE(iommu_dma_reserve_iova(domain, region->start, end) == NULL); Overly long line..
I hoped this could be an exception, it's easier to grok without the line break and isn't crazy long. Because you mentioned it I'll fix it. On Mon, Apr 15, 2019 at 7:31 AM Christoph Hellwig <hch@infradead.org> wrote: > > On Thu, Apr 11, 2019 at 07:47:32PM +0100, Tom Murphy via iommu wrote: > > + > > + WARN_ON_ONCE(iommu_dma_reserve_iova(domain, region->start, end) == NULL); > > Overly long line..
On 16/04/2019 14:22, Tom Murphy wrote: > I hoped this could be an exception, it's easier to grok without the > line break and isn't crazy long. Because you mentioned it I'll fix it. Frankly this patch is hard to justify anyway - iommu-dma already has its own reserved region handling, and there should be no need for external callers to be poking into the innards provided the IOMMU driver reports the correct reserved regions in the first place. If the iommu-dma abstraction is not quite sufficient to actually convert amd-iommu to use it properly, then we should improve the abstraction, rather than just punching holes in it to merely poke renamed parts of the existing amd-iommu logic into. Robin. > On Mon, Apr 15, 2019 at 7:31 AM Christoph Hellwig <hch@infradead.org> wrote: >> >> On Thu, Apr 11, 2019 at 07:47:32PM +0100, Tom Murphy via iommu wrote: >>> + >>> + WARN_ON_ONCE(iommu_dma_reserve_iova(domain, region->start, end) == NULL); >> >> Overly long line..
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
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@arista.com> --- drivers/iommu/dma-iommu.c | 27 +++++++++++++++++++++++++++ include/linux/dma-iommu.h | 7 +++++++ 2 files changed, 34 insertions(+)