<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<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);">
Reviewed-by: Alex Deucher <alexander.deucher@amd.com><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> amd-gfx <amd-gfx-bounces@lists.freedesktop.org> on behalf of Christian König <ckoenig.leichtzumerken@gmail.com><br>
<b>Sent:</b> Friday, September 13, 2019 8:08 AM<br>
<b>To:</b> Grodzovsky, Andrey <Andrey.Grodzovsky@amd.com>; Zhou1, Tao <Tao.Zhou1@amd.com>; Chen, Guchun <Guchun.Chen@amd.com>; amd-gfx@lists.freedesktop.org <amd-gfx@lists.freedesktop.org><br>
<b>Subject:</b> [PATCH] drm/amdgpu: cleanup creating BOs at fixed location</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt;">
<div class="PlainText">The placement is something TTM/BO internal and the RAS code should<br>
avoid touching that directly.<br>
<br>
Add a helper to create a BO at a fixed location and use that instead.<br>
<br>
Signed-off-by: Christian König <christian.koenig@amd.com><br>
---<br>
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 61 ++++++++++++++++<br>
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h | 3 +<br>
drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c | 82 ++--------------------<br>
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 82 ++++------------------<br>
4 files changed, 81 insertions(+), 147 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 510d04fd6e5f..70d45d48907a 100644<br>
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c<br>
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c<br>
@@ -342,6 +342,67 @@ int amdgpu_bo_create_kernel(struct amdgpu_device *adev,<br>
return 0;<br>
}<br>
<br>
+/**<br>
+ * amdgpu_bo_create_kernel - create BO for kernel use at specific location<br>
+ *<br>
+ * @adev: amdgpu device object<br>
+ * @offset: offset of the BO<br>
+ * @size: size of the BO<br>
+ * @domain: where to place it<br>
+ * @bo_ptr: used to initialize BOs in structures<br>
+ * @cpu_addr: optional CPU address mapping<br>
+ *<br>
+ * Creates a kernel BO at a specific offset in the address space of the domain.<br>
+ *<br>
+ * Returns:<br>
+ * 0 on success, negative error code otherwise.<br>
+ */<br>
+int amdgpu_bo_create_kernel_at(struct amdgpu_device *adev,<br>
+ uint64_t offset, uint64_t size, uint32_t domain,<br>
+ struct amdgpu_bo **bo_ptr, void **cpu_addr)<br>
+{<br>
+ struct ttm_operation_ctx ctx = { false, false };<br>
+ unsigned int i;<br>
+ int r;<br>
+<br>
+ offset &= PAGE_MASK;<br>
+ size = ALIGN(offset, PAGE_SIZE);<br>
+<br>
+ r = amdgpu_bo_create_reserved(adev, size, PAGE_SIZE, domain, bo_ptr,<br>
+ NULL, NULL);<br>
+ if (r)<br>
+ return r;<br>
+<br>
+ /*<br>
+ * Remove the original mem node and create a new one at the request<br>
+ * position.<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>
+ }<br>
+<br>
+ ttm_bo_mem_put(&(*bo_ptr)->tbo, &(*bo_ptr)->tbo.mem);<br>
+ r = ttm_bo_mem_space(&(*bo_ptr)->tbo, &(*bo_ptr)->placement,<br>
+ &(*bo_ptr)->tbo.mem, &ctx);<br>
+ if (r)<br>
+ goto error;<br>
+<br>
+ if (cpu_addr) {<br>
+ r = amdgpu_bo_kmap(*bo_ptr, cpu_addr);<br>
+ if (r)<br>
+ goto error;<br>
+ }<br>
+<br>
+ amdgpu_bo_unreserve(*bo_ptr);<br>
+ return 0;<br>
+<br>
+error:<br>
+ amdgpu_bo_unreserve(*bo_ptr);<br>
+ amdgpu_bo_unref(bo_ptr);<br>
+ return r;<br>
+}<br>
+<br>
/**<br>
* amdgpu_bo_free_kernel - free BO for kernel use<br>
*<br>
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h<br>
index e6ddd048a984..f9b550f19ea9 100644<br>
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h<br>
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.h<br>
@@ -239,6 +239,9 @@ int amdgpu_bo_create_kernel(struct amdgpu_device *adev,<br>
unsigned long size, int align,<br>
u32 domain, struct amdgpu_bo **bo_ptr,<br>
u64 *gpu_addr, void **cpu_addr);<br>
+int amdgpu_bo_create_kernel_at(struct amdgpu_device *adev,<br>
+ uint64_t offset, uint64_t size, uint32_t domain,<br>
+ struct amdgpu_bo **bo_ptr, void **cpu_addr);<br>
void amdgpu_bo_free_kernel(struct amdgpu_bo **bo, u64 *gpu_addr,<br>
void **cpu_addr);<br>
int amdgpu_bo_kmap(struct amdgpu_bo *bo, void **ptr);<br>
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c<br>
index 5f06f1e645c7..cfda72650773 100644<br>
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c<br>
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c<br>
@@ -69,12 +69,6 @@ const char *ras_block_string[] = {<br>
<br>
atomic_t amdgpu_ras_in_intr = ATOMIC_INIT(0);<br>
<br>
-static int amdgpu_ras_reserve_vram(struct amdgpu_device *adev,<br>
- uint64_t offset, uint64_t size,<br>
- struct amdgpu_bo **bo_ptr);<br>
-static int amdgpu_ras_release_vram(struct amdgpu_device *adev,<br>
- struct amdgpu_bo **bo_ptr);<br>
-<br>
static ssize_t amdgpu_ras_debugfs_read(struct file *f, char __user *buf,<br>
size_t size, loff_t *pos)<br>
{<br>
@@ -1260,75 +1254,6 @@ static void amdgpu_ras_do_recovery(struct work_struct *work)<br>
atomic_set(&ras->in_recovery, 0);<br>
}<br>
<br>
-static int amdgpu_ras_release_vram(struct amdgpu_device *adev,<br>
- struct amdgpu_bo **bo_ptr)<br>
-{<br>
- /* no need to free it actually. */<br>
- amdgpu_bo_free_kernel(bo_ptr, NULL, NULL);<br>
- return 0;<br>
-}<br>
-<br>
-/* reserve vram with size@offset */<br>
-static int amdgpu_ras_reserve_vram(struct amdgpu_device *adev,<br>
- uint64_t offset, uint64_t size,<br>
- struct amdgpu_bo **bo_ptr)<br>
-{<br>
- struct ttm_operation_ctx ctx = { false, false };<br>
- struct amdgpu_bo_param bp;<br>
- int r = 0;<br>
- int i;<br>
- struct amdgpu_bo *bo;<br>
-<br>
- if (bo_ptr)<br>
- *bo_ptr = NULL;<br>
- memset(&bp, 0, sizeof(bp));<br>
- bp.size = size;<br>
- bp.byte_align = PAGE_SIZE;<br>
- bp.domain = AMDGPU_GEM_DOMAIN_VRAM;<br>
- bp.flags = AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS |<br>
- AMDGPU_GEM_CREATE_NO_CPU_ACCESS;<br>
- bp.type = ttm_bo_type_kernel;<br>
- bp.resv = NULL;<br>
-<br>
- r = amdgpu_bo_create(adev, &bp, &bo);<br>
- if (r)<br>
- return -EINVAL;<br>
-<br>
- r = amdgpu_bo_reserve(bo, false);<br>
- if (r)<br>
- goto error_reserve;<br>
-<br>
- offset = ALIGN(offset, PAGE_SIZE);<br>
- for (i = 0; i < bo->placement.num_placement; ++i) {<br>
- bo->placements[i].fpfn = offset >> PAGE_SHIFT;<br>
- bo->placements[i].lpfn = (offset + size) >> PAGE_SHIFT;<br>
- }<br>
-<br>
- ttm_bo_mem_put(&bo->tbo, &bo->tbo.mem);<br>
- r = ttm_bo_mem_space(&bo->tbo, &bo->placement, &bo->tbo.mem, &ctx);<br>
- if (r)<br>
- goto error_pin;<br>
-<br>
- r = amdgpu_bo_pin_restricted(bo,<br>
- AMDGPU_GEM_DOMAIN_VRAM,<br>
- offset,<br>
- offset + size);<br>
- if (r)<br>
- goto error_pin;<br>
-<br>
- if (bo_ptr)<br>
- *bo_ptr = bo;<br>
-<br>
- amdgpu_bo_unreserve(bo);<br>
- return r;<br>
-<br>
-error_pin:<br>
- amdgpu_bo_unreserve(bo);<br>
-error_reserve:<br>
- amdgpu_bo_unref(&bo);<br>
- return r;<br>
-}<br>
-<br>
/* alloc/realloc bps array */<br>
static int amdgpu_ras_realloc_eh_data_space(struct amdgpu_device *adev,<br>
struct ras_err_handler_data *data, int pages)<br>
@@ -1478,8 +1403,9 @@ int amdgpu_ras_reserve_bad_pages(struct amdgpu_device *adev)<br>
for (i = data->last_reserved; i < data->count; i++) {<br>
bp = data->bps[i].retired_page;<br>
<br>
- if (amdgpu_ras_reserve_vram(adev, bp << PAGE_SHIFT,<br>
- PAGE_SIZE, &bo))<br>
+ if (amdgpu_bo_create_kernel_at(adev, bp << PAGE_SIZE, PAGE_SIZE,<br>
+ AMDGPU_GEM_DOMAIN_VRAM,<br>
+ &bo, NULL))<br>
DRM_ERROR("RAS ERROR: reserve vram %llx fail\n", bp);<br>
<br>
data->bps_bo[i] = bo;<br>
@@ -1512,7 +1438,7 @@ static int amdgpu_ras_release_bad_pages(struct amdgpu_device *adev)<br>
for (i = data->last_reserved - 1; i >= 0; i--) {<br>
bo = data->bps_bo[i];<br>
<br>
- amdgpu_ras_release_vram(adev, &bo);<br>
+ amdgpu_bo_free_kernel(&bo, NULL, NULL);<br>
<br>
data->bps_bo[i] = bo;<br>
data->last_reserved = i;<br>
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c<br>
index c05638cf3f3d..00f8f38d7993 100644<br>
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c<br>
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c<br>
@@ -1645,81 +1645,25 @@ static void amdgpu_ttm_fw_reserve_vram_fini(struct amdgpu_device *adev)<br>
*/<br>
static int amdgpu_ttm_fw_reserve_vram_init(struct amdgpu_device *adev)<br>
{<br>
- struct ttm_operation_ctx ctx = { false, false };<br>
- struct amdgpu_bo_param bp;<br>
- int r = 0;<br>
- int i;<br>
- u64 vram_size = adev->gmc.visible_vram_size;<br>
- u64 offset = adev->fw_vram_usage.start_offset;<br>
- u64 size = adev->fw_vram_usage.size;<br>
- struct amdgpu_bo *bo;<br>
-<br>
- memset(&bp, 0, sizeof(bp));<br>
- bp.size = adev->fw_vram_usage.size;<br>
- bp.byte_align = PAGE_SIZE;<br>
- bp.domain = AMDGPU_GEM_DOMAIN_VRAM;<br>
- bp.flags = AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED |<br>
- AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS;<br>
- bp.type = ttm_bo_type_kernel;<br>
- bp.resv = NULL;<br>
+ uint64_t vram_size = adev->gmc.visible_vram_size;<br>
+ int r;<br>
+<br>
adev->fw_vram_usage.va = NULL;<br>
adev->fw_vram_usage.reserved_bo = NULL;<br>
<br>
- if (adev->fw_vram_usage.size > 0 &&<br>
- adev->fw_vram_usage.size <= vram_size) {<br>
-<br>
- r = amdgpu_bo_create(adev, &bp,<br>
- &adev->fw_vram_usage.reserved_bo);<br>
- if (r)<br>
- goto error_create;<br>
-<br>
- r = amdgpu_bo_reserve(adev->fw_vram_usage.reserved_bo, false);<br>
- if (r)<br>
- goto error_reserve;<br>
-<br>
- /* remove the original mem node and create a new one at the<br>
- * request position<br>
- */<br>
- bo = adev->fw_vram_usage.reserved_bo;<br>
- offset = ALIGN(offset, PAGE_SIZE);<br>
- for (i = 0; i < bo->placement.num_placement; ++i) {<br>
- bo->placements[i].fpfn = offset >> PAGE_SHIFT;<br>
- bo->placements[i].lpfn = (offset + size) >> PAGE_SHIFT;<br>
- }<br>
-<br>
- ttm_bo_mem_put(&bo->tbo, &bo->tbo.mem);<br>
- r = ttm_bo_mem_space(&bo->tbo, &bo->placement,<br>
- &bo->tbo.mem, &ctx);<br>
- if (r)<br>
- goto error_pin;<br>
-<br>
- r = amdgpu_bo_pin_restricted(adev->fw_vram_usage.reserved_bo,<br>
- AMDGPU_GEM_DOMAIN_VRAM,<br>
- adev->fw_vram_usage.start_offset,<br>
- (adev->fw_vram_usage.start_offset +<br>
- adev->fw_vram_usage.size));<br>
- if (r)<br>
- goto error_pin;<br>
- r = amdgpu_bo_kmap(adev->fw_vram_usage.reserved_bo,<br>
- &adev->fw_vram_usage.va);<br>
- if (r)<br>
- goto error_kmap;<br>
-<br>
- amdgpu_bo_unreserve(adev->fw_vram_usage.reserved_bo);<br>
- }<br>
- return r;<br>
+ if (adev->fw_vram_usage.size == 0 ||<br>
+ adev->fw_vram_usage.size > vram_size)<br>
+ return 0;<br>
<br>
-error_kmap:<br>
- amdgpu_bo_unpin(adev->fw_vram_usage.reserved_bo);<br>
-error_pin:<br>
- amdgpu_bo_unreserve(adev->fw_vram_usage.reserved_bo);<br>
-error_reserve:<br>
- amdgpu_bo_unref(&adev->fw_vram_usage.reserved_bo);<br>
-error_create:<br>
- adev->fw_vram_usage.va = NULL;<br>
- adev->fw_vram_usage.reserved_bo = NULL;<br>
+ return amdgpu_bo_create_kernel_at(adev,<br>
+ adev->fw_vram_usage.start_offset,<br>
+ adev->fw_vram_usage.size,<br>
+ AMDGPU_GEM_DOMAIN_VRAM,<br>
+ &adev->fw_vram_usage.reserved_bo,<br>
+ &adev->fw_vram_usage.va);<br>
return r;<br>
}<br>
+<br>
/**<br>
* amdgpu_ttm_init - Init the memory management (ttm) as well as various<br>
* gtt/vram related fields.<br>
-- <br>
2.17.1<br>
<br>
_______________________________________________<br>
amd-gfx mailing list<br>
amd-gfx@lists.freedesktop.org<br>
<a href="https://lists.freedesktop.org/mailman/listinfo/amd-gfx">https://lists.freedesktop.org/mailman/listinfo/amd-gfx</a></div>
</span></font></div>
</body>
</html>