Skip to contentSkip to conversation

drm/amdgpu: correction of ucode fw_size calculation errors

PATCH In review Kevin Wang 2 participants 2 messages Apr 13, 2021

Subsystems (3)
lore
Share & tools
lore

Kevin Wang

author
#0 lore raw

PATCH 1/1 drm/amdgpu: correction of ucode fw_size calculation errors

correct big and little endian problems on different platforms.

---
 drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c         | 8 ++++----
 drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c          | 2 +-
 drivers/gpu/drm/amd/pm/swsmu/smu11/smu_v11_0.c | 2 +-
 drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0.c | 2 +-
 4 files changed, 7 insertions(+), 7 deletions(-)
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +4 -4
index 85a6a10e048f..0a00a7cc8eaa 100644
@@ -4354,7 +4354,7 @@ static int gfx_v10_0_mec_init(struct amdgpu_device *adev)
 			 le32_to_cpu(mec_hdr->header.ucode_array_offset_bytes));
 		fw_size = le32_to_cpu(mec_hdr->header.ucode_size_bytes);
 
-		r = amdgpu_bo_create_reserved(adev, mec_hdr->header.ucode_size_bytes,
+		r = amdgpu_bo_create_reserved(adev, fw_size,
 					      PAGE_SIZE, AMDGPU_GEM_DOMAIN_GTT,
 					      &adev->gfx.mec.mec_fw_obj,
 					      &adev->gfx.mec.mec_fw_gpu_addr,
@@ -5769,7 +5769,7 @@ static int gfx_v10_0_cp_gfx_load_pfp_microcode(struct amdgpu_device *adev)
 		le32_to_cpu(pfp_hdr->header.ucode_array_offset_bytes));
 	fw_size = le32_to_cpu(pfp_hdr->header.ucode_size_bytes);
 
-	r = amdgpu_bo_create_reserved(adev, pfp_hdr->header.ucode_size_bytes,
+	r = amdgpu_bo_create_reserved(adev, fw_size,
 				      PAGE_SIZE, AMDGPU_GEM_DOMAIN_GTT,
 				      &adev->gfx.pfp.pfp_fw_obj,
 				      &adev->gfx.pfp.pfp_fw_gpu_addr,
@@ -5847,7 +5847,7 @@ static int gfx_v10_0_cp_gfx_load_ce_microcode(struct amdgpu_device *adev)
 		le32_to_cpu(ce_hdr->header.ucode_array_offset_bytes));
 	fw_size = le32_to_cpu(ce_hdr->header.ucode_size_bytes);
 
-	r = amdgpu_bo_create_reserved(adev, ce_hdr->header.ucode_size_bytes,
+	r = amdgpu_bo_create_reserved(adev, fw_size,
 				      PAGE_SIZE, AMDGPU_GEM_DOMAIN_GTT,
 				      &adev->gfx.ce.ce_fw_obj,
 				      &adev->gfx.ce.ce_fw_gpu_addr,
@@ -5924,7 +5924,7 @@ static int gfx_v10_0_cp_gfx_load_me_microcode(struct amdgpu_device *adev)
 		le32_to_cpu(me_hdr->header.ucode_array_offset_bytes));
 	fw_size = le32_to_cpu(me_hdr->header.ucode_size_bytes);
 
-	r = amdgpu_bo_create_reserved(adev, me_hdr->header.ucode_size_bytes,
+	r = amdgpu_bo_create_reserved(adev, fw_size,
 				      PAGE_SIZE, AMDGPU_GEM_DOMAIN_GTT,
 				      &adev->gfx.me.me_fw_obj,
 				      &adev->gfx.me.me_fw_gpu_addr,
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +1 -1
index 06811a1f4625..831398e15b84 100644
@@ -2013,7 +2013,7 @@ static int gfx_v9_0_mec_init(struct amdgpu_device *adev)
 		 le32_to_cpu(mec_hdr->header.ucode_array_offset_bytes));
 	fw_size = le32_to_cpu(mec_hdr->header.ucode_size_bytes);
 
-	r = amdgpu_bo_create_reserved(adev, mec_hdr->header.ucode_size_bytes,
+	r = amdgpu_bo_create_reserved(adev, fw_size,
 				      PAGE_SIZE, AMDGPU_GEM_DOMAIN_GTT,
 				      &adev->gfx.mec.mec_fw_obj,
 				      &adev->gfx.mec.mec_fw_gpu_addr,
drivers/gpu/drm/amd/pm/swsmu/smu11/smu_v11_0.c +1 -1
index 6274cae4a065..00610def69ea 100644
@@ -174,7 +174,7 @@ int smu_v11_0_load_microcode(struct smu_context *smu)
 	hdr = (const struct smc_firmware_header_v1_0 *) adev->pm.fw->data;
 	src = (const uint32_t *)(adev->pm.fw->data +
 		le32_to_cpu(hdr->header.ucode_array_offset_bytes));
-	smc_fw_size = hdr->header.ucode_size_bytes;
+	smc_fw_size = le32_to_cpu(hdr->header.ucode_size_bytes;)
 
 	for (i = 1; i < smc_fw_size/4 - 1; i++) {
 		WREG32_PCIE(addr_start, src[i]);
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0.c +1 -1
index 0864083e7435..d7ea8215d7dc 100644
@@ -149,7 +149,7 @@ int smu_v13_0_load_microcode(struct smu_context *smu)
 	hdr = (const struct smc_firmware_header_v1_0 *) adev->pm.fw->data;
 	src = (const uint32_t *)(adev->pm.fw->data +
 				 le32_to_cpu(hdr->header.ucode_array_offset_bytes));
-	smc_fw_size = hdr->header.ucode_size_bytes;
+	smc_fw_size = le32_to_cpu(hdr->header.ucode_size_bytes);
 
 	for (i = 1; i < smc_fw_size/4 - 1; i++) {
 		WREG32_PCIE(addr_start, src[i]);
Signature · 6 lines
2.17.1

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

[AMD Public Use]

________________________________
From: amd-gfx <[email protected]> on behalf of Kevin Wang <[email protected]>
Sent: Tuesday, April 13, 2021 7:51 AM
To: [email protected] <[email protected]>
Cc: Wang, Kevin(Yang) <[email protected]>
Subject: [PATCH] drm/amdgpu: correction of ucode fw_size calculation errors

correct big and little endian problems on different platforms.

---
 drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c         | 8 ++++----
 drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c          | 2 +-
 drivers/gpu/drm/amd/pm/swsmu/smu11/smu_v11_0.c | 2 +-
 drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0.c | 2 +-
 4 files changed, 7 insertions(+), 7 deletions(-)
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +4 -4
index 85a6a10e048f..0a00a7cc8eaa 100644
@@ -4354,7 +4354,7 @@ static int gfx_v10_0_mec_init(struct amdgpu_device *adev)
                          le32_to_cpu(mec_hdr->header.ucode_array_offset_bytes));
                 fw_size = le32_to_cpu(mec_hdr->header.ucode_size_bytes);
 
-               r = amdgpu_bo_create_reserved(adev, mec_hdr->header.ucode_size_bytes,
+               r = amdgpu_bo_create_reserved(adev, fw_size,
                                               PAGE_SIZE, AMDGPU_GEM_DOMAIN_GTT,
                                               &adev->gfx.mec.mec_fw_obj,
                                               &adev->gfx.mec.mec_fw_gpu_addr,
@@ -5769,7 +5769,7 @@ static int gfx_v10_0_cp_gfx_load_pfp_microcode(struct amdgpu_device *adev)
                 le32_to_cpu(pfp_hdr->header.ucode_array_offset_bytes));
         fw_size = le32_to_cpu(pfp_hdr->header.ucode_size_bytes);
 
-       r = amdgpu_bo_create_reserved(adev, pfp_hdr->header.ucode_size_bytes,
+       r = amdgpu_bo_create_reserved(adev, fw_size,
                                       PAGE_SIZE, AMDGPU_GEM_DOMAIN_GTT,
                                       &adev->gfx.pfp.pfp_fw_obj,
                                       &adev->gfx.pfp.pfp_fw_gpu_addr,
@@ -5847,7 +5847,7 @@ static int gfx_v10_0_cp_gfx_load_ce_microcode(struct amdgpu_device *adev)
                 le32_to_cpu(ce_hdr->header.ucode_array_offset_bytes));
         fw_size = le32_to_cpu(ce_hdr->header.ucode_size_bytes);
 
-       r = amdgpu_bo_create_reserved(adev, ce_hdr->header.ucode_size_bytes,
+       r = amdgpu_bo_create_reserved(adev, fw_size,
                                       PAGE_SIZE, AMDGPU_GEM_DOMAIN_GTT,
                                       &adev->gfx.ce.ce_fw_obj,
                                       &adev->gfx.ce.ce_fw_gpu_addr,
@@ -5924,7 +5924,7 @@ static int gfx_v10_0_cp_gfx_load_me_microcode(struct amdgpu_device *adev)
                 le32_to_cpu(me_hdr->header.ucode_array_offset_bytes));
         fw_size = le32_to_cpu(me_hdr->header.ucode_size_bytes);
 
-       r = amdgpu_bo_create_reserved(adev, me_hdr->header.ucode_size_bytes,
+       r = amdgpu_bo_create_reserved(adev, fw_size,
                                       PAGE_SIZE, AMDGPU_GEM_DOMAIN_GTT,
                                       &adev->gfx.me.me_fw_obj,
                                       &adev->gfx.me.me_fw_gpu_addr,
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +1 -1
index 06811a1f4625..831398e15b84 100644
@@ -2013,7 +2013,7 @@ static int gfx_v9_0_mec_init(struct amdgpu_device *adev)
                  le32_to_cpu(mec_hdr->header.ucode_array_offset_bytes));
         fw_size = le32_to_cpu(mec_hdr->header.ucode_size_bytes);
 
-       r = amdgpu_bo_create_reserved(adev, mec_hdr->header.ucode_size_bytes,
+       r = amdgpu_bo_create_reserved(adev, fw_size,
                                       PAGE_SIZE, AMDGPU_GEM_DOMAIN_GTT,
                                       &adev->gfx.mec.mec_fw_obj,
                                       &adev->gfx.mec.mec_fw_gpu_addr,
drivers/gpu/drm/amd/pm/swsmu/smu11/smu_v11_0.c +1 -1
index 6274cae4a065..00610def69ea 100644
@@ -174,7 +174,7 @@ int smu_v11_0_load_microcode(struct smu_context *smu)
         hdr = (const struct smc_firmware_header_v1_0 *) adev->pm.fw->data;
         src = (const uint32_t *)(adev->pm.fw->data +
                 le32_to_cpu(hdr->header.ucode_array_offset_bytes));
-       smc_fw_size = hdr->header.ucode_size_bytes;
+       smc_fw_size = le32_to_cpu(hdr->header.ucode_size_bytes;)
 
         for (i = 1; i < smc_fw_size/4 - 1; i++) {
                 WREG32_PCIE(addr_start, src[i]);
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0.c +1 -1
index 0864083e7435..d7ea8215d7dc 100644
@@ -149,7 +149,7 @@ int smu_v13_0_load_microcode(struct smu_context *smu)
         hdr = (const struct smc_firmware_header_v1_0 *) adev->pm.fw->data;
         src = (const uint32_t *)(adev->pm.fw->data +
                                  le32_to_cpu(hdr->header.ucode_array_offset_bytes));
-       smc_fw_size = hdr->header.ucode_size_bytes;
+       smc_fw_size = le32_to_cpu(hdr->header.ucode_size_bytes);
 
         for (i = 1; i < smc_fw_size/4 - 1; i++) {
                 WREG32_PCIE(addr_start, src[i]);

--
2.17.1

_______________________________________________
amd-gfx mailing list
[email protected]
https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.freedesktop.org%2Fmailman%2Flistinfo%2Famd-gfx&amp;data=04%7C01%7Calexander.deucher%40amd.com%7C3992236102744469006b08d8fe728650%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637539115132533430%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&amp;sdata=pQO64zy%2F99rHa7Vr9uZd%2F9q04R6DDPL%2BnOiw%2Fo2oScY%3D&amp;reserved=0

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