aboutsummaryrefslogtreecommitdiffstats
path: root/meta-amd-bsp/recipes-kernel/linux-4.19/linux-yocto-4.19.8/0134-drm-amdgpu-Compute-GPU-VM-space-if-unchanged-from-de.patch
blob: 264e015c331a7bc40ed5253b1ec403a2b5d0f635 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
From cee2fb237aff722d2b5c6ee81cd7ded51776cbbf Mon Sep 17 00:00:00 2001
From: Kent Russell <kent.russell@amd.com>
Date: Fri, 23 Feb 2018 11:49:46 -0500
Subject: [PATCH 0134/2940] drm/amdgpu: Compute GPU VM space if unchanged from
 default

Change-Id: I9a20db93c2ad75a0cd07c7d084e9faee5d554cf4
Signed-off-by: Kent Russell <kent.russell@amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 31 +++++++++++++++++++---
 1 file changed, 27 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
index 63668764bf5d..227bbc1f689e 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
@@ -899,11 +899,34 @@ static void amdgpu_device_check_block_size(struct amdgpu_device *adev)
  */
 static void amdgpu_device_check_vm_size(struct amdgpu_device *adev)
 {
-	/* no need to check the default value */
-	if (amdgpu_vm_size == -1)
-		return;
+	struct sysinfo si;
+	int phys_ram_gb, amdgpu_vm_size_aligned;
+
+	/* Compute the GPU VM space only if the user
+	 * hasn't changed it from the default.
+	 * In order for Raven ATC memory to work, vm size should be 256TB.
+	 * So we do not compute the new vm size here for Raven.
+	 */
+	if (amdgpu_vm_size == -1 && adev->asic_type != CHIP_RAVEN) {
+		/* Computation depends on the amount of physical RAM available.
+		 * Cannot exceed 1TB.
+		 */
+		si_meminfo(&si);
+		phys_ram_gb = ((uint64_t)si.totalram * si.mem_unit) >> 30;
+		amdgpu_vm_size = min(phys_ram_gb * 3 + 16, 1024);
+
+		/* GPUVM sizes are almost never perfect powers of two.
+		 * Round up to nearest power of two starting from
+		 * the minimum allowed but aligned size of 32GB
+		 */
+		amdgpu_vm_size_aligned = 32;
+		while (amdgpu_vm_size > amdgpu_vm_size_aligned)
+			amdgpu_vm_size_aligned *= 2;
+
+		amdgpu_vm_size = amdgpu_vm_size_aligned;
+	}
 
-	if (amdgpu_vm_size < 1) {
+	if (amdgpu_vm_size != -1 && amdgpu_vm_size < 1) {
 		dev_warn(adev->dev, "VM size (%d) too small, min is 1GB\n",
 			 amdgpu_vm_size);
 		amdgpu_vm_size = -1;
-- 
2.17.1