[PATCH 2/3] drm/amdgpu: validate module parameter smu_prv_buffer_size

Rex Zhu Rex.Zhu at amd.com
Tue Oct 10 10:39:32 UTC 2017


Change-Id: I5f7025a357720c7553035c02519b2b6ac2c59358
Signed-off-by: Rex Zhu <Rex.Zhu at amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 43 ++++++++++++++++++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c    |  3 +++
 drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c      |  2 ++
 drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c      |  3 +++
 drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c      |  2 ++
 drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c      |  2 ++
 6 files changed, 55 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
index fdfe418..548f4dc 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
@@ -1152,6 +1152,46 @@ static void amdgpu_check_vm_size(struct amdgpu_device *adev)
 	amdgpu_vm_size = -1;
 }
 
+static void amdgpu_device_check_smu_prv_buffer_size(struct amdgpu_device *adev)
+{
+	struct sysinfo si;
+	bool is_os_64 = (sizeof(void *) == 8) ? true : false;
+	uint64_t total_memory;
+	uint64_t dram_size_seven_GB = 0x1B8000000;
+	uint64_t dram_size_three_GB = 0xB8000000;
+
+	if (amdgpu_smu_memory_pool_size == 0)
+		return;
+
+	if (!is_os_64) {
+		DRM_WARN("Not 64-bit OS, feature not supported\n");
+		goto def_value;
+	}
+	si_meminfo(&si);
+	total_memory = (uint64_t)si.totalram * si.mem_unit;
+
+	if ((amdgpu_smu_memory_pool_size == 1) ||
+		(amdgpu_smu_memory_pool_size == 2)) {
+		if (total_memory < dram_size_three_GB)
+			goto def_value1;
+	} else if ((amdgpu_smu_memory_pool_size == 4) ||
+		(amdgpu_smu_memory_pool_size == 8)) {
+		if (total_memory < dram_size_seven_GB)
+			goto def_value1;
+	} else {
+		DRM_WARN("Smu memory pool size not supported\n");
+		goto def_value;
+	}
+	amdgpu_smu_memory_pool_size = amdgpu_smu_memory_pool_size << 28;
+
+	return;
+
+def_value1:
+	DRM_WARN("No enough system memory\n");
+def_value:
+	amdgpu_smu_memory_pool_size = 0;
+}
+
 /**
  * amdgpu_check_arguments - validate module params
  *
@@ -1193,6 +1233,8 @@ static void amdgpu_check_arguments(struct amdgpu_device *adev)
 		amdgpu_vm_fragment_size = -1;
 	}
 
+	amdgpu_device_check_smu_prv_buffer_size(adev);
+
 	amdgpu_check_vm_size(adev);
 
 	amdgpu_check_block_size(adev);
@@ -2430,6 +2472,7 @@ void amdgpu_device_fini(struct amdgpu_device *adev)
 		release_firmware(adev->firmware.gpu_info_fw);
 		adev->firmware.gpu_info_fw = NULL;
 	}
+
 	adev->accel_working = false;
 	cancel_delayed_work_sync(&adev->late_init_work);
 	/* free i2c buses */
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
index fa2781b..9eab064 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
@@ -1280,6 +1280,9 @@ int amdgpu_ttm_init(struct amdgpu_device *adev)
 			       adev->mc.mc_vram_size);
 	else
 		gtt_size = (uint64_t)amdgpu_gtt_size << 20;
+
+	gtt_size = gtt_size + amdgpu_smu_memory_pool_size;
+
 	r = ttm_bo_init_mm(&adev->mman.bdev, TTM_PL_TT, gtt_size >> PAGE_SHIFT);
 	if (r) {
 		DRM_ERROR("Failed initializing GTT heap.\n");
diff --git a/drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c b/drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c
index f4603a7..e1f97b1 100644
--- a/drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c
@@ -350,6 +350,8 @@ static int gmc_v6_0_mc_init(struct amdgpu_device *adev)
 		adev->mc.gart_size = (u64)amdgpu_gart_size << 20;
 	}
 
+	adev->mc.gart_size += amdgpu_smu_memory_pool_size;
+
 	gmc_v6_0_vram_gtt_location(adev, &adev->mc);
 
 	return 0;
diff --git a/drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c b/drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c
index b0528ca..ac481a0 100644
--- a/drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c
@@ -407,6 +407,9 @@ static int gmc_v7_0_mc_init(struct amdgpu_device *adev)
 		adev->mc.gart_size = (u64)amdgpu_gart_size << 20;
 	}
 
+
+	adev->mc.gart_size += amdgpu_smu_memory_pool_size;
+
 	gmc_v7_0_vram_gtt_location(adev, &adev->mc);
 
 	return 0;
diff --git a/drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c b/drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c
index f368cfe..0f5bccc 100644
--- a/drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c
@@ -582,6 +582,8 @@ static int gmc_v8_0_mc_init(struct amdgpu_device *adev)
 		adev->mc.gart_size = (u64)amdgpu_gart_size << 20;
 	}
 
+	adev->mc.gart_size += amdgpu_smu_memory_pool_size;
+
 	gmc_v8_0_vram_gtt_location(adev, &adev->mc);
 
 	return 0;
diff --git a/drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c b/drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c
index 6216993..09cf381 100644
--- a/drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c
@@ -511,6 +511,8 @@ static int gmc_v9_0_mc_init(struct amdgpu_device *adev)
 		adev->mc.gart_size = (u64)amdgpu_gart_size << 20;
 	}
 
+	adev->mc.gart_size += amdgpu_smu_memory_pool_size;
+
 	gmc_v9_0_vram_gtt_location(adev, &adev->mc);
 
 	return 0;
-- 
1.9.1



More information about the amd-gfx mailing list