Skip to contentSkip to conversation

drm/amdgpu/mes: Support 64-bit register reads

PATCH Superseded Victor Zhao 2 participants 7 messages Sep 24 – Sep 28

Subsystems (2)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/2 drm/amdgpu/mes: Support 64-bit register reads

[why]
Some register values span two consecutive dwords and must be sampled with one MES operation.

[how]
Add amdgpu_mes_rreg64(), set READ_REG read64Bits for MES 11 and MES 12, and combine the two returned dwords into a 64-bit value.

v2: add MES 11 support with the same read64Bits option

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c       | 42 +++++++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_mes.h       |  3 ++
 drivers/gpu/drm/amd/amdgpu/mes_v11_0.c        |  2 +
 drivers/gpu/drm/amd/amdgpu/mes_v12_0.c        |  2 +
 drivers/gpu/drm/amd/amdgpu/mes_v12_1.c        |  2 +
 drivers/gpu/drm/amd/include/mes_v11_api_def.h |  7 ++++
 6 files changed, 58 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c +42 -0
index 5bebe74de01ad..52b05dc7b74e2 100644
@@ -582,6 +582,7 @@ uint32_t amdgpu_mes_rreg(struct amdgpu_device *adev, uint32_t reg,
 	op_input.op = MES_MISC_OP_READ_REG;
 	op_input.read_reg.reg_offset = reg;
 	op_input.read_reg.buffer_addr = read_val_gpu_addr;
+	op_input.read_reg.read64_bits = false;
 
 	if (!adev->mes.funcs->misc_op) {
 		dev_err(adev->dev, "mes rreg is not supported!\n");
@@ -602,6 +603,47 @@ uint32_t amdgpu_mes_rreg(struct amdgpu_device *adev, uint32_t reg,
 	return val;
 }
 
+uint64_t amdgpu_mes_rreg64(struct amdgpu_device *adev, uint32_t reg,
+			   uint32_t xcc_id)
+{
+	struct mes_misc_op_input op_input = { 0 };
+	uint64_t val = 0;
+	uint32_t addr_offset;
+	uint32_t *read_val_ptr;
+	int r;
+
+	if (amdgpu_wb_get(adev, &addr_offset)) {
+		dev_err(adev->dev, "critical bug! too many mes readers\n");
+		return 0;
+	}
+
+	read_val_ptr = (uint32_t *)&adev->wb.wb[addr_offset];
+	op_input.xcc_id = xcc_id;
+	op_input.op = MES_MISC_OP_READ_REG;
+	op_input.read_reg.reg_offset = reg;
+	op_input.read_reg.buffer_addr = adev->wb.gpu_addr + addr_offset * 4;
+	op_input.read_reg.read64_bits = true;
+
+	if (!adev->mes.funcs->misc_op) {
+		dev_err(adev->dev, "mes rreg is not supported!\n");
+		goto error;
+	}
+
+	amdgpu_mes_lock(&adev->mes);
+	r = adev->mes.funcs->misc_op(&adev->mes, &op_input);
+	amdgpu_mes_unlock(&adev->mes);
+	if (r) {
+		dev_err(adev->dev, "failed to read reg (0x%x)\n", reg);
+	} else {
+		val = READ_ONCE(read_val_ptr[0]);
+		val |= (uint64_t)READ_ONCE(read_val_ptr[1]) << 32;
+	}
+
+error:
+	amdgpu_wb_free(adev, addr_offset);
+	return val;
+}
+
 int amdgpu_mes_wreg(struct amdgpu_device *adev, uint32_t reg,
 		    uint32_t val, uint32_t xcc_id)
 {
drivers/gpu/drm/amd/amdgpu/amdgpu_mes.h +3 -0
index 33a426f58e723..d67814124f9e1 100644
@@ -373,6 +373,7 @@ struct mes_misc_op_input {
 		struct {
 			uint32_t                  reg_offset;
 			uint64_t                  buffer_addr;
+			bool                      read64_bits;
 		} read_reg;
 
 		struct {
@@ -545,6 +546,8 @@ int amdgpu_mes_detect_and_reset_hung_queues(struct amdgpu_device *adev,
 
 uint32_t amdgpu_mes_rreg(struct amdgpu_device *adev, uint32_t reg,
 			 uint32_t xcc_id);
+uint64_t amdgpu_mes_rreg64(struct amdgpu_device *adev, uint32_t reg,
+			   uint32_t xcc_id);
 int amdgpu_mes_wreg(struct amdgpu_device *adev,
 		    uint32_t reg, uint32_t val, uint32_t xcc_id);
 int amdgpu_mes_reg_write_reg_wait(struct amdgpu_device *adev,
drivers/gpu/drm/amd/amdgpu/mes_v11_0.c +2 -0
index d8b4d3deff605..304087b851644 100644
@@ -905,6 +905,8 @@ static int mes_v11_0_misc_op(struct amdgpu_mes *mes,
 		misc_pkt.opcode = MESAPI_MISC__READ_REG;
 		misc_pkt.read_reg.reg_offset = input->read_reg.reg_offset;
 		misc_pkt.read_reg.buffer_addr = input->read_reg.buffer_addr;
+		misc_pkt.read_reg.option.bits.read64Bits =
+			input->read_reg.read64_bits;
 		break;
 	case MES_MISC_OP_WRITE_REG:
 		misc_pkt.opcode = MESAPI_MISC__WRITE_REG;
drivers/gpu/drm/amd/amdgpu/mes_v12_0.c +2 -0
index 04465804c2544..0d2a60528802e 100644
@@ -858,6 +858,8 @@ static int mes_v12_0_misc_op(struct amdgpu_mes *mes,
 		misc_pkt.opcode = MESAPI_MISC__READ_REG;
 		misc_pkt.read_reg.reg_offset = input->read_reg.reg_offset;
 		misc_pkt.read_reg.buffer_addr = input->read_reg.buffer_addr;
+		misc_pkt.read_reg.option.bits.read64Bits =
+			input->read_reg.read64_bits;
 		break;
 	case MES_MISC_OP_WRITE_REG:
 		misc_pkt.opcode = MESAPI_MISC__WRITE_REG;
drivers/gpu/drm/amd/amdgpu/mes_v12_1.c +2 -0
index d17ced46d5f73..e0a488e516c09 100644
@@ -581,6 +581,8 @@ static int mes_v12_1_misc_op(struct amdgpu_mes *mes,
 	case MES_MISC_OP_READ_REG:
 		misc_pkt.opcode = MESAPI_MISC__READ_REG;
 		misc_pkt.read_reg.buffer_addr = input->read_reg.buffer_addr;
+		misc_pkt.read_reg.option.bits.read64Bits =
+			input->read_reg.read64_bits;
 		mes_v12_1_get_rrmt(input->read_reg.reg_offset,
 				   GET_INST(GC, input->xcc_id),
 				   &misc_pkt.read_reg.rrmt_opt,
drivers/gpu/drm/amd/include/mes_v11_api_def.h +7 -0
index 1fe824b41f2a5..b27ec78da3b08 100644
@@ -635,6 +635,13 @@ struct WRITE_REG {
 struct READ_REG {
 	uint32_t                  reg_offset;
 	uint64_t                  buffer_addr;
+	union {
+		struct {
+			uint32_t read64Bits : 1;
+			uint32_t reserved : 31;
+		} bits;
+		uint32_t all;
+	} option;
 };
 
 enum WRM_OPERATION {
Signature · 1 line
2.50.1
#1 lore raw

PATCH v2 2/2 drm/amdgpu: Read RLC GPU clock on GFX12.1 VF

[why]
VF timestamp queries need a TSC sample independent of CP/MES. The SMUIO path is not safe on VF.

[how]
Capture via RLC_CAPTURE_GPU_CLOCK_COUNT and read the consecutive count registers with amdgpu_mes_rreg64().

---
 drivers/gpu/drm/amd/amdgpu/gfx_v12_1.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)
drivers/gpu/drm/amd/amdgpu/gfx_v12_1.c +26 -0
index d6f70d33201a0..3c8133c94d6fc 100644
@@ -3168,10 +3168,36 @@ static int gfx_v12_1_wait_for_idle(struct amdgpu_ip_block *ip_block)
 	return -ETIMEDOUT;
 }
 
+static uint64_t gfx_v12_1_get_rlc_gpu_clock_counter(struct amdgpu_device *adev)
+{
+	uint64_t clock = 0;
+	uint32_t reg;
+
+	if (!down_read_trylock(&adev->reset_domain->sem))
+		return 0;
+	if (amdgpu_device_skip_hw_access(adev) ||
+	    !adev->mes.ring[0].sched.ready)
+		goto unlock_reset;
+
+	mutex_lock(&adev->gfx.gpu_clock_mutex);
+	WREG32_SOC15(GC, GET_INST(GC, 0), regRLC_CAPTURE_GPU_CLOCK_COUNT, 1);
+	reg = SOC15_REG_OFFSET(GC, GET_INST(GC, 0),
+			       regRLC_GPU_CLOCK_COUNT_LSB);
+	clock = amdgpu_mes_rreg64(adev, reg, 0);
+	mutex_unlock(&adev->gfx.gpu_clock_mutex);
+
+unlock_reset:
+	up_read(&adev->reset_domain->sem);
+	return clock;
+}
+
 static uint64_t gfx_v12_1_get_gpu_clock_counter(struct amdgpu_device *adev)
 {
 	uint64_t clock = 0;
 
+	if (amdgpu_sriov_vf(adev))
+		return gfx_v12_1_get_rlc_gpu_clock_counter(adev);
+
 	if (adev->smuio.funcs &&
 	    adev->smuio.funcs->get_gpu_clock_counter)
 		clock = adev->smuio.funcs->get_gpu_clock_counter(adev);
Signature · 1 line
2.50.1
#2 lore raw

RE: [PATCH v2 2/2] drm/amdgpu: Read RLC GPU clock on GFX12.1 VF

AMD General

@Lazar, Lijo @Liu, Shaoyun,

Can you help review?

Thanks,
Victor

-----Original Message-----
From: Victor Zhao <[email protected]>
Sent: Thursday, September 24, 2026 2:35 PM
To: [email protected]; Lazar, Lijo <[email protected]>; Deucher, Alexander <[email protected]>; Liu, Shaoyun <[email protected]>
Cc: Ming, Davis <[email protected]>; Wan, Gavin <[email protected]>; Zhao, Victor <[email protected]>
Subject: [PATCH v2 2/2] drm/amdgpu: Read RLC GPU clock on GFX12.1 VF

[why]
VF timestamp queries need a TSC sample independent of CP/MES. The SMUIO path is not safe on VF.

[how]
Capture via RLC_CAPTURE_GPU_CLOCK_COUNT and read the consecutive count registers with amdgpu_mes_rreg64().

---
 drivers/gpu/drm/amd/amdgpu/gfx_v12_1.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)
drivers/gpu/drm/amd/amdgpu/gfx_v12_1.c +26 -1
index d6f70d33201a0..3c8133c94d6fc 100644
@@ -3168,10 +3168,36 @@ static int gfx_v12_1_wait_for_idle(struct amdgpu_ip_block *ip_block)
        return -ETIMEDOUT;
 }
 
+static uint64_t gfx_v12_1_get_rlc_gpu_clock_counter(struct
+amdgpu_device *adev) {
+       uint64_t clock = 0;
+       uint32_t reg;
+
+       if (!down_read_trylock(&adev->reset_domain->sem))
+               return 0;
+       if (amdgpu_device_skip_hw_access(adev) ||
+           !adev->mes.ring[0].sched.ready)
+               goto unlock_reset;
+
+       mutex_lock(&adev->gfx.gpu_clock_mutex);
+       WREG32_SOC15(GC, GET_INST(GC, 0), regRLC_CAPTURE_GPU_CLOCK_COUNT, 1);
+       reg = SOC15_REG_OFFSET(GC, GET_INST(GC, 0),
+                              regRLC_GPU_CLOCK_COUNT_LSB);
+       clock = amdgpu_mes_rreg64(adev, reg, 0);
+       mutex_unlock(&adev->gfx.gpu_clock_mutex);
+
+unlock_reset:
+       up_read(&adev->reset_domain->sem);
+       return clock;
+}
+
 static uint64_t gfx_v12_1_get_gpu_clock_counter(struct amdgpu_device *adev)  {
        uint64_t clock = 0;
 
+       if (amdgpu_sriov_vf(adev))
+               return gfx_v12_1_get_rlc_gpu_clock_counter(adev);
+
        if (adev->smuio.funcs &&
            adev->smuio.funcs->get_gpu_clock_counter)
                clock = adev->smuio.funcs->get_gpu_clock_counter(adev);
--

2.50.1

#3 lore raw

Re: [PATCH v2 2/2] drm/amdgpu: Read RLC GPU clock on GFX12.1 VF

In reply to Victor Zhao
Quoted 27 lines · Victor Zhao

[why]
VF timestamp queries need a TSC sample independent of CP/MES. The SMUIO path is not safe on VF.

[how]
Capture via RLC_CAPTURE_GPU_CLOCK_COUNT and read the consecutive count registers with amdgpu_mes_rreg64().

---
  drivers/gpu/drm/amd/amdgpu/gfx_v12_1.c | 26 ++++++++++++++++++++++++++
  1 file changed, 26 insertions(+)
drivers/gpu/drm/amd/amdgpu/gfx_v12_1.c +6 -0
index d6f70d33201a0..3c8133c94d6fc 100644
@@ -3168,10 +3168,36 @@ static int gfx_v12_1_wait_for_idle(struct amdgpu_ip_block *ip_block)
  	return -ETIMEDOUT;
  }
 
+static uint64_t gfx_v12_1_get_rlc_gpu_clock_counter(struct amdgpu_device *adev)
+{
+	uint64_t clock = 0;
+	uint32_t reg;
+
+	if (!down_read_trylock(&adev->reset_domain->sem))

drivers/gpu/drm/amd/amdgpu/gfx_v12_1.c static int gfx_v12_1_wait_for_idle(struct amdgpu_ip_block *ip_block) · line 3186

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/gfx_v12_1.c +10 -0
+		return 0;
+	if (amdgpu_device_skip_hw_access(adev) ||
+	    !adev->mes.ring[0].sched.ready)
+		goto unlock_reset;
+
+	mutex_lock(&adev->gfx.gpu_clock_mutex);
+	WREG32_SOC15(GC, GET_INST(GC, 0), regRLC_CAPTURE_GPU_CLOCK_COUNT, 1);
+	reg = SOC15_REG_OFFSET(GC, GET_INST(GC, 0),
+			       regRLC_GPU_CLOCK_COUNT_LSB);
+	clock = amdgpu_mes_rreg64(adev, reg, 0);

The API error cases should be checked and the clock value (0?) should be returned accordingly to indicate an invalid counter value.

Thanks,
Lijo

Quoted 17 lines
drivers/gpu/drm/amd/amdgpu/gfx_v12_1.c +10 -0
+	mutex_unlock(&adev->gfx.gpu_clock_mutex);
+
+unlock_reset:
+	up_read(&adev->reset_domain->sem);
+	return clock;
+}
+
  static uint64_t gfx_v12_1_get_gpu_clock_counter(struct amdgpu_device *adev)
  {
  	uint64_t clock = 0;
 
+	if (amdgpu_sriov_vf(adev))
+		return gfx_v12_1_get_rlc_gpu_clock_counter(adev);
+
  	if (adev->smuio.funcs &&
  	    adev->smuio.funcs->get_gpu_clock_counter)
  		clock = adev->smuio.funcs->get_gpu_clock_counter(adev);
#4 lore raw
In reply to Victor Zhao
Quoted 106 lines · Victor Zhao

[why]
Some register values span two consecutive dwords and must be sampled with one MES operation.

[how]
Add amdgpu_mes_rreg64(), set READ_REG read64Bits for MES 11 and MES 12, and combine the two returned dwords into a 64-bit value.

v2: add MES 11 support with the same read64Bits option

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c       | 42 +++++++++++++++++++
  drivers/gpu/drm/amd/amdgpu/amdgpu_mes.h       |  3 ++
  drivers/gpu/drm/amd/amdgpu/mes_v11_0.c        |  2 +
  drivers/gpu/drm/amd/amdgpu/mes_v12_0.c        |  2 +
  drivers/gpu/drm/amd/amdgpu/mes_v12_1.c        |  2 +
  drivers/gpu/drm/amd/include/mes_v11_api_def.h |  7 ++++
  6 files changed, 58 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c +42 -0
index 5bebe74de01ad..52b05dc7b74e2 100644
@@ -582,6 +582,7 @@ uint32_t amdgpu_mes_rreg(struct amdgpu_device *adev, uint32_t reg,
  	op_input.op = MES_MISC_OP_READ_REG;
  	op_input.read_reg.reg_offset = reg;
  	op_input.read_reg.buffer_addr = read_val_gpu_addr;
+	op_input.read_reg.read64_bits = false;
 
  	if (!adev->mes.funcs->misc_op) {
  		dev_err(adev->dev, "mes rreg is not supported!\n");
@@ -602,6 +603,47 @@ uint32_t amdgpu_mes_rreg(struct amdgpu_device *adev, uint32_t reg,
  	return val;
  }
 
+uint64_t amdgpu_mes_rreg64(struct amdgpu_device *adev, uint32_t reg,
+			   uint32_t xcc_id)
+{
+	struct mes_misc_op_input op_input = { 0 };
+	uint64_t val = 0;
+	uint32_t addr_offset;
+	uint32_t *read_val_ptr;
+	int r;
+
+	if (amdgpu_wb_get(adev, &addr_offset)) {
+		dev_err(adev->dev, "critical bug! too many mes readers\n");
+		return 0;
+	}
+
+	read_val_ptr = (uint32_t *)&adev->wb.wb[addr_offset];
+	op_input.xcc_id = xcc_id;
+	op_input.op = MES_MISC_OP_READ_REG;
+	op_input.read_reg.reg_offset = reg;
+	op_input.read_reg.buffer_addr = adev->wb.gpu_addr + addr_offset * 4;
+	op_input.read_reg.read64_bits = true;
+
+	if (!adev->mes.funcs->misc_op) {
+		dev_err(adev->dev, "mes rreg is not supported!\n");
+		goto error;
+	}
+
+	amdgpu_mes_lock(&adev->mes);
+	r = adev->mes.funcs->misc_op(&adev->mes, &op_input);
+	amdgpu_mes_unlock(&adev->mes);
+	if (r) {
+		dev_err(adev->dev, "failed to read reg (0x%x)\n", reg);
+	} else {
+		val = READ_ONCE(read_val_ptr[0]);
+		val |= (uint64_t)READ_ONCE(read_val_ptr[1]) << 32;
+	}
+
+error:
+	amdgpu_wb_free(adev, addr_offset);
+	return val;
+}
+
  int amdgpu_mes_wreg(struct amdgpu_device *adev, uint32_t reg,
  		    uint32_t val, uint32_t xcc_id)
  {
drivers/gpu/drm/amd/amdgpu/amdgpu_mes.h +3 -0
index 33a426f58e723..d67814124f9e1 100644
@@ -373,6 +373,7 @@ struct mes_misc_op_input {
  		struct {
  			uint32_t                  reg_offset;
  			uint64_t                  buffer_addr;
+			bool                      read64_bits;
  		} read_reg;
 
  		struct {
@@ -545,6 +546,8 @@ int amdgpu_mes_detect_and_reset_hung_queues(struct amdgpu_device *adev,
 
  uint32_t amdgpu_mes_rreg(struct amdgpu_device *adev, uint32_t reg,
  			 uint32_t xcc_id);
+uint64_t amdgpu_mes_rreg64(struct amdgpu_device *adev, uint32_t reg,
+			   uint32_t xcc_id);
  int amdgpu_mes_wreg(struct amdgpu_device *adev,
  		    uint32_t reg, uint32_t val, uint32_t xcc_id);
  int amdgpu_mes_reg_write_reg_wait(struct amdgpu_device *adev,
drivers/gpu/drm/amd/amdgpu/mes_v11_0.c +0 -0
index d8b4d3deff605..304087b851644 100644

drivers/gpu/drm/amd/amdgpu/mes_v11_0.c static int mes_v11_0_misc_op(struct amdgpu_mes *mes, · line 909

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/mes_v11_0.c +2 -0
@@ -905,6 +905,8 @@ static int mes_v11_0_misc_op(struct amdgpu_mes *mes,
  		misc_pkt.opcode = MESAPI_MISC__READ_REG;
  		misc_pkt.read_reg.reg_offset = input->read_reg.reg_offset;
  		misc_pkt.read_reg.buffer_addr = input->read_reg.buffer_addr;
+		misc_pkt.read_reg.option.bits.read64Bits =
+			input->read_reg.read64_bits;

Is this only a missing interface definition or does this need supported FW version check?

Thanks,
Lijo

Quoted 47 lines
drivers/gpu/drm/amd/amdgpu/mes_v11_0.c +0 -0
  		break;
  	case MES_MISC_OP_WRITE_REG:
  		misc_pkt.opcode = MESAPI_MISC__WRITE_REG;
drivers/gpu/drm/amd/amdgpu/mes_v12_0.c +2 -0
index 04465804c2544..0d2a60528802e 100644
@@ -858,6 +858,8 @@ static int mes_v12_0_misc_op(struct amdgpu_mes *mes,
  		misc_pkt.opcode = MESAPI_MISC__READ_REG;
  		misc_pkt.read_reg.reg_offset = input->read_reg.reg_offset;
  		misc_pkt.read_reg.buffer_addr = input->read_reg.buffer_addr;
+		misc_pkt.read_reg.option.bits.read64Bits =
+			input->read_reg.read64_bits;
  		break;
  	case MES_MISC_OP_WRITE_REG:
  		misc_pkt.opcode = MESAPI_MISC__WRITE_REG;
drivers/gpu/drm/amd/amdgpu/mes_v12_1.c +2 -0
index d17ced46d5f73..e0a488e516c09 100644
@@ -581,6 +581,8 @@ static int mes_v12_1_misc_op(struct amdgpu_mes *mes,
  	case MES_MISC_OP_READ_REG:
  		misc_pkt.opcode = MESAPI_MISC__READ_REG;
  		misc_pkt.read_reg.buffer_addr = input->read_reg.buffer_addr;
+		misc_pkt.read_reg.option.bits.read64Bits =
+			input->read_reg.read64_bits;
  		mes_v12_1_get_rrmt(input->read_reg.reg_offset,
  				   GET_INST(GC, input->xcc_id),
  				   &misc_pkt.read_reg.rrmt_opt,
drivers/gpu/drm/amd/include/mes_v11_api_def.h +7 -0
index 1fe824b41f2a5..b27ec78da3b08 100644
@@ -635,6 +635,13 @@ struct WRITE_REG {
  struct READ_REG {
  	uint32_t                  reg_offset;
  	uint64_t                  buffer_addr;
+	union {
+		struct {
+			uint32_t read64Bits : 1;
+			uint32_t reserved : 31;
+		} bits;
+		uint32_t all;
+	} option;
  };
 
  enum WRM_OPERATION {
#5 lore raw
Quoted 43 lines · Lijo
Quoted 40 lines · Victor Zhao

[why]
Some register values span two consecutive dwords and must be sampled with one MES operation.

[how]
Add amdgpu_mes_rreg64(), set READ_REG read64Bits for MES 11 and MES 12, and combine the two returned dwords into a 64-bit value.

v2: add MES 11 support with the same read64Bits option

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c       | 42 +++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_mes.h       |  3 ++

  drivers/gpu/drm/amd/amdgpu/mes_v11_0.c        |  2 +
  drivers/gpu/drm/amd/amdgpu/mes_v12_0.c        |  2 +
  drivers/gpu/drm/amd/amdgpu/mes_v12_1.c        |  2 +
  drivers/gpu/drm/amd/include/mes_v11_api_def.h |  7 ++++
  6 files changed, 58 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c +5 -0
index 5bebe74de01ad..52b05dc7b74e2 100644
@@ -582,6 +582,7 @@ uint32_t amdgpu_mes_rreg(struct amdgpu_device 
 *adev, uint32_t reg,
       op_input.op = MES_MISC_OP_READ_REG;
       op_input.read_reg.reg_offset = reg;
       op_input.read_reg.buffer_addr = read_val_gpu_addr;
+    op_input.read_reg.read64_bits = false;
       if (!adev->mes.funcs->misc_op) {
           dev_err(adev->dev, "mes rreg is not supported!\n");
@@ -602,6 +603,47 @@ uint32_t amdgpu_mes_rreg(struct amdgpu_device 
 *adev, uint32_t reg,
       return val;
   }
+uint64_t amdgpu_mes_rreg64(struct amdgpu_device *adev, uint32_t reg,
+               uint32_t xcc_id)
+{
+    struct mes_misc_op_input op_input = { 0 };
Quoted 8 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c uint32_t amdgpu_mes_rreg(struct amdgpu_device *adev, uint32_t reg, · line 617

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c +8 -0
+    uint64_t val = 0;
+    uint32_t addr_offset;
+    uint32_t *read_val_ptr;
+    int r;
+
+    if (amdgpu_wb_get(adev, &addr_offset)) {
+        dev_err(adev->dev, "critical bug! too many mes readers\n");
+        return 0;

For the comment about patch 2, this API should return an error code. 0 could be misinterpreted as a valid register value.

Thanks,
Lijo

Quoted 116 lines
Quoted 57 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c +29 -0
+    }
+
+    read_val_ptr = (uint32_t *)&adev->wb.wb[addr_offset];
+    op_input.xcc_id = xcc_id;
+    op_input.op = MES_MISC_OP_READ_REG;
+    op_input.read_reg.reg_offset = reg;
+    op_input.read_reg.buffer_addr = adev->wb.gpu_addr + addr_offset * 4;
+    op_input.read_reg.read64_bits = true;
+
+    if (!adev->mes.funcs->misc_op) {
+        dev_err(adev->dev, "mes rreg is not supported!\n");
+        goto error;
+    }
+
+    amdgpu_mes_lock(&adev->mes);
+    r = adev->mes.funcs->misc_op(&adev->mes, &op_input);
+    amdgpu_mes_unlock(&adev->mes);
+    if (r) {
+        dev_err(adev->dev, "failed to read reg (0x%x)\n", reg);
+    } else {
+        val = READ_ONCE(read_val_ptr[0]);
+        val |= (uint64_t)READ_ONCE(read_val_ptr[1]) << 32;
+    }
+
+error:
+    amdgpu_wb_free(adev, addr_offset);
+    return val;
+}
+
   int amdgpu_mes_wreg(struct amdgpu_device *adev, uint32_t reg,
               uint32_t val, uint32_t xcc_id)
   {
drivers/gpu/drm/amd/amdgpu/amdgpu_mes.h +3 -0
index 33a426f58e723..d67814124f9e1 100644
@@ -373,6 +373,7 @@ struct mes_misc_op_input {
           struct {
               uint32_t                  reg_offset;
               uint64_t                  buffer_addr;
+            bool                      read64_bits;
           } read_reg;
           struct {
@@ -545,6 +546,8 @@ int amdgpu_mes_detect_and_reset_hung_queues(struct 
 amdgpu_device *adev,
   uint32_t amdgpu_mes_rreg(struct amdgpu_device *adev, uint32_t reg,
                uint32_t xcc_id);
+uint64_t amdgpu_mes_rreg64(struct amdgpu_device *adev, uint32_t reg,
+               uint32_t xcc_id);
   int amdgpu_mes_wreg(struct amdgpu_device *adev,
               uint32_t reg, uint32_t val, uint32_t xcc_id);
   int amdgpu_mes_reg_write_reg_wait(struct amdgpu_device *adev,
drivers/gpu/drm/amd/amdgpu/mes_v11_0.c +0 -0
index d8b4d3deff605..304087b851644 100644

drivers/gpu/drm/amd/amdgpu/mes_v11_0.c static int mes_v11_0_misc_op(struct amdgpu_mes *mes, · line 909

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/mes_v11_0.c +2 -0
@@ -905,6 +905,8 @@ static int mes_v11_0_misc_op(struct amdgpu_mes *mes,
           misc_pkt.opcode = MESAPI_MISC__READ_REG;
           misc_pkt.read_reg.reg_offset = input->read_reg.reg_offset;
           misc_pkt.read_reg.buffer_addr = input->read_reg.buffer_addr;
+        misc_pkt.read_reg.option.bits.read64Bits =
+            input->read_reg.read64_bits;

Is this only a missing interface definition or does this need supported FW version check?

Thanks,
Lijo

Quoted 46 lines
drivers/gpu/drm/amd/amdgpu/mes_v11_0.c +0 -0
           break;

      case MES_MISC_OP_WRITE_REG:
          misc_pkt.opcode = MESAPI_MISC__WRITE_REG;

drivers/gpu/drm/amd/amdgpu/mes_v12_0.c +2 -0
index 04465804c2544..0d2a60528802e 100644
@@ -858,6 +858,8 @@ static int mes_v12_0_misc_op(struct amdgpu_mes *mes,
           misc_pkt.opcode = MESAPI_MISC__READ_REG;
           misc_pkt.read_reg.reg_offset = input->read_reg.reg_offset;
           misc_pkt.read_reg.buffer_addr = input->read_reg.buffer_addr;
+        misc_pkt.read_reg.option.bits.read64Bits =
+            input->read_reg.read64_bits;
           break;

      case MES_MISC_OP_WRITE_REG:
          misc_pkt.opcode = MESAPI_MISC__WRITE_REG;

drivers/gpu/drm/amd/amdgpu/mes_v12_1.c +0 -0
index d17ced46d5f73..e0a488e516c09 100644
@@ -581,6 +581,8 @@ static int mes_v12_1_misc_op(struct amdgpu_mes *mes,

      case MES_MISC_OP_READ_REG:
          misc_pkt.opcode = MESAPI_MISC__READ_REG; misc_pkt.read_reg.buffer_addr = input->read_reg.buffer_addr; +        misc_pkt.read_reg.option.bits.read64Bits =
+            input->read_reg.read64_bits; mes_v12_1_get_rrmt(input->read_reg.reg_offset, GET_INST(GC, input->xcc_id), &misc_pkt.read_reg.rrmt_opt,

drivers/gpu/drm/amd/include/mes_v11_api_def.h +7 -0
index 1fe824b41f2a5..b27ec78da3b08 100644
@@ -635,6 +635,13 @@ struct WRITE_REG {
   struct READ_REG {
       uint32_t                  reg_offset;
       uint64_t                  buffer_addr;
+    union {
+        struct {
+            uint32_t read64Bits : 1;
+            uint32_t reserved : 31;
+        } bits;
+        uint32_t all;
+    } option;
   };
   enum WRM_OPERATION {
#6 lore raw
In reply to Lazar, Lijo

AMD General

Thanks for reviewing. I checked mes change history and the 64bit support was added after 0x42 for mes 11, will add a version check. @Liu, Shaoyun please correct me if its wrong.

Thanks,
Victor

-----Original Message-----
From: Lazar, Lijo <[email protected]>
Sent: Monday, September 28, 2026 12:43 PM
To: Zhao, Victor <[email protected]>; [email protected]; Deucher, Alexander <[email protected]>; Liu, Shaoyun <[email protected]>
Cc: Ming, Davis <[email protected]>; Wan, Gavin <[email protected]>
Subject: Re: [PATCH v2 1/2] drm/amdgpu/mes: Support 64-bit register reads

Quoted 110 lines · Victor Zhao

[why]
Some register values span two consecutive dwords and must be sampled with one MES operation.

[how]
Add amdgpu_mes_rreg64(), set READ_REG read64Bits for MES 11 and MES 12, and combine the two returned dwords into a 64-bit value.

v2: add MES 11 support with the same read64Bits option

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c       | 42 +++++++++++++++++++
  drivers/gpu/drm/amd/amdgpu/amdgpu_mes.h       |  3 ++
  drivers/gpu/drm/amd/amdgpu/mes_v11_0.c        |  2 +
  drivers/gpu/drm/amd/amdgpu/mes_v12_0.c        |  2 +
  drivers/gpu/drm/amd/amdgpu/mes_v12_1.c        |  2 +
  drivers/gpu/drm/amd/include/mes_v11_api_def.h |  7 ++++
  6 files changed, 58 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c +43 -0
index 5bebe74de01ad..52b05dc7b74e2 100644
@@ -582,6 +582,7 @@ uint32_t amdgpu_mes_rreg(struct amdgpu_device *adev, uint32_t reg,
      op_input.op = MES_MISC_OP_READ_REG;
      op_input.read_reg.reg_offset = reg;
      op_input.read_reg.buffer_addr = read_val_gpu_addr;
+     op_input.read_reg.read64_bits = false;
 
      if (!adev->mes.funcs->misc_op) {
              dev_err(adev->dev, "mes rreg is not supported!\n"); @@ -602,6
+603,47 @@ uint32_t amdgpu_mes_rreg(struct amdgpu_device *adev, uint32_t reg,
      return val;
  }
 
+uint64_t amdgpu_mes_rreg64(struct amdgpu_device *adev, uint32_t reg,
+                        uint32_t xcc_id)
+{
+     struct mes_misc_op_input op_input = { 0 };
+     uint64_t val = 0;
+     uint32_t addr_offset;
+     uint32_t *read_val_ptr;
+     int r;
+
+     if (amdgpu_wb_get(adev, &addr_offset)) {
+             dev_err(adev->dev, "critical bug! too many mes readers\n");
+             return 0;
+     }
+
+     read_val_ptr = (uint32_t *)&adev->wb.wb[addr_offset];
+     op_input.xcc_id = xcc_id;
+     op_input.op = MES_MISC_OP_READ_REG;
+     op_input.read_reg.reg_offset = reg;
+     op_input.read_reg.buffer_addr = adev->wb.gpu_addr + addr_offset * 4;
+     op_input.read_reg.read64_bits = true;
+
+     if (!adev->mes.funcs->misc_op) {
+             dev_err(adev->dev, "mes rreg is not supported!\n");
+             goto error;
+     }
+
+     amdgpu_mes_lock(&adev->mes);
+     r = adev->mes.funcs->misc_op(&adev->mes, &op_input);
+     amdgpu_mes_unlock(&adev->mes);
+     if (r) {
+             dev_err(adev->dev, "failed to read reg (0x%x)\n", reg);
+     } else {
+             val = READ_ONCE(read_val_ptr[0]);
+             val |= (uint64_t)READ_ONCE(read_val_ptr[1]) << 32;
+     }
+
+error:
+     amdgpu_wb_free(adev, addr_offset);
+     return val;
+}
+
  int amdgpu_mes_wreg(struct amdgpu_device *adev, uint32_t reg,
                  uint32_t val, uint32_t xcc_id)
  {
drivers/gpu/drm/amd/amdgpu/amdgpu_mes.h +3 -0
index 33a426f58e723..d67814124f9e1 100644
@@ -373,6 +373,7 @@ struct mes_misc_op_input {
              struct {
                      uint32_t                  reg_offset;
                      uint64_t                  buffer_addr;
+                     bool                      read64_bits;
              } read_reg;
 
              struct {
@@ -545,6 +546,8 @@ int amdgpu_mes_detect_and_reset_hung_queues(struct
 amdgpu_device *adev,
 
  uint32_t amdgpu_mes_rreg(struct amdgpu_device *adev, uint32_t reg,
                       uint32_t xcc_id);
+uint64_t amdgpu_mes_rreg64(struct amdgpu_device *adev, uint32_t reg,
+                        uint32_t xcc_id);
  int amdgpu_mes_wreg(struct amdgpu_device *adev,
                  uint32_t reg, uint32_t val, uint32_t xcc_id);

int amdgpu_mes_reg_write_reg_wait(struct amdgpu_device *adev, diff
--git a/drivers/gpu/drm/amd/amdgpu/mes_v11_0.c b/drivers/gpu/drm/amd/amdgpu/mes_v11_0.c
index d8b4d3deff605..304087b851644 100644

drivers/gpu/drm/amd/amdgpu/mes_v11_0.c static int mes_v11_0_misc_op(struct amdgpu_mes *mes, · line 909

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/mes_v11_0.c +2 -0
@@ -905,6 +905,8 @@ static int mes_v11_0_misc_op(struct amdgpu_mes *mes,
              misc_pkt.opcode = MESAPI_MISC__READ_REG;
              misc_pkt.read_reg.reg_offset = input->read_reg.reg_offset;
              misc_pkt.read_reg.buffer_addr = input->read_reg.buffer_addr;
+             misc_pkt.read_reg.option.bits.read64Bits =
+                     input->read_reg.read64_bits;

Is this only a missing interface definition or does this need supported FW version check?

Thanks,
Lijo

Quoted 50 lines
drivers/gpu/drm/amd/amdgpu/mes_v11_0.c +0 -0
              break;
      case MES_MISC_OP_WRITE_REG:
              misc_pkt.opcode = MESAPI_MISC__WRITE_REG; diff --git

a/drivers/gpu/drm/amd/amdgpu/mes_v12_0.c
b/drivers/gpu/drm/amd/amdgpu/mes_v12_0.c
index 04465804c2544..0d2a60528802e 100644

drivers/gpu/drm/amd/amdgpu/mes_v12_0.c +2 -0
@@ -858,6 +858,8 @@ static int mes_v12_0_misc_op(struct amdgpu_mes *mes,
              misc_pkt.opcode = MESAPI_MISC__READ_REG;
              misc_pkt.read_reg.reg_offset = input->read_reg.reg_offset;
              misc_pkt.read_reg.buffer_addr = input->read_reg.buffer_addr;
+             misc_pkt.read_reg.option.bits.read64Bits =
+                     input->read_reg.read64_bits;
              break;
      case MES_MISC_OP_WRITE_REG:
              misc_pkt.opcode = MESAPI_MISC__WRITE_REG; diff --git

a/drivers/gpu/drm/amd/amdgpu/mes_v12_1.c
b/drivers/gpu/drm/amd/amdgpu/mes_v12_1.c
index d17ced46d5f73..e0a488e516c09 100644

drivers/gpu/drm/amd/amdgpu/mes_v12_1.c +2 -0
@@ -581,6 +581,8 @@ static int mes_v12_1_misc_op(struct amdgpu_mes *mes,
      case MES_MISC_OP_READ_REG:
              misc_pkt.opcode = MESAPI_MISC__READ_REG;
              misc_pkt.read_reg.buffer_addr = input->read_reg.buffer_addr;
+             misc_pkt.read_reg.option.bits.read64Bits =
+                     input->read_reg.read64_bits;
              mes_v12_1_get_rrmt(input->read_reg.reg_offset,
                                 GET_INST(GC, input->xcc_id),
                                 &misc_pkt.read_reg.rrmt_opt,
drivers/gpu/drm/amd/include/mes_v11_api_def.h +7 -0
index 1fe824b41f2a5..b27ec78da3b08 100644
@@ -635,6 +635,13 @@ struct WRITE_REG {
  struct READ_REG {
      uint32_t                  reg_offset;
      uint64_t                  buffer_addr;
+     union {
+             struct {
+                     uint32_t read64Bits : 1;
+                     uint32_t reserved : 31;
+             } bits;
+             uint32_t all;
+     } option;
  };
 
  enum WRM_OPERATION {