drm/amdgpu: preparation patchs for the use all SDMA instances series
Subsystems (4)
v4 cover drm/amdgpu: preparation patchs for the use all SDMA instances series
This series is a subset of the "use all SDMA instances" series. It starts at the first modified patch and ends at the last patch before the drm/ttm patch that got merged through drm-misc-next.
v3 of the full series:
https://lists.freedesktop.org/archives/dri-devel/2025-November/537830.html
Pierre-Eric Pelloux-Prayer (13):
drm/amdgpu: introduce amdgpu_ttm_buffer_entity drm/amdgpu: add amdgpu_ttm_job_submit helper drm/amdgpu: fix error handling in amdgpu_copy_buffer drm/amdgpu: pass the entity to use to amdgpu_ttm_map_buffer drm/amdgpu: pass the entity to use to ttm public functions drm/amdgpu: statically assign gart windows to ttm entities drm/amdgpu: remove AMDGPU_GTT_NUM_TRANSFER_WINDOWS drm/amdgpu: add missing lock in amdgpu_benchmark_do_move drm/amdgpu: check entity lock is held in amdgpu_ttm_job_submit drm/amdgpu: double AMDGPU_GTT_MAX_TRANSFER_SIZE drm/amdgpu: use larger gart window when possible drm/amdgpu: introduce amdgpu_sdma_set_vm_pte_scheds drm/amdgpu: move sched status check inside
amdgpu_ttm_set_buffer_funcs_status
drivers/gpu/drm/amd/amdgpu/amdgpu.h | 2 + drivers/gpu/drm/amd/amdgpu/amdgpu_benchmark.c | 5 +- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 13 +- drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c | 8 +- drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c | 8 +- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 4 +- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 295 ++++++++++++------ drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h | 54 +++- drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c | 6 +- drivers/gpu/drm/amd/amdgpu/amdgpu_vce.h | 3 +- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 17 + drivers/gpu/drm/amd/amdgpu/cik_sdma.c | 31 +- drivers/gpu/drm/amd/amdgpu/sdma_v2_4.c | 31 +- drivers/gpu/drm/amd/amdgpu/sdma_v3_0.c | 31 +- drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c | 35 +-- drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c | 35 +-- drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c | 31 +- drivers/gpu/drm/amd/amdgpu/sdma_v5_2.c | 31 +- drivers/gpu/drm/amd/amdgpu/sdma_v6_0.c | 29 +- drivers/gpu/drm/amd/amdgpu/sdma_v7_0.c | 29 +- drivers/gpu/drm/amd/amdgpu/si_dma.c | 31 +- drivers/gpu/drm/amd/amdgpu/vce_v1_0.c | 12 +- drivers/gpu/drm/amd/amdkfd/kfd_migrate.c | 25 +- 23 files changed, 381 insertions(+), 385 deletions(-)
Signature · 1 line
2.43.0
PATCH v4 1/13 drm/amdgpu: introduce amdgpu_ttm_buffer_entity
No functional change for now, but this struct will have more fields added in the next commit.
This change would introduce synchronisation issue, because dependencies between successive jobs are not taken care of properly. For instance, amdgpu_ttm_clear_buffer uses amdgpu_ttm_map_buffer then amdgpu_ttm_fill_mem which should use different entities (default_entity then move/clear entity). To prevent failures for this commit, we limit ourselves to 2 entities: default_entity (which replaces high_pr usages) and clear_entity (which replaces low_pr usages).
The next commits will deal with these dependencies correctly, and then we'll be able to use move_entity.
---
v2: renamed amdgpu_ttm_buffer_entity
v4: don't use move_entity in ttm yet
---
--- drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 30 +++++++++++++++++------- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h | 12 ++++++---- drivers/gpu/drm/amd/amdkfd/kfd_migrate.c | 13 ++++++---- 4 files changed, 39 insertions(+), 18 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +1 -1
@@ -687,7 +687,7 @@ void amdgpu_gmc_flush_gpu_tlb(struct amdgpu_device *adev, uint32_t vmid,* itself at least for GART. */ mutex_lock (&adev->mman.gtt_window_lock); - r =amdgpu_job_alloc_with_ib (ring->adev, &adev->mman.high_pr, + r =amdgpu_job_alloc_with_ib (ring->adev, &adev->mman.default_entity.base,AMDGPU_FENCE_OWNER_UNDEFINED ,16 *4 ,AMDGPU_IB_POOL_IMMEDIATE , &job,AMDGPU_KERNEL_JOB_ID_FLUSH_GPU_TLB );
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +21 -9
@@ -223,7 +223,7 @@ static int amdgpu_ttm_map_buffer(struct ttm_buffer_object *bo, num_dw =ALIGN (adev->mman.buffer_funcs->copy_num_dw,8 ); num_bytes = num_pages *8 *AMDGPU_GPU_PAGES_IN_CPU_PAGE ; - r = amdgpu_job_alloc_with_ib(adev, &adev->mman.high_pr, + r = amdgpu_job_alloc_with_ib(adev, &adev->mman.default_entity.base, AMDGPU_FENCE_OWNER_UNDEFINED, num_dw * 4 + num_bytes, AMDGPU_IB_POOL_DELAYED, &job,
@@ -1478,7 +1478,7 @@ static int amdgpu_ttm_access_memory_sdma(struct ttm_buffer_object *bo,memcpy (adev->mman.sdma_access_ptr, buf, len); num_dw =ALIGN (adev->mman.buffer_funcs->copy_num_dw,8 ); - r = amdgpu_job_alloc_with_ib(adev, &adev->mman.high_pr, + r = amdgpu_job_alloc_with_ib(adev, &adev->mman.default_entity.base, AMDGPU_FENCE_OWNER_UNDEFINED, num_dw * 4, AMDGPU_IB_POOL_DELAYED, &job,
@@ -2162,7 +2162,7 @@ void amdgpu_ttm_set_buffer_funcs_status(struct amdgpu_device *adev, bool enable) ring = adev->mman.buffer_funcs_ring; sched = &ring->sched; - r =drm_sched_entity_init (&adev->mman.high_pr, + r =drm_sched_entity_init (&adev->mman.default_entity.base,DRM_SCHED_PRIORITY_KERNEL , &sched,1 ,NULL );if (r) {
@@ -2172,18 +2172,30 @@ void amdgpu_ttm_set_buffer_funcs_status(struct amdgpu_device *adev, bool enable)return ; } - r =drm_sched_entity_init (&adev->mman.low_pr, + r =drm_sched_entity_init (&adev->mman.clear_entity.base, +DRM_SCHED_PRIORITY_NORMAL , &sched, +1 ,NULL ); +if (r) { +dev_err (adev->dev, +"Failed setting up TTM BO clear entity (%d)\n" , + r); + goto error_free_entity; + } + + r =drm_sched_entity_init (&adev->mman.move_entity.base,DRM_SCHED_PRIORITY_NORMAL , &sched,1 ,NULL );if (r) {dev_err (adev->dev,"Failed setting up TTM BO move entity (%d)\n" , r); +drm_sched_entity_destroy (&adev->mman.clear_entity.base); goto error_free_entity; } }else { -drm_sched_entity_destroy (&adev->mman.high_pr); -drm_sched_entity_destroy (&adev->mman.low_pr); +drm_sched_entity_destroy (&adev->mman.default_entity.base); +drm_sched_entity_destroy (&adev->mman.clear_entity.base); +drm_sched_entity_destroy (&adev->mman.move_entity.base);/* Drop all the old fences since re-creating the scheduler entities * will allocate new contexts. */
@@ -2201,7 +2213,7 @@ void amdgpu_ttm_set_buffer_funcs_status(struct amdgpu_device *adev, bool enable)return ; error_free_entity: -drm_sched_entity_destroy (&adev->mman.high_pr); +drm_sched_entity_destroy (&adev->mman.default_entity.base); } static int amdgpu_ttm_prepare_job(struct amdgpu_device *adev,
@@ -2213,8 +2225,8 @@ static int amdgpu_ttm_prepare_job(struct amdgpu_device *adev, {enum amdgpu_ib_pool_type pool =AMDGPU_IB_POOL_DELAYED ;int r; -struct drm_sched_entity *entity = delayed ? &adev->mman.low_pr : - &adev->mman.high_pr; +struct drm_sched_entity *entity = delayed ? &adev->mman.clear_entity.base : + &adev->mman.default_entity.base; r =amdgpu_job_alloc_with_ib (adev, entity,AMDGPU_FENCE_OWNER_UNDEFINED , num_dw *4 , pool, job, k_job_id);
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h +8 -4
@@ -52,6 +52,10 @@ struct amdgpu_gtt_mgr {spinlock_t lock; }; +struct amdgpu_ttm_buffer_entity { +struct drm_sched_entity base; +}; +struct amdgpu_mman {struct ttm_device bdev;struct ttm_pool *ttm_pools;
@@ -64,10 +68,10 @@ struct amdgpu_mman {bool buffer_funcs_enabled;struct mutex gtt_window_lock; -/* High priority scheduler entity for buffer moves */ -struct drm_sched_entity high_pr; -/* Low priority scheduler entity for VRAM clearing */ -struct drm_sched_entity low_pr; + +struct amdgpu_ttm_buffer_entity default_entity; +struct amdgpu_ttm_buffer_entity clear_entity; +struct amdgpu_ttm_buffer_entity move_entity;struct amdgpu_vram_mgr vram_mgr;struct amdgpu_gtt_mgr gtt_mgr;
drivers/gpu/drm/amd/amdkfd/kfd_migrate.c +9 -4
@@ -45,7 +45,9 @@ svm_migrate_direct_mapping_addr(struct amdgpu_device *adev, u64 addr) }static int -svm_migrate_gart_map (struct amdgpu_ring *ring,u64 npages, +svm_migrate_gart_map (struct amdgpu_ring *ring, +struct amdgpu_ttm_buffer_entity *entity, +u64 npages,dma_addr_t *addr,u64 *gart_addr,u64 flags) {struct amdgpu_device *adev = ring->adev;
@@ -63,7 +65,7 @@ svm_migrate_gart_map(struct amdgpu_ring *ring, u64 npages, num_dw =ALIGN (adev->mman.buffer_funcs->copy_num_dw,8 ); num_bytes = npages *8 ; - r = amdgpu_job_alloc_with_ib(adev, &adev->mman.high_pr, + r = amdgpu_job_alloc_with_ib(adev, &entity->base, AMDGPU_FENCE_OWNER_UNDEFINED, num_dw * 4 + num_bytes, AMDGPU_IB_POOL_DELAYED,
@@ -128,11 +130,14 @@ svm_migrate_copy_memory_gart(struct amdgpu_device *adev, dma_addr_t *sys, {const u64 GTT_MAX_PAGES =AMDGPU_GTT_MAX_TRANSFER_SIZE ;struct amdgpu_ring *ring = adev->mman.buffer_funcs_ring; +struct amdgpu_ttm_buffer_entity *entity;u64 gart_s, gart_d;struct dma_fence *next;u64 size;int r; + entity = &adev->mman.move_entity; +mutex_lock (&adev->mman.gtt_window_lock);while (npages) {
@@ -140,10 +145,10 @@ svm_migrate_copy_memory_gart(struct amdgpu_device *adev, dma_addr_t *sys,if (direction ==FROM_VRAM_TO_RAM ) { gart_s =svm_migrate_direct_mapping_addr (adev, *vram); - r =svm_migrate_gart_map (ring, size, sys, &gart_d,0 ); + r =svm_migrate_gart_map (ring, entity, size, sys, &gart_d,0 ); }else if (direction ==FROM_RAM_TO_VRAM ) { - r =svm_migrate_gart_map (ring, size, sys, &gart_s, + r =svm_migrate_gart_map (ring, entity, size, sys, &gart_s,KFD_IOCTL_SVM_FLAG_GPU_RO ); gart_d =svm_migrate_direct_mapping_addr (adev, *vram); }
Signature · 1 line
2.43.0
PATCH v4 2/13 drm/amdgpu: add amdgpu_ttm_job_submit helper
In reply to Pierre-Eric Pelloux-PrayerDeduplicate the IB padding code and will also be used later to check locking.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 34 ++++++++++++------------- 1 file changed, 16 insertions(+), 18 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +16 -18
@@ -162,6 +162,18 @@ static void amdgpu_evict_flags(struct ttm_buffer_object *bo, *placement = abo->placement; } +static struct dma_fence * +amdgpu_ttm_job_submit (struct amdgpu_device *adev,struct amdgpu_job *job,u32 num_dw) +{ +struct amdgpu_ring *ring; + + ring = adev->mman.buffer_funcs_ring; +amdgpu_ring_pad_ib (ring, &job->ibs[0 ]); +WARN_ON (job->ibs[0 ].length_dw > num_dw); + +return amdgpu_job_submit (job); +} +/** * amdgpu_ttm_map_buffer - Map memory into the GART windows * @bo: buffer object to map
@@ -184,7 +196,6 @@ static int amdgpu_ttm_map_buffer(struct ttm_buffer_object *bo,struct amdgpu_device *adev =amdgpu_ttm_adev (bo->bdev);unsigned int offset, num_pages, num_dw, num_bytes;uint64_t src_addr, dst_addr; -struct amdgpu_ring *ring;struct amdgpu_job *job;void *cpu_addr;uint64_t flags;
@@ -239,10 +250,6 @@ static int amdgpu_ttm_map_buffer(struct ttm_buffer_object *bo,amdgpu_emit_copy_buffer (adev, &job->ibs[0 ], src_addr, dst_addr, num_bytes,0 ); - ring = adev->mman.buffer_funcs_ring; -amdgpu_ring_pad_ib (ring, &job->ibs[0 ]); -WARN_ON (job->ibs[0 ].length_dw > num_dw); - flags =amdgpu_ttm_tt_pte_flags (adev, bo->ttm, mem);if (tmz) flags |=AMDGPU_PTE_TMZ ;
@@ -260,7 +267,7 @@ static int amdgpu_ttm_map_buffer(struct ttm_buffer_object *bo,amdgpu_gart_map_vram_range (adev, pa,0 , num_pages, flags, cpu_addr); } -dma_fence_put (amdgpu_job_submit (job)); +dma_fence_put (amdgpu_ttm_job_submit (adev, job, num_dw));return 0 ; }
@@ -1497,10 +1504,7 @@ static int amdgpu_ttm_access_memory_sdma(struct ttm_buffer_object *bo,amdgpu_emit_copy_buffer (adev, &job->ibs[0 ], src_addr, dst_addr,PAGE_SIZE ,0 ); -amdgpu_ring_pad_ib (adev->mman.buffer_funcs_ring, &job->ibs[0 ]); -WARN_ON (job->ibs[0 ].length_dw > num_dw); - - fence =amdgpu_job_submit (job); + fence =amdgpu_ttm_job_submit (adev, job, num_dw);mutex_unlock (&adev->mman.gtt_window_lock);if (!dma_fence_wait_timeout (fence, false, adev->sdma_timeout))
@@ -2286,11 +2290,9 @@ int amdgpu_copy_buffer(struct amdgpu_device *adev, uint64_t src_offset, byte_count -= cur_size_in_bytes; } -amdgpu_ring_pad_ib (ring, &job->ibs[0 ]); -WARN_ON (job->ibs[0 ].length_dw > num_dw); - *fence =amdgpu_job_submit (job);if (r) goto error_free; + *fence =amdgpu_ttm_job_submit (adev, job, num_dw);return r;
@@ -2308,7 +2310,6 @@ static int amdgpu_ttm_fill_mem(struct amdgpu_device *adev, uint32_t src_data, u64 k_job_id) {unsigned int num_loops, num_dw; -struct amdgpu_ring *ring;struct amdgpu_job *job;uint32_t max_bytes;unsigned int i;
@@ -2332,10 +2333,7 @@ static int amdgpu_ttm_fill_mem(struct amdgpu_device *adev, uint32_t src_data, byte_count -= cur_size; } - ring = adev->mman.buffer_funcs_ring; -amdgpu_ring_pad_ib (ring, &job->ibs[0 ]); -WARN_ON (job->ibs[0 ].length_dw > num_dw); - *fence =amdgpu_job_submit (job); + *fence =amdgpu_ttm_job_submit (adev, job, num_dw);return 0 ; }
Signature · 1 line
2.43.0
PATCH v4 3/13 drm/amdgpu: fix error handling in amdgpu_copy_buffer
In reply to Pierre-Eric Pelloux-Prayerdrm_sched_job_add_resv_dependencies can fail in amdgpu_ttm_prepare_job. In this case we need to use amdgpu_job_free to release memory.
---
v4: moved job pointer clearing to a different patchset
---
--- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +2 -4
@@ -2278,7 +2278,7 @@ int amdgpu_copy_buffer(struct amdgpu_device *adev, uint64_t src_offset, resv, vm_needs_flush, &job, false, AMDGPU_KERNEL_JOB_ID_TTM_COPY_BUFFER);if (r) -return r; + goto error_free;for (i =0 ; i < num_loops; i++) {uint32_t cur_size_in_bytes =min (byte_count, max_bytes);
@@ -2290,11 +2290,9 @@ int amdgpu_copy_buffer(struct amdgpu_device *adev, uint64_t src_offset, byte_count -= cur_size_in_bytes; } -if (r) - goto error_free; *fence =amdgpu_ttm_job_submit (adev, job, num_dw); -return r; +return 0 ; error_free:amdgpu_job_free (job);
Signature · 1 line
2.43.0
Re: [PATCH v4 03/13] drm/amdgpu: fix error handling in amdgpu_copy_buffer
Quoted 8 lines · Pierre-Eric Pelloux-Prayer
drm_sched_job_add_resv_dependenciescan fail inamdgpu_ttm_prepare_job. In this case we need to useamdgpu_job_freeto release memory.---
v4: moved job pointer clearing to a different patchset
---Signed-off-by Pierre-Eric Pelloux-Prayer <[email protected]>
Quoted 30 lines
--- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +2
-4@@ -2278,7 +2278,7 @@ int amdgpu_copy_buffer(struct amdgpu_device *adev, uint64_t src_offset, resv, vm_needs_flush, &job, false, AMDGPU_KERNEL_JOB_ID_TTM_COPY_BUFFER);if (r) -return r; + goto error_free;for (i =0 ; i < num_loops; i++) {uint32_t cur_size_in_bytes =min (byte_count, max_bytes);@@ -2290,11 +2290,9 @@ int amdgpu_copy_buffer(struct amdgpu_device *adev, uint64_t src_offset, byte_count -= cur_size_in_bytes; } -if (r) - goto error_free; *fence =amdgpu_ttm_job_submit (adev, job, num_dw); -return r; +return 0 ; error_free:amdgpu_job_free (job);
PATCH v4 4/13 drm/amdgpu: pass the entity to use to amdgpu_ttm_map_buffer
In reply to Pierre-Eric Pelloux-PrayerThis way the caller can select the one it wants to use.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 55 +++++++++++++++---------- 1 file changed, 34 insertions(+), 21 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +34 -21
@@ -176,6 +176,7 @@ amdgpu_ttm_job_submit(struct amdgpu_device *adev, struct amdgpu_job *job, u32 nu/** * amdgpu_ttm_map_buffer - Map memory into the GART windows +* @entity: entity to run the window setup job * @bo: buffer object to map * @mem: memory object to map * @mm_cur: range to map
@@ -187,7 +188,8 @@ amdgpu_ttm_job_submit(struct amdgpu_device *adev, struct amdgpu_job *job, u32 nu* Setup one of the GART windows to access a specific piece of memory or return * the physical address for local memory. */ -static int amdgpu_ttm_map_buffer(struct ttm_buffer_object *bo, +static int amdgpu_ttm_map_buffer(struct amdgpu_ttm_buffer_entity *entity, + struct ttm_buffer_object *bo, struct ttm_resource *mem, struct amdgpu_res_cursor *mm_cur, unsigned int window,
@@ -234,7 +236,7 @@ static int amdgpu_ttm_map_buffer(struct ttm_buffer_object *bo, num_dw =ALIGN (adev->mman.buffer_funcs->copy_num_dw,8 ); num_bytes = num_pages *8 *AMDGPU_GPU_PAGES_IN_CPU_PAGE ; - r = amdgpu_job_alloc_with_ib(adev, &adev->mman.default_entity.base, + r = amdgpu_job_alloc_with_ib(adev, &entity->base, AMDGPU_FENCE_OWNER_UNDEFINED, num_dw * 4 + num_bytes, AMDGPU_IB_POOL_DELAYED, &job,
@@ -274,6 +276,7 @@ static int amdgpu_ttm_map_buffer(struct ttm_buffer_object *bo,/** * amdgpu_ttm_copy_mem_to_mem - Helper function for copy * @adev: amdgpu device +* @entity: entity to run the jobs * @src: buffer/address where to read from * @dst: buffer/address where to write to * @size: number of bytes to copy
@@ -288,6 +291,7 @@ static int amdgpu_ttm_map_buffer(struct ttm_buffer_object *bo,*/ __attribute__((nonnull)) static int amdgpu_ttm_copy_mem_to_mem(struct amdgpu_device *adev, + struct amdgpu_ttm_buffer_entity *entity, const struct amdgpu_copy_mem *src, const struct amdgpu_copy_mem *dst, uint64_t size, bool tmz,
@@ -319,12 +323,12 @@ static int amdgpu_ttm_copy_mem_to_mem(struct amdgpu_device *adev, cur_size =min3 (src_mm.size, dst_mm.size,256ULL <<20 );/* Map src to window 0 and dst to window 1. */ - r =amdgpu_ttm_map_buffer (src->bo, src->mem, &src_mm, + r =amdgpu_ttm_map_buffer (entity, src->bo, src->mem, &src_mm,0 , tmz, &cur_size, &from);if (r) goto error; - r =amdgpu_ttm_map_buffer (dst->bo, dst->mem, &dst_mm, + r =amdgpu_ttm_map_buffer (entity, dst->bo, dst->mem, &dst_mm,1 , tmz, &cur_size, &to);if (r) goto error;
@@ -393,7 +397,9 @@ static int amdgpu_move_blit(struct ttm_buffer_object *bo, src.offset =0 ; dst.offset =0 ; - r =amdgpu_ttm_copy_mem_to_mem (adev, &src, &dst, + r =amdgpu_ttm_copy_mem_to_mem (adev, + &adev->mman.move_entity, + &src, &dst, new_mem->size,amdgpu_bo_encrypted (abo), bo->base.resv, &fence);
@@ -2221,17 +2227,16 @@ void amdgpu_ttm_set_buffer_funcs_status(struct amdgpu_device *adev, bool enable) }static int amdgpu_ttm_prepare_job (struct amdgpu_device *adev, +struct amdgpu_ttm_buffer_entity *entity,unsigned int num_dw,struct dma_resv *resv,bool vm_needs_flush,struct amdgpu_job **job, -bool delayed,u64 k_job_id) +u64 k_job_id) {enum amdgpu_ib_pool_type pool =AMDGPU_IB_POOL_DELAYED ;int r; -struct drm_sched_entity *entity = delayed ? &adev->mman.clear_entity.base : - &adev->mman.default_entity.base; - r =amdgpu_job_alloc_with_ib (adev, entity, + r =amdgpu_job_alloc_with_ib (adev, &entity->base,AMDGPU_FENCE_OWNER_UNDEFINED , num_dw *4 , pool, job, k_job_id);if (r)
@@ -2274,8 +2279,8 @@ int amdgpu_copy_buffer(struct amdgpu_device *adev, uint64_t src_offset, max_bytes = adev->mman.buffer_funcs->copy_max_bytes; num_loops =DIV_ROUND_UP (byte_count, max_bytes); num_dw =ALIGN (num_loops * adev->mman.buffer_funcs->copy_num_dw,8 ); - r =amdgpu_ttm_prepare_job (adev, num_dw, - resv, vm_needs_flush, &job, false, + r =amdgpu_ttm_prepare_job (adev, &adev->mman.move_entity, num_dw, + resv, vm_needs_flush, &job,AMDGPU_KERNEL_JOB_ID_TTM_COPY_BUFFER );if (r) goto error_free;
@@ -2300,11 +2305,13 @@ int amdgpu_copy_buffer(struct amdgpu_device *adev, uint64_t src_offset,return r; } -static int amdgpu_ttm_fill_mem (struct amdgpu_device *adev,uint32_t src_data, +static int amdgpu_ttm_fill_mem (struct amdgpu_device *adev, +struct amdgpu_ttm_buffer_entity *entity, +uint32_t src_data,uint64_t dst_addr,uint32_t byte_count,struct dma_resv *resv,struct dma_fence **fence, -bool vm_needs_flush,bool delayed, +bool vm_needs_flush,u64 k_job_id) {unsigned int num_loops, num_dw;
@@ -2316,8 +2323,8 @@ static int amdgpu_ttm_fill_mem(struct amdgpu_device *adev, uint32_t src_data, max_bytes = adev->mman.buffer_funcs->fill_max_bytes; num_loops =DIV_ROUND_UP_ULL (byte_count, max_bytes); num_dw =ALIGN (num_loops * adev->mman.buffer_funcs->fill_num_dw,8 ); - r =amdgpu_ttm_prepare_job (adev, num_dw, resv, vm_needs_flush, - &job, delayed, k_job_id); + r =amdgpu_ttm_prepare_job (adev, entity, num_dw, resv, + vm_needs_flush, &job, k_job_id);if (r)return r;
@@ -2378,13 +2385,14 @@ int amdgpu_ttm_clear_buffer(struct amdgpu_bo *bo,/* Never clear more than 256MiB at once to avoid timeouts */ size =min (cursor.size,256ULL <<20 ); - r =amdgpu_ttm_map_buffer (&bo->tbo, bo->tbo.resource, &cursor, + r =amdgpu_ttm_map_buffer (&adev->mman.clear_entity, + &bo->tbo, bo->tbo.resource, &cursor,1 , false, &size, &addr);if (r) goto err; - r =amdgpu_ttm_fill_mem (adev,0 , addr, size, resv, - &next, true, true, + r =amdgpu_ttm_fill_mem (adev, &adev->mman.clear_entity,0 , addr, size, resv, + &next, true,AMDGPU_KERNEL_JOB_ID_TTM_CLEAR_BUFFER );if (r) goto err;
@@ -2408,10 +2416,14 @@ int amdgpu_fill_buffer(struct amdgpu_bo *bo, u64 k_job_id) {struct amdgpu_device *adev =amdgpu_ttm_adev (bo->tbo.bdev); +struct amdgpu_ttm_buffer_entity *entity;struct dma_fence *fence =NULL ;struct amdgpu_res_cursor dst;int r; + entity = delayed ? &adev->mman.clear_entity : + &adev->mman.move_entity; +if (!adev->mman.buffer_funcs_enabled) {dev_err (adev->dev,"Trying to clear memory with ring turned off.\n" );
@@ -2428,13 +2440,14 @@ int amdgpu_fill_buffer(struct amdgpu_bo *bo,/* Never fill more than 256MiB at once to avoid timeouts */ cur_size =min (dst.size,256ULL <<20 ); - r =amdgpu_ttm_map_buffer (&bo->tbo, bo->tbo.resource, &dst, + r =amdgpu_ttm_map_buffer (&adev->mman.default_entity, + &bo->tbo, bo->tbo.resource, &dst,1 , false, &cur_size, &to);if (r) goto error; - r =amdgpu_ttm_fill_mem (adev, src_data, to, cur_size, resv, - &next, true, delayed, k_job_id); + r =amdgpu_ttm_fill_mem (adev, entity, src_data, to, cur_size, resv, + &next, true, k_job_id);if (r) goto error;
Signature · 1 line
2.43.0
PATCH v4 5/13 drm/amdgpu: pass the entity to use to ttm public functions
In reply to Pierre-Eric Pelloux-PrayerThis way the caller can select the one it wants to use.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_benchmark.c | 3 +- drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 4 +-- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 35 +++++++++---------- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h | 16 +++++---- drivers/gpu/drm/amd/amdkfd/kfd_migrate.c | 3 +- 5 files changed, 32 insertions(+), 29 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_benchmark.c +2 -1
@@ -37,7 +37,8 @@ static int amdgpu_benchmark_do_move(struct amdgpu_device *adev, unsigned size, stime =ktime_get ();for (i =0 ; i < n; i++) { - r =amdgpu_copy_buffer (adev, saddr, daddr, size,NULL , &fence, + r =amdgpu_copy_buffer (adev, &adev->mman.default_entity, + saddr, daddr, size,NULL , &fence, false,0 );if (r) goto exit_do_move;
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +2 -2
@@ -1322,8 +1322,8 @@ void amdgpu_bo_release_notify(struct ttm_buffer_object *bo)if (r) goto out; - r =amdgpu_fill_buffer (abo,0 , &bo->base._resv, &fence, true, -AMDGPU_KERNEL_JOB_ID_CLEAR_ON_RELEASE ); + r =amdgpu_fill_buffer (&adev->mman.clear_entity, abo,0 , &bo->base._resv, + &fence,AMDGPU_KERNEL_JOB_ID_CLEAR_ON_RELEASE );if (WARN_ON (r)) goto out;
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +17 -18
@@ -356,7 +356,7 @@ static int amdgpu_ttm_copy_mem_to_mem(struct amdgpu_device *adev, write_compress_disable)); } - r =amdgpu_copy_buffer (adev, from, to, cur_size, resv, + r =amdgpu_copy_buffer (adev, entity, from, to, cur_size, resv, &next, true, copy_flags);if (r) goto error;
@@ -411,8 +411,9 @@ static int amdgpu_move_blit(struct ttm_buffer_object *bo, (abo->flags & AMDGPU_GEM_CREATE_VRAM_WIPE_ON_RELEASE)) {struct dma_fence *wipe_fence =NULL ; - r =amdgpu_fill_buffer (abo,0 ,NULL , &wipe_fence, - false,AMDGPU_KERNEL_JOB_ID_MOVE_BLIT ); + r =amdgpu_fill_buffer (&adev->mman.move_entity, + abo,0 ,NULL , &wipe_fence, +AMDGPU_KERNEL_JOB_ID_MOVE_BLIT );if (r) { goto error; }else if (wipe_fence) {
@@ -2255,7 +2256,9 @@ static int amdgpu_ttm_prepare_job(struct amdgpu_device *adev, DMA_RESV_USAGE_BOOKKEEP); } -int amdgpu_copy_buffer(struct amdgpu_device *adev, uint64_t src_offset, +int amdgpu_copy_buffer(struct amdgpu_device *adev, + struct amdgpu_ttm_buffer_entity *entity, + uint64_t src_offset, uint64_t dst_offset, uint32_t byte_count, struct dma_resv *resv, struct dma_fence **fence,
@@ -2279,7 +2282,7 @@ int amdgpu_copy_buffer(struct amdgpu_device *adev, uint64_t src_offset, max_bytes = adev->mman.buffer_funcs->copy_max_bytes; num_loops =DIV_ROUND_UP (byte_count, max_bytes); num_dw =ALIGN (num_loops * adev->mman.buffer_funcs->copy_num_dw,8 ); - r =amdgpu_ttm_prepare_job (adev, &adev->mman.move_entity, num_dw, + r =amdgpu_ttm_prepare_job (adev, entity, num_dw, resv, vm_needs_flush, &job,AMDGPU_KERNEL_JOB_ID_TTM_COPY_BUFFER );if (r)
@@ -2408,22 +2411,18 @@ int amdgpu_ttm_clear_buffer(struct amdgpu_bo *bo,return r; } -int amdgpu_fill_buffer (struct amdgpu_bo *bo, -uint32_t src_data, -struct dma_resv *resv, -struct dma_fence **f, -bool delayed, -u64 k_job_id) +int amdgpu_fill_buffer (struct amdgpu_ttm_buffer_entity *entity, +struct amdgpu_bo *bo, +uint32_t src_data, +struct dma_resv *resv, +struct dma_fence **f, +u64 k_job_id) {struct amdgpu_device *adev =amdgpu_ttm_adev (bo->tbo.bdev); -struct amdgpu_ttm_buffer_entity *entity;struct dma_fence *fence =NULL ;struct amdgpu_res_cursor dst;int r; - entity = delayed ? &adev->mman.clear_entity : - &adev->mman.move_entity; -if (!adev->mman.buffer_funcs_enabled) {dev_err (adev->dev,"Trying to clear memory with ring turned off.\n" );
@@ -2440,13 +2439,13 @@ int amdgpu_fill_buffer(struct amdgpu_bo *bo,/* Never fill more than 256MiB at once to avoid timeouts */ cur_size =min (dst.size,256ULL <<20 ); - r =amdgpu_ttm_map_buffer (&adev->mman.default_entity, - &bo->tbo, bo->tbo.resource, &dst, + r =amdgpu_ttm_map_buffer (entity, &bo->tbo, bo->tbo.resource, &dst,1 , false, &cur_size, &to);if (r) goto error; - r =amdgpu_ttm_fill_mem (adev, entity, src_data, to, cur_size, resv, + r =amdgpu_ttm_fill_mem (adev, entity, + src_data, to, cur_size, resv, &next, true, k_job_id);if (r) goto error;
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h +9 -7
@@ -167,7 +167,9 @@ int amdgpu_ttm_init(struct amdgpu_device *adev);void amdgpu_ttm_fini (struct amdgpu_device *adev);void amdgpu_ttm_set_buffer_funcs_status (struct amdgpu_device *adev,bool enable); -int amdgpu_copy_buffer(struct amdgpu_device *adev, uint64_t src_offset, +int amdgpu_copy_buffer(struct amdgpu_device *adev, + struct amdgpu_ttm_buffer_entity *entity, + uint64_t src_offset, uint64_t dst_offset, uint32_t byte_count, struct dma_resv *resv, struct dma_fence **fence,
@@ -175,12 +177,12 @@ int amdgpu_copy_buffer(struct amdgpu_device *adev, uint64_t src_offset,int amdgpu_ttm_clear_buffer (struct amdgpu_bo *bo,struct dma_resv *resv,struct dma_fence **fence); -int amdgpu_fill_buffer (struct amdgpu_bo *bo, -uint32_t src_data, -struct dma_resv *resv, -struct dma_fence **fence, -bool delayed, -u64 k_job_id); +int amdgpu_fill_buffer (struct amdgpu_ttm_buffer_entity *entity, +struct amdgpu_bo *bo, +uint32_t src_data, +struct dma_resv *resv, +struct dma_fence **f, +u64 k_job_id);int amdgpu_ttm_alloc_gart (struct ttm_buffer_object *bo);void amdgpu_ttm_recover_gart (struct ttm_buffer_object *tbo);
drivers/gpu/drm/amd/amdkfd/kfd_migrate.c +2 -1
@@ -157,7 +157,8 @@ svm_migrate_copy_memory_gart(struct amdgpu_device *adev, dma_addr_t *sys, goto out_unlock; } - r =amdgpu_copy_buffer (adev, gart_s, gart_d, size *PAGE_SIZE , + r =amdgpu_copy_buffer (adev, entity, + gart_s, gart_d, size *PAGE_SIZE ,NULL , &next, true,0 );if (r) {dev_err (adev->dev,"fail %d to copy memory\n" , r);
Signature · 1 line
2.43.0
PATCH v4 6/13 drm/amdgpu: statically assign gart windows to ttm entities
In reply to Pierre-Eric Pelloux-PrayerIf multiple entities share the same window we must make sure that jobs using them are executed sequentially.
This commit gives separate windows to each entity, so jobs from multiple entities could execute in parallel if needed. (for now they all use the first sdma engine, so it makes no difference yet).
The entity stores the gart window offsets to centralize the "window id" to "window offset" in a single place.
default_entity doesn't get any windows reserved since there is no use for them.
---
v3:
- renamed gart_window_lock -> lock (Christian)
- added amdgpu_ttm_buffer_entity_init (Christian)
- fixed gart_addr in svm_migrate_gart_map (Felix)
- renamed gart_window_idX -> gart_window_offs[]
- added amdgpu_compute_gart_address
v4:
- u32 -> u64
- added kerneldoc
---
--- drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c | 6 +-- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 61 +++++++++++++++++------- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h | 19 +++++++- drivers/gpu/drm/amd/amdkfd/kfd_migrate.c | 9 ++-- 4 files changed, 69 insertions(+), 26 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +3 -3
@@ -686,7 +686,7 @@ void amdgpu_gmc_flush_gpu_tlb(struct amdgpu_device *adev, uint32_t vmid,* translation. Avoid this by doing the invalidation from the SDMA * itself at least for GART. */ -mutex_lock (&adev->mman.gtt_window_lock); +mutex_lock (&adev->mman.default_entity.lock); r = amdgpu_job_alloc_with_ib(ring->adev, &adev->mman.default_entity.base, AMDGPU_FENCE_OWNER_UNDEFINED, 16 * 4, AMDGPU_IB_POOL_IMMEDIATE,
@@ -699,7 +699,7 @@ void amdgpu_gmc_flush_gpu_tlb(struct amdgpu_device *adev, uint32_t vmid, job->ibs->ptr[job->ibs->length_dw++] = ring->funcs->nop;amdgpu_ring_pad_ib (ring, &job->ibs[0 ]); fence =amdgpu_job_submit (job); -mutex_unlock (&adev->mman.gtt_window_lock); +mutex_unlock (&adev->mman.default_entity.lock);dma_fence_wait (fence, false);dma_fence_put (fence);
@@ -707,7 +707,7 @@ void amdgpu_gmc_flush_gpu_tlb(struct amdgpu_device *adev, uint32_t vmid,return ; error_alloc: -mutex_unlock (&adev->mman.gtt_window_lock); +mutex_unlock (&adev->mman.default_entity.lock);dev_err (adev->dev,"Error flushing GPU TLB using the SDMA (%d)!\n" , r); }
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +44 -17
165 lines not on this page · raw message
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h +18 -1
@@ -29,6 +29,7 @@#include <drm/ttm/ttm_placement.h> #include "amdgpu_vram_mgr.h" #include "amdgpu_hmm.h" +#include "amdgpu_gmc.h" #define AMDGPU_PL_GDS (TTM_PL_PRIV + 0)#define AMDGPU_PL_GWS (TTM_PL_PRIV + 1)
@@ -39,7 +40,7 @@#define __AMDGPU_PL_NUM (TTM_PL_PRIV + 6)#define AMDGPU_GTT_MAX_TRANSFER_SIZE 512 -#define AMDGPU_GTT_NUM_TRANSFER_WINDOWS 2 +#define AMDGPU_GTT_NUM_TRANSFER_WINDOWS 3extern const struct attribute_group amdgpu_vram_mgr_attr_group;extern const struct attribute_group amdgpu_gtt_mgr_attr_group;
@@ -54,6 +55,8 @@ struct amdgpu_gtt_mgr {struct amdgpu_ttm_buffer_entity {struct drm_sched_entity base; +struct mutex lock; +u64 gart_window_offs[2 ]; };struct amdgpu_mman {
@@ -69,6 +72,7 @@ struct amdgpu_mman {struct mutex gtt_window_lock; +/* @default_entity: for workarounds, has no gart windows */ struct amdgpu_ttm_buffer_entity default_entity;struct amdgpu_ttm_buffer_entity clear_entity;struct amdgpu_ttm_buffer_entity move_entity;
@@ -199,6 +203,19 @@ static inline int amdgpu_ttm_tt_get_user_pages(struct amdgpu_bo *bo, }#endif +/** +* amdgpu_compute_gart_address() - Returns GART address of an entity's window +* @gmc: The &struct amdgpu_gmc instance to use +* @entity: The &struct amdgpu_ttm_buffer_entity owning the GART window +* @index: The window to use (must be 0 or 1) +*/ +static inline u64 amdgpu_compute_gart_address (struct amdgpu_gmc *gmc, +struct amdgpu_ttm_buffer_entity *entity, +int index) +{ +return gmc->gart_start + entity->gart_window_offs[index]; +} +void amdgpu_ttm_tt_set_user_pages (struct ttm_tt *ttm,struct amdgpu_hmm_range *range);int amdgpu_ttm_tt_get_userptr (const struct ttm_buffer_object *tbo,uint64_t *user_addr);
drivers/gpu/drm/amd/amdkfd/kfd_migrate.c +4 -5
@@ -59,8 +59,7 @@ svm_migrate_gart_map(struct amdgpu_ring *ring,void *cpu_addr;int r; -/* use gart window 0 */ - *gart_addr = adev->gmc.gart_start; + *gart_addr =amdgpu_compute_gart_address (&adev->gmc, entity,0 ); num_dw =ALIGN (adev->mman.buffer_funcs->copy_num_dw,8 ); num_bytes = npages *8 ;
@@ -116,7 +115,7 @@ svm_migrate_gart_map(struct amdgpu_ring *ring,* multiple GTT_MAX_PAGES transfer, all sdma operations are serialized, wait for * the last sdma finish fence which is returned to check copy memory is done. * -* Context: Process context, takes and releases gtt_window_lock +* Context: Process context * * Return: * 0 - OK, otherwise error code
@@ -138,7 +137,7 @@ svm_migrate_copy_memory_gart(struct amdgpu_device *adev, dma_addr_t *sys, entity = &adev->mman.move_entity; -mutex_lock (&adev->mman.gtt_window_lock); +mutex_lock (&entity->lock);while (npages) { size =min (GTT_MAX_PAGES , npages);
@@ -175,7 +174,7 @@ svm_migrate_copy_memory_gart(struct amdgpu_device *adev, dma_addr_t *sys, } out_unlock: -mutex_unlock (&adev->mman.gtt_window_lock); +mutex_unlock (&entity->lock);return r; }
Signature · 1 line
2.43.0
Re: [PATCH v4 06/13] drm/amdgpu: statically assign gart windows to ttm entities
Quoted 25 lines · Pierre-Eric Pelloux-Prayer
If multiple entities share the same window we must make sure that jobs using them are executed sequentially.
This commit gives separate windows to each entity, so jobs from multiple entities could execute in parallel if needed. (for now they all use the first sdma engine, so it makes no difference yet).
The entity stores the gart window offsets to centralize the "window id" to "window offset" in a single place.
default_entitydoesn't get any windows reserved since there is no use for them.---
v3:
- renamedgart_window_lock-> lock (Christian)
- addedamdgpu_ttm_buffer_entity_init(Christian)
- fixedgart_addrinsvm_migrate_gart_map(Felix)
- renamedgart_window_idX-> gart_window_offs[]
- addedamdgpu_compute_gart_address
v4:
- u32 -> u64
- added kerneldoc
---
Quoted 2 lines
Signed-off-by Pierre-Eric Pelloux-Prayer <[email protected]>Acked-by Felix Kuehling <[email protected]>
Quoted 322 lines
--- drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c | 6 +-- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 61 +++++++++++++++++------- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h | 19 +++++++- drivers/gpu/drm/amd/amdkfd/kfd_migrate.c | 9 ++-- 4 files changed, 69 insertions(+), 26 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +3
-3@@ -686,7 +686,7 @@ void amdgpu_gmc_flush_gpu_tlb(struct amdgpu_device *adev, uint32_t vmid,* translation. Avoid this by doing the invalidation from the SDMA * itself at least for GART. */ -mutex_lock (&adev->mman.gtt_window_lock); +mutex_lock (&adev->mman.default_entity.lock); r = amdgpu_job_alloc_with_ib(ring->adev, &adev->mman.default_entity.base, AMDGPU_FENCE_OWNER_UNDEFINED, 16 * 4, AMDGPU_IB_POOL_IMMEDIATE,@@ -699,7 +699,7 @@ void amdgpu_gmc_flush_gpu_tlb(struct amdgpu_device *adev, uint32_t vmid, job->ibs->ptr[job->ibs->length_dw++] = ring->funcs->nop;amdgpu_ring_pad_ib (ring, &job->ibs[0 ]); fence =amdgpu_job_submit (job); -mutex_unlock (&adev->mman.gtt_window_lock); +mutex_unlock (&adev->mman.default_entity.lock);dma_fence_wait (fence, false);dma_fence_put (fence);@@ -707,7 +707,7 @@ void amdgpu_gmc_flush_gpu_tlb(struct amdgpu_device *adev, uint32_t vmid,return ; error_alloc: -mutex_unlock (&adev->mman.gtt_window_lock); +mutex_unlock (&adev->mman.default_entity.lock);dev_err (adev->dev,"Error flushing GPU TLB using the SDMA (%d)!\n" , r); }drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +44
-17@@ -228,9 +228,7 @@ static int amdgpu_ttm_map_buffer(struct amdgpu_ttm_buffer_entity *entity, *size =min (*size, (uint64_t )num_pages *PAGE_SIZE - offset); - *addr = adev->gmc.gart_start; - *addr += (u64 )window *AMDGPU_GTT_MAX_TRANSFER_SIZE * -AMDGPU_GPU_PAGE_SIZE ; + *addr =amdgpu_compute_gart_address (&adev->gmc, entity, window); *addr += offset; num_dw =ALIGN (adev->mman.buffer_funcs->copy_num_dw,8 );@@ -248,7 +246,7 @@ static int amdgpu_ttm_map_buffer(struct amdgpu_ttm_buffer_entity *entity, src_addr += job->ibs[0 ].gpu_addr; dst_addr =amdgpu_bo_gpu_offset (adev->gart.bo); - dst_addr += window *AMDGPU_GTT_MAX_TRANSFER_SIZE *8 ; + dst_addr += (entity->gart_window_offs[window] >>AMDGPU_GPU_PAGE_SHIFT ) *8 ;amdgpu_emit_copy_buffer (adev, &job->ibs[0 ], src_addr, dst_addr, num_bytes,0 );@@ -313,7 +311,7 @@ static int amdgpu_ttm_copy_mem_to_mem(struct amdgpu_device *adev,amdgpu_res_first (src->mem, src->offset, size, &src_mm);amdgpu_res_first (dst->mem, dst->offset, size, &dst_mm); -mutex_lock (&adev->mman.gtt_window_lock); +mutex_lock (&entity->lock);while (src_mm.remaining) {uint64_t from, to, cur_size, tiling_flags;uint32_t num_type, data_format, max_com, write_compress_disable;@@ -368,7 +366,7 @@ static int amdgpu_ttm_copy_mem_to_mem(struct amdgpu_device *adev,amdgpu_res_next (&dst_mm, cur_size); } error: -mutex_unlock (&adev->mman.gtt_window_lock); +mutex_unlock (&entity->lock); *f = fence;return r; }@@ -1500,7 +1498,7 @@ static int amdgpu_ttm_access_memory_sdma(struct ttm_buffer_object *bo,if (r) goto out; -mutex_lock (&adev->mman.gtt_window_lock); +mutex_lock (&adev->mman.default_entity.lock);amdgpu_res_first (abo->tbo.resource, offset, len, &src_mm); src_addr =amdgpu_ttm_domain_start (adev, bo->resource->mem_type) + src_mm.start;@@ -1512,7 +1510,7 @@ static int amdgpu_ttm_access_memory_sdma(struct ttm_buffer_object *bo, PAGE_SIZE, 0); fence =amdgpu_ttm_job_submit (adev, job, num_dw); -mutex_unlock (&adev->mman.gtt_window_lock); +mutex_unlock (&adev->mman.default_entity.lock);if (!dma_fence_wait_timeout (fence, false, adev->sdma_timeout)) r = -ETIMEDOUT ;@@ -1875,6 +1873,27 @@ static void amdgpu_ttm_mmio_remap_bo_fini(struct amdgpu_device *adev) adev->rmmio_remap.bo =NULL ; } +static int amdgpu_ttm_buffer_entity_init (struct amdgpu_ttm_buffer_entity *entity, +int starting_gart_window, +bool needs_src_gart_window, +bool needs_dst_gart_window) +{ +mutex_init (&entity->lock); +if (needs_src_gart_window) { + entity->gart_window_offs[0 ] = + (u64 )starting_gart_window *AMDGPU_GTT_MAX_TRANSFER_SIZE * +AMDGPU_GPU_PAGE_SIZE ; + starting_gart_window++; + } +if (needs_dst_gart_window) { + entity->gart_window_offs[1 ] = + (u64 )starting_gart_window *AMDGPU_GTT_MAX_TRANSFER_SIZE * +AMDGPU_GPU_PAGE_SIZE ; + starting_gart_window++; + } +return starting_gart_window; +} +/* * amdgpu_ttm_init - Init the memory management (ttm) as well as various * gtt/vram related fields. @@ -1889,8 +1908,6 @@ int amdgpu_ttm_init(struct amdgpu_device *adev)uint64_t gtt_size;int r; -mutex_init (&adev->mman.gtt_window_lock); -dma_set_max_seg_size (adev->dev,UINT_MAX );/* No others user of address space so set it to 0 */ r = ttm_device_init(&adev->mman.bdev, &amdgpu_bo_driver, adev->dev,@@ -2160,6 +2177,7 @@ void amdgpu_ttm_fini(struct amdgpu_device *adev)void amdgpu_ttm_set_buffer_funcs_status (struct amdgpu_device *adev,bool enable) {struct ttm_resource_manager *man =ttm_manager_type (&adev->mman.bdev,TTM_PL_VRAM ); +u32 used_windows;uint64_t size;int r;@@ -2203,6 +2221,14 @@ void amdgpu_ttm_set_buffer_funcs_status(struct amdgpu_device *adev, bool enable)drm_sched_entity_destroy (&adev->mman.clear_entity.base); goto error_free_entity; } + +/* Statically assign GART windows to each entity. */ + used_windows =amdgpu_ttm_buffer_entity_init (&adev->mman.default_entity, +0 , false, false); + used_windows =amdgpu_ttm_buffer_entity_init (&adev->mman.move_entity, + used_windows, true, true); + used_windows =amdgpu_ttm_buffer_entity_init (&adev->mman.clear_entity, + used_windows, false, true); }else {drm_sched_entity_destroy (&adev->mman.default_entity.base);drm_sched_entity_destroy (&adev->mman.clear_entity.base);@@ -2361,6 +2387,7 @@ int amdgpu_ttm_clear_buffer(struct amdgpu_bo *bo, struct dma_fence **fence) {struct amdgpu_device *adev =amdgpu_ttm_adev (bo->tbo.bdev); +struct amdgpu_ttm_buffer_entity *entity;struct amdgpu_res_cursor cursor;u64 addr;int r =0 ;@@ -2371,11 +2398,12 @@ int amdgpu_ttm_clear_buffer(struct amdgpu_bo *bo,if (!fence)return -EINVAL ; + entity = &adev->mman.clear_entity; *fence =dma_fence_get_stub ();amdgpu_res_first (bo->tbo.resource,0 ,amdgpu_bo_size (bo), &cursor); -mutex_lock (&adev->mman.gtt_window_lock); +mutex_lock (&entity->lock);while (cursor.remaining) {struct dma_fence *next =NULL ;u64 size;@@ -2388,13 +2416,12 @@ int amdgpu_ttm_clear_buffer(struct amdgpu_bo *bo,/* Never clear more than 256MiB at once to avoid timeouts */ size =min (cursor.size,256ULL <<20 ); - r =amdgpu_ttm_map_buffer (&adev->mman.clear_entity, - &bo->tbo, bo->tbo.resource, &cursor, + r =amdgpu_ttm_map_buffer (entity, &bo->tbo, bo->tbo.resource, &cursor,1 , false, &size, &addr);if (r) goto err; - r =amdgpu_ttm_fill_mem (adev, &adev->mman.clear_entity,0 , addr, size, resv, + r =amdgpu_ttm_fill_mem (adev, entity,0 , addr, size, resv, &next, true,AMDGPU_KERNEL_JOB_ID_TTM_CLEAR_BUFFER );if (r)@@ -2406,7 +2433,7 @@ int amdgpu_ttm_clear_buffer(struct amdgpu_bo *bo,amdgpu_res_next (&cursor, size); } err: -mutex_unlock (&adev->mman.gtt_window_lock); +mutex_unlock (&entity->lock);return r; }@@ -2431,7 +2458,7 @@ int amdgpu_fill_buffer(struct amdgpu_ttm_buffer_entity *entity,amdgpu_res_first (bo->tbo.resource,0 ,amdgpu_bo_size (bo), &dst); -mutex_lock (&adev->mman.gtt_window_lock); +mutex_lock (&entity->lock);while (dst.remaining) {struct dma_fence *next;uint64_t cur_size, to;@@ -2456,7 +2483,7 @@ int amdgpu_fill_buffer(struct amdgpu_ttm_buffer_entity *entity,amdgpu_res_next (&dst, cur_size); } error: -mutex_unlock (&adev->mman.gtt_window_lock); +mutex_unlock (&entity->lock);if (f) *f =dma_fence_get (fence);dma_fence_put (fence);drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h +18
-1@@ -29,6 +29,7 @@#include <drm/ttm/ttm_placement.h> #include "amdgpu_vram_mgr.h" #include "amdgpu_hmm.h" +#include "amdgpu_gmc.h" #define AMDGPU_PL_GDS (TTM_PL_PRIV + 0)#define AMDGPU_PL_GWS (TTM_PL_PRIV + 1)@@ -39,7 +40,7 @@#define __AMDGPU_PL_NUM (TTM_PL_PRIV + 6)#define AMDGPU_GTT_MAX_TRANSFER_SIZE 512 -#define AMDGPU_GTT_NUM_TRANSFER_WINDOWS 2 +#define AMDGPU_GTT_NUM_TRANSFER_WINDOWS 3extern const struct attribute_group amdgpu_vram_mgr_attr_group;extern const struct attribute_group amdgpu_gtt_mgr_attr_group;@@ -54,6 +55,8 @@ struct amdgpu_gtt_mgr {struct amdgpu_ttm_buffer_entity {struct drm_sched_entity base; +struct mutex lock; +u64 gart_window_offs[2 ]; };struct amdgpu_mman {@@ -69,6 +72,7 @@ struct amdgpu_mman {struct mutex gtt_window_lock; +/* @default_entity: for workarounds, has no gart windows */ struct amdgpu_ttm_buffer_entity default_entity;struct amdgpu_ttm_buffer_entity clear_entity;struct amdgpu_ttm_buffer_entity move_entity;@@ -199,6 +203,19 @@ static inline int amdgpu_ttm_tt_get_user_pages(struct amdgpu_bo *bo, }#endif +/** +* amdgpu_compute_gart_address() - Returns GART address of an entity's window +* @gmc: The &struct amdgpu_gmc instance to use +* @entity: The &struct amdgpu_ttm_buffer_entity owning the GART window +* @index: The window to use (must be 0 or 1) +*/ +static inline u64 amdgpu_compute_gart_address (struct amdgpu_gmc *gmc, +struct amdgpu_ttm_buffer_entity *entity, +int index) +{ +return gmc->gart_start + entity->gart_window_offs[index]; +} +void amdgpu_ttm_tt_set_user_pages (struct ttm_tt *ttm,struct amdgpu_hmm_range *range);int amdgpu_ttm_tt_get_userptr (const struct ttm_buffer_object *tbo,uint64_t *user_addr);drivers/gpu/drm/amd/amdkfd/kfd_migrate.c +4
-5@@ -59,8 +59,7 @@ svm_migrate_gart_map(struct amdgpu_ring *ring,void *cpu_addr;int r; -/* use gart window 0 */ - *gart_addr = adev->gmc.gart_start; + *gart_addr =amdgpu_compute_gart_address (&adev->gmc, entity,0 ); num_dw =ALIGN (adev->mman.buffer_funcs->copy_num_dw,8 ); num_bytes = npages *8 ;@@ -116,7 +115,7 @@ svm_migrate_gart_map(struct amdgpu_ring *ring,* multiple GTT_MAX_PAGES transfer, all sdma operations are serialized, wait for * the last sdma finish fence which is returned to check copy memory is done. * -* Context: Process context, takes and releases gtt_window_lock +* Context: Process context * * Return: * 0 - OK, otherwise error code @@ -138,7 +137,7 @@ svm_migrate_copy_memory_gart(struct amdgpu_device *adev, dma_addr_t *sys, entity = &adev->mman.move_entity; -mutex_lock (&adev->mman.gtt_window_lock); +mutex_lock (&entity->lock);while (npages) { size =min (GTT_MAX_PAGES , npages);@@ -175,7 +174,7 @@ svm_migrate_copy_memory_gart(struct amdgpu_device *adev, dma_addr_t *sys, } out_unlock: -mutex_unlock (&adev->mman.gtt_window_lock); +mutex_unlock (&entity->lock);return r; }
PATCH v4 7/13 drm/amdgpu: remove AMDGPU_GTT_NUM_TRANSFER_WINDOWS
In reply to Pierre-Eric Pelloux-Prayerttm is going to use a variable number of windows so we need to get rid of the hardcoded value.
Since amdgpu_gtt_mgr_init is initialized after amdgpu_ttm_set_buffer_funcs_status is called with enable=false, we still need to determine the reserved windows count before doing the real initialisation so a warning is added if the actual value doesn't match the reserved one.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c | 8 +++++--- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 21 ++++++++++++++------- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h | 7 +++---- drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c | 6 ++++-- drivers/gpu/drm/amd/amdgpu/amdgpu_vce.h | 3 ++- drivers/gpu/drm/amd/amdgpu/vce_v1_0.c | 12 ++++-------- 6 files changed, 32 insertions(+), 25 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c +5 -3
@@ -269,10 +269,12 @@ static const struct ttm_resource_manager_func amdgpu_gtt_mgr_func = {* * @adev: amdgpu_device pointer * @gtt_size: maximum size of GTT +* @reserved_windows: num of already used windows * * Allocate and initialize the GTT manager. */ -int amdgpu_gtt_mgr_init (struct amdgpu_device *adev,uint64_t gtt_size) +int amdgpu_gtt_mgr_init (struct amdgpu_device *adev,uint64_t gtt_size, +u32 reserved_windows) {struct amdgpu_gtt_mgr *mgr = &adev->mman.gtt_mgr;struct ttm_resource_manager *man = &mgr->manager;
@@ -283,8 +285,8 @@ int amdgpu_gtt_mgr_init(struct amdgpu_device *adev, uint64_t gtt_size)ttm_resource_manager_init (man, &adev->mman.bdev, gtt_size); - start =AMDGPU_GTT_MAX_TRANSFER_SIZE *AMDGPU_GTT_NUM_TRANSFER_WINDOWS ; - start +=amdgpu_vce_required_gart_pages (adev); + start =AMDGPU_GTT_MAX_TRANSFER_SIZE * reserved_windows; + start +=amdgpu_vce_required_gart_pages (adev, start); size = (adev->gmc.gart_size >>PAGE_SHIFT ) - start;drm_mm_init (&mgr->mm, start, size);spin_lock_init (&mgr->lock);
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +14 -7
@@ -1906,6 +1906,7 @@ static int amdgpu_ttm_buffer_entity_init(struct amdgpu_ttm_buffer_entity *entityint amdgpu_ttm_init (struct amdgpu_device *adev) {uint64_t gtt_size; +u32 reserved_windows;int r;dma_set_max_seg_size (adev->dev,UINT_MAX );
@@ -1938,7 +1939,7 @@ int amdgpu_ttm_init(struct amdgpu_device *adev) }/* Change the size here instead of the init above so only lpfn is affected */ -amdgpu_ttm_set_buffer_funcs_status (adev, false); + reserved_windows =amdgpu_ttm_set_buffer_funcs_status (adev, false);#ifdef CONFIG_64BIT #ifdef CONFIG_X86 if (adev->gmc.xgmi.connected_to_cpu)
@@ -2034,7 +2035,7 @@ int amdgpu_ttm_init(struct amdgpu_device *adev) }/* Initialize GTT memory pool */ - r =amdgpu_gtt_mgr_init (adev, gtt_size); + r =amdgpu_gtt_mgr_init (adev, gtt_size, reserved_windows);if (r) {dev_err (adev->dev,"Failed initializing GTT heap.\n" );return r;
@@ -2173,17 +2174,21 @@ void amdgpu_ttm_fini(struct amdgpu_device *adev)* * Enable/disable use of buffer functions during suspend/resume. This should * only be called at bootup or when userspace isn't running. +* +* Returns: the number of GART reserved window */ -void amdgpu_ttm_set_buffer_funcs_status (struct amdgpu_device *adev,bool enable) +u32 amdgpu_ttm_set_buffer_funcs_status (struct amdgpu_device *adev,bool enable) {struct ttm_resource_manager *man =ttm_manager_type (&adev->mman.bdev,TTM_PL_VRAM ); -u32 used_windows; +u32 used_windows, reserved_windows;uint64_t size;int r; + reserved_windows =3 ; +if (!adev->mman.initialized ||amdgpu_in_reset (adev) || adev->mman.buffer_funcs_enabled == enable || adev->gmc.is_app_apu) -return ; +return reserved_windows;if (enable) {struct amdgpu_ring *ring;
@@ -2198,7 +2203,7 @@ void amdgpu_ttm_set_buffer_funcs_status(struct amdgpu_device *adev, bool enable)dev_err (adev->dev,"Failed setting up TTM BO move entity (%d)\n" , r); -return ; +return 0 ; } r = drm_sched_entity_init(&adev->mman.clear_entity.base,
@@ -2229,6 +2234,7 @@ void amdgpu_ttm_set_buffer_funcs_status(struct amdgpu_device *adev, bool enable) used_windows, true, true); used_windows =amdgpu_ttm_buffer_entity_init (&adev->mman.clear_entity, used_windows, false, true); +WARN_ON (used_windows != reserved_windows); }else {drm_sched_entity_destroy (&adev->mman.default_entity.base);drm_sched_entity_destroy (&adev->mman.clear_entity.base);
@@ -2247,10 +2253,11 @@ void amdgpu_ttm_set_buffer_funcs_status(struct amdgpu_device *adev, bool enable) man->size = size; adev->mman.buffer_funcs_enabled = enable; -return ; +return reserved_windows; error_free_entity:drm_sched_entity_destroy (&adev->mman.default_entity.base); +return 0 ; } static int amdgpu_ttm_prepare_job(struct amdgpu_device *adev,
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h +3 -4
@@ -40,7 +40,6 @@#define __AMDGPU_PL_NUM (TTM_PL_PRIV + 6)#define AMDGPU_GTT_MAX_TRANSFER_SIZE 512 -#define AMDGPU_GTT_NUM_TRANSFER_WINDOWS 3extern const struct attribute_group amdgpu_vram_mgr_attr_group;extern const struct attribute_group amdgpu_gtt_mgr_attr_group;
@@ -135,7 +134,7 @@ struct amdgpu_copy_mem {#define AMDGPU_COPY_FLAGS_GET (value, field) \ (((__u32)(value) >> AMDGPU_COPY_FLAGS_##field##_SHIFT) & AMDGPU_COPY_FLAGS_##field##_MASK) -int amdgpu_gtt_mgr_init (struct amdgpu_device *adev,uint64_t gtt_size); +int amdgpu_gtt_mgr_init (struct amdgpu_device *adev,uint64_t gtt_size,u32 reserved_windows);void amdgpu_gtt_mgr_fini (struct amdgpu_device *adev);int amdgpu_preempt_mgr_init (struct amdgpu_device *adev);void amdgpu_preempt_mgr_fini (struct amdgpu_device *adev);
@@ -169,8 +168,8 @@ bool amdgpu_res_cpu_visible(struct amdgpu_device *adev,int amdgpu_ttm_init (struct amdgpu_device *adev);void amdgpu_ttm_fini (struct amdgpu_device *adev); -void amdgpu_ttm_set_buffer_funcs_status (struct amdgpu_device *adev, -bool enable); +u32 amdgpu_ttm_set_buffer_funcs_status (struct amdgpu_device *adev, +bool enable); int amdgpu_copy_buffer(struct amdgpu_device *adev, struct amdgpu_ttm_buffer_entity *entity, uint64_t src_offset,
drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c +4 -2
@@ -459,11 +459,13 @@ void amdgpu_vce_free_handles(struct amdgpu_device *adev, struct drm_file *filp)* For VCE1, see vce_v1_0_ensure_vcpu_bo_32bit_addr for details. * For VCE2+, this is not needed so return zero. */ -u32 amdgpu_vce_required_gart_pages (struct amdgpu_device *adev) +u32 amdgpu_vce_required_gart_pages (struct amdgpu_device *adev,u64 gtt_transfer_end) {/* VCE IP block not added yet, so can't use amdgpu_ip_version */ -if (adev->family ==AMDGPU_FAMILY_SI ) +if (adev->family ==AMDGPU_FAMILY_SI ) { + adev->vce.gart_page_start = gtt_transfer_end;return 512 ; + }return 0 ; }
drivers/gpu/drm/amd/amdgpu/amdgpu_vce.h +2 -1
@@ -52,6 +52,7 @@ struct amdgpu_vce {uint32_t srbm_soft_reset;unsigned num_rings;uint32_t keyselect; +u64 gart_page_start; };int amdgpu_vce_early_init (struct amdgpu_device *adev);
@@ -61,7 +62,7 @@ int amdgpu_vce_entity_init(struct amdgpu_device *adev, struct amdgpu_ring *ring)int amdgpu_vce_suspend (struct amdgpu_device *adev);int amdgpu_vce_resume (struct amdgpu_device *adev);void amdgpu_vce_free_handles (struct amdgpu_device *adev,struct drm_file *filp); -u32 amdgpu_vce_required_gart_pages (struct amdgpu_device *adev); +u32 amdgpu_vce_required_gart_pages (struct amdgpu_device *adev,u64 gtt_transfer_end);int amdgpu_vce_ring_parse_cs (struct amdgpu_cs_parser *p,struct amdgpu_job *job,struct amdgpu_ib *ib); int amdgpu_vce_ring_parse_cs_vm(struct amdgpu_cs_parser *p,
drivers/gpu/drm/amd/amdgpu/vce_v1_0.c +4 -8
@@ -47,11 +47,6 @@#define VCE_V1_0_DATA_SIZE (7808 * (AMDGPU_MAX_VCE_HANDLES + 1))#define VCE_STATUS_VCPU_REPORT_FW_LOADED_MASK 0x02 -#define VCE_V1_0_GART_PAGE_START \ - (AMDGPU_GTT_MAX_TRANSFER_SIZE * AMDGPU_GTT_NUM_TRANSFER_WINDOWS) -#define VCE_V1_0_GART_ADDR_START \ - (VCE_V1_0_GART_PAGE_START * AMDGPU_GPU_PAGE_SIZE) -static void vce_v1_0_set_ring_funcs (struct amdgpu_device *adev);static void vce_v1_0_set_irq_funcs (struct amdgpu_device *adev);
@@ -541,6 +536,7 @@ static int vce_v1_0_ensure_vcpu_bo_32bit_addr(struct amdgpu_device *adev)u64 num_pages =ALIGN (bo_size,AMDGPU_GPU_PAGE_SIZE ) /AMDGPU_GPU_PAGE_SIZE ;u64 pa =amdgpu_gmc_vram_pa (adev, adev->vce.vcpu_bo);u64 flags =AMDGPU_PTE_READABLE |AMDGPU_PTE_WRITEABLE |AMDGPU_PTE_VALID ; +u64 vce_gart_addr_start = adev->vce.gart_page_start *AMDGPU_GPU_PAGE_SIZE ;/* * Check if the VCPU BO already has a 32-bit address.
@@ -550,12 +546,12 @@ static int vce_v1_0_ensure_vcpu_bo_32bit_addr(struct amdgpu_device *adev)return 0 ;/* Check if we can map the VCPU BO in GART to a 32-bit address. */ -if (adev->gmc.gart_start +VCE_V1_0_GART_ADDR_START > max_vcpu_bo_addr) +if (adev->gmc.gart_start + vce_gart_addr_start > max_vcpu_bo_addr)return -EINVAL ; -amdgpu_gart_map_vram_range (adev, pa,VCE_V1_0_GART_PAGE_START , +amdgpu_gart_map_vram_range (adev, pa, adev->vce.gart_page_start, num_pages, flags, adev->gart.ptr); - adev->vce.gpu_addr = adev->gmc.gart_start +VCE_V1_0_GART_ADDR_START ; + adev->vce.gpu_addr = adev->gmc.gart_start + vce_gart_addr_start;if (adev->vce.gpu_addr > max_vcpu_bo_addr)return -EINVAL ;
Signature · 1 line
2.43.0
Christian König
maintainerRe: [PATCH v4 07/13] drm/amdgpu: remove AMDGPU_GTT_NUM_TRANSFER_WINDOWS
Quoted 8 lines · Pierre-Eric Pelloux-Prayer
ttm is going to use a variable number of windows so we need to get rid of the hardcoded value.
Since
amdgpu_gtt_mgr_initis initialized afteramdgpu_ttm_set_buffer_funcs_statusis called with enable=false, we still need to determine the reserved windows count before doing the real initialisation so a warning is added if the actual value doesn't match the reserved one.
Yeah, the problem is that we need to initialize the SDMA first to figure out the actual number of windows we are going to need.
E.g. it can be that some SDMA instances are harvested or something like that.
Please move this patch as far as possible to the end of the series and let's sync up on teams on how to proceed.
Thanks,
Christian.
Quoted 238 lines
Signed-off-by Pierre-Eric Pelloux-Prayer <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c | 8 +++++--- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 21 ++++++++++++++------- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h | 7 +++---- drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c | 6 ++++-- drivers/gpu/drm/amd/amdgpu/amdgpu_vce.h | 3 ++- drivers/gpu/drm/amd/amdgpu/vce_v1_0.c | 12 ++++-------- 6 files changed, 32 insertions(+), 25 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c +5
-3@@ -269,10 +269,12 @@ static const struct ttm_resource_manager_func amdgpu_gtt_mgr_func = {* * @adev: amdgpu_device pointer * @gtt_size: maximum size of GTT +* @reserved_windows: num of already used windows * * Allocate and initialize the GTT manager. */ -int amdgpu_gtt_mgr_init (struct amdgpu_device *adev,uint64_t gtt_size) +int amdgpu_gtt_mgr_init (struct amdgpu_device *adev,uint64_t gtt_size, +u32 reserved_windows) {struct amdgpu_gtt_mgr *mgr = &adev->mman.gtt_mgr;struct ttm_resource_manager *man = &mgr->manager;@@ -283,8 +285,8 @@ int amdgpu_gtt_mgr_init(struct amdgpu_device *adev, uint64_t gtt_size)ttm_resource_manager_init (man, &adev->mman.bdev, gtt_size); - start =AMDGPU_GTT_MAX_TRANSFER_SIZE *AMDGPU_GTT_NUM_TRANSFER_WINDOWS ; - start +=amdgpu_vce_required_gart_pages (adev); + start =AMDGPU_GTT_MAX_TRANSFER_SIZE * reserved_windows; + start +=amdgpu_vce_required_gart_pages (adev, start); size = (adev->gmc.gart_size >>PAGE_SHIFT ) - start;drm_mm_init (&mgr->mm, start, size);spin_lock_init (&mgr->lock);drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +14
-7@@ -1906,6 +1906,7 @@ static int amdgpu_ttm_buffer_entity_init(struct amdgpu_ttm_buffer_entity *entityint amdgpu_ttm_init (struct amdgpu_device *adev) {uint64_t gtt_size; +u32 reserved_windows;int r;dma_set_max_seg_size (adev->dev,UINT_MAX );@@ -1938,7 +1939,7 @@ int amdgpu_ttm_init(struct amdgpu_device *adev) }/* Change the size here instead of the init above so only lpfn is affected */ -amdgpu_ttm_set_buffer_funcs_status (adev, false); + reserved_windows =amdgpu_ttm_set_buffer_funcs_status (adev, false);#ifdef CONFIG_64BIT #ifdef CONFIG_X86 if (adev->gmc.xgmi.connected_to_cpu)@@ -2034,7 +2035,7 @@ int amdgpu_ttm_init(struct amdgpu_device *adev) }/* Initialize GTT memory pool */ - r =amdgpu_gtt_mgr_init (adev, gtt_size); + r =amdgpu_gtt_mgr_init (adev, gtt_size, reserved_windows);if (r) {dev_err (adev->dev,"Failed initializing GTT heap.\n" );return r;@@ -2173,17 +2174,21 @@ void amdgpu_ttm_fini(struct amdgpu_device *adev)* * Enable/disable use of buffer functions during suspend/resume. This should * only be called at bootup or when userspace isn't running. +* +* Returns: the number of GART reserved window */ -void amdgpu_ttm_set_buffer_funcs_status (struct amdgpu_device *adev,bool enable) +u32 amdgpu_ttm_set_buffer_funcs_status (struct amdgpu_device *adev,bool enable) {struct ttm_resource_manager *man =ttm_manager_type (&adev->mman.bdev,TTM_PL_VRAM ); -u32 used_windows; +u32 used_windows, reserved_windows;uint64_t size;int r; + reserved_windows =3 ; +if (!adev->mman.initialized ||amdgpu_in_reset (adev) || adev->mman.buffer_funcs_enabled == enable || adev->gmc.is_app_apu) -return ; +return reserved_windows;if (enable) {struct amdgpu_ring *ring;@@ -2198,7 +2203,7 @@ void amdgpu_ttm_set_buffer_funcs_status(struct amdgpu_device *adev, bool enable)dev_err (adev->dev,"Failed setting up TTM BO move entity (%d)\n" , r); -return ; +return 0 ; } r = drm_sched_entity_init(&adev->mman.clear_entity.base,@@ -2229,6 +2234,7 @@ void amdgpu_ttm_set_buffer_funcs_status(struct amdgpu_device *adev, bool enable) used_windows, true, true); used_windows =amdgpu_ttm_buffer_entity_init (&adev->mman.clear_entity, used_windows, false, true); +WARN_ON (used_windows != reserved_windows); }else {drm_sched_entity_destroy (&adev->mman.default_entity.base);drm_sched_entity_destroy (&adev->mman.clear_entity.base);@@ -2247,10 +2253,11 @@ void amdgpu_ttm_set_buffer_funcs_status(struct amdgpu_device *adev, bool enable) man->size = size; adev->mman.buffer_funcs_enabled = enable; -return ; +return reserved_windows; error_free_entity:drm_sched_entity_destroy (&adev->mman.default_entity.base); +return 0 ; } static int amdgpu_ttm_prepare_job(struct amdgpu_device *adev,drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h +3
-4@@ -40,7 +40,6 @@#define __AMDGPU_PL_NUM (TTM_PL_PRIV + 6)#define AMDGPU_GTT_MAX_TRANSFER_SIZE 512 -#define AMDGPU_GTT_NUM_TRANSFER_WINDOWS 3extern const struct attribute_group amdgpu_vram_mgr_attr_group;extern const struct attribute_group amdgpu_gtt_mgr_attr_group;@@ -135,7 +134,7 @@ struct amdgpu_copy_mem {#define AMDGPU_COPY_FLAGS_GET (value, field) \ (((__u32)(value) >> AMDGPU_COPY_FLAGS_##field##_SHIFT) & AMDGPU_COPY_FLAGS_##field##_MASK) -int amdgpu_gtt_mgr_init (struct amdgpu_device *adev,uint64_t gtt_size); +int amdgpu_gtt_mgr_init (struct amdgpu_device *adev,uint64_t gtt_size,u32 reserved_windows);void amdgpu_gtt_mgr_fini (struct amdgpu_device *adev);int amdgpu_preempt_mgr_init (struct amdgpu_device *adev);void amdgpu_preempt_mgr_fini (struct amdgpu_device *adev);@@ -169,8 +168,8 @@ bool amdgpu_res_cpu_visible(struct amdgpu_device *adev,int amdgpu_ttm_init (struct amdgpu_device *adev);void amdgpu_ttm_fini (struct amdgpu_device *adev); -void amdgpu_ttm_set_buffer_funcs_status (struct amdgpu_device *adev, -bool enable); +u32 amdgpu_ttm_set_buffer_funcs_status (struct amdgpu_device *adev, +bool enable); int amdgpu_copy_buffer(struct amdgpu_device *adev, struct amdgpu_ttm_buffer_entity *entity, uint64_t src_offset,drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c +4
-2@@ -459,11 +459,13 @@ void amdgpu_vce_free_handles(struct amdgpu_device *adev, struct drm_file *filp)* For VCE1, see vce_v1_0_ensure_vcpu_bo_32bit_addr for details. * For VCE2+, this is not needed so return zero. */ -u32 amdgpu_vce_required_gart_pages (struct amdgpu_device *adev) +u32 amdgpu_vce_required_gart_pages (struct amdgpu_device *adev,u64 gtt_transfer_end) {/* VCE IP block not added yet, so can't use amdgpu_ip_version */ -if (adev->family ==AMDGPU_FAMILY_SI ) +if (adev->family ==AMDGPU_FAMILY_SI ) { + adev->vce.gart_page_start = gtt_transfer_end;return 512 ; + }return 0 ; }drivers/gpu/drm/amd/amdgpu/amdgpu_vce.h +2
-1@@ -52,6 +52,7 @@ struct amdgpu_vce {uint32_t srbm_soft_reset;unsigned num_rings;uint32_t keyselect; +u64 gart_page_start; };int amdgpu_vce_early_init (struct amdgpu_device *adev);@@ -61,7 +62,7 @@ int amdgpu_vce_entity_init(struct amdgpu_device *adev, struct amdgpu_ring *ring)int amdgpu_vce_suspend (struct amdgpu_device *adev);int amdgpu_vce_resume (struct amdgpu_device *adev);void amdgpu_vce_free_handles (struct amdgpu_device *adev,struct drm_file *filp); -u32 amdgpu_vce_required_gart_pages (struct amdgpu_device *adev); +u32 amdgpu_vce_required_gart_pages (struct amdgpu_device *adev,u64 gtt_transfer_end);int amdgpu_vce_ring_parse_cs (struct amdgpu_cs_parser *p,struct amdgpu_job *job,struct amdgpu_ib *ib); int amdgpu_vce_ring_parse_cs_vm(struct amdgpu_cs_parser *p,drivers/gpu/drm/amd/amdgpu/vce_v1_0.c +4
-8@@ -47,11 +47,6 @@#define VCE_V1_0_DATA_SIZE (7808 * (AMDGPU_MAX_VCE_HANDLES + 1))#define VCE_STATUS_VCPU_REPORT_FW_LOADED_MASK 0x02 -#define VCE_V1_0_GART_PAGE_START \ - (AMDGPU_GTT_MAX_TRANSFER_SIZE * AMDGPU_GTT_NUM_TRANSFER_WINDOWS) -#define VCE_V1_0_GART_ADDR_START \ - (VCE_V1_0_GART_PAGE_START * AMDGPU_GPU_PAGE_SIZE) -static void vce_v1_0_set_ring_funcs (struct amdgpu_device *adev);static void vce_v1_0_set_irq_funcs (struct amdgpu_device *adev);@@ -541,6 +536,7 @@ static int vce_v1_0_ensure_vcpu_bo_32bit_addr(struct amdgpu_device *adev)u64 num_pages =ALIGN (bo_size,AMDGPU_GPU_PAGE_SIZE ) /AMDGPU_GPU_PAGE_SIZE ;u64 pa =amdgpu_gmc_vram_pa (adev, adev->vce.vcpu_bo);u64 flags =AMDGPU_PTE_READABLE |AMDGPU_PTE_WRITEABLE |AMDGPU_PTE_VALID ; +u64 vce_gart_addr_start = adev->vce.gart_page_start *AMDGPU_GPU_PAGE_SIZE ;/* * Check if the VCPU BO already has a 32-bit address. @@ -550,12 +546,12 @@ static int vce_v1_0_ensure_vcpu_bo_32bit_addr(struct amdgpu_device *adev)return 0 ;/* Check if we can map the VCPU BO in GART to a 32-bit address. */ -if (adev->gmc.gart_start +VCE_V1_0_GART_ADDR_START > max_vcpu_bo_addr) +if (adev->gmc.gart_start + vce_gart_addr_start > max_vcpu_bo_addr)return -EINVAL ; -amdgpu_gart_map_vram_range (adev, pa,VCE_V1_0_GART_PAGE_START , +amdgpu_gart_map_vram_range (adev, pa, adev->vce.gart_page_start, num_pages, flags, adev->gart.ptr); - adev->vce.gpu_addr = adev->gmc.gart_start +VCE_V1_0_GART_ADDR_START ; + adev->vce.gpu_addr = adev->gmc.gart_start + vce_gart_addr_start;if (adev->vce.gpu_addr > max_vcpu_bo_addr)return -EINVAL ;
PATCH v4 8/13 drm/amdgpu: add missing lock in amdgpu_benchmark_do_move
In reply to Pierre-Eric Pelloux-PrayerTaking the entity lock is required to guarantee the ordering of execution. The next commit will add a check that the lock is held.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_benchmark.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_benchmark.c +2 -0
@@ -35,6 +35,7 @@ static int amdgpu_benchmark_do_move(struct amdgpu_device *adev, unsigned size,struct dma_fence *fence;int i, r; +mutex_lock (&adev->mman.default_entity.lock); stime =ktime_get ();for (i =0 ; i < n; i++) { r = amdgpu_copy_buffer(adev, &adev->mman.default_entity,
@@ -47,6 +48,7 @@ static int amdgpu_benchmark_do_move(struct amdgpu_device *adev, unsigned size,if (r) goto exit_do_move; } +mutex_unlock (&adev->mman.default_entity.lock); exit_do_move: etime =ktime_get ();
Signature · 1 line
2.43.0
Re: [PATCH v4 08/13] drm/amdgpu: add missing lock in amdgpu_benchmark_do_move
Quoted 5 lines · Pierre-Eric Pelloux-Prayer
Taking the entity lock is required to guarantee the ordering of execution. The next commit will add a check that the lock is held.
Signed-off-by Pierre-Eric Pelloux-Prayer <[email protected]>
Quoted 24 lines
--- drivers/gpu/drm/amd/amdgpu/amdgpu_benchmark.c | 2 ++ 1 file changed, 2 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu_benchmark.c +2
-0@@ -35,6 +35,7 @@ static int amdgpu_benchmark_do_move(struct amdgpu_device *adev, unsigned size,struct dma_fence *fence;int i, r; +mutex_lock (&adev->mman.default_entity.lock); stime =ktime_get ();for (i =0 ; i < n; i++) { r = amdgpu_copy_buffer(adev, &adev->mman.default_entity,@@ -47,6 +48,7 @@ static int amdgpu_benchmark_do_move(struct amdgpu_device *adev, unsigned size,if (r) goto exit_do_move; } +mutex_unlock (&adev->mman.default_entity.lock); exit_do_move: etime =ktime_get ();
PATCH v4 9/13 drm/amdgpu: check entity lock is held in amdgpu_ttm_job_submit
In reply to Pierre-Eric Pelloux-Prayerdrm_sched_job_arm and drm_sched_entity_push_job must be called under the same lock to guarantee the order of execution.
This commit adds a check in amdgpu_ttm_job_submit and fix the places where the lock was missing.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +8 -5
@@ -163,7 +163,8 @@ static void amdgpu_evict_flags(struct ttm_buffer_object *bo, }static struct dma_fence * -amdgpu_ttm_job_submit (struct amdgpu_device *adev,struct amdgpu_job *job,u32 num_dw) +amdgpu_ttm_job_submit (struct amdgpu_device *adev,struct amdgpu_ttm_buffer_entity *entity, +struct amdgpu_job *job,u32 num_dw) {struct amdgpu_ring *ring;
@@ -171,6 +172,8 @@ amdgpu_ttm_job_submit(struct amdgpu_device *adev, struct amdgpu_job *job, u32 nuamdgpu_ring_pad_ib (ring, &job->ibs[0 ]);WARN_ON (job->ibs[0 ].length_dw > num_dw); +lockdep_assert_held (&entity->lock); +return amdgpu_job_submit (job); }
@@ -267,7 +270,7 @@ static int amdgpu_ttm_map_buffer(struct amdgpu_ttm_buffer_entity *entity,amdgpu_gart_map_vram_range (adev, pa,0 , num_pages, flags, cpu_addr); } -dma_fence_put (amdgpu_ttm_job_submit (adev, job, num_dw)); +dma_fence_put (amdgpu_ttm_job_submit (adev, entity, job, num_dw));return 0 ; }
@@ -1509,7 +1512,7 @@ static int amdgpu_ttm_access_memory_sdma(struct ttm_buffer_object *bo,amdgpu_emit_copy_buffer (adev, &job->ibs[0 ], src_addr, dst_addr,PAGE_SIZE ,0 ); - fence =amdgpu_ttm_job_submit (adev, job, num_dw); + fence =amdgpu_ttm_job_submit (adev, &adev->mman.default_entity, job, num_dw);mutex_unlock (&adev->mman.default_entity.lock);if (!dma_fence_wait_timeout (fence, false, adev->sdma_timeout))
@@ -2331,7 +2334,7 @@ int amdgpu_copy_buffer(struct amdgpu_device *adev, byte_count -= cur_size_in_bytes; } - *fence =amdgpu_ttm_job_submit (adev, job, num_dw); + *fence =amdgpu_ttm_job_submit (adev, entity, job, num_dw);return 0 ;
@@ -2374,7 +2377,7 @@ static int amdgpu_ttm_fill_mem(struct amdgpu_device *adev, byte_count -= cur_size; } - *fence =amdgpu_ttm_job_submit (adev, job, num_dw); + *fence =amdgpu_ttm_job_submit (adev, entity, job, num_dw);return 0 ; }
Signature · 1 line
2.43.0
PATCH v4 10/13 drm/amdgpu: double AMDGPU_GTT_MAX_TRANSFER_SIZE
In reply to Pierre-Eric Pelloux-PrayerMakes copies/evictions faster when gart windows are required.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h +1 -1
@@ -39,7 +39,7 @@#define AMDGPU_PL_MMIO_REMAP (TTM_PL_PRIV + 5)#define __AMDGPU_PL_NUM (TTM_PL_PRIV + 6) -#define AMDGPU_GTT_MAX_TRANSFER_SIZE 512 +#define AMDGPU_GTT_MAX_TRANSFER_SIZE 1024extern const struct attribute_group amdgpu_vram_mgr_attr_group;extern const struct attribute_group amdgpu_gtt_mgr_attr_group;
Signature · 1 line
2.43.0
PATCH v4 11/13 drm/amdgpu: use larger gart window when possible
In reply to Pierre-Eric Pelloux-PrayerEntities' gart windows are contiguous so when copying a buffer and src doesn't need a gart window, its window can be used to extend dst one (and vice versa).
This doubles the gart window size and reduces the number of jobs required.
---
v2: pass adev instead of ring to amdgpu_ttm_needs_gart_window v4:
- merge if conditions
- always call amdgpu_ttm_needs_gart_window before calling amdgpu_ttm_map_buffer
---
--- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 83 +++++++++++++++++-------- 1 file changed, 57 insertions(+), 26 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +57 -26
@@ -177,6 +177,21 @@ amdgpu_ttm_job_submit(struct amdgpu_device *adev, struct amdgpu_ttm_buffer_entitreturn amdgpu_job_submit (job); } +static bool amdgpu_ttm_needs_gart_window (struct amdgpu_device *adev, +struct ttm_resource *mem, +struct amdgpu_res_cursor *mm_cur, +bool tmz, +uint64_t *addr) +{ +/* Map only what can't be accessed directly */ +if (!tmz && mem->start !=AMDGPU_BO_INVALID_OFFSET ) { + *addr =amdgpu_ttm_domain_start (adev, mem->mem_type) + + mm_cur->start; +return false; + } +return true; +} +/** * amdgpu_ttm_map_buffer - Map memory into the GART windows * @entity: entity to run the window setup job
@@ -184,18 +199,22 @@ amdgpu_ttm_job_submit(struct amdgpu_device *adev, struct amdgpu_ttm_buffer_entit* @mem: memory object to map * @mm_cur: range to map * @window: which GART window to use +* @use_two_windows: if true, use a double window * @tmz: if we should setup a TMZ enabled mapping * @size: in number of bytes to map, out number of bytes mapped * @addr: resulting address inside the MC address space * * Setup one of the GART windows to access a specific piece of memory or return * the physical address for local memory. +* amdgpu_ttm_needs_gart_window() should be used to check if calling this +* function is required. */ static int amdgpu_ttm_map_buffer (struct amdgpu_ttm_buffer_entity *entity,struct ttm_buffer_object *bo,struct ttm_resource *mem,struct amdgpu_res_cursor *mm_cur,unsigned int window, +bool use_two_windows,bool tmz,uint64_t *size,uint64_t *addr) {struct amdgpu_device *adev =amdgpu_ttm_adev (bo->bdev);
@@ -212,14 +231,6 @@ static int amdgpu_ttm_map_buffer(struct amdgpu_ttm_buffer_entity *entity,if (WARN_ON (mem->mem_type ==AMDGPU_PL_PREEMPT ))return -EINVAL ; -/* Map only what can't be accessed directly */ -if (!tmz && mem->start !=AMDGPU_BO_INVALID_OFFSET ) { - *addr =amdgpu_ttm_domain_start (adev, mem->mem_type) + - mm_cur->start; -return 0 ; - } - -/* * If start begins at an offset inside the page, then adjust the size * and addr accordingly
@@ -227,7 +238,8 @@ static int amdgpu_ttm_map_buffer(struct amdgpu_ttm_buffer_entity *entity, offset = mm_cur->start & ~PAGE_MASK ; num_pages =PFN_UP (*size + offset); - num_pages =min_t (uint32_t, num_pages,AMDGPU_GTT_MAX_TRANSFER_SIZE ); + num_pages =min_t (uint32_t, + num_pages,AMDGPU_GTT_MAX_TRANSFER_SIZE * (use_two_windows ?2 :1 )); *size =min (*size, (uint64_t )num_pages *PAGE_SIZE - offset);
@@ -299,6 +311,7 @@ static int amdgpu_ttm_copy_mem_to_mem(struct amdgpu_device *adev,struct dma_resv *resv, struct dma_fence **f) { + bool src_needs_gart_window, dst_needs_gart_window;struct amdgpu_res_cursor src_mm, dst_mm;struct dma_fence *fence =NULL ;int r =0 ;
@@ -323,16 +336,29 @@ static int amdgpu_ttm_copy_mem_to_mem(struct amdgpu_device *adev,/* Never copy more than 256MiB at once to avoid a timeout */ cur_size =min3 (src_mm.size, dst_mm.size,256ULL <<20 ); -/* Map src to window 0 and dst to window 1. */ - r =amdgpu_ttm_map_buffer (entity, src->bo, src->mem, &src_mm, -0 , tmz, &cur_size, &from); -if (r) - goto error; +/* If only one direction needs a gart window to access memory, use both +* windows for it. +*/ + src_needs_gart_window = +amdgpu_ttm_needs_gart_window (adev, src->mem, &src_mm, tmz, &from); + dst_needs_gart_window = +amdgpu_ttm_needs_gart_window (adev, dst->mem, &dst_mm, tmz, &to); - r =amdgpu_ttm_map_buffer (entity, dst->bo, dst->mem, &dst_mm, -1 , tmz, &cur_size, &to); -if (r) - goto error; +if (src_needs_gart_window) { + r =amdgpu_ttm_map_buffer (entity, src->bo, src->mem, &src_mm, +0 , !dst_needs_gart_window, + tmz, &cur_size, &from); +if (r) + goto error; + } +if (dst_needs_gart_window) { + r =amdgpu_ttm_map_buffer (entity, dst->bo, dst->mem, &dst_mm, + src_needs_gart_window ?1 :0 , + !src_needs_gart_window, + tmz, &cur_size, &to); +if (r) + goto error; + } abo_src =ttm_to_amdgpu_bo (src->bo); abo_dst =ttm_to_amdgpu_bo (dst->bo);
@@ -2426,10 +2452,12 @@ int amdgpu_ttm_clear_buffer(struct amdgpu_bo *bo,/* Never clear more than 256MiB at once to avoid timeouts */ size =min (cursor.size,256ULL <<20 ); - r =amdgpu_ttm_map_buffer (entity, &bo->tbo, bo->tbo.resource, &cursor, -1 , false, &size, &addr); -if (r) - goto err; +if (amdgpu_ttm_needs_gart_window (adev, bo->tbo.resource, &cursor, false, &addr)) { + r =amdgpu_ttm_map_buffer (entity, &bo->tbo, bo->tbo.resource, &cursor, +1 , false, false, &size, &addr); +if (r) + goto err; + } r = amdgpu_ttm_fill_mem(adev, entity, 0, addr, size, resv, &next, true,
@@ -2476,10 +2504,13 @@ int amdgpu_fill_buffer(struct amdgpu_ttm_buffer_entity *entity,/* Never fill more than 256MiB at once to avoid timeouts */ cur_size =min (dst.size,256ULL <<20 ); - r =amdgpu_ttm_map_buffer (entity, &bo->tbo, bo->tbo.resource, &dst, -1 , false, &cur_size, &to); -if (r) - goto error; +if (amdgpu_ttm_needs_gart_window (adev, bo->tbo.resource, &dst, false, &to)) { + r =amdgpu_ttm_map_buffer (entity, &bo->tbo, bo->tbo.resource, &dst, +1 , false, false, + &cur_size, &to); +if (r) + goto error; + } r = amdgpu_ttm_fill_mem(adev, entity, src_data, to, cur_size, resv,
Signature · 1 line
2.43.0
PATCH v4 12/13 drm/amdgpu: introduce amdgpu_sdma_set_vm_pte_scheds
In reply to Pierre-Eric Pelloux-PrayerAll sdma versions used the same logic, so add a helper and move the common code to a single place.
---
v2: pass amdgpu_vm_pte_funcs as well
v3: drop all the *_set_vm_pte_funcs one liners
---
--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 2 ++ drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 17 ++++++++++++ drivers/gpu/drm/amd/amdgpu/cik_sdma.c | 31 ++++++--------------- drivers/gpu/drm/amd/amdgpu/sdma_v2_4.c | 31 ++++++--------------- drivers/gpu/drm/amd/amdgpu/sdma_v3_0.c | 31 ++++++--------------- drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c | 35 ++++++------------------ drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c | 35 ++++++------------------ drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c | 31 ++++++--------------- drivers/gpu/drm/amd/amdgpu/sdma_v5_2.c | 31 ++++++--------------- drivers/gpu/drm/amd/amdgpu/sdma_v6_0.c | 29 ++++++-------------- drivers/gpu/drm/amd/amdgpu/sdma_v7_0.c | 29 ++++++-------------- drivers/gpu/drm/amd/amdgpu/si_dma.c | 31 ++++++--------------- 12 files changed, 105 insertions(+), 228 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +2 -0
@@ -1612,6 +1612,8 @@ struct dma_fence *amdgpu_device_enforce_isolation(struct amdgpu_device *adev,bool amdgpu_device_has_display_hardware (struct amdgpu_device *adev);ssize_t amdgpu_get_soft_full_reset_mask (struct amdgpu_ring *ring);ssize_t amdgpu_show_reset_mask (char *buf,uint32_t supported_reset); +void amdgpu_sdma_set_vm_pte_scheds (struct amdgpu_device *adev, +const struct amdgpu_vm_pte_funcs *vm_pte_funcs);/* atpx handler */ #if defined(CONFIG_VGA_SWITCHEROO )
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +17 -0
@@ -3228,3 +3228,20 @@ void amdgpu_vm_print_task_info(struct amdgpu_device *adev, task_info->process_name, task_info->tgid, task_info->task.comm, task_info->task.pid); } + +void amdgpu_sdma_set_vm_pte_scheds (struct amdgpu_device *adev, +const struct amdgpu_vm_pte_funcs *vm_pte_funcs) +{ +struct drm_gpu_scheduler *sched; +int i; + +for (i =0 ; i < adev->sdma.num_instances; i++) { +if (adev->sdma.has_page_queue) + sched = &adev->sdma.instance[i].page.sched; +else + sched = &adev->sdma.instance[i].ring.sched; + adev->vm_manager.vm_pte_scheds[i] = sched; + } + adev->vm_manager.vm_pte_num_scheds = adev->sdma.num_instances; + adev->vm_manager.vm_pte_funcs = vm_pte_funcs; +}
drivers/gpu/drm/amd/amdgpu/cik_sdma.c +9 -22
@@ -53,7 +53,6 @@ static const u32 sdma_offsets[SDMA_MAX_INSTANCE] =static void cik_sdma_set_ring_funcs (struct amdgpu_device *adev);static void cik_sdma_set_irq_funcs (struct amdgpu_device *adev);static void cik_sdma_set_buffer_funcs (struct amdgpu_device *adev); -static void cik_sdma_set_vm_pte_funcs (struct amdgpu_device *adev);static int cik_sdma_soft_reset (struct amdgpu_ip_block *ip_block);u32 amdgpu_cik_gpu_check_soft_reset (struct amdgpu_device *adev);
@@ -919,6 +918,14 @@ static void cik_enable_sdma_mgls(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_pte_pde = cik_sdma_vm_set_pte_pde, +}; +static int cik_sdma_early_init (struct amdgpu_ip_block *ip_block) {struct amdgpu_device *adev = ip_block->adev;
@@ -933,7 +940,7 @@ static int cik_sdma_early_init(struct amdgpu_ip_block *ip_block)cik_sdma_set_ring_funcs (adev);cik_sdma_set_irq_funcs (adev);cik_sdma_set_buffer_funcs (adev); -cik_sdma_set_vm_pte_funcs (adev); +amdgpu_sdma_set_vm_pte_scheds (adev, &cik_sdma_vm_pte_funcs);return 0 ; }
@@ -1337,26 +1344,6 @@ static void cik_sdma_set_buffer_funcs(struct amdgpu_device *adev) adev->mman.buffer_funcs_ring = &adev->sdma.instance[0 ].ring; } -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_pte_pde = cik_sdma_vm_set_pte_pde, -}; - -static void cik_sdma_set_vm_pte_funcs (struct amdgpu_device *adev) -{ -unsigned i; - - adev->vm_manager.vm_pte_funcs = &cik_sdma_vm_pte_funcs; -for (i =0 ; i < adev->sdma.num_instances; i++) { - adev->vm_manager.vm_pte_scheds[i] = - &adev->sdma.instance[i].ring.sched; - } - adev->vm_manager.vm_pte_num_scheds = adev->sdma.num_instances; -} -const struct amdgpu_ip_block_version cik_sdma_ip_block = { .type =AMD_IP_BLOCK_TYPE_SDMA ,
drivers/gpu/drm/amd/amdgpu/sdma_v2_4.c +9 -22
@@ -51,7 +51,6 @@static void sdma_v2_4_set_ring_funcs (struct amdgpu_device *adev);static void sdma_v2_4_set_buffer_funcs (struct amdgpu_device *adev); -static void sdma_v2_4_set_vm_pte_funcs (struct amdgpu_device *adev);static void sdma_v2_4_set_irq_funcs (struct amdgpu_device *adev);MODULE_FIRMWARE ("amdgpu/topaz_sdma.bin" );
@@ -809,6 +808,14 @@ static void sdma_v2_4_ring_emit_wreg(struct amdgpu_ring *ring,amdgpu_ring_write (ring, val); } +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_pte_pde = sdma_v2_4_vm_set_pte_pde, +}; +static int sdma_v2_4_early_init (struct amdgpu_ip_block *ip_block) {struct amdgpu_device *adev = ip_block->adev;
@@ -822,7 +829,7 @@ static int sdma_v2_4_early_init(struct amdgpu_ip_block *ip_block)sdma_v2_4_set_ring_funcs (adev);sdma_v2_4_set_buffer_funcs (adev); -sdma_v2_4_set_vm_pte_funcs (adev); +amdgpu_sdma_set_vm_pte_scheds (adev, &sdma_v2_4_vm_pte_funcs);sdma_v2_4_set_irq_funcs (adev);return 0 ;
@@ -1232,26 +1239,6 @@ static void sdma_v2_4_set_buffer_funcs(struct amdgpu_device *adev) adev->mman.buffer_funcs_ring = &adev->sdma.instance[0 ].ring; } -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_pte_pde = sdma_v2_4_vm_set_pte_pde, -}; - -static void sdma_v2_4_set_vm_pte_funcs (struct amdgpu_device *adev) -{ -unsigned i; - - adev->vm_manager.vm_pte_funcs = &sdma_v2_4_vm_pte_funcs; -for (i =0 ; i < adev->sdma.num_instances; i++) { - adev->vm_manager.vm_pte_scheds[i] = - &adev->sdma.instance[i].ring.sched; - } - adev->vm_manager.vm_pte_num_scheds = adev->sdma.num_instances; -} -const struct amdgpu_ip_block_version sdma_v2_4_ip_block = { .type =AMD_IP_BLOCK_TYPE_SDMA , .major =2 ,
drivers/gpu/drm/amd/amdgpu/sdma_v3_0.c +9 -22
@@ -51,7 +51,6 @@static void sdma_v3_0_set_ring_funcs (struct amdgpu_device *adev);static void sdma_v3_0_set_buffer_funcs (struct amdgpu_device *adev); -static void sdma_v3_0_set_vm_pte_funcs (struct amdgpu_device *adev);static void sdma_v3_0_set_irq_funcs (struct amdgpu_device *adev);MODULE_FIRMWARE ("amdgpu/tonga_sdma.bin" );
@@ -1082,6 +1081,14 @@ static void sdma_v3_0_ring_emit_wreg(struct amdgpu_ring *ring,amdgpu_ring_write (ring, val); } +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, + .set_pte_pde = sdma_v3_0_vm_set_pte_pde, +}; +static int sdma_v3_0_early_init (struct amdgpu_ip_block *ip_block) {struct amdgpu_device *adev = ip_block->adev;
@@ -1102,7 +1109,7 @@ static int sdma_v3_0_early_init(struct amdgpu_ip_block *ip_block)sdma_v3_0_set_ring_funcs (adev);sdma_v3_0_set_buffer_funcs (adev); -sdma_v3_0_set_vm_pte_funcs (adev); +amdgpu_sdma_set_vm_pte_scheds (adev, &sdma_v3_0_vm_pte_funcs);sdma_v3_0_set_irq_funcs (adev);return 0 ;
@@ -1674,26 +1681,6 @@ static void sdma_v3_0_set_buffer_funcs(struct amdgpu_device *adev) adev->mman.buffer_funcs_ring = &adev->sdma.instance[0 ].ring; } -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, - .set_pte_pde = sdma_v3_0_vm_set_pte_pde, -}; - -static void sdma_v3_0_set_vm_pte_funcs (struct amdgpu_device *adev) -{ -unsigned i; - - adev->vm_manager.vm_pte_funcs = &sdma_v3_0_vm_pte_funcs; -for (i =0 ; i < adev->sdma.num_instances; i++) { - adev->vm_manager.vm_pte_scheds[i] = - &adev->sdma.instance[i].ring.sched; - } - adev->vm_manager.vm_pte_num_scheds = adev->sdma.num_instances; -} -const struct amdgpu_ip_block_version sdma_v3_0_ip_block = { .type =AMD_IP_BLOCK_TYPE_SDMA ,
drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c +9 -26
@@ -129,7 +129,6 @@ static const struct amdgpu_hwip_reg_entry sdma_reg_list_4_0[] = {static void sdma_v4_0_set_ring_funcs (struct amdgpu_device *adev);static void sdma_v4_0_set_buffer_funcs (struct amdgpu_device *adev); -static void sdma_v4_0_set_vm_pte_funcs (struct amdgpu_device *adev);static void sdma_v4_0_set_irq_funcs (struct amdgpu_device *adev);static void sdma_v4_0_set_ras_funcs (struct amdgpu_device *adev);
@@ -1751,6 +1750,14 @@ static bool sdma_v4_0_fw_support_paging_queue(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_pte_pde = sdma_v4_0_vm_set_pte_pde, +}; +static int sdma_v4_0_early_init (struct amdgpu_ip_block *ip_block) {struct amdgpu_device *adev = ip_block->adev;
@@ -1769,7 +1776,7 @@ static int sdma_v4_0_early_init(struct amdgpu_ip_block *ip_block)sdma_v4_0_set_ring_funcs (adev);sdma_v4_0_set_buffer_funcs (adev); -sdma_v4_0_set_vm_pte_funcs (adev); +amdgpu_sdma_set_vm_pte_scheds (adev, &sdma_v4_0_vm_pte_funcs);sdma_v4_0_set_irq_funcs (adev);sdma_v4_0_set_ras_funcs (adev);
@@ -2615,30 +2622,6 @@ static void sdma_v4_0_set_buffer_funcs(struct amdgpu_device *adev) adev->mman.buffer_funcs_ring = &adev->sdma.instance[0 ].ring; } -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_pte_pde = sdma_v4_0_vm_set_pte_pde, -}; - -static void sdma_v4_0_set_vm_pte_funcs (struct amdgpu_device *adev) -{ -struct drm_gpu_scheduler *sched; -unsigned i; - - adev->vm_manager.vm_pte_funcs = &sdma_v4_0_vm_pte_funcs; -for (i =0 ; i < adev->sdma.num_instances; i++) { -if (adev->sdma.has_page_queue) - sched = &adev->sdma.instance[i].page.sched; -else - sched = &adev->sdma.instance[i].ring.sched; - adev->vm_manager.vm_pte_scheds[i] = sched; - } - adev->vm_manager.vm_pte_num_scheds = adev->sdma.num_instances; -} -static void sdma_v4_0_get_ras_error_count (uint32_t value,uint32_t instance,uint32_t *sec_count)
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +9 -26
@@ -104,7 +104,6 @@ static const struct amdgpu_hwip_reg_entry sdma_reg_list_4_4_2[] = {static void sdma_v4_4_2_set_ring_funcs (struct amdgpu_device *adev);static void sdma_v4_4_2_set_buffer_funcs (struct amdgpu_device *adev); -static void sdma_v4_4_2_set_vm_pte_funcs (struct amdgpu_device *adev);static void sdma_v4_4_2_set_irq_funcs (struct amdgpu_device *adev);static void sdma_v4_4_2_set_ras_funcs (struct amdgpu_device *adev);static void sdma_v4_4_2_update_reset_mask (struct amdgpu_device *adev);
@@ -1347,6 +1346,14 @@ static const struct amdgpu_sdma_funcs sdma_v4_4_2_sdma_funcs = { .soft_reset_kernel_queue = &sdma_v4_4_2_soft_reset_engine, }; +static const struct amdgpu_vm_pte_funcs sdma_v4_4_2_vm_pte_funcs = { + .copy_pte_num_dw =7 , + .copy_pte = sdma_v4_4_2_vm_copy_pte, + + .write_pte = sdma_v4_4_2_vm_write_pte, + .set_pte_pde = sdma_v4_4_2_vm_set_pte_pde, +}; +static int sdma_v4_4_2_early_init (struct amdgpu_ip_block *ip_block) {struct amdgpu_device *adev = ip_block->adev;
@@ -1362,7 +1369,7 @@ static int sdma_v4_4_2_early_init(struct amdgpu_ip_block *ip_block)sdma_v4_4_2_set_ring_funcs (adev);sdma_v4_4_2_set_buffer_funcs (adev); -sdma_v4_4_2_set_vm_pte_funcs (adev); +amdgpu_sdma_set_vm_pte_scheds (adev, &sdma_v4_4_2_vm_pte_funcs);sdma_v4_4_2_set_irq_funcs (adev);sdma_v4_4_2_set_ras_funcs (adev);return 0 ;
@@ -2316,30 +2323,6 @@ static void sdma_v4_4_2_set_buffer_funcs(struct amdgpu_device *adev) adev->mman.buffer_funcs_ring = &adev->sdma.instance[0 ].ring; } -static const struct amdgpu_vm_pte_funcs sdma_v4_4_2_vm_pte_funcs = { - .copy_pte_num_dw =7 , - .copy_pte = sdma_v4_4_2_vm_copy_pte, - - .write_pte = sdma_v4_4_2_vm_write_pte, - .set_pte_pde = sdma_v4_4_2_vm_set_pte_pde, -}; - -static void sdma_v4_4_2_set_vm_pte_funcs (struct amdgpu_device *adev) -{ -struct drm_gpu_scheduler *sched; -unsigned i; - - adev->vm_manager.vm_pte_funcs = &sdma_v4_4_2_vm_pte_funcs; -for (i =0 ; i < adev->sdma.num_instances; i++) { -if (adev->sdma.has_page_queue) - sched = &adev->sdma.instance[i].page.sched; -else - sched = &adev->sdma.instance[i].ring.sched; - adev->vm_manager.vm_pte_scheds[i] = sched; - } - adev->vm_manager.vm_pte_num_scheds = adev->sdma.num_instances; -} -/** * sdma_v4_4_2_update_reset_mask - update reset mask for SDMA * @adev: Pointer to the AMDGPU device structure
drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c +8 -23
@@ -110,7 +110,6 @@ static const struct amdgpu_hwip_reg_entry sdma_reg_list_5_0[] = {static void sdma_v5_0_set_ring_funcs (struct amdgpu_device *adev);static void sdma_v5_0_set_buffer_funcs (struct amdgpu_device *adev); -static void sdma_v5_0_set_vm_pte_funcs (struct amdgpu_device *adev);static void sdma_v5_0_set_irq_funcs (struct amdgpu_device *adev);static int sdma_v5_0_stop_queue (struct amdgpu_ring *ring);static int sdma_v5_0_restore_queue (struct amdgpu_ring *ring);
@@ -1357,6 +1356,13 @@ static const struct amdgpu_sdma_funcs sdma_v5_0_sdma_funcs = { .soft_reset_kernel_queue = &sdma_v5_0_soft_reset_engine, }; +static const struct amdgpu_vm_pte_funcs sdma_v5_0_vm_pte_funcs = { + .copy_pte_num_dw =7 , + .copy_pte = sdma_v5_0_vm_copy_pte, + .write_pte = sdma_v5_0_vm_write_pte, + .set_pte_pde = sdma_v5_0_vm_set_pte_pde, +}; +static int sdma_v5_0_early_init (struct amdgpu_ip_block *ip_block) {struct amdgpu_device *adev = ip_block->adev;
@@ -1368,7 +1374,7 @@ static int sdma_v5_0_early_init(struct amdgpu_ip_block *ip_block)sdma_v5_0_set_ring_funcs (adev);sdma_v5_0_set_buffer_funcs (adev); -sdma_v5_0_set_vm_pte_funcs (adev); +amdgpu_sdma_set_vm_pte_scheds (adev, &sdma_v5_0_vm_pte_funcs);sdma_v5_0_set_irq_funcs (adev);sdma_v5_0_set_mqd_funcs (adev);
@@ -2073,27 +2079,6 @@ static void sdma_v5_0_set_buffer_funcs(struct amdgpu_device *adev) } } -static const struct amdgpu_vm_pte_funcs sdma_v5_0_vm_pte_funcs = { - .copy_pte_num_dw =7 , - .copy_pte = sdma_v5_0_vm_copy_pte, - .write_pte = sdma_v5_0_vm_write_pte, - .set_pte_pde = sdma_v5_0_vm_set_pte_pde, -}; - -static void sdma_v5_0_set_vm_pte_funcs (struct amdgpu_device *adev) -{ -unsigned i; - -if (adev->vm_manager.vm_pte_funcs ==NULL ) { - adev->vm_manager.vm_pte_funcs = &sdma_v5_0_vm_pte_funcs; -for (i =0 ; i < adev->sdma.num_instances; i++) { - adev->vm_manager.vm_pte_scheds[i] = - &adev->sdma.instance[i].ring.sched; - } - adev->vm_manager.vm_pte_num_scheds = adev->sdma.num_instances; - } -} -const struct amdgpu_ip_block_version sdma_v5_0_ip_block = { .type =AMD_IP_BLOCK_TYPE_SDMA , .major =5 ,
drivers/gpu/drm/amd/amdgpu/sdma_v5_2.c +8 -23
@@ -111,7 +111,6 @@ static const struct amdgpu_hwip_reg_entry sdma_reg_list_5_2[] = {static void sdma_v5_2_set_ring_funcs (struct amdgpu_device *adev);static void sdma_v5_2_set_buffer_funcs (struct amdgpu_device *adev); -static void sdma_v5_2_set_vm_pte_funcs (struct amdgpu_device *adev);static void sdma_v5_2_set_irq_funcs (struct amdgpu_device *adev);static int sdma_v5_2_stop_queue (struct amdgpu_ring *ring);static int sdma_v5_2_restore_queue (struct amdgpu_ring *ring);
@@ -1248,6 +1247,13 @@ static void sdma_v5_2_ring_emit_reg_write_reg_wait(struct amdgpu_ring *ring,amdgpu_ring_emit_reg_wait (ring, reg1, mask, mask); } +static const struct amdgpu_vm_pte_funcs sdma_v5_2_vm_pte_funcs = { + .copy_pte_num_dw =7 , + .copy_pte = sdma_v5_2_vm_copy_pte, + .write_pte = sdma_v5_2_vm_write_pte, + .set_pte_pde = sdma_v5_2_vm_set_pte_pde, +}; +static int sdma_v5_2_early_init (struct amdgpu_ip_block *ip_block) {struct amdgpu_device *adev = ip_block->adev;
@@ -1259,7 +1265,7 @@ static int sdma_v5_2_early_init(struct amdgpu_ip_block *ip_block)sdma_v5_2_set_ring_funcs (adev);sdma_v5_2_set_buffer_funcs (adev); -sdma_v5_2_set_vm_pte_funcs (adev); +amdgpu_sdma_set_vm_pte_scheds (adev, &sdma_v5_2_vm_pte_funcs);sdma_v5_2_set_irq_funcs (adev);sdma_v5_2_set_mqd_funcs (adev);
@@ -2084,27 +2090,6 @@ static void sdma_v5_2_set_buffer_funcs(struct amdgpu_device *adev) } } -static const struct amdgpu_vm_pte_funcs sdma_v5_2_vm_pte_funcs = { - .copy_pte_num_dw =7 , - .copy_pte = sdma_v5_2_vm_copy_pte, - .write_pte = sdma_v5_2_vm_write_pte, - .set_pte_pde = sdma_v5_2_vm_set_pte_pde, -}; - -static void sdma_v5_2_set_vm_pte_funcs (struct amdgpu_device *adev) -{ -unsigned i; - -if (adev->vm_manager.vm_pte_funcs ==NULL ) { - adev->vm_manager.vm_pte_funcs = &sdma_v5_2_vm_pte_funcs; -for (i =0 ; i < adev->sdma.num_instances; i++) { - adev->vm_manager.vm_pte_scheds[i] = - &adev->sdma.instance[i].ring.sched; - } - adev->vm_manager.vm_pte_num_scheds = adev->sdma.num_instances; - } -} -const struct amdgpu_ip_block_version sdma_v5_2_ip_block = { .type =AMD_IP_BLOCK_TYPE_SDMA , .major =5 ,
drivers/gpu/drm/amd/amdgpu/sdma_v6_0.c +8 -21
@@ -119,7 +119,6 @@ static const struct amdgpu_hwip_reg_entry sdma_reg_list_6_0[] = {static void sdma_v6_0_set_ring_funcs (struct amdgpu_device *adev);static void sdma_v6_0_set_buffer_funcs (struct amdgpu_device *adev); -static void sdma_v6_0_set_vm_pte_funcs (struct amdgpu_device *adev);static void sdma_v6_0_set_irq_funcs (struct amdgpu_device *adev);static int sdma_v6_0_start (struct amdgpu_device *adev);
@@ -1268,6 +1267,13 @@ static void sdma_v6_0_set_ras_funcs(struct amdgpu_device *adev) } } +static const struct amdgpu_vm_pte_funcs sdma_v6_0_vm_pte_funcs = { + .copy_pte_num_dw =7 , + .copy_pte = sdma_v6_0_vm_copy_pte, + .write_pte = sdma_v6_0_vm_write_pte, + .set_pte_pde = sdma_v6_0_vm_set_pte_pde, +}; +static int sdma_v6_0_early_init (struct amdgpu_ip_block *ip_block) {struct amdgpu_device *adev = ip_block->adev;
@@ -1296,7 +1302,7 @@ static int sdma_v6_0_early_init(struct amdgpu_ip_block *ip_block)sdma_v6_0_set_ring_funcs (adev);sdma_v6_0_set_buffer_funcs (adev); -sdma_v6_0_set_vm_pte_funcs (adev); +amdgpu_sdma_set_vm_pte_scheds (adev, &sdma_v6_0_vm_pte_funcs);sdma_v6_0_set_irq_funcs (adev);sdma_v6_0_set_mqd_funcs (adev);sdma_v6_0_set_ras_funcs (adev);
@@ -1889,25 +1895,6 @@ static void sdma_v6_0_set_buffer_funcs(struct amdgpu_device *adev) adev->mman.buffer_funcs_ring = &adev->sdma.instance[0 ].ring; } -static const struct amdgpu_vm_pte_funcs sdma_v6_0_vm_pte_funcs = { - .copy_pte_num_dw =7 , - .copy_pte = sdma_v6_0_vm_copy_pte, - .write_pte = sdma_v6_0_vm_write_pte, - .set_pte_pde = sdma_v6_0_vm_set_pte_pde, -}; - -static void sdma_v6_0_set_vm_pte_funcs (struct amdgpu_device *adev) -{ -unsigned i; - - adev->vm_manager.vm_pte_funcs = &sdma_v6_0_vm_pte_funcs; -for (i =0 ; i < adev->sdma.num_instances; i++) { - adev->vm_manager.vm_pte_scheds[i] = - &adev->sdma.instance[i].ring.sched; - } - adev->vm_manager.vm_pte_num_scheds = adev->sdma.num_instances; -} -const struct amdgpu_ip_block_version sdma_v6_0_ip_block = { .type =AMD_IP_BLOCK_TYPE_SDMA , .major =6 ,
drivers/gpu/drm/amd/amdgpu/sdma_v7_0.c +8 -21
@@ -119,7 +119,6 @@ static const struct amdgpu_hwip_reg_entry sdma_reg_list_7_0[] = {static void sdma_v7_0_set_ring_funcs (struct amdgpu_device *adev);static void sdma_v7_0_set_buffer_funcs (struct amdgpu_device *adev); -static void sdma_v7_0_set_vm_pte_funcs (struct amdgpu_device *adev);static void sdma_v7_0_set_irq_funcs (struct amdgpu_device *adev);static int sdma_v7_0_start (struct amdgpu_device *adev);
@@ -1253,6 +1252,13 @@ static void sdma_v7_0_ring_emit_reg_write_reg_wait(struct amdgpu_ring *ring,amdgpu_ring_emit_reg_wait (ring, reg1, mask, mask); } +static const struct amdgpu_vm_pte_funcs sdma_v7_0_vm_pte_funcs = { + .copy_pte_num_dw =8 , + .copy_pte = sdma_v7_0_vm_copy_pte, + .write_pte = sdma_v7_0_vm_write_pte, + .set_pte_pde = sdma_v7_0_vm_set_pte_pde, +}; +static int sdma_v7_0_early_init (struct amdgpu_ip_block *ip_block) {struct amdgpu_device *adev = ip_block->adev;
@@ -1283,7 +1289,7 @@ static int sdma_v7_0_early_init(struct amdgpu_ip_block *ip_block)sdma_v7_0_set_ring_funcs (adev);sdma_v7_0_set_buffer_funcs (adev); -sdma_v7_0_set_vm_pte_funcs (adev); +amdgpu_sdma_set_vm_pte_scheds (adev, &sdma_v7_0_vm_pte_funcs);sdma_v7_0_set_irq_funcs (adev);sdma_v7_0_set_mqd_funcs (adev);
@@ -1831,25 +1837,6 @@ static void sdma_v7_0_set_buffer_funcs(struct amdgpu_device *adev) adev->mman.buffer_funcs_ring = &adev->sdma.instance[0 ].ring; } -static const struct amdgpu_vm_pte_funcs sdma_v7_0_vm_pte_funcs = { - .copy_pte_num_dw =8 , - .copy_pte = sdma_v7_0_vm_copy_pte, - .write_pte = sdma_v7_0_vm_write_pte, - .set_pte_pde = sdma_v7_0_vm_set_pte_pde, -}; - -static void sdma_v7_0_set_vm_pte_funcs (struct amdgpu_device *adev) -{ -unsigned i; - - adev->vm_manager.vm_pte_funcs = &sdma_v7_0_vm_pte_funcs; -for (i =0 ; i < adev->sdma.num_instances; i++) { - adev->vm_manager.vm_pte_scheds[i] = - &adev->sdma.instance[i].ring.sched; - } - adev->vm_manager.vm_pte_num_scheds = adev->sdma.num_instances; -} -const struct amdgpu_ip_block_version sdma_v7_0_ip_block = { .type =AMD_IP_BLOCK_TYPE_SDMA , .major =7 ,
drivers/gpu/drm/amd/amdgpu/si_dma.c +9 -22
@@ -37,7 +37,6 @@ const u32 sdma_offsets[SDMA_MAX_INSTANCE] =static void si_dma_set_ring_funcs (struct amdgpu_device *adev);static void si_dma_set_buffer_funcs (struct amdgpu_device *adev); -static void si_dma_set_vm_pte_funcs (struct amdgpu_device *adev);static void si_dma_set_irq_funcs (struct amdgpu_device *adev);/**
@@ -473,6 +472,14 @@ static void si_dma_ring_emit_wreg(struct amdgpu_ring *ring,amdgpu_ring_write (ring, val); } +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_pte_pde = si_dma_vm_set_pte_pde, +}; +static int si_dma_early_init (struct amdgpu_ip_block *ip_block) {struct amdgpu_device *adev = ip_block->adev;
@@ -481,7 +488,7 @@ static int si_dma_early_init(struct amdgpu_ip_block *ip_block)si_dma_set_ring_funcs (adev);si_dma_set_buffer_funcs (adev); -si_dma_set_vm_pte_funcs (adev); +amdgpu_sdma_set_vm_pte_scheds (adev, &si_dma_vm_pte_funcs);si_dma_set_irq_funcs (adev);return 0 ;
@@ -830,26 +837,6 @@ static void si_dma_set_buffer_funcs(struct amdgpu_device *adev) adev->mman.buffer_funcs_ring = &adev->sdma.instance[0 ].ring; } -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_pte_pde = si_dma_vm_set_pte_pde, -}; - -static void si_dma_set_vm_pte_funcs (struct amdgpu_device *adev) -{ -unsigned i; - - adev->vm_manager.vm_pte_funcs = &si_dma_vm_pte_funcs; -for (i =0 ; i < adev->sdma.num_instances; i++) { - adev->vm_manager.vm_pte_scheds[i] = - &adev->sdma.instance[i].ring.sched; - } - adev->vm_manager.vm_pte_num_scheds = adev->sdma.num_instances; -} -const struct amdgpu_ip_block_version si_dma_ip_block = { .type =AMD_IP_BLOCK_TYPE_SDMA ,
Signature · 1 line
2.43.0
PATCH v4 13/13 drm/amdgpu: move sched status check inside amdgpu_ttm_set_buffer_funcs_status
In reply to Pierre-Eric Pelloux-PrayerIt avoids duplicated code and allows to output a warning.
---
v4: move check inside the existing if (enable) test
---
--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 13 ++++--------- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 5 +++++ 2 files changed, 9 insertions(+), 9 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +4 -9
@@ -3309,9 +3309,7 @@ static int amdgpu_device_ip_init(struct amdgpu_device *adev)if (r) goto init_failed; -if (adev->mman.buffer_funcs_ring && - adev->mman.buffer_funcs_ring->sched.ready) -amdgpu_ttm_set_buffer_funcs_status (adev, true); +amdgpu_ttm_set_buffer_funcs_status (adev, true);/* Don't init kfd if whole hive need to be reset during init */ if (adev->init_lvl->level !=AMDGPU_INIT_LEVEL_MINIMAL_XGMI ) {
@@ -4191,8 +4189,7 @@ static int amdgpu_device_ip_resume(struct amdgpu_device *adev) r =amdgpu_device_ip_resume_phase2 (adev); -if (adev->mman.buffer_funcs_ring->sched.ready) -amdgpu_ttm_set_buffer_funcs_status (adev, true); +amdgpu_ttm_set_buffer_funcs_status (adev, true);if (r)return r;
@@ -5321,8 +5318,7 @@ int amdgpu_device_suspend(struct drm_device *dev, bool notify_clients)return 0 ; unwind_evict: -if (adev->mman.buffer_funcs_ring->sched.ready) -amdgpu_ttm_set_buffer_funcs_status (adev, true); +amdgpu_ttm_set_buffer_funcs_status (adev, true);amdgpu_fence_driver_hw_init (adev); unwind_userq:
@@ -6050,8 +6046,7 @@ int amdgpu_device_reinit_after_reset(struct amdgpu_reset_context *reset_context)if (r) goto out; -if (tmp_adev->mman.buffer_funcs_ring->sched.ready) -amdgpu_ttm_set_buffer_funcs_status (tmp_adev, true); +amdgpu_ttm_set_buffer_funcs_status (tmp_adev, true); r =amdgpu_device_ip_resume_phase3 (tmp_adev);if (r)
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +5 -0
@@ -2223,6 +2223,11 @@ u32 amdgpu_ttm_set_buffer_funcs_status(struct amdgpu_device *adev, bool enable)struct amdgpu_ring *ring;struct drm_gpu_scheduler *sched; +if (!adev->mman.buffer_funcs_ring || !adev->mman.buffer_funcs_ring->sched.ready) { +dev_warn (adev->dev,"Not enabling DMA transfers for in kernel use" ); +return 0 ; + } + ring = adev->mman.buffer_funcs_ring; sched = &ring->sched; r = drm_sched_entity_init(&adev->mman.default_entity.base,
Signature · 1 line
2.43.0
Christian König
maintainerRe: [PATCH v4 13/13] drm/amdgpu: move sched status check inside amdgpu_ttm_set_buffer_funcs_status
Quoted 62 lines · Pierre-Eric Pelloux-Prayer
It avoids duplicated code and allows to output a warning.
---
v4: move check inside the existing if (enable) test
---Signed-off-by Pierre-Eric Pelloux-Prayer <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 13 ++++--------- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 5 +++++ 2 files changed, 9 insertions(+), 9 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +4
-9@@ -3309,9 +3309,7 @@ static int amdgpu_device_ip_init(struct amdgpu_device *adev)if (r) goto init_failed; -if (adev->mman.buffer_funcs_ring && - adev->mman.buffer_funcs_ring->sched.ready) -amdgpu_ttm_set_buffer_funcs_status (adev, true); +amdgpu_ttm_set_buffer_funcs_status (adev, true);/* Don't init kfd if whole hive need to be reset during init */ if (adev->init_lvl->level !=AMDGPU_INIT_LEVEL_MINIMAL_XGMI ) {@@ -4191,8 +4189,7 @@ static int amdgpu_device_ip_resume(struct amdgpu_device *adev) r =amdgpu_device_ip_resume_phase2 (adev); -if (adev->mman.buffer_funcs_ring->sched.ready) -amdgpu_ttm_set_buffer_funcs_status (adev, true); +amdgpu_ttm_set_buffer_funcs_status (adev, true);if (r)return r;@@ -5321,8 +5318,7 @@ int amdgpu_device_suspend(struct drm_device *dev, bool notify_clients)return 0 ; unwind_evict: -if (adev->mman.buffer_funcs_ring->sched.ready) -amdgpu_ttm_set_buffer_funcs_status (adev, true); +amdgpu_ttm_set_buffer_funcs_status (adev, true);amdgpu_fence_driver_hw_init (adev); unwind_userq:@@ -6050,8 +6046,7 @@ int amdgpu_device_reinit_after_reset(struct amdgpu_reset_context *reset_context)if (r) goto out; -if (tmp_adev->mman.buffer_funcs_ring->sched.ready) -amdgpu_ttm_set_buffer_funcs_status (tmp_adev, true); +amdgpu_ttm_set_buffer_funcs_status (tmp_adev, true); r =amdgpu_device_ip_resume_phase3 (tmp_adev);if (r)drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +0
-0
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c u32 amdgpu_ttm_set_buffer_funcs_status(struct amdgpu_device *adev, bool enable) · line 2232
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +5
-0@@ -2223,6 +2223,11 @@ u32 amdgpu_ttm_set_buffer_funcs_status(struct amdgpu_device *adev, bool enable)struct amdgpu_ring *ring;struct drm_gpu_scheduler *sched; +if (!adev->mman.buffer_funcs_ring || !adev->mman.buffer_funcs_ring->sched.ready) { +dev_warn (adev->dev,"Not enabling DMA transfers for in kernel use" ); +return 0 ; + } + ring = adev->mman.buffer_funcs_ring; sched = &ring->sched;
The ring and sched are assigned to local variables here, so you could move that check just a few more lines down.
Apart from that looks good to me.
Regards,
Christian.
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +0
-0r = drm_sched_entity_init(&adev->mman.default_entity.base,