amdgpu_pm.c 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620
  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. /* Skip limit attributes if DPM is not enabled */
  808. if (!adev->pm.dpm_enabled &&
  809. (attr == &sensor_dev_attr_temp1_crit.dev_attr.attr ||
  810. attr == &sensor_dev_attr_temp1_crit_hyst.dev_attr.attr ||
  811. attr == &sensor_dev_attr_pwm1.dev_attr.attr ||
  812. attr == &sensor_dev_attr_pwm1_enable.dev_attr.attr ||
  813. attr == &sensor_dev_attr_pwm1_max.dev_attr.attr ||
  814. attr == &sensor_dev_attr_pwm1_min.dev_attr.attr))
  815. return 0;
  816. /* Skip fan attributes if fan is not present */
  817. if (adev->pm.no_fan &&
  818. (attr == &sensor_dev_attr_pwm1.dev_attr.attr ||
  819. attr == &sensor_dev_attr_pwm1_enable.dev_attr.attr ||
  820. attr == &sensor_dev_attr_pwm1_max.dev_attr.attr ||
  821. attr == &sensor_dev_attr_pwm1_min.dev_attr.attr))
  822. return 0;
  823. /* mask fan attributes if we have no bindings for this asic to expose */
  824. if ((!adev->powerplay.pp_funcs->get_fan_speed_percent &&
  825. attr == &sensor_dev_attr_pwm1.dev_attr.attr) || /* can't query fan */
  826. (!adev->powerplay.pp_funcs->get_fan_control_mode &&
  827. attr == &sensor_dev_attr_pwm1_enable.dev_attr.attr)) /* can't query state */
  828. effective_mode &= ~S_IRUGO;
  829. if ((!adev->powerplay.pp_funcs->set_fan_speed_percent &&
  830. attr == &sensor_dev_attr_pwm1.dev_attr.attr) || /* can't manage fan */
  831. (!adev->powerplay.pp_funcs->set_fan_control_mode &&
  832. attr == &sensor_dev_attr_pwm1_enable.dev_attr.attr)) /* can't manage state */
  833. effective_mode &= ~S_IWUSR;
  834. /* hide max/min values if we can't both query and manage the fan */
  835. if ((!adev->powerplay.pp_funcs->set_fan_speed_percent &&
  836. !adev->powerplay.pp_funcs->get_fan_speed_percent) &&
  837. (attr == &sensor_dev_attr_pwm1_max.dev_attr.attr ||
  838. attr == &sensor_dev_attr_pwm1_min.dev_attr.attr))
  839. return 0;
  840. /* requires powerplay */
  841. if (attr == &sensor_dev_attr_fan1_input.dev_attr.attr)
  842. return 0;
  843. return effective_mode;
  844. }
  845. static const struct attribute_group hwmon_attrgroup = {
  846. .attrs = hwmon_attributes,
  847. .is_visible = hwmon_attributes_visible,
  848. };
  849. static const struct attribute_group *hwmon_groups[] = {
  850. &hwmon_attrgroup,
  851. NULL
  852. };
  853. void amdgpu_dpm_thermal_work_handler(struct work_struct *work)
  854. {
  855. struct amdgpu_device *adev =
  856. container_of(work, struct amdgpu_device,
  857. pm.dpm.thermal.work);
  858. /* switch to the thermal state */
  859. enum amd_pm_state_type dpm_state = POWER_STATE_TYPE_INTERNAL_THERMAL;
  860. if (!adev->pm.dpm_enabled)
  861. return;
  862. if (adev->powerplay.pp_funcs->get_temperature) {
  863. int temp = amdgpu_dpm_get_temperature(adev);
  864. if (temp < adev->pm.dpm.thermal.min_temp)
  865. /* switch back the user state */
  866. dpm_state = adev->pm.dpm.user_state;
  867. } else {
  868. if (adev->pm.dpm.thermal.high_to_low)
  869. /* switch back the user state */
  870. dpm_state = adev->pm.dpm.user_state;
  871. }
  872. mutex_lock(&adev->pm.mutex);
  873. if (dpm_state == POWER_STATE_TYPE_INTERNAL_THERMAL)
  874. adev->pm.dpm.thermal_active = true;
  875. else
  876. adev->pm.dpm.thermal_active = false;
  877. adev->pm.dpm.state = dpm_state;
  878. mutex_unlock(&adev->pm.mutex);
  879. amdgpu_pm_compute_clocks(adev);
  880. }
  881. static struct amdgpu_ps *amdgpu_dpm_pick_power_state(struct amdgpu_device *adev,
  882. enum amd_pm_state_type dpm_state)
  883. {
  884. int i;
  885. struct amdgpu_ps *ps;
  886. u32 ui_class;
  887. bool single_display = (adev->pm.dpm.new_active_crtc_count < 2) ?
  888. true : false;
  889. /* check if the vblank period is too short to adjust the mclk */
  890. if (single_display && adev->powerplay.pp_funcs->vblank_too_short) {
  891. if (amdgpu_dpm_vblank_too_short(adev))
  892. single_display = false;
  893. }
  894. /* certain older asics have a separare 3D performance state,
  895. * so try that first if the user selected performance
  896. */
  897. if (dpm_state == POWER_STATE_TYPE_PERFORMANCE)
  898. dpm_state = POWER_STATE_TYPE_INTERNAL_3DPERF;
  899. /* balanced states don't exist at the moment */
  900. if (dpm_state == POWER_STATE_TYPE_BALANCED)
  901. dpm_state = POWER_STATE_TYPE_PERFORMANCE;
  902. restart_search:
  903. /* Pick the best power state based on current conditions */
  904. for (i = 0; i < adev->pm.dpm.num_ps; i++) {
  905. ps = &adev->pm.dpm.ps[i];
  906. ui_class = ps->class & ATOM_PPLIB_CLASSIFICATION_UI_MASK;
  907. switch (dpm_state) {
  908. /* user states */
  909. case POWER_STATE_TYPE_BATTERY:
  910. if (ui_class == ATOM_PPLIB_CLASSIFICATION_UI_BATTERY) {
  911. if (ps->caps & ATOM_PPLIB_SINGLE_DISPLAY_ONLY) {
  912. if (single_display)
  913. return ps;
  914. } else
  915. return ps;
  916. }
  917. break;
  918. case POWER_STATE_TYPE_BALANCED:
  919. if (ui_class == ATOM_PPLIB_CLASSIFICATION_UI_BALANCED) {
  920. if (ps->caps & ATOM_PPLIB_SINGLE_DISPLAY_ONLY) {
  921. if (single_display)
  922. return ps;
  923. } else
  924. return ps;
  925. }
  926. break;
  927. case POWER_STATE_TYPE_PERFORMANCE:
  928. if (ui_class == ATOM_PPLIB_CLASSIFICATION_UI_PERFORMANCE) {
  929. if (ps->caps & ATOM_PPLIB_SINGLE_DISPLAY_ONLY) {
  930. if (single_display)
  931. return ps;
  932. } else
  933. return ps;
  934. }
  935. break;
  936. /* internal states */
  937. case POWER_STATE_TYPE_INTERNAL_UVD:
  938. if (adev->pm.dpm.uvd_ps)
  939. return adev->pm.dpm.uvd_ps;
  940. else
  941. break;
  942. case POWER_STATE_TYPE_INTERNAL_UVD_SD:
  943. if (ps->class & ATOM_PPLIB_CLASSIFICATION_SDSTATE)
  944. return ps;
  945. break;
  946. case POWER_STATE_TYPE_INTERNAL_UVD_HD:
  947. if (ps->class & ATOM_PPLIB_CLASSIFICATION_HDSTATE)
  948. return ps;
  949. break;
  950. case POWER_STATE_TYPE_INTERNAL_UVD_HD2:
  951. if (ps->class & ATOM_PPLIB_CLASSIFICATION_HD2STATE)
  952. return ps;
  953. break;
  954. case POWER_STATE_TYPE_INTERNAL_UVD_MVC:
  955. if (ps->class2 & ATOM_PPLIB_CLASSIFICATION2_MVC)
  956. return ps;
  957. break;
  958. case POWER_STATE_TYPE_INTERNAL_BOOT:
  959. return adev->pm.dpm.boot_ps;
  960. case POWER_STATE_TYPE_INTERNAL_THERMAL:
  961. if (ps->class & ATOM_PPLIB_CLASSIFICATION_THERMAL)
  962. return ps;
  963. break;
  964. case POWER_STATE_TYPE_INTERNAL_ACPI:
  965. if (ps->class & ATOM_PPLIB_CLASSIFICATION_ACPI)
  966. return ps;
  967. break;
  968. case POWER_STATE_TYPE_INTERNAL_ULV:
  969. if (ps->class2 & ATOM_PPLIB_CLASSIFICATION2_ULV)
  970. return ps;
  971. break;
  972. case POWER_STATE_TYPE_INTERNAL_3DPERF:
  973. if (ps->class & ATOM_PPLIB_CLASSIFICATION_3DPERFORMANCE)
  974. return ps;
  975. break;
  976. default:
  977. break;
  978. }
  979. }
  980. /* use a fallback state if we didn't match */
  981. switch (dpm_state) {
  982. case POWER_STATE_TYPE_INTERNAL_UVD_SD:
  983. dpm_state = POWER_STATE_TYPE_INTERNAL_UVD_HD;
  984. goto restart_search;
  985. case POWER_STATE_TYPE_INTERNAL_UVD_HD:
  986. case POWER_STATE_TYPE_INTERNAL_UVD_HD2:
  987. case POWER_STATE_TYPE_INTERNAL_UVD_MVC:
  988. if (adev->pm.dpm.uvd_ps) {
  989. return adev->pm.dpm.uvd_ps;
  990. } else {
  991. dpm_state = POWER_STATE_TYPE_PERFORMANCE;
  992. goto restart_search;
  993. }
  994. case POWER_STATE_TYPE_INTERNAL_THERMAL:
  995. dpm_state = POWER_STATE_TYPE_INTERNAL_ACPI;
  996. goto restart_search;
  997. case POWER_STATE_TYPE_INTERNAL_ACPI:
  998. dpm_state = POWER_STATE_TYPE_BATTERY;
  999. goto restart_search;
  1000. case POWER_STATE_TYPE_BATTERY:
  1001. case POWER_STATE_TYPE_BALANCED:
  1002. case POWER_STATE_TYPE_INTERNAL_3DPERF:
  1003. dpm_state = POWER_STATE_TYPE_PERFORMANCE;
  1004. goto restart_search;
  1005. default:
  1006. break;
  1007. }
  1008. return NULL;
  1009. }
  1010. static void amdgpu_dpm_change_power_state_locked(struct amdgpu_device *adev)
  1011. {
  1012. struct amdgpu_ps *ps;
  1013. enum amd_pm_state_type dpm_state;
  1014. int ret;
  1015. bool equal = false;
  1016. /* if dpm init failed */
  1017. if (!adev->pm.dpm_enabled)
  1018. return;
  1019. if (adev->pm.dpm.user_state != adev->pm.dpm.state) {
  1020. /* add other state override checks here */
  1021. if ((!adev->pm.dpm.thermal_active) &&
  1022. (!adev->pm.dpm.uvd_active))
  1023. adev->pm.dpm.state = adev->pm.dpm.user_state;
  1024. }
  1025. dpm_state = adev->pm.dpm.state;
  1026. ps = amdgpu_dpm_pick_power_state(adev, dpm_state);
  1027. if (ps)
  1028. adev->pm.dpm.requested_ps = ps;
  1029. else
  1030. return;
  1031. if (amdgpu_dpm == 1 && adev->powerplay.pp_funcs->print_power_state) {
  1032. printk("switching from power state:\n");
  1033. amdgpu_dpm_print_power_state(adev, adev->pm.dpm.current_ps);
  1034. printk("switching to power state:\n");
  1035. amdgpu_dpm_print_power_state(adev, adev->pm.dpm.requested_ps);
  1036. }
  1037. /* update whether vce is active */
  1038. ps->vce_active = adev->pm.dpm.vce_active;
  1039. if (adev->powerplay.pp_funcs->display_configuration_changed)
  1040. amdgpu_dpm_display_configuration_changed(adev);
  1041. ret = amdgpu_dpm_pre_set_power_state(adev);
  1042. if (ret)
  1043. return;
  1044. if (adev->powerplay.pp_funcs->check_state_equal) {
  1045. if (0 != amdgpu_dpm_check_state_equal(adev, adev->pm.dpm.current_ps, adev->pm.dpm.requested_ps, &equal))
  1046. equal = false;
  1047. }
  1048. if (equal)
  1049. return;
  1050. amdgpu_dpm_set_power_state(adev);
  1051. amdgpu_dpm_post_set_power_state(adev);
  1052. adev->pm.dpm.current_active_crtcs = adev->pm.dpm.new_active_crtcs;
  1053. adev->pm.dpm.current_active_crtc_count = adev->pm.dpm.new_active_crtc_count;
  1054. if (adev->powerplay.pp_funcs->force_performance_level) {
  1055. if (adev->pm.dpm.thermal_active) {
  1056. enum amd_dpm_forced_level level = adev->pm.dpm.forced_level;
  1057. /* force low perf level for thermal */
  1058. amdgpu_dpm_force_performance_level(adev, AMD_DPM_FORCED_LEVEL_LOW);
  1059. /* save the user's level */
  1060. adev->pm.dpm.forced_level = level;
  1061. } else {
  1062. /* otherwise, user selected level */
  1063. amdgpu_dpm_force_performance_level(adev, adev->pm.dpm.forced_level);
  1064. }
  1065. }
  1066. }
  1067. void amdgpu_dpm_enable_uvd(struct amdgpu_device *adev, bool enable)
  1068. {
  1069. if (adev->powerplay.pp_funcs->powergate_uvd) {
  1070. /* enable/disable UVD */
  1071. mutex_lock(&adev->pm.mutex);
  1072. amdgpu_dpm_powergate_uvd(adev, !enable);
  1073. mutex_unlock(&adev->pm.mutex);
  1074. } else {
  1075. if (enable) {
  1076. mutex_lock(&adev->pm.mutex);
  1077. adev->pm.dpm.uvd_active = true;
  1078. adev->pm.dpm.state = POWER_STATE_TYPE_INTERNAL_UVD;
  1079. mutex_unlock(&adev->pm.mutex);
  1080. } else {
  1081. mutex_lock(&adev->pm.mutex);
  1082. adev->pm.dpm.uvd_active = false;
  1083. mutex_unlock(&adev->pm.mutex);
  1084. }
  1085. amdgpu_pm_compute_clocks(adev);
  1086. }
  1087. }
  1088. void amdgpu_dpm_enable_vce(struct amdgpu_device *adev, bool enable)
  1089. {
  1090. if (adev->powerplay.pp_funcs->powergate_vce) {
  1091. /* enable/disable VCE */
  1092. mutex_lock(&adev->pm.mutex);
  1093. amdgpu_dpm_powergate_vce(adev, !enable);
  1094. mutex_unlock(&adev->pm.mutex);
  1095. } else {
  1096. if (enable) {
  1097. mutex_lock(&adev->pm.mutex);
  1098. adev->pm.dpm.vce_active = true;
  1099. /* XXX select vce level based on ring/task */
  1100. adev->pm.dpm.vce_level = AMD_VCE_LEVEL_AC_ALL;
  1101. mutex_unlock(&adev->pm.mutex);
  1102. amdgpu_set_clockgating_state(adev, AMD_IP_BLOCK_TYPE_VCE,
  1103. AMD_CG_STATE_UNGATE);
  1104. amdgpu_set_powergating_state(adev, AMD_IP_BLOCK_TYPE_VCE,
  1105. AMD_PG_STATE_UNGATE);
  1106. amdgpu_pm_compute_clocks(adev);
  1107. } else {
  1108. amdgpu_set_powergating_state(adev, AMD_IP_BLOCK_TYPE_VCE,
  1109. AMD_PG_STATE_GATE);
  1110. amdgpu_set_clockgating_state(adev, AMD_IP_BLOCK_TYPE_VCE,
  1111. AMD_CG_STATE_GATE);
  1112. mutex_lock(&adev->pm.mutex);
  1113. adev->pm.dpm.vce_active = false;
  1114. mutex_unlock(&adev->pm.mutex);
  1115. amdgpu_pm_compute_clocks(adev);
  1116. }
  1117. }
  1118. }
  1119. void amdgpu_pm_print_power_states(struct amdgpu_device *adev)
  1120. {
  1121. int i;
  1122. if (adev->powerplay.pp_funcs->print_power_state == NULL)
  1123. return;
  1124. for (i = 0; i < adev->pm.dpm.num_ps; i++)
  1125. amdgpu_dpm_print_power_state(adev, &adev->pm.dpm.ps[i]);
  1126. }
  1127. int amdgpu_pm_sysfs_init(struct amdgpu_device *adev)
  1128. {
  1129. int ret;
  1130. if (adev->pm.sysfs_initialized)
  1131. return 0;
  1132. if (adev->pm.dpm_enabled == 0)
  1133. return 0;
  1134. if (adev->powerplay.pp_funcs->get_temperature == NULL)
  1135. return 0;
  1136. adev->pm.int_hwmon_dev = hwmon_device_register_with_groups(adev->dev,
  1137. DRIVER_NAME, adev,
  1138. hwmon_groups);
  1139. if (IS_ERR(adev->pm.int_hwmon_dev)) {
  1140. ret = PTR_ERR(adev->pm.int_hwmon_dev);
  1141. dev_err(adev->dev,
  1142. "Unable to register hwmon device: %d\n", ret);
  1143. return ret;
  1144. }
  1145. ret = device_create_file(adev->dev, &dev_attr_power_dpm_state);
  1146. if (ret) {
  1147. DRM_ERROR("failed to create device file for dpm state\n");
  1148. return ret;
  1149. }
  1150. ret = device_create_file(adev->dev, &dev_attr_power_dpm_force_performance_level);
  1151. if (ret) {
  1152. DRM_ERROR("failed to create device file for dpm state\n");
  1153. return ret;
  1154. }
  1155. ret = device_create_file(adev->dev, &dev_attr_pp_num_states);
  1156. if (ret) {
  1157. DRM_ERROR("failed to create device file pp_num_states\n");
  1158. return ret;
  1159. }
  1160. ret = device_create_file(adev->dev, &dev_attr_pp_cur_state);
  1161. if (ret) {
  1162. DRM_ERROR("failed to create device file pp_cur_state\n");
  1163. return ret;
  1164. }
  1165. ret = device_create_file(adev->dev, &dev_attr_pp_force_state);
  1166. if (ret) {
  1167. DRM_ERROR("failed to create device file pp_force_state\n");
  1168. return ret;
  1169. }
  1170. ret = device_create_file(adev->dev, &dev_attr_pp_table);
  1171. if (ret) {
  1172. DRM_ERROR("failed to create device file pp_table\n");
  1173. return ret;
  1174. }
  1175. ret = device_create_file(adev->dev, &dev_attr_pp_dpm_sclk);
  1176. if (ret) {
  1177. DRM_ERROR("failed to create device file pp_dpm_sclk\n");
  1178. return ret;
  1179. }
  1180. ret = device_create_file(adev->dev, &dev_attr_pp_dpm_mclk);
  1181. if (ret) {
  1182. DRM_ERROR("failed to create device file pp_dpm_mclk\n");
  1183. return ret;
  1184. }
  1185. ret = device_create_file(adev->dev, &dev_attr_pp_dpm_pcie);
  1186. if (ret) {
  1187. DRM_ERROR("failed to create device file pp_dpm_pcie\n");
  1188. return ret;
  1189. }
  1190. ret = device_create_file(adev->dev, &dev_attr_pp_sclk_od);
  1191. if (ret) {
  1192. DRM_ERROR("failed to create device file pp_sclk_od\n");
  1193. return ret;
  1194. }
  1195. ret = device_create_file(adev->dev, &dev_attr_pp_mclk_od);
  1196. if (ret) {
  1197. DRM_ERROR("failed to create device file pp_mclk_od\n");
  1198. return ret;
  1199. }
  1200. ret = device_create_file(adev->dev,
  1201. &dev_attr_pp_gfx_power_profile);
  1202. if (ret) {
  1203. DRM_ERROR("failed to create device file "
  1204. "pp_gfx_power_profile\n");
  1205. return ret;
  1206. }
  1207. ret = device_create_file(adev->dev,
  1208. &dev_attr_pp_compute_power_profile);
  1209. if (ret) {
  1210. DRM_ERROR("failed to create device file "
  1211. "pp_compute_power_profile\n");
  1212. return ret;
  1213. }
  1214. ret = amdgpu_debugfs_pm_init(adev);
  1215. if (ret) {
  1216. DRM_ERROR("Failed to register debugfs file for dpm!\n");
  1217. return ret;
  1218. }
  1219. adev->pm.sysfs_initialized = true;
  1220. return 0;
  1221. }
  1222. void amdgpu_pm_sysfs_fini(struct amdgpu_device *adev)
  1223. {
  1224. if (adev->pm.dpm_enabled == 0)
  1225. return;
  1226. if (adev->pm.int_hwmon_dev)
  1227. hwmon_device_unregister(adev->pm.int_hwmon_dev);
  1228. device_remove_file(adev->dev, &dev_attr_power_dpm_state);
  1229. device_remove_file(adev->dev, &dev_attr_power_dpm_force_performance_level);
  1230. device_remove_file(adev->dev, &dev_attr_pp_num_states);
  1231. device_remove_file(adev->dev, &dev_attr_pp_cur_state);
  1232. device_remove_file(adev->dev, &dev_attr_pp_force_state);
  1233. device_remove_file(adev->dev, &dev_attr_pp_table);
  1234. device_remove_file(adev->dev, &dev_attr_pp_dpm_sclk);
  1235. device_remove_file(adev->dev, &dev_attr_pp_dpm_mclk);
  1236. device_remove_file(adev->dev, &dev_attr_pp_dpm_pcie);
  1237. device_remove_file(adev->dev, &dev_attr_pp_sclk_od);
  1238. device_remove_file(adev->dev, &dev_attr_pp_mclk_od);
  1239. device_remove_file(adev->dev,
  1240. &dev_attr_pp_gfx_power_profile);
  1241. device_remove_file(adev->dev,
  1242. &dev_attr_pp_compute_power_profile);
  1243. }
  1244. void amdgpu_pm_compute_clocks(struct amdgpu_device *adev)
  1245. {
  1246. struct drm_device *ddev = adev->ddev;
  1247. struct drm_crtc *crtc;
  1248. struct amdgpu_crtc *amdgpu_crtc;
  1249. int i = 0;
  1250. if (!adev->pm.dpm_enabled)
  1251. return;
  1252. if (adev->mode_info.num_crtc)
  1253. amdgpu_display_bandwidth_update(adev);
  1254. for (i = 0; i < AMDGPU_MAX_RINGS; i++) {
  1255. struct amdgpu_ring *ring = adev->rings[i];
  1256. if (ring && ring->ready)
  1257. amdgpu_fence_wait_empty(ring);
  1258. }
  1259. if (adev->powerplay.pp_funcs->dispatch_tasks) {
  1260. amdgpu_dpm_dispatch_task(adev, AMD_PP_TASK_DISPLAY_CONFIG_CHANGE, NULL, NULL);
  1261. } else {
  1262. mutex_lock(&adev->pm.mutex);
  1263. adev->pm.dpm.new_active_crtcs = 0;
  1264. adev->pm.dpm.new_active_crtc_count = 0;
  1265. if (adev->mode_info.num_crtc && adev->mode_info.mode_config_initialized) {
  1266. list_for_each_entry(crtc,
  1267. &ddev->mode_config.crtc_list, head) {
  1268. amdgpu_crtc = to_amdgpu_crtc(crtc);
  1269. if (crtc->enabled) {
  1270. adev->pm.dpm.new_active_crtcs |= (1 << amdgpu_crtc->crtc_id);
  1271. adev->pm.dpm.new_active_crtc_count++;
  1272. }
  1273. }
  1274. }
  1275. /* update battery/ac status */
  1276. if (power_supply_is_system_supplied() > 0)
  1277. adev->pm.dpm.ac_power = true;
  1278. else
  1279. adev->pm.dpm.ac_power = false;
  1280. amdgpu_dpm_change_power_state_locked(adev);
  1281. mutex_unlock(&adev->pm.mutex);
  1282. }
  1283. }
  1284. /*
  1285. * Debugfs info
  1286. */
  1287. #if defined(CONFIG_DEBUG_FS)
  1288. static int amdgpu_debugfs_pm_info_pp(struct seq_file *m, struct amdgpu_device *adev)
  1289. {
  1290. uint32_t value;
  1291. struct pp_gpu_power query = {0};
  1292. int size;
  1293. /* sanity check PP is enabled */
  1294. if (!(adev->powerplay.pp_funcs &&
  1295. adev->powerplay.pp_funcs->read_sensor))
  1296. return -EINVAL;
  1297. /* GPU Clocks */
  1298. size = sizeof(value);
  1299. seq_printf(m, "GFX Clocks and Power:\n");
  1300. if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GFX_MCLK, (void *)&value, &size))
  1301. seq_printf(m, "\t%u MHz (MCLK)\n", value/100);
  1302. if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GFX_SCLK, (void *)&value, &size))
  1303. seq_printf(m, "\t%u MHz (SCLK)\n", value/100);
  1304. if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_VDDGFX, (void *)&value, &size))
  1305. seq_printf(m, "\t%u mV (VDDGFX)\n", value);
  1306. if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_VDDNB, (void *)&value, &size))
  1307. seq_printf(m, "\t%u mV (VDDNB)\n", value);
  1308. size = sizeof(query);
  1309. if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GPU_POWER, (void *)&query, &size)) {
  1310. seq_printf(m, "\t%u.%u W (VDDC)\n", query.vddc_power >> 8,
  1311. query.vddc_power & 0xff);
  1312. seq_printf(m, "\t%u.%u W (VDDCI)\n", query.vddci_power >> 8,
  1313. query.vddci_power & 0xff);
  1314. seq_printf(m, "\t%u.%u W (max GPU)\n", query.max_gpu_power >> 8,
  1315. query.max_gpu_power & 0xff);
  1316. seq_printf(m, "\t%u.%u W (average GPU)\n", query.average_gpu_power >> 8,
  1317. query.average_gpu_power & 0xff);
  1318. }
  1319. size = sizeof(value);
  1320. seq_printf(m, "\n");
  1321. /* GPU Temp */
  1322. if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GPU_TEMP, (void *)&value, &size))
  1323. seq_printf(m, "GPU Temperature: %u C\n", value/1000);
  1324. /* GPU Load */
  1325. if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GPU_LOAD, (void *)&value, &size))
  1326. seq_printf(m, "GPU Load: %u %%\n", value);
  1327. seq_printf(m, "\n");
  1328. /* UVD clocks */
  1329. if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_UVD_POWER, (void *)&value, &size)) {
  1330. if (!value) {
  1331. seq_printf(m, "UVD: Disabled\n");
  1332. } else {
  1333. seq_printf(m, "UVD: Enabled\n");
  1334. if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_UVD_DCLK, (void *)&value, &size))
  1335. seq_printf(m, "\t%u MHz (DCLK)\n", value/100);
  1336. if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_UVD_VCLK, (void *)&value, &size))
  1337. seq_printf(m, "\t%u MHz (VCLK)\n", value/100);
  1338. }
  1339. }
  1340. seq_printf(m, "\n");
  1341. /* VCE clocks */
  1342. if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_VCE_POWER, (void *)&value, &size)) {
  1343. if (!value) {
  1344. seq_printf(m, "VCE: Disabled\n");
  1345. } else {
  1346. seq_printf(m, "VCE: Enabled\n");
  1347. if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_VCE_ECCLK, (void *)&value, &size))
  1348. seq_printf(m, "\t%u MHz (ECCLK)\n", value/100);
  1349. }
  1350. }
  1351. return 0;
  1352. }
  1353. static void amdgpu_parse_cg_state(struct seq_file *m, u32 flags)
  1354. {
  1355. int i;
  1356. for (i = 0; clocks[i].flag; i++)
  1357. seq_printf(m, "\t%s: %s\n", clocks[i].name,
  1358. (flags & clocks[i].flag) ? "On" : "Off");
  1359. }
  1360. static int amdgpu_debugfs_pm_info(struct seq_file *m, void *data)
  1361. {
  1362. struct drm_info_node *node = (struct drm_info_node *) m->private;
  1363. struct drm_device *dev = node->minor->dev;
  1364. struct amdgpu_device *adev = dev->dev_private;
  1365. struct drm_device *ddev = adev->ddev;
  1366. u32 flags = 0;
  1367. amdgpu_get_clockgating_state(adev, &flags);
  1368. seq_printf(m, "Clock Gating Flags Mask: 0x%x\n", flags);
  1369. amdgpu_parse_cg_state(m, flags);
  1370. seq_printf(m, "\n");
  1371. if (!adev->pm.dpm_enabled) {
  1372. seq_printf(m, "dpm not enabled\n");
  1373. return 0;
  1374. }
  1375. if ((adev->flags & AMD_IS_PX) &&
  1376. (ddev->switch_power_state != DRM_SWITCH_POWER_ON)) {
  1377. seq_printf(m, "PX asic powered off\n");
  1378. } else if (adev->powerplay.pp_funcs->debugfs_print_current_performance_level) {
  1379. mutex_lock(&adev->pm.mutex);
  1380. if (adev->powerplay.pp_funcs->debugfs_print_current_performance_level)
  1381. adev->powerplay.pp_funcs->debugfs_print_current_performance_level(adev, m);
  1382. else
  1383. seq_printf(m, "Debugfs support not implemented for this asic\n");
  1384. mutex_unlock(&adev->pm.mutex);
  1385. } else {
  1386. return amdgpu_debugfs_pm_info_pp(m, adev);
  1387. }
  1388. return 0;
  1389. }
  1390. static const struct drm_info_list amdgpu_pm_info_list[] = {
  1391. {"amdgpu_pm_info", amdgpu_debugfs_pm_info, 0, NULL},
  1392. };
  1393. #endif
  1394. static int amdgpu_debugfs_pm_init(struct amdgpu_device *adev)
  1395. {
  1396. #if defined(CONFIG_DEBUG_FS)
  1397. return amdgpu_debugfs_add_files(adev, amdgpu_pm_info_list, ARRAY_SIZE(amdgpu_pm_info_list));
  1398. #else
  1399. return 0;
  1400. #endif
  1401. }