amdgpu_pm.c 46 KB

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