Blob Blame History Raw
From 90f6452ca58d436de4f69b423ecd75a109aa9766 Mon Sep 17 00:00:00 2001
From: changzhu <Changfeng.Zhu@amd.com>
Date: Tue, 10 Dec 2019 22:00:59 +0800
Subject: drm/amdgpu: add invalidate semaphore limit for SRIOV and picasso in
 gmc9
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Git-commit: 90f6452ca58d436de4f69b423ecd75a109aa9766
Patch-mainline: v5.5-rc2
References: bsc#1152472

It may fail to load guest driver in round 2 or cause Xstart problem
when using invalidate semaphore for SRIOV or picasso. So it needs avoid
using invalidate semaphore for SRIOV and picasso.

Signed-off-by: changzhu <Changfeng.Zhu@amd.com>
Reviewed-by: Christian König <christian.koenig@amd.com>
Reviewed-by: Huang Rui <ray.huang@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
Acked-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c |   44 ++++++++++++++++++----------------
 1 file changed, 24 insertions(+), 20 deletions(-)

--- a/drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c
@@ -397,6 +397,24 @@ static uint32_t gmc_v9_0_get_invalidate_
 	return req;
 }
 
+/**
+ * gmc_v9_0_use_invalidate_semaphore - judge whether to use semaphore
+ *
+ * @adev: amdgpu_device pointer
+ * @vmhub: vmhub type
+ *
+ */
+static bool gmc_v9_0_use_invalidate_semaphore(struct amdgpu_device *adev,
+				       uint32_t vmhub)
+{
+	return ((vmhub == AMDGPU_MMHUB_0 ||
+		 vmhub == AMDGPU_MMHUB_1) &&
+		(!amdgpu_sriov_vf(adev)) &&
+		(!(adev->asic_type == CHIP_RAVEN &&
+		   adev->rev_id < 0x8 &&
+		   adev->pdev->device == 0x15d8)));
+}
+
 /*
  * GART
  * VMID 0 is the physical GPU addresses as used by the kernel.
@@ -423,6 +441,7 @@ static void gmc_v9_0_flush_gpu_tlb(struc
 		uint32_t vmhub = i;
 		struct amdgpu_vmhub *hub = &adev->vmhub[i];
 		u32 tmp = gmc_v9_0_get_invalidate_req(vmid, flush_type);
+		bool use_semaphore = gmc_v9_0_use_invalidate_semaphore(adev, vmhub);
 
 		/* This is necessary for a HW workaround under SRIOV as well
 		 * as GFXOFF under bare metal
@@ -448,11 +467,7 @@ static void gmc_v9_0_flush_gpu_tlb(struc
 		 */
 
 		/* TODO: It needs to continue working on debugging with semaphore for GFXHUB as well. */
-		if ((vmhub == AMDGPU_MMHUB_0 ||
-		     vmhub == AMDGPU_MMHUB_1) &&
-		    (!(adev->asic_type == CHIP_RAVEN &&
-		       adev->rev_id < 0x8 &&
-		       adev->pdev->device == 0x15d8))) {
+		if (use_semaphore) {
 			for (j = 0; j < adev->usec_timeout; j++) {
 				/* a read return value of 1 means semaphore acuqire */
 				tmp = RREG32_NO_KIQ(hub->vm_inv_eng0_sem + eng);
@@ -474,11 +489,7 @@ static void gmc_v9_0_flush_gpu_tlb(struc
 		}
 
 		/* TODO: It needs to continue working on debugging with semaphore for GFXHUB as well. */
-		if ((vmhub == AMDGPU_MMHUB_0 ||
-		     vmhub == AMDGPU_MMHUB_1) &&
-		    (!(adev->asic_type == CHIP_RAVEN &&
-		       adev->rev_id < 0x8 &&
-		       adev->pdev->device == 0x15d8)))
+		if (use_semaphore)
 			/*
 			 * add semaphore release after invalidation,
 			 * write with 0 means semaphore release
@@ -497,6 +508,7 @@ static void gmc_v9_0_flush_gpu_tlb(struc
 static uint64_t gmc_v9_0_emit_flush_gpu_tlb(struct amdgpu_ring *ring,
 					    unsigned vmid, uint64_t pd_addr)
 {
+	bool use_semaphore = gmc_v9_0_use_invalidate_semaphore(ring->adev, ring->funcs->vmhub);
 	struct amdgpu_device *adev = ring->adev;
 	struct amdgpu_vmhub *hub = &adev->vmhub[ring->funcs->vmhub];
 	uint32_t req = gmc_v9_0_get_invalidate_req(vmid, 0);
@@ -510,11 +522,7 @@ static uint64_t gmc_v9_0_emit_flush_gpu_
 	 */
 
 	/* TODO: It needs to continue working on debugging with semaphore for GFXHUB as well. */
-	if ((ring->funcs->vmhub == AMDGPU_MMHUB_0 ||
-	     ring->funcs->vmhub == AMDGPU_MMHUB_1) &&
-	    (!(adev->asic_type == CHIP_RAVEN &&
-	       adev->rev_id < 0x8 &&
-	       adev->pdev->device == 0x15d8)))
+	if (use_semaphore)
 		/* a read return value of 1 means semaphore acuqire */
 		amdgpu_ring_emit_reg_wait(ring,
 					  hub->vm_inv_eng0_sem + eng, 0x1, 0x1);
@@ -530,11 +538,7 @@ static uint64_t gmc_v9_0_emit_flush_gpu_
 					    req, 1 << vmid);
 
 	/* TODO: It needs to continue working on debugging with semaphore for GFXHUB as well. */
-	if ((ring->funcs->vmhub == AMDGPU_MMHUB_0 ||
-	     ring->funcs->vmhub == AMDGPU_MMHUB_1) &&
-	    (!(adev->asic_type == CHIP_RAVEN &&
-	       adev->rev_id < 0x8 &&
-	       adev->pdev->device == 0x15d8)))
+	if (use_semaphore)
 		/*
 		 * add semaphore release after invalidation,
 		 * write with 0 means semaphore release