Skip to contentSkip to conversation

drm/amdgpu: Make contiguous pinning optional

PATCH In review Felix Kuehling 2 participants 2 messages Jan 21, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/amdgpu: Make contiguous pinning optional

Enable pinning of VRAM without forcing it to be contiguous. When memory is already pinned, make sure it's contiguous if requested.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +6 -1
index d026cef8e520..137f275f90ee 100644
@@ -914,10 +914,15 @@ int amdgpu_bo_pin_restricted(struct amdgpu_bo *bo, u32 domain,
 
 	if (bo->pin_count) {
 		uint32_t mem_type = bo->tbo.mem.mem_type;
+		uint32_t mem_flags = bo->tbo.mem.placement;
 
 		if (!(domain & amdgpu_mem_type_to_domain(mem_type)))
 			return -EINVAL;
 
+		if ((bo->flags & AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS) &&
+		    !(mem_flags & TTM_PL_FLAG_CONTIGUOUS))
+			return -EINVAL;
+
 		bo->pin_count++;
 
 		if (max_offset != 0) {
@@ -933,7 +938,6 @@ int amdgpu_bo_pin_restricted(struct amdgpu_bo *bo, u32 domain,
 	if (bo->tbo.base.import_attach)
 		dma_buf_pin(bo->tbo.base.import_attach);
 
-	bo->flags |= AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS;
 	/* force to pin into visible video ram */
 	if (!(bo->flags & AMDGPU_GEM_CREATE_NO_CPU_ACCESS))
 		bo->flags |= AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED;
@@ -987,6 +991,7 @@ int amdgpu_bo_pin_restricted(struct amdgpu_bo *bo, u32 domain,
  */
 int amdgpu_bo_pin(struct amdgpu_bo *bo, u32 domain)
 {
+	bo->flags |= AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS;
 	return amdgpu_bo_pin_restricted(bo, domain, 0, 0);
 }
 
Signature · 6 lines
2.30.0

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
maintainer Reviewed-by on v1 1/1
#1 lore raw

Am 21.01.21 um 06:08 schrieb Felix Kuehling:

Quoted 5 lines

Enable pinning of VRAM without forcing it to be contiguous. When memory is already pinned, make sure it's contiguous if requested.

Quoted 33 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 7 ++++++-
  1 file changed, 6 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +5 -1
index d026cef8e520..137f275f90ee 100644
@@ -914,10 +914,15 @@ int amdgpu_bo_pin_restricted(struct amdgpu_bo *bo, u32 domain,
 
  	if (bo->pin_count) {
  		uint32_t mem_type = bo->tbo.mem.mem_type;
+		uint32_t mem_flags = bo->tbo.mem.placement;
 
  		if (!(domain & amdgpu_mem_type_to_domain(mem_type)))
  			return -EINVAL;
 
+		if ((bo->flags & AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS) &&
+		    !(mem_flags & TTM_PL_FLAG_CONTIGUOUS))
+			return -EINVAL;
+
  		bo->pin_count++;
 
  		if (max_offset != 0) {
@@ -933,7 +938,6 @@ int amdgpu_bo_pin_restricted(struct amdgpu_bo *bo, u32 domain,
  	if (bo->tbo.base.import_attach)
  		dma_buf_pin(bo->tbo.base.import_attach);
 
-	bo->flags |= AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS;
  	/* force to pin into visible video ram */
  	if (!(bo->flags & AMDGPU_GEM_CREATE_NO_CPU_ACCESS))
  		bo->flags |= AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED;

drivers/gpu/drm/amd/amdgpu/amdgpu_object.c int amdgpu_bo_pin_restricted(struct amdgpu_bo *bo, u32 domain, · line 997

Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +1 -0
@@ -987,6 +991,7 @@ int amdgpu_bo_pin_restricted(struct amdgpu_bo *bo, u32 domain,
   */
  int amdgpu_bo_pin(struct amdgpu_bo *bo, u32 domain)
  {
+	bo->flags |= AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS;
  	return amdgpu_bo_pin_restricted(bo, domain, 0, 0);
  }
 

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx