TMR requires physical contiguous memory, amdgpu_bo_create_kernel()
can't satisfy large(>128MB) physical contiguous memory allocation
request with default 512MB VRAM on APU.

When requested TMR size > 128MB, use amdgpu_bo_create_kernel_at()
to create the TMR BO at offset 64MB.

Signed-off-by: Lang Yu <lang...@amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c | 42 ++++++++++++++++---------
 1 file changed, 28 insertions(+), 14 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
index 15217e33b51d..2eac82113d34 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c
@@ -783,13 +783,38 @@ static bool psp_boottime_tmr(struct psp_context *psp)
        }
 }
 
+static inline int psp_create_tmr_bo(struct psp_context *psp, int tmr_size)
+{
+       void *tmr_buf;
+       void **pptr;
+       int ret;
+
+       if (psp->tmr_bo)
+               return 0;
+
+       pptr = amdgpu_sriov_vf(psp->adev) ? &tmr_buf : NULL;
+
+       if (psp->adev->flags & AMD_IS_APU && tmr_size > 0x8000000)
+               ret = amdgpu_bo_create_kernel_at(psp->adev, 0x4000000, tmr_size,
+                                                &psp->tmr_bo, 
&psp->tmr_mc_addr,
+                                                pptr);
+       else
+               ret = amdgpu_bo_create_kernel(psp->adev, tmr_size,
+                                             PSP_TMR_ALIGNMENT,
+                                             AMDGPU_HAS_VRAM(psp->adev) ?
+                                             AMDGPU_GEM_DOMAIN_VRAM :
+                                             AMDGPU_GEM_DOMAIN_GTT,
+                                             &psp->tmr_bo, &psp->tmr_mc_addr,
+                                             pptr);
+
+       return ret;
+}
+
 /* Set up Trusted Memory Region */
 static int psp_tmr_init(struct psp_context *psp)
 {
        int ret = 0;
        int tmr_size;
-       void *tmr_buf;
-       void **pptr;
 
        /*
         * According to HW engineer, they prefer the TMR address be "naturally
@@ -813,18 +838,7 @@ static int psp_tmr_init(struct psp_context *psp)
                }
        }
 
-       if (!psp->tmr_bo) {
-               pptr = amdgpu_sriov_vf(psp->adev) ? &tmr_buf : NULL;
-               ret = amdgpu_bo_create_kernel(psp->adev, tmr_size,
-                                             PSP_TMR_ALIGNMENT,
-                                             AMDGPU_HAS_VRAM(psp->adev) ?
-                                             AMDGPU_GEM_DOMAIN_VRAM :
-                                             AMDGPU_GEM_DOMAIN_GTT,
-                                             &psp->tmr_bo, &psp->tmr_mc_addr,
-                                             pptr);
-       }
-
-       return ret;
+       return psp_create_tmr_bo(psp, tmr_size);
 }
 
 static bool psp_skip_tmr(struct psp_context *psp)
-- 
2.25.1

Reply via email to