<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
This was an old patch I accidentally sent out.  Please ignore.</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Alex<br>
</div>
<div id="appendonsend"></div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> Christian König <ckoenig.leichtzumerken@gmail.com><br>
<b>Sent:</b> Thursday, August 22, 2019 5:32 AM<br>
<b>To:</b> Alex Deucher <alexdeucher@gmail.com>; amd-gfx@lists.freedesktop.org <amd-gfx@lists.freedesktop.org><br>
<b>Cc:</b> Deucher, Alexander <Alexander.Deucher@amd.com><br>
<b>Subject:</b> Re: [PATCH 2/2] drm/radeon: use WAIT_REG_MEM special op for CP HDP flush</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt;">
<div class="PlainText">Every time we actually tried this it just ended in users reporting CP hangs.<br>
<br>
Christian.<br>
<br>
Am 22.08.19 um 00:20 schrieb Alex Deucher:<br>
> Flush via the ring works differently on CIK and requires a<br>
> special sequence.<br>
><br>
> Signed-off-by: Alex Deucher <alexander.deucher@amd.com><br>
> ---<br>
>   drivers/gpu/drm/radeon/cik.c | 73 +++++++++++++++++++++++++++-----------------<br>
>   1 file changed, 45 insertions(+), 28 deletions(-)<br>
><br>
> diff --git a/drivers/gpu/drm/radeon/cik.c b/drivers/gpu/drm/radeon/cik.c<br>
> index 0847367..03dd075 100644<br>
> --- a/drivers/gpu/drm/radeon/cik.c<br>
> +++ b/drivers/gpu/drm/radeon/cik.c<br>
> @@ -3485,6 +3485,48 @@ int cik_ring_test(struct radeon_device *rdev, struct radeon_ring *ring)<br>
>        return r;<br>
>   }<br>
>   <br>
> +static void cik_gfx_hdp_flush(struct radeon_device *rdev,<br>
> +                           int ridx)<br>
> +{<br>
> +     struct radeon_ring *ring = &rdev->ring[ridx];<br>
> +     u32 ref_and_mask;<br>
> +<br>
> +     switch (ring->idx) {<br>
> +     case CAYMAN_RING_TYPE_CP1_INDEX:<br>
> +     case CAYMAN_RING_TYPE_CP2_INDEX:<br>
> +             switch (ring->me) {<br>
> +             case 0:<br>
> +                     ref_and_mask = CP2 << ring->pipe;<br>
> +                     break;<br>
> +             case 1:<br>
> +                     ref_and_mask = CP6 << ring->pipe;<br>
> +                     break;<br>
> +             default:<br>
> +                     return;<br>
> +             }<br>
> +             break;<br>
> +     case RADEON_RING_TYPE_GFX_INDEX:<br>
> +             ref_and_mask = CP0;<br>
> +             break;<br>
> +     default:<br>
> +             return;<br>
> +     }<br>
> +<br>
> +     radeon_ring_write(ring, PACKET3(PACKET3_SET_UCONFIG_REG, 1));<br>
> +     radeon_ring_write(ring, ((CP_WAIT_REG_MEM_TIMEOUT -<br>
> +                               PACKET3_SET_UCONFIG_REG_START) >> 2));<br>
> +     radeon_ring_write(ring, 0xfff);<br>
> +<br>
> +     radeon_ring_write(ring, PACKET3(PACKET3_WAIT_REG_MEM, 5));<br>
> +     radeon_ring_write(ring, (WAIT_REG_MEM_OPERATION(1) | /* special op */<br>
> +                              WAIT_REG_MEM_FUNCTION(3))); /* == */<br>
> +     radeon_ring_write(ring, GPU_HDP_FLUSH_REQ >> 2);<br>
> +     radeon_ring_write(ring, GPU_HDP_FLUSH_DONE >> 2);<br>
> +     radeon_ring_write(ring, ref_and_mask);<br>
> +     radeon_ring_write(ring, ref_and_mask);<br>
> +     radeon_ring_write(ring, 0xa); /* poll interval */<br>
> +}<br>
> +<br>
>   /**<br>
>    * cik_fence_gfx_ring_emit - emit a fence on the gfx ring<br>
>    *<br>
> @@ -3511,15 +3553,7 @@ void cik_fence_gfx_ring_emit(struct radeon_device *rdev,<br>
>        radeon_ring_write(ring, fence->seq);<br>
>        radeon_ring_write(ring, 0);<br>
>        /* HDP flush */<br>
> -     /* We should be using the new WAIT_REG_MEM special op packet here<br>
> -      * but it causes the CP to hang<br>
> -      */<br>
> -     radeon_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 3));<br>
> -     radeon_ring_write(ring, (WRITE_DATA_ENGINE_SEL(0) |<br>
> -                              WRITE_DATA_DST_SEL(0)));<br>
> -     radeon_ring_write(ring, HDP_MEM_COHERENCY_FLUSH_CNTL >> 2);<br>
> -     radeon_ring_write(ring, 0);<br>
> -     radeon_ring_write(ring, 0);<br>
> +     cik_gfx_hdp_flush(rdev, fence->ring);<br>
>   }<br>
>   <br>
>   /**<br>
> @@ -3549,15 +3583,7 @@ void cik_fence_compute_ring_emit(struct radeon_device *rdev,<br>
>        radeon_ring_write(ring, fence->seq);<br>
>        radeon_ring_write(ring, 0);<br>
>        /* HDP flush */<br>
> -     /* We should be using the new WAIT_REG_MEM special op packet here<br>
> -      * but it causes the CP to hang<br>
> -      */<br>
> -     radeon_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 3));<br>
> -     radeon_ring_write(ring, (WRITE_DATA_ENGINE_SEL(0) |<br>
> -                              WRITE_DATA_DST_SEL(0)));<br>
> -     radeon_ring_write(ring, HDP_MEM_COHERENCY_FLUSH_CNTL >> 2);<br>
> -     radeon_ring_write(ring, 0);<br>
> -     radeon_ring_write(ring, 0);<br>
> +     cik_gfx_hdp_flush(rdev, fence->ring);<br>
>   }<br>
>   <br>
>   bool cik_semaphore_ring_emit(struct radeon_device *rdev,<br>
> @@ -5369,16 +5395,7 @@ void cik_vm_flush(struct radeon_device *rdev, int ridx, struct radeon_vm *vm)<br>
>        radeon_ring_write(ring, VMID(0));<br>
>   <br>
>        /* HDP flush */<br>
> -     /* We should be using the WAIT_REG_MEM packet here like in<br>
> -      * cik_fence_ring_emit(), but it causes the CP to hang in this<br>
> -      * context...<br>
> -      */<br>
> -     radeon_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 3));<br>
> -     radeon_ring_write(ring, (WRITE_DATA_ENGINE_SEL(0) |<br>
> -                              WRITE_DATA_DST_SEL(0)));<br>
> -     radeon_ring_write(ring, HDP_MEM_COHERENCY_FLUSH_CNTL >> 2);<br>
> -     radeon_ring_write(ring, 0);<br>
> -     radeon_ring_write(ring, 0);<br>
> +     cik_gfx_hdp_flush(rdev, ridx);<br>
>   <br>
>        /* bits 0-15 are the VM contexts0-15 */<br>
>        radeon_ring_write(ring, PACKET3(PACKET3_WRITE_DATA, 3));<br>
<br>
</div>
</span></font></div>
</body>
</html>