Add mes_userq_gfx_mqd_update() to update a GFX queue's MQD from a
drm_amdgpu_userq_mqd_gfx11 (shadow/csa address, queue size, ring base),
re-init it in place via prop->modify + prop->user_wptr, and wire it into
the queue_type dispatcher.
v3: re-init the MQD via the mqd_prop modify flag instead of a separate
update_mqd callback, per review.
Signed-off-by: Jesse Zhang <[email protected]>
Suggested-by: Alexander Deucher <[email protected]>
---
drivers/gpu/drm/amd/amdgpu/mes_userqueue.c | 51 ++++++++++++++++++++++
include/uapi/drm/amdgpu_drm.h | 6 +++
2 files changed, 57 insertions(+)
diff --git a/drivers/gpu/drm/amd/amdgpu/mes_userqueue.c
b/drivers/gpu/drm/amd/amdgpu/mes_userqueue.c
index c6ac3194e4da..99da719ecffb 100644
--- a/drivers/gpu/drm/amd/amdgpu/mes_userqueue.c
+++ b/drivers/gpu/drm/amd/amdgpu/mes_userqueue.c
@@ -574,8 +574,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;
@@ -696,6 +704,47 @@ 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;
+ }
+
+ 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;
+ userq_props->modify = true;
+ userq_props->user_wptr = mes_userq_read_user_wptr(queue);
+
+ retval = mqd_hw_default->init_mqd(adev, (void *)queue->mqd.cpu_ptr,
+ userq_props);
+
+ 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)
{
@@ -741,6 +790,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