aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorErnst Sjöstrand <ernstp@gmail.com>2017-11-19 12:52:46 -0500
committerAlex Deucher <alexander.deucher@amd.com>2017-12-06 12:48:00 -0500
commit8cdbad98c52380bde20ea5753533640d2cdcc005 (patch)
treecb4b476b41cf3ecc48a092ba78ced093fe692a9b
parent47e8788b4924b0e3348caf4ad08de5a162bfc4cd (diff)
drm/amd/powerplay: Followup fixes to mc_reg_address
This is a followup to: drm/amd/powerplay: Fix buffer overflows with mc_reg_address Rework *_set_mc_special_registers for the other architectures to use the same logic as the first patch. This allows the last entry of the array to be filled without an error message for example. This doesn't fix any known problems, perhaps avoided by luck. Reviewed-by: Alex Deucher <alexander.deucher@amd.com> Signed-off-by: Ernst Sjöstrand <ernstp@gmail.com> Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
-rw-r--r--drivers/gpu/drm/amd/amdgpu/si_dpm.c10
-rw-r--r--drivers/gpu/drm/amd/powerplay/smumgr/ci_smumgr.c12
-rw-r--r--drivers/gpu/drm/amd/powerplay/smumgr/iceland_smumgr.c12
3 files changed, 11 insertions, 23 deletions
diff --git a/drivers/gpu/drm/amd/amdgpu/si_dpm.c b/drivers/gpu/drm/amd/amdgpu/si_dpm.c
index 51fd0c9a20a5..299cb3161b2c 100644
--- a/drivers/gpu/drm/amd/amdgpu/si_dpm.c
+++ b/drivers/gpu/drm/amd/amdgpu/si_dpm.c
@@ -5845,9 +5845,9 @@ static int si_set_mc_special_registers(struct amdgpu_device *adev,
5845 ((temp_reg & 0xffff0000)) | 5845 ((temp_reg & 0xffff0000)) |
5846 ((table->mc_reg_table_entry[k].mc_data[i] & 0xffff0000) >> 16); 5846 ((table->mc_reg_table_entry[k].mc_data[i] & 0xffff0000) >> 16);
5847 j++; 5847 j++;
5848
5848 if (j >= SMC_SISLANDS_MC_REGISTER_ARRAY_SIZE) 5849 if (j >= SMC_SISLANDS_MC_REGISTER_ARRAY_SIZE)
5849 return -EINVAL; 5850 return -EINVAL;
5850
5851 temp_reg = RREG32(MC_PMG_CMD_MRS); 5851 temp_reg = RREG32(MC_PMG_CMD_MRS);
5852 table->mc_reg_address[j].s1 = MC_PMG_CMD_MRS; 5852 table->mc_reg_address[j].s1 = MC_PMG_CMD_MRS;
5853 table->mc_reg_address[j].s0 = MC_SEQ_PMG_CMD_MRS_LP; 5853 table->mc_reg_address[j].s0 = MC_SEQ_PMG_CMD_MRS_LP;
@@ -5859,18 +5859,16 @@ static int si_set_mc_special_registers(struct amdgpu_device *adev,
5859 table->mc_reg_table_entry[k].mc_data[j] |= 0x100; 5859 table->mc_reg_table_entry[k].mc_data[j] |= 0x100;
5860 } 5860 }
5861 j++; 5861 j++;
5862 if (j >= SMC_SISLANDS_MC_REGISTER_ARRAY_SIZE)
5863 return -EINVAL;
5864 5862
5865 if (adev->mc.vram_type != AMDGPU_VRAM_TYPE_GDDR5) { 5863 if (adev->mc.vram_type != AMDGPU_VRAM_TYPE_GDDR5) {
5864 if (j >= SMC_SISLANDS_MC_REGISTER_ARRAY_SIZE)
5865 return -EINVAL;
5866 table->mc_reg_address[j].s1 = MC_PMG_AUTO_CMD; 5866 table->mc_reg_address[j].s1 = MC_PMG_AUTO_CMD;
5867 table->mc_reg_address[j].s0 = MC_PMG_AUTO_CMD; 5867 table->mc_reg_address[j].s0 = MC_PMG_AUTO_CMD;
5868 for (k = 0; k < table->num_entries; k++) 5868 for (k = 0; k < table->num_entries; k++)
5869 table->mc_reg_table_entry[k].mc_data[j] = 5869 table->mc_reg_table_entry[k].mc_data[j] =
5870 (table->mc_reg_table_entry[k].mc_data[i] & 0xffff0000) >> 16; 5870 (table->mc_reg_table_entry[k].mc_data[i] & 0xffff0000) >> 16;
5871 j++; 5871 j++;
5872 if (j >= SMC_SISLANDS_MC_REGISTER_ARRAY_SIZE)
5873 return -EINVAL;
5874 } 5872 }
5875 break; 5873 break;
5876 case MC_SEQ_RESERVE_M: 5874 case MC_SEQ_RESERVE_M:
@@ -5882,8 +5880,6 @@ static int si_set_mc_special_registers(struct amdgpu_device *adev,
5882 (temp_reg & 0xffff0000) | 5880 (temp_reg & 0xffff0000) |
5883 (table->mc_reg_table_entry[k].mc_data[i] & 0x0000ffff); 5881 (table->mc_reg_table_entry[k].mc_data[i] & 0x0000ffff);
5884 j++; 5882 j++;
5885 if (j >= SMC_SISLANDS_MC_REGISTER_ARRAY_SIZE)
5886 return -EINVAL;
5887 break; 5883 break;
5888 default: 5884 default:
5889 break; 5885 break;
diff --git a/drivers/gpu/drm/amd/powerplay/smumgr/ci_smumgr.c b/drivers/gpu/drm/amd/powerplay/smumgr/ci_smumgr.c
index ed4b37e566a3..c36f00ef46f3 100644
--- a/drivers/gpu/drm/amd/powerplay/smumgr/ci_smumgr.c
+++ b/drivers/gpu/drm/amd/powerplay/smumgr/ci_smumgr.c
@@ -2600,9 +2600,9 @@ static int ci_set_mc_special_registers(struct pp_hwmgr *hwmgr,
2600 ((table->mc_reg_table_entry[k].mc_data[i] & 0xffff0000) >> 16); 2600 ((table->mc_reg_table_entry[k].mc_data[i] & 0xffff0000) >> 16);
2601 } 2601 }
2602 j++; 2602 j++;
2603
2603 PP_ASSERT_WITH_CODE((j < SMU7_DISCRETE_MC_REGISTER_ARRAY_SIZE), 2604 PP_ASSERT_WITH_CODE((j < SMU7_DISCRETE_MC_REGISTER_ARRAY_SIZE),
2604 "Invalid VramInfo table.", return -EINVAL); 2605 "Invalid VramInfo table.", return -EINVAL);
2605
2606 temp_reg = cgs_read_register(hwmgr->device, mmMC_PMG_CMD_MRS); 2606 temp_reg = cgs_read_register(hwmgr->device, mmMC_PMG_CMD_MRS);
2607 table->mc_reg_address[j].s1 = mmMC_PMG_CMD_MRS; 2607 table->mc_reg_address[j].s1 = mmMC_PMG_CMD_MRS;
2608 table->mc_reg_address[j].s0 = mmMC_SEQ_PMG_CMD_MRS_LP; 2608 table->mc_reg_address[j].s0 = mmMC_SEQ_PMG_CMD_MRS_LP;
@@ -2615,10 +2615,10 @@ static int ci_set_mc_special_registers(struct pp_hwmgr *hwmgr,
2615 table->mc_reg_table_entry[k].mc_data[j] |= 0x100; 2615 table->mc_reg_table_entry[k].mc_data[j] |= 0x100;
2616 } 2616 }
2617 j++; 2617 j++;
2618 PP_ASSERT_WITH_CODE((j <= SMU7_DISCRETE_MC_REGISTER_ARRAY_SIZE),
2619 "Invalid VramInfo table.", return -EINVAL);
2620 2618
2621 if (!data->is_memory_gddr5 && j < SMU7_DISCRETE_MC_REGISTER_ARRAY_SIZE) { 2619 if (!data->is_memory_gddr5) {
2620 PP_ASSERT_WITH_CODE((j < SMU7_DISCRETE_MC_REGISTER_ARRAY_SIZE),
2621 "Invalid VramInfo table.", return -EINVAL);
2622 table->mc_reg_address[j].s1 = mmMC_PMG_AUTO_CMD; 2622 table->mc_reg_address[j].s1 = mmMC_PMG_AUTO_CMD;
2623 table->mc_reg_address[j].s0 = mmMC_PMG_AUTO_CMD; 2623 table->mc_reg_address[j].s0 = mmMC_PMG_AUTO_CMD;
2624 for (k = 0; k < table->num_entries; k++) { 2624 for (k = 0; k < table->num_entries; k++) {
@@ -2626,8 +2626,6 @@ static int ci_set_mc_special_registers(struct pp_hwmgr *hwmgr,
2626 (table->mc_reg_table_entry[k].mc_data[i] & 0xffff0000) >> 16; 2626 (table->mc_reg_table_entry[k].mc_data[i] & 0xffff0000) >> 16;
2627 } 2627 }
2628 j++; 2628 j++;
2629 PP_ASSERT_WITH_CODE((j <= SMU7_DISCRETE_MC_REGISTER_ARRAY_SIZE),
2630 "Invalid VramInfo table.", return -EINVAL);
2631 } 2629 }
2632 2630
2633 break; 2631 break;
@@ -2642,8 +2640,6 @@ static int ci_set_mc_special_registers(struct pp_hwmgr *hwmgr,
2642 (table->mc_reg_table_entry[k].mc_data[i] & 0x0000ffff); 2640 (table->mc_reg_table_entry[k].mc_data[i] & 0x0000ffff);
2643 } 2641 }
2644 j++; 2642 j++;
2645 PP_ASSERT_WITH_CODE((j <= SMU7_DISCRETE_MC_REGISTER_ARRAY_SIZE),
2646 "Invalid VramInfo table.", return -EINVAL);
2647 break; 2643 break;
2648 2644
2649 default: 2645 default:
diff --git a/drivers/gpu/drm/amd/powerplay/smumgr/iceland_smumgr.c b/drivers/gpu/drm/amd/powerplay/smumgr/iceland_smumgr.c
index 2ff682d44e8c..d62078681cae 100644
--- a/drivers/gpu/drm/amd/powerplay/smumgr/iceland_smumgr.c
+++ b/drivers/gpu/drm/amd/powerplay/smumgr/iceland_smumgr.c
@@ -2549,9 +2549,9 @@ static int iceland_set_mc_special_registers(struct pp_hwmgr *hwmgr,
2549 ((table->mc_reg_table_entry[k].mc_data[i] & 0xffff0000) >> 16); 2549 ((table->mc_reg_table_entry[k].mc_data[i] & 0xffff0000) >> 16);
2550 } 2550 }
2551 j++; 2551 j++;
2552
2552 PP_ASSERT_WITH_CODE((j < SMU71_DISCRETE_MC_REGISTER_ARRAY_SIZE), 2553 PP_ASSERT_WITH_CODE((j < SMU71_DISCRETE_MC_REGISTER_ARRAY_SIZE),
2553 "Invalid VramInfo table.", return -EINVAL); 2554 "Invalid VramInfo table.", return -EINVAL);
2554
2555 temp_reg = cgs_read_register(hwmgr->device, mmMC_PMG_CMD_MRS); 2555 temp_reg = cgs_read_register(hwmgr->device, mmMC_PMG_CMD_MRS);
2556 table->mc_reg_address[j].s1 = mmMC_PMG_CMD_MRS; 2556 table->mc_reg_address[j].s1 = mmMC_PMG_CMD_MRS;
2557 table->mc_reg_address[j].s0 = mmMC_SEQ_PMG_CMD_MRS_LP; 2557 table->mc_reg_address[j].s0 = mmMC_SEQ_PMG_CMD_MRS_LP;
@@ -2565,10 +2565,10 @@ static int iceland_set_mc_special_registers(struct pp_hwmgr *hwmgr,
2565 } 2565 }
2566 } 2566 }
2567 j++; 2567 j++;
2568 PP_ASSERT_WITH_CODE((j <= SMU71_DISCRETE_MC_REGISTER_ARRAY_SIZE),
2569 "Invalid VramInfo table.", return -EINVAL);
2570 2568
2571 if (!data->is_memory_gddr5 && j < SMU71_DISCRETE_MC_REGISTER_ARRAY_SIZE) { 2569 if (!data->is_memory_gddr5) {
2570 PP_ASSERT_WITH_CODE((j < SMU71_DISCRETE_MC_REGISTER_ARRAY_SIZE),
2571 "Invalid VramInfo table.", return -EINVAL);
2572 table->mc_reg_address[j].s1 = mmMC_PMG_AUTO_CMD; 2572 table->mc_reg_address[j].s1 = mmMC_PMG_AUTO_CMD;
2573 table->mc_reg_address[j].s0 = mmMC_PMG_AUTO_CMD; 2573 table->mc_reg_address[j].s0 = mmMC_PMG_AUTO_CMD;
2574 for (k = 0; k < table->num_entries; k++) { 2574 for (k = 0; k < table->num_entries; k++) {
@@ -2576,8 +2576,6 @@ static int iceland_set_mc_special_registers(struct pp_hwmgr *hwmgr,
2576 (table->mc_reg_table_entry[k].mc_data[i] & 0xffff0000) >> 16; 2576 (table->mc_reg_table_entry[k].mc_data[i] & 0xffff0000) >> 16;
2577 } 2577 }
2578 j++; 2578 j++;
2579 PP_ASSERT_WITH_CODE((j <= SMU71_DISCRETE_MC_REGISTER_ARRAY_SIZE),
2580 "Invalid VramInfo table.", return -EINVAL);
2581 } 2579 }
2582 2580
2583 break; 2581 break;
@@ -2592,8 +2590,6 @@ static int iceland_set_mc_special_registers(struct pp_hwmgr *hwmgr,
2592 (table->mc_reg_table_entry[k].mc_data[i] & 0x0000ffff); 2590 (table->mc_reg_table_entry[k].mc_data[i] & 0x0000ffff);
2593 } 2591 }
2594 j++; 2592 j++;
2595 PP_ASSERT_WITH_CODE((j <= SMU71_DISCRETE_MC_REGISTER_ARRAY_SIZE),
2596 "Invalid VramInfo table.", return -EINVAL);
2597 break; 2593 break;
2598 2594
2599 default: 2595 default: