amdgpu_pm.c 46 KB

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