On Tue, Jan 3, 2023 at 4:40 AM Shashank Sharma <shashank.sharma@xxxxxxx> wrote: > > > On 29/12/2022 18:54, Alex Deucher wrote: > > On Fri, Dec 23, 2022 at 2:37 PM Shashank Sharma <shashank.sharma@xxxxxxx> wrote: > >> The FW expects us to allocate atleast one page as process > >> context space, and one for gang context space. This patch adds some > >> object for the same. > > This should be handled in the IP specific code for the MQD creation. > > Each IP may have different requirements for MQD related metadata. > > > > Alex > > Noted, so 3 IP specific functions so far, > > .init_mqd(), .map() and .create_ctx_space(). > I think this can be handled in init_mqd(). No need for a separate callback. Alex > - Shashank > > > > >> Cc: Alex Deucher <alexander.deucher@xxxxxxx> > >> Cc: Christian Koenig <christian.koenig@xxxxxxx> > >> > >> Signed-off-by: Shashank Sharma <shashank.sharma@xxxxxxx> > >> --- > >> drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c | 57 +++++++++++++++++++ > >> .../drm/amd/include/amdgpu_usermode_queue.h | 8 +++ > >> 2 files changed, 65 insertions(+) > >> > >> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c > >> index b566ce4cb7f0..2a854a5e2f70 100644 > >> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c > >> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c > >> @@ -69,6 +69,56 @@ amdgpu_userqueue_get_doorbell(struct amdgpu_device *adev, > >> return 0; > >> } > >> > >> +static int > >> +amdgpu_userqueue_create_context(struct amdgpu_device *adev, struct amdgpu_usermode_queue *queue) > >> +{ > >> + int r; > >> + struct amdgpu_userq_ctx *pctx = &queue->proc_ctx; > >> + struct amdgpu_userq_ctx *gctx = &queue->gang_ctx; > >> + /* > >> + * The FW expects atleast one page space allocated for > >> + * process context related work, and one for gang context. > >> + */ > >> + r = amdgpu_bo_create_kernel(adev, PAGE_SIZE, PAGE_SIZE, > >> + AMDGPU_GEM_DOMAIN_VRAM, > >> + &pctx->obj, > >> + &pctx->gpu_addr, > >> + &pctx->cpu_ptr); > >> + if (r) { > >> + DRM_ERROR("Failed to allocate proc bo for userqueue (%d)", r); > >> + return r; > >> + } > >> + > >> + r = amdgpu_bo_create_kernel(adev, PAGE_SIZE, PAGE_SIZE, > >> + AMDGPU_GEM_DOMAIN_VRAM, > >> + &gctx->obj, > >> + &gctx->gpu_addr, > >> + &gctx->cpu_ptr); > >> + if (r) { > >> + DRM_ERROR("Failed to allocate proc bo for userqueue (%d)", r); > >> + amdgpu_bo_free_kernel(&pctx->obj, > >> + &pctx->gpu_addr, > >> + &pctx->cpu_ptr); > >> + return r; > >> + } > >> + > >> + return 0; > >> +} > >> + > >> +static void > >> +amdgpu_userqueue_free_context(struct amdgpu_device *adev, struct amdgpu_usermode_queue *queue) > >> +{ > >> + struct amdgpu_userq_ctx *pctx = &queue->proc_ctx; > >> + struct amdgpu_userq_ctx *gctx = &queue->gang_ctx; > >> + > >> + amdgpu_bo_free_kernel(&pctx->obj, > >> + &pctx->gpu_addr, > >> + &pctx->cpu_ptr); > >> + amdgpu_bo_free_kernel(&pctx->obj, > >> + &gctx->gpu_addr, > >> + &gctx->cpu_ptr); > >> +} > >> + > >> static void > >> amdgpu_userqueue_setup_mqd(struct amdgpu_device *adev, struct amdgpu_usermode_queue *queue) > >> { > >> @@ -282,6 +332,12 @@ int amdgpu_userqueue_create(struct amdgpu_device *adev, struct drm_file *filp, > >> goto free_mqd; > >> } > >> > >> + r = amdgpu_userqueue_create_context(adev, queue); > >> + if (r < 0) { > >> + DRM_ERROR("Failed to create context for queue\n"); > >> + goto free_mqd; > >> + } > >> + > >> ctx->userq = queue; > >> args->out.q_id = queue->queue_id; > >> args->out.flags = 0; > >> @@ -306,6 +362,7 @@ void amdgpu_userqueue_destroy(struct amdgpu_device *adev, struct drm_file *filp, > >> struct amdgpu_usermode_queue *queue = ctx->userq; > >> > >> mutex_lock(&adev->userq.userq_mutex); > >> + amdgpu_userqueue_free_context(adev, queue); > >> amdgpu_userqueue_destroy_mqd(queue); > >> amdgpu_userqueue_remove_index(adev, queue); > >> ctx->userq = NULL; > >> diff --git a/drivers/gpu/drm/amd/include/amdgpu_usermode_queue.h b/drivers/gpu/drm/amd/include/amdgpu_usermode_queue.h > >> index c1fe39ffaf72..8bf3c0be6937 100644 > >> --- a/drivers/gpu/drm/amd/include/amdgpu_usermode_queue.h > >> +++ b/drivers/gpu/drm/amd/include/amdgpu_usermode_queue.h > >> @@ -26,6 +26,12 @@ > >> > >> #define AMDGPU_MAX_USERQ 512 > >> > >> +struct amdgpu_userq_ctx { > >> + struct amdgpu_bo *obj; > >> + uint64_t gpu_addr; > >> + void *cpu_ptr; > >> +}; > >> + > >> struct amdgpu_usermode_queue { > >> int queue_id; > >> int queue_type; > >> @@ -44,6 +50,8 @@ struct amdgpu_usermode_queue { > >> > >> struct amdgpu_bo *mqd_obj; > >> struct amdgpu_vm *vm; > >> + struct amdgpu_userq_ctx proc_ctx; > >> + struct amdgpu_userq_ctx gang_ctx; > >> struct list_head list; > >> }; > >> > >> -- > >> 2.34.1 > >>