AMD-GFX Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: "Christian König" <christian.koenig@amd.com>
To: Shashank Sharma <shashank.sharma@amd.com>, amd-gfx@lists.freedesktop.org
Cc: Alex Deucher <alexander.deucher@amd.com>, arvind.yadav@amd.com
Subject: Re: [PATCH v5 08/10] drm/amdgpu: generate doorbell index for userqueue
Date: Fri, 7 Jul 2023 09:15:10 +0200	[thread overview]
Message-ID: <2834445d-8da2-e853-50c2-2fececdb86e2@amd.com> (raw)
In-Reply-To: <20230706123602.2331-9-shashank.sharma@amd.com>

Am 06.07.23 um 14:36 schrieb Shashank Sharma:
> The userspace sends us the doorbell object and the relative doobell
> index in the object to be used for the usermode queue, but the FW
> expects the absolute doorbell index on the PCI BAR in the MQD. This
> patch adds a function to convert this relative doorbell index to
> absolute doorbell index.
>
> This patch is dependent on the doorbell manager series:
> Link: https://patchwork.freedesktop.org/series/115802/
>
> V5: Fix the db object reference leak (Christian)
>
> Cc: Alex Deucher <alexander.deucher@amd.com>
> Cc: Christian Koenig <christian.koenig@amd.com>
> Signed-off-by: Shashank Sharma <shashank.sharma@amd.com>
> ---
>   drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c | 34 +++++++++++++++++++
>   drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c        |  1 +
>   2 files changed, 35 insertions(+)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c
> index bb774144c372..61064266c4f8 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c
> @@ -32,6 +32,31 @@ amdgpu_userqueue_find(struct amdgpu_userq_mgr *uq_mgr, int qid)
>   	return idr_find(&uq_mgr->userq_idr, qid);
>   }
>   
> +static uint64_t
> +amdgpu_userqueue_get_doorbell_index(struct amdgpu_userq_mgr *uq_mgr,
> +				     struct amdgpu_usermode_queue *queue,
> +				     struct drm_file *filp,
> +				     uint32_t doorbell_offset)
> +{
> +	struct drm_gem_object *gobj;
> +	struct amdgpu_bo *db_bo;
> +	uint64_t index;
> +
> +	gobj = drm_gem_object_lookup(filp, queue->doorbell_handle);
> +	if (gobj == NULL) {
> +		DRM_ERROR("Can't find GEM object for doorbell\n");
> +		return -EINVAL;
> +	}
> +
> +	db_bo = amdgpu_bo_ref(gem_to_amdgpu_bo(gobj));
> +	drm_gem_object_put(gobj);
> +
> +	index = amdgpu_doorbell_index_on_bar(uq_mgr->adev, db_bo, doorbell_offset);

This can only be done with the doorbell BO locked and as soon as you 
unlock it the value becomes invalid unless you pin the BO.

Regards,
Christian.

> +	amdgpu_bo_unref(&db_bo);
> +	DRM_DEBUG_DRIVER("[Usermode queues] doorbell index=%lld\n", index);
> +	return index;
> +}
> +
>   static int
>   amdgpu_userqueue_destroy(struct drm_file *filp, int queue_id)
>   {
> @@ -64,6 +89,7 @@ amdgpu_userqueue_create(struct drm_file *filp, union drm_amdgpu_userq *args)
>   	struct amdgpu_userq_mgr *uq_mgr = &fpriv->userq_mgr;
>   	const struct amdgpu_userq_funcs *uq_funcs;
>   	struct amdgpu_usermode_queue *queue;
> +	uint64_t index;
>   	int qid, r = 0;
>   
>   	mutex_lock(&uq_mgr->userq_mutex);
> @@ -87,6 +113,14 @@ amdgpu_userqueue_create(struct drm_file *filp, union drm_amdgpu_userq *args)
>   	queue->flags = args->in.flags;
>   	queue->vm = &fpriv->vm;
>   
> +	/* Convert relative doorbell offset into absolute doorbell index */
> +	index = amdgpu_userqueue_get_doorbell_index(uq_mgr, queue, filp, args->in.doorbell_offset);
> +	if (index == (uint64_t)-EINVAL) {
> +		DRM_ERROR("Failed to get doorbell for queue\n");
> +		goto unlock;
> +	}
> +	queue->doorbell_index = index;
> +
>   	r = uq_funcs->mqd_create(uq_mgr, &args->in, queue);
>   	if (r) {
>   		DRM_ERROR("Failed to create Queue\n");
> diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c b/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c
> index afaeecb9940a..8edb020683a1 100644
> --- a/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c
> +++ b/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c
> @@ -6719,6 +6719,7 @@ static int gfx_v11_0_userq_mqd_create(struct amdgpu_userq_mgr *uq_mgr,
>   	userq_props.queue_size = mqd_user.queue_size;
>   	userq_props.hqd_base_gpu_addr = mqd_user.queue_va;
>   	userq_props.mqd_gpu_addr = queue->mqd.gpu_addr;
> +	userq_props.doorbell_index = queue->doorbell_index;
>   	userq_props.use_doorbell = true;
>   
>   	r = mqd_gfx_generic->init_mqd(adev, (void *)queue->mqd.cpu_ptr, &userq_props);


  reply	other threads:[~2023-07-07  7:15 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-06 12:35 [PATCH v5 00/10] AMDGPU Usermode queues Shashank Sharma
2023-07-06 12:35 ` [PATCH v5 01/10] drm/amdgpu: UAPI for user queue management Shashank Sharma
2023-07-06 12:35 ` [PATCH v5 02/10] drm/amdgpu: add usermode queue base code Shashank Sharma
2023-07-06 12:46   ` Christian König
2023-07-06 16:36   ` Alex Deucher
2023-07-06 16:52     ` Shashank Sharma
2023-07-06 17:34       ` Alex Deucher
2023-07-06 12:35 ` [PATCH v5 03/10] drm/amdgpu: add new IOCTL for usermode queue Shashank Sharma
2023-07-06 13:20   ` Christian König
2023-07-06 12:35 ` [PATCH v5 04/10] drm/amdgpu: create GFX-gen11 " Shashank Sharma
2023-07-06 13:22   ` Christian König
2023-07-06 13:37     ` Shashank Sharma
2023-07-06 13:39       ` Christian König
2023-07-06 13:43         ` Shashank Sharma
2023-07-11 19:51         ` Felix Kuehling
2023-07-12 15:55           ` Shashank Sharma
2023-07-12 16:01             ` Felix Kuehling
2023-07-12 16:07               ` Shashank Sharma
2023-07-06 16:27   ` Alex Deucher
2023-07-06 16:29     ` Shashank Sharma
2023-07-07  7:24   ` Christian König
2023-07-07  7:46     ` Shashank Sharma
2023-07-07  8:37       ` Christian König
2023-07-07 10:02         ` Shashank Sharma
2023-07-07 12:28           ` Christian König
2023-07-07 12:46             ` Shashank Sharma
2023-07-06 12:35 ` [PATCH v5 05/10] drm/amdgpu: create context space for " Shashank Sharma
2023-07-06 13:28   ` Christian König
2023-07-06 13:33     ` Shashank Sharma
2023-07-06 13:37       ` Christian König
2023-07-06 16:44   ` Alex Deucher
2023-07-06 12:35 ` [PATCH v5 06/10] drm/amdgpu: map usermode queue into MES Shashank Sharma
2023-07-06 14:47   ` Christian König
2023-07-06 16:52   ` Alex Deucher
2023-07-06 17:15     ` Shashank Sharma
2023-07-06 17:26       ` Alex Deucher
2023-07-06 17:32         ` Shashank Sharma
2023-07-06 17:36           ` Alex Deucher
2023-07-06 12:35 ` [PATCH v5 07/10] drm/amdgpu: map wptr BO into GART Shashank Sharma
2023-07-06 12:36 ` [PATCH v5 08/10] drm/amdgpu: generate doorbell index for userqueue Shashank Sharma
2023-07-07  7:15   ` Christian König [this message]
2023-07-07  7:39     ` Shashank Sharma
2023-07-07  7:57       ` Christian König
2023-07-07  9:00         ` Shashank Sharma
2023-07-06 12:36 ` [PATCH v5 09/10] drm/amdgpu: cleanup leftover queues Shashank Sharma
2023-07-07  7:17   ` Christian König
2023-07-07  7:40     ` Shashank Sharma
2023-07-06 12:36 ` [PATCH v5 10/10] drm/amdgpu: add delay after userqueue mapping Shashank Sharma
2023-07-06 17:41   ` Alex Deucher
2023-07-06 18:30     ` Shashank Sharma

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2834445d-8da2-e853-50c2-2fececdb86e2@amd.com \
    --to=christian.koenig@amd.com \
    --cc=alexander.deucher@amd.com \
    --cc=amd-gfx@lists.freedesktop.org \
    --cc=arvind.yadav@amd.com \
    --cc=shashank.sharma@amd.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox