Skip to contentSkip to conversation

drm/amdgpu: Correct bytes limit for SDMA 3.0 copy and fill

PATCH In review Yong Zhao 2 participants 4 messages Sep 18, 2017 – Sep 19, 2017 2 messages not in the archive

Subsystems (2)
lore
Share & tools
lore

Yong Zhao

author
#0 lore raw

PATCH 1/2 drm/amdgpu: Correct bytes limit for SDMA 3.0 copy and fill

Change-Id I10fc5efbc303056c5c5c4dc4f4dd2c3186595a91
---
 drivers/gpu/drm/amd/amdgpu/sdma_v3_0.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/sdma_v3_0.c +2 -2
index 728c0d8..4e7fe07 100644
@@ -1730,11 +1730,11 @@ static void sdma_v3_0_emit_fill_buffer(struct amdgpu_ib *ib,
 }
 
 static const struct amdgpu_buffer_funcs sdma_v3_0_buffer_funcs = {
-	.copy_max_bytes = 0x1fffff,
+	.copy_max_bytes = 0x3fffe0, /* not 0x3fffff due to HW limitation*/
 	.copy_num_dw = 7,
 	.emit_copy_buffer = sdma_v3_0_emit_copy_buffer,
 
-	.fill_max_bytes = 0x1fffff,
+	.fill_max_bytes = 0x3fffe0, /* not 0x3fffff due to HW limitation*/
 	.fill_num_dw = 5,
 	.emit_fill_buffer = sdma_v3_0_emit_fill_buffer,
 };
Signature · 6 lines
2.7.4

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

A message that is not in the archive (sent off-list or not yet received): 1505762316-13975-1-git-send-email-yong.zhao-5C7GfCeVMHo@public.gmane.org

author
#2 lore raw

PATCH 2/2 drm/amdgpu: Fix a bug in amdgpu_fill_buffer()

When max_bytes is not 8 bytes aligned and bo size is larger than max_bytes, the last 8 bytes in a ttm node may be left unchanged. For example, on pre SDMA 4.0, max_bytes = 0x1fffff, and the bo size is 0x200000, the problem will happen.

In order to fix the problem, we store the max nums of PTEs/PDEs a single operation can set separately in amdgpu_vm_pte_funcs structure.

Change-Id I37c588a57cb63f1a8251fb5ead2eff4b39e047c9
---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h     | 6 ++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 8 ++++----
 drivers/gpu/drm/amd/amdgpu/cik_sdma.c   | 3 +++
 drivers/gpu/drm/amd/amdgpu/sdma_v2_4.c  | 3 +++
 drivers/gpu/drm/amd/amdgpu/sdma_v3_0.c  | 3 +++
 drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c  | 3 +++
 drivers/gpu/drm/amd/amdgpu/si_dma.c     | 3 +++
 7 files changed, 25 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +6 -0
index a34c4cb..91bb111 100644
@@ -309,6 +309,12 @@ struct amdgpu_vm_pte_funcs {
 			    uint64_t pe,
 			    uint64_t addr, unsigned count,
 			    uint32_t incr, uint64_t flags);
+
+	/* maximum nums of PTEs/PDEs in a single operation */
+	uint32_t	set_max_nums_pte_pde;
+
+	/* number of dw to reserve per operation */
+	unsigned	set_pte_pde_num_dw;
 };
 
 /* provided by the gmc block */
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +4 -4
index 2180ed3..8685b0c 100644
@@ -1556,8 +1556,8 @@ int amdgpu_fill_buffer(struct amdgpu_bo *bo,
 		       struct dma_fence **fence)
 {
 	struct amdgpu_device *adev = amdgpu_ttm_adev(bo->tbo.bdev);
-	/* max_bytes applies to SDMA_OP_PTEPDE as well as SDMA_OP_CONST_FILL*/
-	uint32_t max_bytes = adev->mman.buffer_funcs->fill_max_bytes;
+	uint32_t max_bytes = 8 *
+			adev->vm_manager.vm_pte_funcs->set_max_nums_pte_pde;
 	struct amdgpu_ring *ring = adev->mman.buffer_funcs_ring;
 
 	struct drm_mm_node *mm_node;
@@ -1589,8 +1589,8 @@ int amdgpu_fill_buffer(struct amdgpu_bo *bo,
 		++mm_node;
 	}
 
-	/* 10 double words for each SDMA_OP_PTEPDE cmd */
-	num_dw = num_loops * 10;
+	/* num of dwords for each SDMA_OP_PTEPDE cmd */
+	num_dw = num_loops * adev->vm_manager.vm_pte_funcs->set_pte_pde_num_dw;
 
 	/* for IB padding */
 	num_dw += 64;
drivers/gpu/drm/amd/amdgpu/cik_sdma.c +3 -0
index f508f4d..ff59351 100644
@@ -1390,6 +1390,9 @@ static const struct amdgpu_vm_pte_funcs cik_sdma_vm_pte_funcs = {
 	.copy_pte = cik_sdma_vm_copy_pte,
 	.write_pte = cik_sdma_vm_write_pte,
 	.set_pte_pde = cik_sdma_vm_set_pte_pde,
+
+	.set_max_nums_pte_pde = 0x1fffff >> 3,
+	.set_pte_pde_num_dw = 10,
 };
 
 static void cik_sdma_set_vm_pte_funcs(struct amdgpu_device *adev)
drivers/gpu/drm/amd/amdgpu/sdma_v2_4.c +3 -0
index f2d0710..aec3586 100644
@@ -1327,6 +1327,9 @@ static const struct amdgpu_vm_pte_funcs sdma_v2_4_vm_pte_funcs = {
 	.copy_pte = sdma_v2_4_vm_copy_pte,
 	.write_pte = sdma_v2_4_vm_write_pte,
 	.set_pte_pde = sdma_v2_4_vm_set_pte_pde,
+
+	.set_max_nums_pte_pde = 0x1fffff >> 3,
+	.set_pte_pde_num_dw = 10,
 };
 
 static void sdma_v2_4_set_vm_pte_funcs(struct amdgpu_device *adev)
drivers/gpu/drm/amd/amdgpu/sdma_v3_0.c +3 -0
index 4e7fe07..7610272 100644
@@ -1751,6 +1751,9 @@ static const struct amdgpu_vm_pte_funcs sdma_v3_0_vm_pte_funcs = {
 	.copy_pte = sdma_v3_0_vm_copy_pte,
 	.write_pte = sdma_v3_0_vm_write_pte,
 	.set_pte_pde = sdma_v3_0_vm_set_pte_pde,
+
+	.set_max_nums_pte_pde = 0x3fffe0 >> 3,
+	.set_pte_pde_num_dw = 10,
 };
 
 static void sdma_v3_0_set_vm_pte_funcs(struct amdgpu_device *adev)
drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c +3 -0
index fd7c72a..6e1e0c0 100644
@@ -1717,6 +1717,9 @@ static const struct amdgpu_vm_pte_funcs sdma_v4_0_vm_pte_funcs = {
 	.copy_pte = sdma_v4_0_vm_copy_pte,
 	.write_pte = sdma_v4_0_vm_write_pte,
 	.set_pte_pde = sdma_v4_0_vm_set_pte_pde,
+
+	.set_max_nums_pte_pde = 0x400000 >> 3,
+	.set_pte_pde_num_dw = 10,
 };
 
 static void sdma_v4_0_set_vm_pte_funcs(struct amdgpu_device *adev)
drivers/gpu/drm/amd/amdgpu/si_dma.c +3 -0
index 112969f..2d3091f 100644
@@ -890,6 +890,9 @@ static const struct amdgpu_vm_pte_funcs si_dma_vm_pte_funcs = {
 	.copy_pte = si_dma_vm_copy_pte,
 	.write_pte = si_dma_vm_write_pte,
 	.set_pte_pde = si_dma_vm_set_pte_pde,
+
+	.set_max_nums_pte_pde = 0xffff8 >> 3,
+	.set_pte_pde_num_dw = 9,
 };
 
 static void si_dma_set_vm_pte_funcs(struct amdgpu_device *adev)
Signature · 6 lines
2.7.4

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

A message that is not in the archive (sent off-list or not yet received): 1505762316-13975-2-git-send-email-yong.zhao-5C7GfCeVMHo@public.gmane.org

#4 lore raw

Re: [PATCH 2/2] drm/amdgpu: Fix a bug in amdgpu_fill_buffer()

Am 18.09.2017 um 21:18 schrieb Yong Zhao:

Quoted 11 lines

When max_bytes is not 8 bytes aligned and bo size is larger than max_bytes, the last 8 bytes in a ttm node may be left unchanged. For example, on pre SDMA 4.0, max_bytes = 0x1fffff, and the bo size is 0x200000, the problem will happen.

In order to fix the problem, we store the max nums of PTEs/PDEs a single operation can set separately in amdgpu_vm_pte_funcs structure.

Change-Id I37c588a57cb63f1a8251fb5ead2eff4b39e047c9

Looks really good to me, patch is Reviewed-by: Christian König <[email protected]>.

Bonus points for finding the right lines in amdgpu_vm_bo_update_mapping() and replace the hard coded "10" there with the value from amdgpu_vm_pte_funcs as well.

Regards,
Christian.

Quoted 114 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu.h     | 6 ++++++
  drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 8 ++++----
  drivers/gpu/drm/amd/amdgpu/cik_sdma.c   | 3 +++
  drivers/gpu/drm/amd/amdgpu/sdma_v2_4.c  | 3 +++
  drivers/gpu/drm/amd/amdgpu/sdma_v3_0.c  | 3 +++
  drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c  | 3 +++
  drivers/gpu/drm/amd/amdgpu/si_dma.c     | 3 +++
  7 files changed, 25 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +6 -0
index a34c4cb..91bb111 100644
@@ -309,6 +309,12 @@ struct amdgpu_vm_pte_funcs {
  			    uint64_t pe,
  			    uint64_t addr, unsigned count,
  			    uint32_t incr, uint64_t flags);
+
+	/* maximum nums of PTEs/PDEs in a single operation */
+	uint32_t	set_max_nums_pte_pde;
+
+	/* number of dw to reserve per operation */
+	unsigned	set_pte_pde_num_dw;
  };
 
  /* provided by the gmc block */
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +4 -4
index 2180ed3..8685b0c 100644
@@ -1556,8 +1556,8 @@ int amdgpu_fill_buffer(struct amdgpu_bo *bo,
  		       struct dma_fence **fence)
  {
  	struct amdgpu_device *adev = amdgpu_ttm_adev(bo->tbo.bdev);
-	/* max_bytes applies to SDMA_OP_PTEPDE as well as SDMA_OP_CONST_FILL*/
-	uint32_t max_bytes = adev->mman.buffer_funcs->fill_max_bytes;
+	uint32_t max_bytes = 8 *
+			adev->vm_manager.vm_pte_funcs->set_max_nums_pte_pde;
  	struct amdgpu_ring *ring = adev->mman.buffer_funcs_ring;
 
  	struct drm_mm_node *mm_node;
@@ -1589,8 +1589,8 @@ int amdgpu_fill_buffer(struct amdgpu_bo *bo,
  		++mm_node;
  	}
 
-	/* 10 double words for each SDMA_OP_PTEPDE cmd */
-	num_dw = num_loops * 10;
+	/* num of dwords for each SDMA_OP_PTEPDE cmd */
+	num_dw = num_loops * adev->vm_manager.vm_pte_funcs->set_pte_pde_num_dw;
 
  	/* for IB padding */
  	num_dw += 64;
drivers/gpu/drm/amd/amdgpu/cik_sdma.c +3 -0
index f508f4d..ff59351 100644
@@ -1390,6 +1390,9 @@ static const struct amdgpu_vm_pte_funcs cik_sdma_vm_pte_funcs = {
  	.copy_pte = cik_sdma_vm_copy_pte,
  	.write_pte = cik_sdma_vm_write_pte,
  	.set_pte_pde = cik_sdma_vm_set_pte_pde,
+
+	.set_max_nums_pte_pde = 0x1fffff >> 3,
+	.set_pte_pde_num_dw = 10,
  };
 
  static void cik_sdma_set_vm_pte_funcs(struct amdgpu_device *adev)
drivers/gpu/drm/amd/amdgpu/sdma_v2_4.c +3 -0
index f2d0710..aec3586 100644
@@ -1327,6 +1327,9 @@ static const struct amdgpu_vm_pte_funcs sdma_v2_4_vm_pte_funcs = {
  	.copy_pte = sdma_v2_4_vm_copy_pte,
  	.write_pte = sdma_v2_4_vm_write_pte,
  	.set_pte_pde = sdma_v2_4_vm_set_pte_pde,
+
+	.set_max_nums_pte_pde = 0x1fffff >> 3,
+	.set_pte_pde_num_dw = 10,
  };
 
  static void sdma_v2_4_set_vm_pte_funcs(struct amdgpu_device *adev)
drivers/gpu/drm/amd/amdgpu/sdma_v3_0.c +3 -0
index 4e7fe07..7610272 100644
@@ -1751,6 +1751,9 @@ static const struct amdgpu_vm_pte_funcs sdma_v3_0_vm_pte_funcs = {
  	.copy_pte = sdma_v3_0_vm_copy_pte,
  	.write_pte = sdma_v3_0_vm_write_pte,
  	.set_pte_pde = sdma_v3_0_vm_set_pte_pde,
+
+	.set_max_nums_pte_pde = 0x3fffe0 >> 3,
+	.set_pte_pde_num_dw = 10,
  };
 
  static void sdma_v3_0_set_vm_pte_funcs(struct amdgpu_device *adev)
drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c +3 -0
index fd7c72a..6e1e0c0 100644
@@ -1717,6 +1717,9 @@ static const struct amdgpu_vm_pte_funcs sdma_v4_0_vm_pte_funcs = {
  	.copy_pte = sdma_v4_0_vm_copy_pte,
  	.write_pte = sdma_v4_0_vm_write_pte,
  	.set_pte_pde = sdma_v4_0_vm_set_pte_pde,
+
+	.set_max_nums_pte_pde = 0x400000 >> 3,
+	.set_pte_pde_num_dw = 10,
  };
 
  static void sdma_v4_0_set_vm_pte_funcs(struct amdgpu_device *adev)
drivers/gpu/drm/amd/amdgpu/si_dma.c +0 -0
index 112969f..2d3091f 100644

drivers/gpu/drm/amd/amdgpu/si_dma.c static const struct amdgpu_vm_pte_funcs si_dma_vm_pte_funcs = { · line 898

Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/si_dma.c +3 -0
@@ -890,6 +890,9 @@ static const struct amdgpu_vm_pte_funcs si_dma_vm_pte_funcs = {
  	.copy_pte = si_dma_vm_copy_pte,
  	.write_pte = si_dma_vm_write_pte,
  	.set_pte_pde = si_dma_vm_set_pte_pde,
+
+	.set_max_nums_pte_pde = 0xffff8 >> 3,
+	.set_pte_pde_num_dw = 9,
  };
 
  static void si_dma_set_vm_pte_funcs(struct amdgpu_device *adev)

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

Reviewed-by
#5 lore raw
In reply to a message not in the archive

Am 18.09.2017 um 21:18 schrieb Yong Zhao:

Quoted 2 lines
Change-Id I10fc5efbc303056c5c5c4dc4f4dd2c3186595a91
Quoted 12 lines
---
  drivers/gpu/drm/amd/amdgpu/sdma_v3_0.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/sdma_v3_0.c +0 -0
index 728c0d8..4e7fe07 100644
@@ -1730,11 +1730,11 @@ static void sdma_v3_0_emit_fill_buffer(struct amdgpu_ib *ib,
  }
 
  static const struct amdgpu_buffer_funcs sdma_v3_0_buffer_funcs = {

drivers/gpu/drm/amd/amdgpu/sdma_v3_0.c static void sdma_v3_0_emit_fill_buffer(struct amdgpu_ib *ib, · line 1740

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/sdma_v3_0.c +2 -2
-	.copy_max_bytes = 0x1fffff,
+	.copy_max_bytes = 0x3fffe0, /* not 0x3fffff due to HW limitation*/
  	.copy_num_dw = 7,
  	.emit_copy_buffer = sdma_v3_0_emit_copy_buffer,
 
-	.fill_max_bytes = 0x1fffff,
+	.fill_max_bytes = 0x3fffe0, /* not 0x3fffff due to HW limitation*/
  	.fill_num_dw = 5,
  	.emit_fill_buffer = sdma_v3_0_emit_fill_buffer,
  };

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