Skip to contentSkip to conversation

drm/amdgpu/mes_userqueue: refactor mqd_update into per-IP helpers

PATCH In review Jesse Zhang 2 participants 10 messages Sep 7 – Sep 14

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v4 1/8 drm/amdgpu/mes_userqueue: refactor mqd_update into per-IP helpers

Split the inlined compute path out of mes_userq_mqd_update() into mes_userq_compute_mqd_update() and turn the former into a dispatcher that switches on queue_type, giving other IPs an obvious place to hook in.

No functional change.

---
 drivers/gpu/drm/amd/amdgpu/mes_userqueue.c | 22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)
drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +15 -7
index ad72ced472dd..82bb4369451e 100644
@@ -681,7 +681,8 @@ static int mes_userq_mqd_create(struct amdgpu_usermode_queue *queue,
 	return r;
 }
 
-static int mes_userq_mqd_update(struct amdgpu_usermode_queue *queue, struct drm_amdgpu_userq_in *args_in)
+static int mes_userq_compute_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;
@@ -689,12 +690,6 @@ static int mes_userq_mqd_update(struct amdgpu_usermode_queue *queue, struct drm_
 	struct amdgpu_mqd *mqd_hw_default = &adev->mqds[queue->queue_type];
 	struct drm_amdgpu_userq_mqd_compute_gfx11 *compute_mqd_v11;
 
-	if (!queue || !userq_props)
-		return -EINVAL;
-
-	if (queue->queue_type != AMDGPU_HW_IP_COMPUTE)
-		return -EINVAL;
-
 	if (args_in->mqd_size != sizeof(*compute_mqd_v11)) {
 		DRM_ERROR("Invalid compute IP MQD size\n");
 		return -EINVAL;
@@ -720,6 +715,19 @@ static int mes_userq_mqd_update(struct amdgpu_usermode_queue *queue, struct drm_
 	return retval;
 }
 
+static int mes_userq_mqd_update(struct amdgpu_usermode_queue *queue, struct drm_amdgpu_userq_in *args_in)
+{
+	if (!queue || !queue->userq_prop)
+		return -EINVAL;
+
+	switch (queue->queue_type) {
+	case AMDGPU_HW_IP_COMPUTE:
+		return mes_userq_compute_mqd_update(queue, args_in);
+	default:
+		return -EINVAL;
+	}
+}
+
 static void mes_userq_mqd_destroy(struct amdgpu_usermode_queue *queue)
 {
 
Signature · 1 line
2.49.0
#1 lore raw

PATCH v4 2/8 drm/amdgpu: add mqd_prop modify flag for queue MODIFY

Add a modify flag to struct amdgpu_mqd_prop. When set, init_mqd patches the MQD in place, keeping the ring rptr/wptr that firmware context-saved into it on unmap. KFD already patches the MQD in place for the same disable/re-enable sequence.

v3: use an mqd_prop modify flag consumed by init_mqd instead of a
separate per-IP update_mqd callback, per review.
v4: drop the user_wptr field - firmware context-saves the wptr into the
MQD on unmap, so init_mqd just keeps it rather than restoring a value read back from the wptr BO.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_mes.h | 1 +
 1 file changed, 1 insertion(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_mes.h +1 -0
index 63670b41c26c..d231d5d283df 100644
@@ -494,6 +494,7 @@ struct amdgpu_mqd_prop {
 	uint64_t ctx_save_area_addr;
 	uint32_t ctx_save_area_size;
 	uint32_t ctl_stack_size;
+	bool modify;
 };
 
 struct amdgpu_mqd {
Signature · 1 line
2.49.0
#2 lore raw

PATCH v4 3/8 drm/amdgpu/gfx11: honor mqd_prop modify flag in init_mqd

In reply to Jesse Zhang

On a queue MODIFY (prop->modify) the gfx11 GFX and compute init_mqd keep the ring rptr/wptr that firmware context-saved into the MQD, so a re-enabled queue resumes at the first un-consumed packet.

v2: rebuild the HQD via init_mqd and save/restore the rptr, matching the
SDMA update_mqd style, instead of patching individual MQD fields in place. Keeps all update_mqd callbacks consistent.
v3: consume the mqd_prop modify flag inside init_mqd instead of adding a
separate gfx11 update_mqd callback, per review.
v4: also keep the context-saved wptr instead of programming a user_wptr,
per review.

---
 drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 27 ++++++++++++++++----------
 1 file changed, 17 insertions(+), 10 deletions(-)
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +17 -10
index a447562977ab..301f7ab30bdf 100644
@@ -4167,9 +4167,11 @@ static int gfx_v11_0_gfx_mqd_init(struct amdgpu_device *adev, void *m,
 	uint32_t tmp;
 	uint32_t rb_bufsz;
 
-	/* set up gfx hqd wptr */
-	mqd->cp_gfx_hqd_wptr = 0;
-	mqd->cp_gfx_hqd_wptr_hi = 0;
+	/* MODIFY keeps the firmware-saved wptr; otherwise start at 0 */
+	if (!prop->modify) {
+		mqd->cp_gfx_hqd_wptr = 0;
+		mqd->cp_gfx_hqd_wptr_hi = 0;
+	}
 
 	/* set the pointer to the MQD */
 	mqd->cp_mqd_base_addr = prop->mqd_gpu_addr & 0xfffffffc;
@@ -4237,8 +4239,9 @@ static int gfx_v11_0_gfx_mqd_init(struct amdgpu_device *adev, void *m,
 				    DOORBELL_EN, 0);
 	mqd->cp_rb_doorbell_control = tmp;
 
-	/* reset read and write pointers, similar to CP_RB0_WPTR/_RPTR */
-	mqd->cp_gfx_hqd_rptr = regCP_GFX_HQD_RPTR_DEFAULT;
+	/* MODIFY keeps the firmware-saved rptr; otherwise reset it */
+	if (!prop->modify)
+		mqd->cp_gfx_hqd_rptr = regCP_GFX_HQD_RPTR_DEFAULT;
 
 	/* active the queue */
 	mqd->cp_gfx_hqd_active = 1;
@@ -4379,9 +4382,12 @@ static int gfx_v11_0_compute_mqd_init(struct amdgpu_device *adev, void *m,
 
 	/* disable the queue if it's active */
 	mqd->cp_hqd_dequeue_request = 0;
-	mqd->cp_hqd_pq_rptr = 0;
-	mqd->cp_hqd_pq_wptr_lo = 0;
-	mqd->cp_hqd_pq_wptr_hi = 0;
+	/* MODIFY keeps the firmware-saved rptr/wptr; otherwise start at 0 */
+	if (!prop->modify) {
+		mqd->cp_hqd_pq_rptr = 0;
+		mqd->cp_hqd_pq_wptr_lo = 0;
+		mqd->cp_hqd_pq_wptr_hi = 0;
+	}
 
 	/* set the pointer to the MQD */
 	mqd->cp_mqd_base_addr_lo = prop->mqd_gpu_addr & 0xfffffffc;
@@ -4442,8 +4448,9 @@ static int gfx_v11_0_compute_mqd_init(struct amdgpu_device *adev, void *m,
 
 	mqd->cp_hqd_pq_doorbell_control = tmp;
 
-	/* reset read and write pointers, similar to CP_RB0_WPTR/_RPTR */
-	mqd->cp_hqd_pq_rptr = regCP_HQD_PQ_RPTR_DEFAULT;
+	/* MODIFY keeps the firmware-saved rptr; otherwise reset it */
+	if (!prop->modify)
+		mqd->cp_hqd_pq_rptr = regCP_HQD_PQ_RPTR_DEFAULT;
 
 	/* set the vmid for the queue */
 	mqd->cp_hqd_vmid = 0;
Signature · 1 line
2.49.0
#3 lore raw

PATCH v4 4/8 drm/amdgpu/gfx12: honor mqd_prop modify flag in init_mqd

In reply to Jesse Zhang

On a queue MODIFY (prop->modify) the gfx12 GFX and compute init_mqd keep the ring rptr/wptr that firmware context-saved into the MQD, so a re-enabled queue resumes at the first un-consumed packet.

v2: rebuild the HQD via init_mqd and save/restore the rptr, matching the
SDMA update_mqd style, instead of patching individual MQD fields in place. Keeps all update_mqd callbacks consistent.
v3: consume the mqd_prop modify flag inside init_mqd instead of adding a
separate gfx12 update_mqd callback, per review.
v4: also keep the context-saved wptr instead of programming a user_wptr,
per review.

---
 drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c | 23 ++++++++++++++---------
 1 file changed, 14 insertions(+), 9 deletions(-)
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +14 -9
index a434b665d913..b2d210681224 100644
@@ -3006,9 +3006,11 @@ static int gfx_v12_0_gfx_mqd_init(struct amdgpu_device *adev, void *m,
 	uint32_t tmp;
 	uint32_t rb_bufsz;
 
-	/* set up gfx hqd wptr */
-	mqd->cp_gfx_hqd_wptr = 0;
-	mqd->cp_gfx_hqd_wptr_hi = 0;
+	/* MODIFY keeps the firmware-saved wptr; otherwise start at 0 */
+	if (!prop->modify) {
+		mqd->cp_gfx_hqd_wptr = 0;
+		mqd->cp_gfx_hqd_wptr_hi = 0;
+	}
 
 	/* set the pointer to the MQD */
 	mqd->cp_mqd_base_addr = prop->mqd_gpu_addr & 0xfffffffc;
@@ -3079,8 +3081,9 @@ static int gfx_v12_0_gfx_mqd_init(struct amdgpu_device *adev, void *m,
 				    DOORBELL_EN, 0);
 	mqd->cp_rb_doorbell_control = tmp;
 
-	/* reset read and write pointers, similar to CP_RB0_WPTR/_RPTR */
-	mqd->cp_gfx_hqd_rptr = regCP_GFX_HQD_RPTR_DEFAULT;
+	/* MODIFY keeps the firmware-saved rptr; otherwise reset it */
+	if (!prop->modify)
+		mqd->cp_gfx_hqd_rptr = regCP_GFX_HQD_RPTR_DEFAULT;
 
 	/* active the queue */
 	mqd->cp_gfx_hqd_active = 1;
@@ -3212,10 +3215,12 @@ static int gfx_v12_0_compute_mqd_init(struct amdgpu_device *adev, void *m,
 
 	/* disable the queue if it's active */
 	mqd->cp_hqd_dequeue_request = 0;
-	/* reset read and write pointers, similar to CP_RB0_WPTR/_RPTR */
-	mqd->cp_hqd_pq_rptr = regCP_HQD_PQ_RPTR_DEFAULT;
-	mqd->cp_hqd_pq_wptr_lo = 0;
-	mqd->cp_hqd_pq_wptr_hi = 0;
+	/* MODIFY keeps the firmware-saved rptr/wptr; otherwise start at 0 */
+	if (!prop->modify) {
+		mqd->cp_hqd_pq_rptr = regCP_HQD_PQ_RPTR_DEFAULT;
+		mqd->cp_hqd_pq_wptr_lo = 0;
+		mqd->cp_hqd_pq_wptr_hi = 0;
+	}
 
 	/* set the pointer to the MQD */
 	mqd->cp_mqd_base_addr_lo = prop->mqd_gpu_addr & 0xfffffffc;
Signature · 1 line
2.49.0
#4 lore raw

PATCH v4 5/8 drm/amdgpu/sdma6: honor mqd_prop modify flag in init_mqd

In reply to Jesse Zhang

On a queue MODIFY (prop->modify) sdma6 init_mqd keeps the ring rptr/wptr that firmware context-saved into the MQD, so a re-enabled queue resumes at the first un-consumed packet. It also forces IB_ENABLE back on, since ib_cntl reads back IB_ENABLE=0 on a stopped queue.

v3: consume the mqd_prop modify flag inside init_mqd instead of adding a
separate sdma6 update_mqd callback, per review.
v4: also keep the context-saved wptr instead of programming a user_wptr,
per review.

---
 drivers/gpu/drm/amd/amdgpu/sdma_v6_0.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/gpu/drm/amd/amdgpu/sdma_v6_0.c +8 -0
index 3fd3e530c76b..a7dac93386db 100644
@@ -881,6 +881,14 @@ static int sdma_v6_0_mqd_init(struct amdgpu_device *adev, void *mqd,
 	m->sdmax_rlcx_f32_dbg0 = lower_32_bits(prop->fence_address);
 	m->sdmax_rlcx_f32_dbg1 = upper_32_bits(prop->fence_address);
 
+	if (prop->modify) {
+		/*
+		 * MODIFY keeps the firmware-saved rptr/wptr (left untouched above);
+		 * ib_cntl read back IB_ENABLE=0 on the stopped queue, so force it on.
+		 */
+		m->sdmax_rlcx_ib_cntl |= SDMA0_QUEUE0_IB_CNTL__IB_ENABLE_MASK;
+	}
+
 	return 0;
 }
 
Signature · 1 line
2.49.0
#5 lore raw

PATCH v4 6/8 drm/amdgpu/sdma7: honor mqd_prop modify flag in init_mqd

In reply to Jesse Zhang

On a queue MODIFY (prop->modify) sdma7 init_mqd keeps the ring rptr/wptr that firmware context-saved into the MQD, so a re-enabled queue resumes at the first un-consumed packet. It also forces IB_ENABLE back on, since ib_cntl reads back IB_ENABLE=0 on a stopped queue.

v3: consume the mqd_prop modify flag inside init_mqd instead of adding a
separate sdma7 update_mqd callback, per review.
v4: also keep the context-saved wptr instead of programming a user_wptr,
per review.

---
 drivers/gpu/drm/amd/amdgpu/sdma_v7_0.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/gpu/drm/amd/amdgpu/sdma_v7_0.c +8 -0
index 2068e2e6e3d6..20c2423a0c4d 100644
@@ -902,6 +902,14 @@ static int sdma_v7_0_mqd_init(struct amdgpu_device *adev, void *mqd,
 	m->sdmax_rlcx_mcu_dbg0 = lower_32_bits(prop->fence_address);
 	m->sdmax_rlcx_mcu_dbg1 = upper_32_bits(prop->fence_address);
 
+	if (prop->modify) {
+		/*
+		 * MODIFY keeps the firmware-saved rptr/wptr (left untouched above);
+		 * ib_cntl read back IB_ENABLE=0 on the stopped queue, so force it on.
+		 */
+		m->sdmax_rlcx_ib_cntl |= SDMA0_QUEUE0_IB_CNTL__IB_ENABLE_MASK;
+	}
+
 	return 0;
 }
 
Signature · 1 line
2.49.0
#6 lore raw

PATCH v4 7/8 drm/amdgpu/sdma7_1: honor mqd_prop modify flag in init_mqd

In reply to Jesse Zhang

On a queue MODIFY (prop->modify) sdma7_1 init_mqd keeps the ring rptr/wptr that firmware context-saved into the MQD, so a re-enabled queue resumes at the first un-consumed packet. It also forces IB_ENABLE back on, since ib_cntl reads back IB_ENABLE=0 on a stopped queue.

v3: consume the mqd_prop modify flag inside init_mqd instead of adding a
separate sdma7_1 update_mqd callback, per review.
v4: also keep the context-saved wptr instead of programming a user_wptr,
per review.

---
 drivers/gpu/drm/amd/amdgpu/sdma_v7_1.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/gpu/drm/amd/amdgpu/sdma_v7_1.c +8 -0
index e9a3bcfd7775..0af11841b727 100644
@@ -886,6 +886,14 @@ static int sdma_v7_1_mqd_init(struct amdgpu_device *adev, void *mqd,
 	m->sdmax_rlcx_csa_addr_lo = lower_32_bits(prop->csa_addr);
 	m->sdmax_rlcx_csa_addr_hi = upper_32_bits(prop->csa_addr);
 
+	if (prop->modify) {
+		/*
+		 * MODIFY keeps the firmware-saved rptr/wptr (left untouched above);
+		 * ib_cntl read back IB_ENABLE=0 on the stopped queue, so force it on.
+		 */
+		m->sdmax_rlcx_ib_cntl |= SDMA0_SDMA_QUEUE0_IB_CNTL__IB_ENABLE_MASK;
+	}
+
 	return 0;
 }
 
Signature · 1 line
2.49.0
#7 lore raw

PATCH v4 8/8 drm/amdgpu/mes_userqueue: add SDMA MODIFY support

In reply to Jesse Zhang

Add mes_userq_sdma_mqd_update() to update an SDMA queue's MQD from a drm_amdgpu_userq_mqd_sdma_gfx11 (csa address, queue size, ring base), re-init it in place via prop->modify, and wire it into the queue_type dispatcher. This aligns KGD user queues with KFD's update_mqd_sdma.

v3: re-init the MQD via the mqd_prop modify flag instead of a separate
update_mqd callback, per review.
v4: keep the context-saved wptr instead of forwarding a user_wptr, per
review.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c   |   1 +
 drivers/gpu/drm/amd/amdgpu/mes_userqueue.c | 104 ++++++++++++++++++++-
 include/uapi/drm/amdgpu_drm.h              |  12 +++
 3 files changed, 116 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +1 -0
index 686c92e96025..5210ec381be7 100644
@@ -840,6 +840,7 @@ static void amdgpu_ring_to_mqd_prop(struct amdgpu_ring *ring,
 	prop->use_doorbell = ring->use_doorbell;
 	prop->doorbell_index = ring->doorbell_index;
 	prop->kernel_queue = true;
+	prop->modify = false;
 
 	/* map_queues packet doesn't need activate the queue,
 	 * so only kiq need set this field.
drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +103 -1

149 lines not on this page · raw message

include/uapi/drm/amdgpu_drm.h +12 -0
index 2de47ff7c4d0..94497d1217b8 100644
@@ -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 */
@@ -459,6 +465,12 @@ struct drm_amdgpu_userq_mqd_sdma_gfx11 {
 	 * to get the size.
 	 */
 	__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 Compute IP specific MQD parameters */
Signature · 1 line
2.49.0
Reviewed-by on v4 8/8
#8 lore raw

Re: [PATCH v4 8/8] drm/amdgpu/mes_userqueue: add SDMA MODIFY support

Series is:

Quoted 224 lines · Jesse Zhang

Add mes_userq_sdma_mqd_update() to update an SDMA queue's MQD from a drm_amdgpu_userq_mqd_sdma_gfx11 (csa address, queue size, ring base), re-init it in place via prop->modify, and wire it into the queue_type dispatcher. This aligns KGD user queues with KFD's update_mqd_sdma.

v3: re-init the MQD via the mqd_prop modify flag instead of a separate
update_mqd callback, per review.
v4: keep the context-saved wptr instead of forwarding a user_wptr, per
review.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c   |   1 +
 drivers/gpu/drm/amd/amdgpu/mes_userqueue.c | 104 ++++++++++++++++++++-
 include/uapi/drm/amdgpu_drm.h              |  12 +++
 3 files changed, 116 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +1 -0
index 686c92e96025..5210ec381be7 100644
@@ -840,6 +840,7 @@ static void amdgpu_ring_to_mqd_prop(struct amdgpu_ring *ring,
        prop->use_doorbell = ring->use_doorbell;
        prop->doorbell_index = ring->doorbell_index;
        prop->kernel_queue = true;
+       prop->modify = false;
 
        /* map_queues packet doesn't need activate the queue,
         * so only kiq need set this field.
drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +103 -1
index 82bb4369451e..5b53e6ec8897 100644
@@ -479,6 +479,7 @@ static int mes_userq_mqd_create(struct amdgpu_usermode_queue *queue,
        userq_props->use_doorbell = true;
        userq_props->doorbell_index = queue->doorbell_index;
        userq_props->fence_address = queue->fence_drv->gpu_addr;
+       userq_props->modify = false;
 
        if (queue->queue_type == AMDGPU_HW_IP_COMPUTE) {
                struct drm_amdgpu_userq_mqd_compute_gfx11 *compute_mqd;
@@ -573,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;
 
@@ -618,6 +627,13 @@ static int mes_userq_mqd_create(struct amdgpu_usermode_queue *queue,
                        goto free_mqd;
                }
 
+               if (mqd_sdma_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_sdma_v11);
+                       goto free_mqd;
+               }
+
                r = amdgpu_bo_reserve(queue->vm->root.bo, false);
                if (r) {
                        kfree(mqd_sdma_v11);
@@ -633,6 +649,7 @@ static int mes_userq_mqd_create(struct amdgpu_usermode_queue *queue,
                }
 
                userq_props->csa_addr = mqd_sdma_v11->csa_va;
+               userq_props->queue_percentage = mqd_sdma_v11->queue_percentage;
                kfree(mqd_sdma_v11);
        }
 
@@ -681,6 +698,85 @@ static int mes_userq_mqd_create(struct amdgpu_usermode_queue *queue,
        return r;
 }
 
+static int mes_userq_sdma_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_sdma_gfx11 *sdma_mqd_v11;
+
+       if (args_in->mqd_size != sizeof(*sdma_mqd_v11)) {
+               DRM_ERROR("Invalid SDMA IP MQD size\n");
+               return -EINVAL;
+       }
+
+       sdma_mqd_v11 = memdup_user(u64_to_user_ptr(args_in->mqd), args_in->mqd_size);
+       if (IS_ERR(sdma_mqd_v11)) {
+               DRM_ERROR("Failed to read user MQD\n");
+               return -ENOMEM;
+       }
+
+       if (sdma_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(sdma_mqd_v11);
+               return -EINVAL;
+       }
+
+       userq_props->csa_addr = sdma_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 = sdma_mqd_v11->queue_percentage;
+       userq_props->modify = true;
+
+       retval = mqd_hw_default->init_mqd(adev, (void *)queue->mqd.cpu_ptr,
+                                        userq_props);
+
+       kfree(sdma_mqd_v11);
+       return retval;
+}
+
+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;
+
+       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)
 {
@@ -707,8 +803,10 @@ static int mes_userq_compute_mqd_update(struct amdgpu_usermode_queue *queue,
 
        userq_props->queue_size = args_in->queue_size;
        userq_props->hqd_base_gpu_addr = args_in->queue_va;
+       userq_props->modify = true;
 
-       retval = mqd_hw_default->init_mqd(adev, (void *)queue->mqd.cpu_ptr, userq_props);
+       retval = mqd_hw_default->init_mqd(adev, (void *)queue->mqd.cpu_ptr,
+                                        userq_props);
 
 free:
        kfree(compute_mqd_v11);
@@ -723,6 +821,10 @@ 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);
+       case AMDGPU_HW_IP_DMA:
+               return mes_userq_sdma_mqd_update(queue, args_in);
        default:
                return -EINVAL;
        }
include/uapi/drm/amdgpu_drm.h +12 -1
index 2de47ff7c4d0..94497d1217b8 100644
@@ -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 */
@@ -459,6 +465,12 @@ struct drm_amdgpu_userq_mqd_sdma_gfx11 {
         * to get the size.
         */
        __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 Compute IP specific MQD parameters */
--

2.49.0

#9 lore raw
In reply to Jesse Zhang

AMD General

Ping ..

Quoted 75 lines

-----Original Message-----
From: Jesse Zhang <[email protected]>
Sent: Monday, September 7, 2026 9:45 AM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>; Zhang, Jesse(Jie) <[email protected]>
Subject: [PATCH v4 1/8] drm/amdgpu/mes_userqueue: refactor mqd_update into per-IP helpers

Split the inlined compute path out of mes_userq_mqd_update() into mes_userq_compute_mqd_update() and turn the former into a dispatcher that switches on queue_type, giving other IPs an obvious place to hook in.

No functional change.

---
 drivers/gpu/drm/amd/amdgpu/mes_userqueue.c | 22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)
drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +2 -1
index ad72ced472dd..82bb4369451e 100644
@@ -681,7 +681,8 @@ static int mes_userq_mqd_create(struct
 amdgpu_usermode_queue *queue,
      return r;
 }
 
-static int mes_userq_mqd_update(struct amdgpu_usermode_queue *queue, struct
 drm_amdgpu_userq_in *args_in)
+static int mes_userq_compute_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; @@ -689,12
+690,6 @@ static int mes_userq_mqd_update(struct amdgpu_usermode_queue
*queue, struct drm_
      struct amdgpu_mqd *mqd_hw_default = &adev->mqds[queue-
Quoted 1 line

queue_type];

      struct drm_amdgpu_userq_mqd_compute_gfx11 *compute_mqd_v11;
drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +0 -6
-     if (!queue || !userq_props)
-             return -EINVAL;
-
-     if (queue->queue_type != AMDGPU_HW_IP_COMPUTE)
-             return -EINVAL;
-
      if (args_in->mqd_size != sizeof(*compute_mqd_v11)) {
              DRM_ERROR("Invalid compute IP MQD size\n");
              return -EINVAL;
@@ -720,6 +715,19 @@ static int mes_userq_mqd_update(struct

amdgpu_usermode_queue *queue, struct drm_

      return retval;

}

drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +13 -1
+static int mes_userq_mqd_update(struct amdgpu_usermode_queue *queue,
+struct drm_amdgpu_userq_in *args_in) {
+     if (!queue || !queue->userq_prop)
+             return -EINVAL;
+
+     switch (queue->queue_type) {
+     case AMDGPU_HW_IP_COMPUTE:
+             return mes_userq_compute_mqd_update(queue, args_in);
+     default:
+             return -EINVAL;
+     }
+}
+
 static void mes_userq_mqd_destroy(struct amdgpu_usermode_queue *queue)  {
 
--

2.49.0