Skip to contentSkip to conversation

drm/amdgpu/gmc: add a way to force a particular placement for GART

PATCH In review Alex Deucher 4 participants 8 messages Sep 14, 2023 – Sep 19, 2023

Subsystems (2)
lore
Share & tools
lore

Alex Deucher

author maintainer
#0 lore raw

PATCH 1/4 drm/amdgpu/gmc: add a way to force a particular placement for GART

We normally place GART based on the location of VRAM and the available address space around that, but provide an option to force a particular location for hardware that needs it.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c | 19 +++++++++++++++----
 drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h |  7 +++++++
 2 files changed, 22 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +15 -4
index c7793db6d098..c41321c456fe 100644
@@ -286,11 +286,22 @@ void amdgpu_gmc_gart_location(struct amdgpu_device *adev, struct amdgpu_gmc *mc)
 		mc->gart_size = max(size_bf, size_af);
 	}
 
-	if ((size_bf >= mc->gart_size && size_bf < size_af) ||
-	    (size_af < mc->gart_size))
-		mc->gart_start = 0;
-	else
+	switch (mc->gart_placement) {
+	case AMDGPU_GART_PLACEMENT_HIGH:
 		mc->gart_start = max_mc_address - mc->gart_size + 1;
+		break;
+	case AMDGPU_GART_PLACEMENT_LOW:
+		mc->gart_start = 0;
+		break;
+	case AMDGPU_GART_PLACEMENT_BEST_FIT:
+	default:
+		if ((size_bf >= mc->gart_size && size_bf < size_af) ||
+		    (size_af < mc->gart_size))
+			mc->gart_start = 0;
+		else
+			mc->gart_start = max_mc_address - mc->gart_size + 1;
+		break;
+	}
 
 	mc->gart_start &= ~(four_gb - 1);
 	mc->gart_end = mc->gart_start + mc->gart_size - 1;
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h +7 -0
index fdc25cd559b6..caa15639d3d5 100644
@@ -197,6 +197,12 @@ struct amdgpu_mem_partition_info {
 
 #define INVALID_PFN    -1
 
+enum amdgpu_gart_placement {
+	AMDGPU_GART_PLACEMENT_BEST_FIT = 0,
+	AMDGPU_GART_PLACEMENT_HIGH,
+	AMDGPU_GART_PLACEMENT_LOW,
+};
+
 struct amdgpu_gmc {
 	/* FB's physical address in MMIO space (for CPU to
 	 * map FB). This is different compared to the agp/
@@ -333,6 +339,7 @@ struct amdgpu_gmc {
 	u64 MC_VM_MX_L1_TLB_CNTL;
 
 	u64 noretry_flags;
+	enum amdgpu_gart_placement gart_placement;
 };
 
 #define amdgpu_gmc_flush_gpu_tlb(adev, vmid, vmhub, type) ((adev)->gmc.gmc_funcs->flush_gpu_tlb((adev), (vmid), (vmhub), (type)))
Signature · 1 line
2.41.0
author maintainer
#1 lore raw

PATCH 2/4 drm/amdgpu/gmc11: set gart placement GC11

Needed to avoid a hardware issue.

---
 drivers/gpu/drm/amd/amdgpu/gmc_v11_0.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/gpu/drm/amd/amdgpu/gmc_v11_0.c +6 -0
index e1f47f9c1881..6947b598e9b2 100644
@@ -740,6 +740,12 @@ static int gmc_v11_0_mc_init(struct amdgpu_device *adev)
 	else
 		adev->gmc.gart_size = (u64)amdgpu_gart_size << 20;
 
+	/* force GART to avoid a hw issue in GC11 */
+	if (adev->flags & AMD_IS_APU)
+		adev->gmc.gart_placement = AMDGPU_GART_PLACEMENT_LOW;
+	else
+		adev->gmc.gart_placement = AMDGPU_GART_PLACEMENT_HIGH;
+
 	gmc_v11_0_vram_gtt_location(adev, &adev->gmc);
 
 	return 0;
Signature · 1 line
2.41.0
author maintainer
#2 lore raw

PATCH 3/4 drm/amdgpu/gmc: add a flag to disable AGP

In reply to Alex Deucher

Allows the driver to disable the AGP aperture when it's not needed.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c | 2 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +1 -1
index c41321c456fe..ed9be37eca66 100644
@@ -326,7 +326,7 @@ void amdgpu_gmc_agp_location(struct amdgpu_device *adev, struct amdgpu_gmc *mc)
 	const uint64_t sixteen_gb_mask = ~(sixteen_gb - 1);
 	u64 size_af, size_bf;
 
-	if (amdgpu_sriov_vf(adev)) {
+	if (amdgpu_sriov_vf(adev) || mc->no_agp) {
 		mc->agp_start = 0xffffffffffff;
 		mc->agp_end = 0x0;
 		mc->agp_size = 0;
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h +1 -0
index caa15639d3d5..65641d7da212 100644
@@ -340,6 +340,7 @@ struct amdgpu_gmc {
 
 	u64 noretry_flags;
 	enum amdgpu_gart_placement gart_placement;
+	bool no_agp;
 };
 
 #define amdgpu_gmc_flush_gpu_tlb(adev, vmid, vmhub, type) ((adev)->gmc.gmc_funcs->flush_gpu_tlb((adev), (vmid), (vmhub), (type)))
Signature · 1 line
2.41.0
author maintainer
#3 lore raw

PATCH 4/4 drm/amdgpu/gmc11: disable AGP on GC 11.5

In reply to Alex Deucher

AGP aperture is deprecated and no longer functional.

---
 drivers/gpu/drm/amd/amdgpu/gmc_v11_0.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/gpu/drm/amd/amdgpu/gmc_v11_0.c +3 -0
index 6947b598e9b2..7ee91b66f761 100644
@@ -745,6 +745,9 @@ static int gmc_v11_0_mc_init(struct amdgpu_device *adev)
 		adev->gmc.gart_placement = AMDGPU_GART_PLACEMENT_LOW;
 	else
 		adev->gmc.gart_placement = AMDGPU_GART_PLACEMENT_HIGH;
+	/* AGP aperture is removed on GC11.5 */
+	if (amdgpu_ip_version(adev, GC_HWIP, -2) >= IP_VERSION(11, 5, 0))
+		adev->gmc.no_agp = true;
 
 	gmc_v11_0_vram_gtt_location(adev, &adev->gmc);
 
Signature · 1 line
2.41.0
#4 lore raw

Re: [PATCH 4/4] drm/amdgpu/gmc11: disable AGP on GC 11.5

Quoted 13 lines · Alex Deucher

AGP aperture is deprecated and no longer functional.

---
 drivers/gpu/drm/amd/amdgpu/gmc_v11_0.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/gpu/drm/amd/amdgpu/gmc_v11_0.c +0 -0
index 6947b598e9b2..7ee91b66f761 100644

drivers/gpu/drm/amd/amdgpu/gmc_v11_0.c static int gmc_v11_0_mc_init(struct amdgpu_device *adev) · line 749

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/gmc_v11_0.c +2 -0
@@ -745,6 +745,9 @@ static int gmc_v11_0_mc_init(struct amdgpu_device *adev)
                adev->gmc.gart_placement = AMDGPU_GART_PLACEMENT_LOW;
        else
                adev->gmc.gart_placement = AMDGPU_GART_PLACEMENT_HIGH;
+       /* AGP aperture is removed on GC11.5 */
+       if (amdgpu_ip_version(adev, GC_HWIP, -2) >= IP_VERSION(11, 5, 0))

Not sure what happened here. I've replaced the -2 with 0 locally.

Alex

Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/gmc_v11_0.c +1 -1
+               adev->gmc.no_agp = true;
 
        gmc_v11_0_vram_gtt_location(adev, &adev->gmc);
 
--

2.41.0

#5 lore raw

Re: [PATCH 4/4] drm/amdgpu/gmc11: disable AGP on GC 11.5

Am 14.09.23 um 20:49 schrieb Alex Deucher:

Quoted 8 lines · Alex Deucher
Quoted 7 lines

AGP aperture is deprecated and no longer functional.

---
  drivers/gpu/drm/amd/amdgpu/gmc_v11_0.c | 3 +++
  1 file changed, 3 insertions(+)
Quoted 11 lines

drivers/gpu/drm/amd/amdgpu/gmc_v11_0.c static int gmc_v11_0_mc_init(struct amdgpu_device *adev) · line 749

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/gmc_v11_0.c +2 -0
index 6947b598e9b2..7ee91b66f761 100644
@@ -745,6 +745,9 @@ static int gmc_v11_0_mc_init(struct amdgpu_device *adev)
                 adev->gmc.gart_placement = AMDGPU_GART_PLACEMENT_LOW;
         else
                 adev->gmc.gart_placement = AMDGPU_GART_PLACEMENT_HIGH;
+       /* AGP aperture is removed on GC11.5 */
+       if (amdgpu_ip_version(adev, GC_HWIP, -2) >= IP_VERSION(11, 5, 0))

Not sure what happened here. I've replaced the -2 with 0 locally.

I also don't see patch #1 in the series.

Patch #3 shouldn't be necessary, if the AGP aperture isn't wanted the code should just not call amdgpu_gmc_agp_location().

Christian.

Quoted 10 lines

Alex

Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/gmc_v11_0.c +1 -1
+               adev->gmc.no_agp = true;
 
         gmc_v11_0_vram_gtt_location(adev, &adev->gmc);
 
--

2.41.0

#6 lore raw

Re: [PATCH 4/4] drm/amdgpu/gmc11: disable AGP on GC 11.5

Quoted 22 lines · Christian König

Am 14.09.23 um 20:49 schrieb Alex Deucher:

Quoted 8 lines · Alex Deucher
Quoted 7 lines

AGP aperture is deprecated and no longer functional.

---
  drivers/gpu/drm/amd/amdgpu/gmc_v11_0.c | 3 +++
  1 file changed, 3 insertions(+)
Quoted 11 lines

drivers/gpu/drm/amd/amdgpu/gmc_v11_0.c static int gmc_v11_0_mc_init(struct amdgpu_device *adev) · line 749

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/gmc_v11_0.c +2 -0
index 6947b598e9b2..7ee91b66f761 100644
@@ -745,6 +745,9 @@ static int gmc_v11_0_mc_init(struct amdgpu_device *adev)
                 adev->gmc.gart_placement = AMDGPU_GART_PLACEMENT_LOW;
         else
                 adev->gmc.gart_placement = AMDGPU_GART_PLACEMENT_HIGH;
+       /* AGP aperture is removed on GC11.5 */
+       if (amdgpu_ip_version(adev, GC_HWIP, -2) >= IP_VERSION(11, 5, 0))

Not sure what happened here. I've replaced the -2 with 0 locally.

Quoted 2 lines

I also don't see patch #1 in the series.

https://patchwork.freedesktop.org/patch/557552/?series=123727&rev=1

Quoted 2 lines

Patch #3 shouldn't be necessary, if the AGP aperture isn't wanted the code should just not call amdgpu_gmc_agp_location().

Yeah, I could go that way too if you prefer. Same difference at the end of the day.

Alex

Quoted 14 lines

Christian.

Quoted 10 lines

Alex

Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/gmc_v11_0.c +1 -1
+               adev->gmc.no_agp = true;
 
         gmc_v11_0_vram_gtt_location(adev, &adev->gmc);
 
--

2.41.0

maintainer
#7 lore raw
In reply to Alex Deucher

Am 14.09.23 um 20:21 schrieb Alex Deucher:

Quoted 3 lines

We normally place GART based on the location of VRAM and the available address space around that, but provide an option to force a particular location for hardware that needs it.

Ah, somehow that patch arrived delayed in my inbox.

Quoted 25 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c | 19 +++++++++++++++----
  drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h |  7 +++++++
  2 files changed, 22 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +5 -4
index c7793db6d098..c41321c456fe 100644
@@ -286,11 +286,22 @@ void amdgpu_gmc_gart_location(struct amdgpu_device *adev, struct amdgpu_gmc *mc)
  		mc->gart_size = max(size_bf, size_af);
  	}
 
-	if ((size_bf >= mc->gart_size && size_bf < size_af) ||
-	    (size_af < mc->gart_size))
-		mc->gart_start = 0;
-	else
+	switch (mc->gart_placement) {
+	case AMDGPU_GART_PLACEMENT_HIGH:
  		mc->gart_start = max_mc_address - mc->gart_size + 1;
+		break;
+	case AMDGPU_GART_PLACEMENT_LOW:
+		mc->gart_start = 0;

drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c void amdgpu_gmc_gart_location(struct amdgpu_device *adev, struct amdgpu_gmc *mc) · line 304

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +10 -0
+		break;
+	case AMDGPU_GART_PLACEMENT_BEST_FIT:
+	default:
+		if ((size_bf >= mc->gart_size && size_bf < size_af) ||
+		    (size_af < mc->gart_size))
+			mc->gart_start = 0;
+		else
+			mc->gart_start = max_mc_address - mc->gart_size + 1;
+		break;
+	}

I'm not very keen of this because it doesn't really handle the problem, but rather just works around it.

Ideally we would use the kernels resource management functions for the internal address space and declare everything which is reserved as such.

Christian.

Quoted 28 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +0 -0
  	mc->gart_start &= ~(four_gb - 1);
  	mc->gart_end = mc->gart_start + mc->gart_size - 1;
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h +7 -0
index fdc25cd559b6..caa15639d3d5 100644
@@ -197,6 +197,12 @@ struct amdgpu_mem_partition_info {
 
  #define INVALID_PFN    -1
 
+enum amdgpu_gart_placement {
+	AMDGPU_GART_PLACEMENT_BEST_FIT = 0,
+	AMDGPU_GART_PLACEMENT_HIGH,
+	AMDGPU_GART_PLACEMENT_LOW,
+};
+
  struct amdgpu_gmc {
  	/* FB's physical address in MMIO space (for CPU to
  	 * map FB). This is different compared to the agp/
@@ -333,6 +339,7 @@ struct amdgpu_gmc {
  	u64 MC_VM_MX_L1_TLB_CNTL;
 
  	u64 noretry_flags;
+	enum amdgpu_gart_placement gart_placement;
  };
 
  #define amdgpu_gmc_flush_gpu_tlb(adev, vmid, vmhub, type) ((adev)->gmc.gmc_funcs->flush_gpu_tlb((adev), (vmid), (vmhub), (type)))