<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body>
<p style="font-family:Arial;font-size:10pt;color:#0000FF;margin:5pt;" align="Left">
[AMD Official Use Only]<br>
</p>
<br>
<div>
<div dir="auto" style="direction: ltr; margin: 0px; padding: 0px; font-family: sans-serif; font-size: 11pt; color: black; text-align: left;">
well, If IB test fails because we use gtt domain or</div>
<div dir="auto" style="direction: ltr; margin: 0px; padding: 0px; font-family: sans-serif; font-size: 11pt; color: black; text-align: left;">
the above 256MB vram<span style="font-size: 11pt;">. Then the failure</span><span style="font-size: 11pt;"> is expected. </span></div>
<div dir="auto" style="direction: ltr; margin: 0px; padding: 0px; font-family: sans-serif; font-size: 11pt; color: black; text-align: left;">
<span style="font-size: 11pt;">Doesn't IB test exist to detect such issue?</span></div>
<div id="id-6c97172e-0116-45da-8423-7906d63f733c" class="ms-outlook-mobile-reference-message">
<div style="font-family: sans-serif; font-size: 12pt; color: rgb(0, 0, 0);"><br>
</div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg"><strong>发件人:</strong> Koenig, Christian <Christian.Koenig@amd.com><br>
<strong>发送时间:</strong> 2021年9月9日星期四 15:16<br>
<strong>收件人:</strong> Pan, Xinhui; amd-gfx@lists.freedesktop.org<br>
<strong>抄送:</strong> Deucher, Alexander<br>
<strong>主题:</strong> Re: [PATCH 2/2] drm/amdgpu: alloc IB extra msg from IB pool<br>
</div>
<br>
<meta name="Generator" content="Microsoft Exchange Server">
<!-- converted from text --><style><!-- .EmailQuote { margin-left: 1pt; padding-left: 4pt; border-left: #800000 2px solid; } --></style><font size="2"><span style="font-size:11pt;">
<div class="PlainText">Am 09.09.21 um 07:55 schrieb Pan, Xinhui:<br>
> [AMD Official Use Only]<br>
><br>
> There is one dedicated IB pool for IB test. So lets use it for extra msg<br>
> too.<br>
><br>
> For UVD on older HW, use one reserved BO at specific range.<br>
><br>
> Signed-off-by: xinhui pan <xinhui.pan@amd.com><br>
> ---<br>
>   drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c | 173 +++++++++++++++---------<br>
>   drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.h |   1 +<br>
>   drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c |  18 +--<br>
>   drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c |  99 ++++++--------<br>
>   drivers/gpu/drm/amd/amdgpu/uvd_v6_0.c   |  28 ++--<br>
>   drivers/gpu/drm/amd/amdgpu/uvd_v7_0.c   |  28 ++--<br>
>   6 files changed, 185 insertions(+), 162 deletions(-)<br>
<br>
Please split that up into one patch for UVD, one for VCE and a third for <br>
VCN.<br>
<br>
><br>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c<br>
> index d451c359606a..733cfc848c6c 100644<br>
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c<br>
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c<br>
> @@ -299,8 +299,36 @@ int amdgpu_uvd_sw_init(struct amdgpu_device *adev)<br>
>          }<br>
><br>
>          /* from uvd v5.0 HW addressing capacity increased to 64 bits */<br>
> -       if (!amdgpu_device_ip_block_version_cmp(adev, AMD_IP_BLOCK_TYPE_UVD, 5, 0))<br>
> +       if (!amdgpu_device_ip_block_version_cmp(adev, AMD_IP_BLOCK_TYPE_UVD, 5, 0)) {<br>
>                  adev->uvd.address_64_bit = true;<br>
<br>
Yeah, that's exactly what I'm trying to avoid.<br>
<br>
We should use the BO approach both for old and new UVD blocks, just <br>
making sure that we place it correctly for the old ones.<br>
<br>
This way we have much lower chance of breaking the old stuff.<br>
<br>
Thanks,<br>
Christian.<br>
<br>
> +       } else {<br>
> +               struct amdgpu_bo *bo = NULL;<br>
> +               void *addr;<br>
> +<br>
> +               r = amdgpu_bo_create_reserved(adev, PAGE_SIZE, PAGE_SIZE,<br>
> +                               AMDGPU_GEM_DOMAIN_VRAM,<br>
> +                               &bo, NULL, &addr);<br>
> +               if (r)<br>
> +                       return r;<br>
> +               amdgpu_bo_kunmap(bo);<br>
> +               amdgpu_bo_unpin(bo);<br>
> +               r = amdgpu_bo_pin_restricted(bo, AMDGPU_GEM_DOMAIN_VRAM,<br>
> +                               0, 256 << 20);<br>
> +               if (r) {<br>
> +                       amdgpu_bo_unreserve(bo);<br>
> +                       amdgpu_bo_unref(&bo);<br>
> +                       return r;<br>
> +               }<br>
> +               r = amdgpu_bo_kmap(bo, &addr);<br>
> +               if (r) {<br>
> +                       amdgpu_bo_unpin(bo);<br>
> +                       amdgpu_bo_unreserve(bo);<br>
> +                       amdgpu_bo_unref(&bo);<br>
> +                       return r;<br>
> +               }<br>
> +               adev->uvd.ib_bo = bo;<br>
> +               amdgpu_bo_unreserve(bo);<br>
> +       }<br>
><br>
>          switch (adev->asic_type) {<br>
>          case CHIP_TONGA:<br>
> @@ -342,6 +370,7 @@ int amdgpu_uvd_sw_fini(struct amdgpu_device *adev)<br>
>                  for (i = 0; i < AMDGPU_MAX_UVD_ENC_RINGS; ++i)<br>
>                          amdgpu_ring_fini(&adev->uvd.inst[j].ring_enc[i]);<br>
>          }<br>
> +       amdgpu_bo_free_kernel(&adev->uvd.ib_bo, NULL, NULL);<br>
>          release_firmware(adev->uvd.fw);<br>
><br>
>          return 0;<br>
> @@ -1066,7 +1095,7 @@ int amdgpu_uvd_ring_parse_cs(struct amdgpu_cs_parser *parser, uint32_t ib_idx)<br>
>          return 0;<br>
>   }<br>
><br>
> -static int amdgpu_uvd_send_msg(struct amdgpu_ring *ring, struct amdgpu_bo *bo,<br>
> +static int amdgpu_uvd_send_msg(struct amdgpu_ring *ring, uint64_t addr,<br>
>                                 bool direct, struct dma_fence **fence)<br>
>   {<br>
>          struct amdgpu_device *adev = ring->adev;<br>
> @@ -1074,29 +1103,15 @@ static int amdgpu_uvd_send_msg(struct amdgpu_ring *ring, struct amdgpu_bo *bo,<br>
>          struct amdgpu_job *job;<br>
>          struct amdgpu_ib *ib;<br>
>          uint32_t data[4];<br>
> -       uint64_t addr;<br>
>          long r;<br>
>          int i;<br>
>          unsigned offset_idx = 0;<br>
>          unsigned offset[3] = { UVD_BASE_SI, 0, 0 };<br>
><br>
> -       amdgpu_bo_kunmap(bo);<br>
> -       amdgpu_bo_unpin(bo);<br>
> -<br>
> -       if (!ring->adev->uvd.address_64_bit) {<br>
> -               struct ttm_operation_ctx ctx = { true, false };<br>
> -<br>
> -               amdgpu_bo_placement_from_domain(bo, AMDGPU_GEM_DOMAIN_VRAM);<br>
> -               amdgpu_uvd_force_into_uvd_segment(bo);<br>
> -               r = ttm_bo_validate(&bo->tbo, &bo->placement, &ctx);<br>
> -               if (r)<br>
> -                       goto err;<br>
> -       }<br>
> -<br>
>          r = amdgpu_job_alloc_with_ib(adev, 64, direct ? AMDGPU_IB_POOL_DIRECT :<br>
>                                       AMDGPU_IB_POOL_DELAYED, &job);<br>
>          if (r)<br>
> -               goto err;<br>
> +               return r;<br>
><br>
>          if (adev->asic_type >= CHIP_VEGA10) {<br>
>                  offset_idx = 1 + ring->me;<br>
> @@ -1110,7 +1125,6 @@ static int amdgpu_uvd_send_msg(struct amdgpu_ring *ring, struct amdgpu_bo *bo,<br>
>          data[3] = PACKET0(offset[offset_idx] + UVD_NO_OP, 0);<br>
><br>
>          ib = &job->ibs[0];<br>
> -       addr = amdgpu_bo_gpu_offset(bo);<br>
>          ib->ptr[0] = data[0];<br>
>          ib->ptr[1] = addr;<br>
>          ib->ptr[2] = data[1];<br>
> @@ -1123,33 +1137,13 @@ static int amdgpu_uvd_send_msg(struct amdgpu_ring *ring, struct amdgpu_bo *bo,<br>
>          }<br>
>          ib->length_dw = 16;<br>
><br>
> -       if (direct) {<br>
> -               r = dma_resv_wait_timeout(bo->tbo.base.resv, true, false,<br>
> -                                         msecs_to_jiffies(10));<br>
> -               if (r == 0)<br>
> -                       r = -ETIMEDOUT;<br>
> -               if (r < 0)<br>
> -                       goto err_free;<br>
> -<br>
> +       if (direct)<br>
>                  r = amdgpu_job_submit_direct(job, ring, &f);<br>
> -               if (r)<br>
> -                       goto err_free;<br>
> -       } else {<br>
> -               r = amdgpu_sync_resv(adev, &job->sync, bo->tbo.base.resv,<br>
> -                                    AMDGPU_SYNC_ALWAYS,<br>
> -                                    AMDGPU_FENCE_OWNER_UNDEFINED);<br>
> -               if (r)<br>
> -                       goto err_free;<br>
> -<br>
> +       else<br>
>                  r = amdgpu_job_submit(job, &adev->uvd.entity,<br>
> -                                     AMDGPU_FENCE_OWNER_UNDEFINED, &f);<br>
> -               if (r)<br>
> -                       goto err_free;<br>
> -       }<br>
> -<br>
> -       amdgpu_bo_fence(bo, f, false);<br>
> -       amdgpu_bo_unreserve(bo);<br>
> -       amdgpu_bo_unref(&bo);<br>
> +                               AMDGPU_FENCE_OWNER_UNDEFINED, &f);<br>
> +       if (r)<br>
> +               goto err_free;<br>
><br>
>          if (fence)<br>
>                  *fence = dma_fence_get(f);<br>
> @@ -1159,10 +1153,6 @@ static int amdgpu_uvd_send_msg(struct amdgpu_ring *ring, struct amdgpu_bo *bo,<br>
><br>
>   err_free:<br>
>          amdgpu_job_free(job);<br>
> -<br>
> -err:<br>
> -       amdgpu_bo_unreserve(bo);<br>
> -       amdgpu_bo_unref(&bo);<br>
>          return r;<br>
>   }<br>
><br>
> @@ -1173,16 +1163,31 @@ int amdgpu_uvd_get_create_msg(struct amdgpu_ring *ring, uint32_t handle,<br>
>                                struct dma_fence **fence)<br>
>   {<br>
>          struct amdgpu_device *adev = ring->adev;<br>
> -       struct amdgpu_bo *bo = NULL;<br>
> +       struct amdgpu_bo *bo = adev->uvd.ib_bo;<br>
> +       struct dma_fence *f = NULL;<br>
> +       struct amdgpu_ib ib;<br>
>          uint32_t *msg;<br>
>          int r, i;<br>
><br>
> -       r = amdgpu_bo_create_reserved(adev, 1024, PAGE_SIZE,<br>
> -                                     AMDGPU_GEM_DOMAIN_GTT,<br>
> -                                     &bo, NULL, (void **)&msg);<br>
> -       if (r)<br>
> -               return r;<br>
> -<br>
> +       if (bo) {<br>
> +               r = ttm_bo_reserve(&bo->tbo, true, true, NULL);<br>
> +               if (r)<br>
> +                       return r;<br>
> +               r = dma_resv_wait_timeout(bo->tbo.base.resv, true, false,<br>
> +                               msecs_to_jiffies(10));<br>
> +               if (r == 0)<br>
> +                       r = -ETIMEDOUT;<br>
> +               if (r < 0)<br>
> +                       goto err;<br>
> +               ib.gpu_addr = amdgpu_bo_gpu_offset(bo);<br>
> +               msg = amdgpu_bo_kptr(bo);<br>
> +       } else {<br>
> +               memset(&ib, 0, sizeof(ib));<br>
> +               r = amdgpu_ib_get(adev, NULL, PAGE_SIZE,<br>
> +                               AMDGPU_IB_POOL_DIRECT,<br>
> +                               &ib);<br>
> +               msg = ib.ptr;<br>
> +       }<br>
>          /* stitch together an UVD create msg */<br>
>          msg[0] = cpu_to_le32(0x00000de4);<br>
>          msg[1] = cpu_to_le32(0x00000000);<br>
> @@ -1198,23 +1203,52 @@ int amdgpu_uvd_get_create_msg(struct amdgpu_ring *ring, uint32_t handle,<br>
>          for (i = 11; i < 1024; ++i)<br>
>                  msg[i] = cpu_to_le32(0x0);<br>
><br>
> -       return amdgpu_uvd_send_msg(ring, bo, true, fence);<br>
> +       r = amdgpu_uvd_send_msg(ring, ib.gpu_addr, true, &f);<br>
> +       if (r)<br>
> +               goto err;<br>
> +       if (bo)<br>
> +               amdgpu_bo_fence(bo, f, false);<br>
> +       if (fence)<br>
> +               *fence = dma_fence_get(f);<br>
> +err:<br>
> +       if (bo)<br>
> +               amdgpu_bo_unreserve(bo);<br>
> +       else<br>
> +               amdgpu_ib_free(adev, &ib, f);<br>
> +       dma_fence_put(f);<br>
> +       return r;<br>
>   }<br>
><br>
>   int amdgpu_uvd_get_destroy_msg(struct amdgpu_ring *ring, uint32_t handle,<br>
>                                 bool direct, struct dma_fence **fence)<br>
>   {<br>
>          struct amdgpu_device *adev = ring->adev;<br>
> -       struct amdgpu_bo *bo = NULL;<br>
> +       struct amdgpu_bo *bo = adev->uvd.ib_bo;<br>
> +       struct dma_fence *f = NULL;<br>
> +       struct amdgpu_ib ib;<br>
>          uint32_t *msg;<br>
>          int r, i;<br>
><br>
> -       r = amdgpu_bo_create_reserved(adev, 1024, PAGE_SIZE,<br>
> -                                     AMDGPU_GEM_DOMAIN_GTT,<br>
> -                                     &bo, NULL, (void **)&msg);<br>
> -       if (r)<br>
> -               return r;<br>
> -<br>
> +       if (bo) {<br>
> +               r = ttm_bo_reserve(&bo->tbo, true, true, NULL);<br>
> +               if (r)<br>
> +                       return r;<br>
> +               r = dma_resv_wait_timeout(bo->tbo.base.resv, true, false,<br>
> +                               msecs_to_jiffies(10));<br>
> +               if (r == 0)<br>
> +                       r = -ETIMEDOUT;<br>
> +               if (r < 0)<br>
> +                       goto err;<br>
> +               ib.gpu_addr = amdgpu_bo_gpu_offset(bo);<br>
> +               msg = amdgpu_bo_kptr(bo);<br>
> +       } else {<br>
> +               memset(&ib, 0, sizeof(ib));<br>
> +               r = amdgpu_ib_get(adev, NULL, PAGE_SIZE,<br>
> +                               direct ?<br>
> +                               AMDGPU_IB_POOL_DIRECT : AMDGPU_IB_POOL_DELAYED,<br>
> +                               &ib);<br>
> +               msg = ib.ptr;<br>
> +       }<br>
>          /* stitch together an UVD destroy msg */<br>
>          msg[0] = cpu_to_le32(0x00000de4);<br>
>          msg[1] = cpu_to_le32(0x00000002);<br>
> @@ -1223,7 +1257,20 @@ int amdgpu_uvd_get_destroy_msg(struct amdgpu_ring *ring, uint32_t handle,<br>
>          for (i = 4; i < 1024; ++i)<br>
>                  msg[i] = cpu_to_le32(0x0);<br>
><br>
> -       return amdgpu_uvd_send_msg(ring, bo, direct, fence);<br>
> +       r = amdgpu_uvd_send_msg(ring, ib.gpu_addr, true, &f);<br>
> +       if (r)<br>
> +               goto err;<br>
> +       if (bo)<br>
> +               amdgpu_bo_fence(bo, f, false);<br>
> +       if (fence)<br>
> +               *fence = dma_fence_get(f);<br>
> +err:<br>
> +       if (bo)<br>
> +               amdgpu_bo_unreserve(bo);<br>
> +       else<br>
> +               amdgpu_ib_free(adev, &ib, f);<br>
> +       dma_fence_put(f);<br>
> +       return r;<br>
>   }<br>
><br>
>   static void amdgpu_uvd_idle_work_handler(struct work_struct *work)<br>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.h<br>
> index edbb8194ee81..76ac9699885d 100644<br>
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.h<br>
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.h<br>
> @@ -68,6 +68,7 @@ struct amdgpu_uvd {<br>
>          /* store image width to adjust nb memory state */<br>
>          unsigned                decode_image_width;<br>
>          uint32_t                keyselect;<br>
> +       struct amdgpu_bo        *ib_bo;<br>
>   };<br>
><br>
>   int amdgpu_uvd_sw_init(struct amdgpu_device *adev);<br>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c<br>
> index e9fdf49d69e8..45d98694db18 100644<br>
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c<br>
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c<br>
> @@ -82,7 +82,6 @@ MODULE_FIRMWARE(FIRMWARE_VEGA20);<br>
><br>
>   static void amdgpu_vce_idle_work_handler(struct work_struct *work);<br>
>   static int amdgpu_vce_get_create_msg(struct amdgpu_ring *ring, uint32_t handle,<br>
> -                                    struct amdgpu_bo *bo,<br>
>                                       struct dma_fence **fence);<br>
>   static int amdgpu_vce_get_destroy_msg(struct amdgpu_ring *ring, uint32_t handle,<br>
>                                        bool direct, struct dma_fence **fence);<br>
> @@ -441,7 +440,6 @@ void amdgpu_vce_free_handles(struct amdgpu_device *adev, struct drm_file *filp)<br>
>    * Open up a stream for HW test<br>
>    */<br>
>   static int amdgpu_vce_get_create_msg(struct amdgpu_ring *ring, uint32_t handle,<br>
> -                                    struct amdgpu_bo *bo,<br>
>                                       struct dma_fence **fence)<br>
>   {<br>
>          const unsigned ib_size_dw = 1024;<br>
> @@ -451,14 +449,13 @@ static int amdgpu_vce_get_create_msg(struct amdgpu_ring *ring, uint32_t handle,<br>
>          uint64_t addr;<br>
>          int i, r;<br>
><br>
> -       r = amdgpu_job_alloc_with_ib(ring->adev, ib_size_dw * 4,<br>
> +       r = amdgpu_job_alloc_with_ib(ring->adev, ib_size_dw * 4 + PAGE_SIZE,<br>
>                                       AMDGPU_IB_POOL_DIRECT, &job);<br>
>          if (r)<br>
>                  return r;<br>
><br>
>          ib = &job->ibs[0];<br>
> -<br>
> -       addr = amdgpu_bo_gpu_offset(bo);<br>
> +       addr = ib->gpu_addr + ib_size_dw * 4;<br>
><br>
>          /* stitch together an VCE create msg */<br>
>          ib->length_dw = 0;<br>
> @@ -1134,20 +1131,13 @@ int amdgpu_vce_ring_test_ring(struct amdgpu_ring *ring)<br>
>   int amdgpu_vce_ring_test_ib(struct amdgpu_ring *ring, long timeout)<br>
>   {<br>
>          struct dma_fence *fence = NULL;<br>
> -       struct amdgpu_bo *bo = NULL;<br>
>          long r;<br>
><br>
>          /* skip vce ring1/2 ib test for now, since it's not reliable */<br>
>          if (ring != &ring->adev->vce.ring[0])<br>
>                  return 0;<br>
><br>
> -       r = amdgpu_bo_create_reserved(ring->adev, 512, PAGE_SIZE,<br>
> -                                     AMDGPU_GEM_DOMAIN_VRAM,<br>
> -                                     &bo, NULL, NULL);<br>
> -       if (r)<br>
> -               return r;<br>
> -<br>
> -       r = amdgpu_vce_get_create_msg(ring, 1, bo, NULL);<br>
> +       r = amdgpu_vce_get_create_msg(ring, 1, NULL);<br>
>          if (r)<br>
>                  goto error;<br>
><br>
> @@ -1163,8 +1153,6 @@ int amdgpu_vce_ring_test_ib(struct amdgpu_ring *ring, long timeout)<br>
><br>
>   error:<br>
>          dma_fence_put(fence);<br>
> -       amdgpu_bo_unreserve(bo);<br>
> -       amdgpu_bo_free_kernel(&bo, NULL, NULL);<br>
>          return r;<br>
>   }<br>
><br>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c<br>
> index 561296a85b43..b60d5f01fdae 100644<br>
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c<br>
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c<br>
> @@ -541,15 +541,14 @@ int amdgpu_vcn_dec_sw_ring_test_ring(struct amdgpu_ring *ring)<br>
>   }<br>
><br>
>   static int amdgpu_vcn_dec_send_msg(struct amdgpu_ring *ring,<br>
> -                                  struct amdgpu_bo *bo,<br>
> -                                  struct dma_fence **fence)<br>
> +               struct amdgpu_ib *ib_msg,<br>
> +               struct dma_fence **fence)<br>
>   {<br>
>          struct amdgpu_device *adev = ring->adev;<br>
>          struct dma_fence *f = NULL;<br>
>          struct amdgpu_job *job;<br>
>          struct amdgpu_ib *ib;<br>
> -       uint64_t addr;<br>
> -       void *msg = NULL;<br>
> +       uint64_t addr = ib_msg->gpu_addr;<br>
>          int i, r;<br>
><br>
>          r = amdgpu_job_alloc_with_ib(adev, 64,<br>
> @@ -558,8 +557,6 @@ static int amdgpu_vcn_dec_send_msg(struct amdgpu_ring *ring,<br>
>                  goto err;<br>
><br>
>          ib = &job->ibs[0];<br>
> -       addr = amdgpu_bo_gpu_offset(bo);<br>
> -       msg = amdgpu_bo_kptr(bo);<br>
>          ib->ptr[0] = PACKET0(adev->vcn.internal.data0, 0);<br>
>          ib->ptr[1] = addr;<br>
>          ib->ptr[2] = PACKET0(adev->vcn.internal.data1, 0);<br>
> @@ -576,9 +573,7 @@ static int amdgpu_vcn_dec_send_msg(struct amdgpu_ring *ring,<br>
>          if (r)<br>
>                  goto err_free;<br>
><br>
> -       amdgpu_bo_fence(bo, f, false);<br>
> -       amdgpu_bo_unreserve(bo);<br>
> -       amdgpu_bo_free_kernel(&bo, NULL, (void **)&msg);<br>
> +       amdgpu_ib_free(adev, ib_msg, f);<br>
><br>
>          if (fence)<br>
>                  *fence = dma_fence_get(f);<br>
> @@ -588,27 +583,26 @@ static int amdgpu_vcn_dec_send_msg(struct amdgpu_ring *ring,<br>
><br>
>   err_free:<br>
>          amdgpu_job_free(job);<br>
> -<br>
>   err:<br>
> -       amdgpu_bo_unreserve(bo);<br>
> -       amdgpu_bo_free_kernel(&bo, NULL, (void **)&msg);<br>
> +       amdgpu_ib_free(adev, ib_msg, f);<br>
>          return r;<br>
>   }<br>
><br>
>   static int amdgpu_vcn_dec_get_create_msg(struct amdgpu_ring *ring, uint32_t handle,<br>
> -                                        struct amdgpu_bo **bo)<br>
> +               struct amdgpu_ib *ib)<br>
>   {<br>
>          struct amdgpu_device *adev = ring->adev;<br>
>          uint32_t *msg;<br>
>          int r, i;<br>
><br>
> -       *bo = NULL;<br>
> -       r = amdgpu_bo_create_reserved(adev, 1024, PAGE_SIZE,<br>
> -                                     AMDGPU_GEM_DOMAIN_VRAM,<br>
> -                                     bo, NULL, (void **)&msg);<br>
> +       memset(ib, 0, sizeof(*ib));<br>
> +       r = amdgpu_ib_get(adev, NULL, PAGE_SIZE,<br>
> +                       AMDGPU_IB_POOL_DIRECT,<br>
> +                       ib);<br>
>          if (r)<br>
>                  return r;<br>
><br>
> +       msg = ib->ptr;<br>
>          msg[0] = cpu_to_le32(0x00000028);<br>
>          msg[1] = cpu_to_le32(0x00000038);<br>
>          msg[2] = cpu_to_le32(0x00000001);<br>
> @@ -630,19 +624,20 @@ static int amdgpu_vcn_dec_get_create_msg(struct amdgpu_ring *ring, uint32_t hand<br>
>   }<br>
><br>
>   static int amdgpu_vcn_dec_get_destroy_msg(struct amdgpu_ring *ring, uint32_t handle,<br>
> -                                         struct amdgpu_bo **bo)<br>
> +                                         struct amdgpu_ib *ib)<br>
>   {<br>
>          struct amdgpu_device *adev = ring->adev;<br>
>          uint32_t *msg;<br>
>          int r, i;<br>
><br>
> -       *bo = NULL;<br>
> -       r = amdgpu_bo_create_reserved(adev, 1024, PAGE_SIZE,<br>
> -                                     AMDGPU_GEM_DOMAIN_VRAM,<br>
> -                                     bo, NULL, (void **)&msg);<br>
> +       memset(ib, 0, sizeof(*ib));<br>
> +       r = amdgpu_ib_get(adev, NULL, PAGE_SIZE,<br>
> +                       AMDGPU_IB_POOL_DIRECT,<br>
> +                       ib);<br>
>          if (r)<br>
>                  return r;<br>
><br>
> +       msg = ib->ptr;<br>
>          msg[0] = cpu_to_le32(0x00000028);<br>
>          msg[1] = cpu_to_le32(0x00000018);<br>
>          msg[2] = cpu_to_le32(0x00000000);<br>
> @@ -658,21 +653,21 @@ static int amdgpu_vcn_dec_get_destroy_msg(struct amdgpu_ring *ring, uint32_t han<br>
>   int amdgpu_vcn_dec_ring_test_ib(struct amdgpu_ring *ring, long timeout)<br>
>   {<br>
>          struct dma_fence *fence = NULL;<br>
> -       struct amdgpu_bo *bo;<br>
> +       struct amdgpu_ib ib;<br>
>          long r;<br>
><br>
> -       r = amdgpu_vcn_dec_get_create_msg(ring, 1, &bo);<br>
> +       r = amdgpu_vcn_dec_get_create_msg(ring, 1, &ib);<br>
>          if (r)<br>
>                  goto error;<br>
><br>
> -       r = amdgpu_vcn_dec_send_msg(ring, bo, NULL);<br>
> +       r = amdgpu_vcn_dec_send_msg(ring, &ib, NULL);<br>
>          if (r)<br>
>                  goto error;<br>
> -       r = amdgpu_vcn_dec_get_destroy_msg(ring, 1, &bo);<br>
> +       r = amdgpu_vcn_dec_get_destroy_msg(ring, 1, &ib);<br>
>          if (r)<br>
>                  goto error;<br>
><br>
> -       r = amdgpu_vcn_dec_send_msg(ring, bo, &fence);<br>
> +       r = amdgpu_vcn_dec_send_msg(ring, &ib, &fence);<br>
>          if (r)<br>
>                  goto error;<br>
><br>
> @@ -688,8 +683,8 @@ int amdgpu_vcn_dec_ring_test_ib(struct amdgpu_ring *ring, long timeout)<br>
>   }<br>
><br>
>   static int amdgpu_vcn_dec_sw_send_msg(struct amdgpu_ring *ring,<br>
> -                                  struct amdgpu_bo *bo,<br>
> -                                  struct dma_fence **fence)<br>
> +               struct amdgpu_ib *ib_msg,<br>
> +               struct dma_fence **fence)<br>
>   {<br>
>          struct amdgpu_vcn_decode_buffer *decode_buffer = NULL;<br>
>          const unsigned int ib_size_dw = 64;<br>
> @@ -697,7 +692,7 @@ static int amdgpu_vcn_dec_sw_send_msg(struct amdgpu_ring *ring,<br>
>          struct dma_fence *f = NULL;<br>
>          struct amdgpu_job *job;<br>
>          struct amdgpu_ib *ib;<br>
> -       uint64_t addr;<br>
> +       uint64_t addr = ib_msg->gpu_addr;<br>
>          int i, r;<br>
><br>
>          r = amdgpu_job_alloc_with_ib(adev, ib_size_dw * 4,<br>
> @@ -706,7 +701,6 @@ static int amdgpu_vcn_dec_sw_send_msg(struct amdgpu_ring *ring,<br>
>                  goto err;<br>
><br>
>          ib = &job->ibs[0];<br>
> -       addr = amdgpu_bo_gpu_offset(bo);<br>
>          ib->length_dw = 0;<br>
><br>
>          ib->ptr[ib->length_dw++] = sizeof(struct amdgpu_vcn_decode_buffer) + 8;<br>
> @@ -726,9 +720,7 @@ static int amdgpu_vcn_dec_sw_send_msg(struct amdgpu_ring *ring,<br>
>          if (r)<br>
>                  goto err_free;<br>
><br>
> -       amdgpu_bo_fence(bo, f, false);<br>
> -       amdgpu_bo_unreserve(bo);<br>
> -       amdgpu_bo_unref(&bo);<br>
> +       amdgpu_ib_free(adev, ib_msg, f);<br>
><br>
>          if (fence)<br>
>                  *fence = dma_fence_get(f);<br>
> @@ -738,31 +730,29 @@ static int amdgpu_vcn_dec_sw_send_msg(struct amdgpu_ring *ring,<br>
><br>
>   err_free:<br>
>          amdgpu_job_free(job);<br>
> -<br>
>   err:<br>
> -       amdgpu_bo_unreserve(bo);<br>
> -       amdgpu_bo_unref(&bo);<br>
> +       amdgpu_ib_free(adev, ib_msg, f);<br>
>          return r;<br>
>   }<br>
><br>
>   int amdgpu_vcn_dec_sw_ring_test_ib(struct amdgpu_ring *ring, long timeout)<br>
>   {<br>
>          struct dma_fence *fence = NULL;<br>
> -       struct amdgpu_bo *bo;<br>
> +       struct amdgpu_ib ib;<br>
>          long r;<br>
><br>
> -       r = amdgpu_vcn_dec_get_create_msg(ring, 1, &bo);<br>
> +       r = amdgpu_vcn_dec_get_create_msg(ring, 1, &ib);<br>
>          if (r)<br>
>                  goto error;<br>
><br>
> -       r = amdgpu_vcn_dec_sw_send_msg(ring, bo, NULL);<br>
> +       r = amdgpu_vcn_dec_sw_send_msg(ring, &ib, NULL);<br>
>          if (r)<br>
>                  goto error;<br>
> -       r = amdgpu_vcn_dec_get_destroy_msg(ring, 1, &bo);<br>
> +       r = amdgpu_vcn_dec_get_destroy_msg(ring, 1, &ib);<br>
>          if (r)<br>
>                  goto error;<br>
><br>
> -       r = amdgpu_vcn_dec_sw_send_msg(ring, bo, &fence);<br>
> +       r = amdgpu_vcn_dec_sw_send_msg(ring, &ib, &fence);<br>
>          if (r)<br>
>                  goto error;<br>
><br>
> @@ -809,7 +799,7 @@ int amdgpu_vcn_enc_ring_test_ring(struct amdgpu_ring *ring)<br>
>   }<br>
><br>
>   static int amdgpu_vcn_enc_get_create_msg(struct amdgpu_ring *ring, uint32_t handle,<br>
> -                                        struct amdgpu_bo *bo,<br>
> +                                        struct amdgpu_ib *ib_msg,<br>
>                                           struct dma_fence **fence)<br>
>   {<br>
>          const unsigned ib_size_dw = 16;<br>
> @@ -825,7 +815,7 @@ static int amdgpu_vcn_enc_get_create_msg(struct amdgpu_ring *ring, uint32_t hand<br>
>                  return r;<br>
><br>
>          ib = &job->ibs[0];<br>
> -       addr = amdgpu_bo_gpu_offset(bo);<br>
> +       addr = ib_msg->gpu_addr;<br>
><br>
>          ib->length_dw = 0;<br>
>          ib->ptr[ib->length_dw++] = 0x00000018;<br>
> @@ -863,7 +853,7 @@ static int amdgpu_vcn_enc_get_create_msg(struct amdgpu_ring *ring, uint32_t hand<br>
>   }<br>
><br>
>   static int amdgpu_vcn_enc_get_destroy_msg(struct amdgpu_ring *ring, uint32_t handle,<br>
> -                                         struct amdgpu_bo *bo,<br>
> +                                         struct amdgpu_ib *ib_msg,<br>
>                                            struct dma_fence **fence)<br>
>   {<br>
>          const unsigned ib_size_dw = 16;<br>
> @@ -879,7 +869,7 @@ static int amdgpu_vcn_enc_get_destroy_msg(struct amdgpu_ring *ring, uint32_t han<br>
>                  return r;<br>
><br>
>          ib = &job->ibs[0];<br>
> -       addr = amdgpu_bo_gpu_offset(bo);<br>
> +       addr = ib_msg->gpu_addr;<br>
><br>
>          ib->length_dw = 0;<br>
>          ib->ptr[ib->length_dw++] = 0x00000018;<br>
> @@ -918,21 +908,23 @@ static int amdgpu_vcn_enc_get_destroy_msg(struct amdgpu_ring *ring, uint32_t han<br>
><br>
>   int amdgpu_vcn_enc_ring_test_ib(struct amdgpu_ring *ring, long timeout)<br>
>   {<br>
> +       struct amdgpu_device *adev = ring->adev;<br>
>          struct dma_fence *fence = NULL;<br>
> -       struct amdgpu_bo *bo = NULL;<br>
> +       struct amdgpu_ib ib;<br>
>          long r;<br>
><br>
> -       r = amdgpu_bo_create_reserved(ring->adev, 128 * 1024, PAGE_SIZE,<br>
> -                                     AMDGPU_GEM_DOMAIN_VRAM,<br>
> -                                     &bo, NULL, NULL);<br>
> +       memset(&ib, 0, sizeof(ib));<br>
> +       r = amdgpu_ib_get(adev, NULL, 128 << 10,<br>
> +                       AMDGPU_IB_POOL_DIRECT,<br>
> +                       &ib);<br>
>          if (r)<br>
>                  return r;<br>
><br>
> -       r = amdgpu_vcn_enc_get_create_msg(ring, 1, bo, NULL);<br>
> +       r = amdgpu_vcn_enc_get_create_msg(ring, 1, &ib, NULL);<br>
>          if (r)<br>
>                  goto error;<br>
><br>
> -       r = amdgpu_vcn_enc_get_destroy_msg(ring, 1, bo, &fence);<br>
> +       r = amdgpu_vcn_enc_get_destroy_msg(ring, 1, &ib, &fence);<br>
>          if (r)<br>
>                  goto error;<br>
><br>
> @@ -943,9 +935,8 @@ int amdgpu_vcn_enc_ring_test_ib(struct amdgpu_ring *ring, long timeout)<br>
>                  r = 0;<br>
><br>
>   error:<br>
> +       amdgpu_ib_free(adev, &ib, fence);<br>
>          dma_fence_put(fence);<br>
> -       amdgpu_bo_unreserve(bo);<br>
> -       amdgpu_bo_free_kernel(&bo, NULL, NULL);<br>
><br>
>          return r;<br>
>   }<br>
> diff --git a/drivers/gpu/drm/amd/amdgpu/uvd_v6_0.c b/drivers/gpu/drm/amd/amdgpu/uvd_v6_0.c<br>
> index bc571833632e..98442462135c 100644<br>
> --- a/drivers/gpu/drm/amd/amdgpu/uvd_v6_0.c<br>
> +++ b/drivers/gpu/drm/amd/amdgpu/uvd_v6_0.c<br>
> @@ -206,14 +206,14 @@ static int uvd_v6_0_enc_ring_test_ring(struct amdgpu_ring *ring)<br>
>    * Open up a stream for HW test<br>
>    */<br>
>   static int uvd_v6_0_enc_get_create_msg(struct amdgpu_ring *ring, uint32_t handle,<br>
> -                                      struct amdgpu_bo *bo,<br>
> +                                      struct amdgpu_ib *ib_msg,<br>
>                                         struct dma_fence **fence)<br>
>   {<br>
>          const unsigned ib_size_dw = 16;<br>
>          struct amdgpu_job *job;<br>
>          struct amdgpu_ib *ib;<br>
>          struct dma_fence *f = NULL;<br>
> -       uint64_t addr;<br>
> +       uint64_t addr = ib_msg->gpu_addr;<br>
>          int i, r;<br>
><br>
>          r = amdgpu_job_alloc_with_ib(ring->adev, ib_size_dw * 4,<br>
> @@ -222,7 +222,6 @@ static int uvd_v6_0_enc_get_create_msg(struct amdgpu_ring *ring, uint32_t handle<br>
>                  return r;<br>
><br>
>          ib = &job->ibs[0];<br>
> -       addr = amdgpu_bo_gpu_offset(bo);<br>
><br>
>          ib->length_dw = 0;<br>
>          ib->ptr[ib->length_dw++] = 0x00000018;<br>
> @@ -270,14 +269,14 @@ static int uvd_v6_0_enc_get_create_msg(struct amdgpu_ring *ring, uint32_t handle<br>
>    */<br>
>   static int uvd_v6_0_enc_get_destroy_msg(struct amdgpu_ring *ring,<br>
>                                          uint32_t handle,<br>
> -                                       struct amdgpu_bo *bo,<br>
> +                                       struct amdgpu_ib *ib_msg,<br>
>                                          struct dma_fence **fence)<br>
>   {<br>
>          const unsigned ib_size_dw = 16;<br>
>          struct amdgpu_job *job;<br>
>          struct amdgpu_ib *ib;<br>
>          struct dma_fence *f = NULL;<br>
> -       uint64_t addr;<br>
> +       uint64_t addr = ib_msg->gpu_addr;<br>
>          int i, r;<br>
><br>
>          r = amdgpu_job_alloc_with_ib(ring->adev, ib_size_dw * 4,<br>
> @@ -286,7 +285,6 @@ static int uvd_v6_0_enc_get_destroy_msg(struct amdgpu_ring *ring,<br>
>                  return r;<br>
><br>
>          ib = &job->ibs[0];<br>
> -       addr = amdgpu_bo_gpu_offset(bo);<br>
><br>
>          ib->length_dw = 0;<br>
>          ib->ptr[ib->length_dw++] = 0x00000018;<br>
> @@ -331,21 +329,23 @@ static int uvd_v6_0_enc_get_destroy_msg(struct amdgpu_ring *ring,<br>
>    */<br>
>   static int uvd_v6_0_enc_ring_test_ib(struct amdgpu_ring *ring, long timeout)<br>
>   {<br>
> +       struct amdgpu_device *adev = ring->adev;<br>
>          struct dma_fence *fence = NULL;<br>
> -       struct amdgpu_bo *bo = NULL;<br>
> +       struct amdgpu_ib ib;<br>
>          long r;<br>
><br>
> -       r = amdgpu_bo_create_reserved(ring->adev, 128 * 1024, PAGE_SIZE,<br>
> -                                     AMDGPU_GEM_DOMAIN_VRAM,<br>
> -                                     &bo, NULL, NULL);<br>
> +       memset(&ib, 0, sizeof(ib));<br>
> +       r = amdgpu_ib_get(adev, NULL, 128 << 10,<br>
> +                       AMDGPU_IB_POOL_DIRECT,<br>
> +                       &ib);<br>
>          if (r)<br>
>                  return r;<br>
><br>
> -       r = uvd_v6_0_enc_get_create_msg(ring, 1, bo, NULL);<br>
> +       r = uvd_v6_0_enc_get_create_msg(ring, 1, &ib, NULL);<br>
>          if (r)<br>
>                  goto error;<br>
><br>
> -       r = uvd_v6_0_enc_get_destroy_msg(ring, 1, bo, &fence);<br>
> +       r = uvd_v6_0_enc_get_destroy_msg(ring, 1, &ib, &fence);<br>
>          if (r)<br>
>                  goto error;<br>
><br>
> @@ -356,10 +356,8 @@ static int uvd_v6_0_enc_ring_test_ib(struct amdgpu_ring *ring, long timeout)<br>
>                  r = 0;<br>
><br>
>   error:<br>
> +       amdgpu_ib_free(adev, &ib, fence);<br>
>          dma_fence_put(fence);<br>
> -       amdgpu_bo_unpin(bo);<br>
> -       amdgpu_bo_unreserve(bo);<br>
> -       amdgpu_bo_unref(&bo);<br>
>          return r;<br>
>   }<br>
><br>
> diff --git a/drivers/gpu/drm/amd/amdgpu/uvd_v7_0.c b/drivers/gpu/drm/amd/amdgpu/uvd_v7_0.c<br>
> index b6e82d75561f..3440ef554f99 100644<br>
> --- a/drivers/gpu/drm/amd/amdgpu/uvd_v7_0.c<br>
> +++ b/drivers/gpu/drm/amd/amdgpu/uvd_v7_0.c<br>
> @@ -213,14 +213,14 @@ static int uvd_v7_0_enc_ring_test_ring(struct amdgpu_ring *ring)<br>
>    * Open up a stream for HW test<br>
>    */<br>
>   static int uvd_v7_0_enc_get_create_msg(struct amdgpu_ring *ring, uint32_t handle,<br>
> -                                      struct amdgpu_bo *bo,<br>
> +                                      struct amdgpu_ib *ib_msg,<br>
>                                         struct dma_fence **fence)<br>
>   {<br>
>          const unsigned ib_size_dw = 16;<br>
>          struct amdgpu_job *job;<br>
>          struct amdgpu_ib *ib;<br>
>          struct dma_fence *f = NULL;<br>
> -       uint64_t addr;<br>
> +       uint64_t addr = ib_msg->gpu_addr;<br>
>          int i, r;<br>
><br>
>          r = amdgpu_job_alloc_with_ib(ring->adev, ib_size_dw * 4,<br>
> @@ -229,7 +229,6 @@ static int uvd_v7_0_enc_get_create_msg(struct amdgpu_ring *ring, uint32_t handle<br>
>                  return r;<br>
><br>
>          ib = &job->ibs[0];<br>
> -       addr = amdgpu_bo_gpu_offset(bo);<br>
><br>
>          ib->length_dw = 0;<br>
>          ib->ptr[ib->length_dw++] = 0x00000018;<br>
> @@ -276,14 +275,14 @@ static int uvd_v7_0_enc_get_create_msg(struct amdgpu_ring *ring, uint32_t handle<br>
>    * Close up a stream for HW test or if userspace failed to do so<br>
>    */<br>
>   static int uvd_v7_0_enc_get_destroy_msg(struct amdgpu_ring *ring, uint32_t handle,<br>
> -                                       struct amdgpu_bo *bo,<br>
> +                                       struct amdgpu_ib *ib_msg,<br>
>                                          struct dma_fence **fence)<br>
>   {<br>
>          const unsigned ib_size_dw = 16;<br>
>          struct amdgpu_job *job;<br>
>          struct amdgpu_ib *ib;<br>
>          struct dma_fence *f = NULL;<br>
> -       uint64_t addr;<br>
> +       uint64_t addr = ib_msg->gpu_addr;<br>
>          int i, r;<br>
><br>
>          r = amdgpu_job_alloc_with_ib(ring->adev, ib_size_dw * 4,<br>
> @@ -292,7 +291,6 @@ static int uvd_v7_0_enc_get_destroy_msg(struct amdgpu_ring *ring, uint32_t handl<br>
>                  return r;<br>
><br>
>          ib = &job->ibs[0];<br>
> -       addr = amdgpu_bo_gpu_offset(bo);<br>
><br>
>          ib->length_dw = 0;<br>
>          ib->ptr[ib->length_dw++] = 0x00000018;<br>
> @@ -337,21 +335,23 @@ static int uvd_v7_0_enc_get_destroy_msg(struct amdgpu_ring *ring, uint32_t handl<br>
>    */<br>
>   static int uvd_v7_0_enc_ring_test_ib(struct amdgpu_ring *ring, long timeout)<br>
>   {<br>
> +       struct amdgpu_device *adev = ring->adev;<br>
>          struct dma_fence *fence = NULL;<br>
> -       struct amdgpu_bo *bo = NULL;<br>
> +       struct amdgpu_ib ib;<br>
>          long r;<br>
><br>
> -       r = amdgpu_bo_create_reserved(ring->adev, 128 * 1024, PAGE_SIZE,<br>
> -                                     AMDGPU_GEM_DOMAIN_VRAM,<br>
> -                                     &bo, NULL, NULL);<br>
> +       memset(&ib, 0, sizeof(ib));<br>
> +       r = amdgpu_ib_get(adev, NULL, 128 << 10,<br>
> +                       AMDGPU_IB_POOL_DIRECT,<br>
> +                       &ib);<br>
>          if (r)<br>
>                  return r;<br>
><br>
> -       r = uvd_v7_0_enc_get_create_msg(ring, 1, bo, NULL);<br>
> +       r = uvd_v7_0_enc_get_create_msg(ring, 1, &ib, NULL);<br>
>          if (r)<br>
>                  goto error;<br>
><br>
> -       r = uvd_v7_0_enc_get_destroy_msg(ring, 1, bo, &fence);<br>
> +       r = uvd_v7_0_enc_get_destroy_msg(ring, 1, &ib, &fence);<br>
>          if (r)<br>
>                  goto error;<br>
><br>
> @@ -362,10 +362,8 @@ static int uvd_v7_0_enc_ring_test_ib(struct amdgpu_ring *ring, long timeout)<br>
>                  r = 0;<br>
><br>
>   error:<br>
> +       amdgpu_ib_free(adev, &ib, fence);<br>
>          dma_fence_put(fence);<br>
> -       amdgpu_bo_unpin(bo);<br>
> -       amdgpu_bo_unreserve(bo);<br>
> -       amdgpu_bo_unref(&bo);<br>
>          return r;<br>
>   }<br>
><br>
> --<br>
> 2.25.1<br>
><br>
<br>
</div>
</span></font><br>
</div>
</div>
</body>
</html>