Skip to contentSkip to conversation

drm/amdgpu: update the method to get fb_loc of memory training(V2)

PATCH In review Tianci Yin 3 participants 8 messages Dec 18, 2019 – Dec 19, 2019

Subsystems (2)
lore
Share & tools
lore

Tianci Yin

author
#0 lore raw

PATCH 1/2 drm/amdgpu: update the method to get fb_loc of memory training(V2)

From: "Tianci.Yin" <[email protected]>

The method of getting fb_loc changed from parsing VBIOS to taking certain offset from top of VRAM

Change-Id: I053b42fdb1d822722fa7980b2cd9f86b3fdce539

---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h           |  3 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.c  |  2 +-
 .../gpu/drm/amd/amdgpu/amdgpu_atomfirmware.c  | 38 ++-----------------
 .../gpu/drm/amd/amdgpu/amdgpu_atomfirmware.h  |  2 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c       |  6 ++-
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h       |  7 ++++
 drivers/gpu/drm/amd/include/atomfirmware.h    | 14 -------
 7 files changed, 19 insertions(+), 53 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1 -2
index a78a363b1d71..fa2cf8e7bc07 100644
@@ -642,9 +642,8 @@ struct amdgpu_fw_vram_usage {
 	struct amdgpu_bo *reserved_bo;
 	void *va;
 
-	/* Offset on the top of VRAM, used as c2p write buffer.
+	/* GDDR6 training support flag.
 	*/
-	u64 mem_train_fb_loc;
 	bool mem_train_support;
 };
 
drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.c +1 -1
index 9ba80d828876..fdd52d86a4d7 100644
@@ -2022,7 +2022,7 @@ int amdgpu_atombios_init(struct amdgpu_device *adev)
 	if (adev->is_atom_fw) {
 		amdgpu_atomfirmware_scratch_regs_init(adev);
 		amdgpu_atomfirmware_allocate_fb_scratch(adev);
-		ret = amdgpu_atomfirmware_get_mem_train_fb_loc(adev);
+		ret = amdgpu_atomfirmware_get_mem_train_info(adev);
 		if (ret) {
 			DRM_ERROR("Failed to get mem train fb location.\n");
 			return ret;
drivers/gpu/drm/amd/amdgpu/amdgpu_atomfirmware.c +4 -34
index ff4eb96bdfb5..58f9d8c3a17a 100644
@@ -525,16 +525,12 @@ static int gddr6_mem_train_support(struct amdgpu_device *adev)
 	return ret;
 }
 
-int amdgpu_atomfirmware_get_mem_train_fb_loc(struct amdgpu_device *adev)
+int amdgpu_atomfirmware_get_mem_train_info(struct amdgpu_device *adev)
 {
 	struct atom_context *ctx = adev->mode_info.atom_context;
-	unsigned char *bios = ctx->bios;
-	struct vram_reserve_block *reserved_block;
-	int index, block_number;
+	int index;
 	uint8_t frev, crev;
 	uint16_t data_offset, size;
-	uint32_t start_address_in_kb;
-	uint64_t offset;
 	int ret;
 
 	adev->fw_vram_usage.mem_train_support = false;
@@ -569,32 +565,6 @@ int amdgpu_atomfirmware_get_mem_train_fb_loc(struct amdgpu_device *adev)
 		return -EINVAL;
 	}
 
-	reserved_block = (struct vram_reserve_block *)
-		(bios + data_offset + sizeof(struct atom_common_table_header));
-	block_number = ((unsigned int)size - sizeof(struct atom_common_table_header))
-		/ sizeof(struct vram_reserve_block);
-	reserved_block += (block_number > 0) ? block_number-1 : 0;
-	DRM_DEBUG("block_number:0x%04x, last block: 0x%08xkb sz, %dkb fw, %dkb drv.\n",
-		  block_number,
-		  le32_to_cpu(reserved_block->start_address_in_kb),
-		  le16_to_cpu(reserved_block->used_by_firmware_in_kb),
-		  le16_to_cpu(reserved_block->used_by_driver_in_kb));
-	if (reserved_block->used_by_firmware_in_kb > 0) {
-		start_address_in_kb = le32_to_cpu(reserved_block->start_address_in_kb);
-		offset = (uint64_t)start_address_in_kb * ONE_KiB;
-		if ((offset & (ONE_MiB - 1)) < (4 * ONE_KiB + 1) ) {
-			offset -= ONE_MiB;
-		}
-
-		offset &= ~(ONE_MiB - 1);
-		adev->fw_vram_usage.mem_train_fb_loc = offset;
-		adev->fw_vram_usage.mem_train_support = true;
-		DRM_DEBUG("mem_train_fb_loc:0x%09llx.\n", offset);
-		ret = 0;
-	} else {
-		DRM_ERROR("used_by_firmware_in_kb is 0!\n");
-		ret = -EINVAL;
-	}
-
-	return ret;
+	adev->fw_vram_usage.mem_train_support = true;
+	return 0;
 }
drivers/gpu/drm/amd/amdgpu/amdgpu_atomfirmware.h +1 -1
index f871af5ea6f3..434fe2fa0089 100644
@@ -31,7 +31,7 @@ void amdgpu_atomfirmware_scratch_regs_init(struct amdgpu_device *adev);
 int amdgpu_atomfirmware_allocate_fb_scratch(struct amdgpu_device *adev);
 int amdgpu_atomfirmware_get_vram_info(struct amdgpu_device *adev,
 	int *vram_width, int *vram_type, int *vram_vendor);
-int amdgpu_atomfirmware_get_mem_train_fb_loc(struct amdgpu_device *adev);
+int amdgpu_atomfirmware_get_mem_train_info(struct amdgpu_device *adev);
 int amdgpu_atomfirmware_get_clock_info(struct amdgpu_device *adev);
 int amdgpu_atomfirmware_get_gfx_info(struct amdgpu_device *adev);
 bool amdgpu_atomfirmware_mem_ecc_supported(struct amdgpu_device *adev);
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +5 -1
index 2ff63d0414c9..ce5cb854bdb9 100644
@@ -1705,7 +1705,11 @@ static int amdgpu_ttm_training_reserve_vram_init(struct amdgpu_device *adev)
 		return 0;
 	}
 
-	ctx->c2p_train_data_offset = adev->fw_vram_usage.mem_train_fb_loc;
+	ctx->c2p_train_data_offset = adev->gmc.mc_vram_size;
+	if ((ctx->c2p_train_data_offset & (ONE_MiB - 1)) < (4 * ONE_KiB + 1) ) {
+		ctx->c2p_train_data_offset -= ONE_MiB;
+	}
+	ctx->c2p_train_data_offset &= ~(ONE_MiB - 1);
 	ctx->p2c_train_data_offset = (adev->gmc.mc_vram_size - GDDR6_MEM_TRAINING_OFFSET);
 	ctx->train_data_size = GDDR6_MEM_TRAINING_DATA_SIZE_IN_BYTES;
 
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h +7 -0
index f1ebd424510c..19eb3e8456c7 100644
@@ -66,6 +66,13 @@ struct amdgpu_copy_mem {
 	unsigned long			offset;
 };
 
+/* Definitions for constance */
+enum amdgpu_internal_constants
+{
+	ONE_KiB	= 0x400,
+	ONE_MiB	= 0x100000,
+};
+
 extern const struct ttm_mem_type_manager_func amdgpu_gtt_mgr_func;
 extern const struct ttm_mem_type_manager_func amdgpu_vram_mgr_func;
 
drivers/gpu/drm/amd/include/atomfirmware.h +0 -14
index dd7cbc00a0aa..70146518174c 100644
@@ -672,20 +672,6 @@ struct vram_usagebyfirmware_v2_1
   uint16_t  used_by_driver_in_kb; 
 };
 
-/* This is part of vram_usagebyfirmware_v2_1 */
-struct vram_reserve_block
-{
-	uint32_t start_address_in_kb;
-	uint16_t used_by_firmware_in_kb;
-	uint16_t used_by_driver_in_kb;
-};
-
-/* Definitions for constance */
-enum atomfirmware_internal_constants
-{
-	ONE_KiB	= 0x400,
-	ONE_MiB	= 0x100000,
-};
 
 /* 
   ***************************************************************************
Signature · 6 lines
2.17.1

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
author
#1 lore raw

PATCH 2/2 drm/amdgpu: remove memory training p2c buffer reservation(V2)

From: "Tianci.Yin" <[email protected]>

IP discovery TMR(occupied the top VRAM with size DISCOVERY_TMR_SIZE) has been reserved, and the p2c buffer is in the range of this TMR, so the p2c buffer reservation is unnecessary.

Change-Id Ib1f2f2b4a1f3869c03ffe22e2836cdbee17ba99f
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_psp.h |  1 -
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 21 ++-------------------
 2 files changed, 2 insertions(+), 20 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.h +0 -1
index 5f8fd3e3535b..3265487b859f 100644
@@ -202,7 +202,6 @@ struct psp_memory_training_context {
 
 	/*vram offset of the p2c training data*/
 	u64 p2c_train_data_offset;
-	struct amdgpu_bo *p2c_bo;
 
 	/*vram offset of the c2p training data*/
 	u64 c2p_train_data_offset;
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +2 -19
index ce5cb854bdb9..476ea4a4dc03 100644
@@ -1681,9 +1681,6 @@ static int amdgpu_ttm_training_reserve_vram_fini(struct amdgpu_device *adev)
 	amdgpu_bo_free_kernel(&ctx->c2p_bo, NULL, NULL);
 	ctx->c2p_bo = NULL;
 
-	amdgpu_bo_free_kernel(&ctx->p2c_bo, NULL, NULL);
-	ctx->p2c_bo = NULL;
-
 	return 0;
 }
 
@@ -1718,17 +1715,6 @@ static int amdgpu_ttm_training_reserve_vram_init(struct amdgpu_device *adev)
 		  ctx->p2c_train_data_offset,
 		  ctx->c2p_train_data_offset);
 
-	ret = amdgpu_bo_create_kernel_at(adev,
-					 ctx->p2c_train_data_offset,
-					 ctx->train_data_size,
-					 AMDGPU_GEM_DOMAIN_VRAM,
-					 &ctx->p2c_bo,
-					 NULL);
-	if (ret) {
-		DRM_ERROR("alloc p2c_bo failed(%d)!\n", ret);
-		goto Err_out;
-	}
-
 	ret = amdgpu_bo_create_kernel_at(adev,
 					 ctx->c2p_train_data_offset,
 					 ctx->train_data_size,
@@ -1737,15 +1723,12 @@ static int amdgpu_ttm_training_reserve_vram_init(struct amdgpu_device *adev)
 					 NULL);
 	if (ret) {
 		DRM_ERROR("alloc c2p_bo failed(%d)!\n", ret);
-		goto Err_out;
+		amdgpu_ttm_training_reserve_vram_fini(adev);
+		return ret;
 	}
 
 	ctx->init = PSP_MEM_TRAIN_RESERVE_SUCCESS;
 	return 0;
-
-Err_out:
-	amdgpu_ttm_training_reserve_vram_fini(adev);
-	return ret;
 }
 
 /**
Signature · 6 lines
2.17.1

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Reviewed-by on v1 2/2
#2 lore raw

Re: [PATCH 2/2] drm/amdgpu: remove memory training p2c buffer reservation(V2)

[AMD Official Use Only - Internal Distribution Only]

Best Regards,
Kevin

________________________________
From: Tianci Yin <[email protected]>
Sent: Wednesday, December 18, 2019 4:50 PM
To: [email protected] <[email protected]>
Cc: Tuikov, Luben <[email protected]>; Koenig, Christian <[email protected]>; Deucher, Alexander <[email protected]>; Zhang, Hawking <[email protected]>; Xu, Feifei <[email protected]>; Yuan, Xiaojie <[email protected]>; Long, Gang <[email protected]>; Wang, Kevin(Yang) <[email protected]>; Yin, Tianci (Rico) <[email protected]>
Subject: [PATCH 2/2] drm/amdgpu: remove memory training p2c buffer reservation(V2)

From: "Tianci.Yin" <[email protected]>

IP discovery TMR(occupied the top VRAM with size DISCOVERY_TMR_SIZE) has been reserved, and the p2c buffer is in the range of this TMR, so the p2c buffer reservation is unnecessary.

Change-Id Ib1f2f2b4a1f3869c03ffe22e2836cdbee17ba99f
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_psp.h |  1 -
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 21 ++-------------------
 2 files changed, 2 insertions(+), 20 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.h +0 -1
index 5f8fd3e3535b..3265487b859f 100644
@@ -202,7 +202,6 @@ struct psp_memory_training_context {
 
         /*vram offset of the p2c training data*/
         u64 p2c_train_data_offset;
-       struct amdgpu_bo *p2c_bo;
 
         /*vram offset of the c2p training data*/
         u64 c2p_train_data_offset;
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +2 -19
index ce5cb854bdb9..476ea4a4dc03 100644
@@ -1681,9 +1681,6 @@ static int amdgpu_ttm_training_reserve_vram_fini(struct amdgpu_device *adev)
         amdgpu_bo_free_kernel(&ctx->c2p_bo, NULL, NULL);
         ctx->c2p_bo = NULL;
 
-       amdgpu_bo_free_kernel(&ctx->p2c_bo, NULL, NULL);
-       ctx->p2c_bo = NULL;
-
         return 0;
 }
 
@@ -1718,17 +1715,6 @@ static int amdgpu_ttm_training_reserve_vram_init(struct amdgpu_device *adev)
                   ctx->p2c_train_data_offset,
                   ctx->c2p_train_data_offset);
 
-       ret = amdgpu_bo_create_kernel_at(adev,
-                                        ctx->p2c_train_data_offset,
-                                        ctx->train_data_size,
-                                        AMDGPU_GEM_DOMAIN_VRAM,
-                                        &ctx->p2c_bo,
-                                        NULL);
-       if (ret) {
-               DRM_ERROR("alloc p2c_bo failed(%d)!\n", ret);
-               goto Err_out;
-       }
-
         ret = amdgpu_bo_create_kernel_at(adev,
                                          ctx->c2p_train_data_offset,
                                          ctx->train_data_size,
@@ -1737,15 +1723,12 @@ static int amdgpu_ttm_training_reserve_vram_init(struct amdgpu_device *adev)
                                          NULL);
         if (ret) {
                 DRM_ERROR("alloc c2p_bo failed(%d)!\n", ret);
-               goto Err_out;
+               amdgpu_ttm_training_reserve_vram_fini(adev);
+               return ret;
         }
 
         ctx->init = PSP_MEM_TRAIN_RESERVE_SUCCESS;
         return 0;
-
-Err_out:
-       amdgpu_ttm_training_reserve_vram_fini(adev);
-       return ret;
 }
 
 /**

--
2.17.1

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

author Reviewed-by Kevin Wang
#3 lore raw

Re: [PATCH 2/2] drm/amdgpu: remove memory training p2c buffer reservation(V2)

Thanks Kevin!
________________________________
From: Wang, Kevin(Yang) <[email protected]>
Sent: Wednesday, December 18, 2019 16:53
To: Yin, Tianci (Rico) <[email protected]>; [email protected] <[email protected]>
Cc: Tuikov, Luben <[email protected]>; Koenig, Christian <[email protected]>; Deucher, Alexander <[email protected]>; Zhang, Hawking <[email protected]>; Xu, Feifei <[email protected]>; Yuan, Xiaojie <[email protected]>; Long, Gang <[email protected]>
Subject: Re: [PATCH 2/2] drm/amdgpu: remove memory training p2c buffer reservation(V2)

[AMD Official Use Only - Internal Distribution Only]

Best Regards,
Kevin

________________________________
From: Tianci Yin <[email protected]>
Sent: Wednesday, December 18, 2019 4:50 PM
To: [email protected] <[email protected]>
Cc: Tuikov, Luben <[email protected]>; Koenig, Christian <[email protected]>; Deucher, Alexander <[email protected]>; Zhang, Hawking <[email protected]>; Xu, Feifei <[email protected]>; Yuan, Xiaojie <[email protected]>; Long, Gang <[email protected]>; Wang, Kevin(Yang) <[email protected]>; Yin, Tianci (Rico) <[email protected]>
Subject: [PATCH 2/2] drm/amdgpu: remove memory training p2c buffer reservation(V2)

From: "Tianci.Yin" <[email protected]>

IP discovery TMR(occupied the top VRAM with size DISCOVERY_TMR_SIZE) has been reserved, and the p2c buffer is in the range of this TMR, so the p2c buffer reservation is unnecessary.

Change-Id Ib1f2f2b4a1f3869c03ffe22e2836cdbee17ba99f
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_psp.h |  1 -
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 21 ++-------------------
 2 files changed, 2 insertions(+), 20 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.h +0 -1
index 5f8fd3e3535b..3265487b859f 100644
@@ -202,7 +202,6 @@ struct psp_memory_training_context {
 
         /*vram offset of the p2c training data*/
         u64 p2c_train_data_offset;
-       struct amdgpu_bo *p2c_bo;
 
         /*vram offset of the c2p training data*/
         u64 c2p_train_data_offset;
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +2 -19
index ce5cb854bdb9..476ea4a4dc03 100644
@@ -1681,9 +1681,6 @@ static int amdgpu_ttm_training_reserve_vram_fini(struct amdgpu_device *adev)
         amdgpu_bo_free_kernel(&ctx->c2p_bo, NULL, NULL);
         ctx->c2p_bo = NULL;
 
-       amdgpu_bo_free_kernel(&ctx->p2c_bo, NULL, NULL);
-       ctx->p2c_bo = NULL;
-
         return 0;
 }
 
@@ -1718,17 +1715,6 @@ static int amdgpu_ttm_training_reserve_vram_init(struct amdgpu_device *adev)
                   ctx->p2c_train_data_offset,
                   ctx->c2p_train_data_offset);
 
-       ret = amdgpu_bo_create_kernel_at(adev,
-                                        ctx->p2c_train_data_offset,
-                                        ctx->train_data_size,
-                                        AMDGPU_GEM_DOMAIN_VRAM,
-                                        &ctx->p2c_bo,
-                                        NULL);
-       if (ret) {
-               DRM_ERROR("alloc p2c_bo failed(%d)!\n", ret);
-               goto Err_out;
-       }
-
         ret = amdgpu_bo_create_kernel_at(adev,
                                          ctx->c2p_train_data_offset,
                                          ctx->train_data_size,
@@ -1737,15 +1723,12 @@ static int amdgpu_ttm_training_reserve_vram_init(struct amdgpu_device *adev)
                                          NULL);
         if (ret) {
                 DRM_ERROR("alloc c2p_bo failed(%d)!\n", ret);
-               goto Err_out;
+               amdgpu_ttm_training_reserve_vram_fini(adev);
+               return ret;
         }
 
         ctx->init = PSP_MEM_TRAIN_RESERVE_SUCCESS;
         return 0;
-
-Err_out:
-       amdgpu_ttm_training_reserve_vram_fini(adev);
-       return ret;
 }
 
 /**

--
2.17.1

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

#4 lore raw
In reply to Tianci Yin

[AMD Official Use Only - Internal Distribution Only]

comment inline.
________________________________
From: Tianci Yin <[email protected]>
Sent: Wednesday, December 18, 2019 4:50 PM
To: [email protected] <[email protected]>
Cc: Tuikov, Luben <[email protected]>; Koenig, Christian <[email protected]>; Deucher, Alexander <[email protected]>; Zhang, Hawking <[email protected]>; Xu, Feifei <[email protected]>; Yuan, Xiaojie <[email protected]>; Long, Gang <[email protected]>; Wang, Kevin(Yang) <[email protected]>; Yin, Tianci (Rico) <[email protected]>
Subject: [PATCH 1/2] drm/amdgpu: update the method to get fb_loc of memory training(V2)

From: "Tianci.Yin" <[email protected]>

The method of getting fb_loc changed from parsing VBIOS to taking certain offset from top of VRAM

Change-Id: I053b42fdb1d822722fa7980b2cd9f86b3fdce539

---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h           |  3 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.c  |  2 +-
 .../gpu/drm/amd/amdgpu/amdgpu_atomfirmware.c  | 38 ++-----------------
 .../gpu/drm/amd/amdgpu/amdgpu_atomfirmware.h  |  2 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c       |  6 ++-
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h       |  7 ++++
 drivers/gpu/drm/amd/include/atomfirmware.h    | 14 -------
 7 files changed, 19 insertions(+), 53 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1 -2
index a78a363b1d71..fa2cf8e7bc07 100644
@@ -642,9 +642,8 @@ struct amdgpu_fw_vram_usage {
         struct amdgpu_bo *reserved_bo;
         void *va;
 
-       /* Offset on the top of VRAM, used as c2p write buffer.
+       /* GDDR6 training support flag.
         */
-       u64 mem_train_fb_loc;
         bool mem_train_support;
 };
 
drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.c +1 -1
index 9ba80d828876..fdd52d86a4d7 100644
@@ -2022,7 +2022,7 @@ int amdgpu_atombios_init(struct amdgpu_device *adev)
         if (adev->is_atom_fw) {
                 amdgpu_atomfirmware_scratch_regs_init(adev);
                 amdgpu_atomfirmware_allocate_fb_scratch(adev);
-               ret = amdgpu_atomfirmware_get_mem_train_fb_loc(adev);
+               ret = amdgpu_atomfirmware_get_mem_train_info(adev);
                 if (ret) {
                         DRM_ERROR("Failed to get mem train fb location.\n");
                         return ret;
drivers/gpu/drm/amd/amdgpu/amdgpu_atomfirmware.c +4 -34
index ff4eb96bdfb5..58f9d8c3a17a 100644
@@ -525,16 +525,12 @@ static int gddr6_mem_train_support(struct amdgpu_device *adev)
         return ret;
 }
 
-int amdgpu_atomfirmware_get_mem_train_fb_loc(struct amdgpu_device *adev)
+int amdgpu_atomfirmware_get_mem_train_info(struct amdgpu_device *adev)
 {
         struct atom_context *ctx = adev->mode_info.atom_context;
-       unsigned char *bios = ctx->bios;
-       struct vram_reserve_block *reserved_block;
-       int index, block_number;
+       int index;
         uint8_t frev, crev;
         uint16_t data_offset, size;
-       uint32_t start_address_in_kb;
-       uint64_t offset;
         int ret;
 
         adev->fw_vram_usage.mem_train_support = false;
@@ -569,32 +565,6 @@ int amdgpu_atomfirmware_get_mem_train_fb_loc(struct amdgpu_device *adev)
                 return -EINVAL;
         }
 
-       reserved_block = (struct vram_reserve_block *)
-               (bios + data_offset + sizeof(struct atom_common_table_header));
-       block_number = ((unsigned int)size - sizeof(struct atom_common_table_header))
-               / sizeof(struct vram_reserve_block);
-       reserved_block += (block_number > 0) ? block_number-1 : 0;
-       DRM_DEBUG("block_number:0x%04x, last block: 0x%08xkb sz, %dkb fw, %dkb drv.\n",
-                 block_number,
-                 le32_to_cpu(reserved_block->start_address_in_kb),
-                 le16_to_cpu(reserved_block->used_by_firmware_in_kb),
-                 le16_to_cpu(reserved_block->used_by_driver_in_kb));
-       if (reserved_block->used_by_firmware_in_kb > 0) {
-               start_address_in_kb = le32_to_cpu(reserved_block->start_address_in_kb);
-               offset = (uint64_t)start_address_in_kb * ONE_KiB;
-               if ((offset & (ONE_MiB - 1)) < (4 * ONE_KiB + 1) ) {
-                       offset -= ONE_MiB;
-               }
-
-               offset &= ~(ONE_MiB - 1);
-               adev->fw_vram_usage.mem_train_fb_loc = offset;
-               adev->fw_vram_usage.mem_train_support = true;
-               DRM_DEBUG("mem_train_fb_loc:0x%09llx.\n", offset);
-               ret = 0;
-       } else {
-               DRM_ERROR("used_by_firmware_in_kb is 0!\n");
-               ret = -EINVAL;
-       }
-
-       return ret;
+       adev->fw_vram_usage.mem_train_support = true;
+       return 0;
 }
drivers/gpu/drm/amd/amdgpu/amdgpu_atomfirmware.h +1 -1
index f871af5ea6f3..434fe2fa0089 100644
@@ -31,7 +31,7 @@ void amdgpu_atomfirmware_scratch_regs_init(struct amdgpu_device *adev);
 int amdgpu_atomfirmware_allocate_fb_scratch(struct amdgpu_device *adev);
 int amdgpu_atomfirmware_get_vram_info(struct amdgpu_device *adev,
         int *vram_width, int *vram_type, int *vram_vendor);
-int amdgpu_atomfirmware_get_mem_train_fb_loc(struct amdgpu_device *adev);
+int amdgpu_atomfirmware_get_mem_train_info(struct amdgpu_device *adev);
 int amdgpu_atomfirmware_get_clock_info(struct amdgpu_device *adev);
 int amdgpu_atomfirmware_get_gfx_info(struct amdgpu_device *adev);
 bool amdgpu_atomfirmware_mem_ecc_supported(struct amdgpu_device *adev);
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +5 -1
index 2ff63d0414c9..ce5cb854bdb9 100644
@@ -1705,7 +1705,11 @@ static int amdgpu_ttm_training_reserve_vram_init(struct amdgpu_device *adev)
                 return 0;
         }
 
-       ctx->c2p_train_data_offset = adev->fw_vram_usage.mem_train_fb_loc;
+       ctx->c2p_train_data_offset = adev->gmc.mc_vram_size;
+       if ((ctx->c2p_train_data_offset & (ONE_MiB - 1)) < (4 * ONE_KiB + 1) ) {
+               ctx->c2p_train_data_offset -= ONE_MiB;
+       }
+       ctx->c2p_train_data_offset &= ~(ONE_MiB - 1);
 

[kevin]:
i'd like to use the marco ALIGN() to simple above code. anyway, the patch Reviewed-by: Kevin Wang <[email protected]>

         ctx->p2c_train_data_offset = (adev->gmc.mc_vram_size - GDDR6_MEM_TRAINING_OFFSET);
         ctx->train_data_size = GDDR6_MEM_TRAINING_DATA_SIZE_IN_BYTES;
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h +7 -0
index f1ebd424510c..19eb3e8456c7 100644
@@ -66,6 +66,13 @@ struct amdgpu_copy_mem {
         unsigned long                   offset;
 };
 
+/* Definitions for constance */
+enum amdgpu_internal_constants
+{
+       ONE_KiB = 0x400,
+       ONE_MiB = 0x100000,
+};
+
 extern const struct ttm_mem_type_manager_func amdgpu_gtt_mgr_func;
 extern const struct ttm_mem_type_manager_func amdgpu_vram_mgr_func;
 
drivers/gpu/drm/amd/include/atomfirmware.h +0 -14
index dd7cbc00a0aa..70146518174c 100644
@@ -672,20 +672,6 @@ struct vram_usagebyfirmware_v2_1
   uint16_t  used_by_driver_in_kb;
 };
 
-/* This is part of vram_usagebyfirmware_v2_1 */
-struct vram_reserve_block
-{
-       uint32_t start_address_in_kb;
-       uint16_t used_by_firmware_in_kb;
-       uint16_t used_by_driver_in_kb;
-};
-
-/* Definitions for constance */
-enum atomfirmware_internal_constants
-{
-       ONE_KiB = 0x400,
-       ONE_MiB = 0x100000,
-};
 
 /*
   ***************************************************************************

--
2.17.1

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

#5 lore raw

Hi Kevin,

You mean like this? It's a bit lengthy.
- ctx->c2p_train_data_offset &= ~(ONE_MiB - 1);
+ ctx->c2p_train_data_offset = ALIGN(ctx->c2p_train_data_offset, ONE_MiB);

Rico

________________________________
From: Wang, Kevin(Yang) <[email protected]>
Sent: Wednesday, December 18, 2019 16:56
To: Yin, Tianci (Rico) <[email protected]>; [email protected] <[email protected]>
Cc: Tuikov, Luben <[email protected]>; Koenig, Christian <[email protected]>; Deucher, Alexander <[email protected]>; Zhang, Hawking <[email protected]>; Xu, Feifei <[email protected]>; Yuan, Xiaojie <[email protected]>; Long, Gang <[email protected]>
Subject: Re: [PATCH 1/2] drm/amdgpu: update the method to get fb_loc of memory training(V2)

[AMD Official Use Only - Internal Distribution Only]

comment inline.
________________________________
From: Tianci Yin <[email protected]>
Sent: Wednesday, December 18, 2019 4:50 PM
To: [email protected] <[email protected]>
Cc: Tuikov, Luben <[email protected]>; Koenig, Christian <[email protected]>; Deucher, Alexander <[email protected]>; Zhang, Hawking <[email protected]>; Xu, Feifei <[email protected]>; Yuan, Xiaojie <[email protected]>; Long, Gang <[email protected]>; Wang, Kevin(Yang) <[email protected]>; Yin, Tianci (Rico) <[email protected]>
Subject: [PATCH 1/2] drm/amdgpu: update the method to get fb_loc of memory training(V2)

From: "Tianci.Yin" <[email protected]>

The method of getting fb_loc changed from parsing VBIOS to taking certain offset from top of VRAM

Change-Id: I053b42fdb1d822722fa7980b2cd9f86b3fdce539

---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h           |  3 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.c  |  2 +-
 .../gpu/drm/amd/amdgpu/amdgpu_atomfirmware.c  | 38 ++-----------------
 .../gpu/drm/amd/amdgpu/amdgpu_atomfirmware.h  |  2 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c       |  6 ++-
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h       |  7 ++++
 drivers/gpu/drm/amd/include/atomfirmware.h    | 14 -------
 7 files changed, 19 insertions(+), 53 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1 -2
index a78a363b1d71..fa2cf8e7bc07 100644
@@ -642,9 +642,8 @@ struct amdgpu_fw_vram_usage {
         struct amdgpu_bo *reserved_bo;
         void *va;
 
-       /* Offset on the top of VRAM, used as c2p write buffer.
+       /* GDDR6 training support flag.
         */
-       u64 mem_train_fb_loc;
         bool mem_train_support;
 };
 
drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.c +1 -1
index 9ba80d828876..fdd52d86a4d7 100644
@@ -2022,7 +2022,7 @@ int amdgpu_atombios_init(struct amdgpu_device *adev)
         if (adev->is_atom_fw) {
                 amdgpu_atomfirmware_scratch_regs_init(adev);
                 amdgpu_atomfirmware_allocate_fb_scratch(adev);
-               ret = amdgpu_atomfirmware_get_mem_train_fb_loc(adev);
+               ret = amdgpu_atomfirmware_get_mem_train_info(adev);
                 if (ret) {
                         DRM_ERROR("Failed to get mem train fb location.\n");
                         return ret;
drivers/gpu/drm/amd/amdgpu/amdgpu_atomfirmware.c +4 -34
index ff4eb96bdfb5..58f9d8c3a17a 100644
@@ -525,16 +525,12 @@ static int gddr6_mem_train_support(struct amdgpu_device *adev)
         return ret;
 }
 
-int amdgpu_atomfirmware_get_mem_train_fb_loc(struct amdgpu_device *adev)
+int amdgpu_atomfirmware_get_mem_train_info(struct amdgpu_device *adev)
 {
         struct atom_context *ctx = adev->mode_info.atom_context;
-       unsigned char *bios = ctx->bios;
-       struct vram_reserve_block *reserved_block;
-       int index, block_number;
+       int index;
         uint8_t frev, crev;
         uint16_t data_offset, size;
-       uint32_t start_address_in_kb;
-       uint64_t offset;
         int ret;
 
         adev->fw_vram_usage.mem_train_support = false;
@@ -569,32 +565,6 @@ int amdgpu_atomfirmware_get_mem_train_fb_loc(struct amdgpu_device *adev)
                 return -EINVAL;
         }
 
-       reserved_block = (struct vram_reserve_block *)
-               (bios + data_offset + sizeof(struct atom_common_table_header));
-       block_number = ((unsigned int)size - sizeof(struct atom_common_table_header))
-               / sizeof(struct vram_reserve_block);
-       reserved_block += (block_number > 0) ? block_number-1 : 0;
-       DRM_DEBUG("block_number:0x%04x, last block: 0x%08xkb sz, %dkb fw, %dkb drv.\n",
-                 block_number,
-                 le32_to_cpu(reserved_block->start_address_in_kb),
-                 le16_to_cpu(reserved_block->used_by_firmware_in_kb),
-                 le16_to_cpu(reserved_block->used_by_driver_in_kb));
-       if (reserved_block->used_by_firmware_in_kb > 0) {
-               start_address_in_kb = le32_to_cpu(reserved_block->start_address_in_kb);
-               offset = (uint64_t)start_address_in_kb * ONE_KiB;
-               if ((offset & (ONE_MiB - 1)) < (4 * ONE_KiB + 1) ) {
-                       offset -= ONE_MiB;
-               }
-
-               offset &= ~(ONE_MiB - 1);
-               adev->fw_vram_usage.mem_train_fb_loc = offset;
-               adev->fw_vram_usage.mem_train_support = true;
-               DRM_DEBUG("mem_train_fb_loc:0x%09llx.\n", offset);
-               ret = 0;
-       } else {
-               DRM_ERROR("used_by_firmware_in_kb is 0!\n");
-               ret = -EINVAL;
-       }
-
-       return ret;
+       adev->fw_vram_usage.mem_train_support = true;
+       return 0;
 }
drivers/gpu/drm/amd/amdgpu/amdgpu_atomfirmware.h +1 -1
index f871af5ea6f3..434fe2fa0089 100644
@@ -31,7 +31,7 @@ void amdgpu_atomfirmware_scratch_regs_init(struct amdgpu_device *adev);
 int amdgpu_atomfirmware_allocate_fb_scratch(struct amdgpu_device *adev);
 int amdgpu_atomfirmware_get_vram_info(struct amdgpu_device *adev,
         int *vram_width, int *vram_type, int *vram_vendor);
-int amdgpu_atomfirmware_get_mem_train_fb_loc(struct amdgpu_device *adev);
+int amdgpu_atomfirmware_get_mem_train_info(struct amdgpu_device *adev);
 int amdgpu_atomfirmware_get_clock_info(struct amdgpu_device *adev);
 int amdgpu_atomfirmware_get_gfx_info(struct amdgpu_device *adev);
 bool amdgpu_atomfirmware_mem_ecc_supported(struct amdgpu_device *adev);
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +5 -1
index 2ff63d0414c9..ce5cb854bdb9 100644
@@ -1705,7 +1705,11 @@ static int amdgpu_ttm_training_reserve_vram_init(struct amdgpu_device *adev)
                 return 0;
         }
 
-       ctx->c2p_train_data_offset = adev->fw_vram_usage.mem_train_fb_loc;
+       ctx->c2p_train_data_offset = adev->gmc.mc_vram_size;
+       if ((ctx->c2p_train_data_offset & (ONE_MiB - 1)) < (4 * ONE_KiB + 1) ) {
+               ctx->c2p_train_data_offset -= ONE_MiB;
+       }
+       ctx->c2p_train_data_offset &= ~(ONE_MiB - 1);
 

[kevin]:
i'd like to use the marco ALIGN() to simple above code. anyway, the patch Reviewed-by: Kevin Wang <[email protected]>

         ctx->p2c_train_data_offset = (adev->gmc.mc_vram_size - GDDR6_MEM_TRAINING_OFFSET);
         ctx->train_data_size = GDDR6_MEM_TRAINING_DATA_SIZE_IN_BYTES;
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h +7 -0
index f1ebd424510c..19eb3e8456c7 100644
@@ -66,6 +66,13 @@ struct amdgpu_copy_mem {
         unsigned long                   offset;
 };
 
+/* Definitions for constance */
+enum amdgpu_internal_constants
+{
+       ONE_KiB = 0x400,
+       ONE_MiB = 0x100000,
+};
+
 extern const struct ttm_mem_type_manager_func amdgpu_gtt_mgr_func;
 extern const struct ttm_mem_type_manager_func amdgpu_vram_mgr_func;
 
drivers/gpu/drm/amd/include/atomfirmware.h +0 -14
index dd7cbc00a0aa..70146518174c 100644
@@ -672,20 +672,6 @@ struct vram_usagebyfirmware_v2_1
   uint16_t  used_by_driver_in_kb;
 };
 
-/* This is part of vram_usagebyfirmware_v2_1 */
-struct vram_reserve_block
-{
-       uint32_t start_address_in_kb;
-       uint16_t used_by_firmware_in_kb;
-       uint16_t used_by_driver_in_kb;
-};
-
-/* Definitions for constance */
-enum atomfirmware_internal_constants
-{
-       ONE_KiB = 0x400,
-       ONE_MiB = 0x100000,
-};
 
 /*
   ***************************************************************************

--
2.17.1

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

#6 lore raw
Quoted 6 lines · Tianci (Rico)

Hi Kevin,

You mean like this? It's a bit lengthy.
- ctx->c2p_train_data_offset &= ~(ONE_MiB - 1);
+ ctx->c2p_train_data_offset = ALIGN(ctx->c2p_train_data_offset, ONE_MiB);

Quoted 6 lines

-       ctx->c2p_train_data_offset = adev->fw_vram_usage.mem_train_fb_loc; +       ctx->c2p_train_data_offset = adev->gmc.mc_vram_size;
+       if ((ctx->c2p_train_data_offset & (ONE_MiB - 1)) < (4 * ONE_KiB + 1) ) { +               ctx->c2p_train_data_offset -= ONE_MiB;
+       }
+       ctx->c2p_train_data_offset &= ~(ONE_MiB - 1);

Using the macro ALIGN() is a good practice.
Usually when calculating a quantity, such as the one above, you'd use a working variable, say 'a', and after you're done with the calculation, you'd then assign it to the variable which needs it. Something like this:

a = adev->gmc.mc_vram_size;
if ((a & (ONE_MiB - 1)) < (4 * ONE_KiB + 1))

	a -= ONE_MiB;

ctx->c2p_train_data_offset = ALIGN(a, ONE_MiB);

The easiest way to see this is, imagine, if all this calculation was offloaded to a dedicated function, f(), to do:

ctx->c2p_train_data_offset = f(adev->gmc.mc_vram_size);

Now, by using the working variable 'a', you've shown this abstraction just the same. (By using the working variable 'a', you've shown to the reader,that this calculation is abstracted, and could be relocated to a function.)

Regards,
Luben
P.S. The compiler is probably already doing this, and not working directly on the ctx->c2p_train_data_offs, but assigns a final result, as explicitly shown above. The above is to make it easy for humans to read and understand the code. Hope this helps.

Quoted 48 lines

*[kevin]:*
*i'd like to use the marco ALIGN() to simple above code.* *anyway, the patch Reviewed-by: Kevin Wang <[email protected]>*

         ctx->p2c_train_data_offset = (adev->gmc.mc_vram_size - GDDR6_MEM_TRAINING_OFFSET); ctx->train_data_size = GDDR6_MEM_TRAINING_DATA_SIZE_IN_BYTES;

drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h +0 -0
index f1ebd424510c..19eb3e8456c7 100644
@@ -66,6 +66,13 @@ struct amdgpu_copy_mem {
          unsigned long                   offset;
  };

drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h +7 -0
+/* Definitions for constance */
+enum amdgpu_internal_constants
+{
+       ONE_KiB = 0x400,
+       ONE_MiB = 0x100000,
+};
+

 extern const struct ttm_mem_type_manager_func amdgpu_gtt_mgr_func; extern const struct ttm_mem_type_manager_func amdgpu_vram_mgr_func;

drivers/gpu/drm/amd/include/atomfirmware.h +0 -0
index dd7cbc00a0aa..70146518174c 100644
@@ -672,20 +672,6 @@ struct vram_usagebyfirmware_v2_1
    uint16_t  used_by_driver_in_kb;
  };

drivers/gpu/drm/amd/include/atomfirmware.h +0 -14
-/* This is part of vram_usagebyfirmware_v2_1 */
-struct vram_reserve_block
-{
-       uint32_t start_address_in_kb;
-       uint16_t used_by_firmware_in_kb;
-       uint16_t used_by_driver_in_kb;
-};
-
-/* Definitions for constance */
-enum atomfirmware_internal_constants
-{
-       ONE_KiB = 0x400,
-       ONE_MiB = 0x100000,
-};
Quoted 6 lines


 /*
   ***************************************************************************

Signature · 1 line
2.17.1

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

#7 lore raw

[AMD Official Use Only - Internal Distribution Only]

Hi Luben,

Thank you very much for your suggestion and detailed explanation!

Patch has been refined, please help review.

Rico
________________________________
From: Tuikov, Luben <[email protected]>
Sent: Thursday, December 19, 2019 4:14
To: Yin, Tianci (Rico) <[email protected]>; Wang, Kevin(Yang) <[email protected]>; [email protected] <[email protected]>
Cc: Koenig, Christian <[email protected]>; Deucher, Alexander <[email protected]>; Zhang, Hawking <[email protected]>; Xu, Feifei <[email protected]>; Yuan, Xiaojie <[email protected]>; Long, Gang <[email protected]>
Subject: Re: [PATCH 1/2] drm/amdgpu: update the method to get fb_loc of memory training(V2)

drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c static int amdgpu_ttm_training_reserve_vram_init(struct amdgpu_device *adev) · line 1712

Quoted 12 lines · Tianci (Rico)

Hi Kevin,

You mean like this? It's a bit lengthy.
- ctx->c2p_train_data_offset &= ~(ONE_MiB - 1);
+ ctx->c2p_train_data_offset = ALIGN(ctx->c2p_train_data_offset, ONE_MiB);

drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +5 -1
-       ctx->c2p_train_data_offset = adev->fw_vram_usage.mem_train_fb_loc;
+       ctx->c2p_train_data_offset = adev->gmc.mc_vram_size;
+       if ((ctx->c2p_train_data_offset & (ONE_MiB - 1)) < (4 * ONE_KiB + 1) ) {
+               ctx->c2p_train_data_offset -= ONE_MiB;
+       }
+       ctx->c2p_train_data_offset &= ~(ONE_MiB - 1);

Using the macro ALIGN() is a good practice.
Usually when calculating a quantity, such as the one above, you'd use a working variable, say 'a', and after you're done with the calculation, you'd then assign it to the variable which needs it. Something like this:

a = adev->gmc.mc_vram_size;
if ((a & (ONE_MiB - 1)) < (4 * ONE_KiB + 1))

        a -= ONE_MiB;

ctx->c2p_train_data_offset = ALIGN(a, ONE_MiB);

The easiest way to see this is, imagine, if all this calculation was offloaded to a dedicated function, f(), to do:

ctx->c2p_train_data_offset = f(adev->gmc.mc_vram_size);

Now, by using the working variable 'a', you've shown this abstraction just the same. (By using the working variable 'a', you've shown to the reader,that this calculation is abstracted, and could be relocated to a function.)

Regards,
Luben
P.S. The compiler is probably already doing this, and not working directly on the ctx->c2p_train_data_offs, but assigns a final result, as explicitly shown above. The above is to make it easy for humans to read and understand the code. Hope this helps.

Quoted 52 lines

*[kevin]:*
*i'd like to use the marco ALIGN() to simple above code.* *anyway, the patch Reviewed-by: Kevin Wang <[email protected]>*

         ctx->p2c_train_data_offset = (adev->gmc.mc_vram_size - GDDR6_MEM_TRAINING_OFFSET);
         ctx->train_data_size = GDDR6_MEM_TRAINING_DATA_SIZE_IN_BYTES;
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h +7 -0
index f1ebd424510c..19eb3e8456c7 100644
@@ -66,6 +66,13 @@ struct amdgpu_copy_mem {
         unsigned long                   offset;
 };
 
+/* Definitions for constance */
+enum amdgpu_internal_constants
+{
+       ONE_KiB = 0x400,
+       ONE_MiB = 0x100000,
+};
+
 extern const struct ttm_mem_type_manager_func amdgpu_gtt_mgr_func;
 extern const struct ttm_mem_type_manager_func amdgpu_vram_mgr_func;
 
drivers/gpu/drm/amd/include/atomfirmware.h +0 -15
index dd7cbc00a0aa..70146518174c 100644
@@ -672,20 +672,6 @@ struct vram_usagebyfirmware_v2_1
   uint16_t  used_by_driver_in_kb;
 };
 
-/* This is part of vram_usagebyfirmware_v2_1 */
-struct vram_reserve_block
-{
-       uint32_t start_address_in_kb;
-       uint16_t used_by_firmware_in_kb;
-       uint16_t used_by_driver_in_kb;
-};
-
-/* Definitions for constance */
-enum atomfirmware_internal_constants
-{
-       ONE_KiB = 0x400,
-       ONE_MiB = 0x100000,
-};
 
 /*
   ***************************************************************************
--
Quoted 2 lines

2.17.1

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx