hwmgr.c 24 KB

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