[PATCH 3/8] drm/amdgpu: introduce userqueue MQD handlers

Alex Deucher alexdeucher at gmail.com
Tue Feb 7 14:59:02 UTC 2023


On Fri, Feb 3, 2023 at 4:54 PM Shashank Sharma <shashank.sharma at amd.com> wrote:
>
> From: Shashank Sharma <contactshashanksharma at gmail.com>
>
> A Memory queue descriptor (MQD) of a userqueue defines it in the harware's
> context. As the method of formation of a MQD, and its format can vary between
> different graphics IPs, we need gfx GEN specific handlers to create MQDs.
>
> This patch:
> - Introduces MQD hander functions for the usermode queues
> - A general function to create and destroy MQD for a userqueue.
>
> V1: Worked on review comments from Alex on RFC patches:
>     MQD creation should be gen and IP specific.
>
> Cc: Alex Deucher <alexander.deucher at amd.com>
> Cc: Christian Koenig <christian.koenig at amd.com>
> Signed-off-by: Shashank Sharma <contactshashanksharma at gmail.com>
> ---
>  drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c | 64 +++++++++++++++++++
>  .../gpu/drm/amd/include/amdgpu_userqueue.h    |  9 +++
>  2 files changed, 73 insertions(+)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c
> index d5bc7fe81750..625c2fe1e84a 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c
> @@ -42,6 +42,60 @@ static struct amdgpu_usermode_queue
>      return idr_find(&uq_mgr->userq_idr, qid);
>  }
>
> +static int
> +amdgpu_userqueue_create_mqd(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_usermode_queue *queue)
> +{
> +    int r;
> +    int size;
> +    struct amdgpu_device *adev = uq_mgr->adev;
> +
> +    if (!uq_mgr->userq_mqd_funcs) {
> +        DRM_ERROR("Userqueue not initialized\n");
> +        return -EINVAL;
> +    }
> +
> +    size = uq_mgr->userq_mqd_funcs->mqd_size(uq_mgr);
> +    r = amdgpu_bo_create_kernel(adev, size, PAGE_SIZE,
> +                                AMDGPU_GEM_DOMAIN_VRAM,
> +                                &queue->mqd_obj,
> +                                &queue->mqd_gpu_addr,
> +                                &queue->mqd_cpu_ptr);
> +    if (r) {
> +        DRM_ERROR("Failed to allocate bo for userqueue (%d)", r);
> +        return r;
> +    }
> +
> +    memset(queue->mqd_cpu_ptr, 0, size);
> +    r = amdgpu_bo_reserve(queue->mqd_obj, false);
> +    if (unlikely(r != 0)) {
> +        DRM_ERROR("Failed to reserve mqd for userqueue (%d)", r);
> +        goto free_mqd;
> +    }
> +
> +    r = uq_mgr->userq_mqd_funcs->mqd_create(uq_mgr, queue);
> +    amdgpu_bo_unreserve(queue->mqd_obj);
> +    if (r) {
> +        DRM_ERROR("Failed to create MQD for queue\n");
> +        goto free_mqd;
> +    }
> +    return 0;
> +
> +free_mqd:
> +    amdgpu_bo_free_kernel(&queue->mqd_obj,
> +                          &queue->mqd_gpu_addr,
> +                          &queue->mqd_cpu_ptr);
> +   return r;
> +}
> +
> +static void
> +amdgpu_userqueue_destroy_mqd(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_usermode_queue *queue)
> +{
> +    uq_mgr->userq_mqd_funcs->mqd_destroy(uq_mgr, queue);
> +    amdgpu_bo_free_kernel(&queue->mqd_obj,
> +                          &queue->mqd_gpu_addr,
> +                          &queue->mqd_cpu_ptr);
> +}
> +
>  static int amdgpu_userqueue_create(struct drm_file *filp, union drm_amdgpu_userq *args)
>  {
>      int r, pasid;
> @@ -82,12 +136,21 @@ static int amdgpu_userqueue_create(struct drm_file *filp, union drm_amdgpu_userq
>          goto free_queue;
>      }
>
> +    r = amdgpu_userqueue_create_mqd(uq_mgr, queue);
> +    if (r) {
> +        DRM_ERROR("Failed to create MQD\n");
> +        goto free_qid;
> +    }
> +
>      list_add_tail(&queue->userq_node, &uq_mgr->userq_list);
>      args->out.q_id = queue->queue_id;
>      args->out.flags = 0;
>      mutex_unlock(&uq_mgr->userq_mutex);
>      return 0;
>
> +free_qid:
> +    amdgpu_userqueue_free_index(uq_mgr, queue->queue_id);
> +
>  free_queue:
>      mutex_unlock(&uq_mgr->userq_mutex);
>      kfree(queue);
> @@ -107,6 +170,7 @@ static void amdgpu_userqueue_destroy(struct drm_file *filp, int queue_id)
>      }
>
>      mutex_lock(&uq_mgr->userq_mutex);
> +    amdgpu_userqueue_destroy_mqd(uq_mgr, queue);
>      amdgpu_userqueue_free_index(uq_mgr, queue->queue_id);
>      list_del(&queue->userq_node);
>      mutex_unlock(&uq_mgr->userq_mutex);
> diff --git a/drivers/gpu/drm/amd/include/amdgpu_userqueue.h b/drivers/gpu/drm/amd/include/amdgpu_userqueue.h
> index 9557588fe34f..a6abdfd5cb74 100644
> --- a/drivers/gpu/drm/amd/include/amdgpu_userqueue.h
> +++ b/drivers/gpu/drm/amd/include/amdgpu_userqueue.h
> @@ -26,10 +26,13 @@
>
>  #define AMDGPU_MAX_USERQ 512
>
> +struct amdgpu_userq_mqd_funcs;
> +
>  struct amdgpu_userq_mgr {
>         struct idr userq_idr;
>         struct mutex userq_mutex;
>         struct list_head userq_list;
> +       const struct amdgpu_userq_mqd_funcs *userq_mqd_funcs;
>         struct amdgpu_device *adev;
>  };
>
> @@ -57,6 +60,12 @@ struct amdgpu_usermode_queue {
>
>  int amdgpu_userq_ioctl(struct drm_device *dev, void *data, struct drm_file *filp);
>
> +struct amdgpu_userq_mqd_funcs {
> +       int (*mqd_size)(struct amdgpu_userq_mgr *);
> +       int (*mqd_create)(struct amdgpu_userq_mgr *, struct amdgpu_usermode_queue *);
> +       void (*mqd_destroy)(struct amdgpu_userq_mgr *, struct amdgpu_usermode_queue *);

I think all we need is create and destroy callbacks.  All memory
allocations and metadata required for a specific engine's queue
management should be handled internally in the engine specific code.

Alex

> +};
> +
>  int amdgpu_userq_mgr_init(struct amdgpu_userq_mgr *userq_mgr, struct amdgpu_device *adev);
>
>  void amdgpu_userq_mgr_fini(struct amdgpu_userq_mgr *userq_mgr);
> --
> 2.34.1
>


More information about the amd-gfx mailing list