amdgpu_pm.c 46 KB

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