On 2023-03-29 12:04, Shashank Sharma wrote: > From: Shashank Sharma <contactshashanksharma@xxxxxxxxx> > > A Memory queue descriptor (MQD) of a userqueue defines it in the harware's > context. As MQD 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. > - Adds new functions to create and destroy MQD for GFX-GEN-11-IP > > V1: Worked on review comments from Alex: > - Make MQD functions GEN and IP specific > > V2: Worked on review comments from Alex: > - Reuse the existing adev->mqd[ip] for MQD creation > - Formatting and arrangement of code > > V3: > - Integration with doorbell manager > > Cc: Alex Deucher <alexander.deucher@xxxxxxx> > Cc: Christian Koenig <christian.koenig@xxxxxxx> > > Signed-off-by: Shashank Sharma <contactshashanksharma@xxxxxxxxx> > Signed-off-by: Arvind Yadav <arvind.yadav@xxxxxxx> > --- Don't break up the Cc tag list and the Sob tag list. Check out the following resources: https://www.kernel.org/doc/html/v4.12/process/5.Posting.html#patch-formatting-and-changelogs https://www.kernel.org/doc/html/v4.12/process/submitting-patches.html#the-canonical-patch-format > drivers/gpu/drm/amd/amdgpu/Makefile | 1 + > drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c | 21 +++++ > .../drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c | 84 +++++++++++++++++++ > .../gpu/drm/amd/include/amdgpu_userqueue.h | 7 ++ > 4 files changed, 113 insertions(+) > create mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c > > diff --git a/drivers/gpu/drm/amd/amdgpu/Makefile b/drivers/gpu/drm/amd/amdgpu/Makefile > index 2d90ba618e5d..2cc7897de7e6 100644 > --- a/drivers/gpu/drm/amd/amdgpu/Makefile > +++ b/drivers/gpu/drm/amd/amdgpu/Makefile > @@ -212,6 +212,7 @@ amdgpu-y += amdgpu_amdkfd.o > > # add usermode queue > amdgpu-y += amdgpu_userqueue.o > +amdgpu-y += amdgpu_userqueue_gfx_v11.o > > ifneq ($(CONFIG_HSA_AMD),) > AMDKFD_PATH := ../amdkfd > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c > index 353f57c5a772..052c2c1e8aed 100644 > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c > @@ -81,6 +81,12 @@ static int amdgpu_userqueue_create(struct drm_file *filp, union drm_amdgpu_userq > goto free_queue; > } > > + r = uq_mgr->userq_funcs[queue->queue_type]->mqd_create(uq_mgr, queue); > + if (r) { > + DRM_ERROR("Failed to create/map userqueue MQD\n"); > + goto free_queue; > + } > + > args->out.queue_id = queue->queue_id; > args->out.flags = 0; > mutex_unlock(&uq_mgr->userq_mutex); > @@ -105,6 +111,7 @@ static void amdgpu_userqueue_destroy(struct drm_file *filp, int queue_id) > } > > mutex_lock(&uq_mgr->userq_mutex); > + uq_mgr->userq_funcs[queue->queue_type]->mqd_destroy(uq_mgr, queue); > amdgpu_userqueue_free_index(uq_mgr, queue->queue_id); > mutex_unlock(&uq_mgr->userq_mutex); > kfree(queue); > @@ -135,6 +142,19 @@ int amdgpu_userq_ioctl(struct drm_device *dev, void *data, > return r; > } > > +extern const struct amdgpu_userq_funcs userq_gfx_v11_funcs; > + > +static void > +amdgpu_userqueue_setup_ip_funcs(struct amdgpu_userq_mgr *uq_mgr) > +{ > + int maj; > + struct amdgpu_device *adev = uq_mgr->adev; > + uint32_t version = adev->ip_versions[GC_HWIP][0]; > + > + maj = IP_VERSION_MAJ(version); > + if (maj == 11) > + uq_mgr->userq_funcs[AMDGPU_HW_IP_GFX] = &userq_gfx_v11_funcs; > +} > > int amdgpu_userq_mgr_init(struct amdgpu_userq_mgr *userq_mgr, struct amdgpu_device *adev) > { > @@ -142,6 +162,7 @@ int amdgpu_userq_mgr_init(struct amdgpu_userq_mgr *userq_mgr, struct amdgpu_devi > idr_init_base(&userq_mgr->userq_idr, 1); > userq_mgr->adev = adev; > > + amdgpu_userqueue_setup_ip_funcs(userq_mgr); > return 0; > } > > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c > new file mode 100644 > index 000000000000..12e1a785b65a > --- /dev/null > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c > @@ -0,0 +1,84 @@ > +/* > + * Copyright 2022 Advanced Micro Devices, Inc. > + * > + * Permission is hereby granted, free of charge, to any person obtaining a > + * copy of this software and associated documentation files (the "Software"), > + * to deal in the Software without restriction, including without limitation > + * the rights to use, copy, modify, merge, publish, distribute, sublicense, > + * and/or sell copies of the Software, and to permit persons to whom the > + * Software is furnished to do so, subject to the following conditions: > + * > + * The above copyright notice and this permission notice shall be included in > + * all copies or substantial portions of the Software. > + * > + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR > + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, > + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL > + * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR > + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, > + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR > + * OTHER DEALINGS IN THE SOFTWARE. > + * > + */ > +#include "amdgpu.h" > +#include "amdgpu_userqueue.h" > + > +static int > +amdgpu_userq_gfx_v11_mqd_create(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_usermode_queue *queue) > +{ > + struct amdgpu_device *adev = uq_mgr->adev; > + struct amdgpu_userq_ctx_space *mqd = &queue->mqd; > + struct amdgpu_mqd *gfx_v11_mqd = &adev->mqds[queue->queue_type]; > + int size = gfx_v11_mqd->mqd_size; > + int r; > + > + r = amdgpu_bo_create_kernel(adev, size, PAGE_SIZE, > + AMDGPU_GEM_DOMAIN_GTT, > + &mqd->obj, > + &mqd->gpu_addr, > + &mqd->cpu_ptr); > + if (r) { > + DRM_ERROR("Failed to allocate bo for userqueue (%d)", r); > + return r; > + } > + > + memset(mqd->cpu_ptr, 0, size); > + r = amdgpu_bo_reserve(mqd->obj, false); > + if (unlikely(r != 0)) { > + DRM_ERROR("Failed to reserve mqd for userqueue (%d)", r); > + goto free_mqd; > + } > + > + queue->userq_prop.use_doorbell = true; > + queue->userq_prop.mqd_gpu_addr = mqd->gpu_addr; > + r = gfx_v11_mqd->init_mqd(adev, (void *)mqd->cpu_ptr, &queue->userq_prop); > + amdgpu_bo_unreserve(mqd->obj); > + if (r) { > + DRM_ERROR("Failed to init MQD for queue\n"); > + goto free_mqd; > + } > + > + DRM_DEBUG_DRIVER("MQD for queue %d created\n", queue->queue_id); > + return 0; > + > +free_mqd: > + amdgpu_bo_free_kernel(&mqd->obj, > + &mqd->gpu_addr, > + &mqd->cpu_ptr); > + return r; > +} > + > +static void > +amdgpu_userq_gfx_v11_mqd_destroy(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_usermode_queue *queue) > +{ > + struct amdgpu_userq_ctx_space *mqd = &queue->mqd; > + > + amdgpu_bo_free_kernel(&mqd->obj, > + &mqd->gpu_addr, > + &mqd->cpu_ptr); > +} > + > +const struct amdgpu_userq_funcs userq_gfx_v11_funcs = { > + .mqd_create = amdgpu_userq_gfx_v11_mqd_create, > + .mqd_destroy = amdgpu_userq_gfx_v11_mqd_destroy, > +}; > diff --git a/drivers/gpu/drm/amd/include/amdgpu_userqueue.h b/drivers/gpu/drm/amd/include/amdgpu_userqueue.h > index 7625a862b1fc..2911c88d0fed 100644 > --- a/drivers/gpu/drm/amd/include/amdgpu_userqueue.h > +++ b/drivers/gpu/drm/amd/include/amdgpu_userqueue.h > @@ -27,6 +27,12 @@ > #include "amdgpu.h" > #define AMDGPU_MAX_USERQ 512 > > +struct amdgpu_userq_ctx_space { > + struct amdgpu_bo *obj; > + uint64_t gpu_addr; > + void *cpu_ptr; > +}; > + Code is very readable when the name colums are aligned: struct amdgpu_userq_ctx_space { struct amdgpu_bo *obj; uint64_t gpu_addr; void *cpu_ptr; }; And for the rest of your patches. Regards, Luben > struct amdgpu_usermode_queue { > int queue_id; > int queue_type; > @@ -35,6 +41,7 @@ struct amdgpu_usermode_queue { > struct amdgpu_vm *vm; > struct amdgpu_userq_mgr *userq_mgr; > struct amdgpu_mqd_prop userq_prop; > + struct amdgpu_userq_ctx_space mqd; > }; > > struct amdgpu_userq_funcs {