amdgpu_pm.c 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621
  1. /*
  2. * Permission is hereby granted, free of charge, to any person obtaining a
  3. * copy of this software and associated documentation files (the "Software"),
  4. * to deal in the Software without restriction, including without limitation
  5. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  6. * and/or sell copies of the Software, and to permit persons to whom the
  7. * Software is furnished to do so, subject to the following conditions:
  8. *
  9. * The above copyright notice and this permission notice shall be included in
  10. * all copies or substantial portions of the Software.
  11. *
  12. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  15. * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  16. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  17. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  18. * OTHER DEALINGS IN THE SOFTWARE.
  19. *
  20. * Authors: Rafał Miłecki <zajec5@gmail.com>
  21. * Alex Deucher <alexdeucher@gmail.com>
  22. */
  23. #include <drm/drmP.h>
  24. #include "amdgpu.h"
  25. #include "amdgpu_drv.h"
  26. #include "amdgpu_pm.h"
  27. #include "amdgpu_dpm.h"
  28. #include "atom.h"
  29. #include <linux/power_supply.h>
  30. #include <linux/hwmon.h>
  31. #include <linux/hwmon-sysfs.h>
  32. #include "amd_powerplay.h"
  33. static int amdgpu_debugfs_pm_init(struct amdgpu_device *adev);
  34. static const struct cg_flag_name clocks[] = {
  35. {AMD_CG_SUPPORT_GFX_MGCG, "Graphics Medium Grain Clock Gating"},
  36. {AMD_CG_SUPPORT_GFX_MGLS, "Graphics Medium Grain memory Light Sleep"},
  37. {AMD_CG_SUPPORT_GFX_CGCG, "Graphics Coarse Grain Clock Gating"},
  38. {AMD_CG_SUPPORT_GFX_CGLS, "Graphics Coarse Grain memory Light Sleep"},
  39. {AMD_CG_SUPPORT_GFX_CGTS, "Graphics Coarse Grain Tree Shader Clock Gating"},
  40. {AMD_CG_SUPPORT_GFX_CGTS_LS, "Graphics Coarse Grain Tree Shader Light Sleep"},
  41. {AMD_CG_SUPPORT_GFX_CP_LS, "Graphics Command Processor Light Sleep"},
  42. {AMD_CG_SUPPORT_GFX_RLC_LS, "Graphics Run List Controller Light Sleep"},
  43. {AMD_CG_SUPPORT_GFX_3D_CGCG, "Graphics 3D Coarse Grain Clock Gating"},
  44. {AMD_CG_SUPPORT_GFX_3D_CGLS, "Graphics 3D Coarse Grain memory Light Sleep"},
  45. {AMD_CG_SUPPORT_MC_LS, "Memory Controller Light Sleep"},
  46. {AMD_CG_SUPPORT_MC_MGCG, "Memory Controller Medium Grain Clock Gating"},
  47. {AMD_CG_SUPPORT_SDMA_LS, "System Direct Memory Access Light Sleep"},
  48. {AMD_CG_SUPPORT_SDMA_MGCG, "System Direct Memory Access Medium Grain Clock Gating"},
  49. {AMD_CG_SUPPORT_BIF_MGCG, "Bus Interface Medium Grain Clock Gating"},
  50. {AMD_CG_SUPPORT_BIF_LS, "Bus Interface Light Sleep"},
  51. {AMD_CG_SUPPORT_UVD_MGCG, "Unified Video Decoder Medium Grain Clock Gating"},
  52. {AMD_CG_SUPPORT_VCE_MGCG, "Video Compression Engine Medium Grain Clock Gating"},
  53. {AMD_CG_SUPPORT_HDP_LS, "Host Data Path Light Sleep"},
  54. {AMD_CG_SUPPORT_HDP_MGCG, "Host Data Path Medium Grain Clock Gating"},
  55. {AMD_CG_SUPPORT_DRM_MGCG, "Digital Right Management Medium Grain Clock Gating"},
  56. {AMD_CG_SUPPORT_DRM_LS, "Digital Right Management Light Sleep"},
  57. {AMD_CG_SUPPORT_ROM_MGCG, "Rom Medium Grain Clock Gating"},
  58. {AMD_CG_SUPPORT_DF_MGCG, "Data Fabric Medium Grain Clock Gating"},
  59. {0, NULL},
  60. };
  61. void amdgpu_pm_acpi_event_handler(struct amdgpu_device *adev)
  62. {
  63. if (adev->pp_enabled)
  64. /* TODO */
  65. return;
  66. if (adev->pm.dpm_enabled) {
  67. mutex_lock(&adev->pm.mutex);
  68. if (power_supply_is_system_supplied() > 0)
  69. adev->pm.dpm.ac_power = true;
  70. else
  71. adev->pm.dpm.ac_power = false;
  72. if (adev->powerplay.pp_funcs->enable_bapm)
  73. amdgpu_dpm_enable_bapm(adev, adev->pm.dpm.ac_power);
  74. mutex_unlock(&adev->pm.mutex);
  75. }
  76. }
  77. static ssize_t amdgpu_get_dpm_state(struct device *dev,
  78. struct device_attribute *attr,
  79. char *buf)
  80. {
  81. struct drm_device *ddev = dev_get_drvdata(dev);
  82. struct amdgpu_device *adev = ddev->dev_private;
  83. enum amd_pm_state_type pm;
  84. if (adev->powerplay.pp_funcs->get_current_power_state)
  85. pm = amdgpu_dpm_get_current_power_state(adev);
  86. else
  87. pm = adev->pm.dpm.user_state;
  88. return snprintf(buf, PAGE_SIZE, "%s\n",
  89. (pm == POWER_STATE_TYPE_BATTERY) ? "battery" :
  90. (pm == POWER_STATE_TYPE_BALANCED) ? "balanced" : "performance");
  91. }
  92. static ssize_t amdgpu_set_dpm_state(struct device *dev,
  93. struct device_attribute *attr,
  94. const char *buf,
  95. size_t count)
  96. {
  97. struct drm_device *ddev = dev_get_drvdata(dev);
  98. struct amdgpu_device *adev = ddev->dev_private;
  99. enum amd_pm_state_type state;
  100. if (strncmp("battery", buf, strlen("battery")) == 0)
  101. state = POWER_STATE_TYPE_BATTERY;
  102. else if (strncmp("balanced", buf, strlen("balanced")) == 0)
  103. state = POWER_STATE_TYPE_BALANCED;
  104. else if (strncmp("performance", buf, strlen("performance")) == 0)
  105. state = POWER_STATE_TYPE_PERFORMANCE;
  106. else {
  107. count = -EINVAL;
  108. goto fail;
  109. }
  110. if (adev->pp_enabled) {
  111. amdgpu_dpm_dispatch_task(adev, AMD_PP_TASK_ENABLE_USER_STATE, &state, NULL);
  112. } else {
  113. mutex_lock(&adev->pm.mutex);
  114. adev->pm.dpm.user_state = state;
  115. mutex_unlock(&adev->pm.mutex);
  116. /* Can't set dpm state when the card is off */
  117. if (!(adev->flags & AMD_IS_PX) ||
  118. (ddev->switch_power_state == DRM_SWITCH_POWER_ON))
  119. amdgpu_pm_compute_clocks(adev);
  120. }
  121. fail:
  122. return count;
  123. }
  124. static ssize_t amdgpu_get_dpm_forced_performance_level(struct device *dev,
  125. struct device_attribute *attr,
  126. char *buf)
  127. {
  128. struct drm_device *ddev = dev_get_drvdata(dev);
  129. struct amdgpu_device *adev = ddev->dev_private;
  130. enum amd_dpm_forced_level level = 0xff;
  131. if ((adev->flags & AMD_IS_PX) &&
  132. (ddev->switch_power_state != DRM_SWITCH_POWER_ON))
  133. return snprintf(buf, PAGE_SIZE, "off\n");
  134. if (adev->powerplay.pp_funcs->get_performance_level)
  135. level = amdgpu_dpm_get_performance_level(adev);
  136. else
  137. level = adev->pm.dpm.forced_level;
  138. return snprintf(buf, PAGE_SIZE, "%s\n",
  139. (level == AMD_DPM_FORCED_LEVEL_AUTO) ? "auto" :
  140. (level == AMD_DPM_FORCED_LEVEL_LOW) ? "low" :
  141. (level == AMD_DPM_FORCED_LEVEL_HIGH) ? "high" :
  142. (level == AMD_DPM_FORCED_LEVEL_MANUAL) ? "manual" :
  143. (level == AMD_DPM_FORCED_LEVEL_PROFILE_STANDARD) ? "profile_standard" :
  144. (level == AMD_DPM_FORCED_LEVEL_PROFILE_MIN_SCLK) ? "profile_min_sclk" :
  145. (level == AMD_DPM_FORCED_LEVEL_PROFILE_MIN_MCLK) ? "profile_min_mclk" :
  146. (level == AMD_DPM_FORCED_LEVEL_PROFILE_PEAK) ? "profile_peak" :
  147. "unknown");
  148. }
  149. static ssize_t amdgpu_set_dpm_forced_performance_level(struct device *dev,
  150. struct device_attribute *attr,
  151. const char *buf,
  152. size_t count)
  153. {
  154. struct drm_device *ddev = dev_get_drvdata(dev);
  155. struct amdgpu_device *adev = ddev->dev_private;
  156. enum amd_dpm_forced_level level;
  157. enum amd_dpm_forced_level current_level = 0xff;
  158. int ret = 0;
  159. /* Can't force performance level when the card is off */
  160. if ((adev->flags & AMD_IS_PX) &&
  161. (ddev->switch_power_state != DRM_SWITCH_POWER_ON))
  162. return -EINVAL;
  163. if (adev->powerplay.pp_funcs->get_performance_level)
  164. current_level = amdgpu_dpm_get_performance_level(adev);
  165. if (strncmp("low", buf, strlen("low")) == 0) {
  166. level = AMD_DPM_FORCED_LEVEL_LOW;
  167. } else if (strncmp("high", buf, strlen("high")) == 0) {
  168. level = AMD_DPM_FORCED_LEVEL_HIGH;
  169. } else if (strncmp("auto", buf, strlen("auto")) == 0) {
  170. level = AMD_DPM_FORCED_LEVEL_AUTO;
  171. } else if (strncmp("manual", buf, strlen("manual")) == 0) {
  172. level = AMD_DPM_FORCED_LEVEL_MANUAL;
  173. } else if (strncmp("profile_exit", buf, strlen("profile_exit")) == 0) {
  174. level = AMD_DPM_FORCED_LEVEL_PROFILE_EXIT;
  175. } else if (strncmp("profile_standard", buf, strlen("profile_standard")) == 0) {
  176. level = AMD_DPM_FORCED_LEVEL_PROFILE_STANDARD;
  177. } else if (strncmp("profile_min_sclk", buf, strlen("profile_min_sclk")) == 0) {
  178. level = AMD_DPM_FORCED_LEVEL_PROFILE_MIN_SCLK;
  179. } else if (strncmp("profile_min_mclk", buf, strlen("profile_min_mclk")) == 0) {
  180. level = AMD_DPM_FORCED_LEVEL_PROFILE_MIN_MCLK;
  181. } else if (strncmp("profile_peak", buf, strlen("profile_peak")) == 0) {
  182. level = AMD_DPM_FORCED_LEVEL_PROFILE_PEAK;
  183. } else {
  184. count = -EINVAL;
  185. goto fail;
  186. }
  187. if (current_level == level)
  188. return count;
  189. if (adev->powerplay.pp_funcs->force_performance_level) {
  190. mutex_lock(&adev->pm.mutex);
  191. if (adev->pm.dpm.thermal_active) {
  192. count = -EINVAL;
  193. mutex_unlock(&adev->pm.mutex);
  194. goto fail;
  195. }
  196. ret = amdgpu_dpm_force_performance_level(adev, level);
  197. if (ret)
  198. count = -EINVAL;
  199. else
  200. adev->pm.dpm.forced_level = level;
  201. mutex_unlock(&adev->pm.mutex);
  202. }
  203. fail:
  204. return count;
  205. }
  206. static ssize_t amdgpu_get_pp_num_states(struct device *dev,
  207. struct device_attribute *attr,
  208. char *buf)
  209. {
  210. struct drm_device *ddev = dev_get_drvdata(dev);
  211. struct amdgpu_device *adev = ddev->dev_private;
  212. struct pp_states_info data;
  213. int i, buf_len;
  214. if (adev->powerplay.pp_funcs->get_pp_num_states)
  215. amdgpu_dpm_get_pp_num_states(adev, &data);
  216. buf_len = snprintf(buf, PAGE_SIZE, "states: %d\n", data.nums);
  217. for (i = 0; i < data.nums; i++)
  218. buf_len += snprintf(buf + buf_len, PAGE_SIZE, "%d %s\n", i,
  219. (data.states[i] == POWER_STATE_TYPE_INTERNAL_BOOT) ? "boot" :
  220. (data.states[i] == POWER_STATE_TYPE_BATTERY) ? "battery" :
  221. (data.states[i] == POWER_STATE_TYPE_BALANCED) ? "balanced" :
  222. (data.states[i] == POWER_STATE_TYPE_PERFORMANCE) ? "performance" : "default");
  223. return buf_len;
  224. }
  225. static ssize_t amdgpu_get_pp_cur_state(struct device *dev,
  226. struct device_attribute *attr,
  227. char *buf)
  228. {
  229. struct drm_device *ddev = dev_get_drvdata(dev);
  230. struct amdgpu_device *adev = ddev->dev_private;
  231. struct pp_states_info data;
  232. enum amd_pm_state_type pm = 0;
  233. int i = 0;
  234. if (adev->powerplay.pp_funcs->get_current_power_state
  235. && adev->powerplay.pp_funcs->get_pp_num_states) {
  236. pm = amdgpu_dpm_get_current_power_state(adev);
  237. amdgpu_dpm_get_pp_num_states(adev, &data);
  238. for (i = 0; i < data.nums; i++) {
  239. if (pm == data.states[i])
  240. break;
  241. }
  242. if (i == data.nums)
  243. i = -EINVAL;
  244. }
  245. return snprintf(buf, PAGE_SIZE, "%d\n", i);
  246. }
  247. static ssize_t amdgpu_get_pp_force_state(struct device *dev,
  248. struct device_attribute *attr,
  249. char *buf)
  250. {
  251. struct drm_device *ddev = dev_get_drvdata(dev);
  252. struct amdgpu_device *adev = ddev->dev_private;
  253. if (adev->pp_force_state_enabled)
  254. return amdgpu_get_pp_cur_state(dev, attr, buf);
  255. else
  256. return snprintf(buf, PAGE_SIZE, "\n");
  257. }
  258. static ssize_t amdgpu_set_pp_force_state(struct device *dev,
  259. struct device_attribute *attr,
  260. const char *buf,
  261. size_t count)
  262. {
  263. struct drm_device *ddev = dev_get_drvdata(dev);
  264. struct amdgpu_device *adev = ddev->dev_private;
  265. enum amd_pm_state_type state = 0;
  266. unsigned long idx;
  267. int ret;
  268. if (strlen(buf) == 1)
  269. adev->pp_force_state_enabled = false;
  270. else if (adev->pp_enabled) {
  271. struct pp_states_info data;
  272. ret = kstrtoul(buf, 0, &idx);
  273. if (ret || idx >= ARRAY_SIZE(data.states)) {
  274. count = -EINVAL;
  275. goto fail;
  276. }
  277. amdgpu_dpm_get_pp_num_states(adev, &data);
  278. state = data.states[idx];
  279. /* only set user selected power states */
  280. if (state != POWER_STATE_TYPE_INTERNAL_BOOT &&
  281. state != POWER_STATE_TYPE_DEFAULT) {
  282. amdgpu_dpm_dispatch_task(adev,
  283. AMD_PP_TASK_ENABLE_USER_STATE, &state, NULL);
  284. adev->pp_force_state_enabled = true;
  285. }
  286. }
  287. fail:
  288. return count;
  289. }
  290. static ssize_t amdgpu_get_pp_table(struct device *dev,
  291. struct device_attribute *attr,
  292. char *buf)
  293. {
  294. struct drm_device *ddev = dev_get_drvdata(dev);
  295. struct amdgpu_device *adev = ddev->dev_private;
  296. char *table = NULL;
  297. int size;
  298. if (adev->powerplay.pp_funcs->get_pp_table)
  299. size = amdgpu_dpm_get_pp_table(adev, &table);
  300. else
  301. return 0;
  302. if (size >= PAGE_SIZE)
  303. size = PAGE_SIZE - 1;
  304. memcpy(buf, table, size);
  305. return size;
  306. }
  307. static ssize_t amdgpu_set_pp_table(struct device *dev,
  308. struct device_attribute *attr,
  309. const char *buf,
  310. size_t count)
  311. {
  312. struct drm_device *ddev = dev_get_drvdata(dev);
  313. struct amdgpu_device *adev = ddev->dev_private;
  314. if (adev->powerplay.pp_funcs->set_pp_table)
  315. amdgpu_dpm_set_pp_table(adev, buf, count);
  316. return count;
  317. }
  318. static ssize_t amdgpu_get_pp_dpm_sclk(struct device *dev,
  319. struct device_attribute *attr,
  320. char *buf)
  321. {
  322. struct drm_device *ddev = dev_get_drvdata(dev);
  323. struct amdgpu_device *adev = ddev->dev_private;
  324. if (adev->powerplay.pp_funcs->print_clock_levels)
  325. return amdgpu_dpm_print_clock_levels(adev, PP_SCLK, buf);
  326. else
  327. return snprintf(buf, PAGE_SIZE, "\n");
  328. }
  329. static ssize_t amdgpu_set_pp_dpm_sclk(struct device *dev,
  330. struct device_attribute *attr,
  331. const char *buf,
  332. size_t count)
  333. {
  334. struct drm_device *ddev = dev_get_drvdata(dev);
  335. struct amdgpu_device *adev = ddev->dev_private;
  336. int ret;
  337. long level;
  338. uint32_t i, mask = 0;
  339. char sub_str[2];
  340. for (i = 0; i < strlen(buf); i++) {
  341. if (*(buf + i) == '\n')
  342. continue;
  343. sub_str[0] = *(buf + i);
  344. sub_str[1] = '\0';
  345. ret = kstrtol(sub_str, 0, &level);
  346. if (ret) {
  347. count = -EINVAL;
  348. goto fail;
  349. }
  350. mask |= 1 << level;
  351. }
  352. if (adev->powerplay.pp_funcs->force_clock_level)
  353. amdgpu_dpm_force_clock_level(adev, PP_SCLK, mask);
  354. fail:
  355. return count;
  356. }
  357. static ssize_t amdgpu_get_pp_dpm_mclk(struct device *dev,
  358. struct device_attribute *attr,
  359. char *buf)
  360. {
  361. struct drm_device *ddev = dev_get_drvdata(dev);
  362. struct amdgpu_device *adev = ddev->dev_private;
  363. if (adev->powerplay.pp_funcs->print_clock_levels)
  364. return amdgpu_dpm_print_clock_levels(adev, PP_MCLK, buf);
  365. else
  366. return snprintf(buf, PAGE_SIZE, "\n");
  367. }
  368. static ssize_t amdgpu_set_pp_dpm_mclk(struct device *dev,
  369. struct device_attribute *attr,
  370. const char *buf,
  371. size_t count)
  372. {
  373. struct drm_device *ddev = dev_get_drvdata(dev);
  374. struct amdgpu_device *adev = ddev->dev_private;
  375. int ret;
  376. long level;
  377. uint32_t i, mask = 0;
  378. char sub_str[2];
  379. for (i = 0; i < strlen(buf); i++) {
  380. if (*(buf + i) == '\n')
  381. continue;
  382. sub_str[0] = *(buf + i);
  383. sub_str[1] = '\0';
  384. ret = kstrtol(sub_str, 0, &level);
  385. if (ret) {
  386. count = -EINVAL;
  387. goto fail;
  388. }
  389. mask |= 1 << level;
  390. }
  391. if (adev->powerplay.pp_funcs->force_clock_level)
  392. amdgpu_dpm_force_clock_level(adev, PP_MCLK, mask);
  393. fail:
  394. return count;
  395. }
  396. static ssize_t amdgpu_get_pp_dpm_pcie(struct device *dev,
  397. struct device_attribute *attr,
  398. char *buf)
  399. {
  400. struct drm_device *ddev = dev_get_drvdata(dev);
  401. struct amdgpu_device *adev = ddev->dev_private;
  402. if (adev->powerplay.pp_funcs->print_clock_levels)
  403. return amdgpu_dpm_print_clock_levels(adev, PP_PCIE, buf);
  404. else
  405. return snprintf(buf, PAGE_SIZE, "\n");
  406. }
  407. static ssize_t amdgpu_set_pp_dpm_pcie(struct device *dev,
  408. struct device_attribute *attr,
  409. const char *buf,
  410. size_t count)
  411. {
  412. struct drm_device *ddev = dev_get_drvdata(dev);
  413. struct amdgpu_device *adev = ddev->dev_private;
  414. int ret;
  415. long level;
  416. uint32_t i, mask = 0;
  417. char sub_str[2];
  418. for (i = 0; i < strlen(buf); i++) {
  419. if (*(buf + i) == '\n')
  420. continue;
  421. sub_str[0] = *(buf + i);
  422. sub_str[1] = '\0';
  423. ret = kstrtol(sub_str, 0, &level);
  424. if (ret) {
  425. count = -EINVAL;
  426. goto fail;
  427. }
  428. mask |= 1 << level;
  429. }
  430. if (adev->powerplay.pp_funcs->force_clock_level)
  431. amdgpu_dpm_force_clock_level(adev, PP_PCIE, mask);
  432. fail:
  433. return count;
  434. }
  435. static ssize_t amdgpu_get_pp_sclk_od(struct device *dev,
  436. struct device_attribute *attr,
  437. char *buf)
  438. {
  439. struct drm_device *ddev = dev_get_drvdata(dev);
  440. struct amdgpu_device *adev = ddev->dev_private;
  441. uint32_t value = 0;
  442. if (adev->powerplay.pp_funcs->get_sclk_od)
  443. value = amdgpu_dpm_get_sclk_od(adev);
  444. return snprintf(buf, PAGE_SIZE, "%d\n", value);
  445. }
  446. static ssize_t amdgpu_set_pp_sclk_od(struct device *dev,
  447. struct device_attribute *attr,
  448. const char *buf,
  449. size_t count)
  450. {
  451. struct drm_device *ddev = dev_get_drvdata(dev);
  452. struct amdgpu_device *adev = ddev->dev_private;
  453. int ret;
  454. long int value;
  455. ret = kstrtol(buf, 0, &value);
  456. if (ret) {
  457. count = -EINVAL;
  458. goto fail;
  459. }
  460. if (adev->powerplay.pp_funcs->set_sclk_od)
  461. amdgpu_dpm_set_sclk_od(adev, (uint32_t)value);
  462. if (adev->pp_enabled) {
  463. amdgpu_dpm_dispatch_task(adev, AMD_PP_TASK_READJUST_POWER_STATE, NULL, NULL);
  464. } else {
  465. adev->pm.dpm.current_ps = adev->pm.dpm.boot_ps;
  466. amdgpu_pm_compute_clocks(adev);
  467. }
  468. fail:
  469. return count;
  470. }
  471. static ssize_t amdgpu_get_pp_mclk_od(struct device *dev,
  472. struct device_attribute *attr,
  473. char *buf)
  474. {
  475. struct drm_device *ddev = dev_get_drvdata(dev);
  476. struct amdgpu_device *adev = ddev->dev_private;
  477. uint32_t value = 0;
  478. if (adev->powerplay.pp_funcs->get_mclk_od)
  479. value = amdgpu_dpm_get_mclk_od(adev);
  480. return snprintf(buf, PAGE_SIZE, "%d\n", value);
  481. }
  482. static ssize_t amdgpu_set_pp_mclk_od(struct device *dev,
  483. struct device_attribute *attr,
  484. const char *buf,
  485. size_t count)
  486. {
  487. struct drm_device *ddev = dev_get_drvdata(dev);
  488. struct amdgpu_device *adev = ddev->dev_private;
  489. int ret;
  490. long int value;
  491. ret = kstrtol(buf, 0, &value);
  492. if (ret) {
  493. count = -EINVAL;
  494. goto fail;
  495. }
  496. if (adev->powerplay.pp_funcs->set_mclk_od)
  497. amdgpu_dpm_set_mclk_od(adev, (uint32_t)value);
  498. if (adev->pp_enabled) {
  499. amdgpu_dpm_dispatch_task(adev, AMD_PP_TASK_READJUST_POWER_STATE, NULL, NULL);
  500. } else {
  501. adev->pm.dpm.current_ps = adev->pm.dpm.boot_ps;
  502. amdgpu_pm_compute_clocks(adev);
  503. }
  504. fail:
  505. return count;
  506. }
  507. static ssize_t amdgpu_get_pp_power_profile(struct device *dev,
  508. char *buf, struct amd_pp_profile *query)
  509. {
  510. struct drm_device *ddev = dev_get_drvdata(dev);
  511. struct amdgpu_device *adev = ddev->dev_private;
  512. int ret = 0xff;
  513. if (adev->powerplay.pp_funcs->get_power_profile_state)
  514. ret = amdgpu_dpm_get_power_profile_state(
  515. adev, query);
  516. if (ret)
  517. return ret;
  518. return snprintf(buf, PAGE_SIZE,
  519. "%d %d %d %d %d\n",
  520. query->min_sclk / 100,
  521. query->min_mclk / 100,
  522. query->activity_threshold,
  523. query->up_hyst,
  524. query->down_hyst);
  525. }
  526. static ssize_t amdgpu_get_pp_gfx_power_profile(struct device *dev,
  527. struct device_attribute *attr,
  528. char *buf)
  529. {
  530. struct amd_pp_profile query = {0};
  531. query.type = AMD_PP_GFX_PROFILE;
  532. return amdgpu_get_pp_power_profile(dev, buf, &query);
  533. }
  534. static ssize_t amdgpu_get_pp_compute_power_profile(struct device *dev,
  535. struct device_attribute *attr,
  536. char *buf)
  537. {
  538. struct amd_pp_profile query = {0};
  539. query.type = AMD_PP_COMPUTE_PROFILE;
  540. return amdgpu_get_pp_power_profile(dev, buf, &query);
  541. }
  542. static ssize_t amdgpu_set_pp_power_profile(struct device *dev,
  543. const char *buf,
  544. size_t count,
  545. struct amd_pp_profile *request)
  546. {
  547. struct drm_device *ddev = dev_get_drvdata(dev);
  548. struct amdgpu_device *adev = ddev->dev_private;
  549. uint32_t loop = 0;
  550. char *sub_str, buf_cpy[128], *tmp_str;
  551. const char delimiter[3] = {' ', '\n', '\0'};
  552. long int value;
  553. int ret = 0xff;
  554. if (strncmp("reset", buf, strlen("reset")) == 0) {
  555. if (adev->powerplay.pp_funcs->reset_power_profile_state)
  556. ret = amdgpu_dpm_reset_power_profile_state(
  557. adev, request);
  558. if (ret) {
  559. count = -EINVAL;
  560. goto fail;
  561. }
  562. return count;
  563. }
  564. if (strncmp("set", buf, strlen("set")) == 0) {
  565. if (adev->powerplay.pp_funcs->set_power_profile_state)
  566. ret = amdgpu_dpm_set_power_profile_state(
  567. adev, request);
  568. if (ret) {
  569. count = -EINVAL;
  570. goto fail;
  571. }
  572. return count;
  573. }
  574. if (count + 1 >= 128) {
  575. count = -EINVAL;
  576. goto fail;
  577. }
  578. memcpy(buf_cpy, buf, count + 1);
  579. tmp_str = buf_cpy;
  580. while (tmp_str[0]) {
  581. sub_str = strsep(&tmp_str, delimiter);
  582. ret = kstrtol(sub_str, 0, &value);
  583. if (ret) {
  584. count = -EINVAL;
  585. goto fail;
  586. }
  587. switch (loop) {
  588. case 0:
  589. /* input unit MHz convert to dpm table unit 10KHz*/
  590. request->min_sclk = (uint32_t)value * 100;
  591. break;
  592. case 1:
  593. /* input unit MHz convert to dpm table unit 10KHz*/
  594. request->min_mclk = (uint32_t)value * 100;
  595. break;
  596. case 2:
  597. request->activity_threshold = (uint16_t)value;
  598. break;
  599. case 3:
  600. request->up_hyst = (uint8_t)value;
  601. break;
  602. case 4:
  603. request->down_hyst = (uint8_t)value;
  604. break;
  605. default:
  606. break;
  607. }
  608. loop++;
  609. }
  610. if (adev->powerplay.pp_funcs->set_power_profile_state)
  611. ret = amdgpu_dpm_set_power_profile_state(adev, request);
  612. if (ret)
  613. count = -EINVAL;
  614. fail:
  615. return count;
  616. }
  617. static ssize_t amdgpu_set_pp_gfx_power_profile(struct device *dev,
  618. struct device_attribute *attr,
  619. const char *buf,
  620. size_t count)
  621. {
  622. struct amd_pp_profile request = {0};
  623. request.type = AMD_PP_GFX_PROFILE;
  624. return amdgpu_set_pp_power_profile(dev, buf, count, &request);
  625. }
  626. static ssize_t amdgpu_set_pp_compute_power_profile(struct device *dev,
  627. struct device_attribute *attr,
  628. const char *buf,
  629. size_t count)
  630. {
  631. struct amd_pp_profile request = {0};
  632. request.type = AMD_PP_COMPUTE_PROFILE;
  633. return amdgpu_set_pp_power_profile(dev, buf, count, &request);
  634. }
  635. static DEVICE_ATTR(power_dpm_state, S_IRUGO | S_IWUSR, amdgpu_get_dpm_state, amdgpu_set_dpm_state);
  636. static DEVICE_ATTR(power_dpm_force_performance_level, S_IRUGO | S_IWUSR,
  637. amdgpu_get_dpm_forced_performance_level,
  638. amdgpu_set_dpm_forced_performance_level);
  639. static DEVICE_ATTR(pp_num_states, S_IRUGO, amdgpu_get_pp_num_states, NULL);
  640. static DEVICE_ATTR(pp_cur_state, S_IRUGO, amdgpu_get_pp_cur_state, NULL);
  641. static DEVICE_ATTR(pp_force_state, S_IRUGO | S_IWUSR,
  642. amdgpu_get_pp_force_state,
  643. amdgpu_set_pp_force_state);
  644. static DEVICE_ATTR(pp_table, S_IRUGO | S_IWUSR,
  645. amdgpu_get_pp_table,
  646. amdgpu_set_pp_table);
  647. static DEVICE_ATTR(pp_dpm_sclk, S_IRUGO | S_IWUSR,
  648. amdgpu_get_pp_dpm_sclk,
  649. amdgpu_set_pp_dpm_sclk);
  650. static DEVICE_ATTR(pp_dpm_mclk, S_IRUGO | S_IWUSR,
  651. amdgpu_get_pp_dpm_mclk,
  652. amdgpu_set_pp_dpm_mclk);
  653. static DEVICE_ATTR(pp_dpm_pcie, S_IRUGO | S_IWUSR,
  654. amdgpu_get_pp_dpm_pcie,
  655. amdgpu_set_pp_dpm_pcie);
  656. static DEVICE_ATTR(pp_sclk_od, S_IRUGO | S_IWUSR,
  657. amdgpu_get_pp_sclk_od,
  658. amdgpu_set_pp_sclk_od);
  659. static DEVICE_ATTR(pp_mclk_od, S_IRUGO | S_IWUSR,
  660. amdgpu_get_pp_mclk_od,
  661. amdgpu_set_pp_mclk_od);
  662. static DEVICE_ATTR(pp_gfx_power_profile, S_IRUGO | S_IWUSR,
  663. amdgpu_get_pp_gfx_power_profile,
  664. amdgpu_set_pp_gfx_power_profile);
  665. static DEVICE_ATTR(pp_compute_power_profile, S_IRUGO | S_IWUSR,
  666. amdgpu_get_pp_compute_power_profile,
  667. amdgpu_set_pp_compute_power_profile);
  668. static ssize_t amdgpu_hwmon_show_temp(struct device *dev,
  669. struct device_attribute *attr,
  670. char *buf)
  671. {
  672. struct amdgpu_device *adev = dev_get_drvdata(dev);
  673. struct drm_device *ddev = adev->ddev;
  674. int temp;
  675. /* Can't get temperature when the card is off */
  676. if ((adev->flags & AMD_IS_PX) &&
  677. (ddev->switch_power_state != DRM_SWITCH_POWER_ON))
  678. return -EINVAL;
  679. if (!adev->powerplay.pp_funcs->get_temperature)
  680. temp = 0;
  681. else
  682. temp = amdgpu_dpm_get_temperature(adev);
  683. return snprintf(buf, PAGE_SIZE, "%d\n", temp);
  684. }
  685. static ssize_t amdgpu_hwmon_show_temp_thresh(struct device *dev,
  686. struct device_attribute *attr,
  687. char *buf)
  688. {
  689. struct amdgpu_device *adev = dev_get_drvdata(dev);
  690. int hyst = to_sensor_dev_attr(attr)->index;
  691. int temp;
  692. if (hyst)
  693. temp = adev->pm.dpm.thermal.min_temp;
  694. else
  695. temp = adev->pm.dpm.thermal.max_temp;
  696. return snprintf(buf, PAGE_SIZE, "%d\n", temp);
  697. }
  698. static ssize_t amdgpu_hwmon_get_pwm1_enable(struct device *dev,
  699. struct device_attribute *attr,
  700. char *buf)
  701. {
  702. struct amdgpu_device *adev = dev_get_drvdata(dev);
  703. u32 pwm_mode = 0;
  704. if (!adev->powerplay.pp_funcs->get_fan_control_mode)
  705. return -EINVAL;
  706. pwm_mode = amdgpu_dpm_get_fan_control_mode(adev);
  707. return sprintf(buf, "%i\n", pwm_mode);
  708. }
  709. static ssize_t amdgpu_hwmon_set_pwm1_enable(struct device *dev,
  710. struct device_attribute *attr,
  711. const char *buf,
  712. size_t count)
  713. {
  714. struct amdgpu_device *adev = dev_get_drvdata(dev);
  715. int err;
  716. int value;
  717. if (!adev->powerplay.pp_funcs->set_fan_control_mode)
  718. return -EINVAL;
  719. err = kstrtoint(buf, 10, &value);
  720. if (err)
  721. return err;
  722. amdgpu_dpm_set_fan_control_mode(adev, value);
  723. return count;
  724. }
  725. static ssize_t amdgpu_hwmon_get_pwm1_min(struct device *dev,
  726. struct device_attribute *attr,
  727. char *buf)
  728. {
  729. return sprintf(buf, "%i\n", 0);
  730. }
  731. static ssize_t amdgpu_hwmon_get_pwm1_max(struct device *dev,
  732. struct device_attribute *attr,
  733. char *buf)
  734. {
  735. return sprintf(buf, "%i\n", 255);
  736. }
  737. static ssize_t amdgpu_hwmon_set_pwm1(struct device *dev,
  738. struct device_attribute *attr,
  739. const char *buf, size_t count)
  740. {
  741. struct amdgpu_device *adev = dev_get_drvdata(dev);
  742. int err;
  743. u32 value;
  744. err = kstrtou32(buf, 10, &value);
  745. if (err)
  746. return err;
  747. value = (value * 100) / 255;
  748. if (adev->powerplay.pp_funcs->set_fan_speed_percent) {
  749. err = amdgpu_dpm_set_fan_speed_percent(adev, value);
  750. if (err)
  751. return err;
  752. }
  753. return count;
  754. }
  755. static ssize_t amdgpu_hwmon_get_pwm1(struct device *dev,
  756. struct device_attribute *attr,
  757. char *buf)
  758. {
  759. struct amdgpu_device *adev = dev_get_drvdata(dev);
  760. int err;
  761. u32 speed = 0;
  762. if (adev->powerplay.pp_funcs->get_fan_speed_percent) {
  763. err = amdgpu_dpm_get_fan_speed_percent(adev, &speed);
  764. if (err)
  765. return err;
  766. }
  767. speed = (speed * 255) / 100;
  768. return sprintf(buf, "%i\n", speed);
  769. }
  770. static ssize_t amdgpu_hwmon_get_fan1_input(struct device *dev,
  771. struct device_attribute *attr,
  772. char *buf)
  773. {
  774. struct amdgpu_device *adev = dev_get_drvdata(dev);
  775. int err;
  776. u32 speed = 0;
  777. if (adev->powerplay.pp_funcs->get_fan_speed_rpm) {
  778. err = amdgpu_dpm_get_fan_speed_rpm(adev, &speed);
  779. if (err)
  780. return err;
  781. }
  782. return sprintf(buf, "%i\n", speed);
  783. }
  784. static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, amdgpu_hwmon_show_temp, NULL, 0);
  785. static SENSOR_DEVICE_ATTR(temp1_crit, S_IRUGO, amdgpu_hwmon_show_temp_thresh, NULL, 0);
  786. static SENSOR_DEVICE_ATTR(temp1_crit_hyst, S_IRUGO, amdgpu_hwmon_show_temp_thresh, NULL, 1);
  787. static SENSOR_DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, amdgpu_hwmon_get_pwm1, amdgpu_hwmon_set_pwm1, 0);
  788. static SENSOR_DEVICE_ATTR(pwm1_enable, S_IRUGO | S_IWUSR, amdgpu_hwmon_get_pwm1_enable, amdgpu_hwmon_set_pwm1_enable, 0);
  789. static SENSOR_DEVICE_ATTR(pwm1_min, S_IRUGO, amdgpu_hwmon_get_pwm1_min, NULL, 0);
  790. static SENSOR_DEVICE_ATTR(pwm1_max, S_IRUGO, amdgpu_hwmon_get_pwm1_max, NULL, 0);
  791. static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, amdgpu_hwmon_get_fan1_input, NULL, 0);
  792. static struct attribute *hwmon_attributes[] = {
  793. &sensor_dev_attr_temp1_input.dev_attr.attr,
  794. &sensor_dev_attr_temp1_crit.dev_attr.attr,
  795. &sensor_dev_attr_temp1_crit_hyst.dev_attr.attr,
  796. &sensor_dev_attr_pwm1.dev_attr.attr,
  797. &sensor_dev_attr_pwm1_enable.dev_attr.attr,
  798. &sensor_dev_attr_pwm1_min.dev_attr.attr,
  799. &sensor_dev_attr_pwm1_max.dev_attr.attr,
  800. &sensor_dev_attr_fan1_input.dev_attr.attr,
  801. NULL
  802. };
  803. static umode_t hwmon_attributes_visible(struct kobject *kobj,
  804. struct attribute *attr, int index)
  805. {
  806. struct device *dev = kobj_to_dev(kobj);
  807. struct amdgpu_device *adev = dev_get_drvdata(dev);
  808. umode_t effective_mode = attr->mode;
  809. /* Skip limit attributes if DPM is not enabled */
  810. if (!adev->pm.dpm_enabled &&
  811. (attr == &sensor_dev_attr_temp1_crit.dev_attr.attr ||
  812. attr == &sensor_dev_attr_temp1_crit_hyst.dev_attr.attr ||
  813. attr == &sensor_dev_attr_pwm1.dev_attr.attr ||
  814. attr == &sensor_dev_attr_pwm1_enable.dev_attr.attr ||
  815. attr == &sensor_dev_attr_pwm1_max.dev_attr.attr ||
  816. attr == &sensor_dev_attr_pwm1_min.dev_attr.attr))
  817. return 0;
  818. if (adev->pp_enabled)
  819. return effective_mode;
  820. /* Skip fan attributes if fan is not present */
  821. if (adev->pm.no_fan &&
  822. (attr == &sensor_dev_attr_pwm1.dev_attr.attr ||
  823. attr == &sensor_dev_attr_pwm1_enable.dev_attr.attr ||
  824. attr == &sensor_dev_attr_pwm1_max.dev_attr.attr ||
  825. attr == &sensor_dev_attr_pwm1_min.dev_attr.attr))
  826. return 0;
  827. /* mask fan attributes if we have no bindings for this asic to expose */
  828. if ((!adev->powerplay.pp_funcs->get_fan_speed_percent &&
  829. attr == &sensor_dev_attr_pwm1.dev_attr.attr) || /* can't query fan */
  830. (!adev->powerplay.pp_funcs->get_fan_control_mode &&
  831. attr == &sensor_dev_attr_pwm1_enable.dev_attr.attr)) /* can't query state */
  832. effective_mode &= ~S_IRUGO;
  833. if ((!adev->powerplay.pp_funcs->set_fan_speed_percent &&
  834. attr == &sensor_dev_attr_pwm1.dev_attr.attr) || /* can't manage fan */
  835. (!adev->powerplay.pp_funcs->set_fan_control_mode &&
  836. attr == &sensor_dev_attr_pwm1_enable.dev_attr.attr)) /* can't manage state */
  837. effective_mode &= ~S_IWUSR;
  838. /* hide max/min values if we can't both query and manage the fan */
  839. if ((!adev->powerplay.pp_funcs->set_fan_speed_percent &&
  840. !adev->powerplay.pp_funcs->get_fan_speed_percent) &&
  841. (attr == &sensor_dev_attr_pwm1_max.dev_attr.attr ||
  842. attr == &sensor_dev_attr_pwm1_min.dev_attr.attr))
  843. return 0;
  844. /* requires powerplay */
  845. if (attr == &sensor_dev_attr_fan1_input.dev_attr.attr)
  846. return 0;
  847. return effective_mode;
  848. }
  849. static const struct attribute_group hwmon_attrgroup = {
  850. .attrs = hwmon_attributes,
  851. .is_visible = hwmon_attributes_visible,
  852. };
  853. static const struct attribute_group *hwmon_groups[] = {
  854. &hwmon_attrgroup,
  855. NULL
  856. };
  857. void amdgpu_dpm_thermal_work_handler(struct work_struct *work)
  858. {
  859. struct amdgpu_device *adev =
  860. container_of(work, struct amdgpu_device,
  861. pm.dpm.thermal.work);
  862. /* switch to the thermal state */
  863. enum amd_pm_state_type dpm_state = POWER_STATE_TYPE_INTERNAL_THERMAL;
  864. if (!adev->pm.dpm_enabled)
  865. return;
  866. if (adev->powerplay.pp_funcs->get_temperature) {
  867. int temp = amdgpu_dpm_get_temperature(adev);
  868. if (temp < adev->pm.dpm.thermal.min_temp)
  869. /* switch back the user state */
  870. dpm_state = adev->pm.dpm.user_state;
  871. } else {
  872. if (adev->pm.dpm.thermal.high_to_low)
  873. /* switch back the user state */
  874. dpm_state = adev->pm.dpm.user_state;
  875. }
  876. mutex_lock(&adev->pm.mutex);
  877. if (dpm_state == POWER_STATE_TYPE_INTERNAL_THERMAL)
  878. adev->pm.dpm.thermal_active = true;
  879. else
  880. adev->pm.dpm.thermal_active = false;
  881. adev->pm.dpm.state = dpm_state;
  882. mutex_unlock(&adev->pm.mutex);
  883. amdgpu_pm_compute_clocks(adev);
  884. }
  885. static struct amdgpu_ps *amdgpu_dpm_pick_power_state(struct amdgpu_device *adev,
  886. enum amd_pm_state_type dpm_state)
  887. {
  888. int i;
  889. struct amdgpu_ps *ps;
  890. u32 ui_class;
  891. bool single_display = (adev->pm.dpm.new_active_crtc_count < 2) ?
  892. true : false;
  893. /* check if the vblank period is too short to adjust the mclk */
  894. if (single_display && adev->powerplay.pp_funcs->vblank_too_short) {
  895. if (amdgpu_dpm_vblank_too_short(adev))
  896. single_display = false;
  897. }
  898. /* certain older asics have a separare 3D performance state,
  899. * so try that first if the user selected performance
  900. */
  901. if (dpm_state == POWER_STATE_TYPE_PERFORMANCE)
  902. dpm_state = POWER_STATE_TYPE_INTERNAL_3DPERF;
  903. /* balanced states don't exist at the moment */
  904. if (dpm_state == POWER_STATE_TYPE_BALANCED)
  905. dpm_state = POWER_STATE_TYPE_PERFORMANCE;
  906. restart_search:
  907. /* Pick the best power state based on current conditions */
  908. for (i = 0; i < adev->pm.dpm.num_ps; i++) {
  909. ps = &adev->pm.dpm.ps[i];
  910. ui_class = ps->class & ATOM_PPLIB_CLASSIFICATION_UI_MASK;
  911. switch (dpm_state) {
  912. /* user states */
  913. case POWER_STATE_TYPE_BATTERY:
  914. if (ui_class == ATOM_PPLIB_CLASSIFICATION_UI_BATTERY) {
  915. if (ps->caps & ATOM_PPLIB_SINGLE_DISPLAY_ONLY) {
  916. if (single_display)
  917. return ps;
  918. } else
  919. return ps;
  920. }
  921. break;
  922. case POWER_STATE_TYPE_BALANCED:
  923. if (ui_class == ATOM_PPLIB_CLASSIFICATION_UI_BALANCED) {
  924. if (ps->caps & ATOM_PPLIB_SINGLE_DISPLAY_ONLY) {
  925. if (single_display)
  926. return ps;
  927. } else
  928. return ps;
  929. }
  930. break;
  931. case POWER_STATE_TYPE_PERFORMANCE:
  932. if (ui_class == ATOM_PPLIB_CLASSIFICATION_UI_PERFORMANCE) {
  933. if (ps->caps & ATOM_PPLIB_SINGLE_DISPLAY_ONLY) {
  934. if (single_display)
  935. return ps;
  936. } else
  937. return ps;
  938. }
  939. break;
  940. /* internal states */
  941. case POWER_STATE_TYPE_INTERNAL_UVD:
  942. if (adev->pm.dpm.uvd_ps)
  943. return adev->pm.dpm.uvd_ps;
  944. else
  945. break;
  946. case POWER_STATE_TYPE_INTERNAL_UVD_SD:
  947. if (ps->class & ATOM_PPLIB_CLASSIFICATION_SDSTATE)
  948. return ps;
  949. break;
  950. case POWER_STATE_TYPE_INTERNAL_UVD_HD:
  951. if (ps->class & ATOM_PPLIB_CLASSIFICATION_HDSTATE)
  952. return ps;
  953. break;
  954. case POWER_STATE_TYPE_INTERNAL_UVD_HD2:
  955. if (ps->class & ATOM_PPLIB_CLASSIFICATION_HD2STATE)
  956. return ps;
  957. break;
  958. case POWER_STATE_TYPE_INTERNAL_UVD_MVC:
  959. if (ps->class2 & ATOM_PPLIB_CLASSIFICATION2_MVC)
  960. return ps;
  961. break;
  962. case POWER_STATE_TYPE_INTERNAL_BOOT:
  963. return adev->pm.dpm.boot_ps;
  964. case POWER_STATE_TYPE_INTERNAL_THERMAL:
  965. if (ps->class & ATOM_PPLIB_CLASSIFICATION_THERMAL)
  966. return ps;
  967. break;
  968. case POWER_STATE_TYPE_INTERNAL_ACPI:
  969. if (ps->class & ATOM_PPLIB_CLASSIFICATION_ACPI)
  970. return ps;
  971. break;
  972. case POWER_STATE_TYPE_INTERNAL_ULV:
  973. if (ps->class2 & ATOM_PPLIB_CLASSIFICATION2_ULV)
  974. return ps;
  975. break;
  976. case POWER_STATE_TYPE_INTERNAL_3DPERF:
  977. if (ps->class & ATOM_PPLIB_CLASSIFICATION_3DPERFORMANCE)
  978. return ps;
  979. break;
  980. default:
  981. break;
  982. }
  983. }
  984. /* use a fallback state if we didn't match */
  985. switch (dpm_state) {
  986. case POWER_STATE_TYPE_INTERNAL_UVD_SD:
  987. dpm_state = POWER_STATE_TYPE_INTERNAL_UVD_HD;
  988. goto restart_search;
  989. case POWER_STATE_TYPE_INTERNAL_UVD_HD:
  990. case POWER_STATE_TYPE_INTERNAL_UVD_HD2:
  991. case POWER_STATE_TYPE_INTERNAL_UVD_MVC:
  992. if (adev->pm.dpm.uvd_ps) {
  993. return adev->pm.dpm.uvd_ps;
  994. } else {
  995. dpm_state = POWER_STATE_TYPE_PERFORMANCE;
  996. goto restart_search;
  997. }
  998. case POWER_STATE_TYPE_INTERNAL_THERMAL:
  999. dpm_state = POWER_STATE_TYPE_INTERNAL_ACPI;
  1000. goto restart_search;
  1001. case POWER_STATE_TYPE_INTERNAL_ACPI:
  1002. dpm_state = POWER_STATE_TYPE_BATTERY;
  1003. goto restart_search;
  1004. case POWER_STATE_TYPE_BATTERY:
  1005. case POWER_STATE_TYPE_BALANCED:
  1006. case POWER_STATE_TYPE_INTERNAL_3DPERF:
  1007. dpm_state = POWER_STATE_TYPE_PERFORMANCE;
  1008. goto restart_search;
  1009. default:
  1010. break;
  1011. }
  1012. return NULL;
  1013. }
  1014. static void amdgpu_dpm_change_power_state_locked(struct amdgpu_device *adev)
  1015. {
  1016. struct amdgpu_ps *ps;
  1017. enum amd_pm_state_type dpm_state;
  1018. int ret;
  1019. bool equal = false;
  1020. /* if dpm init failed */
  1021. if (!adev->pm.dpm_enabled)
  1022. return;
  1023. if (adev->pm.dpm.user_state != adev->pm.dpm.state) {
  1024. /* add other state override checks here */
  1025. if ((!adev->pm.dpm.thermal_active) &&
  1026. (!adev->pm.dpm.uvd_active))
  1027. adev->pm.dpm.state = adev->pm.dpm.user_state;
  1028. }
  1029. dpm_state = adev->pm.dpm.state;
  1030. ps = amdgpu_dpm_pick_power_state(adev, dpm_state);
  1031. if (ps)
  1032. adev->pm.dpm.requested_ps = ps;
  1033. else
  1034. return;
  1035. if (amdgpu_dpm == 1 && adev->powerplay.pp_funcs->print_power_state) {
  1036. printk("switching from power state:\n");
  1037. amdgpu_dpm_print_power_state(adev, adev->pm.dpm.current_ps);
  1038. printk("switching to power state:\n");
  1039. amdgpu_dpm_print_power_state(adev, adev->pm.dpm.requested_ps);
  1040. }
  1041. /* update whether vce is active */
  1042. ps->vce_active = adev->pm.dpm.vce_active;
  1043. if (adev->powerplay.pp_funcs->display_configuration_changed)
  1044. amdgpu_dpm_display_configuration_changed(adev);
  1045. ret = amdgpu_dpm_pre_set_power_state(adev);
  1046. if (ret)
  1047. return;
  1048. if (adev->powerplay.pp_funcs->check_state_equal) {
  1049. if (0 != amdgpu_dpm_check_state_equal(adev, adev->pm.dpm.current_ps, adev->pm.dpm.requested_ps, &equal))
  1050. equal = false;
  1051. }
  1052. if (equal)
  1053. return;
  1054. amdgpu_dpm_set_power_state(adev);
  1055. amdgpu_dpm_post_set_power_state(adev);
  1056. adev->pm.dpm.current_active_crtcs = adev->pm.dpm.new_active_crtcs;
  1057. adev->pm.dpm.current_active_crtc_count = adev->pm.dpm.new_active_crtc_count;
  1058. if (adev->powerplay.pp_funcs->force_performance_level) {
  1059. if (adev->pm.dpm.thermal_active) {
  1060. enum amd_dpm_forced_level level = adev->pm.dpm.forced_level;
  1061. /* force low perf level for thermal */
  1062. amdgpu_dpm_force_performance_level(adev, AMD_DPM_FORCED_LEVEL_LOW);
  1063. /* save the user's level */
  1064. adev->pm.dpm.forced_level = level;
  1065. } else {
  1066. /* otherwise, user selected level */
  1067. amdgpu_dpm_force_performance_level(adev, adev->pm.dpm.forced_level);
  1068. }
  1069. }
  1070. }
  1071. void amdgpu_dpm_enable_uvd(struct amdgpu_device *adev, bool enable)
  1072. {
  1073. if (adev->powerplay.pp_funcs->powergate_uvd) {
  1074. /* enable/disable UVD */
  1075. mutex_lock(&adev->pm.mutex);
  1076. amdgpu_dpm_powergate_uvd(adev, !enable);
  1077. mutex_unlock(&adev->pm.mutex);
  1078. } else {
  1079. if (enable) {
  1080. mutex_lock(&adev->pm.mutex);
  1081. adev->pm.dpm.uvd_active = true;
  1082. adev->pm.dpm.state = POWER_STATE_TYPE_INTERNAL_UVD;
  1083. mutex_unlock(&adev->pm.mutex);
  1084. } else {
  1085. mutex_lock(&adev->pm.mutex);
  1086. adev->pm.dpm.uvd_active = false;
  1087. mutex_unlock(&adev->pm.mutex);
  1088. }
  1089. amdgpu_pm_compute_clocks(adev);
  1090. }
  1091. }
  1092. void amdgpu_dpm_enable_vce(struct amdgpu_device *adev, bool enable)
  1093. {
  1094. if (adev->powerplay.pp_funcs->powergate_vce) {
  1095. /* enable/disable VCE */
  1096. mutex_lock(&adev->pm.mutex);
  1097. amdgpu_dpm_powergate_vce(adev, !enable);
  1098. mutex_unlock(&adev->pm.mutex);
  1099. } else {
  1100. if (enable) {
  1101. mutex_lock(&adev->pm.mutex);
  1102. adev->pm.dpm.vce_active = true;
  1103. /* XXX select vce level based on ring/task */
  1104. adev->pm.dpm.vce_level = AMD_VCE_LEVEL_AC_ALL;
  1105. mutex_unlock(&adev->pm.mutex);
  1106. amdgpu_set_clockgating_state(adev, AMD_IP_BLOCK_TYPE_VCE,
  1107. AMD_CG_STATE_UNGATE);
  1108. amdgpu_set_powergating_state(adev, AMD_IP_BLOCK_TYPE_VCE,
  1109. AMD_PG_STATE_UNGATE);
  1110. amdgpu_pm_compute_clocks(adev);
  1111. } else {
  1112. amdgpu_set_powergating_state(adev, AMD_IP_BLOCK_TYPE_VCE,
  1113. AMD_PG_STATE_GATE);
  1114. amdgpu_set_clockgating_state(adev, AMD_IP_BLOCK_TYPE_VCE,
  1115. AMD_CG_STATE_GATE);
  1116. mutex_lock(&adev->pm.mutex);
  1117. adev->pm.dpm.vce_active = false;
  1118. mutex_unlock(&adev->pm.mutex);
  1119. amdgpu_pm_compute_clocks(adev);
  1120. }
  1121. }
  1122. }
  1123. void amdgpu_pm_print_power_states(struct amdgpu_device *adev)
  1124. {
  1125. int i;
  1126. if (adev->powerplay.pp_funcs->print_power_state == NULL)
  1127. return;
  1128. for (i = 0; i < adev->pm.dpm.num_ps; i++)
  1129. amdgpu_dpm_print_power_state(adev, &adev->pm.dpm.ps[i]);
  1130. }
  1131. int amdgpu_pm_sysfs_init(struct amdgpu_device *adev)
  1132. {
  1133. int ret;
  1134. if (adev->pm.sysfs_initialized)
  1135. return 0;
  1136. if (adev->powerplay.pp_funcs->get_temperature == NULL)
  1137. return 0;
  1138. adev->pm.int_hwmon_dev = hwmon_device_register_with_groups(adev->dev,
  1139. DRIVER_NAME, adev,
  1140. hwmon_groups);
  1141. if (IS_ERR(adev->pm.int_hwmon_dev)) {
  1142. ret = PTR_ERR(adev->pm.int_hwmon_dev);
  1143. dev_err(adev->dev,
  1144. "Unable to register hwmon device: %d\n", ret);
  1145. return ret;
  1146. }
  1147. ret = device_create_file(adev->dev, &dev_attr_power_dpm_state);
  1148. if (ret) {
  1149. DRM_ERROR("failed to create device file for dpm state\n");
  1150. return ret;
  1151. }
  1152. ret = device_create_file(adev->dev, &dev_attr_power_dpm_force_performance_level);
  1153. if (ret) {
  1154. DRM_ERROR("failed to create device file for dpm state\n");
  1155. return ret;
  1156. }
  1157. if (adev->pp_enabled) {
  1158. ret = device_create_file(adev->dev, &dev_attr_pp_num_states);
  1159. if (ret) {
  1160. DRM_ERROR("failed to create device file pp_num_states\n");
  1161. return ret;
  1162. }
  1163. ret = device_create_file(adev->dev, &dev_attr_pp_cur_state);
  1164. if (ret) {
  1165. DRM_ERROR("failed to create device file pp_cur_state\n");
  1166. return ret;
  1167. }
  1168. ret = device_create_file(adev->dev, &dev_attr_pp_force_state);
  1169. if (ret) {
  1170. DRM_ERROR("failed to create device file pp_force_state\n");
  1171. return ret;
  1172. }
  1173. ret = device_create_file(adev->dev, &dev_attr_pp_table);
  1174. if (ret) {
  1175. DRM_ERROR("failed to create device file pp_table\n");
  1176. return ret;
  1177. }
  1178. }
  1179. ret = device_create_file(adev->dev, &dev_attr_pp_dpm_sclk);
  1180. if (ret) {
  1181. DRM_ERROR("failed to create device file pp_dpm_sclk\n");
  1182. return ret;
  1183. }
  1184. ret = device_create_file(adev->dev, &dev_attr_pp_dpm_mclk);
  1185. if (ret) {
  1186. DRM_ERROR("failed to create device file pp_dpm_mclk\n");
  1187. return ret;
  1188. }
  1189. ret = device_create_file(adev->dev, &dev_attr_pp_dpm_pcie);
  1190. if (ret) {
  1191. DRM_ERROR("failed to create device file pp_dpm_pcie\n");
  1192. return ret;
  1193. }
  1194. ret = device_create_file(adev->dev, &dev_attr_pp_sclk_od);
  1195. if (ret) {
  1196. DRM_ERROR("failed to create device file pp_sclk_od\n");
  1197. return ret;
  1198. }
  1199. ret = device_create_file(adev->dev, &dev_attr_pp_mclk_od);
  1200. if (ret) {
  1201. DRM_ERROR("failed to create device file pp_mclk_od\n");
  1202. return ret;
  1203. }
  1204. ret = device_create_file(adev->dev,
  1205. &dev_attr_pp_gfx_power_profile);
  1206. if (ret) {
  1207. DRM_ERROR("failed to create device file "
  1208. "pp_gfx_power_profile\n");
  1209. return ret;
  1210. }
  1211. ret = device_create_file(adev->dev,
  1212. &dev_attr_pp_compute_power_profile);
  1213. if (ret) {
  1214. DRM_ERROR("failed to create device file "
  1215. "pp_compute_power_profile\n");
  1216. return ret;
  1217. }
  1218. ret = amdgpu_debugfs_pm_init(adev);
  1219. if (ret) {
  1220. DRM_ERROR("Failed to register debugfs file for dpm!\n");
  1221. return ret;
  1222. }
  1223. adev->pm.sysfs_initialized = true;
  1224. return 0;
  1225. }
  1226. void amdgpu_pm_sysfs_fini(struct amdgpu_device *adev)
  1227. {
  1228. if (adev->pm.int_hwmon_dev)
  1229. hwmon_device_unregister(adev->pm.int_hwmon_dev);
  1230. device_remove_file(adev->dev, &dev_attr_power_dpm_state);
  1231. device_remove_file(adev->dev, &dev_attr_power_dpm_force_performance_level);
  1232. if (adev->pp_enabled) {
  1233. device_remove_file(adev->dev, &dev_attr_pp_num_states);
  1234. device_remove_file(adev->dev, &dev_attr_pp_cur_state);
  1235. device_remove_file(adev->dev, &dev_attr_pp_force_state);
  1236. device_remove_file(adev->dev, &dev_attr_pp_table);
  1237. }
  1238. device_remove_file(adev->dev, &dev_attr_pp_dpm_sclk);
  1239. device_remove_file(adev->dev, &dev_attr_pp_dpm_mclk);
  1240. device_remove_file(adev->dev, &dev_attr_pp_dpm_pcie);
  1241. device_remove_file(adev->dev, &dev_attr_pp_sclk_od);
  1242. device_remove_file(adev->dev, &dev_attr_pp_mclk_od);
  1243. device_remove_file(adev->dev,
  1244. &dev_attr_pp_gfx_power_profile);
  1245. device_remove_file(adev->dev,
  1246. &dev_attr_pp_compute_power_profile);
  1247. }
  1248. void amdgpu_pm_compute_clocks(struct amdgpu_device *adev)
  1249. {
  1250. struct drm_device *ddev = adev->ddev;
  1251. struct drm_crtc *crtc;
  1252. struct amdgpu_crtc *amdgpu_crtc;
  1253. int i = 0;
  1254. if (!adev->pm.dpm_enabled)
  1255. return;
  1256. if (adev->mode_info.num_crtc)
  1257. amdgpu_display_bandwidth_update(adev);
  1258. for (i = 0; i < AMDGPU_MAX_RINGS; i++) {
  1259. struct amdgpu_ring *ring = adev->rings[i];
  1260. if (ring && ring->ready)
  1261. amdgpu_fence_wait_empty(ring);
  1262. }
  1263. if (adev->pp_enabled) {
  1264. amdgpu_dpm_dispatch_task(adev, AMD_PP_TASK_DISPLAY_CONFIG_CHANGE, NULL, NULL);
  1265. } else {
  1266. mutex_lock(&adev->pm.mutex);
  1267. adev->pm.dpm.new_active_crtcs = 0;
  1268. adev->pm.dpm.new_active_crtc_count = 0;
  1269. if (adev->mode_info.num_crtc && adev->mode_info.mode_config_initialized) {
  1270. list_for_each_entry(crtc,
  1271. &ddev->mode_config.crtc_list, head) {
  1272. amdgpu_crtc = to_amdgpu_crtc(crtc);
  1273. if (crtc->enabled) {
  1274. adev->pm.dpm.new_active_crtcs |= (1 << amdgpu_crtc->crtc_id);
  1275. adev->pm.dpm.new_active_crtc_count++;
  1276. }
  1277. }
  1278. }
  1279. /* update battery/ac status */
  1280. if (power_supply_is_system_supplied() > 0)
  1281. adev->pm.dpm.ac_power = true;
  1282. else
  1283. adev->pm.dpm.ac_power = false;
  1284. amdgpu_dpm_change_power_state_locked(adev);
  1285. mutex_unlock(&adev->pm.mutex);
  1286. }
  1287. }
  1288. /*
  1289. * Debugfs info
  1290. */
  1291. #if defined(CONFIG_DEBUG_FS)
  1292. static int amdgpu_debugfs_pm_info_pp(struct seq_file *m, struct amdgpu_device *adev)
  1293. {
  1294. uint32_t value;
  1295. struct pp_gpu_power query = {0};
  1296. int size;
  1297. /* sanity check PP is enabled */
  1298. if (!(adev->powerplay.pp_funcs &&
  1299. adev->powerplay.pp_funcs->read_sensor))
  1300. return -EINVAL;
  1301. /* GPU Clocks */
  1302. size = sizeof(value);
  1303. seq_printf(m, "GFX Clocks and Power:\n");
  1304. if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GFX_MCLK, (void *)&value, &size))
  1305. seq_printf(m, "\t%u MHz (MCLK)\n", value/100);
  1306. if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GFX_SCLK, (void *)&value, &size))
  1307. seq_printf(m, "\t%u MHz (SCLK)\n", value/100);
  1308. if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_VDDGFX, (void *)&value, &size))
  1309. seq_printf(m, "\t%u mV (VDDGFX)\n", value);
  1310. if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_VDDNB, (void *)&value, &size))
  1311. seq_printf(m, "\t%u mV (VDDNB)\n", value);
  1312. size = sizeof(query);
  1313. if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GPU_POWER, (void *)&query, &size)) {
  1314. seq_printf(m, "\t%u.%u W (VDDC)\n", query.vddc_power >> 8,
  1315. query.vddc_power & 0xff);
  1316. seq_printf(m, "\t%u.%u W (VDDCI)\n", query.vddci_power >> 8,
  1317. query.vddci_power & 0xff);
  1318. seq_printf(m, "\t%u.%u W (max GPU)\n", query.max_gpu_power >> 8,
  1319. query.max_gpu_power & 0xff);
  1320. seq_printf(m, "\t%u.%u W (average GPU)\n", query.average_gpu_power >> 8,
  1321. query.average_gpu_power & 0xff);
  1322. }
  1323. size = sizeof(value);
  1324. seq_printf(m, "\n");
  1325. /* GPU Temp */
  1326. if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GPU_TEMP, (void *)&value, &size))
  1327. seq_printf(m, "GPU Temperature: %u C\n", value/1000);
  1328. /* GPU Load */
  1329. if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GPU_LOAD, (void *)&value, &size))
  1330. seq_printf(m, "GPU Load: %u %%\n", value);
  1331. seq_printf(m, "\n");
  1332. /* UVD clocks */
  1333. if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_UVD_POWER, (void *)&value, &size)) {
  1334. if (!value) {
  1335. seq_printf(m, "UVD: Disabled\n");
  1336. } else {
  1337. seq_printf(m, "UVD: Enabled\n");
  1338. if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_UVD_DCLK, (void *)&value, &size))
  1339. seq_printf(m, "\t%u MHz (DCLK)\n", value/100);
  1340. if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_UVD_VCLK, (void *)&value, &size))
  1341. seq_printf(m, "\t%u MHz (VCLK)\n", value/100);
  1342. }
  1343. }
  1344. seq_printf(m, "\n");
  1345. /* VCE clocks */
  1346. if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_VCE_POWER, (void *)&value, &size)) {
  1347. if (!value) {
  1348. seq_printf(m, "VCE: Disabled\n");
  1349. } else {
  1350. seq_printf(m, "VCE: Enabled\n");
  1351. if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_VCE_ECCLK, (void *)&value, &size))
  1352. seq_printf(m, "\t%u MHz (ECCLK)\n", value/100);
  1353. }
  1354. }
  1355. return 0;
  1356. }
  1357. static void amdgpu_parse_cg_state(struct seq_file *m, u32 flags)
  1358. {
  1359. int i;
  1360. for (i = 0; clocks[i].flag; i++)
  1361. seq_printf(m, "\t%s: %s\n", clocks[i].name,
  1362. (flags & clocks[i].flag) ? "On" : "Off");
  1363. }
  1364. static int amdgpu_debugfs_pm_info(struct seq_file *m, void *data)
  1365. {
  1366. struct drm_info_node *node = (struct drm_info_node *) m->private;
  1367. struct drm_device *dev = node->minor->dev;
  1368. struct amdgpu_device *adev = dev->dev_private;
  1369. struct drm_device *ddev = adev->ddev;
  1370. u32 flags = 0;
  1371. amdgpu_get_clockgating_state(adev, &flags);
  1372. seq_printf(m, "Clock Gating Flags Mask: 0x%x\n", flags);
  1373. amdgpu_parse_cg_state(m, flags);
  1374. seq_printf(m, "\n");
  1375. if (!adev->pm.dpm_enabled) {
  1376. seq_printf(m, "dpm not enabled\n");
  1377. return 0;
  1378. }
  1379. if ((adev->flags & AMD_IS_PX) &&
  1380. (ddev->switch_power_state != DRM_SWITCH_POWER_ON)) {
  1381. seq_printf(m, "PX asic powered off\n");
  1382. } else if (adev->pp_enabled) {
  1383. return amdgpu_debugfs_pm_info_pp(m, adev);
  1384. } else {
  1385. mutex_lock(&adev->pm.mutex);
  1386. if (adev->powerplay.pp_funcs->debugfs_print_current_performance_level)
  1387. adev->powerplay.pp_funcs->debugfs_print_current_performance_level(adev, m);
  1388. else
  1389. seq_printf(m, "Debugfs support not implemented for this asic\n");
  1390. mutex_unlock(&adev->pm.mutex);
  1391. }
  1392. return 0;
  1393. }
  1394. static const struct drm_info_list amdgpu_pm_info_list[] = {
  1395. {"amdgpu_pm_info", amdgpu_debugfs_pm_info, 0, NULL},
  1396. };
  1397. #endif
  1398. static int amdgpu_debugfs_pm_init(struct amdgpu_device *adev)
  1399. {
  1400. #if defined(CONFIG_DEBUG_FS)
  1401. return amdgpu_debugfs_add_files(adev, amdgpu_pm_info_list, ARRAY_SIZE(amdgpu_pm_info_list));
  1402. #else
  1403. return 0;
  1404. #endif
  1405. }