ppatomfwctrl.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  1. /*
  2. * Copyright 2016 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 "ppatomfwctrl.h"
  24. #include "atomfirmware.h"
  25. #include "pp_debug.h"
  26. static const union atom_voltage_object_v4 *pp_atomfwctrl_lookup_voltage_type_v4(
  27. const struct atom_voltage_objects_info_v4_1 *voltage_object_info_table,
  28. uint8_t voltage_type, uint8_t voltage_mode)
  29. {
  30. unsigned int size = le16_to_cpu(
  31. voltage_object_info_table->table_header.structuresize);
  32. unsigned int offset =
  33. offsetof(struct atom_voltage_objects_info_v4_1, voltage_object[0]);
  34. unsigned long start = (unsigned long)voltage_object_info_table;
  35. while (offset < size) {
  36. const union atom_voltage_object_v4 *voltage_object =
  37. (const union atom_voltage_object_v4 *)(start + offset);
  38. if (voltage_type == voltage_object->gpio_voltage_obj.header.voltage_type &&
  39. voltage_mode == voltage_object->gpio_voltage_obj.header.voltage_mode)
  40. return voltage_object;
  41. offset += le16_to_cpu(voltage_object->gpio_voltage_obj.header.object_size);
  42. }
  43. return NULL;
  44. }
  45. static struct atom_voltage_objects_info_v4_1 *pp_atomfwctrl_get_voltage_info_table(
  46. struct pp_hwmgr *hwmgr)
  47. {
  48. const void *table_address;
  49. uint16_t idx;
  50. idx = GetIndexIntoMasterDataTable(voltageobject_info);
  51. table_address = cgs_atom_get_data_table(hwmgr->device,
  52. idx, NULL, NULL, NULL);
  53. PP_ASSERT_WITH_CODE(
  54. table_address,
  55. "Error retrieving BIOS Table Address!",
  56. return NULL);
  57. return (struct atom_voltage_objects_info_v4_1 *)table_address;
  58. }
  59. /**
  60. * Returns TRUE if the given voltage type is controlled by GPIO pins.
  61. * voltage_type is one of SET_VOLTAGE_TYPE_ASIC_VDDC, SET_VOLTAGE_TYPE_ASIC_MVDDC, SET_VOLTAGE_TYPE_ASIC_MVDDQ.
  62. * voltage_mode is one of ATOM_SET_VOLTAGE, ATOM_SET_VOLTAGE_PHASE
  63. */
  64. bool pp_atomfwctrl_is_voltage_controlled_by_gpio_v4(struct pp_hwmgr *hwmgr,
  65. uint8_t voltage_type, uint8_t voltage_mode)
  66. {
  67. struct atom_voltage_objects_info_v4_1 *voltage_info =
  68. (struct atom_voltage_objects_info_v4_1 *)
  69. pp_atomfwctrl_get_voltage_info_table(hwmgr);
  70. bool ret;
  71. /* If we cannot find the table do NOT try to control this voltage. */
  72. PP_ASSERT_WITH_CODE(voltage_info,
  73. "Could not find Voltage Table in BIOS.",
  74. return false);
  75. ret = (pp_atomfwctrl_lookup_voltage_type_v4(voltage_info,
  76. voltage_type, voltage_mode)) ? true : false;
  77. return ret;
  78. }
  79. int pp_atomfwctrl_get_voltage_table_v4(struct pp_hwmgr *hwmgr,
  80. uint8_t voltage_type, uint8_t voltage_mode,
  81. struct pp_atomfwctrl_voltage_table *voltage_table)
  82. {
  83. struct atom_voltage_objects_info_v4_1 *voltage_info =
  84. (struct atom_voltage_objects_info_v4_1 *)
  85. pp_atomfwctrl_get_voltage_info_table(hwmgr);
  86. const union atom_voltage_object_v4 *voltage_object;
  87. unsigned int i;
  88. int result = 0;
  89. PP_ASSERT_WITH_CODE(voltage_info,
  90. "Could not find Voltage Table in BIOS.",
  91. return -1);
  92. voltage_object = pp_atomfwctrl_lookup_voltage_type_v4(voltage_info,
  93. voltage_type, voltage_mode);
  94. if (!voltage_object)
  95. return -1;
  96. voltage_table->count = 0;
  97. if (voltage_mode == VOLTAGE_OBJ_GPIO_LUT) {
  98. PP_ASSERT_WITH_CODE(
  99. (voltage_object->gpio_voltage_obj.gpio_entry_num <=
  100. PP_ATOMFWCTRL_MAX_VOLTAGE_ENTRIES),
  101. "Too many voltage entries!",
  102. result = -1);
  103. if (!result) {
  104. for (i = 0; i < voltage_object->gpio_voltage_obj.
  105. gpio_entry_num; i++) {
  106. voltage_table->entries[i].value =
  107. le16_to_cpu(voltage_object->gpio_voltage_obj.
  108. voltage_gpio_lut[i].voltage_level_mv);
  109. voltage_table->entries[i].smio_low =
  110. le32_to_cpu(voltage_object->gpio_voltage_obj.
  111. voltage_gpio_lut[i].voltage_gpio_reg_val);
  112. }
  113. voltage_table->count =
  114. voltage_object->gpio_voltage_obj.gpio_entry_num;
  115. voltage_table->mask_low =
  116. le32_to_cpu(
  117. voltage_object->gpio_voltage_obj.gpio_mask_val);
  118. voltage_table->phase_delay =
  119. voltage_object->gpio_voltage_obj.phase_delay_us;
  120. }
  121. } else if (voltage_mode == VOLTAGE_OBJ_SVID2) {
  122. voltage_table->psi1_enable =
  123. voltage_object->svid2_voltage_obj.loadline_psi1 & 0x1;
  124. voltage_table->psi0_enable =
  125. voltage_object->svid2_voltage_obj.psi0_enable & 0x1;
  126. voltage_table->max_vid_step =
  127. voltage_object->svid2_voltage_obj.maxvstep;
  128. voltage_table->telemetry_offset =
  129. voltage_object->svid2_voltage_obj.telemetry_offset;
  130. voltage_table->telemetry_slope =
  131. voltage_object->svid2_voltage_obj.telemetry_gain;
  132. } else
  133. PP_ASSERT_WITH_CODE(false,
  134. "Unsupported Voltage Object Mode!",
  135. result = -1);
  136. return result;
  137. }
  138. static struct atom_gpio_pin_lut_v2_1 *pp_atomfwctrl_get_gpio_lookup_table(
  139. struct pp_hwmgr *hwmgr)
  140. {
  141. const void *table_address;
  142. uint16_t idx;
  143. idx = GetIndexIntoMasterDataTable(gpio_pin_lut);
  144. table_address = cgs_atom_get_data_table(hwmgr->device,
  145. idx, NULL, NULL, NULL);
  146. PP_ASSERT_WITH_CODE(table_address,
  147. "Error retrieving BIOS Table Address!",
  148. return NULL);
  149. return (struct atom_gpio_pin_lut_v2_1 *)table_address;
  150. }
  151. static bool pp_atomfwctrl_lookup_gpio_pin(
  152. struct atom_gpio_pin_lut_v2_1 *gpio_lookup_table,
  153. const uint32_t pin_id,
  154. struct pp_atomfwctrl_gpio_pin_assignment *gpio_pin_assignment)
  155. {
  156. unsigned int size = le16_to_cpu(
  157. gpio_lookup_table->table_header.structuresize);
  158. unsigned int offset =
  159. offsetof(struct atom_gpio_pin_lut_v2_1, gpio_pin[0]);
  160. unsigned long start = (unsigned long)gpio_lookup_table;
  161. while (offset < size) {
  162. const struct atom_gpio_pin_assignment *pin_assignment =
  163. (const struct atom_gpio_pin_assignment *)(start + offset);
  164. if (pin_id == pin_assignment->gpio_id) {
  165. gpio_pin_assignment->uc_gpio_pin_bit_shift =
  166. pin_assignment->gpio_bitshift;
  167. gpio_pin_assignment->us_gpio_pin_aindex =
  168. le16_to_cpu(pin_assignment->data_a_reg_index);
  169. return true;
  170. }
  171. offset += offsetof(struct atom_gpio_pin_assignment, gpio_id) + 1;
  172. }
  173. return false;
  174. }
  175. /**
  176. * Returns TRUE if the given pin id find in lookup table.
  177. */
  178. bool pp_atomfwctrl_get_pp_assign_pin(struct pp_hwmgr *hwmgr,
  179. const uint32_t pin_id,
  180. struct pp_atomfwctrl_gpio_pin_assignment *gpio_pin_assignment)
  181. {
  182. bool ret = false;
  183. struct atom_gpio_pin_lut_v2_1 *gpio_lookup_table =
  184. pp_atomfwctrl_get_gpio_lookup_table(hwmgr);
  185. /* If we cannot find the table do NOT try to control this voltage. */
  186. PP_ASSERT_WITH_CODE(gpio_lookup_table,
  187. "Could not find GPIO lookup Table in BIOS.",
  188. return false);
  189. ret = pp_atomfwctrl_lookup_gpio_pin(gpio_lookup_table,
  190. pin_id, gpio_pin_assignment);
  191. return ret;
  192. }
  193. /**
  194. * Enter to SelfRefresh mode.
  195. * @param hwmgr
  196. */
  197. int pp_atomfwctrl_enter_self_refresh(struct pp_hwmgr *hwmgr)
  198. {
  199. /* 0 - no action
  200. * 1 - leave power to video memory always on
  201. */
  202. return 0;
  203. }
  204. /** pp_atomfwctrl_get_gpu_pll_dividers_vega10().
  205. *
  206. * @param hwmgr input parameter: pointer to HwMgr
  207. * @param clock_type input parameter: Clock type: 1 - GFXCLK, 2 - UCLK, 0 - All other clocks
  208. * @param clock_value input parameter: Clock
  209. * @param dividers output parameter:Clock dividers
  210. */
  211. int pp_atomfwctrl_get_gpu_pll_dividers_vega10(struct pp_hwmgr *hwmgr,
  212. uint32_t clock_type, uint32_t clock_value,
  213. struct pp_atomfwctrl_clock_dividers_soc15 *dividers)
  214. {
  215. struct compute_gpu_clock_input_parameter_v1_8 pll_parameters;
  216. struct compute_gpu_clock_output_parameter_v1_8 *pll_output;
  217. int result;
  218. uint32_t idx;
  219. pll_parameters.gpuclock_10khz = (uint32_t)clock_value;
  220. pll_parameters.gpu_clock_type = clock_type;
  221. idx = GetIndexIntoMasterCmdTable(computegpuclockparam);
  222. result = cgs_atom_exec_cmd_table(hwmgr->device, idx, &pll_parameters);
  223. if (!result) {
  224. pll_output = (struct compute_gpu_clock_output_parameter_v1_8 *)
  225. &pll_parameters;
  226. dividers->ulClock = le32_to_cpu(pll_output->gpuclock_10khz);
  227. dividers->ulDid = le32_to_cpu(pll_output->dfs_did);
  228. dividers->ulPll_fb_mult = le32_to_cpu(pll_output->pll_fb_mult);
  229. dividers->ulPll_ss_fbsmult = le32_to_cpu(pll_output->pll_ss_fbsmult);
  230. dividers->usPll_ss_slew_frac = le16_to_cpu(pll_output->pll_ss_slew_frac);
  231. dividers->ucPll_ss_enable = pll_output->pll_ss_enable;
  232. }
  233. return result;
  234. }
  235. int pp_atomfwctrl_get_avfs_information(struct pp_hwmgr *hwmgr,
  236. struct pp_atomfwctrl_avfs_parameters *param)
  237. {
  238. uint16_t idx;
  239. struct atom_asic_profiling_info_v4_1 *profile;
  240. idx = GetIndexIntoMasterDataTable(asic_profiling_info);
  241. profile = (struct atom_asic_profiling_info_v4_1 *)
  242. cgs_atom_get_data_table(hwmgr->device,
  243. idx, NULL, NULL, NULL);
  244. if (!profile)
  245. return -1;
  246. param->ulMaxVddc = le32_to_cpu(profile->maxvddc);
  247. param->ulMinVddc = le32_to_cpu(profile->minvddc);
  248. param->ulMeanNsigmaAcontant0 =
  249. le32_to_cpu(profile->avfs_meannsigma_acontant0);
  250. param->ulMeanNsigmaAcontant1 =
  251. le32_to_cpu(profile->avfs_meannsigma_acontant1);
  252. param->ulMeanNsigmaAcontant2 =
  253. le32_to_cpu(profile->avfs_meannsigma_acontant2);
  254. param->usMeanNsigmaDcTolSigma =
  255. le16_to_cpu(profile->avfs_meannsigma_dc_tol_sigma);
  256. param->usMeanNsigmaPlatformMean =
  257. le16_to_cpu(profile->avfs_meannsigma_platform_mean);
  258. param->usMeanNsigmaPlatformSigma =
  259. le16_to_cpu(profile->avfs_meannsigma_platform_sigma);
  260. param->ulGbVdroopTableCksoffA0 =
  261. le32_to_cpu(profile->gb_vdroop_table_cksoff_a0);
  262. param->ulGbVdroopTableCksoffA1 =
  263. le32_to_cpu(profile->gb_vdroop_table_cksoff_a1);
  264. param->ulGbVdroopTableCksoffA2 =
  265. le32_to_cpu(profile->gb_vdroop_table_cksoff_a2);
  266. param->ulGbVdroopTableCksonA0 =
  267. le32_to_cpu(profile->gb_vdroop_table_ckson_a0);
  268. param->ulGbVdroopTableCksonA1 =
  269. le32_to_cpu(profile->gb_vdroop_table_ckson_a1);
  270. param->ulGbVdroopTableCksonA2 =
  271. le32_to_cpu(profile->gb_vdroop_table_ckson_a2);
  272. param->ulGbFuseTableCksoffM1 =
  273. le32_to_cpu(profile->avfsgb_fuse_table_cksoff_m1);
  274. param->ulGbFuseTableCksoffM2 =
  275. le16_to_cpu(profile->avfsgb_fuse_table_cksoff_m2);
  276. param->ulGbFuseTableCksoffB =
  277. le32_to_cpu(profile->avfsgb_fuse_table_cksoff_b);
  278. param->ulGbFuseTableCksonM1 =
  279. le32_to_cpu(profile->avfsgb_fuse_table_ckson_m1);
  280. param->ulGbFuseTableCksonM2 =
  281. le16_to_cpu(profile->avfsgb_fuse_table_ckson_m2);
  282. param->ulGbFuseTableCksonB =
  283. le32_to_cpu(profile->avfsgb_fuse_table_ckson_b);
  284. param->ucEnableGbVdroopTableCkson =
  285. profile->enable_gb_vdroop_table_ckson;
  286. param->ucEnableGbFuseTableCkson =
  287. profile->enable_gb_fuse_table_ckson;
  288. param->usPsmAgeComfactor =
  289. le16_to_cpu(profile->psm_age_comfactor);
  290. param->ulDispclk2GfxclkM1 =
  291. le32_to_cpu(profile->dispclk2gfxclk_a);
  292. param->ulDispclk2GfxclkM2 =
  293. le16_to_cpu(profile->dispclk2gfxclk_b);
  294. param->ulDispclk2GfxclkB =
  295. le32_to_cpu(profile->dispclk2gfxclk_c);
  296. param->ulDcefclk2GfxclkM1 =
  297. le32_to_cpu(profile->dcefclk2gfxclk_a);
  298. param->ulDcefclk2GfxclkM2 =
  299. le16_to_cpu(profile->dcefclk2gfxclk_b);
  300. param->ulDcefclk2GfxclkB =
  301. le32_to_cpu(profile->dcefclk2gfxclk_c);
  302. param->ulPixelclk2GfxclkM1 =
  303. le32_to_cpu(profile->pixclk2gfxclk_a);
  304. param->ulPixelclk2GfxclkM2 =
  305. le16_to_cpu(profile->pixclk2gfxclk_b);
  306. param->ulPixelclk2GfxclkB =
  307. le32_to_cpu(profile->pixclk2gfxclk_c);
  308. param->ulPhyclk2GfxclkM1 =
  309. le32_to_cpu(profile->phyclk2gfxclk_a);
  310. param->ulPhyclk2GfxclkM2 =
  311. le16_to_cpu(profile->phyclk2gfxclk_b);
  312. param->ulPhyclk2GfxclkB =
  313. le32_to_cpu(profile->phyclk2gfxclk_c);
  314. return 0;
  315. }
  316. int pp_atomfwctrl_get_gpio_information(struct pp_hwmgr *hwmgr,
  317. struct pp_atomfwctrl_gpio_parameters *param)
  318. {
  319. struct atom_smu_info_v3_1 *info;
  320. uint16_t idx;
  321. idx = GetIndexIntoMasterDataTable(smu_info);
  322. info = (struct atom_smu_info_v3_1 *)
  323. cgs_atom_get_data_table(hwmgr->device,
  324. idx, NULL, NULL, NULL);
  325. if (!info) {
  326. pr_info("Error retrieving BIOS smu_info Table Address!");
  327. return -1;
  328. }
  329. param->ucAcDcGpio = info->ac_dc_gpio_bit;
  330. param->ucAcDcPolarity = info->ac_dc_polarity;
  331. param->ucVR0HotGpio = info->vr0hot_gpio_bit;
  332. param->ucVR0HotPolarity = info->vr0hot_polarity;
  333. param->ucVR1HotGpio = info->vr1hot_gpio_bit;
  334. param->ucVR1HotPolarity = info->vr1hot_polarity;
  335. param->ucFwCtfGpio = info->fw_ctf_gpio_bit;
  336. param->ucFwCtfPolarity = info->fw_ctf_polarity;
  337. return 0;
  338. }
  339. int pp_atomfwctrl_get_vbios_bootup_values(struct pp_hwmgr *hwmgr,
  340. struct pp_atomfwctrl_bios_boot_up_values *boot_values)
  341. {
  342. struct atom_firmware_info_v3_1 *info = NULL;
  343. uint16_t ix;
  344. ix = GetIndexIntoMasterDataTable(firmwareinfo);
  345. info = (struct atom_firmware_info_v3_1 *)
  346. cgs_atom_get_data_table(hwmgr->device,
  347. ix, NULL, NULL, NULL);
  348. if (!info) {
  349. pr_info("Error retrieving BIOS firmwareinfo!");
  350. return -EINVAL;
  351. }
  352. boot_values->ulRevision = info->firmware_revision;
  353. boot_values->ulGfxClk = info->bootup_sclk_in10khz;
  354. boot_values->ulUClk = info->bootup_mclk_in10khz;
  355. boot_values->ulSocClk = 0;
  356. boot_values->usVddc = info->bootup_vddc_mv;
  357. boot_values->usVddci = info->bootup_vddci_mv;
  358. boot_values->usMvddc = info->bootup_mvddc_mv;
  359. boot_values->usVddGfx = info->bootup_vddgfx_mv;
  360. return 0;
  361. }