cz_hwmgr.c 54 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910
  1. /*
  2. * Copyright 2015 Advanced Micro Devices, Inc.
  3. *
  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:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  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.
  21. *
  22. */
  23. #include "pp_debug.h"
  24. #include <linux/types.h>
  25. #include <linux/kernel.h>
  26. #include <linux/slab.h>
  27. #include "atom-types.h"
  28. #include "atombios.h"
  29. #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"
  34. #include "smumgr.h"
  35. #include "hwmgr.h"
  36. #include "hardwaremanager.h"
  37. #include "cz_ppsmc.h"
  38. #include "cz_hwmgr.h"
  39. #include "power_state.h"
  40. #include "cz_clockpowergating.h"
  41. #define ixSMUSVI_NB_CURRENTVID 0xD8230044
  42. #define CURRENT_NB_VID_MASK 0xff000000
  43. #define CURRENT_NB_VID__SHIFT 24
  44. #define ixSMUSVI_GFX_CURRENTVID 0xD8230048
  45. #define CURRENT_GFX_VID_MASK 0xff000000
  46. #define CURRENT_GFX_VID__SHIFT 24
  47. static const unsigned long PhwCz_Magic = (unsigned long) PHM_Cz_Magic;
  48. static struct cz_power_state *cast_PhwCzPowerState(struct pp_hw_power_state *hw_ps)
  49. {
  50. if (PhwCz_Magic != hw_ps->magic)
  51. return NULL;
  52. return (struct cz_power_state *)hw_ps;
  53. }
  54. static const struct cz_power_state *cast_const_PhwCzPowerState(
  55. const struct pp_hw_power_state *hw_ps)
  56. {
  57. if (PhwCz_Magic != hw_ps->magic)
  58. return NULL;
  59. return (struct cz_power_state *)hw_ps;
  60. }
  61. static uint32_t cz_get_eclk_level(struct pp_hwmgr *hwmgr,
  62. uint32_t clock, uint32_t msg)
  63. {
  64. int i = 0;
  65. struct phm_vce_clock_voltage_dependency_table *ptable =
  66. hwmgr->dyn_state.vce_clock_voltage_dependency_table;
  67. switch (msg) {
  68. case PPSMC_MSG_SetEclkSoftMin:
  69. case PPSMC_MSG_SetEclkHardMin:
  70. for (i = 0; i < (int)ptable->count; i++) {
  71. if (clock <= ptable->entries[i].ecclk)
  72. break;
  73. }
  74. break;
  75. case PPSMC_MSG_SetEclkSoftMax:
  76. case PPSMC_MSG_SetEclkHardMax:
  77. for (i = ptable->count - 1; i >= 0; i--) {
  78. if (clock >= ptable->entries[i].ecclk)
  79. break;
  80. }
  81. break;
  82. default:
  83. break;
  84. }
  85. return i;
  86. }
  87. static uint32_t cz_get_sclk_level(struct pp_hwmgr *hwmgr,
  88. uint32_t clock, uint32_t msg)
  89. {
  90. int i = 0;
  91. struct phm_clock_voltage_dependency_table *table =
  92. hwmgr->dyn_state.vddc_dependency_on_sclk;
  93. switch (msg) {
  94. case PPSMC_MSG_SetSclkSoftMin:
  95. case PPSMC_MSG_SetSclkHardMin:
  96. for (i = 0; i < (int)table->count; i++) {
  97. if (clock <= table->entries[i].clk)
  98. break;
  99. }
  100. break;
  101. case PPSMC_MSG_SetSclkSoftMax:
  102. case PPSMC_MSG_SetSclkHardMax:
  103. for (i = table->count - 1; i >= 0; i--) {
  104. if (clock >= table->entries[i].clk)
  105. break;
  106. }
  107. break;
  108. default:
  109. break;
  110. }
  111. return i;
  112. }
  113. static uint32_t cz_get_uvd_level(struct pp_hwmgr *hwmgr,
  114. uint32_t clock, uint32_t msg)
  115. {
  116. int i = 0;
  117. struct phm_uvd_clock_voltage_dependency_table *ptable =
  118. hwmgr->dyn_state.uvd_clock_voltage_dependency_table;
  119. switch (msg) {
  120. case PPSMC_MSG_SetUvdSoftMin:
  121. case PPSMC_MSG_SetUvdHardMin:
  122. for (i = 0; i < (int)ptable->count; i++) {
  123. if (clock <= ptable->entries[i].vclk)
  124. break;
  125. }
  126. break;
  127. case PPSMC_MSG_SetUvdSoftMax:
  128. case PPSMC_MSG_SetUvdHardMax:
  129. for (i = ptable->count - 1; i >= 0; i--) {
  130. if (clock >= ptable->entries[i].vclk)
  131. break;
  132. }
  133. break;
  134. default:
  135. break;
  136. }
  137. return i;
  138. }
  139. static uint32_t cz_get_max_sclk_level(struct pp_hwmgr *hwmgr)
  140. {
  141. struct cz_hwmgr *cz_hwmgr = (struct cz_hwmgr *)(hwmgr->backend);
  142. if (cz_hwmgr->max_sclk_level == 0) {
  143. smum_send_msg_to_smc(hwmgr, PPSMC_MSG_GetMaxSclkLevel);
  144. cz_hwmgr->max_sclk_level = smum_get_argument(hwmgr) + 1;
  145. }
  146. return cz_hwmgr->max_sclk_level;
  147. }
  148. static int cz_initialize_dpm_defaults(struct pp_hwmgr *hwmgr)
  149. {
  150. struct cz_hwmgr *cz_hwmgr = (struct cz_hwmgr *)(hwmgr->backend);
  151. uint32_t i;
  152. struct cgs_system_info sys_info = {0};
  153. int result;
  154. cz_hwmgr->gfx_ramp_step = 256*25/100;
  155. cz_hwmgr->gfx_ramp_delay = 1; /* by default, we delay 1us */
  156. for (i = 0; i < CZ_MAX_HARDWARE_POWERLEVELS; i++)
  157. cz_hwmgr->activity_target[i] = CZ_AT_DFLT;
  158. cz_hwmgr->mgcg_cgtt_local0 = 0x00000000;
  159. cz_hwmgr->mgcg_cgtt_local1 = 0x00000000;
  160. cz_hwmgr->clock_slow_down_freq = 25000;
  161. cz_hwmgr->skip_clock_slow_down = 1;
  162. cz_hwmgr->enable_nb_ps_policy = 1; /* disable until UNB is ready, Enabled */
  163. cz_hwmgr->voltage_drop_in_dce_power_gating = 0; /* disable until fully verified */
  164. cz_hwmgr->voting_rights_clients = 0x00C00033;
  165. cz_hwmgr->static_screen_threshold = 8;
  166. cz_hwmgr->ddi_power_gating_disabled = 0;
  167. cz_hwmgr->bapm_enabled = 1;
  168. cz_hwmgr->voltage_drop_threshold = 0;
  169. cz_hwmgr->gfx_power_gating_threshold = 500;
  170. cz_hwmgr->vce_slow_sclk_threshold = 20000;
  171. cz_hwmgr->dce_slow_sclk_threshold = 30000;
  172. cz_hwmgr->disable_driver_thermal_policy = 1;
  173. cz_hwmgr->disable_nb_ps3_in_battery = 0;
  174. phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
  175. PHM_PlatformCaps_ABM);
  176. phm_cap_set(hwmgr->platform_descriptor.platformCaps,
  177. PHM_PlatformCaps_NonABMSupportInPPLib);
  178. phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
  179. PHM_PlatformCaps_DynamicM3Arbiter);
  180. cz_hwmgr->override_dynamic_mgpg = 1;
  181. phm_cap_set(hwmgr->platform_descriptor.platformCaps,
  182. PHM_PlatformCaps_DynamicPatchPowerState);
  183. cz_hwmgr->thermal_auto_throttling_treshold = 0;
  184. cz_hwmgr->tdr_clock = 0;
  185. cz_hwmgr->disable_gfx_power_gating_in_uvd = 0;
  186. phm_cap_set(hwmgr->platform_descriptor.platformCaps,
  187. PHM_PlatformCaps_DynamicUVDState);
  188. phm_cap_set(hwmgr->platform_descriptor.platformCaps,
  189. PHM_PlatformCaps_UVDDPM);
  190. phm_cap_set(hwmgr->platform_descriptor.platformCaps,
  191. PHM_PlatformCaps_VCEDPM);
  192. cz_hwmgr->cc6_settings.cpu_cc6_disable = false;
  193. cz_hwmgr->cc6_settings.cpu_pstate_disable = false;
  194. cz_hwmgr->cc6_settings.nb_pstate_switch_disable = false;
  195. cz_hwmgr->cc6_settings.cpu_pstate_separation_time = 0;
  196. phm_cap_set(hwmgr->platform_descriptor.platformCaps,
  197. PHM_PlatformCaps_DisableVoltageIsland);
  198. phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
  199. PHM_PlatformCaps_UVDPowerGating);
  200. phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
  201. PHM_PlatformCaps_VCEPowerGating);
  202. sys_info.size = sizeof(struct cgs_system_info);
  203. sys_info.info_id = CGS_SYSTEM_INFO_PG_FLAGS;
  204. result = cgs_query_system_info(hwmgr->device, &sys_info);
  205. if (!result) {
  206. if (sys_info.value & AMD_PG_SUPPORT_UVD)
  207. phm_cap_set(hwmgr->platform_descriptor.platformCaps,
  208. PHM_PlatformCaps_UVDPowerGating);
  209. if (sys_info.value & AMD_PG_SUPPORT_VCE)
  210. phm_cap_set(hwmgr->platform_descriptor.platformCaps,
  211. PHM_PlatformCaps_VCEPowerGating);
  212. }
  213. return 0;
  214. }
  215. static uint32_t cz_convert_8Bit_index_to_voltage(
  216. struct pp_hwmgr *hwmgr, uint16_t voltage)
  217. {
  218. return 6200 - (voltage * 25);
  219. }
  220. static int cz_construct_max_power_limits_table(struct pp_hwmgr *hwmgr,
  221. struct phm_clock_and_voltage_limits *table)
  222. {
  223. struct cz_hwmgr *cz_hwmgr = (struct cz_hwmgr *)hwmgr->backend;
  224. struct cz_sys_info *sys_info = &cz_hwmgr->sys_info;
  225. struct phm_clock_voltage_dependency_table *dep_table =
  226. hwmgr->dyn_state.vddc_dependency_on_sclk;
  227. if (dep_table->count > 0) {
  228. table->sclk = dep_table->entries[dep_table->count-1].clk;
  229. table->vddc = cz_convert_8Bit_index_to_voltage(hwmgr,
  230. (uint16_t)dep_table->entries[dep_table->count-1].v);
  231. }
  232. table->mclk = sys_info->nbp_memory_clock[0];
  233. return 0;
  234. }
  235. static int cz_init_dynamic_state_adjustment_rule_settings(
  236. struct pp_hwmgr *hwmgr,
  237. ATOM_CLK_VOLT_CAPABILITY *disp_voltage_table)
  238. {
  239. uint32_t table_size =
  240. sizeof(struct phm_clock_voltage_dependency_table) +
  241. (7 * sizeof(struct phm_clock_voltage_dependency_record));
  242. struct phm_clock_voltage_dependency_table *table_clk_vlt =
  243. kzalloc(table_size, GFP_KERNEL);
  244. if (NULL == table_clk_vlt) {
  245. pr_err("Can not allocate memory!\n");
  246. return -ENOMEM;
  247. }
  248. table_clk_vlt->count = 8;
  249. table_clk_vlt->entries[0].clk = PP_DAL_POWERLEVEL_0;
  250. table_clk_vlt->entries[0].v = 0;
  251. table_clk_vlt->entries[1].clk = PP_DAL_POWERLEVEL_1;
  252. table_clk_vlt->entries[1].v = 1;
  253. table_clk_vlt->entries[2].clk = PP_DAL_POWERLEVEL_2;
  254. table_clk_vlt->entries[2].v = 2;
  255. table_clk_vlt->entries[3].clk = PP_DAL_POWERLEVEL_3;
  256. table_clk_vlt->entries[3].v = 3;
  257. table_clk_vlt->entries[4].clk = PP_DAL_POWERLEVEL_4;
  258. table_clk_vlt->entries[4].v = 4;
  259. table_clk_vlt->entries[5].clk = PP_DAL_POWERLEVEL_5;
  260. table_clk_vlt->entries[5].v = 5;
  261. table_clk_vlt->entries[6].clk = PP_DAL_POWERLEVEL_6;
  262. table_clk_vlt->entries[6].v = 6;
  263. table_clk_vlt->entries[7].clk = PP_DAL_POWERLEVEL_7;
  264. table_clk_vlt->entries[7].v = 7;
  265. hwmgr->dyn_state.vddc_dep_on_dal_pwrl = table_clk_vlt;
  266. return 0;
  267. }
  268. static int cz_get_system_info_data(struct pp_hwmgr *hwmgr)
  269. {
  270. struct cz_hwmgr *cz_hwmgr = (struct cz_hwmgr *)hwmgr->backend;
  271. ATOM_INTEGRATED_SYSTEM_INFO_V1_9 *info = NULL;
  272. uint32_t i;
  273. int result = 0;
  274. uint8_t frev, crev;
  275. uint16_t size;
  276. info = (ATOM_INTEGRATED_SYSTEM_INFO_V1_9 *) cgs_atom_get_data_table(
  277. hwmgr->device,
  278. GetIndexIntoMasterTable(DATA, IntegratedSystemInfo),
  279. &size, &frev, &crev);
  280. if (crev != 9) {
  281. pr_err("Unsupported IGP table: %d %d\n", frev, crev);
  282. return -EINVAL;
  283. }
  284. if (info == NULL) {
  285. pr_err("Could not retrieve the Integrated System Info Table!\n");
  286. return -EINVAL;
  287. }
  288. cz_hwmgr->sys_info.bootup_uma_clock =
  289. le32_to_cpu(info->ulBootUpUMAClock);
  290. cz_hwmgr->sys_info.bootup_engine_clock =
  291. le32_to_cpu(info->ulBootUpEngineClock);
  292. cz_hwmgr->sys_info.dentist_vco_freq =
  293. le32_to_cpu(info->ulDentistVCOFreq);
  294. cz_hwmgr->sys_info.system_config =
  295. le32_to_cpu(info->ulSystemConfig);
  296. cz_hwmgr->sys_info.bootup_nb_voltage_index =
  297. le16_to_cpu(info->usBootUpNBVoltage);
  298. cz_hwmgr->sys_info.htc_hyst_lmt =
  299. (info->ucHtcHystLmt == 0) ? 5 : info->ucHtcHystLmt;
  300. cz_hwmgr->sys_info.htc_tmp_lmt =
  301. (info->ucHtcTmpLmt == 0) ? 203 : info->ucHtcTmpLmt;
  302. if (cz_hwmgr->sys_info.htc_tmp_lmt <=
  303. cz_hwmgr->sys_info.htc_hyst_lmt) {
  304. pr_err("The htcTmpLmt should be larger than htcHystLmt.\n");
  305. return -EINVAL;
  306. }
  307. cz_hwmgr->sys_info.nb_dpm_enable =
  308. cz_hwmgr->enable_nb_ps_policy &&
  309. (le32_to_cpu(info->ulSystemConfig) >> 3 & 0x1);
  310. for (i = 0; i < CZ_NUM_NBPSTATES; i++) {
  311. if (i < CZ_NUM_NBPMEMORYCLOCK) {
  312. cz_hwmgr->sys_info.nbp_memory_clock[i] =
  313. le32_to_cpu(info->ulNbpStateMemclkFreq[i]);
  314. }
  315. cz_hwmgr->sys_info.nbp_n_clock[i] =
  316. le32_to_cpu(info->ulNbpStateNClkFreq[i]);
  317. }
  318. for (i = 0; i < MAX_DISPLAY_CLOCK_LEVEL; i++) {
  319. cz_hwmgr->sys_info.display_clock[i] =
  320. le32_to_cpu(info->sDispClkVoltageMapping[i].ulMaximumSupportedCLK);
  321. }
  322. /* Here use 4 levels, make sure not exceed */
  323. for (i = 0; i < CZ_NUM_NBPSTATES; i++) {
  324. cz_hwmgr->sys_info.nbp_voltage_index[i] =
  325. le16_to_cpu(info->usNBPStateVoltage[i]);
  326. }
  327. if (!cz_hwmgr->sys_info.nb_dpm_enable) {
  328. for (i = 1; i < CZ_NUM_NBPSTATES; i++) {
  329. if (i < CZ_NUM_NBPMEMORYCLOCK) {
  330. cz_hwmgr->sys_info.nbp_memory_clock[i] =
  331. cz_hwmgr->sys_info.nbp_memory_clock[0];
  332. }
  333. cz_hwmgr->sys_info.nbp_n_clock[i] =
  334. cz_hwmgr->sys_info.nbp_n_clock[0];
  335. cz_hwmgr->sys_info.nbp_voltage_index[i] =
  336. cz_hwmgr->sys_info.nbp_voltage_index[0];
  337. }
  338. }
  339. if (le32_to_cpu(info->ulGPUCapInfo) &
  340. SYS_INFO_GPUCAPS__ENABEL_DFS_BYPASS) {
  341. phm_cap_set(hwmgr->platform_descriptor.platformCaps,
  342. PHM_PlatformCaps_EnableDFSBypass);
  343. }
  344. cz_hwmgr->sys_info.uma_channel_number = info->ucUMAChannelNumber;
  345. cz_construct_max_power_limits_table (hwmgr,
  346. &hwmgr->dyn_state.max_clock_voltage_on_ac);
  347. cz_init_dynamic_state_adjustment_rule_settings(hwmgr,
  348. &info->sDISPCLK_Voltage[0]);
  349. return result;
  350. }
  351. static int cz_construct_boot_state(struct pp_hwmgr *hwmgr)
  352. {
  353. struct cz_hwmgr *cz_hwmgr = (struct cz_hwmgr *)(hwmgr->backend);
  354. cz_hwmgr->boot_power_level.engineClock =
  355. cz_hwmgr->sys_info.bootup_engine_clock;
  356. cz_hwmgr->boot_power_level.vddcIndex =
  357. (uint8_t)cz_hwmgr->sys_info.bootup_nb_voltage_index;
  358. cz_hwmgr->boot_power_level.dsDividerIndex = 0;
  359. cz_hwmgr->boot_power_level.ssDividerIndex = 0;
  360. cz_hwmgr->boot_power_level.allowGnbSlow = 1;
  361. cz_hwmgr->boot_power_level.forceNBPstate = 0;
  362. cz_hwmgr->boot_power_level.hysteresis_up = 0;
  363. cz_hwmgr->boot_power_level.numSIMDToPowerDown = 0;
  364. cz_hwmgr->boot_power_level.display_wm = 0;
  365. cz_hwmgr->boot_power_level.vce_wm = 0;
  366. return 0;
  367. }
  368. static int cz_upload_pptable_to_smu(struct pp_hwmgr *hwmgr)
  369. {
  370. struct SMU8_Fusion_ClkTable *clock_table;
  371. int ret;
  372. uint32_t i;
  373. void *table = NULL;
  374. pp_atomctrl_clock_dividers_kong dividers;
  375. struct phm_clock_voltage_dependency_table *vddc_table =
  376. hwmgr->dyn_state.vddc_dependency_on_sclk;
  377. struct phm_clock_voltage_dependency_table *vdd_gfx_table =
  378. hwmgr->dyn_state.vdd_gfx_dependency_on_sclk;
  379. struct phm_acp_clock_voltage_dependency_table *acp_table =
  380. hwmgr->dyn_state.acp_clock_voltage_dependency_table;
  381. struct phm_uvd_clock_voltage_dependency_table *uvd_table =
  382. hwmgr->dyn_state.uvd_clock_voltage_dependency_table;
  383. struct phm_vce_clock_voltage_dependency_table *vce_table =
  384. hwmgr->dyn_state.vce_clock_voltage_dependency_table;
  385. if (!hwmgr->need_pp_table_upload)
  386. return 0;
  387. ret = smum_download_powerplay_table(hwmgr, &table);
  388. PP_ASSERT_WITH_CODE((0 == ret && NULL != table),
  389. "Fail to get clock table from SMU!", return -EINVAL;);
  390. clock_table = (struct SMU8_Fusion_ClkTable *)table;
  391. /* patch clock table */
  392. PP_ASSERT_WITH_CODE((vddc_table->count <= CZ_MAX_HARDWARE_POWERLEVELS),
  393. "Dependency table entry exceeds max limit!", return -EINVAL;);
  394. PP_ASSERT_WITH_CODE((vdd_gfx_table->count <= CZ_MAX_HARDWARE_POWERLEVELS),
  395. "Dependency table entry exceeds max limit!", return -EINVAL;);
  396. PP_ASSERT_WITH_CODE((acp_table->count <= CZ_MAX_HARDWARE_POWERLEVELS),
  397. "Dependency table entry exceeds max limit!", return -EINVAL;);
  398. PP_ASSERT_WITH_CODE((uvd_table->count <= CZ_MAX_HARDWARE_POWERLEVELS),
  399. "Dependency table entry exceeds max limit!", return -EINVAL;);
  400. PP_ASSERT_WITH_CODE((vce_table->count <= CZ_MAX_HARDWARE_POWERLEVELS),
  401. "Dependency table entry exceeds max limit!", return -EINVAL;);
  402. for (i = 0; i < CZ_MAX_HARDWARE_POWERLEVELS; i++) {
  403. /* vddc_sclk */
  404. clock_table->SclkBreakdownTable.ClkLevel[i].GnbVid =
  405. (i < vddc_table->count) ? (uint8_t)vddc_table->entries[i].v : 0;
  406. clock_table->SclkBreakdownTable.ClkLevel[i].Frequency =
  407. (i < vddc_table->count) ? vddc_table->entries[i].clk : 0;
  408. atomctrl_get_engine_pll_dividers_kong(hwmgr,
  409. clock_table->SclkBreakdownTable.ClkLevel[i].Frequency,
  410. &dividers);
  411. clock_table->SclkBreakdownTable.ClkLevel[i].DfsDid =
  412. (uint8_t)dividers.pll_post_divider;
  413. /* vddgfx_sclk */
  414. clock_table->SclkBreakdownTable.ClkLevel[i].GfxVid =
  415. (i < vdd_gfx_table->count) ? (uint8_t)vdd_gfx_table->entries[i].v : 0;
  416. /* acp breakdown */
  417. clock_table->AclkBreakdownTable.ClkLevel[i].GfxVid =
  418. (i < acp_table->count) ? (uint8_t)acp_table->entries[i].v : 0;
  419. clock_table->AclkBreakdownTable.ClkLevel[i].Frequency =
  420. (i < acp_table->count) ? acp_table->entries[i].acpclk : 0;
  421. atomctrl_get_engine_pll_dividers_kong(hwmgr,
  422. clock_table->AclkBreakdownTable.ClkLevel[i].Frequency,
  423. &dividers);
  424. clock_table->AclkBreakdownTable.ClkLevel[i].DfsDid =
  425. (uint8_t)dividers.pll_post_divider;
  426. /* uvd breakdown */
  427. clock_table->VclkBreakdownTable.ClkLevel[i].GfxVid =
  428. (i < uvd_table->count) ? (uint8_t)uvd_table->entries[i].v : 0;
  429. clock_table->VclkBreakdownTable.ClkLevel[i].Frequency =
  430. (i < uvd_table->count) ? uvd_table->entries[i].vclk : 0;
  431. atomctrl_get_engine_pll_dividers_kong(hwmgr,
  432. clock_table->VclkBreakdownTable.ClkLevel[i].Frequency,
  433. &dividers);
  434. clock_table->VclkBreakdownTable.ClkLevel[i].DfsDid =
  435. (uint8_t)dividers.pll_post_divider;
  436. clock_table->DclkBreakdownTable.ClkLevel[i].GfxVid =
  437. (i < uvd_table->count) ? (uint8_t)uvd_table->entries[i].v : 0;
  438. clock_table->DclkBreakdownTable.ClkLevel[i].Frequency =
  439. (i < uvd_table->count) ? uvd_table->entries[i].dclk : 0;
  440. atomctrl_get_engine_pll_dividers_kong(hwmgr,
  441. clock_table->DclkBreakdownTable.ClkLevel[i].Frequency,
  442. &dividers);
  443. clock_table->DclkBreakdownTable.ClkLevel[i].DfsDid =
  444. (uint8_t)dividers.pll_post_divider;
  445. /* vce breakdown */
  446. clock_table->EclkBreakdownTable.ClkLevel[i].GfxVid =
  447. (i < vce_table->count) ? (uint8_t)vce_table->entries[i].v : 0;
  448. clock_table->EclkBreakdownTable.ClkLevel[i].Frequency =
  449. (i < vce_table->count) ? vce_table->entries[i].ecclk : 0;
  450. atomctrl_get_engine_pll_dividers_kong(hwmgr,
  451. clock_table->EclkBreakdownTable.ClkLevel[i].Frequency,
  452. &dividers);
  453. clock_table->EclkBreakdownTable.ClkLevel[i].DfsDid =
  454. (uint8_t)dividers.pll_post_divider;
  455. }
  456. ret = smum_upload_powerplay_table(hwmgr);
  457. return ret;
  458. }
  459. static int cz_init_sclk_limit(struct pp_hwmgr *hwmgr)
  460. {
  461. struct cz_hwmgr *cz_hwmgr = (struct cz_hwmgr *)(hwmgr->backend);
  462. struct phm_clock_voltage_dependency_table *table =
  463. hwmgr->dyn_state.vddc_dependency_on_sclk;
  464. unsigned long clock = 0, level;
  465. if (NULL == table || table->count <= 0)
  466. return -EINVAL;
  467. cz_hwmgr->sclk_dpm.soft_min_clk = table->entries[0].clk;
  468. cz_hwmgr->sclk_dpm.hard_min_clk = table->entries[0].clk;
  469. level = cz_get_max_sclk_level(hwmgr) - 1;
  470. if (level < table->count)
  471. clock = table->entries[level].clk;
  472. else
  473. clock = table->entries[table->count - 1].clk;
  474. cz_hwmgr->sclk_dpm.soft_max_clk = clock;
  475. cz_hwmgr->sclk_dpm.hard_max_clk = clock;
  476. return 0;
  477. }
  478. static int cz_init_uvd_limit(struct pp_hwmgr *hwmgr)
  479. {
  480. struct cz_hwmgr *cz_hwmgr = (struct cz_hwmgr *)(hwmgr->backend);
  481. struct phm_uvd_clock_voltage_dependency_table *table =
  482. hwmgr->dyn_state.uvd_clock_voltage_dependency_table;
  483. unsigned long clock = 0, level;
  484. if (NULL == table || table->count <= 0)
  485. return -EINVAL;
  486. cz_hwmgr->uvd_dpm.soft_min_clk = 0;
  487. cz_hwmgr->uvd_dpm.hard_min_clk = 0;
  488. smum_send_msg_to_smc(hwmgr, PPSMC_MSG_GetMaxUvdLevel);
  489. level = smum_get_argument(hwmgr);
  490. if (level < table->count)
  491. clock = table->entries[level].vclk;
  492. else
  493. clock = table->entries[table->count - 1].vclk;
  494. cz_hwmgr->uvd_dpm.soft_max_clk = clock;
  495. cz_hwmgr->uvd_dpm.hard_max_clk = clock;
  496. return 0;
  497. }
  498. static int cz_init_vce_limit(struct pp_hwmgr *hwmgr)
  499. {
  500. struct cz_hwmgr *cz_hwmgr = (struct cz_hwmgr *)(hwmgr->backend);
  501. struct phm_vce_clock_voltage_dependency_table *table =
  502. hwmgr->dyn_state.vce_clock_voltage_dependency_table;
  503. unsigned long clock = 0, level;
  504. if (NULL == table || table->count <= 0)
  505. return -EINVAL;
  506. cz_hwmgr->vce_dpm.soft_min_clk = 0;
  507. cz_hwmgr->vce_dpm.hard_min_clk = 0;
  508. smum_send_msg_to_smc(hwmgr, PPSMC_MSG_GetMaxEclkLevel);
  509. level = smum_get_argument(hwmgr);
  510. if (level < table->count)
  511. clock = table->entries[level].ecclk;
  512. else
  513. clock = table->entries[table->count - 1].ecclk;
  514. cz_hwmgr->vce_dpm.soft_max_clk = clock;
  515. cz_hwmgr->vce_dpm.hard_max_clk = clock;
  516. return 0;
  517. }
  518. static int cz_init_acp_limit(struct pp_hwmgr *hwmgr)
  519. {
  520. struct cz_hwmgr *cz_hwmgr = (struct cz_hwmgr *)(hwmgr->backend);
  521. struct phm_acp_clock_voltage_dependency_table *table =
  522. hwmgr->dyn_state.acp_clock_voltage_dependency_table;
  523. unsigned long clock = 0, level;
  524. if (NULL == table || table->count <= 0)
  525. return -EINVAL;
  526. cz_hwmgr->acp_dpm.soft_min_clk = 0;
  527. cz_hwmgr->acp_dpm.hard_min_clk = 0;
  528. smum_send_msg_to_smc(hwmgr, PPSMC_MSG_GetMaxAclkLevel);
  529. level = smum_get_argument(hwmgr);
  530. if (level < table->count)
  531. clock = table->entries[level].acpclk;
  532. else
  533. clock = table->entries[table->count - 1].acpclk;
  534. cz_hwmgr->acp_dpm.soft_max_clk = clock;
  535. cz_hwmgr->acp_dpm.hard_max_clk = clock;
  536. return 0;
  537. }
  538. static void cz_init_power_gate_state(struct pp_hwmgr *hwmgr)
  539. {
  540. struct cz_hwmgr *cz_hwmgr = (struct cz_hwmgr *)(hwmgr->backend);
  541. cz_hwmgr->uvd_power_gated = false;
  542. cz_hwmgr->vce_power_gated = false;
  543. cz_hwmgr->samu_power_gated = false;
  544. cz_hwmgr->acp_power_gated = false;
  545. cz_hwmgr->pgacpinit = true;
  546. }
  547. static void cz_init_sclk_threshold(struct pp_hwmgr *hwmgr)
  548. {
  549. struct cz_hwmgr *cz_hwmgr = (struct cz_hwmgr *)(hwmgr->backend);
  550. cz_hwmgr->low_sclk_interrupt_threshold = 0;
  551. }
  552. static int cz_update_sclk_limit(struct pp_hwmgr *hwmgr)
  553. {
  554. struct cz_hwmgr *cz_hwmgr = (struct cz_hwmgr *)(hwmgr->backend);
  555. struct phm_clock_voltage_dependency_table *table =
  556. hwmgr->dyn_state.vddc_dependency_on_sclk;
  557. unsigned long clock = 0;
  558. unsigned long level;
  559. unsigned long stable_pstate_sclk;
  560. unsigned long percentage;
  561. cz_hwmgr->sclk_dpm.soft_min_clk = table->entries[0].clk;
  562. level = cz_get_max_sclk_level(hwmgr) - 1;
  563. if (level < table->count)
  564. cz_hwmgr->sclk_dpm.soft_max_clk = table->entries[level].clk;
  565. else
  566. cz_hwmgr->sclk_dpm.soft_max_clk = table->entries[table->count - 1].clk;
  567. clock = hwmgr->display_config.min_core_set_clock;
  568. if (clock == 0)
  569. pr_debug("min_core_set_clock not set\n");
  570. if (cz_hwmgr->sclk_dpm.hard_min_clk != clock) {
  571. cz_hwmgr->sclk_dpm.hard_min_clk = clock;
  572. smum_send_msg_to_smc_with_parameter(hwmgr,
  573. PPSMC_MSG_SetSclkHardMin,
  574. cz_get_sclk_level(hwmgr,
  575. cz_hwmgr->sclk_dpm.hard_min_clk,
  576. PPSMC_MSG_SetSclkHardMin));
  577. }
  578. clock = cz_hwmgr->sclk_dpm.soft_min_clk;
  579. /* update minimum clocks for Stable P-State feature */
  580. if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
  581. PHM_PlatformCaps_StablePState)) {
  582. percentage = 75;
  583. /*Sclk - calculate sclk value based on percentage and find FLOOR sclk from VddcDependencyOnSCLK table */
  584. stable_pstate_sclk = (hwmgr->dyn_state.max_clock_voltage_on_ac.mclk *
  585. percentage) / 100;
  586. if (clock < stable_pstate_sclk)
  587. clock = stable_pstate_sclk;
  588. } else {
  589. if (clock < hwmgr->gfx_arbiter.sclk)
  590. clock = hwmgr->gfx_arbiter.sclk;
  591. }
  592. if (cz_hwmgr->sclk_dpm.soft_min_clk != clock) {
  593. cz_hwmgr->sclk_dpm.soft_min_clk = clock;
  594. smum_send_msg_to_smc_with_parameter(hwmgr,
  595. PPSMC_MSG_SetSclkSoftMin,
  596. cz_get_sclk_level(hwmgr,
  597. cz_hwmgr->sclk_dpm.soft_min_clk,
  598. PPSMC_MSG_SetSclkSoftMin));
  599. }
  600. if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
  601. PHM_PlatformCaps_StablePState) &&
  602. cz_hwmgr->sclk_dpm.soft_max_clk != clock) {
  603. cz_hwmgr->sclk_dpm.soft_max_clk = clock;
  604. smum_send_msg_to_smc_with_parameter(hwmgr,
  605. PPSMC_MSG_SetSclkSoftMax,
  606. cz_get_sclk_level(hwmgr,
  607. cz_hwmgr->sclk_dpm.soft_max_clk,
  608. PPSMC_MSG_SetSclkSoftMax));
  609. }
  610. return 0;
  611. }
  612. static int cz_set_deep_sleep_sclk_threshold(struct pp_hwmgr *hwmgr)
  613. {
  614. if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
  615. PHM_PlatformCaps_SclkDeepSleep)) {
  616. uint32_t clks = hwmgr->display_config.min_core_set_clock_in_sr;
  617. if (clks == 0)
  618. clks = CZ_MIN_DEEP_SLEEP_SCLK;
  619. PP_DBG_LOG("Setting Deep Sleep Clock: %d\n", clks);
  620. smum_send_msg_to_smc_with_parameter(hwmgr,
  621. PPSMC_MSG_SetMinDeepSleepSclk,
  622. clks);
  623. }
  624. return 0;
  625. }
  626. static int cz_set_watermark_threshold(struct pp_hwmgr *hwmgr)
  627. {
  628. struct cz_hwmgr *cz_hwmgr =
  629. (struct cz_hwmgr *)(hwmgr->backend);
  630. smum_send_msg_to_smc_with_parameter(hwmgr,
  631. PPSMC_MSG_SetWatermarkFrequency,
  632. cz_hwmgr->sclk_dpm.soft_max_clk);
  633. return 0;
  634. }
  635. static int cz_nbdpm_pstate_enable_disable(struct pp_hwmgr *hwmgr, bool enable, bool lock)
  636. {
  637. struct cz_hwmgr *hw_data = (struct cz_hwmgr *)(hwmgr->backend);
  638. if (hw_data->is_nb_dpm_enabled) {
  639. if (enable) {
  640. PP_DBG_LOG("enable Low Memory PState.\n");
  641. return smum_send_msg_to_smc_with_parameter(hwmgr,
  642. PPSMC_MSG_EnableLowMemoryPstate,
  643. (lock ? 1 : 0));
  644. } else {
  645. PP_DBG_LOG("disable Low Memory PState.\n");
  646. return smum_send_msg_to_smc_with_parameter(hwmgr,
  647. PPSMC_MSG_DisableLowMemoryPstate,
  648. (lock ? 1 : 0));
  649. }
  650. }
  651. return 0;
  652. }
  653. static int cz_disable_nb_dpm(struct pp_hwmgr *hwmgr)
  654. {
  655. int ret = 0;
  656. struct cz_hwmgr *cz_hwmgr = (struct cz_hwmgr *)(hwmgr->backend);
  657. unsigned long dpm_features = 0;
  658. if (cz_hwmgr->is_nb_dpm_enabled) {
  659. cz_nbdpm_pstate_enable_disable(hwmgr, true, true);
  660. dpm_features |= NB_DPM_MASK;
  661. ret = smum_send_msg_to_smc_with_parameter(
  662. hwmgr,
  663. PPSMC_MSG_DisableAllSmuFeatures,
  664. dpm_features);
  665. if (ret == 0)
  666. cz_hwmgr->is_nb_dpm_enabled = false;
  667. }
  668. return ret;
  669. }
  670. static int cz_enable_nb_dpm(struct pp_hwmgr *hwmgr)
  671. {
  672. int ret = 0;
  673. struct cz_hwmgr *cz_hwmgr = (struct cz_hwmgr *)(hwmgr->backend);
  674. unsigned long dpm_features = 0;
  675. if (!cz_hwmgr->is_nb_dpm_enabled) {
  676. PP_DBG_LOG("enabling ALL SMU features.\n");
  677. dpm_features |= NB_DPM_MASK;
  678. ret = smum_send_msg_to_smc_with_parameter(
  679. hwmgr,
  680. PPSMC_MSG_EnableAllSmuFeatures,
  681. dpm_features);
  682. if (ret == 0)
  683. cz_hwmgr->is_nb_dpm_enabled = true;
  684. }
  685. return ret;
  686. }
  687. static int cz_update_low_mem_pstate(struct pp_hwmgr *hwmgr, const void *input)
  688. {
  689. bool disable_switch;
  690. bool enable_low_mem_state;
  691. struct cz_hwmgr *hw_data = (struct cz_hwmgr *)(hwmgr->backend);
  692. const struct phm_set_power_state_input *states = (struct phm_set_power_state_input *)input;
  693. const struct cz_power_state *pnew_state = cast_const_PhwCzPowerState(states->pnew_state);
  694. if (hw_data->sys_info.nb_dpm_enable) {
  695. disable_switch = hw_data->cc6_settings.nb_pstate_switch_disable ? true : false;
  696. enable_low_mem_state = hw_data->cc6_settings.nb_pstate_switch_disable ? false : true;
  697. if (pnew_state->action == FORCE_HIGH)
  698. cz_nbdpm_pstate_enable_disable(hwmgr, false, disable_switch);
  699. else if (pnew_state->action == CANCEL_FORCE_HIGH)
  700. cz_nbdpm_pstate_enable_disable(hwmgr, true, disable_switch);
  701. else
  702. cz_nbdpm_pstate_enable_disable(hwmgr, enable_low_mem_state, disable_switch);
  703. }
  704. return 0;
  705. }
  706. static int cz_set_power_state_tasks(struct pp_hwmgr *hwmgr, const void *input)
  707. {
  708. int ret = 0;
  709. cz_update_sclk_limit(hwmgr);
  710. cz_set_deep_sleep_sclk_threshold(hwmgr);
  711. cz_set_watermark_threshold(hwmgr);
  712. ret = cz_enable_nb_dpm(hwmgr);
  713. if (ret)
  714. return ret;
  715. cz_update_low_mem_pstate(hwmgr, input);
  716. return 0;
  717. };
  718. static int cz_setup_asic_task(struct pp_hwmgr *hwmgr)
  719. {
  720. int ret;
  721. ret = cz_upload_pptable_to_smu(hwmgr);
  722. if (ret)
  723. return ret;
  724. ret = cz_init_sclk_limit(hwmgr);
  725. if (ret)
  726. return ret;
  727. ret = cz_init_uvd_limit(hwmgr);
  728. if (ret)
  729. return ret;
  730. ret = cz_init_vce_limit(hwmgr);
  731. if (ret)
  732. return ret;
  733. ret = cz_init_acp_limit(hwmgr);
  734. if (ret)
  735. return ret;
  736. cz_init_power_gate_state(hwmgr);
  737. cz_init_sclk_threshold(hwmgr);
  738. return 0;
  739. }
  740. static void cz_power_up_display_clock_sys_pll(struct pp_hwmgr *hwmgr)
  741. {
  742. struct cz_hwmgr *hw_data = (struct cz_hwmgr *)(hwmgr->backend);
  743. hw_data->disp_clk_bypass_pending = false;
  744. hw_data->disp_clk_bypass = false;
  745. }
  746. static void cz_clear_nb_dpm_flag(struct pp_hwmgr *hwmgr)
  747. {
  748. struct cz_hwmgr *hw_data = (struct cz_hwmgr *)(hwmgr->backend);
  749. hw_data->is_nb_dpm_enabled = false;
  750. }
  751. static void cz_reset_cc6_data(struct pp_hwmgr *hwmgr)
  752. {
  753. struct cz_hwmgr *hw_data = (struct cz_hwmgr *)(hwmgr->backend);
  754. hw_data->cc6_settings.cc6_setting_changed = false;
  755. hw_data->cc6_settings.cpu_pstate_separation_time = 0;
  756. hw_data->cc6_settings.cpu_cc6_disable = false;
  757. hw_data->cc6_settings.cpu_pstate_disable = false;
  758. }
  759. static int cz_power_off_asic(struct pp_hwmgr *hwmgr)
  760. {
  761. cz_power_up_display_clock_sys_pll(hwmgr);
  762. cz_clear_nb_dpm_flag(hwmgr);
  763. cz_reset_cc6_data(hwmgr);
  764. return 0;
  765. };
  766. static void cz_program_voting_clients(struct pp_hwmgr *hwmgr)
  767. {
  768. PHMCZ_WRITE_SMC_REGISTER(hwmgr->device, CG_FREQ_TRAN_VOTING_0,
  769. PPCZ_VOTINGRIGHTSCLIENTS_DFLT0);
  770. }
  771. static void cz_clear_voting_clients(struct pp_hwmgr *hwmgr)
  772. {
  773. PHMCZ_WRITE_SMC_REGISTER(hwmgr->device, CG_FREQ_TRAN_VOTING_0, 0);
  774. }
  775. static int cz_start_dpm(struct pp_hwmgr *hwmgr)
  776. {
  777. int ret = 0;
  778. struct cz_hwmgr *cz_hwmgr = (struct cz_hwmgr *)(hwmgr->backend);
  779. unsigned long dpm_features = 0;
  780. cz_hwmgr->dpm_flags |= DPMFlags_SCLK_Enabled;
  781. dpm_features |= SCLK_DPM_MASK;
  782. ret = smum_send_msg_to_smc_with_parameter(hwmgr,
  783. PPSMC_MSG_EnableAllSmuFeatures,
  784. dpm_features);
  785. return ret;
  786. }
  787. static int cz_stop_dpm(struct pp_hwmgr *hwmgr)
  788. {
  789. int ret = 0;
  790. struct cz_hwmgr *cz_hwmgr = (struct cz_hwmgr *)(hwmgr->backend);
  791. unsigned long dpm_features = 0;
  792. if (cz_hwmgr->dpm_flags & DPMFlags_SCLK_Enabled) {
  793. dpm_features |= SCLK_DPM_MASK;
  794. cz_hwmgr->dpm_flags &= ~DPMFlags_SCLK_Enabled;
  795. ret = smum_send_msg_to_smc_with_parameter(hwmgr,
  796. PPSMC_MSG_DisableAllSmuFeatures,
  797. dpm_features);
  798. }
  799. return ret;
  800. }
  801. static int cz_program_bootup_state(struct pp_hwmgr *hwmgr)
  802. {
  803. struct cz_hwmgr *cz_hwmgr = (struct cz_hwmgr *)(hwmgr->backend);
  804. cz_hwmgr->sclk_dpm.soft_min_clk = cz_hwmgr->sys_info.bootup_engine_clock;
  805. cz_hwmgr->sclk_dpm.soft_max_clk = cz_hwmgr->sys_info.bootup_engine_clock;
  806. smum_send_msg_to_smc_with_parameter(hwmgr,
  807. PPSMC_MSG_SetSclkSoftMin,
  808. cz_get_sclk_level(hwmgr,
  809. cz_hwmgr->sclk_dpm.soft_min_clk,
  810. PPSMC_MSG_SetSclkSoftMin));
  811. smum_send_msg_to_smc_with_parameter(hwmgr,
  812. PPSMC_MSG_SetSclkSoftMax,
  813. cz_get_sclk_level(hwmgr,
  814. cz_hwmgr->sclk_dpm.soft_max_clk,
  815. PPSMC_MSG_SetSclkSoftMax));
  816. return 0;
  817. }
  818. static void cz_reset_acp_boot_level(struct pp_hwmgr *hwmgr)
  819. {
  820. struct cz_hwmgr *cz_hwmgr = (struct cz_hwmgr *)(hwmgr->backend);
  821. cz_hwmgr->acp_boot_level = 0xff;
  822. }
  823. static bool cz_dpm_check_smu_features(struct pp_hwmgr *hwmgr,
  824. unsigned long check_feature)
  825. {
  826. int result;
  827. unsigned long features;
  828. result = smum_send_msg_to_smc_with_parameter(hwmgr, PPSMC_MSG_GetFeatureStatus, 0);
  829. if (result == 0) {
  830. features = smum_get_argument(hwmgr);
  831. if (features & check_feature)
  832. return true;
  833. }
  834. return false;
  835. }
  836. static bool cz_check_for_dpm_enabled(struct pp_hwmgr *hwmgr)
  837. {
  838. if (cz_dpm_check_smu_features(hwmgr, SMU_EnabledFeatureScoreboard_SclkDpmOn))
  839. return true;
  840. return false;
  841. }
  842. static int cz_disable_dpm_tasks(struct pp_hwmgr *hwmgr)
  843. {
  844. if (!cz_check_for_dpm_enabled(hwmgr)) {
  845. pr_info("dpm has been disabled\n");
  846. return 0;
  847. }
  848. cz_disable_nb_dpm(hwmgr);
  849. cz_clear_voting_clients(hwmgr);
  850. if (cz_stop_dpm(hwmgr))
  851. return -EINVAL;
  852. return 0;
  853. };
  854. static int cz_enable_dpm_tasks(struct pp_hwmgr *hwmgr)
  855. {
  856. if (cz_check_for_dpm_enabled(hwmgr)) {
  857. pr_info("dpm has been enabled\n");
  858. return 0;
  859. }
  860. cz_program_voting_clients(hwmgr);
  861. if (cz_start_dpm(hwmgr))
  862. return -EINVAL;
  863. cz_program_bootup_state(hwmgr);
  864. cz_reset_acp_boot_level(hwmgr);
  865. return 0;
  866. };
  867. static int cz_apply_state_adjust_rules(struct pp_hwmgr *hwmgr,
  868. struct pp_power_state *prequest_ps,
  869. const struct pp_power_state *pcurrent_ps)
  870. {
  871. struct cz_power_state *cz_ps =
  872. cast_PhwCzPowerState(&prequest_ps->hardware);
  873. const struct cz_power_state *cz_current_ps =
  874. cast_const_PhwCzPowerState(&pcurrent_ps->hardware);
  875. struct cz_hwmgr *cz_hwmgr = (struct cz_hwmgr *)(hwmgr->backend);
  876. struct PP_Clocks clocks = {0, 0, 0, 0};
  877. bool force_high;
  878. uint32_t num_of_active_displays = 0;
  879. struct cgs_display_info info = {0};
  880. cz_ps->evclk = hwmgr->vce_arbiter.evclk;
  881. cz_ps->ecclk = hwmgr->vce_arbiter.ecclk;
  882. cz_ps->need_dfs_bypass = true;
  883. cz_hwmgr->video_start = (hwmgr->uvd_arbiter.vclk != 0 || hwmgr->uvd_arbiter.dclk != 0 ||
  884. hwmgr->vce_arbiter.evclk != 0 || hwmgr->vce_arbiter.ecclk != 0);
  885. cz_hwmgr->battery_state = (PP_StateUILabel_Battery == prequest_ps->classification.ui_label);
  886. clocks.memoryClock = hwmgr->display_config.min_mem_set_clock != 0 ?
  887. hwmgr->display_config.min_mem_set_clock :
  888. cz_hwmgr->sys_info.nbp_memory_clock[1];
  889. cgs_get_active_displays_info(hwmgr->device, &info);
  890. num_of_active_displays = info.display_count;
  891. if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_StablePState))
  892. clocks.memoryClock = hwmgr->dyn_state.max_clock_voltage_on_ac.mclk;
  893. if (clocks.memoryClock < hwmgr->gfx_arbiter.mclk)
  894. clocks.memoryClock = hwmgr->gfx_arbiter.mclk;
  895. force_high = (clocks.memoryClock > cz_hwmgr->sys_info.nbp_memory_clock[CZ_NUM_NBPMEMORYCLOCK - 1])
  896. || (num_of_active_displays >= 3);
  897. cz_ps->action = cz_current_ps->action;
  898. if (hwmgr->request_dpm_level == AMD_DPM_FORCED_LEVEL_PROFILE_PEAK)
  899. cz_nbdpm_pstate_enable_disable(hwmgr, false, false);
  900. else if (hwmgr->request_dpm_level == AMD_DPM_FORCED_LEVEL_PROFILE_STANDARD)
  901. cz_nbdpm_pstate_enable_disable(hwmgr, false, true);
  902. else if (!force_high && (cz_ps->action == FORCE_HIGH))
  903. cz_ps->action = CANCEL_FORCE_HIGH;
  904. else if (force_high && (cz_ps->action != FORCE_HIGH))
  905. cz_ps->action = FORCE_HIGH;
  906. else
  907. cz_ps->action = DO_NOTHING;
  908. return 0;
  909. }
  910. static int cz_hwmgr_backend_init(struct pp_hwmgr *hwmgr)
  911. {
  912. int result = 0;
  913. struct cz_hwmgr *data;
  914. data = kzalloc(sizeof(struct cz_hwmgr), GFP_KERNEL);
  915. if (data == NULL)
  916. return -ENOMEM;
  917. hwmgr->backend = data;
  918. result = cz_initialize_dpm_defaults(hwmgr);
  919. if (result != 0) {
  920. pr_err("cz_initialize_dpm_defaults failed\n");
  921. return result;
  922. }
  923. result = cz_get_system_info_data(hwmgr);
  924. if (result != 0) {
  925. pr_err("cz_get_system_info_data failed\n");
  926. return result;
  927. }
  928. cz_construct_boot_state(hwmgr);
  929. hwmgr->platform_descriptor.hardwareActivityPerformanceLevels = CZ_MAX_HARDWARE_POWERLEVELS;
  930. return result;
  931. }
  932. static int cz_hwmgr_backend_fini(struct pp_hwmgr *hwmgr)
  933. {
  934. if (hwmgr != NULL) {
  935. kfree(hwmgr->dyn_state.vddc_dep_on_dal_pwrl);
  936. hwmgr->dyn_state.vddc_dep_on_dal_pwrl = NULL;
  937. kfree(hwmgr->backend);
  938. hwmgr->backend = NULL;
  939. }
  940. return 0;
  941. }
  942. static int cz_phm_force_dpm_highest(struct pp_hwmgr *hwmgr)
  943. {
  944. struct cz_hwmgr *cz_hwmgr = (struct cz_hwmgr *)(hwmgr->backend);
  945. smum_send_msg_to_smc_with_parameter(hwmgr,
  946. PPSMC_MSG_SetSclkSoftMin,
  947. cz_get_sclk_level(hwmgr,
  948. cz_hwmgr->sclk_dpm.soft_max_clk,
  949. PPSMC_MSG_SetSclkSoftMin));
  950. smum_send_msg_to_smc_with_parameter(hwmgr,
  951. PPSMC_MSG_SetSclkSoftMax,
  952. cz_get_sclk_level(hwmgr,
  953. cz_hwmgr->sclk_dpm.soft_max_clk,
  954. PPSMC_MSG_SetSclkSoftMax));
  955. return 0;
  956. }
  957. static int cz_phm_unforce_dpm_levels(struct pp_hwmgr *hwmgr)
  958. {
  959. struct cz_hwmgr *cz_hwmgr = (struct cz_hwmgr *)(hwmgr->backend);
  960. struct phm_clock_voltage_dependency_table *table =
  961. hwmgr->dyn_state.vddc_dependency_on_sclk;
  962. unsigned long clock = 0, level;
  963. if (NULL == table || table->count <= 0)
  964. return -EINVAL;
  965. cz_hwmgr->sclk_dpm.soft_min_clk = table->entries[0].clk;
  966. cz_hwmgr->sclk_dpm.hard_min_clk = table->entries[0].clk;
  967. level = cz_get_max_sclk_level(hwmgr) - 1;
  968. if (level < table->count)
  969. clock = table->entries[level].clk;
  970. else
  971. clock = table->entries[table->count - 1].clk;
  972. cz_hwmgr->sclk_dpm.soft_max_clk = clock;
  973. cz_hwmgr->sclk_dpm.hard_max_clk = clock;
  974. smum_send_msg_to_smc_with_parameter(hwmgr,
  975. PPSMC_MSG_SetSclkSoftMin,
  976. cz_get_sclk_level(hwmgr,
  977. cz_hwmgr->sclk_dpm.soft_min_clk,
  978. PPSMC_MSG_SetSclkSoftMin));
  979. smum_send_msg_to_smc_with_parameter(hwmgr,
  980. PPSMC_MSG_SetSclkSoftMax,
  981. cz_get_sclk_level(hwmgr,
  982. cz_hwmgr->sclk_dpm.soft_max_clk,
  983. PPSMC_MSG_SetSclkSoftMax));
  984. return 0;
  985. }
  986. static int cz_phm_force_dpm_lowest(struct pp_hwmgr *hwmgr)
  987. {
  988. struct cz_hwmgr *cz_hwmgr = (struct cz_hwmgr *)(hwmgr->backend);
  989. smum_send_msg_to_smc_with_parameter(hwmgr,
  990. PPSMC_MSG_SetSclkSoftMax,
  991. cz_get_sclk_level(hwmgr,
  992. cz_hwmgr->sclk_dpm.soft_min_clk,
  993. PPSMC_MSG_SetSclkSoftMax));
  994. smum_send_msg_to_smc_with_parameter(hwmgr,
  995. PPSMC_MSG_SetSclkSoftMin,
  996. cz_get_sclk_level(hwmgr,
  997. cz_hwmgr->sclk_dpm.soft_min_clk,
  998. PPSMC_MSG_SetSclkSoftMin));
  999. return 0;
  1000. }
  1001. static int cz_dpm_force_dpm_level(struct pp_hwmgr *hwmgr,
  1002. enum amd_dpm_forced_level level)
  1003. {
  1004. int ret = 0;
  1005. switch (level) {
  1006. case AMD_DPM_FORCED_LEVEL_HIGH:
  1007. case AMD_DPM_FORCED_LEVEL_PROFILE_PEAK:
  1008. ret = cz_phm_force_dpm_highest(hwmgr);
  1009. break;
  1010. case AMD_DPM_FORCED_LEVEL_LOW:
  1011. case AMD_DPM_FORCED_LEVEL_PROFILE_MIN_SCLK:
  1012. case AMD_DPM_FORCED_LEVEL_PROFILE_STANDARD:
  1013. ret = cz_phm_force_dpm_lowest(hwmgr);
  1014. break;
  1015. case AMD_DPM_FORCED_LEVEL_AUTO:
  1016. ret = cz_phm_unforce_dpm_levels(hwmgr);
  1017. break;
  1018. case AMD_DPM_FORCED_LEVEL_MANUAL:
  1019. case AMD_DPM_FORCED_LEVEL_PROFILE_EXIT:
  1020. default:
  1021. break;
  1022. }
  1023. return ret;
  1024. }
  1025. int cz_dpm_powerdown_uvd(struct pp_hwmgr *hwmgr)
  1026. {
  1027. if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
  1028. PHM_PlatformCaps_UVDPowerGating))
  1029. return smum_send_msg_to_smc(hwmgr,
  1030. PPSMC_MSG_UVDPowerOFF);
  1031. return 0;
  1032. }
  1033. int cz_dpm_powerup_uvd(struct pp_hwmgr *hwmgr)
  1034. {
  1035. if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
  1036. PHM_PlatformCaps_UVDPowerGating)) {
  1037. if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
  1038. PHM_PlatformCaps_UVDDynamicPowerGating)) {
  1039. return smum_send_msg_to_smc_with_parameter(
  1040. hwmgr,
  1041. PPSMC_MSG_UVDPowerON, 1);
  1042. } else {
  1043. return smum_send_msg_to_smc_with_parameter(
  1044. hwmgr,
  1045. PPSMC_MSG_UVDPowerON, 0);
  1046. }
  1047. }
  1048. return 0;
  1049. }
  1050. int cz_dpm_update_uvd_dpm(struct pp_hwmgr *hwmgr, bool bgate)
  1051. {
  1052. struct cz_hwmgr *cz_hwmgr = (struct cz_hwmgr *)(hwmgr->backend);
  1053. struct phm_uvd_clock_voltage_dependency_table *ptable =
  1054. hwmgr->dyn_state.uvd_clock_voltage_dependency_table;
  1055. if (!bgate) {
  1056. /* Stable Pstate is enabled and we need to set the UVD DPM to highest level */
  1057. if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
  1058. PHM_PlatformCaps_StablePState)
  1059. || hwmgr->en_umd_pstate) {
  1060. cz_hwmgr->uvd_dpm.hard_min_clk =
  1061. ptable->entries[ptable->count - 1].vclk;
  1062. smum_send_msg_to_smc_with_parameter(hwmgr,
  1063. PPSMC_MSG_SetUvdHardMin,
  1064. cz_get_uvd_level(hwmgr,
  1065. cz_hwmgr->uvd_dpm.hard_min_clk,
  1066. PPSMC_MSG_SetUvdHardMin));
  1067. cz_enable_disable_uvd_dpm(hwmgr, true);
  1068. } else {
  1069. cz_enable_disable_uvd_dpm(hwmgr, true);
  1070. }
  1071. } else {
  1072. cz_enable_disable_uvd_dpm(hwmgr, false);
  1073. }
  1074. return 0;
  1075. }
  1076. int cz_dpm_update_vce_dpm(struct pp_hwmgr *hwmgr)
  1077. {
  1078. struct cz_hwmgr *cz_hwmgr = (struct cz_hwmgr *)(hwmgr->backend);
  1079. struct phm_vce_clock_voltage_dependency_table *ptable =
  1080. hwmgr->dyn_state.vce_clock_voltage_dependency_table;
  1081. /* Stable Pstate is enabled and we need to set the VCE DPM to highest level */
  1082. if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
  1083. PHM_PlatformCaps_StablePState)
  1084. || hwmgr->en_umd_pstate) {
  1085. cz_hwmgr->vce_dpm.hard_min_clk =
  1086. ptable->entries[ptable->count - 1].ecclk;
  1087. smum_send_msg_to_smc_with_parameter(hwmgr,
  1088. PPSMC_MSG_SetEclkHardMin,
  1089. cz_get_eclk_level(hwmgr,
  1090. cz_hwmgr->vce_dpm.hard_min_clk,
  1091. PPSMC_MSG_SetEclkHardMin));
  1092. } else {
  1093. /*Program HardMin based on the vce_arbiter.ecclk */
  1094. if (hwmgr->vce_arbiter.ecclk == 0) {
  1095. smum_send_msg_to_smc_with_parameter(hwmgr,
  1096. PPSMC_MSG_SetEclkHardMin, 0);
  1097. /* disable ECLK DPM 0. Otherwise VCE could hang if
  1098. * switching SCLK from DPM 0 to 6/7 */
  1099. smum_send_msg_to_smc_with_parameter(hwmgr,
  1100. PPSMC_MSG_SetEclkSoftMin, 1);
  1101. } else {
  1102. cz_hwmgr->vce_dpm.hard_min_clk = hwmgr->vce_arbiter.ecclk;
  1103. smum_send_msg_to_smc_with_parameter(hwmgr,
  1104. PPSMC_MSG_SetEclkHardMin,
  1105. cz_get_eclk_level(hwmgr,
  1106. cz_hwmgr->vce_dpm.hard_min_clk,
  1107. PPSMC_MSG_SetEclkHardMin));
  1108. }
  1109. }
  1110. return 0;
  1111. }
  1112. int cz_dpm_powerdown_vce(struct pp_hwmgr *hwmgr)
  1113. {
  1114. if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
  1115. PHM_PlatformCaps_VCEPowerGating))
  1116. return smum_send_msg_to_smc(hwmgr,
  1117. PPSMC_MSG_VCEPowerOFF);
  1118. return 0;
  1119. }
  1120. int cz_dpm_powerup_vce(struct pp_hwmgr *hwmgr)
  1121. {
  1122. if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps,
  1123. PHM_PlatformCaps_VCEPowerGating))
  1124. return smum_send_msg_to_smc(hwmgr,
  1125. PPSMC_MSG_VCEPowerON);
  1126. return 0;
  1127. }
  1128. static uint32_t cz_dpm_get_mclk(struct pp_hwmgr *hwmgr, bool low)
  1129. {
  1130. struct cz_hwmgr *cz_hwmgr = (struct cz_hwmgr *)(hwmgr->backend);
  1131. return cz_hwmgr->sys_info.bootup_uma_clock;
  1132. }
  1133. static uint32_t cz_dpm_get_sclk(struct pp_hwmgr *hwmgr, bool low)
  1134. {
  1135. struct pp_power_state *ps;
  1136. struct cz_power_state *cz_ps;
  1137. if (hwmgr == NULL)
  1138. return -EINVAL;
  1139. ps = hwmgr->request_ps;
  1140. if (ps == NULL)
  1141. return -EINVAL;
  1142. cz_ps = cast_PhwCzPowerState(&ps->hardware);
  1143. if (low)
  1144. return cz_ps->levels[0].engineClock;
  1145. else
  1146. return cz_ps->levels[cz_ps->level-1].engineClock;
  1147. }
  1148. static int cz_dpm_patch_boot_state(struct pp_hwmgr *hwmgr,
  1149. struct pp_hw_power_state *hw_ps)
  1150. {
  1151. struct cz_hwmgr *cz_hwmgr = (struct cz_hwmgr *)(hwmgr->backend);
  1152. struct cz_power_state *cz_ps = cast_PhwCzPowerState(hw_ps);
  1153. cz_ps->level = 1;
  1154. cz_ps->nbps_flags = 0;
  1155. cz_ps->bapm_flags = 0;
  1156. cz_ps->levels[0] = cz_hwmgr->boot_power_level;
  1157. return 0;
  1158. }
  1159. static int cz_dpm_get_pp_table_entry_callback(
  1160. struct pp_hwmgr *hwmgr,
  1161. struct pp_hw_power_state *hw_ps,
  1162. unsigned int index,
  1163. const void *clock_info)
  1164. {
  1165. struct cz_power_state *cz_ps = cast_PhwCzPowerState(hw_ps);
  1166. const ATOM_PPLIB_CZ_CLOCK_INFO *cz_clock_info = clock_info;
  1167. struct phm_clock_voltage_dependency_table *table =
  1168. hwmgr->dyn_state.vddc_dependency_on_sclk;
  1169. uint8_t clock_info_index = cz_clock_info->index;
  1170. if (clock_info_index > (uint8_t)(hwmgr->platform_descriptor.hardwareActivityPerformanceLevels - 1))
  1171. clock_info_index = (uint8_t)(hwmgr->platform_descriptor.hardwareActivityPerformanceLevels - 1);
  1172. cz_ps->levels[index].engineClock = table->entries[clock_info_index].clk;
  1173. cz_ps->levels[index].vddcIndex = (uint8_t)table->entries[clock_info_index].v;
  1174. cz_ps->level = index + 1;
  1175. if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_SclkDeepSleep)) {
  1176. cz_ps->levels[index].dsDividerIndex = 5;
  1177. cz_ps->levels[index].ssDividerIndex = 5;
  1178. }
  1179. return 0;
  1180. }
  1181. static int cz_dpm_get_num_of_pp_table_entries(struct pp_hwmgr *hwmgr)
  1182. {
  1183. int result;
  1184. unsigned long ret = 0;
  1185. result = pp_tables_get_num_of_entries(hwmgr, &ret);
  1186. return result ? 0 : ret;
  1187. }
  1188. static int cz_dpm_get_pp_table_entry(struct pp_hwmgr *hwmgr,
  1189. unsigned long entry, struct pp_power_state *ps)
  1190. {
  1191. int result;
  1192. struct cz_power_state *cz_ps;
  1193. ps->hardware.magic = PhwCz_Magic;
  1194. cz_ps = cast_PhwCzPowerState(&(ps->hardware));
  1195. result = pp_tables_get_entry(hwmgr, entry, ps,
  1196. cz_dpm_get_pp_table_entry_callback);
  1197. cz_ps->uvd_clocks.vclk = ps->uvd_clocks.VCLK;
  1198. cz_ps->uvd_clocks.dclk = ps->uvd_clocks.DCLK;
  1199. return result;
  1200. }
  1201. static int cz_get_power_state_size(struct pp_hwmgr *hwmgr)
  1202. {
  1203. return sizeof(struct cz_power_state);
  1204. }
  1205. static void cz_hw_print_display_cfg(
  1206. const struct cc6_settings *cc6_settings)
  1207. {
  1208. PP_DBG_LOG("New Display Configuration:\n");
  1209. PP_DBG_LOG(" cpu_cc6_disable: %d\n",
  1210. cc6_settings->cpu_cc6_disable);
  1211. PP_DBG_LOG(" cpu_pstate_disable: %d\n",
  1212. cc6_settings->cpu_pstate_disable);
  1213. PP_DBG_LOG(" nb_pstate_switch_disable: %d\n",
  1214. cc6_settings->nb_pstate_switch_disable);
  1215. PP_DBG_LOG(" cpu_pstate_separation_time: %d\n\n",
  1216. cc6_settings->cpu_pstate_separation_time);
  1217. }
  1218. static int cz_set_cpu_power_state(struct pp_hwmgr *hwmgr)
  1219. {
  1220. struct cz_hwmgr *hw_data = (struct cz_hwmgr *)(hwmgr->backend);
  1221. uint32_t data = 0;
  1222. if (hw_data->cc6_settings.cc6_setting_changed) {
  1223. hw_data->cc6_settings.cc6_setting_changed = false;
  1224. cz_hw_print_display_cfg(&hw_data->cc6_settings);
  1225. data |= (hw_data->cc6_settings.cpu_pstate_separation_time
  1226. & PWRMGT_SEPARATION_TIME_MASK)
  1227. << PWRMGT_SEPARATION_TIME_SHIFT;
  1228. data |= (hw_data->cc6_settings.cpu_cc6_disable ? 0x1 : 0x0)
  1229. << PWRMGT_DISABLE_CPU_CSTATES_SHIFT;
  1230. data |= (hw_data->cc6_settings.cpu_pstate_disable ? 0x1 : 0x0)
  1231. << PWRMGT_DISABLE_CPU_PSTATES_SHIFT;
  1232. PP_DBG_LOG("SetDisplaySizePowerParams data: 0x%X\n",
  1233. data);
  1234. smum_send_msg_to_smc_with_parameter(hwmgr,
  1235. PPSMC_MSG_SetDisplaySizePowerParams,
  1236. data);
  1237. }
  1238. return 0;
  1239. }
  1240. static int cz_store_cc6_data(struct pp_hwmgr *hwmgr, uint32_t separation_time,
  1241. bool cc6_disable, bool pstate_disable, bool pstate_switch_disable)
  1242. {
  1243. struct cz_hwmgr *hw_data = (struct cz_hwmgr *)(hwmgr->backend);
  1244. if (separation_time !=
  1245. hw_data->cc6_settings.cpu_pstate_separation_time ||
  1246. cc6_disable != hw_data->cc6_settings.cpu_cc6_disable ||
  1247. pstate_disable != hw_data->cc6_settings.cpu_pstate_disable ||
  1248. pstate_switch_disable != hw_data->cc6_settings.nb_pstate_switch_disable) {
  1249. hw_data->cc6_settings.cc6_setting_changed = true;
  1250. hw_data->cc6_settings.cpu_pstate_separation_time =
  1251. separation_time;
  1252. hw_data->cc6_settings.cpu_cc6_disable =
  1253. cc6_disable;
  1254. hw_data->cc6_settings.cpu_pstate_disable =
  1255. pstate_disable;
  1256. hw_data->cc6_settings.nb_pstate_switch_disable =
  1257. pstate_switch_disable;
  1258. }
  1259. return 0;
  1260. }
  1261. static int cz_get_dal_power_level(struct pp_hwmgr *hwmgr,
  1262. struct amd_pp_simple_clock_info *info)
  1263. {
  1264. uint32_t i;
  1265. const struct phm_clock_voltage_dependency_table *table =
  1266. hwmgr->dyn_state.vddc_dep_on_dal_pwrl;
  1267. const struct phm_clock_and_voltage_limits *limits =
  1268. &hwmgr->dyn_state.max_clock_voltage_on_ac;
  1269. info->engine_max_clock = limits->sclk;
  1270. info->memory_max_clock = limits->mclk;
  1271. for (i = table->count - 1; i > 0; i--) {
  1272. if (limits->vddc >= table->entries[i].v) {
  1273. info->level = table->entries[i].clk;
  1274. return 0;
  1275. }
  1276. }
  1277. return -EINVAL;
  1278. }
  1279. static int cz_force_clock_level(struct pp_hwmgr *hwmgr,
  1280. enum pp_clock_type type, uint32_t mask)
  1281. {
  1282. if (hwmgr->dpm_level != AMD_DPM_FORCED_LEVEL_MANUAL)
  1283. return -EINVAL;
  1284. switch (type) {
  1285. case PP_SCLK:
  1286. smum_send_msg_to_smc_with_parameter(hwmgr,
  1287. PPSMC_MSG_SetSclkSoftMin,
  1288. mask);
  1289. smum_send_msg_to_smc_with_parameter(hwmgr,
  1290. PPSMC_MSG_SetSclkSoftMax,
  1291. mask);
  1292. break;
  1293. default:
  1294. break;
  1295. }
  1296. return 0;
  1297. }
  1298. static int cz_print_clock_levels(struct pp_hwmgr *hwmgr,
  1299. enum pp_clock_type type, char *buf)
  1300. {
  1301. struct phm_clock_voltage_dependency_table *sclk_table =
  1302. hwmgr->dyn_state.vddc_dependency_on_sclk;
  1303. int i, now, size = 0;
  1304. switch (type) {
  1305. case PP_SCLK:
  1306. now = PHM_GET_FIELD(cgs_read_ind_register(hwmgr->device,
  1307. CGS_IND_REG__SMC,
  1308. ixTARGET_AND_CURRENT_PROFILE_INDEX),
  1309. TARGET_AND_CURRENT_PROFILE_INDEX,
  1310. CURR_SCLK_INDEX);
  1311. for (i = 0; i < sclk_table->count; i++)
  1312. size += sprintf(buf + size, "%d: %uMhz %s\n",
  1313. i, sclk_table->entries[i].clk / 100,
  1314. (i == now) ? "*" : "");
  1315. break;
  1316. default:
  1317. break;
  1318. }
  1319. return size;
  1320. }
  1321. static int cz_get_performance_level(struct pp_hwmgr *hwmgr, const struct pp_hw_power_state *state,
  1322. PHM_PerformanceLevelDesignation designation, uint32_t index,
  1323. PHM_PerformanceLevel *level)
  1324. {
  1325. const struct cz_power_state *ps;
  1326. struct cz_hwmgr *data;
  1327. uint32_t level_index;
  1328. uint32_t i;
  1329. if (level == NULL || hwmgr == NULL || state == NULL)
  1330. return -EINVAL;
  1331. data = (struct cz_hwmgr *)(hwmgr->backend);
  1332. ps = cast_const_PhwCzPowerState(state);
  1333. level_index = index > ps->level - 1 ? ps->level - 1 : index;
  1334. level->coreClock = ps->levels[level_index].engineClock;
  1335. if (designation == PHM_PerformanceLevelDesignation_PowerContainment) {
  1336. for (i = 1; i < ps->level; i++) {
  1337. if (ps->levels[i].engineClock > data->dce_slow_sclk_threshold) {
  1338. level->coreClock = ps->levels[i].engineClock;
  1339. break;
  1340. }
  1341. }
  1342. }
  1343. if (level_index == 0)
  1344. level->memory_clock = data->sys_info.nbp_memory_clock[CZ_NUM_NBPMEMORYCLOCK - 1];
  1345. else
  1346. level->memory_clock = data->sys_info.nbp_memory_clock[0];
  1347. level->vddc = (cz_convert_8Bit_index_to_voltage(hwmgr, ps->levels[level_index].vddcIndex) + 2) / 4;
  1348. level->nonLocalMemoryFreq = 0;
  1349. level->nonLocalMemoryWidth = 0;
  1350. return 0;
  1351. }
  1352. static int cz_get_current_shallow_sleep_clocks(struct pp_hwmgr *hwmgr,
  1353. const struct pp_hw_power_state *state, struct pp_clock_info *clock_info)
  1354. {
  1355. const struct cz_power_state *ps = cast_const_PhwCzPowerState(state);
  1356. clock_info->min_eng_clk = ps->levels[0].engineClock / (1 << (ps->levels[0].ssDividerIndex));
  1357. clock_info->max_eng_clk = ps->levels[ps->level - 1].engineClock / (1 << (ps->levels[ps->level - 1].ssDividerIndex));
  1358. return 0;
  1359. }
  1360. static int cz_get_clock_by_type(struct pp_hwmgr *hwmgr, enum amd_pp_clock_type type,
  1361. struct amd_pp_clocks *clocks)
  1362. {
  1363. struct cz_hwmgr *data = (struct cz_hwmgr *)(hwmgr->backend);
  1364. int i;
  1365. struct phm_clock_voltage_dependency_table *table;
  1366. clocks->count = cz_get_max_sclk_level(hwmgr);
  1367. switch (type) {
  1368. case amd_pp_disp_clock:
  1369. for (i = 0; i < clocks->count; i++)
  1370. clocks->clock[i] = data->sys_info.display_clock[i];
  1371. break;
  1372. case amd_pp_sys_clock:
  1373. table = hwmgr->dyn_state.vddc_dependency_on_sclk;
  1374. for (i = 0; i < clocks->count; i++)
  1375. clocks->clock[i] = table->entries[i].clk;
  1376. break;
  1377. case amd_pp_mem_clock:
  1378. clocks->count = CZ_NUM_NBPMEMORYCLOCK;
  1379. for (i = 0; i < clocks->count; i++)
  1380. clocks->clock[i] = data->sys_info.nbp_memory_clock[clocks->count - 1 - i];
  1381. break;
  1382. default:
  1383. return -1;
  1384. }
  1385. return 0;
  1386. }
  1387. static int cz_get_max_high_clocks(struct pp_hwmgr *hwmgr, struct amd_pp_simple_clock_info *clocks)
  1388. {
  1389. struct phm_clock_voltage_dependency_table *table =
  1390. hwmgr->dyn_state.vddc_dependency_on_sclk;
  1391. unsigned long level;
  1392. const struct phm_clock_and_voltage_limits *limits =
  1393. &hwmgr->dyn_state.max_clock_voltage_on_ac;
  1394. if ((NULL == table) || (table->count <= 0) || (clocks == NULL))
  1395. return -EINVAL;
  1396. level = cz_get_max_sclk_level(hwmgr) - 1;
  1397. if (level < table->count)
  1398. clocks->engine_max_clock = table->entries[level].clk;
  1399. else
  1400. clocks->engine_max_clock = table->entries[table->count - 1].clk;
  1401. clocks->memory_max_clock = limits->mclk;
  1402. return 0;
  1403. }
  1404. static int cz_thermal_get_temperature(struct pp_hwmgr *hwmgr)
  1405. {
  1406. int actual_temp = 0;
  1407. uint32_t val = cgs_read_ind_register(hwmgr->device,
  1408. CGS_IND_REG__SMC, ixTHM_TCON_CUR_TMP);
  1409. uint32_t temp = PHM_GET_FIELD(val, THM_TCON_CUR_TMP, CUR_TEMP);
  1410. if (PHM_GET_FIELD(val, THM_TCON_CUR_TMP, CUR_TEMP_RANGE_SEL))
  1411. actual_temp = ((temp / 8) - 49) * PP_TEMPERATURE_UNITS_PER_CENTIGRADES;
  1412. else
  1413. actual_temp = (temp / 8) * PP_TEMPERATURE_UNITS_PER_CENTIGRADES;
  1414. return actual_temp;
  1415. }
  1416. static int cz_read_sensor(struct pp_hwmgr *hwmgr, int idx,
  1417. void *value, int *size)
  1418. {
  1419. struct cz_hwmgr *cz_hwmgr = (struct cz_hwmgr *)(hwmgr->backend);
  1420. struct phm_clock_voltage_dependency_table *table =
  1421. hwmgr->dyn_state.vddc_dependency_on_sclk;
  1422. struct phm_vce_clock_voltage_dependency_table *vce_table =
  1423. hwmgr->dyn_state.vce_clock_voltage_dependency_table;
  1424. struct phm_uvd_clock_voltage_dependency_table *uvd_table =
  1425. hwmgr->dyn_state.uvd_clock_voltage_dependency_table;
  1426. uint32_t sclk_index = PHM_GET_FIELD(cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixTARGET_AND_CURRENT_PROFILE_INDEX),
  1427. TARGET_AND_CURRENT_PROFILE_INDEX, CURR_SCLK_INDEX);
  1428. uint32_t uvd_index = PHM_GET_FIELD(cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixTARGET_AND_CURRENT_PROFILE_INDEX_2),
  1429. TARGET_AND_CURRENT_PROFILE_INDEX_2, CURR_UVD_INDEX);
  1430. uint32_t vce_index = PHM_GET_FIELD(cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixTARGET_AND_CURRENT_PROFILE_INDEX_2),
  1431. TARGET_AND_CURRENT_PROFILE_INDEX_2, CURR_VCE_INDEX);
  1432. uint32_t sclk, vclk, dclk, ecclk, tmp, activity_percent;
  1433. uint16_t vddnb, vddgfx;
  1434. int result;
  1435. /* size must be at least 4 bytes for all sensors */
  1436. if (*size < 4)
  1437. return -EINVAL;
  1438. *size = 4;
  1439. switch (idx) {
  1440. case AMDGPU_PP_SENSOR_GFX_SCLK:
  1441. if (sclk_index < NUM_SCLK_LEVELS) {
  1442. sclk = table->entries[sclk_index].clk;
  1443. *((uint32_t *)value) = sclk;
  1444. return 0;
  1445. }
  1446. return -EINVAL;
  1447. case AMDGPU_PP_SENSOR_VDDNB:
  1448. tmp = (cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixSMUSVI_NB_CURRENTVID) &
  1449. CURRENT_NB_VID_MASK) >> CURRENT_NB_VID__SHIFT;
  1450. vddnb = cz_convert_8Bit_index_to_voltage(hwmgr, tmp);
  1451. *((uint32_t *)value) = vddnb;
  1452. return 0;
  1453. case AMDGPU_PP_SENSOR_VDDGFX:
  1454. tmp = (cgs_read_ind_register(hwmgr->device, CGS_IND_REG__SMC, ixSMUSVI_GFX_CURRENTVID) &
  1455. CURRENT_GFX_VID_MASK) >> CURRENT_GFX_VID__SHIFT;
  1456. vddgfx = cz_convert_8Bit_index_to_voltage(hwmgr, (u16)tmp);
  1457. *((uint32_t *)value) = vddgfx;
  1458. return 0;
  1459. case AMDGPU_PP_SENSOR_UVD_VCLK:
  1460. if (!cz_hwmgr->uvd_power_gated) {
  1461. if (uvd_index >= CZ_MAX_HARDWARE_POWERLEVELS) {
  1462. return -EINVAL;
  1463. } else {
  1464. vclk = uvd_table->entries[uvd_index].vclk;
  1465. *((uint32_t *)value) = vclk;
  1466. return 0;
  1467. }
  1468. }
  1469. *((uint32_t *)value) = 0;
  1470. return 0;
  1471. case AMDGPU_PP_SENSOR_UVD_DCLK:
  1472. if (!cz_hwmgr->uvd_power_gated) {
  1473. if (uvd_index >= CZ_MAX_HARDWARE_POWERLEVELS) {
  1474. return -EINVAL;
  1475. } else {
  1476. dclk = uvd_table->entries[uvd_index].dclk;
  1477. *((uint32_t *)value) = dclk;
  1478. return 0;
  1479. }
  1480. }
  1481. *((uint32_t *)value) = 0;
  1482. return 0;
  1483. case AMDGPU_PP_SENSOR_VCE_ECCLK:
  1484. if (!cz_hwmgr->vce_power_gated) {
  1485. if (vce_index >= CZ_MAX_HARDWARE_POWERLEVELS) {
  1486. return -EINVAL;
  1487. } else {
  1488. ecclk = vce_table->entries[vce_index].ecclk;
  1489. *((uint32_t *)value) = ecclk;
  1490. return 0;
  1491. }
  1492. }
  1493. *((uint32_t *)value) = 0;
  1494. return 0;
  1495. case AMDGPU_PP_SENSOR_GPU_LOAD:
  1496. result = smum_send_msg_to_smc(hwmgr, PPSMC_MSG_GetAverageGraphicsActivity);
  1497. if (0 == result) {
  1498. activity_percent = cgs_read_register(hwmgr->device, mmSMU_MP1_SRBM2P_ARG_0);
  1499. activity_percent = activity_percent > 100 ? 100 : activity_percent;
  1500. } else {
  1501. activity_percent = 50;
  1502. }
  1503. *((uint32_t *)value) = activity_percent;
  1504. return 0;
  1505. case AMDGPU_PP_SENSOR_UVD_POWER:
  1506. *((uint32_t *)value) = cz_hwmgr->uvd_power_gated ? 0 : 1;
  1507. return 0;
  1508. case AMDGPU_PP_SENSOR_VCE_POWER:
  1509. *((uint32_t *)value) = cz_hwmgr->vce_power_gated ? 0 : 1;
  1510. return 0;
  1511. case AMDGPU_PP_SENSOR_GPU_TEMP:
  1512. *((uint32_t *)value) = cz_thermal_get_temperature(hwmgr);
  1513. return 0;
  1514. default:
  1515. return -EINVAL;
  1516. }
  1517. }
  1518. static const struct pp_hwmgr_func cz_hwmgr_funcs = {
  1519. .backend_init = cz_hwmgr_backend_init,
  1520. .backend_fini = cz_hwmgr_backend_fini,
  1521. .apply_state_adjust_rules = cz_apply_state_adjust_rules,
  1522. .force_dpm_level = cz_dpm_force_dpm_level,
  1523. .get_power_state_size = cz_get_power_state_size,
  1524. .powerdown_uvd = cz_dpm_powerdown_uvd,
  1525. .powergate_uvd = cz_dpm_powergate_uvd,
  1526. .powergate_vce = cz_dpm_powergate_vce,
  1527. .get_mclk = cz_dpm_get_mclk,
  1528. .get_sclk = cz_dpm_get_sclk,
  1529. .patch_boot_state = cz_dpm_patch_boot_state,
  1530. .get_pp_table_entry = cz_dpm_get_pp_table_entry,
  1531. .get_num_of_pp_table_entries = cz_dpm_get_num_of_pp_table_entries,
  1532. .set_cpu_power_state = cz_set_cpu_power_state,
  1533. .store_cc6_data = cz_store_cc6_data,
  1534. .force_clock_level = cz_force_clock_level,
  1535. .print_clock_levels = cz_print_clock_levels,
  1536. .get_dal_power_level = cz_get_dal_power_level,
  1537. .get_performance_level = cz_get_performance_level,
  1538. .get_current_shallow_sleep_clocks = cz_get_current_shallow_sleep_clocks,
  1539. .get_clock_by_type = cz_get_clock_by_type,
  1540. .get_max_high_clocks = cz_get_max_high_clocks,
  1541. .read_sensor = cz_read_sensor,
  1542. .power_off_asic = cz_power_off_asic,
  1543. .asic_setup = cz_setup_asic_task,
  1544. .dynamic_state_management_enable = cz_enable_dpm_tasks,
  1545. .power_state_set = cz_set_power_state_tasks,
  1546. .dynamic_state_management_disable = cz_disable_dpm_tasks,
  1547. };
  1548. int cz_init_function_pointers(struct pp_hwmgr *hwmgr)
  1549. {
  1550. hwmgr->hwmgr_func = &cz_hwmgr_funcs;
  1551. hwmgr->pptable_func = &pptable_funcs;
  1552. return 0;
  1553. }