[PATCH 2/2] drm/amdgpu/atom: make amdgpu_atomfirmware_allocate_fb parsing consistent

Alex Deucher alexander.deucher at amd.com
Wed Dec 13 21:25:58 UTC 2023


For 2.1, ATOM_VRAM_BLOCK_SRIOV_MSG_SHARE_RESERVATION is SR-IOV only.
For 2.2, return usage_bytes properly for the non-SR-IOV case.

Fixes: 4864f2ee9ee2 ("drm/amdgpu: add vram reservation based on vram_usagebyfirmware_v2_2")
Link: https://bugzilla.opensuse.org/show_bug.cgi?id=1215802
Signed-off-by: Alex Deucher <alexander.deucher at amd.com>
---
 .../gpu/drm/amd/amdgpu/amdgpu_atomfirmware.c  | 55 ++++++++++---------
 1 file changed, 30 insertions(+), 25 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_atomfirmware.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_atomfirmware.c
index d8393e3f2778..b1c1fafa2d8a 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_atomfirmware.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_atomfirmware.c
@@ -115,18 +115,21 @@ static int amdgpu_atomfirmware_allocate_fb_v2_1(struct amdgpu_device *adev,
 			  fw_size,
 			  drv_size);
 
-	if ((start_addr & ATOM_VRAM_OPERATION_FLAGS_MASK) ==
-		(u32)(ATOM_VRAM_BLOCK_SRIOV_MSG_SHARE_RESERVATION <<
-		ATOM_VRAM_OPERATION_FLAGS_SHIFT)) {
-		/* Firmware request VRAM reservation for SR-IOV */
-		adev->mman.fw_vram_usage_start_offset = (start_addr &
-			(~ATOM_VRAM_OPERATION_FLAGS_MASK)) << 10;
-		adev->mman.fw_vram_usage_size = fw_size << 10;
-		/* Use the default scratch size */
-		*usage_bytes = 0;
+	if (amdgpu_sriov_vf(adev)) {
+		if ((start_addr & ATOM_VRAM_OPERATION_FLAGS_MASK) ==
+		    (u32)(ATOM_VRAM_BLOCK_SRIOV_MSG_SHARE_RESERVATION <<
+			  ATOM_VRAM_OPERATION_FLAGS_SHIFT)) {
+			/* Firmware request VRAM reservation for SR-IOV */
+			adev->mman.fw_vram_usage_start_offset = (start_addr &
+								 (~ATOM_VRAM_OPERATION_FLAGS_MASK)) << 10;
+			adev->mman.fw_vram_usage_size = fw_size << 10;
+			/* Use the default scratch size */
+			*usage_bytes = 0;
+		}
 	} else {
 		*usage_bytes = drv_size << 10;
 	}
+
 	return 0;
 }
 
@@ -147,25 +150,27 @@ static int amdgpu_atomfirmware_allocate_fb_v2_2(struct amdgpu_device *adev,
 			  drv_start_addr,
 			  drv_size);
 
-	if (amdgpu_sriov_vf(adev) &&
-	    ((fw_start_addr & (ATOM_VRAM_BLOCK_NEEDS_NO_RESERVATION <<
-		ATOM_VRAM_OPERATION_FLAGS_SHIFT)) == 0)) {
-		/* Firmware request VRAM reservation for SR-IOV */
-		adev->mman.fw_vram_usage_start_offset = (fw_start_addr &
-			(~ATOM_VRAM_OPERATION_FLAGS_MASK)) << 10;
-		adev->mman.fw_vram_usage_size = fw_size << 10;
-	}
+	if (amdgpu_sriov_vf(adev)) {
+		if ((fw_start_addr & (ATOM_VRAM_BLOCK_NEEDS_NO_RESERVATION <<
+				      ATOM_VRAM_OPERATION_FLAGS_SHIFT)) == 0) {
+			/* Firmware request VRAM reservation for SR-IOV */
+			adev->mman.fw_vram_usage_start_offset = (fw_start_addr &
+								 (~ATOM_VRAM_OPERATION_FLAGS_MASK)) << 10;
+			adev->mman.fw_vram_usage_size = fw_size << 10;
+		}
 
-	if (amdgpu_sriov_vf(adev) &&
-	    ((drv_start_addr & (ATOM_VRAM_BLOCK_NEEDS_NO_RESERVATION <<
-		ATOM_VRAM_OPERATION_FLAGS_SHIFT)) == 0)) {
-		/* driver request VRAM reservation for SR-IOV */
-		adev->mman.drv_vram_usage_start_offset = (drv_start_addr &
-			(~ATOM_VRAM_OPERATION_FLAGS_MASK)) << 10;
-		adev->mman.drv_vram_usage_size = drv_size << 10;
+		if ((drv_start_addr & (ATOM_VRAM_BLOCK_NEEDS_NO_RESERVATION <<
+				       ATOM_VRAM_OPERATION_FLAGS_SHIFT)) == 0) {
+			/* driver request VRAM reservation for SR-IOV */
+			adev->mman.drv_vram_usage_start_offset = (drv_start_addr &
+								  (~ATOM_VRAM_OPERATION_FLAGS_MASK)) << 10;
+			adev->mman.drv_vram_usage_size = drv_size << 10;
+		}
+		*usage_bytes = 0;
+	} else {
+		*usage_bytes = drv_size << 10;
 	}
 
-	*usage_bytes = 0;
 	return 0;
 }
 
-- 
2.42.0



More information about the amd-gfx mailing list