Skip to contentSkip to conversation

drm/amdgpu: Reorganize *_flush_gpu_tlb() for kfd to use

PATCH In review Zhao, Yong 5 participants 7 messages Oct 23, 2018 – Oct 24, 2018 3 messages not in the archive

Subsystems (3)
lore
Share & tools
lore

Zhao, Yong

author
#0 lore raw

PATCH 1/2 drm/amdgpu: Reorganize *_flush_gpu_tlb() for kfd to use

Add a flush_type parameter to that series of functions.

Change-Id I3dcd71955297c53b181f82e7078981230c642c01
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c |  4 ++--
 drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h  |  4 ++--
 drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c    |  5 +++--
 drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c    |  5 +++--
 drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c    |  4 ++--
 drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c    | 19 ++++++++++---------
 6 files changed, 22 insertions(+), 19 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c +2 -2
index 11fea28..9a212aa 100644
@@ -248,7 +248,7 @@ int amdgpu_gart_unbind(struct amdgpu_device *adev, uint64_t offset,
 	}
 	mb();
 	amdgpu_asic_flush_hdp(adev, NULL);
-	amdgpu_gmc_flush_gpu_tlb(adev, 0);
+	amdgpu_gmc_flush_gpu_tlb(adev, 0, 0);
 	return 0;
 }
 
@@ -331,7 +331,7 @@ int amdgpu_gart_bind(struct amdgpu_device *adev, uint64_t offset,
 
 	mb();
 	amdgpu_asic_flush_hdp(adev, NULL);
-	amdgpu_gmc_flush_gpu_tlb(adev, 0);
+	amdgpu_gmc_flush_gpu_tlb(adev, 0, 0);
 	return 0;
 }
 
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h +2 -2
index 6fa7ef4..4c5f18c 100644
@@ -64,7 +64,7 @@ struct amdgpu_vmhub {
 struct amdgpu_gmc_funcs {
 	/* flush the vm tlb via mmio */
 	void (*flush_gpu_tlb)(struct amdgpu_device *adev,
-			      uint32_t vmid);
+			      uint32_t vmid, uint32_t flush_type);
 	/* flush the vm tlb via ring */
 	uint64_t (*emit_flush_gpu_tlb)(struct amdgpu_ring *ring, unsigned vmid,
 				       uint64_t pd_addr);
@@ -151,7 +151,7 @@ struct amdgpu_gmc {
 	struct amdgpu_xgmi xgmi;
 };
 
-#define amdgpu_gmc_flush_gpu_tlb(adev, vmid) (adev)->gmc.gmc_funcs->flush_gpu_tlb((adev), (vmid))
+#define amdgpu_gmc_flush_gpu_tlb(adev, vmid, type) (adev)->gmc.gmc_funcs->flush_gpu_tlb((adev), (vmid), (type))
 #define amdgpu_gmc_emit_flush_gpu_tlb(r, vmid, addr) (r)->adev->gmc.gmc_funcs->emit_flush_gpu_tlb((r), (vmid), (addr))
 #define amdgpu_gmc_emit_pasid_mapping(r, vmid, pasid) (r)->adev->gmc.gmc_funcs->emit_pasid_mapping((r), (vmid), (pasid))
 #define amdgpu_gmc_set_pte_pde(adev, pt, idx, addr, flags) (adev)->gmc.gmc_funcs->set_pte_pde((adev), (pt), (idx), (addr), (flags))
drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c +3 -2
index e1c2b4e..2821d1d 100644
@@ -358,7 +358,8 @@ static int gmc_v6_0_mc_init(struct amdgpu_device *adev)
 	return 0;
 }
 
-static void gmc_v6_0_flush_gpu_tlb(struct amdgpu_device *adev, uint32_t vmid)
+static void gmc_v6_0_flush_gpu_tlb(struct amdgpu_device *adev,
+				uint32_t vmid, uint32_t flush_type)
 {
 	WREG32(mmVM_INVALIDATE_REQUEST, 1 << vmid);
 }
@@ -580,7 +581,7 @@ static int gmc_v6_0_gart_enable(struct amdgpu_device *adev)
 	else
 		gmc_v6_0_set_fault_enable_default(adev, true);
 
-	gmc_v6_0_flush_gpu_tlb(adev, 0);
+	gmc_v6_0_flush_gpu_tlb(adev, 0, 0);
 	dev_info(adev->dev, "PCIE GART of %uM enabled (table at 0x%016llX).\n",
 		 (unsigned)(adev->gmc.gart_size >> 20),
 		 (unsigned long long)table_addr);
drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c +3 -2
index 910c4ce..761dcfb 100644
@@ -430,7 +430,8 @@ static int gmc_v7_0_mc_init(struct amdgpu_device *adev)
  *
  * Flush the TLB for the requested page table (CIK).
  */
-static void gmc_v7_0_flush_gpu_tlb(struct amdgpu_device *adev, uint32_t vmid)
+static void gmc_v7_0_flush_gpu_tlb(struct amdgpu_device *adev,
+				uint32_t vmid, uint32_t flush_type)
 {
 	/* bits 0-15 are the VM contexts0-15 */
 	WREG32(mmVM_INVALIDATE_REQUEST, 1 << vmid);
@@ -698,7 +699,7 @@ static int gmc_v7_0_gart_enable(struct amdgpu_device *adev)
 		WREG32(mmCHUB_CONTROL, tmp);
 	}
 
-	gmc_v7_0_flush_gpu_tlb(adev, 0);
+	gmc_v7_0_flush_gpu_tlb(adev, 0, 0);
 	DRM_INFO("PCIE GART of %uM enabled (table at 0x%016llX).\n",
 		 (unsigned)(adev->gmc.gart_size >> 20),
 		 (unsigned long long)table_addr);
drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c +2 -2
index 1d3265c..531aaf3 100644
@@ -611,7 +611,7 @@ static int gmc_v8_0_mc_init(struct amdgpu_device *adev)
  * Flush the TLB for the requested page table (CIK).
  */
 static void gmc_v8_0_flush_gpu_tlb(struct amdgpu_device *adev,
-					uint32_t vmid)
+				uint32_t vmid, uint32_t flush_type)
 {
 	/* bits 0-15 are the VM contexts0-15 */
 	WREG32(mmVM_INVALIDATE_REQUEST, 1 << vmid);
@@ -920,7 +920,7 @@ static int gmc_v8_0_gart_enable(struct amdgpu_device *adev)
 	else
 		gmc_v8_0_set_fault_enable_default(adev, true);
 
-	gmc_v8_0_flush_gpu_tlb(adev, 0);
+	gmc_v8_0_flush_gpu_tlb(adev, 0, 0);
 	DRM_INFO("PCIE GART of %uM enabled (table at 0x%016llX).\n",
 		 (unsigned)(adev->gmc.gart_size >> 20),
 		 (unsigned long long)table_addr);
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +10 -9
index f35d7a5..79d8a84 100644
@@ -293,14 +293,15 @@ static void gmc_v9_0_set_irq_funcs(struct amdgpu_device *adev)
 	adev->gmc.vm_fault.funcs = &gmc_v9_0_irq_funcs;
 }
 
-static uint32_t gmc_v9_0_get_invalidate_req(unsigned int vmid)
+static uint32_t gmc_v9_0_get_invalidate_req(unsigned int vmid,
+					uint32_t flush_type)
 {
 	u32 req = 0;
 
 	/* invalidate using legacy mode on vmid*/
 	req = REG_SET_FIELD(req, VM_INVALIDATE_ENG0_REQ,
 			    PER_VMID_INVALIDATE_REQ, 1 << vmid);
-	req = REG_SET_FIELD(req, VM_INVALIDATE_ENG0_REQ, FLUSH_TYPE, 0);
+	req = REG_SET_FIELD(req, VM_INVALIDATE_ENG0_REQ, FLUSH_TYPE, flush_type);
 	req = REG_SET_FIELD(req, VM_INVALIDATE_ENG0_REQ, INVALIDATE_L2_PTES, 1);
 	req = REG_SET_FIELD(req, VM_INVALIDATE_ENG0_REQ, INVALIDATE_L2_PDE0, 1);
 	req = REG_SET_FIELD(req, VM_INVALIDATE_ENG0_REQ, INVALIDATE_L2_PDE1, 1);
@@ -362,24 +363,24 @@ static signed long  amdgpu_kiq_reg_write_reg_wait(struct amdgpu_device *adev,
  */
 
 /**
- * gmc_v9_0_flush_gpu_tlb - gart tlb flush callback
+ * gmc_v9_0_flush_gpu_tlb - tlb flush with certain type
  *
  * @adev: amdgpu_device pointer
  * @vmid: vm instance to flush
+ * @flush_type: the flush type
  *
- * Flush the TLB for the requested page table.
+ * Flush the TLB for the requested page table using certain type.
  */
 static void gmc_v9_0_flush_gpu_tlb(struct amdgpu_device *adev,
-					uint32_t vmid)
+				uint32_t vmid, uint32_t flush_type)
 {
-	/* Use register 17 for GART */
 	const unsigned eng = 17;
 	unsigned i, j;
 	int r;
 
 	for (i = 0; i < AMDGPU_MAX_VMHUBS; ++i) {
 		struct amdgpu_vmhub *hub = &adev->vmhub[i];
-		u32 tmp = gmc_v9_0_get_invalidate_req(vmid);
+		u32 tmp = gmc_v9_0_get_invalidate_req(vmid, flush_type);
 
 		if (adev->gfx.kiq.ring.ready &&
 		    (amdgpu_sriov_runtime(adev) || !amdgpu_sriov_vf(adev)) &&
@@ -429,7 +430,7 @@ static uint64_t gmc_v9_0_emit_flush_gpu_tlb(struct amdgpu_ring *ring,
 {
 	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);
+	uint32_t req = gmc_v9_0_get_invalidate_req(vmid, 0);
 	unsigned eng = ring->vm_inv_eng;
 
 	amdgpu_ring_emit_wreg(ring, hub->ctx0_ptb_addr_lo32 + (2 * vmid),
@@ -1122,7 +1123,7 @@ static int gmc_v9_0_gart_enable(struct amdgpu_device *adev)
 
 	gfxhub_v1_0_set_fault_enable_default(adev, value);
 	mmhub_v1_0_set_fault_enable_default(adev, value);
-	gmc_v9_0_flush_gpu_tlb(adev, 0);
+	gmc_v9_0_flush_gpu_tlb(adev, 0, 0);
 
 	DRM_INFO("PCIE GART of %uM enabled (table at 0x%016llX).\n",
 		 (unsigned)(adev->gmc.gart_size >> 20),
Signature · 6 lines
2.7.4

_______________________________________________
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): 1540318546-1468-1-git-send-email-Yong.Zhao-5C7GfCeVMHo@public.gmane.org

author
#2 lore raw

PATCH 2/2 drm/amdkfd: Use functions from amdgpu to invalidate vmid in kfd

As part of the change, we stop taking the srbm lock, and start to use the same invalidation engine and software lock.

Change-Id I306305e43d4b4032316909b3f4e3f9f5ca4520ae
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v9.c | 37 +----------------------
 1 file changed, 1 insertion(+), 36 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v9.c +1 -36
index 3ade5d5..f4b4706 100644
@@ -48,17 +48,6 @@
 #include "soc15d.h"
 #include "gmc_v9_0.h"
 
-/* HACK: MMHUB and GC both have VM-related register with the same
- * names but different offsets. Define the MMHUB register we need here
- * with a prefix. A proper solution would be to move the functions
- * programming these registers into gfx_v9_0.c and mmhub_v1_0.c
- * respectively.
- */
-#define mmMMHUB_VM_INVALIDATE_ENG16_REQ				0x06f3
-#define mmMMHUB_VM_INVALIDATE_ENG16_REQ_BASE_IDX		0
-
-#define mmMMHUB_VM_INVALIDATE_ENG16_ACK				0x0705
-#define mmMMHUB_VM_INVALIDATE_ENG16_ACK_BASE_IDX		0
 
 #define V9_PIPE_PER_MEC		(4)
 #define V9_QUEUES_PER_PIPE_MEC	(8)
@@ -742,15 +731,6 @@ static uint16_t get_atc_vmid_pasid_mapping_pasid(struct kgd_dev *kgd,
 static void write_vmid_invalidate_request(struct kgd_dev *kgd, uint8_t vmid)
 {
 	struct amdgpu_device *adev = (struct amdgpu_device *) kgd;
-	uint32_t req = (1 << vmid) |
-		(0 << VM_INVALIDATE_ENG16_REQ__FLUSH_TYPE__SHIFT) | /* legacy */
-		VM_INVALIDATE_ENG16_REQ__INVALIDATE_L2_PTES_MASK |
-		VM_INVALIDATE_ENG16_REQ__INVALIDATE_L2_PDE0_MASK |
-		VM_INVALIDATE_ENG16_REQ__INVALIDATE_L2_PDE1_MASK |
-		VM_INVALIDATE_ENG16_REQ__INVALIDATE_L2_PDE2_MASK |
-		VM_INVALIDATE_ENG16_REQ__INVALIDATE_L1_PTES_MASK;
-
-	mutex_lock(&adev->srbm_mutex);
 
 	/* Use legacy mode tlb invalidation.
 	 *
@@ -767,22 +747,7 @@ static void write_vmid_invalidate_request(struct kgd_dev *kgd, uint8_t vmid)
 	 * TODO 2: support range-based invalidation, requires kfg2kgd
 	 * interface change
 	 */
-	WREG32(SOC15_REG_OFFSET(GC, 0, mmVM_INVALIDATE_ENG16_REQ), req);
-
-	WREG32(SOC15_REG_OFFSET(MMHUB, 0, mmMMHUB_VM_INVALIDATE_ENG16_REQ),
-				req);
-
-	while (!(RREG32(SOC15_REG_OFFSET(GC, 0, mmVM_INVALIDATE_ENG16_ACK)) &
-					(1 << vmid)))
-		cpu_relax();
-
-	while (!(RREG32(SOC15_REG_OFFSET(MMHUB, 0,
-					mmMMHUB_VM_INVALIDATE_ENG16_ACK)) &
-					(1 << vmid)))
-		cpu_relax();
-
-	mutex_unlock(&adev->srbm_mutex);
-
+	amdgpu_gmc_flush_gpu_tlb(adev, vmid, 0);
 }
 
 static int invalidate_tlbs_with_kiq(struct amdgpu_device *adev, uint16_t pasid)
Signature · 6 lines
2.7.4

_______________________________________________
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): 1540318546-1468-2-git-send-email-Yong.Zhao-5C7GfCeVMHo@public.gmane.org

Reviewed-by
#4 lore raw

Re: [PATCH 2/2] drm/amdkfd: Use functions from amdgpu to invalidate vmid in kfd

Series is:

________________________________
From: Zhao, Yong
Sent: Tuesday, October 23, 2018 2:15:59 PM
To: brahma_sw_dev; [email protected]
Cc: Zhao, Yong
Subject: [PATCH 2/2] drm/amdkfd: Use functions from amdgpu to invalidate vmid in kfd

As part of the change, we stop taking the srbm lock, and start to use the same invalidation engine and software lock.

Change-Id I306305e43d4b4032316909b3f4e3f9f5ca4520ae
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v9.c | 37 +----------------------
 1 file changed, 1 insertion(+), 36 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v9.c +1 -36
index 3ade5d5..f4b4706 100644
@@ -48,17 +48,6 @@
 #include "soc15d.h"
 #include "gmc_v9_0.h"
 
-/* HACK: MMHUB and GC both have VM-related register with the same
- * names but different offsets. Define the MMHUB register we need here
- * with a prefix. A proper solution would be to move the functions
- * programming these registers into gfx_v9_0.c and mmhub_v1_0.c
- * respectively.
- */
-#define mmMMHUB_VM_INVALIDATE_ENG16_REQ                                0x06f3
-#define mmMMHUB_VM_INVALIDATE_ENG16_REQ_BASE_IDX               0
-
-#define mmMMHUB_VM_INVALIDATE_ENG16_ACK                                0x0705
-#define mmMMHUB_VM_INVALIDATE_ENG16_ACK_BASE_IDX               0
 
 #define V9_PIPE_PER_MEC         (4)
 #define V9_QUEUES_PER_PIPE_MEC  (8)
@@ -742,15 +731,6 @@ static uint16_t get_atc_vmid_pasid_mapping_pasid(struct kgd_dev *kgd,
 static void write_vmid_invalidate_request(struct kgd_dev *kgd, uint8_t vmid)
 {
         struct amdgpu_device *adev = (struct amdgpu_device *) kgd;
-       uint32_t req = (1 << vmid) |
-               (0 << VM_INVALIDATE_ENG16_REQ__FLUSH_TYPE__SHIFT) | /* legacy */
-               VM_INVALIDATE_ENG16_REQ__INVALIDATE_L2_PTES_MASK |
-               VM_INVALIDATE_ENG16_REQ__INVALIDATE_L2_PDE0_MASK |
-               VM_INVALIDATE_ENG16_REQ__INVALIDATE_L2_PDE1_MASK |
-               VM_INVALIDATE_ENG16_REQ__INVALIDATE_L2_PDE2_MASK |
-               VM_INVALIDATE_ENG16_REQ__INVALIDATE_L1_PTES_MASK;
-
-       mutex_lock(&adev->srbm_mutex);
 
         /* Use legacy mode tlb invalidation.
          *
@@ -767,22 +747,7 @@ static void write_vmid_invalidate_request(struct kgd_dev *kgd, uint8_t vmid)
          * TODO 2: support range-based invalidation, requires kfg2kgd
          * interface change
          */
-       WREG32(SOC15_REG_OFFSET(GC, 0, mmVM_INVALIDATE_ENG16_REQ), req);
-
-       WREG32(SOC15_REG_OFFSET(MMHUB, 0, mmMMHUB_VM_INVALIDATE_ENG16_REQ),
-                               req);
-
-       while (!(RREG32(SOC15_REG_OFFSET(GC, 0, mmVM_INVALIDATE_ENG16_ACK)) &
-                                       (1 << vmid)))
-               cpu_relax();
-
-       while (!(RREG32(SOC15_REG_OFFSET(MMHUB, 0,
-                                       mmMMHUB_VM_INVALIDATE_ENG16_ACK)) &
-                                       (1 << vmid)))
-               cpu_relax();
-
-       mutex_unlock(&adev->srbm_mutex);
-
+       amdgpu_gmc_flush_gpu_tlb(adev, vmid, 0);
 }
 
 static int invalidate_tlbs_with_kiq(struct amdgpu_device *adev, uint16_t pasid)

--
2.7.4

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

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

It occurred to me that the flush_type is a hardware-specific value, but you're using it in a hardware-abstracted interface. If the meaning of the flush type values changes in future HW-generations, we'll need to define an abstract enum that gets translated to the respective HW values in the HW-specific code.

Anyway, this works for now.

One more cosmetic comment inline ...

Other than that the series is Reviewed-by: Felix Kuehling <[email protected]>

Regards,
  Felix

Quoted 130 lines · Yong

Add a flush_type parameter to that series of functions.

Change-Id I3dcd71955297c53b181f82e7078981230c642c01
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c |  4 ++--
 drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h  |  4 ++--
 drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c    |  5 +++--
 drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c    |  5 +++--
 drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c    |  4 ++--
 drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c    | 19 ++++++++++---------
 6 files changed, 22 insertions(+), 19 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c +2 -2
index 11fea28..9a212aa 100644
@@ -248,7 +248,7 @@ int amdgpu_gart_unbind(struct amdgpu_device *adev, uint64_t offset,
 	}
 	mb();
 	amdgpu_asic_flush_hdp(adev, NULL);
-	amdgpu_gmc_flush_gpu_tlb(adev, 0);
+	amdgpu_gmc_flush_gpu_tlb(adev, 0, 0);
 	return 0;
 }
 
@@ -331,7 +331,7 @@ int amdgpu_gart_bind(struct amdgpu_device *adev, uint64_t offset,
 
 	mb();
 	amdgpu_asic_flush_hdp(adev, NULL);
-	amdgpu_gmc_flush_gpu_tlb(adev, 0);
+	amdgpu_gmc_flush_gpu_tlb(adev, 0, 0);
 	return 0;
 }
 
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h +2 -2
index 6fa7ef4..4c5f18c 100644
@@ -64,7 +64,7 @@ struct amdgpu_vmhub {
 struct amdgpu_gmc_funcs {
 	/* flush the vm tlb via mmio */
 	void (*flush_gpu_tlb)(struct amdgpu_device *adev,
-			      uint32_t vmid);
+			      uint32_t vmid, uint32_t flush_type);
 	/* flush the vm tlb via ring */
 	uint64_t (*emit_flush_gpu_tlb)(struct amdgpu_ring *ring, unsigned vmid,
 				       uint64_t pd_addr);
@@ -151,7 +151,7 @@ struct amdgpu_gmc {
 	struct amdgpu_xgmi xgmi;
 };
 
-#define amdgpu_gmc_flush_gpu_tlb(adev, vmid) (adev)->gmc.gmc_funcs->flush_gpu_tlb((adev), (vmid))
+#define amdgpu_gmc_flush_gpu_tlb(adev, vmid, type) (adev)->gmc.gmc_funcs->flush_gpu_tlb((adev), (vmid), (type))
 #define amdgpu_gmc_emit_flush_gpu_tlb(r, vmid, addr) (r)->adev->gmc.gmc_funcs->emit_flush_gpu_tlb((r), (vmid), (addr))
 #define amdgpu_gmc_emit_pasid_mapping(r, vmid, pasid) (r)->adev->gmc.gmc_funcs->emit_pasid_mapping((r), (vmid), (pasid))
 #define amdgpu_gmc_set_pte_pde(adev, pt, idx, addr, flags) (adev)->gmc.gmc_funcs->set_pte_pde((adev), (pt), (idx), (addr), (flags))
drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c +3 -2
index e1c2b4e..2821d1d 100644
@@ -358,7 +358,8 @@ static int gmc_v6_0_mc_init(struct amdgpu_device *adev)
 	return 0;
 }
 
-static void gmc_v6_0_flush_gpu_tlb(struct amdgpu_device *adev, uint32_t vmid)
+static void gmc_v6_0_flush_gpu_tlb(struct amdgpu_device *adev,
+				uint32_t vmid, uint32_t flush_type)
 {
 	WREG32(mmVM_INVALIDATE_REQUEST, 1 << vmid);
 }
@@ -580,7 +581,7 @@ static int gmc_v6_0_gart_enable(struct amdgpu_device *adev)
 	else
 		gmc_v6_0_set_fault_enable_default(adev, true);
 
-	gmc_v6_0_flush_gpu_tlb(adev, 0);
+	gmc_v6_0_flush_gpu_tlb(adev, 0, 0);
 	dev_info(adev->dev, "PCIE GART of %uM enabled (table at 0x%016llX).\n",
 		 (unsigned)(adev->gmc.gart_size >> 20),
 		 (unsigned long long)table_addr);
drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c +3 -2
index 910c4ce..761dcfb 100644
@@ -430,7 +430,8 @@ static int gmc_v7_0_mc_init(struct amdgpu_device *adev)
  *
  * Flush the TLB for the requested page table (CIK).
  */
-static void gmc_v7_0_flush_gpu_tlb(struct amdgpu_device *adev, uint32_t vmid)
+static void gmc_v7_0_flush_gpu_tlb(struct amdgpu_device *adev,
+				uint32_t vmid, uint32_t flush_type)
 {
 	/* bits 0-15 are the VM contexts0-15 */
 	WREG32(mmVM_INVALIDATE_REQUEST, 1 << vmid);
@@ -698,7 +699,7 @@ static int gmc_v7_0_gart_enable(struct amdgpu_device *adev)
 		WREG32(mmCHUB_CONTROL, tmp);
 	}
 
-	gmc_v7_0_flush_gpu_tlb(adev, 0);
+	gmc_v7_0_flush_gpu_tlb(adev, 0, 0);
 	DRM_INFO("PCIE GART of %uM enabled (table at 0x%016llX).\n",
 		 (unsigned)(adev->gmc.gart_size >> 20),
 		 (unsigned long long)table_addr);
drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c +2 -2
index 1d3265c..531aaf3 100644
@@ -611,7 +611,7 @@ static int gmc_v8_0_mc_init(struct amdgpu_device *adev)
  * Flush the TLB for the requested page table (CIK).
  */
 static void gmc_v8_0_flush_gpu_tlb(struct amdgpu_device *adev,
-					uint32_t vmid)
+				uint32_t vmid, uint32_t flush_type)
 {
 	/* bits 0-15 are the VM contexts0-15 */
 	WREG32(mmVM_INVALIDATE_REQUEST, 1 << vmid);
@@ -920,7 +920,7 @@ static int gmc_v8_0_gart_enable(struct amdgpu_device *adev)
 	else
 		gmc_v8_0_set_fault_enable_default(adev, true);
 
-	gmc_v8_0_flush_gpu_tlb(adev, 0);
+	gmc_v8_0_flush_gpu_tlb(adev, 0, 0);
 	DRM_INFO("PCIE GART of %uM enabled (table at 0x%016llX).\n",
 		 (unsigned)(adev->gmc.gart_size >> 20),
 		 (unsigned long long)table_addr);
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +0 -0
index f35d7a5..79d8a84 100644

drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c static void gmc_v9_0_set_irq_funcs(struct amdgpu_device *adev) · line 301

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +2 -1
@@ -293,14 +293,15 @@ static void gmc_v9_0_set_irq_funcs(struct amdgpu_device *adev)
 	adev->gmc.vm_fault.funcs = &gmc_v9_0_irq_funcs;
 }
 
-static uint32_t gmc_v9_0_get_invalidate_req(unsigned int vmid)
+static uint32_t gmc_v9_0_get_invalidate_req(unsigned int vmid,
+					uint32_t flush_type)
 {
 	u32 req = 0;
 
 	/* invalidate using legacy mode on vmid*/

This comment is no longer accurate.

Quoted 47 lines
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +7 -7
 	req = REG_SET_FIELD(req, VM_INVALIDATE_ENG0_REQ,
 			    PER_VMID_INVALIDATE_REQ, 1 << vmid);
-	req = REG_SET_FIELD(req, VM_INVALIDATE_ENG0_REQ, FLUSH_TYPE, 0);
+	req = REG_SET_FIELD(req, VM_INVALIDATE_ENG0_REQ, FLUSH_TYPE, flush_type);
 	req = REG_SET_FIELD(req, VM_INVALIDATE_ENG0_REQ, INVALIDATE_L2_PTES, 1);
 	req = REG_SET_FIELD(req, VM_INVALIDATE_ENG0_REQ, INVALIDATE_L2_PDE0, 1);
 	req = REG_SET_FIELD(req, VM_INVALIDATE_ENG0_REQ, INVALIDATE_L2_PDE1, 1);
@@ -362,24 +363,24 @@ static signed long  amdgpu_kiq_reg_write_reg_wait(struct amdgpu_device *adev,
  */
 
 /**
- * gmc_v9_0_flush_gpu_tlb - gart tlb flush callback
+ * gmc_v9_0_flush_gpu_tlb - tlb flush with certain type
  *
  * @adev: amdgpu_device pointer
  * @vmid: vm instance to flush
+ * @flush_type: the flush type
  *
- * Flush the TLB for the requested page table.
+ * Flush the TLB for the requested page table using certain type.
  */
 static void gmc_v9_0_flush_gpu_tlb(struct amdgpu_device *adev,
-					uint32_t vmid)
+				uint32_t vmid, uint32_t flush_type)
 {
-	/* Use register 17 for GART */
 	const unsigned eng = 17;
 	unsigned i, j;
 	int r;
 
 	for (i = 0; i < AMDGPU_MAX_VMHUBS; ++i) {
 		struct amdgpu_vmhub *hub = &adev->vmhub[i];
-		u32 tmp = gmc_v9_0_get_invalidate_req(vmid);
+		u32 tmp = gmc_v9_0_get_invalidate_req(vmid, flush_type);
 
 		if (adev->gfx.kiq.ring.ready &&
 		    (amdgpu_sriov_runtime(adev) || !amdgpu_sriov_vf(adev)) &&
@@ -429,7 +430,7 @@ static uint64_t gmc_v9_0_emit_flush_gpu_tlb(struct amdgpu_ring *ring,
 {
 	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);
+	uint32_t req = gmc_v9_0_get_invalidate_req(vmid, 0);
 	unsigned eng = ring->vm_inv_eng;
 
 	amdgpu_ring_emit_wreg(ring, hub->ctx0_ptb_addr_lo32 + (2 * vmid),

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

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +1 -1
@@ -1122,7 +1123,7 @@ static int gmc_v9_0_gart_enable(struct amdgpu_device *adev)
 
 	gfxhub_v1_0_set_fault_enable_default(adev, value);
 	mmhub_v1_0_set_fault_enable_default(adev, value);
-	gmc_v9_0_flush_gpu_tlb(adev, 0);
+	gmc_v9_0_flush_gpu_tlb(adev, 0, 0);
 
 	DRM_INFO("PCIE GART of %uM enabled (table at 0x%016llX).\n",
 		 (unsigned)(adev->gmc.gart_size >> 20),

_______________________________________________
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): 367bc700-8dae-1877-5b77-b28f0ba2e118-5C7GfCeVMHo@public.gmane.org

#7 lore raw

I'm working on a vm fault issue that this tlb flush type can have effect on this , do we plan to make a kernel parameter for this ?

Regards

shaoyun.liu

Quoted 208 lines · Felix

It occurred to me that the flush_type is a hardware-specific value, but you're using it in a hardware-abstracted interface. If the meaning of the flush type values changes in future HW-generations, we'll need to define an abstract enum that gets translated to the respective HW values in the HW-specific code.

Anyway, this works for now.

One more cosmetic comment inline ...

Other than that the series is Reviewed-by: Felix Kuehling <[email protected]>

Regards,
  Felix

Quoted 130 lines · Yong

Add a flush_type parameter to that series of functions.

Change-Id I3dcd71955297c53b181f82e7078981230c642c01
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c |  4 ++--
  drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h  |  4 ++--
  drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c    |  5 +++--
  drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c    |  5 +++--
  drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c    |  4 ++--
  drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c    | 19 ++++++++++---------
  6 files changed, 22 insertions(+), 19 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c +2 -2
index 11fea28..9a212aa 100644
@@ -248,7 +248,7 @@ int amdgpu_gart_unbind(struct amdgpu_device *adev, uint64_t offset,
  	}
  	mb();
  	amdgpu_asic_flush_hdp(adev, NULL);
-	amdgpu_gmc_flush_gpu_tlb(adev, 0);
+	amdgpu_gmc_flush_gpu_tlb(adev, 0, 0);
  	return 0;
  }
 
@@ -331,7 +331,7 @@ int amdgpu_gart_bind(struct amdgpu_device *adev, uint64_t offset,
 
  	mb();
  	amdgpu_asic_flush_hdp(adev, NULL);
-	amdgpu_gmc_flush_gpu_tlb(adev, 0);
+	amdgpu_gmc_flush_gpu_tlb(adev, 0, 0);
  	return 0;
  }
 
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h +2 -2
index 6fa7ef4..4c5f18c 100644
@@ -64,7 +64,7 @@ struct amdgpu_vmhub {
  struct amdgpu_gmc_funcs {
  	/* flush the vm tlb via mmio */
  	void (*flush_gpu_tlb)(struct amdgpu_device *adev,
-			      uint32_t vmid);
+			      uint32_t vmid, uint32_t flush_type);
  	/* flush the vm tlb via ring */
  	uint64_t (*emit_flush_gpu_tlb)(struct amdgpu_ring *ring, unsigned vmid,
  				       uint64_t pd_addr);
@@ -151,7 +151,7 @@ struct amdgpu_gmc {
  	struct amdgpu_xgmi xgmi;
  };
 
-#define amdgpu_gmc_flush_gpu_tlb(adev, vmid) (adev)->gmc.gmc_funcs->flush_gpu_tlb((adev), (vmid))
+#define amdgpu_gmc_flush_gpu_tlb(adev, vmid, type) (adev)->gmc.gmc_funcs->flush_gpu_tlb((adev), (vmid), (type))
  #define amdgpu_gmc_emit_flush_gpu_tlb(r, vmid, addr) (r)->adev->gmc.gmc_funcs->emit_flush_gpu_tlb((r), (vmid), (addr))
  #define amdgpu_gmc_emit_pasid_mapping(r, vmid, pasid) (r)->adev->gmc.gmc_funcs->emit_pasid_mapping((r), (vmid), (pasid))
  #define amdgpu_gmc_set_pte_pde(adev, pt, idx, addr, flags) (adev)->gmc.gmc_funcs->set_pte_pde((adev), (pt), (idx), (addr), (flags))
drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c +3 -2
index e1c2b4e..2821d1d 100644
@@ -358,7 +358,8 @@ static int gmc_v6_0_mc_init(struct amdgpu_device *adev)
  	return 0;
  }
 
-static void gmc_v6_0_flush_gpu_tlb(struct amdgpu_device *adev, uint32_t vmid)
+static void gmc_v6_0_flush_gpu_tlb(struct amdgpu_device *adev,
+				uint32_t vmid, uint32_t flush_type)
  {
  	WREG32(mmVM_INVALIDATE_REQUEST, 1 << vmid);
  }
@@ -580,7 +581,7 @@ static int gmc_v6_0_gart_enable(struct amdgpu_device *adev)
  	else
  		gmc_v6_0_set_fault_enable_default(adev, true);
 
-	gmc_v6_0_flush_gpu_tlb(adev, 0);
+	gmc_v6_0_flush_gpu_tlb(adev, 0, 0);
  	dev_info(adev->dev, "PCIE GART of %uM enabled (table at 0x%016llX).\n",
  		 (unsigned)(adev->gmc.gart_size >> 20),
  		 (unsigned long long)table_addr);
drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c +3 -2
index 910c4ce..761dcfb 100644
@@ -430,7 +430,8 @@ static int gmc_v7_0_mc_init(struct amdgpu_device *adev)
   *
   * Flush the TLB for the requested page table (CIK).
   */
-static void gmc_v7_0_flush_gpu_tlb(struct amdgpu_device *adev, uint32_t vmid)
+static void gmc_v7_0_flush_gpu_tlb(struct amdgpu_device *adev,
+				uint32_t vmid, uint32_t flush_type)
  {
  	/* bits 0-15 are the VM contexts0-15 */
  	WREG32(mmVM_INVALIDATE_REQUEST, 1 << vmid);
@@ -698,7 +699,7 @@ static int gmc_v7_0_gart_enable(struct amdgpu_device *adev)
  		WREG32(mmCHUB_CONTROL, tmp);
  	}
 
-	gmc_v7_0_flush_gpu_tlb(adev, 0);
+	gmc_v7_0_flush_gpu_tlb(adev, 0, 0);
  	DRM_INFO("PCIE GART of %uM enabled (table at 0x%016llX).\n",
  		 (unsigned)(adev->gmc.gart_size >> 20),
  		 (unsigned long long)table_addr);
drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c +2 -2
index 1d3265c..531aaf3 100644
@@ -611,7 +611,7 @@ static int gmc_v8_0_mc_init(struct amdgpu_device *adev)
   * Flush the TLB for the requested page table (CIK).
   */
  static void gmc_v8_0_flush_gpu_tlb(struct amdgpu_device *adev,
-					uint32_t vmid)
+				uint32_t vmid, uint32_t flush_type)
  {
  	/* bits 0-15 are the VM contexts0-15 */
  	WREG32(mmVM_INVALIDATE_REQUEST, 1 << vmid);
@@ -920,7 +920,7 @@ static int gmc_v8_0_gart_enable(struct amdgpu_device *adev)
  	else
  		gmc_v8_0_set_fault_enable_default(adev, true);
 
-	gmc_v8_0_flush_gpu_tlb(adev, 0);
+	gmc_v8_0_flush_gpu_tlb(adev, 0, 0);
  	DRM_INFO("PCIE GART of %uM enabled (table at 0x%016llX).\n",
  		 (unsigned)(adev->gmc.gart_size >> 20),
  		 (unsigned long long)table_addr);
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +0 -0
index f35d7a5..79d8a84 100644

drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c static void gmc_v9_0_set_irq_funcs(struct amdgpu_device *adev) · line 301

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +2 -1
@@ -293,14 +293,15 @@ static void gmc_v9_0_set_irq_funcs(struct amdgpu_device *adev)
  	adev->gmc.vm_fault.funcs = &gmc_v9_0_irq_funcs;
  }
 
-static uint32_t gmc_v9_0_get_invalidate_req(unsigned int vmid)
+static uint32_t gmc_v9_0_get_invalidate_req(unsigned int vmid,
+					uint32_t flush_type)
  {
  	u32 req = 0;
 
  	/* invalidate using legacy mode on vmid*/

This comment is no longer accurate.

Quoted 48 lines
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +7 -7
  	req = REG_SET_FIELD(req, VM_INVALIDATE_ENG0_REQ,
  			    PER_VMID_INVALIDATE_REQ, 1 << vmid);
-	req = REG_SET_FIELD(req, VM_INVALIDATE_ENG0_REQ, FLUSH_TYPE, 0);
+	req = REG_SET_FIELD(req, VM_INVALIDATE_ENG0_REQ, FLUSH_TYPE, flush_type);
  	req = REG_SET_FIELD(req, VM_INVALIDATE_ENG0_REQ, INVALIDATE_L2_PTES, 1);
  	req = REG_SET_FIELD(req, VM_INVALIDATE_ENG0_REQ, INVALIDATE_L2_PDE0, 1);
  	req = REG_SET_FIELD(req, VM_INVALIDATE_ENG0_REQ, INVALIDATE_L2_PDE1, 1);
@@ -362,24 +363,24 @@ static signed long  amdgpu_kiq_reg_write_reg_wait(struct amdgpu_device *adev,
   */
 
  /**
- * gmc_v9_0_flush_gpu_tlb - gart tlb flush callback
+ * gmc_v9_0_flush_gpu_tlb - tlb flush with certain type
   *
   * @adev: amdgpu_device pointer
   * @vmid: vm instance to flush
+ * @flush_type: the flush type
   *
- * Flush the TLB for the requested page table.
+ * Flush the TLB for the requested page table using certain type.
   */
  static void gmc_v9_0_flush_gpu_tlb(struct amdgpu_device *adev,
-					uint32_t vmid)
+				uint32_t vmid, uint32_t flush_type)
  {
-	/* Use register 17 for GART */
  	const unsigned eng = 17;
  	unsigned i, j;
  	int r;
 
  	for (i = 0; i < AMDGPU_MAX_VMHUBS; ++i) {
  		struct amdgpu_vmhub *hub = &adev->vmhub[i];
-		u32 tmp = gmc_v9_0_get_invalidate_req(vmid);
+		u32 tmp = gmc_v9_0_get_invalidate_req(vmid, flush_type);
 
  		if (adev->gfx.kiq.ring.ready &&
  		    (amdgpu_sriov_runtime(adev) || !amdgpu_sriov_vf(adev)) &&
@@ -429,7 +430,7 @@ static uint64_t gmc_v9_0_emit_flush_gpu_tlb(struct amdgpu_ring *ring,
  {
  	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);
+	uint32_t req = gmc_v9_0_get_invalidate_req(vmid, 0);
  	unsigned eng = ring->vm_inv_eng;
 
  	amdgpu_ring_emit_wreg(ring, hub->ctx0_ptb_addr_lo32 + (2 * vmid),
@@ -1122,7 +1123,7 @@ static int gmc_v9_0_gart_enable(struct amdgpu_device *adev)
 
Quoted 7 lines

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

Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +1 -1
  	gfxhub_v1_0_set_fault_enable_default(adev, value);
  	mmhub_v1_0_set_fault_enable_default(adev, value);
-	gmc_v9_0_flush_gpu_tlb(adev, 0);
+	gmc_v9_0_flush_gpu_tlb(adev, 0, 0);
 
  	DRM_INFO("PCIE GART of %uM enabled (table at 0x%016llX).\n",
  		 (unsigned)(adev->gmc.gart_size >> 20),

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

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

Revised accordingly, and pushed. Thanks!

Yong

________________________________
From: Kuehling, Felix
Sent: Tuesday, October 23, 2018 4:37:45 PM
To: Zhao, Yong; brahma_sw_dev; [email protected]
Subject: Re: [PATCH 1/2] drm/amdgpu: Reorganize *_flush_gpu_tlb() for kfd to use

It occurred to me that the flush_type is a hardware-specific value, but you're using it in a hardware-abstracted interface. If the meaning of the flush type values changes in future HW-generations, we'll need to define an abstract enum that gets translated to the respective HW values in the HW-specific code.

Anyway, this works for now.

One more cosmetic comment inline ...

Other than that the series is Reviewed-by: Felix Kuehling <[email protected]>

Regards,
Felix

Quoted 130 lines · Yong

Add a flush_type parameter to that series of functions.

Change-Id I3dcd71955297c53b181f82e7078981230c642c01
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c |  4 ++--
 drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h  |  4 ++--
 drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c    |  5 +++--
 drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c    |  5 +++--
 drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c    |  4 ++--
 drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c    | 19 ++++++++++---------
 6 files changed, 22 insertions(+), 19 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c +2 -2
index 11fea28..9a212aa 100644
@@ -248,7 +248,7 @@ int amdgpu_gart_unbind(struct amdgpu_device *adev, uint64_t offset,
       }
       mb();
       amdgpu_asic_flush_hdp(adev, NULL);
-     amdgpu_gmc_flush_gpu_tlb(adev, 0);
+     amdgpu_gmc_flush_gpu_tlb(adev, 0, 0);
       return 0;
 }
 
@@ -331,7 +331,7 @@ int amdgpu_gart_bind(struct amdgpu_device *adev, uint64_t offset,
 
       mb();
       amdgpu_asic_flush_hdp(adev, NULL);
-     amdgpu_gmc_flush_gpu_tlb(adev, 0);
+     amdgpu_gmc_flush_gpu_tlb(adev, 0, 0);
       return 0;
 }
 
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h +2 -2
index 6fa7ef4..4c5f18c 100644
@@ -64,7 +64,7 @@ struct amdgpu_vmhub {
 struct amdgpu_gmc_funcs {
       /* flush the vm tlb via mmio */
       void (*flush_gpu_tlb)(struct amdgpu_device *adev,
-                           uint32_t vmid);
+                           uint32_t vmid, uint32_t flush_type);
       /* flush the vm tlb via ring */
       uint64_t (*emit_flush_gpu_tlb)(struct amdgpu_ring *ring, unsigned vmid,
                                      uint64_t pd_addr);
@@ -151,7 +151,7 @@ struct amdgpu_gmc {
       struct amdgpu_xgmi xgmi;
 };
 
-#define amdgpu_gmc_flush_gpu_tlb(adev, vmid) (adev)->gmc.gmc_funcs->flush_gpu_tlb((adev), (vmid))
+#define amdgpu_gmc_flush_gpu_tlb(adev, vmid, type) (adev)->gmc.gmc_funcs->flush_gpu_tlb((adev), (vmid), (type))
 #define amdgpu_gmc_emit_flush_gpu_tlb(r, vmid, addr) (r)->adev->gmc.gmc_funcs->emit_flush_gpu_tlb((r), (vmid), (addr))
 #define amdgpu_gmc_emit_pasid_mapping(r, vmid, pasid) (r)->adev->gmc.gmc_funcs->emit_pasid_mapping((r), (vmid), (pasid))
 #define amdgpu_gmc_set_pte_pde(adev, pt, idx, addr, flags) (adev)->gmc.gmc_funcs->set_pte_pde((adev), (pt), (idx), (addr), (flags))
drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c +3 -2
index e1c2b4e..2821d1d 100644
@@ -358,7 +358,8 @@ static int gmc_v6_0_mc_init(struct amdgpu_device *adev)
       return 0;
 }
 
-static void gmc_v6_0_flush_gpu_tlb(struct amdgpu_device *adev, uint32_t vmid)
+static void gmc_v6_0_flush_gpu_tlb(struct amdgpu_device *adev,
+                             uint32_t vmid, uint32_t flush_type)
 {
       WREG32(mmVM_INVALIDATE_REQUEST, 1 << vmid);
 }
@@ -580,7 +581,7 @@ static int gmc_v6_0_gart_enable(struct amdgpu_device *adev)
       else
               gmc_v6_0_set_fault_enable_default(adev, true);
 
-     gmc_v6_0_flush_gpu_tlb(adev, 0);
+     gmc_v6_0_flush_gpu_tlb(adev, 0, 0);
       dev_info(adev->dev, "PCIE GART of %uM enabled (table at 0x%016llX).\n",
                (unsigned)(adev->gmc.gart_size >> 20),
                (unsigned long long)table_addr);
drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c +3 -2
index 910c4ce..761dcfb 100644
@@ -430,7 +430,8 @@ static int gmc_v7_0_mc_init(struct amdgpu_device *adev)
  *
  * Flush the TLB for the requested page table (CIK).
  */
-static void gmc_v7_0_flush_gpu_tlb(struct amdgpu_device *adev, uint32_t vmid)
+static void gmc_v7_0_flush_gpu_tlb(struct amdgpu_device *adev,
+                             uint32_t vmid, uint32_t flush_type)
 {
       /* bits 0-15 are the VM contexts0-15 */
       WREG32(mmVM_INVALIDATE_REQUEST, 1 << vmid);
@@ -698,7 +699,7 @@ static int gmc_v7_0_gart_enable(struct amdgpu_device *adev)
               WREG32(mmCHUB_CONTROL, tmp);
       }
 
-     gmc_v7_0_flush_gpu_tlb(adev, 0);
+     gmc_v7_0_flush_gpu_tlb(adev, 0, 0);
       DRM_INFO("PCIE GART of %uM enabled (table at 0x%016llX).\n",
                (unsigned)(adev->gmc.gart_size >> 20),
                (unsigned long long)table_addr);
drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c +2 -2
index 1d3265c..531aaf3 100644
@@ -611,7 +611,7 @@ static int gmc_v8_0_mc_init(struct amdgpu_device *adev)
  * Flush the TLB for the requested page table (CIK).
  */
 static void gmc_v8_0_flush_gpu_tlb(struct amdgpu_device *adev,
-                                     uint32_t vmid)
+                             uint32_t vmid, uint32_t flush_type)
 {
       /* bits 0-15 are the VM contexts0-15 */
       WREG32(mmVM_INVALIDATE_REQUEST, 1 << vmid);
@@ -920,7 +920,7 @@ static int gmc_v8_0_gart_enable(struct amdgpu_device *adev)
       else
               gmc_v8_0_set_fault_enable_default(adev, true);
 
-     gmc_v8_0_flush_gpu_tlb(adev, 0);
+     gmc_v8_0_flush_gpu_tlb(adev, 0, 0);
       DRM_INFO("PCIE GART of %uM enabled (table at 0x%016llX).\n",
                (unsigned)(adev->gmc.gart_size >> 20),
                (unsigned long long)table_addr);
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +0 -0
index f35d7a5..79d8a84 100644

drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c static void gmc_v9_0_set_irq_funcs(struct amdgpu_device *adev) · line 301

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +2 -1
@@ -293,14 +293,15 @@ static void gmc_v9_0_set_irq_funcs(struct amdgpu_device *adev)
       adev->gmc.vm_fault.funcs = &gmc_v9_0_irq_funcs;
 }
 
-static uint32_t gmc_v9_0_get_invalidate_req(unsigned int vmid)
+static uint32_t gmc_v9_0_get_invalidate_req(unsigned int vmid,
+                                     uint32_t flush_type)
 {
       u32 req = 0;
 
       /* invalidate using legacy mode on vmid*/

This comment is no longer accurate.

Quoted 47 lines
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +7 -7
       req = REG_SET_FIELD(req, VM_INVALIDATE_ENG0_REQ,
                           PER_VMID_INVALIDATE_REQ, 1 << vmid);
-     req = REG_SET_FIELD(req, VM_INVALIDATE_ENG0_REQ, FLUSH_TYPE, 0);
+     req = REG_SET_FIELD(req, VM_INVALIDATE_ENG0_REQ, FLUSH_TYPE, flush_type);
       req = REG_SET_FIELD(req, VM_INVALIDATE_ENG0_REQ, INVALIDATE_L2_PTES, 1);
       req = REG_SET_FIELD(req, VM_INVALIDATE_ENG0_REQ, INVALIDATE_L2_PDE0, 1);
       req = REG_SET_FIELD(req, VM_INVALIDATE_ENG0_REQ, INVALIDATE_L2_PDE1, 1);
@@ -362,24 +363,24 @@ static signed long  amdgpu_kiq_reg_write_reg_wait(struct amdgpu_device *adev,
  */
 
 /**
- * gmc_v9_0_flush_gpu_tlb - gart tlb flush callback
+ * gmc_v9_0_flush_gpu_tlb - tlb flush with certain type
  *
  * @adev: amdgpu_device pointer
  * @vmid: vm instance to flush
+ * @flush_type: the flush type
  *
- * Flush the TLB for the requested page table.
+ * Flush the TLB for the requested page table using certain type.
  */
 static void gmc_v9_0_flush_gpu_tlb(struct amdgpu_device *adev,
-                                     uint32_t vmid)
+                             uint32_t vmid, uint32_t flush_type)
 {
-     /* Use register 17 for GART */
       const unsigned eng = 17;
       unsigned i, j;
       int r;
 
       for (i = 0; i < AMDGPU_MAX_VMHUBS; ++i) {
               struct amdgpu_vmhub *hub = &adev->vmhub[i];
-             u32 tmp = gmc_v9_0_get_invalidate_req(vmid);
+             u32 tmp = gmc_v9_0_get_invalidate_req(vmid, flush_type);
 
               if (adev->gfx.kiq.ring.ready &&
                   (amdgpu_sriov_runtime(adev) || !amdgpu_sriov_vf(adev)) &&
@@ -429,7 +430,7 @@ static uint64_t gmc_v9_0_emit_flush_gpu_tlb(struct amdgpu_ring *ring,
 {
       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);
+     uint32_t req = gmc_v9_0_get_invalidate_req(vmid, 0);
       unsigned eng = ring->vm_inv_eng;
 
       amdgpu_ring_emit_wreg(ring, hub->ctx0_ptb_addr_lo32 + (2 * vmid),

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

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +1 -1
@@ -1122,7 +1123,7 @@ static int gmc_v9_0_gart_enable(struct amdgpu_device *adev)
 
       gfxhub_v1_0_set_fault_enable_default(adev, value);
       mmhub_v1_0_set_fault_enable_default(adev, value);
-     gmc_v9_0_flush_gpu_tlb(adev, 0);
+     gmc_v9_0_flush_gpu_tlb(adev, 0, 0);
 
       DRM_INFO("PCIE GART of %uM enabled (table at 0x%016llX).\n",
                (unsigned)(adev->gmc.gart_size >> 20),

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

Reviewed-by Christian König
#9 lore raw
In reply to a message not in the archive

Well that looks *much* cleaner to me.

Only thing I can of hand see is that we should probably use an enum instead of the hardware value directly as Felix noted as well.

But I agree that this can probably come later on, feel free to add an

Christian.

Am 23.10.18 um 20:15 schrieb Zhao, Yong:

Quoted 187 lines

Add a flush_type parameter to that series of functions.

Change-Id I3dcd71955297c53b181f82e7078981230c642c01
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c |  4 ++--
  drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h  |  4 ++--
  drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c    |  5 +++--
  drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c    |  5 +++--
  drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c    |  4 ++--
  drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c    | 19 ++++++++++---------
  6 files changed, 22 insertions(+), 19 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gart.c +2 -2
index 11fea28..9a212aa 100644
@@ -248,7 +248,7 @@ int amdgpu_gart_unbind(struct amdgpu_device *adev, uint64_t offset,
  	}
  	mb();
  	amdgpu_asic_flush_hdp(adev, NULL);
-	amdgpu_gmc_flush_gpu_tlb(adev, 0);
+	amdgpu_gmc_flush_gpu_tlb(adev, 0, 0);
  	return 0;
  }
 
@@ -331,7 +331,7 @@ int amdgpu_gart_bind(struct amdgpu_device *adev, uint64_t offset,
 
  	mb();
  	amdgpu_asic_flush_hdp(adev, NULL);
-	amdgpu_gmc_flush_gpu_tlb(adev, 0);
+	amdgpu_gmc_flush_gpu_tlb(adev, 0, 0);
  	return 0;
  }
 
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h +2 -2
index 6fa7ef4..4c5f18c 100644
@@ -64,7 +64,7 @@ struct amdgpu_vmhub {
  struct amdgpu_gmc_funcs {
  	/* flush the vm tlb via mmio */
  	void (*flush_gpu_tlb)(struct amdgpu_device *adev,
-			      uint32_t vmid);
+			      uint32_t vmid, uint32_t flush_type);
  	/* flush the vm tlb via ring */
  	uint64_t (*emit_flush_gpu_tlb)(struct amdgpu_ring *ring, unsigned vmid,
  				       uint64_t pd_addr);
@@ -151,7 +151,7 @@ struct amdgpu_gmc {
  	struct amdgpu_xgmi xgmi;
  };
 
-#define amdgpu_gmc_flush_gpu_tlb(adev, vmid) (adev)->gmc.gmc_funcs->flush_gpu_tlb((adev), (vmid))
+#define amdgpu_gmc_flush_gpu_tlb(adev, vmid, type) (adev)->gmc.gmc_funcs->flush_gpu_tlb((adev), (vmid), (type))
  #define amdgpu_gmc_emit_flush_gpu_tlb(r, vmid, addr) (r)->adev->gmc.gmc_funcs->emit_flush_gpu_tlb((r), (vmid), (addr))
  #define amdgpu_gmc_emit_pasid_mapping(r, vmid, pasid) (r)->adev->gmc.gmc_funcs->emit_pasid_mapping((r), (vmid), (pasid))
  #define amdgpu_gmc_set_pte_pde(adev, pt, idx, addr, flags) (adev)->gmc.gmc_funcs->set_pte_pde((adev), (pt), (idx), (addr), (flags))
drivers/gpu/drm/amd/amdgpu/gmc_v6_0.c +3 -2
index e1c2b4e..2821d1d 100644
@@ -358,7 +358,8 @@ static int gmc_v6_0_mc_init(struct amdgpu_device *adev)
  	return 0;
  }
 
-static void gmc_v6_0_flush_gpu_tlb(struct amdgpu_device *adev, uint32_t vmid)
+static void gmc_v6_0_flush_gpu_tlb(struct amdgpu_device *adev,
+				uint32_t vmid, uint32_t flush_type)
  {
  	WREG32(mmVM_INVALIDATE_REQUEST, 1 << vmid);
  }
@@ -580,7 +581,7 @@ static int gmc_v6_0_gart_enable(struct amdgpu_device *adev)
  	else
  		gmc_v6_0_set_fault_enable_default(adev, true);
 
-	gmc_v6_0_flush_gpu_tlb(adev, 0);
+	gmc_v6_0_flush_gpu_tlb(adev, 0, 0);
  	dev_info(adev->dev, "PCIE GART of %uM enabled (table at 0x%016llX).\n",
  		 (unsigned)(adev->gmc.gart_size >> 20),
  		 (unsigned long long)table_addr);
drivers/gpu/drm/amd/amdgpu/gmc_v7_0.c +3 -2
index 910c4ce..761dcfb 100644
@@ -430,7 +430,8 @@ static int gmc_v7_0_mc_init(struct amdgpu_device *adev)
   *
   * Flush the TLB for the requested page table (CIK).
   */
-static void gmc_v7_0_flush_gpu_tlb(struct amdgpu_device *adev, uint32_t vmid)
+static void gmc_v7_0_flush_gpu_tlb(struct amdgpu_device *adev,
+				uint32_t vmid, uint32_t flush_type)
  {
  	/* bits 0-15 are the VM contexts0-15 */
  	WREG32(mmVM_INVALIDATE_REQUEST, 1 << vmid);
@@ -698,7 +699,7 @@ static int gmc_v7_0_gart_enable(struct amdgpu_device *adev)
  		WREG32(mmCHUB_CONTROL, tmp);
  	}
 
-	gmc_v7_0_flush_gpu_tlb(adev, 0);
+	gmc_v7_0_flush_gpu_tlb(adev, 0, 0);
  	DRM_INFO("PCIE GART of %uM enabled (table at 0x%016llX).\n",
  		 (unsigned)(adev->gmc.gart_size >> 20),
  		 (unsigned long long)table_addr);
drivers/gpu/drm/amd/amdgpu/gmc_v8_0.c +2 -2
index 1d3265c..531aaf3 100644
@@ -611,7 +611,7 @@ static int gmc_v8_0_mc_init(struct amdgpu_device *adev)
   * Flush the TLB for the requested page table (CIK).
   */
  static void gmc_v8_0_flush_gpu_tlb(struct amdgpu_device *adev,
-					uint32_t vmid)
+				uint32_t vmid, uint32_t flush_type)
  {
  	/* bits 0-15 are the VM contexts0-15 */
  	WREG32(mmVM_INVALIDATE_REQUEST, 1 << vmid);
@@ -920,7 +920,7 @@ static int gmc_v8_0_gart_enable(struct amdgpu_device *adev)
  	else
  		gmc_v8_0_set_fault_enable_default(adev, true);
 
-	gmc_v8_0_flush_gpu_tlb(adev, 0);
+	gmc_v8_0_flush_gpu_tlb(adev, 0, 0);
  	DRM_INFO("PCIE GART of %uM enabled (table at 0x%016llX).\n",
  		 (unsigned)(adev->gmc.gart_size >> 20),
  		 (unsigned long long)table_addr);
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +9 -8
index f35d7a5..79d8a84 100644
@@ -293,14 +293,15 @@ static void gmc_v9_0_set_irq_funcs(struct amdgpu_device *adev)
  	adev->gmc.vm_fault.funcs = &gmc_v9_0_irq_funcs;
  }
 
-static uint32_t gmc_v9_0_get_invalidate_req(unsigned int vmid)
+static uint32_t gmc_v9_0_get_invalidate_req(unsigned int vmid,
+					uint32_t flush_type)
  {
  	u32 req = 0;
 
  	/* invalidate using legacy mode on vmid*/
  	req = REG_SET_FIELD(req, VM_INVALIDATE_ENG0_REQ,
  			    PER_VMID_INVALIDATE_REQ, 1 << vmid);
-	req = REG_SET_FIELD(req, VM_INVALIDATE_ENG0_REQ, FLUSH_TYPE, 0);
+	req = REG_SET_FIELD(req, VM_INVALIDATE_ENG0_REQ, FLUSH_TYPE, flush_type);
  	req = REG_SET_FIELD(req, VM_INVALIDATE_ENG0_REQ, INVALIDATE_L2_PTES, 1);
  	req = REG_SET_FIELD(req, VM_INVALIDATE_ENG0_REQ, INVALIDATE_L2_PDE0, 1);
  	req = REG_SET_FIELD(req, VM_INVALIDATE_ENG0_REQ, INVALIDATE_L2_PDE1, 1);
@@ -362,24 +363,24 @@ static signed long  amdgpu_kiq_reg_write_reg_wait(struct amdgpu_device *adev,
   */
 
  /**
- * gmc_v9_0_flush_gpu_tlb - gart tlb flush callback
+ * gmc_v9_0_flush_gpu_tlb - tlb flush with certain type
   *
   * @adev: amdgpu_device pointer
   * @vmid: vm instance to flush
+ * @flush_type: the flush type
   *
- * Flush the TLB for the requested page table.
+ * Flush the TLB for the requested page table using certain type.
   */
  static void gmc_v9_0_flush_gpu_tlb(struct amdgpu_device *adev,
-					uint32_t vmid)
+				uint32_t vmid, uint32_t flush_type)
  {
-	/* Use register 17 for GART */
  	const unsigned eng = 17;
  	unsigned i, j;
  	int r;
 
  	for (i = 0; i < AMDGPU_MAX_VMHUBS; ++i) {
  		struct amdgpu_vmhub *hub = &adev->vmhub[i];
-		u32 tmp = gmc_v9_0_get_invalidate_req(vmid);
+		u32 tmp = gmc_v9_0_get_invalidate_req(vmid, flush_type);
 
  		if (adev->gfx.kiq.ring.ready &&
  		    (amdgpu_sriov_runtime(adev) || !amdgpu_sriov_vf(adev)) &&
@@ -429,7 +430,7 @@ static uint64_t gmc_v9_0_emit_flush_gpu_tlb(struct amdgpu_ring *ring,
  {
  	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);
+	uint32_t req = gmc_v9_0_get_invalidate_req(vmid, 0);
  	unsigned eng = ring->vm_inv_eng;
 
  	amdgpu_ring_emit_wreg(ring, hub->ctx0_ptb_addr_lo32 + (2 * vmid),

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

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +1 -1
@@ -1122,7 +1123,7 @@ static int gmc_v9_0_gart_enable(struct amdgpu_device *adev)
 
  	gfxhub_v1_0_set_fault_enable_default(adev, value);
  	mmhub_v1_0_set_fault_enable_default(adev, value);
-	gmc_v9_0_flush_gpu_tlb(adev, 0);
+	gmc_v9_0_flush_gpu_tlb(adev, 0, 0);
 
  	DRM_INFO("PCIE GART of %uM enabled (table at 0x%016llX).\n",
  		 (unsigned)(adev->gmc.gart_size >> 20),

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