<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body>
<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>
<div>
<div dir="ltr">
<div dir="ltr">Ping</div>
<div dir="ltr"><br>
<span id="ms-outlook-ios-cursor"></span></div>
</div>
</div>
<div id="mail-editor-reference-message-container" class="ms-outlook-mobile-reference-message">
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif"><b>发件人:</b> Yu, Lang <Lang.Yu@amd.com><br>
<b>发送时间:</b> 星期二, 八月 1, 2023 15:16<br>
<b>收件人:</b> amd-gfx@lists.freedesktop.org <amd-gfx@lists.freedesktop.org><br>
<b>抄送:</b> Koenig, Christian <Christian.Koenig@amd.com>; Paneer Selvam, Arunpravin <Arunpravin.PaneerSelvam@amd.com>; Zhang, Yifan <Yifan1.Zhang@amd.com>; Yu, Lang <Lang.Yu@amd.com><br>
<b>主题:</b> [PATCH v3] drm/amdgpu: refine amdgpu_bo_create_kernel_at()
<div> </div>
</font></div>
<meta name="Generator" content="Microsoft Exchange Server">
<!-- converted from text --><font size="2"><span style="font-size:11pt;">
<div class="PlainText">Use amdgpu_bo_create_reserved() to create a BO in VRAM<br>
domain would fail if requested VRAM size is large(>128MB)<br>
on APU which usually has a default 512MB VRAM.<br>
<br>
That's because VRAM is framgented after several allocations.<br>
<br>
The approach is using amdgpu_bo_create_reserved() to<br>
create a BO in CPU domain first, it will always succeed.<br>
<br>
v2: Don't overwrite the contents at specific offset.<br>
v3: Don't return GPU addr.<br>
<br>
Signed-off-by: Lang Yu <Lang.Yu@amd.com><br>
---<br>
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 19 ++++++++++++++-----<br>
1 file changed, 14 insertions(+), 5 deletions(-)<br>
<br>
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c<br>
index ff73cc11d47e..df5ba9509a41 100644<br>
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c<br>
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c<br>
@@ -377,27 +377,36 @@ int amdgpu_bo_create_kernel_at(struct amdgpu_device *adev,<br>
size = ALIGN(size, PAGE_SIZE);<br>
<br>
r = amdgpu_bo_create_reserved(adev, size, PAGE_SIZE,<br>
- AMDGPU_GEM_DOMAIN_VRAM, bo_ptr, NULL,<br>
- cpu_addr);<br>
+ AMDGPU_GEM_DOMAIN_CPU,<br>
+ bo_ptr, NULL, NULL);<br>
if (r)<br>
return r;<br>
<br>
if ((*bo_ptr) == NULL)<br>
return 0;<br>
<br>
+ (*bo_ptr)->preferred_domains = AMDGPU_GEM_DOMAIN_VRAM;<br>
+ (*bo_ptr)->allowed_domains = (*bo_ptr)->preferred_domains;<br>
+ (*bo_ptr)->flags = AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS;<br>
+ (*bo_ptr)->flags |= cpu_addr ? AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED<br>
+ : AMDGPU_GEM_CREATE_NO_CPU_ACCESS;<br>
+<br>
/*<br>
* Remove the original mem node and create a new one at the request<br>
* position.<br>
*/<br>
- if (cpu_addr)<br>
- amdgpu_bo_kunmap(*bo_ptr);<br>
-<br>
ttm_resource_free(&(*bo_ptr)->tbo, &(*bo_ptr)->tbo.resource);<br>
<br>
for (i = 0; i < (*bo_ptr)->placement.num_placement; ++i) {<br>
(*bo_ptr)->placements[i].fpfn = offset >> PAGE_SHIFT;<br>
(*bo_ptr)->placements[i].lpfn = (offset + size) >> PAGE_SHIFT;<br>
+ (*bo_ptr)->placements[i].mem_type = TTM_PL_VRAM;<br>
+ (*bo_ptr)->placements[i].flags = TTM_PL_FLAG_CONTIGUOUS;<br>
+<br>
+ if (!((*bo_ptr)->flags & AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED))<br>
+ (*bo_ptr)->placements[i].flags |= TTM_PL_FLAG_TOPDOWN;<br>
}<br>
+<br>
r = ttm_bo_mem_space(&(*bo_ptr)->tbo, &(*bo_ptr)->placement,<br>
&(*bo_ptr)->tbo.resource, &ctx);<br>
if (r)<br>
-- <br>
2.25.1<br>
<br>
</div>
</span></font></div>
</div>
</div>
</div>
</body>
</html>