2 * Copyright 2017 Advanced Micro Devices, Inc.
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:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
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.
22 * Authors: Rafał Miłecki <zajec5@gmail.com>
23 * Alex Deucher <alexdeucher@gmail.com>
27 #include "amdgpu_drv.h"
28 #include "amdgpu_pm.h"
29 #include "amdgpu_dpm.h"
31 #include <linux/pci.h>
32 #include <linux/hwmon.h>
33 #include <linux/hwmon-sysfs.h>
34 #include <linux/nospec.h>
35 #include <linux/pm_runtime.h>
36 #include <asm/processor.h>
39 static const struct cg_flag_name clocks[] = {
40 {AMD_CG_SUPPORT_GFX_FGCG, "Graphics Fine Grain Clock Gating"},
41 {AMD_CG_SUPPORT_GFX_MGCG, "Graphics Medium Grain Clock Gating"},
42 {AMD_CG_SUPPORT_GFX_MGLS, "Graphics Medium Grain memory Light Sleep"},
43 {AMD_CG_SUPPORT_GFX_CGCG, "Graphics Coarse Grain Clock Gating"},
44 {AMD_CG_SUPPORT_GFX_CGLS, "Graphics Coarse Grain memory Light Sleep"},
45 {AMD_CG_SUPPORT_GFX_CGTS, "Graphics Coarse Grain Tree Shader Clock Gating"},
46 {AMD_CG_SUPPORT_GFX_CGTS_LS, "Graphics Coarse Grain Tree Shader Light Sleep"},
47 {AMD_CG_SUPPORT_GFX_CP_LS, "Graphics Command Processor Light Sleep"},
48 {AMD_CG_SUPPORT_GFX_RLC_LS, "Graphics Run List Controller Light Sleep"},
49 {AMD_CG_SUPPORT_GFX_3D_CGCG, "Graphics 3D Coarse Grain Clock Gating"},
50 {AMD_CG_SUPPORT_GFX_3D_CGLS, "Graphics 3D Coarse Grain memory Light Sleep"},
51 {AMD_CG_SUPPORT_MC_LS, "Memory Controller Light Sleep"},
52 {AMD_CG_SUPPORT_MC_MGCG, "Memory Controller Medium Grain Clock Gating"},
53 {AMD_CG_SUPPORT_SDMA_LS, "System Direct Memory Access Light Sleep"},
54 {AMD_CG_SUPPORT_SDMA_MGCG, "System Direct Memory Access Medium Grain Clock Gating"},
55 {AMD_CG_SUPPORT_BIF_MGCG, "Bus Interface Medium Grain Clock Gating"},
56 {AMD_CG_SUPPORT_BIF_LS, "Bus Interface Light Sleep"},
57 {AMD_CG_SUPPORT_UVD_MGCG, "Unified Video Decoder Medium Grain Clock Gating"},
58 {AMD_CG_SUPPORT_VCE_MGCG, "Video Compression Engine Medium Grain Clock Gating"},
59 {AMD_CG_SUPPORT_HDP_LS, "Host Data Path Light Sleep"},
60 {AMD_CG_SUPPORT_HDP_MGCG, "Host Data Path Medium Grain Clock Gating"},
61 {AMD_CG_SUPPORT_DRM_MGCG, "Digital Right Management Medium Grain Clock Gating"},
62 {AMD_CG_SUPPORT_DRM_LS, "Digital Right Management Light Sleep"},
63 {AMD_CG_SUPPORT_ROM_MGCG, "Rom Medium Grain Clock Gating"},
64 {AMD_CG_SUPPORT_DF_MGCG, "Data Fabric Medium Grain Clock Gating"},
65 {AMD_CG_SUPPORT_VCN_MGCG, "VCN Medium Grain Clock Gating"},
66 {AMD_CG_SUPPORT_HDP_DS, "Host Data Path Deep Sleep"},
67 {AMD_CG_SUPPORT_HDP_SD, "Host Data Path Shutdown"},
68 {AMD_CG_SUPPORT_IH_CG, "Interrupt Handler Clock Gating"},
69 {AMD_CG_SUPPORT_JPEG_MGCG, "JPEG Medium Grain Clock Gating"},
71 {AMD_CG_SUPPORT_ATHUB_MGCG, "Address Translation Hub Medium Grain Clock Gating"},
72 {AMD_CG_SUPPORT_ATHUB_LS, "Address Translation Hub Light Sleep"},
76 static const struct hwmon_temp_label {
77 enum PP_HWMON_TEMP channel;
80 {PP_TEMP_EDGE, "edge"},
81 {PP_TEMP_JUNCTION, "junction"},
86 * DOC: power_dpm_state
88 * The power_dpm_state file is a legacy interface and is only provided for
89 * backwards compatibility. The amdgpu driver provides a sysfs API for adjusting
90 * certain power related parameters. The file power_dpm_state is used for this.
91 * It accepts the following arguments:
101 * On older GPUs, the vbios provided a special power state for battery
102 * operation. Selecting battery switched to this state. This is no
103 * longer provided on newer GPUs so the option does nothing in that case.
107 * On older GPUs, the vbios provided a special power state for balanced
108 * operation. Selecting balanced switched to this state. This is no
109 * longer provided on newer GPUs so the option does nothing in that case.
113 * On older GPUs, the vbios provided a special power state for performance
114 * operation. Selecting performance switched to this state. This is no
115 * longer provided on newer GPUs so the option does nothing in that case.
119 static ssize_t amdgpu_get_power_dpm_state(struct device *dev,
120 struct device_attribute *attr,
123 struct drm_device *ddev = dev_get_drvdata(dev);
124 struct amdgpu_device *adev = drm_to_adev(ddev);
125 const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
126 enum amd_pm_state_type pm;
129 if (amdgpu_in_reset(adev))
131 if (adev->in_suspend && !adev->in_runpm)
134 ret = pm_runtime_get_sync(ddev->dev);
136 pm_runtime_put_autosuspend(ddev->dev);
140 if (pp_funcs->get_current_power_state) {
141 pm = amdgpu_dpm_get_current_power_state(adev);
143 pm = adev->pm.dpm.user_state;
146 pm_runtime_mark_last_busy(ddev->dev);
147 pm_runtime_put_autosuspend(ddev->dev);
149 return sysfs_emit(buf, "%s\n",
150 (pm == POWER_STATE_TYPE_BATTERY) ? "battery" :
151 (pm == POWER_STATE_TYPE_BALANCED) ? "balanced" : "performance");
154 static ssize_t amdgpu_set_power_dpm_state(struct device *dev,
155 struct device_attribute *attr,
159 struct drm_device *ddev = dev_get_drvdata(dev);
160 struct amdgpu_device *adev = drm_to_adev(ddev);
161 enum amd_pm_state_type state;
164 if (amdgpu_in_reset(adev))
166 if (adev->in_suspend && !adev->in_runpm)
169 if (strncmp("battery", buf, strlen("battery")) == 0)
170 state = POWER_STATE_TYPE_BATTERY;
171 else if (strncmp("balanced", buf, strlen("balanced")) == 0)
172 state = POWER_STATE_TYPE_BALANCED;
173 else if (strncmp("performance", buf, strlen("performance")) == 0)
174 state = POWER_STATE_TYPE_PERFORMANCE;
178 ret = pm_runtime_get_sync(ddev->dev);
180 pm_runtime_put_autosuspend(ddev->dev);
184 if (is_support_sw_smu(adev)) {
185 mutex_lock(&adev->pm.mutex);
186 adev->pm.dpm.user_state = state;
187 mutex_unlock(&adev->pm.mutex);
188 } else if (adev->powerplay.pp_funcs->dispatch_tasks) {
189 amdgpu_dpm_dispatch_task(adev, AMD_PP_TASK_ENABLE_USER_STATE, &state);
191 mutex_lock(&adev->pm.mutex);
192 adev->pm.dpm.user_state = state;
193 mutex_unlock(&adev->pm.mutex);
195 amdgpu_pm_compute_clocks(adev);
197 pm_runtime_mark_last_busy(ddev->dev);
198 pm_runtime_put_autosuspend(ddev->dev);
205 * DOC: power_dpm_force_performance_level
207 * The amdgpu driver provides a sysfs API for adjusting certain power
208 * related parameters. The file power_dpm_force_performance_level is
209 * used for this. It accepts the following arguments:
229 * When auto is selected, the driver will attempt to dynamically select
230 * the optimal power profile for current conditions in the driver.
234 * When low is selected, the clocks are forced to the lowest power state.
238 * When high is selected, the clocks are forced to the highest power state.
242 * When manual is selected, the user can manually adjust which power states
243 * are enabled for each clock domain via the sysfs pp_dpm_mclk, pp_dpm_sclk,
244 * and pp_dpm_pcie files and adjust the power state transition heuristics
245 * via the pp_power_profile_mode sysfs file.
252 * When the profiling modes are selected, clock and power gating are
253 * disabled and the clocks are set for different profiling cases. This
254 * mode is recommended for profiling specific work loads where you do
255 * not want clock or power gating for clock fluctuation to interfere
256 * with your results. profile_standard sets the clocks to a fixed clock
257 * level which varies from asic to asic. profile_min_sclk forces the sclk
258 * to the lowest level. profile_min_mclk forces the mclk to the lowest level.
259 * profile_peak sets all clocks (mclk, sclk, pcie) to the highest levels.
263 static ssize_t amdgpu_get_power_dpm_force_performance_level(struct device *dev,
264 struct device_attribute *attr,
267 struct drm_device *ddev = dev_get_drvdata(dev);
268 struct amdgpu_device *adev = drm_to_adev(ddev);
269 enum amd_dpm_forced_level level = 0xff;
272 if (amdgpu_in_reset(adev))
274 if (adev->in_suspend && !adev->in_runpm)
277 ret = pm_runtime_get_sync(ddev->dev);
279 pm_runtime_put_autosuspend(ddev->dev);
283 if (adev->powerplay.pp_funcs->get_performance_level)
284 level = amdgpu_dpm_get_performance_level(adev);
286 level = adev->pm.dpm.forced_level;
288 pm_runtime_mark_last_busy(ddev->dev);
289 pm_runtime_put_autosuspend(ddev->dev);
291 return sysfs_emit(buf, "%s\n",
292 (level == AMD_DPM_FORCED_LEVEL_AUTO) ? "auto" :
293 (level == AMD_DPM_FORCED_LEVEL_LOW) ? "low" :
294 (level == AMD_DPM_FORCED_LEVEL_HIGH) ? "high" :
295 (level == AMD_DPM_FORCED_LEVEL_MANUAL) ? "manual" :
296 (level == AMD_DPM_FORCED_LEVEL_PROFILE_STANDARD) ? "profile_standard" :
297 (level == AMD_DPM_FORCED_LEVEL_PROFILE_MIN_SCLK) ? "profile_min_sclk" :
298 (level == AMD_DPM_FORCED_LEVEL_PROFILE_MIN_MCLK) ? "profile_min_mclk" :
299 (level == AMD_DPM_FORCED_LEVEL_PROFILE_PEAK) ? "profile_peak" :
300 (level == AMD_DPM_FORCED_LEVEL_PERF_DETERMINISM) ? "perf_determinism" :
304 static ssize_t amdgpu_set_power_dpm_force_performance_level(struct device *dev,
305 struct device_attribute *attr,
309 struct drm_device *ddev = dev_get_drvdata(dev);
310 struct amdgpu_device *adev = drm_to_adev(ddev);
311 const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
312 enum amd_dpm_forced_level level;
313 enum amd_dpm_forced_level current_level = 0xff;
316 if (amdgpu_in_reset(adev))
318 if (adev->in_suspend && !adev->in_runpm)
321 if (strncmp("low", buf, strlen("low")) == 0) {
322 level = AMD_DPM_FORCED_LEVEL_LOW;
323 } else if (strncmp("high", buf, strlen("high")) == 0) {
324 level = AMD_DPM_FORCED_LEVEL_HIGH;
325 } else if (strncmp("auto", buf, strlen("auto")) == 0) {
326 level = AMD_DPM_FORCED_LEVEL_AUTO;
327 } else if (strncmp("manual", buf, strlen("manual")) == 0) {
328 level = AMD_DPM_FORCED_LEVEL_MANUAL;
329 } else if (strncmp("profile_exit", buf, strlen("profile_exit")) == 0) {
330 level = AMD_DPM_FORCED_LEVEL_PROFILE_EXIT;
331 } else if (strncmp("profile_standard", buf, strlen("profile_standard")) == 0) {
332 level = AMD_DPM_FORCED_LEVEL_PROFILE_STANDARD;
333 } else if (strncmp("profile_min_sclk", buf, strlen("profile_min_sclk")) == 0) {
334 level = AMD_DPM_FORCED_LEVEL_PROFILE_MIN_SCLK;
335 } else if (strncmp("profile_min_mclk", buf, strlen("profile_min_mclk")) == 0) {
336 level = AMD_DPM_FORCED_LEVEL_PROFILE_MIN_MCLK;
337 } else if (strncmp("profile_peak", buf, strlen("profile_peak")) == 0) {
338 level = AMD_DPM_FORCED_LEVEL_PROFILE_PEAK;
339 } else if (strncmp("perf_determinism", buf, strlen("perf_determinism")) == 0) {
340 level = AMD_DPM_FORCED_LEVEL_PERF_DETERMINISM;
345 ret = pm_runtime_get_sync(ddev->dev);
347 pm_runtime_put_autosuspend(ddev->dev);
351 if (pp_funcs->get_performance_level)
352 current_level = amdgpu_dpm_get_performance_level(adev);
354 if (current_level == level) {
355 pm_runtime_mark_last_busy(ddev->dev);
356 pm_runtime_put_autosuspend(ddev->dev);
360 if (adev->asic_type == CHIP_RAVEN) {
361 if (!(adev->apu_flags & AMD_APU_IS_RAVEN2)) {
362 if (current_level != AMD_DPM_FORCED_LEVEL_MANUAL && level == AMD_DPM_FORCED_LEVEL_MANUAL)
363 amdgpu_gfx_off_ctrl(adev, false);
364 else if (current_level == AMD_DPM_FORCED_LEVEL_MANUAL && level != AMD_DPM_FORCED_LEVEL_MANUAL)
365 amdgpu_gfx_off_ctrl(adev, true);
369 /* profile_exit setting is valid only when current mode is in profile mode */
370 if (!(current_level & (AMD_DPM_FORCED_LEVEL_PROFILE_STANDARD |
371 AMD_DPM_FORCED_LEVEL_PROFILE_MIN_SCLK |
372 AMD_DPM_FORCED_LEVEL_PROFILE_MIN_MCLK |
373 AMD_DPM_FORCED_LEVEL_PROFILE_PEAK)) &&
374 (level == AMD_DPM_FORCED_LEVEL_PROFILE_EXIT)) {
375 pr_err("Currently not in any profile mode!\n");
376 pm_runtime_mark_last_busy(ddev->dev);
377 pm_runtime_put_autosuspend(ddev->dev);
381 if (pp_funcs->force_performance_level) {
382 mutex_lock(&adev->pm.mutex);
383 if (adev->pm.dpm.thermal_active) {
384 mutex_unlock(&adev->pm.mutex);
385 pm_runtime_mark_last_busy(ddev->dev);
386 pm_runtime_put_autosuspend(ddev->dev);
389 ret = amdgpu_dpm_force_performance_level(adev, level);
391 mutex_unlock(&adev->pm.mutex);
392 pm_runtime_mark_last_busy(ddev->dev);
393 pm_runtime_put_autosuspend(ddev->dev);
396 adev->pm.dpm.forced_level = level;
398 mutex_unlock(&adev->pm.mutex);
400 pm_runtime_mark_last_busy(ddev->dev);
401 pm_runtime_put_autosuspend(ddev->dev);
406 static ssize_t amdgpu_get_pp_num_states(struct device *dev,
407 struct device_attribute *attr,
410 struct drm_device *ddev = dev_get_drvdata(dev);
411 struct amdgpu_device *adev = drm_to_adev(ddev);
412 const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
413 struct pp_states_info data;
416 if (amdgpu_in_reset(adev))
418 if (adev->in_suspend && !adev->in_runpm)
421 ret = pm_runtime_get_sync(ddev->dev);
423 pm_runtime_put_autosuspend(ddev->dev);
427 if (pp_funcs->get_pp_num_states) {
428 amdgpu_dpm_get_pp_num_states(adev, &data);
430 memset(&data, 0, sizeof(data));
433 pm_runtime_mark_last_busy(ddev->dev);
434 pm_runtime_put_autosuspend(ddev->dev);
436 buf_len = snprintf(buf, PAGE_SIZE, "states: %d\n", data.nums);
437 for (i = 0; i < data.nums; i++)
438 buf_len += snprintf(buf + buf_len, PAGE_SIZE, "%d %s\n", i,
439 (data.states[i] == POWER_STATE_TYPE_INTERNAL_BOOT) ? "boot" :
440 (data.states[i] == POWER_STATE_TYPE_BATTERY) ? "battery" :
441 (data.states[i] == POWER_STATE_TYPE_BALANCED) ? "balanced" :
442 (data.states[i] == POWER_STATE_TYPE_PERFORMANCE) ? "performance" : "default");
447 static ssize_t amdgpu_get_pp_cur_state(struct device *dev,
448 struct device_attribute *attr,
451 struct drm_device *ddev = dev_get_drvdata(dev);
452 struct amdgpu_device *adev = drm_to_adev(ddev);
453 const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
454 struct pp_states_info data = {0};
455 enum amd_pm_state_type pm = 0;
458 if (amdgpu_in_reset(adev))
460 if (adev->in_suspend && !adev->in_runpm)
463 ret = pm_runtime_get_sync(ddev->dev);
465 pm_runtime_put_autosuspend(ddev->dev);
469 if (pp_funcs->get_current_power_state
470 && pp_funcs->get_pp_num_states) {
471 pm = amdgpu_dpm_get_current_power_state(adev);
472 amdgpu_dpm_get_pp_num_states(adev, &data);
475 pm_runtime_mark_last_busy(ddev->dev);
476 pm_runtime_put_autosuspend(ddev->dev);
478 for (i = 0; i < data.nums; i++) {
479 if (pm == data.states[i])
486 return sysfs_emit(buf, "%d\n", i);
489 static ssize_t amdgpu_get_pp_force_state(struct device *dev,
490 struct device_attribute *attr,
493 struct drm_device *ddev = dev_get_drvdata(dev);
494 struct amdgpu_device *adev = drm_to_adev(ddev);
496 if (amdgpu_in_reset(adev))
498 if (adev->in_suspend && !adev->in_runpm)
501 if (adev->pp_force_state_enabled)
502 return amdgpu_get_pp_cur_state(dev, attr, buf);
504 return sysfs_emit(buf, "\n");
507 static ssize_t amdgpu_set_pp_force_state(struct device *dev,
508 struct device_attribute *attr,
512 struct drm_device *ddev = dev_get_drvdata(dev);
513 struct amdgpu_device *adev = drm_to_adev(ddev);
514 enum amd_pm_state_type state = 0;
518 if (amdgpu_in_reset(adev))
520 if (adev->in_suspend && !adev->in_runpm)
523 if (strlen(buf) == 1)
524 adev->pp_force_state_enabled = false;
525 else if (is_support_sw_smu(adev))
526 adev->pp_force_state_enabled = false;
527 else if (adev->powerplay.pp_funcs->dispatch_tasks &&
528 adev->powerplay.pp_funcs->get_pp_num_states) {
529 struct pp_states_info data;
531 ret = kstrtoul(buf, 0, &idx);
532 if (ret || idx >= ARRAY_SIZE(data.states))
535 idx = array_index_nospec(idx, ARRAY_SIZE(data.states));
537 amdgpu_dpm_get_pp_num_states(adev, &data);
538 state = data.states[idx];
540 ret = pm_runtime_get_sync(ddev->dev);
542 pm_runtime_put_autosuspend(ddev->dev);
546 /* only set user selected power states */
547 if (state != POWER_STATE_TYPE_INTERNAL_BOOT &&
548 state != POWER_STATE_TYPE_DEFAULT) {
549 amdgpu_dpm_dispatch_task(adev,
550 AMD_PP_TASK_ENABLE_USER_STATE, &state);
551 adev->pp_force_state_enabled = true;
553 pm_runtime_mark_last_busy(ddev->dev);
554 pm_runtime_put_autosuspend(ddev->dev);
563 * The amdgpu driver provides a sysfs API for uploading new powerplay
564 * tables. The file pp_table is used for this. Reading the file
565 * will dump the current power play table. Writing to the file
566 * will attempt to upload a new powerplay table and re-initialize
567 * powerplay using that new table.
571 static ssize_t amdgpu_get_pp_table(struct device *dev,
572 struct device_attribute *attr,
575 struct drm_device *ddev = dev_get_drvdata(dev);
576 struct amdgpu_device *adev = drm_to_adev(ddev);
580 if (amdgpu_in_reset(adev))
582 if (adev->in_suspend && !adev->in_runpm)
585 ret = pm_runtime_get_sync(ddev->dev);
587 pm_runtime_put_autosuspend(ddev->dev);
591 if (adev->powerplay.pp_funcs->get_pp_table) {
592 size = amdgpu_dpm_get_pp_table(adev, &table);
593 pm_runtime_mark_last_busy(ddev->dev);
594 pm_runtime_put_autosuspend(ddev->dev);
598 pm_runtime_mark_last_busy(ddev->dev);
599 pm_runtime_put_autosuspend(ddev->dev);
603 if (size >= PAGE_SIZE)
604 size = PAGE_SIZE - 1;
606 memcpy(buf, table, size);
611 static ssize_t amdgpu_set_pp_table(struct device *dev,
612 struct device_attribute *attr,
616 struct drm_device *ddev = dev_get_drvdata(dev);
617 struct amdgpu_device *adev = drm_to_adev(ddev);
620 if (amdgpu_in_reset(adev))
622 if (adev->in_suspend && !adev->in_runpm)
625 ret = pm_runtime_get_sync(ddev->dev);
627 pm_runtime_put_autosuspend(ddev->dev);
631 ret = amdgpu_dpm_set_pp_table(adev, buf, count);
633 pm_runtime_mark_last_busy(ddev->dev);
634 pm_runtime_put_autosuspend(ddev->dev);
638 pm_runtime_mark_last_busy(ddev->dev);
639 pm_runtime_put_autosuspend(ddev->dev);
645 * DOC: pp_od_clk_voltage
647 * The amdgpu driver provides a sysfs API for adjusting the clocks and voltages
648 * in each power level within a power state. The pp_od_clk_voltage is used for
651 * Note that the actual memory controller clock rate are exposed, not
652 * the effective memory clock of the DRAMs. To translate it, use the
655 * Clock conversion (Mhz):
657 * HBM: effective_memory_clock = memory_controller_clock * 1
659 * G5: effective_memory_clock = memory_controller_clock * 1
661 * G6: effective_memory_clock = memory_controller_clock * 2
663 * DRAM data rate (MT/s):
665 * HBM: effective_memory_clock * 2 = data_rate
667 * G5: effective_memory_clock * 4 = data_rate
669 * G6: effective_memory_clock * 8 = data_rate
673 * data_rate * vram_bit_width / 8 = memory_bandwidth
679 * memory_controller_clock = 1750 Mhz
681 * effective_memory_clock = 1750 Mhz * 1 = 1750 Mhz
683 * data rate = 1750 * 4 = 7000 MT/s
685 * memory_bandwidth = 7000 * 128 bits / 8 = 112000 MB/s
689 * memory_controller_clock = 875 Mhz
691 * effective_memory_clock = 875 Mhz * 2 = 1750 Mhz
693 * data rate = 1750 * 8 = 14000 MT/s
695 * memory_bandwidth = 14000 * 256 bits / 8 = 448000 MB/s
697 * < For Vega10 and previous ASICs >
699 * Reading the file will display:
701 * - a list of engine clock levels and voltages labeled OD_SCLK
703 * - a list of memory clock levels and voltages labeled OD_MCLK
705 * - a list of valid ranges for sclk, mclk, and voltage labeled OD_RANGE
707 * To manually adjust these settings, first select manual using
708 * power_dpm_force_performance_level. Enter a new value for each
709 * level by writing a string that contains "s/m level clock voltage" to
710 * the file. E.g., "s 1 500 820" will update sclk level 1 to be 500 MHz
711 * at 820 mV; "m 0 350 810" will update mclk level 0 to be 350 MHz at
712 * 810 mV. When you have edited all of the states as needed, write
713 * "c" (commit) to the file to commit your changes. If you want to reset to the
714 * default power levels, write "r" (reset) to the file to reset them.
717 * < For Vega20 and newer ASICs >
719 * Reading the file will display:
721 * - minimum and maximum engine clock labeled OD_SCLK
723 * - minimum(not available for Vega20 and Navi1x) and maximum memory
724 * clock labeled OD_MCLK
726 * - three <frequency, voltage> points labeled OD_VDDC_CURVE.
727 * They can be used to calibrate the sclk voltage curve.
729 * - voltage offset(in mV) applied on target voltage calculation.
730 * This is available for Sienna Cichlid, Navy Flounder and Dimgrey
731 * Cavefish. For these ASICs, the target voltage calculation can be
732 * illustrated by "voltage = voltage calculated from v/f curve +
733 * overdrive vddgfx offset"
735 * - a list of valid ranges for sclk, mclk, and voltage curve points
740 * Reading the file will display:
742 * - minimum and maximum engine clock labeled OD_SCLK
744 * - a list of valid ranges for sclk labeled OD_RANGE
746 * To manually adjust these settings:
748 * - First select manual using power_dpm_force_performance_level
750 * - For clock frequency setting, enter a new value by writing a
751 * string that contains "s/m index clock" to the file. The index
752 * should be 0 if to set minimum clock. And 1 if to set maximum
753 * clock. E.g., "s 0 500" will update minimum sclk to be 500 MHz.
754 * "m 1 800" will update maximum mclk to be 800Mhz.
756 * For sclk voltage curve, enter the new values by writing a
757 * string that contains "vc point clock voltage" to the file. The
758 * points are indexed by 0, 1 and 2. E.g., "vc 0 300 600" will
759 * update point1 with clock set as 300Mhz and voltage as
760 * 600mV. "vc 2 1000 1000" will update point3 with clock set
761 * as 1000Mhz and voltage 1000mV.
763 * To update the voltage offset applied for gfxclk/voltage calculation,
764 * enter the new value by writing a string that contains "vo offset".
765 * This is supported by Sienna Cichlid, Navy Flounder and Dimgrey Cavefish.
766 * And the offset can be a positive or negative value.
768 * - When you have edited all of the states as needed, write "c" (commit)
769 * to the file to commit your changes
771 * - If you want to reset to the default power levels, write "r" (reset)
772 * to the file to reset them
776 static ssize_t amdgpu_set_pp_od_clk_voltage(struct device *dev,
777 struct device_attribute *attr,
781 struct drm_device *ddev = dev_get_drvdata(dev);
782 struct amdgpu_device *adev = drm_to_adev(ddev);
784 uint32_t parameter_size = 0;
789 const char delimiter[3] = {' ', '\n', '\0'};
792 if (amdgpu_in_reset(adev))
794 if (adev->in_suspend && !adev->in_runpm)
801 type = PP_OD_EDIT_SCLK_VDDC_TABLE;
802 else if (*buf == 'p')
803 type = PP_OD_EDIT_CCLK_VDDC_TABLE;
804 else if (*buf == 'm')
805 type = PP_OD_EDIT_MCLK_VDDC_TABLE;
807 type = PP_OD_RESTORE_DEFAULT_TABLE;
808 else if (*buf == 'c')
809 type = PP_OD_COMMIT_DPM_TABLE;
810 else if (!strncmp(buf, "vc", 2))
811 type = PP_OD_EDIT_VDDC_CURVE;
812 else if (!strncmp(buf, "vo", 2))
813 type = PP_OD_EDIT_VDDGFX_OFFSET;
817 memcpy(buf_cpy, buf, count+1);
821 if ((type == PP_OD_EDIT_VDDC_CURVE) ||
822 (type == PP_OD_EDIT_VDDGFX_OFFSET))
824 while (isspace(*++tmp_str));
826 while ((sub_str = strsep(&tmp_str, delimiter)) != NULL) {
827 if (strlen(sub_str) == 0)
829 ret = kstrtol(sub_str, 0, ¶meter[parameter_size]);
834 while (isspace(*tmp_str))
838 ret = pm_runtime_get_sync(ddev->dev);
840 pm_runtime_put_autosuspend(ddev->dev);
844 if (adev->powerplay.pp_funcs->set_fine_grain_clk_vol) {
845 ret = amdgpu_dpm_set_fine_grain_clk_vol(adev, type,
849 pm_runtime_mark_last_busy(ddev->dev);
850 pm_runtime_put_autosuspend(ddev->dev);
855 if (adev->powerplay.pp_funcs->odn_edit_dpm_table) {
856 ret = amdgpu_dpm_odn_edit_dpm_table(adev, type,
857 parameter, parameter_size);
859 pm_runtime_mark_last_busy(ddev->dev);
860 pm_runtime_put_autosuspend(ddev->dev);
865 if (type == PP_OD_COMMIT_DPM_TABLE) {
866 if (adev->powerplay.pp_funcs->dispatch_tasks) {
867 amdgpu_dpm_dispatch_task(adev,
868 AMD_PP_TASK_READJUST_POWER_STATE,
870 pm_runtime_mark_last_busy(ddev->dev);
871 pm_runtime_put_autosuspend(ddev->dev);
874 pm_runtime_mark_last_busy(ddev->dev);
875 pm_runtime_put_autosuspend(ddev->dev);
880 pm_runtime_mark_last_busy(ddev->dev);
881 pm_runtime_put_autosuspend(ddev->dev);
886 static ssize_t amdgpu_get_pp_od_clk_voltage(struct device *dev,
887 struct device_attribute *attr,
890 struct drm_device *ddev = dev_get_drvdata(dev);
891 struct amdgpu_device *adev = drm_to_adev(ddev);
895 if (amdgpu_in_reset(adev))
897 if (adev->in_suspend && !adev->in_runpm)
900 ret = pm_runtime_get_sync(ddev->dev);
902 pm_runtime_put_autosuspend(ddev->dev);
906 if (adev->powerplay.pp_funcs->print_clock_levels) {
907 size = amdgpu_dpm_print_clock_levels(adev, OD_SCLK, buf);
908 size += amdgpu_dpm_print_clock_levels(adev, OD_MCLK, buf+size);
909 size += amdgpu_dpm_print_clock_levels(adev, OD_VDDC_CURVE, buf+size);
910 size += amdgpu_dpm_print_clock_levels(adev, OD_VDDGFX_OFFSET, buf+size);
911 size += amdgpu_dpm_print_clock_levels(adev, OD_RANGE, buf+size);
912 size += amdgpu_dpm_print_clock_levels(adev, OD_CCLK, buf+size);
914 size = snprintf(buf, PAGE_SIZE, "\n");
916 pm_runtime_mark_last_busy(ddev->dev);
917 pm_runtime_put_autosuspend(ddev->dev);
925 * The amdgpu driver provides a sysfs API for adjusting what powerplay
926 * features to be enabled. The file pp_features is used for this. And
927 * this is only available for Vega10 and later dGPUs.
929 * Reading back the file will show you the followings:
930 * - Current ppfeature masks
931 * - List of the all supported powerplay features with their naming,
932 * bitmasks and enablement status('Y'/'N' means "enabled"/"disabled").
934 * To manually enable or disable a specific feature, just set or clear
935 * the corresponding bit from original ppfeature masks and input the
936 * new ppfeature masks.
938 static ssize_t amdgpu_set_pp_features(struct device *dev,
939 struct device_attribute *attr,
943 struct drm_device *ddev = dev_get_drvdata(dev);
944 struct amdgpu_device *adev = drm_to_adev(ddev);
945 uint64_t featuremask;
948 if (amdgpu_in_reset(adev))
950 if (adev->in_suspend && !adev->in_runpm)
953 ret = kstrtou64(buf, 0, &featuremask);
957 ret = pm_runtime_get_sync(ddev->dev);
959 pm_runtime_put_autosuspend(ddev->dev);
963 if (adev->powerplay.pp_funcs->set_ppfeature_status) {
964 ret = amdgpu_dpm_set_ppfeature_status(adev, featuremask);
966 pm_runtime_mark_last_busy(ddev->dev);
967 pm_runtime_put_autosuspend(ddev->dev);
971 pm_runtime_mark_last_busy(ddev->dev);
972 pm_runtime_put_autosuspend(ddev->dev);
977 static ssize_t amdgpu_get_pp_features(struct device *dev,
978 struct device_attribute *attr,
981 struct drm_device *ddev = dev_get_drvdata(dev);
982 struct amdgpu_device *adev = drm_to_adev(ddev);
986 if (amdgpu_in_reset(adev))
988 if (adev->in_suspend && !adev->in_runpm)
991 ret = pm_runtime_get_sync(ddev->dev);
993 pm_runtime_put_autosuspend(ddev->dev);
997 if (adev->powerplay.pp_funcs->get_ppfeature_status)
998 size = amdgpu_dpm_get_ppfeature_status(adev, buf);
1000 size = snprintf(buf, PAGE_SIZE, "\n");
1002 pm_runtime_mark_last_busy(ddev->dev);
1003 pm_runtime_put_autosuspend(ddev->dev);
1009 * DOC: pp_dpm_sclk pp_dpm_mclk pp_dpm_socclk pp_dpm_fclk pp_dpm_dcefclk pp_dpm_pcie
1011 * The amdgpu driver provides a sysfs API for adjusting what power levels
1012 * are enabled for a given power state. The files pp_dpm_sclk, pp_dpm_mclk,
1013 * pp_dpm_socclk, pp_dpm_fclk, pp_dpm_dcefclk and pp_dpm_pcie are used for
1016 * pp_dpm_socclk and pp_dpm_dcefclk interfaces are only available for
1017 * Vega10 and later ASICs.
1018 * pp_dpm_fclk interface is only available for Vega20 and later ASICs.
1020 * Reading back the files will show you the available power levels within
1021 * the power state and the clock information for those levels.
1023 * To manually adjust these states, first select manual using
1024 * power_dpm_force_performance_level.
1025 * Secondly, enter a new value for each level by inputing a string that
1026 * contains " echo xx xx xx > pp_dpm_sclk/mclk/pcie"
1029 * .. code-block:: bash
1031 * echo "4 5 6" > pp_dpm_sclk
1033 * will enable sclk levels 4, 5, and 6.
1035 * NOTE: change to the dcefclk max dpm level is not supported now
1038 static ssize_t amdgpu_get_pp_dpm_clock(struct device *dev,
1039 enum pp_clock_type type,
1042 struct drm_device *ddev = dev_get_drvdata(dev);
1043 struct amdgpu_device *adev = drm_to_adev(ddev);
1047 if (amdgpu_in_reset(adev))
1049 if (adev->in_suspend && !adev->in_runpm)
1052 ret = pm_runtime_get_sync(ddev->dev);
1054 pm_runtime_put_autosuspend(ddev->dev);
1058 if (adev->powerplay.pp_funcs->print_clock_levels)
1059 size = amdgpu_dpm_print_clock_levels(adev, type, buf);
1061 size = snprintf(buf, PAGE_SIZE, "\n");
1063 pm_runtime_mark_last_busy(ddev->dev);
1064 pm_runtime_put_autosuspend(ddev->dev);
1070 * Worst case: 32 bits individually specified, in octal at 12 characters
1071 * per line (+1 for \n).
1073 #define AMDGPU_MASK_BUF_MAX (32 * 13)
1075 static ssize_t amdgpu_read_mask(const char *buf, size_t count, uint32_t *mask)
1078 unsigned long level;
1079 char *sub_str = NULL;
1081 char buf_cpy[AMDGPU_MASK_BUF_MAX + 1];
1082 const char delimiter[3] = {' ', '\n', '\0'};
1087 bytes = min(count, sizeof(buf_cpy) - 1);
1088 memcpy(buf_cpy, buf, bytes);
1089 buf_cpy[bytes] = '\0';
1091 while ((sub_str = strsep(&tmp, delimiter)) != NULL) {
1092 if (strlen(sub_str)) {
1093 ret = kstrtoul(sub_str, 0, &level);
1094 if (ret || level > 31)
1096 *mask |= 1 << level;
1104 static ssize_t amdgpu_set_pp_dpm_clock(struct device *dev,
1105 enum pp_clock_type type,
1109 struct drm_device *ddev = dev_get_drvdata(dev);
1110 struct amdgpu_device *adev = drm_to_adev(ddev);
1114 if (amdgpu_in_reset(adev))
1116 if (adev->in_suspend && !adev->in_runpm)
1119 ret = amdgpu_read_mask(buf, count, &mask);
1123 ret = pm_runtime_get_sync(ddev->dev);
1125 pm_runtime_put_autosuspend(ddev->dev);
1129 if (adev->powerplay.pp_funcs->force_clock_level)
1130 ret = amdgpu_dpm_force_clock_level(adev, type, mask);
1134 pm_runtime_mark_last_busy(ddev->dev);
1135 pm_runtime_put_autosuspend(ddev->dev);
1143 static ssize_t amdgpu_get_pp_dpm_sclk(struct device *dev,
1144 struct device_attribute *attr,
1147 return amdgpu_get_pp_dpm_clock(dev, PP_SCLK, buf);
1150 static ssize_t amdgpu_set_pp_dpm_sclk(struct device *dev,
1151 struct device_attribute *attr,
1155 return amdgpu_set_pp_dpm_clock(dev, PP_SCLK, buf, count);
1158 static ssize_t amdgpu_get_pp_dpm_mclk(struct device *dev,
1159 struct device_attribute *attr,
1162 return amdgpu_get_pp_dpm_clock(dev, PP_MCLK, buf);
1165 static ssize_t amdgpu_set_pp_dpm_mclk(struct device *dev,
1166 struct device_attribute *attr,
1170 return amdgpu_set_pp_dpm_clock(dev, PP_MCLK, buf, count);
1173 static ssize_t amdgpu_get_pp_dpm_socclk(struct device *dev,
1174 struct device_attribute *attr,
1177 return amdgpu_get_pp_dpm_clock(dev, PP_SOCCLK, buf);
1180 static ssize_t amdgpu_set_pp_dpm_socclk(struct device *dev,
1181 struct device_attribute *attr,
1185 return amdgpu_set_pp_dpm_clock(dev, PP_SOCCLK, buf, count);
1188 static ssize_t amdgpu_get_pp_dpm_fclk(struct device *dev,
1189 struct device_attribute *attr,
1192 return amdgpu_get_pp_dpm_clock(dev, PP_FCLK, buf);
1195 static ssize_t amdgpu_set_pp_dpm_fclk(struct device *dev,
1196 struct device_attribute *attr,
1200 return amdgpu_set_pp_dpm_clock(dev, PP_FCLK, buf, count);
1203 static ssize_t amdgpu_get_pp_dpm_vclk(struct device *dev,
1204 struct device_attribute *attr,
1207 return amdgpu_get_pp_dpm_clock(dev, PP_VCLK, buf);
1210 static ssize_t amdgpu_set_pp_dpm_vclk(struct device *dev,
1211 struct device_attribute *attr,
1215 return amdgpu_set_pp_dpm_clock(dev, PP_VCLK, buf, count);
1218 static ssize_t amdgpu_get_pp_dpm_dclk(struct device *dev,
1219 struct device_attribute *attr,
1222 return amdgpu_get_pp_dpm_clock(dev, PP_DCLK, buf);
1225 static ssize_t amdgpu_set_pp_dpm_dclk(struct device *dev,
1226 struct device_attribute *attr,
1230 return amdgpu_set_pp_dpm_clock(dev, PP_DCLK, buf, count);
1233 static ssize_t amdgpu_get_pp_dpm_dcefclk(struct device *dev,
1234 struct device_attribute *attr,
1237 return amdgpu_get_pp_dpm_clock(dev, PP_DCEFCLK, buf);
1240 static ssize_t amdgpu_set_pp_dpm_dcefclk(struct device *dev,
1241 struct device_attribute *attr,
1245 return amdgpu_set_pp_dpm_clock(dev, PP_DCEFCLK, buf, count);
1248 static ssize_t amdgpu_get_pp_dpm_pcie(struct device *dev,
1249 struct device_attribute *attr,
1252 return amdgpu_get_pp_dpm_clock(dev, PP_PCIE, buf);
1255 static ssize_t amdgpu_set_pp_dpm_pcie(struct device *dev,
1256 struct device_attribute *attr,
1260 return amdgpu_set_pp_dpm_clock(dev, PP_PCIE, buf, count);
1263 static ssize_t amdgpu_get_pp_sclk_od(struct device *dev,
1264 struct device_attribute *attr,
1267 struct drm_device *ddev = dev_get_drvdata(dev);
1268 struct amdgpu_device *adev = drm_to_adev(ddev);
1272 if (amdgpu_in_reset(adev))
1274 if (adev->in_suspend && !adev->in_runpm)
1277 ret = pm_runtime_get_sync(ddev->dev);
1279 pm_runtime_put_autosuspend(ddev->dev);
1283 if (is_support_sw_smu(adev))
1285 else if (adev->powerplay.pp_funcs->get_sclk_od)
1286 value = amdgpu_dpm_get_sclk_od(adev);
1288 pm_runtime_mark_last_busy(ddev->dev);
1289 pm_runtime_put_autosuspend(ddev->dev);
1291 return sysfs_emit(buf, "%d\n", value);
1294 static ssize_t amdgpu_set_pp_sclk_od(struct device *dev,
1295 struct device_attribute *attr,
1299 struct drm_device *ddev = dev_get_drvdata(dev);
1300 struct amdgpu_device *adev = drm_to_adev(ddev);
1304 if (amdgpu_in_reset(adev))
1306 if (adev->in_suspend && !adev->in_runpm)
1309 ret = kstrtol(buf, 0, &value);
1314 ret = pm_runtime_get_sync(ddev->dev);
1316 pm_runtime_put_autosuspend(ddev->dev);
1320 if (is_support_sw_smu(adev)) {
1323 if (adev->powerplay.pp_funcs->set_sclk_od)
1324 amdgpu_dpm_set_sclk_od(adev, (uint32_t)value);
1326 if (adev->powerplay.pp_funcs->dispatch_tasks) {
1327 amdgpu_dpm_dispatch_task(adev, AMD_PP_TASK_READJUST_POWER_STATE, NULL);
1329 adev->pm.dpm.current_ps = adev->pm.dpm.boot_ps;
1330 amdgpu_pm_compute_clocks(adev);
1334 pm_runtime_mark_last_busy(ddev->dev);
1335 pm_runtime_put_autosuspend(ddev->dev);
1340 static ssize_t amdgpu_get_pp_mclk_od(struct device *dev,
1341 struct device_attribute *attr,
1344 struct drm_device *ddev = dev_get_drvdata(dev);
1345 struct amdgpu_device *adev = drm_to_adev(ddev);
1349 if (amdgpu_in_reset(adev))
1351 if (adev->in_suspend && !adev->in_runpm)
1354 ret = pm_runtime_get_sync(ddev->dev);
1356 pm_runtime_put_autosuspend(ddev->dev);
1360 if (is_support_sw_smu(adev))
1362 else if (adev->powerplay.pp_funcs->get_mclk_od)
1363 value = amdgpu_dpm_get_mclk_od(adev);
1365 pm_runtime_mark_last_busy(ddev->dev);
1366 pm_runtime_put_autosuspend(ddev->dev);
1368 return sysfs_emit(buf, "%d\n", value);
1371 static ssize_t amdgpu_set_pp_mclk_od(struct device *dev,
1372 struct device_attribute *attr,
1376 struct drm_device *ddev = dev_get_drvdata(dev);
1377 struct amdgpu_device *adev = drm_to_adev(ddev);
1381 if (amdgpu_in_reset(adev))
1383 if (adev->in_suspend && !adev->in_runpm)
1386 ret = kstrtol(buf, 0, &value);
1391 ret = pm_runtime_get_sync(ddev->dev);
1393 pm_runtime_put_autosuspend(ddev->dev);
1397 if (is_support_sw_smu(adev)) {
1400 if (adev->powerplay.pp_funcs->set_mclk_od)
1401 amdgpu_dpm_set_mclk_od(adev, (uint32_t)value);
1403 if (adev->powerplay.pp_funcs->dispatch_tasks) {
1404 amdgpu_dpm_dispatch_task(adev, AMD_PP_TASK_READJUST_POWER_STATE, NULL);
1406 adev->pm.dpm.current_ps = adev->pm.dpm.boot_ps;
1407 amdgpu_pm_compute_clocks(adev);
1411 pm_runtime_mark_last_busy(ddev->dev);
1412 pm_runtime_put_autosuspend(ddev->dev);
1418 * DOC: pp_power_profile_mode
1420 * The amdgpu driver provides a sysfs API for adjusting the heuristics
1421 * related to switching between power levels in a power state. The file
1422 * pp_power_profile_mode is used for this.
1424 * Reading this file outputs a list of all of the predefined power profiles
1425 * and the relevant heuristics settings for that profile.
1427 * To select a profile or create a custom profile, first select manual using
1428 * power_dpm_force_performance_level. Writing the number of a predefined
1429 * profile to pp_power_profile_mode will enable those heuristics. To
1430 * create a custom set of heuristics, write a string of numbers to the file
1431 * starting with the number of the custom profile along with a setting
1432 * for each heuristic parameter. Due to differences across asic families
1433 * the heuristic parameters vary from family to family.
1437 static ssize_t amdgpu_get_pp_power_profile_mode(struct device *dev,
1438 struct device_attribute *attr,
1441 struct drm_device *ddev = dev_get_drvdata(dev);
1442 struct amdgpu_device *adev = drm_to_adev(ddev);
1446 if (amdgpu_in_reset(adev))
1448 if (adev->in_suspend && !adev->in_runpm)
1451 ret = pm_runtime_get_sync(ddev->dev);
1453 pm_runtime_put_autosuspend(ddev->dev);
1457 if (adev->powerplay.pp_funcs->get_power_profile_mode)
1458 size = amdgpu_dpm_get_power_profile_mode(adev, buf);
1460 size = snprintf(buf, PAGE_SIZE, "\n");
1462 pm_runtime_mark_last_busy(ddev->dev);
1463 pm_runtime_put_autosuspend(ddev->dev);
1469 static ssize_t amdgpu_set_pp_power_profile_mode(struct device *dev,
1470 struct device_attribute *attr,
1475 struct drm_device *ddev = dev_get_drvdata(dev);
1476 struct amdgpu_device *adev = drm_to_adev(ddev);
1477 uint32_t parameter_size = 0;
1479 char *sub_str, buf_cpy[128];
1483 long int profile_mode = 0;
1484 const char delimiter[3] = {' ', '\n', '\0'};
1486 if (amdgpu_in_reset(adev))
1488 if (adev->in_suspend && !adev->in_runpm)
1493 ret = kstrtol(tmp, 0, &profile_mode);
1497 if (profile_mode == PP_SMC_POWER_PROFILE_CUSTOM) {
1498 if (count < 2 || count > 127)
1500 while (isspace(*++buf))
1502 memcpy(buf_cpy, buf, count-i);
1504 while ((sub_str = strsep(&tmp_str, delimiter)) != NULL) {
1505 if (strlen(sub_str) == 0)
1507 ret = kstrtol(sub_str, 0, ¶meter[parameter_size]);
1511 while (isspace(*tmp_str))
1515 parameter[parameter_size] = profile_mode;
1517 ret = pm_runtime_get_sync(ddev->dev);
1519 pm_runtime_put_autosuspend(ddev->dev);
1523 if (adev->powerplay.pp_funcs->set_power_profile_mode)
1524 ret = amdgpu_dpm_set_power_profile_mode(adev, parameter, parameter_size);
1526 pm_runtime_mark_last_busy(ddev->dev);
1527 pm_runtime_put_autosuspend(ddev->dev);
1536 * DOC: gpu_busy_percent
1538 * The amdgpu driver provides a sysfs API for reading how busy the GPU
1539 * is as a percentage. The file gpu_busy_percent is used for this.
1540 * The SMU firmware computes a percentage of load based on the
1541 * aggregate activity level in the IP cores.
1543 static ssize_t amdgpu_get_gpu_busy_percent(struct device *dev,
1544 struct device_attribute *attr,
1547 struct drm_device *ddev = dev_get_drvdata(dev);
1548 struct amdgpu_device *adev = drm_to_adev(ddev);
1549 int r, value, size = sizeof(value);
1551 if (amdgpu_in_reset(adev))
1553 if (adev->in_suspend && !adev->in_runpm)
1556 r = pm_runtime_get_sync(ddev->dev);
1558 pm_runtime_put_autosuspend(ddev->dev);
1562 /* read the IP busy sensor */
1563 r = amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GPU_LOAD,
1564 (void *)&value, &size);
1566 pm_runtime_mark_last_busy(ddev->dev);
1567 pm_runtime_put_autosuspend(ddev->dev);
1572 return sysfs_emit(buf, "%d\n", value);
1576 * DOC: mem_busy_percent
1578 * The amdgpu driver provides a sysfs API for reading how busy the VRAM
1579 * is as a percentage. The file mem_busy_percent is used for this.
1580 * The SMU firmware computes a percentage of load based on the
1581 * aggregate activity level in the IP cores.
1583 static ssize_t amdgpu_get_mem_busy_percent(struct device *dev,
1584 struct device_attribute *attr,
1587 struct drm_device *ddev = dev_get_drvdata(dev);
1588 struct amdgpu_device *adev = drm_to_adev(ddev);
1589 int r, value, size = sizeof(value);
1591 if (amdgpu_in_reset(adev))
1593 if (adev->in_suspend && !adev->in_runpm)
1596 r = pm_runtime_get_sync(ddev->dev);
1598 pm_runtime_put_autosuspend(ddev->dev);
1602 /* read the IP busy sensor */
1603 r = amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_MEM_LOAD,
1604 (void *)&value, &size);
1606 pm_runtime_mark_last_busy(ddev->dev);
1607 pm_runtime_put_autosuspend(ddev->dev);
1612 return sysfs_emit(buf, "%d\n", value);
1618 * The amdgpu driver provides a sysfs API for estimating how much data
1619 * has been received and sent by the GPU in the last second through PCIe.
1620 * The file pcie_bw is used for this.
1621 * The Perf counters count the number of received and sent messages and return
1622 * those values, as well as the maximum payload size of a PCIe packet (mps).
1623 * Note that it is not possible to easily and quickly obtain the size of each
1624 * packet transmitted, so we output the max payload size (mps) to allow for
1625 * quick estimation of the PCIe bandwidth usage
1627 static ssize_t amdgpu_get_pcie_bw(struct device *dev,
1628 struct device_attribute *attr,
1631 struct drm_device *ddev = dev_get_drvdata(dev);
1632 struct amdgpu_device *adev = drm_to_adev(ddev);
1633 uint64_t count0 = 0, count1 = 0;
1636 if (amdgpu_in_reset(adev))
1638 if (adev->in_suspend && !adev->in_runpm)
1641 if (adev->flags & AMD_IS_APU)
1644 if (!adev->asic_funcs->get_pcie_usage)
1647 ret = pm_runtime_get_sync(ddev->dev);
1649 pm_runtime_put_autosuspend(ddev->dev);
1653 amdgpu_asic_get_pcie_usage(adev, &count0, &count1);
1655 pm_runtime_mark_last_busy(ddev->dev);
1656 pm_runtime_put_autosuspend(ddev->dev);
1658 return sysfs_emit(buf, "%llu %llu %i\n",
1659 count0, count1, pcie_get_mps(adev->pdev));
1665 * The amdgpu driver provides a sysfs API for providing a unique ID for the GPU
1666 * The file unique_id is used for this.
1667 * This will provide a Unique ID that will persist from machine to machine
1669 * NOTE: This will only work for GFX9 and newer. This file will be absent
1670 * on unsupported ASICs (GFX8 and older)
1672 static ssize_t amdgpu_get_unique_id(struct device *dev,
1673 struct device_attribute *attr,
1676 struct drm_device *ddev = dev_get_drvdata(dev);
1677 struct amdgpu_device *adev = drm_to_adev(ddev);
1679 if (amdgpu_in_reset(adev))
1681 if (adev->in_suspend && !adev->in_runpm)
1684 if (adev->unique_id)
1685 return sysfs_emit(buf, "%016llx\n", adev->unique_id);
1691 * DOC: thermal_throttling_logging
1693 * Thermal throttling pulls down the clock frequency and thus the performance.
1694 * It's an useful mechanism to protect the chip from overheating. Since it
1695 * impacts performance, the user controls whether it is enabled and if so,
1696 * the log frequency.
1698 * Reading back the file shows you the status(enabled or disabled) and
1699 * the interval(in seconds) between each thermal logging.
1701 * Writing an integer to the file, sets a new logging interval, in seconds.
1702 * The value should be between 1 and 3600. If the value is less than 1,
1703 * thermal logging is disabled. Values greater than 3600 are ignored.
1705 static ssize_t amdgpu_get_thermal_throttling_logging(struct device *dev,
1706 struct device_attribute *attr,
1709 struct drm_device *ddev = dev_get_drvdata(dev);
1710 struct amdgpu_device *adev = drm_to_adev(ddev);
1712 return sysfs_emit(buf, "%s: thermal throttling logging %s, with interval %d seconds\n",
1713 adev_to_drm(adev)->unique,
1714 atomic_read(&adev->throttling_logging_enabled) ? "enabled" : "disabled",
1715 adev->throttling_logging_rs.interval / HZ + 1);
1718 static ssize_t amdgpu_set_thermal_throttling_logging(struct device *dev,
1719 struct device_attribute *attr,
1723 struct drm_device *ddev = dev_get_drvdata(dev);
1724 struct amdgpu_device *adev = drm_to_adev(ddev);
1725 long throttling_logging_interval;
1726 unsigned long flags;
1729 ret = kstrtol(buf, 0, &throttling_logging_interval);
1733 if (throttling_logging_interval > 3600)
1736 if (throttling_logging_interval > 0) {
1737 raw_spin_lock_irqsave(&adev->throttling_logging_rs.lock, flags);
1739 * Reset the ratelimit timer internals.
1740 * This can effectively restart the timer.
1742 adev->throttling_logging_rs.interval =
1743 (throttling_logging_interval - 1) * HZ;
1744 adev->throttling_logging_rs.begin = 0;
1745 adev->throttling_logging_rs.printed = 0;
1746 adev->throttling_logging_rs.missed = 0;
1747 raw_spin_unlock_irqrestore(&adev->throttling_logging_rs.lock, flags);
1749 atomic_set(&adev->throttling_logging_enabled, 1);
1751 atomic_set(&adev->throttling_logging_enabled, 0);
1760 * The amdgpu driver provides a sysfs API for retrieving current gpu
1761 * metrics data. The file gpu_metrics is used for this. Reading the
1762 * file will dump all the current gpu metrics data.
1764 * These data include temperature, frequency, engines utilization,
1765 * power consume, throttler status, fan speed and cpu core statistics(
1766 * available for APU only). That's it will give a snapshot of all sensors
1769 static ssize_t amdgpu_get_gpu_metrics(struct device *dev,
1770 struct device_attribute *attr,
1773 struct drm_device *ddev = dev_get_drvdata(dev);
1774 struct amdgpu_device *adev = drm_to_adev(ddev);
1779 if (amdgpu_in_reset(adev))
1781 if (adev->in_suspend && !adev->in_runpm)
1784 ret = pm_runtime_get_sync(ddev->dev);
1786 pm_runtime_put_autosuspend(ddev->dev);
1790 if (adev->powerplay.pp_funcs->get_gpu_metrics)
1791 size = amdgpu_dpm_get_gpu_metrics(adev, &gpu_metrics);
1796 if (size >= PAGE_SIZE)
1797 size = PAGE_SIZE - 1;
1799 memcpy(buf, gpu_metrics, size);
1802 pm_runtime_mark_last_busy(ddev->dev);
1803 pm_runtime_put_autosuspend(ddev->dev);
1808 static struct amdgpu_device_attr amdgpu_device_attrs[] = {
1809 AMDGPU_DEVICE_ATTR_RW(power_dpm_state, ATTR_FLAG_BASIC|ATTR_FLAG_ONEVF),
1810 AMDGPU_DEVICE_ATTR_RW(power_dpm_force_performance_level, ATTR_FLAG_BASIC|ATTR_FLAG_ONEVF),
1811 AMDGPU_DEVICE_ATTR_RO(pp_num_states, ATTR_FLAG_BASIC),
1812 AMDGPU_DEVICE_ATTR_RO(pp_cur_state, ATTR_FLAG_BASIC),
1813 AMDGPU_DEVICE_ATTR_RW(pp_force_state, ATTR_FLAG_BASIC),
1814 AMDGPU_DEVICE_ATTR_RW(pp_table, ATTR_FLAG_BASIC),
1815 AMDGPU_DEVICE_ATTR_RW(pp_dpm_sclk, ATTR_FLAG_BASIC|ATTR_FLAG_ONEVF),
1816 AMDGPU_DEVICE_ATTR_RW(pp_dpm_mclk, ATTR_FLAG_BASIC|ATTR_FLAG_ONEVF),
1817 AMDGPU_DEVICE_ATTR_RW(pp_dpm_socclk, ATTR_FLAG_BASIC|ATTR_FLAG_ONEVF),
1818 AMDGPU_DEVICE_ATTR_RW(pp_dpm_fclk, ATTR_FLAG_BASIC|ATTR_FLAG_ONEVF),
1819 AMDGPU_DEVICE_ATTR_RW(pp_dpm_vclk, ATTR_FLAG_BASIC|ATTR_FLAG_ONEVF),
1820 AMDGPU_DEVICE_ATTR_RW(pp_dpm_dclk, ATTR_FLAG_BASIC|ATTR_FLAG_ONEVF),
1821 AMDGPU_DEVICE_ATTR_RW(pp_dpm_dcefclk, ATTR_FLAG_BASIC),
1822 AMDGPU_DEVICE_ATTR_RW(pp_dpm_pcie, ATTR_FLAG_BASIC),
1823 AMDGPU_DEVICE_ATTR_RW(pp_sclk_od, ATTR_FLAG_BASIC),
1824 AMDGPU_DEVICE_ATTR_RW(pp_mclk_od, ATTR_FLAG_BASIC),
1825 AMDGPU_DEVICE_ATTR_RW(pp_power_profile_mode, ATTR_FLAG_BASIC),
1826 AMDGPU_DEVICE_ATTR_RW(pp_od_clk_voltage, ATTR_FLAG_BASIC),
1827 AMDGPU_DEVICE_ATTR_RO(gpu_busy_percent, ATTR_FLAG_BASIC),
1828 AMDGPU_DEVICE_ATTR_RO(mem_busy_percent, ATTR_FLAG_BASIC),
1829 AMDGPU_DEVICE_ATTR_RO(pcie_bw, ATTR_FLAG_BASIC),
1830 AMDGPU_DEVICE_ATTR_RW(pp_features, ATTR_FLAG_BASIC),
1831 AMDGPU_DEVICE_ATTR_RO(unique_id, ATTR_FLAG_BASIC),
1832 AMDGPU_DEVICE_ATTR_RW(thermal_throttling_logging, ATTR_FLAG_BASIC),
1833 AMDGPU_DEVICE_ATTR_RO(gpu_metrics, ATTR_FLAG_BASIC),
1836 static int default_attr_update(struct amdgpu_device *adev, struct amdgpu_device_attr *attr,
1837 uint32_t mask, enum amdgpu_device_attr_states *states)
1839 struct device_attribute *dev_attr = &attr->dev_attr;
1840 const char *attr_name = dev_attr->attr.name;
1841 struct pp_hwmgr *hwmgr = adev->powerplay.pp_handle;
1842 enum amd_asic_type asic_type = adev->asic_type;
1844 if (!(attr->flags & mask)) {
1845 *states = ATTR_STATE_UNSUPPORTED;
1849 #define DEVICE_ATTR_IS(_name) (!strcmp(attr_name, #_name))
1851 if (DEVICE_ATTR_IS(pp_dpm_socclk)) {
1852 if (asic_type < CHIP_VEGA10)
1853 *states = ATTR_STATE_UNSUPPORTED;
1854 } else if (DEVICE_ATTR_IS(pp_dpm_dcefclk)) {
1855 if (asic_type < CHIP_VEGA10 ||
1856 asic_type == CHIP_ARCTURUS ||
1857 asic_type == CHIP_ALDEBARAN)
1858 *states = ATTR_STATE_UNSUPPORTED;
1859 } else if (DEVICE_ATTR_IS(pp_dpm_fclk)) {
1860 if (asic_type < CHIP_VEGA20)
1861 *states = ATTR_STATE_UNSUPPORTED;
1862 } else if (DEVICE_ATTR_IS(pp_od_clk_voltage)) {
1863 *states = ATTR_STATE_UNSUPPORTED;
1864 if ((is_support_sw_smu(adev) && adev->smu.od_enabled) ||
1865 (is_support_sw_smu(adev) && adev->smu.is_apu) ||
1866 (!is_support_sw_smu(adev) && hwmgr->od_enabled))
1867 *states = ATTR_STATE_SUPPORTED;
1868 } else if (DEVICE_ATTR_IS(mem_busy_percent)) {
1869 if (adev->flags & AMD_IS_APU || asic_type == CHIP_VEGA10)
1870 *states = ATTR_STATE_UNSUPPORTED;
1871 } else if (DEVICE_ATTR_IS(pcie_bw)) {
1872 /* PCIe Perf counters won't work on APU nodes */
1873 if (adev->flags & AMD_IS_APU)
1874 *states = ATTR_STATE_UNSUPPORTED;
1875 } else if (DEVICE_ATTR_IS(unique_id)) {
1876 if (asic_type != CHIP_VEGA10 &&
1877 asic_type != CHIP_VEGA20 &&
1878 asic_type != CHIP_ARCTURUS)
1879 *states = ATTR_STATE_UNSUPPORTED;
1880 } else if (DEVICE_ATTR_IS(pp_features)) {
1881 if (adev->flags & AMD_IS_APU || asic_type < CHIP_VEGA10)
1882 *states = ATTR_STATE_UNSUPPORTED;
1883 } else if (DEVICE_ATTR_IS(gpu_metrics)) {
1884 if (asic_type < CHIP_VEGA12)
1885 *states = ATTR_STATE_UNSUPPORTED;
1886 } else if (DEVICE_ATTR_IS(pp_dpm_vclk)) {
1887 if (!(asic_type == CHIP_VANGOGH))
1888 *states = ATTR_STATE_UNSUPPORTED;
1889 } else if (DEVICE_ATTR_IS(pp_dpm_dclk)) {
1890 if (!(asic_type == CHIP_VANGOGH))
1891 *states = ATTR_STATE_UNSUPPORTED;
1894 if (asic_type == CHIP_ARCTURUS) {
1895 /* Arcturus does not support standalone mclk/socclk/fclk level setting */
1896 if (DEVICE_ATTR_IS(pp_dpm_mclk) ||
1897 DEVICE_ATTR_IS(pp_dpm_socclk) ||
1898 DEVICE_ATTR_IS(pp_dpm_fclk)) {
1899 dev_attr->attr.mode &= ~S_IWUGO;
1900 dev_attr->store = NULL;
1904 if (DEVICE_ATTR_IS(pp_dpm_dcefclk)) {
1905 /* SMU MP1 does not support dcefclk level setting */
1906 if (asic_type >= CHIP_NAVI10) {
1907 dev_attr->attr.mode &= ~S_IWUGO;
1908 dev_attr->store = NULL;
1912 #undef DEVICE_ATTR_IS
1918 static int amdgpu_device_attr_create(struct amdgpu_device *adev,
1919 struct amdgpu_device_attr *attr,
1920 uint32_t mask, struct list_head *attr_list)
1923 struct device_attribute *dev_attr = &attr->dev_attr;
1924 const char *name = dev_attr->attr.name;
1925 enum amdgpu_device_attr_states attr_states = ATTR_STATE_SUPPORTED;
1926 struct amdgpu_device_attr_entry *attr_entry;
1928 int (*attr_update)(struct amdgpu_device *adev, struct amdgpu_device_attr *attr,
1929 uint32_t mask, enum amdgpu_device_attr_states *states) = default_attr_update;
1933 attr_update = attr->attr_update ? attr_update : default_attr_update;
1935 ret = attr_update(adev, attr, mask, &attr_states);
1937 dev_err(adev->dev, "failed to update device file %s, ret = %d\n",
1942 if (attr_states == ATTR_STATE_UNSUPPORTED)
1945 ret = device_create_file(adev->dev, dev_attr);
1947 dev_err(adev->dev, "failed to create device file %s, ret = %d\n",
1951 attr_entry = kmalloc(sizeof(*attr_entry), GFP_KERNEL);
1955 attr_entry->attr = attr;
1956 INIT_LIST_HEAD(&attr_entry->entry);
1958 list_add_tail(&attr_entry->entry, attr_list);
1963 static void amdgpu_device_attr_remove(struct amdgpu_device *adev, struct amdgpu_device_attr *attr)
1965 struct device_attribute *dev_attr = &attr->dev_attr;
1967 device_remove_file(adev->dev, dev_attr);
1970 static void amdgpu_device_attr_remove_groups(struct amdgpu_device *adev,
1971 struct list_head *attr_list);
1973 static int amdgpu_device_attr_create_groups(struct amdgpu_device *adev,
1974 struct amdgpu_device_attr *attrs,
1977 struct list_head *attr_list)
1982 for (i = 0; i < counts; i++) {
1983 ret = amdgpu_device_attr_create(adev, &attrs[i], mask, attr_list);
1991 amdgpu_device_attr_remove_groups(adev, attr_list);
1996 static void amdgpu_device_attr_remove_groups(struct amdgpu_device *adev,
1997 struct list_head *attr_list)
1999 struct amdgpu_device_attr_entry *entry, *entry_tmp;
2001 if (list_empty(attr_list))
2004 list_for_each_entry_safe(entry, entry_tmp, attr_list, entry) {
2005 amdgpu_device_attr_remove(adev, entry->attr);
2006 list_del(&entry->entry);
2011 static ssize_t amdgpu_hwmon_show_temp(struct device *dev,
2012 struct device_attribute *attr,
2015 struct amdgpu_device *adev = dev_get_drvdata(dev);
2016 int channel = to_sensor_dev_attr(attr)->index;
2017 int r, temp = 0, size = sizeof(temp);
2019 if (amdgpu_in_reset(adev))
2021 if (adev->in_suspend && !adev->in_runpm)
2024 if (channel >= PP_TEMP_MAX)
2027 r = pm_runtime_get_sync(adev_to_drm(adev)->dev);
2029 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2034 case PP_TEMP_JUNCTION:
2035 /* get current junction temperature */
2036 r = amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_HOTSPOT_TEMP,
2037 (void *)&temp, &size);
2040 /* get current edge temperature */
2041 r = amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_EDGE_TEMP,
2042 (void *)&temp, &size);
2045 /* get current memory temperature */
2046 r = amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_MEM_TEMP,
2047 (void *)&temp, &size);
2054 pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
2055 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2060 return sysfs_emit(buf, "%d\n", temp);
2063 static ssize_t amdgpu_hwmon_show_temp_thresh(struct device *dev,
2064 struct device_attribute *attr,
2067 struct amdgpu_device *adev = dev_get_drvdata(dev);
2068 int hyst = to_sensor_dev_attr(attr)->index;
2072 temp = adev->pm.dpm.thermal.min_temp;
2074 temp = adev->pm.dpm.thermal.max_temp;
2076 return sysfs_emit(buf, "%d\n", temp);
2079 static ssize_t amdgpu_hwmon_show_hotspot_temp_thresh(struct device *dev,
2080 struct device_attribute *attr,
2083 struct amdgpu_device *adev = dev_get_drvdata(dev);
2084 int hyst = to_sensor_dev_attr(attr)->index;
2088 temp = adev->pm.dpm.thermal.min_hotspot_temp;
2090 temp = adev->pm.dpm.thermal.max_hotspot_crit_temp;
2092 return sysfs_emit(buf, "%d\n", temp);
2095 static ssize_t amdgpu_hwmon_show_mem_temp_thresh(struct device *dev,
2096 struct device_attribute *attr,
2099 struct amdgpu_device *adev = dev_get_drvdata(dev);
2100 int hyst = to_sensor_dev_attr(attr)->index;
2104 temp = adev->pm.dpm.thermal.min_mem_temp;
2106 temp = adev->pm.dpm.thermal.max_mem_crit_temp;
2108 return sysfs_emit(buf, "%d\n", temp);
2111 static ssize_t amdgpu_hwmon_show_temp_label(struct device *dev,
2112 struct device_attribute *attr,
2115 int channel = to_sensor_dev_attr(attr)->index;
2117 if (channel >= PP_TEMP_MAX)
2120 return sysfs_emit(buf, "%s\n", temp_label[channel].label);
2123 static ssize_t amdgpu_hwmon_show_temp_emergency(struct device *dev,
2124 struct device_attribute *attr,
2127 struct amdgpu_device *adev = dev_get_drvdata(dev);
2128 int channel = to_sensor_dev_attr(attr)->index;
2131 if (channel >= PP_TEMP_MAX)
2135 case PP_TEMP_JUNCTION:
2136 temp = adev->pm.dpm.thermal.max_hotspot_emergency_temp;
2139 temp = adev->pm.dpm.thermal.max_edge_emergency_temp;
2142 temp = adev->pm.dpm.thermal.max_mem_emergency_temp;
2146 return sysfs_emit(buf, "%d\n", temp);
2149 static ssize_t amdgpu_hwmon_get_pwm1_enable(struct device *dev,
2150 struct device_attribute *attr,
2153 struct amdgpu_device *adev = dev_get_drvdata(dev);
2157 if (amdgpu_in_reset(adev))
2159 if (adev->in_suspend && !adev->in_runpm)
2162 ret = pm_runtime_get_sync(adev_to_drm(adev)->dev);
2164 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2168 if (!adev->powerplay.pp_funcs->get_fan_control_mode) {
2169 pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
2170 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2174 pwm_mode = amdgpu_dpm_get_fan_control_mode(adev);
2176 pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
2177 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2179 return sprintf(buf, "%u\n", pwm_mode);
2182 static ssize_t amdgpu_hwmon_set_pwm1_enable(struct device *dev,
2183 struct device_attribute *attr,
2187 struct amdgpu_device *adev = dev_get_drvdata(dev);
2191 if (amdgpu_in_reset(adev))
2193 if (adev->in_suspend && !adev->in_runpm)
2196 err = kstrtoint(buf, 10, &value);
2200 ret = pm_runtime_get_sync(adev_to_drm(adev)->dev);
2202 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2206 if (!adev->powerplay.pp_funcs->set_fan_control_mode) {
2207 pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
2208 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2212 amdgpu_dpm_set_fan_control_mode(adev, value);
2214 pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
2215 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2220 static ssize_t amdgpu_hwmon_get_pwm1_min(struct device *dev,
2221 struct device_attribute *attr,
2224 return sprintf(buf, "%i\n", 0);
2227 static ssize_t amdgpu_hwmon_get_pwm1_max(struct device *dev,
2228 struct device_attribute *attr,
2231 return sprintf(buf, "%i\n", 255);
2234 static ssize_t amdgpu_hwmon_set_pwm1(struct device *dev,
2235 struct device_attribute *attr,
2236 const char *buf, size_t count)
2238 struct amdgpu_device *adev = dev_get_drvdata(dev);
2243 if (amdgpu_in_reset(adev))
2245 if (adev->in_suspend && !adev->in_runpm)
2248 err = pm_runtime_get_sync(adev_to_drm(adev)->dev);
2250 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2254 pwm_mode = amdgpu_dpm_get_fan_control_mode(adev);
2255 if (pwm_mode != AMD_FAN_CTRL_MANUAL) {
2256 pr_info("manual fan speed control should be enabled first\n");
2257 pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
2258 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2262 err = kstrtou32(buf, 10, &value);
2264 pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
2265 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2269 value = (value * 100) / 255;
2271 if (adev->powerplay.pp_funcs->set_fan_speed_percent)
2272 err = amdgpu_dpm_set_fan_speed_percent(adev, value);
2276 pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
2277 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2285 static ssize_t amdgpu_hwmon_get_pwm1(struct device *dev,
2286 struct device_attribute *attr,
2289 struct amdgpu_device *adev = dev_get_drvdata(dev);
2293 if (amdgpu_in_reset(adev))
2295 if (adev->in_suspend && !adev->in_runpm)
2298 err = pm_runtime_get_sync(adev_to_drm(adev)->dev);
2300 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2304 if (adev->powerplay.pp_funcs->get_fan_speed_percent)
2305 err = amdgpu_dpm_get_fan_speed_percent(adev, &speed);
2309 pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
2310 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2315 speed = (speed * 255) / 100;
2317 return sprintf(buf, "%i\n", speed);
2320 static ssize_t amdgpu_hwmon_get_fan1_input(struct device *dev,
2321 struct device_attribute *attr,
2324 struct amdgpu_device *adev = dev_get_drvdata(dev);
2328 if (amdgpu_in_reset(adev))
2330 if (adev->in_suspend && !adev->in_runpm)
2333 err = pm_runtime_get_sync(adev_to_drm(adev)->dev);
2335 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2339 if (adev->powerplay.pp_funcs->get_fan_speed_rpm)
2340 err = amdgpu_dpm_get_fan_speed_rpm(adev, &speed);
2344 pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
2345 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2350 return sprintf(buf, "%i\n", speed);
2353 static ssize_t amdgpu_hwmon_get_fan1_min(struct device *dev,
2354 struct device_attribute *attr,
2357 struct amdgpu_device *adev = dev_get_drvdata(dev);
2359 u32 size = sizeof(min_rpm);
2362 if (amdgpu_in_reset(adev))
2364 if (adev->in_suspend && !adev->in_runpm)
2367 r = pm_runtime_get_sync(adev_to_drm(adev)->dev);
2369 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2373 r = amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_MIN_FAN_RPM,
2374 (void *)&min_rpm, &size);
2376 pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
2377 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2382 return sysfs_emit(buf, "%d\n", min_rpm);
2385 static ssize_t amdgpu_hwmon_get_fan1_max(struct device *dev,
2386 struct device_attribute *attr,
2389 struct amdgpu_device *adev = dev_get_drvdata(dev);
2391 u32 size = sizeof(max_rpm);
2394 if (amdgpu_in_reset(adev))
2396 if (adev->in_suspend && !adev->in_runpm)
2399 r = pm_runtime_get_sync(adev_to_drm(adev)->dev);
2401 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2405 r = amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_MAX_FAN_RPM,
2406 (void *)&max_rpm, &size);
2408 pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
2409 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2414 return sysfs_emit(buf, "%d\n", max_rpm);
2417 static ssize_t amdgpu_hwmon_get_fan1_target(struct device *dev,
2418 struct device_attribute *attr,
2421 struct amdgpu_device *adev = dev_get_drvdata(dev);
2425 if (amdgpu_in_reset(adev))
2427 if (adev->in_suspend && !adev->in_runpm)
2430 err = pm_runtime_get_sync(adev_to_drm(adev)->dev);
2432 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2436 if (adev->powerplay.pp_funcs->get_fan_speed_rpm)
2437 err = amdgpu_dpm_get_fan_speed_rpm(adev, &rpm);
2441 pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
2442 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2447 return sprintf(buf, "%i\n", rpm);
2450 static ssize_t amdgpu_hwmon_set_fan1_target(struct device *dev,
2451 struct device_attribute *attr,
2452 const char *buf, size_t count)
2454 struct amdgpu_device *adev = dev_get_drvdata(dev);
2459 if (amdgpu_in_reset(adev))
2461 if (adev->in_suspend && !adev->in_runpm)
2464 err = pm_runtime_get_sync(adev_to_drm(adev)->dev);
2466 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2470 pwm_mode = amdgpu_dpm_get_fan_control_mode(adev);
2472 if (pwm_mode != AMD_FAN_CTRL_MANUAL) {
2473 pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
2474 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2478 err = kstrtou32(buf, 10, &value);
2480 pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
2481 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2485 if (adev->powerplay.pp_funcs->set_fan_speed_rpm)
2486 err = amdgpu_dpm_set_fan_speed_rpm(adev, value);
2490 pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
2491 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2499 static ssize_t amdgpu_hwmon_get_fan1_enable(struct device *dev,
2500 struct device_attribute *attr,
2503 struct amdgpu_device *adev = dev_get_drvdata(dev);
2507 if (amdgpu_in_reset(adev))
2509 if (adev->in_suspend && !adev->in_runpm)
2512 ret = pm_runtime_get_sync(adev_to_drm(adev)->dev);
2514 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2518 if (!adev->powerplay.pp_funcs->get_fan_control_mode) {
2519 pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
2520 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2524 pwm_mode = amdgpu_dpm_get_fan_control_mode(adev);
2526 pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
2527 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2529 return sprintf(buf, "%i\n", pwm_mode == AMD_FAN_CTRL_AUTO ? 0 : 1);
2532 static ssize_t amdgpu_hwmon_set_fan1_enable(struct device *dev,
2533 struct device_attribute *attr,
2537 struct amdgpu_device *adev = dev_get_drvdata(dev);
2542 if (amdgpu_in_reset(adev))
2544 if (adev->in_suspend && !adev->in_runpm)
2547 err = kstrtoint(buf, 10, &value);
2552 pwm_mode = AMD_FAN_CTRL_AUTO;
2553 else if (value == 1)
2554 pwm_mode = AMD_FAN_CTRL_MANUAL;
2558 err = pm_runtime_get_sync(adev_to_drm(adev)->dev);
2560 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2564 if (!adev->powerplay.pp_funcs->set_fan_control_mode) {
2565 pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
2566 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2569 amdgpu_dpm_set_fan_control_mode(adev, pwm_mode);
2571 pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
2572 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2577 static ssize_t amdgpu_hwmon_show_vddgfx(struct device *dev,
2578 struct device_attribute *attr,
2581 struct amdgpu_device *adev = dev_get_drvdata(dev);
2583 int r, size = sizeof(vddgfx);
2585 if (amdgpu_in_reset(adev))
2587 if (adev->in_suspend && !adev->in_runpm)
2590 r = pm_runtime_get_sync(adev_to_drm(adev)->dev);
2592 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2596 /* get the voltage */
2597 r = amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_VDDGFX,
2598 (void *)&vddgfx, &size);
2600 pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
2601 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2606 return sysfs_emit(buf, "%d\n", vddgfx);
2609 static ssize_t amdgpu_hwmon_show_vddgfx_label(struct device *dev,
2610 struct device_attribute *attr,
2613 return sysfs_emit(buf, "vddgfx\n");
2616 static ssize_t amdgpu_hwmon_show_vddnb(struct device *dev,
2617 struct device_attribute *attr,
2620 struct amdgpu_device *adev = dev_get_drvdata(dev);
2622 int r, size = sizeof(vddnb);
2624 if (amdgpu_in_reset(adev))
2626 if (adev->in_suspend && !adev->in_runpm)
2629 /* only APUs have vddnb */
2630 if (!(adev->flags & AMD_IS_APU))
2633 r = pm_runtime_get_sync(adev_to_drm(adev)->dev);
2635 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2639 /* get the voltage */
2640 r = amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_VDDNB,
2641 (void *)&vddnb, &size);
2643 pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
2644 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2649 return sysfs_emit(buf, "%d\n", vddnb);
2652 static ssize_t amdgpu_hwmon_show_vddnb_label(struct device *dev,
2653 struct device_attribute *attr,
2656 return sysfs_emit(buf, "vddnb\n");
2659 static ssize_t amdgpu_hwmon_show_power_avg(struct device *dev,
2660 struct device_attribute *attr,
2663 struct amdgpu_device *adev = dev_get_drvdata(dev);
2665 int r, size = sizeof(u32);
2668 if (amdgpu_in_reset(adev))
2670 if (adev->in_suspend && !adev->in_runpm)
2673 r = pm_runtime_get_sync(adev_to_drm(adev)->dev);
2675 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2679 /* get the voltage */
2680 r = amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GPU_POWER,
2681 (void *)&query, &size);
2683 pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
2684 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2689 /* convert to microwatts */
2690 uw = (query >> 8) * 1000000 + (query & 0xff) * 1000;
2692 return sysfs_emit(buf, "%u\n", uw);
2695 static ssize_t amdgpu_hwmon_show_power_cap_min(struct device *dev,
2696 struct device_attribute *attr,
2699 return sprintf(buf, "%i\n", 0);
2702 static ssize_t amdgpu_hwmon_show_power_cap_max(struct device *dev,
2703 struct device_attribute *attr,
2706 struct amdgpu_device *adev = dev_get_drvdata(dev);
2707 const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
2708 int limit_type = to_sensor_dev_attr(attr)->index;
2709 uint32_t limit = limit_type << 24;
2710 uint32_t max_limit = 0;
2714 if (amdgpu_in_reset(adev))
2716 if (adev->in_suspend && !adev->in_runpm)
2719 r = pm_runtime_get_sync(adev_to_drm(adev)->dev);
2721 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2725 if (is_support_sw_smu(adev)) {
2726 smu_get_power_limit(&adev->smu, &limit, SMU_PPT_LIMIT_MAX);
2727 size = snprintf(buf, PAGE_SIZE, "%u\n", limit * 1000000);
2728 } else if (pp_funcs && pp_funcs->get_power_limit) {
2729 pp_funcs->get_power_limit(adev->powerplay.pp_handle,
2730 &limit, &max_limit, true);
2731 size = snprintf(buf, PAGE_SIZE, "%u\n", max_limit * 1000000);
2733 size = snprintf(buf, PAGE_SIZE, "\n");
2736 pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
2737 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2742 static ssize_t amdgpu_hwmon_show_power_cap(struct device *dev,
2743 struct device_attribute *attr,
2746 struct amdgpu_device *adev = dev_get_drvdata(dev);
2747 const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
2748 int limit_type = to_sensor_dev_attr(attr)->index;
2749 uint32_t limit = limit_type << 24;
2753 if (amdgpu_in_reset(adev))
2755 if (adev->in_suspend && !adev->in_runpm)
2758 r = pm_runtime_get_sync(adev_to_drm(adev)->dev);
2760 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2764 if (is_support_sw_smu(adev)) {
2765 smu_get_power_limit(&adev->smu, &limit, SMU_PPT_LIMIT_CURRENT);
2766 size = snprintf(buf, PAGE_SIZE, "%u\n", limit * 1000000);
2767 } else if (pp_funcs && pp_funcs->get_power_limit) {
2768 pp_funcs->get_power_limit(adev->powerplay.pp_handle,
2769 &limit, NULL, false);
2770 size = snprintf(buf, PAGE_SIZE, "%u\n", limit * 1000000);
2772 size = snprintf(buf, PAGE_SIZE, "\n");
2775 pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
2776 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2781 static ssize_t amdgpu_hwmon_show_power_cap_default(struct device *dev,
2782 struct device_attribute *attr,
2785 struct amdgpu_device *adev = dev_get_drvdata(dev);
2786 const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
2787 int limit_type = to_sensor_dev_attr(attr)->index;
2788 uint32_t limit = limit_type << 24;
2792 if (amdgpu_in_reset(adev))
2794 if (adev->in_suspend && !adev->in_runpm)
2797 r = pm_runtime_get_sync(adev_to_drm(adev)->dev);
2799 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2803 if (is_support_sw_smu(adev)) {
2804 smu_get_power_limit(&adev->smu, &limit, SMU_PPT_LIMIT_DEFAULT);
2805 size = snprintf(buf, PAGE_SIZE, "%u\n", limit * 1000000);
2806 } else if (pp_funcs && pp_funcs->get_power_limit) {
2807 pp_funcs->get_power_limit(adev->powerplay.pp_handle,
2808 &limit, NULL, true);
2809 size = snprintf(buf, PAGE_SIZE, "%u\n", limit * 1000000);
2811 size = snprintf(buf, PAGE_SIZE, "\n");
2814 pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
2815 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2819 static ssize_t amdgpu_hwmon_show_power_label(struct device *dev,
2820 struct device_attribute *attr,
2823 int limit_type = to_sensor_dev_attr(attr)->index;
2825 return sysfs_emit(buf, "%s\n",
2826 limit_type == SMU_FAST_PPT_LIMIT ? "fastPPT" : "slowPPT");
2829 static ssize_t amdgpu_hwmon_set_power_cap(struct device *dev,
2830 struct device_attribute *attr,
2834 struct amdgpu_device *adev = dev_get_drvdata(dev);
2835 const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
2836 int limit_type = to_sensor_dev_attr(attr)->index;
2840 if (amdgpu_in_reset(adev))
2842 if (adev->in_suspend && !adev->in_runpm)
2845 if (amdgpu_sriov_vf(adev))
2848 err = kstrtou32(buf, 10, &value);
2852 value = value / 1000000; /* convert to Watt */
2853 value |= limit_type << 24;
2855 err = pm_runtime_get_sync(adev_to_drm(adev)->dev);
2857 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2861 if (pp_funcs && pp_funcs->set_power_limit)
2862 err = pp_funcs->set_power_limit(adev->powerplay.pp_handle, value);
2866 pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
2867 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2875 static ssize_t amdgpu_hwmon_show_sclk(struct device *dev,
2876 struct device_attribute *attr,
2879 struct amdgpu_device *adev = dev_get_drvdata(dev);
2881 int r, size = sizeof(sclk);
2883 if (amdgpu_in_reset(adev))
2885 if (adev->in_suspend && !adev->in_runpm)
2888 r = pm_runtime_get_sync(adev_to_drm(adev)->dev);
2890 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2895 r = amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GFX_SCLK,
2896 (void *)&sclk, &size);
2898 pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
2899 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2904 return sysfs_emit(buf, "%u\n", sclk * 10 * 1000);
2907 static ssize_t amdgpu_hwmon_show_sclk_label(struct device *dev,
2908 struct device_attribute *attr,
2911 return sysfs_emit(buf, "sclk\n");
2914 static ssize_t amdgpu_hwmon_show_mclk(struct device *dev,
2915 struct device_attribute *attr,
2918 struct amdgpu_device *adev = dev_get_drvdata(dev);
2920 int r, size = sizeof(mclk);
2922 if (amdgpu_in_reset(adev))
2924 if (adev->in_suspend && !adev->in_runpm)
2927 r = pm_runtime_get_sync(adev_to_drm(adev)->dev);
2929 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2934 r = amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GFX_MCLK,
2935 (void *)&mclk, &size);
2937 pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
2938 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2943 return sysfs_emit(buf, "%u\n", mclk * 10 * 1000);
2946 static ssize_t amdgpu_hwmon_show_mclk_label(struct device *dev,
2947 struct device_attribute *attr,
2950 return sysfs_emit(buf, "mclk\n");
2956 * The amdgpu driver exposes the following sensor interfaces:
2958 * - GPU temperature (via the on-die sensor)
2962 * - Northbridge voltage (APUs only)
2968 * - GPU gfx/compute engine clock
2970 * - GPU memory clock (dGPU only)
2972 * hwmon interfaces for GPU temperature:
2974 * - temp[1-3]_input: the on die GPU temperature in millidegrees Celsius
2975 * - temp2_input and temp3_input are supported on SOC15 dGPUs only
2977 * - temp[1-3]_label: temperature channel label
2978 * - temp2_label and temp3_label are supported on SOC15 dGPUs only
2980 * - temp[1-3]_crit: temperature critical max value in millidegrees Celsius
2981 * - temp2_crit and temp3_crit are supported on SOC15 dGPUs only
2983 * - temp[1-3]_crit_hyst: temperature hysteresis for critical limit in millidegrees Celsius
2984 * - temp2_crit_hyst and temp3_crit_hyst are supported on SOC15 dGPUs only
2986 * - temp[1-3]_emergency: temperature emergency max value(asic shutdown) in millidegrees Celsius
2987 * - these are supported on SOC15 dGPUs only
2989 * hwmon interfaces for GPU voltage:
2991 * - in0_input: the voltage on the GPU in millivolts
2993 * - in1_input: the voltage on the Northbridge in millivolts
2995 * hwmon interfaces for GPU power:
2997 * - power1_average: average power used by the GPU in microWatts
2999 * - power1_cap_min: minimum cap supported in microWatts
3001 * - power1_cap_max: maximum cap supported in microWatts
3003 * - power1_cap: selected power cap in microWatts
3005 * hwmon interfaces for GPU fan:
3007 * - pwm1: pulse width modulation fan level (0-255)
3009 * - pwm1_enable: pulse width modulation fan control method (0: no fan speed control, 1: manual fan speed control using pwm interface, 2: automatic fan speed control)
3011 * - pwm1_min: pulse width modulation fan control minimum level (0)
3013 * - pwm1_max: pulse width modulation fan control maximum level (255)
3015 * - fan1_min: a minimum value Unit: revolution/min (RPM)
3017 * - fan1_max: a maximum value Unit: revolution/max (RPM)
3019 * - fan1_input: fan speed in RPM
3021 * - fan[1-\*]_target: Desired fan speed Unit: revolution/min (RPM)
3023 * - fan[1-\*]_enable: Enable or disable the sensors.1: Enable 0: Disable
3025 * hwmon interfaces for GPU clocks:
3027 * - freq1_input: the gfx/compute clock in hertz
3029 * - freq2_input: the memory clock in hertz
3031 * You can use hwmon tools like sensors to view this information on your system.
3035 static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, amdgpu_hwmon_show_temp, NULL, PP_TEMP_EDGE);
3036 static SENSOR_DEVICE_ATTR(temp1_crit, S_IRUGO, amdgpu_hwmon_show_temp_thresh, NULL, 0);
3037 static SENSOR_DEVICE_ATTR(temp1_crit_hyst, S_IRUGO, amdgpu_hwmon_show_temp_thresh, NULL, 1);
3038 static SENSOR_DEVICE_ATTR(temp1_emergency, S_IRUGO, amdgpu_hwmon_show_temp_emergency, NULL, PP_TEMP_EDGE);
3039 static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, amdgpu_hwmon_show_temp, NULL, PP_TEMP_JUNCTION);
3040 static SENSOR_DEVICE_ATTR(temp2_crit, S_IRUGO, amdgpu_hwmon_show_hotspot_temp_thresh, NULL, 0);
3041 static SENSOR_DEVICE_ATTR(temp2_crit_hyst, S_IRUGO, amdgpu_hwmon_show_hotspot_temp_thresh, NULL, 1);
3042 static SENSOR_DEVICE_ATTR(temp2_emergency, S_IRUGO, amdgpu_hwmon_show_temp_emergency, NULL, PP_TEMP_JUNCTION);
3043 static SENSOR_DEVICE_ATTR(temp3_input, S_IRUGO, amdgpu_hwmon_show_temp, NULL, PP_TEMP_MEM);
3044 static SENSOR_DEVICE_ATTR(temp3_crit, S_IRUGO, amdgpu_hwmon_show_mem_temp_thresh, NULL, 0);
3045 static SENSOR_DEVICE_ATTR(temp3_crit_hyst, S_IRUGO, amdgpu_hwmon_show_mem_temp_thresh, NULL, 1);
3046 static SENSOR_DEVICE_ATTR(temp3_emergency, S_IRUGO, amdgpu_hwmon_show_temp_emergency, NULL, PP_TEMP_MEM);
3047 static SENSOR_DEVICE_ATTR(temp1_label, S_IRUGO, amdgpu_hwmon_show_temp_label, NULL, PP_TEMP_EDGE);
3048 static SENSOR_DEVICE_ATTR(temp2_label, S_IRUGO, amdgpu_hwmon_show_temp_label, NULL, PP_TEMP_JUNCTION);
3049 static SENSOR_DEVICE_ATTR(temp3_label, S_IRUGO, amdgpu_hwmon_show_temp_label, NULL, PP_TEMP_MEM);
3050 static SENSOR_DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, amdgpu_hwmon_get_pwm1, amdgpu_hwmon_set_pwm1, 0);
3051 static SENSOR_DEVICE_ATTR(pwm1_enable, S_IRUGO | S_IWUSR, amdgpu_hwmon_get_pwm1_enable, amdgpu_hwmon_set_pwm1_enable, 0);
3052 static SENSOR_DEVICE_ATTR(pwm1_min, S_IRUGO, amdgpu_hwmon_get_pwm1_min, NULL, 0);
3053 static SENSOR_DEVICE_ATTR(pwm1_max, S_IRUGO, amdgpu_hwmon_get_pwm1_max, NULL, 0);
3054 static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, amdgpu_hwmon_get_fan1_input, NULL, 0);
3055 static SENSOR_DEVICE_ATTR(fan1_min, S_IRUGO, amdgpu_hwmon_get_fan1_min, NULL, 0);
3056 static SENSOR_DEVICE_ATTR(fan1_max, S_IRUGO, amdgpu_hwmon_get_fan1_max, NULL, 0);
3057 static SENSOR_DEVICE_ATTR(fan1_target, S_IRUGO | S_IWUSR, amdgpu_hwmon_get_fan1_target, amdgpu_hwmon_set_fan1_target, 0);
3058 static SENSOR_DEVICE_ATTR(fan1_enable, S_IRUGO | S_IWUSR, amdgpu_hwmon_get_fan1_enable, amdgpu_hwmon_set_fan1_enable, 0);
3059 static SENSOR_DEVICE_ATTR(in0_input, S_IRUGO, amdgpu_hwmon_show_vddgfx, NULL, 0);
3060 static SENSOR_DEVICE_ATTR(in0_label, S_IRUGO, amdgpu_hwmon_show_vddgfx_label, NULL, 0);
3061 static SENSOR_DEVICE_ATTR(in1_input, S_IRUGO, amdgpu_hwmon_show_vddnb, NULL, 0);
3062 static SENSOR_DEVICE_ATTR(in1_label, S_IRUGO, amdgpu_hwmon_show_vddnb_label, NULL, 0);
3063 static SENSOR_DEVICE_ATTR(power1_average, S_IRUGO, amdgpu_hwmon_show_power_avg, NULL, 0);
3064 static SENSOR_DEVICE_ATTR(power1_cap_max, S_IRUGO, amdgpu_hwmon_show_power_cap_max, NULL, 0);
3065 static SENSOR_DEVICE_ATTR(power1_cap_min, S_IRUGO, amdgpu_hwmon_show_power_cap_min, NULL, 0);
3066 static SENSOR_DEVICE_ATTR(power1_cap, S_IRUGO | S_IWUSR, amdgpu_hwmon_show_power_cap, amdgpu_hwmon_set_power_cap, 0);
3067 static SENSOR_DEVICE_ATTR(power1_cap_default, S_IRUGO, amdgpu_hwmon_show_power_cap_default, NULL, 0);
3068 static SENSOR_DEVICE_ATTR(power1_label, S_IRUGO, amdgpu_hwmon_show_power_label, NULL, 0);
3069 static SENSOR_DEVICE_ATTR(power2_average, S_IRUGO, amdgpu_hwmon_show_power_avg, NULL, 1);
3070 static SENSOR_DEVICE_ATTR(power2_cap_max, S_IRUGO, amdgpu_hwmon_show_power_cap_max, NULL, 1);
3071 static SENSOR_DEVICE_ATTR(power2_cap_min, S_IRUGO, amdgpu_hwmon_show_power_cap_min, NULL, 1);
3072 static SENSOR_DEVICE_ATTR(power2_cap, S_IRUGO | S_IWUSR, amdgpu_hwmon_show_power_cap, amdgpu_hwmon_set_power_cap, 1);
3073 static SENSOR_DEVICE_ATTR(power2_cap_default, S_IRUGO, amdgpu_hwmon_show_power_cap_default, NULL, 1);
3074 static SENSOR_DEVICE_ATTR(power2_label, S_IRUGO, amdgpu_hwmon_show_power_label, NULL, 1);
3075 static SENSOR_DEVICE_ATTR(freq1_input, S_IRUGO, amdgpu_hwmon_show_sclk, NULL, 0);
3076 static SENSOR_DEVICE_ATTR(freq1_label, S_IRUGO, amdgpu_hwmon_show_sclk_label, NULL, 0);
3077 static SENSOR_DEVICE_ATTR(freq2_input, S_IRUGO, amdgpu_hwmon_show_mclk, NULL, 0);
3078 static SENSOR_DEVICE_ATTR(freq2_label, S_IRUGO, amdgpu_hwmon_show_mclk_label, NULL, 0);
3080 static struct attribute *hwmon_attributes[] = {
3081 &sensor_dev_attr_temp1_input.dev_attr.attr,
3082 &sensor_dev_attr_temp1_crit.dev_attr.attr,
3083 &sensor_dev_attr_temp1_crit_hyst.dev_attr.attr,
3084 &sensor_dev_attr_temp2_input.dev_attr.attr,
3085 &sensor_dev_attr_temp2_crit.dev_attr.attr,
3086 &sensor_dev_attr_temp2_crit_hyst.dev_attr.attr,
3087 &sensor_dev_attr_temp3_input.dev_attr.attr,
3088 &sensor_dev_attr_temp3_crit.dev_attr.attr,
3089 &sensor_dev_attr_temp3_crit_hyst.dev_attr.attr,
3090 &sensor_dev_attr_temp1_emergency.dev_attr.attr,
3091 &sensor_dev_attr_temp2_emergency.dev_attr.attr,
3092 &sensor_dev_attr_temp3_emergency.dev_attr.attr,
3093 &sensor_dev_attr_temp1_label.dev_attr.attr,
3094 &sensor_dev_attr_temp2_label.dev_attr.attr,
3095 &sensor_dev_attr_temp3_label.dev_attr.attr,
3096 &sensor_dev_attr_pwm1.dev_attr.attr,
3097 &sensor_dev_attr_pwm1_enable.dev_attr.attr,
3098 &sensor_dev_attr_pwm1_min.dev_attr.attr,
3099 &sensor_dev_attr_pwm1_max.dev_attr.attr,
3100 &sensor_dev_attr_fan1_input.dev_attr.attr,
3101 &sensor_dev_attr_fan1_min.dev_attr.attr,
3102 &sensor_dev_attr_fan1_max.dev_attr.attr,
3103 &sensor_dev_attr_fan1_target.dev_attr.attr,
3104 &sensor_dev_attr_fan1_enable.dev_attr.attr,
3105 &sensor_dev_attr_in0_input.dev_attr.attr,
3106 &sensor_dev_attr_in0_label.dev_attr.attr,
3107 &sensor_dev_attr_in1_input.dev_attr.attr,
3108 &sensor_dev_attr_in1_label.dev_attr.attr,
3109 &sensor_dev_attr_power1_average.dev_attr.attr,
3110 &sensor_dev_attr_power1_cap_max.dev_attr.attr,
3111 &sensor_dev_attr_power1_cap_min.dev_attr.attr,
3112 &sensor_dev_attr_power1_cap.dev_attr.attr,
3113 &sensor_dev_attr_power1_cap_default.dev_attr.attr,
3114 &sensor_dev_attr_power1_label.dev_attr.attr,
3115 &sensor_dev_attr_power2_average.dev_attr.attr,
3116 &sensor_dev_attr_power2_cap_max.dev_attr.attr,
3117 &sensor_dev_attr_power2_cap_min.dev_attr.attr,
3118 &sensor_dev_attr_power2_cap.dev_attr.attr,
3119 &sensor_dev_attr_power2_cap_default.dev_attr.attr,
3120 &sensor_dev_attr_power2_label.dev_attr.attr,
3121 &sensor_dev_attr_freq1_input.dev_attr.attr,
3122 &sensor_dev_attr_freq1_label.dev_attr.attr,
3123 &sensor_dev_attr_freq2_input.dev_attr.attr,
3124 &sensor_dev_attr_freq2_label.dev_attr.attr,
3128 static umode_t hwmon_attributes_visible(struct kobject *kobj,
3129 struct attribute *attr, int index)
3131 struct device *dev = kobj_to_dev(kobj);
3132 struct amdgpu_device *adev = dev_get_drvdata(dev);
3133 umode_t effective_mode = attr->mode;
3135 /* under multi-vf mode, the hwmon attributes are all not supported */
3136 if (amdgpu_sriov_vf(adev) && !amdgpu_sriov_is_pp_one_vf(adev))
3139 /* there is no fan under pp one vf mode */
3140 if (amdgpu_sriov_is_pp_one_vf(adev) &&
3141 (attr == &sensor_dev_attr_pwm1.dev_attr.attr ||
3142 attr == &sensor_dev_attr_pwm1_enable.dev_attr.attr ||
3143 attr == &sensor_dev_attr_pwm1_max.dev_attr.attr ||
3144 attr == &sensor_dev_attr_pwm1_min.dev_attr.attr ||
3145 attr == &sensor_dev_attr_fan1_input.dev_attr.attr ||
3146 attr == &sensor_dev_attr_fan1_min.dev_attr.attr ||
3147 attr == &sensor_dev_attr_fan1_max.dev_attr.attr ||
3148 attr == &sensor_dev_attr_fan1_target.dev_attr.attr ||
3149 attr == &sensor_dev_attr_fan1_enable.dev_attr.attr))
3152 /* Skip fan attributes if fan is not present */
3153 if (adev->pm.no_fan && (attr == &sensor_dev_attr_pwm1.dev_attr.attr ||
3154 attr == &sensor_dev_attr_pwm1_enable.dev_attr.attr ||
3155 attr == &sensor_dev_attr_pwm1_max.dev_attr.attr ||
3156 attr == &sensor_dev_attr_pwm1_min.dev_attr.attr ||
3157 attr == &sensor_dev_attr_fan1_input.dev_attr.attr ||
3158 attr == &sensor_dev_attr_fan1_min.dev_attr.attr ||
3159 attr == &sensor_dev_attr_fan1_max.dev_attr.attr ||
3160 attr == &sensor_dev_attr_fan1_target.dev_attr.attr ||
3161 attr == &sensor_dev_attr_fan1_enable.dev_attr.attr))
3164 /* Skip fan attributes on APU */
3165 if ((adev->flags & AMD_IS_APU) &&
3166 (attr == &sensor_dev_attr_pwm1.dev_attr.attr ||
3167 attr == &sensor_dev_attr_pwm1_enable.dev_attr.attr ||
3168 attr == &sensor_dev_attr_pwm1_max.dev_attr.attr ||
3169 attr == &sensor_dev_attr_pwm1_min.dev_attr.attr ||
3170 attr == &sensor_dev_attr_fan1_input.dev_attr.attr ||
3171 attr == &sensor_dev_attr_fan1_min.dev_attr.attr ||
3172 attr == &sensor_dev_attr_fan1_max.dev_attr.attr ||
3173 attr == &sensor_dev_attr_fan1_target.dev_attr.attr ||
3174 attr == &sensor_dev_attr_fan1_enable.dev_attr.attr))
3177 /* Skip crit temp on APU */
3178 if ((adev->flags & AMD_IS_APU) && (adev->family >= AMDGPU_FAMILY_CZ) &&
3179 (attr == &sensor_dev_attr_temp1_crit.dev_attr.attr ||
3180 attr == &sensor_dev_attr_temp1_crit_hyst.dev_attr.attr))
3183 /* Skip limit attributes if DPM is not enabled */
3184 if (!adev->pm.dpm_enabled &&
3185 (attr == &sensor_dev_attr_temp1_crit.dev_attr.attr ||
3186 attr == &sensor_dev_attr_temp1_crit_hyst.dev_attr.attr ||
3187 attr == &sensor_dev_attr_pwm1.dev_attr.attr ||
3188 attr == &sensor_dev_attr_pwm1_enable.dev_attr.attr ||
3189 attr == &sensor_dev_attr_pwm1_max.dev_attr.attr ||
3190 attr == &sensor_dev_attr_pwm1_min.dev_attr.attr ||
3191 attr == &sensor_dev_attr_fan1_input.dev_attr.attr ||
3192 attr == &sensor_dev_attr_fan1_min.dev_attr.attr ||
3193 attr == &sensor_dev_attr_fan1_max.dev_attr.attr ||
3194 attr == &sensor_dev_attr_fan1_target.dev_attr.attr ||
3195 attr == &sensor_dev_attr_fan1_enable.dev_attr.attr))
3198 if (!is_support_sw_smu(adev)) {
3199 /* mask fan attributes if we have no bindings for this asic to expose */
3200 if ((!adev->powerplay.pp_funcs->get_fan_speed_percent &&
3201 attr == &sensor_dev_attr_pwm1.dev_attr.attr) || /* can't query fan */
3202 (!adev->powerplay.pp_funcs->get_fan_control_mode &&
3203 attr == &sensor_dev_attr_pwm1_enable.dev_attr.attr)) /* can't query state */
3204 effective_mode &= ~S_IRUGO;
3206 if ((!adev->powerplay.pp_funcs->set_fan_speed_percent &&
3207 attr == &sensor_dev_attr_pwm1.dev_attr.attr) || /* can't manage fan */
3208 (!adev->powerplay.pp_funcs->set_fan_control_mode &&
3209 attr == &sensor_dev_attr_pwm1_enable.dev_attr.attr)) /* can't manage state */
3210 effective_mode &= ~S_IWUSR;
3213 if (((adev->family == AMDGPU_FAMILY_SI) ||
3214 ((adev->flags & AMD_IS_APU) &&
3215 (adev->asic_type != CHIP_VANGOGH))) && /* not implemented yet */
3216 (attr == &sensor_dev_attr_power1_cap_max.dev_attr.attr ||
3217 attr == &sensor_dev_attr_power1_cap_min.dev_attr.attr||
3218 attr == &sensor_dev_attr_power1_cap.dev_attr.attr ||
3219 attr == &sensor_dev_attr_power1_cap_default.dev_attr.attr))
3222 if (((adev->family == AMDGPU_FAMILY_SI) ||
3223 ((adev->flags & AMD_IS_APU) &&
3224 (adev->asic_type < CHIP_RENOIR))) && /* not implemented yet */
3225 (attr == &sensor_dev_attr_power1_average.dev_attr.attr))
3228 if (!is_support_sw_smu(adev)) {
3229 /* hide max/min values if we can't both query and manage the fan */
3230 if ((!adev->powerplay.pp_funcs->set_fan_speed_percent &&
3231 !adev->powerplay.pp_funcs->get_fan_speed_percent) &&
3232 (!adev->powerplay.pp_funcs->set_fan_speed_rpm &&
3233 !adev->powerplay.pp_funcs->get_fan_speed_rpm) &&
3234 (attr == &sensor_dev_attr_pwm1_max.dev_attr.attr ||
3235 attr == &sensor_dev_attr_pwm1_min.dev_attr.attr))
3238 if ((!adev->powerplay.pp_funcs->set_fan_speed_rpm &&
3239 !adev->powerplay.pp_funcs->get_fan_speed_rpm) &&
3240 (attr == &sensor_dev_attr_fan1_max.dev_attr.attr ||
3241 attr == &sensor_dev_attr_fan1_min.dev_attr.attr))
3245 if ((adev->family == AMDGPU_FAMILY_SI || /* not implemented yet */
3246 adev->family == AMDGPU_FAMILY_KV) && /* not implemented yet */
3247 (attr == &sensor_dev_attr_in0_input.dev_attr.attr ||
3248 attr == &sensor_dev_attr_in0_label.dev_attr.attr))
3251 /* only APUs have vddnb */
3252 if (!(adev->flags & AMD_IS_APU) &&
3253 (attr == &sensor_dev_attr_in1_input.dev_attr.attr ||
3254 attr == &sensor_dev_attr_in1_label.dev_attr.attr))
3257 /* no mclk on APUs */
3258 if ((adev->flags & AMD_IS_APU) &&
3259 (attr == &sensor_dev_attr_freq2_input.dev_attr.attr ||
3260 attr == &sensor_dev_attr_freq2_label.dev_attr.attr))
3263 /* only SOC15 dGPUs support hotspot and mem temperatures */
3264 if (((adev->flags & AMD_IS_APU) ||
3265 adev->asic_type < CHIP_VEGA10) &&
3266 (attr == &sensor_dev_attr_temp2_crit.dev_attr.attr ||
3267 attr == &sensor_dev_attr_temp2_crit_hyst.dev_attr.attr ||
3268 attr == &sensor_dev_attr_temp3_crit.dev_attr.attr ||
3269 attr == &sensor_dev_attr_temp3_crit_hyst.dev_attr.attr ||
3270 attr == &sensor_dev_attr_temp1_emergency.dev_attr.attr ||
3271 attr == &sensor_dev_attr_temp2_emergency.dev_attr.attr ||
3272 attr == &sensor_dev_attr_temp3_emergency.dev_attr.attr ||
3273 attr == &sensor_dev_attr_temp2_input.dev_attr.attr ||
3274 attr == &sensor_dev_attr_temp3_input.dev_attr.attr ||
3275 attr == &sensor_dev_attr_temp2_label.dev_attr.attr ||
3276 attr == &sensor_dev_attr_temp3_label.dev_attr.attr))
3279 /* only Vangogh has fast PPT limit and power labels */
3280 if (!(adev->asic_type == CHIP_VANGOGH) &&
3281 (attr == &sensor_dev_attr_power2_average.dev_attr.attr ||
3282 attr == &sensor_dev_attr_power2_cap_max.dev_attr.attr ||
3283 attr == &sensor_dev_attr_power2_cap_min.dev_attr.attr ||
3284 attr == &sensor_dev_attr_power2_cap.dev_attr.attr ||
3285 attr == &sensor_dev_attr_power2_cap_default.dev_attr.attr ||
3286 attr == &sensor_dev_attr_power2_label.dev_attr.attr ||
3287 attr == &sensor_dev_attr_power1_label.dev_attr.attr))
3290 return effective_mode;
3293 static const struct attribute_group hwmon_attrgroup = {
3294 .attrs = hwmon_attributes,
3295 .is_visible = hwmon_attributes_visible,
3298 static const struct attribute_group *hwmon_groups[] = {
3303 int amdgpu_pm_sysfs_init(struct amdgpu_device *adev)
3308 if (adev->pm.sysfs_initialized)
3311 if (adev->pm.dpm_enabled == 0)
3314 INIT_LIST_HEAD(&adev->pm.pm_attr_list);
3316 adev->pm.int_hwmon_dev = hwmon_device_register_with_groups(adev->dev,
3319 if (IS_ERR(adev->pm.int_hwmon_dev)) {
3320 ret = PTR_ERR(adev->pm.int_hwmon_dev);
3322 "Unable to register hwmon device: %d\n", ret);
3326 switch (amdgpu_virt_get_sriov_vf_mode(adev)) {
3327 case SRIOV_VF_MODE_ONE_VF:
3328 mask = ATTR_FLAG_ONEVF;
3330 case SRIOV_VF_MODE_MULTI_VF:
3333 case SRIOV_VF_MODE_BARE_METAL:
3335 mask = ATTR_FLAG_MASK_ALL;
3339 ret = amdgpu_device_attr_create_groups(adev,
3340 amdgpu_device_attrs,
3341 ARRAY_SIZE(amdgpu_device_attrs),
3343 &adev->pm.pm_attr_list);
3347 adev->pm.sysfs_initialized = true;
3352 void amdgpu_pm_sysfs_fini(struct amdgpu_device *adev)
3354 if (adev->pm.dpm_enabled == 0)
3357 if (adev->pm.int_hwmon_dev)
3358 hwmon_device_unregister(adev->pm.int_hwmon_dev);
3360 amdgpu_device_attr_remove_groups(adev, &adev->pm.pm_attr_list);
3366 #if defined(CONFIG_DEBUG_FS)
3368 static void amdgpu_debugfs_prints_cpu_info(struct seq_file *m,
3369 struct amdgpu_device *adev) {
3374 if (is_support_cclk_dpm(adev)) {
3375 p_val = kcalloc(adev->smu.cpu_core_num, sizeof(uint16_t),
3378 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_CPU_CLK,
3379 (void *)p_val, &size)) {
3380 for (i = 0; i < adev->smu.cpu_core_num; i++)
3381 seq_printf(m, "\t%u MHz (CPU%d)\n",
3389 static int amdgpu_debugfs_pm_info_pp(struct seq_file *m, struct amdgpu_device *adev)
3392 uint64_t value64 = 0;
3397 size = sizeof(value);
3398 seq_printf(m, "GFX Clocks and Power:\n");
3400 amdgpu_debugfs_prints_cpu_info(m, adev);
3402 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GFX_MCLK, (void *)&value, &size))
3403 seq_printf(m, "\t%u MHz (MCLK)\n", value/100);
3404 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GFX_SCLK, (void *)&value, &size))
3405 seq_printf(m, "\t%u MHz (SCLK)\n", value/100);
3406 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_STABLE_PSTATE_SCLK, (void *)&value, &size))
3407 seq_printf(m, "\t%u MHz (PSTATE_SCLK)\n", value/100);
3408 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_STABLE_PSTATE_MCLK, (void *)&value, &size))
3409 seq_printf(m, "\t%u MHz (PSTATE_MCLK)\n", value/100);
3410 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_VDDGFX, (void *)&value, &size))
3411 seq_printf(m, "\t%u mV (VDDGFX)\n", value);
3412 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_VDDNB, (void *)&value, &size))
3413 seq_printf(m, "\t%u mV (VDDNB)\n", value);
3414 size = sizeof(uint32_t);
3415 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GPU_POWER, (void *)&query, &size))
3416 seq_printf(m, "\t%u.%u W (average GPU)\n", query >> 8, query & 0xff);
3417 size = sizeof(value);
3418 seq_printf(m, "\n");
3421 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GPU_TEMP, (void *)&value, &size))
3422 seq_printf(m, "GPU Temperature: %u C\n", value/1000);
3425 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GPU_LOAD, (void *)&value, &size))
3426 seq_printf(m, "GPU Load: %u %%\n", value);
3428 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_MEM_LOAD, (void *)&value, &size))
3429 seq_printf(m, "MEM Load: %u %%\n", value);
3431 seq_printf(m, "\n");
3433 /* SMC feature mask */
3434 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_ENABLED_SMC_FEATURES_MASK, (void *)&value64, &size))
3435 seq_printf(m, "SMC Feature Mask: 0x%016llx\n", value64);
3437 if (adev->asic_type > CHIP_VEGA20) {
3439 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_VCN_POWER_STATE, (void *)&value, &size)) {
3441 seq_printf(m, "VCN: Disabled\n");
3443 seq_printf(m, "VCN: Enabled\n");
3444 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_UVD_DCLK, (void *)&value, &size))
3445 seq_printf(m, "\t%u MHz (DCLK)\n", value/100);
3446 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_UVD_VCLK, (void *)&value, &size))
3447 seq_printf(m, "\t%u MHz (VCLK)\n", value/100);
3450 seq_printf(m, "\n");
3453 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_UVD_POWER, (void *)&value, &size)) {
3455 seq_printf(m, "UVD: Disabled\n");
3457 seq_printf(m, "UVD: Enabled\n");
3458 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_UVD_DCLK, (void *)&value, &size))
3459 seq_printf(m, "\t%u MHz (DCLK)\n", value/100);
3460 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_UVD_VCLK, (void *)&value, &size))
3461 seq_printf(m, "\t%u MHz (VCLK)\n", value/100);
3464 seq_printf(m, "\n");
3467 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_VCE_POWER, (void *)&value, &size)) {
3469 seq_printf(m, "VCE: Disabled\n");
3471 seq_printf(m, "VCE: Enabled\n");
3472 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_VCE_ECCLK, (void *)&value, &size))
3473 seq_printf(m, "\t%u MHz (ECCLK)\n", value/100);
3481 static void amdgpu_parse_cg_state(struct seq_file *m, u32 flags)
3485 for (i = 0; clocks[i].flag; i++)
3486 seq_printf(m, "\t%s: %s\n", clocks[i].name,
3487 (flags & clocks[i].flag) ? "On" : "Off");
3490 static int amdgpu_debugfs_pm_info_show(struct seq_file *m, void *unused)
3492 struct amdgpu_device *adev = (struct amdgpu_device *)m->private;
3493 struct drm_device *dev = adev_to_drm(adev);
3497 if (amdgpu_in_reset(adev))
3499 if (adev->in_suspend && !adev->in_runpm)
3502 r = pm_runtime_get_sync(dev->dev);
3504 pm_runtime_put_autosuspend(dev->dev);
3508 if (!adev->pm.dpm_enabled) {
3509 seq_printf(m, "dpm not enabled\n");
3510 pm_runtime_mark_last_busy(dev->dev);
3511 pm_runtime_put_autosuspend(dev->dev);
3515 if (!is_support_sw_smu(adev) &&
3516 adev->powerplay.pp_funcs->debugfs_print_current_performance_level) {
3517 mutex_lock(&adev->pm.mutex);
3518 if (adev->powerplay.pp_funcs->debugfs_print_current_performance_level)
3519 adev->powerplay.pp_funcs->debugfs_print_current_performance_level(adev, m);
3521 seq_printf(m, "Debugfs support not implemented for this asic\n");
3522 mutex_unlock(&adev->pm.mutex);
3525 r = amdgpu_debugfs_pm_info_pp(m, adev);
3530 amdgpu_device_ip_get_clockgating_state(adev, &flags);
3532 seq_printf(m, "Clock Gating Flags Mask: 0x%x\n", flags);
3533 amdgpu_parse_cg_state(m, flags);
3534 seq_printf(m, "\n");
3537 pm_runtime_mark_last_busy(dev->dev);
3538 pm_runtime_put_autosuspend(dev->dev);
3543 DEFINE_SHOW_ATTRIBUTE(amdgpu_debugfs_pm_info);
3546 * amdgpu_pm_priv_buffer_read - Read memory region allocated to FW
3548 * Reads debug memory region allocated to PMFW
3550 static ssize_t amdgpu_pm_prv_buffer_read(struct file *f, char __user *buf,
3551 size_t size, loff_t *pos)
3553 struct amdgpu_device *adev = file_inode(f)->i_private;
3554 const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
3555 void *pp_handle = adev->powerplay.pp_handle;
3556 size_t smu_prv_buf_size;
3559 if (amdgpu_in_reset(adev))
3561 if (adev->in_suspend && !adev->in_runpm)
3564 if (pp_funcs && pp_funcs->get_smu_prv_buf_details)
3565 pp_funcs->get_smu_prv_buf_details(pp_handle, &smu_prv_buf,
3570 if (!smu_prv_buf || !smu_prv_buf_size)
3573 return simple_read_from_buffer(buf, size, pos, smu_prv_buf,
3577 static const struct file_operations amdgpu_debugfs_pm_prv_buffer_fops = {
3578 .owner = THIS_MODULE,
3579 .open = simple_open,
3580 .read = amdgpu_pm_prv_buffer_read,
3581 .llseek = default_llseek,
3586 void amdgpu_debugfs_pm_init(struct amdgpu_device *adev)
3588 #if defined(CONFIG_DEBUG_FS)
3589 struct drm_minor *minor = adev_to_drm(adev)->primary;
3590 struct dentry *root = minor->debugfs_root;
3592 debugfs_create_file("amdgpu_pm_info", 0444, root, adev,
3593 &amdgpu_debugfs_pm_info_fops);
3595 if (adev->pm.smu_prv_buffer_size > 0)
3596 debugfs_create_file_size("amdgpu_pm_prv_buffer", 0444, root,
3598 &amdgpu_debugfs_pm_prv_buffer_fops,
3599 adev->pm.smu_prv_buffer_size);