1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23#include "pp_debug.h"
24#include "smumgr.h"
25#include "smu_ucode_xfer_vi.h"
26#include "vegam_smumgr.h"
27#include "smu/smu_7_1_3_d.h"
28#include "smu/smu_7_1_3_sh_mask.h"
29#include "gmc/gmc_8_1_d.h"
30#include "gmc/gmc_8_1_sh_mask.h"
31#include "oss/oss_3_0_d.h"
32#include "gca/gfx_8_0_d.h"
33#include "bif/bif_5_0_d.h"
34#include "bif/bif_5_0_sh_mask.h"
35#include "ppatomctrl.h"
36#include "cgs_common.h"
37#include "smu7_ppsmc.h"
38
39#include "smu7_dyn_defaults.h"
40
41#include "smu7_hwmgr.h"
42#include "hardwaremanager.h"
43#include "ppatomctrl.h"
44#include "atombios.h"
45#include "pppcielanes.h"
46
47#include "dce/dce_11_2_d.h"
48#include "dce/dce_11_2_sh_mask.h"
49
50#define PPVEGAM_TARGETACTIVITY_DFLT 50
51
52#define VOLTAGE_VID_OFFSET_SCALE1 625
53#define VOLTAGE_VID_OFFSET_SCALE2 100
54#define POWERTUNE_DEFAULT_SET_MAX 1
55#define VDDC_VDDCI_DELTA 200
56#define MC_CG_ARB_FREQ_F1 0x0b
57
58#define STRAP_ASIC_RO_LSB 2168
59#define STRAP_ASIC_RO_MSB 2175
60
61#define PPSMC_MSG_ApplyAvfsCksOffVoltage ((uint16_t) 0x415)
62#define PPSMC_MSG_EnableModeSwitchRLCNotification ((uint16_t) 0x305)
63
64static const struct vegam_pt_defaults
65vegam_power_tune_data_set_array[POWERTUNE_DEFAULT_SET_MAX] = {
66
67
68 { 1, 0xF, 0xFD, 0x19, 5, 45, 0, 0xB0000,
69 { 0x79, 0x253, 0x25D, 0xAE, 0x72, 0x80, 0x83, 0x86, 0x6F, 0xC8, 0xC9, 0xC9, 0x2F, 0x4D, 0x61},
70 { 0x17C, 0x172, 0x180, 0x1BC, 0x1B3, 0x1BD, 0x206, 0x200, 0x203, 0x25D, 0x25A, 0x255, 0x2C3, 0x2C5, 0x2B4 } },
71};
72
73static const sclkFcwRange_t Range_Table[NUM_SCLK_RANGE] = {
74 {VCO_2_4, POSTDIV_DIV_BY_16, 75, 160, 112},
75 {VCO_3_6, POSTDIV_DIV_BY_16, 112, 224, 160},
76 {VCO_2_4, POSTDIV_DIV_BY_8, 75, 160, 112},
77 {VCO_3_6, POSTDIV_DIV_BY_8, 112, 224, 160},
78 {VCO_2_4, POSTDIV_DIV_BY_4, 75, 160, 112},
79 {VCO_3_6, POSTDIV_DIV_BY_4, 112, 216, 160},
80 {VCO_2_4, POSTDIV_DIV_BY_2, 75, 160, 108},
81 {VCO_3_6, POSTDIV_DIV_BY_2, 112, 216, 160} };
82
83static int vegam_smu_init(struct pp_hwmgr *hwmgr)
84{
85 struct vegam_smumgr *smu_data;
86
87 smu_data = kzalloc(sizeof(struct vegam_smumgr), GFP_KERNEL);
88 if (smu_data == NULL)
89 return -ENOMEM;
90
91 hwmgr->smu_backend = smu_data;
92
93 if (smu7_init(hwmgr)) {
94 kfree(smu_data);
95 return -EINVAL;
96 }
97
98 return 0;
99}
100
101static int vegam_start_smu_in_protection_mode(struct pp_hwmgr *hwmgr)
102{
103 int result = 0;
104
105
106
107
108
109 PHM_WRITE_VFPF_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
110 SMC_SYSCON_RESET_CNTL, rst_reg, 1);
111
112 result = smu7_upload_smu_firmware_image(hwmgr);
113 if (result != 0)
114 return result;
115
116
117 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixSMU_STATUS, 0);
118
119 PHM_WRITE_VFPF_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
120 SMC_SYSCON_CLOCK_CNTL_0, ck_disable, 0);
121
122
123 PHM_WRITE_VFPF_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
124 SMC_SYSCON_RESET_CNTL, rst_reg, 0);
125
126
127 PHM_WAIT_VFPF_INDIRECT_FIELD(hwmgr, SMC_IND, RCU_UC_EVENTS, INTERRUPTS_ENABLED, 1);
128
129
130
131 smu7_send_msg_to_smc_offset(hwmgr);
132
133
134
135
136 PHM_WAIT_VFPF_INDIRECT_FIELD_UNEQUAL(hwmgr, SMC_IND, SMU_STATUS, SMU_DONE, 0);
137
138 if (1 != PHM_READ_VFPF_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
139 SMU_STATUS, SMU_PASS))
140 PP_ASSERT_WITH_CODE(false, "SMU Firmware start failed!", return -1);
141
142 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixFIRMWARE_FLAGS, 0);
143
144 PHM_WRITE_VFPF_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
145 SMC_SYSCON_RESET_CNTL, rst_reg, 1);
146
147 PHM_WRITE_VFPF_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
148 SMC_SYSCON_RESET_CNTL, rst_reg, 0);
149
150
151 PHM_WAIT_VFPF_INDIRECT_FIELD(hwmgr, SMC_IND, FIRMWARE_FLAGS, INTERRUPTS_ENABLED, 1);
152
153 return result;
154}
155
156static int vegam_start_smu_in_non_protection_mode(struct pp_hwmgr *hwmgr)
157{
158 int result = 0;
159
160
161 PHM_WAIT_VFPF_INDIRECT_FIELD_UNEQUAL(hwmgr, SMC_IND, RCU_UC_EVENTS, boot_seq_done, 0);
162
163
164
165 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
166 ixFIRMWARE_FLAGS, 0);
167
168 PHM_WRITE_VFPF_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
169 SMC_SYSCON_RESET_CNTL,
170 rst_reg, 1);
171
172 result = smu7_upload_smu_firmware_image(hwmgr);
173 if (result != 0)
174 return result;
175
176
177 smu7_program_jump_on_start(hwmgr);
178
179 PHM_WRITE_VFPF_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
180 SMC_SYSCON_CLOCK_CNTL_0, ck_disable, 0);
181
182 PHM_WRITE_VFPF_INDIRECT_FIELD(hwmgr->device, CGS_IND_REG__SMC,
183 SMC_SYSCON_RESET_CNTL, rst_reg, 0);
184
185
186
187 PHM_WAIT_VFPF_INDIRECT_FIELD(hwmgr, SMC_IND,
188 FIRMWARE_FLAGS, INTERRUPTS_ENABLED, 1);
189
190 return result;
191}
192
193static int vegam_start_smu(struct pp_hwmgr *hwmgr)
194{
195 int result = 0;
196 struct vegam_smumgr *smu_data = (struct vegam_smumgr *)(hwmgr->smu_backend);
197
198
199 if (!smu7_is_smc_ram_running(hwmgr) && hwmgr->not_vf) {
200 smu_data->protected_mode = (uint8_t)(PHM_READ_VFPF_INDIRECT_FIELD(hwmgr->device,
201 CGS_IND_REG__SMC, SMU_FIRMWARE, SMU_MODE));
202 smu_data->smu7_data.security_hard_key = (uint8_t)(PHM_READ_VFPF_INDIRECT_FIELD(
203 hwmgr->device, CGS_IND_REG__SMC, SMU_FIRMWARE, SMU_SEL));
204
205
206 if (smu_data->protected_mode == 0)
207 result = vegam_start_smu_in_non_protection_mode(hwmgr);
208 else
209 result = vegam_start_smu_in_protection_mode(hwmgr);
210
211 if (result != 0)
212 PP_ASSERT_WITH_CODE(0, "Failed to load SMU ucode.", return result);
213 }
214
215
216 smu7_read_smc_sram_dword(hwmgr,
217 SMU7_FIRMWARE_HEADER_LOCATION + offsetof(SMU75_Firmware_Header, SoftRegisters),
218 &(smu_data->smu7_data.soft_regs_start),
219 0x40000);
220
221 result = smu7_request_smu_load_fw(hwmgr);
222
223 return result;
224}
225
226static int vegam_process_firmware_header(struct pp_hwmgr *hwmgr)
227{
228 struct vegam_smumgr *smu_data = (struct vegam_smumgr *)(hwmgr->smu_backend);
229 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
230 uint32_t tmp;
231 int result;
232 bool error = false;
233
234 result = smu7_read_smc_sram_dword(hwmgr,
235 SMU7_FIRMWARE_HEADER_LOCATION +
236 offsetof(SMU75_Firmware_Header, DpmTable),
237 &tmp, SMC_RAM_END);
238
239 if (0 == result)
240 smu_data->smu7_data.dpm_table_start = tmp;
241
242 error |= (0 != result);
243
244 result = smu7_read_smc_sram_dword(hwmgr,
245 SMU7_FIRMWARE_HEADER_LOCATION +
246 offsetof(SMU75_Firmware_Header, SoftRegisters),
247 &tmp, SMC_RAM_END);
248
249 if (!result) {
250 data->soft_regs_start = tmp;
251 smu_data->smu7_data.soft_regs_start = tmp;
252 }
253
254 error |= (0 != result);
255
256 result = smu7_read_smc_sram_dword(hwmgr,
257 SMU7_FIRMWARE_HEADER_LOCATION +
258 offsetof(SMU75_Firmware_Header, mcRegisterTable),
259 &tmp, SMC_RAM_END);
260
261 if (!result)
262 smu_data->smu7_data.mc_reg_table_start = tmp;
263
264 result = smu7_read_smc_sram_dword(hwmgr,
265 SMU7_FIRMWARE_HEADER_LOCATION +
266 offsetof(SMU75_Firmware_Header, FanTable),
267 &tmp, SMC_RAM_END);
268
269 if (!result)
270 smu_data->smu7_data.fan_table_start = tmp;
271
272 error |= (0 != result);
273
274 result = smu7_read_smc_sram_dword(hwmgr,
275 SMU7_FIRMWARE_HEADER_LOCATION +
276 offsetof(SMU75_Firmware_Header, mcArbDramTimingTable),
277 &tmp, SMC_RAM_END);
278
279 if (!result)
280 smu_data->smu7_data.arb_table_start = tmp;
281
282 error |= (0 != result);
283
284 result = smu7_read_smc_sram_dword(hwmgr,
285 SMU7_FIRMWARE_HEADER_LOCATION +
286 offsetof(SMU75_Firmware_Header, Version),
287 &tmp, SMC_RAM_END);
288
289 if (!result)
290 hwmgr->microcode_version_info.SMC = tmp;
291
292 error |= (0 != result);
293
294 return error ? -1 : 0;
295}
296
297static bool vegam_is_dpm_running(struct pp_hwmgr *hwmgr)
298{
299 return (1 == PHM_READ_INDIRECT_FIELD(hwmgr->device,
300 CGS_IND_REG__SMC, FEATURE_STATUS, VOLTAGE_CONTROLLER_ON))
301 ? true : false;
302}
303
304static uint32_t vegam_get_mac_definition(uint32_t value)
305{
306 switch (value) {
307 case SMU_MAX_LEVELS_GRAPHICS:
308 return SMU75_MAX_LEVELS_GRAPHICS;
309 case SMU_MAX_LEVELS_MEMORY:
310 return SMU75_MAX_LEVELS_MEMORY;
311 case SMU_MAX_LEVELS_LINK:
312 return SMU75_MAX_LEVELS_LINK;
313 case SMU_MAX_ENTRIES_SMIO:
314 return SMU75_MAX_ENTRIES_SMIO;
315 case SMU_MAX_LEVELS_VDDC:
316 return SMU75_MAX_LEVELS_VDDC;
317 case SMU_MAX_LEVELS_VDDGFX:
318 return SMU75_MAX_LEVELS_VDDGFX;
319 case SMU_MAX_LEVELS_VDDCI:
320 return SMU75_MAX_LEVELS_VDDCI;
321 case SMU_MAX_LEVELS_MVDD:
322 return SMU75_MAX_LEVELS_MVDD;
323 case SMU_UVD_MCLK_HANDSHAKE_DISABLE:
324 return SMU7_UVD_MCLK_HANDSHAKE_DISABLE |
325 SMU7_VCE_MCLK_HANDSHAKE_DISABLE;
326 }
327
328 pr_warn("can't get the mac of %x\n", value);
329 return 0;
330}
331
332static int vegam_update_uvd_smc_table(struct pp_hwmgr *hwmgr)
333{
334 struct vegam_smumgr *smu_data = (struct vegam_smumgr *)(hwmgr->smu_backend);
335 uint32_t mm_boot_level_offset, mm_boot_level_value;
336 struct phm_ppt_v1_information *table_info =
337 (struct phm_ppt_v1_information *)(hwmgr->pptable);
338
339 smu_data->smc_state_table.UvdBootLevel = 0;
340 if (table_info->mm_dep_table->count > 0)
341 smu_data->smc_state_table.UvdBootLevel =
342 (uint8_t) (table_info->mm_dep_table->count - 1);
343 mm_boot_level_offset = smu_data->smu7_data.dpm_table_start + offsetof(SMU75_Discrete_DpmTable,
344 UvdBootLevel);
345 mm_boot_level_offset /= 4;
346 mm_boot_level_offset *= 4;
347 mm_boot_level_value = cgs_read_ind_register(hwmgr->device,
348 CGS_IND_REG__SMC, mm_boot_level_offset);
349 mm_boot_level_value &= 0x00FFFFFF;
350 mm_boot_level_value |= smu_data->smc_state_table.UvdBootLevel << 24;
351 cgs_write_ind_register(hwmgr->device,
352 CGS_IND_REG__SMC, mm_boot_level_offset, mm_boot_level_value);
353
354 if (!phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
355 PHM_PlatformCaps_UVDDPM) ||
356 phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
357 PHM_PlatformCaps_StablePState))
358 smum_send_msg_to_smc_with_parameter(hwmgr,
359 PPSMC_MSG_UVDDPM_SetEnabledMask,
360 (uint32_t)(1 << smu_data->smc_state_table.UvdBootLevel));
361 return 0;
362}
363
364static int vegam_update_vce_smc_table(struct pp_hwmgr *hwmgr)
365{
366 struct vegam_smumgr *smu_data = (struct vegam_smumgr *)(hwmgr->smu_backend);
367 uint32_t mm_boot_level_offset, mm_boot_level_value;
368 struct phm_ppt_v1_information *table_info =
369 (struct phm_ppt_v1_information *)(hwmgr->pptable);
370
371 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
372 PHM_PlatformCaps_StablePState))
373 smu_data->smc_state_table.VceBootLevel =
374 (uint8_t) (table_info->mm_dep_table->count - 1);
375 else
376 smu_data->smc_state_table.VceBootLevel = 0;
377
378 mm_boot_level_offset = smu_data->smu7_data.dpm_table_start +
379 offsetof(SMU75_Discrete_DpmTable, VceBootLevel);
380 mm_boot_level_offset /= 4;
381 mm_boot_level_offset *= 4;
382 mm_boot_level_value = cgs_read_ind_register(hwmgr->device,
383 CGS_IND_REG__SMC, mm_boot_level_offset);
384 mm_boot_level_value &= 0xFF00FFFF;
385 mm_boot_level_value |= smu_data->smc_state_table.VceBootLevel << 16;
386 cgs_write_ind_register(hwmgr->device,
387 CGS_IND_REG__SMC, mm_boot_level_offset, mm_boot_level_value);
388
389 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_StablePState))
390 smum_send_msg_to_smc_with_parameter(hwmgr,
391 PPSMC_MSG_VCEDPM_SetEnabledMask,
392 (uint32_t)1 << smu_data->smc_state_table.VceBootLevel);
393 return 0;
394}
395
396static int vegam_update_bif_smc_table(struct pp_hwmgr *hwmgr)
397{
398 struct vegam_smumgr *smu_data = (struct vegam_smumgr *)(hwmgr->smu_backend);
399 struct phm_ppt_v1_information *table_info =
400 (struct phm_ppt_v1_information *)(hwmgr->pptable);
401 struct phm_ppt_v1_pcie_table *pcie_table = table_info->pcie_table;
402 int max_entry, i;
403
404 max_entry = (SMU75_MAX_LEVELS_LINK < pcie_table->count) ?
405 SMU75_MAX_LEVELS_LINK :
406 pcie_table->count;
407
408 for (i = 0; i < max_entry; i++)
409 smu_data->bif_sclk_table[i] = pcie_table->entries[i].pcie_sclk;
410 return 0;
411}
412
413static int vegam_update_smc_table(struct pp_hwmgr *hwmgr, uint32_t type)
414{
415 switch (type) {
416 case SMU_UVD_TABLE:
417 vegam_update_uvd_smc_table(hwmgr);
418 break;
419 case SMU_VCE_TABLE:
420 vegam_update_vce_smc_table(hwmgr);
421 break;
422 case SMU_BIF_TABLE:
423 vegam_update_bif_smc_table(hwmgr);
424 break;
425 default:
426 break;
427 }
428 return 0;
429}
430
431static void vegam_initialize_power_tune_defaults(struct pp_hwmgr *hwmgr)
432{
433 struct vegam_smumgr *smu_data = (struct vegam_smumgr *)(hwmgr->smu_backend);
434 struct phm_ppt_v1_information *table_info =
435 (struct phm_ppt_v1_information *)(hwmgr->pptable);
436
437 if (table_info &&
438 table_info->cac_dtp_table->usPowerTuneDataSetID <= POWERTUNE_DEFAULT_SET_MAX &&
439 table_info->cac_dtp_table->usPowerTuneDataSetID)
440 smu_data->power_tune_defaults =
441 &vegam_power_tune_data_set_array
442 [table_info->cac_dtp_table->usPowerTuneDataSetID - 1];
443 else
444 smu_data->power_tune_defaults = &vegam_power_tune_data_set_array[0];
445
446}
447
448static int vegam_populate_smc_mvdd_table(struct pp_hwmgr *hwmgr,
449 SMU75_Discrete_DpmTable *table)
450{
451 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
452 uint32_t count, level;
453
454 if (SMU7_VOLTAGE_CONTROL_BY_GPIO == data->mvdd_control) {
455 count = data->mvdd_voltage_table.count;
456 if (count > SMU_MAX_SMIO_LEVELS)
457 count = SMU_MAX_SMIO_LEVELS;
458 for (level = 0; level < count; level++) {
459 table->SmioTable2.Pattern[level].Voltage = PP_HOST_TO_SMC_US(
460 data->mvdd_voltage_table.entries[count].value * VOLTAGE_SCALE);
461
462 table->SmioTable2.Pattern[level].Smio =
463 (uint8_t) level;
464 table->Smio[level] |=
465 data->mvdd_voltage_table.entries[level].smio_low;
466 }
467 table->SmioMask2 = data->mvdd_voltage_table.mask_low;
468
469 table->MvddLevelCount = (uint32_t) PP_HOST_TO_SMC_UL(count);
470 }
471
472 return 0;
473}
474
475static int vegam_populate_smc_vddci_table(struct pp_hwmgr *hwmgr,
476 struct SMU75_Discrete_DpmTable *table)
477{
478 uint32_t count, level;
479 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
480
481 count = data->vddci_voltage_table.count;
482
483 if (SMU7_VOLTAGE_CONTROL_BY_GPIO == data->vddci_control) {
484 if (count > SMU_MAX_SMIO_LEVELS)
485 count = SMU_MAX_SMIO_LEVELS;
486 for (level = 0; level < count; ++level) {
487 table->SmioTable1.Pattern[level].Voltage = PP_HOST_TO_SMC_US(
488 data->vddci_voltage_table.entries[level].value * VOLTAGE_SCALE);
489 table->SmioTable1.Pattern[level].Smio = (uint8_t) level;
490
491 table->Smio[level] |= data->vddci_voltage_table.entries[level].smio_low;
492 }
493 }
494
495 table->SmioMask1 = data->vddci_voltage_table.mask_low;
496
497 return 0;
498}
499
500static int vegam_populate_cac_table(struct pp_hwmgr *hwmgr,
501 struct SMU75_Discrete_DpmTable *table)
502{
503 uint32_t count;
504 uint8_t index;
505 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
506 struct phm_ppt_v1_information *table_info =
507 (struct phm_ppt_v1_information *)(hwmgr->pptable);
508 struct phm_ppt_v1_voltage_lookup_table *lookup_table =
509 table_info->vddc_lookup_table;
510
511
512
513
514
515 for (count = 0; count < lookup_table->count; count++) {
516 index = phm_get_voltage_index(lookup_table,
517 data->vddc_voltage_table.entries[count].value);
518 table->BapmVddcVidLoSidd[count] =
519 convert_to_vid(lookup_table->entries[index].us_cac_low);
520 table->BapmVddcVidHiSidd[count] =
521 convert_to_vid(lookup_table->entries[index].us_cac_mid);
522 table->BapmVddcVidHiSidd2[count] =
523 convert_to_vid(lookup_table->entries[index].us_cac_high);
524 }
525
526 return 0;
527}
528
529static int vegam_populate_smc_voltage_tables(struct pp_hwmgr *hwmgr,
530 struct SMU75_Discrete_DpmTable *table)
531{
532 vegam_populate_smc_vddci_table(hwmgr, table);
533 vegam_populate_smc_mvdd_table(hwmgr, table);
534 vegam_populate_cac_table(hwmgr, table);
535
536 return 0;
537}
538
539static int vegam_populate_ulv_level(struct pp_hwmgr *hwmgr,
540 struct SMU75_Discrete_Ulv *state)
541{
542 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
543 struct phm_ppt_v1_information *table_info =
544 (struct phm_ppt_v1_information *)(hwmgr->pptable);
545
546 state->CcPwrDynRm = 0;
547 state->CcPwrDynRm1 = 0;
548
549 state->VddcOffset = (uint16_t) table_info->us_ulv_voltage_offset;
550 state->VddcOffsetVid = (uint8_t)(table_info->us_ulv_voltage_offset *
551 VOLTAGE_VID_OFFSET_SCALE2 / VOLTAGE_VID_OFFSET_SCALE1);
552
553 state->VddcPhase = data->vddc_phase_shed_control ^ 0x3;
554
555 CONVERT_FROM_HOST_TO_SMC_UL(state->CcPwrDynRm);
556 CONVERT_FROM_HOST_TO_SMC_UL(state->CcPwrDynRm1);
557 CONVERT_FROM_HOST_TO_SMC_US(state->VddcOffset);
558
559 return 0;
560}
561
562static int vegam_populate_ulv_state(struct pp_hwmgr *hwmgr,
563 struct SMU75_Discrete_DpmTable *table)
564{
565 return vegam_populate_ulv_level(hwmgr, &table->Ulv);
566}
567
568static int vegam_populate_smc_link_level(struct pp_hwmgr *hwmgr,
569 struct SMU75_Discrete_DpmTable *table)
570{
571 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
572 struct vegam_smumgr *smu_data =
573 (struct vegam_smumgr *)(hwmgr->smu_backend);
574 struct smu7_dpm_table *dpm_table = &data->dpm_table;
575 int i;
576
577
578
579 for (i = 0; i <= dpm_table->pcie_speed_table.count; i++) {
580 table->LinkLevel[i].PcieGenSpeed =
581 (uint8_t)dpm_table->pcie_speed_table.dpm_levels[i].value;
582 table->LinkLevel[i].PcieLaneCount = (uint8_t)encode_pcie_lane_width(
583 dpm_table->pcie_speed_table.dpm_levels[i].param1);
584 table->LinkLevel[i].EnabledForActivity = 1;
585 table->LinkLevel[i].SPC = (uint8_t)(data->pcie_spc_cap & 0xff);
586 table->LinkLevel[i].DownThreshold = PP_HOST_TO_SMC_UL(5);
587 table->LinkLevel[i].UpThreshold = PP_HOST_TO_SMC_UL(30);
588 }
589
590 smu_data->smc_state_table.LinkLevelCount =
591 (uint8_t)dpm_table->pcie_speed_table.count;
592
593
594 data->dpm_level_enable_mask.pcie_dpm_enable_mask =
595 phm_get_dpm_level_enable_mask_value(&dpm_table->pcie_speed_table);
596
597 return 0;
598}
599
600static int vegam_get_dependency_volt_by_clk(struct pp_hwmgr *hwmgr,
601 struct phm_ppt_v1_clock_voltage_dependency_table *dep_table,
602 uint32_t clock, SMU_VoltageLevel *voltage, uint32_t *mvdd)
603{
604 uint32_t i;
605 uint16_t vddci;
606 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
607
608 *voltage = *mvdd = 0;
609
610
611 if (dep_table->count == 0)
612 return -EINVAL;
613
614 for (i = 0; i < dep_table->count; i++) {
615
616 if (dep_table->entries[i].clk >= clock) {
617 *voltage |= (dep_table->entries[i].vddc *
618 VOLTAGE_SCALE) << VDDC_SHIFT;
619 if (SMU7_VOLTAGE_CONTROL_NONE == data->vddci_control)
620 *voltage |= (data->vbios_boot_state.vddci_bootup_value *
621 VOLTAGE_SCALE) << VDDCI_SHIFT;
622 else if (dep_table->entries[i].vddci)
623 *voltage |= (dep_table->entries[i].vddci *
624 VOLTAGE_SCALE) << VDDCI_SHIFT;
625 else {
626 vddci = phm_find_closest_vddci(&(data->vddci_voltage_table),
627 (dep_table->entries[i].vddc -
628 (uint16_t)VDDC_VDDCI_DELTA));
629 *voltage |= (vddci * VOLTAGE_SCALE) << VDDCI_SHIFT;
630 }
631
632 if (SMU7_VOLTAGE_CONTROL_NONE == data->mvdd_control)
633 *mvdd = data->vbios_boot_state.mvdd_bootup_value *
634 VOLTAGE_SCALE;
635 else if (dep_table->entries[i].mvdd)
636 *mvdd = (uint32_t) dep_table->entries[i].mvdd *
637 VOLTAGE_SCALE;
638
639 *voltage |= 1 << PHASES_SHIFT;
640 return 0;
641 }
642 }
643
644
645 *voltage |= (dep_table->entries[i - 1].vddc * VOLTAGE_SCALE) << VDDC_SHIFT;
646 vddci = phm_find_closest_vddci(&(data->vddci_voltage_table),
647 (dep_table->entries[i - 1].vddc -
648 (uint16_t)VDDC_VDDCI_DELTA));
649
650 if (SMU7_VOLTAGE_CONTROL_NONE == data->vddci_control)
651 *voltage |= (data->vbios_boot_state.vddci_bootup_value *
652 VOLTAGE_SCALE) << VDDCI_SHIFT;
653 else if (dep_table->entries[i - 1].vddci)
654 *voltage |= (dep_table->entries[i - 1].vddci *
655 VOLTAGE_SCALE) << VDDC_SHIFT;
656 else
657 *voltage |= (vddci * VOLTAGE_SCALE) << VDDCI_SHIFT;
658
659 if (SMU7_VOLTAGE_CONTROL_NONE == data->mvdd_control)
660 *mvdd = data->vbios_boot_state.mvdd_bootup_value * VOLTAGE_SCALE;
661 else if (dep_table->entries[i].mvdd)
662 *mvdd = (uint32_t) dep_table->entries[i - 1].mvdd * VOLTAGE_SCALE;
663
664 return 0;
665}
666
667static void vegam_get_sclk_range_table(struct pp_hwmgr *hwmgr,
668 SMU75_Discrete_DpmTable *table)
669{
670 struct vegam_smumgr *smu_data = (struct vegam_smumgr *)(hwmgr->smu_backend);
671 uint32_t i, ref_clk;
672
673 struct pp_atom_ctrl_sclk_range_table range_table_from_vbios = { { {0} } };
674
675 ref_clk = amdgpu_asic_get_xclk((struct amdgpu_device *)hwmgr->adev);
676
677 if (0 == atomctrl_get_smc_sclk_range_table(hwmgr, &range_table_from_vbios)) {
678 for (i = 0; i < NUM_SCLK_RANGE; i++) {
679 table->SclkFcwRangeTable[i].vco_setting =
680 range_table_from_vbios.entry[i].ucVco_setting;
681 table->SclkFcwRangeTable[i].postdiv =
682 range_table_from_vbios.entry[i].ucPostdiv;
683 table->SclkFcwRangeTable[i].fcw_pcc =
684 range_table_from_vbios.entry[i].usFcw_pcc;
685
686 table->SclkFcwRangeTable[i].fcw_trans_upper =
687 range_table_from_vbios.entry[i].usFcw_trans_upper;
688 table->SclkFcwRangeTable[i].fcw_trans_lower =
689 range_table_from_vbios.entry[i].usRcw_trans_lower;
690
691 CONVERT_FROM_HOST_TO_SMC_US(table->SclkFcwRangeTable[i].fcw_pcc);
692 CONVERT_FROM_HOST_TO_SMC_US(table->SclkFcwRangeTable[i].fcw_trans_upper);
693 CONVERT_FROM_HOST_TO_SMC_US(table->SclkFcwRangeTable[i].fcw_trans_lower);
694 }
695 return;
696 }
697
698 for (i = 0; i < NUM_SCLK_RANGE; i++) {
699 smu_data->range_table[i].trans_lower_frequency =
700 (ref_clk * Range_Table[i].fcw_trans_lower) >> Range_Table[i].postdiv;
701 smu_data->range_table[i].trans_upper_frequency =
702 (ref_clk * Range_Table[i].fcw_trans_upper) >> Range_Table[i].postdiv;
703
704 table->SclkFcwRangeTable[i].vco_setting = Range_Table[i].vco_setting;
705 table->SclkFcwRangeTable[i].postdiv = Range_Table[i].postdiv;
706 table->SclkFcwRangeTable[i].fcw_pcc = Range_Table[i].fcw_pcc;
707
708 table->SclkFcwRangeTable[i].fcw_trans_upper = Range_Table[i].fcw_trans_upper;
709 table->SclkFcwRangeTable[i].fcw_trans_lower = Range_Table[i].fcw_trans_lower;
710
711 CONVERT_FROM_HOST_TO_SMC_US(table->SclkFcwRangeTable[i].fcw_pcc);
712 CONVERT_FROM_HOST_TO_SMC_US(table->SclkFcwRangeTable[i].fcw_trans_upper);
713 CONVERT_FROM_HOST_TO_SMC_US(table->SclkFcwRangeTable[i].fcw_trans_lower);
714 }
715}
716
717static int vegam_calculate_sclk_params(struct pp_hwmgr *hwmgr,
718 uint32_t clock, SMU_SclkSetting *sclk_setting)
719{
720 struct vegam_smumgr *smu_data = (struct vegam_smumgr *)(hwmgr->smu_backend);
721 const SMU75_Discrete_DpmTable *table = &(smu_data->smc_state_table);
722 struct pp_atomctrl_clock_dividers_ai dividers;
723 uint32_t ref_clock;
724 uint32_t pcc_target_percent, pcc_target_freq, ss_target_percent, ss_target_freq;
725 uint8_t i;
726 int result;
727 uint64_t temp;
728
729 sclk_setting->SclkFrequency = clock;
730
731 result = atomctrl_get_engine_pll_dividers_ai(hwmgr, clock, ÷rs);
732 if (result == 0) {
733 sclk_setting->Fcw_int = dividers.usSclk_fcw_int;
734 sclk_setting->Fcw_frac = dividers.usSclk_fcw_frac;
735 sclk_setting->Pcc_fcw_int = dividers.usPcc_fcw_int;
736 sclk_setting->PllRange = dividers.ucSclkPllRange;
737 sclk_setting->Sclk_slew_rate = 0x400;
738 sclk_setting->Pcc_up_slew_rate = dividers.usPcc_fcw_slew_frac;
739 sclk_setting->Pcc_down_slew_rate = 0xffff;
740 sclk_setting->SSc_En = dividers.ucSscEnable;
741 sclk_setting->Fcw1_int = dividers.usSsc_fcw1_int;
742 sclk_setting->Fcw1_frac = dividers.usSsc_fcw1_frac;
743 sclk_setting->Sclk_ss_slew_rate = dividers.usSsc_fcw_slew_frac;
744 return result;
745 }
746
747 ref_clock = amdgpu_asic_get_xclk((struct amdgpu_device *)hwmgr->adev);
748
749 for (i = 0; i < NUM_SCLK_RANGE; i++) {
750 if (clock > smu_data->range_table[i].trans_lower_frequency
751 && clock <= smu_data->range_table[i].trans_upper_frequency) {
752 sclk_setting->PllRange = i;
753 break;
754 }
755 }
756
757 sclk_setting->Fcw_int = (uint16_t)
758 ((clock << table->SclkFcwRangeTable[sclk_setting->PllRange].postdiv) /
759 ref_clock);
760 temp = clock << table->SclkFcwRangeTable[sclk_setting->PllRange].postdiv;
761 temp <<= 0x10;
762 do_div(temp, ref_clock);
763 sclk_setting->Fcw_frac = temp & 0xffff;
764
765 pcc_target_percent = 10;
766 pcc_target_freq = clock - (clock * pcc_target_percent / 100);
767 sclk_setting->Pcc_fcw_int = (uint16_t)
768 ((pcc_target_freq << table->SclkFcwRangeTable[sclk_setting->PllRange].postdiv) /
769 ref_clock);
770
771 ss_target_percent = 2;
772 sclk_setting->SSc_En = 0;
773 if (ss_target_percent) {
774 sclk_setting->SSc_En = 1;
775 ss_target_freq = clock - (clock * ss_target_percent / 100);
776 sclk_setting->Fcw1_int = (uint16_t)
777 ((ss_target_freq << table->SclkFcwRangeTable[sclk_setting->PllRange].postdiv) /
778 ref_clock);
779 temp = ss_target_freq << table->SclkFcwRangeTable[sclk_setting->PllRange].postdiv;
780 temp <<= 0x10;
781 do_div(temp, ref_clock);
782 sclk_setting->Fcw1_frac = temp & 0xffff;
783 }
784
785 return 0;
786}
787
788static uint8_t vegam_get_sleep_divider_id_from_clock(uint32_t clock,
789 uint32_t clock_insr)
790{
791 uint8_t i;
792 uint32_t temp;
793 uint32_t min = max(clock_insr, (uint32_t)SMU7_MINIMUM_ENGINE_CLOCK);
794
795 PP_ASSERT_WITH_CODE((clock >= min),
796 "Engine clock can't satisfy stutter requirement!",
797 return 0);
798 for (i = 31; ; i--) {
799 temp = clock / (i + 1);
800
801 if (temp >= min || i == 0)
802 break;
803 }
804 return i;
805}
806
807static int vegam_populate_single_graphic_level(struct pp_hwmgr *hwmgr,
808 uint32_t clock, struct SMU75_Discrete_GraphicsLevel *level)
809{
810 int result;
811
812 uint32_t mvdd;
813 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
814 struct phm_ppt_v1_information *table_info =
815 (struct phm_ppt_v1_information *)(hwmgr->pptable);
816 SMU_SclkSetting curr_sclk_setting = { 0 };
817
818 result = vegam_calculate_sclk_params(hwmgr, clock, &curr_sclk_setting);
819
820
821 result = vegam_get_dependency_volt_by_clk(hwmgr,
822 table_info->vdd_dep_on_sclk, clock,
823 &level->MinVoltage, &mvdd);
824
825 PP_ASSERT_WITH_CODE((0 == result),
826 "can not find VDDC voltage value for "
827 "VDDC engine clock dependency table",
828 return result);
829 level->ActivityLevel = (uint16_t)(SclkDPMTuning_VEGAM >> DPMTuning_Activity_Shift);
830
831 level->CcPwrDynRm = 0;
832 level->CcPwrDynRm1 = 0;
833 level->EnabledForActivity = 0;
834 level->EnabledForThrottle = 1;
835 level->VoltageDownHyst = 0;
836 level->PowerThrottle = 0;
837 data->display_timing.min_clock_in_sr = hwmgr->display_config->min_core_set_clock_in_sr;
838
839 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_SclkDeepSleep))
840 level->DeepSleepDivId = vegam_get_sleep_divider_id_from_clock(clock,
841 hwmgr->display_config->min_core_set_clock_in_sr);
842
843 level->SclkSetting = curr_sclk_setting;
844
845 CONVERT_FROM_HOST_TO_SMC_UL(level->MinVoltage);
846 CONVERT_FROM_HOST_TO_SMC_UL(level->CcPwrDynRm);
847 CONVERT_FROM_HOST_TO_SMC_UL(level->CcPwrDynRm1);
848 CONVERT_FROM_HOST_TO_SMC_US(level->ActivityLevel);
849 CONVERT_FROM_HOST_TO_SMC_UL(level->SclkSetting.SclkFrequency);
850 CONVERT_FROM_HOST_TO_SMC_US(level->SclkSetting.Fcw_int);
851 CONVERT_FROM_HOST_TO_SMC_US(level->SclkSetting.Fcw_frac);
852 CONVERT_FROM_HOST_TO_SMC_US(level->SclkSetting.Pcc_fcw_int);
853 CONVERT_FROM_HOST_TO_SMC_US(level->SclkSetting.Sclk_slew_rate);
854 CONVERT_FROM_HOST_TO_SMC_US(level->SclkSetting.Pcc_up_slew_rate);
855 CONVERT_FROM_HOST_TO_SMC_US(level->SclkSetting.Pcc_down_slew_rate);
856 CONVERT_FROM_HOST_TO_SMC_US(level->SclkSetting.Fcw1_int);
857 CONVERT_FROM_HOST_TO_SMC_US(level->SclkSetting.Fcw1_frac);
858 CONVERT_FROM_HOST_TO_SMC_US(level->SclkSetting.Sclk_ss_slew_rate);
859 return 0;
860}
861
862static int vegam_populate_all_graphic_levels(struct pp_hwmgr *hwmgr)
863{
864 struct smu7_hwmgr *hw_data = (struct smu7_hwmgr *)(hwmgr->backend);
865 struct vegam_smumgr *smu_data = (struct vegam_smumgr *)(hwmgr->smu_backend);
866 struct smu7_dpm_table *dpm_table = &hw_data->dpm_table;
867 struct phm_ppt_v1_information *table_info =
868 (struct phm_ppt_v1_information *)(hwmgr->pptable);
869 struct phm_ppt_v1_pcie_table *pcie_table = table_info->pcie_table;
870 uint8_t pcie_entry_cnt = (uint8_t) hw_data->dpm_table.pcie_speed_table.count;
871 int result = 0;
872 uint32_t array = smu_data->smu7_data.dpm_table_start +
873 offsetof(SMU75_Discrete_DpmTable, GraphicsLevel);
874 uint32_t array_size = sizeof(struct SMU75_Discrete_GraphicsLevel) *
875 SMU75_MAX_LEVELS_GRAPHICS;
876 struct SMU75_Discrete_GraphicsLevel *levels =
877 smu_data->smc_state_table.GraphicsLevel;
878 uint32_t i, max_entry;
879 uint8_t hightest_pcie_level_enabled = 0,
880 lowest_pcie_level_enabled = 0,
881 mid_pcie_level_enabled = 0,
882 count = 0;
883
884 vegam_get_sclk_range_table(hwmgr, &(smu_data->smc_state_table));
885
886 for (i = 0; i < dpm_table->sclk_table.count; i++) {
887
888 result = vegam_populate_single_graphic_level(hwmgr,
889 dpm_table->sclk_table.dpm_levels[i].value,
890 &(smu_data->smc_state_table.GraphicsLevel[i]));
891 if (result)
892 return result;
893
894 levels[i].UpHyst = (uint8_t)
895 (SclkDPMTuning_VEGAM >> DPMTuning_Uphyst_Shift);
896 levels[i].DownHyst = (uint8_t)
897 (SclkDPMTuning_VEGAM >> DPMTuning_Downhyst_Shift);
898
899 if (i > 1)
900 levels[i].DeepSleepDivId = 0;
901 }
902 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
903 PHM_PlatformCaps_SPLLShutdownSupport))
904 smu_data->smc_state_table.GraphicsLevel[0].SclkSetting.SSc_En = 0;
905
906 smu_data->smc_state_table.GraphicsDpmLevelCount =
907 (uint8_t)dpm_table->sclk_table.count;
908 hw_data->dpm_level_enable_mask.sclk_dpm_enable_mask =
909 phm_get_dpm_level_enable_mask_value(&dpm_table->sclk_table);
910
911 for (i = 0; i < dpm_table->sclk_table.count; i++)
912 levels[i].EnabledForActivity =
913 (hw_data->dpm_level_enable_mask.sclk_dpm_enable_mask >> i) & 0x1;
914
915 if (pcie_table != NULL) {
916 PP_ASSERT_WITH_CODE((1 <= pcie_entry_cnt),
917 "There must be 1 or more PCIE levels defined in PPTable.",
918 return -EINVAL);
919 max_entry = pcie_entry_cnt - 1;
920 for (i = 0; i < dpm_table->sclk_table.count; i++)
921 levels[i].pcieDpmLevel =
922 (uint8_t) ((i < max_entry) ? i : max_entry);
923 } else {
924 while (hw_data->dpm_level_enable_mask.pcie_dpm_enable_mask &&
925 ((hw_data->dpm_level_enable_mask.pcie_dpm_enable_mask &
926 (1 << (hightest_pcie_level_enabled + 1))) != 0))
927 hightest_pcie_level_enabled++;
928
929 while (hw_data->dpm_level_enable_mask.pcie_dpm_enable_mask &&
930 ((hw_data->dpm_level_enable_mask.pcie_dpm_enable_mask &
931 (1 << lowest_pcie_level_enabled)) == 0))
932 lowest_pcie_level_enabled++;
933
934 while ((count < hightest_pcie_level_enabled) &&
935 ((hw_data->dpm_level_enable_mask.pcie_dpm_enable_mask &
936 (1 << (lowest_pcie_level_enabled + 1 + count))) == 0))
937 count++;
938
939 mid_pcie_level_enabled = (lowest_pcie_level_enabled + 1 + count) <
940 hightest_pcie_level_enabled ?
941 (lowest_pcie_level_enabled + 1 + count) :
942 hightest_pcie_level_enabled;
943
944
945 for (i = 2; i < dpm_table->sclk_table.count; i++)
946 levels[i].pcieDpmLevel = hightest_pcie_level_enabled;
947
948
949 levels[0].pcieDpmLevel = lowest_pcie_level_enabled;
950
951
952 levels[1].pcieDpmLevel = mid_pcie_level_enabled;
953 }
954
955 result = smu7_copy_bytes_to_smc(hwmgr, array, (uint8_t *)levels,
956 (uint32_t)array_size, SMC_RAM_END);
957
958 return result;
959}
960
961static int vegam_calculate_mclk_params(struct pp_hwmgr *hwmgr,
962 uint32_t clock, struct SMU75_Discrete_MemoryLevel *mem_level)
963{
964 struct pp_atomctrl_memory_clock_param_ai mpll_param;
965
966 PP_ASSERT_WITH_CODE(!atomctrl_get_memory_pll_dividers_ai(hwmgr,
967 clock, &mpll_param),
968 "Failed to retrieve memory pll parameter.",
969 return -EINVAL);
970
971 mem_level->MclkFrequency = (uint32_t)mpll_param.ulClock;
972 mem_level->Fcw_int = (uint16_t)mpll_param.ulMclk_fcw_int;
973 mem_level->Fcw_frac = (uint16_t)mpll_param.ulMclk_fcw_frac;
974 mem_level->Postdiv = (uint8_t)mpll_param.ulPostDiv;
975
976 return 0;
977}
978
979static int vegam_populate_single_memory_level(struct pp_hwmgr *hwmgr,
980 uint32_t clock, struct SMU75_Discrete_MemoryLevel *mem_level)
981{
982 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
983 struct phm_ppt_v1_information *table_info =
984 (struct phm_ppt_v1_information *)(hwmgr->pptable);
985 int result = 0;
986 uint32_t mclk_stutter_mode_threshold = 60000;
987
988
989 if (table_info->vdd_dep_on_mclk) {
990 result = vegam_get_dependency_volt_by_clk(hwmgr,
991 table_info->vdd_dep_on_mclk, clock,
992 &mem_level->MinVoltage, &mem_level->MinMvdd);
993 PP_ASSERT_WITH_CODE(!result,
994 "can not find MinVddc voltage value from memory "
995 "VDDC voltage dependency table", return result);
996 }
997
998 result = vegam_calculate_mclk_params(hwmgr, clock, mem_level);
999 PP_ASSERT_WITH_CODE(!result,
1000 "Failed to calculate mclk params.",
1001 return -EINVAL);
1002
1003 mem_level->EnabledForThrottle = 1;
1004 mem_level->EnabledForActivity = 0;
1005 mem_level->VoltageDownHyst = 0;
1006 mem_level->ActivityLevel = (uint16_t)
1007 (MemoryDPMTuning_VEGAM >> DPMTuning_Activity_Shift);
1008 mem_level->StutterEnable = false;
1009 mem_level->DisplayWatermark = PPSMC_DISPLAY_WATERMARK_LOW;
1010
1011 data->display_timing.num_existing_displays = hwmgr->display_config->num_display;
1012 data->display_timing.vrefresh = hwmgr->display_config->vrefresh;
1013
1014 if (mclk_stutter_mode_threshold &&
1015 (clock <= mclk_stutter_mode_threshold) &&
1016 (PHM_READ_FIELD(hwmgr->device, DPG_PIPE_STUTTER_CONTROL,
1017 STUTTER_ENABLE) & 0x1))
1018 mem_level->StutterEnable = true;
1019
1020 if (!result) {
1021 CONVERT_FROM_HOST_TO_SMC_UL(mem_level->MinMvdd);
1022 CONVERT_FROM_HOST_TO_SMC_UL(mem_level->MclkFrequency);
1023 CONVERT_FROM_HOST_TO_SMC_US(mem_level->Fcw_int);
1024 CONVERT_FROM_HOST_TO_SMC_US(mem_level->Fcw_frac);
1025 CONVERT_FROM_HOST_TO_SMC_US(mem_level->ActivityLevel);
1026 CONVERT_FROM_HOST_TO_SMC_UL(mem_level->MinVoltage);
1027 }
1028
1029 return result;
1030}
1031
1032static int vegam_populate_all_memory_levels(struct pp_hwmgr *hwmgr)
1033{
1034 struct smu7_hwmgr *hw_data = (struct smu7_hwmgr *)(hwmgr->backend);
1035 struct vegam_smumgr *smu_data = (struct vegam_smumgr *)(hwmgr->smu_backend);
1036 struct smu7_dpm_table *dpm_table = &hw_data->dpm_table;
1037 int result;
1038
1039 uint32_t array = smu_data->smu7_data.dpm_table_start +
1040 offsetof(SMU75_Discrete_DpmTable, MemoryLevel);
1041 uint32_t array_size = sizeof(SMU75_Discrete_MemoryLevel) *
1042 SMU75_MAX_LEVELS_MEMORY;
1043 struct SMU75_Discrete_MemoryLevel *levels =
1044 smu_data->smc_state_table.MemoryLevel;
1045 uint32_t i;
1046
1047 for (i = 0; i < dpm_table->mclk_table.count; i++) {
1048 PP_ASSERT_WITH_CODE((0 != dpm_table->mclk_table.dpm_levels[i].value),
1049 "can not populate memory level as memory clock is zero",
1050 return -EINVAL);
1051 result = vegam_populate_single_memory_level(hwmgr,
1052 dpm_table->mclk_table.dpm_levels[i].value,
1053 &levels[i]);
1054
1055 if (result)
1056 return result;
1057
1058 levels[i].UpHyst = (uint8_t)
1059 (MemoryDPMTuning_VEGAM >> DPMTuning_Uphyst_Shift);
1060 levels[i].DownHyst = (uint8_t)
1061 (MemoryDPMTuning_VEGAM >> DPMTuning_Downhyst_Shift);
1062 }
1063
1064 smu_data->smc_state_table.MemoryDpmLevelCount =
1065 (uint8_t)dpm_table->mclk_table.count;
1066 hw_data->dpm_level_enable_mask.mclk_dpm_enable_mask =
1067 phm_get_dpm_level_enable_mask_value(&dpm_table->mclk_table);
1068
1069 for (i = 0; i < dpm_table->mclk_table.count; i++)
1070 levels[i].EnabledForActivity =
1071 (hw_data->dpm_level_enable_mask.mclk_dpm_enable_mask >> i) & 0x1;
1072
1073 levels[dpm_table->mclk_table.count - 1].DisplayWatermark =
1074 PPSMC_DISPLAY_WATERMARK_HIGH;
1075
1076
1077 result = smu7_copy_bytes_to_smc(hwmgr, array, (uint8_t *)levels,
1078 (uint32_t)array_size, SMC_RAM_END);
1079
1080 return result;
1081}
1082
1083static int vegam_populate_mvdd_value(struct pp_hwmgr *hwmgr,
1084 uint32_t mclk, SMIO_Pattern *smio_pat)
1085{
1086 const struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
1087 struct phm_ppt_v1_information *table_info =
1088 (struct phm_ppt_v1_information *)(hwmgr->pptable);
1089 uint32_t i = 0;
1090
1091 if (SMU7_VOLTAGE_CONTROL_NONE != data->mvdd_control) {
1092
1093 for (i = 0; i < table_info->vdd_dep_on_mclk->count; i++) {
1094 if (mclk <= table_info->vdd_dep_on_mclk->entries[i].clk) {
1095 smio_pat->Voltage = data->mvdd_voltage_table.entries[i].value;
1096 break;
1097 }
1098 }
1099 PP_ASSERT_WITH_CODE(i < table_info->vdd_dep_on_mclk->count,
1100 "MVDD Voltage is outside the supported range.",
1101 return -EINVAL);
1102 } else
1103 return -EINVAL;
1104
1105 return 0;
1106}
1107
1108static int vegam_populate_smc_acpi_level(struct pp_hwmgr *hwmgr,
1109 SMU75_Discrete_DpmTable *table)
1110{
1111 int result = 0;
1112 uint32_t sclk_frequency;
1113 const struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
1114 struct phm_ppt_v1_information *table_info =
1115 (struct phm_ppt_v1_information *)(hwmgr->pptable);
1116 SMIO_Pattern vol_level;
1117 uint32_t mvdd;
1118 uint16_t us_mvdd;
1119
1120 table->ACPILevel.Flags &= ~PPSMC_SWSTATE_FLAG_DC;
1121
1122
1123
1124 sclk_frequency = data->vbios_boot_state.sclk_bootup_value;
1125 result = vegam_get_dependency_volt_by_clk(hwmgr,
1126 table_info->vdd_dep_on_sclk,
1127 sclk_frequency,
1128 &table->ACPILevel.MinVoltage, &mvdd);
1129 PP_ASSERT_WITH_CODE(!result,
1130 "Cannot find ACPI VDDC voltage value "
1131 "in Clock Dependency Table",
1132 );
1133
1134 result = vegam_calculate_sclk_params(hwmgr, sclk_frequency,
1135 &(table->ACPILevel.SclkSetting));
1136 PP_ASSERT_WITH_CODE(!result,
1137 "Error retrieving Engine Clock dividers from VBIOS.",
1138 return result);
1139
1140 table->ACPILevel.DeepSleepDivId = 0;
1141 table->ACPILevel.CcPwrDynRm = 0;
1142 table->ACPILevel.CcPwrDynRm1 = 0;
1143
1144 CONVERT_FROM_HOST_TO_SMC_UL(table->ACPILevel.Flags);
1145 CONVERT_FROM_HOST_TO_SMC_UL(table->ACPILevel.MinVoltage);
1146 CONVERT_FROM_HOST_TO_SMC_UL(table->ACPILevel.CcPwrDynRm);
1147 CONVERT_FROM_HOST_TO_SMC_UL(table->ACPILevel.CcPwrDynRm1);
1148
1149 CONVERT_FROM_HOST_TO_SMC_UL(table->ACPILevel.SclkSetting.SclkFrequency);
1150 CONVERT_FROM_HOST_TO_SMC_US(table->ACPILevel.SclkSetting.Fcw_int);
1151 CONVERT_FROM_HOST_TO_SMC_US(table->ACPILevel.SclkSetting.Fcw_frac);
1152 CONVERT_FROM_HOST_TO_SMC_US(table->ACPILevel.SclkSetting.Pcc_fcw_int);
1153 CONVERT_FROM_HOST_TO_SMC_US(table->ACPILevel.SclkSetting.Sclk_slew_rate);
1154 CONVERT_FROM_HOST_TO_SMC_US(table->ACPILevel.SclkSetting.Pcc_up_slew_rate);
1155 CONVERT_FROM_HOST_TO_SMC_US(table->ACPILevel.SclkSetting.Pcc_down_slew_rate);
1156 CONVERT_FROM_HOST_TO_SMC_US(table->ACPILevel.SclkSetting.Fcw1_int);
1157 CONVERT_FROM_HOST_TO_SMC_US(table->ACPILevel.SclkSetting.Fcw1_frac);
1158 CONVERT_FROM_HOST_TO_SMC_US(table->ACPILevel.SclkSetting.Sclk_ss_slew_rate);
1159
1160
1161
1162 table->MemoryACPILevel.MclkFrequency = data->vbios_boot_state.mclk_bootup_value;
1163 result = vegam_get_dependency_volt_by_clk(hwmgr,
1164 table_info->vdd_dep_on_mclk,
1165 table->MemoryACPILevel.MclkFrequency,
1166 &table->MemoryACPILevel.MinVoltage, &mvdd);
1167 PP_ASSERT_WITH_CODE((0 == result),
1168 "Cannot find ACPI VDDCI voltage value "
1169 "in Clock Dependency Table",
1170 );
1171
1172 us_mvdd = 0;
1173 if ((SMU7_VOLTAGE_CONTROL_NONE == data->mvdd_control) ||
1174 (data->mclk_dpm_key_disabled))
1175 us_mvdd = data->vbios_boot_state.mvdd_bootup_value;
1176 else {
1177 if (!vegam_populate_mvdd_value(hwmgr,
1178 data->dpm_table.mclk_table.dpm_levels[0].value,
1179 &vol_level))
1180 us_mvdd = vol_level.Voltage;
1181 }
1182
1183 if (!vegam_populate_mvdd_value(hwmgr, 0, &vol_level))
1184 table->MemoryACPILevel.MinMvdd = PP_HOST_TO_SMC_UL(vol_level.Voltage);
1185 else
1186 table->MemoryACPILevel.MinMvdd = 0;
1187
1188 table->MemoryACPILevel.StutterEnable = false;
1189
1190 table->MemoryACPILevel.EnabledForThrottle = 0;
1191 table->MemoryACPILevel.EnabledForActivity = 0;
1192 table->MemoryACPILevel.UpHyst = 0;
1193 table->MemoryACPILevel.DownHyst = 100;
1194 table->MemoryACPILevel.VoltageDownHyst = 0;
1195 table->MemoryACPILevel.ActivityLevel =
1196 PP_HOST_TO_SMC_US(data->current_profile_setting.mclk_activity);
1197
1198 CONVERT_FROM_HOST_TO_SMC_UL(table->MemoryACPILevel.MclkFrequency);
1199 CONVERT_FROM_HOST_TO_SMC_UL(table->MemoryACPILevel.MinVoltage);
1200
1201 return result;
1202}
1203
1204static int vegam_populate_smc_vce_level(struct pp_hwmgr *hwmgr,
1205 SMU75_Discrete_DpmTable *table)
1206{
1207 int result = -EINVAL;
1208 uint8_t count;
1209 struct pp_atomctrl_clock_dividers_vi dividers;
1210 struct phm_ppt_v1_information *table_info =
1211 (struct phm_ppt_v1_information *)(hwmgr->pptable);
1212 struct phm_ppt_v1_mm_clock_voltage_dependency_table *mm_table =
1213 table_info->mm_dep_table;
1214 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
1215 uint32_t vddci;
1216
1217 table->VceLevelCount = (uint8_t)(mm_table->count);
1218 table->VceBootLevel = 0;
1219
1220 for (count = 0; count < table->VceLevelCount; count++) {
1221 table->VceLevel[count].Frequency = mm_table->entries[count].eclk;
1222 table->VceLevel[count].MinVoltage = 0;
1223 table->VceLevel[count].MinVoltage |=
1224 (mm_table->entries[count].vddc * VOLTAGE_SCALE) << VDDC_SHIFT;
1225
1226 if (SMU7_VOLTAGE_CONTROL_BY_GPIO == data->vddci_control)
1227 vddci = (uint32_t)phm_find_closest_vddci(&(data->vddci_voltage_table),
1228 mm_table->entries[count].vddc - VDDC_VDDCI_DELTA);
1229 else if (SMU7_VOLTAGE_CONTROL_BY_SVID2 == data->vddci_control)
1230 vddci = mm_table->entries[count].vddc - VDDC_VDDCI_DELTA;
1231 else
1232 vddci = (data->vbios_boot_state.vddci_bootup_value * VOLTAGE_SCALE) << VDDCI_SHIFT;
1233
1234
1235 table->VceLevel[count].MinVoltage |=
1236 (vddci * VOLTAGE_SCALE) << VDDCI_SHIFT;
1237 table->VceLevel[count].MinVoltage |= 1 << PHASES_SHIFT;
1238
1239
1240 result = atomctrl_get_dfs_pll_dividers_vi(hwmgr,
1241 table->VceLevel[count].Frequency, ÷rs);
1242 PP_ASSERT_WITH_CODE((0 == result),
1243 "can not find divide id for VCE engine clock",
1244 return result);
1245
1246 table->VceLevel[count].Divider = (uint8_t)dividers.pll_post_divider;
1247
1248 CONVERT_FROM_HOST_TO_SMC_UL(table->VceLevel[count].Frequency);
1249 CONVERT_FROM_HOST_TO_SMC_UL(table->VceLevel[count].MinVoltage);
1250 }
1251 return result;
1252}
1253
1254static int vegam_populate_memory_timing_parameters(struct pp_hwmgr *hwmgr,
1255 int32_t eng_clock, int32_t mem_clock,
1256 SMU75_Discrete_MCArbDramTimingTableEntry *arb_regs)
1257{
1258 uint32_t dram_timing;
1259 uint32_t dram_timing2;
1260 uint32_t burst_time;
1261 uint32_t rfsh_rate;
1262 uint32_t misc3;
1263
1264 int result;
1265
1266 result = atomctrl_set_engine_dram_timings_rv770(hwmgr,
1267 eng_clock, mem_clock);
1268 PP_ASSERT_WITH_CODE(result == 0,
1269 "Error calling VBIOS to set DRAM_TIMING.",
1270 return result);
1271
1272 dram_timing = cgs_read_register(hwmgr->device, mmMC_ARB_DRAM_TIMING);
1273 dram_timing2 = cgs_read_register(hwmgr->device, mmMC_ARB_DRAM_TIMING2);
1274 burst_time = cgs_read_register(hwmgr->device, mmMC_ARB_BURST_TIME);
1275 rfsh_rate = cgs_read_register(hwmgr->device, mmMC_ARB_RFSH_RATE);
1276 misc3 = cgs_read_register(hwmgr->device, mmMC_ARB_MISC3);
1277
1278 arb_regs->McArbDramTiming = PP_HOST_TO_SMC_UL(dram_timing);
1279 arb_regs->McArbDramTiming2 = PP_HOST_TO_SMC_UL(dram_timing2);
1280 arb_regs->McArbBurstTime = PP_HOST_TO_SMC_UL(burst_time);
1281 arb_regs->McArbRfshRate = PP_HOST_TO_SMC_UL(rfsh_rate);
1282 arb_regs->McArbMisc3 = PP_HOST_TO_SMC_UL(misc3);
1283
1284 return 0;
1285}
1286
1287static int vegam_program_memory_timing_parameters(struct pp_hwmgr *hwmgr)
1288{
1289 struct smu7_hwmgr *hw_data = (struct smu7_hwmgr *)(hwmgr->backend);
1290 struct vegam_smumgr *smu_data = (struct vegam_smumgr *)(hwmgr->smu_backend);
1291 struct SMU75_Discrete_MCArbDramTimingTable arb_regs;
1292 uint32_t i, j;
1293 int result = 0;
1294
1295 memset(&arb_regs, 0, sizeof(SMU75_Discrete_MCArbDramTimingTable));
1296
1297 for (i = 0; i < hw_data->dpm_table.sclk_table.count; i++) {
1298 for (j = 0; j < hw_data->dpm_table.mclk_table.count; j++) {
1299 result = vegam_populate_memory_timing_parameters(hwmgr,
1300 hw_data->dpm_table.sclk_table.dpm_levels[i].value,
1301 hw_data->dpm_table.mclk_table.dpm_levels[j].value,
1302 &arb_regs.entries[i][j]);
1303 if (result)
1304 return result;
1305 }
1306 }
1307
1308 result = smu7_copy_bytes_to_smc(
1309 hwmgr,
1310 smu_data->smu7_data.arb_table_start,
1311 (uint8_t *)&arb_regs,
1312 sizeof(SMU75_Discrete_MCArbDramTimingTable),
1313 SMC_RAM_END);
1314 return result;
1315}
1316
1317static int vegam_populate_smc_uvd_level(struct pp_hwmgr *hwmgr,
1318 struct SMU75_Discrete_DpmTable *table)
1319{
1320 int result = -EINVAL;
1321 uint8_t count;
1322 struct pp_atomctrl_clock_dividers_vi dividers;
1323 struct phm_ppt_v1_information *table_info =
1324 (struct phm_ppt_v1_information *)(hwmgr->pptable);
1325 struct phm_ppt_v1_mm_clock_voltage_dependency_table *mm_table =
1326 table_info->mm_dep_table;
1327 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
1328 uint32_t vddci;
1329
1330 table->UvdLevelCount = (uint8_t)(mm_table->count);
1331 table->UvdBootLevel = 0;
1332
1333 for (count = 0; count < table->UvdLevelCount; count++) {
1334 table->UvdLevel[count].MinVoltage = 0;
1335 table->UvdLevel[count].VclkFrequency = mm_table->entries[count].vclk;
1336 table->UvdLevel[count].DclkFrequency = mm_table->entries[count].dclk;
1337 table->UvdLevel[count].MinVoltage |=
1338 (mm_table->entries[count].vddc * VOLTAGE_SCALE) << VDDC_SHIFT;
1339
1340 if (SMU7_VOLTAGE_CONTROL_BY_GPIO == data->vddci_control)
1341 vddci = (uint32_t)phm_find_closest_vddci(&(data->vddci_voltage_table),
1342 mm_table->entries[count].vddc - VDDC_VDDCI_DELTA);
1343 else if (SMU7_VOLTAGE_CONTROL_BY_SVID2 == data->vddci_control)
1344 vddci = mm_table->entries[count].vddc - VDDC_VDDCI_DELTA;
1345 else
1346 vddci = (data->vbios_boot_state.vddci_bootup_value * VOLTAGE_SCALE) << VDDCI_SHIFT;
1347
1348 table->UvdLevel[count].MinVoltage |= (vddci * VOLTAGE_SCALE) << VDDCI_SHIFT;
1349 table->UvdLevel[count].MinVoltage |= 1 << PHASES_SHIFT;
1350
1351
1352 result = atomctrl_get_dfs_pll_dividers_vi(hwmgr,
1353 table->UvdLevel[count].VclkFrequency, ÷rs);
1354 PP_ASSERT_WITH_CODE((0 == result),
1355 "can not find divide id for Vclk clock", return result);
1356
1357 table->UvdLevel[count].VclkDivider = (uint8_t)dividers.pll_post_divider;
1358
1359 result = atomctrl_get_dfs_pll_dividers_vi(hwmgr,
1360 table->UvdLevel[count].DclkFrequency, ÷rs);
1361 PP_ASSERT_WITH_CODE((0 == result),
1362 "can not find divide id for Dclk clock", return result);
1363
1364 table->UvdLevel[count].DclkDivider = (uint8_t)dividers.pll_post_divider;
1365
1366 CONVERT_FROM_HOST_TO_SMC_UL(table->UvdLevel[count].VclkFrequency);
1367 CONVERT_FROM_HOST_TO_SMC_UL(table->UvdLevel[count].DclkFrequency);
1368 CONVERT_FROM_HOST_TO_SMC_UL(table->UvdLevel[count].MinVoltage);
1369 }
1370
1371 return result;
1372}
1373
1374static int vegam_populate_smc_boot_level(struct pp_hwmgr *hwmgr,
1375 struct SMU75_Discrete_DpmTable *table)
1376{
1377 int result = 0;
1378 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
1379
1380 table->GraphicsBootLevel = 0;
1381 table->MemoryBootLevel = 0;
1382
1383
1384 result = phm_find_boot_level(&(data->dpm_table.sclk_table),
1385 data->vbios_boot_state.sclk_bootup_value,
1386 (uint32_t *)&(table->GraphicsBootLevel));
1387
1388 result = phm_find_boot_level(&(data->dpm_table.mclk_table),
1389 data->vbios_boot_state.mclk_bootup_value,
1390 (uint32_t *)&(table->MemoryBootLevel));
1391
1392 table->BootVddc = data->vbios_boot_state.vddc_bootup_value *
1393 VOLTAGE_SCALE;
1394 table->BootVddci = data->vbios_boot_state.vddci_bootup_value *
1395 VOLTAGE_SCALE;
1396 table->BootMVdd = data->vbios_boot_state.mvdd_bootup_value *
1397 VOLTAGE_SCALE;
1398
1399 CONVERT_FROM_HOST_TO_SMC_US(table->BootVddc);
1400 CONVERT_FROM_HOST_TO_SMC_US(table->BootVddci);
1401 CONVERT_FROM_HOST_TO_SMC_US(table->BootMVdd);
1402
1403 return 0;
1404}
1405
1406static int vegam_populate_smc_initial_state(struct pp_hwmgr *hwmgr)
1407{
1408 struct smu7_hwmgr *hw_data = (struct smu7_hwmgr *)(hwmgr->backend);
1409 struct vegam_smumgr *smu_data = (struct vegam_smumgr *)(hwmgr->smu_backend);
1410 struct phm_ppt_v1_information *table_info =
1411 (struct phm_ppt_v1_information *)(hwmgr->pptable);
1412 uint8_t count, level;
1413
1414 count = (uint8_t)(table_info->vdd_dep_on_sclk->count);
1415
1416 for (level = 0; level < count; level++) {
1417 if (table_info->vdd_dep_on_sclk->entries[level].clk >=
1418 hw_data->vbios_boot_state.sclk_bootup_value) {
1419 smu_data->smc_state_table.GraphicsBootLevel = level;
1420 break;
1421 }
1422 }
1423
1424 count = (uint8_t)(table_info->vdd_dep_on_mclk->count);
1425 for (level = 0; level < count; level++) {
1426 if (table_info->vdd_dep_on_mclk->entries[level].clk >=
1427 hw_data->vbios_boot_state.mclk_bootup_value) {
1428 smu_data->smc_state_table.MemoryBootLevel = level;
1429 break;
1430 }
1431 }
1432
1433 return 0;
1434}
1435
1436static uint16_t scale_fan_gain_settings(uint16_t raw_setting)
1437{
1438 uint32_t tmp;
1439 tmp = raw_setting * 4096 / 100;
1440 return (uint16_t)tmp;
1441}
1442
1443static int vegam_populate_bapm_parameters_in_dpm_table(struct pp_hwmgr *hwmgr)
1444{
1445 struct vegam_smumgr *smu_data = (struct vegam_smumgr *)(hwmgr->smu_backend);
1446
1447 const struct vegam_pt_defaults *defaults = smu_data->power_tune_defaults;
1448 SMU75_Discrete_DpmTable *table = &(smu_data->smc_state_table);
1449 struct phm_ppt_v1_information *table_info =
1450 (struct phm_ppt_v1_information *)(hwmgr->pptable);
1451 struct phm_cac_tdp_table *cac_dtp_table = table_info->cac_dtp_table;
1452 struct pp_advance_fan_control_parameters *fan_table =
1453 &hwmgr->thermal_controller.advanceFanControlParameters;
1454 int i, j, k;
1455 const uint16_t *pdef1;
1456 const uint16_t *pdef2;
1457
1458 table->DefaultTdp = PP_HOST_TO_SMC_US((uint16_t)(cac_dtp_table->usTDP * 128));
1459 table->TargetTdp = PP_HOST_TO_SMC_US((uint16_t)(cac_dtp_table->usTDP * 128));
1460
1461 PP_ASSERT_WITH_CODE(cac_dtp_table->usTargetOperatingTemp <= 255,
1462 "Target Operating Temp is out of Range!",
1463 );
1464
1465 table->TemperatureLimitEdge = PP_HOST_TO_SMC_US(
1466 cac_dtp_table->usTargetOperatingTemp * 256);
1467 table->TemperatureLimitHotspot = PP_HOST_TO_SMC_US(
1468 cac_dtp_table->usTemperatureLimitHotspot * 256);
1469 table->FanGainEdge = PP_HOST_TO_SMC_US(
1470 scale_fan_gain_settings(fan_table->usFanGainEdge));
1471 table->FanGainHotspot = PP_HOST_TO_SMC_US(
1472 scale_fan_gain_settings(fan_table->usFanGainHotspot));
1473
1474 pdef1 = defaults->BAPMTI_R;
1475 pdef2 = defaults->BAPMTI_RC;
1476
1477 for (i = 0; i < SMU75_DTE_ITERATIONS; i++) {
1478 for (j = 0; j < SMU75_DTE_SOURCES; j++) {
1479 for (k = 0; k < SMU75_DTE_SINKS; k++) {
1480 table->BAPMTI_R[i][j][k] = PP_HOST_TO_SMC_US(*pdef1);
1481 table->BAPMTI_RC[i][j][k] = PP_HOST_TO_SMC_US(*pdef2);
1482 pdef1++;
1483 pdef2++;
1484 }
1485 }
1486 }
1487
1488 return 0;
1489}
1490
1491static int vegam_populate_clock_stretcher_data_table(struct pp_hwmgr *hwmgr)
1492{
1493 uint32_t ro, efuse, volt_without_cks, volt_with_cks, value, max, min;
1494 struct vegam_smumgr *smu_data =
1495 (struct vegam_smumgr *)(hwmgr->smu_backend);
1496
1497 uint8_t i, stretch_amount, stretch_amount2, volt_offset = 0;
1498 struct phm_ppt_v1_information *table_info =
1499 (struct phm_ppt_v1_information *)(hwmgr->pptable);
1500 struct phm_ppt_v1_clock_voltage_dependency_table *sclk_table =
1501 table_info->vdd_dep_on_sclk;
1502 uint32_t mask = (1 << ((STRAP_ASIC_RO_MSB - STRAP_ASIC_RO_LSB) + 1)) - 1;
1503
1504 stretch_amount = (uint8_t)table_info->cac_dtp_table->usClockStretchAmount;
1505
1506 atomctrl_read_efuse(hwmgr, STRAP_ASIC_RO_LSB, STRAP_ASIC_RO_MSB,
1507 mask, &efuse);
1508
1509 min = 1200;
1510 max = 2500;
1511
1512 ro = efuse * (max - min) / 255 + min;
1513
1514
1515 for (i = 0; i < sclk_table->count; i++) {
1516 smu_data->smc_state_table.Sclk_CKS_masterEn0_7 |=
1517 sclk_table->entries[i].cks_enable << i;
1518 volt_without_cks = (uint32_t)((2753594000U + (sclk_table->entries[i].clk/100) *
1519 136418 - (ro - 70) * 1000000) /
1520 (2424180 - (sclk_table->entries[i].clk/100) * 1132925/1000));
1521 volt_with_cks = (uint32_t)((2797202000U + sclk_table->entries[i].clk/100 *
1522 3232 - (ro - 65) * 1000000) /
1523 (2522480 - sclk_table->entries[i].clk/100 * 115764/100));
1524
1525 if (volt_without_cks >= volt_with_cks)
1526 volt_offset = (uint8_t)(((volt_without_cks - volt_with_cks +
1527 sclk_table->entries[i].cks_voffset) * 100 + 624) / 625);
1528
1529 smu_data->smc_state_table.Sclk_voltageOffset[i] = volt_offset;
1530 }
1531
1532 smu_data->smc_state_table.LdoRefSel =
1533 (table_info->cac_dtp_table->ucCKS_LDO_REFSEL != 0) ?
1534 table_info->cac_dtp_table->ucCKS_LDO_REFSEL : 5;
1535
1536 if (stretch_amount == 1 || stretch_amount == 2 || stretch_amount == 5)
1537 stretch_amount2 = 0;
1538 else if (stretch_amount == 3 || stretch_amount == 4)
1539 stretch_amount2 = 1;
1540 else {
1541 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
1542 PHM_PlatformCaps_ClockStretcher);
1543 PP_ASSERT_WITH_CODE(false,
1544 "Stretch Amount in PPTable not supported\n",
1545 return -EINVAL);
1546 }
1547
1548 value = cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixPWR_CKS_CNTL);
1549 value &= 0xFFFFFFFE;
1550 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixPWR_CKS_CNTL, value);
1551
1552 return 0;
1553}
1554
1555static bool vegam_is_hw_avfs_present(struct pp_hwmgr *hwmgr)
1556{
1557 uint32_t efuse;
1558
1559 efuse = cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC,
1560 ixSMU_EFUSE_0 + (49 * 4));
1561 efuse &= 0x00000001;
1562
1563 if (efuse)
1564 return true;
1565
1566 return false;
1567}
1568
1569static int vegam_populate_avfs_parameters(struct pp_hwmgr *hwmgr)
1570{
1571 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
1572 struct vegam_smumgr *smu_data = (struct vegam_smumgr *)(hwmgr->smu_backend);
1573
1574 SMU75_Discrete_DpmTable *table = &(smu_data->smc_state_table);
1575 int result = 0;
1576 struct pp_atom_ctrl__avfs_parameters avfs_params = {0};
1577 AVFS_meanNsigma_t AVFS_meanNsigma = { {0} };
1578 AVFS_Sclk_Offset_t AVFS_SclkOffset = { {0} };
1579 uint32_t tmp, i;
1580
1581 struct phm_ppt_v1_information *table_info =
1582 (struct phm_ppt_v1_information *)hwmgr->pptable;
1583 struct phm_ppt_v1_clock_voltage_dependency_table *sclk_table =
1584 table_info->vdd_dep_on_sclk;
1585
1586 if (!hwmgr->avfs_supported)
1587 return 0;
1588
1589 result = atomctrl_get_avfs_information(hwmgr, &avfs_params);
1590
1591 if (0 == result) {
1592 table->BTCGB_VDROOP_TABLE[0].a0 =
1593 PP_HOST_TO_SMC_UL(avfs_params.ulGB_VDROOP_TABLE_CKSON_a0);
1594 table->BTCGB_VDROOP_TABLE[0].a1 =
1595 PP_HOST_TO_SMC_UL(avfs_params.ulGB_VDROOP_TABLE_CKSON_a1);
1596 table->BTCGB_VDROOP_TABLE[0].a2 =
1597 PP_HOST_TO_SMC_UL(avfs_params.ulGB_VDROOP_TABLE_CKSON_a2);
1598 table->BTCGB_VDROOP_TABLE[1].a0 =
1599 PP_HOST_TO_SMC_UL(avfs_params.ulGB_VDROOP_TABLE_CKSOFF_a0);
1600 table->BTCGB_VDROOP_TABLE[1].a1 =
1601 PP_HOST_TO_SMC_UL(avfs_params.ulGB_VDROOP_TABLE_CKSOFF_a1);
1602 table->BTCGB_VDROOP_TABLE[1].a2 =
1603 PP_HOST_TO_SMC_UL(avfs_params.ulGB_VDROOP_TABLE_CKSOFF_a2);
1604 table->AVFSGB_FUSE_TABLE[0].m1 =
1605 PP_HOST_TO_SMC_UL(avfs_params.ulAVFSGB_FUSE_TABLE_CKSON_m1);
1606 table->AVFSGB_FUSE_TABLE[0].m2 =
1607 PP_HOST_TO_SMC_US(avfs_params.usAVFSGB_FUSE_TABLE_CKSON_m2);
1608 table->AVFSGB_FUSE_TABLE[0].b =
1609 PP_HOST_TO_SMC_UL(avfs_params.ulAVFSGB_FUSE_TABLE_CKSON_b);
1610 table->AVFSGB_FUSE_TABLE[0].m1_shift = 24;
1611 table->AVFSGB_FUSE_TABLE[0].m2_shift = 12;
1612 table->AVFSGB_FUSE_TABLE[1].m1 =
1613 PP_HOST_TO_SMC_UL(avfs_params.ulAVFSGB_FUSE_TABLE_CKSOFF_m1);
1614 table->AVFSGB_FUSE_TABLE[1].m2 =
1615 PP_HOST_TO_SMC_US(avfs_params.usAVFSGB_FUSE_TABLE_CKSOFF_m2);
1616 table->AVFSGB_FUSE_TABLE[1].b =
1617 PP_HOST_TO_SMC_UL(avfs_params.ulAVFSGB_FUSE_TABLE_CKSOFF_b);
1618 table->AVFSGB_FUSE_TABLE[1].m1_shift = 24;
1619 table->AVFSGB_FUSE_TABLE[1].m2_shift = 12;
1620 table->MaxVoltage = PP_HOST_TO_SMC_US(avfs_params.usMaxVoltage_0_25mv);
1621 AVFS_meanNsigma.Aconstant[0] =
1622 PP_HOST_TO_SMC_UL(avfs_params.ulAVFS_meanNsigma_Acontant0);
1623 AVFS_meanNsigma.Aconstant[1] =
1624 PP_HOST_TO_SMC_UL(avfs_params.ulAVFS_meanNsigma_Acontant1);
1625 AVFS_meanNsigma.Aconstant[2] =
1626 PP_HOST_TO_SMC_UL(avfs_params.ulAVFS_meanNsigma_Acontant2);
1627 AVFS_meanNsigma.DC_tol_sigma =
1628 PP_HOST_TO_SMC_US(avfs_params.usAVFS_meanNsigma_DC_tol_sigma);
1629 AVFS_meanNsigma.Platform_mean =
1630 PP_HOST_TO_SMC_US(avfs_params.usAVFS_meanNsigma_Platform_mean);
1631 AVFS_meanNsigma.PSM_Age_CompFactor =
1632 PP_HOST_TO_SMC_US(avfs_params.usPSM_Age_ComFactor);
1633 AVFS_meanNsigma.Platform_sigma =
1634 PP_HOST_TO_SMC_US(avfs_params.usAVFS_meanNsigma_Platform_sigma);
1635
1636 for (i = 0; i < sclk_table->count; i++) {
1637 AVFS_meanNsigma.Static_Voltage_Offset[i] =
1638 (uint8_t)(sclk_table->entries[i].cks_voffset * 100 / 625);
1639 AVFS_SclkOffset.Sclk_Offset[i] =
1640 PP_HOST_TO_SMC_US((uint16_t)
1641 (sclk_table->entries[i].sclk_offset) / 100);
1642 }
1643
1644 result = smu7_read_smc_sram_dword(hwmgr,
1645 SMU7_FIRMWARE_HEADER_LOCATION +
1646 offsetof(SMU75_Firmware_Header, AvfsMeanNSigma),
1647 &tmp, SMC_RAM_END);
1648 smu7_copy_bytes_to_smc(hwmgr,
1649 tmp,
1650 (uint8_t *)&AVFS_meanNsigma,
1651 sizeof(AVFS_meanNsigma_t),
1652 SMC_RAM_END);
1653
1654 result = smu7_read_smc_sram_dword(hwmgr,
1655 SMU7_FIRMWARE_HEADER_LOCATION +
1656 offsetof(SMU75_Firmware_Header, AvfsSclkOffsetTable),
1657 &tmp, SMC_RAM_END);
1658 smu7_copy_bytes_to_smc(hwmgr,
1659 tmp,
1660 (uint8_t *)&AVFS_SclkOffset,
1661 sizeof(AVFS_Sclk_Offset_t),
1662 SMC_RAM_END);
1663
1664 data->avfs_vdroop_override_setting =
1665 (avfs_params.ucEnableGB_VDROOP_TABLE_CKSON << BTCGB0_Vdroop_Enable_SHIFT) |
1666 (avfs_params.ucEnableGB_VDROOP_TABLE_CKSOFF << BTCGB1_Vdroop_Enable_SHIFT) |
1667 (avfs_params.ucEnableGB_FUSE_TABLE_CKSON << AVFSGB0_Vdroop_Enable_SHIFT) |
1668 (avfs_params.ucEnableGB_FUSE_TABLE_CKSOFF << AVFSGB1_Vdroop_Enable_SHIFT);
1669 data->apply_avfs_cks_off_voltage =
1670 (avfs_params.ucEnableApplyAVFS_CKS_OFF_Voltage == 1) ? true : false;
1671 }
1672 return result;
1673}
1674
1675static int vegam_populate_vr_config(struct pp_hwmgr *hwmgr,
1676 struct SMU75_Discrete_DpmTable *table)
1677{
1678 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
1679 struct vegam_smumgr *smu_data =
1680 (struct vegam_smumgr *)(hwmgr->smu_backend);
1681 uint16_t config;
1682
1683 config = VR_MERGED_WITH_VDDC;
1684 table->VRConfig |= (config << VRCONF_VDDGFX_SHIFT);
1685
1686
1687 if (SMU7_VOLTAGE_CONTROL_BY_SVID2 == data->voltage_control) {
1688 config = VR_SVI2_PLANE_1;
1689 table->VRConfig |= config;
1690 } else {
1691 PP_ASSERT_WITH_CODE(false,
1692 "VDDC should be on SVI2 control in merged mode!",
1693 );
1694 }
1695
1696 if (SMU7_VOLTAGE_CONTROL_BY_SVID2 == data->vddci_control) {
1697 config = VR_SVI2_PLANE_2;
1698 table->VRConfig |= (config << VRCONF_VDDCI_SHIFT);
1699 } else if (SMU7_VOLTAGE_CONTROL_BY_GPIO == data->vddci_control) {
1700 config = VR_SMIO_PATTERN_1;
1701 table->VRConfig |= (config << VRCONF_VDDCI_SHIFT);
1702 } else {
1703 config = VR_STATIC_VOLTAGE;
1704 table->VRConfig |= (config << VRCONF_VDDCI_SHIFT);
1705 }
1706
1707 if (SMU7_VOLTAGE_CONTROL_BY_SVID2 == data->mvdd_control) {
1708 if (config != VR_SVI2_PLANE_2) {
1709 config = VR_SVI2_PLANE_2;
1710 table->VRConfig |= (config << VRCONF_MVDD_SHIFT);
1711 cgs_write_ind_register(hwmgr->device,
1712 CGS_IND_REG__SMC,
1713 smu_data->smu7_data.soft_regs_start +
1714 offsetof(SMU75_SoftRegisters, AllowMvddSwitch),
1715 0x1);
1716 } else {
1717 PP_ASSERT_WITH_CODE(false,
1718 "SVI2 Plane 2 is already taken, set MVDD as Static",);
1719 config = VR_STATIC_VOLTAGE;
1720 table->VRConfig = (config << VRCONF_MVDD_SHIFT);
1721 }
1722 } else if (SMU7_VOLTAGE_CONTROL_BY_GPIO == data->mvdd_control) {
1723 config = VR_SMIO_PATTERN_2;
1724 table->VRConfig = (config << VRCONF_MVDD_SHIFT);
1725 cgs_write_ind_register(hwmgr->device,
1726 CGS_IND_REG__SMC,
1727 smu_data->smu7_data.soft_regs_start +
1728 offsetof(SMU75_SoftRegisters, AllowMvddSwitch),
1729 0x1);
1730 } else {
1731 config = VR_STATIC_VOLTAGE;
1732 table->VRConfig |= (config << VRCONF_MVDD_SHIFT);
1733 }
1734
1735 return 0;
1736}
1737
1738static int vegam_populate_svi_load_line(struct pp_hwmgr *hwmgr)
1739{
1740 struct vegam_smumgr *smu_data = (struct vegam_smumgr *)(hwmgr->smu_backend);
1741 const struct vegam_pt_defaults *defaults = smu_data->power_tune_defaults;
1742
1743 smu_data->power_tune_table.SviLoadLineEn = defaults->SviLoadLineEn;
1744 smu_data->power_tune_table.SviLoadLineVddC = defaults->SviLoadLineVddC;
1745 smu_data->power_tune_table.SviLoadLineTrimVddC = 3;
1746 smu_data->power_tune_table.SviLoadLineOffsetVddC = 0;
1747
1748 return 0;
1749}
1750
1751static int vegam_populate_tdc_limit(struct pp_hwmgr *hwmgr)
1752{
1753 uint16_t tdc_limit;
1754 struct vegam_smumgr *smu_data = (struct vegam_smumgr *)(hwmgr->smu_backend);
1755 struct phm_ppt_v1_information *table_info =
1756 (struct phm_ppt_v1_information *)(hwmgr->pptable);
1757 const struct vegam_pt_defaults *defaults = smu_data->power_tune_defaults;
1758
1759 tdc_limit = (uint16_t)(table_info->cac_dtp_table->usTDC * 128);
1760 smu_data->power_tune_table.TDC_VDDC_PkgLimit =
1761 CONVERT_FROM_HOST_TO_SMC_US(tdc_limit);
1762 smu_data->power_tune_table.TDC_VDDC_ThrottleReleaseLimitPerc =
1763 defaults->TDC_VDDC_ThrottleReleaseLimitPerc;
1764 smu_data->power_tune_table.TDC_MAWt = defaults->TDC_MAWt;
1765
1766 return 0;
1767}
1768
1769static int vegam_populate_dw8(struct pp_hwmgr *hwmgr, uint32_t fuse_table_offset)
1770{
1771 struct vegam_smumgr *smu_data = (struct vegam_smumgr *)(hwmgr->smu_backend);
1772 const struct vegam_pt_defaults *defaults = smu_data->power_tune_defaults;
1773 uint32_t temp;
1774
1775 if (smu7_read_smc_sram_dword(hwmgr,
1776 fuse_table_offset +
1777 offsetof(SMU75_Discrete_PmFuses, TdcWaterfallCtl),
1778 (uint32_t *)&temp, SMC_RAM_END))
1779 PP_ASSERT_WITH_CODE(false,
1780 "Attempt to read PmFuses.DW6 (SviLoadLineEn) from SMC Failed!",
1781 return -EINVAL);
1782 else {
1783 smu_data->power_tune_table.TdcWaterfallCtl = defaults->TdcWaterfallCtl;
1784 smu_data->power_tune_table.LPMLTemperatureMin =
1785 (uint8_t)((temp >> 16) & 0xff);
1786 smu_data->power_tune_table.LPMLTemperatureMax =
1787 (uint8_t)((temp >> 8) & 0xff);
1788 smu_data->power_tune_table.Reserved = (uint8_t)(temp & 0xff);
1789 }
1790 return 0;
1791}
1792
1793static int vegam_populate_temperature_scaler(struct pp_hwmgr *hwmgr)
1794{
1795 int i;
1796 struct vegam_smumgr *smu_data = (struct vegam_smumgr *)(hwmgr->smu_backend);
1797
1798
1799 for (i = 0; i < 16; i++)
1800 smu_data->power_tune_table.LPMLTemperatureScaler[i] = 0;
1801
1802 return 0;
1803}
1804
1805static int vegam_populate_fuzzy_fan(struct pp_hwmgr *hwmgr)
1806{
1807 struct vegam_smumgr *smu_data = (struct vegam_smumgr *)(hwmgr->smu_backend);
1808
1809
1810 if ((hwmgr->thermal_controller.advanceFanControlParameters.usFanOutputSensitivity & (1 << 15))
1811 || 0 == hwmgr->thermal_controller.advanceFanControlParameters.usFanOutputSensitivity)
1812 hwmgr->thermal_controller.advanceFanControlParameters.usFanOutputSensitivity =
1813 hwmgr->thermal_controller.advanceFanControlParameters.usDefaultFanOutputSensitivity;
1814
1815 smu_data->power_tune_table.FuzzyFan_PwmSetDelta = PP_HOST_TO_SMC_US(
1816 hwmgr->thermal_controller.advanceFanControlParameters.usFanOutputSensitivity);
1817 return 0;
1818}
1819
1820static int vegam_populate_gnb_lpml(struct pp_hwmgr *hwmgr)
1821{
1822 int i;
1823 struct vegam_smumgr *smu_data = (struct vegam_smumgr *)(hwmgr->smu_backend);
1824
1825
1826 for (i = 0; i < 16; i++)
1827 smu_data->power_tune_table.GnbLPML[i] = 0;
1828
1829 return 0;
1830}
1831
1832static int vegam_populate_bapm_vddc_base_leakage_sidd(struct pp_hwmgr *hwmgr)
1833{
1834 struct vegam_smumgr *smu_data = (struct vegam_smumgr *)(hwmgr->smu_backend);
1835 struct phm_ppt_v1_information *table_info =
1836 (struct phm_ppt_v1_information *)(hwmgr->pptable);
1837 uint16_t hi_sidd = smu_data->power_tune_table.BapmVddCBaseLeakageHiSidd;
1838 uint16_t lo_sidd = smu_data->power_tune_table.BapmVddCBaseLeakageLoSidd;
1839 struct phm_cac_tdp_table *cac_table = table_info->cac_dtp_table;
1840
1841 hi_sidd = (uint16_t)(cac_table->usHighCACLeakage / 100 * 256);
1842 lo_sidd = (uint16_t)(cac_table->usLowCACLeakage / 100 * 256);
1843
1844 smu_data->power_tune_table.BapmVddCBaseLeakageHiSidd =
1845 CONVERT_FROM_HOST_TO_SMC_US(hi_sidd);
1846 smu_data->power_tune_table.BapmVddCBaseLeakageLoSidd =
1847 CONVERT_FROM_HOST_TO_SMC_US(lo_sidd);
1848
1849 return 0;
1850}
1851
1852static int vegam_populate_pm_fuses(struct pp_hwmgr *hwmgr)
1853{
1854 struct vegam_smumgr *smu_data = (struct vegam_smumgr *)(hwmgr->smu_backend);
1855 uint32_t pm_fuse_table_offset;
1856
1857 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
1858 PHM_PlatformCaps_PowerContainment)) {
1859 if (smu7_read_smc_sram_dword(hwmgr,
1860 SMU7_FIRMWARE_HEADER_LOCATION +
1861 offsetof(SMU75_Firmware_Header, PmFuseTable),
1862 &pm_fuse_table_offset, SMC_RAM_END))
1863 PP_ASSERT_WITH_CODE(false,
1864 "Attempt to get pm_fuse_table_offset Failed!",
1865 return -EINVAL);
1866
1867 if (vegam_populate_svi_load_line(hwmgr))
1868 PP_ASSERT_WITH_CODE(false,
1869 "Attempt to populate SviLoadLine Failed!",
1870 return -EINVAL);
1871
1872 if (vegam_populate_tdc_limit(hwmgr))
1873 PP_ASSERT_WITH_CODE(false,
1874 "Attempt to populate TDCLimit Failed!", return -EINVAL);
1875
1876 if (vegam_populate_dw8(hwmgr, pm_fuse_table_offset))
1877 PP_ASSERT_WITH_CODE(false,
1878 "Attempt to populate TdcWaterfallCtl, "
1879 "LPMLTemperature Min and Max Failed!",
1880 return -EINVAL);
1881
1882 if (0 != vegam_populate_temperature_scaler(hwmgr))
1883 PP_ASSERT_WITH_CODE(false,
1884 "Attempt to populate LPMLTemperatureScaler Failed!",
1885 return -EINVAL);
1886
1887 if (vegam_populate_fuzzy_fan(hwmgr))
1888 PP_ASSERT_WITH_CODE(false,
1889 "Attempt to populate Fuzzy Fan Control parameters Failed!",
1890 return -EINVAL);
1891
1892 if (vegam_populate_gnb_lpml(hwmgr))
1893 PP_ASSERT_WITH_CODE(false,
1894 "Attempt to populate GnbLPML Failed!",
1895 return -EINVAL);
1896
1897 if (vegam_populate_bapm_vddc_base_leakage_sidd(hwmgr))
1898 PP_ASSERT_WITH_CODE(false,
1899 "Attempt to populate BapmVddCBaseLeakage Hi and Lo "
1900 "Sidd Failed!", return -EINVAL);
1901
1902 if (smu7_copy_bytes_to_smc(hwmgr, pm_fuse_table_offset,
1903 (uint8_t *)&smu_data->power_tune_table,
1904 (sizeof(struct SMU75_Discrete_PmFuses) - PMFUSES_AVFSSIZE),
1905 SMC_RAM_END))
1906 PP_ASSERT_WITH_CODE(false,
1907 "Attempt to download PmFuseTable Failed!",
1908 return -EINVAL);
1909 }
1910 return 0;
1911}
1912
1913static int vegam_enable_reconfig_cus(struct pp_hwmgr *hwmgr)
1914{
1915 struct amdgpu_device *adev = hwmgr->adev;
1916
1917 smum_send_msg_to_smc_with_parameter(hwmgr,
1918 PPSMC_MSG_EnableModeSwitchRLCNotification,
1919 adev->gfx.cu_info.number);
1920
1921 return 0;
1922}
1923
1924static int vegam_init_smc_table(struct pp_hwmgr *hwmgr)
1925{
1926 int result;
1927 struct smu7_hwmgr *hw_data = (struct smu7_hwmgr *)(hwmgr->backend);
1928 struct vegam_smumgr *smu_data = (struct vegam_smumgr *)(hwmgr->smu_backend);
1929
1930 struct phm_ppt_v1_information *table_info =
1931 (struct phm_ppt_v1_information *)(hwmgr->pptable);
1932 struct SMU75_Discrete_DpmTable *table = &(smu_data->smc_state_table);
1933 uint8_t i;
1934 struct pp_atomctrl_gpio_pin_assignment gpio_pin;
1935 struct phm_ppt_v1_gpio_table *gpio_table =
1936 (struct phm_ppt_v1_gpio_table *)table_info->gpio_table;
1937 pp_atomctrl_clock_dividers_vi dividers;
1938
1939 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
1940 PHM_PlatformCaps_AutomaticDCTransition);
1941
1942 vegam_initialize_power_tune_defaults(hwmgr);
1943
1944 if (SMU7_VOLTAGE_CONTROL_NONE != hw_data->voltage_control)
1945 vegam_populate_smc_voltage_tables(hwmgr, table);
1946
1947 table->SystemFlags = 0;
1948 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
1949 PHM_PlatformCaps_AutomaticDCTransition))
1950 table->SystemFlags |= PPSMC_SYSTEMFLAG_GPIO_DC;
1951
1952 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
1953 PHM_PlatformCaps_StepVddc))
1954 table->SystemFlags |= PPSMC_SYSTEMFLAG_STEPVDDC;
1955
1956 if (hw_data->is_memory_gddr5)
1957 table->SystemFlags |= PPSMC_SYSTEMFLAG_GDDR5;
1958
1959 if (hw_data->ulv_supported && table_info->us_ulv_voltage_offset) {
1960 result = vegam_populate_ulv_state(hwmgr, table);
1961 PP_ASSERT_WITH_CODE(!result,
1962 "Failed to initialize ULV state!", return result);
1963 cgs_write_ind_register(hwmgr->device, CGS_IND_REG__SMC,
1964 ixCG_ULV_PARAMETER, SMU7_CGULVPARAMETER_DFLT);
1965 }
1966
1967 result = vegam_populate_smc_link_level(hwmgr, table);
1968 PP_ASSERT_WITH_CODE(!result,
1969 "Failed to initialize Link Level!", return result);
1970
1971 result = vegam_populate_all_graphic_levels(hwmgr);
1972 PP_ASSERT_WITH_CODE(!result,
1973 "Failed to initialize Graphics Level!", return result);
1974
1975 result = vegam_populate_all_memory_levels(hwmgr);
1976 PP_ASSERT_WITH_CODE(!result,
1977 "Failed to initialize Memory Level!", return result);
1978
1979 result = vegam_populate_smc_acpi_level(hwmgr, table);
1980 PP_ASSERT_WITH_CODE(!result,
1981 "Failed to initialize ACPI Level!", return result);
1982
1983 result = vegam_populate_smc_vce_level(hwmgr, table);
1984 PP_ASSERT_WITH_CODE(!result,
1985 "Failed to initialize VCE Level!", return result);
1986
1987
1988
1989
1990
1991 result = vegam_program_memory_timing_parameters(hwmgr);
1992 PP_ASSERT_WITH_CODE(!result,
1993 "Failed to Write ARB settings for the initial state.", return result);
1994
1995 result = vegam_populate_smc_uvd_level(hwmgr, table);
1996 PP_ASSERT_WITH_CODE(!result,
1997 "Failed to initialize UVD Level!", return result);
1998
1999 result = vegam_populate_smc_boot_level(hwmgr, table);
2000 PP_ASSERT_WITH_CODE(!result,
2001 "Failed to initialize Boot Level!", return result);
2002
2003 result = vegam_populate_smc_initial_state(hwmgr);
2004 PP_ASSERT_WITH_CODE(!result,
2005 "Failed to initialize Boot State!", return result);
2006
2007 result = vegam_populate_bapm_parameters_in_dpm_table(hwmgr);
2008 PP_ASSERT_WITH_CODE(!result,
2009 "Failed to populate BAPM Parameters!", return result);
2010
2011 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
2012 PHM_PlatformCaps_ClockStretcher)) {
2013 result = vegam_populate_clock_stretcher_data_table(hwmgr);
2014 PP_ASSERT_WITH_CODE(!result,
2015 "Failed to populate Clock Stretcher Data Table!",
2016 return result);
2017 }
2018
2019 result = vegam_populate_avfs_parameters(hwmgr);
2020 PP_ASSERT_WITH_CODE(!result,
2021 "Failed to populate AVFS Parameters!", return result;);
2022
2023 table->CurrSclkPllRange = 0xff;
2024 table->GraphicsVoltageChangeEnable = 1;
2025 table->GraphicsThermThrottleEnable = 1;
2026 table->GraphicsInterval = 1;
2027 table->VoltageInterval = 1;
2028 table->ThermalInterval = 1;
2029 table->TemperatureLimitHigh =
2030 table_info->cac_dtp_table->usTargetOperatingTemp *
2031 SMU7_Q88_FORMAT_CONVERSION_UNIT;
2032 table->TemperatureLimitLow =
2033 (table_info->cac_dtp_table->usTargetOperatingTemp - 1) *
2034 SMU7_Q88_FORMAT_CONVERSION_UNIT;
2035 table->MemoryVoltageChangeEnable = 1;
2036 table->MemoryInterval = 1;
2037 table->VoltageResponseTime = 0;
2038 table->PhaseResponseTime = 0;
2039 table->MemoryThermThrottleEnable = 1;
2040
2041 PP_ASSERT_WITH_CODE(hw_data->dpm_table.pcie_speed_table.count >= 1,
2042 "There must be 1 or more PCIE levels defined in PPTable.",
2043 return -EINVAL);
2044 table->PCIeBootLinkLevel =
2045 hw_data->dpm_table.pcie_speed_table.count;
2046 table->PCIeGenInterval = 1;
2047 table->VRConfig = 0;
2048
2049 result = vegam_populate_vr_config(hwmgr, table);
2050 PP_ASSERT_WITH_CODE(!result,
2051 "Failed to populate VRConfig setting!", return result);
2052
2053 table->ThermGpio = 17;
2054 table->SclkStepSize = 0x4000;
2055
2056 if (atomctrl_get_pp_assign_pin(hwmgr,
2057 VDDC_VRHOT_GPIO_PINID, &gpio_pin)) {
2058 table->VRHotGpio = gpio_pin.uc_gpio_pin_bit_shift;
2059 if (gpio_table)
2060 table->VRHotLevel =
2061 table_info->gpio_table->vrhot_triggered_sclk_dpm_index;
2062 } else {
2063 table->VRHotGpio = SMU7_UNUSED_GPIO_PIN;
2064 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
2065 PHM_PlatformCaps_RegulatorHot);
2066 }
2067
2068 if (atomctrl_get_pp_assign_pin(hwmgr,
2069 PP_AC_DC_SWITCH_GPIO_PINID, &gpio_pin)) {
2070 table->AcDcGpio = gpio_pin.uc_gpio_pin_bit_shift;
2071 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
2072 PHM_PlatformCaps_AutomaticDCTransition) &&
2073 !smum_send_msg_to_smc(hwmgr, PPSMC_MSG_UseNewGPIOScheme))
2074 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
2075 PHM_PlatformCaps_SMCtoPPLIBAcdcGpioScheme);
2076 } else {
2077 table->AcDcGpio = SMU7_UNUSED_GPIO_PIN;
2078 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
2079 PHM_PlatformCaps_AutomaticDCTransition);
2080 }
2081
2082
2083 if (atomctrl_get_pp_assign_pin(hwmgr,
2084 THERMAL_INT_OUTPUT_GPIO_PINID, &gpio_pin)) {
2085 table->ThermOutGpio = gpio_pin.uc_gpio_pin_bit_shift;
2086
2087
2088
2089
2090
2091
2092 table->ThermOutPolarity =
2093 (0 == (cgs_read_register(hwmgr->device, mmGPIOPAD_A) &
2094 (1 << gpio_pin.uc_gpio_pin_bit_shift))) ? 1:0;
2095 table->ThermOutMode = SMU7_THERM_OUT_MODE_THERM_ONLY;
2096
2097
2098 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
2099 PHM_PlatformCaps_RegulatorHot) &&
2100 phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
2101 PHM_PlatformCaps_CombinePCCWithThermalSignal))
2102 table->ThermOutMode = SMU7_THERM_OUT_MODE_THERM_VRHOT;
2103 } else {
2104 table->ThermOutGpio = 17;
2105 table->ThermOutPolarity = 1;
2106 table->ThermOutMode = SMU7_THERM_OUT_MODE_DISABLE;
2107 }
2108
2109
2110 for (i = 0; i <= hw_data->dpm_table.pcie_speed_table.count; i++) {
2111 result = atomctrl_get_dfs_pll_dividers_vi(hwmgr,
2112 smu_data->bif_sclk_table[i], ÷rs);
2113 PP_ASSERT_WITH_CODE(!result,
2114 "Can not find DFS divide id for Sclk",
2115 return result);
2116
2117 if (i == 0)
2118 table->Ulv.BifSclkDfs =
2119 PP_HOST_TO_SMC_US((uint16_t)(dividers.pll_post_divider));
2120 else
2121 table->LinkLevel[i - 1].BifSclkDfs =
2122 PP_HOST_TO_SMC_US((uint16_t)(dividers.pll_post_divider));
2123 }
2124
2125 for (i = 0; i < SMU75_MAX_ENTRIES_SMIO; i++)
2126 table->Smio[i] = PP_HOST_TO_SMC_UL(table->Smio[i]);
2127
2128 CONVERT_FROM_HOST_TO_SMC_UL(table->SystemFlags);
2129 CONVERT_FROM_HOST_TO_SMC_UL(table->VRConfig);
2130 CONVERT_FROM_HOST_TO_SMC_UL(table->SmioMask1);
2131 CONVERT_FROM_HOST_TO_SMC_UL(table->SmioMask2);
2132 CONVERT_FROM_HOST_TO_SMC_UL(table->SclkStepSize);
2133 CONVERT_FROM_HOST_TO_SMC_UL(table->CurrSclkPllRange);
2134 CONVERT_FROM_HOST_TO_SMC_US(table->TemperatureLimitHigh);
2135 CONVERT_FROM_HOST_TO_SMC_US(table->TemperatureLimitLow);
2136 CONVERT_FROM_HOST_TO_SMC_US(table->VoltageResponseTime);
2137 CONVERT_FROM_HOST_TO_SMC_US(table->PhaseResponseTime);
2138
2139
2140 result = smu7_copy_bytes_to_smc(hwmgr,
2141 smu_data->smu7_data.dpm_table_start +
2142 offsetof(SMU75_Discrete_DpmTable, SystemFlags),
2143 (uint8_t *)&(table->SystemFlags),
2144 sizeof(SMU75_Discrete_DpmTable) - 3 * sizeof(SMU75_PIDController),
2145 SMC_RAM_END);
2146 PP_ASSERT_WITH_CODE(!result,
2147 "Failed to upload dpm data to SMC memory!", return result);
2148
2149 result = vegam_populate_pm_fuses(hwmgr);
2150 PP_ASSERT_WITH_CODE(!result,
2151 "Failed to populate PM fuses to SMC memory!", return result);
2152
2153 result = vegam_enable_reconfig_cus(hwmgr);
2154 PP_ASSERT_WITH_CODE(!result,
2155 "Failed to enable reconfigurable CUs!", return result);
2156
2157 return 0;
2158}
2159
2160static uint32_t vegam_get_offsetof(uint32_t type, uint32_t member)
2161{
2162 switch (type) {
2163 case SMU_SoftRegisters:
2164 switch (member) {
2165 case HandshakeDisables:
2166 return offsetof(SMU75_SoftRegisters, HandshakeDisables);
2167 case VoltageChangeTimeout:
2168 return offsetof(SMU75_SoftRegisters, VoltageChangeTimeout);
2169 case AverageGraphicsActivity:
2170 return offsetof(SMU75_SoftRegisters, AverageGraphicsActivity);
2171 case PreVBlankGap:
2172 return offsetof(SMU75_SoftRegisters, PreVBlankGap);
2173 case VBlankTimeout:
2174 return offsetof(SMU75_SoftRegisters, VBlankTimeout);
2175 case UcodeLoadStatus:
2176 return offsetof(SMU75_SoftRegisters, UcodeLoadStatus);
2177 case DRAM_LOG_ADDR_H:
2178 return offsetof(SMU75_SoftRegisters, DRAM_LOG_ADDR_H);
2179 case DRAM_LOG_ADDR_L:
2180 return offsetof(SMU75_SoftRegisters, DRAM_LOG_ADDR_L);
2181 case DRAM_LOG_PHY_ADDR_H:
2182 return offsetof(SMU75_SoftRegisters, DRAM_LOG_PHY_ADDR_H);
2183 case DRAM_LOG_PHY_ADDR_L:
2184 return offsetof(SMU75_SoftRegisters, DRAM_LOG_PHY_ADDR_L);
2185 case DRAM_LOG_BUFF_SIZE:
2186 return offsetof(SMU75_SoftRegisters, DRAM_LOG_BUFF_SIZE);
2187 }
2188 break;
2189 case SMU_Discrete_DpmTable:
2190 switch (member) {
2191 case UvdBootLevel:
2192 return offsetof(SMU75_Discrete_DpmTable, UvdBootLevel);
2193 case VceBootLevel:
2194 return offsetof(SMU75_Discrete_DpmTable, VceBootLevel);
2195 case LowSclkInterruptThreshold:
2196 return offsetof(SMU75_Discrete_DpmTable, LowSclkInterruptThreshold);
2197 }
2198 break;
2199 }
2200 pr_warn("can't get the offset of type %x member %x\n", type, member);
2201 return 0;
2202}
2203
2204static int vegam_program_mem_timing_parameters(struct pp_hwmgr *hwmgr)
2205{
2206 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
2207
2208 if (data->need_update_smu7_dpm_table &
2209 (DPMTABLE_OD_UPDATE_SCLK +
2210 DPMTABLE_UPDATE_SCLK +
2211 DPMTABLE_UPDATE_MCLK))
2212 return vegam_program_memory_timing_parameters(hwmgr);
2213
2214 return 0;
2215}
2216
2217static int vegam_update_sclk_threshold(struct pp_hwmgr *hwmgr)
2218{
2219 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
2220 struct vegam_smumgr *smu_data =
2221 (struct vegam_smumgr *)(hwmgr->smu_backend);
2222 int result = 0;
2223 uint32_t low_sclk_interrupt_threshold = 0;
2224
2225 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
2226 PHM_PlatformCaps_SclkThrottleLowNotification)
2227 && (data->low_sclk_interrupt_threshold != 0)) {
2228 low_sclk_interrupt_threshold =
2229 data->low_sclk_interrupt_threshold;
2230
2231 CONVERT_FROM_HOST_TO_SMC_UL(low_sclk_interrupt_threshold);
2232
2233 result = smu7_copy_bytes_to_smc(
2234 hwmgr,
2235 smu_data->smu7_data.dpm_table_start +
2236 offsetof(SMU75_Discrete_DpmTable,
2237 LowSclkInterruptThreshold),
2238 (uint8_t *)&low_sclk_interrupt_threshold,
2239 sizeof(uint32_t),
2240 SMC_RAM_END);
2241 }
2242 PP_ASSERT_WITH_CODE((result == 0),
2243 "Failed to update SCLK threshold!", return result);
2244
2245 result = vegam_program_mem_timing_parameters(hwmgr);
2246 PP_ASSERT_WITH_CODE((result == 0),
2247 "Failed to program memory timing parameters!",
2248 );
2249
2250 return result;
2251}
2252
2253int vegam_thermal_avfs_enable(struct pp_hwmgr *hwmgr)
2254{
2255 struct smu7_hwmgr *data = (struct smu7_hwmgr *)(hwmgr->backend);
2256 int ret;
2257
2258 if (!hwmgr->avfs_supported)
2259 return 0;
2260
2261 ret = smum_send_msg_to_smc(hwmgr, PPSMC_MSG_EnableAvfs);
2262 if (!ret) {
2263 if (data->apply_avfs_cks_off_voltage)
2264 ret = smum_send_msg_to_smc(hwmgr, PPSMC_MSG_ApplyAvfsCksOffVoltage);
2265 }
2266
2267 return ret;
2268}
2269
2270static int vegam_thermal_setup_fan_table(struct pp_hwmgr *hwmgr)
2271{
2272 PP_ASSERT_WITH_CODE(hwmgr->thermal_controller.fanInfo.bNoFan,
2273 "VBIOS fan info is not correct!",
2274 );
2275 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
2276 PHM_PlatformCaps_MicrocodeFanControl);
2277 return 0;
2278}
2279
2280const struct pp_smumgr_func vegam_smu_funcs = {
2281 .smu_init = vegam_smu_init,
2282 .smu_fini = smu7_smu_fini,
2283 .start_smu = vegam_start_smu,
2284 .check_fw_load_finish = smu7_check_fw_load_finish,
2285 .request_smu_load_fw = smu7_reload_firmware,
2286 .request_smu_load_specific_fw = NULL,
2287 .send_msg_to_smc = smu7_send_msg_to_smc,
2288 .send_msg_to_smc_with_parameter = smu7_send_msg_to_smc_with_parameter,
2289 .process_firmware_header = vegam_process_firmware_header,
2290 .is_dpm_running = vegam_is_dpm_running,
2291 .get_mac_definition = vegam_get_mac_definition,
2292 .update_smc_table = vegam_update_smc_table,
2293 .init_smc_table = vegam_init_smc_table,
2294 .get_offsetof = vegam_get_offsetof,
2295 .populate_all_graphic_levels = vegam_populate_all_graphic_levels,
2296 .populate_all_memory_levels = vegam_populate_all_memory_levels,
2297 .update_sclk_threshold = vegam_update_sclk_threshold,
2298 .is_hw_avfs_present = vegam_is_hw_avfs_present,
2299 .thermal_avfs_enable = vegam_thermal_avfs_enable,
2300 .thermal_setup_fan_table = vegam_thermal_setup_fan_table,
2301};
2302