From: "Timur Kristóf" <timur.kristof@gmail.com>
To: Jesse Zhang <Jesse.Zhang@amd.com>, amd-gfx@lists.freedesktop.org
Cc: Alexander.Deucher@amd.com,
Christian Koenig <christian.koenig@amd.com>,
Lijo.Lazar@amd.com, Mario.Novales@amd.com, Manu.Rastogi@amd.com,
Jiongyu.Zhu@amd.com
Subject: Re: [PATCH v4 06/13] drm/amdgpu/gfx11: save and restore a gfx HQD
Date: Thu, 19 Nov 2026 12:36:15 +0100 [thread overview]
Message-ID: <7cca49f80a855f1cbbd7c77ed62ade1011155570.camel@gmail.com> (raw)
In-Reply-To: <20261105030612.726542-6-Jesse.Zhang@amd.com>
On Thu, 2026-11-05 at 11:05 +0800, Jesse Zhang wrote:
> Implement the gfx callbacks to save and restore a gfx HQD for gfx11:
> - save_hqd() saves the HQD offset, CSMD read pointer and write
> pointer
> of the gfx HQD of a doorbell, and whether the queue is the one
> connected to its pipe;
> - restore_hqd() writes them into the MQD after a reset, for MES to
> map
> the queue again where it was. A queue switched out of the pipe
> resumes
> from the preemption status the PFP saved in its MQD, also in the
> middle of an IB. The queue the pipe was executing has its state in
> the
> PFP, which the reset cleared: it restarts after the work submitted
> so
> far instead, and that work is dropped.
>
> v4: Rename to save_hqd()/restore_hqd() (Timur).
>
> Signed-off-by: Jesse Zhang <Jesse.Zhang@amd.com>
Reviewed-by: Timur Kristóf <timur.kristof@gmail.com>
> ---
> drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 83
> ++++++++++++++++++++++++++
> 1 file changed, 83 insertions(+)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c
> b/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c
> index 430b8f3743b2..798015689f0c 100644
> --- a/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c
> +++ b/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c
> @@ -365,6 +365,11 @@ static void gfx_v11_0_unset_safe_mode(struct
> amdgpu_device *adev, int xcc_id);
> static void gfx_v11_0_update_spm_vmid(struct amdgpu_device *adev,
> int xcc_id,
> unsigned int vmid);
> static void gfx_v11_0_userq_priv_fault_work(struct work_struct
> *work);
> +static bool gfx_v11_0_save_hqd(struct amdgpu_device *adev, u32
> doorbell_index,
> + struct amdgpu_gfx_saved_hqd *hqd);
> +static bool gfx_v11_0_restore_hqd(struct amdgpu_device *adev, void
> *m,
> + u32 ring_size,
> + const struct amdgpu_gfx_saved_hqd
> *hqd);
> static void gfx_v11_0_update_perf_clk(struct amdgpu_device *adev,
> bool enable);
>
> @@ -1150,6 +1155,8 @@ static const struct amdgpu_gfx_funcs
> gfx_v11_0_gfx_funcs = {
> .get_gfx_shadow_info = &gfx_v11_0_get_gfx_shadow_info,
> .get_hdp_flush_mask = &amdgpu_gfx_get_hdp_flush_mask,
> .detect_hung_queue = &gfx_v11_0_detect_hung_queue,
> + .save_hqd = &gfx_v11_0_save_hqd,
> + .restore_hqd = &gfx_v11_0_restore_hqd,
> };
>
> static int gfx_v11_0_gpu_early_init(struct amdgpu_device *adev)
> @@ -6770,6 +6777,82 @@ static void gfx_v11_0_emit_mem_sync(struct
> amdgpu_ring *ring)
> amdgpu_ring_write(ring, gcr_cntl); /* GCR_CNTL */
> }
>
> +#define GFX11_HPD_QUEUE_STATE_CONNECTED_MIN 3
> +#define GFX11_HPD_QUEUE_STATE_CONNECTED_MAX 15
> +
> +static bool gfx_v11_0_save_hqd(struct amdgpu_device *adev, u32
> doorbell_index,
> + struct amdgpu_gfx_saved_hqd *hqd)
> +{
> + u32 me, pipe, queue, status, state;
> +
> + memset(hqd, 0, sizeof(*hqd));
> + hqd->doorbell_index = doorbell_index;
> + if (!gfx_v11_0_detect_hung_queue(adev, doorbell_index, &me,
> &pipe, &queue))
> + return true;
> +
> + amdgpu_gfx_off_ctrl(adev, false);
> + mutex_lock(&adev->srbm_mutex);
> + soc21_grbm_select(adev, me, pipe, queue, 0);
> + hqd->on_hqd = RREG32_SOC15(GC, 0, regCP_GFX_HQD_ACTIVE) &
> + CP_GFX_HQD_ACTIVE__ACTIVE_MASK;
> + if (!hqd->on_hqd)
> + goto out;
> + hqd->mqd_addr = RREG32_SOC15(GC, 0, regCP_GFX_MQD_BASE_ADDR)
> |
> + (u64)RREG32_SOC15(GC, 0,
> regCP_GFX_MQD_BASE_ADDR_HI) << 32;
> + hqd->offset = RREG32_SOC15(GC, 0, regCP_GFX_HQD_OFFSET);
> + hqd->csmd_rptr = RREG32_SOC15(GC, 0,
> regCP_GFX_HQD_CSMD_RPTR);
> + hqd->wptr = RREG32_SOC15(GC, 0, regCP_GFX_HQD_WPTR) |
> + (u64)RREG32_SOC15(GC, 0, regCP_GFX_HQD_WPTR_HI)
> << 32;
> + status = RREG32_SOC15(GC, 0, regCP_GFX_HPD_STATUS0);
> + state = REG_GET_FIELD(status, CP_GFX_HPD_STATUS0,
> QUEUE_STATE);
> + hqd->connected =
> + state >= GFX11_HPD_QUEUE_STATE_CONNECTED_MIN &&
> + state <= GFX11_HPD_QUEUE_STATE_CONNECTED_MAX &&
> + REG_GET_FIELD(status, CP_GFX_HPD_STATUS0,
> MAPPED_QUEUE) == queue;
> +out:
> + soc21_grbm_select(adev, 0, 0, 0, 0);
> + mutex_unlock(&adev->srbm_mutex);
> + amdgpu_gfx_off_ctrl(adev, true);
> +
> + return true;
> +}
> +
> +static bool gfx_v11_0_restore_hqd(struct amdgpu_device *adev, void
> *m,
> + u32 ring_size,
> + const struct amdgpu_gfx_saved_hqd
> *hqd)
> +{
> + struct v11_gfx_mqd *mqd = m;
> + u32 wptr = lower_32_bits(hqd->wptr) & ((ring_size >> 2) -
> 1);
> + u32 *status;
> +
> + /*
> + * MQD dwords 32-41 (reserved_32..41) are the PFP preemption
> status,
> + * mcbp_status_pfp: the offset and chained IB size and
> address of IB1
> + * (32-35) and IB2 (36-39), rb_preempt (40: preempted in the
> ring) and
> + * completion_status (41: 0 IB not started, 1 preempted
> inside an IB,
> + * 2 IB completed, 3 IB resumed). The PFP saves it when the
> queue is
> + * switched out of the pipe and resumes from it when the
> queue runs
> + * again, at the HQD offset. That survives the reset for a
> queue that
> + * was switched out. The queue the pipe executed has its
> state in the
> + * PFP, which the reset cleared: restart it at the write
> pointer with
> + * no IB to resume, and drop its work in flight.
> + */
> + if (hqd->connected) {
> + mqd->cp_gfx_hqd_offset = wptr;
> + mqd->cp_gfx_hqd_csmd_rptr = wptr;
> + for (status = &mqd->reserved_32; status <= &mqd-
> >reserved_41; status++)
> + *status = 0;
> + } else {
> + mqd->cp_gfx_hqd_offset = hqd->offset;
> + mqd->cp_gfx_hqd_csmd_rptr = hqd->csmd_rptr;
> + }
> + mqd->cp_gfx_hqd_wptr = lower_32_bits(hqd->wptr);
> + mqd->cp_gfx_hqd_wptr_hi = upper_32_bits(hqd->wptr);
> + mqd->cp_gfx_hqd_active = 0;
> +
> + return hqd->connected;
> +}
> +
> static int gfx_v11_0_reset_kgq(struct amdgpu_ring *ring,
> unsigned int vmid,
> struct amdgpu_fence *timedout_fence)
next prev parent reply other threads:[~2026-11-19 11:36 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-05 3:05 [PATCH v4 01/13] drm/amdgpu: pass the device to the multi ring reset helpers Jesse Zhang
2026-11-05 3:05 ` [PATCH v4 02/13] drm/amdgpu/ring: During multi-queue reset, only call begin helper if needed Jesse Zhang
2026-11-11 23:52 ` Daniel Campos Ramos
2026-11-19 11:34 ` Timur Kristóf
2026-11-05 3:05 ` [PATCH v4 03/13] drm/amdgpu: add an engine scope to the IP block soft reset Jesse Zhang
2026-11-19 11:35 ` Timur Kristóf
2026-11-05 3:05 ` [PATCH v4 04/13] drm/amdgpu/gfx: add callbacks to save and restore a gfx HQD Jesse Zhang
2026-11-19 11:35 ` Timur Kristóf
2026-11-05 3:05 ` [PATCH v4 05/13] drm/amdgpu/gfx12: " Jesse Zhang
2026-11-19 11:35 ` Timur Kristóf
2026-11-05 3:05 ` [PATCH v4 06/13] drm/amdgpu/gfx11: " Jesse Zhang
2026-11-19 11:36 ` Timur Kristóf [this message]
2026-11-05 3:05 ` [PATCH v4 07/13] drm/amdgpu/userq: add a helper to signal the fences of a queue up to a point Jesse Zhang
2026-11-19 11:36 ` Timur Kristóf
2026-11-05 3:05 ` [PATCH v4 08/13] drm/amdgpu/userq: add helpers to keep the user queues of one engine across a reset Jesse Zhang
2026-11-19 11:36 ` Timur Kristóf
2026-11-05 3:05 ` [PATCH v4 09/13] drm/amdgpu/gfx12: add a gfx engine soft reset Jesse Zhang
2026-11-19 11:42 ` Timur Kristóf
2026-11-05 3:05 ` [PATCH v4 10/13] drm/amdgpu/gfx11: " Jesse Zhang
2026-11-19 11:47 ` Timur Kristóf
2026-11-05 3:05 ` [PATCH v4 11/13] drm/amdgpu/userq: reset the gfx engine when a gfx user queue reset fails Jesse Zhang
2026-11-19 11:47 ` Timur Kristóf
2026-11-05 3:05 ` [PATCH v4 12/13] drm/amdgpu/gfx12: enable the gfx engine soft reset Jesse Zhang
2026-11-19 11:47 ` Timur Kristóf
2026-11-05 3:05 ` [PATCH v4 13/13] drm/amdgpu/gfx11: " Jesse Zhang
2026-11-19 11:47 ` Timur Kristóf
2026-11-10 2:06 ` [PATCH v4 01/13] drm/amdgpu: pass the device to the multi ring reset helpers Zhang, Jesse(Jie)
2026-11-11 15:28 ` Timur Kristóf
2026-11-19 11:33 ` Timur Kristóf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=7cca49f80a855f1cbbd7c77ed62ade1011155570.camel@gmail.com \
--to=timur.kristof@gmail.com \
--cc=Alexander.Deucher@amd.com \
--cc=Jesse.Zhang@amd.com \
--cc=Jiongyu.Zhu@amd.com \
--cc=Lijo.Lazar@amd.com \
--cc=Manu.Rastogi@amd.com \
--cc=Mario.Novales@amd.com \
--cc=amd-gfx@lists.freedesktop.org \
--cc=christian.koenig@amd.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.