drm/amdgpu/mes_userqueue: refactor mqd_update into per-IP helpers
Subsystems (3)
PATCH v2 1/10 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
@@ -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
PATCH v2 2/10 drm/amdgpu: add update_mqd callback for queue MODIFY
A queue MODIFY (e.g. re-enabling a queue after a queue_percentage == 0 disable) must not rebuild the MQD with init_mqd: init_mqd rebuilds the HQD from power-on defaults and zeroes the ring pointers, discarding the state firmware context-saved into the MQD on unmap. The re-mapped engine then comes up idle, drops the packet queued while disabled, and wedges into a GPU reset.
Add an optional update_mqd hook to struct amdgpu_mqd for IPs to patch the MQD in place instead - preserving the saved ring/HQD state and forwarding user_wptr into the MQD write pointer. KFD already handles the same disable/re-enable sequence by patching the MQD in place rather than re-initialising it.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_mes.h | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_mes.h +6 -0
@@ -500,6 +500,12 @@ struct amdgpu_mqd {unsigned mqd_size;int (*init_mqd)(struct amdgpu_device *adev,void *mqd,struct amdgpu_mqd_prop *p); +/* Patch an MQD in place for a queue MODIFY: keep the ring/HQD state +* firmware context-saved into it (init_mqd instead rebuilds from +* defaults) and forward @user_wptr into the MQD write pointer. +*/ +int (*update_mqd)(struct amdgpu_device *adev,void *mqd, +struct amdgpu_mqd_prop *p,u64 user_wptr); };/*
Signature · 1 line
2.49.0
PATCH v2 3/10 drm/amdgpu/gfx11: implement compute and GFX update_mqd
In reply to Jesse ZhangImplement the update_mqd callback for gfx11 compute and GFX user queues. Save the read pointer, re-run init_mqd to rebuild the HQD, then restore the saved read pointer and forward the write pointer to the user wptr, so a re-enabled queue resumes at the first un-consumed packet rather than replaying the ring from 0.
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.
--- drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 44 ++++++++++++++++++++++++++ 1 file changed, 44 insertions(+)
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +44 -0
@@ -4256,6 +4256,26 @@ static int gfx_v11_0_gfx_mqd_init(struct amdgpu_device *adev, void *m,return 0 ; } +/* +* GFX update_mqd: init_mqd resets the ring rptr/wptr, so re-run it to rebuild +* the HQD, then restore the saved rptr and forward the user wptr. +*/ +static int gfx_v11_0_gfx_mqd_update (struct amdgpu_device *adev,void *m, +struct amdgpu_mqd_prop *prop, +u64 user_wptr) +{ +struct v11_gfx_mqd *mqd = m; +u32 saved_rptr = mqd->cp_gfx_hqd_rptr; + +gfx_v11_0_gfx_mqd_init (adev, mqd, prop); + + mqd->cp_gfx_hqd_rptr = saved_rptr; + mqd->cp_gfx_hqd_wptr =lower_32_bits (user_wptr); + mqd->cp_gfx_hqd_wptr_hi =upper_32_bits (user_wptr); + +return 0 ; +} +static int gfx_v11_0_kgq_init_queue (struct amdgpu_ring *ring) {struct amdgpu_device *adev = ring->adev;
@@ -4477,6 +4497,26 @@ static int gfx_v11_0_compute_mqd_init(struct amdgpu_device *adev, void *m,return 0 ; } +/* +* Compute update_mqd: init_mqd resets the ring rptr/wptr, so re-run it to +* rebuild the HQD, then restore the saved rptr and forward the user wptr. +*/ +static int gfx_v11_0_compute_mqd_update (struct amdgpu_device *adev,void *m, +struct amdgpu_mqd_prop *prop, +u64 user_wptr) +{ +struct v11_compute_mqd *mqd = m; +u32 saved_rptr = mqd->cp_hqd_pq_rptr; + +gfx_v11_0_compute_mqd_init (adev, mqd, prop); + + mqd->cp_hqd_pq_rptr = saved_rptr; + mqd->cp_hqd_pq_wptr_lo =lower_32_bits (user_wptr); + mqd->cp_hqd_pq_wptr_hi =upper_32_bits (user_wptr); + +return 0 ; +} +static int gfx_v11_0_kiq_init_register (struct amdgpu_ring *ring) {struct amdgpu_device *adev = ring->adev;
@@ -7271,11 +7311,15 @@ static void gfx_v11_0_set_mqd_funcs(struct amdgpu_device *adev)sizeof (struct v11_gfx_mqd ); adev->mqds[AMDGPU_HW_IP_GFX ].init_mqd = gfx_v11_0_gfx_mqd_init; + adev->mqds[AMDGPU_HW_IP_GFX ].update_mqd = + gfx_v11_0_gfx_mqd_update;/* set compute eng mqd */ adev->mqds[AMDGPU_HW_IP_COMPUTE ].mqd_size =sizeof (struct v11_compute_mqd ); adev->mqds[AMDGPU_HW_IP_COMPUTE ].init_mqd = gfx_v11_0_compute_mqd_init; + adev->mqds[AMDGPU_HW_IP_COMPUTE ].update_mqd = + gfx_v11_0_compute_mqd_update; } static void gfx_v11_0_set_user_wgp_inactive_bitmap_per_sh(struct amdgpu_device *adev,
Signature · 1 line
2.49.0
Re: [PATCH v2 03/10] drm/amdgpu/gfx11: implement compute and GFX update_mqd
Quoted 31 lines · Jesse Zhang
Implement the
update_mqdcallback for gfx11 compute and GFX user queues. Save the read pointer, re-runinit_mqdto rebuild the HQD, then restore the saved read pointer and forward the write pointer to the user wptr, so a re-enabled queue resumes at the first un-consumed packet rather than replaying the ring from 0.v2: rebuild the HQD via
init_mqdand save/restore the rptr, matching the
SDMAupdate_mqdstyle, instead of patching individual MQD fields in place. Keeps allupdate_mqdcallbacks consistent.Signed-off-by Jesse Zhang <[email protected]>Suggested-by Alexander Deucher <[email protected]>--- drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 44 ++++++++++++++++++++++++++ 1 file changed, 44 insertions(+)drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +6
-0@@ -4256,6 +4256,26 @@ static int gfx_v11_0_gfx_mqd_init(struct amdgpu_device *adev, void *m,return 0 ; } +/* +* GFX update_mqd: init_mqd resets the ring rptr/wptr, so re-run it to rebuild +* the HQD, then restore the saved rptr and forward the user wptr. +*/ +static int gfx_v11_0_gfx_mqd_update(struct amdgpu_device *adev, void *m, + struct amdgpu_mqd_prop *prop,
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c static int gfx_v11_0_gfx_mqd_init(struct amdgpu_device *adev, void *m, · line 4274
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +10
-0+ u64 user_wptr) +{ +struct v11_gfx_mqd *mqd = m; +u32 saved_rptr = mqd->cp_gfx_hqd_rptr; + +gfx_v11_0_gfx_mqd_init (adev, mqd, prop); + + mqd->cp_gfx_hqd_rptr = saved_rptr; + mqd->cp_gfx_hqd_wptr =lower_32_bits (user_wptr); + mqd->cp_gfx_hqd_wptr_hi =upper_32_bits (user_wptr);
This seems fragile. Rather than doing it this way, can we just use mqd_init() as is and add a newprop->modify flag? Then we can use that in init_mqd to skip state that should be retained from the MQD.
Alex
Quoted 53 lines
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +28
-1+ +return 0 ; +} +static int gfx_v11_0_kgq_init_queue (struct amdgpu_ring *ring) {struct amdgpu_device *adev = ring->adev;@@ -4477,6 +4497,26 @@ static int gfx_v11_0_compute_mqd_init(struct amdgpu_device *adev, void *m,return 0 ; } +/* +* Compute update_mqd: init_mqd resets the ring rptr/wptr, so re-run it to +* rebuild the HQD, then restore the saved rptr and forward the user wptr. +*/ +static int gfx_v11_0_compute_mqd_update (struct amdgpu_device *adev,void *m, +struct amdgpu_mqd_prop *prop, +u64 user_wptr) +{ +struct v11_compute_mqd *mqd = m; +u32 saved_rptr = mqd->cp_hqd_pq_rptr; + +gfx_v11_0_compute_mqd_init (adev, mqd, prop); + + mqd->cp_hqd_pq_rptr = saved_rptr; + mqd->cp_hqd_pq_wptr_lo =lower_32_bits (user_wptr); + mqd->cp_hqd_pq_wptr_hi =upper_32_bits (user_wptr); + +return 0 ; +} +static int gfx_v11_0_kiq_init_register (struct amdgpu_ring *ring) {struct amdgpu_device *adev = ring->adev;@@ -7271,11 +7311,15 @@ static void gfx_v11_0_set_mqd_funcs(struct amdgpu_device *adev)sizeof (struct v11_gfx_mqd ); adev->mqds[AMDGPU_HW_IP_GFX ].init_mqd = gfx_v11_0_gfx_mqd_init; + adev->mqds[AMDGPU_HW_IP_GFX ].update_mqd = + gfx_v11_0_gfx_mqd_update;/* set compute eng mqd */ adev->mqds[AMDGPU_HW_IP_COMPUTE ].mqd_size =sizeof (struct v11_compute_mqd ); adev->mqds[AMDGPU_HW_IP_COMPUTE ].init_mqd = gfx_v11_0_compute_mqd_init; + adev->mqds[AMDGPU_HW_IP_COMPUTE ].update_mqd = + gfx_v11_0_compute_mqd_update; } static void gfx_v11_0_set_user_wgp_inactive_bitmap_per_sh(struct amdgpu_device *adev, --2.49.0
RE: [PATCH v2 03/10] drm/amdgpu/gfx11: implement compute and GFX update_mqd
AMD General
Quoted 51 lines
-----Original Message-----
From: Alex Deucher <[email protected]>
Sent: Saturday, August 29, 2026 3:17 AM
To: Zhang, Jesse(Jie) <[email protected]>
Cc: [email protected]; Deucher, Alexander <[email protected]>; Koenig, Christian <[email protected]>
Subject: Re: [PATCH v2 03/10] drm/amdgpu/gfx11: implement compute and GFXupdate_mqddrivers/gpu/drm/amd/amdgpu/gfx_v11_0.c static int gfx_v11_0_gfx_mqd_init(struct
Quoted 24 lines · Jesse Zhang
Implement the
update_mqdcallback for gfx11 compute and GFX user queues. Save the read pointer, re-runinit_mqdto rebuild the HQD, then restore the saved read pointer and forward the write pointer to the user wptr, so a re-enabled queue resumes at the first un-consumed packet rather than replaying the ring from 0.v2: rebuild the HQD via
init_mqdand save/restore the rptr, matching the
SDMAupdate_mqdstyle, instead of patching individual MQD fields in place. Keeps allupdate_mqdcallbacks consistent.Signed-off-by Jesse Zhang <[email protected]>Suggested-by Alexander Deucher <[email protected]>--- drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 44 ++++++++++++++++++++++++++ 1 file changed, 44 insertions(+)drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +0
-0@@ -4256,6 +4256,26 @@ static int gfx_v11_0_gfx_mqd_init(struct
amdgpu_device*adev, void *m,Quoted 16 lines
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +13
-0return 0 ; } +/* +* GFX update_mqd: init_mqd resets the ring rptr/wptr, so re-run it +to rebuild +* the HQD, then restore the saved rptr and forward the user wptr. +*/ +static int gfx_v11_0_gfx_mqd_update (struct amdgpu_device *adev,void *m, +struct amdgpu_mqd_prop *prop, +u64 user_wptr) { +struct v11_gfx_mqd *mqd = m; +u32 saved_rptr = mqd->cp_gfx_hqd_rptr; + +gfx_v11_0_gfx_mqd_init (adev, mqd, prop); +
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c static int gfx_v11_0_gfx_mqd_init(struct amdgpu_device *adev, void *m, · line 4274
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +3
-0+ mqd->cp_gfx_hqd_rptr = saved_rptr; + mqd->cp_gfx_hqd_wptr =lower_32_bits (user_wptr); + mqd->cp_gfx_hqd_wptr_hi =upper_32_bits (user_wptr);This seems fragile. Rather than doing it this way, can we just use
mqd_init()as is and add a newprop->modifyflag? Then we can use that ininit_mqdto skip state that should be retained from the MQD.
Makes sense, thanks Alex. In v3, I will drop the per-IP update_mqd callbacks and add a prop->modify flag (plus prop->user_wptr). init_mqd now keeps the context-saved rptr and uses user_wptr as the wptr .
Jesse
Quoted 57 lines
Alex
Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +4
-0+ +return 0 ; +} +static int gfx_v11_0_kgq_init_queue (struct amdgpu_ring *ring) { struct amdgpu_device *adev = ring->adev; @@ -4477,6 +4497,26@@ static int gfx_v11_0_compute_mqd_init(struct
amdgpu_device*adev, void*m,
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c static int gfx_v11_0_compute_mqd_init(struct amdgpu_device *adev, void *m,
Quoted 9 lines
return 0;}
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +6
-0+/* +* Compute update_mqd: init_mqd resets the ring rptr/wptr, so re-run +it to +* rebuild the HQD, then restore the saved rptr and forward the user wptr. +*/ +static int gfx_v11_0_compute_mqd_update(struct amdgpu_device *adev, void*m,
Quoted 36 lines
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +14
-0+ struct amdgpu_mqd_prop *prop, + u64 user_wptr) { +struct v11_compute_mqd *mqd = m; +u32 saved_rptr = mqd->cp_hqd_pq_rptr; + +gfx_v11_0_compute_mqd_init (adev, mqd, prop); + + mqd->cp_hqd_pq_rptr = saved_rptr; + mqd->cp_hqd_pq_wptr_lo =lower_32_bits (user_wptr); + mqd->cp_hqd_pq_wptr_hi =upper_32_bits (user_wptr); + +return 0 ; +} +static int gfx_v11_0_kiq_init_register (struct amdgpu_ring *ring) { struct amdgpu_device *adev = ring->adev; @@ -7271,11 +7311,15@@ static void
gfx_v11_0_set_mqd_funcs(struct amdgpu_device *adev)sizeof(struct v11_gfx_mqd); adev->mqds[AMDGPU_HW_IP_GFX].init_mqd = gfx_v11_0_gfx_mqd_init;drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +4
-0+ adev->mqds[AMDGPU_HW_IP_GFX ].update_mqd = + gfx_v11_0_gfx_mqd_update;/* set compute eng mqd */ adev->mqds[AMDGPU_HW_IP_COMPUTE ].mqd_size =sizeof (struct v11_compute_mqd ); adev->mqds[AMDGPU_HW_IP_COMPUTE ].init_mqd = gfx_v11_0_compute_mqd_init; + adev->mqds[AMDGPU_HW_IP_COMPUTE ].update_mqd = + gfx_v11_0_compute_mqd_update; } static void gfx_v11_0_set_user_wgp_inactive_bitmap_per_sh(struct
amdgpu_device*adev,
--
2.49.0
PATCH v2 4/10 drm/amdgpu/gfx12: implement compute and GFX update_mqd
In reply to Jesse ZhangImplement the update_mqd callback for gfx12 compute and GFX user queues. Save the read pointer, re-run init_mqd to rebuild the HQD, then restore the saved read pointer and forward the write pointer to the user wptr, so a re-enabled queue resumes at the first un-consumed packet rather than replaying the ring from 0.
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.
--- drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c | 44 ++++++++++++++++++++++++++ 1 file changed, 44 insertions(+)
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +44 -0
@@ -3096,6 +3096,26 @@ static int gfx_v12_0_gfx_mqd_init(struct amdgpu_device *adev, void *m,return 0 ; } +/* +* GFX update_mqd: init_mqd resets the ring rptr/wptr, so re-run it to rebuild +* the HQD, then restore the saved rptr and forward the user wptr. +*/ +static int gfx_v12_0_gfx_mqd_update (struct amdgpu_device *adev,void *m, +struct amdgpu_mqd_prop *prop, +u64 user_wptr) +{ +struct v12_gfx_mqd *mqd = m; +u32 saved_rptr = mqd->cp_gfx_hqd_rptr; + +gfx_v12_0_gfx_mqd_init (adev, mqd, prop); + + mqd->cp_gfx_hqd_rptr = saved_rptr; + mqd->cp_gfx_hqd_wptr =lower_32_bits (user_wptr); + mqd->cp_gfx_hqd_wptr_hi =upper_32_bits (user_wptr); + +return 0 ; +} +static int gfx_v12_0_kgq_init_queue (struct amdgpu_ring *ring) {struct amdgpu_device *adev = ring->adev;
@@ -3334,6 +3354,26 @@ static int gfx_v12_0_compute_mqd_init(struct amdgpu_device *adev, void *m,return 0 ; } +/* +* Compute update_mqd: init_mqd resets the ring rptr/wptr, so re-run it to +* rebuild the HQD, then restore the saved rptr and forward the user wptr. +*/ +static int gfx_v12_0_compute_mqd_update (struct amdgpu_device *adev,void *m, +struct amdgpu_mqd_prop *prop, +u64 user_wptr) +{ +struct v12_compute_mqd *mqd = m; +u32 saved_rptr = mqd->cp_hqd_pq_rptr; + +gfx_v12_0_compute_mqd_init (adev, mqd, prop); + + mqd->cp_hqd_pq_rptr = saved_rptr; + mqd->cp_hqd_pq_wptr_lo =lower_32_bits (user_wptr); + mqd->cp_hqd_pq_wptr_hi =upper_32_bits (user_wptr); + +return 0 ; +} +static int gfx_v12_0_kiq_init_register (struct amdgpu_ring *ring) {struct amdgpu_device *adev = ring->adev;
@@ -5543,11 +5583,15 @@ static void gfx_v12_0_set_mqd_funcs(struct amdgpu_device *adev)sizeof (struct v12_gfx_mqd ); adev->mqds[AMDGPU_HW_IP_GFX ].init_mqd = gfx_v12_0_gfx_mqd_init; + adev->mqds[AMDGPU_HW_IP_GFX ].update_mqd = + gfx_v12_0_gfx_mqd_update;/* set compute eng mqd */ adev->mqds[AMDGPU_HW_IP_COMPUTE ].mqd_size =sizeof (struct v12_compute_mqd ); adev->mqds[AMDGPU_HW_IP_COMPUTE ].init_mqd = gfx_v12_0_compute_mqd_init; + adev->mqds[AMDGPU_HW_IP_COMPUTE ].update_mqd = + gfx_v12_0_compute_mqd_update; } static void gfx_v12_0_set_user_wgp_inactive_bitmap_per_sh(struct amdgpu_device *adev,
Signature · 1 line
2.49.0
PATCH v2 5/10 drm/amdgpu/sdma6: implement update_mqd
In reply to Jesse ZhangImplement the update_mqd callback for sdma_v6_0 user queues. SDMA init_mqd leaves the ring rptr/wptr untouched, so re-run it to rebuild the HQD, then restore the saved read pointer and forward the user write pointer.
init_mqd also seeds ib_cntl from the live IB_CNTL register, which reads back IB_ENABLE=0 on a stopped/unmapped queue. Left as-is, the re-mapped engine drains the ring (rptr advances) but never executes the indirect buffers, silently dropping the packet queued while disabled. Force IB_ENABLE on.
--- drivers/gpu/drm/amd/amdgpu/sdma_v6_0.c | 29 ++++++++++++++++++++++++++ 1 file changed, 29 insertions(+)
drivers/gpu/drm/amd/amdgpu/sdma_v6_0.c +29 -0
@@ -884,10 +884,39 @@ static int sdma_v6_0_mqd_init(struct amdgpu_device *adev, void *mqd,return 0 ; } +/* +* SDMA update_mqd: init_mqd leaves the ring rptr/wptr alone, so re-run it to +* rebuild the HQD, then restore the saved rptr and forward the user wptr. +*/ +static int sdma_v6_0_mqd_update (struct amdgpu_device *adev,void *mqd, +struct amdgpu_mqd_prop *prop,u64 user_wptr) +{ +struct v11_sdma_mqd *m = mqd; +u32 saved_rptr = m->sdmax_rlcx_rb_rptr; +u32 saved_rptr_hi = m->sdmax_rlcx_rb_rptr_hi; + +sdma_v6_0_mqd_init (adev, mqd, prop); + + m->sdmax_rlcx_rb_rptr = saved_rptr; + m->sdmax_rlcx_rb_rptr_hi = saved_rptr_hi; + m->sdmax_rlcx_rb_wptr =lower_32_bits (user_wptr); + m->sdmax_rlcx_rb_wptr_hi =upper_32_bits (user_wptr); + +/* +* init_mqd seeds ib_cntl from the live IB_CNTL register, which reads +* back IB_ENABLE=0 on a stopped queue; the re-mapped engine would then +* drain the ring without executing the IBs. Force IB_ENABLE on. +*/ + m->sdmax_rlcx_ib_cntl |=SDMA0_QUEUE0_IB_CNTL__IB_ENABLE_MASK ; + +return 0 ; +} +static void sdma_v6_0_set_mqd_funcs (struct amdgpu_device *adev) { adev->mqds[AMDGPU_HW_IP_DMA ].mqd_size =sizeof (struct v11_sdma_mqd ); adev->mqds[AMDGPU_HW_IP_DMA ].init_mqd = sdma_v6_0_mqd_init; + adev->mqds[AMDGPU_HW_IP_DMA ].update_mqd = sdma_v6_0_mqd_update; }/**
Signature · 1 line
2.49.0
PATCH v2 6/10 drm/amdgpu/sdma7: implement update_mqd
In reply to Jesse ZhangImplement the update_mqd callback for sdma_v7_0 user queues. SDMA init_mqd leaves the ring rptr/wptr alone, so re-run it to rebuild the HQD, then restore the saved read pointer and forward the user write pointer. Force IB_ENABLE on, since init_mqd seeds ib_cntl from the live IB_CNTL register which reads back IB_ENABLE=0 on a stopped queue.
--- drivers/gpu/drm/amd/amdgpu/sdma_v7_0.c | 29 ++++++++++++++++++++++++++ 1 file changed, 29 insertions(+)
drivers/gpu/drm/amd/amdgpu/sdma_v7_0.c +29 -0
@@ -905,10 +905,39 @@ static int sdma_v7_0_mqd_init(struct amdgpu_device *adev, void *mqd,return 0 ; } +/* +* SDMA update_mqd: init_mqd leaves the ring rptr/wptr alone, so re-run it to +* rebuild the HQD, then restore the saved rptr and forward the user wptr. +*/ +static int sdma_v7_0_mqd_update (struct amdgpu_device *adev,void *mqd, +struct amdgpu_mqd_prop *prop,u64 user_wptr) +{ +struct v12_sdma_mqd *m = mqd; +u32 saved_rptr = m->sdmax_rlcx_rb_rptr; +u32 saved_rptr_hi = m->sdmax_rlcx_rb_rptr_hi; + +sdma_v7_0_mqd_init (adev, mqd, prop); + + m->sdmax_rlcx_rb_rptr = saved_rptr; + m->sdmax_rlcx_rb_rptr_hi = saved_rptr_hi; + m->sdmax_rlcx_rb_wptr =lower_32_bits (user_wptr); + m->sdmax_rlcx_rb_wptr_hi =upper_32_bits (user_wptr); + +/* +* init_mqd seeds ib_cntl from the live IB_CNTL register, which reads +* back IB_ENABLE=0 on a stopped queue; the re-mapped engine would then +* drain the ring without executing the IBs. Force IB_ENABLE on. +*/ + m->sdmax_rlcx_ib_cntl |=SDMA0_QUEUE0_IB_CNTL__IB_ENABLE_MASK ; + +return 0 ; +} +static void sdma_v7_0_set_mqd_funcs (struct amdgpu_device *adev) { adev->mqds[AMDGPU_HW_IP_DMA ].mqd_size =sizeof (struct v12_sdma_mqd ); adev->mqds[AMDGPU_HW_IP_DMA ].init_mqd = sdma_v7_0_mqd_init; + adev->mqds[AMDGPU_HW_IP_DMA ].update_mqd = sdma_v7_0_mqd_update; }/**
Signature · 1 line
2.49.0
PATCH v2 7/10 drm/amdgpu/sdma7_1: implement update_mqd
In reply to Jesse ZhangImplement the update_mqd callback for sdma_v7_1 user queues. SDMA init_mqd leaves the ring rptr/wptr alone, so re-run it to rebuild the HQD, then restore the saved read pointer and forward the user write pointer. Force IB_ENABLE on, since init_mqd seeds ib_cntl from the live IB_CNTL register which reads back IB_ENABLE=0 on a stopped queue.
--- drivers/gpu/drm/amd/amdgpu/sdma_v7_1.c | 29 ++++++++++++++++++++++++++ 1 file changed, 29 insertions(+)
drivers/gpu/drm/amd/amdgpu/sdma_v7_1.c +29 -0
@@ -889,10 +889,39 @@ static int sdma_v7_1_mqd_init(struct amdgpu_device *adev, void *mqd,return 0 ; } +/* +* SDMA update_mqd: init_mqd leaves the ring rptr/wptr alone, so re-run it to +* rebuild the HQD, then restore the saved rptr and forward the user wptr. +*/ +static int sdma_v7_1_mqd_update (struct amdgpu_device *adev,void *mqd, +struct amdgpu_mqd_prop *prop,u64 user_wptr) +{ +struct v12_sdma_mqd *m = mqd; +u32 saved_rptr = m->sdmax_rlcx_rb_rptr; +u32 saved_rptr_hi = m->sdmax_rlcx_rb_rptr_hi; + +sdma_v7_1_mqd_init (adev, mqd, prop); + + m->sdmax_rlcx_rb_rptr = saved_rptr; + m->sdmax_rlcx_rb_rptr_hi = saved_rptr_hi; + m->sdmax_rlcx_rb_wptr =lower_32_bits (user_wptr); + m->sdmax_rlcx_rb_wptr_hi =upper_32_bits (user_wptr); + +/* +* init_mqd seeds ib_cntl from the live IB_CNTL register, which reads +* back IB_ENABLE=0 on a stopped queue; the re-mapped engine would then +* drain the ring without executing the IBs. Force IB_ENABLE on. +*/ + m->sdmax_rlcx_ib_cntl |=SDMA0_SDMA_QUEUE0_IB_CNTL__IB_ENABLE_MASK ; + +return 0 ; +} +static void sdma_v7_1_set_mqd_funcs (struct amdgpu_device *adev) { adev->mqds[AMDGPU_HW_IP_DMA ].mqd_size =sizeof (struct v12_sdma_mqd ); adev->mqds[AMDGPU_HW_IP_DMA ].init_mqd = sdma_v7_1_mqd_init; + adev->mqds[AMDGPU_HW_IP_DMA ].update_mqd = sdma_v7_1_mqd_update; }/**
Signature · 1 line
2.49.0
PATCH v2 8/10 drm/amdgpu/mes_userqueue: route compute MODIFY through update_mqd
In reply to Jesse ZhangCall the per-IP update_mqd callback instead of init_mqd for a compute MODIFY, so a queue re-enabled after a queue_percentage == 0 disable keeps its ring position instead of wedging into a GPU reset (see the update_mqd callback commit for why). Add mes_userq_read_user_wptr() to read the current user wptr and forward it to the callback.
--- drivers/gpu/drm/amd/amdgpu/mes_userqueue.c | 28 +++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +27 -1
@@ -681,6 +681,25 @@ static int mes_userq_mqd_create(struct amdgpu_usermode_queue *queue,return r; } +/* +* Read the queue's current user wptr from its wptr poll BO. Packets queued +* while the queue was disabled advanced this value but not the MQD; the per-IP +* update_mqd callback forwards it back into the MQD so a re-enabled queue picks +* the work up. Returns 0 if the BO is not mapped. +*/ +static u64 mes_userq_read_user_wptr (struct amdgpu_usermode_queue *queue) +{ +u64 user_wptr =0 ; +void *wc =NULL ; + +if (queue->wptr_obj.obj && + !amdgpu_bo_kmap (queue->wptr_obj.obj, &wc) && wc) { + user_wptr = *(volatile u64 *)wc; +amdgpu_bo_kunmap (queue->wptr_obj.obj); + } +return user_wptr; +} +static int mes_userq_compute_mqd_update (struct amdgpu_usermode_queue *queue,struct drm_amdgpu_userq_in *args_in) {
@@ -695,6 +714,11 @@ static int mes_userq_compute_mqd_update(struct amdgpu_usermode_queue *queue,return -EINVAL ; } +if (!mqd_hw_default->update_mqd) { +DRM_ERROR ("Compute MQD update not supported on this IP\n" ); +return -EOPNOTSUPP ; + } + compute_mqd_v11 =memdup_user (u64_to_user_ptr (args_in->mqd), args_in->mqd_size);if (IS_ERR (compute_mqd_v11)) {DRM_ERROR ("Failed to read user MQD\n" );
@@ -708,7 +732,9 @@ 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; - retval = mqd_hw_default->init_mqd (adev, (void *)queue->mqd.cpu_ptr, userq_props); + retval = mqd_hw_default->update_mqd (adev, (void *)queue->mqd.cpu_ptr, + userq_props, +mes_userq_read_user_wptr (queue)); free:kfree (compute_mqd_v11);
Signature · 1 line
2.49.0
PATCH v2 9/10 drm/amdgpu/mes_userqueue: add GFX MODIFY support
In reply to Jesse ZhangAdd 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.
--- drivers/gpu/drm/amd/amdgpu/mes_userqueue.c | 55 ++++++++++++++++++++++ include/uapi/drm/amdgpu_drm.h | 6 +++ 2 files changed, 61 insertions(+)
drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +55 -0
@@ -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 ; }
include/uapi/drm/amdgpu_drm.h +6 -0
@@ -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 */
Signature · 1 line
2.49.0
PATCH v2 10/10 drm/amdgpu/mes_userqueue: add SDMA MODIFY support
In reply to Jesse ZhangAdd the SDMA case to the mqd_update dispatcher, routing it through the per-IP update_mqd callback like compute and GFX. Add a queue_percentage field to drm_amdgpu_userq_mqd_sdma_gfx11 and plumb it through create; 0 marks the queue inactive so it is not remapped, aligning KGD SDMA user queues with KFD (which controls activeness the same way via update_mqd_sdma).
--- drivers/gpu/drm/amd/amdgpu/mes_userqueue.c | 54 ++++++++++++++++++++++ include/uapi/drm/amdgpu_drm.h | 6 +++ 2 files changed, 60 insertions(+)
drivers/gpu/drm/amd/amdgpu/mes_userqueue.c +54 -0
@@ -626,6 +626,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);
@@ -641,6 +648,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); }
@@ -708,6 +716,50 @@ static u64 mes_userq_read_user_wptr(struct amdgpu_usermode_queue *queue)return user_wptr; } +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 ; + } + +if (!mqd_hw_default->update_mqd) { +DRM_ERROR ("SDMA MQD update not supported on this IP\n" ); +return -EOPNOTSUPP ; + } + + 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; + + retval = mqd_hw_default->update_mqd (adev, (void *)queue->mqd.cpu_ptr, + userq_props, +mes_userq_read_user_wptr (queue)); + +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) {
@@ -804,6 +856,8 @@ static int mes_userq_mqd_update(struct amdgpu_usermode_queue *queue, struct drm_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 +6 -0
@@ -465,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