amdgpu_dpm.c 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957
  1. /*
  2. * Copyright 2011 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. * Authors: Alex Deucher
  23. */
  24. #include "drmP.h"
  25. #include "amdgpu.h"
  26. #include "amdgpu_atombios.h"
  27. #include "amdgpu_i2c.h"
  28. #include "amdgpu_dpm.h"
  29. #include "atom.h"
  30. void amdgpu_dpm_print_class_info(u32 class, u32 class2)
  31. {
  32. printk("\tui class: ");
  33. switch (class & ATOM_PPLIB_CLASSIFICATION_UI_MASK) {
  34. case ATOM_PPLIB_CLASSIFICATION_UI_NONE:
  35. default:
  36. printk("none\n");
  37. break;
  38. case ATOM_PPLIB_CLASSIFICATION_UI_BATTERY:
  39. printk("battery\n");
  40. break;
  41. case ATOM_PPLIB_CLASSIFICATION_UI_BALANCED:
  42. printk("balanced\n");
  43. break;
  44. case ATOM_PPLIB_CLASSIFICATION_UI_PERFORMANCE:
  45. printk("performance\n");
  46. break;
  47. }
  48. printk("\tinternal class: ");
  49. if (((class & ~ATOM_PPLIB_CLASSIFICATION_UI_MASK) == 0) &&
  50. (class2 == 0))
  51. printk("none");
  52. else {
  53. if (class & ATOM_PPLIB_CLASSIFICATION_BOOT)
  54. printk("boot ");
  55. if (class & ATOM_PPLIB_CLASSIFICATION_THERMAL)
  56. printk("thermal ");
  57. if (class & ATOM_PPLIB_CLASSIFICATION_LIMITEDPOWERSOURCE)
  58. printk("limited_pwr ");
  59. if (class & ATOM_PPLIB_CLASSIFICATION_REST)
  60. printk("rest ");
  61. if (class & ATOM_PPLIB_CLASSIFICATION_FORCED)
  62. printk("forced ");
  63. if (class & ATOM_PPLIB_CLASSIFICATION_3DPERFORMANCE)
  64. printk("3d_perf ");
  65. if (class & ATOM_PPLIB_CLASSIFICATION_OVERDRIVETEMPLATE)
  66. printk("ovrdrv ");
  67. if (class & ATOM_PPLIB_CLASSIFICATION_UVDSTATE)
  68. printk("uvd ");
  69. if (class & ATOM_PPLIB_CLASSIFICATION_3DLOW)
  70. printk("3d_low ");
  71. if (class & ATOM_PPLIB_CLASSIFICATION_ACPI)
  72. printk("acpi ");
  73. if (class & ATOM_PPLIB_CLASSIFICATION_HD2STATE)
  74. printk("uvd_hd2 ");
  75. if (class & ATOM_PPLIB_CLASSIFICATION_HDSTATE)
  76. printk("uvd_hd ");
  77. if (class & ATOM_PPLIB_CLASSIFICATION_SDSTATE)
  78. printk("uvd_sd ");
  79. if (class2 & ATOM_PPLIB_CLASSIFICATION2_LIMITEDPOWERSOURCE_2)
  80. printk("limited_pwr2 ");
  81. if (class2 & ATOM_PPLIB_CLASSIFICATION2_ULV)
  82. printk("ulv ");
  83. if (class2 & ATOM_PPLIB_CLASSIFICATION2_MVC)
  84. printk("uvd_mvc ");
  85. }
  86. printk("\n");
  87. }
  88. void amdgpu_dpm_print_cap_info(u32 caps)
  89. {
  90. printk("\tcaps: ");
  91. if (caps & ATOM_PPLIB_SINGLE_DISPLAY_ONLY)
  92. printk("single_disp ");
  93. if (caps & ATOM_PPLIB_SUPPORTS_VIDEO_PLAYBACK)
  94. printk("video ");
  95. if (caps & ATOM_PPLIB_DISALLOW_ON_DC)
  96. printk("no_dc ");
  97. printk("\n");
  98. }
  99. void amdgpu_dpm_print_ps_status(struct amdgpu_device *adev,
  100. struct amdgpu_ps *rps)
  101. {
  102. printk("\tstatus: ");
  103. if (rps == adev->pm.dpm.current_ps)
  104. printk("c ");
  105. if (rps == adev->pm.dpm.requested_ps)
  106. printk("r ");
  107. if (rps == adev->pm.dpm.boot_ps)
  108. printk("b ");
  109. printk("\n");
  110. }
  111. u32 amdgpu_dpm_get_vblank_time(struct amdgpu_device *adev)
  112. {
  113. struct drm_device *dev = adev->ddev;
  114. struct drm_crtc *crtc;
  115. struct amdgpu_crtc *amdgpu_crtc;
  116. u32 vblank_in_pixels;
  117. u32 vblank_time_us = 0xffffffff; /* if the displays are off, vblank time is max */
  118. if (adev->mode_info.num_crtc && adev->mode_info.mode_config_initialized) {
  119. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
  120. amdgpu_crtc = to_amdgpu_crtc(crtc);
  121. if (crtc->enabled && amdgpu_crtc->enabled && amdgpu_crtc->hw_mode.clock) {
  122. vblank_in_pixels =
  123. amdgpu_crtc->hw_mode.crtc_htotal *
  124. (amdgpu_crtc->hw_mode.crtc_vblank_end -
  125. amdgpu_crtc->hw_mode.crtc_vdisplay +
  126. (amdgpu_crtc->v_border * 2));
  127. vblank_time_us = vblank_in_pixels * 1000 / amdgpu_crtc->hw_mode.clock;
  128. break;
  129. }
  130. }
  131. }
  132. return vblank_time_us;
  133. }
  134. u32 amdgpu_dpm_get_vrefresh(struct amdgpu_device *adev)
  135. {
  136. struct drm_device *dev = adev->ddev;
  137. struct drm_crtc *crtc;
  138. struct amdgpu_crtc *amdgpu_crtc;
  139. u32 vrefresh = 0;
  140. if (adev->mode_info.num_crtc && adev->mode_info.mode_config_initialized) {
  141. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
  142. amdgpu_crtc = to_amdgpu_crtc(crtc);
  143. if (crtc->enabled && amdgpu_crtc->enabled && amdgpu_crtc->hw_mode.clock) {
  144. vrefresh = drm_mode_vrefresh(&amdgpu_crtc->hw_mode);
  145. break;
  146. }
  147. }
  148. }
  149. return vrefresh;
  150. }
  151. void amdgpu_calculate_u_and_p(u32 i, u32 r_c, u32 p_b,
  152. u32 *p, u32 *u)
  153. {
  154. u32 b_c = 0;
  155. u32 i_c;
  156. u32 tmp;
  157. i_c = (i * r_c) / 100;
  158. tmp = i_c >> p_b;
  159. while (tmp) {
  160. b_c++;
  161. tmp >>= 1;
  162. }
  163. *u = (b_c + 1) / 2;
  164. *p = i_c / (1 << (2 * (*u)));
  165. }
  166. int amdgpu_calculate_at(u32 t, u32 h, u32 fh, u32 fl, u32 *tl, u32 *th)
  167. {
  168. u32 k, a, ah, al;
  169. u32 t1;
  170. if ((fl == 0) || (fh == 0) || (fl > fh))
  171. return -EINVAL;
  172. k = (100 * fh) / fl;
  173. t1 = (t * (k - 100));
  174. a = (1000 * (100 * h + t1)) / (10000 + (t1 / 100));
  175. a = (a + 5) / 10;
  176. ah = ((a * t) + 5000) / 10000;
  177. al = a - ah;
  178. *th = t - ah;
  179. *tl = t + al;
  180. return 0;
  181. }
  182. bool amdgpu_is_uvd_state(u32 class, u32 class2)
  183. {
  184. if (class & ATOM_PPLIB_CLASSIFICATION_UVDSTATE)
  185. return true;
  186. if (class & ATOM_PPLIB_CLASSIFICATION_HD2STATE)
  187. return true;
  188. if (class & ATOM_PPLIB_CLASSIFICATION_HDSTATE)
  189. return true;
  190. if (class & ATOM_PPLIB_CLASSIFICATION_SDSTATE)
  191. return true;
  192. if (class2 & ATOM_PPLIB_CLASSIFICATION2_MVC)
  193. return true;
  194. return false;
  195. }
  196. bool amdgpu_is_internal_thermal_sensor(enum amdgpu_int_thermal_type sensor)
  197. {
  198. switch (sensor) {
  199. case THERMAL_TYPE_RV6XX:
  200. case THERMAL_TYPE_RV770:
  201. case THERMAL_TYPE_EVERGREEN:
  202. case THERMAL_TYPE_SUMO:
  203. case THERMAL_TYPE_NI:
  204. case THERMAL_TYPE_SI:
  205. case THERMAL_TYPE_CI:
  206. case THERMAL_TYPE_KV:
  207. return true;
  208. case THERMAL_TYPE_ADT7473_WITH_INTERNAL:
  209. case THERMAL_TYPE_EMC2103_WITH_INTERNAL:
  210. return false; /* need special handling */
  211. case THERMAL_TYPE_NONE:
  212. case THERMAL_TYPE_EXTERNAL:
  213. case THERMAL_TYPE_EXTERNAL_GPIO:
  214. default:
  215. return false;
  216. }
  217. }
  218. union power_info {
  219. struct _ATOM_POWERPLAY_INFO info;
  220. struct _ATOM_POWERPLAY_INFO_V2 info_2;
  221. struct _ATOM_POWERPLAY_INFO_V3 info_3;
  222. struct _ATOM_PPLIB_POWERPLAYTABLE pplib;
  223. struct _ATOM_PPLIB_POWERPLAYTABLE2 pplib2;
  224. struct _ATOM_PPLIB_POWERPLAYTABLE3 pplib3;
  225. struct _ATOM_PPLIB_POWERPLAYTABLE4 pplib4;
  226. struct _ATOM_PPLIB_POWERPLAYTABLE5 pplib5;
  227. };
  228. union fan_info {
  229. struct _ATOM_PPLIB_FANTABLE fan;
  230. struct _ATOM_PPLIB_FANTABLE2 fan2;
  231. struct _ATOM_PPLIB_FANTABLE3 fan3;
  232. };
  233. static int amdgpu_parse_clk_voltage_dep_table(struct amdgpu_clock_voltage_dependency_table *amdgpu_table,
  234. ATOM_PPLIB_Clock_Voltage_Dependency_Table *atom_table)
  235. {
  236. u32 size = atom_table->ucNumEntries *
  237. sizeof(struct amdgpu_clock_voltage_dependency_entry);
  238. int i;
  239. ATOM_PPLIB_Clock_Voltage_Dependency_Record *entry;
  240. amdgpu_table->entries = kzalloc(size, GFP_KERNEL);
  241. if (!amdgpu_table->entries)
  242. return -ENOMEM;
  243. entry = &atom_table->entries[0];
  244. for (i = 0; i < atom_table->ucNumEntries; i++) {
  245. amdgpu_table->entries[i].clk = le16_to_cpu(entry->usClockLow) |
  246. (entry->ucClockHigh << 16);
  247. amdgpu_table->entries[i].v = le16_to_cpu(entry->usVoltage);
  248. entry = (ATOM_PPLIB_Clock_Voltage_Dependency_Record *)
  249. ((u8 *)entry + sizeof(ATOM_PPLIB_Clock_Voltage_Dependency_Record));
  250. }
  251. amdgpu_table->count = atom_table->ucNumEntries;
  252. return 0;
  253. }
  254. int amdgpu_get_platform_caps(struct amdgpu_device *adev)
  255. {
  256. struct amdgpu_mode_info *mode_info = &adev->mode_info;
  257. union power_info *power_info;
  258. int index = GetIndexIntoMasterTable(DATA, PowerPlayInfo);
  259. u16 data_offset;
  260. u8 frev, crev;
  261. if (!amdgpu_atom_parse_data_header(mode_info->atom_context, index, NULL,
  262. &frev, &crev, &data_offset))
  263. return -EINVAL;
  264. power_info = (union power_info *)(mode_info->atom_context->bios + data_offset);
  265. adev->pm.dpm.platform_caps = le32_to_cpu(power_info->pplib.ulPlatformCaps);
  266. adev->pm.dpm.backbias_response_time = le16_to_cpu(power_info->pplib.usBackbiasTime);
  267. adev->pm.dpm.voltage_response_time = le16_to_cpu(power_info->pplib.usVoltageTime);
  268. return 0;
  269. }
  270. /* sizeof(ATOM_PPLIB_EXTENDEDHEADER) */
  271. #define SIZE_OF_ATOM_PPLIB_EXTENDEDHEADER_V2 12
  272. #define SIZE_OF_ATOM_PPLIB_EXTENDEDHEADER_V3 14
  273. #define SIZE_OF_ATOM_PPLIB_EXTENDEDHEADER_V4 16
  274. #define SIZE_OF_ATOM_PPLIB_EXTENDEDHEADER_V5 18
  275. #define SIZE_OF_ATOM_PPLIB_EXTENDEDHEADER_V6 20
  276. #define SIZE_OF_ATOM_PPLIB_EXTENDEDHEADER_V7 22
  277. #define SIZE_OF_ATOM_PPLIB_EXTENDEDHEADER_V8 24
  278. #define SIZE_OF_ATOM_PPLIB_EXTENDEDHEADER_V9 26
  279. int amdgpu_parse_extended_power_table(struct amdgpu_device *adev)
  280. {
  281. struct amdgpu_mode_info *mode_info = &adev->mode_info;
  282. union power_info *power_info;
  283. union fan_info *fan_info;
  284. ATOM_PPLIB_Clock_Voltage_Dependency_Table *dep_table;
  285. int index = GetIndexIntoMasterTable(DATA, PowerPlayInfo);
  286. u16 data_offset;
  287. u8 frev, crev;
  288. int ret, i;
  289. if (!amdgpu_atom_parse_data_header(mode_info->atom_context, index, NULL,
  290. &frev, &crev, &data_offset))
  291. return -EINVAL;
  292. power_info = (union power_info *)(mode_info->atom_context->bios + data_offset);
  293. /* fan table */
  294. if (le16_to_cpu(power_info->pplib.usTableSize) >=
  295. sizeof(struct _ATOM_PPLIB_POWERPLAYTABLE3)) {
  296. if (power_info->pplib3.usFanTableOffset) {
  297. fan_info = (union fan_info *)(mode_info->atom_context->bios + data_offset +
  298. le16_to_cpu(power_info->pplib3.usFanTableOffset));
  299. adev->pm.dpm.fan.t_hyst = fan_info->fan.ucTHyst;
  300. adev->pm.dpm.fan.t_min = le16_to_cpu(fan_info->fan.usTMin);
  301. adev->pm.dpm.fan.t_med = le16_to_cpu(fan_info->fan.usTMed);
  302. adev->pm.dpm.fan.t_high = le16_to_cpu(fan_info->fan.usTHigh);
  303. adev->pm.dpm.fan.pwm_min = le16_to_cpu(fan_info->fan.usPWMMin);
  304. adev->pm.dpm.fan.pwm_med = le16_to_cpu(fan_info->fan.usPWMMed);
  305. adev->pm.dpm.fan.pwm_high = le16_to_cpu(fan_info->fan.usPWMHigh);
  306. if (fan_info->fan.ucFanTableFormat >= 2)
  307. adev->pm.dpm.fan.t_max = le16_to_cpu(fan_info->fan2.usTMax);
  308. else
  309. adev->pm.dpm.fan.t_max = 10900;
  310. adev->pm.dpm.fan.cycle_delay = 100000;
  311. if (fan_info->fan.ucFanTableFormat >= 3) {
  312. adev->pm.dpm.fan.control_mode = fan_info->fan3.ucFanControlMode;
  313. adev->pm.dpm.fan.default_max_fan_pwm =
  314. le16_to_cpu(fan_info->fan3.usFanPWMMax);
  315. adev->pm.dpm.fan.default_fan_output_sensitivity = 4836;
  316. adev->pm.dpm.fan.fan_output_sensitivity =
  317. le16_to_cpu(fan_info->fan3.usFanOutputSensitivity);
  318. }
  319. adev->pm.dpm.fan.ucode_fan_control = true;
  320. }
  321. }
  322. /* clock dependancy tables, shedding tables */
  323. if (le16_to_cpu(power_info->pplib.usTableSize) >=
  324. sizeof(struct _ATOM_PPLIB_POWERPLAYTABLE4)) {
  325. if (power_info->pplib4.usVddcDependencyOnSCLKOffset) {
  326. dep_table = (ATOM_PPLIB_Clock_Voltage_Dependency_Table *)
  327. (mode_info->atom_context->bios + data_offset +
  328. le16_to_cpu(power_info->pplib4.usVddcDependencyOnSCLKOffset));
  329. ret = amdgpu_parse_clk_voltage_dep_table(&adev->pm.dpm.dyn_state.vddc_dependency_on_sclk,
  330. dep_table);
  331. if (ret) {
  332. amdgpu_free_extended_power_table(adev);
  333. return ret;
  334. }
  335. }
  336. if (power_info->pplib4.usVddciDependencyOnMCLKOffset) {
  337. dep_table = (ATOM_PPLIB_Clock_Voltage_Dependency_Table *)
  338. (mode_info->atom_context->bios + data_offset +
  339. le16_to_cpu(power_info->pplib4.usVddciDependencyOnMCLKOffset));
  340. ret = amdgpu_parse_clk_voltage_dep_table(&adev->pm.dpm.dyn_state.vddci_dependency_on_mclk,
  341. dep_table);
  342. if (ret) {
  343. amdgpu_free_extended_power_table(adev);
  344. return ret;
  345. }
  346. }
  347. if (power_info->pplib4.usVddcDependencyOnMCLKOffset) {
  348. dep_table = (ATOM_PPLIB_Clock_Voltage_Dependency_Table *)
  349. (mode_info->atom_context->bios + data_offset +
  350. le16_to_cpu(power_info->pplib4.usVddcDependencyOnMCLKOffset));
  351. ret = amdgpu_parse_clk_voltage_dep_table(&adev->pm.dpm.dyn_state.vddc_dependency_on_mclk,
  352. dep_table);
  353. if (ret) {
  354. amdgpu_free_extended_power_table(adev);
  355. return ret;
  356. }
  357. }
  358. if (power_info->pplib4.usMvddDependencyOnMCLKOffset) {
  359. dep_table = (ATOM_PPLIB_Clock_Voltage_Dependency_Table *)
  360. (mode_info->atom_context->bios + data_offset +
  361. le16_to_cpu(power_info->pplib4.usMvddDependencyOnMCLKOffset));
  362. ret = amdgpu_parse_clk_voltage_dep_table(&adev->pm.dpm.dyn_state.mvdd_dependency_on_mclk,
  363. dep_table);
  364. if (ret) {
  365. amdgpu_free_extended_power_table(adev);
  366. return ret;
  367. }
  368. }
  369. if (power_info->pplib4.usMaxClockVoltageOnDCOffset) {
  370. ATOM_PPLIB_Clock_Voltage_Limit_Table *clk_v =
  371. (ATOM_PPLIB_Clock_Voltage_Limit_Table *)
  372. (mode_info->atom_context->bios + data_offset +
  373. le16_to_cpu(power_info->pplib4.usMaxClockVoltageOnDCOffset));
  374. if (clk_v->ucNumEntries) {
  375. adev->pm.dpm.dyn_state.max_clock_voltage_on_dc.sclk =
  376. le16_to_cpu(clk_v->entries[0].usSclkLow) |
  377. (clk_v->entries[0].ucSclkHigh << 16);
  378. adev->pm.dpm.dyn_state.max_clock_voltage_on_dc.mclk =
  379. le16_to_cpu(clk_v->entries[0].usMclkLow) |
  380. (clk_v->entries[0].ucMclkHigh << 16);
  381. adev->pm.dpm.dyn_state.max_clock_voltage_on_dc.vddc =
  382. le16_to_cpu(clk_v->entries[0].usVddc);
  383. adev->pm.dpm.dyn_state.max_clock_voltage_on_dc.vddci =
  384. le16_to_cpu(clk_v->entries[0].usVddci);
  385. }
  386. }
  387. if (power_info->pplib4.usVddcPhaseShedLimitsTableOffset) {
  388. ATOM_PPLIB_PhaseSheddingLimits_Table *psl =
  389. (ATOM_PPLIB_PhaseSheddingLimits_Table *)
  390. (mode_info->atom_context->bios + data_offset +
  391. le16_to_cpu(power_info->pplib4.usVddcPhaseShedLimitsTableOffset));
  392. ATOM_PPLIB_PhaseSheddingLimits_Record *entry;
  393. adev->pm.dpm.dyn_state.phase_shedding_limits_table.entries =
  394. kzalloc(psl->ucNumEntries *
  395. sizeof(struct amdgpu_phase_shedding_limits_entry),
  396. GFP_KERNEL);
  397. if (!adev->pm.dpm.dyn_state.phase_shedding_limits_table.entries) {
  398. amdgpu_free_extended_power_table(adev);
  399. return -ENOMEM;
  400. }
  401. entry = &psl->entries[0];
  402. for (i = 0; i < psl->ucNumEntries; i++) {
  403. adev->pm.dpm.dyn_state.phase_shedding_limits_table.entries[i].sclk =
  404. le16_to_cpu(entry->usSclkLow) | (entry->ucSclkHigh << 16);
  405. adev->pm.dpm.dyn_state.phase_shedding_limits_table.entries[i].mclk =
  406. le16_to_cpu(entry->usMclkLow) | (entry->ucMclkHigh << 16);
  407. adev->pm.dpm.dyn_state.phase_shedding_limits_table.entries[i].voltage =
  408. le16_to_cpu(entry->usVoltage);
  409. entry = (ATOM_PPLIB_PhaseSheddingLimits_Record *)
  410. ((u8 *)entry + sizeof(ATOM_PPLIB_PhaseSheddingLimits_Record));
  411. }
  412. adev->pm.dpm.dyn_state.phase_shedding_limits_table.count =
  413. psl->ucNumEntries;
  414. }
  415. }
  416. /* cac data */
  417. if (le16_to_cpu(power_info->pplib.usTableSize) >=
  418. sizeof(struct _ATOM_PPLIB_POWERPLAYTABLE5)) {
  419. adev->pm.dpm.tdp_limit = le32_to_cpu(power_info->pplib5.ulTDPLimit);
  420. adev->pm.dpm.near_tdp_limit = le32_to_cpu(power_info->pplib5.ulNearTDPLimit);
  421. adev->pm.dpm.near_tdp_limit_adjusted = adev->pm.dpm.near_tdp_limit;
  422. adev->pm.dpm.tdp_od_limit = le16_to_cpu(power_info->pplib5.usTDPODLimit);
  423. if (adev->pm.dpm.tdp_od_limit)
  424. adev->pm.dpm.power_control = true;
  425. else
  426. adev->pm.dpm.power_control = false;
  427. adev->pm.dpm.tdp_adjustment = 0;
  428. adev->pm.dpm.sq_ramping_threshold = le32_to_cpu(power_info->pplib5.ulSQRampingThreshold);
  429. adev->pm.dpm.cac_leakage = le32_to_cpu(power_info->pplib5.ulCACLeakage);
  430. adev->pm.dpm.load_line_slope = le16_to_cpu(power_info->pplib5.usLoadLineSlope);
  431. if (power_info->pplib5.usCACLeakageTableOffset) {
  432. ATOM_PPLIB_CAC_Leakage_Table *cac_table =
  433. (ATOM_PPLIB_CAC_Leakage_Table *)
  434. (mode_info->atom_context->bios + data_offset +
  435. le16_to_cpu(power_info->pplib5.usCACLeakageTableOffset));
  436. ATOM_PPLIB_CAC_Leakage_Record *entry;
  437. u32 size = cac_table->ucNumEntries * sizeof(struct amdgpu_cac_leakage_table);
  438. adev->pm.dpm.dyn_state.cac_leakage_table.entries = kzalloc(size, GFP_KERNEL);
  439. if (!adev->pm.dpm.dyn_state.cac_leakage_table.entries) {
  440. amdgpu_free_extended_power_table(adev);
  441. return -ENOMEM;
  442. }
  443. entry = &cac_table->entries[0];
  444. for (i = 0; i < cac_table->ucNumEntries; i++) {
  445. if (adev->pm.dpm.platform_caps & ATOM_PP_PLATFORM_CAP_EVV) {
  446. adev->pm.dpm.dyn_state.cac_leakage_table.entries[i].vddc1 =
  447. le16_to_cpu(entry->usVddc1);
  448. adev->pm.dpm.dyn_state.cac_leakage_table.entries[i].vddc2 =
  449. le16_to_cpu(entry->usVddc2);
  450. adev->pm.dpm.dyn_state.cac_leakage_table.entries[i].vddc3 =
  451. le16_to_cpu(entry->usVddc3);
  452. } else {
  453. adev->pm.dpm.dyn_state.cac_leakage_table.entries[i].vddc =
  454. le16_to_cpu(entry->usVddc);
  455. adev->pm.dpm.dyn_state.cac_leakage_table.entries[i].leakage =
  456. le32_to_cpu(entry->ulLeakageValue);
  457. }
  458. entry = (ATOM_PPLIB_CAC_Leakage_Record *)
  459. ((u8 *)entry + sizeof(ATOM_PPLIB_CAC_Leakage_Record));
  460. }
  461. adev->pm.dpm.dyn_state.cac_leakage_table.count = cac_table->ucNumEntries;
  462. }
  463. }
  464. /* ext tables */
  465. if (le16_to_cpu(power_info->pplib.usTableSize) >=
  466. sizeof(struct _ATOM_PPLIB_POWERPLAYTABLE3)) {
  467. ATOM_PPLIB_EXTENDEDHEADER *ext_hdr = (ATOM_PPLIB_EXTENDEDHEADER *)
  468. (mode_info->atom_context->bios + data_offset +
  469. le16_to_cpu(power_info->pplib3.usExtendendedHeaderOffset));
  470. if ((le16_to_cpu(ext_hdr->usSize) >= SIZE_OF_ATOM_PPLIB_EXTENDEDHEADER_V2) &&
  471. ext_hdr->usVCETableOffset) {
  472. VCEClockInfoArray *array = (VCEClockInfoArray *)
  473. (mode_info->atom_context->bios + data_offset +
  474. le16_to_cpu(ext_hdr->usVCETableOffset) + 1);
  475. ATOM_PPLIB_VCE_Clock_Voltage_Limit_Table *limits =
  476. (ATOM_PPLIB_VCE_Clock_Voltage_Limit_Table *)
  477. (mode_info->atom_context->bios + data_offset +
  478. le16_to_cpu(ext_hdr->usVCETableOffset) + 1 +
  479. 1 + array->ucNumEntries * sizeof(VCEClockInfo));
  480. ATOM_PPLIB_VCE_State_Table *states =
  481. (ATOM_PPLIB_VCE_State_Table *)
  482. (mode_info->atom_context->bios + data_offset +
  483. le16_to_cpu(ext_hdr->usVCETableOffset) + 1 +
  484. 1 + (array->ucNumEntries * sizeof (VCEClockInfo)) +
  485. 1 + (limits->numEntries * sizeof(ATOM_PPLIB_VCE_Clock_Voltage_Limit_Record)));
  486. ATOM_PPLIB_VCE_Clock_Voltage_Limit_Record *entry;
  487. ATOM_PPLIB_VCE_State_Record *state_entry;
  488. VCEClockInfo *vce_clk;
  489. u32 size = limits->numEntries *
  490. sizeof(struct amdgpu_vce_clock_voltage_dependency_entry);
  491. adev->pm.dpm.dyn_state.vce_clock_voltage_dependency_table.entries =
  492. kzalloc(size, GFP_KERNEL);
  493. if (!adev->pm.dpm.dyn_state.vce_clock_voltage_dependency_table.entries) {
  494. amdgpu_free_extended_power_table(adev);
  495. return -ENOMEM;
  496. }
  497. adev->pm.dpm.dyn_state.vce_clock_voltage_dependency_table.count =
  498. limits->numEntries;
  499. entry = &limits->entries[0];
  500. state_entry = &states->entries[0];
  501. for (i = 0; i < limits->numEntries; i++) {
  502. vce_clk = (VCEClockInfo *)
  503. ((u8 *)&array->entries[0] +
  504. (entry->ucVCEClockInfoIndex * sizeof(VCEClockInfo)));
  505. adev->pm.dpm.dyn_state.vce_clock_voltage_dependency_table.entries[i].evclk =
  506. le16_to_cpu(vce_clk->usEVClkLow) | (vce_clk->ucEVClkHigh << 16);
  507. adev->pm.dpm.dyn_state.vce_clock_voltage_dependency_table.entries[i].ecclk =
  508. le16_to_cpu(vce_clk->usECClkLow) | (vce_clk->ucECClkHigh << 16);
  509. adev->pm.dpm.dyn_state.vce_clock_voltage_dependency_table.entries[i].v =
  510. le16_to_cpu(entry->usVoltage);
  511. entry = (ATOM_PPLIB_VCE_Clock_Voltage_Limit_Record *)
  512. ((u8 *)entry + sizeof(ATOM_PPLIB_VCE_Clock_Voltage_Limit_Record));
  513. }
  514. for (i = 0; i < states->numEntries; i++) {
  515. if (i >= AMDGPU_MAX_VCE_LEVELS)
  516. break;
  517. vce_clk = (VCEClockInfo *)
  518. ((u8 *)&array->entries[0] +
  519. (state_entry->ucVCEClockInfoIndex * sizeof(VCEClockInfo)));
  520. adev->pm.dpm.vce_states[i].evclk =
  521. le16_to_cpu(vce_clk->usEVClkLow) | (vce_clk->ucEVClkHigh << 16);
  522. adev->pm.dpm.vce_states[i].ecclk =
  523. le16_to_cpu(vce_clk->usECClkLow) | (vce_clk->ucECClkHigh << 16);
  524. adev->pm.dpm.vce_states[i].clk_idx =
  525. state_entry->ucClockInfoIndex & 0x3f;
  526. adev->pm.dpm.vce_states[i].pstate =
  527. (state_entry->ucClockInfoIndex & 0xc0) >> 6;
  528. state_entry = (ATOM_PPLIB_VCE_State_Record *)
  529. ((u8 *)state_entry + sizeof(ATOM_PPLIB_VCE_State_Record));
  530. }
  531. }
  532. if ((le16_to_cpu(ext_hdr->usSize) >= SIZE_OF_ATOM_PPLIB_EXTENDEDHEADER_V3) &&
  533. ext_hdr->usUVDTableOffset) {
  534. UVDClockInfoArray *array = (UVDClockInfoArray *)
  535. (mode_info->atom_context->bios + data_offset +
  536. le16_to_cpu(ext_hdr->usUVDTableOffset) + 1);
  537. ATOM_PPLIB_UVD_Clock_Voltage_Limit_Table *limits =
  538. (ATOM_PPLIB_UVD_Clock_Voltage_Limit_Table *)
  539. (mode_info->atom_context->bios + data_offset +
  540. le16_to_cpu(ext_hdr->usUVDTableOffset) + 1 +
  541. 1 + (array->ucNumEntries * sizeof (UVDClockInfo)));
  542. ATOM_PPLIB_UVD_Clock_Voltage_Limit_Record *entry;
  543. u32 size = limits->numEntries *
  544. sizeof(struct amdgpu_uvd_clock_voltage_dependency_entry);
  545. adev->pm.dpm.dyn_state.uvd_clock_voltage_dependency_table.entries =
  546. kzalloc(size, GFP_KERNEL);
  547. if (!adev->pm.dpm.dyn_state.uvd_clock_voltage_dependency_table.entries) {
  548. amdgpu_free_extended_power_table(adev);
  549. return -ENOMEM;
  550. }
  551. adev->pm.dpm.dyn_state.uvd_clock_voltage_dependency_table.count =
  552. limits->numEntries;
  553. entry = &limits->entries[0];
  554. for (i = 0; i < limits->numEntries; i++) {
  555. UVDClockInfo *uvd_clk = (UVDClockInfo *)
  556. ((u8 *)&array->entries[0] +
  557. (entry->ucUVDClockInfoIndex * sizeof(UVDClockInfo)));
  558. adev->pm.dpm.dyn_state.uvd_clock_voltage_dependency_table.entries[i].vclk =
  559. le16_to_cpu(uvd_clk->usVClkLow) | (uvd_clk->ucVClkHigh << 16);
  560. adev->pm.dpm.dyn_state.uvd_clock_voltage_dependency_table.entries[i].dclk =
  561. le16_to_cpu(uvd_clk->usDClkLow) | (uvd_clk->ucDClkHigh << 16);
  562. adev->pm.dpm.dyn_state.uvd_clock_voltage_dependency_table.entries[i].v =
  563. le16_to_cpu(entry->usVoltage);
  564. entry = (ATOM_PPLIB_UVD_Clock_Voltage_Limit_Record *)
  565. ((u8 *)entry + sizeof(ATOM_PPLIB_UVD_Clock_Voltage_Limit_Record));
  566. }
  567. }
  568. if ((le16_to_cpu(ext_hdr->usSize) >= SIZE_OF_ATOM_PPLIB_EXTENDEDHEADER_V4) &&
  569. ext_hdr->usSAMUTableOffset) {
  570. ATOM_PPLIB_SAMClk_Voltage_Limit_Table *limits =
  571. (ATOM_PPLIB_SAMClk_Voltage_Limit_Table *)
  572. (mode_info->atom_context->bios + data_offset +
  573. le16_to_cpu(ext_hdr->usSAMUTableOffset) + 1);
  574. ATOM_PPLIB_SAMClk_Voltage_Limit_Record *entry;
  575. u32 size = limits->numEntries *
  576. sizeof(struct amdgpu_clock_voltage_dependency_entry);
  577. adev->pm.dpm.dyn_state.samu_clock_voltage_dependency_table.entries =
  578. kzalloc(size, GFP_KERNEL);
  579. if (!adev->pm.dpm.dyn_state.samu_clock_voltage_dependency_table.entries) {
  580. amdgpu_free_extended_power_table(adev);
  581. return -ENOMEM;
  582. }
  583. adev->pm.dpm.dyn_state.samu_clock_voltage_dependency_table.count =
  584. limits->numEntries;
  585. entry = &limits->entries[0];
  586. for (i = 0; i < limits->numEntries; i++) {
  587. adev->pm.dpm.dyn_state.samu_clock_voltage_dependency_table.entries[i].clk =
  588. le16_to_cpu(entry->usSAMClockLow) | (entry->ucSAMClockHigh << 16);
  589. adev->pm.dpm.dyn_state.samu_clock_voltage_dependency_table.entries[i].v =
  590. le16_to_cpu(entry->usVoltage);
  591. entry = (ATOM_PPLIB_SAMClk_Voltage_Limit_Record *)
  592. ((u8 *)entry + sizeof(ATOM_PPLIB_SAMClk_Voltage_Limit_Record));
  593. }
  594. }
  595. if ((le16_to_cpu(ext_hdr->usSize) >= SIZE_OF_ATOM_PPLIB_EXTENDEDHEADER_V5) &&
  596. ext_hdr->usPPMTableOffset) {
  597. ATOM_PPLIB_PPM_Table *ppm = (ATOM_PPLIB_PPM_Table *)
  598. (mode_info->atom_context->bios + data_offset +
  599. le16_to_cpu(ext_hdr->usPPMTableOffset));
  600. adev->pm.dpm.dyn_state.ppm_table =
  601. kzalloc(sizeof(struct amdgpu_ppm_table), GFP_KERNEL);
  602. if (!adev->pm.dpm.dyn_state.ppm_table) {
  603. amdgpu_free_extended_power_table(adev);
  604. return -ENOMEM;
  605. }
  606. adev->pm.dpm.dyn_state.ppm_table->ppm_design = ppm->ucPpmDesign;
  607. adev->pm.dpm.dyn_state.ppm_table->cpu_core_number =
  608. le16_to_cpu(ppm->usCpuCoreNumber);
  609. adev->pm.dpm.dyn_state.ppm_table->platform_tdp =
  610. le32_to_cpu(ppm->ulPlatformTDP);
  611. adev->pm.dpm.dyn_state.ppm_table->small_ac_platform_tdp =
  612. le32_to_cpu(ppm->ulSmallACPlatformTDP);
  613. adev->pm.dpm.dyn_state.ppm_table->platform_tdc =
  614. le32_to_cpu(ppm->ulPlatformTDC);
  615. adev->pm.dpm.dyn_state.ppm_table->small_ac_platform_tdc =
  616. le32_to_cpu(ppm->ulSmallACPlatformTDC);
  617. adev->pm.dpm.dyn_state.ppm_table->apu_tdp =
  618. le32_to_cpu(ppm->ulApuTDP);
  619. adev->pm.dpm.dyn_state.ppm_table->dgpu_tdp =
  620. le32_to_cpu(ppm->ulDGpuTDP);
  621. adev->pm.dpm.dyn_state.ppm_table->dgpu_ulv_power =
  622. le32_to_cpu(ppm->ulDGpuUlvPower);
  623. adev->pm.dpm.dyn_state.ppm_table->tj_max =
  624. le32_to_cpu(ppm->ulTjmax);
  625. }
  626. if ((le16_to_cpu(ext_hdr->usSize) >= SIZE_OF_ATOM_PPLIB_EXTENDEDHEADER_V6) &&
  627. ext_hdr->usACPTableOffset) {
  628. ATOM_PPLIB_ACPClk_Voltage_Limit_Table *limits =
  629. (ATOM_PPLIB_ACPClk_Voltage_Limit_Table *)
  630. (mode_info->atom_context->bios + data_offset +
  631. le16_to_cpu(ext_hdr->usACPTableOffset) + 1);
  632. ATOM_PPLIB_ACPClk_Voltage_Limit_Record *entry;
  633. u32 size = limits->numEntries *
  634. sizeof(struct amdgpu_clock_voltage_dependency_entry);
  635. adev->pm.dpm.dyn_state.acp_clock_voltage_dependency_table.entries =
  636. kzalloc(size, GFP_KERNEL);
  637. if (!adev->pm.dpm.dyn_state.acp_clock_voltage_dependency_table.entries) {
  638. amdgpu_free_extended_power_table(adev);
  639. return -ENOMEM;
  640. }
  641. adev->pm.dpm.dyn_state.acp_clock_voltage_dependency_table.count =
  642. limits->numEntries;
  643. entry = &limits->entries[0];
  644. for (i = 0; i < limits->numEntries; i++) {
  645. adev->pm.dpm.dyn_state.acp_clock_voltage_dependency_table.entries[i].clk =
  646. le16_to_cpu(entry->usACPClockLow) | (entry->ucACPClockHigh << 16);
  647. adev->pm.dpm.dyn_state.acp_clock_voltage_dependency_table.entries[i].v =
  648. le16_to_cpu(entry->usVoltage);
  649. entry = (ATOM_PPLIB_ACPClk_Voltage_Limit_Record *)
  650. ((u8 *)entry + sizeof(ATOM_PPLIB_ACPClk_Voltage_Limit_Record));
  651. }
  652. }
  653. if ((le16_to_cpu(ext_hdr->usSize) >= SIZE_OF_ATOM_PPLIB_EXTENDEDHEADER_V7) &&
  654. ext_hdr->usPowerTuneTableOffset) {
  655. u8 rev = *(u8 *)(mode_info->atom_context->bios + data_offset +
  656. le16_to_cpu(ext_hdr->usPowerTuneTableOffset));
  657. ATOM_PowerTune_Table *pt;
  658. adev->pm.dpm.dyn_state.cac_tdp_table =
  659. kzalloc(sizeof(struct amdgpu_cac_tdp_table), GFP_KERNEL);
  660. if (!adev->pm.dpm.dyn_state.cac_tdp_table) {
  661. amdgpu_free_extended_power_table(adev);
  662. return -ENOMEM;
  663. }
  664. if (rev > 0) {
  665. ATOM_PPLIB_POWERTUNE_Table_V1 *ppt = (ATOM_PPLIB_POWERTUNE_Table_V1 *)
  666. (mode_info->atom_context->bios + data_offset +
  667. le16_to_cpu(ext_hdr->usPowerTuneTableOffset));
  668. adev->pm.dpm.dyn_state.cac_tdp_table->maximum_power_delivery_limit =
  669. ppt->usMaximumPowerDeliveryLimit;
  670. pt = &ppt->power_tune_table;
  671. } else {
  672. ATOM_PPLIB_POWERTUNE_Table *ppt = (ATOM_PPLIB_POWERTUNE_Table *)
  673. (mode_info->atom_context->bios + data_offset +
  674. le16_to_cpu(ext_hdr->usPowerTuneTableOffset));
  675. adev->pm.dpm.dyn_state.cac_tdp_table->maximum_power_delivery_limit = 255;
  676. pt = &ppt->power_tune_table;
  677. }
  678. adev->pm.dpm.dyn_state.cac_tdp_table->tdp = le16_to_cpu(pt->usTDP);
  679. adev->pm.dpm.dyn_state.cac_tdp_table->configurable_tdp =
  680. le16_to_cpu(pt->usConfigurableTDP);
  681. adev->pm.dpm.dyn_state.cac_tdp_table->tdc = le16_to_cpu(pt->usTDC);
  682. adev->pm.dpm.dyn_state.cac_tdp_table->battery_power_limit =
  683. le16_to_cpu(pt->usBatteryPowerLimit);
  684. adev->pm.dpm.dyn_state.cac_tdp_table->small_power_limit =
  685. le16_to_cpu(pt->usSmallPowerLimit);
  686. adev->pm.dpm.dyn_state.cac_tdp_table->low_cac_leakage =
  687. le16_to_cpu(pt->usLowCACLeakage);
  688. adev->pm.dpm.dyn_state.cac_tdp_table->high_cac_leakage =
  689. le16_to_cpu(pt->usHighCACLeakage);
  690. }
  691. if ((le16_to_cpu(ext_hdr->usSize) >= SIZE_OF_ATOM_PPLIB_EXTENDEDHEADER_V8) &&
  692. ext_hdr->usSclkVddgfxTableOffset) {
  693. dep_table = (ATOM_PPLIB_Clock_Voltage_Dependency_Table *)
  694. (mode_info->atom_context->bios + data_offset +
  695. le16_to_cpu(ext_hdr->usSclkVddgfxTableOffset));
  696. ret = amdgpu_parse_clk_voltage_dep_table(
  697. &adev->pm.dpm.dyn_state.vddgfx_dependency_on_sclk,
  698. dep_table);
  699. if (ret) {
  700. kfree(adev->pm.dpm.dyn_state.vddgfx_dependency_on_sclk.entries);
  701. return ret;
  702. }
  703. }
  704. }
  705. return 0;
  706. }
  707. void amdgpu_free_extended_power_table(struct amdgpu_device *adev)
  708. {
  709. struct amdgpu_dpm_dynamic_state *dyn_state = &adev->pm.dpm.dyn_state;
  710. kfree(dyn_state->vddc_dependency_on_sclk.entries);
  711. kfree(dyn_state->vddci_dependency_on_mclk.entries);
  712. kfree(dyn_state->vddc_dependency_on_mclk.entries);
  713. kfree(dyn_state->mvdd_dependency_on_mclk.entries);
  714. kfree(dyn_state->cac_leakage_table.entries);
  715. kfree(dyn_state->phase_shedding_limits_table.entries);
  716. kfree(dyn_state->ppm_table);
  717. kfree(dyn_state->cac_tdp_table);
  718. kfree(dyn_state->vce_clock_voltage_dependency_table.entries);
  719. kfree(dyn_state->uvd_clock_voltage_dependency_table.entries);
  720. kfree(dyn_state->samu_clock_voltage_dependency_table.entries);
  721. kfree(dyn_state->acp_clock_voltage_dependency_table.entries);
  722. kfree(dyn_state->vddgfx_dependency_on_sclk.entries);
  723. }
  724. static const char *pp_lib_thermal_controller_names[] = {
  725. "NONE",
  726. "lm63",
  727. "adm1032",
  728. "adm1030",
  729. "max6649",
  730. "lm64",
  731. "f75375",
  732. "RV6xx",
  733. "RV770",
  734. "adt7473",
  735. "NONE",
  736. "External GPIO",
  737. "Evergreen",
  738. "emc2103",
  739. "Sumo",
  740. "Northern Islands",
  741. "Southern Islands",
  742. "lm96163",
  743. "Sea Islands",
  744. "Kaveri/Kabini",
  745. };
  746. void amdgpu_add_thermal_controller(struct amdgpu_device *adev)
  747. {
  748. struct amdgpu_mode_info *mode_info = &adev->mode_info;
  749. ATOM_PPLIB_POWERPLAYTABLE *power_table;
  750. int index = GetIndexIntoMasterTable(DATA, PowerPlayInfo);
  751. ATOM_PPLIB_THERMALCONTROLLER *controller;
  752. struct amdgpu_i2c_bus_rec i2c_bus;
  753. u16 data_offset;
  754. u8 frev, crev;
  755. if (!amdgpu_atom_parse_data_header(mode_info->atom_context, index, NULL,
  756. &frev, &crev, &data_offset))
  757. return;
  758. power_table = (ATOM_PPLIB_POWERPLAYTABLE *)
  759. (mode_info->atom_context->bios + data_offset);
  760. controller = &power_table->sThermalController;
  761. /* add the i2c bus for thermal/fan chip */
  762. if (controller->ucType > 0) {
  763. if (controller->ucFanParameters & ATOM_PP_FANPARAMETERS_NOFAN)
  764. adev->pm.no_fan = true;
  765. adev->pm.fan_pulses_per_revolution =
  766. controller->ucFanParameters & ATOM_PP_FANPARAMETERS_TACHOMETER_PULSES_PER_REVOLUTION_MASK;
  767. if (adev->pm.fan_pulses_per_revolution) {
  768. adev->pm.fan_min_rpm = controller->ucFanMinRPM;
  769. adev->pm.fan_max_rpm = controller->ucFanMaxRPM;
  770. }
  771. if (controller->ucType == ATOM_PP_THERMALCONTROLLER_RV6xx) {
  772. DRM_INFO("Internal thermal controller %s fan control\n",
  773. (controller->ucFanParameters &
  774. ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
  775. adev->pm.int_thermal_type = THERMAL_TYPE_RV6XX;
  776. } else if (controller->ucType == ATOM_PP_THERMALCONTROLLER_RV770) {
  777. DRM_INFO("Internal thermal controller %s fan control\n",
  778. (controller->ucFanParameters &
  779. ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
  780. adev->pm.int_thermal_type = THERMAL_TYPE_RV770;
  781. } else if (controller->ucType == ATOM_PP_THERMALCONTROLLER_EVERGREEN) {
  782. DRM_INFO("Internal thermal controller %s fan control\n",
  783. (controller->ucFanParameters &
  784. ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
  785. adev->pm.int_thermal_type = THERMAL_TYPE_EVERGREEN;
  786. } else if (controller->ucType == ATOM_PP_THERMALCONTROLLER_SUMO) {
  787. DRM_INFO("Internal thermal controller %s fan control\n",
  788. (controller->ucFanParameters &
  789. ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
  790. adev->pm.int_thermal_type = THERMAL_TYPE_SUMO;
  791. } else if (controller->ucType == ATOM_PP_THERMALCONTROLLER_NISLANDS) {
  792. DRM_INFO("Internal thermal controller %s fan control\n",
  793. (controller->ucFanParameters &
  794. ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
  795. adev->pm.int_thermal_type = THERMAL_TYPE_NI;
  796. } else if (controller->ucType == ATOM_PP_THERMALCONTROLLER_SISLANDS) {
  797. DRM_INFO("Internal thermal controller %s fan control\n",
  798. (controller->ucFanParameters &
  799. ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
  800. adev->pm.int_thermal_type = THERMAL_TYPE_SI;
  801. } else if (controller->ucType == ATOM_PP_THERMALCONTROLLER_CISLANDS) {
  802. DRM_INFO("Internal thermal controller %s fan control\n",
  803. (controller->ucFanParameters &
  804. ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
  805. adev->pm.int_thermal_type = THERMAL_TYPE_CI;
  806. } else if (controller->ucType == ATOM_PP_THERMALCONTROLLER_KAVERI) {
  807. DRM_INFO("Internal thermal controller %s fan control\n",
  808. (controller->ucFanParameters &
  809. ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
  810. adev->pm.int_thermal_type = THERMAL_TYPE_KV;
  811. } else if (controller->ucType == ATOM_PP_THERMALCONTROLLER_EXTERNAL_GPIO) {
  812. DRM_INFO("External GPIO thermal controller %s fan control\n",
  813. (controller->ucFanParameters &
  814. ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
  815. adev->pm.int_thermal_type = THERMAL_TYPE_EXTERNAL_GPIO;
  816. } else if (controller->ucType ==
  817. ATOM_PP_THERMALCONTROLLER_ADT7473_WITH_INTERNAL) {
  818. DRM_INFO("ADT7473 with internal thermal controller %s fan control\n",
  819. (controller->ucFanParameters &
  820. ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
  821. adev->pm.int_thermal_type = THERMAL_TYPE_ADT7473_WITH_INTERNAL;
  822. } else if (controller->ucType ==
  823. ATOM_PP_THERMALCONTROLLER_EMC2103_WITH_INTERNAL) {
  824. DRM_INFO("EMC2103 with internal thermal controller %s fan control\n",
  825. (controller->ucFanParameters &
  826. ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
  827. adev->pm.int_thermal_type = THERMAL_TYPE_EMC2103_WITH_INTERNAL;
  828. } else if (controller->ucType < ARRAY_SIZE(pp_lib_thermal_controller_names)) {
  829. DRM_INFO("Possible %s thermal controller at 0x%02x %s fan control\n",
  830. pp_lib_thermal_controller_names[controller->ucType],
  831. controller->ucI2cAddress >> 1,
  832. (controller->ucFanParameters &
  833. ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
  834. adev->pm.int_thermal_type = THERMAL_TYPE_EXTERNAL;
  835. i2c_bus = amdgpu_atombios_lookup_i2c_gpio(adev, controller->ucI2cLine);
  836. adev->pm.i2c_bus = amdgpu_i2c_lookup(adev, &i2c_bus);
  837. if (adev->pm.i2c_bus) {
  838. struct i2c_board_info info = { };
  839. const char *name = pp_lib_thermal_controller_names[controller->ucType];
  840. info.addr = controller->ucI2cAddress >> 1;
  841. strlcpy(info.type, name, sizeof(info.type));
  842. i2c_new_device(&adev->pm.i2c_bus->adapter, &info);
  843. }
  844. } else {
  845. DRM_INFO("Unknown thermal controller type %d at 0x%02x %s fan control\n",
  846. controller->ucType,
  847. controller->ucI2cAddress >> 1,
  848. (controller->ucFanParameters &
  849. ATOM_PP_FANPARAMETERS_NOFAN) ? "without" : "with");
  850. }
  851. }
  852. }
  853. enum amdgpu_pcie_gen amdgpu_get_pcie_gen_support(struct amdgpu_device *adev,
  854. u32 sys_mask,
  855. enum amdgpu_pcie_gen asic_gen,
  856. enum amdgpu_pcie_gen default_gen)
  857. {
  858. switch (asic_gen) {
  859. case AMDGPU_PCIE_GEN1:
  860. return AMDGPU_PCIE_GEN1;
  861. case AMDGPU_PCIE_GEN2:
  862. return AMDGPU_PCIE_GEN2;
  863. case AMDGPU_PCIE_GEN3:
  864. return AMDGPU_PCIE_GEN3;
  865. default:
  866. if ((sys_mask & DRM_PCIE_SPEED_80) && (default_gen == AMDGPU_PCIE_GEN3))
  867. return AMDGPU_PCIE_GEN3;
  868. else if ((sys_mask & DRM_PCIE_SPEED_50) && (default_gen == AMDGPU_PCIE_GEN2))
  869. return AMDGPU_PCIE_GEN2;
  870. else
  871. return AMDGPU_PCIE_GEN1;
  872. }
  873. return AMDGPU_PCIE_GEN1;
  874. }
  875. u16 amdgpu_get_pcie_lane_support(struct amdgpu_device *adev,
  876. u16 asic_lanes,
  877. u16 default_lanes)
  878. {
  879. switch (asic_lanes) {
  880. case 0:
  881. default:
  882. return default_lanes;
  883. case 1:
  884. return 1;
  885. case 2:
  886. return 2;
  887. case 4:
  888. return 4;
  889. case 8:
  890. return 8;
  891. case 12:
  892. return 12;
  893. case 16:
  894. return 16;
  895. }
  896. }
  897. u8 amdgpu_encode_pci_lane_width(u32 lanes)
  898. {
  899. u8 encoded_lanes[] = { 0, 1, 2, 0, 3, 0, 0, 0, 4, 0, 0, 0, 5, 0, 0, 0, 6 };
  900. if (lanes > 16)
  901. return 0;
  902. return encoded_lanes[lanes];
  903. }