The DMA backend can return CPU-cached instance memory on a coherent
Tegra device. Report the coherent system-memory target for these
allocations to the GPU.

Signed-off-by: Mikko Perttunen <[email protected]>
---
 drivers/gpu/drm/nouveau/nvkm/subdev/instmem/gk20a.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/instmem/gk20a.c 
b/drivers/gpu/drm/nouveau/nvkm/subdev/instmem/gk20a.c
index 8f85fc88bdb6..1e1d71a32bc0 100644
--- a/drivers/gpu/drm/nouveau/nvkm/subdev/instmem/gk20a.c
+++ b/drivers/gpu/drm/nouveau/nvkm/subdev/instmem/gk20a.c
@@ -32,10 +32,8 @@
  * 2) If no IOMMU unit is probed, the DMA API is used to allocate physically
  *    contiguous memory.
  *
- * In both cases CPU read and writes are performed by creating a write-combined
- * mapping. The GPU L2 cache must thus be flushed/invalidated when required. To
- * be conservative we do this every time we acquire or release an instobj, but
- * ideally L2 management should be handled at a higher level.
+ * CPU reads and writes use a write-combined or DMA-coherent mapping. The GPU
+ * L2 cache is flushed or invalidated on every instobj acquire or release.
  *
  * To improve performance, CPU mappings are not removed upon instobj release.
  * Instead they are placed into a LRU list to be recycled when the mapped space
@@ -112,6 +110,15 @@ struct gk20a_instmem {
 };
 #define gk20a_instmem(p) container_of((p), struct gk20a_instmem, base)
 
+static enum nvkm_memory_target
+gk20a_instobj_target_dma(struct nvkm_memory *memory)
+{
+       struct gk20a_instmem *imem = gk20a_instobj(memory)->imem;
+
+       return imem->base.subdev.device->cpu_coherent ?
+               NVKM_MEM_TARGET_HOST : NVKM_MEM_TARGET_NCOH;
+}
+
 static enum nvkm_memory_target
 gk20a_instobj_target(struct nvkm_memory *memory)
 {
@@ -352,7 +359,7 @@ gk20a_instobj_dtor_iommu(struct nvkm_memory *memory)
 static const struct nvkm_memory_func
 gk20a_instobj_func_dma = {
        .dtor = gk20a_instobj_dtor_dma,
-       .target = gk20a_instobj_target,
+       .target = gk20a_instobj_target_dma,
        .page = gk20a_instobj_page,
        .addr = gk20a_instobj_addr,
        .size = gk20a_instobj_size,

-- 
2.56.1

Reply via email to