Skip to contentSkip to conversation

drm/amdgpu/gmc: steal the appropriate amount of vram for fw hand-over

PATCH In review Alex Deucher 3 participants 5 messages Apr 6, 2018 2 messages not in the archive

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 drm/amdgpu/gmc: steal the appropriate amount of vram for fw hand-over

Steal 9 MB for vga emulation and fb if vga is enabled, otherwise, steal enough to cover the current display size as set by the vbios.

If no memory is used (e.g., secondary or headless card), skip stolen memory reserve.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 17 +++++++------
 drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c   | 17 ++++++++++++-
 drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c   | 17 ++++++++++++-
 drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c   | 17 ++++++++++++-
 drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c   | 42 ++++++++++++++++++++++++++++++++-
 5 files changed, 99 insertions(+), 11 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +10 -7
index 205da3ff9cd0..2de2f5e5a0f9 100644
@@ -1454,12 +1454,14 @@ int amdgpu_ttm_init(struct amdgpu_device *adev)
 		return r;
 	}
 
-	r = amdgpu_bo_create_kernel(adev, adev->gmc.stolen_size, PAGE_SIZE,
-				    AMDGPU_GEM_DOMAIN_VRAM,
-				    &adev->stolen_vga_memory,
-				    NULL, NULL);
-	if (r)
-		return r;
+	if (adev->gmc.stolen_size) {
+		r = amdgpu_bo_create_kernel(adev, adev->gmc.stolen_size, PAGE_SIZE,
+					    AMDGPU_GEM_DOMAIN_VRAM,
+					    &adev->stolen_vga_memory,
+					    NULL, NULL);
+		if (r)
+			return r;
+	}
 	DRM_INFO("amdgpu: %uM of VRAM memory ready\n",
 		 (unsigned) (adev->gmc.real_vram_size / (1024 * 1024)));
 
@@ -1534,7 +1536,8 @@ void amdgpu_ttm_fini(struct amdgpu_device *adev)
 		return;
 
 	amdgpu_ttm_debugfs_fini(adev);
-	amdgpu_bo_free_kernel(&adev->stolen_vga_memory, NULL, NULL);
+	if (adev->gmc.stolen_size)
+		amdgpu_bo_free_kernel(&adev->stolen_vga_memory, NULL, NULL);
 	amdgpu_ttm_fw_reserve_vram_fini(adev);
 	if (adev->mman.aper_base_kaddr)
 		iounmap(adev->mman.aper_base_kaddr);
drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c +16 -1
index 5617cf62c566..63f0b65854a3 100644
@@ -825,6 +825,21 @@ static int gmc_v6_0_late_init(void *handle)
 		return 0;
 }
 
+static unsigned gmc_v6_0_get_vbios_fb_size(struct amdgpu_device *adev)
+{
+	u32 d1vga_control = RREG32(mmD1VGA_CONTROL);
+
+	if (REG_GET_FIELD(d1vga_control, D1VGA_CONTROL, D1VGA_MODE_ENABLE)) {
+		return 9 * 1024 * 1024; /* reserve 8MB for vga emulator and 1 MB for FB */
+	} else {
+		u32 viewport = RREG32(mmVIEWPORT_SIZE);
+		unsigned size = (REG_GET_FIELD(viewport, VIEWPORT_SIZE, VIEWPORT_HEIGHT) *
+				 REG_GET_FIELD(viewport, VIEWPORT_SIZE, VIEWPORT_WIDTH) *
+				 4);
+		return size;
+	}
+}
+
 static int gmc_v6_0_sw_init(void *handle)
 {
 	int r;
@@ -851,7 +866,7 @@ static int gmc_v6_0_sw_init(void *handle)
 
 	adev->gmc.mc_mask = 0xffffffffffULL;
 
-	adev->gmc.stolen_size = 256 * 1024;
+	adev->gmc.stolen_size = gmc_v6_0_get_vbios_fb_size(adev);
 
 	adev->need_dma32 = false;
 	dma_bits = adev->need_dma32 ? 32 : 40;
drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c +16 -1
index 80054f36e487..2deb5c93ef28 100644
@@ -964,6 +964,21 @@ static int gmc_v7_0_late_init(void *handle)
 		return 0;
 }
 
+static unsigned gmc_v7_0_get_vbios_fb_size(struct amdgpu_device *adev)
+{
+	u32 d1vga_control = RREG32(mmD1VGA_CONTROL);
+
+	if (REG_GET_FIELD(d1vga_control, D1VGA_CONTROL, D1VGA_MODE_ENABLE)) {
+		return 9 * 1024 * 1024; /* reserve 8MB for vga emulator and 1 MB for FB */
+	} else {
+		u32 viewport = RREG32(mmVIEWPORT_SIZE);
+		unsigned size = (REG_GET_FIELD(viewport, VIEWPORT_SIZE, VIEWPORT_HEIGHT) *
+				 REG_GET_FIELD(viewport, VIEWPORT_SIZE, VIEWPORT_WIDTH) *
+				 4);
+		return size;
+	}
+}
+
 static int gmc_v7_0_sw_init(void *handle)
 {
 	int r;
@@ -998,7 +1013,7 @@ static int gmc_v7_0_sw_init(void *handle)
 	 */
 	adev->gmc.mc_mask = 0xffffffffffULL; /* 40 bit MC */
 
-	adev->gmc.stolen_size = 256 * 1024;
+	adev->gmc.stolen_size = gmc_v7_0_get_vbios_fb_size(adev);
 
 	/* set DMA mask + need_dma32 flags.
 	 * PCIE - can handle 40-bits.
drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c +16 -1
index d71d4cb68f9c..04b00df3c6e6 100644
@@ -1055,6 +1055,21 @@ static int gmc_v8_0_late_init(void *handle)
 		return 0;
 }
 
+static unsigned gmc_v8_0_get_vbios_fb_size(struct amdgpu_device *adev)
+{
+	u32 d1vga_control = RREG32(mmD1VGA_CONTROL);
+
+	if (REG_GET_FIELD(d1vga_control, D1VGA_CONTROL, D1VGA_MODE_ENABLE)) {
+		return 9 * 1024 * 1024; /* reserve 8MB for vga emulator and 1 MB for FB */
+	} else {
+		u32 viewport = RREG32(mmVIEWPORT_SIZE);
+		unsigned size = (REG_GET_FIELD(viewport, VIEWPORT_SIZE, VIEWPORT_HEIGHT) *
+				 REG_GET_FIELD(viewport, VIEWPORT_SIZE, VIEWPORT_WIDTH) *
+				 4);
+		return size;
+	}
+}
+
 #define mmMC_SEQ_MISC0_FIJI 0xA71
 
 static int gmc_v8_0_sw_init(void *handle)
@@ -1096,7 +1111,7 @@ static int gmc_v8_0_sw_init(void *handle)
 	 */
 	adev->gmc.mc_mask = 0xffffffffffULL; /* 40 bit MC */
 
-	adev->gmc.stolen_size = 256 * 1024;
+	adev->gmc.stolen_size = gmc_v8_0_get_vbios_fb_size(adev);
 
 	/* set DMA mask + need_dma32 flags.
 	 * PCIE - can handle 40-bits.
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +41 -1

54 lines not on this page · raw message

Signature · 6 lines
2.13.6

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

A message that is not in the archive (sent off-list or not yet received): 20180406172437.12695-1-alexander.deucher-5C7GfCeVMHo@public.gmane.org

#2 lore raw

PATCH 2/2 drm/amdgpu: Free VGA stolen memory as soon as possible.

From: Andrey Grodzovsky <[email protected]>

Reserved VRAM is used to avoid overriding pre OS FB. Once our display stack takes over we don't need the reserved VRAM anymore.

v2:
Remove comment, we know actually why we need to reserve the stolen VRAM. Fix return type for amdgpu_ttm_late_init.
v3:
Return 0 in amdgpu_bo_late_init, rebase on changes to previous patch

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 7 +++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_object.h | 1 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c    | 8 ++++++--
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h    | 1 +
 drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c      | 2 ++
 drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c      | 2 ++
 drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c      | 2 ++
 drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c      | 6 ++----
 8 files changed, 23 insertions(+), 6 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +7 -0
index 9e23d6f6f3f3..a160ef0332d6 100644
@@ -852,6 +852,13 @@ int amdgpu_bo_init(struct amdgpu_device *adev)
 	return amdgpu_ttm_init(adev);
 }
 
+int amdgpu_bo_late_init(struct amdgpu_device *adev)
+{
+	amdgpu_ttm_late_init(adev);
+
+	return 0;
+}
+
 void amdgpu_bo_fini(struct amdgpu_device *adev)
 {
 	amdgpu_ttm_fini(adev);
drivers/gpu/drm/amd/amdgpu/amdgpu_object.h +1 -0
index 546f77cb7882..8648eee9ecda 100644
@@ -230,6 +230,7 @@ int amdgpu_bo_pin_restricted(struct amdgpu_bo *bo, u32 domain,
 int amdgpu_bo_unpin(struct amdgpu_bo *bo);
 int amdgpu_bo_evict_vram(struct amdgpu_device *adev);
 int amdgpu_bo_init(struct amdgpu_device *adev);
+int amdgpu_bo_late_init(struct amdgpu_device *adev);
 void amdgpu_bo_fini(struct amdgpu_device *adev);
 int amdgpu_bo_fbdev_mmap(struct amdgpu_bo *bo,
 				struct vm_area_struct *vma);
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +6 -2
index 2de2f5e5a0f9..158a7d5d24f3 100644
@@ -1530,14 +1530,18 @@ int amdgpu_ttm_init(struct amdgpu_device *adev)
 	return 0;
 }
 
+void amdgpu_ttm_late_init(struct amdgpu_device *adev)
+{
+	if (adev->gmc.stolen_size)
+		amdgpu_bo_free_kernel(&adev->stolen_vga_memory, NULL, NULL);
+}
+
 void amdgpu_ttm_fini(struct amdgpu_device *adev)
 {
 	if (!adev->mman.initialized)
 		return;
 
 	amdgpu_ttm_debugfs_fini(adev);
-	if (adev->gmc.stolen_size)
-		amdgpu_bo_free_kernel(&adev->stolen_vga_memory, NULL, NULL);
 	amdgpu_ttm_fw_reserve_vram_fini(adev);
 	if (adev->mman.aper_base_kaddr)
 		iounmap(adev->mman.aper_base_kaddr);
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h +1 -0
index 6ea7de863041..e969c879d87e 100644
@@ -77,6 +77,7 @@ uint64_t amdgpu_vram_mgr_usage(struct ttm_mem_type_manager *man);
 uint64_t amdgpu_vram_mgr_vis_usage(struct ttm_mem_type_manager *man);
 
 int amdgpu_ttm_init(struct amdgpu_device *adev);
+void amdgpu_ttm_late_init(struct amdgpu_device *adev);
 void amdgpu_ttm_fini(struct amdgpu_device *adev);
 void amdgpu_ttm_set_buffer_funcs_status(struct amdgpu_device *adev,
 					bool enable);
drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c +2 -0
index 63f0b65854a3..4a8f9bd48cb3 100644
@@ -819,6 +819,8 @@ static int gmc_v6_0_late_init(void *handle)
 {
 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
 
+	amdgpu_bo_late_init(adev);
+
 	if (amdgpu_vm_fault_stop != AMDGPU_VM_FAULT_STOP_ALWAYS)
 		return amdgpu_irq_get(adev, &adev->gmc.vm_fault, 0);
 	else
drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c +2 -0
index 2deb5c93ef28..189fdf9471ea 100644
@@ -958,6 +958,8 @@ static int gmc_v7_0_late_init(void *handle)
 {
 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
 
+	amdgpu_bo_late_init(adev);
+
 	if (amdgpu_vm_fault_stop != AMDGPU_VM_FAULT_STOP_ALWAYS)
 		return amdgpu_irq_get(adev, &adev->gmc.vm_fault, 0);
 	else
drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c +2 -0
index 04b00df3c6e6..19e153ff4fb5 100644
@@ -1049,6 +1049,8 @@ static int gmc_v8_0_late_init(void *handle)
 {
 	struct amdgpu_device *adev = (struct amdgpu_device *)handle;
 
+	amdgpu_bo_late_init(adev);
+
 	if (amdgpu_vm_fault_stop != AMDGPU_VM_FAULT_STOP_ALWAYS)
 		return amdgpu_irq_get(adev, &adev->gmc.vm_fault, 0);
 	else
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +2 -4
index 252a6c6998b7..09e26bca5cab 100644
@@ -659,6 +659,8 @@ static int gmc_v9_0_late_init(void *handle)
 	unsigned i;
 	int r;
 
+	amdgpu_bo_late_init(adev);
+
 	for(i = 0; i < adev->num_rings; ++i) {
 		struct amdgpu_ring *ring = adev->rings[i];
 		unsigned vmhub = ring->funcs->vmhub;
@@ -884,10 +886,6 @@ static int gmc_v9_0_sw_init(void *handle)
 	 */
 	adev->gmc.mc_mask = 0xffffffffffffULL; /* 48 bit MC */
 
-	/*
-	 * It needs to reserve 8M stolen memory for vega10
-	 * TODO: Figure out how to avoid that...
-	 */
 	adev->gmc.stolen_size = gmc_v9_0_get_vbios_fb_size(adev);
 
 	/* set DMA mask + need_dma32 flags.
Signature · 6 lines
2.13.6

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
#3 lore raw
In reply to a message not in the archive

Andrey

Quoted 207 lines · Alex Deucher

Steal 9 MB for vga emulation and fb if vga is enabled, otherwise, steal enough to cover the current display size as set by the vbios.

If no memory is used (e.g., secondary or headless card), skip stolen memory reserve.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 17 +++++++------
  drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c   | 17 ++++++++++++-
  drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c   | 17 ++++++++++++-
  drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c   | 17 ++++++++++++-
  drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c   | 42 ++++++++++++++++++++++++++++++++-
  5 files changed, 99 insertions(+), 11 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +10 -7
index 205da3ff9cd0..2de2f5e5a0f9 100644
@@ -1454,12 +1454,14 @@ int amdgpu_ttm_init(struct amdgpu_device *adev)
  		return r;
  	}
 
-	r = amdgpu_bo_create_kernel(adev, adev->gmc.stolen_size, PAGE_SIZE,
-				    AMDGPU_GEM_DOMAIN_VRAM,
-				    &adev->stolen_vga_memory,
-				    NULL, NULL);
-	if (r)
-		return r;
+	if (adev->gmc.stolen_size) {
+		r = amdgpu_bo_create_kernel(adev, adev->gmc.stolen_size, PAGE_SIZE,
+					    AMDGPU_GEM_DOMAIN_VRAM,
+					    &adev->stolen_vga_memory,
+					    NULL, NULL);
+		if (r)
+			return r;
+	}
  	DRM_INFO("amdgpu: %uM of VRAM memory ready\n",
  		 (unsigned) (adev->gmc.real_vram_size / (1024 * 1024)));
 
@@ -1534,7 +1536,8 @@ void amdgpu_ttm_fini(struct amdgpu_device *adev)
  		return;
 
  	amdgpu_ttm_debugfs_fini(adev);
-	amdgpu_bo_free_kernel(&adev->stolen_vga_memory, NULL, NULL);
+	if (adev->gmc.stolen_size)
+		amdgpu_bo_free_kernel(&adev->stolen_vga_memory, NULL, NULL);
  	amdgpu_ttm_fw_reserve_vram_fini(adev);
  	if (adev->mman.aper_base_kaddr)
  		iounmap(adev->mman.aper_base_kaddr);
drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c +16 -1
index 5617cf62c566..63f0b65854a3 100644
@@ -825,6 +825,21 @@ static int gmc_v6_0_late_init(void *handle)
  		return 0;
  }
 
+static unsigned gmc_v6_0_get_vbios_fb_size(struct amdgpu_device *adev)
+{
+	u32 d1vga_control = RREG32(mmD1VGA_CONTROL);
+
+	if (REG_GET_FIELD(d1vga_control, D1VGA_CONTROL, D1VGA_MODE_ENABLE)) {
+		return 9 * 1024 * 1024; /* reserve 8MB for vga emulator and 1 MB for FB */
+	} else {
+		u32 viewport = RREG32(mmVIEWPORT_SIZE);
+		unsigned size = (REG_GET_FIELD(viewport, VIEWPORT_SIZE, VIEWPORT_HEIGHT) *
+				 REG_GET_FIELD(viewport, VIEWPORT_SIZE, VIEWPORT_WIDTH) *
+				 4);
+		return size;
+	}
+}
+
  static int gmc_v6_0_sw_init(void *handle)
  {
  	int r;
@@ -851,7 +866,7 @@ static int gmc_v6_0_sw_init(void *handle)
 
  	adev->gmc.mc_mask = 0xffffffffffULL;
 
-	adev->gmc.stolen_size = 256 * 1024;
+	adev->gmc.stolen_size = gmc_v6_0_get_vbios_fb_size(adev);
 
  	adev->need_dma32 = false;
  	dma_bits = adev->need_dma32 ? 32 : 40;
drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c +16 -1
index 80054f36e487..2deb5c93ef28 100644
@@ -964,6 +964,21 @@ static int gmc_v7_0_late_init(void *handle)
  		return 0;
  }
 
+static unsigned gmc_v7_0_get_vbios_fb_size(struct amdgpu_device *adev)
+{
+	u32 d1vga_control = RREG32(mmD1VGA_CONTROL);
+
+	if (REG_GET_FIELD(d1vga_control, D1VGA_CONTROL, D1VGA_MODE_ENABLE)) {
+		return 9 * 1024 * 1024; /* reserve 8MB for vga emulator and 1 MB for FB */
+	} else {
+		u32 viewport = RREG32(mmVIEWPORT_SIZE);
+		unsigned size = (REG_GET_FIELD(viewport, VIEWPORT_SIZE, VIEWPORT_HEIGHT) *
+				 REG_GET_FIELD(viewport, VIEWPORT_SIZE, VIEWPORT_WIDTH) *
+				 4);
+		return size;
+	}
+}
+
  static int gmc_v7_0_sw_init(void *handle)
  {
  	int r;
@@ -998,7 +1013,7 @@ static int gmc_v7_0_sw_init(void *handle)
  	 */
  	adev->gmc.mc_mask = 0xffffffffffULL; /* 40 bit MC */
 
-	adev->gmc.stolen_size = 256 * 1024;
+	adev->gmc.stolen_size = gmc_v7_0_get_vbios_fb_size(adev);
 
  	/* set DMA mask + need_dma32 flags.
  	 * PCIE - can handle 40-bits.
drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c +16 -1
index d71d4cb68f9c..04b00df3c6e6 100644
@@ -1055,6 +1055,21 @@ static int gmc_v8_0_late_init(void *handle)
  		return 0;
  }
 
+static unsigned gmc_v8_0_get_vbios_fb_size(struct amdgpu_device *adev)
+{
+	u32 d1vga_control = RREG32(mmD1VGA_CONTROL);
+
+	if (REG_GET_FIELD(d1vga_control, D1VGA_CONTROL, D1VGA_MODE_ENABLE)) {
+		return 9 * 1024 * 1024; /* reserve 8MB for vga emulator and 1 MB for FB */
+	} else {
+		u32 viewport = RREG32(mmVIEWPORT_SIZE);
+		unsigned size = (REG_GET_FIELD(viewport, VIEWPORT_SIZE, VIEWPORT_HEIGHT) *
+				 REG_GET_FIELD(viewport, VIEWPORT_SIZE, VIEWPORT_WIDTH) *
+				 4);
+		return size;
+	}
+}
+
  #define mmMC_SEQ_MISC0_FIJI 0xA71
 
  static int gmc_v8_0_sw_init(void *handle)
@@ -1096,7 +1111,7 @@ static int gmc_v8_0_sw_init(void *handle)
  	 */
  	adev->gmc.mc_mask = 0xffffffffffULL; /* 40 bit MC */
 
-	adev->gmc.stolen_size = 256 * 1024;
+	adev->gmc.stolen_size = gmc_v8_0_get_vbios_fb_size(adev);
 
  	/* set DMA mask + need_dma32 flags.
  	 * PCIE - can handle 40-bits.
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +40 -0
index 070946e1e4a7..252a6c6998b7 100644
@@ -793,6 +793,46 @@ static int gmc_v9_0_gart_init(struct amdgpu_device *adev)
  	return amdgpu_gart_table_vram_alloc(adev);
  }
 
+#define mmHUBP0_DCSURF_PRI_VIEWPORT_DIMENSION                                                          0x055d
+#define mmHUBP0_DCSURF_PRI_VIEWPORT_DIMENSION_BASE_IDX                                                 2
+#define HUBP0_DCSURF_PRI_VIEWPORT_DIMENSION__PRI_VIEWPORT_WIDTH__SHIFT                                        0x0
+#define HUBP0_DCSURF_PRI_VIEWPORT_DIMENSION__PRI_VIEWPORT_HEIGHT__SHIFT                                       0x10
+#define HUBP0_DCSURF_PRI_VIEWPORT_DIMENSION__PRI_VIEWPORT_WIDTH_MASK                                          0x00003FFFL
+#define HUBP0_DCSURF_PRI_VIEWPORT_DIMENSION__PRI_VIEWPORT_HEIGHT_MASK                                         0x3FFF0000L
+
+static unsigned gmc_v9_0_get_vbios_fb_size(struct amdgpu_device *adev)
+{
+	u32 d1vga_control = RREG32_SOC15(DCE, 0, mmD1VGA_CONTROL);
+
+	if (REG_GET_FIELD(d1vga_control, D1VGA_CONTROL, D1VGA_MODE_ENABLE)) {
+		return 9 * 1024 * 1024; /* reserve 8MB for vga emulator and 1 MB for FB */
+	} else {
+		u32 viewport;
+		unsigned size;
+
+		switch (adev->asic_type) {
+		case CHIP_RAVEN:
+			viewport = RREG32_SOC15(DCE, 0, mmHUBP0_DCSURF_PRI_VIEWPORT_DIMENSION);
+			size = (REG_GET_FIELD(viewport,
+					      HUBP0_DCSURF_PRI_VIEWPORT_DIMENSION, PRI_VIEWPORT_HEIGHT) *
+				REG_GET_FIELD(viewport,
+					      HUBP0_DCSURF_PRI_VIEWPORT_DIMENSION, PRI_VIEWPORT_WIDTH) *
+				4);
+			break;
+		case CHIP_VEGA10:
+		case CHIP_VEGA12:
+		default:
+			viewport = RREG32_SOC15(DCE, 0, mmSCL0_VIEWPORT_SIZE);
+			size = (REG_GET_FIELD(viewport, SCL0_VIEWPORT_SIZE, VIEWPORT_HEIGHT) *
+				REG_GET_FIELD(viewport, SCL0_VIEWPORT_SIZE, VIEWPORT_WIDTH) *
+				4);
+			break;
+		}
+
+		return size;
+	}
+}
+
  static int gmc_v9_0_sw_init(void *handle)
  {
  	int r;

drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c static int gmc_v9_0_sw_init(void *handle) · line 894

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +1 -1
@@ -848,7 +888,7 @@ static int gmc_v9_0_sw_init(void *handle)
  	 * It needs to reserve 8M stolen memory for vega10
  	 * TODO: Figure out how to avoid that...
  	 */
-	adev->gmc.stolen_size = 8 * 1024 * 1024;
+	adev->gmc.stolen_size = gmc_v9_0_get_vbios_fb_size(adev);
 
  	/* set DMA mask + need_dma32 flags.
  	 * PCIE - can handle 44-bits.

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

#4 lore raw
In reply to a message not in the archive

Am 06.04.2018 um 19:24 schrieb Alex Deucher:

Quoted 27 lines

Steal 9 MB for vga emulation and fb if vga is enabled, otherwise, steal enough to cover the current display size as set by the vbios.

If no memory is used (e.g., secondary or headless card), skip stolen memory reserve.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 17 +++++++------
  drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c   | 17 ++++++++++++-
  drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c   | 17 ++++++++++++-
  drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c   | 17 ++++++++++++-
  drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c   | 42 ++++++++++++++++++++++++++++++++-
  5 files changed, 99 insertions(+), 11 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +0 -4
index 205da3ff9cd0..2de2f5e5a0f9 100644
@@ -1454,12 +1454,14 @@ int amdgpu_ttm_init(struct amdgpu_device *adev)
  		return r;
  	}
 
-	r = amdgpu_bo_create_kernel(adev, adev->gmc.stolen_size, PAGE_SIZE,
-				    AMDGPU_GEM_DOMAIN_VRAM,
-				    &adev->stolen_vga_memory,
-				    NULL, NULL);

drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c int amdgpu_ttm_init(struct amdgpu_device *adev) · line 1464

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +8 -2
-	if (r)
-		return r;
+	if (adev->gmc.stolen_size) {
+		r = amdgpu_bo_create_kernel(adev, adev->gmc.stolen_size, PAGE_SIZE,
+					    AMDGPU_GEM_DOMAIN_VRAM,
+					    &adev->stolen_vga_memory,
+					    NULL, NULL);
+		if (r)
+			return r;
+	}

We should probably rather handle zero size in amdgpu_bo_create_kernel() as just setting the pointer to NULL instead of trying to allocate a zero sized BO.

drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c void amdgpu_ttm_fini(struct amdgpu_device *adev) · line 1540

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +2 -1
  	DRM_INFO("amdgpu: %uM of VRAM memory ready\n",
  		 (unsigned) (adev->gmc.real_vram_size / (1024 * 1024)));
 
@@ -1534,7 +1536,8 @@ void amdgpu_ttm_fini(struct amdgpu_device *adev)
  		return;
 
  	amdgpu_ttm_debugfs_fini(adev);
-	amdgpu_bo_free_kernel(&adev->stolen_vga_memory, NULL, NULL);
+	if (adev->gmc.stolen_size)
+		amdgpu_bo_free_kernel(&adev->stolen_vga_memory, NULL, NULL);

The if can be skipped here, freeing a NULL pointer is harmless.

Quoted 113 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +0 -0
  	amdgpu_ttm_fw_reserve_vram_fini(adev);
  	if (adev->mman.aper_base_kaddr)
  		iounmap(adev->mman.aper_base_kaddr);
drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c +16 -1
index 5617cf62c566..63f0b65854a3 100644
@@ -825,6 +825,21 @@ static int gmc_v6_0_late_init(void *handle)
  		return 0;
  }
 
+static unsigned gmc_v6_0_get_vbios_fb_size(struct amdgpu_device *adev)
+{
+	u32 d1vga_control = RREG32(mmD1VGA_CONTROL);
+
+	if (REG_GET_FIELD(d1vga_control, D1VGA_CONTROL, D1VGA_MODE_ENABLE)) {
+		return 9 * 1024 * 1024; /* reserve 8MB for vga emulator and 1 MB for FB */
+	} else {
+		u32 viewport = RREG32(mmVIEWPORT_SIZE);
+		unsigned size = (REG_GET_FIELD(viewport, VIEWPORT_SIZE, VIEWPORT_HEIGHT) *
+				 REG_GET_FIELD(viewport, VIEWPORT_SIZE, VIEWPORT_WIDTH) *
+				 4);
+		return size;
+	}
+}
+
  static int gmc_v6_0_sw_init(void *handle)
  {
  	int r;
@@ -851,7 +866,7 @@ static int gmc_v6_0_sw_init(void *handle)
 
  	adev->gmc.mc_mask = 0xffffffffffULL;
 
-	adev->gmc.stolen_size = 256 * 1024;
+	adev->gmc.stolen_size = gmc_v6_0_get_vbios_fb_size(adev);
 
  	adev->need_dma32 = false;
  	dma_bits = adev->need_dma32 ? 32 : 40;
drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c +16 -1
index 80054f36e487..2deb5c93ef28 100644
@@ -964,6 +964,21 @@ static int gmc_v7_0_late_init(void *handle)
  		return 0;
  }
 
+static unsigned gmc_v7_0_get_vbios_fb_size(struct amdgpu_device *adev)
+{
+	u32 d1vga_control = RREG32(mmD1VGA_CONTROL);
+
+	if (REG_GET_FIELD(d1vga_control, D1VGA_CONTROL, D1VGA_MODE_ENABLE)) {
+		return 9 * 1024 * 1024; /* reserve 8MB for vga emulator and 1 MB for FB */
+	} else {
+		u32 viewport = RREG32(mmVIEWPORT_SIZE);
+		unsigned size = (REG_GET_FIELD(viewport, VIEWPORT_SIZE, VIEWPORT_HEIGHT) *
+				 REG_GET_FIELD(viewport, VIEWPORT_SIZE, VIEWPORT_WIDTH) *
+				 4);
+		return size;
+	}
+}
+
  static int gmc_v7_0_sw_init(void *handle)
  {
  	int r;
@@ -998,7 +1013,7 @@ static int gmc_v7_0_sw_init(void *handle)
  	 */
  	adev->gmc.mc_mask = 0xffffffffffULL; /* 40 bit MC */
 
-	adev->gmc.stolen_size = 256 * 1024;
+	adev->gmc.stolen_size = gmc_v7_0_get_vbios_fb_size(adev);
 
  	/* set DMA mask + need_dma32 flags.
  	 * PCIE - can handle 40-bits.
drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c +16 -1
index d71d4cb68f9c..04b00df3c6e6 100644
@@ -1055,6 +1055,21 @@ static int gmc_v8_0_late_init(void *handle)
  		return 0;
  }
 
+static unsigned gmc_v8_0_get_vbios_fb_size(struct amdgpu_device *adev)
+{
+	u32 d1vga_control = RREG32(mmD1VGA_CONTROL);
+
+	if (REG_GET_FIELD(d1vga_control, D1VGA_CONTROL, D1VGA_MODE_ENABLE)) {
+		return 9 * 1024 * 1024; /* reserve 8MB for vga emulator and 1 MB for FB */
+	} else {
+		u32 viewport = RREG32(mmVIEWPORT_SIZE);
+		unsigned size = (REG_GET_FIELD(viewport, VIEWPORT_SIZE, VIEWPORT_HEIGHT) *
+				 REG_GET_FIELD(viewport, VIEWPORT_SIZE, VIEWPORT_WIDTH) *
+				 4);
+		return size;
+	}
+}
+
  #define mmMC_SEQ_MISC0_FIJI 0xA71
 
  static int gmc_v8_0_sw_init(void *handle)
@@ -1096,7 +1111,7 @@ static int gmc_v8_0_sw_init(void *handle)
  	 */
  	adev->gmc.mc_mask = 0xffffffffffULL; /* 40 bit MC */
 
-	adev->gmc.stolen_size = 256 * 1024;
+	adev->gmc.stolen_size = gmc_v8_0_get_vbios_fb_size(adev);
 
  	/* set DMA mask + need_dma32 flags.
  	 * PCIE - can handle 40-bits.
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +0 -0
index 070946e1e4a7..252a6c6998b7 100644

drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c static int gmc_v9_0_gart_init(struct amdgpu_device *adev) · line 801

Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +6 -0
@@ -793,6 +793,46 @@ static int gmc_v9_0_gart_init(struct amdgpu_device *adev)
  	return amdgpu_gart_table_vram_alloc(adev);
  }
 
+#define mmHUBP0_DCSURF_PRI_VIEWPORT_DIMENSION                                                          0x055d
+#define mmHUBP0_DCSURF_PRI_VIEWPORT_DIMENSION_BASE_IDX                                                 2
+#define HUBP0_DCSURF_PRI_VIEWPORT_DIMENSION__PRI_VIEWPORT_WIDTH__SHIFT                                        0x0
+#define HUBP0_DCSURF_PRI_VIEWPORT_DIMENSION__PRI_VIEWPORT_HEIGHT__SHIFT                                       0x10
+#define HUBP0_DCSURF_PRI_VIEWPORT_DIMENSION__PRI_VIEWPORT_WIDTH_MASK                                          0x00003FFFL
+#define HUBP0_DCSURF_PRI_VIEWPORT_DIMENSION__PRI_VIEWPORT_HEIGHT_MASK                                         0x3FFF0000L

Mhm, hub defines in the middle of gmc_v9_0.c? At least put them at the start of the file.

But I would rather see that delegated to DAL or something like this, cause that doesn't really looks GMC related.

Christian.

Quoted 38 lines
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +34 -0
+
+static unsigned gmc_v9_0_get_vbios_fb_size(struct amdgpu_device *adev)
+{
+	u32 d1vga_control = RREG32_SOC15(DCE, 0, mmD1VGA_CONTROL);
+
+	if (REG_GET_FIELD(d1vga_control, D1VGA_CONTROL, D1VGA_MODE_ENABLE)) {
+		return 9 * 1024 * 1024; /* reserve 8MB for vga emulator and 1 MB for FB */
+	} else {
+		u32 viewport;
+		unsigned size;
+
+		switch (adev->asic_type) {
+		case CHIP_RAVEN:
+			viewport = RREG32_SOC15(DCE, 0, mmHUBP0_DCSURF_PRI_VIEWPORT_DIMENSION);
+			size = (REG_GET_FIELD(viewport,
+					      HUBP0_DCSURF_PRI_VIEWPORT_DIMENSION, PRI_VIEWPORT_HEIGHT) *
+				REG_GET_FIELD(viewport,
+					      HUBP0_DCSURF_PRI_VIEWPORT_DIMENSION, PRI_VIEWPORT_WIDTH) *
+				4);
+			break;
+		case CHIP_VEGA10:
+		case CHIP_VEGA12:
+		default:
+			viewport = RREG32_SOC15(DCE, 0, mmSCL0_VIEWPORT_SIZE);
+			size = (REG_GET_FIELD(viewport, SCL0_VIEWPORT_SIZE, VIEWPORT_HEIGHT) *
+				REG_GET_FIELD(viewport, SCL0_VIEWPORT_SIZE, VIEWPORT_WIDTH) *
+				4);
+			break;
+		}
+
+		return size;
+	}
+}
+
  static int gmc_v9_0_sw_init(void *handle)
  {
  	int r;

drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c static int gmc_v9_0_sw_init(void *handle) · line 894

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +1 -1
@@ -848,7 +888,7 @@ static int gmc_v9_0_sw_init(void *handle)
  	 * It needs to reserve 8M stolen memory for vega10
  	 * TODO: Figure out how to avoid that...
  	 */
-	adev->gmc.stolen_size = 8 * 1024 * 1024;
+	adev->gmc.stolen_size = gmc_v9_0_get_vbios_fb_size(adev);
 
  	/* set DMA mask + need_dma32 flags.
  	 * PCIE - can handle 44-bits.

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

A message that is not in the archive (sent off-list or not yet received): f3ad2bab-5955-8932-5636-6d51c88ace1a-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org

#6 lore raw
Quoted 39 lines · Christian König

Am 06.04.2018 um 19:24 schrieb Alex Deucher:

Quoted 38 lines

Steal 9 MB for vga emulation and fb if vga is enabled, otherwise, steal enough to cover the current display size as set by the vbios.

If no memory is used (e.g., secondary or headless card), skip stolen memory reserve.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 17 +++++++------
  drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c   | 17 ++++++++++++-
  drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c   | 17 ++++++++++++-
  drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c   | 17 ++++++++++++-
  drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c   | 42
++++++++++++++++++++++++++++++++-
  5 files changed, 99 insertions(+), 11 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +5 -5
index 205da3ff9cd0..2de2f5e5a0f9 100644
@@ -1454,12 +1454,14 @@ int amdgpu_ttm_init(struct amdgpu_device *adev)
                return r;
        }
  -     r = amdgpu_bo_create_kernel(adev, adev->gmc.stolen_size,
 PAGE_SIZE,
-                                   AMDGPU_GEM_DOMAIN_VRAM,
-                                   &adev->stolen_vga_memory,
-                                   NULL, NULL);
-       if (r)
-               return r;
+       if (adev->gmc.stolen_size) {
+               r = amdgpu_bo_create_kernel(adev, adev->gmc.stolen_size,
 PAGE_SIZE,
+                                           AMDGPU_GEM_DOMAIN_VRAM,
+                                           &adev->stolen_vga_memory,
+                                           NULL, NULL);
Quoted 8 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c int amdgpu_ttm_init(struct amdgpu_device *adev) · line 1464

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +3 -0
+               if (r)
+                       return r;
+       }

We should probably rather handle zero size in amdgpu_bo_create_kernel() as just setting the pointer to NULL instead of trying to allocate a zero sized BO.

yeah, I guess that would work too.

Quoted 12 lines
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +2 -1
        DRM_INFO("amdgpu: %uM of VRAM memory ready\n",
                 (unsigned) (adev->gmc.real_vram_size / (1024 * 1024)));
  @@ -1534,7 +1536,8 @@ void amdgpu_ttm_fini(struct amdgpu_device *adev)
                return;
        amdgpu_ttm_debugfs_fini(adev);
-       amdgpu_bo_free_kernel(&adev->stolen_vga_memory, NULL, NULL);
+       if (adev->gmc.stolen_size)
+               amdgpu_bo_free_kernel(&adev->stolen_vga_memory, NULL,

NULL);

Quoted 1 line

The if can be skipped here, freeing a NULL pointer is harmless.

Ok.

Quoted 131 lines
Quoted 131 lines

        amdgpu_ttm_fw_reserve_vram_fini(adev);
        if (adev->mman.aper_base_kaddr)
                iounmap(adev->mman.aper_base_kaddr);
drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c +5 -0
index 5617cf62c566..63f0b65854a3 100644
@@ -825,6 +825,21 @@ static int gmc_v6_0_late_init(void *handle)
                return 0;
  }
  +static unsigned gmc_v6_0_get_vbios_fb_size(struct amdgpu_device *adev)
+{
+       u32 d1vga_control = RREG32(mmD1VGA_CONTROL);
+
+       if (REG_GET_FIELD(d1vga_control, D1VGA_CONTROL,
 D1VGA_MODE_ENABLE)) {
+               return 9 * 1024 * 1024; /* reserve 8MB for vga emulator

and 1 MB for FB */

drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c +3 -0
+       } else {
+               u32 viewport = RREG32(mmVIEWPORT_SIZE);
+               unsigned size = (REG_GET_FIELD(viewport, VIEWPORT_SIZE,

VIEWPORT_HEIGHT) *
+ REG_GET_FIELD(viewport, VIEWPORT_SIZE,
VIEWPORT_WIDTH) *

drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c +6 -0
+                                4);
+               return size;
+       }
+}
+
  static int gmc_v6_0_sw_init(void *handle)
  {
        int r;
@@ -851,7 +866,7 @@ static int gmc_v6_0_sw_init(void *handle)
        adev->gmc.mc_mask = 0xffffffffffULL;
  -     adev->gmc.stolen_size = 256 * 1024;
+       adev->gmc.stolen_size = gmc_v6_0_get_vbios_fb_size(adev);
        adev->need_dma32 = false;
        dma_bits = adev->need_dma32 ? 32 : 40;
drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c +5 -0
index 80054f36e487..2deb5c93ef28 100644
@@ -964,6 +964,21 @@ static int gmc_v7_0_late_init(void *handle)
                return 0;
  }
  +static unsigned gmc_v7_0_get_vbios_fb_size(struct amdgpu_device *adev)
+{
+       u32 d1vga_control = RREG32(mmD1VGA_CONTROL);
+
+       if (REG_GET_FIELD(d1vga_control, D1VGA_CONTROL,
 D1VGA_MODE_ENABLE)) {
+               return 9 * 1024 * 1024; /* reserve 8MB for vga emulator

and 1 MB for FB */

drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c +3 -0
+       } else {
+               u32 viewport = RREG32(mmVIEWPORT_SIZE);
+               unsigned size = (REG_GET_FIELD(viewport, VIEWPORT_SIZE,

VIEWPORT_HEIGHT) *
+ REG_GET_FIELD(viewport, VIEWPORT_SIZE,
VIEWPORT_WIDTH) *

drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c +6 -0
+                                4);
+               return size;
+       }
+}
+
  static int gmc_v7_0_sw_init(void *handle)
  {
        int r;
@@ -998,7 +1013,7 @@ static int gmc_v7_0_sw_init(void *handle)
         */
        adev->gmc.mc_mask = 0xffffffffffULL; /* 40 bit MC */
  -     adev->gmc.stolen_size = 256 * 1024;
+       adev->gmc.stolen_size = gmc_v7_0_get_vbios_fb_size(adev);
        /* set DMA mask + need_dma32 flags.
         * PCIE - can handle 40-bits.
drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c +5 -0
index d71d4cb68f9c..04b00df3c6e6 100644
@@ -1055,6 +1055,21 @@ static int gmc_v8_0_late_init(void *handle)
                return 0;
  }
  +static unsigned gmc_v8_0_get_vbios_fb_size(struct amdgpu_device *adev)
+{
+       u32 d1vga_control = RREG32(mmD1VGA_CONTROL);
+
+       if (REG_GET_FIELD(d1vga_control, D1VGA_CONTROL,
 D1VGA_MODE_ENABLE)) {
+               return 9 * 1024 * 1024; /* reserve 8MB for vga emulator

and 1 MB for FB */

drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c +3 -0
+       } else {
+               u32 viewport = RREG32(mmVIEWPORT_SIZE);
+               unsigned size = (REG_GET_FIELD(viewport, VIEWPORT_SIZE,

VIEWPORT_HEIGHT) *
+ REG_GET_FIELD(viewport, VIEWPORT_SIZE,
VIEWPORT_WIDTH) *

drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c +6 -0
+                                4);
+               return size;
+       }
+}
+
  #define mmMC_SEQ_MISC0_FIJI 0xA71
    static int gmc_v8_0_sw_init(void *handle)
@@ -1096,7 +1111,7 @@ static int gmc_v8_0_sw_init(void *handle)
         */
        adev->gmc.mc_mask = 0xffffffffffULL; /* 40 bit MC */
  -     adev->gmc.stolen_size = 256 * 1024;
+       adev->gmc.stolen_size = gmc_v8_0_get_vbios_fb_size(adev);
        /* set DMA mask + need_dma32 flags.
         * PCIE - can handle 40-bits.
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +0 -0
index 070946e1e4a7..252a6c6998b7 100644
@@ -793,6 +793,46 @@ static int gmc_v9_0_gart_init(struct amdgpu_device
 *adev)
        return amdgpu_gart_table_vram_alloc(adev);
  }
  +#define mmHUBP0_DCSURF_PRI_VIEWPORT_DIMENSION

0x055d
+#define mmHUBP0_DCSURF_PRI_VIEWPORT_DIMENSION_BASE_IDX
2
+#define HUBP0_DCSURF_PRI_VIEWPORT_DIMENSION__PRI_VIEWPORT_WIDTH__SHIFT 0x0
+#define HUBP0_DCSURF_PRI_VIEWPORT_DIMENSION__PRI_VIEWPORT_HEIGHT__SHIFT 0x10

Quoted 8 lines
Quoted 4 lines

+#define HUBP0_DCSURF_PRI_VIEWPORT_DIMENSION__PRI_VIEWPORT_WIDTH_MASK 0x00003FFFL
+#define HUBP0_DCSURF_PRI_VIEWPORT_DIMENSION__PRI_VIEWPORT_HEIGHT_MASK 0x3FFF0000L

Mhm, hub defines in the middle of gmc_v9_0.c? At least put them at the start of the file.

OK.

Quoted 3 lines

But I would rather see that delegated to DAL or something like this, cause that doesn't really looks GMC related.

We already include the DCE headers in all the gmc files because we already have to snoop some of the vga registers for other things. The only reason I added the DCN register defines was because the viewport register is different between DCE and DCN. It seemed like overkill to add an api to DC just to fetch one register.

The other issue is what to do about boards like APUs with limited vram? E.g., what if the board only has 32MB of vram and the vbios is using 32MB of vram for the pre-OS display. Seems like in that case, just setting the stolen size to 0 and dealing with potential garbage on the display during the transition from vbios to driver is an ok trade off. I'm not sure how often this will come up in practice.

I'll respin the patches.

Alex

Quoted 49 lines

Christian.

Quoted 45 lines
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +6 -0
+
+static unsigned gmc_v9_0_get_vbios_fb_size(struct amdgpu_device *adev)
+{
+       u32 d1vga_control = RREG32_SOC15(DCE, 0, mmD1VGA_CONTROL);
+
+       if (REG_GET_FIELD(d1vga_control, D1VGA_CONTROL,

D1VGA_MODE_ENABLE)) {
+ return 9 * 1024 * 1024; /* reserve 8MB for vga emulator
and 1 MB for FB */

drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +7 -0
+       } else {
+               u32 viewport;
+               unsigned size;
+
+               switch (adev->asic_type) {
+               case CHIP_RAVEN:
+                       viewport = RREG32_SOC15(DCE, 0,

mmHUBP0_DCSURF_PRI_VIEWPORT_DIMENSION);

drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +2 -0
+                       size = (REG_GET_FIELD(viewport,
+

HUBP0_DCSURF_PRI_VIEWPORT_DIMENSION, PRI_VIEWPORT_HEIGHT) *

drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +2 -0
+                               REG_GET_FIELD(viewport,
+

HUBP0_DCSURF_PRI_VIEWPORT_DIMENSION, PRI_VIEWPORT_WIDTH) *

drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +6 -0
+                               4);
+                       break;
+               case CHIP_VEGA10:
+               case CHIP_VEGA12:
+               default:
+                       viewport = RREG32_SOC15(DCE, 0,

mmSCL0_VIEWPORT_SIZE);
+ size = (REG_GET_FIELD(viewport,
SCL0_VIEWPORT_SIZE, VIEWPORT_HEIGHT) *
+ REG_GET_FIELD(viewport,
SCL0_VIEWPORT_SIZE, VIEWPORT_WIDTH) *

drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +8 -0
+                               4);
+                       break;
+               }
+
+               return size;
+       }
+}
+
  static int gmc_v9_0_sw_init(void *handle)
  {
        int r;
Quoted 10 lines

drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c static int gmc_v9_0_sw_init(void *handle) · line 893

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +1 -1
@@ -848,7 +888,7 @@ static int gmc_v9_0_sw_init(void *handle)
         * It needs to reserve 8M stolen memory for vega10
         * TODO: Figure out how to avoid that...
         */
-       adev->gmc.stolen_size = 8 * 1024 * 1024;
+       adev->gmc.stolen_size = gmc_v9_0_get_vbios_fb_size(adev);
        /* set DMA mask + need_dma32 flags.
         * PCIE - can handle 44-bits.

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