[PATCH 1/2] drm/amdgpu: Use fw vram offset when allocating stolen vga memory.

Yongqiang Sun yongqiang.sun at amd.com
Mon Mar 14 18:54:02 UTC 2022


[Why]
Memory access violation will happen in case of allocate stolen vga
memory with size isn't 0.

[How]
when allocating stolen vga memory, use fw vram offset as the start point
instead of hard code value 0.

Signed-off-by: Yongqiang Sun <yongqiang.sun at amd.com>
Change-Id: I7c555a6c1fb4b3fa8685753b4bdcbe215f89ea1e
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 31 +++++++++++++++++++------
 1 file changed, 24 insertions(+), 7 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
index 41d6f604813d..1f635fdb0395 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
@@ -1708,6 +1708,7 @@ int amdgpu_ttm_init(struct amdgpu_device *adev)
 	uint64_t gtt_size;
 	int r;
 	u64 vis_vram_limit;
+	u64 memory_offset = adev->mman.fw_vram_usage_start_offset + adev->mman.fw_vram_usage_size;
 
 	mutex_init(&adev->mman.gtt_window_lock);
 
@@ -1774,24 +1775,40 @@ int amdgpu_ttm_init(struct amdgpu_device *adev)
 	 * This is used for VGA emulation and pre-OS scanout buffers to
 	 * avoid display artifacts while transitioning between pre-OS
 	 * and driver.  */
-	r = amdgpu_bo_create_kernel_at(adev, 0, adev->mman.stolen_vga_size,
+	r = amdgpu_bo_create_kernel_at(adev,
+					   memory_offset,
+			           adev->mman.stolen_vga_size,
 				       AMDGPU_GEM_DOMAIN_VRAM,
 				       &adev->mman.stolen_vga_memory,
 				       NULL);
 	if (r)
 		return r;
-	r = amdgpu_bo_create_kernel_at(adev, adev->mman.stolen_vga_size,
+
+	memory_offset += adev->mman.stolen_vga_size;
+
+	r = amdgpu_bo_create_kernel_at(adev,
+					   memory_offset,
 				       adev->mman.stolen_extended_size,
 				       AMDGPU_GEM_DOMAIN_VRAM,
 				       &adev->mman.stolen_extended_memory,
 				       NULL);
 	if (r)
 		return r;
-	r = amdgpu_bo_create_kernel_at(adev, adev->mman.stolen_reserved_offset,
-				       adev->mman.stolen_reserved_size,
-				       AMDGPU_GEM_DOMAIN_VRAM,
-				       &adev->mman.stolen_reserved_memory,
-				       NULL);
+
+	memory_offset += adev->mman.stolen_extended_size;
+
+	if (adev->mman.stolen_reserved_offset > memory_offset)
+		r = amdgpu_bo_create_kernel_at(adev, adev->mman.stolen_reserved_offset,
+						   adev->mman.stolen_reserved_size,
+						   AMDGPU_GEM_DOMAIN_VRAM,
+						   &adev->mman.stolen_reserved_memory,
+						   NULL);
+	else if (adev->mman.stolen_reserved_offset + adev->mman.stolen_reserved_size > memory_offset)
+		r = amdgpu_bo_create_kernel_at(adev, memory_offset,
+						adev->mman.stolen_reserved_offset + adev->mman.stolen_reserved_size - memory_offset,
+						   AMDGPU_GEM_DOMAIN_VRAM,
+						   &adev->mman.stolen_reserved_memory,
+						   NULL);
 	if (r)
 		return r;
 
-- 
2.25.1



More information about the amd-gfx mailing list