Skip to contentSkip to conversation

drm/amdkfd: add watch_addresses to set_shader_debugger interface

PATCH New David Belanger 1 participant 3 messages Oct 15

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/3 drm/amdkfd: add watch_addresses to set_shader_debugger interface

Pass watchpoint addresses through amdgpu_mes_set_shader_debugger() so MES programs TCP_WATCH registers at dispatch time.

Assisted-by claude-code:claude-sonnet-4
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c | 3 +++
 drivers/gpu/drm/amd/amdgpu/amdgpu_mes.h | 2 ++
 drivers/gpu/drm/amd/amdkfd/kfd_debug.c  | 6 +++++-
 drivers/gpu/drm/amd/amdkfd/kfd_priv.h   | 1 +
 4 files changed, 11 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c +3 -0
index 05bbbd1afb630..53d7cb1402d80 100644
@@ -695,6 +695,7 @@ int amdgpu_mes_set_shader_debugger(struct amdgpu_device *adev,
 				uint64_t process_context_addr,
 				uint32_t spi_gdbg_per_vmid_cntl,
 				const uint32_t *tcp_watch_cntl,
+				const uint64_t *watch_addresses,
 				uint32_t flags,
 				bool trap_en,
 				uint32_t xcc_id)
@@ -720,6 +721,8 @@ int amdgpu_mes_set_shader_debugger(struct amdgpu_device *adev,
 	op_input.set_shader_debugger.spi_gdbg_per_vmid_cntl = spi_gdbg_per_vmid_cntl;
 	memcpy(op_input.set_shader_debugger.tcp_watch_cntl, tcp_watch_cntl,
 			sizeof(op_input.set_shader_debugger.tcp_watch_cntl));
+	memcpy(op_input.set_shader_debugger.watch_addresses, watch_addresses,
+			sizeof(op_input.set_shader_debugger.watch_addresses));
 
 	if (((adev->mes.sched_version & AMDGPU_MES_API_VERSION_MASK) >>
 			AMDGPU_MES_API_VERSION_SHIFT) >= 14)
drivers/gpu/drm/amd/amdgpu/amdgpu_mes.h +2 -0
index b967b6c0b4c75..0c4cd663de9ff 100644
@@ -435,6 +435,7 @@ struct mes_misc_op_input {
 			} flags;
 			uint32_t spi_gdbg_per_vmid_cntl;
 			uint32_t tcp_watch_cntl[4];
+			uint64_t watch_addresses[4];
 			uint32_t trap_en;
 		} set_shader_debugger;
 
@@ -623,6 +624,7 @@ int amdgpu_mes_set_shader_debugger(struct amdgpu_device *adev,
 				uint64_t process_context_addr,
 				uint32_t spi_gdbg_per_vmid_cntl,
 				const uint32_t *tcp_watch_cntl,
+				const uint64_t *watch_addresses,
 				uint32_t flags,
 				bool trap_en,
 				uint32_t xcc_id);
drivers/gpu/drm/amd/amdkfd/kfd_debug.c +5 -1
index 8bed0d0f9bd26..71b34a57c2cc2 100644
@@ -374,7 +374,9 @@ int kfd_dbg_set_mes_debug_mode(struct kfd_process_device *pdd, bool sq_trap_en)
 
 	return amdgpu_mes_set_shader_debugger(pdd->dev->adev,
 					pdd->proc_ctx_gpu_addr, spi_dbg_cntl,
-					pdd->watch_points, flags, sq_trap_en,
+					pdd->watch_points,
+					pdd->watch_addresses,
+					flags, sq_trap_en,
 					ffs(pdd->dev->xcc_mask) - 1);
 }
 
@@ -449,6 +451,7 @@ int kfd_dbg_trap_clear_dev_address_watch(struct kfd_process_device *pdd,
 	pdd->watch_points[watch_id] = pdd->dev->kfd2kgd->clear_address_watch(
 							pdd->dev->adev,
 							watch_id);
+	pdd->watch_addresses[watch_id] = 0;
 	amdgpu_gfx_off_ctrl(pdd->dev->adev, true);
 
 	if (!pdd->dev->kfd->shared_resources.enable_mes)
@@ -485,6 +488,7 @@ int kfd_dbg_trap_set_dev_address_watch(struct kfd_process_device *pdd,
 	}
 
 	amdgpu_gfx_off_ctrl(pdd->dev->adev, false);
+	pdd->watch_addresses[*watch_id] = watch_address;
 	for_each_inst(xcc_id, xcc_mask)
 		pdd->watch_points[*watch_id] = pdd->dev->kfd2kgd->set_address_watch(
 				pdd->dev->adev,
drivers/gpu/drm/amd/amdkfd/kfd_priv.h +1 -0
index 7a365fca68e4f..c0207f44493cb 100644
@@ -870,6 +870,7 @@ struct kfd_process_device {
 	uint32_t spi_dbg_override;
 	uint32_t spi_dbg_launch_mode;
 	uint32_t watch_points[4];
+	uint64_t watch_addresses[4];
 	uint32_t alloc_watch_ids;
 
 	/*
Signature · 1 line
2.55.0
#1 lore raw

PATCH 2/3 drm/amdkfd: pass watchpoint addresses to MES for GFX11

Update SET_SHADER_DEBUGGER packet with tcp_watch_addr_lo/hi fields. Remove direct TCP_WATCH register writes from set_address_watch().

Assisted-by claude-code:claude-sonnet-4
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v11.c | 12 ------------
 drivers/gpu/drm/amd/amdgpu/mes_v11_0.c             |  6 ++++++
 drivers/gpu/drm/amd/include/mes_v11_api_def.h      |  3 +++
 3 files changed, 9 insertions(+), 12 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v11.c +0 -12
index 04fab30ab5dd4..96a308b946469 100644
@@ -747,13 +747,9 @@ static uint32_t kgd_gfx_v11_set_address_watch(struct amdgpu_device *adev,
 					uint32_t debug_vmid,
 					uint32_t inst)
 {
-	uint32_t watch_address_high;
-	uint32_t watch_address_low;
 	uint32_t watch_address_cntl;
 
 	watch_address_cntl = 0;
-	watch_address_low = lower_32_bits(watch_address);
-	watch_address_high = upper_32_bits(watch_address) & 0xffff;
 
 	watch_address_cntl = REG_SET_FIELD(watch_address_cntl,
 			TCP_WATCH0_CNTL,
@@ -770,14 +766,6 @@ static uint32_t kgd_gfx_v11_set_address_watch(struct amdgpu_device *adev,
 			VALID,
 			1);
 
-	WREG32_RLC((SOC15_REG_OFFSET(GC, 0, regTCP_WATCH0_ADDR_H) +
-			(watch_id * TCP_WATCH_STRIDE)),
-			watch_address_high);
-
-	WREG32_RLC((SOC15_REG_OFFSET(GC, 0, regTCP_WATCH0_ADDR_L) +
-			(watch_id * TCP_WATCH_STRIDE)),
-			watch_address_low);
-
 	return watch_address_cntl;
 }
 
drivers/gpu/drm/amd/amdgpu/mes_v11_0.c +6 -0
index 043ac05eb0fa1..3939eed05150c 100644
@@ -1028,6 +1028,12 @@ static int mes_v11_0_misc_op(struct amdgpu_mes *mes,
 		memcpy(misc_pkt.set_shader_debugger.tcp_watch_cntl,
 				input->set_shader_debugger.tcp_watch_cntl,
 				sizeof(misc_pkt.set_shader_debugger.tcp_watch_cntl));
+		for (int i = 0; i < 4; i++) {
+			misc_pkt.set_shader_debugger.tcp_watch_addr_lo[i] =
+				lower_32_bits(input->set_shader_debugger.watch_addresses[i]);
+			misc_pkt.set_shader_debugger.tcp_watch_addr_hi[i] =
+				upper_32_bits(input->set_shader_debugger.watch_addresses[i]) & 0xffff;
+		}
 		misc_pkt.set_shader_debugger.trap_en = input->set_shader_debugger.trap_en;
 		break;
 	case MES_MISC_OP_CHANGE_CONFIG:
drivers/gpu/drm/amd/include/mes_v11_api_def.h +3 -0
index e251ccc41f9ca..de217882f5e8a 100644
@@ -676,6 +676,9 @@ struct SET_SHADER_DEBUGGER {
 	uint32_t spi_gdbg_per_vmid_cntl;
 	uint32_t tcp_watch_cntl[4]; /* TCP_WATCHx_CNTL */
 	uint32_t trap_en;
+	uint32_t tcp_watch_addr_lo[4]; /* TCP_WATCHx_ADDR_L */
+	uint32_t tcp_watch_addr_hi[4]; /* TCP_WATCHx_ADDR_H */
+	uint32_t process_context_array_index;
 };
 
 enum MESAPI_MISC__CHANGE_CONFIG_OPTION {
Signature · 1 line
2.55.0
#2 lore raw

PATCH 3/3 drm/amdkfd: pass watchpoint addresses to MES for GFX12

In reply to David Belanger

Update SET_SHADER_DEBUGGER packet with tcp_watch_addr_lo/hi fields. Remove direct TCP_WATCH register writes from set_address_watch().

v2: Add missing code for mes_v12_1.c

Assisted-by claude-code:claude-sonnet-4
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v12.c   | 12 ------------
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v12_1.c | 12 ------------
 drivers/gpu/drm/amd/amdgpu/mes_v12_0.c               |  6 ++++++
 drivers/gpu/drm/amd/amdgpu/mes_v12_1.c               |  6 ++++++
 drivers/gpu/drm/amd/include/mes_v12_api_def.h        |  3 +++
 5 files changed, 15 insertions(+), 24 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v12.c +0 -12
index 62b9db64368e3..004d0253f60db 100644
@@ -322,13 +322,9 @@ static uint32_t kgd_gfx_v12_set_address_watch(struct amdgpu_device *adev,
 					uint32_t debug_vmid,
 					uint32_t inst)
 {
-	uint32_t watch_address_high;
-	uint32_t watch_address_low;
 	uint32_t watch_address_cntl;
 
 	watch_address_cntl = 0;
-	watch_address_low = lower_32_bits(watch_address);
-	watch_address_high = upper_32_bits(watch_address) & 0xffff;
 
 	watch_address_cntl = REG_SET_FIELD(watch_address_cntl,
 			TCP_WATCH0_CNTL,
@@ -345,14 +341,6 @@ static uint32_t kgd_gfx_v12_set_address_watch(struct amdgpu_device *adev,
 			VALID,
 			1);
 
-	WREG32_RLC((SOC15_REG_OFFSET(GC, 0, regTCP_WATCH0_ADDR_H) +
-			(watch_id * TCP_WATCH_STRIDE)),
-			watch_address_high);
-
-	WREG32_RLC((SOC15_REG_OFFSET(GC, 0, regTCP_WATCH0_ADDR_L) +
-			(watch_id * TCP_WATCH_STRIDE)),
-			watch_address_low);
-
 	return watch_address_cntl;
 }
 
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v12_1.c +0 -12
index bda9578c40359..ca82eac6035ab 100644
@@ -325,13 +325,9 @@ static uint32_t kgd_gfx_v12_1_set_address_watch(struct amdgpu_device *adev,
 					uint32_t debug_vmid,
 					uint32_t inst)
 {
-	uint32_t watch_address_high;
-	uint32_t watch_address_low;
 	uint32_t watch_address_cntl;
 
 	watch_address_cntl = 0;
-	watch_address_low = lower_32_bits(watch_address);
-	watch_address_high = upper_32_bits(watch_address) & 0x1ffffff;
 
 	watch_address_cntl = REG_SET_FIELD(watch_address_cntl,
 			TCP_WATCH0_CNTL,
@@ -348,14 +344,6 @@ static uint32_t kgd_gfx_v12_1_set_address_watch(struct amdgpu_device *adev,
 			VALID,
 			1);
 
-	WREG32_XCC((SOC15_REG_OFFSET(GC, GET_INST(GC, inst), regTCP_WATCH0_ADDR_H) +
-			(watch_id * TCP_WATCH_STRIDE)),
-			watch_address_high, inst);
-
-	WREG32_XCC((SOC15_REG_OFFSET(GC, GET_INST(GC, inst), regTCP_WATCH0_ADDR_L) +
-			(watch_id * TCP_WATCH_STRIDE)),
-			watch_address_low, inst);
-
 	return watch_address_cntl;
 }
 
drivers/gpu/drm/amd/amdgpu/mes_v12_0.c +6 -0
index 0f8b9e59d394e..fdb21739c1d53 100644
@@ -981,6 +981,12 @@ static int mes_v12_0_misc_op(struct amdgpu_mes *mes,
 		memcpy(misc_pkt.set_shader_debugger.tcp_watch_cntl,
 				input->set_shader_debugger.tcp_watch_cntl,
 				sizeof(misc_pkt.set_shader_debugger.tcp_watch_cntl));
+		for (int i = 0; i < 4; i++) {
+			misc_pkt.set_shader_debugger.tcp_watch_addr_lo[i] =
+				lower_32_bits(input->set_shader_debugger.watch_addresses[i]);
+			misc_pkt.set_shader_debugger.tcp_watch_addr_hi[i] =
+				upper_32_bits(input->set_shader_debugger.watch_addresses[i]) & 0xffff;
+		}
 		misc_pkt.set_shader_debugger.trap_en = input->set_shader_debugger.trap_en;
 		break;
 	case MES_MISC_OP_CHANGE_CONFIG:
drivers/gpu/drm/amd/amdgpu/mes_v12_1.c +6 -0
index ef81c5a23b9da..3c154529aff30 100644
@@ -622,6 +622,12 @@ static int mes_v12_1_misc_op(struct amdgpu_mes *mes,
 		memcpy(misc_pkt.set_shader_debugger.tcp_watch_cntl,
 				input->set_shader_debugger.tcp_watch_cntl,
 				sizeof(misc_pkt.set_shader_debugger.tcp_watch_cntl));
+		for (int i = 0; i < 4; i++) {
+			misc_pkt.set_shader_debugger.tcp_watch_addr_lo[i] =
+				lower_32_bits(input->set_shader_debugger.watch_addresses[i]);
+			misc_pkt.set_shader_debugger.tcp_watch_addr_hi[i] =
+				upper_32_bits(input->set_shader_debugger.watch_addresses[i]) & 0xffff;
+		}
 		misc_pkt.set_shader_debugger.trap_en = input->set_shader_debugger.trap_en;
 		break;
 	case MES_MISC_OP_CHANGE_CONFIG:
drivers/gpu/drm/amd/include/mes_v12_api_def.h +3 -0
index 3e214cb4f6e13..090c9142674e3 100644
@@ -805,6 +805,9 @@ struct SET_SHADER_DEBUGGER {
 	uint32_t spi_gdbg_per_vmid_cntl;
 	uint32_t tcp_watch_cntl[4]; // TCP_WATCHx_CNTL
 	uint32_t trap_en;
+	uint32_t tcp_watch_addr_lo[4]; // TCP_WATCHx_ADDR_L
+	uint32_t tcp_watch_addr_hi[4]; // TCP_WATCHx_ADDR_H
+	uint32_t process_context_array_index;
 };
 
 struct SET_GANG_SUBMIT {
Signature · 1 line
2.55.0