Skip to contentSkip to conversation

drm/amdkfd: Improve doorbell variable names

PATCH In review Zhao, Yong 5 participants 12 messages Feb 5, 2019 – Feb 8, 2019 6 messages not in the archive

Subsystems (3)
lore
Share & tools
lore

Zhao, Yong

author
#0 lore raw

PATCH 1/5 drm/amdkfd: Improve doorbell variable names

Indicate that the doorbell offset and range is in dwords.

Change-Id Ib0f2564ffa7b1940ffb8725cdc03f662184f5436
---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h          | 2 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_doorbell.h | 3 ++-
 drivers/gpu/drm/amd/amdgpu/nbio_v6_1.c       | 6 +++---
 drivers/gpu/drm/amd/amdgpu/nbio_v7_0.c       | 6 +++---
 drivers/gpu/drm/amd/amdgpu/nbio_v7_4.c       | 6 +++---
 drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c       | 3 ++-
 drivers/gpu/drm/amd/amdgpu/soc15.c           | 2 +-
 drivers/gpu/drm/amd/amdgpu/vega10_reg_init.c | 6 +++++-
 drivers/gpu/drm/amd/amdgpu/vega20_reg_init.c | 6 +++++-
 9 files changed, 25 insertions(+), 15 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1 -1
index d67f8b1dfe80..6230425f3f3d 100644
@@ -642,7 +642,7 @@ struct amdgpu_nbio_funcs {
 	void (*hdp_flush)(struct amdgpu_device *adev, struct amdgpu_ring *ring);
 	u32 (*get_memsize)(struct amdgpu_device *adev);
 	void (*sdma_doorbell_range)(struct amdgpu_device *adev, int instance,
-			bool use_doorbell, int doorbell_index, int doorbell_size);
+			bool use_doorbell, int index_in_dw, int range_dw_size);
 	void (*enable_doorbell_aperture)(struct amdgpu_device *adev,
 					 bool enable);
 	void (*enable_doorbell_selfring_aperture)(struct amdgpu_device *adev,
drivers/gpu/drm/amd/amdgpu/amdgpu_doorbell.h +2 -1
index 1cfec06f81d4..5c8d04c353d0 100644
@@ -39,6 +39,7 @@ struct amdgpu_doorbell {
  * can be 64-bit, so the index defined is in qword.
  */
 struct amdgpu_doorbell_index {
+	uint32_t entry_dw_size;
 	uint32_t kiq;
 	uint32_t mec_ring0;
 	uint32_t mec_ring1;
@@ -73,7 +74,7 @@ struct amdgpu_doorbell_index {
 	};
 	uint32_t max_assignment;
 	/* Per engine SDMA doorbell size in dword */
-	uint32_t sdma_doorbell_range;
+	uint32_t dw_range_per_sdma_eng;
 };
 
 typedef enum _AMDGPU_DOORBELL_ASSIGNMENT
drivers/gpu/drm/amd/amdgpu/nbio_v6_1.c +3 -3
index cc967dbfd631..64bc41afd71e 100644
@@ -68,7 +68,7 @@ static u32 nbio_v6_1_get_memsize(struct amdgpu_device *adev)
 }
 
 static void nbio_v6_1_sdma_doorbell_range(struct amdgpu_device *adev, int instance,
-			bool use_doorbell, int doorbell_index, int doorbell_size)
+			bool use_doorbell, int index_in_dw, int range_dw_size)
 {
 	u32 reg = instance == 0 ? SOC15_REG_OFFSET(NBIO, 0, mmBIF_SDMA0_DOORBELL_RANGE) :
 			SOC15_REG_OFFSET(NBIO, 0, mmBIF_SDMA1_DOORBELL_RANGE);
@@ -76,8 +76,8 @@ static void nbio_v6_1_sdma_doorbell_range(struct amdgpu_device *adev, int instan
 	u32 doorbell_range = RREG32(reg);
 
 	if (use_doorbell) {
-		doorbell_range = REG_SET_FIELD(doorbell_range, BIF_SDMA0_DOORBELL_RANGE, OFFSET, doorbell_index);
-		doorbell_range = REG_SET_FIELD(doorbell_range, BIF_SDMA0_DOORBELL_RANGE, SIZE, doorbell_size);
+		doorbell_range = REG_SET_FIELD(doorbell_range, BIF_SDMA0_DOORBELL_RANGE, OFFSET, index_in_dw);
+		doorbell_range = REG_SET_FIELD(doorbell_range, BIF_SDMA0_DOORBELL_RANGE, SIZE, range_dw_size);
 	} else
 		doorbell_range = REG_SET_FIELD(doorbell_range, BIF_SDMA0_DOORBELL_RANGE, SIZE, 0);
 
drivers/gpu/drm/amd/amdgpu/nbio_v7_0.c +3 -3
index 1cdb98ad2db3..28cc96b7a292 100644
@@ -67,7 +67,7 @@ static u32 nbio_v7_0_get_memsize(struct amdgpu_device *adev)
 }
 
 static void nbio_v7_0_sdma_doorbell_range(struct amdgpu_device *adev, int instance,
-			bool use_doorbell, int doorbell_index, int doorbell_size)
+			bool use_doorbell, int index_in_dw, int range_dw_size)
 {
 	u32 reg = instance == 0 ? SOC15_REG_OFFSET(NBIO, 0, mmBIF_SDMA0_DOORBELL_RANGE) :
 			SOC15_REG_OFFSET(NBIO, 0, mmBIF_SDMA1_DOORBELL_RANGE);
@@ -75,8 +75,8 @@ static void nbio_v7_0_sdma_doorbell_range(struct amdgpu_device *adev, int instan
 	u32 doorbell_range = RREG32(reg);
 
 	if (use_doorbell) {
-		doorbell_range = REG_SET_FIELD(doorbell_range, BIF_SDMA0_DOORBELL_RANGE, OFFSET, doorbell_index);
-		doorbell_range = REG_SET_FIELD(doorbell_range, BIF_SDMA0_DOORBELL_RANGE, SIZE, doorbell_size);
+		doorbell_range = REG_SET_FIELD(doorbell_range, BIF_SDMA0_DOORBELL_RANGE, OFFSET, index_in_dw);
+		doorbell_range = REG_SET_FIELD(doorbell_range, BIF_SDMA0_DOORBELL_RANGE, SIZE, range_dw_size);
 	} else
 		doorbell_range = REG_SET_FIELD(doorbell_range, BIF_SDMA0_DOORBELL_RANGE, SIZE, 0);
 
drivers/gpu/drm/amd/amdgpu/nbio_v7_4.c +3 -3
index 221f26e50322..9ae8cd4dc702 100644
@@ -65,7 +65,7 @@ static u32 nbio_v7_4_get_memsize(struct amdgpu_device *adev)
 }
 
 static void nbio_v7_4_sdma_doorbell_range(struct amdgpu_device *adev, int instance,
-			bool use_doorbell, int doorbell_index, int doorbell_size)
+			bool use_doorbell, int index_in_dw, int range_dw_size)
 {
 	u32 reg = instance == 0 ? SOC15_REG_OFFSET(NBIO, 0, mmBIF_SDMA0_DOORBELL_RANGE) :
 			SOC15_REG_OFFSET(NBIO, 0, mmBIF_SDMA1_DOORBELL_RANGE);
@@ -73,8 +73,8 @@ static void nbio_v7_4_sdma_doorbell_range(struct amdgpu_device *adev, int instan
 	u32 doorbell_range = RREG32(reg);
 
 	if (use_doorbell) {
-		doorbell_range = REG_SET_FIELD(doorbell_range, BIF_SDMA0_DOORBELL_RANGE, OFFSET, doorbell_index);
-		doorbell_range = REG_SET_FIELD(doorbell_range, BIF_SDMA0_DOORBELL_RANGE, SIZE, doorbell_size);
+		doorbell_range = REG_SET_FIELD(doorbell_range, BIF_SDMA0_DOORBELL_RANGE, OFFSET, index_in_dw);
+		doorbell_range = REG_SET_FIELD(doorbell_range, BIF_SDMA0_DOORBELL_RANGE, SIZE, range_dw_size);
 	} else
 		doorbell_range = REG_SET_FIELD(doorbell_range, BIF_SDMA0_DOORBELL_RANGE, SIZE, 0);
 
drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c +2 -1
index 127b85983e8f..e65e9bc52bd4 100644
@@ -1520,7 +1520,8 @@ static int sdma_v4_0_sw_init(void *handle)
 				ring->use_doorbell?"true":"false");
 
 		/* doorbell size is 2 dwords, get DWORD offset */
-		ring->doorbell_index = adev->doorbell_index.sdma_engine[i] << 1;
+		ring->doorbell_index = adev->doorbell_index.sdma_engine[i]
+				* adev->doorbell_index.entry_dw_size;
 
 		sprintf(ring->name, "sdma%d", i);
 		r = amdgpu_ring_init(adev, ring, 1024,
drivers/gpu/drm/amd/amdgpu/soc15.c +1 -1
index 99ebcf29dcb0..aad72ac80361 100644
@@ -980,7 +980,7 @@ static void soc15_doorbell_range_init(struct amdgpu_device *adev)
 		ring = &adev->sdma.instance[i].ring;
 		adev->nbio_funcs->sdma_doorbell_range(adev, i,
 			ring->use_doorbell, ring->doorbell_index,
-			adev->doorbell_index.sdma_doorbell_range);
+			adev->doorbell_index.dw_range_per_sdma_eng);
 	}
 
 	adev->nbio_funcs->ih_doorbell_range(adev, adev->irq.ih.use_doorbell,
drivers/gpu/drm/amd/amdgpu/vega10_reg_init.c +5 -1
index 4b5d60ea3e78..d2409df2dde9 100644
@@ -58,6 +58,7 @@ int vega10_reg_base_init(struct amdgpu_device *adev)
 
 void vega10_doorbell_index_init(struct amdgpu_device *adev)
 {
+	adev->doorbell_index.entry_dw_size = 2;
 	adev->doorbell_index.kiq = AMDGPU_DOORBELL64_KIQ;
 	adev->doorbell_index.mec_ring0 = AMDGPU_DOORBELL64_MEC_RING0;
 	adev->doorbell_index.mec_ring1 = AMDGPU_DOORBELL64_MEC_RING1;
@@ -83,6 +84,9 @@ void vega10_doorbell_index_init(struct amdgpu_device *adev)
 	adev->doorbell_index.uvd_vce.vce_ring6_7 = AMDGPU_DOORBELL64_VCE_RING6_7;
 	/* In unit of dword doorbell */
 	adev->doorbell_index.max_assignment = AMDGPU_DOORBELL64_MAX_ASSIGNMENT << 1;
-	adev->doorbell_index.sdma_doorbell_range = 4;
+	adev->doorbell_index.dw_range_per_sdma_eng =
+			(adev->doorbell_index.sdma_engine[1]
+			- adev->doorbell_index.sdma_engine[0])
+			* adev->doorbell_index.entry_dw_size;
 }
 
drivers/gpu/drm/amd/amdgpu/vega20_reg_init.c +5 -1
index 53716c593b2b..b28c5999d8f0 100644
@@ -56,6 +56,7 @@ int vega20_reg_base_init(struct amdgpu_device *adev)
 
 void vega20_doorbell_index_init(struct amdgpu_device *adev)
 {
+	adev->doorbell_index.entry_dw_size = 2;
 	adev->doorbell_index.kiq = AMDGPU_VEGA20_DOORBELL_KIQ;
 	adev->doorbell_index.mec_ring0 = AMDGPU_VEGA20_DOORBELL_MEC_RING0;
 	adev->doorbell_index.mec_ring1 = AMDGPU_VEGA20_DOORBELL_MEC_RING1;
@@ -86,6 +87,9 @@ void vega20_doorbell_index_init(struct amdgpu_device *adev)
 	adev->doorbell_index.uvd_vce.vce_ring4_5 = AMDGPU_VEGA20_DOORBELL64_VCE_RING4_5;
 	adev->doorbell_index.uvd_vce.vce_ring6_7 = AMDGPU_VEGA20_DOORBELL64_VCE_RING6_7;
 	adev->doorbell_index.max_assignment = AMDGPU_VEGA20_DOORBELL_MAX_ASSIGNMENT << 1;
-	adev->doorbell_index.sdma_doorbell_range = 20;
+	adev->doorbell_index.dw_range_per_sdma_eng =
+			(adev->doorbell_index.sdma_engine[1]
+			- adev->doorbell_index.sdma_engine[0])
+			* adev->doorbell_index.entry_dw_size;
 }
 
Signature · 6 lines
2.17.1

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

A message that is not in the archive (sent off-list or not yet received): [email protected]

author
#2 lore raw

PATCH 2/5 drm/amdgpu: Fix a bug in setting CP_MEC_DOORBELL_RANGE_UPPER on SOC15

Because CP can use all doorbells outside the ones reserved for SDMA, IH, and VCN, so the value set to CP_MEC_DOORBELL_RANGE_UPPER should be the maximal index possible in a page.

Change-Id I402a56ce9a80e6c2ed2f96be431ae71ca88e73a4
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_doorbell.h | 1 +
 drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c        | 2 +-
 drivers/gpu/drm/amd/amdgpu/vega10_reg_init.c | 3 +++
 drivers/gpu/drm/amd/amdgpu/vega20_reg_init.c | 3 +++
 4 files changed, 8 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_doorbell.h +1 -0
index 5c8d04c353d0..90eca63605ea 100644
@@ -73,6 +73,7 @@ struct amdgpu_doorbell_index {
 		} uvd_vce;
 	};
 	uint32_t max_assignment;
+	uint32_t last_idx;
 	/* Per engine SDMA doorbell size in dword */
 	uint32_t dw_range_per_sdma_eng;
 };
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +1 -1
index 262ee3cf6f1c..0278e3ab6b94 100644
@@ -2998,7 +2998,7 @@ static int gfx_v9_0_kiq_init_register(struct amdgpu_ring *ring)
 		WREG32_SOC15(GC, 0, mmCP_MEC_DOORBELL_RANGE_LOWER,
 					(adev->doorbell_index.kiq * 2) << 2);
 		WREG32_SOC15(GC, 0, mmCP_MEC_DOORBELL_RANGE_UPPER,
-					(adev->doorbell_index.userqueue_end * 2) << 2);
+				(adev->doorbell_index.last_idx * 2) << 2);
 	}
 
 	WREG32_SOC15(GC, 0, mmCP_HQD_PQ_DOORBELL_CONTROL,
drivers/gpu/drm/amd/amdgpu/vega10_reg_init.c +3 -0
index d2409df2dde9..9eb8c9209231 100644
@@ -88,5 +88,8 @@ void vega10_doorbell_index_init(struct amdgpu_device *adev)
 			(adev->doorbell_index.sdma_engine[1]
 			- adev->doorbell_index.sdma_engine[0])
 			* adev->doorbell_index.entry_dw_size;
+
+	adev->doorbell_index.last_idx = PAGE_SIZE
+		/ (sizeof(uint32_t) * adev->doorbell_index.entry_dw_size) - 1;
 }
 
drivers/gpu/drm/amd/amdgpu/vega20_reg_init.c +3 -0
index b28c5999d8f0..aa8c7699c689 100644
@@ -91,5 +91,8 @@ void vega20_doorbell_index_init(struct amdgpu_device *adev)
 			(adev->doorbell_index.sdma_engine[1]
 			- adev->doorbell_index.sdma_engine[0])
 			* adev->doorbell_index.entry_dw_size;
+
+	adev->doorbell_index.last_idx = PAGE_SIZE
+		/ (sizeof(uint32_t) * adev->doorbell_index.entry_dw_size) - 1;
 }
 
Signature · 6 lines
2.17.1

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

A message that is not in the archive (sent off-list or not yet received): [email protected]

#4 lore raw

RE: [PATCH 2/5] drm/amdgpu: Fix a bug in setting CP_MEC_DOORBELL_RANGE_UPPER on SOC15

+ Clint/Alice

Hi Clint,

We think CP_MEC_DOORBELL_RANGE_LOWER/UPPER registers are used by MEC to check whether a doorbell routed to MEC belongs to MEC, is this understanding correct?

From the register spec, those registers are 27 bits. Does this mean MEC use all 27 bits to determine? For example, if we set lower/upper to [0, 4k], will a doorbell ring at 6K address be ignored by MEC?

Thanks,
Oak

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Zhao, Yong
Sent: Tuesday, February 5, 2019 3:31 PM
To: [email protected]
Cc: Zhao, Yong <[email protected]>
Subject: [PATCH 2/5] drm/amdgpu: Fix a bug in setting CP_MEC_DOORBELL_RANGE_UPPER on SOC15

Because CP can use all doorbells outside the ones reserved for SDMA, IH, and VCN, so the value set to CP_MEC_DOORBELL_RANGE_UPPER should be the maximal index possible in a page.

Change-Id I402a56ce9a80e6c2ed2f96be431ae71ca88e73a4
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_doorbell.h | 1 +
 drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c        | 2 +-
 drivers/gpu/drm/amd/amdgpu/vega10_reg_init.c | 3 +++  drivers/gpu/drm/amd/amdgpu/vega20_reg_init.c | 3 +++
 4 files changed, 8 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_doorbell.h +1 -0
index 5c8d04c353d0..90eca63605ea 100644
@@ -73,6 +73,7 @@ struct amdgpu_doorbell_index {
 		} uvd_vce;
 	};
 	uint32_t max_assignment;
+	uint32_t last_idx;
 	/* Per engine SDMA doorbell size in dword */
 	uint32_t dw_range_per_sdma_eng;
 };
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +1 -1
index 262ee3cf6f1c..0278e3ab6b94 100644
@@ -2998,7 +2998,7 @@ static int gfx_v9_0_kiq_init_register(struct amdgpu_ring *ring)
 		WREG32_SOC15(GC, 0, mmCP_MEC_DOORBELL_RANGE_LOWER,
 					(adev->doorbell_index.kiq * 2) << 2);
 		WREG32_SOC15(GC, 0, mmCP_MEC_DOORBELL_RANGE_UPPER,
-					(adev->doorbell_index.userqueue_end * 2) << 2);
+				(adev->doorbell_index.last_idx * 2) << 2);
 	}
 
 	WREG32_SOC15(GC, 0, mmCP_HQD_PQ_DOORBELL_CONTROL, diff --git a/drivers/gpu/drm/amd/amdgpu/vega10_reg_init.c b/drivers/gpu/drm/amd/amdgpu/vega10_reg_init.c

index d2409df2dde9..9eb8c9209231 100644

drivers/gpu/drm/amd/amdgpu/vega10_reg_init.c +3 -0
@@ -88,5 +88,8 @@ void vega10_doorbell_index_init(struct amdgpu_device *adev)
 			(adev->doorbell_index.sdma_engine[1]
 			- adev->doorbell_index.sdma_engine[0])
 			* adev->doorbell_index.entry_dw_size;
+
+	adev->doorbell_index.last_idx = PAGE_SIZE
+		/ (sizeof(uint32_t) * adev->doorbell_index.entry_dw_size) - 1;
 }
 
drivers/gpu/drm/amd/amdgpu/vega20_reg_init.c +3 -0
index b28c5999d8f0..aa8c7699c689 100644
@@ -91,5 +91,8 @@ void vega20_doorbell_index_init(struct amdgpu_device *adev)
 			(adev->doorbell_index.sdma_engine[1]
 			- adev->doorbell_index.sdma_engine[0])
 			* adev->doorbell_index.entry_dw_size;
+
+	adev->doorbell_index.last_idx = PAGE_SIZE
+		/ (sizeof(uint32_t) * adev->doorbell_index.entry_dw_size) - 1;
 }
 

--
2.17.1

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

A message that is not in the archive (sent off-list or not yet received): BL0PR12MB258079D4BB56B65F60C55C06806F0-b4cIHhjg/p/[email protected]

#6 lore raw

RE: [PATCH 2/5] drm/amdgpu: Fix a bug in setting CP_MEC_DOORBELL_RANGE_UPPER on SOC15

Hey Oak,

Interesting you should ask since this has been discussed a lot here recently. So I didn't know until recently that the nbif routes doorbells only using 11:2. So in each 4k page there is an area for the various doorbell recipients including cp gfx and compute.

The doorbell upper/lower in the CP only control the setting of a doorbell updated bit and currently uses the full 27:2. The CP also uses the full 27:2 to match the doorbell to a queue slot and initiate work.

So for your example if you set the ranges to 4k then the CP would not consider a 6k address to match the MEC range and would not actually trigger this doorbell updated logic. This logic is only needed for waking up an idle scheduler and for power gating support.

We are changing the hardware in the doorbell range check to only look at 11:2 to match the nbif routing logic. With the current hardware I am not even sure how you configure the range registers if you are using PASID in bits 27:12 of the doorbell. The default for those registers says that compute gets everything from gfx (0x12) up to 3fffff.

How do you actually configure these currently, do you leave these defaults? That seems like the only way to have it pseudo work without the coming hardware change.

Thanks
Clint

-----Original Message-----
From: Zeng, Oak
Sent: Wednesday, February 06, 2019 10:23 AM
To: Zhao, Yong <[email protected]>; [email protected]; Knott, William <[email protected]>; Yang, Alice (SRDC 3D) <[email protected]>
Cc: Zhao, Yong <[email protected]>
Subject: RE: [PATCH 2/5] drm/amdgpu: Fix a bug in setting CP_MEC_DOORBELL_RANGE_UPPER on SOC15

+ Clint/Alice

Hi Clint,

We think CP_MEC_DOORBELL_RANGE_LOWER/UPPER registers are used by MEC to check whether a doorbell routed to MEC belongs to MEC, is this understanding correct?

From the register spec, those registers are 27 bits. Does this mean MEC use all 27 bits to determine? For example, if we set lower/upper to [0, 4k], will a doorbell ring at 6K address be ignored by MEC?

Thanks,
Oak

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Zhao, Yong
Sent: Tuesday, February 5, 2019 3:31 PM
To: [email protected]
Cc: Zhao, Yong <[email protected]>
Subject: [PATCH 2/5] drm/amdgpu: Fix a bug in setting CP_MEC_DOORBELL_RANGE_UPPER on SOC15

Because CP can use all doorbells outside the ones reserved for SDMA, IH, and VCN, so the value set to CP_MEC_DOORBELL_RANGE_UPPER should be the maximal index possible in a page.

Change-Id I402a56ce9a80e6c2ed2f96be431ae71ca88e73a4
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_doorbell.h | 1 +
 drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c        | 2 +-
 drivers/gpu/drm/amd/amdgpu/vega10_reg_init.c | 3 +++  drivers/gpu/drm/amd/amdgpu/vega20_reg_init.c | 3 +++
 4 files changed, 8 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_doorbell.h +1 -0
index 5c8d04c353d0..90eca63605ea 100644
@@ -73,6 +73,7 @@ struct amdgpu_doorbell_index {
 		} uvd_vce;
 	};
 	uint32_t max_assignment;
+	uint32_t last_idx;
 	/* Per engine SDMA doorbell size in dword */
 	uint32_t dw_range_per_sdma_eng;
 };
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +1 -1
index 262ee3cf6f1c..0278e3ab6b94 100644
@@ -2998,7 +2998,7 @@ static int gfx_v9_0_kiq_init_register(struct amdgpu_ring *ring)
 		WREG32_SOC15(GC, 0, mmCP_MEC_DOORBELL_RANGE_LOWER,
 					(adev->doorbell_index.kiq * 2) << 2);
 		WREG32_SOC15(GC, 0, mmCP_MEC_DOORBELL_RANGE_UPPER,
-					(adev->doorbell_index.userqueue_end * 2) << 2);
+				(adev->doorbell_index.last_idx * 2) << 2);
 	}
 
 	WREG32_SOC15(GC, 0, mmCP_HQD_PQ_DOORBELL_CONTROL, diff --git a/drivers/gpu/drm/amd/amdgpu/vega10_reg_init.c b/drivers/gpu/drm/amd/amdgpu/vega10_reg_init.c

index d2409df2dde9..9eb8c9209231 100644

drivers/gpu/drm/amd/amdgpu/vega10_reg_init.c +3 -0
@@ -88,5 +88,8 @@ void vega10_doorbell_index_init(struct amdgpu_device *adev)
 			(adev->doorbell_index.sdma_engine[1]
 			- adev->doorbell_index.sdma_engine[0])
 			* adev->doorbell_index.entry_dw_size;
+
+	adev->doorbell_index.last_idx = PAGE_SIZE
+		/ (sizeof(uint32_t) * adev->doorbell_index.entry_dw_size) - 1;
 }
 
drivers/gpu/drm/amd/amdgpu/vega20_reg_init.c +3 -0
index b28c5999d8f0..aa8c7699c689 100644
@@ -91,5 +91,8 @@ void vega20_doorbell_index_init(struct amdgpu_device *adev)
 			(adev->doorbell_index.sdma_engine[1]
 			- adev->doorbell_index.sdma_engine[0])
 			* adev->doorbell_index.entry_dw_size;
+
+	adev->doorbell_index.last_idx = PAGE_SIZE
+		/ (sizeof(uint32_t) * adev->doorbell_index.entry_dw_size) - 1;
 }
 

--
2.17.1

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

author
#7 lore raw

PATCH 3/5 drm/amdgpu: Delete user queue doorbell variables

In reply to a message not in the archive

They are no longer used, so delete them to avoid confusion.

Change-Id I3cf23fe7110ff88f53c0c279b2b4ec8d1a53b87c
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_doorbell.h | 8 --------
 drivers/gpu/drm/amd/amdgpu/vega10_reg_init.c | 2 --
 drivers/gpu/drm/amd/amdgpu/vega20_reg_init.c | 2 --
 3 files changed, 12 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_doorbell.h +0 -8
index 90eca63605ea..59c41841cbce 100644
@@ -49,8 +49,6 @@ struct amdgpu_doorbell_index {
 	uint32_t mec_ring5;
 	uint32_t mec_ring6;
 	uint32_t mec_ring7;
-	uint32_t userqueue_start;
-	uint32_t userqueue_end;
 	uint32_t gfx_ring0;
 	uint32_t sdma_engine[8];
 	uint32_t ih;
@@ -113,8 +111,6 @@ typedef enum _AMDGPU_VEGA20_DOORBELL_ASSIGNMENT
 	AMDGPU_VEGA20_DOORBELL_MEC_RING5               = 0x008,
 	AMDGPU_VEGA20_DOORBELL_MEC_RING6               = 0x009,
 	AMDGPU_VEGA20_DOORBELL_MEC_RING7               = 0x00A,
-	AMDGPU_VEGA20_DOORBELL_USERQUEUE_START	       = 0x00B,
-	AMDGPU_VEGA20_DOORBELL_USERQUEUE_END	       = 0x08A,
 	AMDGPU_VEGA20_DOORBELL_GFX_RING0               = 0x08B,
 	/* SDMA:256~335*/
 	AMDGPU_VEGA20_DOORBELL_sDMA_ENGINE0            = 0x100,
@@ -178,10 +174,6 @@ typedef enum _AMDGPU_DOORBELL64_ASSIGNMENT
 	AMDGPU_DOORBELL64_MEC_RING6               = 0x09,
 	AMDGPU_DOORBELL64_MEC_RING7               = 0x0a,
 
-	/* User queue doorbell range (128 doorbells) */
-	AMDGPU_DOORBELL64_USERQUEUE_START         = 0x0b,
-	AMDGPU_DOORBELL64_USERQUEUE_END           = 0x8a,
-
 	/* Graphics engine */
 	AMDGPU_DOORBELL64_GFX_RING0               = 0x8b,
 
drivers/gpu/drm/amd/amdgpu/vega10_reg_init.c +0 -2
index 9eb8c9209231..65214c7b0b20 100644
@@ -68,8 +68,6 @@ void vega10_doorbell_index_init(struct amdgpu_device *adev)
 	adev->doorbell_index.mec_ring5 = AMDGPU_DOORBELL64_MEC_RING5;
 	adev->doorbell_index.mec_ring6 = AMDGPU_DOORBELL64_MEC_RING6;
 	adev->doorbell_index.mec_ring7 = AMDGPU_DOORBELL64_MEC_RING7;
-	adev->doorbell_index.userqueue_start = AMDGPU_DOORBELL64_USERQUEUE_START;
-	adev->doorbell_index.userqueue_end = AMDGPU_DOORBELL64_USERQUEUE_END;
 	adev->doorbell_index.gfx_ring0 = AMDGPU_DOORBELL64_GFX_RING0;
 	adev->doorbell_index.sdma_engine[0] = AMDGPU_DOORBELL64_sDMA_ENGINE0;
 	adev->doorbell_index.sdma_engine[1] = AMDGPU_DOORBELL64_sDMA_ENGINE1;
drivers/gpu/drm/amd/amdgpu/vega20_reg_init.c +0 -2
index aa8c7699c689..a388d306391a 100644
@@ -66,8 +66,6 @@ void vega20_doorbell_index_init(struct amdgpu_device *adev)
 	adev->doorbell_index.mec_ring5 = AMDGPU_VEGA20_DOORBELL_MEC_RING5;
 	adev->doorbell_index.mec_ring6 = AMDGPU_VEGA20_DOORBELL_MEC_RING6;
 	adev->doorbell_index.mec_ring7 = AMDGPU_VEGA20_DOORBELL_MEC_RING7;
-	adev->doorbell_index.userqueue_start = AMDGPU_VEGA20_DOORBELL_USERQUEUE_START;
-	adev->doorbell_index.userqueue_end = AMDGPU_VEGA20_DOORBELL_USERQUEUE_END;
 	adev->doorbell_index.gfx_ring0 = AMDGPU_VEGA20_DOORBELL_GFX_RING0;
 	adev->doorbell_index.sdma_engine[0] = AMDGPU_VEGA20_DOORBELL_sDMA_ENGINE0;
 	adev->doorbell_index.sdma_engine[1] = AMDGPU_VEGA20_DOORBELL_sDMA_ENGINE1;
Signature · 6 lines
2.17.1

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
author
#8 lore raw

PATCH 4/5 drm/amdkfd: Fix bugs regarding CP user queue doorbells mask on SOC15

In reply to a message not in the archive

Reserved doorbells for SDMA IH and VCN were not properly masked out when allocating doorbells for CP user queues. This patch fixed that.

Change-Id I670adfc3fd7725d2ed0bd9665cb7f69f8b9023c2
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c    | 17 +++++++++++----
 drivers/gpu/drm/amd/amdgpu/amdgpu_doorbell.h  |  4 ++++
 drivers/gpu/drm/amd/amdgpu/vega10_reg_init.c  |  3 +++
 drivers/gpu/drm/amd/amdgpu/vega20_reg_init.c  |  3 +++
 drivers/gpu/drm/amd/amdkfd/kfd_priv.h         |  9 ++++++++
 drivers/gpu/drm/amd/amdkfd/kfd_process.c      | 21 ++++++++++++++-----
 .../gpu/drm/amd/include/kgd_kfd_interface.h   | 19 ++++++-----------
 7 files changed, 54 insertions(+), 22 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c +13 -4
index e957e42c539a..ee8527701731 100644
@@ -196,11 +196,20 @@ void amdgpu_amdkfd_device_init(struct amdgpu_device *adev)
 			gpu_resources.sdma_doorbell[1][i+1] =
 				adev->doorbell_index.sdma_engine[1] + 0x200 + (i >> 1);
 		}
-		/* Doorbells 0x0e0-0ff and 0x2e0-2ff are reserved for
-		 * SDMA, IH and VCN. So don't use them for the CP.
+
+		/* Because of the setting in registers like
+		 * SDMA0_DOORBELL_RANGE etc., BIF statically uses the
+		 * lower 12 bits of doorbell address for routing. In
+		 * order to route the CP queue doorbells to CP engine,
+		 * the doorbells allocated to CP queues have to be
+		 * outside the range set for SDMA, VCN, and IH blocks
+		 * Prior to SOC15, all queues use queue ID to
+		 * determine doorbells.
 		 */
-		gpu_resources.reserved_doorbell_mask = 0x1e0;
-		gpu_resources.reserved_doorbell_val  = 0x0e0;
+		gpu_resources.reserved_doorbells_start =
+				adev->doorbell_index.sdma_engine[0];
+		gpu_resources.reserved_doorbells_end =
+				adev->doorbell_index.last_non_cp;
 
 		kgd2kfd_device_init(adev->kfd.dev, &gpu_resources);
 	}
drivers/gpu/drm/amd/amdgpu/amdgpu_doorbell.h +4 -0
index 59c41841cbce..74b8e2bfabd3 100644
@@ -70,6 +70,7 @@ struct amdgpu_doorbell_index {
 			uint32_t vce_ring6_7;
 		} uvd_vce;
 	};
+	uint32_t last_non_cp;
 	uint32_t max_assignment;
 	uint32_t last_idx;
 	/* Per engine SDMA doorbell size in dword */
@@ -141,6 +142,7 @@ typedef enum _AMDGPU_VEGA20_DOORBELL_ASSIGNMENT
 	AMDGPU_VEGA20_DOORBELL64_VCE_RING2_3             = 0x18D,
 	AMDGPU_VEGA20_DOORBELL64_VCE_RING4_5             = 0x18E,
 	AMDGPU_VEGA20_DOORBELL64_VCE_RING6_7             = 0x18F,
+	AMDGPU_VEGA20_DOORBELL64_LAST_NON_CP             = AMDGPU_VEGA20_DOORBELL64_VCE_RING6_7,
 	AMDGPU_VEGA20_DOORBELL_MAX_ASSIGNMENT            = 0x18F,
 	AMDGPU_VEGA20_DOORBELL_INVALID                   = 0xFFFF
 } AMDGPU_VEGA20_DOORBELL_ASSIGNMENT;
@@ -216,6 +218,8 @@ typedef enum _AMDGPU_DOORBELL64_ASSIGNMENT
 	AMDGPU_DOORBELL64_VCE_RING4_5             = 0xFE,
 	AMDGPU_DOORBELL64_VCE_RING6_7             = 0xFF,
 
+	AMDGPU_DOORBELL64_LAST_NON_CP             = AMDGPU_DOORBELL64_VCE_RING6_7,
+
 	AMDGPU_DOORBELL64_MAX_ASSIGNMENT          = 0xFF,
 	AMDGPU_DOORBELL64_INVALID                 = 0xFFFF
 } AMDGPU_DOORBELL64_ASSIGNMENT;
drivers/gpu/drm/amd/amdgpu/vega10_reg_init.c +3 -0
index 65214c7b0b20..76166c0ec509 100644
@@ -80,6 +80,9 @@ void vega10_doorbell_index_init(struct amdgpu_device *adev)
 	adev->doorbell_index.uvd_vce.vce_ring2_3 = AMDGPU_DOORBELL64_VCE_RING2_3;
 	adev->doorbell_index.uvd_vce.vce_ring4_5 = AMDGPU_DOORBELL64_VCE_RING4_5;
 	adev->doorbell_index.uvd_vce.vce_ring6_7 = AMDGPU_DOORBELL64_VCE_RING6_7;
+
+	adev->doorbell_index.last_non_cp = AMDGPU_DOORBELL64_LAST_NON_CP;
+
 	/* In unit of dword doorbell */
 	adev->doorbell_index.max_assignment = AMDGPU_DOORBELL64_MAX_ASSIGNMENT << 1;
 	adev->doorbell_index.dw_range_per_sdma_eng =
drivers/gpu/drm/amd/amdgpu/vega20_reg_init.c +3 -0
index a388d306391a..10df2fed5a99 100644
@@ -84,6 +84,9 @@ void vega20_doorbell_index_init(struct amdgpu_device *adev)
 	adev->doorbell_index.uvd_vce.vce_ring2_3 = AMDGPU_VEGA20_DOORBELL64_VCE_RING2_3;
 	adev->doorbell_index.uvd_vce.vce_ring4_5 = AMDGPU_VEGA20_DOORBELL64_VCE_RING4_5;
 	adev->doorbell_index.uvd_vce.vce_ring6_7 = AMDGPU_VEGA20_DOORBELL64_VCE_RING6_7;
+
+	adev->doorbell_index.last_non_cp = AMDGPU_VEGA20_DOORBELL64_LAST_NON_CP;
+
 	adev->doorbell_index.max_assignment = AMDGPU_VEGA20_DOORBELL_MAX_ASSIGNMENT << 1;
 	adev->doorbell_index.dw_range_per_sdma_eng =
 			(adev->doorbell_index.sdma_engine[1]
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +9 -0
index e5ebcca7f031..6b8459f852cc 100644
@@ -103,6 +103,15 @@
 
 #define KFD_KERNEL_QUEUE_SIZE 2048
 
+/* 512 = 0x200
+ * On SOC15, the doorbell index distance for SDMA RLC i and (i + 1) in the
+ * same SDMA engine, where i is a even number.
+ * For 8-bytes doorbells, it ensures that the mirror doorbell range (in terms
+ * of low 12 bit address for each HW engine) on the second doorbell page is
+ * the same as the range of the first doorbell page.*/
+#define KFD_QUEUE_DOORBELL_MIRROR_OFFSET 512
+
+
 /*
  * Kernel module parameter to specify maximum number of supported queues per
  * device
drivers/gpu/drm/amd/amdkfd/kfd_process.c +16 -5
index 80b36e860a0a..e904d6036b3d 100644
@@ -607,13 +607,24 @@ static int init_doorbell_bitmap(struct qcm_process_device *qpd,
 	if (!qpd->doorbell_bitmap)
 		return -ENOMEM;
 
-	/* Mask out any reserved doorbells */
-	for (i = 0; i < KFD_MAX_NUM_OF_QUEUES_PER_PROCESS; i++)
-		if ((dev->shared_resources.reserved_doorbell_mask & i) ==
-		    dev->shared_resources.reserved_doorbell_val) {
+	/* Mask out all reserved doorbells for SDMA, IH, and VCN on SOC15.
+	 * Because of the setting in registers like SDMA0_DOORBELL_RANGE etc.,
+	 * BIF statically uses the lower 12 bits of doorbell address for
+	 * routing. In order to route the CP queue doorbells to CP engine,
+	 * the doorbells allocated to CP queues have to be outside the range
+	 * set for SDMA, VCN, and IH blocks.
+	 * Prior to SOC15, all queues use queue ID to
+	 * determine doorbells. */
+	for (i = 0; i < KFD_MAX_NUM_OF_QUEUES_PER_PROCESS / 2; i++) {
+		if (i >= dev->shared_resources.reserved_doorbells_start
+			&& i <= dev->shared_resources.reserved_doorbells_end) {
 			set_bit(i, qpd->doorbell_bitmap);
-			pr_debug("reserved doorbell 0x%03x\n", i);
+			set_bit(i + KFD_QUEUE_DOORBELL_MIRROR_OFFSET,
+				qpd->doorbell_bitmap);
+			pr_debug("reserved doorbell 0x%03x and 0x%03x\n", i,
+				i + KFD_QUEUE_DOORBELL_MIRROR_OFFSET);
 		}
+	}
 
 	return 0;
 }
drivers/gpu/drm/amd/include/kgd_kfd_interface.h +6 -13
index 83d960110d23..b1bf45419d93 100644
@@ -137,20 +137,13 @@ struct kgd2kfd_shared_resources {
 	/* Bit n == 1 means Queue n is available for KFD */
 	DECLARE_BITMAP(queue_bitmap, KGD_MAX_QUEUES);
 
-	/* Doorbell assignments (SOC15 and later chips only). Only
-	 * specific doorbells are routed to each SDMA engine. Others
-	 * are routed to IH and VCN. They are not usable by the CP.
-	 *
-	 * Any doorbell number D that satisfies the following condition
-	 * is reserved: (D & reserved_doorbell_mask) == reserved_doorbell_val
-	 *
-	 * KFD currently uses 1024 (= 0x3ff) doorbells per process. If
-	 * doorbells 0x0e0-0x0ff and 0x2e0-0x2ff are reserved, that means
-	 * mask would be set to 0x1e0 and val set to 0x0e0.
-	 */
 	unsigned int sdma_doorbell[2][8];
-	unsigned int reserved_doorbell_mask;
-	unsigned int reserved_doorbell_val;
+
+	/* From SOC15 onwards, the doorbell indexes reserved for SDMA, IH,
+	 * and VCN
+	 */
+	unsigned int reserved_doorbells_start;
+	unsigned int reserved_doorbells_end;
 
 	/* Base address of doorbell aperture. */
 	phys_addr_t doorbell_physical_address;
Signature · 6 lines
2.17.1

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

A message that is not in the archive (sent off-list or not yet received): [email protected]

author
#10 lore raw

Re: [PATCH 4/5] drm/amdkfd: Fix bugs regarding CP user queue doorbells mask on SOC15

Felix,

Can you review the 4th and 5th patch? They were kept unchanged.

Regards,
Yong
________________________________
From: Zhao, Yong
Sent: Tuesday, February 5, 2019 3:31 PM
To: [email protected]
Cc: Zhao, Yong
Subject: [PATCH 4/5] drm/amdkfd: Fix bugs regarding CP user queue doorbells mask on SOC15

Reserved doorbells for SDMA IH and VCN were not properly masked out when allocating doorbells for CP user queues. This patch fixed that.

Change-Id I670adfc3fd7725d2ed0bd9665cb7f69f8b9023c2
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c    | 17 +++++++++++----
 drivers/gpu/drm/amd/amdgpu/amdgpu_doorbell.h  |  4 ++++
 drivers/gpu/drm/amd/amdgpu/vega10_reg_init.c  |  3 +++
 drivers/gpu/drm/amd/amdgpu/vega20_reg_init.c  |  3 +++
 drivers/gpu/drm/amd/amdkfd/kfd_priv.h         |  9 ++++++++
 drivers/gpu/drm/amd/amdkfd/kfd_process.c      | 21 ++++++++++++++-----
 .../gpu/drm/amd/include/kgd_kfd_interface.h   | 19 ++++++-----------
 7 files changed, 54 insertions(+), 22 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c +13 -4
index e957e42c539a..ee8527701731 100644
@@ -196,11 +196,20 @@ void amdgpu_amdkfd_device_init(struct amdgpu_device *adev)
                         gpu_resources.sdma_doorbell[1][i+1] =
                                 adev->doorbell_index.sdma_engine[1] + 0x200 + (i >> 1);
                 }
-               /* Doorbells 0x0e0-0ff and 0x2e0-2ff are reserved for
-                * SDMA, IH and VCN. So don't use them for the CP.
+
+               /* Because of the setting in registers like
+                * SDMA0_DOORBELL_RANGE etc., BIF statically uses the
+                * lower 12 bits of doorbell address for routing. In
+                * order to route the CP queue doorbells to CP engine,
+                * the doorbells allocated to CP queues have to be
+                * outside the range set for SDMA, VCN, and IH blocks
+                * Prior to SOC15, all queues use queue ID to
+                * determine doorbells.
                  */
-               gpu_resources.reserved_doorbell_mask = 0x1e0;
-               gpu_resources.reserved_doorbell_val  = 0x0e0;
+               gpu_resources.reserved_doorbells_start =
+                               adev->doorbell_index.sdma_engine[0];
+               gpu_resources.reserved_doorbells_end =
+                               adev->doorbell_index.last_non_cp;
 
                 kgd2kfd_device_init(adev->kfd.dev, &gpu_resources);
         }
drivers/gpu/drm/amd/amdgpu/amdgpu_doorbell.h +4 -0
index 59c41841cbce..74b8e2bfabd3 100644
@@ -70,6 +70,7 @@ struct amdgpu_doorbell_index {
                         uint32_t vce_ring6_7;
                 } uvd_vce;
         };
+       uint32_t last_non_cp;
         uint32_t max_assignment;
         uint32_t last_idx;
         /* Per engine SDMA doorbell size in dword */
@@ -141,6 +142,7 @@ typedef enum _AMDGPU_VEGA20_DOORBELL_ASSIGNMENT
         AMDGPU_VEGA20_DOORBELL64_VCE_RING2_3             = 0x18D,
         AMDGPU_VEGA20_DOORBELL64_VCE_RING4_5             = 0x18E,
         AMDGPU_VEGA20_DOORBELL64_VCE_RING6_7             = 0x18F,
+       AMDGPU_VEGA20_DOORBELL64_LAST_NON_CP             = AMDGPU_VEGA20_DOORBELL64_VCE_RING6_7,
         AMDGPU_VEGA20_DOORBELL_MAX_ASSIGNMENT            = 0x18F,
         AMDGPU_VEGA20_DOORBELL_INVALID                   = 0xFFFF
 } AMDGPU_VEGA20_DOORBELL_ASSIGNMENT;
@@ -216,6 +218,8 @@ typedef enum _AMDGPU_DOORBELL64_ASSIGNMENT
         AMDGPU_DOORBELL64_VCE_RING4_5             = 0xFE,
         AMDGPU_DOORBELL64_VCE_RING6_7             = 0xFF,
 
+       AMDGPU_DOORBELL64_LAST_NON_CP             = AMDGPU_DOORBELL64_VCE_RING6_7,
+
         AMDGPU_DOORBELL64_MAX_ASSIGNMENT          = 0xFF,
         AMDGPU_DOORBELL64_INVALID                 = 0xFFFF
 } AMDGPU_DOORBELL64_ASSIGNMENT;
drivers/gpu/drm/amd/amdgpu/vega10_reg_init.c +3 -0
index 65214c7b0b20..76166c0ec509 100644
@@ -80,6 +80,9 @@ void vega10_doorbell_index_init(struct amdgpu_device *adev)
         adev->doorbell_index.uvd_vce.vce_ring2_3 = AMDGPU_DOORBELL64_VCE_RING2_3;
         adev->doorbell_index.uvd_vce.vce_ring4_5 = AMDGPU_DOORBELL64_VCE_RING4_5;
         adev->doorbell_index.uvd_vce.vce_ring6_7 = AMDGPU_DOORBELL64_VCE_RING6_7;
+
+       adev->doorbell_index.last_non_cp = AMDGPU_DOORBELL64_LAST_NON_CP;
+
         /* In unit of dword doorbell */
         adev->doorbell_index.max_assignment = AMDGPU_DOORBELL64_MAX_ASSIGNMENT << 1;
         adev->doorbell_index.dw_range_per_sdma_eng =
drivers/gpu/drm/amd/amdgpu/vega20_reg_init.c +3 -0
index a388d306391a..10df2fed5a99 100644
@@ -84,6 +84,9 @@ void vega20_doorbell_index_init(struct amdgpu_device *adev)
         adev->doorbell_index.uvd_vce.vce_ring2_3 = AMDGPU_VEGA20_DOORBELL64_VCE_RING2_3;
         adev->doorbell_index.uvd_vce.vce_ring4_5 = AMDGPU_VEGA20_DOORBELL64_VCE_RING4_5;
         adev->doorbell_index.uvd_vce.vce_ring6_7 = AMDGPU_VEGA20_DOORBELL64_VCE_RING6_7;
+
+       adev->doorbell_index.last_non_cp = AMDGPU_VEGA20_DOORBELL64_LAST_NON_CP;
+
         adev->doorbell_index.max_assignment = AMDGPU_VEGA20_DOORBELL_MAX_ASSIGNMENT << 1;
         adev->doorbell_index.dw_range_per_sdma_eng =
                         (adev->doorbell_index.sdma_engine[1]
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +9 -0
index e5ebcca7f031..6b8459f852cc 100644
@@ -103,6 +103,15 @@
 
 #define KFD_KERNEL_QUEUE_SIZE 2048
 
+/* 512 = 0x200
+ * On SOC15, the doorbell index distance for SDMA RLC i and (i + 1) in the
+ * same SDMA engine, where i is a even number.
+ * For 8-bytes doorbells, it ensures that the mirror doorbell range (in terms
+ * of low 12 bit address for each HW engine) on the second doorbell page is
+ * the same as the range of the first doorbell page.*/
+#define KFD_QUEUE_DOORBELL_MIRROR_OFFSET 512
+
+
 /*
  * Kernel module parameter to specify maximum number of supported queues per
  * device
drivers/gpu/drm/amd/amdkfd/kfd_process.c +16 -5
index 80b36e860a0a..e904d6036b3d 100644
@@ -607,13 +607,24 @@ static int init_doorbell_bitmap(struct qcm_process_device *qpd,
         if (!qpd->doorbell_bitmap)
                 return -ENOMEM;
 
-       /* Mask out any reserved doorbells */
-       for (i = 0; i < KFD_MAX_NUM_OF_QUEUES_PER_PROCESS; i++)
-               if ((dev->shared_resources.reserved_doorbell_mask & i) ==
-                   dev->shared_resources.reserved_doorbell_val) {
+       /* Mask out all reserved doorbells for SDMA, IH, and VCN on SOC15.
+        * Because of the setting in registers like SDMA0_DOORBELL_RANGE etc.,
+        * BIF statically uses the lower 12 bits of doorbell address for
+        * routing. In order to route the CP queue doorbells to CP engine,
+        * the doorbells allocated to CP queues have to be outside the range
+        * set for SDMA, VCN, and IH blocks.
+        * Prior to SOC15, all queues use queue ID to
+        * determine doorbells. */
+       for (i = 0; i < KFD_MAX_NUM_OF_QUEUES_PER_PROCESS / 2; i++) {
+               if (i >= dev->shared_resources.reserved_doorbells_start
+                       && i <= dev->shared_resources.reserved_doorbells_end) {
                         set_bit(i, qpd->doorbell_bitmap);
-                       pr_debug("reserved doorbell 0x%03x\n", i);
+                       set_bit(i + KFD_QUEUE_DOORBELL_MIRROR_OFFSET,
+                               qpd->doorbell_bitmap);
+                       pr_debug("reserved doorbell 0x%03x and 0x%03x\n", i,
+                               i + KFD_QUEUE_DOORBELL_MIRROR_OFFSET);
                 }
+       }
 
         return 0;
 }
drivers/gpu/drm/amd/include/kgd_kfd_interface.h +6 -13
index 83d960110d23..b1bf45419d93 100644
@@ -137,20 +137,13 @@ struct kgd2kfd_shared_resources {
         /* Bit n == 1 means Queue n is available for KFD */
         DECLARE_BITMAP(queue_bitmap, KGD_MAX_QUEUES);
 
-       /* Doorbell assignments (SOC15 and later chips only). Only
-        * specific doorbells are routed to each SDMA engine. Others
-        * are routed to IH and VCN. They are not usable by the CP.
-        *
-        * Any doorbell number D that satisfies the following condition
-        * is reserved: (D & reserved_doorbell_mask) == reserved_doorbell_val
-        *
-        * KFD currently uses 1024 (= 0x3ff) doorbells per process. If
-        * doorbells 0x0e0-0x0ff and 0x2e0-0x2ff are reserved, that means
-        * mask would be set to 0x1e0 and val set to 0x0e0.
-        */
         unsigned int sdma_doorbell[2][8];
-       unsigned int reserved_doorbell_mask;
-       unsigned int reserved_doorbell_val;
+
+       /* From SOC15 onwards, the doorbell indexes reserved for SDMA, IH,
+        * and VCN
+        */
+       unsigned int reserved_doorbells_start;
+       unsigned int reserved_doorbells_end;
 
         /* Base address of doorbell aperture. */
         phys_addr_t doorbell_physical_address;

--
2.17.1

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

#11 lore raw

Re: [PATCH 4/5] drm/amdkfd: Fix bugs regarding CP user queue doorbells mask on SOC15

In reply to a message not in the archive

The code is fine. Some comments about your comment changes inline to help clarify things a bit.

Quoted 24 lines · Yong

Reserved doorbells for SDMA IH and VCN were not properly masked out when allocating doorbells for CP user queues. This patch fixed that.

Change-Id I670adfc3fd7725d2ed0bd9665cb7f69f8b9023c2
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c    | 17 +++++++++++----
  drivers/gpu/drm/amd/amdgpu/amdgpu_doorbell.h  |  4 ++++
  drivers/gpu/drm/amd/amdgpu/vega10_reg_init.c  |  3 +++
  drivers/gpu/drm/amd/amdgpu/vega20_reg_init.c  |  3 +++
  drivers/gpu/drm/amd/amdkfd/kfd_priv.h         |  9 ++++++++
  drivers/gpu/drm/amd/amdkfd/kfd_process.c      | 21 ++++++++++++++-----
  .../gpu/drm/amd/include/kgd_kfd_interface.h   | 19 ++++++-----------
  7 files changed, 54 insertions(+), 22 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c +0 -1
index e957e42c539a..ee8527701731 100644
@@ -196,11 +196,20 @@ void amdgpu_amdkfd_device_init(struct amdgpu_device *adev)
  			gpu_resources.sdma_doorbell[1][i+1] =
  				adev->doorbell_index.sdma_engine[1] + 0x200 + (i >> 1);
  		}
-		/* Doorbells 0x0e0-0ff and 0x2e0-2ff are reserved for

drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c void amdgpu_amdkfd_device_init(struct amdgpu_device *adev) · line 207

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c +9 -1
-		 * SDMA, IH and VCN. So don't use them for the CP.
+
+		/* Because of the setting in registers like
+		 * SDMA0_DOORBELL_RANGE etc., BIF statically uses the
+		 * lower 12 bits of doorbell address for routing. In
+		 * order to route the CP queue doorbells to CP engine,
+		 * the doorbells allocated to CP queues have to be
+		 * outside the range set for SDMA, VCN, and IH blocks
+		 * Prior to SOC15, all queues use queue ID to
+		 * determine doorbells.

This comment mixes up cause and effect:

1. Doorbell routing by the BIF (cause)
2. Changes to doorbell assignment for user mode queues (effect)

The first is a HW change (cause). The second is a consequence from that (effect). Amdgpu doesn't know anything about KFD queue IDs. I'd just drop that sentence.

In this context, what distinguishes SOC15 from older chips is, that on older chips the BIF does not route doorbells. All doorbells can be used by all engines. Only on SOC15 and newer, KFD needs to know about how doorbells are routed by the BIF in order to correctly assign doorbells to queues. Therefore the reserved_doorbell_... and sdma_doorbell fields are only used on SOC15.

Quoted 126 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c +4 -2
  		 */
-		gpu_resources.reserved_doorbell_mask = 0x1e0;
-		gpu_resources.reserved_doorbell_val  = 0x0e0;
+		gpu_resources.reserved_doorbells_start =
+				adev->doorbell_index.sdma_engine[0];
+		gpu_resources.reserved_doorbells_end =
+				adev->doorbell_index.last_non_cp;
 
  		kgd2kfd_device_init(adev->kfd.dev, &gpu_resources);
  	}
drivers/gpu/drm/amd/amdgpu/amdgpu_doorbell.h +4 -0
index 59c41841cbce..74b8e2bfabd3 100644
@@ -70,6 +70,7 @@ struct amdgpu_doorbell_index {
  			uint32_t vce_ring6_7;
  		} uvd_vce;
  	};
+	uint32_t last_non_cp;
  	uint32_t max_assignment;
  	uint32_t last_idx;
  	/* Per engine SDMA doorbell size in dword */
@@ -141,6 +142,7 @@ typedef enum _AMDGPU_VEGA20_DOORBELL_ASSIGNMENT
  	AMDGPU_VEGA20_DOORBELL64_VCE_RING2_3             = 0x18D,
  	AMDGPU_VEGA20_DOORBELL64_VCE_RING4_5             = 0x18E,
  	AMDGPU_VEGA20_DOORBELL64_VCE_RING6_7             = 0x18F,
+	AMDGPU_VEGA20_DOORBELL64_LAST_NON_CP             = AMDGPU_VEGA20_DOORBELL64_VCE_RING6_7,
  	AMDGPU_VEGA20_DOORBELL_MAX_ASSIGNMENT            = 0x18F,
  	AMDGPU_VEGA20_DOORBELL_INVALID                   = 0xFFFF
  } AMDGPU_VEGA20_DOORBELL_ASSIGNMENT;
@@ -216,6 +218,8 @@ typedef enum _AMDGPU_DOORBELL64_ASSIGNMENT
  	AMDGPU_DOORBELL64_VCE_RING4_5             = 0xFE,
  	AMDGPU_DOORBELL64_VCE_RING6_7             = 0xFF,
 
+	AMDGPU_DOORBELL64_LAST_NON_CP             = AMDGPU_DOORBELL64_VCE_RING6_7,
+
  	AMDGPU_DOORBELL64_MAX_ASSIGNMENT          = 0xFF,
  	AMDGPU_DOORBELL64_INVALID                 = 0xFFFF
  } AMDGPU_DOORBELL64_ASSIGNMENT;
drivers/gpu/drm/amd/amdgpu/vega10_reg_init.c +3 -0
index 65214c7b0b20..76166c0ec509 100644
@@ -80,6 +80,9 @@ void vega10_doorbell_index_init(struct amdgpu_device *adev)
  	adev->doorbell_index.uvd_vce.vce_ring2_3 = AMDGPU_DOORBELL64_VCE_RING2_3;
  	adev->doorbell_index.uvd_vce.vce_ring4_5 = AMDGPU_DOORBELL64_VCE_RING4_5;
  	adev->doorbell_index.uvd_vce.vce_ring6_7 = AMDGPU_DOORBELL64_VCE_RING6_7;
+
+	adev->doorbell_index.last_non_cp = AMDGPU_DOORBELL64_LAST_NON_CP;
+
  	/* In unit of dword doorbell */
  	adev->doorbell_index.max_assignment = AMDGPU_DOORBELL64_MAX_ASSIGNMENT << 1;
  	adev->doorbell_index.dw_range_per_sdma_eng =
drivers/gpu/drm/amd/amdgpu/vega20_reg_init.c +3 -0
index a388d306391a..10df2fed5a99 100644
@@ -84,6 +84,9 @@ void vega20_doorbell_index_init(struct amdgpu_device *adev)
  	adev->doorbell_index.uvd_vce.vce_ring2_3 = AMDGPU_VEGA20_DOORBELL64_VCE_RING2_3;
  	adev->doorbell_index.uvd_vce.vce_ring4_5 = AMDGPU_VEGA20_DOORBELL64_VCE_RING4_5;
  	adev->doorbell_index.uvd_vce.vce_ring6_7 = AMDGPU_VEGA20_DOORBELL64_VCE_RING6_7;
+
+	adev->doorbell_index.last_non_cp = AMDGPU_VEGA20_DOORBELL64_LAST_NON_CP;
+
  	adev->doorbell_index.max_assignment = AMDGPU_VEGA20_DOORBELL_MAX_ASSIGNMENT << 1;
  	adev->doorbell_index.dw_range_per_sdma_eng =
  			(adev->doorbell_index.sdma_engine[1]
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +9 -0
index e5ebcca7f031..6b8459f852cc 100644
@@ -103,6 +103,15 @@
 
  #define KFD_KERNEL_QUEUE_SIZE 2048
 
+/* 512 = 0x200
+ * On SOC15, the doorbell index distance for SDMA RLC i and (i + 1) in the
+ * same SDMA engine, where i is a even number.
+ * For 8-bytes doorbells, it ensures that the mirror doorbell range (in terms
+ * of low 12 bit address for each HW engine) on the second doorbell page is
+ * the same as the range of the first doorbell page.*/
+#define KFD_QUEUE_DOORBELL_MIRROR_OFFSET 512
+
+
  /*
   * Kernel module parameter to specify maximum number of supported queues per
   * device
drivers/gpu/drm/amd/amdkfd/kfd_process.c +16 -5
index 80b36e860a0a..e904d6036b3d 100644
@@ -607,13 +607,24 @@ static int init_doorbell_bitmap(struct qcm_process_device *qpd,
  	if (!qpd->doorbell_bitmap)
  		return -ENOMEM;
 
-	/* Mask out any reserved doorbells */
-	for (i = 0; i < KFD_MAX_NUM_OF_QUEUES_PER_PROCESS; i++)
-		if ((dev->shared_resources.reserved_doorbell_mask & i) ==
-		    dev->shared_resources.reserved_doorbell_val) {
+	/* Mask out all reserved doorbells for SDMA, IH, and VCN on SOC15.
+	 * Because of the setting in registers like SDMA0_DOORBELL_RANGE etc.,
+	 * BIF statically uses the lower 12 bits of doorbell address for
+	 * routing. In order to route the CP queue doorbells to CP engine,
+	 * the doorbells allocated to CP queues have to be outside the range
+	 * set for SDMA, VCN, and IH blocks.
+	 * Prior to SOC15, all queues use queue ID to
+	 * determine doorbells. */
+	for (i = 0; i < KFD_MAX_NUM_OF_QUEUES_PER_PROCESS / 2; i++) {
+		if (i >= dev->shared_resources.reserved_doorbells_start
+			&& i <= dev->shared_resources.reserved_doorbells_end) {
  			set_bit(i, qpd->doorbell_bitmap);
-			pr_debug("reserved doorbell 0x%03x\n", i);
+			set_bit(i + KFD_QUEUE_DOORBELL_MIRROR_OFFSET,
+				qpd->doorbell_bitmap);
+			pr_debug("reserved doorbell 0x%03x and 0x%03x\n", i,
+				i + KFD_QUEUE_DOORBELL_MIRROR_OFFSET);
  		}
+	}
 
  	return 0;
  }
drivers/gpu/drm/amd/include/kgd_kfd_interface.h +0 -0
index 83d960110d23..b1bf45419d93 100644

drivers/gpu/drm/amd/include/kgd_kfd_interface.h struct kgd2kfd_shared_resources { · line 142

Quoted 6 lines
drivers/gpu/drm/amd/include/kgd_kfd_interface.h +0 -3
@@ -137,20 +137,13 @@ struct kgd2kfd_shared_resources {
  	/* Bit n == 1 means Queue n is available for KFD */
  	DECLARE_BITMAP(queue_bitmap, KGD_MAX_QUEUES);
 
-	/* Doorbell assignments (SOC15 and later chips only). Only
-	 * specific doorbells are routed to each SDMA engine. Others
-	 * are routed to IH and VCN. They are not usable by the CP.

This first paragraph is still applicable and explains why we need the sdma_doorbell array on SOC15 to assign doorbells for SDMA queues.

Quoted 4 lines
drivers/gpu/drm/amd/include/kgd_kfd_interface.h +0 -4
-	 *
-	 * Any doorbell number D that satisfies the following condition
-	 * is reserved: (D & reserved_doorbell_mask) == reserved_doorbell_val
-	 *

drivers/gpu/drm/amd/include/kgd_kfd_interface.h struct kgd2kfd_shared_resources { · line 143

Quoted 10 lines
drivers/gpu/drm/amd/include/kgd_kfd_interface.h +3 -6
-	 * KFD currently uses 1024 (= 0x3ff) doorbells per process. If
-	 * doorbells 0x0e0-0x0ff and 0x2e0-0x2ff are reserved, that means
-	 * mask would be set to 0x1e0 and val set to 0x0e0.
-	 */
  	unsigned int sdma_doorbell[2][8];
-	unsigned int reserved_doorbell_mask;
-	unsigned int reserved_doorbell_val;
+
+	/* From SOC15 onwards, the doorbell indexes reserved for SDMA, IH,
+	 * and VCN

The important bit that you should not forget to mention, is that these doorbells are not routed to the CP, so they're reserved (unusable) for CP queues.

Regards,
  Felix

drivers/gpu/drm/amd/include/kgd_kfd_interface.h struct kgd2kfd_shared_resources { · line 149

Quoted 6 lines
drivers/gpu/drm/amd/include/kgd_kfd_interface.h +3 -0
+	 */
+	unsigned int reserved_doorbells_start;
+	unsigned int reserved_doorbells_end;
 
  	/* Base address of doorbell aperture. */
  	phys_addr_t doorbell_physical_address;

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

author
#12 lore raw

PATCH 5/5 drm/amdkfd: Optimize out sdma doorbell array in kgd2kfd_shared_resources

In reply to a message not in the archive

We can directly calculate the sdma doorbell index in the process doorbell pages through the doorbell_index structure in amdgpu_device, so no need to cache them in kgd2kfd_shared_resources any more, resulting in more portable code.

Change-Id Ic657799856ed0256f36b01e502ef0cab263b1f49
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c    | 55 ++++++-------------
 .../drm/amd/amdkfd/kfd_device_queue_manager.c | 18 ++++--
 .../gpu/drm/amd/include/kgd_kfd_interface.h   |  2 +-
 3 files changed, 31 insertions(+), 44 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c +17 -38
index ee8527701731..e62c3703169a 100644
@@ -131,7 +131,7 @@ static void amdgpu_doorbell_get_kfd_info(struct amdgpu_device *adev,
 
 void amdgpu_amdkfd_device_init(struct amdgpu_device *adev)
 {
-	int i, n;
+	int i;
 	int last_valid_bit;
 
 	if (adev->kfd.dev) {
@@ -142,7 +142,9 @@ void amdgpu_amdkfd_device_init(struct amdgpu_device *adev)
 			.gpuvm_size = min(adev->vm_manager.max_pfn
 					  << AMDGPU_GPU_PAGE_SHIFT,
 					  AMDGPU_GMC_HOLE_START),
-			.drm_render_minor = adev->ddev->render->index
+			.drm_render_minor = adev->ddev->render->index,
+			.sdma_doorbell_idx = adev->doorbell_index.sdma_engine,
+
 		};
 
 		/* this is going to have a few of the MSBs set that we need to
@@ -172,45 +174,22 @@ void amdgpu_amdkfd_device_init(struct amdgpu_device *adev)
 				&gpu_resources.doorbell_aperture_size,
 				&gpu_resources.doorbell_start_offset);
 
-		if (adev->asic_type < CHIP_VEGA10) {
-			kgd2kfd_device_init(adev->kfd.dev, &gpu_resources);
-			return;
-		}
-
-		n = (adev->asic_type < CHIP_VEGA20) ? 2 : 8;
-
-		for (i = 0; i < n; i += 2) {
-			/* On SOC15 the BIF is involved in routing
-			 * doorbells using the low 12 bits of the
-			 * address. Communicate the assignments to
-			 * KFD. KFD uses two doorbell pages per
-			 * process in case of 64-bit doorbells so we
-			 * can use each doorbell assignment twice.
+		if (adev->asic_type >= CHIP_VEGA10) {
+			/* Because of the setting in registers like
+			 * SDMA0_DOORBELL_RANGE etc., BIF statically uses the
+			 * lower 12 bits of doorbell address for routing. In
+			 * order to route the CP queue doorbells to CP engine,
+			 * the doorbells allocated to CP queues have to be
+			 * outside the range set for SDMA, VCN, and IH blocks
+			 * Prior to SOC15, all queues use queue ID to
+			 * determine doorbells.
 			 */
-			gpu_resources.sdma_doorbell[0][i] =
-				adev->doorbell_index.sdma_engine[0] + (i >> 1);
-			gpu_resources.sdma_doorbell[0][i+1] =
-				adev->doorbell_index.sdma_engine[0] + 0x200 + (i >> 1);
-			gpu_resources.sdma_doorbell[1][i] =
-				adev->doorbell_index.sdma_engine[1] + (i >> 1);
-			gpu_resources.sdma_doorbell[1][i+1] =
-				adev->doorbell_index.sdma_engine[1] + 0x200 + (i >> 1);
+			gpu_resources.reserved_doorbells_start =
+					adev->doorbell_index.sdma_engine[0];
+			gpu_resources.reserved_doorbells_end =
+					adev->doorbell_index.last_non_cp;
 		}
 
-		/* Because of the setting in registers like
-		 * SDMA0_DOORBELL_RANGE etc., BIF statically uses the
-		 * lower 12 bits of doorbell address for routing. In
-		 * order to route the CP queue doorbells to CP engine,
-		 * the doorbells allocated to CP queues have to be
-		 * outside the range set for SDMA, VCN, and IH blocks
-		 * Prior to SOC15, all queues use queue ID to
-		 * determine doorbells.
-		 */
-		gpu_resources.reserved_doorbells_start =
-				adev->doorbell_index.sdma_engine[0];
-		gpu_resources.reserved_doorbells_end =
-				adev->doorbell_index.last_non_cp;
-
 		kgd2kfd_device_init(adev->kfd.dev, &gpu_resources);
 	}
 }
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +13 -5
index 8372556b52eb..81280ce5aa27 100644
@@ -134,12 +134,20 @@ static int allocate_doorbell(struct qcm_process_device *qpd, struct queue *q)
 		 */
 		q->doorbell_id = q->properties.queue_id;
 	} else if (q->properties.type == KFD_QUEUE_TYPE_SDMA) {
-		/* For SDMA queues on SOC15, use static doorbell
-		 * assignments based on the engine and queue.
+		/* For SDMA queues on SOC15 with 8-byte doorbell, use static
+		 * doorbell assignments based on the engine and queue id.
+		 * The doobell index distance between RLC (2*i) and (2*i+1)
+		 * for a SDMA engine is 512.
+		 * 512 8-byte doorbell distance (i.e. one page away) ensures
+		 * that SDMA RLC (2*i+1) doorbell lies exactly in the doorbell
+		 * OFFSET and SIZE set in register BIF_SDMA0_DOORBELL_RANGE.
 		 */
-		q->doorbell_id = dev->shared_resources.sdma_doorbell
-			[q->properties.sdma_engine_id]
-			[q->properties.sdma_queue_id];
+		unsigned int *idx_offset =
+				dev->shared_resources.sdma_doorbell_idx;
+		q->doorbell_id = idx_offset[q->properties.sdma_engine_id]
+			+ (q->properties.sdma_queue_id >> 1)
+			+ (q->properties.sdma_queue_id % 2)
+			* KFD_QUEUE_DOORBELL_MIRROR_OFFSET;
 	} else {
 		/* For CP queues on SOC15 reserve a free doorbell ID */
 		unsigned int found;
drivers/gpu/drm/amd/include/kgd_kfd_interface.h +1 -1
index b1bf45419d93..3559170f6fb3 100644
@@ -137,7 +137,7 @@ struct kgd2kfd_shared_resources {
 	/* Bit n == 1 means Queue n is available for KFD */
 	DECLARE_BITMAP(queue_bitmap, KGD_MAX_QUEUES);
 
-	unsigned int sdma_doorbell[2][8];
+	unsigned int *sdma_doorbell_idx;
 
 	/* From SOC15 onwards, the doorbell indexes reserved for SDMA, IH,
 	 * and VCN
Signature · 6 lines
2.17.1

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

A message that is not in the archive (sent off-list or not yet received): [email protected]

#14 lore raw

Re: [PATCH 5/5] drm/amdkfd: Optimize out sdma doorbell array in kgd2kfd_shared_resources

Some nit-picks inline. Looks good otherwise.

Quoted 4 lines · Yong

We can directly calculate the sdma doorbell index in the process doorbell pages through the doorbell_index structure in amdgpu_device, so no need to cache them in kgd2kfd_shared_resources any more, resulting in more portable code.

What do you mean by "portable" here? Portable to what? Other architectures? Kernels? GPUs?

Quoted 105 lines
Change-Id Ic657799856ed0256f36b01e502ef0cab263b1f49
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c    | 55 ++++++-------------
  .../drm/amd/amdkfd/kfd_device_queue_manager.c | 18 ++++--
  .../gpu/drm/amd/include/kgd_kfd_interface.h   |  2 +-
  3 files changed, 31 insertions(+), 44 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c +17 -38
index ee8527701731..e62c3703169a 100644
@@ -131,7 +131,7 @@ static void amdgpu_doorbell_get_kfd_info(struct amdgpu_device *adev,
 
  void amdgpu_amdkfd_device_init(struct amdgpu_device *adev)
  {
-	int i, n;
+	int i;
  	int last_valid_bit;
 
  	if (adev->kfd.dev) {
@@ -142,7 +142,9 @@ void amdgpu_amdkfd_device_init(struct amdgpu_device *adev)
  			.gpuvm_size = min(adev->vm_manager.max_pfn
  					  << AMDGPU_GPU_PAGE_SHIFT,
  					  AMDGPU_GMC_HOLE_START),
-			.drm_render_minor = adev->ddev->render->index
+			.drm_render_minor = adev->ddev->render->index,
+			.sdma_doorbell_idx = adev->doorbell_index.sdma_engine,
+
  		};
 
  		/* this is going to have a few of the MSBs set that we need to
@@ -172,45 +174,22 @@ void amdgpu_amdkfd_device_init(struct amdgpu_device *adev)
  				&gpu_resources.doorbell_aperture_size,
  				&gpu_resources.doorbell_start_offset);
 
-		if (adev->asic_type < CHIP_VEGA10) {
-			kgd2kfd_device_init(adev->kfd.dev, &gpu_resources);
-			return;
-		}
-
-		n = (adev->asic_type < CHIP_VEGA20) ? 2 : 8;
-
-		for (i = 0; i < n; i += 2) {
-			/* On SOC15 the BIF is involved in routing
-			 * doorbells using the low 12 bits of the
-			 * address. Communicate the assignments to
-			 * KFD. KFD uses two doorbell pages per
-			 * process in case of 64-bit doorbells so we
-			 * can use each doorbell assignment twice.
+		if (adev->asic_type >= CHIP_VEGA10) {
+			/* Because of the setting in registers like
+			 * SDMA0_DOORBELL_RANGE etc., BIF statically uses the
+			 * lower 12 bits of doorbell address for routing. In
+			 * order to route the CP queue doorbells to CP engine,
+			 * the doorbells allocated to CP queues have to be
+			 * outside the range set for SDMA, VCN, and IH blocks
+			 * Prior to SOC15, all queues use queue ID to
+			 * determine doorbells.
  			 */
-			gpu_resources.sdma_doorbell[0][i] =
-				adev->doorbell_index.sdma_engine[0] + (i >> 1);
-			gpu_resources.sdma_doorbell[0][i+1] =
-				adev->doorbell_index.sdma_engine[0] + 0x200 + (i >> 1);
-			gpu_resources.sdma_doorbell[1][i] =
-				adev->doorbell_index.sdma_engine[1] + (i >> 1);
-			gpu_resources.sdma_doorbell[1][i+1] =
-				adev->doorbell_index.sdma_engine[1] + 0x200 + (i >> 1);
+			gpu_resources.reserved_doorbells_start =
+					adev->doorbell_index.sdma_engine[0];
+			gpu_resources.reserved_doorbells_end =
+					adev->doorbell_index.last_non_cp;
  		}
 
-		/* Because of the setting in registers like
-		 * SDMA0_DOORBELL_RANGE etc., BIF statically uses the
-		 * lower 12 bits of doorbell address for routing. In
-		 * order to route the CP queue doorbells to CP engine,
-		 * the doorbells allocated to CP queues have to be
-		 * outside the range set for SDMA, VCN, and IH blocks
-		 * Prior to SOC15, all queues use queue ID to
-		 * determine doorbells.
-		 */
-		gpu_resources.reserved_doorbells_start =
-				adev->doorbell_index.sdma_engine[0];
-		gpu_resources.reserved_doorbells_end =
-				adev->doorbell_index.last_non_cp;
-
  		kgd2kfd_device_init(adev->kfd.dev, &gpu_resources);
  	}
  }
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +3 -2
index 8372556b52eb..81280ce5aa27 100644
@@ -134,12 +134,20 @@ static int allocate_doorbell(struct qcm_process_device *qpd, struct queue *q)
  		 */
  		q->doorbell_id = q->properties.queue_id;
  	} else if (q->properties.type == KFD_QUEUE_TYPE_SDMA) {
-		/* For SDMA queues on SOC15, use static doorbell
-		 * assignments based on the engine and queue.
+		/* For SDMA queues on SOC15 with 8-byte doorbell, use static
+		 * doorbell assignments based on the engine and queue id.
+		 * The doobell index distance between RLC (2*i) and (2*i+1)

drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c static int allocate_doorbell(struct qcm_process_device *qpd, struct queue *q) · line 146

Quoted 10 lines
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +6 -3
+		 * for a SDMA engine is 512.
+		 * 512 8-byte doorbell distance (i.e. one page away) ensures
+		 * that SDMA RLC (2*i+1) doorbell lies exactly in the doorbell
+		 * OFFSET and SIZE set in register BIF_SDMA0_DOORBELL_RANGE.
  		 */
-		q->doorbell_id = dev->shared_resources.sdma_doorbell
-			[q->properties.sdma_engine_id]
-			[q->properties.sdma_queue_id];
+		unsigned int *idx_offset =
+				dev->shared_resources.sdma_doorbell_idx;

The type in struct amdgpu_doorbell_index is uint32_t. I'd prefer matching the type of the pointer here.

drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c static int allocate_doorbell(struct qcm_process_device *qpd, struct queue *q) · line 149

Quoted 3 lines
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +3 -0
+		q->doorbell_id = idx_offset[q->properties.sdma_engine_id]
+			+ (q->properties.sdma_queue_id >> 1)
+			+ (q->properties.sdma_queue_id % 2)

Be consistent with the use of bit-wise operations (x >> 1 and x & 1) or division (x / 2 and x %2). Here you're mixing them. I prefer the bit-wise operations for division and modulo with powers of two.

Quoted 9 lines
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +1 -0
+			* KFD_QUEUE_DOORBELL_MIRROR_OFFSET;
  	} else {
  		/* For CP queues on SOC15 reserve a free doorbell ID */
  		unsigned int found;
drivers/gpu/drm/amd/include/kgd_kfd_interface.h +0 -0
index b1bf45419d93..3559170f6fb3 100644

drivers/gpu/drm/amd/include/kgd_kfd_interface.h struct kgd2kfd_shared_resources { · line 140

Quoted 5 lines
drivers/gpu/drm/amd/include/kgd_kfd_interface.h +1 -1
@@ -137,7 +137,7 @@ struct kgd2kfd_shared_resources {
  	/* Bit n == 1 means Queue n is available for KFD */
  	DECLARE_BITMAP(queue_bitmap, KGD_MAX_QUEUES);
 
-	unsigned int sdma_doorbell[2][8];
+	unsigned int *sdma_doorbell_idx;

The type in struct amdgpu_doorbell_index is uint32_t. I'd prefer matching the type of the pointer here.

Regards,
  Felix

drivers/gpu/drm/amd/include/kgd_kfd_interface.h struct kgd2kfd_shared_resources { · line 143

Quoted 3 lines
drivers/gpu/drm/amd/include/kgd_kfd_interface.h +0 -0
  	/* From SOC15 onwards, the doorbell indexes reserved for SDMA, IH,
  	 * and VCN

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

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

The headline should start with "drm/amdgpu". This change is not KFD specific.

I think Alex should review this change.

Regards,
  Felix

Quoted 185 lines · Yong

Indicate that the doorbell offset and range is in dwords.

Change-Id Ib0f2564ffa7b1940ffb8725cdc03f662184f5436
---
  drivers/gpu/drm/amd/amdgpu/amdgpu.h          | 2 +-
  drivers/gpu/drm/amd/amdgpu/amdgpu_doorbell.h | 3 ++-
  drivers/gpu/drm/amd/amdgpu/nbio_v6_1.c       | 6 +++---
  drivers/gpu/drm/amd/amdgpu/nbio_v7_0.c       | 6 +++---
  drivers/gpu/drm/amd/amdgpu/nbio_v7_4.c       | 6 +++---
  drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c       | 3 ++-
  drivers/gpu/drm/amd/amdgpu/soc15.c           | 2 +-
  drivers/gpu/drm/amd/amdgpu/vega10_reg_init.c | 6 +++++-
  drivers/gpu/drm/amd/amdgpu/vega20_reg_init.c | 6 +++++-
  9 files changed, 25 insertions(+), 15 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1 -1
index d67f8b1dfe80..6230425f3f3d 100644
@@ -642,7 +642,7 @@ struct amdgpu_nbio_funcs {
  	void (*hdp_flush)(struct amdgpu_device *adev, struct amdgpu_ring *ring);
  	u32 (*get_memsize)(struct amdgpu_device *adev);
  	void (*sdma_doorbell_range)(struct amdgpu_device *adev, int instance,
-			bool use_doorbell, int doorbell_index, int doorbell_size);
+			bool use_doorbell, int index_in_dw, int range_dw_size);
  	void (*enable_doorbell_aperture)(struct amdgpu_device *adev,
  					 bool enable);
  	void (*enable_doorbell_selfring_aperture)(struct amdgpu_device *adev,
drivers/gpu/drm/amd/amdgpu/amdgpu_doorbell.h +2 -1
index 1cfec06f81d4..5c8d04c353d0 100644
@@ -39,6 +39,7 @@ struct amdgpu_doorbell {
   * can be 64-bit, so the index defined is in qword.
   */
  struct amdgpu_doorbell_index {
+	uint32_t entry_dw_size;
  	uint32_t kiq;
  	uint32_t mec_ring0;
  	uint32_t mec_ring1;
@@ -73,7 +74,7 @@ struct amdgpu_doorbell_index {
  	};
  	uint32_t max_assignment;
  	/* Per engine SDMA doorbell size in dword */
-	uint32_t sdma_doorbell_range;
+	uint32_t dw_range_per_sdma_eng;
  };
 
  typedef enum _AMDGPU_DOORBELL_ASSIGNMENT
drivers/gpu/drm/amd/amdgpu/nbio_v6_1.c +3 -3
index cc967dbfd631..64bc41afd71e 100644
@@ -68,7 +68,7 @@ static u32 nbio_v6_1_get_memsize(struct amdgpu_device *adev)
  }
 
  static void nbio_v6_1_sdma_doorbell_range(struct amdgpu_device *adev, int instance,
-			bool use_doorbell, int doorbell_index, int doorbell_size)
+			bool use_doorbell, int index_in_dw, int range_dw_size)
  {
  	u32 reg = instance == 0 ? SOC15_REG_OFFSET(NBIO, 0, mmBIF_SDMA0_DOORBELL_RANGE) :
  			SOC15_REG_OFFSET(NBIO, 0, mmBIF_SDMA1_DOORBELL_RANGE);
@@ -76,8 +76,8 @@ static void nbio_v6_1_sdma_doorbell_range(struct amdgpu_device *adev, int instan
  	u32 doorbell_range = RREG32(reg);
 
  	if (use_doorbell) {
-		doorbell_range = REG_SET_FIELD(doorbell_range, BIF_SDMA0_DOORBELL_RANGE, OFFSET, doorbell_index);
-		doorbell_range = REG_SET_FIELD(doorbell_range, BIF_SDMA0_DOORBELL_RANGE, SIZE, doorbell_size);
+		doorbell_range = REG_SET_FIELD(doorbell_range, BIF_SDMA0_DOORBELL_RANGE, OFFSET, index_in_dw);
+		doorbell_range = REG_SET_FIELD(doorbell_range, BIF_SDMA0_DOORBELL_RANGE, SIZE, range_dw_size);
  	} else
  		doorbell_range = REG_SET_FIELD(doorbell_range, BIF_SDMA0_DOORBELL_RANGE, SIZE, 0);
 
drivers/gpu/drm/amd/amdgpu/nbio_v7_0.c +3 -3
index 1cdb98ad2db3..28cc96b7a292 100644
@@ -67,7 +67,7 @@ static u32 nbio_v7_0_get_memsize(struct amdgpu_device *adev)
  }
 
  static void nbio_v7_0_sdma_doorbell_range(struct amdgpu_device *adev, int instance,
-			bool use_doorbell, int doorbell_index, int doorbell_size)
+			bool use_doorbell, int index_in_dw, int range_dw_size)
  {
  	u32 reg = instance == 0 ? SOC15_REG_OFFSET(NBIO, 0, mmBIF_SDMA0_DOORBELL_RANGE) :
  			SOC15_REG_OFFSET(NBIO, 0, mmBIF_SDMA1_DOORBELL_RANGE);
@@ -75,8 +75,8 @@ static void nbio_v7_0_sdma_doorbell_range(struct amdgpu_device *adev, int instan
  	u32 doorbell_range = RREG32(reg);
 
  	if (use_doorbell) {
-		doorbell_range = REG_SET_FIELD(doorbell_range, BIF_SDMA0_DOORBELL_RANGE, OFFSET, doorbell_index);
-		doorbell_range = REG_SET_FIELD(doorbell_range, BIF_SDMA0_DOORBELL_RANGE, SIZE, doorbell_size);
+		doorbell_range = REG_SET_FIELD(doorbell_range, BIF_SDMA0_DOORBELL_RANGE, OFFSET, index_in_dw);
+		doorbell_range = REG_SET_FIELD(doorbell_range, BIF_SDMA0_DOORBELL_RANGE, SIZE, range_dw_size);
  	} else
  		doorbell_range = REG_SET_FIELD(doorbell_range, BIF_SDMA0_DOORBELL_RANGE, SIZE, 0);
 
drivers/gpu/drm/amd/amdgpu/nbio_v7_4.c +3 -3
index 221f26e50322..9ae8cd4dc702 100644
@@ -65,7 +65,7 @@ static u32 nbio_v7_4_get_memsize(struct amdgpu_device *adev)
  }
 
  static void nbio_v7_4_sdma_doorbell_range(struct amdgpu_device *adev, int instance,
-			bool use_doorbell, int doorbell_index, int doorbell_size)
+			bool use_doorbell, int index_in_dw, int range_dw_size)
  {
  	u32 reg = instance == 0 ? SOC15_REG_OFFSET(NBIO, 0, mmBIF_SDMA0_DOORBELL_RANGE) :
  			SOC15_REG_OFFSET(NBIO, 0, mmBIF_SDMA1_DOORBELL_RANGE);
@@ -73,8 +73,8 @@ static void nbio_v7_4_sdma_doorbell_range(struct amdgpu_device *adev, int instan
  	u32 doorbell_range = RREG32(reg);
 
  	if (use_doorbell) {
-		doorbell_range = REG_SET_FIELD(doorbell_range, BIF_SDMA0_DOORBELL_RANGE, OFFSET, doorbell_index);
-		doorbell_range = REG_SET_FIELD(doorbell_range, BIF_SDMA0_DOORBELL_RANGE, SIZE, doorbell_size);
+		doorbell_range = REG_SET_FIELD(doorbell_range, BIF_SDMA0_DOORBELL_RANGE, OFFSET, index_in_dw);
+		doorbell_range = REG_SET_FIELD(doorbell_range, BIF_SDMA0_DOORBELL_RANGE, SIZE, range_dw_size);
  	} else
  		doorbell_range = REG_SET_FIELD(doorbell_range, BIF_SDMA0_DOORBELL_RANGE, SIZE, 0);
 
drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c +2 -1
index 127b85983e8f..e65e9bc52bd4 100644
@@ -1520,7 +1520,8 @@ static int sdma_v4_0_sw_init(void *handle)
  				ring->use_doorbell?"true":"false");
 
  		/* doorbell size is 2 dwords, get DWORD offset */
-		ring->doorbell_index = adev->doorbell_index.sdma_engine[i] << 1;
+		ring->doorbell_index = adev->doorbell_index.sdma_engine[i]
+				* adev->doorbell_index.entry_dw_size;
 
  		sprintf(ring->name, "sdma%d", i);
  		r = amdgpu_ring_init(adev, ring, 1024,
drivers/gpu/drm/amd/amdgpu/soc15.c +1 -1
index 99ebcf29dcb0..aad72ac80361 100644
@@ -980,7 +980,7 @@ static void soc15_doorbell_range_init(struct amdgpu_device *adev)
  		ring = &adev->sdma.instance[i].ring;
  		adev->nbio_funcs->sdma_doorbell_range(adev, i,
  			ring->use_doorbell, ring->doorbell_index,
-			adev->doorbell_index.sdma_doorbell_range);
+			adev->doorbell_index.dw_range_per_sdma_eng);
  	}
 
  	adev->nbio_funcs->ih_doorbell_range(adev, adev->irq.ih.use_doorbell,
drivers/gpu/drm/amd/amdgpu/vega10_reg_init.c +5 -1
index 4b5d60ea3e78..d2409df2dde9 100644
@@ -58,6 +58,7 @@ int vega10_reg_base_init(struct amdgpu_device *adev)
 
  void vega10_doorbell_index_init(struct amdgpu_device *adev)
  {
+	adev->doorbell_index.entry_dw_size = 2;
  	adev->doorbell_index.kiq = AMDGPU_DOORBELL64_KIQ;
  	adev->doorbell_index.mec_ring0 = AMDGPU_DOORBELL64_MEC_RING0;
  	adev->doorbell_index.mec_ring1 = AMDGPU_DOORBELL64_MEC_RING1;
@@ -83,6 +84,9 @@ void vega10_doorbell_index_init(struct amdgpu_device *adev)
  	adev->doorbell_index.uvd_vce.vce_ring6_7 = AMDGPU_DOORBELL64_VCE_RING6_7;
  	/* In unit of dword doorbell */
  	adev->doorbell_index.max_assignment = AMDGPU_DOORBELL64_MAX_ASSIGNMENT << 1;
-	adev->doorbell_index.sdma_doorbell_range = 4;
+	adev->doorbell_index.dw_range_per_sdma_eng =
+			(adev->doorbell_index.sdma_engine[1]
+			- adev->doorbell_index.sdma_engine[0])
+			* adev->doorbell_index.entry_dw_size;
  }
 
drivers/gpu/drm/amd/amdgpu/vega20_reg_init.c +1 -0
index 53716c593b2b..b28c5999d8f0 100644
@@ -56,6 +56,7 @@ int vega20_reg_base_init(struct amdgpu_device *adev)
 
  void vega20_doorbell_index_init(struct amdgpu_device *adev)
  {
+	adev->doorbell_index.entry_dw_size = 2;
  	adev->doorbell_index.kiq = AMDGPU_VEGA20_DOORBELL_KIQ;
  	adev->doorbell_index.mec_ring0 = AMDGPU_VEGA20_DOORBELL_MEC_RING0;
  	adev->doorbell_index.mec_ring1 = AMDGPU_VEGA20_DOORBELL_MEC_RING1;

drivers/gpu/drm/amd/amdgpu/vega20_reg_init.c void vega20_doorbell_index_init(struct amdgpu_device *adev) · line 95

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/vega20_reg_init.c +4 -1
@@ -86,6 +87,9 @@ void vega20_doorbell_index_init(struct amdgpu_device *adev)
  	adev->doorbell_index.uvd_vce.vce_ring4_5 = AMDGPU_VEGA20_DOORBELL64_VCE_RING4_5;
  	adev->doorbell_index.uvd_vce.vce_ring6_7 = AMDGPU_VEGA20_DOORBELL64_VCE_RING6_7;
  	adev->doorbell_index.max_assignment = AMDGPU_VEGA20_DOORBELL_MAX_ASSIGNMENT << 1;
-	adev->doorbell_index.sdma_doorbell_range = 20;
+	adev->doorbell_index.dw_range_per_sdma_eng =
+			(adev->doorbell_index.sdma_engine[1]
+			- adev->doorbell_index.sdma_engine[0])
+			* adev->doorbell_index.entry_dw_size;
  }
 

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

A message that is not in the archive (sent off-list or not yet received): 911744ff-f4e5-b165-123e-a574b2310746-5C7GfCeVMHo@public.gmane.org

#17 lore raw
Quoted 5 lines · Felix

The headline should start with "drm/amdgpu". This change is not KFD specific.

I think Alex should review this change.

If we are going to change it, let's be consistent for all IPs (e.g., gfx, vcn, etc.).

Alex

Quoted 196 lines

Regards,
Felix

Quoted 191 lines · Yong

Indicate that the doorbell offset and range is in dwords.

Change-Id Ib0f2564ffa7b1940ffb8725cdc03f662184f5436
---
  drivers/gpu/drm/amd/amdgpu/amdgpu.h          | 2 +-
  drivers/gpu/drm/amd/amdgpu/amdgpu_doorbell.h | 3 ++-
  drivers/gpu/drm/amd/amdgpu/nbio_v6_1.c       | 6 +++---
  drivers/gpu/drm/amd/amdgpu/nbio_v7_0.c       | 6 +++---
  drivers/gpu/drm/amd/amdgpu/nbio_v7_4.c       | 6 +++---
  drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c       | 3 ++-
  drivers/gpu/drm/amd/amdgpu/soc15.c           | 2 +-
  drivers/gpu/drm/amd/amdgpu/vega10_reg_init.c | 6 +++++-
  drivers/gpu/drm/amd/amdgpu/vega20_reg_init.c | 6 +++++-
  9 files changed, 25 insertions(+), 15 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1 -1
index d67f8b1dfe80..6230425f3f3d 100644
@@ -642,7 +642,7 @@ struct amdgpu_nbio_funcs {
      void (*hdp_flush)(struct amdgpu_device *adev, struct amdgpu_ring *ring);
      u32 (*get_memsize)(struct amdgpu_device *adev);
      void (*sdma_doorbell_range)(struct amdgpu_device *adev, int instance,
-                     bool use_doorbell, int doorbell_index, int doorbell_size);
+                     bool use_doorbell, int index_in_dw, int range_dw_size);
      void (*enable_doorbell_aperture)(struct amdgpu_device *adev,
                                       bool enable);
      void (*enable_doorbell_selfring_aperture)(struct amdgpu_device *adev,
drivers/gpu/drm/amd/amdgpu/amdgpu_doorbell.h +2 -1
index 1cfec06f81d4..5c8d04c353d0 100644
@@ -39,6 +39,7 @@ struct amdgpu_doorbell {
   * can be 64-bit, so the index defined is in qword.
   */
  struct amdgpu_doorbell_index {
+     uint32_t entry_dw_size;
      uint32_t kiq;
      uint32_t mec_ring0;
      uint32_t mec_ring1;
@@ -73,7 +74,7 @@ struct amdgpu_doorbell_index {
      };
      uint32_t max_assignment;
      /* Per engine SDMA doorbell size in dword */
-     uint32_t sdma_doorbell_range;
+     uint32_t dw_range_per_sdma_eng;
  };
 
  typedef enum _AMDGPU_DOORBELL_ASSIGNMENT
drivers/gpu/drm/amd/amdgpu/nbio_v6_1.c +3 -3
index cc967dbfd631..64bc41afd71e 100644
@@ -68,7 +68,7 @@ static u32 nbio_v6_1_get_memsize(struct amdgpu_device *adev)
  }
 
  static void nbio_v6_1_sdma_doorbell_range(struct amdgpu_device *adev, int instance,
-                     bool use_doorbell, int doorbell_index, int doorbell_size)
+                     bool use_doorbell, int index_in_dw, int range_dw_size)
  {
      u32 reg = instance == 0 ? SOC15_REG_OFFSET(NBIO, 0, mmBIF_SDMA0_DOORBELL_RANGE) :
                      SOC15_REG_OFFSET(NBIO, 0, mmBIF_SDMA1_DOORBELL_RANGE);
@@ -76,8 +76,8 @@ static void nbio_v6_1_sdma_doorbell_range(struct amdgpu_device *adev, int instan
      u32 doorbell_range = RREG32(reg);
 
      if (use_doorbell) {
-             doorbell_range = REG_SET_FIELD(doorbell_range, BIF_SDMA0_DOORBELL_RANGE, OFFSET, doorbell_index);
-             doorbell_range = REG_SET_FIELD(doorbell_range, BIF_SDMA0_DOORBELL_RANGE, SIZE, doorbell_size);
+             doorbell_range = REG_SET_FIELD(doorbell_range, BIF_SDMA0_DOORBELL_RANGE, OFFSET, index_in_dw);
+             doorbell_range = REG_SET_FIELD(doorbell_range, BIF_SDMA0_DOORBELL_RANGE, SIZE, range_dw_size);
      } else
              doorbell_range = REG_SET_FIELD(doorbell_range, BIF_SDMA0_DOORBELL_RANGE, SIZE, 0);
 
drivers/gpu/drm/amd/amdgpu/nbio_v7_0.c +3 -3
index 1cdb98ad2db3..28cc96b7a292 100644
@@ -67,7 +67,7 @@ static u32 nbio_v7_0_get_memsize(struct amdgpu_device *adev)
  }
 
  static void nbio_v7_0_sdma_doorbell_range(struct amdgpu_device *adev, int instance,
-                     bool use_doorbell, int doorbell_index, int doorbell_size)
+                     bool use_doorbell, int index_in_dw, int range_dw_size)
  {
      u32 reg = instance == 0 ? SOC15_REG_OFFSET(NBIO, 0, mmBIF_SDMA0_DOORBELL_RANGE) :
                      SOC15_REG_OFFSET(NBIO, 0, mmBIF_SDMA1_DOORBELL_RANGE);
@@ -75,8 +75,8 @@ static void nbio_v7_0_sdma_doorbell_range(struct amdgpu_device *adev, int instan
      u32 doorbell_range = RREG32(reg);
 
      if (use_doorbell) {
-             doorbell_range = REG_SET_FIELD(doorbell_range, BIF_SDMA0_DOORBELL_RANGE, OFFSET, doorbell_index);
-             doorbell_range = REG_SET_FIELD(doorbell_range, BIF_SDMA0_DOORBELL_RANGE, SIZE, doorbell_size);
+             doorbell_range = REG_SET_FIELD(doorbell_range, BIF_SDMA0_DOORBELL_RANGE, OFFSET, index_in_dw);
+             doorbell_range = REG_SET_FIELD(doorbell_range, BIF_SDMA0_DOORBELL_RANGE, SIZE, range_dw_size);
      } else
              doorbell_range = REG_SET_FIELD(doorbell_range, BIF_SDMA0_DOORBELL_RANGE, SIZE, 0);
 
drivers/gpu/drm/amd/amdgpu/nbio_v7_4.c +3 -3
index 221f26e50322..9ae8cd4dc702 100644
@@ -65,7 +65,7 @@ static u32 nbio_v7_4_get_memsize(struct amdgpu_device *adev)
  }
 
  static void nbio_v7_4_sdma_doorbell_range(struct amdgpu_device *adev, int instance,
-                     bool use_doorbell, int doorbell_index, int doorbell_size)
+                     bool use_doorbell, int index_in_dw, int range_dw_size)
  {
      u32 reg = instance == 0 ? SOC15_REG_OFFSET(NBIO, 0, mmBIF_SDMA0_DOORBELL_RANGE) :
                      SOC15_REG_OFFSET(NBIO, 0, mmBIF_SDMA1_DOORBELL_RANGE);
@@ -73,8 +73,8 @@ static void nbio_v7_4_sdma_doorbell_range(struct amdgpu_device *adev, int instan
      u32 doorbell_range = RREG32(reg);
 
      if (use_doorbell) {
-             doorbell_range = REG_SET_FIELD(doorbell_range, BIF_SDMA0_DOORBELL_RANGE, OFFSET, doorbell_index);
-             doorbell_range = REG_SET_FIELD(doorbell_range, BIF_SDMA0_DOORBELL_RANGE, SIZE, doorbell_size);
+             doorbell_range = REG_SET_FIELD(doorbell_range, BIF_SDMA0_DOORBELL_RANGE, OFFSET, index_in_dw);
+             doorbell_range = REG_SET_FIELD(doorbell_range, BIF_SDMA0_DOORBELL_RANGE, SIZE, range_dw_size);
      } else
              doorbell_range = REG_SET_FIELD(doorbell_range, BIF_SDMA0_DOORBELL_RANGE, SIZE, 0);
 
drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c +2 -1
index 127b85983e8f..e65e9bc52bd4 100644
@@ -1520,7 +1520,8 @@ static int sdma_v4_0_sw_init(void *handle)
                              ring->use_doorbell?"true":"false");
 
              /* doorbell size is 2 dwords, get DWORD offset */
-             ring->doorbell_index = adev->doorbell_index.sdma_engine[i] << 1;
+             ring->doorbell_index = adev->doorbell_index.sdma_engine[i]
+                             * adev->doorbell_index.entry_dw_size;
 
              sprintf(ring->name, "sdma%d", i);
              r = amdgpu_ring_init(adev, ring, 1024,
drivers/gpu/drm/amd/amdgpu/soc15.c +1 -1
index 99ebcf29dcb0..aad72ac80361 100644
@@ -980,7 +980,7 @@ static void soc15_doorbell_range_init(struct amdgpu_device *adev)
              ring = &adev->sdma.instance[i].ring;
              adev->nbio_funcs->sdma_doorbell_range(adev, i,
                      ring->use_doorbell, ring->doorbell_index,
-                     adev->doorbell_index.sdma_doorbell_range);
+                     adev->doorbell_index.dw_range_per_sdma_eng);
      }
 
      adev->nbio_funcs->ih_doorbell_range(adev, adev->irq.ih.use_doorbell,
drivers/gpu/drm/amd/amdgpu/vega10_reg_init.c +5 -1
index 4b5d60ea3e78..d2409df2dde9 100644
@@ -58,6 +58,7 @@ int vega10_reg_base_init(struct amdgpu_device *adev)
 
  void vega10_doorbell_index_init(struct amdgpu_device *adev)
  {
+     adev->doorbell_index.entry_dw_size = 2;
      adev->doorbell_index.kiq = AMDGPU_DOORBELL64_KIQ;
      adev->doorbell_index.mec_ring0 = AMDGPU_DOORBELL64_MEC_RING0;
      adev->doorbell_index.mec_ring1 = AMDGPU_DOORBELL64_MEC_RING1;
@@ -83,6 +84,9 @@ void vega10_doorbell_index_init(struct amdgpu_device *adev)
      adev->doorbell_index.uvd_vce.vce_ring6_7 = AMDGPU_DOORBELL64_VCE_RING6_7;
      /* In unit of dword doorbell */
      adev->doorbell_index.max_assignment = AMDGPU_DOORBELL64_MAX_ASSIGNMENT << 1;
-     adev->doorbell_index.sdma_doorbell_range = 4;
+     adev->doorbell_index.dw_range_per_sdma_eng =
+                     (adev->doorbell_index.sdma_engine[1]
+                     - adev->doorbell_index.sdma_engine[0])
+                     * adev->doorbell_index.entry_dw_size;
  }
 
drivers/gpu/drm/amd/amdgpu/vega20_reg_init.c +3 -1
index 53716c593b2b..b28c5999d8f0 100644
@@ -56,6 +56,7 @@ int vega20_reg_base_init(struct amdgpu_device *adev)
 
  void vega20_doorbell_index_init(struct amdgpu_device *adev)
  {
+     adev->doorbell_index.entry_dw_size = 2;
      adev->doorbell_index.kiq = AMDGPU_VEGA20_DOORBELL_KIQ;
      adev->doorbell_index.mec_ring0 = AMDGPU_VEGA20_DOORBELL_MEC_RING0;
      adev->doorbell_index.mec_ring1 = AMDGPU_VEGA20_DOORBELL_MEC_RING1;
@@ -86,6 +87,9 @@ void vega20_doorbell_index_init(struct amdgpu_device *adev)
      adev->doorbell_index.uvd_vce.vce_ring4_5 = AMDGPU_VEGA20_DOORBELL64_VCE_RING4_5;
      adev->doorbell_index.uvd_vce.vce_ring6_7 = AMDGPU_VEGA20_DOORBELL64_VCE_RING6_7;
      adev->doorbell_index.max_assignment = AMDGPU_VEGA20_DOORBELL_MAX_ASSIGNMENT << 1;
-     adev->doorbell_index.sdma_doorbell_range = 20;
+     adev->doorbell_index.dw_range_per_sdma_eng =
+                     (adev->doorbell_index.sdma_engine[1]
Quoted 8 lines

drivers/gpu/drm/amd/amdgpu/vega20_reg_init.c void vega20_doorbell_index_init(struct amdgpu_device *adev) · line 95

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/vega20_reg_init.c +2 -0
+                     - adev->doorbell_index.sdma_engine[0])
+                     * adev->doorbell_index.entry_dw_size;
  }
 

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

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