Add the GFX case to the mqd_update dispatcher, routing it through the
per-IP update_mqd callback like compute. Add a queue_percentage field to
drm_amdgpu_userq_mqd_gfx11 and plumb it through create; 0 marks the queue
inactive so it is not remapped, aligning KGD GFX user queues with KFD.

Signed-off-by: Jesse Zhang <[email protected]>
Suggested-by: Alexander Deucher <[email protected]>
---
 drivers/gpu/drm/amd/amdgpu/mes_userqueue.c | 55 ++++++++++++++++++++++
 include/uapi/drm/amdgpu_drm.h              |  6 +++
 2 files changed, 61 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/mes_userqueue.c 
b/drivers/gpu/drm/amd/amdgpu/mes_userqueue.c
index f2742fa28dc6..3059224dd9ad 100644
--- a/drivers/gpu/drm/amd/amdgpu/mes_userqueue.c
+++ b/drivers/gpu/drm/amd/amdgpu/mes_userqueue.c
@@ -573,8 +573,16 @@ static int mes_userq_mqd_create(struct 
amdgpu_usermode_queue *queue,
                        goto free_mqd;
                }
 
+               if (mqd_gfx_v11->queue_percentage > 
AMDGPU_USERQ_MAX_QUEUE_PERCENTAGE) {
+                       DRM_ERROR("Queue percentage must be between 0 to 
AMDGPU_USERQ_MAX_QUEUE_PERCENTAGE.\n");
+                       r = -EINVAL;
+                       kfree(mqd_gfx_v11);
+                       goto free_mqd;
+               }
+
                userq_props->shadow_addr = mqd_gfx_v11->shadow_va;
                userq_props->csa_addr = mqd_gfx_v11->csa_va;
+               userq_props->queue_percentage = mqd_gfx_v11->queue_percentage;
                userq_props->tmz_queue =
                        mqd_user->flags & 
AMDGPU_USERQ_CREATE_FLAGS_QUEUE_SECURE;
 
@@ -700,6 +708,51 @@ static u64 mes_userq_read_user_wptr(struct 
amdgpu_usermode_queue *queue)
        return user_wptr;
 }
 
+static int mes_userq_gfx_mqd_update(struct amdgpu_usermode_queue *queue,
+                                   struct drm_amdgpu_userq_in *args_in)
+{
+       int retval = 0;
+       struct amdgpu_device *adev = queue->userq_mgr->adev;
+       struct amdgpu_mqd_prop *userq_props = queue->userq_prop;
+       struct amdgpu_mqd *mqd_hw_default = &adev->mqds[queue->queue_type];
+       struct drm_amdgpu_userq_mqd_gfx11 *gfx_mqd_v11;
+
+       if (args_in->mqd_size != sizeof(*gfx_mqd_v11)) {
+               DRM_ERROR("Invalid GFX IP MQD size\n");
+               return -EINVAL;
+       }
+
+       if (!mqd_hw_default->update_mqd) {
+               DRM_ERROR("GFX MQD update not supported on this IP\n");
+               return -EOPNOTSUPP;
+       }
+
+       gfx_mqd_v11 = memdup_user(u64_to_user_ptr(args_in->mqd), 
args_in->mqd_size);
+       if (IS_ERR(gfx_mqd_v11)) {
+               DRM_ERROR("Failed to read user MQD\n");
+               return -ENOMEM;
+       }
+
+       if (gfx_mqd_v11->queue_percentage > AMDGPU_USERQ_MAX_QUEUE_PERCENTAGE) {
+               DRM_ERROR("Queue percentage must be between 0 to 
AMDGPU_USERQ_MAX_QUEUE_PERCENTAGE.\n");
+               kfree(gfx_mqd_v11);
+               return -EINVAL;
+       }
+
+       userq_props->shadow_addr = gfx_mqd_v11->shadow_va;
+       userq_props->csa_addr = gfx_mqd_v11->csa_va;
+       userq_props->queue_size = args_in->queue_size;
+       userq_props->hqd_base_gpu_addr = args_in->queue_va;
+       userq_props->queue_percentage = gfx_mqd_v11->queue_percentage;
+
+       retval = mqd_hw_default->update_mqd(adev, (void *)queue->mqd.cpu_ptr,
+                                           userq_props,
+                                           mes_userq_read_user_wptr(queue));
+
+       kfree(gfx_mqd_v11);
+       return retval;
+}
+
 static int mes_userq_compute_mqd_update(struct amdgpu_usermode_queue *queue,
                                        struct drm_amdgpu_userq_in *args_in)
 {
@@ -749,6 +802,8 @@ static int mes_userq_mqd_update(struct 
amdgpu_usermode_queue *queue, struct drm_
        switch (queue->queue_type) {
        case AMDGPU_HW_IP_COMPUTE:
                return mes_userq_compute_mqd_update(queue, args_in);
+       case AMDGPU_HW_IP_GFX:
+               return mes_userq_gfx_mqd_update(queue, args_in);
        default:
                return -EINVAL;
        }
diff --git a/include/uapi/drm/amdgpu_drm.h b/include/uapi/drm/amdgpu_drm.h
index 2de47ff7c4d0..da2016f42a2e 100644
--- a/include/uapi/drm/amdgpu_drm.h
+++ b/include/uapi/drm/amdgpu_drm.h
@@ -449,6 +449,12 @@ struct drm_amdgpu_userq_mqd_gfx11 {
         * Use AMDGPU_INFO_IOCTL to find the exact size of the object.
         */
        __u64   csa_va;
+       /**
+        * @queue_percentage: Queue resource allocation percentage (0-100)
+        * Defines the percentage of GPU resources allocated to this queue.
+        * A value of 0 marks the queue inactive and it will not be mapped.
+        */
+       __u32   queue_percentage;
 };
 
 /* GFX V11 SDMA IP specific MQD parameters */
-- 
2.49.0

Reply via email to