diff --git a/drivers/gpu/nvgpu/common/linux/dma.c b/drivers/gpu/nvgpu/common/linux/dma.c index 67b58016a..7b892731c 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 dc1e9688f..3d1f8d284 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 50681f8dd..c0397b584 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 *