Skip to contentSkip to conversation

*** GFX9 RLCG Interface modifications ***

PATCH Superseded Victor Skvortsov 6 participants 20 messages Dec 15, 2021 – Dec 16, 2021

Subsystems (3)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover *** GFX9 RLCG Interface modifications ***

This patchset introduces an expanded sriov RLCG interface. This interface will be used by Aldebaran in sriov mode for indirect GC register access during full access.

Victor Skvortsov (5):
drm/amdgpu: Add *_SOC15_IP_NO_KIQ() macro definitions drm/amdgpu: Modify indirect register access for gmc_v9_0 sriov drm/amdgpu: Modify indirect register access for amdkfd_gfx_v9 sriov drm/amdgpu: Initialize Aldebaran RLC function pointers drm/amdgpu: Modify indirect register access for gfx9 sriov

 .../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v9.c |  27 ++---
 drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c |   2 +
 drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c         | 114 +++++++++++++-----
 drivers/gpu/drm/amd/amdgpu/gfx_v9_0.h         |   2 +
 drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c         |  45 +++++--
 drivers/gpu/drm/amd/amdgpu/soc15_common.h     |   5 +
 6 files changed, 138 insertions(+), 57 deletions(-)
Signature · 1 line
2.25.1
#1 lore raw

PATCH 1/5 drm/amdgpu: Add *_SOC15_IP_NO_KIQ() macro definitions

Add helper macros to change register access
from direct to indirect.

---
 drivers/gpu/drm/amd/amdgpu/soc15_common.h | 5 +++++
 1 file changed, 5 insertions(+)
drivers/gpu/drm/amd/amdgpu/soc15_common.h +5 -0
index 8a9ca87d8663..473767e03676 100644
@@ -51,6 +51,8 @@
 
 #define RREG32_SOC15_IP(ip, reg) __RREG32_SOC15_RLC__(reg, 0, ip##_HWIP)
 
+#define RREG32_SOC15_IP_NO_KIQ(ip, reg) __RREG32_SOC15_RLC__(reg, AMDGPU_REGS_NO_KIQ, ip##_HWIP)
+
 #define RREG32_SOC15_NO_KIQ(ip, inst, reg) \
 	__RREG32_SOC15_RLC__(adev->reg_offset[ip##_HWIP][inst][reg##_BASE_IDX] + reg, \
 			 AMDGPU_REGS_NO_KIQ, ip##_HWIP)
@@ -65,6 +67,9 @@
 #define WREG32_SOC15_IP(ip, reg, value) \
 	 __WREG32_SOC15_RLC__(reg, value, 0, ip##_HWIP)
 
+#define WREG32_SOC15_IP_NO_KIQ(ip, reg, value) \
+	 __WREG32_SOC15_RLC__(reg, value, AMDGPU_REGS_NO_KIQ, ip##_HWIP)
+
 #define WREG32_SOC15_NO_KIQ(ip, inst, reg, value) \
 	__WREG32_SOC15_RLC__(adev->reg_offset[ip##_HWIP][inst][reg##_BASE_IDX] + reg, \
 			     value, AMDGPU_REGS_NO_KIQ, ip##_HWIP)
Signature · 1 line
2.25.1
Reviewed-by on v1 1/5
#2 lore raw

Re: [PATCH 1/5] drm/amdgpu: Add *_SOC15_IP_NO_KIQ() macro definitions

[AMD Official Use Only]

________________________________
From: Skvortsov, Victor <[email protected]>
Sent: Wednesday, December 15, 2021 10:55 AM
To: [email protected] <[email protected]>; Deng, Emily <[email protected]>; Liu, Monk <[email protected]>; Ming, Davis <[email protected]>; Liu, Shaoyun <[email protected]>; Zhou, Peng Ju <[email protected]>; Chen, JingWen <[email protected]>; Chen, Horace <[email protected]>; Nieto, David M <[email protected]>
Cc: Skvortsov, Victor <[email protected]>
Subject: [PATCH 1/5] drm/amdgpu: Add *_SOC15_IP_NO_KIQ() macro definitions

Add helper macros to change register access
from direct to indirect.

---
 drivers/gpu/drm/amd/amdgpu/soc15_common.h | 5 +++++
 1 file changed, 5 insertions(+)
drivers/gpu/drm/amd/amdgpu/soc15_common.h +5 -0
index 8a9ca87d8663..473767e03676 100644
@@ -51,6 +51,8 @@
 
 #define RREG32_SOC15_IP(ip, reg) __RREG32_SOC15_RLC__(reg, 0, ip##_HWIP)
 
+#define RREG32_SOC15_IP_NO_KIQ(ip, reg) __RREG32_SOC15_RLC__(reg, AMDGPU_REGS_NO_KIQ, ip##_HWIP)
+
 #define RREG32_SOC15_NO_KIQ(ip, inst, reg) \
         __RREG32_SOC15_RLC__(adev->reg_offset[ip##_HWIP][inst][reg##_BASE_IDX] + reg, \
                          AMDGPU_REGS_NO_KIQ, ip##_HWIP)
@@ -65,6 +67,9 @@
 #define WREG32_SOC15_IP(ip, reg, value) \
          __WREG32_SOC15_RLC__(reg, value, 0, ip##_HWIP)
 
+#define WREG32_SOC15_IP_NO_KIQ(ip, reg, value) \
+        __WREG32_SOC15_RLC__(reg, value, AMDGPU_REGS_NO_KIQ, ip##_HWIP)
+
 #define WREG32_SOC15_NO_KIQ(ip, inst, reg, value) \
         __WREG32_SOC15_RLC__(adev->reg_offset[ip##_HWIP][inst][reg##_BASE_IDX] + reg, \
                              value, AMDGPU_REGS_NO_KIQ, ip##_HWIP)

--
2.25.1

#3 lore raw

PATCH 2/5 drm/amdgpu: Modify indirect register access for gmc_v9_0 sriov

In reply to Victor Skvortsov

Modify GC register access from MMIO to RLCG if the indirect flag is set

---
 drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c | 45 +++++++++++++++++++--------
 1 file changed, 32 insertions(+), 13 deletions(-)
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +32 -13
index db2ec84f7237..345ce7fc6463 100644
@@ -478,9 +478,16 @@ static int gmc_v9_0_vm_fault_interrupt_state(struct amdgpu_device *adev,
 			hub = &adev->vmhub[j];
 			for (i = 0; i < 16; i++) {
 				reg = hub->vm_context0_cntl + i;
-				tmp = RREG32(reg);
+
+				tmp = (j == AMDGPU_GFXHUB_0) ?
+					RREG32_SOC15_IP(GC, reg) :
+					RREG32_SOC15_IP(MMHUB, reg);
+
 				tmp &= ~bits;
-				WREG32(reg, tmp);
+
+				(j == AMDGPU_GFXHUB_0) ?
+					WREG32_SOC15_IP(GC, reg, tmp) :
+					WREG32_SOC15_IP(MMHUB, reg, tmp);
 			}
 		}
 		break;
@@ -489,9 +496,16 @@ static int gmc_v9_0_vm_fault_interrupt_state(struct amdgpu_device *adev,
 			hub = &adev->vmhub[j];
 			for (i = 0; i < 16; i++) {
 				reg = hub->vm_context0_cntl + i;
-				tmp = RREG32(reg);
+
+				tmp = (j == AMDGPU_GFXHUB_0) ?
+					RREG32_SOC15_IP(GC, reg) :
+					RREG32_SOC15_IP(MMHUB, reg);
+
 				tmp |= bits;
-				WREG32(reg, tmp);
+
+				(j == AMDGPU_GFXHUB_0) ?
+					WREG32_SOC15_IP(GC, reg, tmp) :
+					WREG32_SOC15_IP(MMHUB, reg, tmp);
 			}
 		}
 		break;
@@ -789,8 +803,9 @@ static void gmc_v9_0_flush_gpu_tlb(struct amdgpu_device *adev, uint32_t vmid,
 	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 +
-					    hub->eng_distance * eng);
+			tmp = (vmhub == AMDGPU_GFXHUB_0) ?
+					RREG32_SOC15_IP_NO_KIQ(GC, hub->vm_inv_eng0_sem + hub->eng_distance * eng) :
+					RREG32_SOC15_IP_NO_KIQ(MMHUB, hub->vm_inv_eng0_sem + hub->eng_distance * eng);
 			if (tmp & 0x1)
 				break;
 			udelay(1);
@@ -801,8 +816,9 @@ static void gmc_v9_0_flush_gpu_tlb(struct amdgpu_device *adev, uint32_t vmid,
 	}
 
 	do {
-		WREG32_NO_KIQ(hub->vm_inv_eng0_req +
-			      hub->eng_distance * eng, inv_req);
+		(vmhub == AMDGPU_GFXHUB_0) ?
+			WREG32_SOC15_IP_NO_KIQ(GC, hub->vm_inv_eng0_req + hub->eng_distance * eng, inv_req) :
+			WREG32_SOC15_IP_NO_KIQ(MMHUB, hub->vm_inv_eng0_req + hub->eng_distance * eng, inv_req);
 
 		/*
 		 * Issue a dummy read to wait for the ACK register to
@@ -815,8 +831,9 @@ static void gmc_v9_0_flush_gpu_tlb(struct amdgpu_device *adev, uint32_t vmid,
 				      hub->eng_distance * eng);
 
 		for (j = 0; j < adev->usec_timeout; j++) {
-			tmp = RREG32_NO_KIQ(hub->vm_inv_eng0_ack +
-					    hub->eng_distance * eng);
+			tmp = (vmhub == AMDGPU_GFXHUB_0) ?
+				RREG32_SOC15_IP_NO_KIQ(GC, hub->vm_inv_eng0_ack + hub->eng_distance * eng) :
+				RREG32_SOC15_IP_NO_KIQ(MMHUB, hub->vm_inv_eng0_ack + hub->eng_distance * eng);
 			if (tmp & (1 << vmid))
 				break;
 			udelay(1);
@@ -827,13 +844,15 @@ static void gmc_v9_0_flush_gpu_tlb(struct amdgpu_device *adev, uint32_t vmid,
 	} while (inv_req);
 
 	/* TODO: It needs to continue working on debugging with semaphore for GFXHUB as well. */
-	if (use_semaphore)
+	if (use_semaphore) {
 		/*
 		 * add semaphore release after invalidation,
 		 * write with 0 means semaphore release
 		 */
-		WREG32_NO_KIQ(hub->vm_inv_eng0_sem +
-			      hub->eng_distance * eng, 0);
+		(vmhub == AMDGPU_GFXHUB_0) ?
+			WREG32_SOC15_IP_NO_KIQ(GC, hub->vm_inv_eng0_sem + hub->eng_distance * eng, 0) :
+			WREG32_SOC15_IP_NO_KIQ(MMHUB, hub->vm_inv_eng0_sem + hub->eng_distance * eng, 0);
+	}
 
 	spin_unlock(&adev->gmc.invalidate_lock);
 
Signature · 1 line
2.25.1
#4 lore raw

Re: [PATCH 2/5] drm/amdgpu: Modify indirect register access for gmc_v9_0 sriov

[AMD Official Use Only]

I don't know what others may think, but this coding while correct:

- WREG32_NO_KIQ(hub->vm_inv_eng0_req +
- hub->eng_distance * eng, inv_req);
+ (vmhub == AMDGPU_GFXHUB_0) ?
+ WREG32_SOC15_IP_NO_KIQ(GC, hub->vm_inv_eng0_req + hub->eng_distance * eng, inv_req) :
+ WREG32_SOC15_IP_NO_KIQ(MMHUB, hub->vm_inv_eng0_req + hub->eng_distance * eng, inv_req);

if is bit difficult to read. I wouldn't mind if the results of those function calls were stored in a variable, but here, you are using it as an if/else or a switch statement. It is better to do it like that:

switch(vmhub) {
case AMDGPU_GFXHUB_0):
//yadayada

or

if (vmhub == AMDGPU_GFXHUB_0)
//yadayada
else {
// yada du
}
________________________________
From: Skvortsov, Victor <[email protected]>
Sent: Wednesday, December 15, 2021 10:55 AM
To: [email protected] <[email protected]>; Deng, Emily <[email protected]>; Liu, Monk <[email protected]>; Ming, Davis <[email protected]>; Liu, Shaoyun <[email protected]>; Zhou, Peng Ju <[email protected]>; Chen, JingWen <[email protected]>; Chen, Horace <[email protected]>; Nieto, David M <[email protected]>
Cc: Skvortsov, Victor <[email protected]>
Subject: [PATCH 2/5] drm/amdgpu: Modify indirect register access for gmc_v9_0 sriov

Modify GC register access from MMIO to RLCG if the indirect flag is set

---
 drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c | 45 +++++++++++++++++++--------
 1 file changed, 32 insertions(+), 13 deletions(-)
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +32 -13
index db2ec84f7237..345ce7fc6463 100644
@@ -478,9 +478,16 @@ static int gmc_v9_0_vm_fault_interrupt_state(struct amdgpu_device *adev,
                         hub = &adev->vmhub[j];
                         for (i = 0; i < 16; i++) {
                                 reg = hub->vm_context0_cntl + i;
-                               tmp = RREG32(reg);
+
+                               tmp = (j == AMDGPU_GFXHUB_0) ?
+                                       RREG32_SOC15_IP(GC, reg) :
+                                       RREG32_SOC15_IP(MMHUB, reg);
+
                                 tmp &= ~bits;
-                               WREG32(reg, tmp);
+
+                               (j == AMDGPU_GFXHUB_0) ?
+                                       WREG32_SOC15_IP(GC, reg, tmp) :
+                                       WREG32_SOC15_IP(MMHUB, reg, tmp);
                         }
                 }
                 break;
@@ -489,9 +496,16 @@ static int gmc_v9_0_vm_fault_interrupt_state(struct amdgpu_device *adev,
                         hub = &adev->vmhub[j];
                         for (i = 0; i < 16; i++) {
                                 reg = hub->vm_context0_cntl + i;
-                               tmp = RREG32(reg);
+
+                               tmp = (j == AMDGPU_GFXHUB_0) ?
+                                       RREG32_SOC15_IP(GC, reg) :
+                                       RREG32_SOC15_IP(MMHUB, reg);
+
                                 tmp |= bits;
-                               WREG32(reg, tmp);
+
+                               (j == AMDGPU_GFXHUB_0) ?
+                                       WREG32_SOC15_IP(GC, reg, tmp) :
+                                       WREG32_SOC15_IP(MMHUB, reg, tmp);
                         }
                 }
                 break;
@@ -789,8 +803,9 @@ static void gmc_v9_0_flush_gpu_tlb(struct amdgpu_device *adev, uint32_t vmid,
         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 +
-                                           hub->eng_distance * eng);
+                       tmp = (vmhub == AMDGPU_GFXHUB_0) ?
+                                       RREG32_SOC15_IP_NO_KIQ(GC, hub->vm_inv_eng0_sem + hub->eng_distance * eng) :
+                                       RREG32_SOC15_IP_NO_KIQ(MMHUB, hub->vm_inv_eng0_sem + hub->eng_distance * eng);
                         if (tmp & 0x1)
                                 break;
                         udelay(1);
@@ -801,8 +816,9 @@ static void gmc_v9_0_flush_gpu_tlb(struct amdgpu_device *adev, uint32_t vmid,
         }
 
         do {
-               WREG32_NO_KIQ(hub->vm_inv_eng0_req +
-                             hub->eng_distance * eng, inv_req);
+               (vmhub == AMDGPU_GFXHUB_0) ?
+                       WREG32_SOC15_IP_NO_KIQ(GC, hub->vm_inv_eng0_req + hub->eng_distance * eng, inv_req) :
+                       WREG32_SOC15_IP_NO_KIQ(MMHUB, hub->vm_inv_eng0_req + hub->eng_distance * eng, inv_req);
 
                 /*
                  * Issue a dummy read to wait for the ACK register to
@@ -815,8 +831,9 @@ static void gmc_v9_0_flush_gpu_tlb(struct amdgpu_device *adev, uint32_t vmid,
                                       hub->eng_distance * eng);
 
                 for (j = 0; j < adev->usec_timeout; j++) {
-                       tmp = RREG32_NO_KIQ(hub->vm_inv_eng0_ack +
-                                           hub->eng_distance * eng);
+                       tmp = (vmhub == AMDGPU_GFXHUB_0) ?
+                               RREG32_SOC15_IP_NO_KIQ(GC, hub->vm_inv_eng0_ack + hub->eng_distance * eng) :
+                               RREG32_SOC15_IP_NO_KIQ(MMHUB, hub->vm_inv_eng0_ack + hub->eng_distance * eng);
                         if (tmp & (1 << vmid))
                                 break;
                         udelay(1);
@@ -827,13 +844,15 @@ static void gmc_v9_0_flush_gpu_tlb(struct amdgpu_device *adev, uint32_t vmid,
         } while (inv_req);
 
         /* TODO: It needs to continue working on debugging with semaphore for GFXHUB as well. */
-       if (use_semaphore)
+       if (use_semaphore) {
                 /*
                  * add semaphore release after invalidation,
                  * write with 0 means semaphore release
                  */
-               WREG32_NO_KIQ(hub->vm_inv_eng0_sem +
-                             hub->eng_distance * eng, 0);
+               (vmhub == AMDGPU_GFXHUB_0) ?
+                       WREG32_SOC15_IP_NO_KIQ(GC, hub->vm_inv_eng0_sem + hub->eng_distance * eng, 0) :
+                       WREG32_SOC15_IP_NO_KIQ(MMHUB, hub->vm_inv_eng0_sem + hub->eng_distance * eng, 0);
+       }
 
         spin_unlock(&adev->gmc.invalidate_lock);
 

--
2.25.1

#5 lore raw

PATCH 3/5 drm/amdgpu: Modify indirect register access for amdkfd_gfx_v9 sriov

In reply to Victor Skvortsov

Modify GC register access from MMIO to RLCG if the indirect flag is set

---
 .../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v9.c | 27 +++++++++----------
 1 file changed, 13 insertions(+), 14 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v9.c +13 -14
index ddfe7aff919d..1abf662a0e91 100644
@@ -166,7 +166,7 @@ int kgd_gfx_v9_init_interrupts(struct amdgpu_device *adev, uint32_t pipe_id)
 
 	lock_srbm(adev, mec, pipe, 0, 0);
 
-	WREG32(SOC15_REG_OFFSET(GC, 0, mmCPC_INT_CNTL),
+	WREG32_SOC15(GC, 0, mmCPC_INT_CNTL,
 		CP_INT_CNTL_RING0__TIME_STAMP_INT_ENABLE_MASK |
 		CP_INT_CNTL_RING0__OPCODE_ERROR_INT_ENABLE_MASK);
 
@@ -279,7 +279,7 @@ int kgd_gfx_v9_hqd_load(struct amdgpu_device *adev, void *mqd,
 		       lower_32_bits((uintptr_t)wptr));
 		WREG32_RLC(SOC15_REG_OFFSET(GC, 0, mmCP_HQD_PQ_WPTR_POLL_ADDR_HI),
 		       upper_32_bits((uintptr_t)wptr));
-		WREG32(SOC15_REG_OFFSET(GC, 0, mmCP_PQ_WPTR_POLL_CNTL1),
+		WREG32_SOC15(GC, 0, mmCP_PQ_WPTR_POLL_CNTL1,
 		       (uint32_t)get_queue_mask(adev, pipe_id, queue_id));
 	}
 
@@ -488,13 +488,13 @@ bool kgd_gfx_v9_hqd_is_occupied(struct amdgpu_device *adev,
 	uint32_t low, high;
 
 	acquire_queue(adev, pipe_id, queue_id);
-	act = RREG32(SOC15_REG_OFFSET(GC, 0, mmCP_HQD_ACTIVE));
+	act = RREG32_SOC15(GC, 0, mmCP_HQD_ACTIVE);
 	if (act) {
 		low = lower_32_bits(queue_address >> 8);
 		high = upper_32_bits(queue_address >> 8);
 
-		if (low == RREG32(SOC15_REG_OFFSET(GC, 0, mmCP_HQD_PQ_BASE)) &&
-		   high == RREG32(SOC15_REG_OFFSET(GC, 0, mmCP_HQD_PQ_BASE_HI)))
+		if (low == RREG32_SOC15(GC, 0, mmCP_HQD_PQ_BASE) &&
+		   high == RREG32_SOC15(GC, 0, mmCP_HQD_PQ_BASE_HI))
 			retval = true;
 	}
 	release_queue(adev);
@@ -556,7 +556,7 @@ int kgd_gfx_v9_hqd_destroy(struct amdgpu_device *adev, void *mqd,
 
 	end_jiffies = (utimeout * HZ / 1000) + jiffies;
 	while (true) {
-		temp = RREG32(SOC15_REG_OFFSET(GC, 0, mmCP_HQD_ACTIVE));
+		temp = RREG32_SOC15(GC, 0, mmCP_HQD_ACTIVE);
 		if (!(temp & CP_HQD_ACTIVE__ACTIVE_MASK))
 			break;
 		if (time_after(jiffies, end_jiffies)) {
@@ -645,7 +645,7 @@ int kgd_gfx_v9_wave_control_execute(struct amdgpu_device *adev,
 	mutex_lock(&adev->grbm_idx_mutex);
 
 	WREG32_SOC15_RLC_SHADOW(GC, 0, mmGRBM_GFX_INDEX, gfx_index_val);
-	WREG32(SOC15_REG_OFFSET(GC, 0, mmSQ_CMD), sq_cmd);
+	WREG32_SOC15(GC, 0, mmSQ_CMD, sq_cmd);
 
 	data = REG_SET_FIELD(data, GRBM_GFX_INDEX,
 		INSTANCE_BROADCAST_WRITES, 1);
@@ -722,7 +722,7 @@ static void get_wave_count(struct amdgpu_device *adev, int queue_idx,
 	pipe_idx = queue_idx / adev->gfx.mec.num_queue_per_pipe;
 	queue_slot = queue_idx % adev->gfx.mec.num_queue_per_pipe;
 	soc15_grbm_select(adev, 1, pipe_idx, queue_slot, 0);
-	reg_val = RREG32(SOC15_REG_OFFSET(GC, 0, mmSPI_CSQ_WF_ACTIVE_COUNT_0) +
+	reg_val = RREG32_SOC15_IP(GC, SOC15_REG_OFFSET(GC, 0, mmSPI_CSQ_WF_ACTIVE_COUNT_0) +
 			 queue_slot);
 	*wave_cnt = reg_val & SPI_CSQ_WF_ACTIVE_COUNT_0__COUNT_MASK;
 	if (*wave_cnt != 0)
@@ -809,8 +809,7 @@ void kgd_gfx_v9_get_cu_occupancy(struct amdgpu_device *adev, int pasid,
 		for (sh_idx = 0; sh_idx < sh_cnt; sh_idx++) {
 
 			gfx_v9_0_select_se_sh(adev, se_idx, sh_idx, 0xffffffff);
-			queue_map = RREG32(SOC15_REG_OFFSET(GC, 0,
-					   mmSPI_CSQ_WF_ACTIVE_STATUS));
+			queue_map = RREG32_SOC15(GC, 0, mmSPI_CSQ_WF_ACTIVE_STATUS);
 
 			/*
 			 * Assumption: queue map encodes following schema: four
@@ -860,17 +859,17 @@ void kgd_gfx_v9_program_trap_handler_settings(struct amdgpu_device *adev,
 	/*
 	 * Program TBA registers
 	 */
-	WREG32(SOC15_REG_OFFSET(GC, 0, mmSQ_SHADER_TBA_LO),
+	WREG32_SOC15(GC, 0, mmSQ_SHADER_TBA_LO,
                         lower_32_bits(tba_addr >> 8));
-	WREG32(SOC15_REG_OFFSET(GC, 0, mmSQ_SHADER_TBA_HI),
+	WREG32_SOC15(GC, 0, mmSQ_SHADER_TBA_HI,
                         upper_32_bits(tba_addr >> 8));
 
 	/*
 	 * Program TMA registers
 	 */
-	WREG32(SOC15_REG_OFFSET(GC, 0, mmSQ_SHADER_TMA_LO),
+	WREG32_SOC15(GC, 0, mmSQ_SHADER_TMA_LO,
 			lower_32_bits(tma_addr >> 8));
-	WREG32(SOC15_REG_OFFSET(GC, 0, mmSQ_SHADER_TMA_HI),
+	WREG32_SOC15(GC, 0, mmSQ_SHADER_TMA_HI,
 			upper_32_bits(tma_addr >> 8));
 
 	unlock_srbm(adev);
Signature · 1 line
2.25.1
Reviewed-by on v1 3/5
#6 lore raw

Re: [PATCH 3/5] drm/amdgpu: Modify indirect register access for amdkfd_gfx_v9 sriov

[AMD Official Use Only]

________________________________
From: Skvortsov, Victor <[email protected]>
Sent: Wednesday, December 15, 2021 10:55 AM
To: [email protected] <[email protected]>; Deng, Emily <[email protected]>; Liu, Monk <[email protected]>; Ming, Davis <[email protected]>; Liu, Shaoyun <[email protected]>; Zhou, Peng Ju <[email protected]>; Chen, JingWen <[email protected]>; Chen, Horace <[email protected]>; Nieto, David M <[email protected]>
Cc: Skvortsov, Victor <[email protected]>
Subject: [PATCH 3/5] drm/amdgpu: Modify indirect register access for amdkfd_gfx_v9 sriov

Modify GC register access from MMIO to RLCG if the indirect flag is set

---
 .../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v9.c | 27 +++++++++----------
 1 file changed, 13 insertions(+), 14 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v9.c +13 -14
index ddfe7aff919d..1abf662a0e91 100644
@@ -166,7 +166,7 @@ int kgd_gfx_v9_init_interrupts(struct amdgpu_device *adev, uint32_t pipe_id)
 
         lock_srbm(adev, mec, pipe, 0, 0);
 
-       WREG32(SOC15_REG_OFFSET(GC, 0, mmCPC_INT_CNTL),
+       WREG32_SOC15(GC, 0, mmCPC_INT_CNTL,
                 CP_INT_CNTL_RING0__TIME_STAMP_INT_ENABLE_MASK |
                 CP_INT_CNTL_RING0__OPCODE_ERROR_INT_ENABLE_MASK);
 
@@ -279,7 +279,7 @@ int kgd_gfx_v9_hqd_load(struct amdgpu_device *adev, void *mqd,
                        lower_32_bits((uintptr_t)wptr));
                 WREG32_RLC(SOC15_REG_OFFSET(GC, 0, mmCP_HQD_PQ_WPTR_POLL_ADDR_HI),
                        upper_32_bits((uintptr_t)wptr));
-               WREG32(SOC15_REG_OFFSET(GC, 0, mmCP_PQ_WPTR_POLL_CNTL1),
+               WREG32_SOC15(GC, 0, mmCP_PQ_WPTR_POLL_CNTL1,
                        (uint32_t)get_queue_mask(adev, pipe_id, queue_id));
         }
 
@@ -488,13 +488,13 @@ bool kgd_gfx_v9_hqd_is_occupied(struct amdgpu_device *adev,
         uint32_t low, high;
 
         acquire_queue(adev, pipe_id, queue_id);
-       act = RREG32(SOC15_REG_OFFSET(GC, 0, mmCP_HQD_ACTIVE));
+       act = RREG32_SOC15(GC, 0, mmCP_HQD_ACTIVE);
         if (act) {
                 low = lower_32_bits(queue_address >> 8);
                 high = upper_32_bits(queue_address >> 8);
 
-               if (low == RREG32(SOC15_REG_OFFSET(GC, 0, mmCP_HQD_PQ_BASE)) &&
-                  high == RREG32(SOC15_REG_OFFSET(GC, 0, mmCP_HQD_PQ_BASE_HI)))
+               if (low == RREG32_SOC15(GC, 0, mmCP_HQD_PQ_BASE) &&
+                  high == RREG32_SOC15(GC, 0, mmCP_HQD_PQ_BASE_HI))
                         retval = true;
         }
         release_queue(adev);
@@ -556,7 +556,7 @@ int kgd_gfx_v9_hqd_destroy(struct amdgpu_device *adev, void *mqd,
 
         end_jiffies = (utimeout * HZ / 1000) + jiffies;
         while (true) {
-               temp = RREG32(SOC15_REG_OFFSET(GC, 0, mmCP_HQD_ACTIVE));
+               temp = RREG32_SOC15(GC, 0, mmCP_HQD_ACTIVE);
                 if (!(temp & CP_HQD_ACTIVE__ACTIVE_MASK))
                         break;
                 if (time_after(jiffies, end_jiffies)) {
@@ -645,7 +645,7 @@ int kgd_gfx_v9_wave_control_execute(struct amdgpu_device *adev,
         mutex_lock(&adev->grbm_idx_mutex);
 
         WREG32_SOC15_RLC_SHADOW(GC, 0, mmGRBM_GFX_INDEX, gfx_index_val);
-       WREG32(SOC15_REG_OFFSET(GC, 0, mmSQ_CMD), sq_cmd);
+       WREG32_SOC15(GC, 0, mmSQ_CMD, sq_cmd);
 
         data = REG_SET_FIELD(data, GRBM_GFX_INDEX,
                 INSTANCE_BROADCAST_WRITES, 1);
@@ -722,7 +722,7 @@ static void get_wave_count(struct amdgpu_device *adev, int queue_idx,
         pipe_idx = queue_idx / adev->gfx.mec.num_queue_per_pipe;
         queue_slot = queue_idx % adev->gfx.mec.num_queue_per_pipe;
         soc15_grbm_select(adev, 1, pipe_idx, queue_slot, 0);
-       reg_val = RREG32(SOC15_REG_OFFSET(GC, 0, mmSPI_CSQ_WF_ACTIVE_COUNT_0) +
+       reg_val = RREG32_SOC15_IP(GC, SOC15_REG_OFFSET(GC, 0, mmSPI_CSQ_WF_ACTIVE_COUNT_0) +
                          queue_slot);
         *wave_cnt = reg_val & SPI_CSQ_WF_ACTIVE_COUNT_0__COUNT_MASK;
         if (*wave_cnt != 0)
@@ -809,8 +809,7 @@ void kgd_gfx_v9_get_cu_occupancy(struct amdgpu_device *adev, int pasid,
                 for (sh_idx = 0; sh_idx < sh_cnt; sh_idx++) {
 
                         gfx_v9_0_select_se_sh(adev, se_idx, sh_idx, 0xffffffff);
-                       queue_map = RREG32(SOC15_REG_OFFSET(GC, 0,
-                                          mmSPI_CSQ_WF_ACTIVE_STATUS));
+                       queue_map = RREG32_SOC15(GC, 0, mmSPI_CSQ_WF_ACTIVE_STATUS);
 
                         /*
                          * Assumption: queue map encodes following schema: four
@@ -860,17 +859,17 @@ void kgd_gfx_v9_program_trap_handler_settings(struct amdgpu_device *adev,
         /*
          * Program TBA registers
          */
-       WREG32(SOC15_REG_OFFSET(GC, 0, mmSQ_SHADER_TBA_LO),
+       WREG32_SOC15(GC, 0, mmSQ_SHADER_TBA_LO,
                         lower_32_bits(tba_addr >> 8));
-       WREG32(SOC15_REG_OFFSET(GC, 0, mmSQ_SHADER_TBA_HI),
+       WREG32_SOC15(GC, 0, mmSQ_SHADER_TBA_HI,
                         upper_32_bits(tba_addr >> 8));
 
         /*
          * Program TMA registers
          */
-       WREG32(SOC15_REG_OFFSET(GC, 0, mmSQ_SHADER_TMA_LO),
+       WREG32_SOC15(GC, 0, mmSQ_SHADER_TMA_LO,
                         lower_32_bits(tma_addr >> 8));
-       WREG32(SOC15_REG_OFFSET(GC, 0, mmSQ_SHADER_TMA_HI),
+       WREG32_SOC15(GC, 0, mmSQ_SHADER_TMA_HI,
                         upper_32_bits(tma_addr >> 8));
 
         unlock_srbm(adev);

--
2.25.1

#7 lore raw

PATCH 4/5 drm/amdgpu: Initialize Aldebaran RLC function pointers

In reply to Victor Skvortsov

In SRIOV, RLC function pointers must be initialized early as we rely on the RLCG interface for all GC register access.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c | 2 ++
 drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c         | 3 +--
 drivers/gpu/drm/amd/amdgpu/gfx_v9_0.h         | 2 ++
 3 files changed, 5 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c +2 -0
index 65e1f6cc59dd..1bc92a38d124 100644
@@ -844,6 +844,8 @@ static int amdgpu_discovery_set_gc_ip_blocks(struct amdgpu_device *adev)
 	case IP_VERSION(9, 4, 1):
 	case IP_VERSION(9, 4, 2):
 		amdgpu_device_ip_block_add(adev, &gfx_v9_0_ip_block);
+		if (amdgpu_sriov_vf(adev) && adev->ip_versions[GC_HWIP][0] == IP_VERSION(9, 4, 2))
+			gfx_v9_0_set_rlc_funcs(adev);
 		break;
 	case IP_VERSION(10, 1, 10):
 	case IP_VERSION(10, 1, 2):
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +1 -2
index edb3e3b08eed..d252b06efa43 100644
@@ -816,7 +816,6 @@ static void gfx_v9_0_sriov_wreg(struct amdgpu_device *adev, u32 offset,
 static void gfx_v9_0_set_ring_funcs(struct amdgpu_device *adev);
 static void gfx_v9_0_set_irq_funcs(struct amdgpu_device *adev);
 static void gfx_v9_0_set_gds_init(struct amdgpu_device *adev);
-static void gfx_v9_0_set_rlc_funcs(struct amdgpu_device *adev);
 static int gfx_v9_0_get_cu_info(struct amdgpu_device *adev,
 				struct amdgpu_cu_info *cu_info);
 static uint64_t gfx_v9_0_get_gpu_clock_counter(struct amdgpu_device *adev);
@@ -7066,7 +7065,7 @@ static void gfx_v9_0_set_irq_funcs(struct amdgpu_device *adev)
 	adev->gfx.cp_ecc_error_irq.funcs = &gfx_v9_0_cp_ecc_error_irq_funcs;
 }
 
-static void gfx_v9_0_set_rlc_funcs(struct amdgpu_device *adev)
+void gfx_v9_0_set_rlc_funcs(struct amdgpu_device *adev)
 {
 	switch (adev->ip_versions[GC_HWIP][0]) {
 	case IP_VERSION(9, 0, 1):
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.h +2 -0
index dfe8d4841f58..1817e252354f 100644
@@ -29,4 +29,6 @@ extern const struct amdgpu_ip_block_version gfx_v9_0_ip_block;
 void gfx_v9_0_select_se_sh(struct amdgpu_device *adev, u32 se_num, u32 sh_num,
 			   u32 instance);
 
+void gfx_v9_0_set_rlc_funcs(struct amdgpu_device *adev);
+
 #endif
Signature · 1 line
2.25.1
#8 lore raw

Re: [PATCH 4/5] drm/amdgpu: Initialize Aldebaran RLC function pointers

[AMD Official Use Only]

         case IP_VERSION(9, 4, 1):
         case IP_VERSION(9, 4, 2):
                 amdgpu_device_ip_block_add(adev, &gfx_v9_0_ip_block);
+               if (amdgpu_sriov_vf(adev) && adev->ip_versions[GC_HWIP][0] == IP_VERSION(9, 4, 2))
+                       gfx_v9_0_set_rlc_funcs(adev);
                 break;
         case IP_VERSION(10, 1, 10):

I think for the above, it would be more clear just to separate them:

case IP_VERSION(9, 4, 1):

    amdgpu_device_ip_block_add(adev, &gfx_v9_0_ip_block);
    break;
case IP_VERSION(9, 4, 2):
   amdgpu_device_ip_block_add(adev, &gfx_v9_0_ip_block);
   if (amdgpu_sriov_vf(adev))
       gfx_v9_0_set_rlc_funcs(adev);

break;
________________________________
From: Skvortsov, Victor <[email protected]>
Sent: Wednesday, December 15, 2021 10:55 AM
To: [email protected] <[email protected]>; Deng, Emily <[email protected]>; Liu, Monk <[email protected]>; Ming, Davis <[email protected]>; Liu, Shaoyun <[email protected]>; Zhou, Peng Ju <[email protected]>; Chen, JingWen <[email protected]>; Chen, Horace <[email protected]>; Nieto, David M <[email protected]>
Cc: Skvortsov, Victor <[email protected]>
Subject: [PATCH 4/5] drm/amdgpu: Initialize Aldebaran RLC function pointers

In SRIOV, RLC function pointers must be initialized early as we rely on the RLCG interface for all GC register access.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c | 2 ++
 drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c         | 3 +--
 drivers/gpu/drm/amd/amdgpu/gfx_v9_0.h         | 2 ++
 3 files changed, 5 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c +2 -0
index 65e1f6cc59dd..1bc92a38d124 100644
@@ -844,6 +844,8 @@ static int amdgpu_discovery_set_gc_ip_blocks(struct amdgpu_device *adev)
         case IP_VERSION(9, 4, 1):
         case IP_VERSION(9, 4, 2):
                 amdgpu_device_ip_block_add(adev, &gfx_v9_0_ip_block);
+               if (amdgpu_sriov_vf(adev) && adev->ip_versions[GC_HWIP][0] == IP_VERSION(9, 4, 2))
+                       gfx_v9_0_set_rlc_funcs(adev);
                 break;
         case IP_VERSION(10, 1, 10):
         case IP_VERSION(10, 1, 2):
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +1 -2
index edb3e3b08eed..d252b06efa43 100644
@@ -816,7 +816,6 @@ static void gfx_v9_0_sriov_wreg(struct amdgpu_device *adev, u32 offset,
 static void gfx_v9_0_set_ring_funcs(struct amdgpu_device *adev);
 static void gfx_v9_0_set_irq_funcs(struct amdgpu_device *adev);
 static void gfx_v9_0_set_gds_init(struct amdgpu_device *adev);
-static void gfx_v9_0_set_rlc_funcs(struct amdgpu_device *adev);
 static int gfx_v9_0_get_cu_info(struct amdgpu_device *adev,
                                 struct amdgpu_cu_info *cu_info);
 static uint64_t gfx_v9_0_get_gpu_clock_counter(struct amdgpu_device *adev);
@@ -7066,7 +7065,7 @@ static void gfx_v9_0_set_irq_funcs(struct amdgpu_device *adev)
         adev->gfx.cp_ecc_error_irq.funcs = &gfx_v9_0_cp_ecc_error_irq_funcs;
 }
 
-static void gfx_v9_0_set_rlc_funcs(struct amdgpu_device *adev)
+void gfx_v9_0_set_rlc_funcs(struct amdgpu_device *adev)
 {
         switch (adev->ip_versions[GC_HWIP][0]) {
         case IP_VERSION(9, 0, 1):
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.h +2 -0
index dfe8d4841f58..1817e252354f 100644
@@ -29,4 +29,6 @@ extern const struct amdgpu_ip_block_version gfx_v9_0_ip_block;
 void gfx_v9_0_select_se_sh(struct amdgpu_device *adev, u32 se_num, u32 sh_num,
                            u32 instance);
 
+void gfx_v9_0_set_rlc_funcs(struct amdgpu_device *adev);
+
 #endif

--
2.25.1

#9 lore raw

Re: [PATCH 4/5] drm/amdgpu: Initialize Aldebaran RLC function pointers

In reply to Victor Skvortsov
Quoted 16 lines · Victor Skvortsov

In SRIOV, RLC function pointers must be initialized early as we rely on the RLCG interface for all GC register access.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c | 2 ++
 drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c         | 3 +--
 drivers/gpu/drm/amd/amdgpu/gfx_v9_0.h         | 2 ++
 3 files changed, 5 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c +0 -0
index 65e1f6cc59dd..1bc92a38d124 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c static int amdgpu_discovery_set_gc_ip_blocks(struct amdgpu_device *adev) · line 848

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c +2 -0
@@ -844,6 +844,8 @@ static int amdgpu_discovery_set_gc_ip_blocks(struct amdgpu_device *adev)
        case IP_VERSION(9, 4, 1):
        case IP_VERSION(9, 4, 2):
                amdgpu_device_ip_block_add(adev, &gfx_v9_0_ip_block);
+               if (amdgpu_sriov_vf(adev) && adev->ip_versions[GC_HWIP][0] == IP_VERSION(9, 4, 2))
+                       gfx_v9_0_set_rlc_funcs(adev);

amdgpu_discovery.c is IP independent. I'd rather not add random IP specific function calls. gfx_v9_0_set_rlc_funcs() already gets called in gfx_v9_0_early_init(). Is that not early enough? In general we shouldn't be touching the hardware much if at all in early_init.

Alex

Quoted 38 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c +0 -0
                break;
        case IP_VERSION(10, 1, 10):
        case IP_VERSION(10, 1, 2):
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +1 -2
index edb3e3b08eed..d252b06efa43 100644
@@ -816,7 +816,6 @@ static void gfx_v9_0_sriov_wreg(struct amdgpu_device *adev, u32 offset,
 static void gfx_v9_0_set_ring_funcs(struct amdgpu_device *adev);
 static void gfx_v9_0_set_irq_funcs(struct amdgpu_device *adev);
 static void gfx_v9_0_set_gds_init(struct amdgpu_device *adev);
-static void gfx_v9_0_set_rlc_funcs(struct amdgpu_device *adev);
 static int gfx_v9_0_get_cu_info(struct amdgpu_device *adev,
                                struct amdgpu_cu_info *cu_info);
 static uint64_t gfx_v9_0_get_gpu_clock_counter(struct amdgpu_device *adev);
@@ -7066,7 +7065,7 @@ static void gfx_v9_0_set_irq_funcs(struct amdgpu_device *adev)
        adev->gfx.cp_ecc_error_irq.funcs = &gfx_v9_0_cp_ecc_error_irq_funcs;
 }
 
-static void gfx_v9_0_set_rlc_funcs(struct amdgpu_device *adev)
+void gfx_v9_0_set_rlc_funcs(struct amdgpu_device *adev)
 {
        switch (adev->ip_versions[GC_HWIP][0]) {
        case IP_VERSION(9, 0, 1):
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.h +2 -1
index dfe8d4841f58..1817e252354f 100644
@@ -29,4 +29,6 @@ extern const struct amdgpu_ip_block_version gfx_v9_0_ip_block;
 void gfx_v9_0_select_se_sh(struct amdgpu_device *adev, u32 se_num, u32 sh_num,
                           u32 instance);
 
+void gfx_v9_0_set_rlc_funcs(struct amdgpu_device *adev);
+
 #endif
--

2.25.1

#10 lore raw

RE: [PATCH 4/5] drm/amdgpu: Initialize Aldebaran RLC function pointers

[AMD Official Use Only]

Hey Alex,

This change was based on the fact that amd-mainline-dkms-5.13 calls get_xgmi_info() in gmc_v9_0_early_init(). But I can see that drm-next it's instead called in gmc_v9_0_sw_init(). So, I'm not sure whats the correct behavior. But I do agree that the change is kind of ugly. I don't know where else to put it if we do need to call get_xgmi_info() in early_init.

Thanks,
Victor

-----Original Message-----
From: Alex Deucher <[email protected]>
Sent: Wednesday, December 15, 2021 4:38 PM
To: Skvortsov, Victor <[email protected]>
Cc: amd-gfx list <[email protected]>; Deng, Emily <[email protected]>; Liu, Monk <[email protected]>; Ming, Davis <[email protected]>; Liu, Shaoyun <[email protected]>; Zhou, Peng Ju <[email protected]>; Chen, JingWen <[email protected]>; Chen, Horace <[email protected]>; Nieto, David M <[email protected]>
Subject: Re: [PATCH 4/5] drm/amdgpu: Initialize Aldebaran RLC function pointers

[CAUTION: External Email]

Quoted 17 lines · Victor Skvortsov

In SRIOV, RLC function pointers must be initialized early as we rely on the RLCG interface for all GC register access.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c | 2 ++
 drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c         | 3 +--
 drivers/gpu/drm/amd/amdgpu/gfx_v9_0.h         | 2 ++
 3 files changed, 5 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c +0 -0
index 65e1f6cc59dd..1bc92a38d124 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c static int amdgpu_discovery_set_gc_ip_blocks(struct amdgpu_device *adev) · line 848

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c +2 -0
@@ -844,6 +844,8 @@ static int amdgpu_discovery_set_gc_ip_blocks(struct amdgpu_device *adev)
        case IP_VERSION(9, 4, 1):
        case IP_VERSION(9, 4, 2):
                amdgpu_device_ip_block_add(adev, &gfx_v9_0_ip_block);
+               if (amdgpu_sriov_vf(adev) && adev->ip_versions[GC_HWIP][0] == IP_VERSION(9, 4, 2))
+                       gfx_v9_0_set_rlc_funcs(adev);

amdgpu_discovery.c is IP independent. I'd rather not add random IP specific function calls. gfx_v9_0_set_rlc_funcs() already gets called in gfx_v9_0_early_init(). Is that not early enough? In general we shouldn't be touching the hardware much if at all in early_init.

Alex

Quoted 40 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c +0 -0
                break;
        case IP_VERSION(10, 1, 10):
        case IP_VERSION(10, 1, 2):
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +0 -0
index edb3e3b08eed..d252b06efa43 100644
@@ -816,7 +816,6 @@ static void gfx_v9_0_sriov_wreg(struct 

amdgpu_device *adev, u32 offset, static void
gfx_v9_0_set_ring_funcs(struct amdgpu_device *adev); static void gfx_v9_0_set_irq_funcs(struct amdgpu_device *adev); static void
gfx_v9_0_set_gds_init(struct amdgpu_device *adev); -static void
gfx_v9_0_set_rlc_funcs(struct amdgpu_device *adev); static int gfx_v9_0_get_cu_info(struct amdgpu_device *adev,

                                struct amdgpu_cu_info *cu_info);  
static uint64_t gfx_v9_0_get_gpu_clock_counter(struct amdgpu_device 
*adev); @@ -7066,7 +7065,7 @@ static void gfx_v9_0_set_irq_funcs(struct amdgpu_device *adev)
        adev->gfx.cp_ecc_error_irq.funcs = 

&gfx_v9_0_cp_ecc_error_irq_funcs; }

drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +1 -1
-static void gfx_v9_0_set_rlc_funcs(struct amdgpu_device *adev)
+void gfx_v9_0_set_rlc_funcs(struct amdgpu_device *adev)
 {
        switch (adev->ip_versions[GC_HWIP][0]) {
        case IP_VERSION(9, 0, 1):
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.h +2 -1
index dfe8d4841f58..1817e252354f 100644
@@ -29,4 +29,6 @@ extern const struct amdgpu_ip_block_version 
 gfx_v9_0_ip_block;  void gfx_v9_0_select_se_sh(struct amdgpu_device *adev, u32 se_num, u32 sh_num,
                           u32 instance);
 
+void gfx_v9_0_set_rlc_funcs(struct amdgpu_device *adev);
+
 #endif
--

2.25.1

#11 lore raw

Re: [PATCH 4/5] drm/amdgpu: Initialize Aldebaran RLC function pointers

Quoted 7 lines · Victor

[AMD Official Use Only]

Hey Alex,

This change was based on the fact that amd-mainline-dkms-5.13 calls get_xgmi_info() in gmc_v9_0_early_init(). But I can see that drm-next it's instead called in gmc_v9_0_sw_init(). So, I'm not sure whats the correct behavior. But I do agree that the change is kind of ugly. I don't know where else to put it if we do need to call get_xgmi_info() in early_init.

We could skip this patch for drm-next and just apply it to the dkms branch. There's already a lot of ugly stuff in there to deal with multiple kernel versions.

Alex

Quoted 80 lines

Thanks,
Victor

-----Original Message-----
From: Alex Deucher <[email protected]>
Sent: Wednesday, December 15, 2021 4:38 PM
To: Skvortsov, Victor <[email protected]>
Cc: amd-gfx list <[email protected]>; Deng, Emily <[email protected]>; Liu, Monk <[email protected]>; Ming, Davis <[email protected]>; Liu, Shaoyun <[email protected]>; Zhou, Peng Ju <[email protected]>; Chen, JingWen <[email protected]>; Chen, Horace <[email protected]>; Nieto, David M <[email protected]>
Subject: Re: [PATCH 4/5] drm/amdgpu: Initialize Aldebaran RLC function pointers

[CAUTION: External Email]

Quoted 17 lines · Victor Skvortsov

In SRIOV, RLC function pointers must be initialized early as we rely on the RLCG interface for all GC register access.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c | 2 ++
 drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c         | 3 +--
 drivers/gpu/drm/amd/amdgpu/gfx_v9_0.h         | 2 ++
 3 files changed, 5 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c +0 -0
index 65e1f6cc59dd..1bc92a38d124 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c static int amdgpu_discovery_set_gc_ip_blocks(struct amdgpu_device *adev) · line 848

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c +2 -0
@@ -844,6 +844,8 @@ static int amdgpu_discovery_set_gc_ip_blocks(struct amdgpu_device *adev)
        case IP_VERSION(9, 4, 1):
        case IP_VERSION(9, 4, 2):
                amdgpu_device_ip_block_add(adev, &gfx_v9_0_ip_block);
+               if (amdgpu_sriov_vf(adev) && adev->ip_versions[GC_HWIP][0] == IP_VERSION(9, 4, 2))
+                       gfx_v9_0_set_rlc_funcs(adev);

amdgpu_discovery.c is IP independent. I'd rather not add random IP specific function calls. gfx_v9_0_set_rlc_funcs() already gets called in gfx_v9_0_early_init(). Is that not early enough? In general we shouldn't be touching the hardware much if at all in early_init.

Alex

Quoted 40 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c +0 -0
                break;
        case IP_VERSION(10, 1, 10):
        case IP_VERSION(10, 1, 2):
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +0 -0
index edb3e3b08eed..d252b06efa43 100644
@@ -816,7 +816,6 @@ static void gfx_v9_0_sriov_wreg(struct

amdgpu_device *adev, u32 offset, static void
gfx_v9_0_set_ring_funcs(struct amdgpu_device *adev); static void gfx_v9_0_set_irq_funcs(struct amdgpu_device *adev); static void
gfx_v9_0_set_gds_init(struct amdgpu_device *adev); -static void
gfx_v9_0_set_rlc_funcs(struct amdgpu_device *adev); static int gfx_v9_0_get_cu_info(struct amdgpu_device *adev,

                                struct amdgpu_cu_info *cu_info);
static uint64_t gfx_v9_0_get_gpu_clock_counter(struct amdgpu_device
*adev); @@ -7066,7 +7065,7 @@ static void gfx_v9_0_set_irq_funcs(struct amdgpu_device *adev)
        adev->gfx.cp_ecc_error_irq.funcs =

&gfx_v9_0_cp_ecc_error_irq_funcs; }

drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +1 -1
-static void gfx_v9_0_set_rlc_funcs(struct amdgpu_device *adev)
+void gfx_v9_0_set_rlc_funcs(struct amdgpu_device *adev)
 {
        switch (adev->ip_versions[GC_HWIP][0]) {
        case IP_VERSION(9, 0, 1):
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.h +2 -1
index dfe8d4841f58..1817e252354f 100644
@@ -29,4 +29,6 @@ extern const struct amdgpu_ip_block_version
 gfx_v9_0_ip_block;  void gfx_v9_0_select_se_sh(struct amdgpu_device *adev, u32 se_num, u32 sh_num,
                           u32 instance);
 
+void gfx_v9_0_set_rlc_funcs(struct amdgpu_device *adev);
+
 #endif
--

2.25.1

#12 lore raw

RE: [PATCH 4/5] drm/amdgpu: Initialize Aldebaran RLC function pointers

[AMD Official Use Only]

Gotcha, I will skip this patch for drm-next

-----Original Message-----
From: Alex Deucher <[email protected]>
Sent: Thursday, December 16, 2021 8:53 AM
To: Skvortsov, Victor <[email protected]>
Cc: amd-gfx list <[email protected]>; Deng, Emily <[email protected]>; Liu, Monk <[email protected]>; Ming, Davis <[email protected]>; Liu, Shaoyun <[email protected]>; Zhou, Peng Ju <[email protected]>; Chen, JingWen <[email protected]>; Chen, Horace <[email protected]>; Nieto, David M <[email protected]>
Subject: Re: [PATCH 4/5] drm/amdgpu: Initialize Aldebaran RLC function pointers

[CAUTION: External Email]

Quoted 7 lines · Victor

[AMD Official Use Only]

Hey Alex,

This change was based on the fact that amd-mainline-dkms-5.13 calls get_xgmi_info() in gmc_v9_0_early_init(). But I can see that drm-next it's instead called in gmc_v9_0_sw_init(). So, I'm not sure whats the correct behavior. But I do agree that the change is kind of ugly. I don't know where else to put it if we do need to call get_xgmi_info() in early_init.

We could skip this patch for drm-next and just apply it to the dkms branch. There's already a lot of ugly stuff in there to deal with multiple kernel versions.

Alex

Quoted 86 lines

Thanks,
Victor

-----Original Message-----
From: Alex Deucher <[email protected]>
Sent: Wednesday, December 15, 2021 4:38 PM
To: Skvortsov, Victor <[email protected]>
Cc: amd-gfx list <[email protected]>; Deng, Emily <[email protected]>; Liu, Monk <[email protected]>; Ming, Davis <[email protected]>; Liu, Shaoyun <[email protected]>; Zhou, Peng Ju <[email protected]>; Chen, JingWen <[email protected]>; Chen, Horace <[email protected]>; Nieto, David M <[email protected]>
Subject: Re: [PATCH 4/5] drm/amdgpu: Initialize Aldebaran RLC function pointers

[CAUTION: External Email]

Quoted 17 lines · Victor Skvortsov

In SRIOV, RLC function pointers must be initialized early as we rely on the RLCG interface for all GC register access.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c | 2 ++
 drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c         | 3 +--
 drivers/gpu/drm/amd/amdgpu/gfx_v9_0.h         | 2 ++
 3 files changed, 5 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c +0 -0
index 65e1f6cc59dd..1bc92a38d124 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c static int amdgpu_discovery_set_gc_ip_blocks(struct amdgpu_device *adev) · line 849

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c +2 -0
@@ -844,6 +844,8 @@ static int amdgpu_discovery_set_gc_ip_blocks(struct amdgpu_device *adev)
        case IP_VERSION(9, 4, 1):
        case IP_VERSION(9, 4, 2):
                amdgpu_device_ip_block_add(adev, 
 &gfx_v9_0_ip_block);
+               if (amdgpu_sriov_vf(adev) && adev->ip_versions[GC_HWIP][0] == IP_VERSION(9, 4, 2))
+                       gfx_v9_0_set_rlc_funcs(adev);

amdgpu_discovery.c is IP independent. I'd rather not add random IP specific function calls. gfx_v9_0_set_rlc_funcs() already gets called in gfx_v9_0_early_init(). Is that not early enough? In general we shouldn't be touching the hardware much if at all in early_init.

Alex

Quoted 40 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c +0 -0
                break;
        case IP_VERSION(10, 1, 10):
        case IP_VERSION(10, 1, 2):
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +0 -0
index edb3e3b08eed..d252b06efa43 100644
@@ -816,7 +816,6 @@ static void gfx_v9_0_sriov_wreg(struct 

amdgpu_device *adev, u32 offset, static void
gfx_v9_0_set_ring_funcs(struct amdgpu_device *adev); static void gfx_v9_0_set_irq_funcs(struct amdgpu_device *adev); static void
gfx_v9_0_set_gds_init(struct amdgpu_device *adev); -static void
gfx_v9_0_set_rlc_funcs(struct amdgpu_device *adev); static int gfx_v9_0_get_cu_info(struct amdgpu_device *adev,

                                struct amdgpu_cu_info *cu_info); 
static uint64_t gfx_v9_0_get_gpu_clock_counter(struct amdgpu_device 
*adev); @@ -7066,7 +7065,7 @@ static void gfx_v9_0_set_irq_funcs(struct amdgpu_device *adev)
        adev->gfx.cp_ecc_error_irq.funcs = 

&gfx_v9_0_cp_ecc_error_irq_funcs; }

drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +1 -1
-static void gfx_v9_0_set_rlc_funcs(struct amdgpu_device *adev)
+void gfx_v9_0_set_rlc_funcs(struct amdgpu_device *adev)
 {
        switch (adev->ip_versions[GC_HWIP][0]) {
        case IP_VERSION(9, 0, 1):
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.h +2 -1
index dfe8d4841f58..1817e252354f 100644
@@ -29,4 +29,6 @@ extern const struct amdgpu_ip_block_version 
 gfx_v9_0_ip_block;  void gfx_v9_0_select_se_sh(struct amdgpu_device *adev, u32 se_num, u32 sh_num,
                           u32 instance);
 
+void gfx_v9_0_set_rlc_funcs(struct amdgpu_device *adev);
+
 #endif
--

2.25.1

Acked-by Alex Deucher
#13 lore raw

RE: [PATCH 4/5] drm/amdgpu: Initialize Aldebaran RLC function pointers

[Public]

Hi Victor,

calling get_xgmi_info() in gmc_v9_0_early_init is from below patch, which also sent out to amd-gfx for review as a upstream patch. Do you know why it's missed from upstream?

drm/amdgpu: get xgmi info at eary_init

Driver need to get XGMI info function earlier before ip_init since driver need to check the XGMI setting to determine how to perform reset during init

Change-Id Ic37276bbb6640bb4e9360220fed99494cedd3ef5

Regards,
Guchun

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Skvortsov, Victor
Sent: Thursday, December 16, 2021 10:28 PM
To: Alex Deucher <[email protected]>
Cc: Ming, Davis <[email protected]>; Chen, JingWen <[email protected]>; amd-gfx list <[email protected]>; Deng, Emily <[email protected]>; Nieto, David M <[email protected]>; Chen, Horace <[email protected]>; Liu, Monk <[email protected]>; Liu, Shaoyun <[email protected]>
Subject: RE: [PATCH 4/5] drm/amdgpu: Initialize Aldebaran RLC function pointers

[AMD Official Use Only]

Gotcha, I will skip this patch for drm-next

-----Original Message-----
From: Alex Deucher <[email protected]>
Sent: Thursday, December 16, 2021 8:53 AM
To: Skvortsov, Victor <[email protected]>
Cc: amd-gfx list <[email protected]>; Deng, Emily <[email protected]>; Liu, Monk <[email protected]>; Ming, Davis <[email protected]>; Liu, Shaoyun <[email protected]>; Zhou, Peng Ju <[email protected]>; Chen, JingWen <[email protected]>; Chen, Horace <[email protected]>; Nieto, David M <[email protected]>
Subject: Re: [PATCH 4/5] drm/amdgpu: Initialize Aldebaran RLC function pointers

[CAUTION: External Email]

Quoted 7 lines · Victor

[AMD Official Use Only]

Hey Alex,

This change was based on the fact that amd-mainline-dkms-5.13 calls get_xgmi_info() in gmc_v9_0_early_init(). But I can see that drm-next it's instead called in gmc_v9_0_sw_init(). So, I'm not sure whats the correct behavior. But I do agree that the change is kind of ugly. I don't know where else to put it if we do need to call get_xgmi_info() in early_init.

We could skip this patch for drm-next and just apply it to the dkms branch. There's already a lot of ugly stuff in there to deal with multiple kernel versions.

Alex

Quoted 86 lines

Thanks,
Victor

-----Original Message-----
From: Alex Deucher <[email protected]>
Sent: Wednesday, December 15, 2021 4:38 PM
To: Skvortsov, Victor <[email protected]>
Cc: amd-gfx list <[email protected]>; Deng, Emily <[email protected]>; Liu, Monk <[email protected]>; Ming, Davis <[email protected]>; Liu, Shaoyun <[email protected]>; Zhou, Peng Ju <[email protected]>; Chen, JingWen <[email protected]>; Chen, Horace <[email protected]>; Nieto, David M <[email protected]>
Subject: Re: [PATCH 4/5] drm/amdgpu: Initialize Aldebaran RLC function pointers

[CAUTION: External Email]

Quoted 17 lines · Victor Skvortsov

In SRIOV, RLC function pointers must be initialized early as we rely on the RLCG interface for all GC register access.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c | 2 ++
 drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c         | 3 +--
 drivers/gpu/drm/amd/amdgpu/gfx_v9_0.h         | 2 ++
 3 files changed, 5 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c +0 -0
index 65e1f6cc59dd..1bc92a38d124 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c static int amdgpu_discovery_set_gc_ip_blocks(struct amdgpu_device *adev) · line 849

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c +2 -0
@@ -844,6 +844,8 @@ static int amdgpu_discovery_set_gc_ip_blocks(struct amdgpu_device *adev)
        case IP_VERSION(9, 4, 1):
        case IP_VERSION(9, 4, 2):
                amdgpu_device_ip_block_add(adev, 
 &gfx_v9_0_ip_block);
+               if (amdgpu_sriov_vf(adev) && adev->ip_versions[GC_HWIP][0] == IP_VERSION(9, 4, 2))
+                       gfx_v9_0_set_rlc_funcs(adev);

amdgpu_discovery.c is IP independent. I'd rather not add random IP specific function calls. gfx_v9_0_set_rlc_funcs() already gets called in gfx_v9_0_early_init(). Is that not early enough? In general we shouldn't be touching the hardware much if at all in early_init.

Alex

Quoted 40 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c +0 -0
                break;
        case IP_VERSION(10, 1, 10):
        case IP_VERSION(10, 1, 2):
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +0 -0
index edb3e3b08eed..d252b06efa43 100644
@@ -816,7 +816,6 @@ static void gfx_v9_0_sriov_wreg(struct 

amdgpu_device *adev, u32 offset, static void
gfx_v9_0_set_ring_funcs(struct amdgpu_device *adev); static void gfx_v9_0_set_irq_funcs(struct amdgpu_device *adev); static void
gfx_v9_0_set_gds_init(struct amdgpu_device *adev); -static void
gfx_v9_0_set_rlc_funcs(struct amdgpu_device *adev); static int gfx_v9_0_get_cu_info(struct amdgpu_device *adev,

                                struct amdgpu_cu_info *cu_info); 
static uint64_t gfx_v9_0_get_gpu_clock_counter(struct amdgpu_device 
*adev); @@ -7066,7 +7065,7 @@ static void gfx_v9_0_set_irq_funcs(struct amdgpu_device *adev)
        adev->gfx.cp_ecc_error_irq.funcs = 

&gfx_v9_0_cp_ecc_error_irq_funcs; }

drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +1 -1
-static void gfx_v9_0_set_rlc_funcs(struct amdgpu_device *adev)
+void gfx_v9_0_set_rlc_funcs(struct amdgpu_device *adev)
 {
        switch (adev->ip_versions[GC_HWIP][0]) {
        case IP_VERSION(9, 0, 1):
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.h +2 -1
index dfe8d4841f58..1817e252354f 100644
@@ -29,4 +29,6 @@ extern const struct amdgpu_ip_block_version 
 gfx_v9_0_ip_block;  void gfx_v9_0_select_se_sh(struct amdgpu_device *adev, u32 se_num, u32 sh_num,
                           u32 instance);
 
+void gfx_v9_0_set_rlc_funcs(struct amdgpu_device *adev);
+
 #endif
--

2.25.1

#14 lore raw

RE: [PATCH 4/5] drm/amdgpu: Initialize Aldebaran RLC function pointers

In reply to Skvortsov, Victor

[AMD Official Use Only]

Actually I don't know why the change " a35f147621bc drm/amdgpu: get xgmi info at eary_init " not in drm-next , instead it’s in amd-mainline-dkms-5.13. That change is necessary for passthrough XGMI hive to a VM and rely on our driver to do the reset on whole hive when driver is loaded .

I checked the code again, it seems we should be ok as long as we get xgmi info at eary_init. So since gfx_v9_0_set_rlc_funcs() already gets called in gfx_v9_0_early_init(), we can move get xgmi info out of gmc_early_init and call it at the last step early_init .

Regards
Shaoyun.liu

-----Original Message-----
From: Skvortsov, Victor <[email protected]>
Sent: Thursday, December 16, 2021 9:28 AM
To: Alex Deucher <[email protected]>
Cc: amd-gfx list <[email protected]>; Deng, Emily <[email protected]>; Liu, Monk <[email protected]>; Ming, Davis <[email protected]>; Liu, Shaoyun <[email protected]>; Zhou, Peng Ju <[email protected]>; Chen, JingWen <[email protected]>; Chen, Horace <[email protected]>; Nieto, David M <[email protected]>
Subject: RE: [PATCH 4/5] drm/amdgpu: Initialize Aldebaran RLC function pointers

[AMD Official Use Only]

Gotcha, I will skip this patch for drm-next

-----Original Message-----
From: Alex Deucher <[email protected]>
Sent: Thursday, December 16, 2021 8:53 AM
To: Skvortsov, Victor <[email protected]>
Cc: amd-gfx list <[email protected]>; Deng, Emily <[email protected]>; Liu, Monk <[email protected]>; Ming, Davis <[email protected]>; Liu, Shaoyun <[email protected]>; Zhou, Peng Ju <[email protected]>; Chen, JingWen <[email protected]>; Chen, Horace <[email protected]>; Nieto, David M <[email protected]>
Subject: Re: [PATCH 4/5] drm/amdgpu: Initialize Aldebaran RLC function pointers

[CAUTION: External Email]

Quoted 7 lines · Victor

[AMD Official Use Only]

Hey Alex,

This change was based on the fact that amd-mainline-dkms-5.13 calls get_xgmi_info() in gmc_v9_0_early_init(). But I can see that drm-next it's instead called in gmc_v9_0_sw_init(). So, I'm not sure whats the correct behavior. But I do agree that the change is kind of ugly. I don't know where else to put it if we do need to call get_xgmi_info() in early_init.

We could skip this patch for drm-next and just apply it to the dkms branch. There's already a lot of ugly stuff in there to deal with multiple kernel versions.

Alex

Quoted 86 lines

Thanks,
Victor

-----Original Message-----
From: Alex Deucher <[email protected]>
Sent: Wednesday, December 15, 2021 4:38 PM
To: Skvortsov, Victor <[email protected]>
Cc: amd-gfx list <[email protected]>; Deng, Emily <[email protected]>; Liu, Monk <[email protected]>; Ming, Davis <[email protected]>; Liu, Shaoyun <[email protected]>; Zhou, Peng Ju <[email protected]>; Chen, JingWen <[email protected]>; Chen, Horace <[email protected]>; Nieto, David M <[email protected]>
Subject: Re: [PATCH 4/5] drm/amdgpu: Initialize Aldebaran RLC function pointers

[CAUTION: External Email]

Quoted 17 lines · Victor Skvortsov

In SRIOV, RLC function pointers must be initialized early as we rely on the RLCG interface for all GC register access.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c | 2 ++
 drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c         | 3 +--
 drivers/gpu/drm/amd/amdgpu/gfx_v9_0.h         | 2 ++
 3 files changed, 5 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c +0 -0
index 65e1f6cc59dd..1bc92a38d124 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c static int amdgpu_discovery_set_gc_ip_blocks(struct amdgpu_device *adev) · line 849

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c +2 -0
@@ -844,6 +844,8 @@ static int amdgpu_discovery_set_gc_ip_blocks(struct amdgpu_device *adev)
        case IP_VERSION(9, 4, 1):
        case IP_VERSION(9, 4, 2):
                amdgpu_device_ip_block_add(adev, 
 &gfx_v9_0_ip_block);
+               if (amdgpu_sriov_vf(adev) && adev->ip_versions[GC_HWIP][0] == IP_VERSION(9, 4, 2))
+                       gfx_v9_0_set_rlc_funcs(adev);

amdgpu_discovery.c is IP independent. I'd rather not add random IP specific function calls. gfx_v9_0_set_rlc_funcs() already gets called in gfx_v9_0_early_init(). Is that not early enough? In general we shouldn't be touching the hardware much if at all in early_init.

Alex

Quoted 40 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c +0 -0
                break;
        case IP_VERSION(10, 1, 10):
        case IP_VERSION(10, 1, 2):
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +0 -0
index edb3e3b08eed..d252b06efa43 100644
@@ -816,7 +816,6 @@ static void gfx_v9_0_sriov_wreg(struct 

amdgpu_device *adev, u32 offset, static void
gfx_v9_0_set_ring_funcs(struct amdgpu_device *adev); static void gfx_v9_0_set_irq_funcs(struct amdgpu_device *adev); static void
gfx_v9_0_set_gds_init(struct amdgpu_device *adev); -static void
gfx_v9_0_set_rlc_funcs(struct amdgpu_device *adev); static int gfx_v9_0_get_cu_info(struct amdgpu_device *adev,

                                struct amdgpu_cu_info *cu_info); 
static uint64_t gfx_v9_0_get_gpu_clock_counter(struct amdgpu_device 
*adev); @@ -7066,7 +7065,7 @@ static void gfx_v9_0_set_irq_funcs(struct amdgpu_device *adev)
        adev->gfx.cp_ecc_error_irq.funcs = 

&gfx_v9_0_cp_ecc_error_irq_funcs; }

drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +1 -1
-static void gfx_v9_0_set_rlc_funcs(struct amdgpu_device *adev)
+void gfx_v9_0_set_rlc_funcs(struct amdgpu_device *adev)
 {
        switch (adev->ip_versions[GC_HWIP][0]) {
        case IP_VERSION(9, 0, 1):
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.h +2 -1
index dfe8d4841f58..1817e252354f 100644
@@ -29,4 +29,6 @@ extern const struct amdgpu_ip_block_version 
 gfx_v9_0_ip_block;  void gfx_v9_0_select_se_sh(struct amdgpu_device *adev, u32 se_num, u32 sh_num,
                           u32 instance);
 
+void gfx_v9_0_set_rlc_funcs(struct amdgpu_device *adev);
+
 #endif
--

2.25.1

#15 lore raw

Re: [PATCH 4/5] drm/amdgpu: Initialize Aldebaran RLC function pointers

[Public]

If it needs to be in drm-next, please make sure it lands there.

Alex

________________________________
From: amd-gfx <[email protected]> on behalf of Liu, Shaoyun <[email protected]>
Sent: Thursday, December 16, 2021 12:51 PM
To: Skvortsov, Victor <[email protected]>; Alex Deucher <[email protected]>
Cc: Ming, Davis <[email protected]>; Chen, JingWen <[email protected]>; amd-gfx list <[email protected]>; Deng, Emily <[email protected]>; Chen, Horace <[email protected]>; Liu, Monk <[email protected]>; Nieto, David M <[email protected]>
Subject: RE: [PATCH 4/5] drm/amdgpu: Initialize Aldebaran RLC function pointers

[AMD Official Use Only]

Actually I don't know why the change " a35f147621bc drm/amdgpu: get xgmi info at eary_init " not in drm-next , instead it’s in amd-mainline-dkms-5.13. That change is necessary for passthrough XGMI hive to a VM and rely on our driver to do the reset on whole hive when driver is loaded .

I checked the code again, it seems we should be ok as long as we get xgmi info at eary_init. So since gfx_v9_0_set_rlc_funcs() already gets called in gfx_v9_0_early_init(), we can move get xgmi info out of gmc_early_init and call it at the last step early_init .

Regards
Shaoyun.liu

-----Original Message-----
From: Skvortsov, Victor <[email protected]>
Sent: Thursday, December 16, 2021 9:28 AM
To: Alex Deucher <[email protected]>
Cc: amd-gfx list <[email protected]>; Deng, Emily <[email protected]>; Liu, Monk <[email protected]>; Ming, Davis <[email protected]>; Liu, Shaoyun <[email protected]>; Zhou, Peng Ju <[email protected]>; Chen, JingWen <[email protected]>; Chen, Horace <[email protected]>; Nieto, David M <[email protected]>
Subject: RE: [PATCH 4/5] drm/amdgpu: Initialize Aldebaran RLC function pointers

[AMD Official Use Only]

Gotcha, I will skip this patch for drm-next

-----Original Message-----
From: Alex Deucher <[email protected]>
Sent: Thursday, December 16, 2021 8:53 AM
To: Skvortsov, Victor <[email protected]>
Cc: amd-gfx list <[email protected]>; Deng, Emily <[email protected]>; Liu, Monk <[email protected]>; Ming, Davis <[email protected]>; Liu, Shaoyun <[email protected]>; Zhou, Peng Ju <[email protected]>; Chen, JingWen <[email protected]>; Chen, Horace <[email protected]>; Nieto, David M <[email protected]>
Subject: Re: [PATCH 4/5] drm/amdgpu: Initialize Aldebaran RLC function pointers

[CAUTION: External Email]

Quoted 7 lines · Victor

[AMD Official Use Only]

Hey Alex,

This change was based on the fact that amd-mainline-dkms-5.13 calls get_xgmi_info() in gmc_v9_0_early_init(). But I can see that drm-next it's instead called in gmc_v9_0_sw_init(). So, I'm not sure whats the correct behavior. But I do agree that the change is kind of ugly. I don't know where else to put it if we do need to call get_xgmi_info() in early_init.

We could skip this patch for drm-next and just apply it to the dkms branch. There's already a lot of ugly stuff in there to deal with multiple kernel versions.

Alex

Quoted 86 lines

Thanks,
Victor

-----Original Message-----
From: Alex Deucher <[email protected]>
Sent: Wednesday, December 15, 2021 4:38 PM
To: Skvortsov, Victor <[email protected]>
Cc: amd-gfx list <[email protected]>; Deng, Emily <[email protected]>; Liu, Monk <[email protected]>; Ming, Davis <[email protected]>; Liu, Shaoyun <[email protected]>; Zhou, Peng Ju <[email protected]>; Chen, JingWen <[email protected]>; Chen, Horace <[email protected]>; Nieto, David M <[email protected]>
Subject: Re: [PATCH 4/5] drm/amdgpu: Initialize Aldebaran RLC function pointers

[CAUTION: External Email]

Quoted 17 lines · Victor Skvortsov

In SRIOV, RLC function pointers must be initialized early as we rely on the RLCG interface for all GC register access.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c | 2 ++
 drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c         | 3 +--
 drivers/gpu/drm/amd/amdgpu/gfx_v9_0.h         | 2 ++
 3 files changed, 5 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c +0 -0
index 65e1f6cc59dd..1bc92a38d124 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c static int amdgpu_discovery_set_gc_ip_blocks(struct amdgpu_device *adev) · line 849

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c +2 -0
@@ -844,6 +844,8 @@ static int amdgpu_discovery_set_gc_ip_blocks(struct amdgpu_device *adev)
        case IP_VERSION(9, 4, 1):
        case IP_VERSION(9, 4, 2):
                amdgpu_device_ip_block_add(adev,
 &gfx_v9_0_ip_block);
+               if (amdgpu_sriov_vf(adev) && adev->ip_versions[GC_HWIP][0] == IP_VERSION(9, 4, 2))
+                       gfx_v9_0_set_rlc_funcs(adev);

amdgpu_discovery.c is IP independent. I'd rather not add random IP specific function calls. gfx_v9_0_set_rlc_funcs() already gets called in gfx_v9_0_early_init(). Is that not early enough? In general we shouldn't be touching the hardware much if at all in early_init.

Alex

Quoted 40 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c +0 -0
                break;
        case IP_VERSION(10, 1, 10):
        case IP_VERSION(10, 1, 2):
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +0 -0
index edb3e3b08eed..d252b06efa43 100644
@@ -816,7 +816,6 @@ static void gfx_v9_0_sriov_wreg(struct

amdgpu_device *adev, u32 offset, static void
gfx_v9_0_set_ring_funcs(struct amdgpu_device *adev); static void gfx_v9_0_set_irq_funcs(struct amdgpu_device *adev); static void
gfx_v9_0_set_gds_init(struct amdgpu_device *adev); -static void
gfx_v9_0_set_rlc_funcs(struct amdgpu_device *adev); static int gfx_v9_0_get_cu_info(struct amdgpu_device *adev,

                                struct amdgpu_cu_info *cu_info);
static uint64_t gfx_v9_0_get_gpu_clock_counter(struct amdgpu_device
*adev); @@ -7066,7 +7065,7 @@ static void gfx_v9_0_set_irq_funcs(struct amdgpu_device *adev)
        adev->gfx.cp_ecc_error_irq.funcs =

&gfx_v9_0_cp_ecc_error_irq_funcs; }

drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +1 -1
-static void gfx_v9_0_set_rlc_funcs(struct amdgpu_device *adev)
+void gfx_v9_0_set_rlc_funcs(struct amdgpu_device *adev)
 {
        switch (adev->ip_versions[GC_HWIP][0]) {
        case IP_VERSION(9, 0, 1):
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.h +2 -1
index dfe8d4841f58..1817e252354f 100644
@@ -29,4 +29,6 @@ extern const struct amdgpu_ip_block_version
 gfx_v9_0_ip_block;  void gfx_v9_0_select_se_sh(struct amdgpu_device *adev, u32 se_num, u32 sh_num,
                           u32 instance);
 
+void gfx_v9_0_set_rlc_funcs(struct amdgpu_device *adev);
+
 #endif
--

2.25.1

#16 lore raw

PATCH 5/5 drm/amdgpu: Modify indirect register access for gfx9 sriov

In reply to Victor Skvortsov

Expand RLCG interface for new GC read & write commands.
New interface will only be used if the PF enables the flag in pf2vf msg.

---
 drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c | 111 +++++++++++++++++++-------
 1 file changed, 83 insertions(+), 28 deletions(-)
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +83 -28
index d252b06efa43..bce6ab52cae0 100644
@@ -63,6 +63,13 @@
 #define mmGCEA_PROBE_MAP                        0x070c
 #define mmGCEA_PROBE_MAP_BASE_IDX               0
 
+#define GFX9_RLCG_GC_WRITE_OLD			(0x8 << 28)
+#define GFX9_RLCG_GC_WRITE			(0x0 << 28)
+#define GFX9_RLCG_GC_READ			(0x1 << 28)
+#define GFX9_RLCG_VFGATE_DISABLED		0x4000000
+#define GFX9_RLCG_WRONG_OPERATION_TYPE		0x2000000
+#define GFX9_RLCG_NOT_IN_RANGE			0x1000000
+
 MODULE_FIRMWARE("amdgpu/vega10_ce.bin");
 MODULE_FIRMWARE("amdgpu/vega10_pfp.bin");
 MODULE_FIRMWARE("amdgpu/vega10_me.bin");
@@ -739,7 +746,7 @@ static const u32 GFX_RLC_SRM_INDEX_CNTL_DATA_OFFSETS[] =
 	mmRLC_SRM_INDEX_CNTL_DATA_7 - mmRLC_SRM_INDEX_CNTL_DATA_0,
 };
 
-static void gfx_v9_0_rlcg_w(struct amdgpu_device *adev, u32 offset, u32 v, u32 flag)
+static u32 gfx_v9_0_rlcg_rw(struct amdgpu_device *adev, u32 offset, u32 v, uint32_t flag)
 {
 	static void *scratch_reg0;
 	static void *scratch_reg1;
@@ -748,21 +755,20 @@ static void gfx_v9_0_rlcg_w(struct amdgpu_device *adev, u32 offset, u32 v, u32 f
 	static void *spare_int;
 	static uint32_t grbm_cntl;
 	static uint32_t grbm_idx;
+	uint32_t i = 0;
+	uint32_t retries = 50000;
+	u32 ret = 0;
+	u32 tmp;
 
 	scratch_reg0 = adev->rmmio + (adev->reg_offset[GC_HWIP][0][mmSCRATCH_REG0_BASE_IDX] + mmSCRATCH_REG0)*4;
 	scratch_reg1 = adev->rmmio + (adev->reg_offset[GC_HWIP][0][mmSCRATCH_REG1_BASE_IDX] + mmSCRATCH_REG1)*4;
-	scratch_reg2 = adev->rmmio + (adev->reg_offset[GC_HWIP][0][mmSCRATCH_REG1_BASE_IDX] + mmSCRATCH_REG2)*4;
-	scratch_reg3 = adev->rmmio + (adev->reg_offset[GC_HWIP][0][mmSCRATCH_REG1_BASE_IDX] + mmSCRATCH_REG3)*4;
+	scratch_reg2 = adev->rmmio + (adev->reg_offset[GC_HWIP][0][mmSCRATCH_REG2_BASE_IDX] + mmSCRATCH_REG2)*4;
+	scratch_reg3 = adev->rmmio + (adev->reg_offset[GC_HWIP][0][mmSCRATCH_REG3_BASE_IDX] + mmSCRATCH_REG3)*4;
 	spare_int = adev->rmmio + (adev->reg_offset[GC_HWIP][0][mmRLC_SPARE_INT_BASE_IDX] + mmRLC_SPARE_INT)*4;
 
 	grbm_cntl = adev->reg_offset[GC_HWIP][0][mmGRBM_GFX_CNTL_BASE_IDX] + mmGRBM_GFX_CNTL;
 	grbm_idx = adev->reg_offset[GC_HWIP][0][mmGRBM_GFX_INDEX_BASE_IDX] + mmGRBM_GFX_INDEX;
 
-	if (amdgpu_sriov_runtime(adev)) {
-		pr_err("shouldn't call rlcg write register during runtime\n");
-		return;
-	}
-
 	if (offset == grbm_cntl || offset == grbm_idx) {
 		if (offset  == grbm_cntl)
 			writel(v, scratch_reg2);
@@ -771,41 +777,89 @@ static void gfx_v9_0_rlcg_w(struct amdgpu_device *adev, u32 offset, u32 v, u32 f
 
 		writel(v, ((void __iomem *)adev->rmmio) + (offset * 4));
 	} else {
-		uint32_t i = 0;
-		uint32_t retries = 50000;
-
 		writel(v, scratch_reg0);
-		writel(offset | 0x80000000, scratch_reg1);
+		writel(offset | flag, scratch_reg1);
 		writel(1, spare_int);
-		for (i = 0; i < retries; i++) {
-			u32 tmp;
 
+		for (i = 0; i < retries; i++) {
 			tmp = readl(scratch_reg1);
-			if (!(tmp & 0x80000000))
+			if (!(tmp & flag))
 				break;
 
 			udelay(10);
 		}
-		if (i >= retries)
-			pr_err("timeout: rlcg program reg:0x%05x failed !\n", offset);
+
+		if (i >= retries) {
+			if (amdgpu_sriov_reg_indirect_gc(adev)) {
+				if (tmp & GFX9_RLCG_VFGATE_DISABLED)
+					pr_err("The vfgate is disabled, program reg:0x%05x failed!\n", offset);
+				else if (tmp & GFX9_RLCG_WRONG_OPERATION_TYPE)
+					pr_err("Wrong operation type, program reg:0x%05x failed!\n", offset);
+				else if (tmp & GFX9_RLCG_NOT_IN_RANGE)
+					pr_err("The register is not in range, program reg:0x%05x failed!\n", offset);
+				else
+					pr_err("Unknown error type, program reg:0x%05x failed!\n", offset);
+			} else
+				pr_err("timeout: rlcg program reg:0x%05x failed!\n", offset);
+		}
+	}
+
+	ret = readl(scratch_reg0);
+
+	return ret;
+}
+
+static bool gfx_v9_0_get_rlcg_flag(struct amdgpu_device *adev, u32 acc_flags, u32 hwip,
+				int write, u32 *rlcg_flag)
+{
+
+	switch (hwip) {
+	case GC_HWIP:
+		if (amdgpu_sriov_reg_indirect_gc(adev)) {
+			*rlcg_flag = write ? GFX9_RLCG_GC_WRITE : GFX9_RLCG_GC_READ;
+
+			return true;
+		/* only in new version, AMDGPU_REGS_NO_KIQ and AMDGPU_REGS_RLC enabled simultaneously */
+		} else if ((acc_flags & AMDGPU_REGS_RLC) && !(acc_flags & AMDGPU_REGS_NO_KIQ) && write) {
+			*rlcg_flag = GFX9_RLCG_GC_WRITE_OLD;
+			return true;
+		}
+
+		break;
+	default:
+		return false;
 	}
 
+	return false;
+}
+
+static u32 gfx_v9_0_sriov_rreg(struct amdgpu_device *adev, u32 offset, u32 acc_flags, u32 hwip)
+{
+	u32 rlcg_flag;
+
+	if (!amdgpu_sriov_runtime(adev) && gfx_v9_0_get_rlcg_flag(adev, acc_flags, hwip, 0, &rlcg_flag))
+		return gfx_v9_0_rlcg_rw(adev, offset, 0, rlcg_flag);
+
+	if (acc_flags & AMDGPU_REGS_NO_KIQ)
+		return RREG32_NO_KIQ(offset);
+	else
+		return RREG32(offset);
 }
 
 static void gfx_v9_0_sriov_wreg(struct amdgpu_device *adev, u32 offset,
-			       u32 v, u32 acc_flags, u32 hwip)
+			       u32 value, u32 acc_flags, u32 hwip)
 {
-	if ((acc_flags & AMDGPU_REGS_RLC) &&
-	    amdgpu_sriov_fullaccess(adev)) {
-		gfx_v9_0_rlcg_w(adev, offset, v, acc_flags);
+	u32 rlcg_flag;
 
+	if (!amdgpu_sriov_runtime(adev) && gfx_v9_0_get_rlcg_flag(adev, acc_flags, hwip, 1, &rlcg_flag)) {
+		gfx_v9_0_rlcg_rw(adev, offset, value, rlcg_flag);
 		return;
 	}
 
 	if (acc_flags & AMDGPU_REGS_NO_KIQ)
-		WREG32_NO_KIQ(offset, v);
+		WREG32_NO_KIQ(offset, value);
 	else
-		WREG32(offset, v);
+		WREG32(offset, value);
 }
 
 #define VEGA10_GB_ADDR_CONFIG_GOLDEN 0x2a114042
@@ -5134,7 +5188,7 @@ static void gfx_v9_0_update_spm_vmid(struct amdgpu_device *adev, unsigned vmid)
 	if (amdgpu_sriov_is_pp_one_vf(adev))
 		data = RREG32_NO_KIQ(reg);
 	else
-		data = RREG32(reg);
+		data = RREG32_SOC15(GC, 0, mmRLC_SPM_MC_CNTL);
 
 	data &= ~RLC_SPM_MC_CNTL__RLC_SPM_VMID_MASK;
 	data |= (vmid & RLC_SPM_MC_CNTL__RLC_SPM_VMID_MASK) << RLC_SPM_MC_CNTL__RLC_SPM_VMID__SHIFT;
@@ -5190,6 +5244,7 @@ static const struct amdgpu_rlc_funcs gfx_v9_0_rlc_funcs = {
 	.start = gfx_v9_0_rlc_start,
 	.update_spm_vmid = gfx_v9_0_update_spm_vmid,
 	.sriov_wreg = gfx_v9_0_sriov_wreg,
+	.sriov_rreg = gfx_v9_0_sriov_rreg,
 	.is_rlcg_access_range = gfx_v9_0_is_rlcg_access_range,
 };
 
@@ -5795,16 +5850,16 @@ static void gfx_v9_0_set_compute_eop_interrupt_state(struct amdgpu_device *adev,
 
 	switch (state) {
 	case AMDGPU_IRQ_STATE_DISABLE:
-		mec_int_cntl = RREG32(mec_int_cntl_reg);
+		mec_int_cntl = RREG32_SOC15_IP(GC,mec_int_cntl_reg);
 		mec_int_cntl = REG_SET_FIELD(mec_int_cntl, CP_ME1_PIPE0_INT_CNTL,
 					     TIME_STAMP_INT_ENABLE, 0);
-		WREG32(mec_int_cntl_reg, mec_int_cntl);
+		WREG32_SOC15_IP(GC, mec_int_cntl_reg, mec_int_cntl);
 		break;
 	case AMDGPU_IRQ_STATE_ENABLE:
-		mec_int_cntl = RREG32(mec_int_cntl_reg);
+		mec_int_cntl = RREG32_SOC15_IP(GC, mec_int_cntl_reg);
 		mec_int_cntl = REG_SET_FIELD(mec_int_cntl, CP_ME1_PIPE0_INT_CNTL,
 					     TIME_STAMP_INT_ENABLE, 1);
-		WREG32(mec_int_cntl_reg, mec_int_cntl);
+		WREG32_SOC15_IP(GC, mec_int_cntl_reg, mec_int_cntl);
 		break;
 	default:
 		break;
Signature · 1 line
2.25.1
#17 lore raw

Re: [PATCH 5/5] drm/amdgpu: Modify indirect register access for gfx9 sriov

[AMD Official Use Only]

         scratch_reg0 = adev->rmmio + (adev->reg_offset[GC_HWIP][0][mmSCRATCH_REG0_BASE_IDX] + mmSCRATCH_REG0)*4;
         scratch_reg1 = adev->rmmio + (adev->reg_offset[GC_HWIP][0][mmSCRATCH_REG1_BASE_IDX] + mmSCRATCH_REG1)*4;
-       scratch_reg2 = adev->rmmio + (adev->reg_offset[GC_HWIP][0][mmSCRATCH_REG1_BASE_IDX] + mmSCRATCH_REG2)*4;
-       scratch_reg3 = adev->rmmio + (adev->reg_offset[GC_HWIP][0][mmSCRATCH_REG1_BASE_IDX] + mmSCRATCH_REG3)*4;
+       scratch_reg2 = adev->rmmio + (adev->reg_offset[GC_HWIP][0][mmSCRATCH_REG2_BASE_IDX] + mmSCRATCH_REG2)*4;
+       scratch_reg3 = adev->rmmio + (adev->reg_offset[GC_HWIP][0][mmSCRATCH_REG3_BASE_IDX] + mmSCRATCH_REG3)*4;
         spare_int = adev->rmmio + (adev->reg_offset[GC_HWIP][0][mmRLC_SPARE_INT_BASE_IDX] + mmRLC_SPARE_INT)*4;

the definition of scratch_reg2 and 3 has here.... will this be backwards compatible? Was it a bug in the definition?
________________________________
From: Skvortsov, Victor <[email protected]>
Sent: Wednesday, December 15, 2021 10:55 AM
To: [email protected] <[email protected]>; Deng, Emily <[email protected]>; Liu, Monk <[email protected]>; Ming, Davis <[email protected]>; Liu, Shaoyun <[email protected]>; Zhou, Peng Ju <[email protected]>; Chen, JingWen <[email protected]>; Chen, Horace <[email protected]>; Nieto, David M <[email protected]>
Cc: Skvortsov, Victor <[email protected]>
Subject: [PATCH 5/5] drm/amdgpu: Modify indirect register access for gfx9 sriov

Expand RLCG interface for new GC read & write commands.
New interface will only be used if the PF enables the flag in pf2vf msg.

---
 drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c | 111 +++++++++++++++++++-------
 1 file changed, 83 insertions(+), 28 deletions(-)
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +83 -28
index d252b06efa43..bce6ab52cae0 100644
@@ -63,6 +63,13 @@
 #define mmGCEA_PROBE_MAP                        0x070c
 #define mmGCEA_PROBE_MAP_BASE_IDX               0
 
+#define GFX9_RLCG_GC_WRITE_OLD                 (0x8 << 28)
+#define GFX9_RLCG_GC_WRITE                     (0x0 << 28)
+#define GFX9_RLCG_GC_READ                      (0x1 << 28)
+#define GFX9_RLCG_VFGATE_DISABLED              0x4000000
+#define GFX9_RLCG_WRONG_OPERATION_TYPE         0x2000000
+#define GFX9_RLCG_NOT_IN_RANGE                 0x1000000
+
 MODULE_FIRMWARE("amdgpu/vega10_ce.bin");
 MODULE_FIRMWARE("amdgpu/vega10_pfp.bin");
 MODULE_FIRMWARE("amdgpu/vega10_me.bin");
@@ -739,7 +746,7 @@ static const u32 GFX_RLC_SRM_INDEX_CNTL_DATA_OFFSETS[] =
         mmRLC_SRM_INDEX_CNTL_DATA_7 - mmRLC_SRM_INDEX_CNTL_DATA_0,
 };
 
-static void gfx_v9_0_rlcg_w(struct amdgpu_device *adev, u32 offset, u32 v, u32 flag)
+static u32 gfx_v9_0_rlcg_rw(struct amdgpu_device *adev, u32 offset, u32 v, uint32_t flag)
 {
         static void *scratch_reg0;
         static void *scratch_reg1;
@@ -748,21 +755,20 @@ static void gfx_v9_0_rlcg_w(struct amdgpu_device *adev, u32 offset, u32 v, u32 f
         static void *spare_int;
         static uint32_t grbm_cntl;
         static uint32_t grbm_idx;
+       uint32_t i = 0;
+       uint32_t retries = 50000;
+       u32 ret = 0;
+       u32 tmp;
 
         scratch_reg0 = adev->rmmio + (adev->reg_offset[GC_HWIP][0][mmSCRATCH_REG0_BASE_IDX] + mmSCRATCH_REG0)*4;
         scratch_reg1 = adev->rmmio + (adev->reg_offset[GC_HWIP][0][mmSCRATCH_REG1_BASE_IDX] + mmSCRATCH_REG1)*4;
-       scratch_reg2 = adev->rmmio + (adev->reg_offset[GC_HWIP][0][mmSCRATCH_REG1_BASE_IDX] + mmSCRATCH_REG2)*4;
-       scratch_reg3 = adev->rmmio + (adev->reg_offset[GC_HWIP][0][mmSCRATCH_REG1_BASE_IDX] + mmSCRATCH_REG3)*4;
+       scratch_reg2 = adev->rmmio + (adev->reg_offset[GC_HWIP][0][mmSCRATCH_REG2_BASE_IDX] + mmSCRATCH_REG2)*4;
+       scratch_reg3 = adev->rmmio + (adev->reg_offset[GC_HWIP][0][mmSCRATCH_REG3_BASE_IDX] + mmSCRATCH_REG3)*4;
         spare_int = adev->rmmio + (adev->reg_offset[GC_HWIP][0][mmRLC_SPARE_INT_BASE_IDX] + mmRLC_SPARE_INT)*4;
 
         grbm_cntl = adev->reg_offset[GC_HWIP][0][mmGRBM_GFX_CNTL_BASE_IDX] + mmGRBM_GFX_CNTL;
         grbm_idx = adev->reg_offset[GC_HWIP][0][mmGRBM_GFX_INDEX_BASE_IDX] + mmGRBM_GFX_INDEX;
 
-       if (amdgpu_sriov_runtime(adev)) {
-               pr_err("shouldn't call rlcg write register during runtime\n");
-               return;
-       }
-
         if (offset == grbm_cntl || offset == grbm_idx) {
                 if (offset  == grbm_cntl)
                         writel(v, scratch_reg2);
@@ -771,41 +777,89 @@ static void gfx_v9_0_rlcg_w(struct amdgpu_device *adev, u32 offset, u32 v, u32 f
 
                 writel(v, ((void __iomem *)adev->rmmio) + (offset * 4));
         } else {
-               uint32_t i = 0;
-               uint32_t retries = 50000;
-
                 writel(v, scratch_reg0);
-               writel(offset | 0x80000000, scratch_reg1);
+               writel(offset | flag, scratch_reg1);
                 writel(1, spare_int);
-               for (i = 0; i < retries; i++) {
-                       u32 tmp;
 
+               for (i = 0; i < retries; i++) {
                         tmp = readl(scratch_reg1);
-                       if (!(tmp & 0x80000000))
+                       if (!(tmp & flag))
                                 break;
 
                         udelay(10);
                 }
-               if (i >= retries)
-                       pr_err("timeout: rlcg program reg:0x%05x failed !\n", offset);
+
+               if (i >= retries) {
+                       if (amdgpu_sriov_reg_indirect_gc(adev)) {
+                               if (tmp & GFX9_RLCG_VFGATE_DISABLED)
+                                       pr_err("The vfgate is disabled, program reg:0x%05x failed!\n", offset);
+                               else if (tmp & GFX9_RLCG_WRONG_OPERATION_TYPE)
+                                       pr_err("Wrong operation type, program reg:0x%05x failed!\n", offset);
+                               else if (tmp & GFX9_RLCG_NOT_IN_RANGE)
+                                       pr_err("The register is not in range, program reg:0x%05x failed!\n", offset);
+                               else
+                                       pr_err("Unknown error type, program reg:0x%05x failed!\n", offset);
+                       } else
+                               pr_err("timeout: rlcg program reg:0x%05x failed!\n", offset);
+               }
+       }
+
+       ret = readl(scratch_reg0);
+
+       return ret;
+}
+
+static bool gfx_v9_0_get_rlcg_flag(struct amdgpu_device *adev, u32 acc_flags, u32 hwip,
+                               int write, u32 *rlcg_flag)
+{
+
+       switch (hwip) {
+       case GC_HWIP:
+               if (amdgpu_sriov_reg_indirect_gc(adev)) {
+                       *rlcg_flag = write ? GFX9_RLCG_GC_WRITE : GFX9_RLCG_GC_READ;
+
+                       return true;
+               /* only in new version, AMDGPU_REGS_NO_KIQ and AMDGPU_REGS_RLC enabled simultaneously */
+               } else if ((acc_flags & AMDGPU_REGS_RLC) && !(acc_flags & AMDGPU_REGS_NO_KIQ) && write) {
+                       *rlcg_flag = GFX9_RLCG_GC_WRITE_OLD;
+                       return true;
+               }
+
+               break;
+       default:
+               return false;
         }
 
+       return false;
+}
+
+static u32 gfx_v9_0_sriov_rreg(struct amdgpu_device *adev, u32 offset, u32 acc_flags, u32 hwip)
+{
+       u32 rlcg_flag;
+
+       if (!amdgpu_sriov_runtime(adev) && gfx_v9_0_get_rlcg_flag(adev, acc_flags, hwip, 0, &rlcg_flag))
+               return gfx_v9_0_rlcg_rw(adev, offset, 0, rlcg_flag);
+
+       if (acc_flags & AMDGPU_REGS_NO_KIQ)
+               return RREG32_NO_KIQ(offset);
+       else
+               return RREG32(offset);
 }
 
 static void gfx_v9_0_sriov_wreg(struct amdgpu_device *adev, u32 offset,
-                              u32 v, u32 acc_flags, u32 hwip)
+                              u32 value, u32 acc_flags, u32 hwip)
 {
-       if ((acc_flags & AMDGPU_REGS_RLC) &&
-           amdgpu_sriov_fullaccess(adev)) {
-               gfx_v9_0_rlcg_w(adev, offset, v, acc_flags);
+       u32 rlcg_flag;
 
+       if (!amdgpu_sriov_runtime(adev) && gfx_v9_0_get_rlcg_flag(adev, acc_flags, hwip, 1, &rlcg_flag)) {
+               gfx_v9_0_rlcg_rw(adev, offset, value, rlcg_flag);
                 return;
         }
 
         if (acc_flags & AMDGPU_REGS_NO_KIQ)
-               WREG32_NO_KIQ(offset, v);
+               WREG32_NO_KIQ(offset, value);
         else
-               WREG32(offset, v);
+               WREG32(offset, value);
 }
 
 #define VEGA10_GB_ADDR_CONFIG_GOLDEN 0x2a114042
@@ -5134,7 +5188,7 @@ static void gfx_v9_0_update_spm_vmid(struct amdgpu_device *adev, unsigned vmid)
         if (amdgpu_sriov_is_pp_one_vf(adev))
                 data = RREG32_NO_KIQ(reg);
         else
-               data = RREG32(reg);
+               data = RREG32_SOC15(GC, 0, mmRLC_SPM_MC_CNTL);
 
         data &= ~RLC_SPM_MC_CNTL__RLC_SPM_VMID_MASK;
         data |= (vmid & RLC_SPM_MC_CNTL__RLC_SPM_VMID_MASK) << RLC_SPM_MC_CNTL__RLC_SPM_VMID__SHIFT;
@@ -5190,6 +5244,7 @@ static const struct amdgpu_rlc_funcs gfx_v9_0_rlc_funcs = {
         .start = gfx_v9_0_rlc_start,
         .update_spm_vmid = gfx_v9_0_update_spm_vmid,
         .sriov_wreg = gfx_v9_0_sriov_wreg,
+       .sriov_rreg = gfx_v9_0_sriov_rreg,
         .is_rlcg_access_range = gfx_v9_0_is_rlcg_access_range,
 };
 
@@ -5795,16 +5850,16 @@ static void gfx_v9_0_set_compute_eop_interrupt_state(struct amdgpu_device *adev,
 
         switch (state) {
         case AMDGPU_IRQ_STATE_DISABLE:
-               mec_int_cntl = RREG32(mec_int_cntl_reg);
+               mec_int_cntl = RREG32_SOC15_IP(GC,mec_int_cntl_reg);
                 mec_int_cntl = REG_SET_FIELD(mec_int_cntl, CP_ME1_PIPE0_INT_CNTL,
                                              TIME_STAMP_INT_ENABLE, 0);
-               WREG32(mec_int_cntl_reg, mec_int_cntl);
+               WREG32_SOC15_IP(GC, mec_int_cntl_reg, mec_int_cntl);
                 break;
         case AMDGPU_IRQ_STATE_ENABLE:
-               mec_int_cntl = RREG32(mec_int_cntl_reg);
+               mec_int_cntl = RREG32_SOC15_IP(GC, mec_int_cntl_reg);
                 mec_int_cntl = REG_SET_FIELD(mec_int_cntl, CP_ME1_PIPE0_INT_CNTL,
                                              TIME_STAMP_INT_ENABLE, 1);
-               WREG32(mec_int_cntl_reg, mec_int_cntl);
+               WREG32_SOC15_IP(GC, mec_int_cntl_reg, mec_int_cntl);
                 break;
         default:
                 break;

--
2.25.1

#18 lore raw

RE: [PATCH 5/5] drm/amdgpu: Modify indirect register access for gfx9 sriov

[AMD Official Use Only]

This was a bug in the original definition, but it functionally it makes no difference (in both cases the macros resolve to the same value).

From: Nieto, David M <[email protected]>
Sent: Wednesday, December 15, 2021 2:16 PM
To: Skvortsov, Victor <[email protected]>; [email protected]; Deng, Emily <[email protected]>; Liu, Monk <[email protected]>; Ming, Davis <[email protected]>; Liu, Shaoyun <[email protected]>; Zhou, Peng Ju <[email protected]>; Chen, JingWen <[email protected]>; Chen, Horace <[email protected]>
Subject: Re: [PATCH 5/5] drm/amdgpu: Modify indirect register access for gfx9 sriov

[AMD Official Use Only]

         scratch_reg0 = adev->rmmio + (adev->reg_offset[GC_HWIP][0][mmSCRATCH_REG0_BASE_IDX] + mmSCRATCH_REG0)*4;
         scratch_reg1 = adev->rmmio + (adev->reg_offset[GC_HWIP][0][mmSCRATCH_REG1_BASE_IDX] + mmSCRATCH_REG1)*4;
-       scratch_reg2 = adev->rmmio + (adev->reg_offset[GC_HWIP][0][mmSCRATCH_REG1_BASE_IDX] + mmSCRATCH_REG2)*4;
-       scratch_reg3 = adev->rmmio + (adev->reg_offset[GC_HWIP][0][mmSCRATCH_REG1_BASE_IDX] + mmSCRATCH_REG3)*4;
+       scratch_reg2 = adev->rmmio + (adev->reg_offset[GC_HWIP][0][mmSCRATCH_REG2_BASE_IDX] + mmSCRATCH_REG2)*4;
+       scratch_reg3 = adev->rmmio + (adev->reg_offset[GC_HWIP][0][mmSCRATCH_REG3_BASE_IDX] + mmSCRATCH_REG3)*4;
         spare_int = adev->rmmio + (adev->reg_offset[GC_HWIP][0][mmRLC_SPARE_INT_BASE_IDX] + mmRLC_SPARE_INT)*4;

the definition of scratch_reg2 and 3 has here.... will this be backwards compatible? Was it a bug in the definition?
________________________________
From: Skvortsov, Victor <[email protected]<mailto:[email protected]>>
Sent: Wednesday, December 15, 2021 10:55 AM
To: [email protected]<mailto:[email protected]> <[email protected]<mailto:[email protected]>>; Deng, Emily <[email protected]<mailto:[email protected]>>; Liu, Monk <[email protected]<mailto:[email protected]>>; Ming, Davis <[email protected]<mailto:[email protected]>>; Liu, Shaoyun <[email protected]<mailto:[email protected]>>; Zhou, Peng Ju <[email protected]<mailto:[email protected]>>; Chen, JingWen <[email protected]<mailto:[email protected]>>; Chen, Horace <[email protected]<mailto:[email protected]>>; Nieto, David M <[email protected]<mailto:[email protected]>>
Cc: Skvortsov, Victor <[email protected]<mailto:[email protected]>>
Subject: [PATCH 5/5] drm/amdgpu: Modify indirect register access for gfx9 sriov

Expand RLCG interface for new GC read & write commands.
New interface will only be used if the PF enables the flag in pf2vf msg.

---
 drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c | 111 +++++++++++++++++++-------
 1 file changed, 83 insertions(+), 28 deletions(-)
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +83 -28
index d252b06efa43..bce6ab52cae0 100644
@@ -63,6 +63,13 @@
 #define mmGCEA_PROBE_MAP                        0x070c
 #define mmGCEA_PROBE_MAP_BASE_IDX               0
 
+#define GFX9_RLCG_GC_WRITE_OLD                 (0x8 << 28)
+#define GFX9_RLCG_GC_WRITE                     (0x0 << 28)
+#define GFX9_RLCG_GC_READ                      (0x1 << 28)
+#define GFX9_RLCG_VFGATE_DISABLED              0x4000000
+#define GFX9_RLCG_WRONG_OPERATION_TYPE         0x2000000
+#define GFX9_RLCG_NOT_IN_RANGE                 0x1000000
+
 MODULE_FIRMWARE("amdgpu/vega10_ce.bin");
 MODULE_FIRMWARE("amdgpu/vega10_pfp.bin");
 MODULE_FIRMWARE("amdgpu/vega10_me.bin");
@@ -739,7 +746,7 @@ static const u32 GFX_RLC_SRM_INDEX_CNTL_DATA_OFFSETS[] =
         mmRLC_SRM_INDEX_CNTL_DATA_7 - mmRLC_SRM_INDEX_CNTL_DATA_0,
 };
 
-static void gfx_v9_0_rlcg_w(struct amdgpu_device *adev, u32 offset, u32 v, u32 flag)
+static u32 gfx_v9_0_rlcg_rw(struct amdgpu_device *adev, u32 offset, u32 v, uint32_t flag)
 {
         static void *scratch_reg0;
         static void *scratch_reg1;
@@ -748,21 +755,20 @@ static void gfx_v9_0_rlcg_w(struct amdgpu_device *adev, u32 offset, u32 v, u32 f
         static void *spare_int;
         static uint32_t grbm_cntl;
         static uint32_t grbm_idx;
+       uint32_t i = 0;
+       uint32_t retries = 50000;
+       u32 ret = 0;
+       u32 tmp;
 
         scratch_reg0 = adev->rmmio + (adev->reg_offset[GC_HWIP][0][mmSCRATCH_REG0_BASE_IDX] + mmSCRATCH_REG0)*4;
         scratch_reg1 = adev->rmmio + (adev->reg_offset[GC_HWIP][0][mmSCRATCH_REG1_BASE_IDX] + mmSCRATCH_REG1)*4;
-       scratch_reg2 = adev->rmmio + (adev->reg_offset[GC_HWIP][0][mmSCRATCH_REG1_BASE_IDX] + mmSCRATCH_REG2)*4;
-       scratch_reg3 = adev->rmmio + (adev->reg_offset[GC_HWIP][0][mmSCRATCH_REG1_BASE_IDX] + mmSCRATCH_REG3)*4;
+       scratch_reg2 = adev->rmmio + (adev->reg_offset[GC_HWIP][0][mmSCRATCH_REG2_BASE_IDX] + mmSCRATCH_REG2)*4;
+       scratch_reg3 = adev->rmmio + (adev->reg_offset[GC_HWIP][0][mmSCRATCH_REG3_BASE_IDX] + mmSCRATCH_REG3)*4;
         spare_int = adev->rmmio + (adev->reg_offset[GC_HWIP][0][mmRLC_SPARE_INT_BASE_IDX] + mmRLC_SPARE_INT)*4;
 
         grbm_cntl = adev->reg_offset[GC_HWIP][0][mmGRBM_GFX_CNTL_BASE_IDX] + mmGRBM_GFX_CNTL;
         grbm_idx = adev->reg_offset[GC_HWIP][0][mmGRBM_GFX_INDEX_BASE_IDX] + mmGRBM_GFX_INDEX;
 
-       if (amdgpu_sriov_runtime(adev)) {
-               pr_err("shouldn't call rlcg write register during runtime\n");
-               return;
-       }
-
         if (offset == grbm_cntl || offset == grbm_idx) {
                 if (offset  == grbm_cntl)
                         writel(v, scratch_reg2);
@@ -771,41 +777,89 @@ static void gfx_v9_0_rlcg_w(struct amdgpu_device *adev, u32 offset, u32 v, u32 f
 
                 writel(v, ((void __iomem *)adev->rmmio) + (offset * 4));
         } else {
-               uint32_t i = 0;
-               uint32_t retries = 50000;
-
                 writel(v, scratch_reg0);
-               writel(offset | 0x80000000, scratch_reg1);
+               writel(offset | flag, scratch_reg1);
                 writel(1, spare_int);
-               for (i = 0; i < retries; i++) {
-                       u32 tmp;
 
+               for (i = 0; i < retries; i++) {
                         tmp = readl(scratch_reg1);
-                       if (!(tmp & 0x80000000))
+                       if (!(tmp & flag))
                                 break;
 
                         udelay(10);
                 }
-               if (i >= retries)
-                       pr_err("timeout: rlcg program reg:0x%05x failed !\n", offset);
+
+               if (i >= retries) {
+                       if (amdgpu_sriov_reg_indirect_gc(adev)) {
+                               if (tmp & GFX9_RLCG_VFGATE_DISABLED)
+                                       pr_err("The vfgate is disabled, program reg:0x%05x failed!\n", offset);
+                               else if (tmp & GFX9_RLCG_WRONG_OPERATION_TYPE)
+                                       pr_err("Wrong operation type, program reg:0x%05x failed!\n", offset);
+                               else if (tmp & GFX9_RLCG_NOT_IN_RANGE)
+                                       pr_err("The register is not in range, program reg:0x%05x failed!\n", offset);
+                               else
+                                       pr_err("Unknown error type, program reg:0x%05x failed!\n", offset);
+                       } else
+                               pr_err("timeout: rlcg program reg:0x%05x failed!\n", offset);
+               }
+       }
+
+       ret = readl(scratch_reg0);
+
+       return ret;
+}
+
+static bool gfx_v9_0_get_rlcg_flag(struct amdgpu_device *adev, u32 acc_flags, u32 hwip,
+                               int write, u32 *rlcg_flag)
+{
+
+       switch (hwip) {
+       case GC_HWIP:
+               if (amdgpu_sriov_reg_indirect_gc(adev)) {
+                       *rlcg_flag = write ? GFX9_RLCG_GC_WRITE : GFX9_RLCG_GC_READ;
+
+                       return true;
+               /* only in new version, AMDGPU_REGS_NO_KIQ and AMDGPU_REGS_RLC enabled simultaneously */
+               } else if ((acc_flags & AMDGPU_REGS_RLC) && !(acc_flags & AMDGPU_REGS_NO_KIQ) && write) {
+                       *rlcg_flag = GFX9_RLCG_GC_WRITE_OLD;
+                       return true;
+               }
+
+               break;
+       default:
+               return false;
         }
 
+       return false;
+}
+
+static u32 gfx_v9_0_sriov_rreg(struct amdgpu_device *adev, u32 offset, u32 acc_flags, u32 hwip)
+{
+       u32 rlcg_flag;
+
+       if (!amdgpu_sriov_runtime(adev) && gfx_v9_0_get_rlcg_flag(adev, acc_flags, hwip, 0, &rlcg_flag))
+               return gfx_v9_0_rlcg_rw(adev, offset, 0, rlcg_flag);
+
+       if (acc_flags & AMDGPU_REGS_NO_KIQ)
+               return RREG32_NO_KIQ(offset);
+       else
+               return RREG32(offset);
 }
 
 static void gfx_v9_0_sriov_wreg(struct amdgpu_device *adev, u32 offset,
-                              u32 v, u32 acc_flags, u32 hwip)
+                              u32 value, u32 acc_flags, u32 hwip)
 {
-       if ((acc_flags & AMDGPU_REGS_RLC) &&
-           amdgpu_sriov_fullaccess(adev)) {
-               gfx_v9_0_rlcg_w(adev, offset, v, acc_flags);
+       u32 rlcg_flag;
 
+       if (!amdgpu_sriov_runtime(adev) && gfx_v9_0_get_rlcg_flag(adev, acc_flags, hwip, 1, &rlcg_flag)) {
+               gfx_v9_0_rlcg_rw(adev, offset, value, rlcg_flag);
                 return;
         }
 
         if (acc_flags & AMDGPU_REGS_NO_KIQ)
-               WREG32_NO_KIQ(offset, v);
+               WREG32_NO_KIQ(offset, value);
         else
-               WREG32(offset, v);
+               WREG32(offset, value);
 }
 
 #define VEGA10_GB_ADDR_CONFIG_GOLDEN 0x2a114042
@@ -5134,7 +5188,7 @@ static void gfx_v9_0_update_spm_vmid(struct amdgpu_device *adev, unsigned vmid)
         if (amdgpu_sriov_is_pp_one_vf(adev))
                 data = RREG32_NO_KIQ(reg);
         else
-               data = RREG32(reg);
+               data = RREG32_SOC15(GC, 0, mmRLC_SPM_MC_CNTL);
 
         data &= ~RLC_SPM_MC_CNTL__RLC_SPM_VMID_MASK;
         data |= (vmid & RLC_SPM_MC_CNTL__RLC_SPM_VMID_MASK) << RLC_SPM_MC_CNTL__RLC_SPM_VMID__SHIFT;
@@ -5190,6 +5244,7 @@ static const struct amdgpu_rlc_funcs gfx_v9_0_rlc_funcs = {
         .start = gfx_v9_0_rlc_start,
         .update_spm_vmid = gfx_v9_0_update_spm_vmid,
         .sriov_wreg = gfx_v9_0_sriov_wreg,
+       .sriov_rreg = gfx_v9_0_sriov_rreg,
         .is_rlcg_access_range = gfx_v9_0_is_rlcg_access_range,
 };
 
@@ -5795,16 +5850,16 @@ static void gfx_v9_0_set_compute_eop_interrupt_state(struct amdgpu_device *adev,
 
         switch (state) {
         case AMDGPU_IRQ_STATE_DISABLE:
-               mec_int_cntl = RREG32(mec_int_cntl_reg);
+               mec_int_cntl = RREG32_SOC15_IP(GC,mec_int_cntl_reg);
                 mec_int_cntl = REG_SET_FIELD(mec_int_cntl, CP_ME1_PIPE0_INT_CNTL,
                                              TIME_STAMP_INT_ENABLE, 0);
-               WREG32(mec_int_cntl_reg, mec_int_cntl);
+               WREG32_SOC15_IP(GC, mec_int_cntl_reg, mec_int_cntl);
                 break;
         case AMDGPU_IRQ_STATE_ENABLE:
-               mec_int_cntl = RREG32(mec_int_cntl_reg);
+               mec_int_cntl = RREG32_SOC15_IP(GC, mec_int_cntl_reg);
                 mec_int_cntl = REG_SET_FIELD(mec_int_cntl, CP_ME1_PIPE0_INT_CNTL,
                                              TIME_STAMP_INT_ENABLE, 1);
-               WREG32(mec_int_cntl_reg, mec_int_cntl);
+               WREG32_SOC15_IP(GC, mec_int_cntl_reg, mec_int_cntl);
                 break;
         default:
                 break;

--
2.25.1

#19 lore raw

Re: [PATCH 5/5] drm/amdgpu: Modify indirect register access for gfx9 sriov

[Public]

Gotcha,

Can you add prior to the implementation a small description on how the interface and the different scratch registers work? It may be easier to review with a clear idea of the operation. I know the earlier implementation did not include it, but now that we are modifying it, it would be good to document it.

________________________________
From: Skvortsov, Victor <[email protected]>
Sent: Wednesday, December 15, 2021 11:18 AM
To: Nieto, David M <[email protected]>; [email protected] <[email protected]>; Deng, Emily <[email protected]>; Liu, Monk <[email protected]>; Ming, Davis <[email protected]>; Liu, Shaoyun <[email protected]>; Zhou, Peng Ju <[email protected]>; Chen, JingWen <[email protected]>; Chen, Horace <[email protected]>
Subject: RE: [PATCH 5/5] drm/amdgpu: Modify indirect register access for gfx9 sriov

[AMD Official Use Only]

This was a bug in the original definition, but it functionally it makes no difference (in both cases the macros resolve to the same value).

From: Nieto, David M <[email protected]>
Sent: Wednesday, December 15, 2021 2:16 PM
To: Skvortsov, Victor <[email protected]>; [email protected]; Deng, Emily <[email protected]>; Liu, Monk <[email protected]>; Ming, Davis <[email protected]>; Liu, Shaoyun <[email protected]>; Zhou, Peng Ju <[email protected]>; Chen, JingWen <[email protected]>; Chen, Horace <[email protected]>
Subject: Re: [PATCH 5/5] drm/amdgpu: Modify indirect register access for gfx9 sriov

[AMD Official Use Only]

         scratch_reg0 = adev->rmmio + (adev->reg_offset[GC_HWIP][0][mmSCRATCH_REG0_BASE_IDX] + mmSCRATCH_REG0)*4;
         scratch_reg1 = adev->rmmio + (adev->reg_offset[GC_HWIP][0][mmSCRATCH_REG1_BASE_IDX] + mmSCRATCH_REG1)*4;
-       scratch_reg2 = adev->rmmio + (adev->reg_offset[GC_HWIP][0][mmSCRATCH_REG1_BASE_IDX] + mmSCRATCH_REG2)*4;
-       scratch_reg3 = adev->rmmio + (adev->reg_offset[GC_HWIP][0][mmSCRATCH_REG1_BASE_IDX] + mmSCRATCH_REG3)*4;
+       scratch_reg2 = adev->rmmio + (adev->reg_offset[GC_HWIP][0][mmSCRATCH_REG2_BASE_IDX] + mmSCRATCH_REG2)*4;
+       scratch_reg3 = adev->rmmio + (adev->reg_offset[GC_HWIP][0][mmSCRATCH_REG3_BASE_IDX] + mmSCRATCH_REG3)*4;
         spare_int = adev->rmmio + (adev->reg_offset[GC_HWIP][0][mmRLC_SPARE_INT_BASE_IDX] + mmRLC_SPARE_INT)*4;

the definition of scratch_reg2 and 3 has here.... will this be backwards compatible? Was it a bug in the definition?

________________________________

From: Skvortsov, Victor <[email protected]<mailto:[email protected]>>
Sent: Wednesday, December 15, 2021 10:55 AM
To: [email protected]<mailto:[email protected]> <[email protected]<mailto:[email protected]>>; Deng, Emily <[email protected]<mailto:[email protected]>>; Liu, Monk <[email protected]<mailto:[email protected]>>; Ming, Davis <[email protected]<mailto:[email protected]>>; Liu, Shaoyun <[email protected]<mailto:[email protected]>>; Zhou, Peng Ju <[email protected]<mailto:[email protected]>>; Chen, JingWen <[email protected]<mailto:[email protected]>>; Chen, Horace <[email protected]<mailto:[email protected]>>; Nieto, David M <[email protected]<mailto:[email protected]>>
Cc: Skvortsov, Victor <[email protected]<mailto:[email protected]>>
Subject: [PATCH 5/5] drm/amdgpu: Modify indirect register access for gfx9 sriov

Expand RLCG interface for new GC read & write commands.
New interface will only be used if the PF enables the flag in pf2vf msg.

---
 drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c | 111 +++++++++++++++++++-------
 1 file changed, 83 insertions(+), 28 deletions(-)
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +83 -28
index d252b06efa43..bce6ab52cae0 100644
@@ -63,6 +63,13 @@
 #define mmGCEA_PROBE_MAP                        0x070c
 #define mmGCEA_PROBE_MAP_BASE_IDX               0
 
+#define GFX9_RLCG_GC_WRITE_OLD                 (0x8 << 28)
+#define GFX9_RLCG_GC_WRITE                     (0x0 << 28)
+#define GFX9_RLCG_GC_READ                      (0x1 << 28)
+#define GFX9_RLCG_VFGATE_DISABLED              0x4000000
+#define GFX9_RLCG_WRONG_OPERATION_TYPE         0x2000000
+#define GFX9_RLCG_NOT_IN_RANGE                 0x1000000
+
 MODULE_FIRMWARE("amdgpu/vega10_ce.bin");
 MODULE_FIRMWARE("amdgpu/vega10_pfp.bin");
 MODULE_FIRMWARE("amdgpu/vega10_me.bin");
@@ -739,7 +746,7 @@ static const u32 GFX_RLC_SRM_INDEX_CNTL_DATA_OFFSETS[] =
         mmRLC_SRM_INDEX_CNTL_DATA_7 - mmRLC_SRM_INDEX_CNTL_DATA_0,
 };
 
-static void gfx_v9_0_rlcg_w(struct amdgpu_device *adev, u32 offset, u32 v, u32 flag)
+static u32 gfx_v9_0_rlcg_rw(struct amdgpu_device *adev, u32 offset, u32 v, uint32_t flag)
 {
         static void *scratch_reg0;
         static void *scratch_reg1;
@@ -748,21 +755,20 @@ static void gfx_v9_0_rlcg_w(struct amdgpu_device *adev, u32 offset, u32 v, u32 f
         static void *spare_int;
         static uint32_t grbm_cntl;
         static uint32_t grbm_idx;
+       uint32_t i = 0;
+       uint32_t retries = 50000;
+       u32 ret = 0;
+       u32 tmp;
 
         scratch_reg0 = adev->rmmio + (adev->reg_offset[GC_HWIP][0][mmSCRATCH_REG0_BASE_IDX] + mmSCRATCH_REG0)*4;
         scratch_reg1 = adev->rmmio + (adev->reg_offset[GC_HWIP][0][mmSCRATCH_REG1_BASE_IDX] + mmSCRATCH_REG1)*4;
-       scratch_reg2 = adev->rmmio + (adev->reg_offset[GC_HWIP][0][mmSCRATCH_REG1_BASE_IDX] + mmSCRATCH_REG2)*4;
-       scratch_reg3 = adev->rmmio + (adev->reg_offset[GC_HWIP][0][mmSCRATCH_REG1_BASE_IDX] + mmSCRATCH_REG3)*4;
+       scratch_reg2 = adev->rmmio + (adev->reg_offset[GC_HWIP][0][mmSCRATCH_REG2_BASE_IDX] + mmSCRATCH_REG2)*4;
+       scratch_reg3 = adev->rmmio + (adev->reg_offset[GC_HWIP][0][mmSCRATCH_REG3_BASE_IDX] + mmSCRATCH_REG3)*4;
         spare_int = adev->rmmio + (adev->reg_offset[GC_HWIP][0][mmRLC_SPARE_INT_BASE_IDX] + mmRLC_SPARE_INT)*4;
 
         grbm_cntl = adev->reg_offset[GC_HWIP][0][mmGRBM_GFX_CNTL_BASE_IDX] + mmGRBM_GFX_CNTL;
         grbm_idx = adev->reg_offset[GC_HWIP][0][mmGRBM_GFX_INDEX_BASE_IDX] + mmGRBM_GFX_INDEX;
 
-       if (amdgpu_sriov_runtime(adev)) {
-               pr_err("shouldn't call rlcg write register during runtime\n");
-               return;
-       }
-
         if (offset == grbm_cntl || offset == grbm_idx) {
                 if (offset  == grbm_cntl)
                         writel(v, scratch_reg2);
@@ -771,41 +777,89 @@ static void gfx_v9_0_rlcg_w(struct amdgpu_device *adev, u32 offset, u32 v, u32 f
 
                 writel(v, ((void __iomem *)adev->rmmio) + (offset * 4));
         } else {
-               uint32_t i = 0;
-               uint32_t retries = 50000;
-
                 writel(v, scratch_reg0);
-               writel(offset | 0x80000000, scratch_reg1);
+               writel(offset | flag, scratch_reg1);
                 writel(1, spare_int);
-               for (i = 0; i < retries; i++) {
-                       u32 tmp;
 
+               for (i = 0; i < retries; i++) {
                         tmp = readl(scratch_reg1);
-                       if (!(tmp & 0x80000000))
+                       if (!(tmp & flag))
                                 break;
 
                         udelay(10);
                 }
-               if (i >= retries)
-                       pr_err("timeout: rlcg program reg:0x%05x failed !\n", offset);
+
+               if (i >= retries) {
+                       if (amdgpu_sriov_reg_indirect_gc(adev)) {
+                               if (tmp & GFX9_RLCG_VFGATE_DISABLED)
+                                       pr_err("The vfgate is disabled, program reg:0x%05x failed!\n", offset);
+                               else if (tmp & GFX9_RLCG_WRONG_OPERATION_TYPE)
+                                       pr_err("Wrong operation type, program reg:0x%05x failed!\n", offset);
+                               else if (tmp & GFX9_RLCG_NOT_IN_RANGE)
+                                       pr_err("The register is not in range, program reg:0x%05x failed!\n", offset);
+                               else
+                                       pr_err("Unknown error type, program reg:0x%05x failed!\n", offset);
+                       } else
+                               pr_err("timeout: rlcg program reg:0x%05x failed!\n", offset);
+               }
+       }
+
+       ret = readl(scratch_reg0);
+
+       return ret;
+}
+
+static bool gfx_v9_0_get_rlcg_flag(struct amdgpu_device *adev, u32 acc_flags, u32 hwip,
+                               int write, u32 *rlcg_flag)
+{
+
+       switch (hwip) {
+       case GC_HWIP:
+               if (amdgpu_sriov_reg_indirect_gc(adev)) {
+                       *rlcg_flag = write ? GFX9_RLCG_GC_WRITE : GFX9_RLCG_GC_READ;
+
+                       return true;
+               /* only in new version, AMDGPU_REGS_NO_KIQ and AMDGPU_REGS_RLC enabled simultaneously */
+               } else if ((acc_flags & AMDGPU_REGS_RLC) && !(acc_flags & AMDGPU_REGS_NO_KIQ) && write) {
+                       *rlcg_flag = GFX9_RLCG_GC_WRITE_OLD;
+                       return true;
+               }
+
+               break;
+       default:
+               return false;
         }
 
+       return false;
+}
+
+static u32 gfx_v9_0_sriov_rreg(struct amdgpu_device *adev, u32 offset, u32 acc_flags, u32 hwip)
+{
+       u32 rlcg_flag;
+
+       if (!amdgpu_sriov_runtime(adev) && gfx_v9_0_get_rlcg_flag(adev, acc_flags, hwip, 0, &rlcg_flag))
+               return gfx_v9_0_rlcg_rw(adev, offset, 0, rlcg_flag);
+
+       if (acc_flags & AMDGPU_REGS_NO_KIQ)
+               return RREG32_NO_KIQ(offset);
+       else
+               return RREG32(offset);
 }
 
 static void gfx_v9_0_sriov_wreg(struct amdgpu_device *adev, u32 offset,
-                              u32 v, u32 acc_flags, u32 hwip)
+                              u32 value, u32 acc_flags, u32 hwip)
 {
-       if ((acc_flags & AMDGPU_REGS_RLC) &&
-           amdgpu_sriov_fullaccess(adev)) {
-               gfx_v9_0_rlcg_w(adev, offset, v, acc_flags);
+       u32 rlcg_flag;
 
+       if (!amdgpu_sriov_runtime(adev) && gfx_v9_0_get_rlcg_flag(adev, acc_flags, hwip, 1, &rlcg_flag)) {
+               gfx_v9_0_rlcg_rw(adev, offset, value, rlcg_flag);
                 return;
         }
 
         if (acc_flags & AMDGPU_REGS_NO_KIQ)
-               WREG32_NO_KIQ(offset, v);
+               WREG32_NO_KIQ(offset, value);
         else
-               WREG32(offset, v);
+               WREG32(offset, value);
 }
 
 #define VEGA10_GB_ADDR_CONFIG_GOLDEN 0x2a114042
@@ -5134,7 +5188,7 @@ static void gfx_v9_0_update_spm_vmid(struct amdgpu_device *adev, unsigned vmid)
         if (amdgpu_sriov_is_pp_one_vf(adev))
                 data = RREG32_NO_KIQ(reg);
         else
-               data = RREG32(reg);
+               data = RREG32_SOC15(GC, 0, mmRLC_SPM_MC_CNTL);
 
         data &= ~RLC_SPM_MC_CNTL__RLC_SPM_VMID_MASK;
         data |= (vmid & RLC_SPM_MC_CNTL__RLC_SPM_VMID_MASK) << RLC_SPM_MC_CNTL__RLC_SPM_VMID__SHIFT;
@@ -5190,6 +5244,7 @@ static const struct amdgpu_rlc_funcs gfx_v9_0_rlc_funcs = {
         .start = gfx_v9_0_rlc_start,
         .update_spm_vmid = gfx_v9_0_update_spm_vmid,
         .sriov_wreg = gfx_v9_0_sriov_wreg,
+       .sriov_rreg = gfx_v9_0_sriov_rreg,
         .is_rlcg_access_range = gfx_v9_0_is_rlcg_access_range,
 };
 
@@ -5795,16 +5850,16 @@ static void gfx_v9_0_set_compute_eop_interrupt_state(struct amdgpu_device *adev,
 
         switch (state) {
         case AMDGPU_IRQ_STATE_DISABLE:
-               mec_int_cntl = RREG32(mec_int_cntl_reg);
+               mec_int_cntl = RREG32_SOC15_IP(GC,mec_int_cntl_reg);
                 mec_int_cntl = REG_SET_FIELD(mec_int_cntl, CP_ME1_PIPE0_INT_CNTL,
                                              TIME_STAMP_INT_ENABLE, 0);
-               WREG32(mec_int_cntl_reg, mec_int_cntl);
+               WREG32_SOC15_IP(GC, mec_int_cntl_reg, mec_int_cntl);
                 break;
         case AMDGPU_IRQ_STATE_ENABLE:
-               mec_int_cntl = RREG32(mec_int_cntl_reg);
+               mec_int_cntl = RREG32_SOC15_IP(GC, mec_int_cntl_reg);
                 mec_int_cntl = REG_SET_FIELD(mec_int_cntl, CP_ME1_PIPE0_INT_CNTL,
                                              TIME_STAMP_INT_ENABLE, 1);
-               WREG32(mec_int_cntl_reg, mec_int_cntl);
+               WREG32_SOC15_IP(GC, mec_int_cntl_reg, mec_int_cntl);
                 break;
         default:
                 break;

--
2.25.1