Unify amdgpu_mes_alloc/free_proc|gang_ctx_index to provide centralized RS64mem bitmap management for both KGD and KFD.
Signed-off-by: Prike Liang <[email protected]> --- drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c | 28 +++++++++++----------- drivers/gpu/drm/amd/amdgpu/amdgpu_mes.h | 8 +++---- drivers/gpu/drm/amd/amdgpu/mes_userqueue.c | 12 ++++++---- 3 files changed, 26 insertions(+), 22 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c index 9af7c97af5be..e3862095ff99 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c @@ -1040,13 +1040,13 @@ int amdgpu_mes_rs64mem_setup_bitmaps(struct amdgpu_mes *mes) * amdgpu_mes_alloc_proc_ctx_index - allocate a process context slot * * @mes: MES instance - * @queue: Usermode queue receiving the allocated process context index + * @index: the allocated process context index * * Returns 0 on success, -ENOSPC if all slots are used, or * -EOPNOTSUPP if RS64 local memory is unavailable. */ int amdgpu_mes_alloc_proc_ctx_index(struct amdgpu_mes *mes, - struct amdgpu_usermode_queue *queue) + uint32_t *index) { unsigned long bit; @@ -1061,7 +1061,7 @@ int amdgpu_mes_alloc_proc_ctx_index(struct amdgpu_mes *mes, return -ENOSPC; } set_bit(bit, mes->proc_ctx_bitmap); - queue->proc_ctx_array_index = (uint32_t)bit; + *index = (uint32_t)bit; amdgpu_mes_unlock(mes); return 0; @@ -1071,18 +1071,18 @@ int amdgpu_mes_alloc_proc_ctx_index(struct amdgpu_mes *mes, * amdgpu_mes_free_proc_ctx_index - free a process context slot * * @mes: MES instance - * @queue: Usermode queue whose process context index is released + * @index: process context index is released */ void amdgpu_mes_free_proc_ctx_index(struct amdgpu_mes *mes, - struct amdgpu_usermode_queue *queue) + uint32_t index) { if (!mes->use_rs64mem || !mes->proc_ctx_bitmap) return; - if (queue->proc_ctx_array_index >= mes->proc_ctx_array_size) + if (index >= mes->proc_ctx_array_size) return; amdgpu_mes_lock(mes); - clear_bit(queue->proc_ctx_array_index, mes->proc_ctx_bitmap); + clear_bit(index, mes->proc_ctx_bitmap); amdgpu_mes_unlock(mes); } @@ -1090,13 +1090,13 @@ void amdgpu_mes_free_proc_ctx_index(struct amdgpu_mes *mes, * amdgpu_mes_alloc_gang_ctx_index - allocate a gang context slot * * @mes: MES instance - * @queue: Usermode queue receiving the allocated gang context index + * @queue: the allocated gang context index * * Returns 0 on success, -ENOSPC if all slots are used, or * -EOPNOTSUPP if RS64 local memory is unavailable. */ int amdgpu_mes_alloc_gang_ctx_index(struct amdgpu_mes *mes, - struct amdgpu_usermode_queue *queue) + uint32_t *index) { unsigned long bit; @@ -1111,7 +1111,7 @@ int amdgpu_mes_alloc_gang_ctx_index(struct amdgpu_mes *mes, return -ENOSPC; } set_bit(bit, mes->gang_ctx_bitmap); - queue->gang_ctx_array_index = bit; + *index = bit; amdgpu_mes_unlock(mes); return 0; @@ -1121,18 +1121,18 @@ int amdgpu_mes_alloc_gang_ctx_index(struct amdgpu_mes *mes, * amdgpu_mes_free_gang_ctx_index - free a gang context slot * * @mes: MES instance - * @queue: Usermode queue whose gang context index is released + * @queue: gang context index is released */ void amdgpu_mes_free_gang_ctx_index(struct amdgpu_mes *mes, - struct amdgpu_usermode_queue *queue) + uint32_t index) { if (!mes->use_rs64mem || !mes->gang_ctx_bitmap) return; - if (queue->gang_ctx_array_index >= mes->gang_ctx_array_size) + if (index >= mes->gang_ctx_array_size) return; amdgpu_mes_lock(mes); - clear_bit(queue->gang_ctx_array_index, mes->gang_ctx_bitmap); + clear_bit(index, mes->gang_ctx_bitmap); amdgpu_mes_unlock(mes); } diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_mes.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_mes.h index c67db2d6e122..977c057dcce8 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_mes.h +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_mes.h @@ -636,11 +636,11 @@ int amdgpu_mes_rs64mem_init(struct amdgpu_mes *mes); void amdgpu_mes_rs64mem_fini(struct amdgpu_mes *mes); int amdgpu_mes_rs64mem_setup_bitmaps(struct amdgpu_mes *mes); int amdgpu_mes_alloc_proc_ctx_index(struct amdgpu_mes *mes, - struct amdgpu_usermode_queue *queue); + uint32_t *index); void amdgpu_mes_free_proc_ctx_index(struct amdgpu_mes *mes, - struct amdgpu_usermode_queue *queue); + uint32_t index); int amdgpu_mes_alloc_gang_ctx_index(struct amdgpu_mes *mes, - struct amdgpu_usermode_queue *queue); + uint32_t *index); void amdgpu_mes_free_gang_ctx_index(struct amdgpu_mes *mes, - struct amdgpu_usermode_queue *queue); + uint32_t index); #endif /* __AMDGPU_MES_H__ */ diff --git a/drivers/gpu/drm/amd/amdgpu/mes_userqueue.c b/drivers/gpu/drm/amd/amdgpu/mes_userqueue.c index a914198a4d62..7369a8e05101 100644 --- a/drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +++ b/drivers/gpu/drm/amd/amdgpu/mes_userqueue.c @@ -144,9 +144,13 @@ static int mes_userq_map(struct amdgpu_usermode_queue *queue) queue_input.page_table_base_addr = amdgpu_gmc_pd_addr(queue->vm->root.bo); queue_input.wptr_mc_addr = queue->wptr_obj.gpu_addr; if (mes->use_rs64mem) { - amdgpu_mes_alloc_proc_ctx_index(mes, queue); + uint32_t index; + + amdgpu_mes_alloc_proc_ctx_index(mes, &index); + queue->proc_ctx_array_index = index; queue_input.process_context_array_index = queue->proc_ctx_array_index; - amdgpu_mes_alloc_gang_ctx_index(mes, queue); + amdgpu_mes_alloc_gang_ctx_index(mes, &index); + queue->gang_ctx_array_index = index; queue_input.gang_context_array_index = queue->gang_ctx_array_index; } amdgpu_mes_lock(&adev->mes); @@ -180,8 +184,8 @@ static int mes_userq_unmap(struct amdgpu_usermode_queue *queue) r = adev->mes.funcs->remove_hw_queue(&adev->mes, &queue_input); amdgpu_mes_unlock(&adev->mes); if (mes->use_rs64mem) { - amdgpu_mes_free_proc_ctx_index(mes, queue); - amdgpu_mes_free_gang_ctx_index(mes, queue); + amdgpu_mes_free_proc_ctx_index(mes, queue->proc_ctx_array_index); + amdgpu_mes_free_gang_ctx_index(mes, queue->gang_ctx_array_index); } if (r) DRM_ERROR("Failed to unmap queue in HW, err (%d)\n", r); -- 2.34.1
