<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<p style="font-family:Calibri;font-size:10pt;color:#008000;margin:5pt;font-style:normal;font-weight:normal;text-decoration:none;" align="Left">
[Public]<br>
</p>
<br>
<div>
<div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Reviewed-by: Alex Deucher <alexander.deucher@amd.com></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> Min, Frank <Frank.Min@amd.com><br>
<b>Sent:</b> Sunday, June 30, 2024 11:17 PM<br>
<b>To:</b> Deucher, Alexander <Alexander.Deucher@amd.com>; Olsak, Marek <Marek.Olsak@amd.com>; Koenig, Christian <Christian.Koenig@amd.com>; Zhang, Hawking <Hawking.Zhang@amd.com>; Gao, Likun <Likun.Gao@amd.com>; amd-gfx@lists.freedesktop.org <amd-gfx@lists.freedesktop.org><br>
<b>Subject:</b> [PATCH] drm/amdgpu: restore dcc bo tilling configs while moving</font>
<div> </div>
</div>
<div class="BodyFragment"><font face="Times New Roman" size="3"><span style="font-size:12pt;"><a name="BM_BEGIN"></a>
<div><font size="2"><span style="font-size:11pt;">[AMD Official Use Only - AMD Internal Distribution Only]<br>
<br>
From: Frank Min <Frank.Min@amd.com><br>
<br>
While moving buffer which as dcc tiling config, it is needed to restore its original dcc tiling.<br>
<br>
1. extend copy flag to cover tiling bits<br>
<br>
2. add logic to restore original dcc tiling config<br>
<br>
Signed-off-by: Frank Min <Frank.Min@amd.com><br>
---<br>
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 17 ++++++++++++++--- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h | 11 +++++++++++ drivers/gpu/drm/amd/amdgpu/sdma_v7_0.c | 10 ++++++++--<br>
3 files changed, 33 insertions(+), 5 deletions(-)<br>
<br>
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c<br>
index 9a92dd3c9fb8..dd4aed47af1e 100644<br>
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c<br>
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c<br>
@@ -308,7 +308,8 @@ int amdgpu_ttm_copy_mem_to_mem(struct amdgpu_device *adev,<br>
<br>
mutex_lock(&adev->mman.gtt_window_lock);<br>
while (src_mm.remaining) {<br>
- uint64_t from, to, cur_size;<br>
+ uint64_t from, to, cur_size, tiling_flags;<br>
+ uint32_t num_type, data_format, max_com;<br>
struct dma_fence *next;<br>
<br>
/* Never copy more than 256MiB at once to avoid a timeout */ @@ -329,10 +330,20 @@ int amdgpu_ttm_copy_mem_to_mem(struct amdgpu_device *adev,<br>
abo_dst = ttm_to_amdgpu_bo(dst->bo);<br>
if (tmz)<br>
copy_flags |= AMDGPU_COPY_FLAGS_TMZ;<br>
- if (abo_src->flags & AMDGPU_GEM_CREATE_GFX12_DCC)<br>
+ if ((abo_src->flags & AMDGPU_GEM_CREATE_GFX12_DCC) &&<br>
+ (abo_src->tbo.resource->mem_type == TTM_PL_VRAM))<br>
copy_flags |= AMDGPU_COPY_FLAGS_READ_DECOMPRESSED;<br>
- if (abo_dst->flags & AMDGPU_GEM_CREATE_GFX12_DCC)<br>
+ if ((abo_dst->flags & AMDGPU_GEM_CREATE_GFX12_DCC) &&<br>
+ (dst->mem->mem_type == TTM_PL_VRAM)) {<br>
copy_flags |= AMDGPU_COPY_FLAGS_WRITE_COMPRESSED;<br>
+ amdgpu_bo_get_tiling_flags(abo_dst, &tiling_flags);<br>
+ max_com = AMDGPU_TILING_GET(tiling_flags, GFX12_DCC_MAX_COMPRESSED_BLOCK);<br>
+ num_type = AMDGPU_TILING_GET(tiling_flags, GFX12_DCC_NUMBER_TYPE);<br>
+ data_format = AMDGPU_TILING_GET(tiling_flags, GFX12_DCC_DATA_FORMAT);<br>
+ copy_flags |= (AMDGPU_COPY_FLAGS_SET(MAX_COMPRESSED, max_com) |<br>
+ AMDGPU_COPY_FLAGS_SET(NUMBER_TYPE, num_type) |<br>
+ AMDGPU_COPY_FLAGS_SET(DATA_FORMAT, data_format));<br>
+ }<br>
<br>
r = amdgpu_copy_buffer(ring, from, to, cur_size, resv,<br>
&next, false, true, copy_flags); diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h<br>
index 7c903a6c9ddb..8d34e8588dc2 100644<br>
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h<br>
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h<br>
@@ -114,6 +114,17 @@ struct amdgpu_copy_mem {<br>
#define AMDGPU_COPY_FLAGS_TMZ (1 << 0)<br>
#define AMDGPU_COPY_FLAGS_READ_DECOMPRESSED (1 << 1)<br>
#define AMDGPU_COPY_FLAGS_WRITE_COMPRESSED (1 << 2)<br>
+#define AMDGPU_COPY_FLAGS_MAX_COMPRESSED_SHIFT 3<br>
+#define AMDGPU_COPY_FLAGS_MAX_COMPRESSED_MASK 0x03<br>
+#define AMDGPU_COPY_FLAGS_NUMBER_TYPE_SHIFT 5<br>
+#define AMDGPU_COPY_FLAGS_NUMBER_TYPE_MASK 0x07<br>
+#define AMDGPU_COPY_FLAGS_DATA_FORMAT_SHIFT 8<br>
+#define AMDGPU_COPY_FLAGS_DATA_FORMAT_MASK 0x3f<br>
+<br>
+#define AMDGPU_COPY_FLAGS_SET(field, value) \<br>
+ (((__u32)(value) & AMDGPU_COPY_FLAGS_##field##_MASK) <<<br>
+AMDGPU_COPY_FLAGS_##field##_SHIFT)<br>
+#define AMDGPU_COPY_FLAGS_GET(value, field) \<br>
+ (((__u32)(value) >> AMDGPU_COPY_FLAGS_##field##_SHIFT) &<br>
+AMDGPU_COPY_FLAGS_##field##_MASK)<br>
<br>
int amdgpu_gtt_mgr_init(struct amdgpu_device *adev, uint64_t gtt_size); void amdgpu_gtt_mgr_fini(struct amdgpu_device *adev); diff --git a/drivers/gpu/drm/amd/amdgpu/sdma_v7_0.c b/drivers/gpu/drm/amd/amdgpu/sdma_v7_0.c<br>
index 96514fd77e35..41b5e45697dc 100644<br>
--- a/drivers/gpu/drm/amd/amdgpu/sdma_v7_0.c<br>
+++ b/drivers/gpu/drm/amd/amdgpu/sdma_v7_0.c<br>
@@ -1566,6 +1566,12 @@ static void sdma_v7_0_emit_copy_buffer(struct amdgpu_ib *ib,<br>
uint32_t byte_count,<br>
uint32_t copy_flags)<br>
{<br>
+ uint32_t num_type, data_format, max_com;<br>
+<br>
+ max_com = AMDGPU_COPY_FLAGS_GET(copy_flags, MAX_COMPRESSED);<br>
+ data_format = AMDGPU_COPY_FLAGS_GET(copy_flags, DATA_FORMAT);<br>
+ num_type = AMDGPU_COPY_FLAGS_GET(copy_flags, NUMBER_TYPE);<br>
+<br>
ib->ptr[ib->length_dw++] = SDMA_PKT_COPY_LINEAR_HEADER_OP(SDMA_OP_COPY) |<br>
SDMA_PKT_COPY_LINEAR_HEADER_SUB_OP(SDMA_SUBOP_COPY_LINEAR) |<br>
SDMA_PKT_COPY_LINEAR_HEADER_TMZ((copy_flags & AMDGPU_COPY_FLAGS_TMZ) ? 1 : 0) | @@ -1580,10 +1586,10 @@ static void sdma_v7_0_emit_copy_buffer(struct amdgpu_ib *ib,<br>
ib->ptr[ib->length_dw++] = upper_32_bits(dst_offset);<br>
<br>
if ((copy_flags & (AMDGPU_COPY_FLAGS_READ_DECOMPRESSED | AMDGPU_COPY_FLAGS_WRITE_COMPRESSED)))<br>
- ib->ptr[ib->length_dw++] = SDMA_DCC_DATA_FORMAT(4) | SDMA_DCC_NUM_TYPE(4) |<br>
+ ib->ptr[ib->length_dw++] = SDMA_DCC_DATA_FORMAT(data_format) |<br>
+SDMA_DCC_NUM_TYPE(num_type) |<br>
((copy_flags & AMDGPU_COPY_FLAGS_READ_DECOMPRESSED) ? SDMA_DCC_READ_CM(2) : 0) |<br>
((copy_flags & AMDGPU_COPY_FLAGS_WRITE_COMPRESSED) ? SDMA_DCC_WRITE_CM(1) : 0) |<br>
- SDMA_DCC_MAX_COM(1) | SDMA_DCC_MAX_UCOM(1);<br>
+ SDMA_DCC_MAX_COM(max_com) | SDMA_DCC_MAX_UCOM(1);<br>
}<br>
<br>
/**<br>
--<br>
2.34.1<br>
<br>
</span></font></div>
</span></font></div>
</div>
</body>
</html>