From 3fdd8e38b280123fd13bcc4f3fd8928c15e94db6 Mon Sep 17 00:00:00 2001 From: Alex Waterman Date: Wed, 14 Feb 2018 10:58:24 -0800 Subject: gpu: nvgpu: Use our own vmap() for coherent DMA buffers For some reason the GPU does not like the mappings created by the DMA API for coherent sysmem buffers. But a plain vmap() does seem to work. To work around this, when we are using coherent sysmem, force the NO_KERNEL_MAPPING flag to on and then make a vmap() in the nvgpu DMA API wrapper. The rest of the driver will be none the wiser but will work as expected. This problem is not understood yet but it is being tracked in bug 2040115. Once this bug is understood this WAR should either be determined as necessary or reverted with an appropriate fix. Bug 2040115 JIRA EVLR-2333 Change-Id: Idae7a0c92441f0309df572ac18697af49bb6ff2b Signed-off-by: Alex Waterman Reviewed-on: https://git-master.nvidia.com/r/1657568 Reviewed-by: mobile promotions Tested-by: mobile promotions --- drivers/gpu/nvgpu/common/linux/nvgpu_mem.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'drivers/gpu/nvgpu/common/linux/nvgpu_mem.c') diff --git a/drivers/gpu/nvgpu/common/linux/nvgpu_mem.c b/drivers/gpu/nvgpu/common/linux/nvgpu_mem.c index c859520d..69897694 100644 --- a/drivers/gpu/nvgpu/common/linux/nvgpu_mem.c +++ b/drivers/gpu/nvgpu/common/linux/nvgpu_mem.c @@ -44,6 +44,14 @@ int nvgpu_mem_begin(struct gk20a *g, struct nvgpu_mem *mem) if (mem->aperture != APERTURE_SYSMEM || g->mm.force_pramin) return 0; + /* + * WAR for bug 2040115: we already will always have a coherent vmap() + * for all sysmem buffers. The prot settings are left alone since + * eventually this should be deleted. + */ + if (nvgpu_is_enabled(g, NVGPU_USE_COHERENT_SYSMEM)) + return 0; + /* * A CPU mapping is implicitly made for all SYSMEM DMA allocations that * don't have NVGPU_DMA_NO_KERNEL_MAPPING. Thus we don't need to make @@ -73,6 +81,13 @@ void nvgpu_mem_end(struct gk20a *g, struct nvgpu_mem *mem) if (mem->aperture != APERTURE_SYSMEM || g->mm.force_pramin) return; + /* + * WAR for bug 2040115: skip this since the map will be taken care of + * during the free in the DMA API. + */ + if (nvgpu_is_enabled(g, NVGPU_USE_COHERENT_SYSMEM)) + return; + /* * Similar to nvgpu_mem_begin() we don't need to unmap the CPU mapping * already made by the DMA API. @@ -393,8 +408,12 @@ int nvgpu_mem_create_from_mem(struct gk20a *g, /* * Re-use the CPU mapping only if the mapping was made by the DMA API. + * + * Bug 2040115: the DMA API wrapper makes the mapping that we should + * re-use. */ - if (!(src->priv.flags & NVGPU_DMA_NO_KERNEL_MAPPING)) + if (!(src->priv.flags & NVGPU_DMA_NO_KERNEL_MAPPING) || + nvgpu_is_enabled(g, NVGPU_USE_COHERENT_SYSMEM)) dest->cpu_va = src->cpu_va + (PAGE_SIZE * start_page); dest->priv.pages = src->priv.pages + start_page; -- cgit v1.2.2