amdgpu_pm.c 45 KB

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