Commit a434b94c authored by Yong Zhao's avatar Yong Zhao Committed by Alex Deucher

drm/amdkfd: Improve function get_sdma_rlc_reg_offset() (v2)

The SOC15_REG_OFFSET() macro needs to dereference adev->reg_offset[IP]
pointer, which is sometimes NULL when there are fewer than 8 sdma engines.
Avoid that by not initializing the array regardless.

v2: squash in warning fixes
Signed-off-by: default avatarYong Zhao <Yong.Zhao@amd.com>
Reviewed-by: default avatarFelix Kuehling <Felix.Kuehling@amd.com>
Signed-off-by: default avatarAlex Deucher <alexander.deucher@amd.com>
parent 1fc636c9
...@@ -71,32 +71,56 @@ static uint32_t get_sdma_rlc_reg_offset(struct amdgpu_device *adev, ...@@ -71,32 +71,56 @@ static uint32_t get_sdma_rlc_reg_offset(struct amdgpu_device *adev,
unsigned int engine_id, unsigned int engine_id,
unsigned int queue_id) unsigned int queue_id)
{ {
uint32_t sdma_engine_reg_base[8] = { uint32_t sdma_engine_reg_base = 0;
SOC15_REG_OFFSET(SDMA0, 0, uint32_t sdma_rlc_reg_offset;
mmSDMA0_RLC0_RB_CNTL) - mmSDMA0_RLC0_RB_CNTL,
SOC15_REG_OFFSET(SDMA1, 0, switch (engine_id) {
mmSDMA1_RLC0_RB_CNTL) - mmSDMA1_RLC0_RB_CNTL, default:
SOC15_REG_OFFSET(SDMA2, 0, dev_warn(adev->dev,
mmSDMA2_RLC0_RB_CNTL) - mmSDMA2_RLC0_RB_CNTL, "Invalid sdma engine id (%d), using engine id 0\n",
SOC15_REG_OFFSET(SDMA3, 0, engine_id);
mmSDMA3_RLC0_RB_CNTL) - mmSDMA3_RLC0_RB_CNTL, /* fall through */
SOC15_REG_OFFSET(SDMA4, 0, case 0:
mmSDMA4_RLC0_RB_CNTL) - mmSDMA4_RLC0_RB_CNTL, sdma_engine_reg_base = SOC15_REG_OFFSET(SDMA0, 0,
SOC15_REG_OFFSET(SDMA5, 0, mmSDMA0_RLC0_RB_CNTL) - mmSDMA0_RLC0_RB_CNTL;
mmSDMA5_RLC0_RB_CNTL) - mmSDMA5_RLC0_RB_CNTL, break;
SOC15_REG_OFFSET(SDMA6, 0, case 1:
mmSDMA6_RLC0_RB_CNTL) - mmSDMA6_RLC0_RB_CNTL, sdma_engine_reg_base = SOC15_REG_OFFSET(SDMA1, 0,
SOC15_REG_OFFSET(SDMA7, 0, mmSDMA1_RLC0_RB_CNTL) - mmSDMA1_RLC0_RB_CNTL;
mmSDMA7_RLC0_RB_CNTL) - mmSDMA7_RLC0_RB_CNTL break;
}; case 2:
sdma_engine_reg_base = SOC15_REG_OFFSET(SDMA2, 0,
uint32_t retval = sdma_engine_reg_base[engine_id] mmSDMA2_RLC0_RB_CNTL) - mmSDMA2_RLC0_RB_CNTL;
break;
case 3:
sdma_engine_reg_base = SOC15_REG_OFFSET(SDMA3, 0,
mmSDMA3_RLC0_RB_CNTL) - mmSDMA3_RLC0_RB_CNTL;
break;
case 4:
sdma_engine_reg_base = SOC15_REG_OFFSET(SDMA4, 0,
mmSDMA4_RLC0_RB_CNTL) - mmSDMA4_RLC0_RB_CNTL;
break;
case 5:
sdma_engine_reg_base = SOC15_REG_OFFSET(SDMA5, 0,
mmSDMA5_RLC0_RB_CNTL) - mmSDMA5_RLC0_RB_CNTL;
break;
case 6:
sdma_engine_reg_base = SOC15_REG_OFFSET(SDMA6, 0,
mmSDMA6_RLC0_RB_CNTL) - mmSDMA6_RLC0_RB_CNTL;
break;
case 7:
sdma_engine_reg_base = SOC15_REG_OFFSET(SDMA7, 0,
mmSDMA7_RLC0_RB_CNTL) - mmSDMA7_RLC0_RB_CNTL;
break;
}
sdma_rlc_reg_offset = sdma_engine_reg_base
+ queue_id * (mmSDMA0_RLC1_RB_CNTL - mmSDMA0_RLC0_RB_CNTL); + queue_id * (mmSDMA0_RLC1_RB_CNTL - mmSDMA0_RLC0_RB_CNTL);
pr_debug("RLC register offset for SDMA%d RLC%d: 0x%x\n", engine_id, pr_debug("RLC register offset for SDMA%d RLC%d: 0x%x\n", engine_id,
queue_id, retval); queue_id, sdma_rlc_reg_offset);
return retval; return sdma_rlc_reg_offset;
} }
static int kgd_hqd_sdma_load(struct kgd_dev *kgd, void *mqd, static int kgd_hqd_sdma_load(struct kgd_dev *kgd, void *mqd,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment