hwmgr.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861
  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/delay.h"
  25. #include <linux/types.h>
  26. #include <linux/kernel.h>
  27. #include <linux/slab.h>
  28. #include <drm/amdgpu_drm.h>
  29. #include "cgs_common.h"
  30. #include "power_state.h"
  31. #include "hwmgr.h"
  32. #include "pppcielanes.h"
  33. #include "ppatomctrl.h"
  34. #include "ppsmc.h"
  35. #include "pp_acpi.h"
  36. #include "amd_acpi.h"
  37. extern int cz_init_function_pointers(struct pp_hwmgr *hwmgr);
  38. static int polaris_set_asic_special_caps(struct pp_hwmgr *hwmgr);
  39. static void hwmgr_init_default_caps(struct pp_hwmgr *hwmgr);
  40. static int hwmgr_set_user_specify_caps(struct pp_hwmgr *hwmgr);
  41. static int fiji_set_asic_special_caps(struct pp_hwmgr *hwmgr);
  42. static int tonga_set_asic_special_caps(struct pp_hwmgr *hwmgr);
  43. static int topaz_set_asic_special_caps(struct pp_hwmgr *hwmgr);
  44. uint8_t convert_to_vid(uint16_t vddc)
  45. {
  46. return (uint8_t) ((6200 - (vddc * VOLTAGE_SCALE)) / 25);
  47. }
  48. int hwmgr_early_init(struct pp_instance *handle)
  49. {
  50. struct pp_hwmgr *hwmgr;
  51. if (handle == NULL)
  52. return -EINVAL;
  53. hwmgr = kzalloc(sizeof(struct pp_hwmgr), GFP_KERNEL);
  54. if (hwmgr == NULL)
  55. return -ENOMEM;
  56. handle->hwmgr = hwmgr;
  57. hwmgr->smumgr = handle->smu_mgr;
  58. hwmgr->device = handle->device;
  59. hwmgr->chip_family = handle->chip_family;
  60. hwmgr->chip_id = handle->chip_id;
  61. hwmgr->feature_mask = handle->feature_mask;
  62. hwmgr->usec_timeout = AMD_MAX_USEC_TIMEOUT;
  63. hwmgr->power_source = PP_PowerSource_AC;
  64. hwmgr->pp_table_version = PP_TABLE_V1;
  65. hwmgr->dpm_level = AMD_DPM_FORCED_LEVEL_AUTO;
  66. hwmgr_init_default_caps(hwmgr);
  67. hwmgr_set_user_specify_caps(hwmgr);
  68. switch (hwmgr->chip_family) {
  69. case AMDGPU_FAMILY_CZ:
  70. cz_init_function_pointers(hwmgr);
  71. break;
  72. case AMDGPU_FAMILY_VI:
  73. switch (hwmgr->chip_id) {
  74. case CHIP_TOPAZ:
  75. topaz_set_asic_special_caps(hwmgr);
  76. hwmgr->feature_mask &= ~ (PP_VBI_TIME_SUPPORT_MASK |
  77. PP_ENABLE_GFX_CG_THRU_SMU);
  78. hwmgr->pp_table_version = PP_TABLE_V0;
  79. break;
  80. case CHIP_TONGA:
  81. tonga_set_asic_special_caps(hwmgr);
  82. hwmgr->feature_mask &= ~PP_VBI_TIME_SUPPORT_MASK;
  83. break;
  84. case CHIP_FIJI:
  85. fiji_set_asic_special_caps(hwmgr);
  86. hwmgr->feature_mask &= ~ (PP_VBI_TIME_SUPPORT_MASK |
  87. PP_ENABLE_GFX_CG_THRU_SMU);
  88. break;
  89. case CHIP_POLARIS11:
  90. case CHIP_POLARIS10:
  91. case CHIP_POLARIS12:
  92. polaris_set_asic_special_caps(hwmgr);
  93. hwmgr->feature_mask &= ~(PP_UVD_HANDSHAKE_MASK);
  94. break;
  95. default:
  96. return -EINVAL;
  97. }
  98. smu7_init_function_pointers(hwmgr);
  99. break;
  100. case AMDGPU_FAMILY_AI:
  101. switch (hwmgr->chip_id) {
  102. case CHIP_VEGA10:
  103. vega10_hwmgr_init(hwmgr);
  104. break;
  105. default:
  106. return -EINVAL;
  107. }
  108. break;
  109. default:
  110. return -EINVAL;
  111. }
  112. return 0;
  113. }
  114. static int hw_init_power_state_table(struct pp_hwmgr *hwmgr)
  115. {
  116. int result;
  117. unsigned int i;
  118. unsigned int table_entries;
  119. struct pp_power_state *state;
  120. int size;
  121. if (hwmgr->hwmgr_func->get_num_of_pp_table_entries == NULL)
  122. return -EINVAL;
  123. if (hwmgr->hwmgr_func->get_power_state_size == NULL)
  124. return -EINVAL;
  125. hwmgr->num_ps = table_entries = hwmgr->hwmgr_func->get_num_of_pp_table_entries(hwmgr);
  126. hwmgr->ps_size = size = hwmgr->hwmgr_func->get_power_state_size(hwmgr) +
  127. sizeof(struct pp_power_state);
  128. hwmgr->ps = kzalloc(size * table_entries, GFP_KERNEL);
  129. if (hwmgr->ps == NULL)
  130. return -ENOMEM;
  131. hwmgr->request_ps = kzalloc(size, GFP_KERNEL);
  132. if (hwmgr->request_ps == NULL) {
  133. kfree(hwmgr->ps);
  134. hwmgr->ps = NULL;
  135. return -ENOMEM;
  136. }
  137. hwmgr->current_ps = kzalloc(size, GFP_KERNEL);
  138. if (hwmgr->current_ps == NULL) {
  139. kfree(hwmgr->request_ps);
  140. kfree(hwmgr->ps);
  141. hwmgr->request_ps = NULL;
  142. hwmgr->ps = NULL;
  143. return -ENOMEM;
  144. }
  145. state = hwmgr->ps;
  146. for (i = 0; i < table_entries; i++) {
  147. result = hwmgr->hwmgr_func->get_pp_table_entry(hwmgr, i, state);
  148. if (state->classification.flags & PP_StateClassificationFlag_Boot) {
  149. hwmgr->boot_ps = state;
  150. memcpy(hwmgr->current_ps, state, size);
  151. memcpy(hwmgr->request_ps, state, size);
  152. }
  153. state->id = i + 1; /* assigned unique num for every power state id */
  154. if (state->classification.flags & PP_StateClassificationFlag_Uvd)
  155. hwmgr->uvd_ps = state;
  156. state = (struct pp_power_state *)((unsigned long)state + size);
  157. }
  158. return 0;
  159. }
  160. static int hw_fini_power_state_table(struct pp_hwmgr *hwmgr)
  161. {
  162. if (hwmgr == NULL)
  163. return -EINVAL;
  164. kfree(hwmgr->current_ps);
  165. kfree(hwmgr->request_ps);
  166. kfree(hwmgr->ps);
  167. hwmgr->request_ps = NULL;
  168. hwmgr->ps = NULL;
  169. hwmgr->current_ps = NULL;
  170. return 0;
  171. }
  172. int hwmgr_hw_init(struct pp_instance *handle)
  173. {
  174. struct pp_hwmgr *hwmgr;
  175. int ret = 0;
  176. if (handle == NULL)
  177. return -EINVAL;
  178. hwmgr = handle->hwmgr;
  179. if (hwmgr->pptable_func == NULL ||
  180. hwmgr->pptable_func->pptable_init == NULL ||
  181. hwmgr->hwmgr_func->backend_init == NULL)
  182. return -EINVAL;
  183. ret = hwmgr->pptable_func->pptable_init(hwmgr);
  184. if (ret)
  185. goto err;
  186. ret = hwmgr->hwmgr_func->backend_init(hwmgr);
  187. if (ret)
  188. goto err1;
  189. ret = hw_init_power_state_table(hwmgr);
  190. if (ret)
  191. goto err2;
  192. return 0;
  193. err2:
  194. if (hwmgr->hwmgr_func->backend_fini)
  195. hwmgr->hwmgr_func->backend_fini(hwmgr);
  196. err1:
  197. if (hwmgr->pptable_func->pptable_fini)
  198. hwmgr->pptable_func->pptable_fini(hwmgr);
  199. err:
  200. pr_err("amdgpu: powerplay initialization failed\n");
  201. return ret;
  202. }
  203. int hwmgr_hw_fini(struct pp_instance *handle)
  204. {
  205. struct pp_hwmgr *hwmgr;
  206. if (handle == NULL)
  207. return -EINVAL;
  208. hwmgr = handle->hwmgr;
  209. if (hwmgr->hwmgr_func->backend_fini)
  210. hwmgr->hwmgr_func->backend_fini(hwmgr);
  211. if (hwmgr->pptable_func->pptable_fini)
  212. hwmgr->pptable_func->pptable_fini(hwmgr);
  213. return hw_fini_power_state_table(hwmgr);
  214. }
  215. /**
  216. * Returns once the part of the register indicated by the mask has
  217. * reached the given value.
  218. */
  219. int phm_wait_on_register(struct pp_hwmgr *hwmgr, uint32_t index,
  220. uint32_t value, uint32_t mask)
  221. {
  222. uint32_t i;
  223. uint32_t cur_value;
  224. if (hwmgr == NULL || hwmgr->device == NULL) {
  225. pr_err("Invalid Hardware Manager!");
  226. return -EINVAL;
  227. }
  228. for (i = 0; i < hwmgr->usec_timeout; i++) {
  229. cur_value = cgs_read_register(hwmgr->device, index);
  230. if ((cur_value & mask) == (value & mask))
  231. break;
  232. udelay(1);
  233. }
  234. /* timeout means wrong logic*/
  235. if (i == hwmgr->usec_timeout)
  236. return -1;
  237. return 0;
  238. }
  239. /**
  240. * Returns once the part of the register indicated by the mask has
  241. * reached the given value.The indirect space is described by giving
  242. * the memory-mapped index of the indirect index register.
  243. */
  244. void phm_wait_on_indirect_register(struct pp_hwmgr *hwmgr,
  245. uint32_t indirect_port,
  246. uint32_t index,
  247. uint32_t value,
  248. uint32_t mask)
  249. {
  250. if (hwmgr == NULL || hwmgr->device == NULL) {
  251. pr_err("Invalid Hardware Manager!");
  252. return;
  253. }
  254. cgs_write_register(hwmgr->device, indirect_port, index);
  255. phm_wait_on_register(hwmgr, indirect_port + 1, mask, value);
  256. }
  257. bool phm_cf_want_uvd_power_gating(struct pp_hwmgr *hwmgr)
  258. {
  259. return phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_UVDPowerGating);
  260. }
  261. bool phm_cf_want_vce_power_gating(struct pp_hwmgr *hwmgr)
  262. {
  263. return phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_VCEPowerGating);
  264. }
  265. int phm_trim_voltage_table(struct pp_atomctrl_voltage_table *vol_table)
  266. {
  267. uint32_t i, j;
  268. uint16_t vvalue;
  269. bool found = false;
  270. struct pp_atomctrl_voltage_table *table;
  271. PP_ASSERT_WITH_CODE((NULL != vol_table),
  272. "Voltage Table empty.", return -EINVAL);
  273. table = kzalloc(sizeof(struct pp_atomctrl_voltage_table),
  274. GFP_KERNEL);
  275. if (NULL == table)
  276. return -EINVAL;
  277. table->mask_low = vol_table->mask_low;
  278. table->phase_delay = vol_table->phase_delay;
  279. for (i = 0; i < vol_table->count; i++) {
  280. vvalue = vol_table->entries[i].value;
  281. found = false;
  282. for (j = 0; j < table->count; j++) {
  283. if (vvalue == table->entries[j].value) {
  284. found = true;
  285. break;
  286. }
  287. }
  288. if (!found) {
  289. table->entries[table->count].value = vvalue;
  290. table->entries[table->count].smio_low =
  291. vol_table->entries[i].smio_low;
  292. table->count++;
  293. }
  294. }
  295. memcpy(vol_table, table, sizeof(struct pp_atomctrl_voltage_table));
  296. kfree(table);
  297. table = NULL;
  298. return 0;
  299. }
  300. int phm_get_svi2_mvdd_voltage_table(struct pp_atomctrl_voltage_table *vol_table,
  301. phm_ppt_v1_clock_voltage_dependency_table *dep_table)
  302. {
  303. uint32_t i;
  304. int result;
  305. PP_ASSERT_WITH_CODE((0 != dep_table->count),
  306. "Voltage Dependency Table empty.", return -EINVAL);
  307. PP_ASSERT_WITH_CODE((NULL != vol_table),
  308. "vol_table empty.", return -EINVAL);
  309. vol_table->mask_low = 0;
  310. vol_table->phase_delay = 0;
  311. vol_table->count = dep_table->count;
  312. for (i = 0; i < dep_table->count; i++) {
  313. vol_table->entries[i].value = dep_table->entries[i].mvdd;
  314. vol_table->entries[i].smio_low = 0;
  315. }
  316. result = phm_trim_voltage_table(vol_table);
  317. PP_ASSERT_WITH_CODE((0 == result),
  318. "Failed to trim MVDD table.", return result);
  319. return 0;
  320. }
  321. int phm_get_svi2_vddci_voltage_table(struct pp_atomctrl_voltage_table *vol_table,
  322. phm_ppt_v1_clock_voltage_dependency_table *dep_table)
  323. {
  324. uint32_t i;
  325. int result;
  326. PP_ASSERT_WITH_CODE((0 != dep_table->count),
  327. "Voltage Dependency Table empty.", return -EINVAL);
  328. PP_ASSERT_WITH_CODE((NULL != vol_table),
  329. "vol_table empty.", return -EINVAL);
  330. vol_table->mask_low = 0;
  331. vol_table->phase_delay = 0;
  332. vol_table->count = dep_table->count;
  333. for (i = 0; i < dep_table->count; i++) {
  334. vol_table->entries[i].value = dep_table->entries[i].vddci;
  335. vol_table->entries[i].smio_low = 0;
  336. }
  337. result = phm_trim_voltage_table(vol_table);
  338. PP_ASSERT_WITH_CODE((0 == result),
  339. "Failed to trim VDDCI table.", return result);
  340. return 0;
  341. }
  342. int phm_get_svi2_vdd_voltage_table(struct pp_atomctrl_voltage_table *vol_table,
  343. phm_ppt_v1_voltage_lookup_table *lookup_table)
  344. {
  345. int i = 0;
  346. PP_ASSERT_WITH_CODE((0 != lookup_table->count),
  347. "Voltage Lookup Table empty.", return -EINVAL);
  348. PP_ASSERT_WITH_CODE((NULL != vol_table),
  349. "vol_table empty.", return -EINVAL);
  350. vol_table->mask_low = 0;
  351. vol_table->phase_delay = 0;
  352. vol_table->count = lookup_table->count;
  353. for (i = 0; i < vol_table->count; i++) {
  354. vol_table->entries[i].value = lookup_table->entries[i].us_vdd;
  355. vol_table->entries[i].smio_low = 0;
  356. }
  357. return 0;
  358. }
  359. void phm_trim_voltage_table_to_fit_state_table(uint32_t max_vol_steps,
  360. struct pp_atomctrl_voltage_table *vol_table)
  361. {
  362. unsigned int i, diff;
  363. if (vol_table->count <= max_vol_steps)
  364. return;
  365. diff = vol_table->count - max_vol_steps;
  366. for (i = 0; i < max_vol_steps; i++)
  367. vol_table->entries[i] = vol_table->entries[i + diff];
  368. vol_table->count = max_vol_steps;
  369. return;
  370. }
  371. int phm_reset_single_dpm_table(void *table,
  372. uint32_t count, int max)
  373. {
  374. int i;
  375. struct vi_dpm_table *dpm_table = (struct vi_dpm_table *)table;
  376. dpm_table->count = count > max ? max : count;
  377. for (i = 0; i < dpm_table->count; i++)
  378. dpm_table->dpm_level[i].enabled = false;
  379. return 0;
  380. }
  381. void phm_setup_pcie_table_entry(
  382. void *table,
  383. uint32_t index, uint32_t pcie_gen,
  384. uint32_t pcie_lanes)
  385. {
  386. struct vi_dpm_table *dpm_table = (struct vi_dpm_table *)table;
  387. dpm_table->dpm_level[index].value = pcie_gen;
  388. dpm_table->dpm_level[index].param1 = pcie_lanes;
  389. dpm_table->dpm_level[index].enabled = 1;
  390. }
  391. int32_t phm_get_dpm_level_enable_mask_value(void *table)
  392. {
  393. int32_t i;
  394. int32_t mask = 0;
  395. struct vi_dpm_table *dpm_table = (struct vi_dpm_table *)table;
  396. for (i = dpm_table->count; i > 0; i--) {
  397. mask = mask << 1;
  398. if (dpm_table->dpm_level[i - 1].enabled)
  399. mask |= 0x1;
  400. else
  401. mask &= 0xFFFFFFFE;
  402. }
  403. return mask;
  404. }
  405. uint8_t phm_get_voltage_index(
  406. struct phm_ppt_v1_voltage_lookup_table *lookup_table, uint16_t voltage)
  407. {
  408. uint8_t count = (uint8_t) (lookup_table->count);
  409. uint8_t i;
  410. PP_ASSERT_WITH_CODE((NULL != lookup_table),
  411. "Lookup Table empty.", return 0);
  412. PP_ASSERT_WITH_CODE((0 != count),
  413. "Lookup Table empty.", return 0);
  414. for (i = 0; i < lookup_table->count; i++) {
  415. /* find first voltage equal or bigger than requested */
  416. if (lookup_table->entries[i].us_vdd >= voltage)
  417. return i;
  418. }
  419. /* voltage is bigger than max voltage in the table */
  420. return i - 1;
  421. }
  422. uint8_t phm_get_voltage_id(pp_atomctrl_voltage_table *voltage_table,
  423. uint32_t voltage)
  424. {
  425. uint8_t count = (uint8_t) (voltage_table->count);
  426. uint8_t i = 0;
  427. PP_ASSERT_WITH_CODE((NULL != voltage_table),
  428. "Voltage Table empty.", return 0;);
  429. PP_ASSERT_WITH_CODE((0 != count),
  430. "Voltage Table empty.", return 0;);
  431. for (i = 0; i < count; i++) {
  432. /* find first voltage bigger than requested */
  433. if (voltage_table->entries[i].value >= voltage)
  434. return i;
  435. }
  436. /* voltage is bigger than max voltage in the table */
  437. return i - 1;
  438. }
  439. uint16_t phm_find_closest_vddci(struct pp_atomctrl_voltage_table *vddci_table, uint16_t vddci)
  440. {
  441. uint32_t i;
  442. for (i = 0; i < vddci_table->count; i++) {
  443. if (vddci_table->entries[i].value >= vddci)
  444. return vddci_table->entries[i].value;
  445. }
  446. PP_ASSERT_WITH_CODE(false,
  447. "VDDCI is larger than max VDDCI in VDDCI Voltage Table!",
  448. return vddci_table->entries[i-1].value);
  449. }
  450. int phm_find_boot_level(void *table,
  451. uint32_t value, uint32_t *boot_level)
  452. {
  453. int result = -EINVAL;
  454. uint32_t i;
  455. struct vi_dpm_table *dpm_table = (struct vi_dpm_table *)table;
  456. for (i = 0; i < dpm_table->count; i++) {
  457. if (value == dpm_table->dpm_level[i].value) {
  458. *boot_level = i;
  459. result = 0;
  460. }
  461. }
  462. return result;
  463. }
  464. int phm_get_sclk_for_voltage_evv(struct pp_hwmgr *hwmgr,
  465. phm_ppt_v1_voltage_lookup_table *lookup_table,
  466. uint16_t virtual_voltage_id, int32_t *sclk)
  467. {
  468. uint8_t entryId;
  469. uint8_t voltageId;
  470. struct phm_ppt_v1_information *table_info =
  471. (struct phm_ppt_v1_information *)(hwmgr->pptable);
  472. PP_ASSERT_WITH_CODE(lookup_table->count != 0, "Lookup table is empty", return -EINVAL);
  473. /* search for leakage voltage ID 0xff01 ~ 0xff08 and sckl */
  474. for (entryId = 0; entryId < table_info->vdd_dep_on_sclk->count; entryId++) {
  475. voltageId = table_info->vdd_dep_on_sclk->entries[entryId].vddInd;
  476. if (lookup_table->entries[voltageId].us_vdd == virtual_voltage_id)
  477. break;
  478. }
  479. PP_ASSERT_WITH_CODE(entryId < table_info->vdd_dep_on_sclk->count,
  480. "Can't find requested voltage id in vdd_dep_on_sclk table!",
  481. return -EINVAL;
  482. );
  483. *sclk = table_info->vdd_dep_on_sclk->entries[entryId].clk;
  484. return 0;
  485. }
  486. /**
  487. * Initialize Dynamic State Adjustment Rule Settings
  488. *
  489. * @param hwmgr the address of the powerplay hardware manager.
  490. */
  491. int phm_initializa_dynamic_state_adjustment_rule_settings(struct pp_hwmgr *hwmgr)
  492. {
  493. uint32_t table_size;
  494. struct phm_clock_voltage_dependency_table *table_clk_vlt;
  495. struct phm_ppt_v1_information *pptable_info = (struct phm_ppt_v1_information *)(hwmgr->pptable);
  496. /* initialize vddc_dep_on_dal_pwrl table */
  497. table_size = sizeof(uint32_t) + 4 * sizeof(struct phm_clock_voltage_dependency_record);
  498. table_clk_vlt = kzalloc(table_size, GFP_KERNEL);
  499. if (NULL == table_clk_vlt) {
  500. pr_err("Can not allocate space for vddc_dep_on_dal_pwrl! \n");
  501. return -ENOMEM;
  502. } else {
  503. table_clk_vlt->count = 4;
  504. table_clk_vlt->entries[0].clk = PP_DAL_POWERLEVEL_ULTRALOW;
  505. table_clk_vlt->entries[0].v = 0;
  506. table_clk_vlt->entries[1].clk = PP_DAL_POWERLEVEL_LOW;
  507. table_clk_vlt->entries[1].v = 720;
  508. table_clk_vlt->entries[2].clk = PP_DAL_POWERLEVEL_NOMINAL;
  509. table_clk_vlt->entries[2].v = 810;
  510. table_clk_vlt->entries[3].clk = PP_DAL_POWERLEVEL_PERFORMANCE;
  511. table_clk_vlt->entries[3].v = 900;
  512. if (pptable_info != NULL)
  513. pptable_info->vddc_dep_on_dal_pwrl = table_clk_vlt;
  514. hwmgr->dyn_state.vddc_dep_on_dal_pwrl = table_clk_vlt;
  515. }
  516. return 0;
  517. }
  518. uint32_t phm_get_lowest_enabled_level(struct pp_hwmgr *hwmgr, uint32_t mask)
  519. {
  520. uint32_t level = 0;
  521. while (0 == (mask & (1 << level)))
  522. level++;
  523. return level;
  524. }
  525. void phm_apply_dal_min_voltage_request(struct pp_hwmgr *hwmgr)
  526. {
  527. struct phm_ppt_v1_information *table_info =
  528. (struct phm_ppt_v1_information *)hwmgr->pptable;
  529. struct phm_clock_voltage_dependency_table *table =
  530. table_info->vddc_dep_on_dal_pwrl;
  531. struct phm_ppt_v1_clock_voltage_dependency_table *vddc_table;
  532. enum PP_DAL_POWERLEVEL dal_power_level = hwmgr->dal_power_level;
  533. uint32_t req_vddc = 0, req_volt, i;
  534. if (!table || table->count <= 0
  535. || dal_power_level < PP_DAL_POWERLEVEL_ULTRALOW
  536. || dal_power_level > PP_DAL_POWERLEVEL_PERFORMANCE)
  537. return;
  538. for (i = 0; i < table->count; i++) {
  539. if (dal_power_level == table->entries[i].clk) {
  540. req_vddc = table->entries[i].v;
  541. break;
  542. }
  543. }
  544. vddc_table = table_info->vdd_dep_on_sclk;
  545. for (i = 0; i < vddc_table->count; i++) {
  546. if (req_vddc <= vddc_table->entries[i].vddc) {
  547. req_volt = (((uint32_t)vddc_table->entries[i].vddc) * VOLTAGE_SCALE);
  548. smum_send_msg_to_smc_with_parameter(hwmgr->smumgr,
  549. PPSMC_MSG_VddC_Request, req_volt);
  550. return;
  551. }
  552. }
  553. pr_err("DAL requested level can not"
  554. " found a available voltage in VDDC DPM Table \n");
  555. }
  556. void hwmgr_init_default_caps(struct pp_hwmgr *hwmgr)
  557. {
  558. phm_cap_unset(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_DisableVoltageTransition);
  559. phm_cap_unset(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_DisableEngineTransition);
  560. phm_cap_unset(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_DisableMemoryTransition);
  561. phm_cap_unset(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_DisableMGClockGating);
  562. phm_cap_unset(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_DisableMGCGTSSM);
  563. phm_cap_unset(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_DisableLSClockGating);
  564. phm_cap_unset(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_Force3DClockSupport);
  565. phm_cap_unset(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_DisableLightSleep);
  566. phm_cap_unset(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_DisableMCLS);
  567. phm_cap_set(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_DisablePowerGating);
  568. phm_cap_unset(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_DisableDPM);
  569. phm_cap_unset(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_DisableSMUUVDHandshake);
  570. phm_cap_unset(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_ThermalAutoThrottling);
  571. phm_cap_unset(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_PCIEPerformanceRequest);
  572. phm_cap_unset(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_NoOD5Support);
  573. phm_cap_unset(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_UserMaxClockForMultiDisplays);
  574. phm_cap_unset(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_VpuRecoveryInProgress);
  575. phm_cap_set(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_UVDDPM);
  576. phm_cap_set(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_VCEDPM);
  577. if (acpi_atcs_functions_supported(hwmgr->device, ATCS_FUNCTION_PCIE_PERFORMANCE_REQUEST) &&
  578. acpi_atcs_functions_supported(hwmgr->device, ATCS_FUNCTION_PCIE_DEVICE_READY_NOTIFICATION))
  579. phm_cap_set(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_PCIEPerformanceRequest);
  580. phm_cap_set(hwmgr->platform_descriptor.platformCaps,
  581. PHM_PlatformCaps_DynamicPatchPowerState);
  582. phm_cap_set(hwmgr->platform_descriptor.platformCaps,
  583. PHM_PlatformCaps_EnableSMU7ThermalManagement);
  584. phm_cap_set(hwmgr->platform_descriptor.platformCaps,
  585. PHM_PlatformCaps_DynamicPowerManagement);
  586. phm_cap_set(hwmgr->platform_descriptor.platformCaps,
  587. PHM_PlatformCaps_SMC);
  588. phm_cap_set(hwmgr->platform_descriptor.platformCaps,
  589. PHM_PlatformCaps_DynamicUVDState);
  590. phm_cap_set(hwmgr->platform_descriptor.platformCaps,
  591. PHM_PlatformCaps_FanSpeedInTableIsRPM);
  592. return;
  593. }
  594. int hwmgr_set_user_specify_caps(struct pp_hwmgr *hwmgr)
  595. {
  596. if (hwmgr->feature_mask & PP_SCLK_DEEP_SLEEP_MASK)
  597. phm_cap_set(hwmgr->platform_descriptor.platformCaps,
  598. PHM_PlatformCaps_SclkDeepSleep);
  599. else
  600. phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
  601. PHM_PlatformCaps_SclkDeepSleep);
  602. if (hwmgr->feature_mask & PP_POWER_CONTAINMENT_MASK) {
  603. phm_cap_set(hwmgr->platform_descriptor.platformCaps,
  604. PHM_PlatformCaps_PowerContainment);
  605. phm_cap_set(hwmgr->platform_descriptor.platformCaps,
  606. PHM_PlatformCaps_CAC);
  607. } else {
  608. phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
  609. PHM_PlatformCaps_PowerContainment);
  610. phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
  611. PHM_PlatformCaps_CAC);
  612. }
  613. return 0;
  614. }
  615. int phm_get_voltage_evv_on_sclk(struct pp_hwmgr *hwmgr, uint8_t voltage_type,
  616. uint32_t sclk, uint16_t id, uint16_t *voltage)
  617. {
  618. uint32_t vol;
  619. int ret = 0;
  620. if (hwmgr->chip_id < CHIP_TONGA) {
  621. ret = atomctrl_get_voltage_evv(hwmgr, id, voltage);
  622. } else if (hwmgr->chip_id < CHIP_POLARIS10) {
  623. ret = atomctrl_get_voltage_evv_on_sclk(hwmgr, voltage_type, sclk, id, voltage);
  624. if (*voltage >= 2000 || *voltage == 0)
  625. *voltage = 1150;
  626. } else {
  627. ret = atomctrl_get_voltage_evv_on_sclk_ai(hwmgr, voltage_type, sclk, id, &vol);
  628. *voltage = (uint16_t)(vol/100);
  629. }
  630. return ret;
  631. }
  632. int polaris_set_asic_special_caps(struct pp_hwmgr *hwmgr)
  633. {
  634. phm_cap_set(hwmgr->platform_descriptor.platformCaps,
  635. PHM_PlatformCaps_SQRamping);
  636. phm_cap_set(hwmgr->platform_descriptor.platformCaps,
  637. PHM_PlatformCaps_RegulatorHot);
  638. phm_cap_set(hwmgr->platform_descriptor.platformCaps,
  639. PHM_PlatformCaps_AutomaticDCTransition);
  640. phm_cap_set(hwmgr->platform_descriptor.platformCaps,
  641. PHM_PlatformCaps_TablelessHardwareInterface);
  642. if (hwmgr->chip_id != CHIP_POLARIS10)
  643. phm_cap_set(hwmgr->platform_descriptor.platformCaps,
  644. PHM_PlatformCaps_SPLLShutdownSupport);
  645. if (hwmgr->chip_id != CHIP_POLARIS11) {
  646. phm_cap_set(hwmgr->platform_descriptor.platformCaps,
  647. PHM_PlatformCaps_DBRamping);
  648. phm_cap_set(hwmgr->platform_descriptor.platformCaps,
  649. PHM_PlatformCaps_TDRamping);
  650. phm_cap_set(hwmgr->platform_descriptor.platformCaps,
  651. PHM_PlatformCaps_TCPRamping);
  652. }
  653. return 0;
  654. }
  655. int fiji_set_asic_special_caps(struct pp_hwmgr *hwmgr)
  656. {
  657. phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
  658. PHM_PlatformCaps_SQRamping);
  659. phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
  660. PHM_PlatformCaps_DBRamping);
  661. phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
  662. PHM_PlatformCaps_TDRamping);
  663. phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
  664. PHM_PlatformCaps_TCPRamping);
  665. phm_cap_set(hwmgr->platform_descriptor.platformCaps,
  666. PHM_PlatformCaps_TablelessHardwareInterface);
  667. return 0;
  668. }
  669. int tonga_set_asic_special_caps(struct pp_hwmgr *hwmgr)
  670. {
  671. phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
  672. PHM_PlatformCaps_SQRamping);
  673. phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
  674. PHM_PlatformCaps_DBRamping);
  675. phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
  676. PHM_PlatformCaps_TDRamping);
  677. phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
  678. PHM_PlatformCaps_TCPRamping);
  679. phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
  680. PHM_PlatformCaps_UVDPowerGating);
  681. phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
  682. PHM_PlatformCaps_VCEPowerGating);
  683. phm_cap_set(hwmgr->platform_descriptor.platformCaps,
  684. PHM_PlatformCaps_TablelessHardwareInterface);
  685. return 0;
  686. }
  687. int topaz_set_asic_special_caps(struct pp_hwmgr *hwmgr)
  688. {
  689. phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
  690. PHM_PlatformCaps_SQRamping);
  691. phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
  692. PHM_PlatformCaps_DBRamping);
  693. phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
  694. PHM_PlatformCaps_TDRamping);
  695. phm_cap_unset(hwmgr->platform_descriptor.platformCaps,
  696. PHM_PlatformCaps_TCPRamping);
  697. phm_cap_set(hwmgr->platform_descriptor.platformCaps,
  698. PHM_PlatformCaps_TablelessHardwareInterface);
  699. phm_cap_set(hwmgr->platform_descriptor.platformCaps,
  700. PHM_PlatformCaps_EVV);
  701. return 0;
  702. }