aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpu
diff options
context:
space:
mode:
authorRex Zhu <Rex.Zhu@amd.com>2016-08-25 08:25:40 -0400
committerAlex Deucher <alexander.deucher@amd.com>2016-09-19 13:22:15 -0400
commit5746f90c56ebc9aeca10ee0296f1bc426a4bb2e1 (patch)
tree3cba901fe5bea224197e6ca1748e29b86b7167bb /drivers/gpu
parentd01ec3fb8c9bff2f82db075027f56b3390a3c77e (diff)
drm/amd/powerplay: use smu7 common functions and data on Fiji.
Signed-off-by: Rex Zhu <Rex.Zhu@amd.com> Reviewed-by: Alex Deucher <alexander.deucher@amd.com> Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
Diffstat (limited to 'drivers/gpu')
-rw-r--r--drivers/gpu/drm/amd/powerplay/smumgr/fiji_smc.c69
-rw-r--r--drivers/gpu/drm/amd/powerplay/smumgr/fiji_smumgr.c605
-rw-r--r--drivers/gpu/drm/amd/powerplay/smumgr/fiji_smumgr.h29
3 files changed, 68 insertions, 635 deletions
diff --git a/drivers/gpu/drm/amd/powerplay/smumgr/fiji_smc.c b/drivers/gpu/drm/amd/powerplay/smumgr/fiji_smc.c
index fd0c00173cce..76310ac7ef0d 100644
--- a/drivers/gpu/drm/amd/powerplay/smumgr/fiji_smc.c
+++ b/drivers/gpu/drm/amd/powerplay/smumgr/fiji_smc.c
@@ -42,6 +42,7 @@
42#include "bif/bif_5_0_sh_mask.h" 42#include "bif/bif_5_0_sh_mask.h"
43#include "dce/dce_10_0_d.h" 43#include "dce/dce_10_0_d.h"
44#include "dce/dce_10_0_sh_mask.h" 44#include "dce/dce_10_0_sh_mask.h"
45#include "smu7_smumgr.h"
45 46
46#define VOLTAGE_SCALE 4 47#define VOLTAGE_SCALE 4
47#define POWERTUNE_DEFAULT_SET_MAX 1 48#define POWERTUNE_DEFAULT_SET_MAX 1
@@ -337,7 +338,7 @@ static int fiji_populate_dw8(struct pp_hwmgr *hwmgr, uint32_t fuse_table_offset)
337 const struct fiji_pt_defaults *defaults = smu_data->power_tune_defaults; 338 const struct fiji_pt_defaults *defaults = smu_data->power_tune_defaults;
338 uint32_t temp; 339 uint32_t temp;
339 340
340 if (fiji_read_smc_sram_dword(hwmgr->smumgr, 341 if (smu7_read_smc_sram_dword(hwmgr->smumgr,
341 fuse_table_offset + 342 fuse_table_offset +
342 offsetof(SMU73_Discrete_PmFuses, TdcWaterfallCtl), 343 offsetof(SMU73_Discrete_PmFuses, TdcWaterfallCtl),
343 (uint32_t *)&temp, SMC_RAM_END)) 344 (uint32_t *)&temp, SMC_RAM_END))
@@ -429,7 +430,7 @@ static int fiji_populate_pm_fuses(struct pp_hwmgr *hwmgr)
429 430
430 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, 431 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
431 PHM_PlatformCaps_PowerContainment)) { 432 PHM_PlatformCaps_PowerContainment)) {
432 if (fiji_read_smc_sram_dword(hwmgr->smumgr, 433 if (smu7_read_smc_sram_dword(hwmgr->smumgr,
433 SMU7_FIRMWARE_HEADER_LOCATION + 434 SMU7_FIRMWARE_HEADER_LOCATION +
434 offsetof(SMU73_Firmware_Header, PmFuseTable), 435 offsetof(SMU73_Firmware_Header, PmFuseTable),
435 &pm_fuse_table_offset, SMC_RAM_END)) 436 &pm_fuse_table_offset, SMC_RAM_END))
@@ -483,7 +484,7 @@ static int fiji_populate_pm_fuses(struct pp_hwmgr *hwmgr)
483 "Attempt to populate BapmVddCBaseLeakage Hi and Lo " 484 "Attempt to populate BapmVddCBaseLeakage Hi and Lo "
484 "Sidd Failed!", return -EINVAL); 485 "Sidd Failed!", return -EINVAL);
485 486
486 if (fiji_copy_bytes_to_smc(hwmgr->smumgr, pm_fuse_table_offset, 487 if (smu7_copy_bytes_to_smc(hwmgr->smumgr, pm_fuse_table_offset,
487 (uint8_t *)&smu_data->power_tune_table, 488 (uint8_t *)&smu_data->power_tune_table,
488 sizeof(struct SMU73_Discrete_PmFuses), SMC_RAM_END)) 489 sizeof(struct SMU73_Discrete_PmFuses), SMC_RAM_END))
489 PP_ASSERT_WITH_CODE(false, 490 PP_ASSERT_WITH_CODE(false,
@@ -781,7 +782,7 @@ int fiji_populate_all_graphic_levels(struct pp_hwmgr *hwmgr)
781 struct phm_ppt_v1_pcie_table *pcie_table = table_info->pcie_table; 782 struct phm_ppt_v1_pcie_table *pcie_table = table_info->pcie_table;
782 uint8_t pcie_entry_cnt = (uint8_t) data->dpm_table.pcie_speed_table.count; 783 uint8_t pcie_entry_cnt = (uint8_t) data->dpm_table.pcie_speed_table.count;
783 int result = 0; 784 int result = 0;
784 uint32_t array = smu_data->dpm_table_start + 785 uint32_t array = smu_data->smu7_data.dpm_table_start +
785 offsetof(SMU73_Discrete_DpmTable, GraphicsLevel); 786 offsetof(SMU73_Discrete_DpmTable, GraphicsLevel);
786 uint32_t array_size = sizeof(struct SMU73_Discrete_GraphicsLevel) * 787 uint32_t array_size = sizeof(struct SMU73_Discrete_GraphicsLevel) *
787 SMU73_MAX_LEVELS_GRAPHICS; 788 SMU73_MAX_LEVELS_GRAPHICS;
@@ -858,7 +859,7 @@ int fiji_populate_all_graphic_levels(struct pp_hwmgr *hwmgr)
858 levels[1].pcieDpmLevel = mid_pcie_level_enabled; 859 levels[1].pcieDpmLevel = mid_pcie_level_enabled;
859 } 860 }
860 /* level count will send to smc once at init smc table and never change */ 861 /* level count will send to smc once at init smc table and never change */
861 result = fiji_copy_bytes_to_smc(hwmgr->smumgr, array, (uint8_t *)levels, 862 result = smu7_copy_bytes_to_smc(hwmgr->smumgr, array, (uint8_t *)levels,
862 (uint32_t)array_size, SMC_RAM_END); 863 (uint32_t)array_size, SMC_RAM_END);
863 864
864 return result; 865 return result;
@@ -1003,7 +1004,7 @@ int fiji_populate_all_memory_levels(struct pp_hwmgr *hwmgr)
1003 struct smu7_dpm_table *dpm_table = &data->dpm_table; 1004 struct smu7_dpm_table *dpm_table = &data->dpm_table;
1004 int result; 1005 int result;
1005 /* populate MCLK dpm table to SMU7 */ 1006 /* populate MCLK dpm table to SMU7 */
1006 uint32_t array = smu_data->dpm_table_start + 1007 uint32_t array = smu_data->smu7_data.dpm_table_start +
1007 offsetof(SMU73_Discrete_DpmTable, MemoryLevel); 1008 offsetof(SMU73_Discrete_DpmTable, MemoryLevel);
1008 uint32_t array_size = sizeof(SMU73_Discrete_MemoryLevel) * 1009 uint32_t array_size = sizeof(SMU73_Discrete_MemoryLevel) *
1009 SMU73_MAX_LEVELS_MEMORY; 1010 SMU73_MAX_LEVELS_MEMORY;
@@ -1042,7 +1043,7 @@ int fiji_populate_all_memory_levels(struct pp_hwmgr *hwmgr)
1042 PPSMC_DISPLAY_WATERMARK_HIGH; 1043 PPSMC_DISPLAY_WATERMARK_HIGH;
1043 1044
1044 /* level count will send to smc once at init smc table and never change */ 1045 /* level count will send to smc once at init smc table and never change */
1045 result = fiji_copy_bytes_to_smc(hwmgr->smumgr, array, (uint8_t *)levels, 1046 result = smu7_copy_bytes_to_smc(hwmgr->smumgr, array, (uint8_t *)levels,
1046 (uint32_t)array_size, SMC_RAM_END); 1047 (uint32_t)array_size, SMC_RAM_END);
1047 1048
1048 return result; 1049 return result;
@@ -1368,9 +1369,9 @@ static int fiji_program_memory_timing_parameters(struct pp_hwmgr *hwmgr)
1368 } 1369 }
1369 1370
1370 if (!result) 1371 if (!result)
1371 result = fiji_copy_bytes_to_smc( 1372 result = smu7_copy_bytes_to_smc(
1372 hwmgr->smumgr, 1373 hwmgr->smumgr,
1373 smu_data->arb_table_start, 1374 smu_data->smu7_data.arb_table_start,
1374 (uint8_t *)&arb_regs, 1375 (uint8_t *)&arb_regs,
1375 sizeof(SMU73_Discrete_MCArbDramTimingTable), 1376 sizeof(SMU73_Discrete_MCArbDramTimingTable),
1376 SMC_RAM_END); 1377 SMC_RAM_END);
@@ -1707,8 +1708,8 @@ static int fiji_init_arb_table_index(struct pp_smumgr *smumgr)
1707 * In reality this field should not be in that structure 1708 * In reality this field should not be in that structure
1708 * but in a soft register. 1709 * but in a soft register.
1709 */ 1710 */
1710 result = fiji_read_smc_sram_dword(smumgr, 1711 result = smu7_read_smc_sram_dword(smumgr,
1711 smu_data->arb_table_start, &tmp, SMC_RAM_END); 1712 smu_data->smu7_data.arb_table_start, &tmp, SMC_RAM_END);
1712 1713
1713 if (result) 1714 if (result)
1714 return result; 1715 return result;
@@ -1716,8 +1717,8 @@ static int fiji_init_arb_table_index(struct pp_smumgr *smumgr)
1716 tmp &= 0x00FFFFFF; 1717 tmp &= 0x00FFFFFF;
1717 tmp |= ((uint32_t)MC_CG_ARB_FREQ_F1) << 24; 1718 tmp |= ((uint32_t)MC_CG_ARB_FREQ_F1) << 24;
1718 1719
1719 return fiji_write_smc_sram_dword(smumgr, 1720 return smu7_write_smc_sram_dword(smumgr,
1720 smu_data->arb_table_start, tmp, SMC_RAM_END); 1721 smu_data->smu7_data.arb_table_start, tmp, SMC_RAM_END);
1721} 1722}
1722 1723
1723/** 1724/**
@@ -1917,8 +1918,8 @@ int fiji_init_smc_table(struct pp_hwmgr *hwmgr)
1917 CONVERT_FROM_HOST_TO_SMC_US(table->PhaseResponseTime); 1918 CONVERT_FROM_HOST_TO_SMC_US(table->PhaseResponseTime);
1918 1919
1919 /* Upload all dpm data to SMC memory.(dpm level, dpm level count etc) */ 1920 /* Upload all dpm data to SMC memory.(dpm level, dpm level count etc) */
1920 result = fiji_copy_bytes_to_smc(hwmgr->smumgr, 1921 result = smu7_copy_bytes_to_smc(hwmgr->smumgr,
1921 smu_data->dpm_table_start + 1922 smu_data->smu7_data.dpm_table_start +
1922 offsetof(SMU73_Discrete_DpmTable, SystemFlags), 1923 offsetof(SMU73_Discrete_DpmTable, SystemFlags),
1923 (uint8_t *)&(table->SystemFlags), 1924 (uint8_t *)&(table->SystemFlags),
1924 sizeof(SMU73_Discrete_DpmTable) - 3 * sizeof(SMU73_PIDController), 1925 sizeof(SMU73_Discrete_DpmTable) - 3 * sizeof(SMU73_PIDController),
@@ -1957,7 +1958,7 @@ int fiji_thermal_setup_fan_table(struct pp_hwmgr *hwmgr)
1957 int res; 1958 int res;
1958 uint64_t tmp64; 1959 uint64_t tmp64;
1959 1960
1960 if (smu_data->fan_table_start == 0) { 1961 if (smu_data->smu7_data.fan_table_start == 0) {
1961 phm_cap_unset(hwmgr->platform_descriptor.platformCaps, 1962 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
1962 PHM_PlatformCaps_MicrocodeFanControl); 1963 PHM_PlatformCaps_MicrocodeFanControl);
1963 return 0; 1964 return 0;
@@ -2023,7 +2024,7 @@ int fiji_thermal_setup_fan_table(struct pp_hwmgr *hwmgr)
2023 hwmgr->device, CGS_IND_REG__SMC, 2024 hwmgr->device, CGS_IND_REG__SMC,
2024 CG_MULT_THERMAL_CTRL, TEMP_SEL); 2025 CG_MULT_THERMAL_CTRL, TEMP_SEL);
2025 2026
2026 res = fiji_copy_bytes_to_smc(hwmgr->smumgr, smu_data->fan_table_start, 2027 res = smu7_copy_bytes_to_smc(hwmgr->smumgr, smu_data->smu7_data.fan_table_start,
2027 (uint8_t *)&fan_table, (uint32_t)sizeof(fan_table), 2028 (uint8_t *)&fan_table, (uint32_t)sizeof(fan_table),
2028 SMC_RAM_END); 2029 SMC_RAM_END);
2029 2030
@@ -2078,9 +2079,9 @@ int fiji_update_sclk_threshold(struct pp_hwmgr *hwmgr)
2078 2079
2079 CONVERT_FROM_HOST_TO_SMC_UL(low_sclk_interrupt_threshold); 2080 CONVERT_FROM_HOST_TO_SMC_UL(low_sclk_interrupt_threshold);
2080 2081
2081 result = fiji_copy_bytes_to_smc( 2082 result = smu7_copy_bytes_to_smc(
2082 hwmgr->smumgr, 2083 hwmgr->smumgr,
2083 smu_data->dpm_table_start + 2084 smu_data->smu7_data.dpm_table_start +
2084 offsetof(SMU73_Discrete_DpmTable, 2085 offsetof(SMU73_Discrete_DpmTable,
2085 LowSclkInterruptThreshold), 2086 LowSclkInterruptThreshold),
2086 (uint8_t *)&low_sclk_interrupt_threshold, 2087 (uint8_t *)&low_sclk_interrupt_threshold,
@@ -2109,6 +2110,8 @@ uint32_t fiji_get_offsetof(uint32_t type, uint32_t member)
2109 return offsetof(SMU73_SoftRegisters, PreVBlankGap); 2110 return offsetof(SMU73_SoftRegisters, PreVBlankGap);
2110 case VBlankTimeout: 2111 case VBlankTimeout:
2111 return offsetof(SMU73_SoftRegisters, VBlankTimeout); 2112 return offsetof(SMU73_SoftRegisters, VBlankTimeout);
2113 case UcodeLoadStatus:
2114 return offsetof(SMU73_SoftRegisters, UcodeLoadStatus);
2112 } 2115 }
2113 case SMU_Discrete_DpmTable: 2116 case SMU_Discrete_DpmTable:
2114 switch (member) { 2117 switch (member) {
@@ -2163,7 +2166,7 @@ static int fiji_update_uvd_smc_table(struct pp_hwmgr *hwmgr)
2163 if (table_info->mm_dep_table->count > 0) 2166 if (table_info->mm_dep_table->count > 0)
2164 smu_data->smc_state_table.UvdBootLevel = 2167 smu_data->smc_state_table.UvdBootLevel =
2165 (uint8_t) (table_info->mm_dep_table->count - 1); 2168 (uint8_t) (table_info->mm_dep_table->count - 1);
2166 mm_boot_level_offset = smu_data->dpm_table_start + offsetof(SMU73_Discrete_DpmTable, 2169 mm_boot_level_offset = smu_data->smu7_data.dpm_table_start + offsetof(SMU73_Discrete_DpmTable,
2167 UvdBootLevel); 2170 UvdBootLevel);
2168 mm_boot_level_offset /= 4; 2171 mm_boot_level_offset /= 4;
2169 mm_boot_level_offset *= 4; 2172 mm_boot_level_offset *= 4;
@@ -2198,7 +2201,7 @@ static int fiji_update_vce_smc_table(struct pp_hwmgr *hwmgr)
2198 else 2201 else
2199 smu_data->smc_state_table.VceBootLevel = 0; 2202 smu_data->smc_state_table.VceBootLevel = 0;
2200 2203
2201 mm_boot_level_offset = smu_data->dpm_table_start + 2204 mm_boot_level_offset = smu_data->smu7_data.dpm_table_start +
2202 offsetof(SMU73_Discrete_DpmTable, VceBootLevel); 2205 offsetof(SMU73_Discrete_DpmTable, VceBootLevel);
2203 mm_boot_level_offset /= 4; 2206 mm_boot_level_offset /= 4;
2204 mm_boot_level_offset *= 4; 2207 mm_boot_level_offset *= 4;
@@ -2223,7 +2226,7 @@ static int fiji_update_samu_smc_table(struct pp_hwmgr *hwmgr)
2223 2226
2224 2227
2225 smu_data->smc_state_table.SamuBootLevel = 0; 2228 smu_data->smc_state_table.SamuBootLevel = 0;
2226 mm_boot_level_offset = smu_data->dpm_table_start + 2229 mm_boot_level_offset = smu_data->smu7_data.dpm_table_start +
2227 offsetof(SMU73_Discrete_DpmTable, SamuBootLevel); 2230 offsetof(SMU73_Discrete_DpmTable, SamuBootLevel);
2228 2231
2229 mm_boot_level_offset /= 4; 2232 mm_boot_level_offset /= 4;
@@ -2276,57 +2279,57 @@ int fiji_process_firmware_header(struct pp_hwmgr *hwmgr)
2276 int result; 2279 int result;
2277 bool error = false; 2280 bool error = false;
2278 2281
2279 result = fiji_read_smc_sram_dword(hwmgr->smumgr, 2282 result = smu7_read_smc_sram_dword(hwmgr->smumgr,
2280 SMU7_FIRMWARE_HEADER_LOCATION + 2283 SMU7_FIRMWARE_HEADER_LOCATION +
2281 offsetof(SMU73_Firmware_Header, DpmTable), 2284 offsetof(SMU73_Firmware_Header, DpmTable),
2282 &tmp, SMC_RAM_END); 2285 &tmp, SMC_RAM_END);
2283 2286
2284 if (0 == result) 2287 if (0 == result)
2285 smu_data->dpm_table_start = tmp; 2288 smu_data->smu7_data.dpm_table_start = tmp;
2286 2289
2287 error |= (0 != result); 2290 error |= (0 != result);
2288 2291
2289 result = fiji_read_smc_sram_dword(hwmgr->smumgr, 2292 result = smu7_read_smc_sram_dword(hwmgr->smumgr,
2290 SMU7_FIRMWARE_HEADER_LOCATION + 2293 SMU7_FIRMWARE_HEADER_LOCATION +
2291 offsetof(SMU73_Firmware_Header, SoftRegisters), 2294 offsetof(SMU73_Firmware_Header, SoftRegisters),
2292 &tmp, SMC_RAM_END); 2295 &tmp, SMC_RAM_END);
2293 2296
2294 if (!result) { 2297 if (!result) {
2295 data->soft_regs_start = tmp; 2298 data->soft_regs_start = tmp;
2296 smu_data->soft_regs_start = tmp; 2299 smu_data->smu7_data.soft_regs_start = tmp;
2297 } 2300 }
2298 2301
2299 error |= (0 != result); 2302 error |= (0 != result);
2300 2303
2301 result = fiji_read_smc_sram_dword(hwmgr->smumgr, 2304 result = smu7_read_smc_sram_dword(hwmgr->smumgr,
2302 SMU7_FIRMWARE_HEADER_LOCATION + 2305 SMU7_FIRMWARE_HEADER_LOCATION +
2303 offsetof(SMU73_Firmware_Header, mcRegisterTable), 2306 offsetof(SMU73_Firmware_Header, mcRegisterTable),
2304 &tmp, SMC_RAM_END); 2307 &tmp, SMC_RAM_END);
2305 2308
2306 if (!result) 2309 if (!result)
2307 smu_data->mc_reg_table_start = tmp; 2310 smu_data->smu7_data.mc_reg_table_start = tmp;
2308 2311
2309 result = fiji_read_smc_sram_dword(hwmgr->smumgr, 2312 result = smu7_read_smc_sram_dword(hwmgr->smumgr,
2310 SMU7_FIRMWARE_HEADER_LOCATION + 2313 SMU7_FIRMWARE_HEADER_LOCATION +
2311 offsetof(SMU73_Firmware_Header, FanTable), 2314 offsetof(SMU73_Firmware_Header, FanTable),
2312 &tmp, SMC_RAM_END); 2315 &tmp, SMC_RAM_END);
2313 2316
2314 if (!result) 2317 if (!result)
2315 smu_data->fan_table_start = tmp; 2318 smu_data->smu7_data.fan_table_start = tmp;
2316 2319
2317 error |= (0 != result); 2320 error |= (0 != result);
2318 2321
2319 result = fiji_read_smc_sram_dword(hwmgr->smumgr, 2322 result = smu7_read_smc_sram_dword(hwmgr->smumgr,
2320 SMU7_FIRMWARE_HEADER_LOCATION + 2323 SMU7_FIRMWARE_HEADER_LOCATION +
2321 offsetof(SMU73_Firmware_Header, mcArbDramTimingTable), 2324 offsetof(SMU73_Firmware_Header, mcArbDramTimingTable),
2322 &tmp, SMC_RAM_END); 2325 &tmp, SMC_RAM_END);
2323 2326
2324 if (!result) 2327 if (!result)
2325 smu_data->arb_table_start = tmp; 2328 smu_data->smu7_data.arb_table_start = tmp;
2326 2329
2327 error |= (0 != result); 2330 error |= (0 != result);
2328 2331
2329 result = fiji_read_smc_sram_dword(hwmgr->smumgr, 2332 result = smu7_read_smc_sram_dword(hwmgr->smumgr,
2330 SMU7_FIRMWARE_HEADER_LOCATION + 2333 SMU7_FIRMWARE_HEADER_LOCATION +
2331 offsetof(SMU73_Firmware_Header, Version), 2334 offsetof(SMU73_Firmware_Header, Version),
2332 &tmp, SMC_RAM_END); 2335 &tmp, SMC_RAM_END);
diff --git a/drivers/gpu/drm/amd/powerplay/smumgr/fiji_smumgr.c b/drivers/gpu/drm/amd/powerplay/smumgr/fiji_smumgr.c
index 82a8be4af63b..02fe1df855a9 100644
--- a/drivers/gpu/drm/amd/powerplay/smumgr/fiji_smumgr.c
+++ b/drivers/gpu/drm/amd/powerplay/smumgr/fiji_smumgr.c
@@ -58,520 +58,6 @@ static const struct SMU73_Discrete_GraphicsLevel avfs_graphics_level[8] = {
58 { 0xf811d047, 0x80380100, 0x01, 0x00, 0x1e00, 0x00000610, 0x87020000, 0x21680000, 0x12000000, 0, 0, 0x0c, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00 } 58 { 0xf811d047, 0x80380100, 0x01, 0x00, 0x1e00, 0x00000610, 0x87020000, 0x21680000, 0x12000000, 0, 0, 0x0c, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00 }
59}; 59};
60 60
61static enum cgs_ucode_id fiji_convert_fw_type_to_cgs(uint32_t fw_type)
62{
63 enum cgs_ucode_id result = CGS_UCODE_ID_MAXIMUM;
64
65 switch (fw_type) {
66 case UCODE_ID_SMU:
67 result = CGS_UCODE_ID_SMU;
68 break;
69 case UCODE_ID_SDMA0:
70 result = CGS_UCODE_ID_SDMA0;
71 break;
72 case UCODE_ID_SDMA1:
73 result = CGS_UCODE_ID_SDMA1;
74 break;
75 case UCODE_ID_CP_CE:
76 result = CGS_UCODE_ID_CP_CE;
77 break;
78 case UCODE_ID_CP_PFP:
79 result = CGS_UCODE_ID_CP_PFP;
80 break;
81 case UCODE_ID_CP_ME:
82 result = CGS_UCODE_ID_CP_ME;
83 break;
84 case UCODE_ID_CP_MEC:
85 result = CGS_UCODE_ID_CP_MEC;
86 break;
87 case UCODE_ID_CP_MEC_JT1:
88 result = CGS_UCODE_ID_CP_MEC_JT1;
89 break;
90 case UCODE_ID_CP_MEC_JT2:
91 result = CGS_UCODE_ID_CP_MEC_JT2;
92 break;
93 case UCODE_ID_RLC_G:
94 result = CGS_UCODE_ID_RLC_G;
95 break;
96 default:
97 break;
98 }
99
100 return result;
101}
102/**
103* Set the address for reading/writing the SMC SRAM space.
104* @param smumgr the address of the powerplay hardware manager.
105* @param smc_addr the address in the SMC RAM to access.
106*/
107static int fiji_set_smc_sram_address(struct pp_smumgr *smumgr,
108 uint32_t smc_addr, uint32_t limit)
109{
110 PP_ASSERT_WITH_CODE((0 == (3 & smc_addr)),
111 "SMC address must be 4 byte aligned.", return -EINVAL;);
112 PP_ASSERT_WITH_CODE((limit > (smc_addr + 3)),
113 "SMC address is beyond the SMC RAM area.", return -EINVAL;);
114
115 cgs_write_register(smumgr->device, mmSMC_IND_INDEX_0, smc_addr);
116 SMUM_WRITE_FIELD(smumgr->device, SMC_IND_ACCESS_CNTL, AUTO_INCREMENT_IND_0, 0);
117
118 return 0;
119}
120
121/**
122* Copy bytes from an array into the SMC RAM space.
123*
124* @param smumgr the address of the powerplay SMU manager.
125* @param smcStartAddress the start address in the SMC RAM to copy bytes to.
126* @param src the byte array to copy the bytes from.
127* @param byteCount the number of bytes to copy.
128*/
129int fiji_copy_bytes_to_smc(struct pp_smumgr *smumgr,
130 uint32_t smcStartAddress, const uint8_t *src,
131 uint32_t byteCount, uint32_t limit)
132{
133 int result;
134 uint32_t data, originalData;
135 uint32_t addr, extraShift;
136
137 PP_ASSERT_WITH_CODE((0 == (3 & smcStartAddress)),
138 "SMC address must be 4 byte aligned.", return -EINVAL;);
139 PP_ASSERT_WITH_CODE((limit > (smcStartAddress + byteCount)),
140 "SMC address is beyond the SMC RAM area.", return -EINVAL;);
141
142 addr = smcStartAddress;
143
144 while (byteCount >= 4) {
145 /* Bytes are written into the SMC addres space with the MSB first. */
146 data = src[0] * 0x1000000 + src[1] * 0x10000 + src[2] * 0x100 + src[3];
147
148 result = fiji_set_smc_sram_address(smumgr, addr, limit);
149 if (result)
150 return result;
151
152 cgs_write_register(smumgr->device, mmSMC_IND_DATA_0, data);
153
154 src += 4;
155 byteCount -= 4;
156 addr += 4;
157 }
158
159 if (byteCount) {
160 /* Now write the odd bytes left.
161 * Do a read modify write cycle.
162 */
163 data = 0;
164
165 result = fiji_set_smc_sram_address(smumgr, addr, limit);
166 if (result)
167 return result;
168
169 originalData = cgs_read_register(smumgr->device, mmSMC_IND_DATA_0);
170 extraShift = 8 * (4 - byteCount);
171
172 while (byteCount > 0) {
173 /* Bytes are written into the SMC addres
174 * space with the MSB first.
175 */
176 data = (0x100 * data) + *src++;
177 byteCount--;
178 }
179 data <<= extraShift;
180 data |= (originalData & ~((~0UL) << extraShift));
181
182 result = fiji_set_smc_sram_address(smumgr, addr, limit);
183 if (!result)
184 return result;
185
186 cgs_write_register(smumgr->device, mmSMC_IND_DATA_0, data);
187 }
188 return 0;
189}
190
191int fiji_program_jump_on_start(struct pp_smumgr *smumgr)
192{
193 static const unsigned char data[] = { 0xE0, 0x00, 0x80, 0x40 };
194
195 fiji_copy_bytes_to_smc(smumgr, 0x0, data, 4, sizeof(data) + 1);
196
197 return 0;
198}
199
200/**
201* Return if the SMC is currently running.
202*
203* @param smumgr the address of the powerplay hardware manager.
204*/
205bool fiji_is_smc_ram_running(struct pp_smumgr *smumgr)
206{
207 return ((0 == SMUM_READ_VFPF_INDIRECT_FIELD(smumgr->device,
208 CGS_IND_REG__SMC,
209 SMC_SYSCON_CLOCK_CNTL_0, ck_disable))
210 && (0x20100 <= cgs_read_ind_register(smumgr->device,
211 CGS_IND_REG__SMC, ixSMC_PC_C)));
212}
213
214/**
215* Send a message to the SMC, and wait for its response.
216*
217* @param smumgr the address of the powerplay hardware manager.
218* @param msg the message to send.
219* @return The response that came from the SMC.
220*/
221int fiji_send_msg_to_smc(struct pp_smumgr *smumgr, uint16_t msg)
222{
223 int ret;
224
225 if (!fiji_is_smc_ram_running(smumgr))
226 return -1;
227
228
229 SMUM_WAIT_FIELD_UNEQUAL(smumgr, SMC_RESP_0, SMC_RESP, 0);
230
231 ret = SMUM_READ_FIELD(smumgr->device, SMC_RESP_0, SMC_RESP);
232
233 if (ret != 1)
234 printk("\n failed to send pre message %x ret is %d \n", msg, ret);
235
236 cgs_write_register(smumgr->device, mmSMC_MESSAGE_0, msg);
237
238 SMUM_WAIT_FIELD_UNEQUAL(smumgr, SMC_RESP_0, SMC_RESP, 0);
239
240 ret = SMUM_READ_FIELD(smumgr->device, SMC_RESP_0, SMC_RESP);
241
242 if (ret != 1)
243 printk("\n failed to send message %x ret is %d \n", msg, ret);
244
245 return 0;
246}
247
248/**
249 * Send a message to the SMC with parameter
250 * @param smumgr: the address of the powerplay hardware manager.
251 * @param msg: the message to send.
252 * @param parameter: the parameter to send
253 * @return The response that came from the SMC.
254 */
255int fiji_send_msg_to_smc_with_parameter(struct pp_smumgr *smumgr,
256 uint16_t msg, uint32_t parameter)
257{
258 if (!fiji_is_smc_ram_running(smumgr))
259 return -1;
260
261 if (1 != SMUM_READ_FIELD(smumgr->device, SMC_RESP_0, SMC_RESP)) {
262 printk(KERN_ERR "Failed to send Previous Message.");
263 SMUM_WAIT_FIELD_UNEQUAL(smumgr, SMC_RESP_0, SMC_RESP, 0);
264 }
265
266 cgs_write_register(smumgr->device, mmSMC_MSG_ARG_0, parameter);
267 cgs_write_register(smumgr->device, mmSMC_MESSAGE_0, msg);
268 SMUM_WAIT_FIELD_UNEQUAL(smumgr, SMC_RESP_0, SMC_RESP, 0);
269
270 return 0;
271}
272
273
274/**
275* Send a message to the SMC with parameter, do not wait for response
276*
277* @param smumgr: the address of the powerplay hardware manager.
278* @param msg: the message to send.
279* @param parameter: the parameter to send
280* @return The response that came from the SMC.
281*/
282int fiji_send_msg_to_smc_with_parameter_without_waiting(
283 struct pp_smumgr *smumgr, uint16_t msg, uint32_t parameter)
284{
285 if (1 != SMUM_READ_FIELD(smumgr->device, SMC_RESP_0, SMC_RESP)) {
286 printk(KERN_ERR "Failed to send Previous Message.");
287 SMUM_WAIT_FIELD_UNEQUAL(smumgr, SMC_RESP_0, SMC_RESP, 0);
288 }
289 cgs_write_register(smumgr->device, mmSMC_MSG_ARG_0, parameter);
290 cgs_write_register(smumgr->device, mmSMC_MESSAGE_0, msg);
291
292 return 0;
293}
294
295/**
296* Uploads the SMU firmware from .hex file
297*
298* @param smumgr the address of the powerplay SMU manager.
299* @return 0 or -1.
300*/
301
302static int fiji_upload_smu_firmware_image(struct pp_smumgr *smumgr)
303{
304 const uint8_t *src;
305 uint32_t byte_count;
306 uint32_t *data;
307 struct cgs_firmware_info info = {0};
308
309 cgs_get_firmware_info(smumgr->device,
310 fiji_convert_fw_type_to_cgs(UCODE_ID_SMU), &info);
311
312 if (info.image_size & 3) {
313 printk(KERN_ERR "SMC ucode is not 4 bytes aligned\n");
314 return -EINVAL;
315 }
316
317 if (info.image_size > FIJI_SMC_SIZE) {
318 printk(KERN_ERR "SMC address is beyond the SMC RAM area\n");
319 return -EINVAL;
320 }
321
322 cgs_write_register(smumgr->device, mmSMC_IND_INDEX_0, 0x20000);
323 SMUM_WRITE_FIELD(smumgr->device, SMC_IND_ACCESS_CNTL, AUTO_INCREMENT_IND_0, 1);
324
325 byte_count = info.image_size;
326 src = (const uint8_t *)info.kptr;
327
328 data = (uint32_t *)src;
329 for (; byte_count >= 4; data++, byte_count -= 4)
330 cgs_write_register(smumgr->device, mmSMC_IND_DATA_0, data[0]);
331
332 SMUM_WRITE_FIELD(smumgr->device, SMC_IND_ACCESS_CNTL, AUTO_INCREMENT_IND_0, 0);
333 return 0;
334}
335
336/**
337* Read a 32bit value from the SMC SRAM space.
338* ALL PARAMETERS ARE IN HOST BYTE ORDER.
339* @param smumgr the address of the powerplay hardware manager.
340* @param smc_addr the address in the SMC RAM to access.
341* @param value and output parameter for the data read from the SMC SRAM.
342*/
343int fiji_read_smc_sram_dword(struct pp_smumgr *smumgr, uint32_t smc_addr,
344 uint32_t *value, uint32_t limit)
345{
346 int result = fiji_set_smc_sram_address(smumgr, smc_addr, limit);
347
348 if (result)
349 return result;
350
351 *value = cgs_read_register(smumgr->device, mmSMC_IND_DATA_0);
352 return 0;
353}
354
355/**
356* Write a 32bit value to the SMC SRAM space.
357* ALL PARAMETERS ARE IN HOST BYTE ORDER.
358* @param smumgr the address of the powerplay hardware manager.
359* @param smc_addr the address in the SMC RAM to access.
360* @param value to write to the SMC SRAM.
361*/
362int fiji_write_smc_sram_dword(struct pp_smumgr *smumgr, uint32_t smc_addr,
363 uint32_t value, uint32_t limit)
364{
365 int result;
366
367 result = fiji_set_smc_sram_address(smumgr, smc_addr, limit);
368
369 if (result)
370 return result;
371
372 cgs_write_register(smumgr->device, mmSMC_IND_DATA_0, value);
373 return 0;
374}
375
376static uint32_t fiji_get_mask_for_firmware_type(uint32_t fw_type)
377{
378 uint32_t result = 0;
379
380 switch (fw_type) {
381 case UCODE_ID_SDMA0:
382 result = UCODE_ID_SDMA0_MASK;
383 break;
384 case UCODE_ID_SDMA1:
385 result = UCODE_ID_SDMA1_MASK;
386 break;
387 case UCODE_ID_CP_CE:
388 result = UCODE_ID_CP_CE_MASK;
389 break;
390 case UCODE_ID_CP_PFP:
391 result = UCODE_ID_CP_PFP_MASK;
392 break;
393 case UCODE_ID_CP_ME:
394 result = UCODE_ID_CP_ME_MASK;
395 break;
396 case UCODE_ID_CP_MEC_JT1:
397 result = UCODE_ID_CP_MEC_MASK | UCODE_ID_CP_MEC_JT1_MASK;
398 break;
399 case UCODE_ID_CP_MEC_JT2:
400 result = UCODE_ID_CP_MEC_MASK | UCODE_ID_CP_MEC_JT2_MASK;
401 break;
402 case UCODE_ID_RLC_G:
403 result = UCODE_ID_RLC_G_MASK;
404 break;
405 default:
406 printk(KERN_ERR "UCode type is out of range!");
407 result = 0;
408 }
409
410 return result;
411}
412
413/* Populate one firmware image to the data structure */
414static int fiji_populate_single_firmware_entry(struct pp_smumgr *smumgr,
415 uint32_t fw_type, struct SMU_Entry *entry)
416{
417 int result;
418 struct cgs_firmware_info info = {0};
419
420 result = cgs_get_firmware_info(
421 smumgr->device,
422 fiji_convert_fw_type_to_cgs(fw_type),
423 &info);
424
425 if (!result) {
426 entry->version = 0;
427 entry->id = (uint16_t)fw_type;
428 entry->image_addr_high = smu_upper_32_bits(info.mc_addr);
429 entry->image_addr_low = smu_lower_32_bits(info.mc_addr);
430 entry->meta_data_addr_high = 0;
431 entry->meta_data_addr_low = 0;
432 entry->data_size_byte = info.image_size;
433 entry->num_register_entries = 0;
434
435 if (fw_type == UCODE_ID_RLC_G)
436 entry->flags = 1;
437 else
438 entry->flags = 0;
439 }
440
441 return result;
442}
443
444static int fiji_request_smu_load_fw(struct pp_smumgr *smumgr)
445{
446 struct fiji_smumgr *priv = (struct fiji_smumgr *)(smumgr->backend);
447 uint32_t fw_to_load;
448 struct SMU_DRAMData_TOC *toc;
449
450 if (priv->soft_regs_start)
451 cgs_write_ind_register(smumgr->device, CGS_IND_REG__SMC,
452 priv->soft_regs_start +
453 offsetof(SMU73_SoftRegisters, UcodeLoadStatus),
454 0x0);
455
456 toc = (struct SMU_DRAMData_TOC *)priv->header;
457 toc->num_entries = 0;
458 toc->structure_version = 1;
459
460 PP_ASSERT_WITH_CODE(
461 0 == fiji_populate_single_firmware_entry(smumgr,
462 UCODE_ID_RLC_G, &toc->entry[toc->num_entries++]),
463 "Failed to Get Firmware Entry.\n" , return -1 );
464 PP_ASSERT_WITH_CODE(
465 0 == fiji_populate_single_firmware_entry(smumgr,
466 UCODE_ID_CP_CE, &toc->entry[toc->num_entries++]),
467 "Failed to Get Firmware Entry.\n" , return -1 );
468 PP_ASSERT_WITH_CODE(
469 0 == fiji_populate_single_firmware_entry(smumgr,
470 UCODE_ID_CP_PFP, &toc->entry[toc->num_entries++]),
471 "Failed to Get Firmware Entry.\n" , return -1 );
472 PP_ASSERT_WITH_CODE(
473 0 == fiji_populate_single_firmware_entry(smumgr,
474 UCODE_ID_CP_ME, &toc->entry[toc->num_entries++]),
475 "Failed to Get Firmware Entry.\n" , return -1 );
476 PP_ASSERT_WITH_CODE(
477 0 == fiji_populate_single_firmware_entry(smumgr,
478 UCODE_ID_CP_MEC, &toc->entry[toc->num_entries++]),
479 "Failed to Get Firmware Entry.\n" , return -1 );
480 PP_ASSERT_WITH_CODE(
481 0 == fiji_populate_single_firmware_entry(smumgr,
482 UCODE_ID_CP_MEC_JT1, &toc->entry[toc->num_entries++]),
483 "Failed to Get Firmware Entry.\n" , return -1 );
484 PP_ASSERT_WITH_CODE(
485 0 == fiji_populate_single_firmware_entry(smumgr,
486 UCODE_ID_CP_MEC_JT2, &toc->entry[toc->num_entries++]),
487 "Failed to Get Firmware Entry.\n" , return -1 );
488 PP_ASSERT_WITH_CODE(
489 0 == fiji_populate_single_firmware_entry(smumgr,
490 UCODE_ID_SDMA0, &toc->entry[toc->num_entries++]),
491 "Failed to Get Firmware Entry.\n" , return -1 );
492 PP_ASSERT_WITH_CODE(
493 0 == fiji_populate_single_firmware_entry(smumgr,
494 UCODE_ID_SDMA1, &toc->entry[toc->num_entries++]),
495 "Failed to Get Firmware Entry.\n" , return -1 );
496
497 fiji_send_msg_to_smc_with_parameter(smumgr, PPSMC_MSG_DRV_DRAM_ADDR_HI,
498 priv->header_buffer.mc_addr_high);
499 fiji_send_msg_to_smc_with_parameter(smumgr,PPSMC_MSG_DRV_DRAM_ADDR_LO,
500 priv->header_buffer.mc_addr_low);
501
502 fw_to_load = UCODE_ID_RLC_G_MASK
503 + UCODE_ID_SDMA0_MASK
504 + UCODE_ID_SDMA1_MASK
505 + UCODE_ID_CP_CE_MASK
506 + UCODE_ID_CP_ME_MASK
507 + UCODE_ID_CP_PFP_MASK
508 + UCODE_ID_CP_MEC_MASK
509 + UCODE_ID_CP_MEC_JT1_MASK
510 + UCODE_ID_CP_MEC_JT2_MASK;
511
512 if (fiji_send_msg_to_smc_with_parameter(smumgr,
513 PPSMC_MSG_LoadUcodes, fw_to_load))
514 printk(KERN_ERR "Fail to Request SMU Load uCode");
515
516 return 0;
517}
518
519
520/* Check if the FW has been loaded, SMU will not return
521 * if loading has not finished.
522 */
523static int fiji_check_fw_load_finish(struct pp_smumgr *smumgr,
524 uint32_t fw_type)
525{
526 struct fiji_smumgr *priv = (struct fiji_smumgr *)(smumgr->backend);
527 uint32_t mask = fiji_get_mask_for_firmware_type(fw_type);
528
529 /* Check SOFT_REGISTERS_TABLE_28.UcodeLoadStatus */
530 if (smum_wait_on_indirect_register(smumgr, mmSMC_IND_INDEX,
531 priv->soft_regs_start +
532 offsetof(SMU73_SoftRegisters, UcodeLoadStatus),
533 mask, mask)) {
534 printk(KERN_ERR "check firmware loading failed\n");
535 return -EINVAL;
536 }
537 return 0;
538}
539
540
541static int fiji_reload_firmware(struct pp_smumgr *smumgr)
542{
543 return smumgr->smumgr_funcs->start_smu(smumgr);
544}
545
546static bool fiji_is_hw_virtualization_enabled(struct pp_smumgr *smumgr)
547{
548 uint32_t value;
549
550 value = cgs_read_register(smumgr->device, mmBIF_IOV_FUNC_IDENTIFIER);
551 if (value & BIF_IOV_FUNC_IDENTIFIER__IOV_ENABLE_MASK) {
552 /* driver reads on SR-IOV enabled PF: 0x80000000
553 * driver reads on SR-IOV enabled VF: 0x80000001
554 * driver reads on SR-IOV disabled: 0x00000000
555 */
556 return true;
557 }
558 return false;
559}
560
561static int fiji_request_smu_specific_fw_load(struct pp_smumgr *smumgr, uint32_t fw_type)
562{
563 if (fiji_is_hw_virtualization_enabled(smumgr)) {
564 uint32_t masks = fiji_get_mask_for_firmware_type(fw_type);
565 if (fiji_send_msg_to_smc_with_parameter_without_waiting(smumgr,
566 PPSMC_MSG_LoadUcodes, masks))
567 printk(KERN_ERR "Fail to Request SMU Load uCode");
568 }
569 /* For non-virtualization cases,
570 * SMU loads all FWs at once in fiji_request_smu_load_fw.
571 */
572 return 0;
573}
574
575static int fiji_start_smu_in_protection_mode(struct pp_smumgr *smumgr) 61static int fiji_start_smu_in_protection_mode(struct pp_smumgr *smumgr)
576{ 62{
577 int result = 0; 63 int result = 0;
@@ -583,7 +69,7 @@ static int fiji_start_smu_in_protection_mode(struct pp_smumgr *smumgr)
583 SMUM_WRITE_VFPF_INDIRECT_FIELD(smumgr->device, CGS_IND_REG__SMC, 69 SMUM_WRITE_VFPF_INDIRECT_FIELD(smumgr->device, CGS_IND_REG__SMC,
584 SMC_SYSCON_RESET_CNTL, rst_reg, 1); 70 SMC_SYSCON_RESET_CNTL, rst_reg, 1);
585 71
586 result = fiji_upload_smu_firmware_image(smumgr); 72 result = smu7_upload_smu_firmware_image(smumgr);
587 if (result) 73 if (result)
588 return result; 74 return result;
589 75
@@ -622,8 +108,8 @@ static int fiji_start_smu_in_protection_mode(struct pp_smumgr *smumgr)
622 SMU_STATUS, SMU_DONE, 0); 108 SMU_STATUS, SMU_DONE, 0);
623 109
624 /* Check pass/failed indicator */ 110 /* Check pass/failed indicator */
625 if (1 != SMUM_READ_VFPF_INDIRECT_FIELD(smumgr->device, CGS_IND_REG__SMC, 111 if (SMUM_READ_VFPF_INDIRECT_FIELD(smumgr->device, CGS_IND_REG__SMC,
626 SMU_STATUS, SMU_PASS)) { 112 SMU_STATUS, SMU_PASS) != 1) {
627 PP_ASSERT_WITH_CODE(false, 113 PP_ASSERT_WITH_CODE(false,
628 "SMU Firmware start failed!", return -1); 114 "SMU Firmware start failed!", return -1);
629 } 115 }
@@ -651,12 +137,12 @@ static int fiji_start_smu_in_non_protection_mode(struct pp_smumgr *smumgr)
651 SMUM_WRITE_VFPF_INDIRECT_FIELD(smumgr->device, CGS_IND_REG__SMC, 137 SMUM_WRITE_VFPF_INDIRECT_FIELD(smumgr->device, CGS_IND_REG__SMC,
652 SMC_SYSCON_RESET_CNTL, rst_reg, 1); 138 SMC_SYSCON_RESET_CNTL, rst_reg, 1);
653 139
654 result = fiji_upload_smu_firmware_image(smumgr); 140 result = smu7_upload_smu_firmware_image(smumgr);
655 if (result) 141 if (result)
656 return result; 142 return result;
657 143
658 /* Set smc instruct start point at 0x0 */ 144 /* Set smc instruct start point at 0x0 */
659 fiji_program_jump_on_start(smumgr); 145 smu7_program_jump_on_start(smumgr);
660 146
661 /* Enable clock */ 147 /* Enable clock */
662 SMUM_WRITE_VFPF_INDIRECT_FIELD(smumgr->device, CGS_IND_REG__SMC, 148 SMUM_WRITE_VFPF_INDIRECT_FIELD(smumgr->device, CGS_IND_REG__SMC,
@@ -710,15 +196,15 @@ static int fiji_start_avfs_btc(struct pp_smumgr *smumgr)
710 196
711 priv->avfs.AvfsBtcStatus = AVFS_BTC_STARTED; 197 priv->avfs.AvfsBtcStatus = AVFS_BTC_STARTED;
712 if (priv->avfs.AvfsBtcParam) { 198 if (priv->avfs.AvfsBtcParam) {
713 if (!fiji_send_msg_to_smc_with_parameter(smumgr, 199 if (!smum_send_msg_to_smc_with_parameter(smumgr,
714 PPSMC_MSG_PerformBtc, priv->avfs.AvfsBtcParam)) { 200 PPSMC_MSG_PerformBtc, priv->avfs.AvfsBtcParam)) {
715 if (!fiji_send_msg_to_smc(smumgr, PPSMC_MSG_EnableAvfs)) { 201 if (!smum_send_msg_to_smc(smumgr, PPSMC_MSG_EnableAvfs)) {
716 priv->avfs.AvfsBtcStatus = AVFS_BTC_COMPLETED_UNSAVED; 202 priv->avfs.AvfsBtcStatus = AVFS_BTC_COMPLETED_UNSAVED;
717 result = 0; 203 result = 0;
718 } else { 204 } else {
719 printk(KERN_ERR "[AVFS][fiji_start_avfs_btc] Attempt" 205 printk(KERN_ERR "[AVFS][fiji_start_avfs_btc] Attempt"
720 " to Enable AVFS Failed!"); 206 " to Enable AVFS Failed!");
721 fiji_send_msg_to_smc(smumgr, PPSMC_MSG_DisableAvfs); 207 smum_send_msg_to_smc(smumgr, PPSMC_MSG_DisableAvfs);
722 result = -1; 208 result = -1;
723 } 209 }
724 } else { 210 } else {
@@ -748,7 +234,7 @@ int fiji_setup_pm_fuse_for_avfs(struct pp_smumgr *smumgr)
748 charz_freq = 0x30750000; /* In 10KHz units 0x00007530 Actual value */ 234 charz_freq = 0x30750000; /* In 10KHz units 0x00007530 Actual value */
749 inversion_voltage = 0x1A04; /* mV Q14.2 0x41A Actual value */ 235 inversion_voltage = 0x1A04; /* mV Q14.2 0x41A Actual value */
750 236
751 PP_ASSERT_WITH_CODE(0 == fiji_read_smc_sram_dword(smumgr, 237 PP_ASSERT_WITH_CODE(0 == smu7_read_smc_sram_dword(smumgr,
752 SMU7_FIRMWARE_HEADER_LOCATION + offsetof(SMU73_Firmware_Header, 238 SMU7_FIRMWARE_HEADER_LOCATION + offsetof(SMU73_Firmware_Header,
753 PmFuseTable), &table_start, 0x40000), 239 PmFuseTable), &table_start, 0x40000),
754 "[AVFS][Fiji_SetupGfxLvlStruct] SMU could not communicate " 240 "[AVFS][Fiji_SetupGfxLvlStruct] SMU could not communicate "
@@ -760,13 +246,13 @@ int fiji_setup_pm_fuse_for_avfs(struct pp_smumgr *smumgr)
760 inversion_voltage_addr = table_start + 246 inversion_voltage_addr = table_start +
761 offsetof(struct SMU73_Discrete_PmFuses, InversionVoltage); 247 offsetof(struct SMU73_Discrete_PmFuses, InversionVoltage);
762 248
763 result = fiji_copy_bytes_to_smc(smumgr, charz_freq_addr, 249 result = smu7_copy_bytes_to_smc(smumgr, charz_freq_addr,
764 (uint8_t *)(&charz_freq), sizeof(charz_freq), 0x40000); 250 (uint8_t *)(&charz_freq), sizeof(charz_freq), 0x40000);
765 PP_ASSERT_WITH_CODE(0 == result, 251 PP_ASSERT_WITH_CODE(0 == result,
766 "[AVFS][fiji_setup_pm_fuse_for_avfs] charz_freq could not " 252 "[AVFS][fiji_setup_pm_fuse_for_avfs] charz_freq could not "
767 "be populated.", return -1;); 253 "be populated.", return -1;);
768 254
769 result = fiji_copy_bytes_to_smc(smumgr, inversion_voltage_addr, 255 result = smu7_copy_bytes_to_smc(smumgr, inversion_voltage_addr,
770 (uint8_t *)(&inversion_voltage), sizeof(inversion_voltage), 0x40000); 256 (uint8_t *)(&inversion_voltage), sizeof(inversion_voltage), 0x40000);
771 PP_ASSERT_WITH_CODE(0 == result, "[AVFS][fiji_setup_pm_fuse_for_avfs] " 257 PP_ASSERT_WITH_CODE(0 == result, "[AVFS][fiji_setup_pm_fuse_for_avfs] "
772 "charz_freq could not be populated.", return -1;); 258 "charz_freq could not be populated.", return -1;);
@@ -781,7 +267,7 @@ int fiji_setup_graphics_level_structure(struct pp_smumgr *smumgr)
781 uint32_t level_addr, vr_config_addr; 267 uint32_t level_addr, vr_config_addr;
782 uint32_t level_size = sizeof(avfs_graphics_level); 268 uint32_t level_size = sizeof(avfs_graphics_level);
783 269
784 PP_ASSERT_WITH_CODE(0 == fiji_read_smc_sram_dword(smumgr, 270 PP_ASSERT_WITH_CODE(0 == smu7_read_smc_sram_dword(smumgr,
785 SMU7_FIRMWARE_HEADER_LOCATION + 271 SMU7_FIRMWARE_HEADER_LOCATION +
786 offsetof(SMU73_Firmware_Header, DpmTable), 272 offsetof(SMU73_Firmware_Header, DpmTable),
787 &table_start, 0x40000), 273 &table_start, 0x40000),
@@ -796,7 +282,7 @@ int fiji_setup_graphics_level_structure(struct pp_smumgr *smumgr)
796 vr_config_addr = table_start + 282 vr_config_addr = table_start +
797 offsetof(SMU73_Discrete_DpmTable, VRConfig); 283 offsetof(SMU73_Discrete_DpmTable, VRConfig);
798 284
799 PP_ASSERT_WITH_CODE(0 == fiji_copy_bytes_to_smc(smumgr, vr_config_addr, 285 PP_ASSERT_WITH_CODE(0 == smu7_copy_bytes_to_smc(smumgr, vr_config_addr,
800 (uint8_t *)&vr_config, sizeof(int32_t), 0x40000), 286 (uint8_t *)&vr_config, sizeof(int32_t), 0x40000),
801 "[AVFS][Fiji_SetupGfxLvlStruct] Problems copying " 287 "[AVFS][Fiji_SetupGfxLvlStruct] Problems copying "
802 "vr_config value over to SMC", 288 "vr_config value over to SMC",
@@ -804,7 +290,7 @@ int fiji_setup_graphics_level_structure(struct pp_smumgr *smumgr)
804 290
805 level_addr = table_start + offsetof(SMU73_Discrete_DpmTable, GraphicsLevel); 291 level_addr = table_start + offsetof(SMU73_Discrete_DpmTable, GraphicsLevel);
806 292
807 PP_ASSERT_WITH_CODE(0 == fiji_copy_bytes_to_smc(smumgr, level_addr, 293 PP_ASSERT_WITH_CODE(0 == smu7_copy_bytes_to_smc(smumgr, level_addr,
808 (uint8_t *)(&avfs_graphics_level), level_size, 0x40000), 294 (uint8_t *)(&avfs_graphics_level), level_size, 0x40000),
809 "[AVFS][Fiji_SetupGfxLvlStruct] Copying of DPM table failed!", 295 "[AVFS][Fiji_SetupGfxLvlStruct] Copying of DPM table failed!",
810 return -1;); 296 return -1;);
@@ -851,13 +337,13 @@ int fiji_avfs_event_mgr(struct pp_smumgr *smumgr, bool smu_started)
851 break; 337 break;
852 case AVFS_BTC_COMPLETED_RESTORED: /*S3 State - Post SMU Start*/ 338 case AVFS_BTC_COMPLETED_RESTORED: /*S3 State - Post SMU Start*/
853 priv->avfs.AvfsBtcStatus = AVFS_BTC_SMUMSG_ERROR; 339 priv->avfs.AvfsBtcStatus = AVFS_BTC_SMUMSG_ERROR;
854 PP_ASSERT_WITH_CODE(0 == fiji_send_msg_to_smc(smumgr, 340 PP_ASSERT_WITH_CODE(0 == smum_send_msg_to_smc(smumgr,
855 0x666), 341 0x666),
856 "[AVFS][fiji_avfs_event_mgr] SMU did not respond " 342 "[AVFS][fiji_avfs_event_mgr] SMU did not respond "
857 "correctly to VftTableIsValid Msg", 343 "correctly to VftTableIsValid Msg",
858 return -1;); 344 return -1;);
859 priv->avfs.AvfsBtcStatus = AVFS_BTC_SMUMSG_ERROR; 345 priv->avfs.AvfsBtcStatus = AVFS_BTC_SMUMSG_ERROR;
860 PP_ASSERT_WITH_CODE(0 == fiji_send_msg_to_smc(smumgr, 346 PP_ASSERT_WITH_CODE(0 == smum_send_msg_to_smc(smumgr,
861 PPSMC_MSG_EnableAvfs), 347 PPSMC_MSG_EnableAvfs),
862 "[AVFS][fiji_avfs_event_mgr] SMU did not respond " 348 "[AVFS][fiji_avfs_event_mgr] SMU did not respond "
863 "correctly to EnableAvfs Message Msg", 349 "correctly to EnableAvfs Message Msg",
@@ -910,7 +396,7 @@ static int fiji_start_smu(struct pp_smumgr *smumgr)
910 struct fiji_smumgr *priv = (struct fiji_smumgr *)(smumgr->backend); 396 struct fiji_smumgr *priv = (struct fiji_smumgr *)(smumgr->backend);
911 397
912 /* Only start SMC if SMC RAM is not running */ 398 /* Only start SMC if SMC RAM is not running */
913 if (!fiji_is_smc_ram_running(smumgr)) { 399 if (!smu7_is_smc_ram_running(smumgr)) {
914 fiji_avfs_event_mgr(smumgr, false); 400 fiji_avfs_event_mgr(smumgr, false);
915 401
916 /* Check if SMU is running in protected mode */ 402 /* Check if SMU is running in protected mode */
@@ -941,12 +427,12 @@ static int fiji_start_smu(struct pp_smumgr *smumgr)
941 /* Setup SoftRegsStart here for register lookup in case 427 /* Setup SoftRegsStart here for register lookup in case
942 * DummyBackEnd is used and ProcessFirmwareHeader is not executed 428 * DummyBackEnd is used and ProcessFirmwareHeader is not executed
943 */ 429 */
944 fiji_read_smc_sram_dword(smumgr, 430 smu7_read_smc_sram_dword(smumgr,
945 SMU7_FIRMWARE_HEADER_LOCATION + 431 SMU7_FIRMWARE_HEADER_LOCATION +
946 offsetof(SMU73_Firmware_Header, SoftRegisters), 432 offsetof(SMU73_Firmware_Header, SoftRegisters),
947 &(priv->soft_regs_start), 0x40000); 433 &(priv->smu7_data.soft_regs_start), 0x40000);
948 434
949 result = fiji_request_smu_load_fw(smumgr); 435 result = smu7_request_smu_load_fw(smumgr);
950 436
951 return result; 437 return result;
952} 438}
@@ -975,29 +461,10 @@ static bool fiji_is_hw_avfs_present(struct pp_smumgr *smumgr)
975static int fiji_smu_init(struct pp_smumgr *smumgr) 461static int fiji_smu_init(struct pp_smumgr *smumgr)
976{ 462{
977 struct fiji_smumgr *priv = (struct fiji_smumgr *)(smumgr->backend); 463 struct fiji_smumgr *priv = (struct fiji_smumgr *)(smumgr->backend);
978 uint64_t mc_addr;
979 int i; 464 int i;
980 465
981 priv->header_buffer.data_size = 466 if (smu7_init(smumgr))
982 ((sizeof(struct SMU_DRAMData_TOC) / 4096) + 1) * 4096; 467 return -EINVAL;
983 smu_allocate_memory(smumgr->device,
984 priv->header_buffer.data_size,
985 CGS_GPU_MEM_TYPE__VISIBLE_CONTIG_FB,
986 PAGE_SIZE,
987 &mc_addr,
988 &priv->header_buffer.kaddr,
989 &priv->header_buffer.handle);
990
991 priv->header = priv->header_buffer.kaddr;
992 priv->header_buffer.mc_addr_high = smu_upper_32_bits(mc_addr);
993 priv->header_buffer.mc_addr_low = smu_lower_32_bits(mc_addr);
994
995 PP_ASSERT_WITH_CODE((NULL != priv->header),
996 "Out of memory.",
997 kfree(smumgr->backend);
998 cgs_free_gpu_mem(smumgr->device,
999 (cgs_handle_t)priv->header_buffer.handle);
1000 return -1);
1001 468
1002 priv->avfs.AvfsBtcStatus = AVFS_BTC_BOOT; 469 priv->avfs.AvfsBtcStatus = AVFS_BTC_BOOT;
1003 if (fiji_is_hw_avfs_present(smumgr)) 470 if (fiji_is_hw_avfs_present(smumgr))
@@ -1012,38 +479,22 @@ static int fiji_smu_init(struct pp_smumgr *smumgr)
1012 else 479 else
1013 priv->avfs.AvfsBtcStatus = AVFS_BTC_NOTSUPPORTED; 480 priv->avfs.AvfsBtcStatus = AVFS_BTC_NOTSUPPORTED;
1014 481
1015 priv->acpi_optimization = 1;
1016
1017 for (i = 0; i < SMU73_MAX_LEVELS_GRAPHICS; i++) 482 for (i = 0; i < SMU73_MAX_LEVELS_GRAPHICS; i++)
1018 priv->activity_target[i] = 30; 483 priv->activity_target[i] = 30;
1019 484
1020 return 0; 485 return 0;
1021} 486}
1022 487
1023static int fiji_smu_fini(struct pp_smumgr *smumgr)
1024{
1025 struct fiji_smumgr *priv = (struct fiji_smumgr *)(smumgr->backend);
1026
1027 smu_free_memory(smumgr->device, (void *)priv->header_buffer.handle);
1028
1029 if (smumgr->backend) {
1030 kfree(smumgr->backend);
1031 smumgr->backend = NULL;
1032 }
1033
1034 cgs_rel_firmware(smumgr->device, CGS_UCODE_ID_SMU);
1035 return 0;
1036}
1037 488
1038static const struct pp_smumgr_func fiji_smu_funcs = { 489static const struct pp_smumgr_func fiji_smu_funcs = {
1039 .smu_init = &fiji_smu_init, 490 .smu_init = &fiji_smu_init,
1040 .smu_fini = &fiji_smu_fini, 491 .smu_fini = &smu7_smu_fini,
1041 .start_smu = &fiji_start_smu, 492 .start_smu = &fiji_start_smu,
1042 .check_fw_load_finish = &fiji_check_fw_load_finish, 493 .check_fw_load_finish = &smu7_check_fw_load_finish,
1043 .request_smu_load_fw = &fiji_reload_firmware, 494 .request_smu_load_fw = &smu7_reload_firmware,
1044 .request_smu_load_specific_fw = &fiji_request_smu_specific_fw_load, 495 .request_smu_load_specific_fw = NULL,
1045 .send_msg_to_smc = &fiji_send_msg_to_smc, 496 .send_msg_to_smc = &smu7_send_msg_to_smc,
1046 .send_msg_to_smc_with_parameter = &fiji_send_msg_to_smc_with_parameter, 497 .send_msg_to_smc_with_parameter = &smu7_send_msg_to_smc_with_parameter,
1047 .download_pptable_settings = NULL, 498 .download_pptable_settings = NULL,
1048 .upload_pptable_settings = NULL, 499 .upload_pptable_settings = NULL,
1049 .update_smc_table = fiji_update_smc_table, 500 .update_smc_table = fiji_update_smc_table,
diff --git a/drivers/gpu/drm/amd/powerplay/smumgr/fiji_smumgr.h b/drivers/gpu/drm/amd/powerplay/smumgr/fiji_smumgr.h
index 291f7042a585..adcbdfb209be 100644
--- a/drivers/gpu/drm/amd/powerplay/smumgr/fiji_smumgr.h
+++ b/drivers/gpu/drm/amd/powerplay/smumgr/fiji_smumgr.h
@@ -25,35 +25,20 @@
25 25
26#include "smu73_discrete.h" 26#include "smu73_discrete.h"
27#include <pp_endian.h> 27#include <pp_endian.h>
28#include "smu7_smumgr.h"
29
28 30
29#define SMC_RAM_END 0x40000
30 31
31struct fiji_smu_avfs { 32struct fiji_smu_avfs {
32 enum AVFS_BTC_STATUS AvfsBtcStatus; 33 enum AVFS_BTC_STATUS AvfsBtcStatus;
33 uint32_t AvfsBtcParam; 34 uint32_t AvfsBtcParam;
34}; 35};
35 36
36struct fiji_buffer_entry {
37 uint32_t data_size;
38 uint32_t mc_addr_low;
39 uint32_t mc_addr_high;
40 void *kaddr;
41 unsigned long handle;
42};
43 37
44struct fiji_smumgr { 38struct fiji_smumgr {
45 uint8_t *header; 39 struct smu7_smumgr smu7_data;
46 uint8_t *mec_image;
47 40
48 uint32_t soft_regs_start;
49 uint32_t dpm_table_start;
50 uint32_t mc_reg_table_start;
51 uint32_t fan_table_start;
52 uint32_t arb_table_start;
53 struct fiji_smu_avfs avfs; 41 struct fiji_smu_avfs avfs;
54 uint32_t acpi_optimization;
55 struct fiji_buffer_entry header_buffer;
56
57 struct SMU73_Discrete_DpmTable smc_state_table; 42 struct SMU73_Discrete_DpmTable smc_state_table;
58 struct SMU73_Discrete_Ulv ulv_setting; 43 struct SMU73_Discrete_Ulv ulv_setting;
59 struct SMU73_Discrete_PmFuses power_tune_table; 44 struct SMU73_Discrete_PmFuses power_tune_table;
@@ -62,13 +47,7 @@ struct fiji_smumgr {
62 47
63}; 48};
64 49
65int fiji_smum_init(struct pp_smumgr *smumgr); 50
66int fiji_read_smc_sram_dword(struct pp_smumgr *smumgr, uint32_t smcAddress,
67 uint32_t *value, uint32_t limit);
68int fiji_write_smc_sram_dword(struct pp_smumgr *smumgr, uint32_t smc_addr,
69 uint32_t value, uint32_t limit);
70int fiji_copy_bytes_to_smc(struct pp_smumgr *smumgr, uint32_t smcStartAddress,
71 const uint8_t *src, uint32_t byteCount, uint32_t limit);
72 51
73#endif 52#endif
74 53