drm/amdgpu: Fix a bug in amdgpu_fill_buffer()
Subsystems (2)
PATCH 1/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 separately store the max nums of PTEs/PDEs a single operation can set in amdgpu_vm_pte_funcs structure, rather than inferring it from bytes limit of SDMA constant fill, i.e. fill_max_bytes.
Together with the fix, we replace the hard code value "10" in amdgpu_vm_bo_update_mapping() with the corresponding values from structure amdgpu_vm_pte_funcs.
--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 7 +++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 8 ++++---- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 5 +++-- 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 | 4 ++++ drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c | 3 +++ drivers/gpu/drm/amd/amdgpu/si_dma.c | 3 +++ 8 files changed, 30 insertions(+), 6 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +7 -0
@@ -304,6 +304,13 @@ struct amdgpu_vm_pte_funcs {void (*write_pte)(struct amdgpu_ib *ib,uint64_t pe,uint64_t value,unsigned count,uint32_t incr); + +/* 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; +/* for linear pte/pde updates without addr mapping */ void (*set_pte_pde)(struct amdgpu_ib *ib, uint64_t pe,
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +4 -4
@@ -1527,8 +1527,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;
@@ -1560,8 +1560,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/amdgpu_vm.c +3 -2
@@ -1606,10 +1606,11 @@ static int amdgpu_vm_bo_update_mapping(struct amdgpu_device *adev, }else {/* set page commands needed */ - ndw += ncmds *10 ; + ndw += ncmds * adev->vm_manager.vm_pte_funcs->set_pte_pde_num_dw;/* extra commands for begin/end fragments */ - ndw +=2 *10 * adev->vm_manager.fragment_size; + ndw +=2 * adev->vm_manager.vm_pte_funcs->set_pte_pde_num_dw + * adev->vm_manager.fragment_size; params.func = amdgpu_vm_do_set_ptes; }
drivers/gpu/drm/amd/amdgpu/cik_sdma.c +3 -0
@@ -1389,6 +1389,9 @@ static void cik_sdma_set_buffer_funcs(struct amdgpu_device *adev)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_max_nums_pte_pde =0x1fffff >>3 , + .set_pte_pde_num_dw =10 , .set_pte_pde = cik_sdma_vm_set_pte_pde, };
drivers/gpu/drm/amd/amdgpu/sdma_v2_4.c +3 -0
@@ -1326,6 +1326,9 @@ static void sdma_v2_4_set_buffer_funcs(struct amdgpu_device *adev)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_max_nums_pte_pde =0x1fffff >>3 , + .set_pte_pde_num_dw =10 , .set_pte_pde = sdma_v2_4_vm_set_pte_pde, };
drivers/gpu/drm/amd/amdgpu/sdma_v3_0.c +4 -0
@@ -1750,6 +1750,10 @@ static void sdma_v3_0_set_buffer_funcs(struct amdgpu_device *adev)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, + +/* not 0x3fffff due to HW limitation */ + .set_max_nums_pte_pde =0x3fffe0 >>3 , + .set_pte_pde_num_dw =10 , .set_pte_pde = sdma_v3_0_vm_set_pte_pde, };
drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c +3 -0
@@ -1716,6 +1716,9 @@ static void sdma_v4_0_set_buffer_funcs(struct amdgpu_device *adev)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_max_nums_pte_pde =0x400000 >>3 , + .set_pte_pde_num_dw =10 , .set_pte_pde = sdma_v4_0_vm_set_pte_pde, };
drivers/gpu/drm/amd/amdgpu/si_dma.c +3 -0
@@ -889,6 +889,9 @@ static void si_dma_set_buffer_funcs(struct amdgpu_device *adev)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_max_nums_pte_pde =0xffff8 >>3 , + .set_pte_pde_num_dw =9 , .set_pte_pde = si_dma_vm_set_pte_pde, };
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): 1505840849-5061-1-git-send-email-yong.zhao-5C7GfCeVMHo@public.gmane.org
PATCH 2/2 drm/amdgpu: Add copy_pte_num_dw member in amdgpu_vm_pte_funcs
Use it to replace the hard coded value in amdgpu_vm_bo_update_mapping().
--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 4 ++++ drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 2 +- drivers/gpu/drm/amd/amdgpu/cik_sdma.c | 2 ++ drivers/gpu/drm/amd/amdgpu/sdma_v2_4.c | 2 ++ drivers/gpu/drm/amd/amdgpu/sdma_v3_0.c | 2 ++ drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c | 2 ++ drivers/gpu/drm/amd/amdgpu/si_dma.c | 2 ++ 7 files changed, 15 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +4 -0
@@ -296,10 +296,14 @@ struct amdgpu_buffer_funcs {/* provided by hw blocks that can write ptes, e.g., sdma */ struct amdgpu_vm_pte_funcs { +/* number of dw to reserve per operation */ +unsigned copy_pte_num_dw; +/* copy pte entries from GART */ void (*copy_pte)(struct amdgpu_ib *ib,uint64_t pe,uint64_t src,unsigned count); +/* write pte one entry at a time with addr mapping */ void (*write_pte)(struct amdgpu_ib *ib, uint64_t pe, uint64_t value, unsigned count,
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1 -1
@@ -1597,7 +1597,7 @@ static int amdgpu_vm_bo_update_mapping(struct amdgpu_device *adev,if (pages_addr) {/* copy commands needed */ - ndw += ncmds *7 ; + ndw += ncmds * adev->vm_manager.vm_pte_funcs->copy_pte_num_dw;/* and also PTEs */ ndw += nptes *2 ;
drivers/gpu/drm/amd/amdgpu/cik_sdma.c +2 -0
@@ -1387,7 +1387,9 @@ static void cik_sdma_set_buffer_funcs(struct amdgpu_device *adev) }static const struct amdgpu_vm_pte_funcs cik_sdma_vm_pte_funcs = { + .copy_pte_num_dw =7 , .copy_pte = cik_sdma_vm_copy_pte, + .write_pte = cik_sdma_vm_write_pte, .set_max_nums_pte_pde =0x1fffff >>3 ,
drivers/gpu/drm/amd/amdgpu/sdma_v2_4.c +2 -0
@@ -1324,7 +1324,9 @@ static void sdma_v2_4_set_buffer_funcs(struct amdgpu_device *adev) }static const struct amdgpu_vm_pte_funcs sdma_v2_4_vm_pte_funcs = { + .copy_pte_num_dw =7 , .copy_pte = sdma_v2_4_vm_copy_pte, + .write_pte = sdma_v2_4_vm_write_pte, .set_max_nums_pte_pde =0x1fffff >>3 ,
drivers/gpu/drm/amd/amdgpu/sdma_v3_0.c +2 -0
@@ -1748,7 +1748,9 @@ static void sdma_v3_0_set_buffer_funcs(struct amdgpu_device *adev) }static const struct amdgpu_vm_pte_funcs sdma_v3_0_vm_pte_funcs = { + .copy_pte_num_dw =7 , .copy_pte = sdma_v3_0_vm_copy_pte, + .write_pte = sdma_v3_0_vm_write_pte,/* not 0x3fffff due to HW limitation */
drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c +2 -0
@@ -1714,7 +1714,9 @@ static void sdma_v4_0_set_buffer_funcs(struct amdgpu_device *adev) }static const struct amdgpu_vm_pte_funcs sdma_v4_0_vm_pte_funcs = { + .copy_pte_num_dw =7 , .copy_pte = sdma_v4_0_vm_copy_pte, + .write_pte = sdma_v4_0_vm_write_pte, .set_max_nums_pte_pde =0x400000 >>3 ,
drivers/gpu/drm/amd/amdgpu/si_dma.c +2 -0
@@ -887,7 +887,9 @@ static void si_dma_set_buffer_funcs(struct amdgpu_device *adev) }static const struct amdgpu_vm_pte_funcs si_dma_vm_pte_funcs = { + .copy_pte_num_dw =5 , .copy_pte = si_dma_vm_copy_pte, + .write_pte = si_dma_vm_write_pte, .set_max_nums_pte_pde =0xffff8 >>3 ,
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): 1505840849-5061-2-git-send-email-yong.zhao-5C7GfCeVMHo@public.gmane.org
Christian König
Reviewed-byRe: [PATCH 2/2] drm/amdgpu: Add copy_pte_num_dw member in amdgpu_vm_pte_funcs
Am 19.09.2017 um 19:07 schrieb Yong Zhao:
Quoted 4 lines
Use it to replace the hard coded value in
amdgpu_vm_bo_update_mapping().Change-Id I85d89d401b8dbcf01ca9c55c281e552db874fde5Signed-off-by Yong Zhao <[email protected]>
Quoted 103 lines
--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 4 ++++ drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 2 +- drivers/gpu/drm/amd/amdgpu/cik_sdma.c | 2 ++ drivers/gpu/drm/amd/amdgpu/sdma_v2_4.c | 2 ++ drivers/gpu/drm/amd/amdgpu/sdma_v3_0.c | 2 ++ drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c | 2 ++ drivers/gpu/drm/amd/amdgpu/si_dma.c | 2 ++ 7 files changed, 15 insertions(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/amdgpu.h +4
-0@@ -296,10 +296,14 @@ struct amdgpu_buffer_funcs {/* provided by hw blocks that can write ptes, e.g., sdma */ struct amdgpu_vm_pte_funcs { +/* number of dw to reserve per operation */ +unsigned copy_pte_num_dw; +/* copy pte entries from GART */ void (*copy_pte)(struct amdgpu_ib *ib,uint64_t pe,uint64_t src,unsigned count); +/* write pte one entry at a time with addr mapping */ void (*write_pte)(struct amdgpu_ib *ib, uint64_t pe, uint64_t value, unsigned count,drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1
-1@@ -1597,7 +1597,7 @@ static int amdgpu_vm_bo_update_mapping(struct amdgpu_device *adev,if (pages_addr) {/* copy commands needed */ - ndw += ncmds *7 ; + ndw += ncmds * adev->vm_manager.vm_pte_funcs->copy_pte_num_dw;/* and also PTEs */ ndw += nptes *2 ;drivers/gpu/drm/amd/amdgpu/cik_sdma.c +2
-0@@ -1387,7 +1387,9 @@ static void cik_sdma_set_buffer_funcs(struct amdgpu_device *adev) }static const struct amdgpu_vm_pte_funcs cik_sdma_vm_pte_funcs = { + .copy_pte_num_dw =7 , .copy_pte = cik_sdma_vm_copy_pte, + .write_pte = cik_sdma_vm_write_pte, .set_max_nums_pte_pde =0x1fffff >>3 ,drivers/gpu/drm/amd/amdgpu/sdma_v2_4.c +2
-0@@ -1324,7 +1324,9 @@ static void sdma_v2_4_set_buffer_funcs(struct amdgpu_device *adev) }static const struct amdgpu_vm_pte_funcs sdma_v2_4_vm_pte_funcs = { + .copy_pte_num_dw =7 , .copy_pte = sdma_v2_4_vm_copy_pte, + .write_pte = sdma_v2_4_vm_write_pte, .set_max_nums_pte_pde =0x1fffff >>3 ,drivers/gpu/drm/amd/amdgpu/sdma_v3_0.c +2
-0@@ -1748,7 +1748,9 @@ static void sdma_v3_0_set_buffer_funcs(struct amdgpu_device *adev) }static const struct amdgpu_vm_pte_funcs sdma_v3_0_vm_pte_funcs = { + .copy_pte_num_dw =7 , .copy_pte = sdma_v3_0_vm_copy_pte, + .write_pte = sdma_v3_0_vm_write_pte,/* not 0x3fffff due to HW limitation */ drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c +2
-0@@ -1714,7 +1714,9 @@ static void sdma_v4_0_set_buffer_funcs(struct amdgpu_device *adev) }static const struct amdgpu_vm_pte_funcs sdma_v4_0_vm_pte_funcs = { + .copy_pte_num_dw =7 , .copy_pte = sdma_v4_0_vm_copy_pte, + .write_pte = sdma_v4_0_vm_write_pte, .set_max_nums_pte_pde =0x400000 >>3 ,drivers/gpu/drm/amd/amdgpu/si_dma.c +0
-0
drivers/gpu/drm/amd/amdgpu/si_dma.c static void si_dma_set_buffer_funcs(struct amdgpu_device *adev) · line 895
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/si_dma.c +2
-0@@ -887,7 +887,9 @@ static void si_dma_set_buffer_funcs(struct amdgpu_device *adev) }static const struct amdgpu_vm_pte_funcs si_dma_vm_pte_funcs = { + .copy_pte_num_dw =5 , .copy_pte = si_dma_vm_copy_pte, + .write_pte = si_dma_vm_write_pte, .set_max_nums_pte_pde =0xffff8 >>3 ,
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx