[PATCH v2 0/9]
Subsystems (3)
v2 cover [PATCH v2 0/9]
From: Shashank Sharma <[email protected]>
This patch series introduces AMDGPU usermode graphics queues. User queues is a method of GPU workload submission into the graphics hardware without any interaction with kernel/DRM schedulers. In this method, a userspace graphics application can create its own workqueue and submit it directly in the GPU HW.
The general idea of how this is supposed to work:
- The application creates the following GPU objetcs:
- A queue object to hold the workload packets.
- A read pointer object.
- A write pointer object.
- A doorbell page.
- Kernel picks any 32-bit offset in the doorbell page for this queue.
- The application uses the usermode_queue_create IOCTL introduced in this patch, by passing the the GPU addresses of these objects (read ptr, write ptr, queue base address and doorbell address)
- The kernel creates the queue and maps it in the HW.
- The application can start submitting the data in the queue as soon as the kernel IOCTL returns.
- Once the data is filled in the queue, the app must write the number of dwords in the doorbell offset, and the GPU will start fetching the data.
libDRM changes for this series and a sample DRM test program can be found in the MESA merge request here:
https://gitlab.freedesktop.org/mesa/drm/-/merge_requests/287
The RFC patch series and previous discussion can be seen here:
https://patchwork.freedesktop.org/series/112214/
This patch series needs the doorbell re-design changes, which are being reviewed here:
https://patchwork.freedesktop.org/series/113669/
In absence of the doorbell patches, this patch series uses a hack patch to test the functionality. That hack patch is also published here at the end of the series, just for reference.
Alex Deucher (1):
drm/amdgpu: UAPI for user queue management
Arvind Yadav (2):
drm/amdgpu: add new parameters in v11_struct
drm/amdgpu: map wptr BO into GART
Shashank Sharma (6):
drm/amdgpu: add usermode queue base code drm/amdgpu: add new IOCTL for usermode queue drm/amdgpu: create GFX-gen11 MQD for userqueue drm/amdgpu: create context space for usermode queue drm/amdgpu: map usermode queue into MES drm/amdgpu: create doorbell index of the userqueue
drivers/gpu/drm/amd/amdgpu/Makefile | 3 + drivers/gpu/drm/amd/amdgpu/amdgpu.h | 10 +- drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 2 + drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 6 + drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c | 325 ++++++++++++++++++ .../drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c | 230 +++++++++++++ .../gpu/drm/amd/include/amdgpu_userqueue.h | 66 ++++ drivers/gpu/drm/amd/include/v11_structs.h | 16 +- include/uapi/drm/amdgpu_drm.h | 55 +++ 9 files changed, 704 insertions(+), 9 deletions(-) create mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c create mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c create mode 100644 drivers/gpu/drm/amd/include/amdgpu_userqueue.h
Signature · 1 line
2.34.1
PATCH v2 1/9 drm/amdgpu: UAPI for user queue management
From: Alex Deucher <[email protected]>
This patch intorduces new UAPI/IOCTL for usermode graphics queue. The userspace app will fill this structure and request the graphics driver to add a graphics work queue for it. The output of this UAPI is a queue id.
This UAPI maps the queue into GPU, so the graphics app can start submitting work to the queue as soon as the call returns.
V2: Addressed review comments from Alex and Christian
- Make the doorbell offset's comment clearer
- Change the output parameter name to queue_id
--- include/uapi/drm/amdgpu_drm.h | 55 +++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+)
include/uapi/drm/amdgpu_drm.h +55 -0
@@ -54,6 +54,7 @@ extern "C" {#define DRM_AMDGPU_VM 0x13#define DRM_AMDGPU_FENCE_TO_HANDLE 0x14#define DRM_AMDGPU_SCHED 0x15 +#define DRM_AMDGPU_USERQ 0x16#define DRM_IOCTL_AMDGPU_GEM_CREATE DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_CREATE, union drm_amdgpu_gem_create)#define DRM_IOCTL_AMDGPU_GEM_MMAP DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_MMAP, union drm_amdgpu_gem_mmap)
@@ -71,6 +72,7 @@ extern "C" {#define DRM_IOCTL_AMDGPU_VM DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_VM, union drm_amdgpu_vm)#define DRM_IOCTL_AMDGPU_FENCE_TO_HANDLE DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_FENCE_TO_HANDLE, union drm_amdgpu_fence_to_handle)#define DRM_IOCTL_AMDGPU_SCHED DRM_IOW(DRM_COMMAND_BASE + DRM_AMDGPU_SCHED, union drm_amdgpu_sched) +#define DRM_IOCTL_AMDGPU_USERQ DRM_IOW(DRM_COMMAND_BASE + DRM_AMDGPU_USERQ, union drm_amdgpu_userq)/** * DOC: memory domains
@@ -302,6 +304,59 @@ union drm_amdgpu_ctx {union drm_amdgpu_ctx_out out; }; +/* user queue IOCTL */ +#define AMDGPU_USERQ_OP_CREATE 1 +#define AMDGPU_USERQ_OP_FREE 2 + +#define AMDGPU_USERQ_MQD_FLAGS_SECURE (1 << 0) +#define AMDGPU_USERQ_MQD_FLAGS_AQL (1 << 1) + +struct drm_amdgpu_userq_mqd { +/** Flags: AMDGPU_USERQ_MQD_FLAGS_* */ +__u32 flags; +/** IP type: AMDGPU_HW_IP_* */ +__u32 ip_type; +/** GEM object handle */ +__u32 doorbell_handle; +/** Doorbell's offset in the doorbell bo */ +__u32 doorbell_offset; +/** GPU virtual address of the queue */ +__u64 queue_va; +/** Size of the queue in bytes */ +__u64 queue_size; +/** GPU virtual address of the rptr */ +__u64 rptr_va; +/** GPU virtual address of the wptr */ +__u64 wptr_va; +/** GPU virtual address of the shadow context space */ +__u64 shadow_va; +}; + +struct drm_amdgpu_userq_in { +/** AMDGPU_USERQ_OP_* */ +__u32 op; +/** Flags */ +__u32 flags; +/** Queue handle to associate the queue free call with, +* unused for queue create calls */ +__u32 queue_id; +__u32 pad; +/** Queue descriptor */ +struct drm_amdgpu_userq_mqd mqd; +}; + +struct drm_amdgpu_userq_out { +/** Queue handle */ +__u32 queue_id; +/** Flags */ +__u32 flags; +}; + +union drm_amdgpu_userq { +struct drm_amdgpu_userq_in in; +struct drm_amdgpu_userq_out out; +}; +/* vm ioctl */ #define AMDGPU_VM_OP_RESERVE_VMID 1#define AMDGPU_VM_OP_UNRESERVE_VMID 2
Signature · 1 line
2.34.1
Re: [PATCH v2 1/9] drm/amdgpu: UAPI for user queue management
Am 15.02.23 um 19:43 schrieb Shashank Sharma:
Quoted 10 lines
From: Alex Deucher <[email protected]>
This patch intorduces new UAPI/IOCTL for usermode graphics queue. The userspace app will fill this structure and request the graphics driver to add a graphics work queue for it. The output of this UAPI is a queue id.
This UAPI maps the queue into GPU, so the graphics app can start submitting work to the queue as soon as the call returns.
Quoted 8 lines
V2: Addressed review comments from Alex and Christian
- Make the doorbell offset's comment clearer
- Change the output parameter name toqueue_idCc Alex Deucher <[email protected]>Cc Christian Koenig <[email protected]>Signed-off-by Alex Deucher <[email protected]>Signed-off-by Shashank Sharma <[email protected]>
Quoted 84 lines
--- include/uapi/drm/amdgpu_drm.h | 55 +++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+)include/uapi/drm/amdgpu_drm.h +55
-0@@ -54,6 +54,7 @@ extern "C" {#define DRM_AMDGPU_VM 0x13#define DRM_AMDGPU_FENCE_TO_HANDLE 0x14#define DRM_AMDGPU_SCHED 0x15 +#define DRM_AMDGPU_USERQ 0x16#define DRM_IOCTL_AMDGPU_GEM_CREATE DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_CREATE, union drm_amdgpu_gem_create)#define DRM_IOCTL_AMDGPU_GEM_MMAP DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_MMAP, union drm_amdgpu_gem_mmap)@@ -71,6 +72,7 @@ extern "C" {#define DRM_IOCTL_AMDGPU_VM DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_VM, union drm_amdgpu_vm)#define DRM_IOCTL_AMDGPU_FENCE_TO_HANDLE DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_FENCE_TO_HANDLE, union drm_amdgpu_fence_to_handle)#define DRM_IOCTL_AMDGPU_SCHED DRM_IOW(DRM_COMMAND_BASE + DRM_AMDGPU_SCHED, union drm_amdgpu_sched) +#define DRM_IOCTL_AMDGPU_USERQ DRM_IOW(DRM_COMMAND_BASE + DRM_AMDGPU_USERQ, union drm_amdgpu_userq)/** * DOC: memory domains @@ -302,6 +304,59 @@ union drm_amdgpu_ctx {union drm_amdgpu_ctx_out out; }; +/* user queue IOCTL */ +#define AMDGPU_USERQ_OP_CREATE 1 +#define AMDGPU_USERQ_OP_FREE 2 + +#define AMDGPU_USERQ_MQD_FLAGS_SECURE (1 << 0) +#define AMDGPU_USERQ_MQD_FLAGS_AQL (1 << 1) + +struct drm_amdgpu_userq_mqd { +/** Flags: AMDGPU_USERQ_MQD_FLAGS_* */ +__u32 flags; +/** IP type: AMDGPU_HW_IP_* */ +__u32 ip_type; +/** GEM object handle */ +__u32 doorbell_handle; +/** Doorbell's offset in the doorbell bo */ +__u32 doorbell_offset; +/** GPU virtual address of the queue */ +__u64 queue_va; +/** Size of the queue in bytes */ +__u64 queue_size; +/** GPU virtual address of the rptr */ +__u64 rptr_va; +/** GPU virtual address of the wptr */ +__u64 wptr_va; +/** GPU virtual address of the shadow context space */ +__u64 shadow_va; +}; + +struct drm_amdgpu_userq_in { +/** AMDGPU_USERQ_OP_* */ +__u32 op; +/** Flags */ +__u32 flags; +/** Queue handle to associate the queue free call with, +* unused for queue create calls */ +__u32 queue_id; +__u32 pad; +/** Queue descriptor */ +struct drm_amdgpu_userq_mqd mqd; +}; + +struct drm_amdgpu_userq_out { +/** Queue handle */ +__u32 queue_id; +/** Flags */ +__u32 flags; +}; + +union drm_amdgpu_userq { +struct drm_amdgpu_userq_in in; +struct drm_amdgpu_userq_out out; +}; +/* vm ioctl */ #define AMDGPU_VM_OP_RESERVE_VMID 1#define AMDGPU_VM_OP_UNRESERVE_VMID 2
Re: [PATCH v2 1/9] drm/amdgpu: UAPI for user queue management
In reply to Shashank SharmaQuoted 64 lines · Shashank Sharma
From: Alex Deucher <[email protected]>
This patch intorduces new UAPI/IOCTL for usermode graphics queue. The userspace app will fill this structure and request the graphics driver to add a graphics work queue for it. The output of this UAPI is a queue id.
This UAPI maps the queue into GPU, so the graphics app can start submitting work to the queue as soon as the call returns.
V2: Addressed review comments from Alex and Christian
- Make the doorbell offset's comment clearer
- Change the output parameter name toqueue_idCc Alex Deucher <[email protected]>Cc Christian Koenig <[email protected]>Signed-off-by Alex Deucher <[email protected]>Signed-off-by Shashank Sharma <[email protected]>--- include/uapi/drm/amdgpu_drm.h | 55 +++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+)include/uapi/drm/amdgpu_drm.h +19
-0@@ -54,6 +54,7 @@ extern "C" {#define DRM_AMDGPU_VM 0x13#define DRM_AMDGPU_FENCE_TO_HANDLE 0x14#define DRM_AMDGPU_SCHED 0x15 +#define DRM_AMDGPU_USERQ 0x16#define DRM_IOCTL_AMDGPU_GEM_CREATE DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_CREATE, union drm_amdgpu_gem_create)#define DRM_IOCTL_AMDGPU_GEM_MMAP DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_MMAP, union drm_amdgpu_gem_mmap)@@ -71,6 +72,7 @@ extern "C" {#define DRM_IOCTL_AMDGPU_VM DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_VM, union drm_amdgpu_vm)#define DRM_IOCTL_AMDGPU_FENCE_TO_HANDLE DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_FENCE_TO_HANDLE, union drm_amdgpu_fence_to_handle)#define DRM_IOCTL_AMDGPU_SCHED DRM_IOW(DRM_COMMAND_BASE + DRM_AMDGPU_SCHED, union drm_amdgpu_sched) +#define DRM_IOCTL_AMDGPU_USERQ DRM_IOW(DRM_COMMAND_BASE + DRM_AMDGPU_USERQ, union drm_amdgpu_userq)/** * DOC: memory domains @@ -302,6 +304,59 @@ union drm_amdgpu_ctx {union drm_amdgpu_ctx_out out; }; +/* user queue IOCTL */ +#define AMDGPU_USERQ_OP_CREATE 1 +#define AMDGPU_USERQ_OP_FREE 2 + +#define AMDGPU_USERQ_MQD_FLAGS_SECURE (1 << 0) +#define AMDGPU_USERQ_MQD_FLAGS_AQL (1 << 1) + +struct drm_amdgpu_userq_mqd { +/** Flags: AMDGPU_USERQ_MQD_FLAGS_* */ +__u32 flags; +/** IP type: AMDGPU_HW_IP_* */ +__u32 ip_type; +/** GEM object handle */ +__u32 doorbell_handle; +/** Doorbell's offset in the doorbell bo */ +__u32 doorbell_offset; +/** GPU virtual address of the queue */
include/uapi/drm/amdgpu_drm.h union drm_amdgpu_ctx { · line 333
Quoted 10 lines
include/uapi/drm/amdgpu_drm.h +10
-0+__u64 queue_va; +/** Size of the queue in bytes */ +__u64 queue_size; +/** GPU virtual address of the rptr */ +__u64 rptr_va; +/** GPU virtual address of the wptr */ +__u64 wptr_va; +/** GPU virtual address of the shadow context space */ +__u64 shadow_va; +};
We should test this with SDMA user queues as well to make sure we haven't missed anything that it needs. If sdma or vcn have major differences, we might want to consider making drm_amdgpu_userq_mqd a union.
Alex
Quoted 32 lines
include/uapi/drm/amdgpu_drm.h +26
-1+ +struct drm_amdgpu_userq_in { +/** AMDGPU_USERQ_OP_* */ +__u32 op; +/** Flags */ +__u32 flags; +/** Queue handle to associate the queue free call with, +* unused for queue create calls */ +__u32 queue_id; +__u32 pad; +/** Queue descriptor */ +struct drm_amdgpu_userq_mqd mqd; +}; + +struct drm_amdgpu_userq_out { +/** Queue handle */ +__u32 queue_id; +/** Flags */ +__u32 flags; +}; + +union drm_amdgpu_userq { +struct drm_amdgpu_userq_in in; +struct drm_amdgpu_userq_out out; +}; +/* vm ioctl */ #define AMDGPU_VM_OP_RESERVE_VMID 1#define AMDGPU_VM_OP_UNRESERVE_VMID 2 --2.34.1
PATCH v2 2/9 drm/amdgpu: add usermode queue base code
In reply to Shashank SharmaFrom: Shashank Sharma <[email protected]>
This patch adds skeleton code for amdgpu usermode queue. It contains:
- A new files with init functions of usermode queues.
- A queue context manager in driver private data.
V1: Worked on design review comments from RFC patch series:
(https://patchwork.freedesktop.org/series/112214/)
- Alex: Keep a list of queues, instead of single queue per process.
- Christian: Use the queue manager instead of global ptrs, Don't keep the queue structure in amdgpu_ctx
V2:
- Reformatted code, split the big patch into two
--- drivers/gpu/drm/amd/amdgpu/Makefile | 2 + drivers/gpu/drm/amd/amdgpu/amdgpu.h | 10 +++- drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 6 +++ drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c | 39 +++++++++++++++ .../gpu/drm/amd/include/amdgpu_userqueue.h | 49 +++++++++++++++++++ 6 files changed, 106 insertions(+), 1 deletion(-) create mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c create mode 100644 drivers/gpu/drm/amd/include/amdgpu_userqueue.h
drivers/gpu/drm/amd/amdgpu/Makefile +2 -0
@@ -210,6 +210,8 @@ amdgpu-y += \ # add amdkfd interfaces amdgpu-y += amdgpu_amdkfd.o +# add usermode queue +amdgpu-y += amdgpu_userqueue.o ifneq ($(CONFIG_HSA_AMD),) AMDKFD_PATH := ../amdkfd
drivers/gpu/drm/amd/amdgpu/amdgpu.h +9 -1
@@ -438,6 +438,14 @@ struct amdgpu_sa_manager {uint32_t align; }; +/* Gfx usermode queues */ +struct amdgpu_userq_mgr { +struct idr userq_idr; +struct mutex userq_mutex; +struct amdgpu_device *adev; +const struct amdgpu_userq_funcs *userq_funcs[AMDGPU_HW_IP_NUM ]; +}; +/* sub-allocation buffer */ struct amdgpu_sa_bo {struct list_head olist;
@@ -470,7 +478,6 @@ struct amdgpu_flip_work {bool async; }; -/* * file private structure */
@@ -482,6 +489,7 @@ struct amdgpu_fpriv {struct mutex bo_list_lock;struct idr bo_list_handles;struct amdgpu_ctx_mgr ctx_mgr; +struct amdgpu_userq_mgr userq_mgr; };int amdgpu_file_to_fpriv (struct file *filp,struct amdgpu_fpriv **fpriv);
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +1 -0
@@ -52,6 +52,7 @@#include "amdgpu_ras.h" #include "amdgpu_xgmi.h" #include "amdgpu_reset.h" +#include "amdgpu_userqueue.h" /* * KMS wrapper.
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +6 -0
@@ -43,6 +43,7 @@#include "amdgpu_gem.h" #include "amdgpu_display.h" #include "amdgpu_ras.h" +#include "amdgpu_userqueue.h" void amdgpu_unregister_gpu_instance (struct amdgpu_device *adev) {
@@ -1187,6 +1188,10 @@ int amdgpu_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv)amdgpu_ctx_mgr_init (&fpriv->ctx_mgr, adev); + r =amdgpu_userq_mgr_init (&fpriv->userq_mgr, adev); +if (r) +DRM_WARN ("Can't setup usermode queues, only legacy workload submission will work\n" ); + file_priv->driver_priv = fpriv; goto out_suspend;
@@ -1254,6 +1259,7 @@ void amdgpu_driver_postclose_kms(struct drm_device *dev,amdgpu_ctx_mgr_fini (&fpriv->ctx_mgr);amdgpu_vm_fini (adev, &fpriv->vm); +amdgpu_userq_mgr_fini (&fpriv->userq_mgr);if (pasid)amdgpu_pasid_free_delayed (pd->tbo.base.resv, pasid);
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c new file +39 -0
@@ -0,0 +1,39 @@ +/* +* 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" + +int amdgpu_userq_mgr_init (struct amdgpu_userq_mgr *userq_mgr,struct amdgpu_device *adev) +{ +mutex_init (&userq_mgr->userq_mutex); +idr_init_base (&userq_mgr->userq_idr,1 ); + userq_mgr->adev = adev; + +return 0 ; +} + +void amdgpu_userq_mgr_fini (struct amdgpu_userq_mgr *userq_mgr) +{ +idr_destroy (&userq_mgr->userq_idr); +mutex_destroy (&userq_mgr->userq_mutex); +}
drivers/gpu/drm/amd/include/amdgpu_userqueue.h new file +49 -0
49 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH v2 3/9 drm/amdgpu: add new IOCTL for usermode queue
In reply to Shashank SharmaFrom: Shashank Sharma <[email protected]>
This patch adds:
- A new IOCTL function to create and destroy
- A new structure to keep all the user queue data in one place.
- A function to generate unique index for the queue.
V1: Worked on review comments from RFC patch series:
- Alex: Keep a list of queues, instead of single queue per process.
- Christian: Use the queue manager instead of global ptrs, Don't keep the queue structure in amdgpu_ctx
V2: Worked on review comments:
- Christian:
- Formatting of text
- There is no need for queuing of userqueues, with idr in place
- Alex:
- Remove use_doorbell, its unnecessary
- Reuse amdgpu_mqd_props for saving mqd fields
- Code formatting and re-arrangement
--- drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c | 114 ++++++++++++++++++ .../gpu/drm/amd/include/amdgpu_userqueue.h | 2 + 3 files changed, 117 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +1 -0
@@ -2749,6 +2749,7 @@ const struct drm_ioctl_desc amdgpu_ioctls_kms[] = {DRM_IOCTL_DEF_DRV (AMDGPU_GEM_VA , amdgpu_gem_va_ioctl,DRM_AUTH |DRM_RENDER_ALLOW ),DRM_IOCTL_DEF_DRV (AMDGPU_GEM_OP , amdgpu_gem_op_ioctl,DRM_AUTH |DRM_RENDER_ALLOW ),DRM_IOCTL_DEF_DRV (AMDGPU_GEM_USERPTR , amdgpu_gem_userptr_ioctl,DRM_AUTH |DRM_RENDER_ALLOW ), + DRM_IOCTL_DEF_DRV(AMDGPU_USERQ, amdgpu_userq_ioctl, DRM_AUTH|DRM_RENDER_ALLOW), }; static const struct drm_driver amdgpu_kms_driver = {
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +114 -0
120 lines not on this page · raw message
drivers/gpu/drm/amd/include/amdgpu_userqueue.h +2 -0
@@ -42,6 +42,8 @@ struct amdgpu_userq_funcs {void (*mqd_destroy)(struct amdgpu_userq_mgr *,struct amdgpu_usermode_queue *); }; +int amdgpu_userq_ioctl (struct drm_device *dev,void *data,struct drm_file *filp); +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);
Signature · 1 line
2.34.1
Christian König
maintainerRe: [PATCH v2 3/9] drm/amdgpu: add new IOCTL for usermode queue
Am 15.02.23 um 19:43 schrieb Shashank Sharma:
Quoted 101 lines
From: Shashank Sharma <[email protected]>
This patch adds:
- A new IOCTL function to create and destroy
- A new structure to keep all the user queue data in one place.
- A function to generate unique index for the queue.V1: Worked on review comments from RFC patch series:
- Alex: Keep a list of queues, instead of single queue per process.
- Christian: Use the queue manager instead of global ptrs, Don't keep the queue structure inamdgpu_ctxV2: Worked on review comments:
- Christian:
- Formatting of text
- There is no need for queuing of userqueues, with idr in place
- Alex:
- Removeuse_doorbell, its unnecessary
- Reuseamdgpu_mqd_propsfor saving mqd fields- Code formatting and re-arrangement
Cc Alex Deucher <[email protected]>Cc Christian Koenig <[email protected]>Signed-off-by Shashank Sharma <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c | 114 ++++++++++++++++++ .../gpu/drm/amd/include/amdgpu_userqueue.h | 2 + 3 files changed, 117 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +1
-0@@ -2749,6 +2749,7 @@ const struct drm_ioctl_desc amdgpu_ioctls_kms[] = {DRM_IOCTL_DEF_DRV (AMDGPU_GEM_VA , amdgpu_gem_va_ioctl,DRM_AUTH |DRM_RENDER_ALLOW ),DRM_IOCTL_DEF_DRV (AMDGPU_GEM_OP , amdgpu_gem_op_ioctl,DRM_AUTH |DRM_RENDER_ALLOW ),DRM_IOCTL_DEF_DRV (AMDGPU_GEM_USERPTR , amdgpu_gem_userptr_ioctl,DRM_AUTH |DRM_RENDER_ALLOW ), + DRM_IOCTL_DEF_DRV(AMDGPU_USERQ, amdgpu_userq_ioctl, DRM_AUTH|DRM_RENDER_ALLOW), }; static const struct drm_driver amdgpu_kms_driver = {drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +50
-0@@ -22,6 +22,120 @@*/ #include "amdgpu.h" +#include "amdgpu_vm.h" +#include "amdgpu_userqueue.h" + +static inline int +amdgpu_userqueue_index (struct amdgpu_userq_mgr *uq_mgr,struct amdgpu_usermode_queue *queue) +{ +return idr_alloc (&uq_mgr->userq_idr, queue,1 ,AMDGPU_MAX_USERQ ,GFP_KERNEL ); +} + +static inline void +amdgpu_userqueue_free_index (struct amdgpu_userq_mgr *uq_mgr,int queue_id) +{ +idr_remove (&uq_mgr->userq_idr, queue_id); +} + +static struct amdgpu_usermode_queue * +amdgpu_userqueue_find (struct amdgpu_userq_mgr *uq_mgr,int qid) +{ +return idr_find (&uq_mgr->userq_idr, qid); +} + +static int amdgpu_userqueue_create (struct drm_file *filp,union drm_amdgpu_userq *args) +{ +struct amdgpu_usermode_queue *queue; +struct amdgpu_fpriv *fpriv = filp->driver_priv; +struct amdgpu_userq_mgr *uq_mgr = &fpriv->userq_mgr; +struct drm_amdgpu_userq_mqd *mqd_in = &args->in.mqd; +int r; + +/* Do we have support userqueues for this IP ? */ +if (!uq_mgr->userq_funcs[mqd_in->ip_type]) { +DRM_ERROR ("GFX User queues not supported for this IP: %d\n" , mqd_in->ip_type); +return -EINVAL ; + } + + queue =kzalloc (sizeof (struct amdgpu_usermode_queue ),GFP_KERNEL ); +if (!queue) { +DRM_ERROR ("Failed to allocate memory for queue\n" ); +return -ENOMEM ; + } + +mutex_lock (&uq_mgr->userq_mutex); + queue->userq_prop.wptr_gpu_addr = mqd_in->wptr_va; + queue->userq_prop.rptr_gpu_addr = mqd_in->rptr_va; + queue->userq_prop.queue_size = mqd_in->queue_size; + queue->userq_prop.hqd_base_gpu_addr = mqd_in->queue_va; + queue->userq_prop.queue_size = mqd_in->queue_size; + + queue->doorbell_handle = mqd_in->doorbell_handle; + queue->queue_type = mqd_in->ip_type;
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c line 84
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +9
-0+ queue->flags = mqd_in->flags; + queue->vm = &fpriv->vm; + queue->shadow_ctx_gpu_addr = mqd_in->shadow_va; + queue->queue_id =amdgpu_userqueue_index (uq_mgr, queue); +if (queue->queue_id <0 ) { +DRM_ERROR ("Failed to allocate a queue id\n" ); + r = queue->queue_id; + goto free_queue; + }
Don't keep the assigned id inside the queue structure. This is only used as handle between userspace and kernel and not useful inside the kernel otherwise.
This prevents people from using it in hw communication.
Apart from that this looks good to me,
Christian.
Quoted 71 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +55
-0+ + args->out.queue_id = queue->queue_id; + args->out.flags =0 ; +mutex_unlock (&uq_mgr->userq_mutex); +return 0 ; + +free_queue: +mutex_unlock (&uq_mgr->userq_mutex); +kfree (queue); +return r; +} + +static void amdgpu_userqueue_destroy (struct drm_file *filp,int queue_id) +{ +struct amdgpu_fpriv *fpriv = filp->driver_priv; +struct amdgpu_userq_mgr *uq_mgr = &fpriv->userq_mgr; +struct amdgpu_usermode_queue *queue; + + queue =amdgpu_userqueue_find (uq_mgr, queue_id); +if (!queue) { +DRM_DEBUG_DRIVER ("Invalid queue id to destroy\n" ); +return ; + } + +mutex_lock (&uq_mgr->userq_mutex); +amdgpu_userqueue_free_index (uq_mgr, queue->queue_id); +mutex_unlock (&uq_mgr->userq_mutex); +kfree (queue); +} + +int amdgpu_userq_ioctl (struct drm_device *dev,void *data, +struct drm_file *filp) +{ +union drm_amdgpu_userq *args = data; +int r =0 ; + +switch (args->in.op) { +case AMDGPU_USERQ_OP_CREATE : + r =amdgpu_userqueue_create (filp, args); +if (r) +DRM_ERROR ("Failed to create usermode queue\n" ); +break ; + +case AMDGPU_USERQ_OP_FREE : +amdgpu_userqueue_destroy (filp, args->in.queue_id); +break ; + +default : +DRM_ERROR ("Invalid user queue op specified: %d\n" , args->in.op); +return -EINVAL ; + } + +return r; +} +int amdgpu_userq_mgr_init (struct amdgpu_userq_mgr *userq_mgr,struct amdgpu_device *adev){drivers/gpu/drm/amd/include/amdgpu_userqueue.h +2
-0@@ -42,6 +42,8 @@ struct amdgpu_userq_funcs {void (*mqd_destroy)(struct amdgpu_userq_mgr *,struct amdgpu_usermode_queue *); }; +int amdgpu_userq_ioctl (struct drm_device *dev,void *data,struct drm_file *filp); +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);
Re: [PATCH v2 3/9] drm/amdgpu: add new IOCTL for usermode queue
Hey Christian,
Quoted 118 lines · Christian König
Am 15.02.23 um 19:43 schrieb Shashank Sharma:
Quoted 106 lines
From: Shashank Sharma <[email protected]>
This patch adds:
- A new IOCTL function to create and destroy
- A new structure to keep all the user queue data in one place.
- A function to generate unique index for the queue.V1: Worked on review comments from RFC patch series:
- Alex: Keep a list of queues, instead of single queue per process.
- Christian: Use the queue manager instead of global ptrs, Don't keep the queue structure inamdgpu_ctxV2: Worked on review comments:
- Christian:
- Formatting of text
- There is no need for queuing of userqueues, with idr in place
- Alex:
- Removeuse_doorbell, its unnecessary
- Reuseamdgpu_mqd_propsfor saving mqd fields- Code formatting and re-arrangement
Cc Alex Deucher <[email protected]>Cc Christian Koenig <[email protected]>Signed-off-by Shashank Sharma <[email protected]>---
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 1 +drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c| 114 ++++++++++++++++++ .../gpu/drm/amd/include/amdgpu_userqueue.h | 2 +3 files changed, 117 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +1
-0@@ -2749,6 +2749,7 @@ const struct drm_ioctl_desc amdgpu_ioctls_kms[] = { DRM_IOCTL_DEF_DRV(AMDGPU_GEM_VA, amdgpu_gem_va_ioctl, DRM_AUTH|DRM_RENDER_ALLOW), DRM_IOCTL_DEF_DRV(AMDGPU_GEM_OP, amdgpu_gem_op_ioctl, DRM_AUTH|DRM_RENDER_ALLOW), DRM_IOCTL_DEF_DRV(AMDGPU_GEM_USERPTR, amdgpu_gem_userptr_ioctl, DRM_AUTH|DRM_RENDER_ALLOW), + DRM_IOCTL_DEF_DRV(AMDGPU_USERQ, amdgpu_userq_ioctl,DRM_AUTH |DRM_RENDER_ALLOW ), };static const struct
drm_driveramdgpu_kms_driver= {drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +32
-0@@ -22,6 +22,120 @@*/ #include "amdgpu.h" +#include "amdgpu_vm.h" +#include "amdgpu_userqueue.h" + +static inline int +amdgpu_userqueue_index (struct amdgpu_userq_mgr *uq_mgr,struct amdgpu_usermode_queue *queue) +{ + return idr_alloc(&uq_mgr->userq_idr, queue, 1, AMDGPU_MAX_USERQ,GFP_KERNEL ); +} + +static inline void +amdgpu_userqueue_free_index (struct amdgpu_userq_mgr *uq_mgr,int queue_id) +{ + idr_remove(&uq_mgr->userq_idr, queue_id); +} + +static struct amdgpu_usermode_queue * +amdgpu_userqueue_find (struct amdgpu_userq_mgr *uq_mgr,int qid) +{ + return idr_find(&uq_mgr->userq_idr, qid); +} + +static int amdgpu_userqueue_create (struct drm_file *filp,union drm_amdgpu_userq *args) +{ + struct amdgpu_usermode_queue *queue; + struct amdgpu_fpriv *fpriv = filp->driver_priv; + struct amdgpu_userq_mgr *uq_mgr = &fpriv->userq_mgr; + struct drm_amdgpu_userq_mqd *mqd_in = &args->in.mqd; + int r; + + /* Do we have support userqueues for this IP ? */ + if (!uq_mgr->userq_funcs[mqd_in->ip_type]) { + DRM_ERROR("GFX User queues not supported for this IP: %d\n",
mqd_in->ip_type);
+ return-EINVAL;
+ }drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +16
-0+ + queue = kzalloc(sizeof(struct amdgpu_usermode_queue), GFP_KERNEL); + if (!queue) { + DRM_ERROR("Failed to allocate memory for queue\n"); + return -ENOMEM; + } + + mutex_lock(&uq_mgr->userq_mutex); + queue->userq_prop.wptr_gpu_addr = mqd_in->wptr_va; + queue->userq_prop.rptr_gpu_addr = mqd_in->rptr_va; + queue->userq_prop.queue_size = mqd_in->queue_size; + queue->userq_prop.hqd_base_gpu_addr = mqd_in->queue_va; + queue->userq_prop.queue_size = mqd_in->queue_size; + + queue->doorbell_handle = mqd_in->doorbell_handle; + queue->queue_type = mqd_in->ip_type;drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +9
-0+ queue->flags = mqd_in->flags; + queue->vm = &fpriv->vm; + queue->shadow_ctx_gpu_addr = mqd_in->shadow_va; + queue->queue_id = amdgpu_userqueue_index(uq_mgr, queue); + if (queue->queue_id < 0) { + DRM_ERROR("Failed to allocate a queue id\n"); + r = queue->queue_id; + goto free_queue; + }
Quoted 3 lines
Don't keep the assigned id inside the queue structure. This is only used as handle between userspace and kernel and not useful inside the kernel otherwise.
This prevents people from using it in hw communication.
Noted,
- Shashank
Quoted 75 lines
Apart from that this looks good to me,
Christian.Quoted 70 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +13
-0+ + args->out.queue_id = queue->queue_id; + args->out.flags = 0; + mutex_unlock(&uq_mgr->userq_mutex); + return 0; + +free_queue: + mutex_unlock(&uq_mgr->userq_mutex); + kfree(queue); + return r; +} + +static void amdgpu_userqueue_destroy(struct drm_file *filp, int
queue_id)drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +36
-0+{ + struct amdgpu_fpriv *fpriv = filp->driver_priv; + struct amdgpu_userq_mgr *uq_mgr = &fpriv->userq_mgr; + struct amdgpu_usermode_queue *queue; + + queue = amdgpu_userqueue_find(uq_mgr, queue_id); + if (!queue) { + DRM_DEBUG_DRIVER("Invalid queue id to destroy\n"); + return; + } + + mutex_lock(&uq_mgr->userq_mutex); + amdgpu_userqueue_free_index(uq_mgr, queue->queue_id); + mutex_unlock(&uq_mgr->userq_mutex); + kfree(queue); +} + +int amdgpu_userq_ioctl (struct drm_device *dev,void *data, + struct drm_file *filp) +{ + union drm_amdgpu_userq *args = data; + int r = 0; + + switch (args->in.op) { + case AMDGPU_USERQ_OP_CREATE: + r = amdgpu_userqueue_create(filp, args); + if (r) + DRM_ERROR("Failed to create usermode queue\n"); + break; + + case AMDGPU_USERQ_OP_FREE: + amdgpu_userqueue_destroy(filp, args->in.queue_id); + break; + + default: + DRM_ERROR("Invalid user queue op specified: %d\n",
args->in.op);
+ return-EINVAL;
+ }drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +4
-0+ + return r; +} +int
amdgpu_userq_mgr_init(struct amdgpu_userq_mgr *userq_mgr, struct amdgpu_device *adev){drivers/gpu/drm/amd/include/amdgpu_userqueue.h +1
-0@@ -42,6 +42,8 @@ struct amdgpu_userq_funcs { void (*mqd_destroy)(struct amdgpu_userq_mgr *, struct amdgpu_usermode_queue *); }; +int amdgpu_userq_ioctl(struct drm_device *dev, void *data, struct drm_file *filp); + 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);
PATCH v2 4/9 drm/amdgpu: create GFX-gen11 MQD for userqueue
In reply to Shashank SharmaFrom: Shashank Sharma <[email protected]>
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
--- 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
drivers/gpu/drm/amd/amdgpu/Makefile +1 -0
@@ -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
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +21 -0
@@ -82,6 +82,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);
@@ -106,6 +112,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);
@@ -136,6 +143,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) {
@@ -143,6 +163,7 @@ int amdgpu_userq_mgr_init(struct amdgpu_userq_mgr *userq_mgr, struct amdgpu_deviidr_init_base (&userq_mgr->userq_idr,1 ); userq_mgr->adev = adev; +amdgpu_userqueue_setup_ip_funcs (userq_mgr);return 0 ; }
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c new file +84 -0
84 lines not on this page · raw message
drivers/gpu/drm/amd/include/amdgpu_userqueue.h +7 -0
@@ -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; +}; +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 {
Signature · 1 line
2.34.1
Christian König
maintainerRe: [PATCH v2 4/9] drm/amdgpu: create GFX-gen11 MQD for userqueue
Am 15.02.23 um 19:43 schrieb Shashank Sharma:
Quoted 130 lines
From: Shashank Sharma <[email protected]>
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-IPV1: Worked on review comments from Alex:
- Make MQD functions GEN and IP specificV2: Worked on review comments from Alex:
- Reuse the existing adev->mqd[ip] for MQD creation
- Formatting and arrangement of codeCc Alex Deucher <[email protected]>Cc Christian Koenig <[email protected]>Signed-off-by Shashank Sharma <[email protected]>Signed-off-by Arvind Yadav <[email protected]>--- 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.cdrivers/gpu/drm/amd/amdgpu/Makefile +1
-0@@ -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 := ../amdkfddrivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +21
-0@@ -82,6 +82,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);@@ -106,6 +112,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);@@ -136,6 +143,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) {@@ -143,6 +163,7 @@ int amdgpu_userq_mgr_init(struct amdgpu_userq_mgr *userq_mgr, struct amdgpu_deviidr_init_base (&userq_mgr->userq_idr,1 ); userq_mgr->adev = adev; +amdgpu_userqueue_setup_ip_funcs (userq_mgr);return 0 ; }drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c new file +29
-0@@ -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;
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c line 39
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c new file +10
-0+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);
Don't use amdgpu_bo_create_kernel() for any memory allocation in your patches. This allocation is on behalves of userspace and can't use this function.
What we need is an eviction fence similar to what the KFD has implemented.
Regards,
Christian.
Quoted 70 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c new file +45
-0+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, +};drivers/gpu/drm/amd/include/amdgpu_userqueue.h +7
-0@@ -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; +}; +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 {
Re: [PATCH v2 4/9] drm/amdgpu: create GFX-gen11 MQD for userqueue
Quoted 153 lines · Christian König
Am 15.02.23 um 19:43 schrieb Shashank Sharma:
Quoted 139 lines
From: Shashank Sharma <[email protected]>
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-IPV1: Worked on review comments from Alex:
- Make MQD functions GEN and IP specificV2: Worked on review comments from Alex:
- Reuse the existing adev->mqd[ip] for MQD creation
- Formatting and arrangement of codeCc Alex Deucher <[email protected]>Cc Christian Koenig <[email protected]>Signed-off-by Shashank Sharma <[email protected]>Signed-off-by Arvind Yadav <[email protected]>---
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.cdrivers/gpu/drm/amd/amdgpu/Makefile +0
-0@@ -212,6 +212,7 @@ amdgpu-y += amdgpu_amdkfd.o # add usermode queueamdgpu-y += amdgpu_userqueue.o
+amdgpu-y += amdgpu_userqueue_gfx_v11.o
ifneq ($(CONFIG_HSA_AMD),)
AMDKFD_PATH:= ../amdkfddrivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +5
-0@@ -82,6 +82,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);drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +13
-0@@ -106,6 +112,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);@@ -136,6 +143,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) {@@ -143,6 +163,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.cb/drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.cnew file mode 100644
index 000000000000..12e1a785b65adrivers/gpu/drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c new file +4
-0@@ -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.
+ *
+ */drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c new file +5
-0+#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)drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c new file +2
-0+{ + struct amdgpu_device *adev = uq_mgr->adev;drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c line 39
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c new file +10
-0+ 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);Don't use
amdgpu_bo_create_kernel()for any memory allocation in your patches. This allocation is on behalves of userspace and can't use this function.
Quoted 1 line
What we need is an eviction fence similar to what the KFD has implemented.
I want to discuss more on this, why are you considering this allocation on behalf of user-space ?
MQD will be accessed and used only by Kernel and FW, userspace just requests us to create and map
queues with some specifications, it doesn't know anything about MQD. All userspace accessible allocations
(Queue, WPTR and RPTR) are done in userspace.
- Shashank
Quoted 75 lines
Regards,
Christian.Quoted 70 lines
+ if (r) {
+DRM_ERROR("Failed to allocate bo for userqueue (%d)", r); + return r;
+ }drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c new file +11
-0+ + 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"); + gotofree_mqd;
+ }drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c new file +13
-0+ + 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)drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c new file +12
-0+{ + 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, +};drivers/gpu/drm/amd/include/amdgpu_userqueue.h +6
-0@@ -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; +}; + 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 {
PATCH v2 5/9 drm/amdgpu: create context space for usermode queue
In reply to Shashank SharmaFrom: Shashank Sharma <[email protected]>
The FW expects us to allocate atleast one page as context space to process gang, process, shadow, GDS and FW related work. This patch creates a joint object for the same, and calculates GPU space offsets for each of these spaces.
V1: Addressed review comments on RFC patch:
Alex: Make this function IP specific
V2: Addressed review comments from Christian
- Allocate only one object for total FW space, and calculate offsets for each of these objects.
--- .../drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c | 60 ++++++++++++++++++- .../gpu/drm/amd/include/amdgpu_userqueue.h | 7 +++ 2 files changed, 65 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c +58 -2
@@ -23,6 +23,51 @@#include "amdgpu.h" #include "amdgpu_userqueue.h" +#define AMDGPU_USERQ_PROC_CTX_SZ PAGE_SIZE +#define AMDGPU_USERQ_GANG_CTX_SZ PAGE_SIZE +#define AMDGPU_USERQ_FW_CTX_SZ PAGE_SIZE +#define AMDGPU_USERQ_GDS_CTX_SZ PAGE_SIZE + +static int amdgpu_userq_gfx_v11_create_ctx_space (struct amdgpu_userq_mgr *uq_mgr, +struct amdgpu_usermode_queue *queue) +{ +struct amdgpu_device *adev = uq_mgr->adev; +struct amdgpu_userq_ctx_space *ctx = &queue->fw_space; +int r, size; + +/* +* The FW expects atleast one page space allocated for +* process ctx, gang ctx, gds ctx, fw ctx and shadow ctx each. +*/ + size =AMDGPU_USERQ_PROC_CTX_SZ +AMDGPU_USERQ_GANG_CTX_SZ + +AMDGPU_USERQ_FW_CTX_SZ +AMDGPU_USERQ_GDS_CTX_SZ ; + r =amdgpu_bo_create_kernel (adev, size,PAGE_SIZE , +AMDGPU_GEM_DOMAIN_GTT , + &ctx->obj, + &ctx->gpu_addr, + &ctx->cpu_ptr); +if (r) { +DRM_ERROR ("Failed to allocate ctx space bo for userqueue, err:%d\n" , r); +return r; + } + + queue->proc_ctx_gpu_addr = ctx->gpu_addr; + queue->gang_ctx_gpu_addr = queue->proc_ctx_gpu_addr +AMDGPU_USERQ_PROC_CTX_SZ ; + queue->fw_ctx_gpu_addr = queue->gang_ctx_gpu_addr +AMDGPU_USERQ_GANG_CTX_SZ ; + queue->gds_ctx_gpu_addr = queue->fw_ctx_gpu_addr +AMDGPU_USERQ_FW_CTX_SZ ; +return 0 ; +} + +static void amdgpu_userq_gfx_v11_destroy_ctx_space (struct amdgpu_userq_mgr *uq_mgr, +struct amdgpu_usermode_queue *queue) +{ +struct amdgpu_userq_ctx_space *ctx = &queue->fw_space; + +amdgpu_bo_free_kernel (&ctx->obj, + &ctx->gpu_addr, + &ctx->cpu_ptr); +} +static int amdgpu_userq_gfx_v11_mqd_create (struct amdgpu_userq_mgr *uq_mgr,struct amdgpu_usermode_queue *queue) {
@@ -43,10 +88,17 @@ amdgpu_userq_gfx_v11_mqd_create(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_u }memset (mqd->cpu_ptr,0 , size); + + r =amdgpu_userq_gfx_v11_create_ctx_space (uq_mgr, queue); +if (r) { +DRM_ERROR ("Failed to create CTX space for userqueue (%d)\n" , r); + goto free_mqd; + } + r =amdgpu_bo_reserve (mqd->obj, false);if (unlikely (r !=0 )) {DRM_ERROR ("Failed to reserve mqd for userqueue (%d)" , r); - goto free_mqd; + goto free_ctx; } queue->userq_prop.use_doorbell = true;
@@ -55,12 +107,15 @@ amdgpu_userq_gfx_v11_mqd_create(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_uamdgpu_bo_unreserve (mqd->obj);if (r) {DRM_ERROR ("Failed to init MQD for queue\n" ); - goto free_mqd; + goto free_ctx; }DRM_DEBUG_DRIVER ("MQD for queue %d created\n" , queue->queue_id);return 0 ; +free_ctx: +amdgpu_userq_gfx_v11_destroy_ctx_space (uq_mgr, queue); + free_mqd: amdgpu_bo_free_kernel(&mqd->obj, &mqd->gpu_addr,
@@ -73,6 +128,7 @@ amdgpu_userq_gfx_v11_mqd_destroy(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_ {struct amdgpu_userq_ctx_space *mqd = &queue->mqd; +amdgpu_userq_gfx_v11_destroy_ctx_space (uq_mgr, queue);amdgpu_bo_free_kernel (&mqd->obj, &mqd->gpu_addr, &mqd->cpu_ptr);
drivers/gpu/drm/amd/include/amdgpu_userqueue.h +7 -0
@@ -38,10 +38,17 @@ struct amdgpu_usermode_queue {int queue_type;uint64_t flags;uint64_t doorbell_handle; +uint64_t proc_ctx_gpu_addr; +uint64_t gang_ctx_gpu_addr; +uint64_t gds_ctx_gpu_addr; +uint64_t fw_ctx_gpu_addr; +uint64_t shadow_ctx_gpu_addr; +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_ctx_space fw_space; };struct amdgpu_userq_funcs {
Signature · 1 line
2.34.1
PATCH v2 6/9 drm/amdgpu: add new parameters in v11_struct
In reply to Shashank SharmaFrom: Arvind Yadav <[email protected]>
This patch:
- adds some new parameters defined for the gfx usermode queues use cases in the v11_mqd_struct.
- sets those parametes with the respective allocated gpu context space addresses.
--- .../drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c | 21 ++++++++++++++++++- drivers/gpu/drm/amd/include/v11_structs.h | 16 +++++++------- 2 files changed, 28 insertions(+), 9 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c +20 -1
@@ -22,6 +22,7 @@*/ #include "amdgpu.h" #include "amdgpu_userqueue.h" +#include "v11_structs.h" #define AMDGPU_USERQ_PROC_CTX_SZ PAGE_SIZE#define AMDGPU_USERQ_GANG_CTX_SZ PAGE_SIZE
@@ -68,6 +69,22 @@ static void amdgpu_userq_gfx_v11_destroy_ctx_space(struct amdgpu_userq_mgr *uq_m &ctx->cpu_ptr); } +static void +amdgpu_userq_set_ctx_space (struct amdgpu_userq_mgr *uq_mgr, +struct amdgpu_usermode_queue *queue) +{ +struct v11_gfx_mqd *mqd = queue->mqd.cpu_ptr; + + mqd->shadow_base_lo = queue->shadow_ctx_gpu_addr &0xfffffffc ; + mqd->shadow_base_hi =upper_32_bits (queue->shadow_ctx_gpu_addr); + + mqd->gds_bkup_base_lo = queue->gds_ctx_gpu_addr &0xfffffffc ; + mqd->gds_bkup_base_hi =upper_32_bits (queue->gds_ctx_gpu_addr); + + mqd->fw_work_area_base_lo = queue->fw_ctx_gpu_addr &0xfffffffc ; + mqd->fw_work_area_base_lo =upper_32_bits (queue->fw_ctx_gpu_addr); +} +static int amdgpu_userq_gfx_v11_mqd_create (struct amdgpu_userq_mgr *uq_mgr,struct amdgpu_usermode_queue *queue) {
@@ -104,12 +121,14 @@ amdgpu_userq_gfx_v11_mqd_create(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_u 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) { +amdgpu_bo_unreserve (mqd->obj);DRM_ERROR ("Failed to init MQD for queue\n" ); goto free_ctx; } +amdgpu_userq_set_ctx_space (uq_mgr, queue); +amdgpu_bo_unreserve (mqd->obj);DRM_DEBUG_DRIVER ("MQD for queue %d created\n" , queue->queue_id);return 0 ;
drivers/gpu/drm/amd/include/v11_structs.h +8 -8
@@ -25,14 +25,14 @@#define V11_STRUCTS_H_ struct v11_gfx_mqd { -uint32_t reserved_0;// offset: 0 (0x0) -uint32_t reserved_1;// offset: 1 (0x1) -uint32_t reserved_2;// offset: 2 (0x2) -uint32_t reserved_3;// offset: 3 (0x3) -uint32_t reserved_4;// offset: 4 (0x4) -uint32_t reserved_5;// offset: 5 (0x5) -uint32_t reserved_6;// offset: 6 (0x6) -uint32_t reserved_7;// offset: 7 (0x7) +uint32_t shadow_base_lo;// offset: 0 (0x0) +uint32_t shadow_base_hi;// offset: 1 (0x1) +uint32_t gds_bkup_base_lo;// offset: 2 (0x2) +uint32_t gds_bkup_base_hi;// offset: 3 (0x3) +uint32_t fw_work_area_base_lo;// offset: 4 (0x4) +uint32_t fw_work_area_base_hi;// offset: 5 (0x5) +uint32_t shadow_initialized;// offset: 6 (0x6) +uint32_t ib_vmid;// offset: 7 (0x7) uint32_t reserved_8;// offset: 8 (0x8) uint32_t reserved_9;// offset: 9 (0x9) uint32_t reserved_10;// offset: 10 (0xA)
Signature · 1 line
2.34.1
PATCH v2 7/9 drm/amdgpu: map usermode queue into MES
In reply to Shashank SharmaFrom: Shashank Sharma <[email protected]>
This patch adds new functions to map/unmap a usermode queue into the FW, using the MES ring. As soon as this mapping is done, the queue would be considered ready to accept the workload.
V1: Addressed review comments from Alex on the RFC patch series
- Map/Unmap should be IP specific.
V2:
Addressed review comments from Christian:
- Fix the wptr_mc_addr calculation (moved into another patch) Addressed review comments from Alex:
- Do not add fptrs for map/unmap
--- .../drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c +70 -0
@@ -23,12 +23,73 @@#include "amdgpu.h" #include "amdgpu_userqueue.h" #include "v11_structs.h" +#include "amdgpu_mes.h" #define AMDGPU_USERQ_PROC_CTX_SZ PAGE_SIZE#define AMDGPU_USERQ_GANG_CTX_SZ PAGE_SIZE#define AMDGPU_USERQ_FW_CTX_SZ PAGE_SIZE#define AMDGPU_USERQ_GDS_CTX_SZ PAGE_SIZE +static int +amdgpu_userq_gfx_v11_map (struct amdgpu_userq_mgr *uq_mgr, +struct amdgpu_usermode_queue *queue) +{ +struct amdgpu_device *adev = uq_mgr->adev; +struct mes_add_queue_input queue_input; +int r; + +memset (&queue_input,0x0 ,sizeof (struct mes_add_queue_input )); + + queue_input.process_va_start =0 ; + queue_input.process_va_end = (adev->vm_manager.max_pfn -1 ) <<AMDGPU_GPU_PAGE_SHIFT ; + queue_input.process_quantum =100000 ;/* 10ms */ + queue_input.gang_quantum =10000 ;/* 1ms */ + queue_input.paging = false; + + queue_input.gang_context_addr = queue->gang_ctx_gpu_addr; + queue_input.process_context_addr = queue->proc_ctx_gpu_addr; + queue_input.inprocess_gang_priority =AMDGPU_MES_PRIORITY_LEVEL_NORMAL ; + queue_input.gang_global_priority_level =AMDGPU_MES_PRIORITY_LEVEL_NORMAL ; + + queue_input.process_id = queue->vm->pasid; + queue_input.queue_type = queue->queue_type; + queue_input.mqd_addr = queue->mqd.gpu_addr; + queue_input.wptr_addr = queue->userq_prop.wptr_gpu_addr; + 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); + +amdgpu_mes_lock (&adev->mes); + r = adev->mes.funcs->add_hw_queue (&adev->mes, &queue_input); +amdgpu_mes_unlock (&adev->mes); +if (r) { +DRM_ERROR ("Failed to map queue in HW, err (%d)\n" , r); +return r; + } + +DRM_DEBUG_DRIVER ("Queue %d mapped successfully\n" , queue->queue_id); +return 0 ; +} + +static void +amdgpu_userq_gfx_v11_unmap (struct amdgpu_userq_mgr *uq_mgr, +struct amdgpu_usermode_queue *queue) +{ +struct amdgpu_device *adev = uq_mgr->adev; +struct mes_remove_queue_input queue_input; +int r; + +memset (&queue_input,0x0 ,sizeof (struct mes_remove_queue_input )); + queue_input.doorbell_offset = queue->userq_prop.doorbell_index; + queue_input.gang_context_addr = queue->gang_ctx_gpu_addr; + +amdgpu_mes_lock (&adev->mes); + r = adev->mes.funcs->remove_hw_queue (&adev->mes, &queue_input); +amdgpu_mes_unlock (&adev->mes); +if (r) +DRM_ERROR ("Failed to unmap queue in HW, err (%d)\n" , r); +} +static int amdgpu_userq_gfx_v11_create_ctx_space (struct amdgpu_userq_mgr *uq_mgr,struct amdgpu_usermode_queue *queue) {
@@ -129,6 +190,14 @@ amdgpu_userq_gfx_v11_mqd_create(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_uamdgpu_userq_set_ctx_space (uq_mgr, queue);amdgpu_bo_unreserve (mqd->obj); + +/* Map the queue in HW using MES ring */ + r =amdgpu_userq_gfx_v11_map (uq_mgr, queue); +if (r) { +DRM_ERROR ("Failed to map userqueue (%d)\n" , r); + goto free_ctx; + } +DRM_DEBUG_DRIVER ("MQD for queue %d created\n" , queue->queue_id);return 0 ;
@@ -147,6 +216,7 @@ amdgpu_userq_gfx_v11_mqd_destroy(struct amdgpu_userq_mgr *uq_mgr, struct amdgpu_ {struct amdgpu_userq_ctx_space *mqd = &queue->mqd; +amdgpu_userq_gfx_v11_unmap (uq_mgr, queue);amdgpu_userq_gfx_v11_destroy_ctx_space (uq_mgr, queue); amdgpu_bo_free_kernel(&mqd->obj, &mqd->gpu_addr,
Signature · 1 line
2.34.1
PATCH v2 8/9 drm/amdgpu: map wptr BO into GART
In reply to Shashank SharmaFrom: Arvind Yadav <[email protected]>
To support oversubscription, MES expects WPTR BOs to be mapped to GART, before they are submitted to usermode queues.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c | 89 +++++++++++++++++++ .../drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c | 1 + .../gpu/drm/amd/include/amdgpu_userqueue.h | 1 + 3 files changed, 91 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c +89 -0
@@ -43,6 +43,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; + } + + +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); +if (ret) + goto err_wptr_map_gart; + + 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 (struct drm_file *filp,union drm_amdgpu_userq *args) {struct amdgpu_usermode_queue *queue;
@@ -82,6 +165,12 @@ static int amdgpu_userqueue_create(struct drm_file *filp, union drm_amdgpu_userq 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; + } + r = uq_mgr->userq_funcs[queue->queue_type]->mqd_create (uq_mgr, queue);if (r) {DRM_ERROR ("Failed to create/map userqueue MQD\n" );
drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c +1 -0
@@ -58,6 +58,7 @@ amdgpu_userq_gfx_v11_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);
drivers/gpu/drm/amd/include/amdgpu_userqueue.h +1 -0
@@ -38,6 +38,7 @@ struct amdgpu_usermode_queue {int queue_type;uint64_t flags;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;
Signature · 1 line
2.34.1
v2 cover AMDGPU usermode queues
In reply to Shashank SharmaFrom: Shashank Sharma <[email protected]>
This patch series introduces AMDGPU usermode graphics queues. User queues is a method of GPU workload submission into the graphics hardware without any interaction with kernel/DRM schedulers. In this method, a userspace graphics application can create its own workqueue and submit it directly in the GPU HW.
The general idea of how this is supposed to work:
- The application creates the following GPU objetcs:
- A queue object to hold the workload packets.
- A read pointer object.
- A write pointer object.
- A doorbell page.
- Kernel picks any 32-bit offset in the doorbell page for this queue.
- The application uses the usermode_queue_create IOCTL introduced in this patch, by passing the the GPU addresses of these objects (read ptr, write ptr, queue base address and doorbell address)
- The kernel creates the queue and maps it in the HW.
- The application can start submitting the data in the queue as soon as the kernel IOCTL returns.
- Once the data is filled in the queue, the app must write the number of dwords in the doorbell offset, and the GPU will start fetching the data.
libDRM changes for this series and a sample DRM test program can be found in the MESA merge request here:
https://gitlab.freedesktop.org/mesa/drm/-/merge_requests/287
The RFC patch series and previous discussion can be seen here:
https://patchwork.freedesktop.org/series/112214/
This patch series needs the doorbell re-design changes, which are being reviewed here:
https://patchwork.freedesktop.org/series/113669/
In absence of the doorbell patches, this patch series uses a hack patch to test the functionality. That hack patch is also published here at the end of the series, just for reference.
Alex Deucher (1):
drm/amdgpu: UAPI for user queue management
Arvind Yadav (2):
drm/amdgpu: add new parameters in v11_struct
drm/amdgpu: map wptr BO into GART
Shashank Sharma (5):
drm/amdgpu: add usermode queue base code drm/amdgpu: add new IOCTL for usermode queue drm/amdgpu: create GFX-gen11 MQD for userqueue drm/amdgpu: create context space for usermode queue drm/amdgpu: map usermode queue into MES
drivers/gpu/drm/amd/amdgpu/Makefile | 3 + drivers/gpu/drm/amd/amdgpu/amdgpu.h | 10 +- drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 2 + drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 6 + drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c | 325 ++++++++++++++++++ .../drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c | 230 +++++++++++++ .../gpu/drm/amd/include/amdgpu_userqueue.h | 66 ++++ drivers/gpu/drm/amd/include/v11_structs.h | 16 +- include/uapi/drm/amdgpu_drm.h | 55 +++ 9 files changed, 704 insertions(+), 9 deletions(-) create mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue.c create mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_userqueue_gfx_v11.c create mode 100644 drivers/gpu/drm/amd/include/amdgpu_userqueue.h
Signature · 1 line
2.34.1