Skip to contentSkip to conversation

drm/amdgpu: add workarounds for Raven VCN TMZ issue

PATCH Superseded Lang Yu 2 participants 3 messages Mar 4, 2022

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Lang Yu

author
#0 lore raw

PATCH 1/1 drm/amdgpu: add workarounds for Raven VCN TMZ issue

It is a hardware issue that VCN can't handle a GTT backing stored TMZ buffer on Raven.

Move such a TMZ buffer to VRAM domain before command submission.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 27 ++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +27 -0
index af12256e1bd3..66345f2ce6ba 100644
@@ -393,6 +393,24 @@ void amdgpu_cs_report_moved_bytes(struct amdgpu_device *adev, u64 num_bytes,
 	spin_unlock(&adev->mm_stats.lock);
 }
 
+static int raven_vcn_tmz_quirks(struct amdgpu_cs_parser *p, struct amdgpu_bo *bo, uint32_t *domain)
+{
+	struct amdgpu_device *adev = amdgpu_ttm_adev(bo->tbo.bdev);
+	struct amdgpu_ring *ring = to_amdgpu_ring(p->entity->rq->sched);
+
+	if ((adev->asic_type == CHIP_RAVEN) &&
+	    (bo->flags & AMDGPU_GEM_CREATE_ENCRYPTED) &&
+	    (ring->funcs->type == AMDGPU_HW_IP_VCN_DEC ||
+	    ring->funcs->type == AMDGPU_HW_IP_VCN_ENC ||
+	    ring->funcs->type == AMDGPU_HW_IP_VCN_JPEG)) {
+		if (domain)
+			*domain = AMDGPU_GEM_DOMAIN_VRAM;
+		return 1;
+	}
+
+	return 0;
+}
+
 static int amdgpu_cs_bo_validate(void *param, struct amdgpu_bo *bo)
 {
 	struct amdgpu_device *adev = amdgpu_ttm_adev(bo->tbo.bdev);
@@ -403,6 +421,7 @@ static int amdgpu_cs_bo_validate(void *param, struct amdgpu_bo *bo)
 		.resv = bo->tbo.base.resv
 	};
 	uint32_t domain;
+	bool need_retry = 1;
 	int r;
 
 	if (bo->tbo.pin_count)
@@ -431,6 +450,8 @@ static int amdgpu_cs_bo_validate(void *param, struct amdgpu_bo *bo)
 		domain = bo->allowed_domains;
 	}
 
+	raven_vcn_tmz_quirks(p, bo, &domain);
+
 retry:
 	amdgpu_bo_placement_from_domain(bo, domain);
 	r = ttm_bo_validate(&bo->tbo, &bo->placement, &ctx);
@@ -442,6 +463,12 @@ static int amdgpu_cs_bo_validate(void *param, struct amdgpu_bo *bo)
 
 	if (unlikely(r == -ENOMEM) && domain != bo->allowed_domains) {
 		domain = bo->allowed_domains;
+		if (raven_vcn_tmz_quirks(p, bo, &domain)) {
+			if (need_retry)
+				need_retry = 0;
+			else
+				return r;
+		}
 		goto retry;
 	}
 
Signature · 1 line
2.25.1
maintainer
#1 lore raw

Am 04.03.22 um 10:15 schrieb Lang Yu:

Quoted 5 lines

It is a hardware issue that VCN can't handle a GTT backing stored TMZ buffer on Raven.

Move such a TMZ buffer to VRAM domain before command submission.

Please don't touch the CS code with that. What you can do is to implement a Raven specific patch_cs_in_place callback in the vcn_v*.c file.

See amdgpu_uvd_force_into_uvd_segment() how we handle the 256MiB window on really old UVD blocks. You just don't need to implement the full parsing of the command stream (yet).

Regards,
Christian.

Quoted 65 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 27 ++++++++++++++++++++++++++
  1 file changed, 27 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +27 -0
index af12256e1bd3..66345f2ce6ba 100644
@@ -393,6 +393,24 @@ void amdgpu_cs_report_moved_bytes(struct amdgpu_device *adev, u64 num_bytes,
  	spin_unlock(&adev->mm_stats.lock);
  }
 
+static int raven_vcn_tmz_quirks(struct amdgpu_cs_parser *p, struct amdgpu_bo *bo, uint32_t *domain)
+{
+	struct amdgpu_device *adev = amdgpu_ttm_adev(bo->tbo.bdev);
+	struct amdgpu_ring *ring = to_amdgpu_ring(p->entity->rq->sched);
+
+	if ((adev->asic_type == CHIP_RAVEN) &&
+	    (bo->flags & AMDGPU_GEM_CREATE_ENCRYPTED) &&
+	    (ring->funcs->type == AMDGPU_HW_IP_VCN_DEC ||
+	    ring->funcs->type == AMDGPU_HW_IP_VCN_ENC ||
+	    ring->funcs->type == AMDGPU_HW_IP_VCN_JPEG)) {
+		if (domain)
+			*domain = AMDGPU_GEM_DOMAIN_VRAM;
+		return 1;
+	}
+
+	return 0;
+}
+
  static int amdgpu_cs_bo_validate(void *param, struct amdgpu_bo *bo)
  {
  	struct amdgpu_device *adev = amdgpu_ttm_adev(bo->tbo.bdev);
@@ -403,6 +421,7 @@ static int amdgpu_cs_bo_validate(void *param, struct amdgpu_bo *bo)
  		.resv = bo->tbo.base.resv
  	};
  	uint32_t domain;
+	bool need_retry = 1;
  	int r;
 
  	if (bo->tbo.pin_count)
@@ -431,6 +450,8 @@ static int amdgpu_cs_bo_validate(void *param, struct amdgpu_bo *bo)
  		domain = bo->allowed_domains;
  	}
 
+	raven_vcn_tmz_quirks(p, bo, &domain);
+
  retry:
  	amdgpu_bo_placement_from_domain(bo, domain);
  	r = ttm_bo_validate(&bo->tbo, &bo->placement, &ctx);
@@ -442,6 +463,12 @@ static int amdgpu_cs_bo_validate(void *param, struct amdgpu_bo *bo)
 
  	if (unlikely(r == -ENOMEM) && domain != bo->allowed_domains) {
  		domain = bo->allowed_domains;
+		if (raven_vcn_tmz_quirks(p, bo, &domain)) {
+			if (need_retry)
+				need_retry = 0;
+			else
+				return r;
+		}
  		goto retry;
  	}
 
author
#2 lore raw
Quoted 7 lines · Christian König

Am 04.03.22 um 10:15 schrieb Lang Yu:

Quoted 5 lines

It is a hardware issue that VCN can't handle a GTT backing stored TMZ buffer on Raven.

Move such a TMZ buffer to VRAM domain before command submission.

Quoted 6 lines

Please don't touch the CS code with that. What you can do is to implement a Raven specific patch_cs_in_place callback in the vcn_v*.c file.

See amdgpu_uvd_force_into_uvd_segment() how we handle the 256MiB window on really old UVD blocks. You just don't need to implement the full parsing of the command stream (yet).

Thanks for comments and suggestions. I will have a try.

Regards,
Lang

Quoted 64 lines

Regards,
Christian.

Quoted 60 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 27 ++++++++++++++++++++++++++
  1 file changed, 27 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +27 -0
index af12256e1bd3..66345f2ce6ba 100644
@@ -393,6 +393,24 @@ void amdgpu_cs_report_moved_bytes(struct amdgpu_device *adev, u64 num_bytes,
  	spin_unlock(&adev->mm_stats.lock);
  }
+static int raven_vcn_tmz_quirks(struct amdgpu_cs_parser *p, struct amdgpu_bo *bo, uint32_t *domain)
+{
+	struct amdgpu_device *adev = amdgpu_ttm_adev(bo->tbo.bdev);
+	struct amdgpu_ring *ring = to_amdgpu_ring(p->entity->rq->sched);
+
+	if ((adev->asic_type == CHIP_RAVEN) &&
+	    (bo->flags & AMDGPU_GEM_CREATE_ENCRYPTED) &&
+	    (ring->funcs->type == AMDGPU_HW_IP_VCN_DEC ||
+	    ring->funcs->type == AMDGPU_HW_IP_VCN_ENC ||
+	    ring->funcs->type == AMDGPU_HW_IP_VCN_JPEG)) {
+		if (domain)
+			*domain = AMDGPU_GEM_DOMAIN_VRAM;
+		return 1;
+	}
+
+	return 0;
+}
+
  static int amdgpu_cs_bo_validate(void *param, struct amdgpu_bo *bo)
  {
  	struct amdgpu_device *adev = amdgpu_ttm_adev(bo->tbo.bdev);
@@ -403,6 +421,7 @@ static int amdgpu_cs_bo_validate(void *param, struct amdgpu_bo *bo)
  		.resv = bo->tbo.base.resv
  	};
  	uint32_t domain;
+	bool need_retry = 1;
  	int r;
  	if (bo->tbo.pin_count)
@@ -431,6 +450,8 @@ static int amdgpu_cs_bo_validate(void *param, struct amdgpu_bo *bo)
  		domain = bo->allowed_domains;
  	}
+	raven_vcn_tmz_quirks(p, bo, &domain);
+
  retry:
  	amdgpu_bo_placement_from_domain(bo, domain);
  	r = ttm_bo_validate(&bo->tbo, &bo->placement, &ctx);
@@ -442,6 +463,12 @@ static int amdgpu_cs_bo_validate(void *param, struct amdgpu_bo *bo)
  	if (unlikely(r == -ENOMEM) && domain != bo->allowed_domains) {
  		domain = bo->allowed_domains;
+		if (raven_vcn_tmz_quirks(p, bo, &domain)) {
+			if (need_retry)
+				need_retry = 0;
+			else
+				return r;
+		}
  		goto retry;
  	}