>-----Original Message----- >From: dri-devel <dri-devel-bounces@xxxxxxxxxxxxxxxxxxxxx> On Behalf Of >Christian König >Sent: Thursday, October 1, 2020 7:28 AM >To: dri-devel@xxxxxxxxxxxxxxxxxxxxx; ray.huang@xxxxxxx; >airlied@xxxxxxxxx; daniel@xxxxxxxx >Subject: [PATCH 5/8] drm/ttm: set the tt caching state at creation time > >All drivers can determine the tt caching state at creation time, >no need to do this on the fly during every validation. Reviewed-by: Michael J. Ruhl <michael.j.ruhl@xxxxxxxxx> m >Signed-off-by: Christian König <christian.koenig@xxxxxxx> >--- > drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 9 ++++++++- > drivers/gpu/drm/drm_gem_vram_helper.c | 2 +- > drivers/gpu/drm/nouveau/nouveau_sgdma.c | 13 ++++++++++++- > drivers/gpu/drm/qxl/qxl_ttm.c | 2 +- > drivers/gpu/drm/radeon/radeon_ttm.c | 14 +++++++++++++- > drivers/gpu/drm/ttm/ttm_agp_backend.c | 2 +- > drivers/gpu/drm/ttm/ttm_tt.c | 16 +++++++++------- > drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c | 6 ++++-- > include/drm/ttm/ttm_tt.h | 7 ++++--- > 9 files changed, 53 insertions(+), 18 deletions(-) > >diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c >b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c >index 2af24cf39e94..7f41a47e7353 100644 >--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c >+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c >@@ -1292,7 +1292,9 @@ static void amdgpu_ttm_backend_destroy(struct >ttm_bo_device *bdev, > static struct ttm_tt *amdgpu_ttm_tt_create(struct ttm_buffer_object *bo, > uint32_t page_flags) > { >+ struct amdgpu_bo *abo = ttm_to_amdgpu_bo(bo); > struct amdgpu_ttm_tt *gtt; >+ enum ttm_caching caching; > > gtt = kzalloc(sizeof(struct amdgpu_ttm_tt), GFP_KERNEL); > if (gtt == NULL) { >@@ -1300,8 +1302,13 @@ static struct ttm_tt *amdgpu_ttm_tt_create(struct >ttm_buffer_object *bo, > } > gtt->gobj = &bo->base; > >+ if (abo->flags & AMDGPU_GEM_CREATE_CPU_GTT_USWC) >+ caching = ttm_write_combined; >+ else >+ caching = ttm_cached; >+ > /* allocate space for the uninitialized page entries */ >- if (ttm_sg_tt_init(>t->ttm, bo, page_flags)) { >+ if (ttm_sg_tt_init(>t->ttm, bo, page_flags, caching)) { > kfree(gtt); > return NULL; > } >diff --git a/drivers/gpu/drm/drm_gem_vram_helper.c >b/drivers/gpu/drm/drm_gem_vram_helper.c >index 3fe4b326e18e..62235926e077 100644 >--- a/drivers/gpu/drm/drm_gem_vram_helper.c >+++ b/drivers/gpu/drm/drm_gem_vram_helper.c >@@ -910,7 +910,7 @@ static struct ttm_tt *bo_driver_ttm_tt_create(struct >ttm_buffer_object *bo, > if (!tt) > return NULL; > >- ret = ttm_tt_init(tt, bo, page_flags); >+ ret = ttm_tt_init(tt, bo, page_flags, ttm_cached); > if (ret < 0) > goto err_ttm_tt_init; > >diff --git a/drivers/gpu/drm/nouveau/nouveau_sgdma.c >b/drivers/gpu/drm/nouveau/nouveau_sgdma.c >index 806d9ec310f5..cd6fdebae795 100644 >--- a/drivers/gpu/drm/nouveau/nouveau_sgdma.c >+++ b/drivers/gpu/drm/nouveau/nouveau_sgdma.c >@@ -5,6 +5,7 @@ > #include "nouveau_drv.h" > #include "nouveau_mem.h" > #include "nouveau_ttm.h" >+#include "nouveau_bo.h" > > struct nouveau_sgdma_be { > /* this has to be the first field so populate/unpopulated in >@@ -67,13 +68,23 @@ nouveau_sgdma_unbind(struct ttm_bo_device >*bdev, struct ttm_tt *ttm) > struct ttm_tt * > nouveau_sgdma_create_ttm(struct ttm_buffer_object *bo, uint32_t >page_flags) > { >+ struct nouveau_drm *drm = nouveau_bdev(bo->bdev); >+ struct nouveau_bo *nvbo = nouveau_bo(bo); > struct nouveau_sgdma_be *nvbe; >+ enum ttm_caching caching; >+ >+ if (nvbo->force_coherent) >+ caching = ttm_uncached; >+ else if (drm->agp.bridge) >+ caching = ttm_write_combined; >+ else >+ caching = ttm_cached; > > nvbe = kzalloc(sizeof(*nvbe), GFP_KERNEL); > if (!nvbe) > return NULL; > >- if (ttm_dma_tt_init(&nvbe->ttm, bo, page_flags)) { >+ if (ttm_dma_tt_init(&nvbe->ttm, bo, page_flags, caching)) { > kfree(nvbe); > return NULL; > } >diff --git a/drivers/gpu/drm/qxl/qxl_ttm.c b/drivers/gpu/drm/qxl/qxl_ttm.c >index 2c35ca4270c6..dcf4ac1480c7 100644 >--- a/drivers/gpu/drm/qxl/qxl_ttm.c >+++ b/drivers/gpu/drm/qxl/qxl_ttm.c >@@ -146,7 +146,7 @@ static struct ttm_tt *qxl_ttm_tt_create(struct >ttm_buffer_object *bo, > if (gtt == NULL) > return NULL; > gtt->qdev = qdev; >- if (ttm_tt_init(>t->ttm, bo, page_flags)) { >+ if (ttm_tt_init(>t->ttm, bo, page_flags, ttm_cached)) { > kfree(gtt); > return NULL; > } >diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c >b/drivers/gpu/drm/radeon/radeon_ttm.c >index f01e74113f40..130a7cea35c3 100644 >--- a/drivers/gpu/drm/radeon/radeon_ttm.c >+++ b/drivers/gpu/drm/radeon/radeon_ttm.c >@@ -590,6 +590,10 @@ static struct ttm_tt *radeon_ttm_tt_create(struct >ttm_buffer_object *bo, > { > struct radeon_device *rdev; > struct radeon_ttm_tt *gtt; >+ enum ttm_caching caching; >+ struct radeon_bo *rbo; >+ >+ rbo = container_of(bo, struct radeon_bo, tbo); > > rdev = radeon_get_rdev(bo->bdev); > #if IS_ENABLED(CONFIG_AGP) >@@ -603,7 +607,15 @@ static struct ttm_tt *radeon_ttm_tt_create(struct >ttm_buffer_object *bo, > if (gtt == NULL) { > return NULL; > } >- if (ttm_dma_tt_init(>t->ttm, bo, page_flags)) { >+ >+ if (rbo->flags & RADEON_GEM_GTT_UC) >+ caching = ttm_uncached; >+ else if (rbo->flags & RADEON_GEM_GTT_WC) >+ caching = ttm_write_combined; >+ else >+ caching = ttm_cached; >+ >+ if (ttm_dma_tt_init(>t->ttm, bo, page_flags, caching)) { > kfree(gtt); > return NULL; > } >diff --git a/drivers/gpu/drm/ttm/ttm_agp_backend.c >b/drivers/gpu/drm/ttm/ttm_agp_backend.c >index a98fd795b752..a723062d37e7 100644 >--- a/drivers/gpu/drm/ttm/ttm_agp_backend.c >+++ b/drivers/gpu/drm/ttm/ttm_agp_backend.c >@@ -136,7 +136,7 @@ struct ttm_tt *ttm_agp_tt_create(struct >ttm_buffer_object *bo, > agp_be->mem = NULL; > agp_be->bridge = bridge; > >- if (ttm_tt_init(&agp_be->ttm, bo, page_flags)) { >+ if (ttm_tt_init(&agp_be->ttm, bo, page_flags, ttm_write_combined)) >{ > kfree(agp_be); > return NULL; > } >diff --git a/drivers/gpu/drm/ttm/ttm_tt.c b/drivers/gpu/drm/ttm/ttm_tt.c >index d4c80e0f3b3b..a465f51df027 100644 >--- a/drivers/gpu/drm/ttm/ttm_tt.c >+++ b/drivers/gpu/drm/ttm/ttm_tt.c >@@ -161,7 +161,8 @@ void ttm_tt_destroy(struct ttm_bo_device *bdev, >struct ttm_tt *ttm) > > static void ttm_tt_init_fields(struct ttm_tt *ttm, > struct ttm_buffer_object *bo, >- uint32_t page_flags) >+ uint32_t page_flags, >+ enum ttm_caching caching) > { > ttm->num_pages = bo->num_pages; > ttm->caching = ttm_cached; >@@ -169,12 +170,13 @@ static void ttm_tt_init_fields(struct ttm_tt *ttm, > ttm_tt_set_unpopulated(ttm); > ttm->swap_storage = NULL; > ttm->sg = bo->sg; >+ ttm->caching = caching; > } > > int ttm_tt_init(struct ttm_tt *ttm, struct ttm_buffer_object *bo, >- uint32_t page_flags) >+ uint32_t page_flags, enum ttm_caching caching) > { >- ttm_tt_init_fields(ttm, bo, page_flags); >+ ttm_tt_init_fields(ttm, bo, page_flags, caching); > > if (ttm_tt_alloc_page_directory(ttm)) { > pr_err("Failed allocating page table\n"); >@@ -192,11 +194,11 @@ void ttm_tt_fini(struct ttm_tt *ttm) > EXPORT_SYMBOL(ttm_tt_fini); > > int ttm_dma_tt_init(struct ttm_dma_tt *ttm_dma, struct ttm_buffer_object >*bo, >- uint32_t page_flags) >+ uint32_t page_flags, enum ttm_caching caching) > { > struct ttm_tt *ttm = &ttm_dma->ttm; > >- ttm_tt_init_fields(ttm, bo, page_flags); >+ ttm_tt_init_fields(ttm, bo, page_flags, caching); > > INIT_LIST_HEAD(&ttm_dma->pages_list); > if (ttm_dma_tt_alloc_page_directory(ttm_dma)) { >@@ -208,12 +210,12 @@ int ttm_dma_tt_init(struct ttm_dma_tt *ttm_dma, >struct ttm_buffer_object *bo, > EXPORT_SYMBOL(ttm_dma_tt_init); > > int ttm_sg_tt_init(struct ttm_dma_tt *ttm_dma, struct ttm_buffer_object >*bo, >- uint32_t page_flags) >+ uint32_t page_flags, enum ttm_caching caching) > { > struct ttm_tt *ttm = &ttm_dma->ttm; > int ret; > >- ttm_tt_init_fields(ttm, bo, page_flags); >+ ttm_tt_init_fields(ttm, bo, page_flags, caching); > > INIT_LIST_HEAD(&ttm_dma->pages_list); > if (page_flags & TTM_PAGE_FLAG_SG) >diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c >b/drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c >index fc68f54df46a..42f957d40c9f 100644 >--- a/drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c >+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c >@@ -647,9 +647,11 @@ static struct ttm_tt *vmw_ttm_tt_create(struct >ttm_buffer_object *bo, > vmw_be->mob = NULL; > > if (vmw_be->dev_priv->map_mode == vmw_dma_alloc_coherent) >- ret = ttm_dma_tt_init(&vmw_be->dma_ttm, bo, page_flags); >+ ret = ttm_dma_tt_init(&vmw_be->dma_ttm, bo, page_flags, >+ ttm_cached); > else >- ret = ttm_tt_init(&vmw_be->dma_ttm.ttm, bo, page_flags); >+ ret = ttm_tt_init(&vmw_be->dma_ttm.ttm, bo, page_flags, >+ ttm_cached); > if (unlikely(ret != 0)) > goto out_no_init; > >diff --git a/include/drm/ttm/ttm_tt.h b/include/drm/ttm/ttm_tt.h >index b90c8c451a54..c39c722d5184 100644 >--- a/include/drm/ttm/ttm_tt.h >+++ b/include/drm/ttm/ttm_tt.h >@@ -116,6 +116,7 @@ int ttm_tt_create(struct ttm_buffer_object *bo, bool >zero_alloc); > * @ttm: The struct ttm_tt. > * @bo: The buffer object we create the ttm for. > * @page_flags: Page flags as identified by TTM_PAGE_FLAG_XX flags. >+ * @caching: the desired caching state of the pages > * > * Create a struct ttm_tt to back data with system memory pages. > * No pages are actually allocated. >@@ -123,11 +124,11 @@ int ttm_tt_create(struct ttm_buffer_object *bo, >bool zero_alloc); > * NULL: Out of memory. > */ > int ttm_tt_init(struct ttm_tt *ttm, struct ttm_buffer_object *bo, >- uint32_t page_flags); >+ uint32_t page_flags, enum ttm_caching caching); > int ttm_dma_tt_init(struct ttm_dma_tt *ttm_dma, struct ttm_buffer_object >*bo, >- uint32_t page_flags); >+ uint32_t page_flags, enum ttm_caching caching); > int ttm_sg_tt_init(struct ttm_dma_tt *ttm_dma, struct ttm_buffer_object >*bo, >- uint32_t page_flags); >+ uint32_t page_flags, enum ttm_caching caching); > > /** > * ttm_tt_fini >-- >2.17.1 > >_______________________________________________ >dri-devel mailing list >dri-devel@xxxxxxxxxxxxxxxxxxxxx >https://lists.freedesktop.org/mailman/listinfo/dri-devel _______________________________________________ dri-devel mailing list dri-devel@xxxxxxxxxxxxxxxxxxxxx https://lists.freedesktop.org/mailman/listinfo/dri-devel