amdgpu_pm.c 46 KB

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