2 * Copyright 2015 Advanced Micro Devices, Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
23 #include <linux/types.h>
24 #include <linux/kernel.h>
25 #include <linux/slab.h>
26 #include "atom-types.h"
28 #include "processpptables.h"
30 #include "cgs_common.h"
31 #include "smu/smu_8_0_d.h"
32 #include "smu8_fusion.h"
33 #include "smu/smu_8_0_sh_mask.h"
36 #include "hardwaremanager.h"
39 #include "power_state.h"
40 #include "cz_clockpowergating.h"
43 #define ixSMUSVI_NB_CURRENTVID 0xD8230044
44 #define CURRENT_NB_VID_MASK 0xff000000
45 #define CURRENT_NB_VID__SHIFT 24
46 #define ixSMUSVI_GFX_CURRENTVID 0xD8230048
47 #define CURRENT_GFX_VID_MASK 0xff000000
48 #define CURRENT_GFX_VID__SHIFT 24
50 static const unsigned long PhwCz_Magic = (unsigned long) PHM_Cz_Magic;
52 static struct cz_power_state *cast_PhwCzPowerState(struct pp_hw_power_state *hw_ps)
54 if (PhwCz_Magic != hw_ps->magic)
57 return (struct cz_power_state *)hw_ps;
60 static const struct cz_power_state *cast_const_PhwCzPowerState(
61 const struct pp_hw_power_state *hw_ps)
63 if (PhwCz_Magic != hw_ps->magic)
66 return (struct cz_power_state *)hw_ps;
69 uint32_t cz_get_eclk_level(struct pp_hwmgr *hwmgr,
70 uint32_t clock, uint32_t msg)
73 struct phm_vce_clock_voltage_dependency_table *ptable =
74 hwmgr->dyn_state.vce_clock_voltage_dependency_table;
77 case PPSMC_MSG_SetEclkSoftMin:
78 case PPSMC_MSG_SetEclkHardMin:
79 for (i = 0; i < (int)ptable->count; i++) {
80 if (clock <= ptable->entries[i].ecclk)
85 case PPSMC_MSG_SetEclkSoftMax:
86 case PPSMC_MSG_SetEclkHardMax:
87 for (i = ptable->count - 1; i >= 0; i--) {
88 if (clock >= ptable->entries[i].ecclk)
100 static uint32_t cz_get_sclk_level(struct pp_hwmgr *hwmgr,
101 uint32_t clock, uint32_t msg)
104 struct phm_clock_voltage_dependency_table *table =
105 hwmgr->dyn_state.vddc_dependency_on_sclk;
108 case PPSMC_MSG_SetSclkSoftMin:
109 case PPSMC_MSG_SetSclkHardMin:
110 for (i = 0; i < (int)table->count; i++) {
111 if (clock <= table->entries[i].clk)
116 case PPSMC_MSG_SetSclkSoftMax:
117 case PPSMC_MSG_SetSclkHardMax:
118 for (i = table->count - 1; i >= 0; i--) {
119 if (clock >= table->entries[i].clk)
130 static uint32_t cz_get_uvd_level(struct pp_hwmgr *hwmgr,
131 uint32_t clock, uint32_t msg)
134 struct phm_uvd_clock_voltage_dependency_table *ptable =
135 hwmgr->dyn_state.uvd_clock_voltage_dependency_table;
138 case PPSMC_MSG_SetUvdSoftMin:
139 case PPSMC_MSG_SetUvdHardMin:
140 for (i = 0; i < (int)ptable->count; i++) {
141 if (clock <= ptable->entries[i].vclk)
146 case PPSMC_MSG_SetUvdSoftMax:
147 case PPSMC_MSG_SetUvdHardMax:
148 for (i = ptable->count - 1; i >= 0; i--) {
149 if (clock >= ptable->entries[i].vclk)
161 static uint32_t cz_get_max_sclk_level(struct pp_hwmgr *hwmgr)
163 struct cz_hwmgr *cz_hwmgr = (struct cz_hwmgr *)(hwmgr->backend);
165 if (cz_hwmgr->max_sclk_level == 0) {
166 smum_send_msg_to_smc(hwmgr->smumgr, PPSMC_MSG_GetMaxSclkLevel);
167 cz_hwmgr->max_sclk_level = smum_get_argument(hwmgr->smumgr) + 1;
170 return cz_hwmgr->max_sclk_level;
173 static int cz_initialize_dpm_defaults(struct pp_hwmgr *hwmgr)
175 struct cz_hwmgr *cz_hwmgr = (struct cz_hwmgr *)(hwmgr->backend);
177 struct cgs_system_info sys_info = {0};
180 cz_hwmgr->gfx_ramp_step = 256*25/100;
182 cz_hwmgr->gfx_ramp_delay = 1; /* by default, we delay 1us */
184 for (i = 0; i < CZ_MAX_HARDWARE_POWERLEVELS; i++)
185 cz_hwmgr->activity_target[i] = CZ_AT_DFLT;
187 cz_hwmgr->mgcg_cgtt_local0 = 0x00000000;
188 cz_hwmgr->mgcg_cgtt_local1 = 0x00000000;
190 cz_hwmgr->clock_slow_down_freq = 25000;
192 cz_hwmgr->skip_clock_slow_down = 1;
194 cz_hwmgr->enable_nb_ps_policy = 1; /* disable until UNB is ready, Enabled */
196 cz_hwmgr->voltage_drop_in_dce_power_gating = 0; /* disable until fully verified */
198 cz_hwmgr->voting_rights_clients = 0x00C00033;
200 cz_hwmgr->static_screen_threshold = 8;
202 cz_hwmgr->ddi_power_gating_disabled = 0;
204 cz_hwmgr->bapm_enabled = 1;
206 cz_hwmgr->voltage_drop_threshold = 0;
208 cz_hwmgr->gfx_power_gating_threshold = 500;
210 cz_hwmgr->vce_slow_sclk_threshold = 20000;
212 cz_hwmgr->dce_slow_sclk_threshold = 30000;
214 cz_hwmgr->disable_driver_thermal_policy = 1;
216 cz_hwmgr->disable_nb_ps3_in_battery = 0;
218 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
219 PHM_PlatformCaps_ABM);
221 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
222 PHM_PlatformCaps_NonABMSupportInPPLib);
224 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
225 PHM_PlatformCaps_SclkDeepSleep);
227 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
228 PHM_PlatformCaps_DynamicM3Arbiter);
230 cz_hwmgr->override_dynamic_mgpg = 1;
232 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
233 PHM_PlatformCaps_DynamicPatchPowerState);
235 cz_hwmgr->thermal_auto_throttling_treshold = 0;
237 cz_hwmgr->tdr_clock = 0;
239 cz_hwmgr->disable_gfx_power_gating_in_uvd = 0;
241 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
242 PHM_PlatformCaps_DynamicUVDState);
244 cz_hwmgr->cc6_settings.cpu_cc6_disable = false;
245 cz_hwmgr->cc6_settings.cpu_pstate_disable = false;
246 cz_hwmgr->cc6_settings.nb_pstate_switch_disable = false;
247 cz_hwmgr->cc6_settings.cpu_pstate_separation_time = 0;
249 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
250 PHM_PlatformCaps_DisableVoltageIsland);
252 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
253 PHM_PlatformCaps_UVDPowerGating);
254 phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
255 PHM_PlatformCaps_VCEPowerGating);
256 sys_info.size = sizeof(struct cgs_system_info);
257 sys_info.info_id = CGS_SYSTEM_INFO_PG_FLAGS;
258 result = cgs_query_system_info(hwmgr->device, &sys_info);
260 if (sys_info.value & AMD_PG_SUPPORT_UVD)
261 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
262 PHM_PlatformCaps_UVDPowerGating);
263 if (sys_info.value & AMD_PG_SUPPORT_VCE)
264 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
265 PHM_PlatformCaps_VCEPowerGating);
271 static uint32_t cz_convert_8Bit_index_to_voltage(
272 struct pp_hwmgr *hwmgr, uint16_t voltage)
274 return 6200 - (voltage * 25);
277 static int cz_construct_max_power_limits_table(struct pp_hwmgr *hwmgr,
278 struct phm_clock_and_voltage_limits *table)
280 struct cz_hwmgr *cz_hwmgr = (struct cz_hwmgr *)hwmgr->backend;
281 struct cz_sys_info *sys_info = &cz_hwmgr->sys_info;
282 struct phm_clock_voltage_dependency_table *dep_table =
283 hwmgr->dyn_state.vddc_dependency_on_sclk;
285 if (dep_table->count > 0) {
286 table->sclk = dep_table->entries[dep_table->count-1].clk;
287 table->vddc = cz_convert_8Bit_index_to_voltage(hwmgr,
288 (uint16_t)dep_table->entries[dep_table->count-1].v);
290 table->mclk = sys_info->nbp_memory_clock[0];
294 static int cz_init_dynamic_state_adjustment_rule_settings(
295 struct pp_hwmgr *hwmgr,
296 ATOM_CLK_VOLT_CAPABILITY *disp_voltage_table)
298 uint32_t table_size =
299 sizeof(struct phm_clock_voltage_dependency_table) +
300 (7 * sizeof(struct phm_clock_voltage_dependency_record));
302 struct phm_clock_voltage_dependency_table *table_clk_vlt =
303 kzalloc(table_size, GFP_KERNEL);
305 if (NULL == table_clk_vlt) {
306 printk(KERN_ERR "[ powerplay ] Can not allocate memory!\n");
310 table_clk_vlt->count = 8;
311 table_clk_vlt->entries[0].clk = PP_DAL_POWERLEVEL_0;
312 table_clk_vlt->entries[0].v = 0;
313 table_clk_vlt->entries[1].clk = PP_DAL_POWERLEVEL_1;
314 table_clk_vlt->entries[1].v = 1;
315 table_clk_vlt->entries[2].clk = PP_DAL_POWERLEVEL_2;
316 table_clk_vlt->entries[2].v = 2;
317 table_clk_vlt->entries[3].clk = PP_DAL_POWERLEVEL_3;
318 table_clk_vlt->entries[3].v = 3;
319 table_clk_vlt->entries[4].clk = PP_DAL_POWERLEVEL_4;
320 table_clk_vlt->entries[4].v = 4;
321 table_clk_vlt->entries[5].clk = PP_DAL_POWERLEVEL_5;
322 table_clk_vlt->entries[5].v = 5;
323 table_clk_vlt->entries[6].clk = PP_DAL_POWERLEVEL_6;
324 table_clk_vlt->entries[6].v = 6;
325 table_clk_vlt->entries[7].clk = PP_DAL_POWERLEVEL_7;
326 table_clk_vlt->entries[7].v = 7;
327 hwmgr->dyn_state.vddc_dep_on_dal_pwrl = table_clk_vlt;
332 static int cz_get_system_info_data(struct pp_hwmgr *hwmgr)
334 struct cz_hwmgr *cz_hwmgr = (struct cz_hwmgr *)hwmgr->backend;
335 ATOM_INTEGRATED_SYSTEM_INFO_V1_9 *info = NULL;
341 info = (ATOM_INTEGRATED_SYSTEM_INFO_V1_9 *) cgs_atom_get_data_table(
343 GetIndexIntoMasterTable(DATA, IntegratedSystemInfo),
344 &size, &frev, &crev);
347 printk(KERN_ERR "[ powerplay ] Unsupported IGP table: %d %d\n", frev, crev);
352 printk(KERN_ERR "[ powerplay ] Could not retrieve the Integrated System Info Table!\n");
356 cz_hwmgr->sys_info.bootup_uma_clock =
357 le32_to_cpu(info->ulBootUpUMAClock);
359 cz_hwmgr->sys_info.bootup_engine_clock =
360 le32_to_cpu(info->ulBootUpEngineClock);
362 cz_hwmgr->sys_info.dentist_vco_freq =
363 le32_to_cpu(info->ulDentistVCOFreq);
365 cz_hwmgr->sys_info.system_config =
366 le32_to_cpu(info->ulSystemConfig);
368 cz_hwmgr->sys_info.bootup_nb_voltage_index =
369 le16_to_cpu(info->usBootUpNBVoltage);
371 cz_hwmgr->sys_info.htc_hyst_lmt =
372 (info->ucHtcHystLmt == 0) ? 5 : info->ucHtcHystLmt;
374 cz_hwmgr->sys_info.htc_tmp_lmt =
375 (info->ucHtcTmpLmt == 0) ? 203 : info->ucHtcTmpLmt;
377 if (cz_hwmgr->sys_info.htc_tmp_lmt <=
378 cz_hwmgr->sys_info.htc_hyst_lmt) {
379 printk(KERN_ERR "[ powerplay ] The htcTmpLmt should be larger than htcHystLmt.\n");
383 cz_hwmgr->sys_info.nb_dpm_enable =
384 cz_hwmgr->enable_nb_ps_policy &&
385 (le32_to_cpu(info->ulSystemConfig) >> 3 & 0x1);
387 for (i = 0; i < CZ_NUM_NBPSTATES; i++) {
388 if (i < CZ_NUM_NBPMEMORYCLOCK) {
389 cz_hwmgr->sys_info.nbp_memory_clock[i] =
390 le32_to_cpu(info->ulNbpStateMemclkFreq[i]);
392 cz_hwmgr->sys_info.nbp_n_clock[i] =
393 le32_to_cpu(info->ulNbpStateNClkFreq[i]);
396 for (i = 0; i < MAX_DISPLAY_CLOCK_LEVEL; i++) {
397 cz_hwmgr->sys_info.display_clock[i] =
398 le32_to_cpu(info->sDispClkVoltageMapping[i].ulMaximumSupportedCLK);
401 /* Here use 4 levels, make sure not exceed */
402 for (i = 0; i < CZ_NUM_NBPSTATES; i++) {
403 cz_hwmgr->sys_info.nbp_voltage_index[i] =
404 le16_to_cpu(info->usNBPStateVoltage[i]);
407 if (!cz_hwmgr->sys_info.nb_dpm_enable) {
408 for (i = 1; i < CZ_NUM_NBPSTATES; i++) {
409 if (i < CZ_NUM_NBPMEMORYCLOCK) {
410 cz_hwmgr->sys_info.nbp_memory_clock[i] =
411 cz_hwmgr->sys_info.nbp_memory_clock[0];
413 cz_hwmgr->sys_info.nbp_n_clock[i] =
414 cz_hwmgr->sys_info.nbp_n_clock[0];
415 cz_hwmgr->sys_info.nbp_voltage_index[i] =
416 cz_hwmgr->sys_info.nbp_voltage_index[0];
420 if (le32_to_cpu(info->ulGPUCapInfo) &
421 SYS_INFO_GPUCAPS__ENABEL_DFS_BYPASS) {
422 phm_cap_set(hwmgr->platform_descriptor.platformCaps,
423 PHM_PlatformCaps_EnableDFSBypass);
426 cz_hwmgr->sys_info.uma_channel_number = info->ucUMAChannelNumber;
428 cz_construct_max_power_limits_table (hwmgr,
429 &hwmgr->dyn_state.max_clock_voltage_on_ac);
431 cz_init_dynamic_state_adjustment_rule_settings(hwmgr,
432 &info->sDISPCLK_Voltage[0]);
437 static int cz_construct_boot_state(struct pp_hwmgr *hwmgr)
439 struct cz_hwmgr *cz_hwmgr = (struct cz_hwmgr *)(hwmgr->backend);
441 cz_hwmgr->boot_power_level.engineClock =
442 cz_hwmgr->sys_info.bootup_engine_clock;
444 cz_hwmgr->boot_power_level.vddcIndex =
445 (uint8_t)cz_hwmgr->sys_info.bootup_nb_voltage_index;
447 cz_hwmgr->boot_power_level.dsDividerIndex = 0;
449 cz_hwmgr->boot_power_level.ssDividerIndex = 0;
451 cz_hwmgr->boot_power_level.allowGnbSlow = 1;
453 cz_hwmgr->boot_power_level.forceNBPstate = 0;
455 cz_hwmgr->boot_power_level.hysteresis_up = 0;
457 cz_hwmgr->boot_power_level.numSIMDToPowerDown = 0;
459 cz_hwmgr->boot_power_level.display_wm = 0;
461 cz_hwmgr->boot_power_level.vce_wm = 0;
466 static int cz_tf_reset_active_process_mask(struct pp_hwmgr *hwmgr, void *input,
467 void *output, void *storage, int result)
472 static int cz_tf_upload_pptable_to_smu(struct pp_hwmgr *hwmgr, void *input,
473 void *output, void *storage, int result)
475 struct SMU8_Fusion_ClkTable *clock_table;
479 pp_atomctrl_clock_dividers_kong dividers;
481 struct phm_clock_voltage_dependency_table *vddc_table =
482 hwmgr->dyn_state.vddc_dependency_on_sclk;
483 struct phm_clock_voltage_dependency_table *vdd_gfx_table =
484 hwmgr->dyn_state.vdd_gfx_dependency_on_sclk;
485 struct phm_acp_clock_voltage_dependency_table *acp_table =
486 hwmgr->dyn_state.acp_clock_voltage_dependency_table;
487 struct phm_uvd_clock_voltage_dependency_table *uvd_table =
488 hwmgr->dyn_state.uvd_clock_voltage_dependency_table;
489 struct phm_vce_clock_voltage_dependency_table *vce_table =
490 hwmgr->dyn_state.vce_clock_voltage_dependency_table;
492 if (!hwmgr->need_pp_table_upload)
495 ret = smum_download_powerplay_table(hwmgr->smumgr, &table);
497 PP_ASSERT_WITH_CODE((0 == ret && NULL != table),
498 "Fail to get clock table from SMU!", return -EINVAL;);
500 clock_table = (struct SMU8_Fusion_ClkTable *)table;
502 /* patch clock table */
503 PP_ASSERT_WITH_CODE((vddc_table->count <= CZ_MAX_HARDWARE_POWERLEVELS),
504 "Dependency table entry exceeds max limit!", return -EINVAL;);
505 PP_ASSERT_WITH_CODE((vdd_gfx_table->count <= CZ_MAX_HARDWARE_POWERLEVELS),
506 "Dependency table entry exceeds max limit!", return -EINVAL;);
507 PP_ASSERT_WITH_CODE((acp_table->count <= CZ_MAX_HARDWARE_POWERLEVELS),
508 "Dependency table entry exceeds max limit!", return -EINVAL;);
509 PP_ASSERT_WITH_CODE((uvd_table->count <= CZ_MAX_HARDWARE_POWERLEVELS),
510 "Dependency table entry exceeds max limit!", return -EINVAL;);
511 PP_ASSERT_WITH_CODE((vce_table->count <= CZ_MAX_HARDWARE_POWERLEVELS),
512 "Dependency table entry exceeds max limit!", return -EINVAL;);
514 for (i = 0; i < CZ_MAX_HARDWARE_POWERLEVELS; i++) {
517 clock_table->SclkBreakdownTable.ClkLevel[i].GnbVid =
518 (i < vddc_table->count) ? (uint8_t)vddc_table->entries[i].v : 0;
519 clock_table->SclkBreakdownTable.ClkLevel[i].Frequency =
520 (i < vddc_table->count) ? vddc_table->entries[i].clk : 0;
522 atomctrl_get_engine_pll_dividers_kong(hwmgr,
523 clock_table->SclkBreakdownTable.ClkLevel[i].Frequency,
526 clock_table->SclkBreakdownTable.ClkLevel[i].DfsDid =
527 (uint8_t)dividers.pll_post_divider;
530 clock_table->SclkBreakdownTable.ClkLevel[i].GfxVid =
531 (i < vdd_gfx_table->count) ? (uint8_t)vdd_gfx_table->entries[i].v : 0;
534 clock_table->AclkBreakdownTable.ClkLevel[i].GfxVid =
535 (i < acp_table->count) ? (uint8_t)acp_table->entries[i].v : 0;
536 clock_table->AclkBreakdownTable.ClkLevel[i].Frequency =
537 (i < acp_table->count) ? acp_table->entries[i].acpclk : 0;
539 atomctrl_get_engine_pll_dividers_kong(hwmgr,
540 clock_table->AclkBreakdownTable.ClkLevel[i].Frequency,
543 clock_table->AclkBreakdownTable.ClkLevel[i].DfsDid =
544 (uint8_t)dividers.pll_post_divider;
548 clock_table->VclkBreakdownTable.ClkLevel[i].GfxVid =
549 (i < uvd_table->count) ? (uint8_t)uvd_table->entries[i].v : 0;
550 clock_table->VclkBreakdownTable.ClkLevel[i].Frequency =
551 (i < uvd_table->count) ? uvd_table->entries[i].vclk : 0;
553 atomctrl_get_engine_pll_dividers_kong(hwmgr,
554 clock_table->VclkBreakdownTable.ClkLevel[i].Frequency,
557 clock_table->VclkBreakdownTable.ClkLevel[i].DfsDid =
558 (uint8_t)dividers.pll_post_divider;
560 clock_table->DclkBreakdownTable.ClkLevel[i].GfxVid =
561 (i < uvd_table->count) ? (uint8_t)uvd_table->entries[i].v : 0;
562 clock_table->DclkBreakdownTable.ClkLevel[i].Frequency =
563 (i < uvd_table->count) ? uvd_table->entries[i].dclk : 0;
565 atomctrl_get_engine_pll_dividers_kong(hwmgr,
566 clock_table->DclkBreakdownTable.ClkLevel[i].Frequency,
569 clock_table->DclkBreakdownTable.ClkLevel[i].DfsDid =
570 (uint8_t)dividers.pll_post_divider;
573 clock_table->EclkBreakdownTable.ClkLevel[i].GfxVid =
574 (i < vce_table->count) ? (uint8_t)vce_table->entries[i].v : 0;
575 clock_table->EclkBreakdownTable.ClkLevel[i].Frequency =
576 (i < vce_table->count) ? vce_table->entries[i].ecclk : 0;
579 atomctrl_get_engine_pll_dividers_kong(hwmgr,
580 clock_table->EclkBreakdownTable.ClkLevel[i].Frequency,
583 clock_table->EclkBreakdownTable.ClkLevel[i].DfsDid =
584 (uint8_t)dividers.pll_post_divider;
587 ret = smum_upload_powerplay_table(hwmgr->smumgr);
592 static int cz_tf_init_sclk_limit(struct pp_hwmgr *hwmgr, void *input,
593 void *output, void *storage, int result)
595 struct cz_hwmgr *cz_hwmgr = (struct cz_hwmgr *)(hwmgr->backend);
596 struct phm_clock_voltage_dependency_table *table =
597 hwmgr->dyn_state.vddc_dependency_on_sclk;
598 unsigned long clock = 0, level;
600 if (NULL == table || table->count <= 0)
603 cz_hwmgr->sclk_dpm.soft_min_clk = table->entries[0].clk;
604 cz_hwmgr->sclk_dpm.hard_min_clk = table->entries[0].clk;
606 level = cz_get_max_sclk_level(hwmgr) - 1;
608 if (level < table->count)
609 clock = table->entries[level].clk;
611 clock = table->entries[table->count - 1].clk;
613 cz_hwmgr->sclk_dpm.soft_max_clk = clock;
614 cz_hwmgr->sclk_dpm.hard_max_clk = clock;
619 static int cz_tf_init_uvd_limit(struct pp_hwmgr *hwmgr, void *input,
620 void *output, void *storage, int result)
622 struct cz_hwmgr *cz_hwmgr = (struct cz_hwmgr *)(hwmgr->backend);
623 struct phm_uvd_clock_voltage_dependency_table *table =
624 hwmgr->dyn_state.uvd_clock_voltage_dependency_table;
625 unsigned long clock = 0, level;
627 if (NULL == table || table->count <= 0)
630 cz_hwmgr->uvd_dpm.soft_min_clk = 0;
631 cz_hwmgr->uvd_dpm.hard_min_clk = 0;
633 smum_send_msg_to_smc(hwmgr->smumgr, PPSMC_MSG_GetMaxUvdLevel);
634 level = smum_get_argument(hwmgr->smumgr);
636 if (level < table->count)
637 clock = table->entries[level].vclk;
639 clock = table->entries[table->count - 1].vclk;
641 cz_hwmgr->uvd_dpm.soft_max_clk = clock;
642 cz_hwmgr->uvd_dpm.hard_max_clk = clock;
647 static int cz_tf_init_vce_limit(struct pp_hwmgr *hwmgr, void *input,
648 void *output, void *storage, int result)
650 struct cz_hwmgr *cz_hwmgr = (struct cz_hwmgr *)(hwmgr->backend);
651 struct phm_vce_clock_voltage_dependency_table *table =
652 hwmgr->dyn_state.vce_clock_voltage_dependency_table;
653 unsigned long clock = 0, level;
655 if (NULL == table || table->count <= 0)
658 cz_hwmgr->vce_dpm.soft_min_clk = 0;
659 cz_hwmgr->vce_dpm.hard_min_clk = 0;
661 smum_send_msg_to_smc(hwmgr->smumgr, PPSMC_MSG_GetMaxEclkLevel);
662 level = smum_get_argument(hwmgr->smumgr);
664 if (level < table->count)
665 clock = table->entries[level].ecclk;
667 clock = table->entries[table->count - 1].ecclk;
669 cz_hwmgr->vce_dpm.soft_max_clk = clock;
670 cz_hwmgr->vce_dpm.hard_max_clk = clock;
675 static int cz_tf_init_acp_limit(struct pp_hwmgr *hwmgr, void *input,
676 void *output, void *storage, int result)
678 struct cz_hwmgr *cz_hwmgr = (struct cz_hwmgr *)(hwmgr->backend);
679 struct phm_acp_clock_voltage_dependency_table *table =
680 hwmgr->dyn_state.acp_clock_voltage_dependency_table;
681 unsigned long clock = 0, level;
683 if (NULL == table || table->count <= 0)
686 cz_hwmgr->acp_dpm.soft_min_clk = 0;
687 cz_hwmgr->acp_dpm.hard_min_clk = 0;
689 smum_send_msg_to_smc(hwmgr->smumgr, PPSMC_MSG_GetMaxAclkLevel);
690 level = smum_get_argument(hwmgr->smumgr);
692 if (level < table->count)
693 clock = table->entries[level].acpclk;
695 clock = table->entries[table->count - 1].acpclk;
697 cz_hwmgr->acp_dpm.soft_max_clk = clock;
698 cz_hwmgr->acp_dpm.hard_max_clk = clock;
702 static int cz_tf_init_power_gate_state(struct pp_hwmgr *hwmgr, void *input,
703 void *output, void *storage, int result)
705 struct cz_hwmgr *cz_hwmgr = (struct cz_hwmgr *)(hwmgr->backend);
707 cz_hwmgr->uvd_power_gated = false;
708 cz_hwmgr->vce_power_gated = false;
709 cz_hwmgr->samu_power_gated = false;
710 cz_hwmgr->acp_power_gated = false;
711 cz_hwmgr->pgacpinit = true;
716 static int cz_tf_init_sclk_threshold(struct pp_hwmgr *hwmgr, void *input,
717 void *output, void *storage, int result)
719 struct cz_hwmgr *cz_hwmgr = (struct cz_hwmgr *)(hwmgr->backend);
721 cz_hwmgr->low_sclk_interrupt_threshold = 0;
725 static int cz_tf_update_sclk_limit(struct pp_hwmgr *hwmgr,
726 void *input, void *output,
727 void *storage, int result)
729 struct cz_hwmgr *cz_hwmgr = (struct cz_hwmgr *)(hwmgr->backend);
730 struct phm_clock_voltage_dependency_table *table =
731 hwmgr->dyn_state.vddc_dependency_on_sclk;
733 unsigned long clock = 0;
735 unsigned long stable_pstate_sclk;
736 struct PP_Clocks clocks;
737 unsigned long percentage;
739 cz_hwmgr->sclk_dpm.soft_min_clk = table->entries[0].clk;
740 level = cz_get_max_sclk_level(hwmgr) - 1;
742 if (level < table->count)
743 cz_hwmgr->sclk_dpm.soft_max_clk = table->entries[level].clk;
745 cz_hwmgr->sclk_dpm.soft_max_clk = table->entries[table->count - 1].clk;
747 /*PECI_GetMinClockSettings(pHwMgr->pPECI, &clocks);*/
748 clock = clocks.engineClock;
750 if (cz_hwmgr->sclk_dpm.hard_min_clk != clock) {
751 cz_hwmgr->sclk_dpm.hard_min_clk = clock;
753 smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
754 PPSMC_MSG_SetSclkHardMin,
755 cz_get_sclk_level(hwmgr,
756 cz_hwmgr->sclk_dpm.hard_min_clk,
757 PPSMC_MSG_SetSclkHardMin));
760 clock = cz_hwmgr->sclk_dpm.soft_min_clk;
762 /* update minimum clocks for Stable P-State feature */
763 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
764 PHM_PlatformCaps_StablePState)) {
766 /*Sclk - calculate sclk value based on percentage and find FLOOR sclk from VddcDependencyOnSCLK table */
767 stable_pstate_sclk = (hwmgr->dyn_state.max_clock_voltage_on_ac.mclk *
770 if (clock < stable_pstate_sclk)
771 clock = stable_pstate_sclk;
773 if (clock < hwmgr->gfx_arbiter.sclk)
774 clock = hwmgr->gfx_arbiter.sclk;
777 if (cz_hwmgr->sclk_dpm.soft_min_clk != clock) {
778 cz_hwmgr->sclk_dpm.soft_min_clk = clock;
779 smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
780 PPSMC_MSG_SetSclkSoftMin,
781 cz_get_sclk_level(hwmgr,
782 cz_hwmgr->sclk_dpm.soft_min_clk,
783 PPSMC_MSG_SetSclkSoftMin));
786 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
787 PHM_PlatformCaps_StablePState) &&
788 cz_hwmgr->sclk_dpm.soft_max_clk != clock) {
789 cz_hwmgr->sclk_dpm.soft_max_clk = clock;
790 smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
791 PPSMC_MSG_SetSclkSoftMax,
792 cz_get_sclk_level(hwmgr,
793 cz_hwmgr->sclk_dpm.soft_max_clk,
794 PPSMC_MSG_SetSclkSoftMax));
800 static int cz_tf_set_deep_sleep_sclk_threshold(struct pp_hwmgr *hwmgr,
801 void *input, void *output,
802 void *storage, int result)
804 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
805 PHM_PlatformCaps_SclkDeepSleep)) {
806 uint32_t clks = hwmgr->display_config.min_core_set_clock_in_sr;
808 clks = CZ_MIN_DEEP_SLEEP_SCLK;
810 PP_DBG_LOG("Setting Deep Sleep Clock: %d\n", clks);
812 smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
813 PPSMC_MSG_SetMinDeepSleepSclk,
820 static int cz_tf_set_watermark_threshold(struct pp_hwmgr *hwmgr,
821 void *input, void *output,
822 void *storage, int result)
824 struct cz_hwmgr *cz_hwmgr =
825 (struct cz_hwmgr *)(hwmgr->backend);
827 smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
828 PPSMC_MSG_SetWatermarkFrequency,
829 cz_hwmgr->sclk_dpm.soft_max_clk);
834 static int cz_tf_set_enabled_levels(struct pp_hwmgr *hwmgr,
835 void *input, void *output,
836 void *storage, int result)
842 static int cz_tf_enable_nb_dpm(struct pp_hwmgr *hwmgr,
843 void *input, void *output,
844 void *storage, int result)
848 struct cz_hwmgr *cz_hwmgr = (struct cz_hwmgr *)(hwmgr->backend);
849 unsigned long dpm_features = 0;
851 if (!cz_hwmgr->is_nb_dpm_enabled) {
852 PP_DBG_LOG("enabling ALL SMU features.\n");
853 dpm_features |= NB_DPM_MASK;
854 ret = smum_send_msg_to_smc_with_parameter(
856 PPSMC_MSG_EnableAllSmuFeatures,
859 cz_hwmgr->is_nb_dpm_enabled = true;
865 static int cz_nbdpm_pstate_enable_disable(struct pp_hwmgr *hwmgr, bool enable, bool lock)
867 struct cz_hwmgr *hw_data = (struct cz_hwmgr *)(hwmgr->backend);
869 if (hw_data->is_nb_dpm_enabled) {
871 PP_DBG_LOG("enable Low Memory PState.\n");
873 return smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
874 PPSMC_MSG_EnableLowMemoryPstate,
877 PP_DBG_LOG("disable Low Memory PState.\n");
879 return smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
880 PPSMC_MSG_DisableLowMemoryPstate,
888 static int cz_tf_update_low_mem_pstate(struct pp_hwmgr *hwmgr,
889 void *input, void *output,
890 void *storage, int result)
893 bool enable_low_mem_state;
894 struct cz_hwmgr *hw_data = (struct cz_hwmgr *)(hwmgr->backend);
895 const struct phm_set_power_state_input *states = (struct phm_set_power_state_input *)input;
896 const struct cz_power_state *pnew_state = cast_const_PhwCzPowerState(states->pnew_state);
898 if (hw_data->sys_info.nb_dpm_enable) {
899 disable_switch = hw_data->cc6_settings.nb_pstate_switch_disable ? true : false;
900 enable_low_mem_state = hw_data->cc6_settings.nb_pstate_switch_disable ? false : true;
902 if (pnew_state->action == FORCE_HIGH)
903 cz_nbdpm_pstate_enable_disable(hwmgr, false, disable_switch);
904 else if(pnew_state->action == CANCEL_FORCE_HIGH)
905 cz_nbdpm_pstate_enable_disable(hwmgr, false, disable_switch);
907 cz_nbdpm_pstate_enable_disable(hwmgr, enable_low_mem_state, disable_switch);
912 static struct phm_master_table_item cz_set_power_state_list[] = {
913 {NULL, cz_tf_update_sclk_limit},
914 {NULL, cz_tf_set_deep_sleep_sclk_threshold},
915 {NULL, cz_tf_set_watermark_threshold},
916 {NULL, cz_tf_set_enabled_levels},
917 {NULL, cz_tf_enable_nb_dpm},
918 {NULL, cz_tf_update_low_mem_pstate},
922 static struct phm_master_table_header cz_set_power_state_master = {
924 PHM_MasterTableFlag_None,
925 cz_set_power_state_list
928 static struct phm_master_table_item cz_setup_asic_list[] = {
929 {NULL, cz_tf_reset_active_process_mask},
930 {NULL, cz_tf_upload_pptable_to_smu},
931 {NULL, cz_tf_init_sclk_limit},
932 {NULL, cz_tf_init_uvd_limit},
933 {NULL, cz_tf_init_vce_limit},
934 {NULL, cz_tf_init_acp_limit},
935 {NULL, cz_tf_init_power_gate_state},
936 {NULL, cz_tf_init_sclk_threshold},
940 static struct phm_master_table_header cz_setup_asic_master = {
942 PHM_MasterTableFlag_None,
946 static int cz_tf_power_up_display_clock_sys_pll(struct pp_hwmgr *hwmgr,
947 void *input, void *output,
948 void *storage, int result)
950 struct cz_hwmgr *hw_data = (struct cz_hwmgr *)(hwmgr->backend);
951 hw_data->disp_clk_bypass_pending = false;
952 hw_data->disp_clk_bypass = false;
957 static int cz_tf_clear_nb_dpm_flag(struct pp_hwmgr *hwmgr,
958 void *input, void *output,
959 void *storage, int result)
961 struct cz_hwmgr *hw_data = (struct cz_hwmgr *)(hwmgr->backend);
962 hw_data->is_nb_dpm_enabled = false;
967 static int cz_tf_reset_cc6_data(struct pp_hwmgr *hwmgr,
968 void *input, void *output,
969 void *storage, int result)
971 struct cz_hwmgr *hw_data = (struct cz_hwmgr *)(hwmgr->backend);
973 hw_data->cc6_settings.cc6_setting_changed = false;
974 hw_data->cc6_settings.cpu_pstate_separation_time = 0;
975 hw_data->cc6_settings.cpu_cc6_disable = false;
976 hw_data->cc6_settings.cpu_pstate_disable = false;
981 static struct phm_master_table_item cz_power_down_asic_list[] = {
982 {NULL, cz_tf_power_up_display_clock_sys_pll},
983 {NULL, cz_tf_clear_nb_dpm_flag},
984 {NULL, cz_tf_reset_cc6_data},
988 static struct phm_master_table_header cz_power_down_asic_master = {
990 PHM_MasterTableFlag_None,
991 cz_power_down_asic_list
994 static int cz_tf_program_voting_clients(struct pp_hwmgr *hwmgr, void *input,
995 void *output, void *storage, int result)
997 PHMCZ_WRITE_SMC_REGISTER(hwmgr->device, CG_FREQ_TRAN_VOTING_0,
998 PPCZ_VOTINGRIGHTSCLIENTS_DFLT0);
1002 static int cz_tf_start_dpm(struct pp_hwmgr *hwmgr, void *input, void *output,
1003 void *storage, int result)
1006 struct cz_hwmgr *cz_hwmgr = (struct cz_hwmgr *)(hwmgr->backend);
1007 unsigned long dpm_features = 0;
1009 cz_hwmgr->dpm_flags |= DPMFlags_SCLK_Enabled;
1010 dpm_features |= SCLK_DPM_MASK;
1012 res = smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
1013 PPSMC_MSG_EnableAllSmuFeatures,
1019 static int cz_tf_program_bootup_state(struct pp_hwmgr *hwmgr, void *input,
1020 void *output, void *storage, int result)
1022 struct cz_hwmgr *cz_hwmgr = (struct cz_hwmgr *)(hwmgr->backend);
1024 cz_hwmgr->sclk_dpm.soft_min_clk = cz_hwmgr->sys_info.bootup_engine_clock;
1025 cz_hwmgr->sclk_dpm.soft_max_clk = cz_hwmgr->sys_info.bootup_engine_clock;
1027 smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
1028 PPSMC_MSG_SetSclkSoftMin,
1029 cz_get_sclk_level(hwmgr,
1030 cz_hwmgr->sclk_dpm.soft_min_clk,
1031 PPSMC_MSG_SetSclkSoftMin));
1033 smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
1034 PPSMC_MSG_SetSclkSoftMax,
1035 cz_get_sclk_level(hwmgr,
1036 cz_hwmgr->sclk_dpm.soft_max_clk,
1037 PPSMC_MSG_SetSclkSoftMax));
1042 int cz_tf_reset_acp_boot_level(struct pp_hwmgr *hwmgr, void *input,
1043 void *output, void *storage, int result)
1045 struct cz_hwmgr *cz_hwmgr = (struct cz_hwmgr *)(hwmgr->backend);
1047 cz_hwmgr->acp_boot_level = 0xff;
1051 static bool cz_dpm_check_smu_features(struct pp_hwmgr *hwmgr,
1052 unsigned long check_feature)
1055 unsigned long features;
1057 result = smum_send_msg_to_smc_with_parameter(hwmgr->smumgr, PPSMC_MSG_GetFeatureStatus, 0);
1059 features = smum_get_argument(hwmgr->smumgr);
1060 if (features & check_feature)
1067 static int cz_tf_check_for_dpm_disabled(struct pp_hwmgr *hwmgr, void *input,
1068 void *output, void *storage, int result)
1070 if (cz_dpm_check_smu_features(hwmgr, SMU_EnabledFeatureScoreboard_SclkDpmOn))
1071 return PP_Result_TableImmediateExit;
1075 static int cz_tf_enable_didt(struct pp_hwmgr *hwmgr, void *input,
1076 void *output, void *storage, int result)
1082 static int cz_tf_check_for_dpm_enabled(struct pp_hwmgr *hwmgr,
1083 void *input, void *output,
1084 void *storage, int result)
1086 if (!cz_dpm_check_smu_features(hwmgr,
1087 SMU_EnabledFeatureScoreboard_SclkDpmOn))
1088 return PP_Result_TableImmediateExit;
1092 static struct phm_master_table_item cz_disable_dpm_list[] = {
1093 { NULL, cz_tf_check_for_dpm_enabled},
1098 static struct phm_master_table_header cz_disable_dpm_master = {
1100 PHM_MasterTableFlag_None,
1104 static struct phm_master_table_item cz_enable_dpm_list[] = {
1105 { NULL, cz_tf_check_for_dpm_disabled },
1106 { NULL, cz_tf_program_voting_clients },
1107 { NULL, cz_tf_start_dpm},
1108 { NULL, cz_tf_program_bootup_state},
1109 { NULL, cz_tf_enable_didt },
1110 { NULL, cz_tf_reset_acp_boot_level },
1114 static struct phm_master_table_header cz_enable_dpm_master = {
1116 PHM_MasterTableFlag_None,
1120 static int cz_apply_state_adjust_rules(struct pp_hwmgr *hwmgr,
1121 struct pp_power_state *prequest_ps,
1122 const struct pp_power_state *pcurrent_ps)
1124 struct cz_power_state *cz_ps =
1125 cast_PhwCzPowerState(&prequest_ps->hardware);
1127 const struct cz_power_state *cz_current_ps =
1128 cast_const_PhwCzPowerState(&pcurrent_ps->hardware);
1130 struct cz_hwmgr *cz_hwmgr = (struct cz_hwmgr *)(hwmgr->backend);
1131 struct PP_Clocks clocks;
1133 unsigned long num_of_active_displays = 4;
1135 cz_ps->evclk = hwmgr->vce_arbiter.evclk;
1136 cz_ps->ecclk = hwmgr->vce_arbiter.ecclk;
1138 cz_ps->need_dfs_bypass = true;
1140 cz_hwmgr->video_start = (hwmgr->uvd_arbiter.vclk != 0 || hwmgr->uvd_arbiter.dclk != 0 ||
1141 hwmgr->vce_arbiter.evclk != 0 || hwmgr->vce_arbiter.ecclk != 0);
1143 cz_hwmgr->battery_state = (PP_StateUILabel_Battery == prequest_ps->classification.ui_label);
1145 /* to do PECI_GetMinClockSettings(pHwMgr->pPECI, &clocks); */
1146 /* PECI_GetNumberOfActiveDisplays(pHwMgr->pPECI, &numOfActiveDisplays); */
1147 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_StablePState))
1148 clocks.memoryClock = hwmgr->dyn_state.max_clock_voltage_on_ac.mclk;
1150 clocks.memoryClock = 0;
1152 if (clocks.memoryClock < hwmgr->gfx_arbiter.mclk)
1153 clocks.memoryClock = hwmgr->gfx_arbiter.mclk;
1155 force_high = (clocks.memoryClock > cz_hwmgr->sys_info.nbp_memory_clock[CZ_NUM_NBPMEMORYCLOCK - 1])
1156 || (num_of_active_displays >= 3);
1158 cz_ps->action = cz_current_ps->action;
1160 if ((force_high == false) && (cz_ps->action == FORCE_HIGH))
1161 cz_ps->action = CANCEL_FORCE_HIGH;
1162 else if ((force_high == true) && (cz_ps->action != FORCE_HIGH))
1163 cz_ps->action = FORCE_HIGH;
1165 cz_ps->action = DO_NOTHING;
1170 static int cz_hwmgr_backend_init(struct pp_hwmgr *hwmgr)
1174 result = cz_initialize_dpm_defaults(hwmgr);
1176 printk(KERN_ERR "[ powerplay ] cz_initialize_dpm_defaults failed\n");
1180 result = cz_get_system_info_data(hwmgr);
1182 printk(KERN_ERR "[ powerplay ] cz_get_system_info_data failed\n");
1186 cz_construct_boot_state(hwmgr);
1188 result = phm_construct_table(hwmgr, &cz_setup_asic_master,
1189 &(hwmgr->setup_asic));
1191 printk(KERN_ERR "[ powerplay ] Fail to construct setup ASIC\n");
1195 result = phm_construct_table(hwmgr, &cz_power_down_asic_master,
1196 &(hwmgr->power_down_asic));
1198 printk(KERN_ERR "[ powerplay ] Fail to construct power down ASIC\n");
1202 result = phm_construct_table(hwmgr, &cz_disable_dpm_master,
1203 &(hwmgr->disable_dynamic_state_management));
1205 printk(KERN_ERR "[ powerplay ] Fail to disable_dynamic_state\n");
1208 result = phm_construct_table(hwmgr, &cz_enable_dpm_master,
1209 &(hwmgr->enable_dynamic_state_management));
1211 printk(KERN_ERR "[ powerplay ] Fail to enable_dynamic_state\n");
1214 result = phm_construct_table(hwmgr, &cz_set_power_state_master,
1215 &(hwmgr->set_power_state));
1217 printk(KERN_ERR "[ powerplay ] Fail to construct set_power_state\n");
1221 result = phm_construct_table(hwmgr, &cz_phm_enable_clock_power_gatings_master, &(hwmgr->enable_clock_power_gatings));
1223 printk(KERN_ERR "[ powerplay ] Fail to construct enable_clock_power_gatings\n");
1229 static int cz_hwmgr_backend_fini(struct pp_hwmgr *hwmgr)
1231 if (hwmgr != NULL || hwmgr->backend != NULL) {
1232 kfree(hwmgr->backend);
1238 int cz_phm_force_dpm_highest(struct pp_hwmgr *hwmgr)
1240 struct cz_hwmgr *cz_hwmgr = (struct cz_hwmgr *)(hwmgr->backend);
1242 if (cz_hwmgr->sclk_dpm.soft_min_clk !=
1243 cz_hwmgr->sclk_dpm.soft_max_clk)
1244 smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
1245 PPSMC_MSG_SetSclkSoftMin,
1246 cz_get_sclk_level(hwmgr,
1247 cz_hwmgr->sclk_dpm.soft_max_clk,
1248 PPSMC_MSG_SetSclkSoftMin));
1252 int cz_phm_unforce_dpm_levels(struct pp_hwmgr *hwmgr)
1254 struct cz_hwmgr *cz_hwmgr = (struct cz_hwmgr *)(hwmgr->backend);
1255 struct phm_clock_voltage_dependency_table *table =
1256 hwmgr->dyn_state.vddc_dependency_on_sclk;
1257 unsigned long clock = 0, level;
1259 if (NULL == table || table->count <= 0)
1262 cz_hwmgr->sclk_dpm.soft_min_clk = table->entries[0].clk;
1263 cz_hwmgr->sclk_dpm.hard_min_clk = table->entries[0].clk;
1265 level = cz_get_max_sclk_level(hwmgr) - 1;
1267 if (level < table->count)
1268 clock = table->entries[level].clk;
1270 clock = table->entries[table->count - 1].clk;
1272 cz_hwmgr->sclk_dpm.soft_max_clk = clock;
1273 cz_hwmgr->sclk_dpm.hard_max_clk = clock;
1275 smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
1276 PPSMC_MSG_SetSclkSoftMin,
1277 cz_get_sclk_level(hwmgr,
1278 cz_hwmgr->sclk_dpm.soft_min_clk,
1279 PPSMC_MSG_SetSclkSoftMin));
1281 smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
1282 PPSMC_MSG_SetSclkSoftMax,
1283 cz_get_sclk_level(hwmgr,
1284 cz_hwmgr->sclk_dpm.soft_max_clk,
1285 PPSMC_MSG_SetSclkSoftMax));
1290 int cz_phm_force_dpm_lowest(struct pp_hwmgr *hwmgr)
1292 struct cz_hwmgr *cz_hwmgr = (struct cz_hwmgr *)(hwmgr->backend);
1294 if (cz_hwmgr->sclk_dpm.soft_min_clk !=
1295 cz_hwmgr->sclk_dpm.soft_max_clk) {
1296 cz_hwmgr->sclk_dpm.soft_max_clk =
1297 cz_hwmgr->sclk_dpm.soft_min_clk;
1299 smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
1300 PPSMC_MSG_SetSclkSoftMax,
1301 cz_get_sclk_level(hwmgr,
1302 cz_hwmgr->sclk_dpm.soft_max_clk,
1303 PPSMC_MSG_SetSclkSoftMax));
1309 static int cz_dpm_force_dpm_level(struct pp_hwmgr *hwmgr,
1310 enum amd_dpm_forced_level level)
1315 case AMD_DPM_FORCED_LEVEL_HIGH:
1316 ret = cz_phm_force_dpm_highest(hwmgr);
1320 case AMD_DPM_FORCED_LEVEL_LOW:
1321 ret = cz_phm_force_dpm_lowest(hwmgr);
1325 case AMD_DPM_FORCED_LEVEL_AUTO:
1326 ret = cz_phm_unforce_dpm_levels(hwmgr);
1334 hwmgr->dpm_level = level;
1339 int cz_dpm_powerdown_uvd(struct pp_hwmgr *hwmgr)
1341 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
1342 PHM_PlatformCaps_UVDPowerGating))
1343 return smum_send_msg_to_smc(hwmgr->smumgr,
1344 PPSMC_MSG_UVDPowerOFF);
1348 int cz_dpm_powerup_uvd(struct pp_hwmgr *hwmgr)
1350 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
1351 PHM_PlatformCaps_UVDPowerGating)) {
1352 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
1353 PHM_PlatformCaps_UVDDynamicPowerGating)) {
1354 return smum_send_msg_to_smc_with_parameter(
1356 PPSMC_MSG_UVDPowerON, 1);
1358 return smum_send_msg_to_smc_with_parameter(
1360 PPSMC_MSG_UVDPowerON, 0);
1367 int cz_dpm_update_uvd_dpm(struct pp_hwmgr *hwmgr, bool bgate)
1369 struct cz_hwmgr *cz_hwmgr = (struct cz_hwmgr *)(hwmgr->backend);
1370 struct phm_uvd_clock_voltage_dependency_table *ptable =
1371 hwmgr->dyn_state.uvd_clock_voltage_dependency_table;
1374 /* Stable Pstate is enabled and we need to set the UVD DPM to highest level */
1375 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
1376 PHM_PlatformCaps_StablePState)) {
1377 cz_hwmgr->uvd_dpm.hard_min_clk =
1378 ptable->entries[ptable->count - 1].vclk;
1380 smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
1381 PPSMC_MSG_SetUvdHardMin,
1382 cz_get_uvd_level(hwmgr,
1383 cz_hwmgr->uvd_dpm.hard_min_clk,
1384 PPSMC_MSG_SetUvdHardMin));
1386 cz_enable_disable_uvd_dpm(hwmgr, true);
1388 cz_enable_disable_uvd_dpm(hwmgr, true);
1390 cz_enable_disable_uvd_dpm(hwmgr, false);
1395 int cz_dpm_update_vce_dpm(struct pp_hwmgr *hwmgr)
1397 struct cz_hwmgr *cz_hwmgr = (struct cz_hwmgr *)(hwmgr->backend);
1398 struct phm_vce_clock_voltage_dependency_table *ptable =
1399 hwmgr->dyn_state.vce_clock_voltage_dependency_table;
1401 /* Stable Pstate is enabled and we need to set the VCE DPM to highest level */
1402 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
1403 PHM_PlatformCaps_StablePState)) {
1404 cz_hwmgr->vce_dpm.hard_min_clk =
1405 ptable->entries[ptable->count - 1].ecclk;
1407 smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
1408 PPSMC_MSG_SetEclkHardMin,
1409 cz_get_eclk_level(hwmgr,
1410 cz_hwmgr->vce_dpm.hard_min_clk,
1411 PPSMC_MSG_SetEclkHardMin));
1413 /*EPR# 419220 -HW limitation to to */
1414 cz_hwmgr->vce_dpm.hard_min_clk = hwmgr->vce_arbiter.ecclk;
1415 smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
1416 PPSMC_MSG_SetEclkHardMin,
1417 cz_get_eclk_level(hwmgr,
1418 cz_hwmgr->vce_dpm.hard_min_clk,
1419 PPSMC_MSG_SetEclkHardMin));
1425 int cz_dpm_powerdown_vce(struct pp_hwmgr *hwmgr)
1427 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
1428 PHM_PlatformCaps_VCEPowerGating))
1429 return smum_send_msg_to_smc(hwmgr->smumgr,
1430 PPSMC_MSG_VCEPowerOFF);
1434 int cz_dpm_powerup_vce(struct pp_hwmgr *hwmgr)
1436 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
1437 PHM_PlatformCaps_VCEPowerGating))
1438 return smum_send_msg_to_smc(hwmgr->smumgr,
1439 PPSMC_MSG_VCEPowerON);
1443 static int cz_dpm_get_mclk(struct pp_hwmgr *hwmgr, bool low)
1445 struct cz_hwmgr *cz_hwmgr = (struct cz_hwmgr *)(hwmgr->backend);
1447 return cz_hwmgr->sys_info.bootup_uma_clock;
1450 static int cz_dpm_get_sclk(struct pp_hwmgr *hwmgr, bool low)
1452 struct pp_power_state *ps;
1453 struct cz_power_state *cz_ps;
1458 ps = hwmgr->request_ps;
1463 cz_ps = cast_PhwCzPowerState(&ps->hardware);
1466 return cz_ps->levels[0].engineClock;
1468 return cz_ps->levels[cz_ps->level-1].engineClock;
1471 static int cz_dpm_patch_boot_state(struct pp_hwmgr *hwmgr,
1472 struct pp_hw_power_state *hw_ps)
1474 struct cz_hwmgr *cz_hwmgr = (struct cz_hwmgr *)(hwmgr->backend);
1475 struct cz_power_state *cz_ps = cast_PhwCzPowerState(hw_ps);
1478 cz_ps->nbps_flags = 0;
1479 cz_ps->bapm_flags = 0;
1480 cz_ps->levels[0] = cz_hwmgr->boot_power_level;
1485 static int cz_dpm_get_pp_table_entry_callback(
1486 struct pp_hwmgr *hwmgr,
1487 struct pp_hw_power_state *hw_ps,
1489 const void *clock_info)
1491 struct cz_power_state *cz_ps = cast_PhwCzPowerState(hw_ps);
1493 const ATOM_PPLIB_CZ_CLOCK_INFO *cz_clock_info = clock_info;
1495 struct phm_clock_voltage_dependency_table *table =
1496 hwmgr->dyn_state.vddc_dependency_on_sclk;
1497 uint8_t clock_info_index = cz_clock_info->index;
1499 if (clock_info_index > (uint8_t)(hwmgr->platform_descriptor.hardwareActivityPerformanceLevels - 1))
1500 clock_info_index = (uint8_t)(hwmgr->platform_descriptor.hardwareActivityPerformanceLevels - 1);
1502 cz_ps->levels[index].engineClock = table->entries[clock_info_index].clk;
1503 cz_ps->levels[index].vddcIndex = (uint8_t)table->entries[clock_info_index].v;
1505 cz_ps->level = index + 1;
1507 if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_SclkDeepSleep)) {
1508 cz_ps->levels[index].dsDividerIndex = 5;
1509 cz_ps->levels[index].ssDividerIndex = 5;
1515 static int cz_dpm_get_num_of_pp_table_entries(struct pp_hwmgr *hwmgr)
1518 unsigned long ret = 0;
1520 result = pp_tables_get_num_of_entries(hwmgr, &ret);
1522 return result ? 0 : ret;
1525 static int cz_dpm_get_pp_table_entry(struct pp_hwmgr *hwmgr,
1526 unsigned long entry, struct pp_power_state *ps)
1529 struct cz_power_state *cz_ps;
1531 ps->hardware.magic = PhwCz_Magic;
1533 cz_ps = cast_PhwCzPowerState(&(ps->hardware));
1535 result = pp_tables_get_entry(hwmgr, entry, ps,
1536 cz_dpm_get_pp_table_entry_callback);
1538 cz_ps->uvd_clocks.vclk = ps->uvd_clocks.VCLK;
1539 cz_ps->uvd_clocks.dclk = ps->uvd_clocks.DCLK;
1544 int cz_get_power_state_size(struct pp_hwmgr *hwmgr)
1546 return sizeof(struct cz_power_state);
1550 cz_print_current_perforce_level(struct pp_hwmgr *hwmgr, struct seq_file *m)
1552 struct cz_hwmgr *cz_hwmgr = (struct cz_hwmgr *)(hwmgr->backend);
1554 struct phm_clock_voltage_dependency_table *table =
1555 hwmgr->dyn_state.vddc_dependency_on_sclk;
1557 struct phm_vce_clock_voltage_dependency_table *vce_table =
1558 hwmgr->dyn_state.vce_clock_voltage_dependency_table;
1560 struct phm_uvd_clock_voltage_dependency_table *uvd_table =
1561 hwmgr->dyn_state.uvd_clock_voltage_dependency_table;
1563 uint32_t sclk_index = PHM_GET_FIELD(cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixTARGET_AND_CURRENT_PROFILE_INDEX),
1564 TARGET_AND_CURRENT_PROFILE_INDEX, CURR_SCLK_INDEX);
1565 uint32_t uvd_index = PHM_GET_FIELD(cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixTARGET_AND_CURRENT_PROFILE_INDEX_2),
1566 TARGET_AND_CURRENT_PROFILE_INDEX_2, CURR_UVD_INDEX);
1567 uint32_t vce_index = PHM_GET_FIELD(cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixTARGET_AND_CURRENT_PROFILE_INDEX_2),
1568 TARGET_AND_CURRENT_PROFILE_INDEX_2, CURR_VCE_INDEX);
1570 uint32_t sclk, vclk, dclk, ecclk, tmp, activity_percent;
1571 uint16_t vddnb, vddgfx;
1574 if (sclk_index >= NUM_SCLK_LEVELS) {
1575 seq_printf(m, "\n invalid sclk dpm profile %d\n", sclk_index);
1577 sclk = table->entries[sclk_index].clk;
1578 seq_printf(m, "\n index: %u sclk: %u MHz\n", sclk_index, sclk/100);
1581 tmp = (cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixSMUSVI_NB_CURRENTVID) &
1582 CURRENT_NB_VID_MASK) >> CURRENT_NB_VID__SHIFT;
1583 vddnb = cz_convert_8Bit_index_to_voltage(hwmgr, tmp);
1584 tmp = (cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixSMUSVI_GFX_CURRENTVID) &
1585 CURRENT_GFX_VID_MASK) >> CURRENT_GFX_VID__SHIFT;
1586 vddgfx = cz_convert_8Bit_index_to_voltage(hwmgr, (u16)tmp);
1587 seq_printf(m, "\n vddnb: %u vddgfx: %u\n", vddnb, vddgfx);
1589 seq_printf(m, "\n uvd %sabled\n", cz_hwmgr->uvd_power_gated ? "dis" : "en");
1590 if (!cz_hwmgr->uvd_power_gated) {
1591 if (uvd_index >= CZ_MAX_HARDWARE_POWERLEVELS) {
1592 seq_printf(m, "\n invalid uvd dpm level %d\n", uvd_index);
1594 vclk = uvd_table->entries[uvd_index].vclk;
1595 dclk = uvd_table->entries[uvd_index].dclk;
1596 seq_printf(m, "\n index: %u uvd vclk: %u MHz dclk: %u MHz\n", uvd_index, vclk/100, dclk/100);
1600 seq_printf(m, "\n vce %sabled\n", cz_hwmgr->vce_power_gated ? "dis" : "en");
1601 if (!cz_hwmgr->vce_power_gated) {
1602 if (vce_index >= CZ_MAX_HARDWARE_POWERLEVELS) {
1603 seq_printf(m, "\n invalid vce dpm level %d\n", vce_index);
1605 ecclk = vce_table->entries[vce_index].ecclk;
1606 seq_printf(m, "\n index: %u vce ecclk: %u MHz\n", vce_index, ecclk/100);
1610 result = smum_send_msg_to_smc(hwmgr->smumgr, PPSMC_MSG_GetAverageGraphicsActivity);
1612 activity_percent = cgs_read_register(hwmgr->device, mmSMU_MP1_SRBM2P_ARG_0);
1613 activity_percent = activity_percent > 100 ? 100 : activity_percent;
1615 activity_percent = 50;
1618 seq_printf(m, "\n [GPU load]: %u %%\n\n", activity_percent);
1621 static void cz_hw_print_display_cfg(
1622 const struct cc6_settings *cc6_settings)
1624 PP_DBG_LOG("New Display Configuration:\n");
1626 PP_DBG_LOG(" cpu_cc6_disable: %d\n",
1627 cc6_settings->cpu_cc6_disable);
1628 PP_DBG_LOG(" cpu_pstate_disable: %d\n",
1629 cc6_settings->cpu_pstate_disable);
1630 PP_DBG_LOG(" nb_pstate_switch_disable: %d\n",
1631 cc6_settings->nb_pstate_switch_disable);
1632 PP_DBG_LOG(" cpu_pstate_separation_time: %d\n\n",
1633 cc6_settings->cpu_pstate_separation_time);
1636 static int cz_set_cpu_power_state(struct pp_hwmgr *hwmgr)
1638 struct cz_hwmgr *hw_data = (struct cz_hwmgr *)(hwmgr->backend);
1641 if (hw_data->cc6_settings.cc6_setting_changed == true) {
1643 hw_data->cc6_settings.cc6_setting_changed = false;
1645 cz_hw_print_display_cfg(&hw_data->cc6_settings);
1647 data |= (hw_data->cc6_settings.cpu_pstate_separation_time
1648 & PWRMGT_SEPARATION_TIME_MASK)
1649 << PWRMGT_SEPARATION_TIME_SHIFT;
1651 data|= (hw_data->cc6_settings.cpu_cc6_disable ? 0x1 : 0x0)
1652 << PWRMGT_DISABLE_CPU_CSTATES_SHIFT;
1654 data|= (hw_data->cc6_settings.cpu_pstate_disable ? 0x1 : 0x0)
1655 << PWRMGT_DISABLE_CPU_PSTATES_SHIFT;
1657 PP_DBG_LOG("SetDisplaySizePowerParams data: 0x%X\n",
1660 smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
1661 PPSMC_MSG_SetDisplaySizePowerParams,
1669 static int cz_store_cc6_data(struct pp_hwmgr *hwmgr, uint32_t separation_time,
1670 bool cc6_disable, bool pstate_disable, bool pstate_switch_disable)
1672 struct cz_hwmgr *hw_data = (struct cz_hwmgr *)(hwmgr->backend);
1674 if (separation_time !=
1675 hw_data->cc6_settings.cpu_pstate_separation_time
1677 hw_data->cc6_settings.cpu_cc6_disable
1678 || pstate_disable !=
1679 hw_data->cc6_settings.cpu_pstate_disable
1680 || pstate_switch_disable !=
1681 hw_data->cc6_settings.nb_pstate_switch_disable) {
1683 hw_data->cc6_settings.cc6_setting_changed = true;
1685 hw_data->cc6_settings.cpu_pstate_separation_time =
1687 hw_data->cc6_settings.cpu_cc6_disable =
1689 hw_data->cc6_settings.cpu_pstate_disable =
1691 hw_data->cc6_settings.nb_pstate_switch_disable =
1692 pstate_switch_disable;
1699 static int cz_get_dal_power_level(struct pp_hwmgr *hwmgr,
1700 struct amd_pp_dal_clock_info*info)
1703 const struct phm_clock_voltage_dependency_table * table =
1704 hwmgr->dyn_state.vddc_dep_on_dal_pwrl;
1705 const struct phm_clock_and_voltage_limits* limits =
1706 &hwmgr->dyn_state.max_clock_voltage_on_ac;
1708 info->engine_max_clock = limits->sclk;
1709 info->memory_max_clock = limits->mclk;
1711 for (i = table->count - 1; i > 0; i--) {
1713 if (limits->vddc >= table->entries[i].v) {
1714 info->level = table->entries[i].clk;
1721 static const struct pp_hwmgr_func cz_hwmgr_funcs = {
1722 .backend_init = cz_hwmgr_backend_init,
1723 .backend_fini = cz_hwmgr_backend_fini,
1725 .apply_state_adjust_rules = cz_apply_state_adjust_rules,
1726 .force_dpm_level = cz_dpm_force_dpm_level,
1727 .get_power_state_size = cz_get_power_state_size,
1728 .powerdown_uvd = cz_dpm_powerdown_uvd,
1729 .powergate_uvd = cz_dpm_powergate_uvd,
1730 .powergate_vce = cz_dpm_powergate_vce,
1731 .get_mclk = cz_dpm_get_mclk,
1732 .get_sclk = cz_dpm_get_sclk,
1733 .patch_boot_state = cz_dpm_patch_boot_state,
1734 .get_pp_table_entry = cz_dpm_get_pp_table_entry,
1735 .get_num_of_pp_table_entries = cz_dpm_get_num_of_pp_table_entries,
1736 .print_current_perforce_level = cz_print_current_perforce_level,
1737 .set_cpu_power_state = cz_set_cpu_power_state,
1738 .store_cc6_data = cz_store_cc6_data,
1739 .get_dal_power_level= cz_get_dal_power_level,
1742 int cz_hwmgr_init(struct pp_hwmgr *hwmgr)
1744 struct cz_hwmgr *cz_hwmgr;
1747 cz_hwmgr = kzalloc(sizeof(struct cz_hwmgr), GFP_KERNEL);
1748 if (cz_hwmgr == NULL)
1751 hwmgr->backend = cz_hwmgr;
1752 hwmgr->hwmgr_func = &cz_hwmgr_funcs;
1753 hwmgr->pptable_func = &pptable_funcs;