<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  </head>
  <body>
    Hi Lang,<br>
    This is not the right method to allocate memory if you dont have a
    specific offset for TMR. I will send a patch for your testing in drm
    buddy<br>
    which could fix this problem.<br>
    <br>
    Regards,<br>
    Arun.<br>
    <br>
    <div class="moz-cite-prefix">On 8/3/2023 8:58 PM, Yu, Lang wrote:<br>
    </div>
    <blockquote type="cite" cite="mid:DM6PR12MB42503F416BD78E9163666A90FB08A@DM6PR12MB4250.namprd12.prod.outlook.com">
      
      <p style="font-family:Arial;font-size:10pt;color:#008000;margin:15pt;font-style:normal;font-weight:normal;text-decoration:none;" align="Left">
        [Public]<br>
      </p>
      <br>
      <div>
        <div dir="ltr">
          <div>
            <div>
              <div dir="ltr">Ping</div>
            </div>
          </div>
        </div>
        <hr style="display:inline-block;width:98%" tabindex="-1">
        <div id="divRplyFwdMsg" dir="ltr"><font style="font-size:11pt" face="Calibri, sans-serif" color="#000000"><b>发件人:</b> Yu,
            Lang <a class="moz-txt-link-rfc2396E" href="mailto:Lang.Yu@amd.com"><Lang.Yu@amd.com></a><br>
            <b>发送时间:</b> Tuesday, August 1, 2023 3:38:32 PM<br>
            <b>收件人:</b> <a class="moz-txt-link-abbreviated" href="mailto:amd-gfx@lists.freedesktop.org">amd-gfx@lists.freedesktop.org</a>
            <a class="moz-txt-link-rfc2396E" href="mailto:amd-gfx@lists.freedesktop.org"><amd-gfx@lists.freedesktop.org></a><br>
            <b>抄送:</b> Koenig, Christian
            <a class="moz-txt-link-rfc2396E" href="mailto:Christian.Koenig@amd.com"><Christian.Koenig@amd.com></a>; Paneer Selvam, Arunpravin
            <a class="moz-txt-link-rfc2396E" href="mailto:Arunpravin.PaneerSelvam@amd.com"><Arunpravin.PaneerSelvam@amd.com></a>; Zhang, Yifan
            <a class="moz-txt-link-rfc2396E" href="mailto:Yifan1.Zhang@amd.com"><Yifan1.Zhang@amd.com></a>; Yu, Lang
            <a class="moz-txt-link-rfc2396E" href="mailto:Lang.Yu@amd.com"><Lang.Yu@amd.com></a><br>
            <b>主题:</b> [PATCH] drm/amdgpu: add support to create large
            TMR BO for APU</font>
          <div> </div>
        </div>
        <div class="BodyFragment"><font size="2"><span style="font-size:11pt;">
              <div class="PlainText">TMR requires physical contiguous
                memory, amdgpu_bo_create_kernel()<br>
                can't satisfy large(>128MB) physical contiguous
                memory allocation<br>
                request with default 512MB VRAM on APU.<br>
                <br>
                When requested TMR size > 128MB, use
                amdgpu_bo_create_kernel_at()<br>
                to create the BO at offset 32MB with a step 1MB in the
                VRAM range.<br>
                <br>
                Signed-off-by: Lang Yu <a class="moz-txt-link-rfc2396E" href="mailto:Lang.Yu@amd.com"><Lang.Yu@amd.com></a><br>
                ---<br>
                 drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c | 38
                +++++++++++++++++++++++--<br>
                 1 file changed, 35 insertions(+), 3 deletions(-)<br>
                <br>
                diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
                b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c<br>
                index 15217e33b51d..3fadfaa63b2e 100644<br>
                --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c<br>
                +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c<br>
                @@ -783,6 +783,34 @@ static bool psp_boottime_tmr(struct
                psp_context *psp)<br>
                         }<br>
                 }<br>
                 <br>
                +static int psp_create_large_tmr_bo_for_apu(struct
                psp_context *psp,<br>
                +                                          int tmr_size,<br>
                +                                          void
                **cpu_addr)<br>
                +{<br>
                +       struct amdgpu_vram_mgr *mgr =
                &psp->adev->mman.vram_mgr;<br>
                +       uint32_t rounded_size = round_up(tmr_size,
                0x100000);<br>
                +       uint32_t start = 0x2000000;<br>
                +       uint32_t step = 0x100000;<br>
                +       int ret = -ENOMEM;<br>
                +<br>
                +       for (; start + rounded_size <=
                mgr->manager.size &&<br>
                +            start + step <= mgr->manager.size;
                start += step) {<br>
                +<br>
                +               ret =
                amdgpu_bo_create_kernel_at(psp->adev, start,
                tmr_size,<br>
                +                                               
                &psp->tmr_bo, cpu_addr);<br>
                +               if (ret == -ENOMEM)<br>
                +                       continue;<br>
                +               if (ret)<br>
                +                       return ret;<br>
                +<br>
                +               psp->tmr_mc_addr =
                amdgpu_bo_gpu_offset(psp->tmr_bo);<br>
                +<br>
                +               break;<br>
                +       }<br>
                +<br>
                +       return ret;<br>
                +}<br>
                +<br>
                 /* Set up Trusted Memory Region */<br>
                 static int psp_tmr_init(struct psp_context *psp)<br>
                 {<br>
                @@ -813,8 +841,13 @@ static int psp_tmr_init(struct
                psp_context *psp)<br>
                                 }<br>
                         }<br>
                 <br>
                -       if (!psp->tmr_bo) {<br>
                -               pptr = amdgpu_sriov_vf(psp->adev) ?
                &tmr_buf : NULL;<br>
                +       if (psp->tmr_bo)<br>
                +               return 0;<br>
                +<br>
                +       pptr = amdgpu_sriov_vf(psp->adev) ?
                &tmr_buf : NULL;<br>
                +       if (psp->adev->flags & AMD_IS_APU
                && tmr_size > 0x8000000)<br>
                +               ret =
                psp_create_large_tmr_bo_for_apu(psp, tmr_size, pptr);<br>
                +       else<br>
                                 ret =
                amdgpu_bo_create_kernel(psp->adev, tmr_size,<br>
                                                              
                PSP_TMR_ALIGNMENT,<br>
                                                              
                AMDGPU_HAS_VRAM(psp->adev) ?<br>
                @@ -822,7 +855,6 @@ static int psp_tmr_init(struct
                psp_context *psp)<br>
                                                              
                AMDGPU_GEM_DOMAIN_GTT,<br>
                                                              
                &psp->tmr_bo, &psp->tmr_mc_addr,<br>
                                                               pptr);<br>
                -       }<br>
                 <br>
                         return ret;<br>
                 }<br>
                -- <br>
                2.25.1<br>
                <br>
              </div>
            </span></font></div>
      </div>
    </blockquote>
    <br>
  </body>
</html>