From: Shashank Sharma <shashank.sharma@amd.com>
To: "Christian König" <christian.koenig@amd.com>,
amd-gfx@lists.freedesktop.org
Cc: Alex Deucher <alexander.deucher@amd.com>,
pierre-eric.pelloux-prayer@amd.com,
contactshashanksharma@gmail.com, arvind.yadav@amd.com
Subject: Re: [PATCH v4 08/10] drm/amdgpu: map wptr BO into GART
Date: Tue, 25 Apr 2023 15:33:21 +0200 [thread overview]
Message-ID: <3da97c12-7ab6-8c16-00f0-359b73f6b0e9@amd.com> (raw)
In-Reply-To: <007d02c2-069d-5597-79c4-3cd21e24d3c1@amd.com>
On 25/04/2023 14:36, Christian König wrote:
> Am 24.04.23 um 19:38 schrieb Shashank Sharma:
>> To support oversubscription, MES FW expects WPTR BOs to
>> be mapped into GART, before they are submitted to usermode
>> queues. This patch adds a function for the same.
>>
>> V4: fix the wptr value before mapping lookup (Bas, Christian).
>>
>> Cc: Alex Deucher <alexander.deucher@amd.com>
>> Cc: Christian Koenig <christian.koenig@amd.com>
>> Signed-off-by: Arvind Yadav <arvind.yadav@amd.com>
>> Signed-off-by: Shashank Sharma <shashank.sharma@amd.com>
>> ---
>> drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c | 90 +++++++++++++++++++
>> drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 1 +
>> .../gpu/drm/amd/include/amdgpu_userqueue.h | 1 +
>> 3 files changed, 92 insertions(+)
>>
>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c
>> b/drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c
>> index e95fb35b0cb5..385cd51b6c96 100644
>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c
>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c
>> @@ -44,6 +44,89 @@ amdgpu_userqueue_find(struct amdgpu_userq_mgr
>> *uq_mgr, int qid)
>> return idr_find(&uq_mgr->userq_idr, qid);
>> }
>> +static int
>> +amdgpu_userqueue_map_gtt_bo_to_gart(struct amdgpu_device *adev,
>> struct amdgpu_bo *bo)
>> +{
>> + int ret;
>> +
>> + ret = amdgpu_bo_reserve(bo, true);
>> + if (ret) {
>> + DRM_ERROR("Failed to reserve bo. ret %d\n", ret);
>> + goto err_reserve_bo_failed;
>> + }
>> +
>> + ret = amdgpu_bo_pin(bo, AMDGPU_GEM_DOMAIN_GTT);
>> + if (ret) {
>> + DRM_ERROR("Failed to pin bo. ret %d\n", ret);
>> + goto err_pin_bo_failed;
>> + }
>> +
>> + ret = amdgpu_ttm_alloc_gart(&bo->tbo);
>> + if (ret) {
>> + DRM_ERROR("Failed to bind bo to GART. ret %d\n", ret);
>> + goto err_map_bo_gart_failed;
>> + }
>
> Either pinning *or* allocating GART, but not both!
>
> I think calling amdgpu_ttm_alloc_gart() is the right thing to do here.
>
Ah, silly me :), Thanks for pointing this out.
>> +
>> + amdgpu_bo_unreserve(bo);
>> + bo = amdgpu_bo_ref(bo);
>> +
>> + return 0;
>> +
>> +err_map_bo_gart_failed:
>> + amdgpu_bo_unpin(bo);
>> +err_pin_bo_failed:
>> + amdgpu_bo_unreserve(bo);
>> +err_reserve_bo_failed:
>> +
>> + return ret;
>> +}
>> +
>> +
>> +static int
>> +amdgpu_userqueue_create_wptr_mapping(struct amdgpu_device *adev,
>> + struct drm_file *filp,
>> + struct amdgpu_usermode_queue *queue)
>> +{
>> + struct amdgpu_bo_va_mapping *wptr_mapping;
>> + struct amdgpu_vm *wptr_vm;
>> + struct amdgpu_bo *wptr_bo = NULL;
>> + uint64_t wptr = queue->userq_prop.wptr_gpu_addr;
>> + int ret;
>> +
>> + wptr_vm = queue->vm;
>> + ret = amdgpu_bo_reserve(wptr_vm->root.bo, false);
>
> All the handling must be done with the VM and all resource locks held.
>
> So this should be something the caller of the function does.
Noted, will add the protections.
- Shashank
>
> Regards,
> Christian.
>
>> + if (ret)
>> + goto err_wptr_map_gart;
>> +
>> + wptr &= AMDGPU_GMC_HOLE_MASK;
>> + wptr_mapping = amdgpu_vm_bo_lookup_mapping(wptr_vm, wptr >>
>> PAGE_SHIFT);
>> + amdgpu_bo_unreserve(wptr_vm->root.bo);
>> + if (!wptr_mapping) {
>> + DRM_ERROR("Failed to lookup wptr bo\n");
>> + ret = -EINVAL;
>> + goto err_wptr_map_gart;
>> + }
>> +
>> + wptr_bo = wptr_mapping->bo_va->base.bo;
>> + if (wptr_bo->tbo.base.size > PAGE_SIZE) {
>> + DRM_ERROR("Requested GART mapping for wptr bo larger than
>> one page\n");
>> + ret = -EINVAL;
>> + goto err_wptr_map_gart;
>> + }
>> +
>> + ret = amdgpu_userqueue_map_gtt_bo_to_gart(adev, wptr_bo);
>> + if (ret) {
>> + DRM_ERROR("Failed to map wptr bo to GART\n");
>> + goto err_wptr_map_gart;
>> + }
>> +
>> + queue->wptr_mc_addr = wptr_bo->tbo.resource->start << PAGE_SHIFT;
>> + return 0;
>> +
>> +err_wptr_map_gart:
>> + return ret;
>> +}
>> +
>> static int amdgpu_userqueue_create_gfx(struct drm_file *filp, union
>> drm_amdgpu_userq *args)
>> {
>> struct amdgpu_usermode_queue *queue;
>> @@ -81,6 +164,13 @@ static int amdgpu_userqueue_create_gfx(struct
>> drm_file *filp, union drm_amdgpu_u
>> goto free_queue;
>> }
>> + r = amdgpu_userqueue_create_wptr_mapping(uq_mgr->adev, filp,
>> queue);
>> + if (r) {
>> + DRM_ERROR("Failed to map WPTR (0x%llx) for userqueue\n",
>> + queue->userq_prop.wptr_gpu_addr);
>> + goto free_queue;
>> + }
>> +
>> if (uq_mgr->userq_funcs[queue->queue_type]->mqd_create) {
>> r =
>> uq_mgr->userq_funcs[queue->queue_type]->mqd_create(uq_mgr, queue);
>> if (r) {
>> diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c
>> b/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c
>> index 7a45d68091ec..6eeae0206d8a 100644
>> --- a/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c
>> +++ b/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c
>> @@ -6439,6 +6439,7 @@ static int gfx_v11_userq_map(struct
>> amdgpu_userq_mgr *uq_mgr,
>> queue_input.queue_size = queue->userq_prop.queue_size >> 2;
>> queue_input.doorbell_offset = queue->userq_prop.doorbell_index;
>> queue_input.page_table_base_addr =
>> amdgpu_gmc_pd_addr(queue->vm->root.bo);
>> + queue_input.wptr_mc_addr = queue->wptr_mc_addr;
>> amdgpu_mes_lock(&adev->mes);
>> r = adev->mes.funcs->add_hw_queue(&adev->mes, &queue_input);
>> diff --git a/drivers/gpu/drm/amd/include/amdgpu_userqueue.h
>> b/drivers/gpu/drm/amd/include/amdgpu_userqueue.h
>> index 11e8ad649f6e..0001ecd710a7 100644
>> --- a/drivers/gpu/drm/amd/include/amdgpu_userqueue.h
>> +++ b/drivers/gpu/drm/amd/include/amdgpu_userqueue.h
>> @@ -38,6 +38,7 @@ struct amdgpu_usermode_queue {
>> int queue_id;
>> int queue_type;
>> uint64_t doorbell_handle;
>> + uint64_t wptr_mc_addr;
>> uint64_t proc_ctx_gpu_addr;
>> uint64_t gang_ctx_gpu_addr;
>> uint64_t gds_ctx_gpu_addr;
>
next prev parent reply other threads:[~2023-04-25 13:33 UTC|newest]
Thread overview: 45+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-24 17:38 [PATCH v4 00/10] AMDGPU usermode queues Shashank Sharma
2023-04-24 17:38 ` [PATCH v4 01/10] drm/amdgpu: UAPI for user queue management Shashank Sharma
2023-05-19 21:03 ` Alex Deucher
2023-05-22 8:54 ` Shashank Sharma
2023-04-24 17:38 ` [PATCH v4 02/10] drm/amdgpu: add usermode queue base code Shashank Sharma
2023-04-25 12:03 ` Christian König
2023-04-25 12:19 ` Shashank Sharma
2023-04-24 17:38 ` [PATCH v4 03/10] drm/amdgpu: add new IOCTL for usermode queue Shashank Sharma
2023-04-25 12:14 ` Christian König
2023-04-25 12:21 ` Shashank Sharma
2023-04-24 17:38 ` [PATCH v4 04/10] drm/amdgpu: create GFX-gen11 MQD for userqueue Shashank Sharma
2023-04-25 12:27 ` Christian König
2023-04-25 13:10 ` Shashank Sharma
2023-04-25 13:45 ` Christian König
2023-04-25 17:02 ` Shashank Sharma
2023-05-19 21:19 ` Alex Deucher
2023-05-22 9:05 ` Shashank Sharma
2023-04-24 17:38 ` [PATCH v4 05/10] drm/amdgpu: create context space for usermode queue Shashank Sharma
2023-04-25 12:30 ` Christian König
2023-04-25 13:13 ` Shashank Sharma
2023-04-25 17:38 ` Deucher, Alexander
2023-04-25 20:00 ` Sharma, Shashank
2023-05-19 21:21 ` Alex Deucher
2023-05-22 9:05 ` Shashank Sharma
2023-04-24 17:38 ` [PATCH v4 06/10] drm/amdgpu: set FW parameters in v11_struct Shashank Sharma
2023-04-25 12:32 ` Christian König
2023-04-25 13:27 ` Shashank Sharma
2023-05-19 21:22 ` Alex Deucher
2023-05-22 9:06 ` Shashank Sharma
2023-04-24 17:38 ` [PATCH v4 07/10] drm/amdgpu: map usermode queue into MES Shashank Sharma
2023-04-25 12:34 ` Christian König
2023-04-25 13:31 ` Shashank Sharma
2023-04-25 15:33 ` Christian König
2023-04-25 16:56 ` Shashank Sharma
2023-05-19 21:22 ` Alex Deucher
2023-05-22 9:06 ` Shashank Sharma
2023-04-24 17:38 ` [PATCH v4 08/10] drm/amdgpu: map wptr BO into GART Shashank Sharma
2023-04-25 12:36 ` Christian König
2023-04-25 13:33 ` Shashank Sharma [this message]
2023-04-24 17:38 ` [PATCH v4 09/10] drm/amdgpu: generate doorbell index for userqueue Shashank Sharma
2023-04-25 12:38 ` Christian König
2023-04-25 13:34 ` Shashank Sharma
2023-04-24 17:38 ` [PATCH v4 10/10] drm/amdgpu: cleanup leftover queues Shashank Sharma
2023-04-25 12:40 ` Christian König
2023-04-25 13:34 ` 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=3da97c12-7ab6-8c16-00f0-359b73f6b0e9@amd.com \
--to=shashank.sharma@amd.com \
--cc=alexander.deucher@amd.com \
--cc=amd-gfx@lists.freedesktop.org \
--cc=arvind.yadav@amd.com \
--cc=christian.koenig@amd.com \
--cc=contactshashanksharma@gmail.com \
--cc=pierre-eric.pelloux-prayer@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