A gfx engine reset clears the HQD registers of the gfx queues, including
the only copy of the ring position of the queues MES didn't preempt.
MES doesn't save them in the MQD either when the engine hangs.

Add struct amdgpu_gfx_saved_hqd for that state, and gfx callbacks for
the gfx IP, which knows its registers and the layout of its MQD:
- save_hqd() saves the state of the gfx HQD of a doorbell;
- restore_hqd() writes it into the MQD after the reset, for MES to load
  it into the HQD when it maps the queue again.

v4: Rename to save_hqd()/restore_hqd() and struct amdgpu_gfx_saved_hqd
    (Timur).

Reviewed-by: Timur Kristóf <[email protected]>
Signed-off-by: Jesse Zhang <[email protected]>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h
index 99739b00c35f..ec77f24db0e2 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h
@@ -340,6 +340,17 @@ struct amdgpu_gfx_shadow_info {
        u32 eop_alignment;
 };
 
+/* State of a gfx HQD that a gfx engine reset clears. */
+struct amdgpu_gfx_saved_hqd {
+       u32     doorbell_index;
+       u64     mqd_addr;       /* the MQD loaded in the HQD */
+       bool    on_hqd;
+       u64     wptr;
+       u32     offset;
+       u32     csmd_rptr;
+       bool    connected;      /* the queue the pipe executes */
+};
+
 struct amdgpu_gfx_funcs {
        /* get the gpu clock counter */
        uint64_t (*get_gpu_clock_counter)(struct amdgpu_device *adev);
@@ -374,6 +385,17 @@ struct amdgpu_gfx_funcs {
        /* find the gfx HQD slot (me/pipe/queue) for a doorbell */
        bool (*detect_hung_queue)(struct amdgpu_device *adev, u32 
doorbell_index,
                                  u32 *me, u32 *pipe, u32 *queue);
+       /* save the state of the gfx HQD of a doorbell, if it has one */
+       bool (*save_hqd)(struct amdgpu_device *adev, u32 doorbell_index,
+                        struct amdgpu_gfx_saved_hqd *hqd);
+       /*
+        * write the HQD state saved by save_hqd() into a gfx MQD, for MES to
+        * load it into the HQD when it maps the queue again;
+        * true if the work up to hqd->wptr was dropped
+        */
+       bool (*restore_hqd)(struct amdgpu_device *adev, void *mqd,
+                           u32 ring_size,
+                           const struct amdgpu_gfx_saved_hqd *hqd);
 };
 
 struct sq_work {
-- 
2.50.1

Reply via email to