From 2559fa295d0c478466e47496174fa2108ab01c33 Mon Sep 17 00:00:00 2001 From: Alex Waterman Date: Wed, 16 Aug 2017 15:53:55 -0700 Subject: gpu: nvgpu: Add common vaddr translate function Add a function to do address translation for IOMMU capable GPUs. When an iGPU is behind and IOMMU it can pick whether to use that IOMMU for translation by adding a bit to physical addresses. This function takes care of that. However, this required an abstracted nvgpu_iommuable() API to check whether a GPU is behind an IOMMU. This patch adds that API for Linux. JIRA NVGPU-68 Change-Id: I489d14475167c019c294407372395df78c8b5feb Signed-off-by: Alex Waterman Reviewed-on: https://git-master.nvidia.com/r/1542965 Reviewed-by: Automatic_Commit_Validation_User Reviewed-by: svc-mobile-coverity Reviewed-by: svccoveritychecker GVS: Gerrit_Virtual_Submit Reviewed-by: Sourab Gupta Reviewed-by: Konsta Holtta Reviewed-by: Vijayakumar Subbu --- drivers/gpu/nvgpu/common/linux/dma.c | 7 +++++++ drivers/gpu/nvgpu/gk20a/mm_gk20a.c | 3 +-- drivers/gpu/nvgpu/include/nvgpu/dma.h | 14 ++++++++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) (limited to 'drivers') diff --git a/drivers/gpu/nvgpu/common/linux/dma.c b/drivers/gpu/nvgpu/common/linux/dma.c index 67b58016..7b892731 100644 --- a/drivers/gpu/nvgpu/common/linux/dma.c +++ b/drivers/gpu/nvgpu/common/linux/dma.c @@ -631,3 +631,10 @@ void nvgpu_free_sgtable(struct gk20a *g, struct sg_table **sgt) nvgpu_kfree(g, *sgt); *sgt = NULL; } + +bool nvgpu_iommuable(struct gk20a *g) +{ + struct nvgpu_os_linux *l = nvgpu_os_linux_from_gk20a(g); + + return device_is_iommuable(l->dev); +} diff --git a/drivers/gpu/nvgpu/gk20a/mm_gk20a.c b/drivers/gpu/nvgpu/gk20a/mm_gk20a.c index dc1e9688..3d1f8d28 100644 --- a/drivers/gpu/nvgpu/gk20a/mm_gk20a.c +++ b/drivers/gpu/nvgpu/gk20a/mm_gk20a.c @@ -1276,8 +1276,7 @@ u64 gk20a_mm_smmu_vaddr_translate(struct gk20a *g, u64 iova) /* ensure it is not vidmem allocation */ WARN_ON(is_vidmem_page_alloc(iova)); - if (device_is_iommuable(dev_from_gk20a(g)) && - g->ops.mm.get_physical_addr_bits) + if (nvgpu_iommuable(g) && g->ops.mm.get_physical_addr_bits) return iova | 1ULL << g->ops.mm.get_physical_addr_bits(g); return iova; diff --git a/drivers/gpu/nvgpu/include/nvgpu/dma.h b/drivers/gpu/nvgpu/include/nvgpu/dma.h index 50681f8d..c0397b58 100644 --- a/drivers/gpu/nvgpu/include/nvgpu/dma.h +++ b/drivers/gpu/nvgpu/include/nvgpu/dma.h @@ -50,6 +50,20 @@ struct nvgpu_mem; */ #define NVGPU_DMA_READ_ONLY (1 << 2) +/** + * nvgpu_iommuable - Check if GPU is behind IOMMU + * + * @g - The GPU. + * + * Returns true if the passed GPU is behind an IOMMU; false otherwise. If the + * GPU is iommuable then the DMA address in nvgpu_mem_sgl is valid. + * + * Note that even if a GPU is behind an IOMMU that does not necessarily mean the + * GPU _must_ use DMA addresses. GPUs may still use physical addresses if it + * makes sense. + */ +bool nvgpu_iommuable(struct gk20a *g); + /** * nvgpu_dma_alloc - Allocate DMA memory * -- cgit v1.2.2