drm/amdgpu: add reset register dump function for gfx_v10_0
Subsystems (2)
PATCH 1/3 drm/amdgpu: add reset register dump function for gfx_v10_0
Implementation of register dump function when the AMD GPU resets
--- drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c | 55 +++++++++++++++++++++++- drivers/gpu/drm/amd/include/amd_shared.h | 2 + 2 files changed, 56 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +54 -1
@@ -7466,7 +7466,6 @@ static int gfx_v10_0_hw_init(void *handle) {int r;struct amdgpu_device *adev = (struct amdgpu_device *)handle; -if (!amdgpu_emu_mode)gfx_v10_0_init_golden_registers (adev);
@@ -7580,6 +7579,59 @@ static int gfx_v10_0_hw_fini(void *handle)return 0 ; } +static int gfx_v10_0_reset_reg_dumps (void *handle, +uint32_t (**dump)[2 ],uint32_t *n_regs,char ***r_names) +{ +struct amdgpu_device *adev = (struct amdgpu_device *)handle; +uint32_t i =0 ; + +#define N_REGS (17) +#define DUMP_REG (addr) do { \ + (*dump)[i][0] = (addr); \ + (*dump)[i++][1] = RREG32(addr); \ + } while (0) + +char *reg_names[N_REGS ] = { +"mmGRBM_STATUS2" ,"mmGRBM_STATUS_SE0" ,"mmGRBM_STATUS_SE1" , +"mmGRBM_STATUS_SE2" ,"mmGRBM_STATUS_SE3" ,"mmSDMA0_STATUS_REG" , +"mmSDMA1_STATUS_REG" ,"mmCP_STAT" ,"mmCP_STALLED_STAT1" , +"mmCP_STALLED_STAT1" ,"mmCP_STALLED_STAT3" ,"mmCP_CPC_STATUS" , +"mmCP_CPC_BUSY_STAT" ,"mmCP_CPC_STALLED_STAT1" ,"mmCP_CPF_STATUS" , +"mmCP_CPF_BUSY_STAT" ,"mmCP_CPF_STALLED_STAT1" + }; + + *dump =kmalloc (N_REGS *2 *sizeof (uint32_t ),GFP_KERNEL ); +if (*dump ==NULL ) +return -ENOMEM ; +DUMP_REG (mmGRBM_STATUS2); +DUMP_REG (mmGRBM_STATUS_SE0); +DUMP_REG (mmGRBM_STATUS_SE1); +DUMP_REG (mmGRBM_STATUS_SE2); +DUMP_REG (mmGRBM_STATUS_SE3); +DUMP_REG (mmSDMA0_STATUS_REG); +DUMP_REG (mmSDMA1_STATUS_REG); +DUMP_REG (mmCP_STAT); +DUMP_REG (mmCP_STALLED_STAT1); +DUMP_REG (mmCP_STALLED_STAT1); +DUMP_REG (mmCP_STALLED_STAT3); +DUMP_REG (mmCP_CPC_STATUS); +DUMP_REG (mmCP_CPC_BUSY_STAT); +DUMP_REG (mmCP_CPC_STALLED_STAT1); +DUMP_REG (mmCP_CPF_STATUS); +DUMP_REG (mmCP_CPF_BUSY_STAT); +DUMP_REG (mmCP_CPF_STALLED_STAT1); + + *n_regs = i; + + (*r_names) =kcalloc (N_REGS ,sizeof (char *),GFP_KERNEL ); +for (i =0 ; i <N_REGS ; i++) { + (*r_names)[i] =kcalloc (30 ,sizeof (char ),GFP_KERNEL ); +strcpy ((*r_names)[i], reg_names[i]); + } + +return 0 ; +} +static int gfx_v10_0_suspend (void *handle) {return gfx_v10_0_hw_fini (handle);
@@ -9359,6 +9411,7 @@ static const struct amd_ip_funcs gfx_v10_0_ip_funcs = { .set_clockgating_state = gfx_v10_0_set_clockgating_state, .set_powergating_state = gfx_v10_0_set_powergating_state, .get_clockgating_state = gfx_v10_0_get_clockgating_state, + .reset_reg_dumps = gfx_v10_0_reset_reg_dumps, };static const struct amdgpu_ring_funcs gfx_v10_0_ring_funcs_gfx = {
drivers/gpu/drm/amd/include/amd_shared.h +2 -0
@@ -298,6 +298,8 @@ struct amd_ip_funcs { enum amd_powergating_state state);void (*get_clockgating_state)(void *handle,u32 *flags);int (*enable_umd_pstate)(void *handle,enum amd_dpm_forced_level *level); +int (*reset_reg_dumps)(void *handle, +uint32_t (**dump)[2 ],uint32_t *n_regs,char ***r_names); };
Signature · 1 line
2.25.1
Am 11.01.22 um 08:11 schrieb Somalapuram Amaranath:
Quoted 25 lines
Implementation of register dump function when the AMD GPU resets
Signed-off-by Somalapuram Amaranath <[email protected]>--- drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c | 55 +++++++++++++++++++++++- drivers/gpu/drm/amd/include/amd_shared.h | 2 + 2 files changed, 56 insertions(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +1
-1@@ -7466,7 +7466,6 @@ static int gfx_v10_0_hw_init(void *handle) {int r;struct amdgpu_device *adev = (struct amdgpu_device *)handle; -if (!amdgpu_emu_mode)gfx_v10_0_init_golden_registers (adev);@@ -7580,6 +7579,59 @@ static int gfx_v10_0_hw_fini(void *handle)return 0 ; } +static int gfx_v10_0_reset_reg_dumps(void *handle,
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c static int gfx_v10_0_hw_fini(void *handle) · line 7592
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +10
-0+ uint32_t (**dump)[2], uint32_t *n_regs, char ***r_names) +{ + struct amdgpu_device *adev = (struct amdgpu_device *)handle; +uint32_t i =0 ; + +#define N_REGS (17) +#define DUMP_REG (addr) do { \ + (*dump)[i][0] = (addr); \ + (*dump)[i++][1] = RREG32(addr); \ + } while (0)
Please no unprefixed local defines like this.
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c static int gfx_v10_0_hw_fini(void *handle) · line 7601
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +9
-0+ +char *reg_names[N_REGS ] = { +"mmGRBM_STATUS2" ,"mmGRBM_STATUS_SE0" ,"mmGRBM_STATUS_SE1" , +"mmGRBM_STATUS_SE2" ,"mmGRBM_STATUS_SE3" ,"mmSDMA0_STATUS_REG" , +"mmSDMA1_STATUS_REG" ,"mmCP_STAT" ,"mmCP_STALLED_STAT1" , +"mmCP_STALLED_STAT1" ,"mmCP_STALLED_STAT3" ,"mmCP_CPC_STATUS" , +"mmCP_CPC_BUSY_STAT" ,"mmCP_CPC_STALLED_STAT1" ,"mmCP_CPF_STATUS" , +"mmCP_CPF_BUSY_STAT" ,"mmCP_CPF_STALLED_STAT1" + };
IIRC you can avoid that by stringifying the names in the macro, but in general I think the kernel should not have those names.
Only userspace needs to be able to match the register number to the name.
Regards,
Christian.
Quoted 58 lines
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +33
-0+ + *dump =kmalloc (N_REGS *2 *sizeof (uint32_t ),GFP_KERNEL ); +if (*dump ==NULL ) +return -ENOMEM ; +DUMP_REG (mmGRBM_STATUS2); +DUMP_REG (mmGRBM_STATUS_SE0); +DUMP_REG (mmGRBM_STATUS_SE1); +DUMP_REG (mmGRBM_STATUS_SE2); +DUMP_REG (mmGRBM_STATUS_SE3); +DUMP_REG (mmSDMA0_STATUS_REG); +DUMP_REG (mmSDMA1_STATUS_REG); +DUMP_REG (mmCP_STAT); +DUMP_REG (mmCP_STALLED_STAT1); +DUMP_REG (mmCP_STALLED_STAT1); +DUMP_REG (mmCP_STALLED_STAT3); +DUMP_REG (mmCP_CPC_STATUS); +DUMP_REG (mmCP_CPC_BUSY_STAT); +DUMP_REG (mmCP_CPC_STALLED_STAT1); +DUMP_REG (mmCP_CPF_STATUS); +DUMP_REG (mmCP_CPF_BUSY_STAT); +DUMP_REG (mmCP_CPF_STALLED_STAT1); + + *n_regs = i; + + (*r_names) =kcalloc (N_REGS ,sizeof (char *),GFP_KERNEL ); +for (i =0 ; i <N_REGS ; i++) { + (*r_names)[i] =kcalloc (30 ,sizeof (char ),GFP_KERNEL ); +strcpy ((*r_names)[i], reg_names[i]); + } + +return 0 ; +} +static int gfx_v10_0_suspend (void *handle) {return gfx_v10_0_hw_fini(handle);drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +1
-0@@ -9359,6 +9411,7 @@ static const struct amd_ip_funcs gfx_v10_0_ip_funcs = { .set_clockgating_state = gfx_v10_0_set_clockgating_state, .set_powergating_state = gfx_v10_0_set_powergating_state, .get_clockgating_state = gfx_v10_0_get_clockgating_state, + .reset_reg_dumps = gfx_v10_0_reset_reg_dumps, };static const struct amdgpu_ring_funcs gfx_v10_0_ring_funcs_gfx = {drivers/gpu/drm/amd/include/amd_shared.h +2
-0@@ -298,6 +298,8 @@ struct amd_ip_funcs { enum amd_powergating_state state);void (*get_clockgating_state)(void *handle,u32 *flags);int (*enable_umd_pstate)(void *handle,enum amd_dpm_forced_level *level); +int (*reset_reg_dumps)(void *handle, +uint32_t (**dump)[2 ],uint32_t *n_regs,char ***r_names); };
Quoted 25 lines · Somalapuram Amaranath
Implementation of register dump function when the AMD GPU resets
Signed-off-by Somalapuram Amaranath <[email protected]>--- drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c | 55 +++++++++++++++++++++++- drivers/gpu/drm/amd/include/amd_shared.h | 2 + 2 files changed, 56 insertions(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +0
-1@@ -7466,7 +7466,6 @@ static int gfx_v10_0_hw_init(void *handle) {int r;struct amdgpu_device *adev = (struct amdgpu_device *)handle; -if (!amdgpu_emu_mode)gfx_v10_0_init_golden_registers (adev);@@ -7580,6 +7579,59 @@ static int gfx_v10_0_hw_fini(void *handle)return 0 ; }
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c static int gfx_v10_0_hw_fini(void *handle) · line 7591
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +10
-0+static int gfx_v10_0_reset_reg_dumps (void *handle, +uint32_t (**dump)[2 ],uint32_t *n_regs,char ***r_names) +{ +struct amdgpu_device *adev = (struct amdgpu_device *)handle; +uint32_t i =0 ; + +#define N_REGS (17) +#define DUMP_REG (addr) do { \ + (*dump)[i][0] = (addr); \ + (*dump)[i++][1] = RREG32(addr); \
For soc15 and newer asics (e.g., vega and newer), we need to use the RREG_SOC15 macros rather than the regular RREG macros.
Alex
Quoted 70 lines
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +44
-0+ }while (0 ) + + char *reg_names[N_REGS] = { +"mmGRBM_STATUS2" ,"mmGRBM_STATUS_SE0" ,"mmGRBM_STATUS_SE1" , +"mmGRBM_STATUS_SE2" ,"mmGRBM_STATUS_SE3" ,"mmSDMA0_STATUS_REG" , +"mmSDMA1_STATUS_REG" ,"mmCP_STAT" ,"mmCP_STALLED_STAT1" , +"mmCP_STALLED_STAT1" ,"mmCP_STALLED_STAT3" ,"mmCP_CPC_STATUS" , +"mmCP_CPC_BUSY_STAT" ,"mmCP_CPC_STALLED_STAT1" ,"mmCP_CPF_STATUS" , +"mmCP_CPF_BUSY_STAT" ,"mmCP_CPF_STALLED_STAT1" + }; + + *dump =kmalloc (N_REGS *2 *sizeof (uint32_t ),GFP_KERNEL ); +if (*dump ==NULL ) +return -ENOMEM ; +DUMP_REG (mmGRBM_STATUS2); +DUMP_REG (mmGRBM_STATUS_SE0); +DUMP_REG (mmGRBM_STATUS_SE1); +DUMP_REG (mmGRBM_STATUS_SE2); +DUMP_REG (mmGRBM_STATUS_SE3); +DUMP_REG (mmSDMA0_STATUS_REG); +DUMP_REG (mmSDMA1_STATUS_REG); +DUMP_REG (mmCP_STAT); +DUMP_REG (mmCP_STALLED_STAT1); +DUMP_REG (mmCP_STALLED_STAT1); +DUMP_REG (mmCP_STALLED_STAT3); +DUMP_REG (mmCP_CPC_STATUS); +DUMP_REG (mmCP_CPC_BUSY_STAT); +DUMP_REG (mmCP_CPC_STALLED_STAT1); +DUMP_REG (mmCP_CPF_STATUS); +DUMP_REG (mmCP_CPF_BUSY_STAT); +DUMP_REG (mmCP_CPF_STALLED_STAT1); + + *n_regs = i; + + (*r_names) =kcalloc (N_REGS ,sizeof (char *),GFP_KERNEL ); +for (i =0 ; i <N_REGS ; i++) { + (*r_names)[i] =kcalloc (30 ,sizeof (char ),GFP_KERNEL ); +strcpy ((*r_names)[i], reg_names[i]); + } + +return 0 ; +} +static int gfx_v10_0_suspend (void *handle) {return gfx_v10_0_hw_fini (handle);@@ -9359,6 +9411,7 @@ static const struct amd_ip_funcs gfx_v10_0_ip_funcs = { .set_clockgating_state = gfx_v10_0_set_clockgating_state, .set_powergating_state = gfx_v10_0_set_powergating_state, .get_clockgating_state = gfx_v10_0_get_clockgating_state, + .reset_reg_dumps = gfx_v10_0_reset_reg_dumps, };static const struct amdgpu_ring_funcs gfx_v10_0_ring_funcs_gfx = {drivers/gpu/drm/amd/include/amd_shared.h +2
-1@@ -298,6 +298,8 @@ struct amd_ip_funcs { enum amd_powergating_state state);void (*get_clockgating_state)(void *handle,u32 *flags);int (*enable_umd_pstate)(void *handle,enum amd_dpm_forced_level *level); +int (*reset_reg_dumps)(void *handle, +uint32_t (**dump)[2 ],uint32_t *n_regs,char ***r_names); }; --2.25.1