amdgpu_pm.c 61 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112
  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. static int amdgpu_debugfs_pm_init(struct amdgpu_device *adev);
  35. static const struct cg_flag_name clocks[] = {
  36. {AMD_CG_SUPPORT_GFX_MGCG, "Graphics Medium Grain Clock Gating"},
  37. {AMD_CG_SUPPORT_GFX_MGLS, "Graphics Medium Grain memory Light Sleep"},
  38. {AMD_CG_SUPPORT_GFX_CGCG, "Graphics Coarse Grain Clock Gating"},
  39. {AMD_CG_SUPPORT_GFX_CGLS, "Graphics Coarse Grain memory Light Sleep"},
  40. {AMD_CG_SUPPORT_GFX_CGTS, "Graphics Coarse Grain Tree Shader Clock Gating"},
  41. {AMD_CG_SUPPORT_GFX_CGTS_LS, "Graphics Coarse Grain Tree Shader Light Sleep"},
  42. {AMD_CG_SUPPORT_GFX_CP_LS, "Graphics Command Processor Light Sleep"},
  43. {AMD_CG_SUPPORT_GFX_RLC_LS, "Graphics Run List Controller Light Sleep"},
  44. {AMD_CG_SUPPORT_GFX_3D_CGCG, "Graphics 3D Coarse Grain Clock Gating"},
  45. {AMD_CG_SUPPORT_GFX_3D_CGLS, "Graphics 3D Coarse Grain memory Light Sleep"},
  46. {AMD_CG_SUPPORT_MC_LS, "Memory Controller Light Sleep"},
  47. {AMD_CG_SUPPORT_MC_MGCG, "Memory Controller Medium Grain Clock Gating"},
  48. {AMD_CG_SUPPORT_SDMA_LS, "System Direct Memory Access Light Sleep"},
  49. {AMD_CG_SUPPORT_SDMA_MGCG, "System Direct Memory Access Medium Grain Clock Gating"},
  50. {AMD_CG_SUPPORT_BIF_MGCG, "Bus Interface Medium Grain Clock Gating"},
  51. {AMD_CG_SUPPORT_BIF_LS, "Bus Interface Light Sleep"},
  52. {AMD_CG_SUPPORT_UVD_MGCG, "Unified Video Decoder Medium Grain Clock Gating"},
  53. {AMD_CG_SUPPORT_VCE_MGCG, "Video Compression Engine Medium Grain Clock Gating"},
  54. {AMD_CG_SUPPORT_HDP_LS, "Host Data Path Light Sleep"},
  55. {AMD_CG_SUPPORT_HDP_MGCG, "Host Data Path Medium Grain Clock Gating"},
  56. {AMD_CG_SUPPORT_DRM_MGCG, "Digital Right Management Medium Grain Clock Gating"},
  57. {AMD_CG_SUPPORT_DRM_LS, "Digital Right Management Light Sleep"},
  58. {AMD_CG_SUPPORT_ROM_MGCG, "Rom Medium Grain Clock Gating"},
  59. {AMD_CG_SUPPORT_DF_MGCG, "Data Fabric Medium Grain Clock Gating"},
  60. {0, NULL},
  61. };
  62. void amdgpu_pm_acpi_event_handler(struct amdgpu_device *adev)
  63. {
  64. if (adev->pm.dpm_enabled) {
  65. mutex_lock(&adev->pm.mutex);
  66. if (power_supply_is_system_supplied() > 0)
  67. adev->pm.ac_power = true;
  68. else
  69. adev->pm.ac_power = false;
  70. if (adev->powerplay.pp_funcs->enable_bapm)
  71. amdgpu_dpm_enable_bapm(adev, adev->pm.ac_power);
  72. mutex_unlock(&adev->pm.mutex);
  73. }
  74. }
  75. /**
  76. * DOC: power_dpm_state
  77. *
  78. * The power_dpm_state file is a legacy interface and is only provided for
  79. * backwards compatibility. The amdgpu driver provides a sysfs API for adjusting
  80. * certain power related parameters. The file power_dpm_state is used for this.
  81. * It accepts the following arguments:
  82. *
  83. * - battery
  84. *
  85. * - balanced
  86. *
  87. * - performance
  88. *
  89. * battery
  90. *
  91. * On older GPUs, the vbios provided a special power state for battery
  92. * operation. Selecting battery switched to this state. This is no
  93. * longer provided on newer GPUs so the option does nothing in that case.
  94. *
  95. * balanced
  96. *
  97. * On older GPUs, the vbios provided a special power state for balanced
  98. * operation. Selecting balanced switched to this state. This is no
  99. * longer provided on newer GPUs so the option does nothing in that case.
  100. *
  101. * performance
  102. *
  103. * On older GPUs, the vbios provided a special power state for performance
  104. * operation. Selecting performance switched to this state. This is no
  105. * longer provided on newer GPUs so the option does nothing in that case.
  106. *
  107. */
  108. static ssize_t amdgpu_get_dpm_state(struct device *dev,
  109. struct device_attribute *attr,
  110. char *buf)
  111. {
  112. struct drm_device *ddev = dev_get_drvdata(dev);
  113. struct amdgpu_device *adev = ddev->dev_private;
  114. enum amd_pm_state_type pm;
  115. if (adev->powerplay.pp_funcs->get_current_power_state)
  116. pm = amdgpu_dpm_get_current_power_state(adev);
  117. else
  118. pm = adev->pm.dpm.user_state;
  119. return snprintf(buf, PAGE_SIZE, "%s\n",
  120. (pm == POWER_STATE_TYPE_BATTERY) ? "battery" :
  121. (pm == POWER_STATE_TYPE_BALANCED) ? "balanced" : "performance");
  122. }
  123. static ssize_t amdgpu_set_dpm_state(struct device *dev,
  124. struct device_attribute *attr,
  125. const char *buf,
  126. size_t count)
  127. {
  128. struct drm_device *ddev = dev_get_drvdata(dev);
  129. struct amdgpu_device *adev = ddev->dev_private;
  130. enum amd_pm_state_type state;
  131. if (strncmp("battery", buf, strlen("battery")) == 0)
  132. state = POWER_STATE_TYPE_BATTERY;
  133. else if (strncmp("balanced", buf, strlen("balanced")) == 0)
  134. state = POWER_STATE_TYPE_BALANCED;
  135. else if (strncmp("performance", buf, strlen("performance")) == 0)
  136. state = POWER_STATE_TYPE_PERFORMANCE;
  137. else {
  138. count = -EINVAL;
  139. goto fail;
  140. }
  141. if (adev->powerplay.pp_funcs->dispatch_tasks) {
  142. amdgpu_dpm_dispatch_task(adev, AMD_PP_TASK_ENABLE_USER_STATE, &state);
  143. } else {
  144. mutex_lock(&adev->pm.mutex);
  145. adev->pm.dpm.user_state = state;
  146. mutex_unlock(&adev->pm.mutex);
  147. /* Can't set dpm state when the card is off */
  148. if (!(adev->flags & AMD_IS_PX) ||
  149. (ddev->switch_power_state == DRM_SWITCH_POWER_ON))
  150. amdgpu_pm_compute_clocks(adev);
  151. }
  152. fail:
  153. return count;
  154. }
  155. /**
  156. * DOC: power_dpm_force_performance_level
  157. *
  158. * The amdgpu driver provides a sysfs API for adjusting certain power
  159. * related parameters. The file power_dpm_force_performance_level is
  160. * used for this. It accepts the following arguments:
  161. *
  162. * - auto
  163. *
  164. * - low
  165. *
  166. * - high
  167. *
  168. * - manual
  169. *
  170. * - profile_standard
  171. *
  172. * - profile_min_sclk
  173. *
  174. * - profile_min_mclk
  175. *
  176. * - profile_peak
  177. *
  178. * auto
  179. *
  180. * When auto is selected, the driver will attempt to dynamically select
  181. * the optimal power profile for current conditions in the driver.
  182. *
  183. * low
  184. *
  185. * When low is selected, the clocks are forced to the lowest power state.
  186. *
  187. * high
  188. *
  189. * When high is selected, the clocks are forced to the highest power state.
  190. *
  191. * manual
  192. *
  193. * When manual is selected, the user can manually adjust which power states
  194. * are enabled for each clock domain via the sysfs pp_dpm_mclk, pp_dpm_sclk,
  195. * and pp_dpm_pcie files and adjust the power state transition heuristics
  196. * via the pp_power_profile_mode sysfs file.
  197. *
  198. * profile_standard
  199. * profile_min_sclk
  200. * profile_min_mclk
  201. * profile_peak
  202. *
  203. * When the profiling modes are selected, clock and power gating are
  204. * disabled and the clocks are set for different profiling cases. This
  205. * mode is recommended for profiling specific work loads where you do
  206. * not want clock or power gating for clock fluctuation to interfere
  207. * with your results. profile_standard sets the clocks to a fixed clock
  208. * level which varies from asic to asic. profile_min_sclk forces the sclk
  209. * to the lowest level. profile_min_mclk forces the mclk to the lowest level.
  210. * profile_peak sets all clocks (mclk, sclk, pcie) to the highest levels.
  211. *
  212. */
  213. static ssize_t amdgpu_get_dpm_forced_performance_level(struct device *dev,
  214. struct device_attribute *attr,
  215. char *buf)
  216. {
  217. struct drm_device *ddev = dev_get_drvdata(dev);
  218. struct amdgpu_device *adev = ddev->dev_private;
  219. enum amd_dpm_forced_level level = 0xff;
  220. if ((adev->flags & AMD_IS_PX) &&
  221. (ddev->switch_power_state != DRM_SWITCH_POWER_ON))
  222. return snprintf(buf, PAGE_SIZE, "off\n");
  223. if (adev->powerplay.pp_funcs->get_performance_level)
  224. level = amdgpu_dpm_get_performance_level(adev);
  225. else
  226. level = adev->pm.dpm.forced_level;
  227. return snprintf(buf, PAGE_SIZE, "%s\n",
  228. (level == AMD_DPM_FORCED_LEVEL_AUTO) ? "auto" :
  229. (level == AMD_DPM_FORCED_LEVEL_LOW) ? "low" :
  230. (level == AMD_DPM_FORCED_LEVEL_HIGH) ? "high" :
  231. (level == AMD_DPM_FORCED_LEVEL_MANUAL) ? "manual" :
  232. (level == AMD_DPM_FORCED_LEVEL_PROFILE_STANDARD) ? "profile_standard" :
  233. (level == AMD_DPM_FORCED_LEVEL_PROFILE_MIN_SCLK) ? "profile_min_sclk" :
  234. (level == AMD_DPM_FORCED_LEVEL_PROFILE_MIN_MCLK) ? "profile_min_mclk" :
  235. (level == AMD_DPM_FORCED_LEVEL_PROFILE_PEAK) ? "profile_peak" :
  236. "unknown");
  237. }
  238. static ssize_t amdgpu_set_dpm_forced_performance_level(struct device *dev,
  239. struct device_attribute *attr,
  240. const char *buf,
  241. size_t count)
  242. {
  243. struct drm_device *ddev = dev_get_drvdata(dev);
  244. struct amdgpu_device *adev = ddev->dev_private;
  245. enum amd_dpm_forced_level level;
  246. enum amd_dpm_forced_level current_level = 0xff;
  247. int ret = 0;
  248. /* Can't force performance level when the card is off */
  249. if ((adev->flags & AMD_IS_PX) &&
  250. (ddev->switch_power_state != DRM_SWITCH_POWER_ON))
  251. return -EINVAL;
  252. if (adev->powerplay.pp_funcs->get_performance_level)
  253. current_level = amdgpu_dpm_get_performance_level(adev);
  254. if (strncmp("low", buf, strlen("low")) == 0) {
  255. level = AMD_DPM_FORCED_LEVEL_LOW;
  256. } else if (strncmp("high", buf, strlen("high")) == 0) {
  257. level = AMD_DPM_FORCED_LEVEL_HIGH;
  258. } else if (strncmp("auto", buf, strlen("auto")) == 0) {
  259. level = AMD_DPM_FORCED_LEVEL_AUTO;
  260. } else if (strncmp("manual", buf, strlen("manual")) == 0) {
  261. level = AMD_DPM_FORCED_LEVEL_MANUAL;
  262. } else if (strncmp("profile_exit", buf, strlen("profile_exit")) == 0) {
  263. level = AMD_DPM_FORCED_LEVEL_PROFILE_EXIT;
  264. } else if (strncmp("profile_standard", buf, strlen("profile_standard")) == 0) {
  265. level = AMD_DPM_FORCED_LEVEL_PROFILE_STANDARD;
  266. } else if (strncmp("profile_min_sclk", buf, strlen("profile_min_sclk")) == 0) {
  267. level = AMD_DPM_FORCED_LEVEL_PROFILE_MIN_SCLK;
  268. } else if (strncmp("profile_min_mclk", buf, strlen("profile_min_mclk")) == 0) {
  269. level = AMD_DPM_FORCED_LEVEL_PROFILE_MIN_MCLK;
  270. } else if (strncmp("profile_peak", buf, strlen("profile_peak")) == 0) {
  271. level = AMD_DPM_FORCED_LEVEL_PROFILE_PEAK;
  272. } else {
  273. count = -EINVAL;
  274. goto fail;
  275. }
  276. if (current_level == level)
  277. return count;
  278. if (adev->powerplay.pp_funcs->force_performance_level) {
  279. mutex_lock(&adev->pm.mutex);
  280. if (adev->pm.dpm.thermal_active) {
  281. count = -EINVAL;
  282. mutex_unlock(&adev->pm.mutex);
  283. goto fail;
  284. }
  285. ret = amdgpu_dpm_force_performance_level(adev, level);
  286. if (ret)
  287. count = -EINVAL;
  288. else
  289. adev->pm.dpm.forced_level = level;
  290. mutex_unlock(&adev->pm.mutex);
  291. }
  292. fail:
  293. return count;
  294. }
  295. static ssize_t amdgpu_get_pp_num_states(struct device *dev,
  296. struct device_attribute *attr,
  297. char *buf)
  298. {
  299. struct drm_device *ddev = dev_get_drvdata(dev);
  300. struct amdgpu_device *adev = ddev->dev_private;
  301. struct pp_states_info data;
  302. int i, buf_len;
  303. if (adev->powerplay.pp_funcs->get_pp_num_states)
  304. amdgpu_dpm_get_pp_num_states(adev, &data);
  305. buf_len = snprintf(buf, PAGE_SIZE, "states: %d\n", data.nums);
  306. for (i = 0; i < data.nums; i++)
  307. buf_len += snprintf(buf + buf_len, PAGE_SIZE, "%d %s\n", i,
  308. (data.states[i] == POWER_STATE_TYPE_INTERNAL_BOOT) ? "boot" :
  309. (data.states[i] == POWER_STATE_TYPE_BATTERY) ? "battery" :
  310. (data.states[i] == POWER_STATE_TYPE_BALANCED) ? "balanced" :
  311. (data.states[i] == POWER_STATE_TYPE_PERFORMANCE) ? "performance" : "default");
  312. return buf_len;
  313. }
  314. static ssize_t amdgpu_get_pp_cur_state(struct device *dev,
  315. struct device_attribute *attr,
  316. char *buf)
  317. {
  318. struct drm_device *ddev = dev_get_drvdata(dev);
  319. struct amdgpu_device *adev = ddev->dev_private;
  320. struct pp_states_info data;
  321. enum amd_pm_state_type pm = 0;
  322. int i = 0;
  323. if (adev->powerplay.pp_funcs->get_current_power_state
  324. && adev->powerplay.pp_funcs->get_pp_num_states) {
  325. pm = amdgpu_dpm_get_current_power_state(adev);
  326. amdgpu_dpm_get_pp_num_states(adev, &data);
  327. for (i = 0; i < data.nums; i++) {
  328. if (pm == data.states[i])
  329. break;
  330. }
  331. if (i == data.nums)
  332. i = -EINVAL;
  333. }
  334. return snprintf(buf, PAGE_SIZE, "%d\n", i);
  335. }
  336. static ssize_t amdgpu_get_pp_force_state(struct device *dev,
  337. struct device_attribute *attr,
  338. char *buf)
  339. {
  340. struct drm_device *ddev = dev_get_drvdata(dev);
  341. struct amdgpu_device *adev = ddev->dev_private;
  342. if (adev->pp_force_state_enabled)
  343. return amdgpu_get_pp_cur_state(dev, attr, buf);
  344. else
  345. return snprintf(buf, PAGE_SIZE, "\n");
  346. }
  347. static ssize_t amdgpu_set_pp_force_state(struct device *dev,
  348. struct device_attribute *attr,
  349. const char *buf,
  350. size_t count)
  351. {
  352. struct drm_device *ddev = dev_get_drvdata(dev);
  353. struct amdgpu_device *adev = ddev->dev_private;
  354. enum amd_pm_state_type state = 0;
  355. unsigned long idx;
  356. int ret;
  357. if (strlen(buf) == 1)
  358. adev->pp_force_state_enabled = false;
  359. else if (adev->powerplay.pp_funcs->dispatch_tasks &&
  360. adev->powerplay.pp_funcs->get_pp_num_states) {
  361. struct pp_states_info data;
  362. ret = kstrtoul(buf, 0, &idx);
  363. if (ret || idx >= ARRAY_SIZE(data.states)) {
  364. count = -EINVAL;
  365. goto fail;
  366. }
  367. amdgpu_dpm_get_pp_num_states(adev, &data);
  368. state = data.states[idx];
  369. /* only set user selected power states */
  370. if (state != POWER_STATE_TYPE_INTERNAL_BOOT &&
  371. state != POWER_STATE_TYPE_DEFAULT) {
  372. amdgpu_dpm_dispatch_task(adev,
  373. AMD_PP_TASK_ENABLE_USER_STATE, &state);
  374. adev->pp_force_state_enabled = true;
  375. }
  376. }
  377. fail:
  378. return count;
  379. }
  380. /**
  381. * DOC: pp_table
  382. *
  383. * The amdgpu driver provides a sysfs API for uploading new powerplay
  384. * tables. The file pp_table is used for this. Reading the file
  385. * will dump the current power play table. Writing to the file
  386. * will attempt to upload a new powerplay table and re-initialize
  387. * powerplay using that new table.
  388. *
  389. */
  390. static ssize_t amdgpu_get_pp_table(struct device *dev,
  391. struct device_attribute *attr,
  392. char *buf)
  393. {
  394. struct drm_device *ddev = dev_get_drvdata(dev);
  395. struct amdgpu_device *adev = ddev->dev_private;
  396. char *table = NULL;
  397. int size;
  398. if (adev->powerplay.pp_funcs->get_pp_table)
  399. size = amdgpu_dpm_get_pp_table(adev, &table);
  400. else
  401. return 0;
  402. if (size >= PAGE_SIZE)
  403. size = PAGE_SIZE - 1;
  404. memcpy(buf, table, size);
  405. return size;
  406. }
  407. static ssize_t amdgpu_set_pp_table(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. if (adev->powerplay.pp_funcs->set_pp_table)
  415. amdgpu_dpm_set_pp_table(adev, buf, count);
  416. return count;
  417. }
  418. /**
  419. * DOC: pp_od_clk_voltage
  420. *
  421. * The amdgpu driver provides a sysfs API for adjusting the clocks and voltages
  422. * in each power level within a power state. The pp_od_clk_voltage is used for
  423. * this.
  424. *
  425. * Reading the file will display:
  426. *
  427. * - a list of engine clock levels and voltages labeled OD_SCLK
  428. *
  429. * - a list of memory clock levels and voltages labeled OD_MCLK
  430. *
  431. * - a list of valid ranges for sclk, mclk, and voltage labeled OD_RANGE
  432. *
  433. * To manually adjust these settings, first select manual using
  434. * power_dpm_force_performance_level. Enter a new value for each
  435. * level by writing a string that contains "s/m level clock voltage" to
  436. * the file. E.g., "s 1 500 820" will update sclk level 1 to be 500 MHz
  437. * at 820 mV; "m 0 350 810" will update mclk level 0 to be 350 MHz at
  438. * 810 mV. When you have edited all of the states as needed, write
  439. * "c" (commit) to the file to commit your changes. If you want to reset to the
  440. * default power levels, write "r" (reset) to the file to reset them.
  441. *
  442. */
  443. static ssize_t amdgpu_set_pp_od_clk_voltage(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. uint32_t parameter_size = 0;
  452. long parameter[64];
  453. char buf_cpy[128];
  454. char *tmp_str;
  455. char *sub_str;
  456. const char delimiter[3] = {' ', '\n', '\0'};
  457. uint32_t type;
  458. if (count > 127)
  459. return -EINVAL;
  460. if (*buf == 's')
  461. type = PP_OD_EDIT_SCLK_VDDC_TABLE;
  462. else if (*buf == 'm')
  463. type = PP_OD_EDIT_MCLK_VDDC_TABLE;
  464. else if(*buf == 'r')
  465. type = PP_OD_RESTORE_DEFAULT_TABLE;
  466. else if (*buf == 'c')
  467. type = PP_OD_COMMIT_DPM_TABLE;
  468. else
  469. return -EINVAL;
  470. memcpy(buf_cpy, buf, count+1);
  471. tmp_str = buf_cpy;
  472. while (isspace(*++tmp_str));
  473. while (tmp_str[0]) {
  474. sub_str = strsep(&tmp_str, delimiter);
  475. ret = kstrtol(sub_str, 0, &parameter[parameter_size]);
  476. if (ret)
  477. return -EINVAL;
  478. parameter_size++;
  479. while (isspace(*tmp_str))
  480. tmp_str++;
  481. }
  482. if (adev->powerplay.pp_funcs->odn_edit_dpm_table)
  483. ret = amdgpu_dpm_odn_edit_dpm_table(adev, type,
  484. parameter, parameter_size);
  485. if (ret)
  486. return -EINVAL;
  487. if (type == PP_OD_COMMIT_DPM_TABLE) {
  488. if (adev->powerplay.pp_funcs->dispatch_tasks) {
  489. amdgpu_dpm_dispatch_task(adev, AMD_PP_TASK_READJUST_POWER_STATE, NULL);
  490. return count;
  491. } else {
  492. return -EINVAL;
  493. }
  494. }
  495. return count;
  496. }
  497. static ssize_t amdgpu_get_pp_od_clk_voltage(struct device *dev,
  498. struct device_attribute *attr,
  499. char *buf)
  500. {
  501. struct drm_device *ddev = dev_get_drvdata(dev);
  502. struct amdgpu_device *adev = ddev->dev_private;
  503. uint32_t size = 0;
  504. if (adev->powerplay.pp_funcs->print_clock_levels) {
  505. size = amdgpu_dpm_print_clock_levels(adev, OD_SCLK, buf);
  506. size += amdgpu_dpm_print_clock_levels(adev, OD_MCLK, buf+size);
  507. size += amdgpu_dpm_print_clock_levels(adev, OD_RANGE, buf+size);
  508. return size;
  509. } else {
  510. return snprintf(buf, PAGE_SIZE, "\n");
  511. }
  512. }
  513. /**
  514. * DOC: pp_dpm_sclk pp_dpm_mclk pp_dpm_pcie
  515. *
  516. * The amdgpu driver provides a sysfs API for adjusting what power levels
  517. * are enabled for a given power state. The files pp_dpm_sclk, pp_dpm_mclk,
  518. * and pp_dpm_pcie are used for this.
  519. *
  520. * Reading back the files will show you the available power levels within
  521. * the power state and the clock information for those levels.
  522. *
  523. * To manually adjust these states, first select manual using
  524. * power_dpm_force_performance_level.
  525. * Secondly,Enter a new value for each level by inputing a string that
  526. * contains " echo xx xx xx > pp_dpm_sclk/mclk/pcie"
  527. * E.g., echo 4 5 6 to > pp_dpm_sclk will enable sclk levels 4, 5, and 6.
  528. */
  529. static ssize_t amdgpu_get_pp_dpm_sclk(struct device *dev,
  530. struct device_attribute *attr,
  531. char *buf)
  532. {
  533. struct drm_device *ddev = dev_get_drvdata(dev);
  534. struct amdgpu_device *adev = ddev->dev_private;
  535. if (adev->powerplay.pp_funcs->print_clock_levels)
  536. return amdgpu_dpm_print_clock_levels(adev, PP_SCLK, buf);
  537. else
  538. return snprintf(buf, PAGE_SIZE, "\n");
  539. }
  540. static ssize_t amdgpu_set_pp_dpm_sclk(struct device *dev,
  541. struct device_attribute *attr,
  542. const char *buf,
  543. size_t count)
  544. {
  545. struct drm_device *ddev = dev_get_drvdata(dev);
  546. struct amdgpu_device *adev = ddev->dev_private;
  547. int ret;
  548. long level;
  549. uint32_t mask = 0;
  550. char *sub_str = NULL;
  551. char *tmp;
  552. char buf_cpy[count];
  553. const char delimiter[3] = {' ', '\n', '\0'};
  554. memcpy(buf_cpy, buf, count+1);
  555. tmp = buf_cpy;
  556. while (tmp[0]) {
  557. sub_str = strsep(&tmp, delimiter);
  558. if (strlen(sub_str)) {
  559. ret = kstrtol(sub_str, 0, &level);
  560. if (ret) {
  561. count = -EINVAL;
  562. goto fail;
  563. }
  564. mask |= 1 << level;
  565. } else
  566. break;
  567. }
  568. if (adev->powerplay.pp_funcs->force_clock_level)
  569. amdgpu_dpm_force_clock_level(adev, PP_SCLK, mask);
  570. fail:
  571. return count;
  572. }
  573. static ssize_t amdgpu_get_pp_dpm_mclk(struct device *dev,
  574. struct device_attribute *attr,
  575. char *buf)
  576. {
  577. struct drm_device *ddev = dev_get_drvdata(dev);
  578. struct amdgpu_device *adev = ddev->dev_private;
  579. if (adev->powerplay.pp_funcs->print_clock_levels)
  580. return amdgpu_dpm_print_clock_levels(adev, PP_MCLK, buf);
  581. else
  582. return snprintf(buf, PAGE_SIZE, "\n");
  583. }
  584. static ssize_t amdgpu_set_pp_dpm_mclk(struct device *dev,
  585. struct device_attribute *attr,
  586. const char *buf,
  587. size_t count)
  588. {
  589. struct drm_device *ddev = dev_get_drvdata(dev);
  590. struct amdgpu_device *adev = ddev->dev_private;
  591. int ret;
  592. long level;
  593. uint32_t mask = 0;
  594. char *sub_str = NULL;
  595. char *tmp;
  596. char buf_cpy[count];
  597. const char delimiter[3] = {' ', '\n', '\0'};
  598. memcpy(buf_cpy, buf, count+1);
  599. tmp = buf_cpy;
  600. while (tmp[0]) {
  601. sub_str = strsep(&tmp, delimiter);
  602. if (strlen(sub_str)) {
  603. ret = kstrtol(sub_str, 0, &level);
  604. if (ret) {
  605. count = -EINVAL;
  606. goto fail;
  607. }
  608. mask |= 1 << level;
  609. } else
  610. break;
  611. }
  612. if (adev->powerplay.pp_funcs->force_clock_level)
  613. amdgpu_dpm_force_clock_level(adev, PP_MCLK, mask);
  614. fail:
  615. return count;
  616. }
  617. static ssize_t amdgpu_get_pp_dpm_pcie(struct device *dev,
  618. struct device_attribute *attr,
  619. char *buf)
  620. {
  621. struct drm_device *ddev = dev_get_drvdata(dev);
  622. struct amdgpu_device *adev = ddev->dev_private;
  623. if (adev->powerplay.pp_funcs->print_clock_levels)
  624. return amdgpu_dpm_print_clock_levels(adev, PP_PCIE, buf);
  625. else
  626. return snprintf(buf, PAGE_SIZE, "\n");
  627. }
  628. static ssize_t amdgpu_set_pp_dpm_pcie(struct device *dev,
  629. struct device_attribute *attr,
  630. const char *buf,
  631. size_t count)
  632. {
  633. struct drm_device *ddev = dev_get_drvdata(dev);
  634. struct amdgpu_device *adev = ddev->dev_private;
  635. int ret;
  636. long level;
  637. uint32_t mask = 0;
  638. char *sub_str = NULL;
  639. char *tmp;
  640. char buf_cpy[count];
  641. const char delimiter[3] = {' ', '\n', '\0'};
  642. memcpy(buf_cpy, buf, count+1);
  643. tmp = buf_cpy;
  644. while (tmp[0]) {
  645. sub_str = strsep(&tmp, delimiter);
  646. if (strlen(sub_str)) {
  647. ret = kstrtol(sub_str, 0, &level);
  648. if (ret) {
  649. count = -EINVAL;
  650. goto fail;
  651. }
  652. mask |= 1 << level;
  653. } else
  654. break;
  655. }
  656. if (adev->powerplay.pp_funcs->force_clock_level)
  657. amdgpu_dpm_force_clock_level(adev, PP_PCIE, mask);
  658. fail:
  659. return count;
  660. }
  661. static ssize_t amdgpu_get_pp_sclk_od(struct device *dev,
  662. struct device_attribute *attr,
  663. char *buf)
  664. {
  665. struct drm_device *ddev = dev_get_drvdata(dev);
  666. struct amdgpu_device *adev = ddev->dev_private;
  667. uint32_t value = 0;
  668. if (adev->powerplay.pp_funcs->get_sclk_od)
  669. value = amdgpu_dpm_get_sclk_od(adev);
  670. return snprintf(buf, PAGE_SIZE, "%d\n", value);
  671. }
  672. static ssize_t amdgpu_set_pp_sclk_od(struct device *dev,
  673. struct device_attribute *attr,
  674. const char *buf,
  675. size_t count)
  676. {
  677. struct drm_device *ddev = dev_get_drvdata(dev);
  678. struct amdgpu_device *adev = ddev->dev_private;
  679. int ret;
  680. long int value;
  681. ret = kstrtol(buf, 0, &value);
  682. if (ret) {
  683. count = -EINVAL;
  684. goto fail;
  685. }
  686. if (adev->powerplay.pp_funcs->set_sclk_od)
  687. amdgpu_dpm_set_sclk_od(adev, (uint32_t)value);
  688. if (adev->powerplay.pp_funcs->dispatch_tasks) {
  689. amdgpu_dpm_dispatch_task(adev, AMD_PP_TASK_READJUST_POWER_STATE, NULL);
  690. } else {
  691. adev->pm.dpm.current_ps = adev->pm.dpm.boot_ps;
  692. amdgpu_pm_compute_clocks(adev);
  693. }
  694. fail:
  695. return count;
  696. }
  697. static ssize_t amdgpu_get_pp_mclk_od(struct device *dev,
  698. struct device_attribute *attr,
  699. char *buf)
  700. {
  701. struct drm_device *ddev = dev_get_drvdata(dev);
  702. struct amdgpu_device *adev = ddev->dev_private;
  703. uint32_t value = 0;
  704. if (adev->powerplay.pp_funcs->get_mclk_od)
  705. value = amdgpu_dpm_get_mclk_od(adev);
  706. return snprintf(buf, PAGE_SIZE, "%d\n", value);
  707. }
  708. static ssize_t amdgpu_set_pp_mclk_od(struct device *dev,
  709. struct device_attribute *attr,
  710. const char *buf,
  711. size_t count)
  712. {
  713. struct drm_device *ddev = dev_get_drvdata(dev);
  714. struct amdgpu_device *adev = ddev->dev_private;
  715. int ret;
  716. long int value;
  717. ret = kstrtol(buf, 0, &value);
  718. if (ret) {
  719. count = -EINVAL;
  720. goto fail;
  721. }
  722. if (adev->powerplay.pp_funcs->set_mclk_od)
  723. amdgpu_dpm_set_mclk_od(adev, (uint32_t)value);
  724. if (adev->powerplay.pp_funcs->dispatch_tasks) {
  725. amdgpu_dpm_dispatch_task(adev, AMD_PP_TASK_READJUST_POWER_STATE, NULL);
  726. } else {
  727. adev->pm.dpm.current_ps = adev->pm.dpm.boot_ps;
  728. amdgpu_pm_compute_clocks(adev);
  729. }
  730. fail:
  731. return count;
  732. }
  733. /**
  734. * DOC: pp_power_profile_mode
  735. *
  736. * The amdgpu driver provides a sysfs API for adjusting the heuristics
  737. * related to switching between power levels in a power state. The file
  738. * pp_power_profile_mode is used for this.
  739. *
  740. * Reading this file outputs a list of all of the predefined power profiles
  741. * and the relevant heuristics settings for that profile.
  742. *
  743. * To select a profile or create a custom profile, first select manual using
  744. * power_dpm_force_performance_level. Writing the number of a predefined
  745. * profile to pp_power_profile_mode will enable those heuristics. To
  746. * create a custom set of heuristics, write a string of numbers to the file
  747. * starting with the number of the custom profile along with a setting
  748. * for each heuristic parameter. Due to differences across asic families
  749. * the heuristic parameters vary from family to family.
  750. *
  751. */
  752. static ssize_t amdgpu_get_pp_power_profile_mode(struct device *dev,
  753. struct device_attribute *attr,
  754. char *buf)
  755. {
  756. struct drm_device *ddev = dev_get_drvdata(dev);
  757. struct amdgpu_device *adev = ddev->dev_private;
  758. if (adev->powerplay.pp_funcs->get_power_profile_mode)
  759. return amdgpu_dpm_get_power_profile_mode(adev, buf);
  760. return snprintf(buf, PAGE_SIZE, "\n");
  761. }
  762. static ssize_t amdgpu_set_pp_power_profile_mode(struct device *dev,
  763. struct device_attribute *attr,
  764. const char *buf,
  765. size_t count)
  766. {
  767. int ret = 0xff;
  768. struct drm_device *ddev = dev_get_drvdata(dev);
  769. struct amdgpu_device *adev = ddev->dev_private;
  770. uint32_t parameter_size = 0;
  771. long parameter[64];
  772. char *sub_str, buf_cpy[128];
  773. char *tmp_str;
  774. uint32_t i = 0;
  775. char tmp[2];
  776. long int profile_mode = 0;
  777. const char delimiter[3] = {' ', '\n', '\0'};
  778. tmp[0] = *(buf);
  779. tmp[1] = '\0';
  780. ret = kstrtol(tmp, 0, &profile_mode);
  781. if (ret)
  782. goto fail;
  783. if (profile_mode == PP_SMC_POWER_PROFILE_CUSTOM) {
  784. if (count < 2 || count > 127)
  785. return -EINVAL;
  786. while (isspace(*++buf))
  787. i++;
  788. memcpy(buf_cpy, buf, count-i);
  789. tmp_str = buf_cpy;
  790. while (tmp_str[0]) {
  791. sub_str = strsep(&tmp_str, delimiter);
  792. ret = kstrtol(sub_str, 0, &parameter[parameter_size]);
  793. if (ret) {
  794. count = -EINVAL;
  795. goto fail;
  796. }
  797. parameter_size++;
  798. while (isspace(*tmp_str))
  799. tmp_str++;
  800. }
  801. }
  802. parameter[parameter_size] = profile_mode;
  803. if (adev->powerplay.pp_funcs->set_power_profile_mode)
  804. ret = amdgpu_dpm_set_power_profile_mode(adev, parameter, parameter_size);
  805. if (!ret)
  806. return count;
  807. fail:
  808. return -EINVAL;
  809. }
  810. /**
  811. * DOC: busy_percent
  812. *
  813. * The amdgpu driver provides a sysfs API for reading how busy the GPU
  814. * is as a percentage. The file gpu_busy_percent is used for this.
  815. * The SMU firmware computes a percentage of load based on the
  816. * aggregate activity level in the IP cores.
  817. */
  818. static ssize_t amdgpu_get_busy_percent(struct device *dev,
  819. struct device_attribute *attr,
  820. char *buf)
  821. {
  822. struct drm_device *ddev = dev_get_drvdata(dev);
  823. struct amdgpu_device *adev = ddev->dev_private;
  824. int r, value, size = sizeof(value);
  825. /* sanity check PP is enabled */
  826. if (!(adev->powerplay.pp_funcs &&
  827. adev->powerplay.pp_funcs->read_sensor))
  828. return -EINVAL;
  829. /* read the IP busy sensor */
  830. r = amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GPU_LOAD,
  831. (void *)&value, &size);
  832. if (r)
  833. return r;
  834. return snprintf(buf, PAGE_SIZE, "%d\n", value);
  835. }
  836. static DEVICE_ATTR(power_dpm_state, S_IRUGO | S_IWUSR, amdgpu_get_dpm_state, amdgpu_set_dpm_state);
  837. static DEVICE_ATTR(power_dpm_force_performance_level, S_IRUGO | S_IWUSR,
  838. amdgpu_get_dpm_forced_performance_level,
  839. amdgpu_set_dpm_forced_performance_level);
  840. static DEVICE_ATTR(pp_num_states, S_IRUGO, amdgpu_get_pp_num_states, NULL);
  841. static DEVICE_ATTR(pp_cur_state, S_IRUGO, amdgpu_get_pp_cur_state, NULL);
  842. static DEVICE_ATTR(pp_force_state, S_IRUGO | S_IWUSR,
  843. amdgpu_get_pp_force_state,
  844. amdgpu_set_pp_force_state);
  845. static DEVICE_ATTR(pp_table, S_IRUGO | S_IWUSR,
  846. amdgpu_get_pp_table,
  847. amdgpu_set_pp_table);
  848. static DEVICE_ATTR(pp_dpm_sclk, S_IRUGO | S_IWUSR,
  849. amdgpu_get_pp_dpm_sclk,
  850. amdgpu_set_pp_dpm_sclk);
  851. static DEVICE_ATTR(pp_dpm_mclk, S_IRUGO | S_IWUSR,
  852. amdgpu_get_pp_dpm_mclk,
  853. amdgpu_set_pp_dpm_mclk);
  854. static DEVICE_ATTR(pp_dpm_pcie, S_IRUGO | S_IWUSR,
  855. amdgpu_get_pp_dpm_pcie,
  856. amdgpu_set_pp_dpm_pcie);
  857. static DEVICE_ATTR(pp_sclk_od, S_IRUGO | S_IWUSR,
  858. amdgpu_get_pp_sclk_od,
  859. amdgpu_set_pp_sclk_od);
  860. static DEVICE_ATTR(pp_mclk_od, S_IRUGO | S_IWUSR,
  861. amdgpu_get_pp_mclk_od,
  862. amdgpu_set_pp_mclk_od);
  863. static DEVICE_ATTR(pp_power_profile_mode, S_IRUGO | S_IWUSR,
  864. amdgpu_get_pp_power_profile_mode,
  865. amdgpu_set_pp_power_profile_mode);
  866. static DEVICE_ATTR(pp_od_clk_voltage, S_IRUGO | S_IWUSR,
  867. amdgpu_get_pp_od_clk_voltage,
  868. amdgpu_set_pp_od_clk_voltage);
  869. static DEVICE_ATTR(gpu_busy_percent, S_IRUGO,
  870. amdgpu_get_busy_percent, NULL);
  871. static ssize_t amdgpu_hwmon_show_temp(struct device *dev,
  872. struct device_attribute *attr,
  873. char *buf)
  874. {
  875. struct amdgpu_device *adev = dev_get_drvdata(dev);
  876. struct drm_device *ddev = adev->ddev;
  877. int r, temp, size = sizeof(temp);
  878. /* Can't get temperature when the card is off */
  879. if ((adev->flags & AMD_IS_PX) &&
  880. (ddev->switch_power_state != DRM_SWITCH_POWER_ON))
  881. return -EINVAL;
  882. /* sanity check PP is enabled */
  883. if (!(adev->powerplay.pp_funcs &&
  884. adev->powerplay.pp_funcs->read_sensor))
  885. return -EINVAL;
  886. /* get the temperature */
  887. r = amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GPU_TEMP,
  888. (void *)&temp, &size);
  889. if (r)
  890. return r;
  891. return snprintf(buf, PAGE_SIZE, "%d\n", temp);
  892. }
  893. static ssize_t amdgpu_hwmon_show_temp_thresh(struct device *dev,
  894. struct device_attribute *attr,
  895. char *buf)
  896. {
  897. struct amdgpu_device *adev = dev_get_drvdata(dev);
  898. int hyst = to_sensor_dev_attr(attr)->index;
  899. int temp;
  900. if (hyst)
  901. temp = adev->pm.dpm.thermal.min_temp;
  902. else
  903. temp = adev->pm.dpm.thermal.max_temp;
  904. return snprintf(buf, PAGE_SIZE, "%d\n", temp);
  905. }
  906. static ssize_t amdgpu_hwmon_get_pwm1_enable(struct device *dev,
  907. struct device_attribute *attr,
  908. char *buf)
  909. {
  910. struct amdgpu_device *adev = dev_get_drvdata(dev);
  911. u32 pwm_mode = 0;
  912. if (!adev->powerplay.pp_funcs->get_fan_control_mode)
  913. return -EINVAL;
  914. pwm_mode = amdgpu_dpm_get_fan_control_mode(adev);
  915. return sprintf(buf, "%i\n", pwm_mode);
  916. }
  917. static ssize_t amdgpu_hwmon_set_pwm1_enable(struct device *dev,
  918. struct device_attribute *attr,
  919. const char *buf,
  920. size_t count)
  921. {
  922. struct amdgpu_device *adev = dev_get_drvdata(dev);
  923. int err;
  924. int value;
  925. /* Can't adjust fan when the card is off */
  926. if ((adev->flags & AMD_IS_PX) &&
  927. (adev->ddev->switch_power_state != DRM_SWITCH_POWER_ON))
  928. return -EINVAL;
  929. if (!adev->powerplay.pp_funcs->set_fan_control_mode)
  930. return -EINVAL;
  931. err = kstrtoint(buf, 10, &value);
  932. if (err)
  933. return err;
  934. amdgpu_dpm_set_fan_control_mode(adev, value);
  935. return count;
  936. }
  937. static ssize_t amdgpu_hwmon_get_pwm1_min(struct device *dev,
  938. struct device_attribute *attr,
  939. char *buf)
  940. {
  941. return sprintf(buf, "%i\n", 0);
  942. }
  943. static ssize_t amdgpu_hwmon_get_pwm1_max(struct device *dev,
  944. struct device_attribute *attr,
  945. char *buf)
  946. {
  947. return sprintf(buf, "%i\n", 255);
  948. }
  949. static ssize_t amdgpu_hwmon_set_pwm1(struct device *dev,
  950. struct device_attribute *attr,
  951. const char *buf, size_t count)
  952. {
  953. struct amdgpu_device *adev = dev_get_drvdata(dev);
  954. int err;
  955. u32 value;
  956. /* Can't adjust fan when the card is off */
  957. if ((adev->flags & AMD_IS_PX) &&
  958. (adev->ddev->switch_power_state != DRM_SWITCH_POWER_ON))
  959. return -EINVAL;
  960. err = kstrtou32(buf, 10, &value);
  961. if (err)
  962. return err;
  963. value = (value * 100) / 255;
  964. if (adev->powerplay.pp_funcs->set_fan_speed_percent) {
  965. err = amdgpu_dpm_set_fan_speed_percent(adev, value);
  966. if (err)
  967. return err;
  968. }
  969. return count;
  970. }
  971. static ssize_t amdgpu_hwmon_get_pwm1(struct device *dev,
  972. struct device_attribute *attr,
  973. char *buf)
  974. {
  975. struct amdgpu_device *adev = dev_get_drvdata(dev);
  976. int err;
  977. u32 speed = 0;
  978. /* Can't adjust fan when the card is off */
  979. if ((adev->flags & AMD_IS_PX) &&
  980. (adev->ddev->switch_power_state != DRM_SWITCH_POWER_ON))
  981. return -EINVAL;
  982. if (adev->powerplay.pp_funcs->get_fan_speed_percent) {
  983. err = amdgpu_dpm_get_fan_speed_percent(adev, &speed);
  984. if (err)
  985. return err;
  986. }
  987. speed = (speed * 255) / 100;
  988. return sprintf(buf, "%i\n", speed);
  989. }
  990. static ssize_t amdgpu_hwmon_get_fan1_input(struct device *dev,
  991. struct device_attribute *attr,
  992. char *buf)
  993. {
  994. struct amdgpu_device *adev = dev_get_drvdata(dev);
  995. int err;
  996. u32 speed = 0;
  997. /* Can't adjust fan when the card is off */
  998. if ((adev->flags & AMD_IS_PX) &&
  999. (adev->ddev->switch_power_state != DRM_SWITCH_POWER_ON))
  1000. return -EINVAL;
  1001. if (adev->powerplay.pp_funcs->get_fan_speed_rpm) {
  1002. err = amdgpu_dpm_get_fan_speed_rpm(adev, &speed);
  1003. if (err)
  1004. return err;
  1005. }
  1006. return sprintf(buf, "%i\n", speed);
  1007. }
  1008. static ssize_t amdgpu_hwmon_show_vddgfx(struct device *dev,
  1009. struct device_attribute *attr,
  1010. char *buf)
  1011. {
  1012. struct amdgpu_device *adev = dev_get_drvdata(dev);
  1013. struct drm_device *ddev = adev->ddev;
  1014. u32 vddgfx;
  1015. int r, size = sizeof(vddgfx);
  1016. /* Can't get voltage when the card is off */
  1017. if ((adev->flags & AMD_IS_PX) &&
  1018. (ddev->switch_power_state != DRM_SWITCH_POWER_ON))
  1019. return -EINVAL;
  1020. /* sanity check PP is enabled */
  1021. if (!(adev->powerplay.pp_funcs &&
  1022. adev->powerplay.pp_funcs->read_sensor))
  1023. return -EINVAL;
  1024. /* get the voltage */
  1025. r = amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_VDDGFX,
  1026. (void *)&vddgfx, &size);
  1027. if (r)
  1028. return r;
  1029. return snprintf(buf, PAGE_SIZE, "%d\n", vddgfx);
  1030. }
  1031. static ssize_t amdgpu_hwmon_show_vddgfx_label(struct device *dev,
  1032. struct device_attribute *attr,
  1033. char *buf)
  1034. {
  1035. return snprintf(buf, PAGE_SIZE, "vddgfx\n");
  1036. }
  1037. static ssize_t amdgpu_hwmon_show_vddnb(struct device *dev,
  1038. struct device_attribute *attr,
  1039. char *buf)
  1040. {
  1041. struct amdgpu_device *adev = dev_get_drvdata(dev);
  1042. struct drm_device *ddev = adev->ddev;
  1043. u32 vddnb;
  1044. int r, size = sizeof(vddnb);
  1045. /* only APUs have vddnb */
  1046. if (adev->flags & AMD_IS_APU)
  1047. return -EINVAL;
  1048. /* Can't get voltage when the card is off */
  1049. if ((adev->flags & AMD_IS_PX) &&
  1050. (ddev->switch_power_state != DRM_SWITCH_POWER_ON))
  1051. return -EINVAL;
  1052. /* sanity check PP is enabled */
  1053. if (!(adev->powerplay.pp_funcs &&
  1054. adev->powerplay.pp_funcs->read_sensor))
  1055. return -EINVAL;
  1056. /* get the voltage */
  1057. r = amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_VDDNB,
  1058. (void *)&vddnb, &size);
  1059. if (r)
  1060. return r;
  1061. return snprintf(buf, PAGE_SIZE, "%d\n", vddnb);
  1062. }
  1063. static ssize_t amdgpu_hwmon_show_vddnb_label(struct device *dev,
  1064. struct device_attribute *attr,
  1065. char *buf)
  1066. {
  1067. return snprintf(buf, PAGE_SIZE, "vddnb\n");
  1068. }
  1069. static ssize_t amdgpu_hwmon_show_power_avg(struct device *dev,
  1070. struct device_attribute *attr,
  1071. char *buf)
  1072. {
  1073. struct amdgpu_device *adev = dev_get_drvdata(dev);
  1074. struct drm_device *ddev = adev->ddev;
  1075. u32 query = 0;
  1076. int r, size = sizeof(u32);
  1077. unsigned uw;
  1078. /* Can't get power when the card is off */
  1079. if ((adev->flags & AMD_IS_PX) &&
  1080. (ddev->switch_power_state != DRM_SWITCH_POWER_ON))
  1081. return -EINVAL;
  1082. /* sanity check PP is enabled */
  1083. if (!(adev->powerplay.pp_funcs &&
  1084. adev->powerplay.pp_funcs->read_sensor))
  1085. return -EINVAL;
  1086. /* get the voltage */
  1087. r = amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GPU_POWER,
  1088. (void *)&query, &size);
  1089. if (r)
  1090. return r;
  1091. /* convert to microwatts */
  1092. uw = (query >> 8) * 1000000 + (query & 0xff) * 1000;
  1093. return snprintf(buf, PAGE_SIZE, "%u\n", uw);
  1094. }
  1095. static ssize_t amdgpu_hwmon_show_power_cap_min(struct device *dev,
  1096. struct device_attribute *attr,
  1097. char *buf)
  1098. {
  1099. return sprintf(buf, "%i\n", 0);
  1100. }
  1101. static ssize_t amdgpu_hwmon_show_power_cap_max(struct device *dev,
  1102. struct device_attribute *attr,
  1103. char *buf)
  1104. {
  1105. struct amdgpu_device *adev = dev_get_drvdata(dev);
  1106. uint32_t limit = 0;
  1107. if (adev->powerplay.pp_funcs && adev->powerplay.pp_funcs->get_power_limit) {
  1108. adev->powerplay.pp_funcs->get_power_limit(adev->powerplay.pp_handle, &limit, true);
  1109. return snprintf(buf, PAGE_SIZE, "%u\n", limit * 1000000);
  1110. } else {
  1111. return snprintf(buf, PAGE_SIZE, "\n");
  1112. }
  1113. }
  1114. static ssize_t amdgpu_hwmon_show_power_cap(struct device *dev,
  1115. struct device_attribute *attr,
  1116. char *buf)
  1117. {
  1118. struct amdgpu_device *adev = dev_get_drvdata(dev);
  1119. uint32_t limit = 0;
  1120. if (adev->powerplay.pp_funcs && adev->powerplay.pp_funcs->get_power_limit) {
  1121. adev->powerplay.pp_funcs->get_power_limit(adev->powerplay.pp_handle, &limit, false);
  1122. return snprintf(buf, PAGE_SIZE, "%u\n", limit * 1000000);
  1123. } else {
  1124. return snprintf(buf, PAGE_SIZE, "\n");
  1125. }
  1126. }
  1127. static ssize_t amdgpu_hwmon_set_power_cap(struct device *dev,
  1128. struct device_attribute *attr,
  1129. const char *buf,
  1130. size_t count)
  1131. {
  1132. struct amdgpu_device *adev = dev_get_drvdata(dev);
  1133. int err;
  1134. u32 value;
  1135. err = kstrtou32(buf, 10, &value);
  1136. if (err)
  1137. return err;
  1138. value = value / 1000000; /* convert to Watt */
  1139. if (adev->powerplay.pp_funcs && adev->powerplay.pp_funcs->set_power_limit) {
  1140. err = adev->powerplay.pp_funcs->set_power_limit(adev->powerplay.pp_handle, value);
  1141. if (err)
  1142. return err;
  1143. } else {
  1144. return -EINVAL;
  1145. }
  1146. return count;
  1147. }
  1148. /**
  1149. * DOC: hwmon
  1150. *
  1151. * The amdgpu driver exposes the following sensor interfaces:
  1152. *
  1153. * - GPU temperature (via the on-die sensor)
  1154. *
  1155. * - GPU voltage
  1156. *
  1157. * - Northbridge voltage (APUs only)
  1158. *
  1159. * - GPU power
  1160. *
  1161. * - GPU fan
  1162. *
  1163. * hwmon interfaces for GPU temperature:
  1164. *
  1165. * - temp1_input: the on die GPU temperature in millidegrees Celsius
  1166. *
  1167. * - temp1_crit: temperature critical max value in millidegrees Celsius
  1168. *
  1169. * - temp1_crit_hyst: temperature hysteresis for critical limit in millidegrees Celsius
  1170. *
  1171. * hwmon interfaces for GPU voltage:
  1172. *
  1173. * - in0_input: the voltage on the GPU in millivolts
  1174. *
  1175. * - in1_input: the voltage on the Northbridge in millivolts
  1176. *
  1177. * hwmon interfaces for GPU power:
  1178. *
  1179. * - power1_average: average power used by the GPU in microWatts
  1180. *
  1181. * - power1_cap_min: minimum cap supported in microWatts
  1182. *
  1183. * - power1_cap_max: maximum cap supported in microWatts
  1184. *
  1185. * - power1_cap: selected power cap in microWatts
  1186. *
  1187. * hwmon interfaces for GPU fan:
  1188. *
  1189. * - pwm1: pulse width modulation fan level (0-255)
  1190. *
  1191. * - pwm1_enable: pulse width modulation fan control method (0: no fan speed control, 1: manual fan speed control using pwm interface, 2: automatic fan speed control)
  1192. *
  1193. * - pwm1_min: pulse width modulation fan control minimum level (0)
  1194. *
  1195. * - pwm1_max: pulse width modulation fan control maximum level (255)
  1196. *
  1197. * - fan1_input: fan speed in RPM
  1198. *
  1199. * You can use hwmon tools like sensors to view this information on your system.
  1200. *
  1201. */
  1202. static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, amdgpu_hwmon_show_temp, NULL, 0);
  1203. static SENSOR_DEVICE_ATTR(temp1_crit, S_IRUGO, amdgpu_hwmon_show_temp_thresh, NULL, 0);
  1204. static SENSOR_DEVICE_ATTR(temp1_crit_hyst, S_IRUGO, amdgpu_hwmon_show_temp_thresh, NULL, 1);
  1205. static SENSOR_DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, amdgpu_hwmon_get_pwm1, amdgpu_hwmon_set_pwm1, 0);
  1206. static SENSOR_DEVICE_ATTR(pwm1_enable, S_IRUGO | S_IWUSR, amdgpu_hwmon_get_pwm1_enable, amdgpu_hwmon_set_pwm1_enable, 0);
  1207. static SENSOR_DEVICE_ATTR(pwm1_min, S_IRUGO, amdgpu_hwmon_get_pwm1_min, NULL, 0);
  1208. static SENSOR_DEVICE_ATTR(pwm1_max, S_IRUGO, amdgpu_hwmon_get_pwm1_max, NULL, 0);
  1209. static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, amdgpu_hwmon_get_fan1_input, NULL, 0);
  1210. static SENSOR_DEVICE_ATTR(in0_input, S_IRUGO, amdgpu_hwmon_show_vddgfx, NULL, 0);
  1211. static SENSOR_DEVICE_ATTR(in0_label, S_IRUGO, amdgpu_hwmon_show_vddgfx_label, NULL, 0);
  1212. static SENSOR_DEVICE_ATTR(in1_input, S_IRUGO, amdgpu_hwmon_show_vddnb, NULL, 0);
  1213. static SENSOR_DEVICE_ATTR(in1_label, S_IRUGO, amdgpu_hwmon_show_vddnb_label, NULL, 0);
  1214. static SENSOR_DEVICE_ATTR(power1_average, S_IRUGO, amdgpu_hwmon_show_power_avg, NULL, 0);
  1215. static SENSOR_DEVICE_ATTR(power1_cap_max, S_IRUGO, amdgpu_hwmon_show_power_cap_max, NULL, 0);
  1216. static SENSOR_DEVICE_ATTR(power1_cap_min, S_IRUGO, amdgpu_hwmon_show_power_cap_min, NULL, 0);
  1217. static SENSOR_DEVICE_ATTR(power1_cap, S_IRUGO | S_IWUSR, amdgpu_hwmon_show_power_cap, amdgpu_hwmon_set_power_cap, 0);
  1218. static struct attribute *hwmon_attributes[] = {
  1219. &sensor_dev_attr_temp1_input.dev_attr.attr,
  1220. &sensor_dev_attr_temp1_crit.dev_attr.attr,
  1221. &sensor_dev_attr_temp1_crit_hyst.dev_attr.attr,
  1222. &sensor_dev_attr_pwm1.dev_attr.attr,
  1223. &sensor_dev_attr_pwm1_enable.dev_attr.attr,
  1224. &sensor_dev_attr_pwm1_min.dev_attr.attr,
  1225. &sensor_dev_attr_pwm1_max.dev_attr.attr,
  1226. &sensor_dev_attr_fan1_input.dev_attr.attr,
  1227. &sensor_dev_attr_in0_input.dev_attr.attr,
  1228. &sensor_dev_attr_in0_label.dev_attr.attr,
  1229. &sensor_dev_attr_in1_input.dev_attr.attr,
  1230. &sensor_dev_attr_in1_label.dev_attr.attr,
  1231. &sensor_dev_attr_power1_average.dev_attr.attr,
  1232. &sensor_dev_attr_power1_cap_max.dev_attr.attr,
  1233. &sensor_dev_attr_power1_cap_min.dev_attr.attr,
  1234. &sensor_dev_attr_power1_cap.dev_attr.attr,
  1235. NULL
  1236. };
  1237. static umode_t hwmon_attributes_visible(struct kobject *kobj,
  1238. struct attribute *attr, int index)
  1239. {
  1240. struct device *dev = kobj_to_dev(kobj);
  1241. struct amdgpu_device *adev = dev_get_drvdata(dev);
  1242. umode_t effective_mode = attr->mode;
  1243. /* Skip fan attributes if fan is not present */
  1244. if (adev->pm.no_fan && (attr == &sensor_dev_attr_pwm1.dev_attr.attr ||
  1245. attr == &sensor_dev_attr_pwm1_enable.dev_attr.attr ||
  1246. attr == &sensor_dev_attr_pwm1_max.dev_attr.attr ||
  1247. attr == &sensor_dev_attr_pwm1_min.dev_attr.attr ||
  1248. attr == &sensor_dev_attr_fan1_input.dev_attr.attr))
  1249. return 0;
  1250. /* Skip limit attributes if DPM is not enabled */
  1251. if (!adev->pm.dpm_enabled &&
  1252. (attr == &sensor_dev_attr_temp1_crit.dev_attr.attr ||
  1253. attr == &sensor_dev_attr_temp1_crit_hyst.dev_attr.attr ||
  1254. attr == &sensor_dev_attr_pwm1.dev_attr.attr ||
  1255. attr == &sensor_dev_attr_pwm1_enable.dev_attr.attr ||
  1256. attr == &sensor_dev_attr_pwm1_max.dev_attr.attr ||
  1257. attr == &sensor_dev_attr_pwm1_min.dev_attr.attr))
  1258. return 0;
  1259. /* mask fan attributes if we have no bindings for this asic to expose */
  1260. if ((!adev->powerplay.pp_funcs->get_fan_speed_percent &&
  1261. attr == &sensor_dev_attr_pwm1.dev_attr.attr) || /* can't query fan */
  1262. (!adev->powerplay.pp_funcs->get_fan_control_mode &&
  1263. attr == &sensor_dev_attr_pwm1_enable.dev_attr.attr)) /* can't query state */
  1264. effective_mode &= ~S_IRUGO;
  1265. if ((!adev->powerplay.pp_funcs->set_fan_speed_percent &&
  1266. attr == &sensor_dev_attr_pwm1.dev_attr.attr) || /* can't manage fan */
  1267. (!adev->powerplay.pp_funcs->set_fan_control_mode &&
  1268. attr == &sensor_dev_attr_pwm1_enable.dev_attr.attr)) /* can't manage state */
  1269. effective_mode &= ~S_IWUSR;
  1270. if ((adev->flags & AMD_IS_APU) &&
  1271. (attr == &sensor_dev_attr_power1_cap_max.dev_attr.attr ||
  1272. attr == &sensor_dev_attr_power1_cap_min.dev_attr.attr||
  1273. attr == &sensor_dev_attr_power1_cap.dev_attr.attr))
  1274. return 0;
  1275. /* hide max/min values if we can't both query and manage the fan */
  1276. if ((!adev->powerplay.pp_funcs->set_fan_speed_percent &&
  1277. !adev->powerplay.pp_funcs->get_fan_speed_percent) &&
  1278. (attr == &sensor_dev_attr_pwm1_max.dev_attr.attr ||
  1279. attr == &sensor_dev_attr_pwm1_min.dev_attr.attr))
  1280. return 0;
  1281. /* only APUs have vddnb */
  1282. if (!(adev->flags & AMD_IS_APU) &&
  1283. (attr == &sensor_dev_attr_in1_input.dev_attr.attr ||
  1284. attr == &sensor_dev_attr_in1_label.dev_attr.attr))
  1285. return 0;
  1286. return effective_mode;
  1287. }
  1288. static const struct attribute_group hwmon_attrgroup = {
  1289. .attrs = hwmon_attributes,
  1290. .is_visible = hwmon_attributes_visible,
  1291. };
  1292. static const struct attribute_group *hwmon_groups[] = {
  1293. &hwmon_attrgroup,
  1294. NULL
  1295. };
  1296. void amdgpu_dpm_thermal_work_handler(struct work_struct *work)
  1297. {
  1298. struct amdgpu_device *adev =
  1299. container_of(work, struct amdgpu_device,
  1300. pm.dpm.thermal.work);
  1301. /* switch to the thermal state */
  1302. enum amd_pm_state_type dpm_state = POWER_STATE_TYPE_INTERNAL_THERMAL;
  1303. int temp, size = sizeof(temp);
  1304. if (!adev->pm.dpm_enabled)
  1305. return;
  1306. if (adev->powerplay.pp_funcs &&
  1307. adev->powerplay.pp_funcs->read_sensor &&
  1308. !amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GPU_TEMP,
  1309. (void *)&temp, &size)) {
  1310. if (temp < adev->pm.dpm.thermal.min_temp)
  1311. /* switch back the user state */
  1312. dpm_state = adev->pm.dpm.user_state;
  1313. } else {
  1314. if (adev->pm.dpm.thermal.high_to_low)
  1315. /* switch back the user state */
  1316. dpm_state = adev->pm.dpm.user_state;
  1317. }
  1318. mutex_lock(&adev->pm.mutex);
  1319. if (dpm_state == POWER_STATE_TYPE_INTERNAL_THERMAL)
  1320. adev->pm.dpm.thermal_active = true;
  1321. else
  1322. adev->pm.dpm.thermal_active = false;
  1323. adev->pm.dpm.state = dpm_state;
  1324. mutex_unlock(&adev->pm.mutex);
  1325. amdgpu_pm_compute_clocks(adev);
  1326. }
  1327. static struct amdgpu_ps *amdgpu_dpm_pick_power_state(struct amdgpu_device *adev,
  1328. enum amd_pm_state_type dpm_state)
  1329. {
  1330. int i;
  1331. struct amdgpu_ps *ps;
  1332. u32 ui_class;
  1333. bool single_display = (adev->pm.dpm.new_active_crtc_count < 2) ?
  1334. true : false;
  1335. /* check if the vblank period is too short to adjust the mclk */
  1336. if (single_display && adev->powerplay.pp_funcs->vblank_too_short) {
  1337. if (amdgpu_dpm_vblank_too_short(adev))
  1338. single_display = false;
  1339. }
  1340. /* certain older asics have a separare 3D performance state,
  1341. * so try that first if the user selected performance
  1342. */
  1343. if (dpm_state == POWER_STATE_TYPE_PERFORMANCE)
  1344. dpm_state = POWER_STATE_TYPE_INTERNAL_3DPERF;
  1345. /* balanced states don't exist at the moment */
  1346. if (dpm_state == POWER_STATE_TYPE_BALANCED)
  1347. dpm_state = POWER_STATE_TYPE_PERFORMANCE;
  1348. restart_search:
  1349. /* Pick the best power state based on current conditions */
  1350. for (i = 0; i < adev->pm.dpm.num_ps; i++) {
  1351. ps = &adev->pm.dpm.ps[i];
  1352. ui_class = ps->class & ATOM_PPLIB_CLASSIFICATION_UI_MASK;
  1353. switch (dpm_state) {
  1354. /* user states */
  1355. case POWER_STATE_TYPE_BATTERY:
  1356. if (ui_class == ATOM_PPLIB_CLASSIFICATION_UI_BATTERY) {
  1357. if (ps->caps & ATOM_PPLIB_SINGLE_DISPLAY_ONLY) {
  1358. if (single_display)
  1359. return ps;
  1360. } else
  1361. return ps;
  1362. }
  1363. break;
  1364. case POWER_STATE_TYPE_BALANCED:
  1365. if (ui_class == ATOM_PPLIB_CLASSIFICATION_UI_BALANCED) {
  1366. if (ps->caps & ATOM_PPLIB_SINGLE_DISPLAY_ONLY) {
  1367. if (single_display)
  1368. return ps;
  1369. } else
  1370. return ps;
  1371. }
  1372. break;
  1373. case POWER_STATE_TYPE_PERFORMANCE:
  1374. if (ui_class == ATOM_PPLIB_CLASSIFICATION_UI_PERFORMANCE) {
  1375. if (ps->caps & ATOM_PPLIB_SINGLE_DISPLAY_ONLY) {
  1376. if (single_display)
  1377. return ps;
  1378. } else
  1379. return ps;
  1380. }
  1381. break;
  1382. /* internal states */
  1383. case POWER_STATE_TYPE_INTERNAL_UVD:
  1384. if (adev->pm.dpm.uvd_ps)
  1385. return adev->pm.dpm.uvd_ps;
  1386. else
  1387. break;
  1388. case POWER_STATE_TYPE_INTERNAL_UVD_SD:
  1389. if (ps->class & ATOM_PPLIB_CLASSIFICATION_SDSTATE)
  1390. return ps;
  1391. break;
  1392. case POWER_STATE_TYPE_INTERNAL_UVD_HD:
  1393. if (ps->class & ATOM_PPLIB_CLASSIFICATION_HDSTATE)
  1394. return ps;
  1395. break;
  1396. case POWER_STATE_TYPE_INTERNAL_UVD_HD2:
  1397. if (ps->class & ATOM_PPLIB_CLASSIFICATION_HD2STATE)
  1398. return ps;
  1399. break;
  1400. case POWER_STATE_TYPE_INTERNAL_UVD_MVC:
  1401. if (ps->class2 & ATOM_PPLIB_CLASSIFICATION2_MVC)
  1402. return ps;
  1403. break;
  1404. case POWER_STATE_TYPE_INTERNAL_BOOT:
  1405. return adev->pm.dpm.boot_ps;
  1406. case POWER_STATE_TYPE_INTERNAL_THERMAL:
  1407. if (ps->class & ATOM_PPLIB_CLASSIFICATION_THERMAL)
  1408. return ps;
  1409. break;
  1410. case POWER_STATE_TYPE_INTERNAL_ACPI:
  1411. if (ps->class & ATOM_PPLIB_CLASSIFICATION_ACPI)
  1412. return ps;
  1413. break;
  1414. case POWER_STATE_TYPE_INTERNAL_ULV:
  1415. if (ps->class2 & ATOM_PPLIB_CLASSIFICATION2_ULV)
  1416. return ps;
  1417. break;
  1418. case POWER_STATE_TYPE_INTERNAL_3DPERF:
  1419. if (ps->class & ATOM_PPLIB_CLASSIFICATION_3DPERFORMANCE)
  1420. return ps;
  1421. break;
  1422. default:
  1423. break;
  1424. }
  1425. }
  1426. /* use a fallback state if we didn't match */
  1427. switch (dpm_state) {
  1428. case POWER_STATE_TYPE_INTERNAL_UVD_SD:
  1429. dpm_state = POWER_STATE_TYPE_INTERNAL_UVD_HD;
  1430. goto restart_search;
  1431. case POWER_STATE_TYPE_INTERNAL_UVD_HD:
  1432. case POWER_STATE_TYPE_INTERNAL_UVD_HD2:
  1433. case POWER_STATE_TYPE_INTERNAL_UVD_MVC:
  1434. if (adev->pm.dpm.uvd_ps) {
  1435. return adev->pm.dpm.uvd_ps;
  1436. } else {
  1437. dpm_state = POWER_STATE_TYPE_PERFORMANCE;
  1438. goto restart_search;
  1439. }
  1440. case POWER_STATE_TYPE_INTERNAL_THERMAL:
  1441. dpm_state = POWER_STATE_TYPE_INTERNAL_ACPI;
  1442. goto restart_search;
  1443. case POWER_STATE_TYPE_INTERNAL_ACPI:
  1444. dpm_state = POWER_STATE_TYPE_BATTERY;
  1445. goto restart_search;
  1446. case POWER_STATE_TYPE_BATTERY:
  1447. case POWER_STATE_TYPE_BALANCED:
  1448. case POWER_STATE_TYPE_INTERNAL_3DPERF:
  1449. dpm_state = POWER_STATE_TYPE_PERFORMANCE;
  1450. goto restart_search;
  1451. default:
  1452. break;
  1453. }
  1454. return NULL;
  1455. }
  1456. static void amdgpu_dpm_change_power_state_locked(struct amdgpu_device *adev)
  1457. {
  1458. struct amdgpu_ps *ps;
  1459. enum amd_pm_state_type dpm_state;
  1460. int ret;
  1461. bool equal = false;
  1462. /* if dpm init failed */
  1463. if (!adev->pm.dpm_enabled)
  1464. return;
  1465. if (adev->pm.dpm.user_state != adev->pm.dpm.state) {
  1466. /* add other state override checks here */
  1467. if ((!adev->pm.dpm.thermal_active) &&
  1468. (!adev->pm.dpm.uvd_active))
  1469. adev->pm.dpm.state = adev->pm.dpm.user_state;
  1470. }
  1471. dpm_state = adev->pm.dpm.state;
  1472. ps = amdgpu_dpm_pick_power_state(adev, dpm_state);
  1473. if (ps)
  1474. adev->pm.dpm.requested_ps = ps;
  1475. else
  1476. return;
  1477. if (amdgpu_dpm == 1 && adev->powerplay.pp_funcs->print_power_state) {
  1478. printk("switching from power state:\n");
  1479. amdgpu_dpm_print_power_state(adev, adev->pm.dpm.current_ps);
  1480. printk("switching to power state:\n");
  1481. amdgpu_dpm_print_power_state(adev, adev->pm.dpm.requested_ps);
  1482. }
  1483. /* update whether vce is active */
  1484. ps->vce_active = adev->pm.dpm.vce_active;
  1485. if (adev->powerplay.pp_funcs->display_configuration_changed)
  1486. amdgpu_dpm_display_configuration_changed(adev);
  1487. ret = amdgpu_dpm_pre_set_power_state(adev);
  1488. if (ret)
  1489. return;
  1490. if (adev->powerplay.pp_funcs->check_state_equal) {
  1491. if (0 != amdgpu_dpm_check_state_equal(adev, adev->pm.dpm.current_ps, adev->pm.dpm.requested_ps, &equal))
  1492. equal = false;
  1493. }
  1494. if (equal)
  1495. return;
  1496. amdgpu_dpm_set_power_state(adev);
  1497. amdgpu_dpm_post_set_power_state(adev);
  1498. adev->pm.dpm.current_active_crtcs = adev->pm.dpm.new_active_crtcs;
  1499. adev->pm.dpm.current_active_crtc_count = adev->pm.dpm.new_active_crtc_count;
  1500. if (adev->powerplay.pp_funcs->force_performance_level) {
  1501. if (adev->pm.dpm.thermal_active) {
  1502. enum amd_dpm_forced_level level = adev->pm.dpm.forced_level;
  1503. /* force low perf level for thermal */
  1504. amdgpu_dpm_force_performance_level(adev, AMD_DPM_FORCED_LEVEL_LOW);
  1505. /* save the user's level */
  1506. adev->pm.dpm.forced_level = level;
  1507. } else {
  1508. /* otherwise, user selected level */
  1509. amdgpu_dpm_force_performance_level(adev, adev->pm.dpm.forced_level);
  1510. }
  1511. }
  1512. }
  1513. void amdgpu_dpm_enable_uvd(struct amdgpu_device *adev, bool enable)
  1514. {
  1515. if (adev->powerplay.pp_funcs->set_powergating_by_smu) {
  1516. /* enable/disable UVD */
  1517. mutex_lock(&adev->pm.mutex);
  1518. amdgpu_dpm_set_powergating_by_smu(adev, AMD_IP_BLOCK_TYPE_UVD, !enable);
  1519. mutex_unlock(&adev->pm.mutex);
  1520. } else {
  1521. if (enable) {
  1522. mutex_lock(&adev->pm.mutex);
  1523. adev->pm.dpm.uvd_active = true;
  1524. adev->pm.dpm.state = POWER_STATE_TYPE_INTERNAL_UVD;
  1525. mutex_unlock(&adev->pm.mutex);
  1526. } else {
  1527. mutex_lock(&adev->pm.mutex);
  1528. adev->pm.dpm.uvd_active = false;
  1529. mutex_unlock(&adev->pm.mutex);
  1530. }
  1531. amdgpu_pm_compute_clocks(adev);
  1532. }
  1533. }
  1534. void amdgpu_dpm_enable_vce(struct amdgpu_device *adev, bool enable)
  1535. {
  1536. if (adev->powerplay.pp_funcs->set_powergating_by_smu) {
  1537. /* enable/disable VCE */
  1538. mutex_lock(&adev->pm.mutex);
  1539. amdgpu_dpm_set_powergating_by_smu(adev, AMD_IP_BLOCK_TYPE_VCE, !enable);
  1540. mutex_unlock(&adev->pm.mutex);
  1541. } else {
  1542. if (enable) {
  1543. mutex_lock(&adev->pm.mutex);
  1544. adev->pm.dpm.vce_active = true;
  1545. /* XXX select vce level based on ring/task */
  1546. adev->pm.dpm.vce_level = AMD_VCE_LEVEL_AC_ALL;
  1547. mutex_unlock(&adev->pm.mutex);
  1548. amdgpu_device_ip_set_clockgating_state(adev, AMD_IP_BLOCK_TYPE_VCE,
  1549. AMD_CG_STATE_UNGATE);
  1550. amdgpu_device_ip_set_powergating_state(adev, AMD_IP_BLOCK_TYPE_VCE,
  1551. AMD_PG_STATE_UNGATE);
  1552. amdgpu_pm_compute_clocks(adev);
  1553. } else {
  1554. amdgpu_device_ip_set_powergating_state(adev, AMD_IP_BLOCK_TYPE_VCE,
  1555. AMD_PG_STATE_GATE);
  1556. amdgpu_device_ip_set_clockgating_state(adev, AMD_IP_BLOCK_TYPE_VCE,
  1557. AMD_CG_STATE_GATE);
  1558. mutex_lock(&adev->pm.mutex);
  1559. adev->pm.dpm.vce_active = false;
  1560. mutex_unlock(&adev->pm.mutex);
  1561. amdgpu_pm_compute_clocks(adev);
  1562. }
  1563. }
  1564. }
  1565. void amdgpu_pm_print_power_states(struct amdgpu_device *adev)
  1566. {
  1567. int i;
  1568. if (adev->powerplay.pp_funcs->print_power_state == NULL)
  1569. return;
  1570. for (i = 0; i < adev->pm.dpm.num_ps; i++)
  1571. amdgpu_dpm_print_power_state(adev, &adev->pm.dpm.ps[i]);
  1572. }
  1573. int amdgpu_pm_sysfs_init(struct amdgpu_device *adev)
  1574. {
  1575. int ret;
  1576. if (adev->pm.sysfs_initialized)
  1577. return 0;
  1578. if (adev->pm.dpm_enabled == 0)
  1579. return 0;
  1580. adev->pm.int_hwmon_dev = hwmon_device_register_with_groups(adev->dev,
  1581. DRIVER_NAME, adev,
  1582. hwmon_groups);
  1583. if (IS_ERR(adev->pm.int_hwmon_dev)) {
  1584. ret = PTR_ERR(adev->pm.int_hwmon_dev);
  1585. dev_err(adev->dev,
  1586. "Unable to register hwmon device: %d\n", ret);
  1587. return ret;
  1588. }
  1589. ret = device_create_file(adev->dev, &dev_attr_power_dpm_state);
  1590. if (ret) {
  1591. DRM_ERROR("failed to create device file for dpm state\n");
  1592. return ret;
  1593. }
  1594. ret = device_create_file(adev->dev, &dev_attr_power_dpm_force_performance_level);
  1595. if (ret) {
  1596. DRM_ERROR("failed to create device file for dpm state\n");
  1597. return ret;
  1598. }
  1599. ret = device_create_file(adev->dev, &dev_attr_pp_num_states);
  1600. if (ret) {
  1601. DRM_ERROR("failed to create device file pp_num_states\n");
  1602. return ret;
  1603. }
  1604. ret = device_create_file(adev->dev, &dev_attr_pp_cur_state);
  1605. if (ret) {
  1606. DRM_ERROR("failed to create device file pp_cur_state\n");
  1607. return ret;
  1608. }
  1609. ret = device_create_file(adev->dev, &dev_attr_pp_force_state);
  1610. if (ret) {
  1611. DRM_ERROR("failed to create device file pp_force_state\n");
  1612. return ret;
  1613. }
  1614. ret = device_create_file(adev->dev, &dev_attr_pp_table);
  1615. if (ret) {
  1616. DRM_ERROR("failed to create device file pp_table\n");
  1617. return ret;
  1618. }
  1619. ret = device_create_file(adev->dev, &dev_attr_pp_dpm_sclk);
  1620. if (ret) {
  1621. DRM_ERROR("failed to create device file pp_dpm_sclk\n");
  1622. return ret;
  1623. }
  1624. ret = device_create_file(adev->dev, &dev_attr_pp_dpm_mclk);
  1625. if (ret) {
  1626. DRM_ERROR("failed to create device file pp_dpm_mclk\n");
  1627. return ret;
  1628. }
  1629. ret = device_create_file(adev->dev, &dev_attr_pp_dpm_pcie);
  1630. if (ret) {
  1631. DRM_ERROR("failed to create device file pp_dpm_pcie\n");
  1632. return ret;
  1633. }
  1634. ret = device_create_file(adev->dev, &dev_attr_pp_sclk_od);
  1635. if (ret) {
  1636. DRM_ERROR("failed to create device file pp_sclk_od\n");
  1637. return ret;
  1638. }
  1639. ret = device_create_file(adev->dev, &dev_attr_pp_mclk_od);
  1640. if (ret) {
  1641. DRM_ERROR("failed to create device file pp_mclk_od\n");
  1642. return ret;
  1643. }
  1644. ret = device_create_file(adev->dev,
  1645. &dev_attr_pp_power_profile_mode);
  1646. if (ret) {
  1647. DRM_ERROR("failed to create device file "
  1648. "pp_power_profile_mode\n");
  1649. return ret;
  1650. }
  1651. ret = device_create_file(adev->dev,
  1652. &dev_attr_pp_od_clk_voltage);
  1653. if (ret) {
  1654. DRM_ERROR("failed to create device file "
  1655. "pp_od_clk_voltage\n");
  1656. return ret;
  1657. }
  1658. ret = device_create_file(adev->dev,
  1659. &dev_attr_gpu_busy_percent);
  1660. if (ret) {
  1661. DRM_ERROR("failed to create device file "
  1662. "gpu_busy_level\n");
  1663. return ret;
  1664. }
  1665. ret = amdgpu_debugfs_pm_init(adev);
  1666. if (ret) {
  1667. DRM_ERROR("Failed to register debugfs file for dpm!\n");
  1668. return ret;
  1669. }
  1670. adev->pm.sysfs_initialized = true;
  1671. return 0;
  1672. }
  1673. void amdgpu_pm_sysfs_fini(struct amdgpu_device *adev)
  1674. {
  1675. if (adev->pm.dpm_enabled == 0)
  1676. return;
  1677. if (adev->pm.int_hwmon_dev)
  1678. hwmon_device_unregister(adev->pm.int_hwmon_dev);
  1679. device_remove_file(adev->dev, &dev_attr_power_dpm_state);
  1680. device_remove_file(adev->dev, &dev_attr_power_dpm_force_performance_level);
  1681. device_remove_file(adev->dev, &dev_attr_pp_num_states);
  1682. device_remove_file(adev->dev, &dev_attr_pp_cur_state);
  1683. device_remove_file(adev->dev, &dev_attr_pp_force_state);
  1684. device_remove_file(adev->dev, &dev_attr_pp_table);
  1685. device_remove_file(adev->dev, &dev_attr_pp_dpm_sclk);
  1686. device_remove_file(adev->dev, &dev_attr_pp_dpm_mclk);
  1687. device_remove_file(adev->dev, &dev_attr_pp_dpm_pcie);
  1688. device_remove_file(adev->dev, &dev_attr_pp_sclk_od);
  1689. device_remove_file(adev->dev, &dev_attr_pp_mclk_od);
  1690. device_remove_file(adev->dev,
  1691. &dev_attr_pp_power_profile_mode);
  1692. device_remove_file(adev->dev,
  1693. &dev_attr_pp_od_clk_voltage);
  1694. device_remove_file(adev->dev, &dev_attr_gpu_busy_percent);
  1695. }
  1696. void amdgpu_pm_compute_clocks(struct amdgpu_device *adev)
  1697. {
  1698. int i = 0;
  1699. if (!adev->pm.dpm_enabled)
  1700. return;
  1701. if (adev->mode_info.num_crtc)
  1702. amdgpu_display_bandwidth_update(adev);
  1703. for (i = 0; i < AMDGPU_MAX_RINGS; i++) {
  1704. struct amdgpu_ring *ring = adev->rings[i];
  1705. if (ring && ring->ready)
  1706. amdgpu_fence_wait_empty(ring);
  1707. }
  1708. mutex_lock(&adev->pm.mutex);
  1709. /* update battery/ac status */
  1710. if (power_supply_is_system_supplied() > 0)
  1711. adev->pm.ac_power = true;
  1712. else
  1713. adev->pm.ac_power = false;
  1714. mutex_unlock(&adev->pm.mutex);
  1715. if (adev->powerplay.pp_funcs->dispatch_tasks) {
  1716. if (!amdgpu_device_has_dc_support(adev)) {
  1717. mutex_lock(&adev->pm.mutex);
  1718. amdgpu_dpm_get_active_displays(adev);
  1719. adev->pm.pm_display_cfg.num_display = adev->pm.dpm.new_active_crtc_count;
  1720. adev->pm.pm_display_cfg.vrefresh = amdgpu_dpm_get_vrefresh(adev);
  1721. adev->pm.pm_display_cfg.min_vblank_time = amdgpu_dpm_get_vblank_time(adev);
  1722. /* we have issues with mclk switching with refresh rates over 120 hz on the non-DC code. */
  1723. if (adev->pm.pm_display_cfg.vrefresh > 120)
  1724. adev->pm.pm_display_cfg.min_vblank_time = 0;
  1725. if (adev->powerplay.pp_funcs->display_configuration_change)
  1726. adev->powerplay.pp_funcs->display_configuration_change(
  1727. adev->powerplay.pp_handle,
  1728. &adev->pm.pm_display_cfg);
  1729. mutex_unlock(&adev->pm.mutex);
  1730. }
  1731. amdgpu_dpm_dispatch_task(adev, AMD_PP_TASK_DISPLAY_CONFIG_CHANGE, NULL);
  1732. } else {
  1733. mutex_lock(&adev->pm.mutex);
  1734. amdgpu_dpm_get_active_displays(adev);
  1735. amdgpu_dpm_change_power_state_locked(adev);
  1736. mutex_unlock(&adev->pm.mutex);
  1737. }
  1738. }
  1739. /*
  1740. * Debugfs info
  1741. */
  1742. #if defined(CONFIG_DEBUG_FS)
  1743. static int amdgpu_debugfs_pm_info_pp(struct seq_file *m, struct amdgpu_device *adev)
  1744. {
  1745. uint32_t value;
  1746. uint32_t query = 0;
  1747. int size;
  1748. /* sanity check PP is enabled */
  1749. if (!(adev->powerplay.pp_funcs &&
  1750. adev->powerplay.pp_funcs->read_sensor))
  1751. return -EINVAL;
  1752. /* GPU Clocks */
  1753. size = sizeof(value);
  1754. seq_printf(m, "GFX Clocks and Power:\n");
  1755. if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GFX_MCLK, (void *)&value, &size))
  1756. seq_printf(m, "\t%u MHz (MCLK)\n", value/100);
  1757. if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GFX_SCLK, (void *)&value, &size))
  1758. seq_printf(m, "\t%u MHz (SCLK)\n", value/100);
  1759. if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_STABLE_PSTATE_SCLK, (void *)&value, &size))
  1760. seq_printf(m, "\t%u MHz (PSTATE_SCLK)\n", value/100);
  1761. if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_STABLE_PSTATE_MCLK, (void *)&value, &size))
  1762. seq_printf(m, "\t%u MHz (PSTATE_MCLK)\n", value/100);
  1763. if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_VDDGFX, (void *)&value, &size))
  1764. seq_printf(m, "\t%u mV (VDDGFX)\n", value);
  1765. if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_VDDNB, (void *)&value, &size))
  1766. seq_printf(m, "\t%u mV (VDDNB)\n", value);
  1767. size = sizeof(uint32_t);
  1768. if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GPU_POWER, (void *)&query, &size))
  1769. seq_printf(m, "\t%u.%u W (average GPU)\n", query >> 8, query & 0xff);
  1770. size = sizeof(value);
  1771. seq_printf(m, "\n");
  1772. /* GPU Temp */
  1773. if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GPU_TEMP, (void *)&value, &size))
  1774. seq_printf(m, "GPU Temperature: %u C\n", value/1000);
  1775. /* GPU Load */
  1776. if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GPU_LOAD, (void *)&value, &size))
  1777. seq_printf(m, "GPU Load: %u %%\n", value);
  1778. seq_printf(m, "\n");
  1779. /* UVD clocks */
  1780. if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_UVD_POWER, (void *)&value, &size)) {
  1781. if (!value) {
  1782. seq_printf(m, "UVD: Disabled\n");
  1783. } else {
  1784. seq_printf(m, "UVD: Enabled\n");
  1785. if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_UVD_DCLK, (void *)&value, &size))
  1786. seq_printf(m, "\t%u MHz (DCLK)\n", value/100);
  1787. if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_UVD_VCLK, (void *)&value, &size))
  1788. seq_printf(m, "\t%u MHz (VCLK)\n", value/100);
  1789. }
  1790. }
  1791. seq_printf(m, "\n");
  1792. /* VCE clocks */
  1793. if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_VCE_POWER, (void *)&value, &size)) {
  1794. if (!value) {
  1795. seq_printf(m, "VCE: Disabled\n");
  1796. } else {
  1797. seq_printf(m, "VCE: Enabled\n");
  1798. if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_VCE_ECCLK, (void *)&value, &size))
  1799. seq_printf(m, "\t%u MHz (ECCLK)\n", value/100);
  1800. }
  1801. }
  1802. return 0;
  1803. }
  1804. static void amdgpu_parse_cg_state(struct seq_file *m, u32 flags)
  1805. {
  1806. int i;
  1807. for (i = 0; clocks[i].flag; i++)
  1808. seq_printf(m, "\t%s: %s\n", clocks[i].name,
  1809. (flags & clocks[i].flag) ? "On" : "Off");
  1810. }
  1811. static int amdgpu_debugfs_pm_info(struct seq_file *m, void *data)
  1812. {
  1813. struct drm_info_node *node = (struct drm_info_node *) m->private;
  1814. struct drm_device *dev = node->minor->dev;
  1815. struct amdgpu_device *adev = dev->dev_private;
  1816. struct drm_device *ddev = adev->ddev;
  1817. u32 flags = 0;
  1818. amdgpu_device_ip_get_clockgating_state(adev, &flags);
  1819. seq_printf(m, "Clock Gating Flags Mask: 0x%x\n", flags);
  1820. amdgpu_parse_cg_state(m, flags);
  1821. seq_printf(m, "\n");
  1822. if (!adev->pm.dpm_enabled) {
  1823. seq_printf(m, "dpm not enabled\n");
  1824. return 0;
  1825. }
  1826. if ((adev->flags & AMD_IS_PX) &&
  1827. (ddev->switch_power_state != DRM_SWITCH_POWER_ON)) {
  1828. seq_printf(m, "PX asic powered off\n");
  1829. } else if (adev->powerplay.pp_funcs->debugfs_print_current_performance_level) {
  1830. mutex_lock(&adev->pm.mutex);
  1831. if (adev->powerplay.pp_funcs->debugfs_print_current_performance_level)
  1832. adev->powerplay.pp_funcs->debugfs_print_current_performance_level(adev, m);
  1833. else
  1834. seq_printf(m, "Debugfs support not implemented for this asic\n");
  1835. mutex_unlock(&adev->pm.mutex);
  1836. } else {
  1837. return amdgpu_debugfs_pm_info_pp(m, adev);
  1838. }
  1839. return 0;
  1840. }
  1841. static const struct drm_info_list amdgpu_pm_info_list[] = {
  1842. {"amdgpu_pm_info", amdgpu_debugfs_pm_info, 0, NULL},
  1843. };
  1844. #endif
  1845. static int amdgpu_debugfs_pm_init(struct amdgpu_device *adev)
  1846. {
  1847. #if defined(CONFIG_DEBUG_FS)
  1848. return amdgpu_debugfs_add_files(adev, amdgpu_pm_info_list, ARRAY_SIZE(amdgpu_pm_info_list));
  1849. #else
  1850. return 0;
  1851. #endif
  1852. }