Skip to contentSkip to conversation

drm/amdgpu/gmc: check if AGP is disabled in amdgpu_gmc_agp_addr()

PATCH In review Alex Deucher 3 participants 4 messages Nov 21, 2023 – Nov 27, 2023

Subsystems (2)
lore
Share & tools
lore

Alex Deucher

author maintainer
#0 lore raw

PATCH 1/2 drm/amdgpu/gmc: check if AGP is disabled in amdgpu_gmc_agp_addr()

Return AMDGPU_BO_INVALID_OFFSET if the AGP aperture is disabled. There is no reason to check further if the aperture is disabled.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +3 -0
index 5f71414190e9..0f85f906791b 100644
@@ -181,6 +181,9 @@ uint64_t amdgpu_gmc_agp_addr(struct ttm_buffer_object *bo)
 {
 	struct amdgpu_device *adev = amdgpu_ttm_adev(bo->bdev);
 
+	if (!adev->gmc.agp_size)
+		return AMDGPU_BO_INVALID_OFFSET;
+
 	if (bo->ttm->num_pages != 1 || bo->ttm->caching == ttm_cached)
 		return AMDGPU_BO_INVALID_OFFSET;
 
Signature · 1 line
2.42.0
author maintainer
#1 lore raw

PATCH 2/2 drm/amdgpu: fix AGP addressing when GART is not at 0

This worked by luck if the GART aperture ended up at 0. When we ended up moving GART on some chips, the GART aperture ended up offsetting the the AGP address since the resource->start is a GART offset, not an MC address. Fix this by moving the AGP address setup into amdgpu_bo_gpu_offset_no_check().

v2: check mem_type before checking agp
v3: check if the ttm bo has a ttm_tt allocated yet

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c    |  3 +++
 drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 10 +++++++---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c    |  4 +---
 3 files changed, 11 insertions(+), 6 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +3 -0
index 0f85f906791b..a0dda572e490 100644
@@ -184,6 +184,9 @@ uint64_t amdgpu_gmc_agp_addr(struct ttm_buffer_object *bo)
 	if (!adev->gmc.agp_size)
 		return AMDGPU_BO_INVALID_OFFSET;
 
+	if (!bo->ttm)
+		return AMDGPU_BO_INVALID_OFFSET;
+
 	if (bo->ttm->num_pages != 1 || bo->ttm->caching == ttm_cached)
 		return AMDGPU_BO_INVALID_OFFSET;
 
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +7 -3
index c938648de853..c24f7b2c04c1 100644
@@ -1538,10 +1538,14 @@ u64 amdgpu_bo_gpu_offset(struct amdgpu_bo *bo)
 u64 amdgpu_bo_gpu_offset_no_check(struct amdgpu_bo *bo)
 {
 	struct amdgpu_device *adev = amdgpu_ttm_adev(bo->tbo.bdev);
-	uint64_t offset;
+	uint64_t offset = AMDGPU_BO_INVALID_OFFSET;
 
-	offset = (bo->tbo.resource->start << PAGE_SHIFT) +
-		 amdgpu_ttm_domain_start(adev, bo->tbo.resource->mem_type);
+	if (bo->tbo.resource->mem_type == TTM_PL_TT)
+		offset = amdgpu_gmc_agp_addr(&bo->tbo);
+
+	if (offset == AMDGPU_BO_INVALID_OFFSET)
+		offset = (bo->tbo.resource->start << PAGE_SHIFT) +
+			amdgpu_ttm_domain_start(adev, bo->tbo.resource->mem_type);
 
 	return amdgpu_gmc_sign_extend(offset);
 }
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +1 -3
index 05991c5c8ddb..ab4a762aed5b 100644
@@ -959,10 +959,8 @@ int amdgpu_ttm_alloc_gart(struct ttm_buffer_object *bo)
 		return 0;
 
 	addr = amdgpu_gmc_agp_addr(bo);
-	if (addr != AMDGPU_BO_INVALID_OFFSET) {
-		bo->resource->start = addr >> PAGE_SHIFT;
+	if (addr != AMDGPU_BO_INVALID_OFFSET)
 		return 0;
-	}
 
 	/* allocate GART space */
 	placement.num_placement = 1;
Signature · 1 line
2.42.0
#2 lore raw
In reply to Alex Deucher
Quoted 5 lines · Alex Deucher

Return AMDGPU_BO_INVALID_OFFSET if the AGP aperture is disabled. There is no reason to check further if the aperture is disabled.

Ping?

Quoted 21 lines
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +3 -1
index 5f71414190e9..0f85f906791b 100644
@@ -181,6 +181,9 @@ uint64_t amdgpu_gmc_agp_addr(struct ttm_buffer_object *bo)
 {
        struct amdgpu_device *adev = amdgpu_ttm_adev(bo->bdev);
 
+       if (!adev->gmc.agp_size)
+               return AMDGPU_BO_INVALID_OFFSET;
+
        if (bo->ttm->num_pages != 1 || bo->ttm->caching == ttm_cached)
                return AMDGPU_BO_INVALID_OFFSET;
 
--

2.42.0

#3 lore raw
In reply to Alex Deucher

Am 21.11.23 um 16:05 schrieb Alex Deucher:

Quoted 2 lines

Return AMDGPU_BO_INVALID_OFFSET if the AGP aperture is disabled. There is no reason to check further if the aperture is disabled.

Yeah, but there shouldn't be a reason to check it earlier either.

The "if (bo->ttm->dma_address[0] + PAGE_SIZE >= adev->gmc.agp_size)" just below this code here should catch that perfectly well.

Christian.

Quoted 20 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c | 3 +++
  1 file changed, 3 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +3 -0
index 5f71414190e9..0f85f906791b 100644
@@ -181,6 +181,9 @@ uint64_t amdgpu_gmc_agp_addr(struct ttm_buffer_object *bo)
  {
  	struct amdgpu_device *adev = amdgpu_ttm_adev(bo->bdev);
 
+	if (!adev->gmc.agp_size)
+		return AMDGPU_BO_INVALID_OFFSET;
+
  	if (bo->ttm->num_pages != 1 || bo->ttm->caching == ttm_cached)
  		return AMDGPU_BO_INVALID_OFFSET;