drm/amdgpu/mes: Support 64-bit register reads
Subsystems (2)
PATCH v4 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. Reject 64-bit reads on MES 11 scheduler firmware older than 0x42, which predates read64Bits support.
v2: add MES 11 support with the same read64Bits option
v3: return read status separately and require MES 11 firmware 0x42 or newer
--- drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c | 41 +++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_mes.h | 3 ++ drivers/gpu/drm/amd/amdgpu/mes_v11_0.c | 6 +++ 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, 61 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c +41 -0
@@ -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,46 @@ uint32_t amdgpu_mes_rreg(struct amdgpu_device *adev, uint32_t reg,return val; } +int amdgpu_mes_rreg64 (struct amdgpu_device *adev,uint32_t reg, +uint32_t xcc_id,uint64_t *val) +{ +struct mes_misc_op_input op_input = {0 }; +uint32_t addr_offset; +uint64_t *read_val_ptr; +int r; + + r =amdgpu_wb_get (adev, &addr_offset); +if (r) { +dev_err (adev->dev,"critical bug! too many mes readers\n" ); +return r; + } + + read_val_ptr = (uint64_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" ); + r = -EINVAL ; + 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); + +error: +amdgpu_wb_free (adev, addr_offset); +return r; +} +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
@@ -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); +int amdgpu_mes_rreg64 (struct amdgpu_device *adev,uint32_t reg, +uint32_t xcc_id,uint64_t *val);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 +6 -0
@@ -902,9 +902,15 @@ static int mes_v11_0_misc_op(struct amdgpu_mes *mes,switch (input->op) {case MES_MISC_OP_READ_REG : +if (input->read_reg.read64_bits && + (mes->sched_version &AMDGPU_MES_VERSION_MASK ) <0x42 ) +return -EOPNOTSUPP ; + 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
@@ -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
@@ -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
@@ -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
PATCH v4 2/2 drm/amdgpu: Read SMUIO GPU clock on GFX12.1 VF
[why]
GFX12.1 VF timestamp queries need a SMUIO Golden TSC sample, but direct SMUIO MMIO access is restricted on VF.
[how]
Read the consecutive SMUIO Golden TSC upper and lower registers with amdgpu_mes_rreg64() on GFX12.1 VF. Swap the returned dwords to reconstruct the counter value.
v4: use SMUIO Golden TSC for GFX12.1 VF timestamp queries
--- 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
@@ -37,6 +37,7 @@#include "gc/gc_12_1_0_offset.h" #include "gc/gc_12_1_0_sh_mask.h" +#include "smuio/smuio_15_0_0_offset.h" #include "soc24_enum.h" #include "ivsrcid/gfx/irqsrcs_gfx_12_1_0.h"
@@ -3168,10 +3169,35 @@ static int gfx_v12_1_wait_for_idle(struct amdgpu_ip_block *ip_block)return -ETIMEDOUT ; } +static uint64_t gfx_v12_1_get_smuio_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; + + reg =SOC15_REG_OFFSET (SMUIO ,0 , regGOLDEN_TSC_COUNT_UPPER); +if (amdgpu_mes_rreg64 (adev, reg,0 , &clock)) + goto unlock_reset; + + clock = (clock <<32 ) | (clock >>32 ); + +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_smuio_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
Re: [PATCH v4 2/2] drm/amdgpu: Read SMUIO GPU clock on GFX12.1 VF
Quoted 36 lines · Victor Zhao
[why]
GFX12.1 VF timestamp queries need a SMUIO Golden TSC sample, but direct SMUIO MMIO access is restricted on VF.[how]
Read the consecutive SMUIO Golden TSC upper and lower registers withamdgpu_mes_rreg64()on GFX12.1 VF. Swap the returned dwords to reconstruct the counter value.v4: use SMUIO Golden TSC for GFX12.1 VF timestamp queries
Signed-off-by Victor Zhao <[email protected]>--- drivers/gpu/drm/amd/amdgpu/gfx_v12_1.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+)drivers/gpu/drm/amd/amdgpu/gfx_v12_1.c +4
-0@@ -37,6 +37,7 @@#include "gc/gc_12_1_0_offset.h" #include "gc/gc_12_1_0_sh_mask.h" +#include "smuio/smuio_15_0_0_offset.h" #include "soc24_enum.h" #include "ivsrcid/gfx/irqsrcs_gfx_12_1_0.h" @@ -3168,10 +3169,35 @@ static int gfx_v12_1_wait_for_idle(struct amdgpu_ip_block *ip_block)return -ETIMEDOUT ; } +static uint64_t gfx_v12_1_get_smuio_gpu_clock_counter (struct amdgpu_device *adev) +{ +uint64_t clock =0 ;
drivers/gpu/drm/amd/amdgpu/gfx_v12_1.c static int gfx_v12_1_wait_for_idle(struct amdgpu_ip_block *ip_block) · line 3184
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/gfx_v12_1.c +10
-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; + + reg =SOC15_REG_OFFSET (SMUIO ,0 , regGOLDEN_TSC_COUNT_UPPER); +if (amdgpu_mes_rreg64 (adev, reg,0 , &clock))
I don't see this function in the current tree. Are you missing a patch?
Alex
Quoted 22 lines
drivers/gpu/drm/amd/amdgpu/gfx_v12_1.c +12
-1+ goto unlock_reset; + + clock = (clock <<32 ) | (clock >>32 ); + +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_smuio_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
Re: [PATCH v4 2/2] drm/amdgpu: Read SMUIO GPU clock on GFX12.1 VF
Quoted 35 lines · Alex Deucher
Quoted 33 lines · Victor Zhao
[why]
GFX12.1 VF timestamp queries need a SMUIO Golden TSC sample, but direct SMUIO MMIO access is restricted on VF.[how]
Read the consecutive SMUIO Golden TSC upper and lower registers withamdgpu_mes_rreg64()on GFX12.1 VF. Swap the returned dwords to reconstruct the counter value.v4: use SMUIO Golden TSC for GFX12.1 VF timestamp queries
Signed-off-by Victor Zhao <[email protected]>--- drivers/gpu/drm/amd/amdgpu/gfx_v12_1.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+)drivers/gpu/drm/amd/amdgpu/gfx_v12_1.c +1
-0@@ -37,6 +37,7 @@#include "gc/gc_12_1_0_offset.h" #include "gc/gc_12_1_0_sh_mask.h" +#include "smuio/smuio_15_0_0_offset.h" #include "soc24_enum.h" #include "ivsrcid/gfx/irqsrcs_gfx_12_1_0.h" @@ -3168,10 +3169,35 @@ static int gfx_v12_1_wait_for_idle(struct amdgpu_ip_block *ip_block)return -ETIMEDOUT ; }
Quoted 15 lines
drivers/gpu/drm/amd/amdgpu/gfx_v12_1.c static int gfx_v12_1_wait_for_idle(struct amdgpu_ip_block *ip_block) · line 3184
Quoted 13 lines
drivers/gpu/drm/amd/amdgpu/gfx_v12_1.c +13
-0+static uint64_t gfx_v12_1_get_smuio_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; + + reg =SOC15_REG_OFFSET (SMUIO ,0 , regGOLDEN_TSC_COUNT_UPPER); +if (amdgpu_mes_rreg64 (adev, reg,0 , &clock))I don't see this function in the current tree. Are you missing a patch?
Nevermind. I see it now. Stupid gmail keeps blackholing mailing list emails.
Alex
Quoted 25 lines
Alex
Quoted 22 lines
drivers/gpu/drm/amd/amdgpu/gfx_v12_1.c +12
-1+ goto unlock_reset; + + clock = (clock <<32 ) | (clock >>32 ); + +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_smuio_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
RE: [PATCH v4 2/2] drm/amdgpu: Read SMUIO GPU clock on GFX12.1 VF
In reply to Victor ZhaoAMD General
Quoted 13 lines
-----Original Message-----
From: Victor Zhao <[email protected]>
Sent: Friday, October 16, 2026 5:52 AM
To: [email protected]; Lazar, Lijo <[email protected]>; Deucher, Alexander <[email protected]>
Cc: Ming, Davis <[email protected]>; Wan, Gavin <[email protected]>; Zhao, Victor <[email protected]>
Subject: [PATCH v4 2/2] drm/amdgpu: Read SMUIO GPU clock on GFX12.1 VF[why]
GFX12.1 VF timestamp queries need a SMUIO Golden TSC sample, but direct SMUIO MMIO access is restricted on VF.
Quoted 8 lines
[how]
Read the consecutive SMUIO Golden TSC upper and lower registers withamdgpu_mes_rreg64()on GFX12.1 VF. Swap the returned dwords to reconstruct the counter value.v4: use SMUIO Golden TSC for GFX12.1 VF timestamp queries
Signed-off-by Victor Zhao <[email protected]>
Series is:
Quoted 58 lines
--- 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@@ -37,6 +37,7 @@#include "gc/gc_12_1_0_offset.h" #include "gc/gc_12_1_0_sh_mask.h" +#include "smuio/smuio_15_0_0_offset.h" #include "soc24_enum.h" #include "ivsrcid/gfx/irqsrcs_gfx_12_1_0.h" @@ -3168,10 +3169,35 @@ static int gfx_v12_1_wait_for_idle(struct amdgpu_ip_block *ip_block)return -ETIMEDOUT ; } +static uint64_t gfx_v12_1_get_smuio_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; + + reg =SOC15_REG_OFFSET (SMUIO ,0 , regGOLDEN_TSC_COUNT_UPPER); +if (amdgpu_mes_rreg64 (adev, reg,0 , &clock)) + goto unlock_reset; + + clock = (clock <<32 ) | (clock >>32 ); + +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_smuio_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