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
748 * Reading the file will display:
750 * - minimum and maximum engine clock labeled OD_SCLK
751 * - minimum and maximum core clocks labeled OD_CCLK
753 * - a list of valid ranges for sclk and cclk labeled OD_RANGE
755 * To manually adjust these settings:
757 * - First select manual using power_dpm_force_performance_level
759 * - For clock frequency setting, enter a new value by writing a
760 * string that contains "s/m index clock" to the file. The index
761 * should be 0 if to set minimum clock. And 1 if to set maximum
762 * clock. E.g., "s 0 500" will update minimum sclk to be 500 MHz.
763 * "m 1 800" will update maximum mclk to be 800Mhz. For core
764 * clocks on VanGogh, the string contains "p core index clock".
765 * E.g., "p 2 0 800" would set the minimum core clock on core
768 * For sclk voltage curve, enter the new values by writing a
769 * string that contains "vc point clock voltage" to the file. The
770 * points are indexed by 0, 1 and 2. E.g., "vc 0 300 600" will
771 * update point1 with clock set as 300Mhz and voltage as
772 * 600mV. "vc 2 1000 1000" will update point3 with clock set
773 * as 1000Mhz and voltage 1000mV.
775 * To update the voltage offset applied for gfxclk/voltage calculation,
776 * enter the new value by writing a string that contains "vo offset".
777 * This is supported by Sienna Cichlid, Navy Flounder and Dimgrey Cavefish.
778 * And the offset can be a positive or negative value.
780 * - When you have edited all of the states as needed, write "c" (commit)
781 * to the file to commit your changes
783 * - If you want to reset to the default power levels, write "r" (reset)
784 * to the file to reset them
788 static ssize_t amdgpu_set_pp_od_clk_voltage(struct device *dev,
789 struct device_attribute *attr,
793 struct drm_device *ddev = dev_get_drvdata(dev);
794 struct amdgpu_device *adev = drm_to_adev(ddev);
796 uint32_t parameter_size = 0;
801 const char delimiter[3] = {' ', '\n', '\0'};
804 if (amdgpu_in_reset(adev))
806 if (adev->in_suspend && !adev->in_runpm)
813 type = PP_OD_EDIT_SCLK_VDDC_TABLE;
814 else if (*buf == 'p')
815 type = PP_OD_EDIT_CCLK_VDDC_TABLE;
816 else if (*buf == 'm')
817 type = PP_OD_EDIT_MCLK_VDDC_TABLE;
819 type = PP_OD_RESTORE_DEFAULT_TABLE;
820 else if (*buf == 'c')
821 type = PP_OD_COMMIT_DPM_TABLE;
822 else if (!strncmp(buf, "vc", 2))
823 type = PP_OD_EDIT_VDDC_CURVE;
824 else if (!strncmp(buf, "vo", 2))
825 type = PP_OD_EDIT_VDDGFX_OFFSET;
829 memcpy(buf_cpy, buf, count+1);
833 if ((type == PP_OD_EDIT_VDDC_CURVE) ||
834 (type == PP_OD_EDIT_VDDGFX_OFFSET))
836 while (isspace(*++tmp_str));
838 while ((sub_str = strsep(&tmp_str, delimiter)) != NULL) {
839 if (strlen(sub_str) == 0)
841 ret = kstrtol(sub_str, 0, ¶meter[parameter_size]);
846 while (isspace(*tmp_str))
850 ret = pm_runtime_get_sync(ddev->dev);
852 pm_runtime_put_autosuspend(ddev->dev);
856 if (adev->powerplay.pp_funcs->set_fine_grain_clk_vol) {
857 ret = amdgpu_dpm_set_fine_grain_clk_vol(adev, type,
861 pm_runtime_mark_last_busy(ddev->dev);
862 pm_runtime_put_autosuspend(ddev->dev);
867 if (adev->powerplay.pp_funcs->odn_edit_dpm_table) {
868 ret = amdgpu_dpm_odn_edit_dpm_table(adev, type,
869 parameter, parameter_size);
871 pm_runtime_mark_last_busy(ddev->dev);
872 pm_runtime_put_autosuspend(ddev->dev);
877 if (type == PP_OD_COMMIT_DPM_TABLE) {
878 if (adev->powerplay.pp_funcs->dispatch_tasks) {
879 amdgpu_dpm_dispatch_task(adev,
880 AMD_PP_TASK_READJUST_POWER_STATE,
882 pm_runtime_mark_last_busy(ddev->dev);
883 pm_runtime_put_autosuspend(ddev->dev);
886 pm_runtime_mark_last_busy(ddev->dev);
887 pm_runtime_put_autosuspend(ddev->dev);
892 pm_runtime_mark_last_busy(ddev->dev);
893 pm_runtime_put_autosuspend(ddev->dev);
898 static ssize_t amdgpu_get_pp_od_clk_voltage(struct device *dev,
899 struct device_attribute *attr,
902 struct drm_device *ddev = dev_get_drvdata(dev);
903 struct amdgpu_device *adev = drm_to_adev(ddev);
907 if (amdgpu_in_reset(adev))
909 if (adev->in_suspend && !adev->in_runpm)
912 ret = pm_runtime_get_sync(ddev->dev);
914 pm_runtime_put_autosuspend(ddev->dev);
918 if (adev->powerplay.pp_funcs->print_clock_levels) {
919 size = amdgpu_dpm_print_clock_levels(adev, OD_SCLK, buf);
920 size += amdgpu_dpm_print_clock_levels(adev, OD_MCLK, buf+size);
921 size += amdgpu_dpm_print_clock_levels(adev, OD_VDDC_CURVE, buf+size);
922 size += amdgpu_dpm_print_clock_levels(adev, OD_VDDGFX_OFFSET, buf+size);
923 size += amdgpu_dpm_print_clock_levels(adev, OD_RANGE, buf+size);
924 size += amdgpu_dpm_print_clock_levels(adev, OD_CCLK, buf+size);
926 size = snprintf(buf, PAGE_SIZE, "\n");
928 pm_runtime_mark_last_busy(ddev->dev);
929 pm_runtime_put_autosuspend(ddev->dev);
937 * The amdgpu driver provides a sysfs API for adjusting what powerplay
938 * features to be enabled. The file pp_features is used for this. And
939 * this is only available for Vega10 and later dGPUs.
941 * Reading back the file will show you the followings:
942 * - Current ppfeature masks
943 * - List of the all supported powerplay features with their naming,
944 * bitmasks and enablement status('Y'/'N' means "enabled"/"disabled").
946 * To manually enable or disable a specific feature, just set or clear
947 * the corresponding bit from original ppfeature masks and input the
948 * new ppfeature masks.
950 static ssize_t amdgpu_set_pp_features(struct device *dev,
951 struct device_attribute *attr,
955 struct drm_device *ddev = dev_get_drvdata(dev);
956 struct amdgpu_device *adev = drm_to_adev(ddev);
957 uint64_t featuremask;
960 if (amdgpu_in_reset(adev))
962 if (adev->in_suspend && !adev->in_runpm)
965 ret = kstrtou64(buf, 0, &featuremask);
969 ret = pm_runtime_get_sync(ddev->dev);
971 pm_runtime_put_autosuspend(ddev->dev);
975 if (adev->powerplay.pp_funcs->set_ppfeature_status) {
976 ret = amdgpu_dpm_set_ppfeature_status(adev, featuremask);
978 pm_runtime_mark_last_busy(ddev->dev);
979 pm_runtime_put_autosuspend(ddev->dev);
983 pm_runtime_mark_last_busy(ddev->dev);
984 pm_runtime_put_autosuspend(ddev->dev);
989 static ssize_t amdgpu_get_pp_features(struct device *dev,
990 struct device_attribute *attr,
993 struct drm_device *ddev = dev_get_drvdata(dev);
994 struct amdgpu_device *adev = drm_to_adev(ddev);
998 if (amdgpu_in_reset(adev))
1000 if (adev->in_suspend && !adev->in_runpm)
1003 ret = pm_runtime_get_sync(ddev->dev);
1005 pm_runtime_put_autosuspend(ddev->dev);
1009 if (adev->powerplay.pp_funcs->get_ppfeature_status)
1010 size = amdgpu_dpm_get_ppfeature_status(adev, buf);
1012 size = snprintf(buf, PAGE_SIZE, "\n");
1014 pm_runtime_mark_last_busy(ddev->dev);
1015 pm_runtime_put_autosuspend(ddev->dev);
1021 * DOC: pp_dpm_sclk pp_dpm_mclk pp_dpm_socclk pp_dpm_fclk pp_dpm_dcefclk pp_dpm_pcie
1023 * The amdgpu driver provides a sysfs API for adjusting what power levels
1024 * are enabled for a given power state. The files pp_dpm_sclk, pp_dpm_mclk,
1025 * pp_dpm_socclk, pp_dpm_fclk, pp_dpm_dcefclk and pp_dpm_pcie are used for
1028 * pp_dpm_socclk and pp_dpm_dcefclk interfaces are only available for
1029 * Vega10 and later ASICs.
1030 * pp_dpm_fclk interface is only available for Vega20 and later ASICs.
1032 * Reading back the files will show you the available power levels within
1033 * the power state and the clock information for those levels.
1035 * To manually adjust these states, first select manual using
1036 * power_dpm_force_performance_level.
1037 * Secondly, enter a new value for each level by inputing a string that
1038 * contains " echo xx xx xx > pp_dpm_sclk/mclk/pcie"
1041 * .. code-block:: bash
1043 * echo "4 5 6" > pp_dpm_sclk
1045 * will enable sclk levels 4, 5, and 6.
1047 * NOTE: change to the dcefclk max dpm level is not supported now
1050 static ssize_t amdgpu_get_pp_dpm_clock(struct device *dev,
1051 enum pp_clock_type type,
1054 struct drm_device *ddev = dev_get_drvdata(dev);
1055 struct amdgpu_device *adev = drm_to_adev(ddev);
1059 if (amdgpu_in_reset(adev))
1061 if (adev->in_suspend && !adev->in_runpm)
1064 ret = pm_runtime_get_sync(ddev->dev);
1066 pm_runtime_put_autosuspend(ddev->dev);
1070 if (adev->powerplay.pp_funcs->print_clock_levels)
1071 size = amdgpu_dpm_print_clock_levels(adev, type, buf);
1073 size = snprintf(buf, PAGE_SIZE, "\n");
1075 pm_runtime_mark_last_busy(ddev->dev);
1076 pm_runtime_put_autosuspend(ddev->dev);
1082 * Worst case: 32 bits individually specified, in octal at 12 characters
1083 * per line (+1 for \n).
1085 #define AMDGPU_MASK_BUF_MAX (32 * 13)
1087 static ssize_t amdgpu_read_mask(const char *buf, size_t count, uint32_t *mask)
1090 unsigned long level;
1091 char *sub_str = NULL;
1093 char buf_cpy[AMDGPU_MASK_BUF_MAX + 1];
1094 const char delimiter[3] = {' ', '\n', '\0'};
1099 bytes = min(count, sizeof(buf_cpy) - 1);
1100 memcpy(buf_cpy, buf, bytes);
1101 buf_cpy[bytes] = '\0';
1103 while ((sub_str = strsep(&tmp, delimiter)) != NULL) {
1104 if (strlen(sub_str)) {
1105 ret = kstrtoul(sub_str, 0, &level);
1106 if (ret || level > 31)
1108 *mask |= 1 << level;
1116 static ssize_t amdgpu_set_pp_dpm_clock(struct device *dev,
1117 enum pp_clock_type type,
1121 struct drm_device *ddev = dev_get_drvdata(dev);
1122 struct amdgpu_device *adev = drm_to_adev(ddev);
1126 if (amdgpu_in_reset(adev))
1128 if (adev->in_suspend && !adev->in_runpm)
1131 ret = amdgpu_read_mask(buf, count, &mask);
1135 ret = pm_runtime_get_sync(ddev->dev);
1137 pm_runtime_put_autosuspend(ddev->dev);
1141 if (adev->powerplay.pp_funcs->force_clock_level)
1142 ret = amdgpu_dpm_force_clock_level(adev, type, mask);
1146 pm_runtime_mark_last_busy(ddev->dev);
1147 pm_runtime_put_autosuspend(ddev->dev);
1155 static ssize_t amdgpu_get_pp_dpm_sclk(struct device *dev,
1156 struct device_attribute *attr,
1159 return amdgpu_get_pp_dpm_clock(dev, PP_SCLK, buf);
1162 static ssize_t amdgpu_set_pp_dpm_sclk(struct device *dev,
1163 struct device_attribute *attr,
1167 return amdgpu_set_pp_dpm_clock(dev, PP_SCLK, buf, count);
1170 static ssize_t amdgpu_get_pp_dpm_mclk(struct device *dev,
1171 struct device_attribute *attr,
1174 return amdgpu_get_pp_dpm_clock(dev, PP_MCLK, buf);
1177 static ssize_t amdgpu_set_pp_dpm_mclk(struct device *dev,
1178 struct device_attribute *attr,
1182 return amdgpu_set_pp_dpm_clock(dev, PP_MCLK, buf, count);
1185 static ssize_t amdgpu_get_pp_dpm_socclk(struct device *dev,
1186 struct device_attribute *attr,
1189 return amdgpu_get_pp_dpm_clock(dev, PP_SOCCLK, buf);
1192 static ssize_t amdgpu_set_pp_dpm_socclk(struct device *dev,
1193 struct device_attribute *attr,
1197 return amdgpu_set_pp_dpm_clock(dev, PP_SOCCLK, buf, count);
1200 static ssize_t amdgpu_get_pp_dpm_fclk(struct device *dev,
1201 struct device_attribute *attr,
1204 return amdgpu_get_pp_dpm_clock(dev, PP_FCLK, buf);
1207 static ssize_t amdgpu_set_pp_dpm_fclk(struct device *dev,
1208 struct device_attribute *attr,
1212 return amdgpu_set_pp_dpm_clock(dev, PP_FCLK, buf, count);
1215 static ssize_t amdgpu_get_pp_dpm_vclk(struct device *dev,
1216 struct device_attribute *attr,
1219 return amdgpu_get_pp_dpm_clock(dev, PP_VCLK, buf);
1222 static ssize_t amdgpu_set_pp_dpm_vclk(struct device *dev,
1223 struct device_attribute *attr,
1227 return amdgpu_set_pp_dpm_clock(dev, PP_VCLK, buf, count);
1230 static ssize_t amdgpu_get_pp_dpm_dclk(struct device *dev,
1231 struct device_attribute *attr,
1234 return amdgpu_get_pp_dpm_clock(dev, PP_DCLK, buf);
1237 static ssize_t amdgpu_set_pp_dpm_dclk(struct device *dev,
1238 struct device_attribute *attr,
1242 return amdgpu_set_pp_dpm_clock(dev, PP_DCLK, buf, count);
1245 static ssize_t amdgpu_get_pp_dpm_dcefclk(struct device *dev,
1246 struct device_attribute *attr,
1249 return amdgpu_get_pp_dpm_clock(dev, PP_DCEFCLK, buf);
1252 static ssize_t amdgpu_set_pp_dpm_dcefclk(struct device *dev,
1253 struct device_attribute *attr,
1257 return amdgpu_set_pp_dpm_clock(dev, PP_DCEFCLK, buf, count);
1260 static ssize_t amdgpu_get_pp_dpm_pcie(struct device *dev,
1261 struct device_attribute *attr,
1264 return amdgpu_get_pp_dpm_clock(dev, PP_PCIE, buf);
1267 static ssize_t amdgpu_set_pp_dpm_pcie(struct device *dev,
1268 struct device_attribute *attr,
1272 return amdgpu_set_pp_dpm_clock(dev, PP_PCIE, buf, count);
1275 static ssize_t amdgpu_get_pp_sclk_od(struct device *dev,
1276 struct device_attribute *attr,
1279 struct drm_device *ddev = dev_get_drvdata(dev);
1280 struct amdgpu_device *adev = drm_to_adev(ddev);
1284 if (amdgpu_in_reset(adev))
1286 if (adev->in_suspend && !adev->in_runpm)
1289 ret = pm_runtime_get_sync(ddev->dev);
1291 pm_runtime_put_autosuspend(ddev->dev);
1295 if (is_support_sw_smu(adev))
1297 else if (adev->powerplay.pp_funcs->get_sclk_od)
1298 value = amdgpu_dpm_get_sclk_od(adev);
1300 pm_runtime_mark_last_busy(ddev->dev);
1301 pm_runtime_put_autosuspend(ddev->dev);
1303 return sysfs_emit(buf, "%d\n", value);
1306 static ssize_t amdgpu_set_pp_sclk_od(struct device *dev,
1307 struct device_attribute *attr,
1311 struct drm_device *ddev = dev_get_drvdata(dev);
1312 struct amdgpu_device *adev = drm_to_adev(ddev);
1316 if (amdgpu_in_reset(adev))
1318 if (adev->in_suspend && !adev->in_runpm)
1321 ret = kstrtol(buf, 0, &value);
1326 ret = pm_runtime_get_sync(ddev->dev);
1328 pm_runtime_put_autosuspend(ddev->dev);
1332 if (is_support_sw_smu(adev)) {
1335 if (adev->powerplay.pp_funcs->set_sclk_od)
1336 amdgpu_dpm_set_sclk_od(adev, (uint32_t)value);
1338 if (adev->powerplay.pp_funcs->dispatch_tasks) {
1339 amdgpu_dpm_dispatch_task(adev, AMD_PP_TASK_READJUST_POWER_STATE, NULL);
1341 adev->pm.dpm.current_ps = adev->pm.dpm.boot_ps;
1342 amdgpu_pm_compute_clocks(adev);
1346 pm_runtime_mark_last_busy(ddev->dev);
1347 pm_runtime_put_autosuspend(ddev->dev);
1352 static ssize_t amdgpu_get_pp_mclk_od(struct device *dev,
1353 struct device_attribute *attr,
1356 struct drm_device *ddev = dev_get_drvdata(dev);
1357 struct amdgpu_device *adev = drm_to_adev(ddev);
1361 if (amdgpu_in_reset(adev))
1363 if (adev->in_suspend && !adev->in_runpm)
1366 ret = pm_runtime_get_sync(ddev->dev);
1368 pm_runtime_put_autosuspend(ddev->dev);
1372 if (is_support_sw_smu(adev))
1374 else if (adev->powerplay.pp_funcs->get_mclk_od)
1375 value = amdgpu_dpm_get_mclk_od(adev);
1377 pm_runtime_mark_last_busy(ddev->dev);
1378 pm_runtime_put_autosuspend(ddev->dev);
1380 return sysfs_emit(buf, "%d\n", value);
1383 static ssize_t amdgpu_set_pp_mclk_od(struct device *dev,
1384 struct device_attribute *attr,
1388 struct drm_device *ddev = dev_get_drvdata(dev);
1389 struct amdgpu_device *adev = drm_to_adev(ddev);
1393 if (amdgpu_in_reset(adev))
1395 if (adev->in_suspend && !adev->in_runpm)
1398 ret = kstrtol(buf, 0, &value);
1403 ret = pm_runtime_get_sync(ddev->dev);
1405 pm_runtime_put_autosuspend(ddev->dev);
1409 if (is_support_sw_smu(adev)) {
1412 if (adev->powerplay.pp_funcs->set_mclk_od)
1413 amdgpu_dpm_set_mclk_od(adev, (uint32_t)value);
1415 if (adev->powerplay.pp_funcs->dispatch_tasks) {
1416 amdgpu_dpm_dispatch_task(adev, AMD_PP_TASK_READJUST_POWER_STATE, NULL);
1418 adev->pm.dpm.current_ps = adev->pm.dpm.boot_ps;
1419 amdgpu_pm_compute_clocks(adev);
1423 pm_runtime_mark_last_busy(ddev->dev);
1424 pm_runtime_put_autosuspend(ddev->dev);
1430 * DOC: pp_power_profile_mode
1432 * The amdgpu driver provides a sysfs API for adjusting the heuristics
1433 * related to switching between power levels in a power state. The file
1434 * pp_power_profile_mode is used for this.
1436 * Reading this file outputs a list of all of the predefined power profiles
1437 * and the relevant heuristics settings for that profile.
1439 * To select a profile or create a custom profile, first select manual using
1440 * power_dpm_force_performance_level. Writing the number of a predefined
1441 * profile to pp_power_profile_mode will enable those heuristics. To
1442 * create a custom set of heuristics, write a string of numbers to the file
1443 * starting with the number of the custom profile along with a setting
1444 * for each heuristic parameter. Due to differences across asic families
1445 * the heuristic parameters vary from family to family.
1449 static ssize_t amdgpu_get_pp_power_profile_mode(struct device *dev,
1450 struct device_attribute *attr,
1453 struct drm_device *ddev = dev_get_drvdata(dev);
1454 struct amdgpu_device *adev = drm_to_adev(ddev);
1458 if (amdgpu_in_reset(adev))
1460 if (adev->in_suspend && !adev->in_runpm)
1463 ret = pm_runtime_get_sync(ddev->dev);
1465 pm_runtime_put_autosuspend(ddev->dev);
1469 if (adev->powerplay.pp_funcs->get_power_profile_mode)
1470 size = amdgpu_dpm_get_power_profile_mode(adev, buf);
1472 size = snprintf(buf, PAGE_SIZE, "\n");
1474 pm_runtime_mark_last_busy(ddev->dev);
1475 pm_runtime_put_autosuspend(ddev->dev);
1481 static ssize_t amdgpu_set_pp_power_profile_mode(struct device *dev,
1482 struct device_attribute *attr,
1487 struct drm_device *ddev = dev_get_drvdata(dev);
1488 struct amdgpu_device *adev = drm_to_adev(ddev);
1489 uint32_t parameter_size = 0;
1491 char *sub_str, buf_cpy[128];
1495 long int profile_mode = 0;
1496 const char delimiter[3] = {' ', '\n', '\0'};
1498 if (amdgpu_in_reset(adev))
1500 if (adev->in_suspend && !adev->in_runpm)
1505 ret = kstrtol(tmp, 0, &profile_mode);
1509 if (profile_mode == PP_SMC_POWER_PROFILE_CUSTOM) {
1510 if (count < 2 || count > 127)
1512 while (isspace(*++buf))
1514 memcpy(buf_cpy, buf, count-i);
1516 while ((sub_str = strsep(&tmp_str, delimiter)) != NULL) {
1517 if (strlen(sub_str) == 0)
1519 ret = kstrtol(sub_str, 0, ¶meter[parameter_size]);
1523 while (isspace(*tmp_str))
1527 parameter[parameter_size] = profile_mode;
1529 ret = pm_runtime_get_sync(ddev->dev);
1531 pm_runtime_put_autosuspend(ddev->dev);
1535 if (adev->powerplay.pp_funcs->set_power_profile_mode)
1536 ret = amdgpu_dpm_set_power_profile_mode(adev, parameter, parameter_size);
1538 pm_runtime_mark_last_busy(ddev->dev);
1539 pm_runtime_put_autosuspend(ddev->dev);
1548 * DOC: gpu_busy_percent
1550 * The amdgpu driver provides a sysfs API for reading how busy the GPU
1551 * is as a percentage. The file gpu_busy_percent is used for this.
1552 * The SMU firmware computes a percentage of load based on the
1553 * aggregate activity level in the IP cores.
1555 static ssize_t amdgpu_get_gpu_busy_percent(struct device *dev,
1556 struct device_attribute *attr,
1559 struct drm_device *ddev = dev_get_drvdata(dev);
1560 struct amdgpu_device *adev = drm_to_adev(ddev);
1561 int r, value, size = sizeof(value);
1563 if (amdgpu_in_reset(adev))
1565 if (adev->in_suspend && !adev->in_runpm)
1568 r = pm_runtime_get_sync(ddev->dev);
1570 pm_runtime_put_autosuspend(ddev->dev);
1574 /* read the IP busy sensor */
1575 r = amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GPU_LOAD,
1576 (void *)&value, &size);
1578 pm_runtime_mark_last_busy(ddev->dev);
1579 pm_runtime_put_autosuspend(ddev->dev);
1584 return sysfs_emit(buf, "%d\n", value);
1588 * DOC: mem_busy_percent
1590 * The amdgpu driver provides a sysfs API for reading how busy the VRAM
1591 * is as a percentage. The file mem_busy_percent is used for this.
1592 * The SMU firmware computes a percentage of load based on the
1593 * aggregate activity level in the IP cores.
1595 static ssize_t amdgpu_get_mem_busy_percent(struct device *dev,
1596 struct device_attribute *attr,
1599 struct drm_device *ddev = dev_get_drvdata(dev);
1600 struct amdgpu_device *adev = drm_to_adev(ddev);
1601 int r, value, size = sizeof(value);
1603 if (amdgpu_in_reset(adev))
1605 if (adev->in_suspend && !adev->in_runpm)
1608 r = pm_runtime_get_sync(ddev->dev);
1610 pm_runtime_put_autosuspend(ddev->dev);
1614 /* read the IP busy sensor */
1615 r = amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_MEM_LOAD,
1616 (void *)&value, &size);
1618 pm_runtime_mark_last_busy(ddev->dev);
1619 pm_runtime_put_autosuspend(ddev->dev);
1624 return sysfs_emit(buf, "%d\n", value);
1630 * The amdgpu driver provides a sysfs API for estimating how much data
1631 * has been received and sent by the GPU in the last second through PCIe.
1632 * The file pcie_bw is used for this.
1633 * The Perf counters count the number of received and sent messages and return
1634 * those values, as well as the maximum payload size of a PCIe packet (mps).
1635 * Note that it is not possible to easily and quickly obtain the size of each
1636 * packet transmitted, so we output the max payload size (mps) to allow for
1637 * quick estimation of the PCIe bandwidth usage
1639 static ssize_t amdgpu_get_pcie_bw(struct device *dev,
1640 struct device_attribute *attr,
1643 struct drm_device *ddev = dev_get_drvdata(dev);
1644 struct amdgpu_device *adev = drm_to_adev(ddev);
1645 uint64_t count0 = 0, count1 = 0;
1648 if (amdgpu_in_reset(adev))
1650 if (adev->in_suspend && !adev->in_runpm)
1653 if (adev->flags & AMD_IS_APU)
1656 if (!adev->asic_funcs->get_pcie_usage)
1659 ret = pm_runtime_get_sync(ddev->dev);
1661 pm_runtime_put_autosuspend(ddev->dev);
1665 amdgpu_asic_get_pcie_usage(adev, &count0, &count1);
1667 pm_runtime_mark_last_busy(ddev->dev);
1668 pm_runtime_put_autosuspend(ddev->dev);
1670 return sysfs_emit(buf, "%llu %llu %i\n",
1671 count0, count1, pcie_get_mps(adev->pdev));
1677 * The amdgpu driver provides a sysfs API for providing a unique ID for the GPU
1678 * The file unique_id is used for this.
1679 * This will provide a Unique ID that will persist from machine to machine
1681 * NOTE: This will only work for GFX9 and newer. This file will be absent
1682 * on unsupported ASICs (GFX8 and older)
1684 static ssize_t amdgpu_get_unique_id(struct device *dev,
1685 struct device_attribute *attr,
1688 struct drm_device *ddev = dev_get_drvdata(dev);
1689 struct amdgpu_device *adev = drm_to_adev(ddev);
1691 if (amdgpu_in_reset(adev))
1693 if (adev->in_suspend && !adev->in_runpm)
1696 if (adev->unique_id)
1697 return sysfs_emit(buf, "%016llx\n", adev->unique_id);
1703 * DOC: thermal_throttling_logging
1705 * Thermal throttling pulls down the clock frequency and thus the performance.
1706 * It's an useful mechanism to protect the chip from overheating. Since it
1707 * impacts performance, the user controls whether it is enabled and if so,
1708 * the log frequency.
1710 * Reading back the file shows you the status(enabled or disabled) and
1711 * the interval(in seconds) between each thermal logging.
1713 * Writing an integer to the file, sets a new logging interval, in seconds.
1714 * The value should be between 1 and 3600. If the value is less than 1,
1715 * thermal logging is disabled. Values greater than 3600 are ignored.
1717 static ssize_t amdgpu_get_thermal_throttling_logging(struct device *dev,
1718 struct device_attribute *attr,
1721 struct drm_device *ddev = dev_get_drvdata(dev);
1722 struct amdgpu_device *adev = drm_to_adev(ddev);
1724 return sysfs_emit(buf, "%s: thermal throttling logging %s, with interval %d seconds\n",
1725 adev_to_drm(adev)->unique,
1726 atomic_read(&adev->throttling_logging_enabled) ? "enabled" : "disabled",
1727 adev->throttling_logging_rs.interval / HZ + 1);
1730 static ssize_t amdgpu_set_thermal_throttling_logging(struct device *dev,
1731 struct device_attribute *attr,
1735 struct drm_device *ddev = dev_get_drvdata(dev);
1736 struct amdgpu_device *adev = drm_to_adev(ddev);
1737 long throttling_logging_interval;
1738 unsigned long flags;
1741 ret = kstrtol(buf, 0, &throttling_logging_interval);
1745 if (throttling_logging_interval > 3600)
1748 if (throttling_logging_interval > 0) {
1749 raw_spin_lock_irqsave(&adev->throttling_logging_rs.lock, flags);
1751 * Reset the ratelimit timer internals.
1752 * This can effectively restart the timer.
1754 adev->throttling_logging_rs.interval =
1755 (throttling_logging_interval - 1) * HZ;
1756 adev->throttling_logging_rs.begin = 0;
1757 adev->throttling_logging_rs.printed = 0;
1758 adev->throttling_logging_rs.missed = 0;
1759 raw_spin_unlock_irqrestore(&adev->throttling_logging_rs.lock, flags);
1761 atomic_set(&adev->throttling_logging_enabled, 1);
1763 atomic_set(&adev->throttling_logging_enabled, 0);
1772 * The amdgpu driver provides a sysfs API for retrieving current gpu
1773 * metrics data. The file gpu_metrics is used for this. Reading the
1774 * file will dump all the current gpu metrics data.
1776 * These data include temperature, frequency, engines utilization,
1777 * power consume, throttler status, fan speed and cpu core statistics(
1778 * available for APU only). That's it will give a snapshot of all sensors
1781 static ssize_t amdgpu_get_gpu_metrics(struct device *dev,
1782 struct device_attribute *attr,
1785 struct drm_device *ddev = dev_get_drvdata(dev);
1786 struct amdgpu_device *adev = drm_to_adev(ddev);
1791 if (amdgpu_in_reset(adev))
1793 if (adev->in_suspend && !adev->in_runpm)
1796 ret = pm_runtime_get_sync(ddev->dev);
1798 pm_runtime_put_autosuspend(ddev->dev);
1802 if (adev->powerplay.pp_funcs->get_gpu_metrics)
1803 size = amdgpu_dpm_get_gpu_metrics(adev, &gpu_metrics);
1808 if (size >= PAGE_SIZE)
1809 size = PAGE_SIZE - 1;
1811 memcpy(buf, gpu_metrics, size);
1814 pm_runtime_mark_last_busy(ddev->dev);
1815 pm_runtime_put_autosuspend(ddev->dev);
1820 static struct amdgpu_device_attr amdgpu_device_attrs[] = {
1821 AMDGPU_DEVICE_ATTR_RW(power_dpm_state, ATTR_FLAG_BASIC|ATTR_FLAG_ONEVF),
1822 AMDGPU_DEVICE_ATTR_RW(power_dpm_force_performance_level, ATTR_FLAG_BASIC|ATTR_FLAG_ONEVF),
1823 AMDGPU_DEVICE_ATTR_RO(pp_num_states, ATTR_FLAG_BASIC),
1824 AMDGPU_DEVICE_ATTR_RO(pp_cur_state, ATTR_FLAG_BASIC),
1825 AMDGPU_DEVICE_ATTR_RW(pp_force_state, ATTR_FLAG_BASIC),
1826 AMDGPU_DEVICE_ATTR_RW(pp_table, ATTR_FLAG_BASIC),
1827 AMDGPU_DEVICE_ATTR_RW(pp_dpm_sclk, ATTR_FLAG_BASIC|ATTR_FLAG_ONEVF),
1828 AMDGPU_DEVICE_ATTR_RW(pp_dpm_mclk, ATTR_FLAG_BASIC|ATTR_FLAG_ONEVF),
1829 AMDGPU_DEVICE_ATTR_RW(pp_dpm_socclk, ATTR_FLAG_BASIC|ATTR_FLAG_ONEVF),
1830 AMDGPU_DEVICE_ATTR_RW(pp_dpm_fclk, ATTR_FLAG_BASIC|ATTR_FLAG_ONEVF),
1831 AMDGPU_DEVICE_ATTR_RW(pp_dpm_vclk, ATTR_FLAG_BASIC|ATTR_FLAG_ONEVF),
1832 AMDGPU_DEVICE_ATTR_RW(pp_dpm_dclk, ATTR_FLAG_BASIC|ATTR_FLAG_ONEVF),
1833 AMDGPU_DEVICE_ATTR_RW(pp_dpm_dcefclk, ATTR_FLAG_BASIC),
1834 AMDGPU_DEVICE_ATTR_RW(pp_dpm_pcie, ATTR_FLAG_BASIC),
1835 AMDGPU_DEVICE_ATTR_RW(pp_sclk_od, ATTR_FLAG_BASIC),
1836 AMDGPU_DEVICE_ATTR_RW(pp_mclk_od, ATTR_FLAG_BASIC),
1837 AMDGPU_DEVICE_ATTR_RW(pp_power_profile_mode, ATTR_FLAG_BASIC),
1838 AMDGPU_DEVICE_ATTR_RW(pp_od_clk_voltage, ATTR_FLAG_BASIC),
1839 AMDGPU_DEVICE_ATTR_RO(gpu_busy_percent, ATTR_FLAG_BASIC),
1840 AMDGPU_DEVICE_ATTR_RO(mem_busy_percent, ATTR_FLAG_BASIC),
1841 AMDGPU_DEVICE_ATTR_RO(pcie_bw, ATTR_FLAG_BASIC),
1842 AMDGPU_DEVICE_ATTR_RW(pp_features, ATTR_FLAG_BASIC),
1843 AMDGPU_DEVICE_ATTR_RO(unique_id, ATTR_FLAG_BASIC),
1844 AMDGPU_DEVICE_ATTR_RW(thermal_throttling_logging, ATTR_FLAG_BASIC),
1845 AMDGPU_DEVICE_ATTR_RO(gpu_metrics, ATTR_FLAG_BASIC),
1848 static int default_attr_update(struct amdgpu_device *adev, struct amdgpu_device_attr *attr,
1849 uint32_t mask, enum amdgpu_device_attr_states *states)
1851 struct device_attribute *dev_attr = &attr->dev_attr;
1852 const char *attr_name = dev_attr->attr.name;
1853 struct pp_hwmgr *hwmgr = adev->powerplay.pp_handle;
1854 enum amd_asic_type asic_type = adev->asic_type;
1856 if (!(attr->flags & mask)) {
1857 *states = ATTR_STATE_UNSUPPORTED;
1861 #define DEVICE_ATTR_IS(_name) (!strcmp(attr_name, #_name))
1863 if (DEVICE_ATTR_IS(pp_dpm_socclk)) {
1864 if (asic_type < CHIP_VEGA10)
1865 *states = ATTR_STATE_UNSUPPORTED;
1866 } else if (DEVICE_ATTR_IS(pp_dpm_dcefclk)) {
1867 if (asic_type < CHIP_VEGA10 ||
1868 asic_type == CHIP_ARCTURUS ||
1869 asic_type == CHIP_ALDEBARAN)
1870 *states = ATTR_STATE_UNSUPPORTED;
1871 } else if (DEVICE_ATTR_IS(pp_dpm_fclk)) {
1872 if (asic_type < CHIP_VEGA20)
1873 *states = ATTR_STATE_UNSUPPORTED;
1874 } else if (DEVICE_ATTR_IS(pp_od_clk_voltage)) {
1875 *states = ATTR_STATE_UNSUPPORTED;
1876 if ((is_support_sw_smu(adev) && adev->smu.od_enabled) ||
1877 (is_support_sw_smu(adev) && adev->smu.is_apu) ||
1878 (!is_support_sw_smu(adev) && hwmgr->od_enabled))
1879 *states = ATTR_STATE_SUPPORTED;
1880 } else if (DEVICE_ATTR_IS(mem_busy_percent)) {
1881 if (adev->flags & AMD_IS_APU || asic_type == CHIP_VEGA10)
1882 *states = ATTR_STATE_UNSUPPORTED;
1883 } else if (DEVICE_ATTR_IS(pcie_bw)) {
1884 /* PCIe Perf counters won't work on APU nodes */
1885 if (adev->flags & AMD_IS_APU)
1886 *states = ATTR_STATE_UNSUPPORTED;
1887 } else if (DEVICE_ATTR_IS(unique_id)) {
1888 if (asic_type != CHIP_VEGA10 &&
1889 asic_type != CHIP_VEGA20 &&
1890 asic_type != CHIP_ARCTURUS)
1891 *states = ATTR_STATE_UNSUPPORTED;
1892 } else if (DEVICE_ATTR_IS(pp_features)) {
1893 if (adev->flags & AMD_IS_APU || asic_type < CHIP_VEGA10)
1894 *states = ATTR_STATE_UNSUPPORTED;
1895 } else if (DEVICE_ATTR_IS(gpu_metrics)) {
1896 if (asic_type < CHIP_VEGA12)
1897 *states = ATTR_STATE_UNSUPPORTED;
1898 } else if (DEVICE_ATTR_IS(pp_dpm_vclk)) {
1899 if (!(asic_type == CHIP_VANGOGH))
1900 *states = ATTR_STATE_UNSUPPORTED;
1901 } else if (DEVICE_ATTR_IS(pp_dpm_dclk)) {
1902 if (!(asic_type == CHIP_VANGOGH))
1903 *states = ATTR_STATE_UNSUPPORTED;
1906 if (asic_type == CHIP_ARCTURUS) {
1907 /* Arcturus does not support standalone mclk/socclk/fclk level setting */
1908 if (DEVICE_ATTR_IS(pp_dpm_mclk) ||
1909 DEVICE_ATTR_IS(pp_dpm_socclk) ||
1910 DEVICE_ATTR_IS(pp_dpm_fclk)) {
1911 dev_attr->attr.mode &= ~S_IWUGO;
1912 dev_attr->store = NULL;
1916 if (DEVICE_ATTR_IS(pp_dpm_dcefclk)) {
1917 /* SMU MP1 does not support dcefclk level setting */
1918 if (asic_type >= CHIP_NAVI10) {
1919 dev_attr->attr.mode &= ~S_IWUGO;
1920 dev_attr->store = NULL;
1924 #undef DEVICE_ATTR_IS
1930 static int amdgpu_device_attr_create(struct amdgpu_device *adev,
1931 struct amdgpu_device_attr *attr,
1932 uint32_t mask, struct list_head *attr_list)
1935 struct device_attribute *dev_attr = &attr->dev_attr;
1936 const char *name = dev_attr->attr.name;
1937 enum amdgpu_device_attr_states attr_states = ATTR_STATE_SUPPORTED;
1938 struct amdgpu_device_attr_entry *attr_entry;
1940 int (*attr_update)(struct amdgpu_device *adev, struct amdgpu_device_attr *attr,
1941 uint32_t mask, enum amdgpu_device_attr_states *states) = default_attr_update;
1945 attr_update = attr->attr_update ? attr->attr_update : default_attr_update;
1947 ret = attr_update(adev, attr, mask, &attr_states);
1949 dev_err(adev->dev, "failed to update device file %s, ret = %d\n",
1954 if (attr_states == ATTR_STATE_UNSUPPORTED)
1957 ret = device_create_file(adev->dev, dev_attr);
1959 dev_err(adev->dev, "failed to create device file %s, ret = %d\n",
1963 attr_entry = kmalloc(sizeof(*attr_entry), GFP_KERNEL);
1967 attr_entry->attr = attr;
1968 INIT_LIST_HEAD(&attr_entry->entry);
1970 list_add_tail(&attr_entry->entry, attr_list);
1975 static void amdgpu_device_attr_remove(struct amdgpu_device *adev, struct amdgpu_device_attr *attr)
1977 struct device_attribute *dev_attr = &attr->dev_attr;
1979 device_remove_file(adev->dev, dev_attr);
1982 static void amdgpu_device_attr_remove_groups(struct amdgpu_device *adev,
1983 struct list_head *attr_list);
1985 static int amdgpu_device_attr_create_groups(struct amdgpu_device *adev,
1986 struct amdgpu_device_attr *attrs,
1989 struct list_head *attr_list)
1994 for (i = 0; i < counts; i++) {
1995 ret = amdgpu_device_attr_create(adev, &attrs[i], mask, attr_list);
2003 amdgpu_device_attr_remove_groups(adev, attr_list);
2008 static void amdgpu_device_attr_remove_groups(struct amdgpu_device *adev,
2009 struct list_head *attr_list)
2011 struct amdgpu_device_attr_entry *entry, *entry_tmp;
2013 if (list_empty(attr_list))
2016 list_for_each_entry_safe(entry, entry_tmp, attr_list, entry) {
2017 amdgpu_device_attr_remove(adev, entry->attr);
2018 list_del(&entry->entry);
2023 static ssize_t amdgpu_hwmon_show_temp(struct device *dev,
2024 struct device_attribute *attr,
2027 struct amdgpu_device *adev = dev_get_drvdata(dev);
2028 int channel = to_sensor_dev_attr(attr)->index;
2029 int r, temp = 0, size = sizeof(temp);
2031 if (amdgpu_in_reset(adev))
2033 if (adev->in_suspend && !adev->in_runpm)
2036 if (channel >= PP_TEMP_MAX)
2039 r = pm_runtime_get_sync(adev_to_drm(adev)->dev);
2041 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2046 case PP_TEMP_JUNCTION:
2047 /* get current junction temperature */
2048 r = amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_HOTSPOT_TEMP,
2049 (void *)&temp, &size);
2052 /* get current edge temperature */
2053 r = amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_EDGE_TEMP,
2054 (void *)&temp, &size);
2057 /* get current memory temperature */
2058 r = amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_MEM_TEMP,
2059 (void *)&temp, &size);
2066 pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
2067 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2072 return sysfs_emit(buf, "%d\n", temp);
2075 static ssize_t amdgpu_hwmon_show_temp_thresh(struct device *dev,
2076 struct device_attribute *attr,
2079 struct amdgpu_device *adev = dev_get_drvdata(dev);
2080 int hyst = to_sensor_dev_attr(attr)->index;
2084 temp = adev->pm.dpm.thermal.min_temp;
2086 temp = adev->pm.dpm.thermal.max_temp;
2088 return sysfs_emit(buf, "%d\n", temp);
2091 static ssize_t amdgpu_hwmon_show_hotspot_temp_thresh(struct device *dev,
2092 struct device_attribute *attr,
2095 struct amdgpu_device *adev = dev_get_drvdata(dev);
2096 int hyst = to_sensor_dev_attr(attr)->index;
2100 temp = adev->pm.dpm.thermal.min_hotspot_temp;
2102 temp = adev->pm.dpm.thermal.max_hotspot_crit_temp;
2104 return sysfs_emit(buf, "%d\n", temp);
2107 static ssize_t amdgpu_hwmon_show_mem_temp_thresh(struct device *dev,
2108 struct device_attribute *attr,
2111 struct amdgpu_device *adev = dev_get_drvdata(dev);
2112 int hyst = to_sensor_dev_attr(attr)->index;
2116 temp = adev->pm.dpm.thermal.min_mem_temp;
2118 temp = adev->pm.dpm.thermal.max_mem_crit_temp;
2120 return sysfs_emit(buf, "%d\n", temp);
2123 static ssize_t amdgpu_hwmon_show_temp_label(struct device *dev,
2124 struct device_attribute *attr,
2127 int channel = to_sensor_dev_attr(attr)->index;
2129 if (channel >= PP_TEMP_MAX)
2132 return sysfs_emit(buf, "%s\n", temp_label[channel].label);
2135 static ssize_t amdgpu_hwmon_show_temp_emergency(struct device *dev,
2136 struct device_attribute *attr,
2139 struct amdgpu_device *adev = dev_get_drvdata(dev);
2140 int channel = to_sensor_dev_attr(attr)->index;
2143 if (channel >= PP_TEMP_MAX)
2147 case PP_TEMP_JUNCTION:
2148 temp = adev->pm.dpm.thermal.max_hotspot_emergency_temp;
2151 temp = adev->pm.dpm.thermal.max_edge_emergency_temp;
2154 temp = adev->pm.dpm.thermal.max_mem_emergency_temp;
2158 return sysfs_emit(buf, "%d\n", temp);
2161 static ssize_t amdgpu_hwmon_get_pwm1_enable(struct device *dev,
2162 struct device_attribute *attr,
2165 struct amdgpu_device *adev = dev_get_drvdata(dev);
2169 if (amdgpu_in_reset(adev))
2171 if (adev->in_suspend && !adev->in_runpm)
2174 ret = pm_runtime_get_sync(adev_to_drm(adev)->dev);
2176 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2180 if (!adev->powerplay.pp_funcs->get_fan_control_mode) {
2181 pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
2182 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2186 pwm_mode = amdgpu_dpm_get_fan_control_mode(adev);
2188 pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
2189 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2191 return sprintf(buf, "%u\n", pwm_mode);
2194 static ssize_t amdgpu_hwmon_set_pwm1_enable(struct device *dev,
2195 struct device_attribute *attr,
2199 struct amdgpu_device *adev = dev_get_drvdata(dev);
2203 if (amdgpu_in_reset(adev))
2205 if (adev->in_suspend && !adev->in_runpm)
2208 err = kstrtoint(buf, 10, &value);
2212 ret = pm_runtime_get_sync(adev_to_drm(adev)->dev);
2214 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2218 if (!adev->powerplay.pp_funcs->set_fan_control_mode) {
2219 pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
2220 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2224 amdgpu_dpm_set_fan_control_mode(adev, value);
2226 pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
2227 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2232 static ssize_t amdgpu_hwmon_get_pwm1_min(struct device *dev,
2233 struct device_attribute *attr,
2236 return sprintf(buf, "%i\n", 0);
2239 static ssize_t amdgpu_hwmon_get_pwm1_max(struct device *dev,
2240 struct device_attribute *attr,
2243 return sprintf(buf, "%i\n", 255);
2246 static ssize_t amdgpu_hwmon_set_pwm1(struct device *dev,
2247 struct device_attribute *attr,
2248 const char *buf, size_t count)
2250 struct amdgpu_device *adev = dev_get_drvdata(dev);
2255 if (amdgpu_in_reset(adev))
2257 if (adev->in_suspend && !adev->in_runpm)
2260 err = pm_runtime_get_sync(adev_to_drm(adev)->dev);
2262 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2266 pwm_mode = amdgpu_dpm_get_fan_control_mode(adev);
2267 if (pwm_mode != AMD_FAN_CTRL_MANUAL) {
2268 pr_info("manual fan speed control should be enabled first\n");
2269 pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
2270 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2274 err = kstrtou32(buf, 10, &value);
2276 pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
2277 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2281 value = (value * 100) / 255;
2283 if (adev->powerplay.pp_funcs->set_fan_speed_percent)
2284 err = amdgpu_dpm_set_fan_speed_percent(adev, value);
2288 pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
2289 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2297 static ssize_t amdgpu_hwmon_get_pwm1(struct device *dev,
2298 struct device_attribute *attr,
2301 struct amdgpu_device *adev = dev_get_drvdata(dev);
2305 if (amdgpu_in_reset(adev))
2307 if (adev->in_suspend && !adev->in_runpm)
2310 err = pm_runtime_get_sync(adev_to_drm(adev)->dev);
2312 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2316 if (adev->powerplay.pp_funcs->get_fan_speed_percent)
2317 err = amdgpu_dpm_get_fan_speed_percent(adev, &speed);
2321 pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
2322 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2327 speed = (speed * 255) / 100;
2329 return sprintf(buf, "%i\n", speed);
2332 static ssize_t amdgpu_hwmon_get_fan1_input(struct device *dev,
2333 struct device_attribute *attr,
2336 struct amdgpu_device *adev = dev_get_drvdata(dev);
2340 if (amdgpu_in_reset(adev))
2342 if (adev->in_suspend && !adev->in_runpm)
2345 err = pm_runtime_get_sync(adev_to_drm(adev)->dev);
2347 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2351 if (adev->powerplay.pp_funcs->get_fan_speed_rpm)
2352 err = amdgpu_dpm_get_fan_speed_rpm(adev, &speed);
2356 pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
2357 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2362 return sprintf(buf, "%i\n", speed);
2365 static ssize_t amdgpu_hwmon_get_fan1_min(struct device *dev,
2366 struct device_attribute *attr,
2369 struct amdgpu_device *adev = dev_get_drvdata(dev);
2371 u32 size = sizeof(min_rpm);
2374 if (amdgpu_in_reset(adev))
2376 if (adev->in_suspend && !adev->in_runpm)
2379 r = pm_runtime_get_sync(adev_to_drm(adev)->dev);
2381 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2385 r = amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_MIN_FAN_RPM,
2386 (void *)&min_rpm, &size);
2388 pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
2389 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2394 return sysfs_emit(buf, "%d\n", min_rpm);
2397 static ssize_t amdgpu_hwmon_get_fan1_max(struct device *dev,
2398 struct device_attribute *attr,
2401 struct amdgpu_device *adev = dev_get_drvdata(dev);
2403 u32 size = sizeof(max_rpm);
2406 if (amdgpu_in_reset(adev))
2408 if (adev->in_suspend && !adev->in_runpm)
2411 r = pm_runtime_get_sync(adev_to_drm(adev)->dev);
2413 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2417 r = amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_MAX_FAN_RPM,
2418 (void *)&max_rpm, &size);
2420 pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
2421 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2426 return sysfs_emit(buf, "%d\n", max_rpm);
2429 static ssize_t amdgpu_hwmon_get_fan1_target(struct device *dev,
2430 struct device_attribute *attr,
2433 struct amdgpu_device *adev = dev_get_drvdata(dev);
2437 if (amdgpu_in_reset(adev))
2439 if (adev->in_suspend && !adev->in_runpm)
2442 err = pm_runtime_get_sync(adev_to_drm(adev)->dev);
2444 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2448 if (adev->powerplay.pp_funcs->get_fan_speed_rpm)
2449 err = amdgpu_dpm_get_fan_speed_rpm(adev, &rpm);
2453 pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
2454 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2459 return sprintf(buf, "%i\n", rpm);
2462 static ssize_t amdgpu_hwmon_set_fan1_target(struct device *dev,
2463 struct device_attribute *attr,
2464 const char *buf, size_t count)
2466 struct amdgpu_device *adev = dev_get_drvdata(dev);
2471 if (amdgpu_in_reset(adev))
2473 if (adev->in_suspend && !adev->in_runpm)
2476 err = pm_runtime_get_sync(adev_to_drm(adev)->dev);
2478 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2482 pwm_mode = amdgpu_dpm_get_fan_control_mode(adev);
2484 if (pwm_mode != AMD_FAN_CTRL_MANUAL) {
2485 pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
2486 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2490 err = kstrtou32(buf, 10, &value);
2492 pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
2493 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2497 if (adev->powerplay.pp_funcs->set_fan_speed_rpm)
2498 err = amdgpu_dpm_set_fan_speed_rpm(adev, value);
2502 pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
2503 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2511 static ssize_t amdgpu_hwmon_get_fan1_enable(struct device *dev,
2512 struct device_attribute *attr,
2515 struct amdgpu_device *adev = dev_get_drvdata(dev);
2519 if (amdgpu_in_reset(adev))
2521 if (adev->in_suspend && !adev->in_runpm)
2524 ret = pm_runtime_get_sync(adev_to_drm(adev)->dev);
2526 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2530 if (!adev->powerplay.pp_funcs->get_fan_control_mode) {
2531 pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
2532 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2536 pwm_mode = amdgpu_dpm_get_fan_control_mode(adev);
2538 pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
2539 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2541 return sprintf(buf, "%i\n", pwm_mode == AMD_FAN_CTRL_AUTO ? 0 : 1);
2544 static ssize_t amdgpu_hwmon_set_fan1_enable(struct device *dev,
2545 struct device_attribute *attr,
2549 struct amdgpu_device *adev = dev_get_drvdata(dev);
2554 if (amdgpu_in_reset(adev))
2556 if (adev->in_suspend && !adev->in_runpm)
2559 err = kstrtoint(buf, 10, &value);
2564 pwm_mode = AMD_FAN_CTRL_AUTO;
2565 else if (value == 1)
2566 pwm_mode = AMD_FAN_CTRL_MANUAL;
2570 err = pm_runtime_get_sync(adev_to_drm(adev)->dev);
2572 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2576 if (!adev->powerplay.pp_funcs->set_fan_control_mode) {
2577 pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
2578 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2581 amdgpu_dpm_set_fan_control_mode(adev, pwm_mode);
2583 pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
2584 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2589 static ssize_t amdgpu_hwmon_show_vddgfx(struct device *dev,
2590 struct device_attribute *attr,
2593 struct amdgpu_device *adev = dev_get_drvdata(dev);
2595 int r, size = sizeof(vddgfx);
2597 if (amdgpu_in_reset(adev))
2599 if (adev->in_suspend && !adev->in_runpm)
2602 r = pm_runtime_get_sync(adev_to_drm(adev)->dev);
2604 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2608 /* get the voltage */
2609 r = amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_VDDGFX,
2610 (void *)&vddgfx, &size);
2612 pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
2613 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2618 return sysfs_emit(buf, "%d\n", vddgfx);
2621 static ssize_t amdgpu_hwmon_show_vddgfx_label(struct device *dev,
2622 struct device_attribute *attr,
2625 return sysfs_emit(buf, "vddgfx\n");
2628 static ssize_t amdgpu_hwmon_show_vddnb(struct device *dev,
2629 struct device_attribute *attr,
2632 struct amdgpu_device *adev = dev_get_drvdata(dev);
2634 int r, size = sizeof(vddnb);
2636 if (amdgpu_in_reset(adev))
2638 if (adev->in_suspend && !adev->in_runpm)
2641 /* only APUs have vddnb */
2642 if (!(adev->flags & AMD_IS_APU))
2645 r = pm_runtime_get_sync(adev_to_drm(adev)->dev);
2647 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2651 /* get the voltage */
2652 r = amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_VDDNB,
2653 (void *)&vddnb, &size);
2655 pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
2656 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2661 return sysfs_emit(buf, "%d\n", vddnb);
2664 static ssize_t amdgpu_hwmon_show_vddnb_label(struct device *dev,
2665 struct device_attribute *attr,
2668 return sysfs_emit(buf, "vddnb\n");
2671 static ssize_t amdgpu_hwmon_show_power_avg(struct device *dev,
2672 struct device_attribute *attr,
2675 struct amdgpu_device *adev = dev_get_drvdata(dev);
2677 int r, size = sizeof(u32);
2680 if (amdgpu_in_reset(adev))
2682 if (adev->in_suspend && !adev->in_runpm)
2685 r = pm_runtime_get_sync(adev_to_drm(adev)->dev);
2687 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2691 /* get the voltage */
2692 r = amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GPU_POWER,
2693 (void *)&query, &size);
2695 pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
2696 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2701 /* convert to microwatts */
2702 uw = (query >> 8) * 1000000 + (query & 0xff) * 1000;
2704 return sysfs_emit(buf, "%u\n", uw);
2707 static ssize_t amdgpu_hwmon_show_power_cap_min(struct device *dev,
2708 struct device_attribute *attr,
2711 return sprintf(buf, "%i\n", 0);
2714 static ssize_t amdgpu_hwmon_show_power_cap_max(struct device *dev,
2715 struct device_attribute *attr,
2718 struct amdgpu_device *adev = dev_get_drvdata(dev);
2719 const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
2720 int limit_type = to_sensor_dev_attr(attr)->index;
2721 uint32_t limit = limit_type << 24;
2722 uint32_t max_limit = 0;
2726 if (amdgpu_in_reset(adev))
2728 if (adev->in_suspend && !adev->in_runpm)
2731 r = pm_runtime_get_sync(adev_to_drm(adev)->dev);
2733 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2737 if (is_support_sw_smu(adev)) {
2738 smu_get_power_limit(&adev->smu, &limit, SMU_PPT_LIMIT_MAX);
2739 size = snprintf(buf, PAGE_SIZE, "%u\n", limit * 1000000);
2740 } else if (pp_funcs && pp_funcs->get_power_limit) {
2741 pp_funcs->get_power_limit(adev->powerplay.pp_handle,
2742 &limit, &max_limit, true);
2743 size = snprintf(buf, PAGE_SIZE, "%u\n", max_limit * 1000000);
2745 size = snprintf(buf, PAGE_SIZE, "\n");
2748 pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
2749 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2754 static ssize_t amdgpu_hwmon_show_power_cap(struct device *dev,
2755 struct device_attribute *attr,
2758 struct amdgpu_device *adev = dev_get_drvdata(dev);
2759 const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
2760 int limit_type = to_sensor_dev_attr(attr)->index;
2761 uint32_t limit = limit_type << 24;
2765 if (amdgpu_in_reset(adev))
2767 if (adev->in_suspend && !adev->in_runpm)
2770 r = pm_runtime_get_sync(adev_to_drm(adev)->dev);
2772 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2776 if (is_support_sw_smu(adev)) {
2777 smu_get_power_limit(&adev->smu, &limit, SMU_PPT_LIMIT_CURRENT);
2778 size = snprintf(buf, PAGE_SIZE, "%u\n", limit * 1000000);
2779 } else if (pp_funcs && pp_funcs->get_power_limit) {
2780 pp_funcs->get_power_limit(adev->powerplay.pp_handle,
2781 &limit, NULL, false);
2782 size = snprintf(buf, PAGE_SIZE, "%u\n", limit * 1000000);
2784 size = snprintf(buf, PAGE_SIZE, "\n");
2787 pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
2788 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2793 static ssize_t amdgpu_hwmon_show_power_cap_default(struct device *dev,
2794 struct device_attribute *attr,
2797 struct amdgpu_device *adev = dev_get_drvdata(dev);
2798 const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
2799 int limit_type = to_sensor_dev_attr(attr)->index;
2800 uint32_t limit = limit_type << 24;
2804 if (amdgpu_in_reset(adev))
2806 if (adev->in_suspend && !adev->in_runpm)
2809 r = pm_runtime_get_sync(adev_to_drm(adev)->dev);
2811 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2815 if (is_support_sw_smu(adev)) {
2816 smu_get_power_limit(&adev->smu, &limit, SMU_PPT_LIMIT_DEFAULT);
2817 size = snprintf(buf, PAGE_SIZE, "%u\n", limit * 1000000);
2818 } else if (pp_funcs && pp_funcs->get_power_limit) {
2819 pp_funcs->get_power_limit(adev->powerplay.pp_handle,
2820 &limit, NULL, true);
2821 size = snprintf(buf, PAGE_SIZE, "%u\n", limit * 1000000);
2823 size = snprintf(buf, PAGE_SIZE, "\n");
2826 pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
2827 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2831 static ssize_t amdgpu_hwmon_show_power_label(struct device *dev,
2832 struct device_attribute *attr,
2835 int limit_type = to_sensor_dev_attr(attr)->index;
2837 return sysfs_emit(buf, "%s\n",
2838 limit_type == SMU_FAST_PPT_LIMIT ? "fastPPT" : "slowPPT");
2841 static ssize_t amdgpu_hwmon_set_power_cap(struct device *dev,
2842 struct device_attribute *attr,
2846 struct amdgpu_device *adev = dev_get_drvdata(dev);
2847 const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
2848 int limit_type = to_sensor_dev_attr(attr)->index;
2852 if (amdgpu_in_reset(adev))
2854 if (adev->in_suspend && !adev->in_runpm)
2857 if (amdgpu_sriov_vf(adev))
2860 err = kstrtou32(buf, 10, &value);
2864 value = value / 1000000; /* convert to Watt */
2865 value |= limit_type << 24;
2867 err = pm_runtime_get_sync(adev_to_drm(adev)->dev);
2869 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2873 if (pp_funcs && pp_funcs->set_power_limit)
2874 err = pp_funcs->set_power_limit(adev->powerplay.pp_handle, value);
2878 pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
2879 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2887 static ssize_t amdgpu_hwmon_show_sclk(struct device *dev,
2888 struct device_attribute *attr,
2891 struct amdgpu_device *adev = dev_get_drvdata(dev);
2893 int r, size = sizeof(sclk);
2895 if (amdgpu_in_reset(adev))
2897 if (adev->in_suspend && !adev->in_runpm)
2900 r = pm_runtime_get_sync(adev_to_drm(adev)->dev);
2902 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2907 r = amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GFX_SCLK,
2908 (void *)&sclk, &size);
2910 pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
2911 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2916 return sysfs_emit(buf, "%u\n", sclk * 10 * 1000);
2919 static ssize_t amdgpu_hwmon_show_sclk_label(struct device *dev,
2920 struct device_attribute *attr,
2923 return sysfs_emit(buf, "sclk\n");
2926 static ssize_t amdgpu_hwmon_show_mclk(struct device *dev,
2927 struct device_attribute *attr,
2930 struct amdgpu_device *adev = dev_get_drvdata(dev);
2932 int r, size = sizeof(mclk);
2934 if (amdgpu_in_reset(adev))
2936 if (adev->in_suspend && !adev->in_runpm)
2939 r = pm_runtime_get_sync(adev_to_drm(adev)->dev);
2941 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2946 r = amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GFX_MCLK,
2947 (void *)&mclk, &size);
2949 pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
2950 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2955 return sysfs_emit(buf, "%u\n", mclk * 10 * 1000);
2958 static ssize_t amdgpu_hwmon_show_mclk_label(struct device *dev,
2959 struct device_attribute *attr,
2962 return sysfs_emit(buf, "mclk\n");
2968 * The amdgpu driver exposes the following sensor interfaces:
2970 * - GPU temperature (via the on-die sensor)
2974 * - Northbridge voltage (APUs only)
2980 * - GPU gfx/compute engine clock
2982 * - GPU memory clock (dGPU only)
2984 * hwmon interfaces for GPU temperature:
2986 * - temp[1-3]_input: the on die GPU temperature in millidegrees Celsius
2987 * - temp2_input and temp3_input are supported on SOC15 dGPUs only
2989 * - temp[1-3]_label: temperature channel label
2990 * - temp2_label and temp3_label are supported on SOC15 dGPUs only
2992 * - temp[1-3]_crit: temperature critical max value in millidegrees Celsius
2993 * - temp2_crit and temp3_crit are supported on SOC15 dGPUs only
2995 * - temp[1-3]_crit_hyst: temperature hysteresis for critical limit in millidegrees Celsius
2996 * - temp2_crit_hyst and temp3_crit_hyst are supported on SOC15 dGPUs only
2998 * - temp[1-3]_emergency: temperature emergency max value(asic shutdown) in millidegrees Celsius
2999 * - these are supported on SOC15 dGPUs only
3001 * hwmon interfaces for GPU voltage:
3003 * - in0_input: the voltage on the GPU in millivolts
3005 * - in1_input: the voltage on the Northbridge in millivolts
3007 * hwmon interfaces for GPU power:
3009 * - power1_average: average power used by the GPU in microWatts
3011 * - power1_cap_min: minimum cap supported in microWatts
3013 * - power1_cap_max: maximum cap supported in microWatts
3015 * - power1_cap: selected power cap in microWatts
3017 * hwmon interfaces for GPU fan:
3019 * - pwm1: pulse width modulation fan level (0-255)
3021 * - 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)
3023 * - pwm1_min: pulse width modulation fan control minimum level (0)
3025 * - pwm1_max: pulse width modulation fan control maximum level (255)
3027 * - fan1_min: a minimum value Unit: revolution/min (RPM)
3029 * - fan1_max: a maximum value Unit: revolution/max (RPM)
3031 * - fan1_input: fan speed in RPM
3033 * - fan[1-\*]_target: Desired fan speed Unit: revolution/min (RPM)
3035 * - fan[1-\*]_enable: Enable or disable the sensors.1: Enable 0: Disable
3037 * hwmon interfaces for GPU clocks:
3039 * - freq1_input: the gfx/compute clock in hertz
3041 * - freq2_input: the memory clock in hertz
3043 * You can use hwmon tools like sensors to view this information on your system.
3047 static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, amdgpu_hwmon_show_temp, NULL, PP_TEMP_EDGE);
3048 static SENSOR_DEVICE_ATTR(temp1_crit, S_IRUGO, amdgpu_hwmon_show_temp_thresh, NULL, 0);
3049 static SENSOR_DEVICE_ATTR(temp1_crit_hyst, S_IRUGO, amdgpu_hwmon_show_temp_thresh, NULL, 1);
3050 static SENSOR_DEVICE_ATTR(temp1_emergency, S_IRUGO, amdgpu_hwmon_show_temp_emergency, NULL, PP_TEMP_EDGE);
3051 static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, amdgpu_hwmon_show_temp, NULL, PP_TEMP_JUNCTION);
3052 static SENSOR_DEVICE_ATTR(temp2_crit, S_IRUGO, amdgpu_hwmon_show_hotspot_temp_thresh, NULL, 0);
3053 static SENSOR_DEVICE_ATTR(temp2_crit_hyst, S_IRUGO, amdgpu_hwmon_show_hotspot_temp_thresh, NULL, 1);
3054 static SENSOR_DEVICE_ATTR(temp2_emergency, S_IRUGO, amdgpu_hwmon_show_temp_emergency, NULL, PP_TEMP_JUNCTION);
3055 static SENSOR_DEVICE_ATTR(temp3_input, S_IRUGO, amdgpu_hwmon_show_temp, NULL, PP_TEMP_MEM);
3056 static SENSOR_DEVICE_ATTR(temp3_crit, S_IRUGO, amdgpu_hwmon_show_mem_temp_thresh, NULL, 0);
3057 static SENSOR_DEVICE_ATTR(temp3_crit_hyst, S_IRUGO, amdgpu_hwmon_show_mem_temp_thresh, NULL, 1);
3058 static SENSOR_DEVICE_ATTR(temp3_emergency, S_IRUGO, amdgpu_hwmon_show_temp_emergency, NULL, PP_TEMP_MEM);
3059 static SENSOR_DEVICE_ATTR(temp1_label, S_IRUGO, amdgpu_hwmon_show_temp_label, NULL, PP_TEMP_EDGE);
3060 static SENSOR_DEVICE_ATTR(temp2_label, S_IRUGO, amdgpu_hwmon_show_temp_label, NULL, PP_TEMP_JUNCTION);
3061 static SENSOR_DEVICE_ATTR(temp3_label, S_IRUGO, amdgpu_hwmon_show_temp_label, NULL, PP_TEMP_MEM);
3062 static SENSOR_DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, amdgpu_hwmon_get_pwm1, amdgpu_hwmon_set_pwm1, 0);
3063 static SENSOR_DEVICE_ATTR(pwm1_enable, S_IRUGO | S_IWUSR, amdgpu_hwmon_get_pwm1_enable, amdgpu_hwmon_set_pwm1_enable, 0);
3064 static SENSOR_DEVICE_ATTR(pwm1_min, S_IRUGO, amdgpu_hwmon_get_pwm1_min, NULL, 0);
3065 static SENSOR_DEVICE_ATTR(pwm1_max, S_IRUGO, amdgpu_hwmon_get_pwm1_max, NULL, 0);
3066 static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, amdgpu_hwmon_get_fan1_input, NULL, 0);
3067 static SENSOR_DEVICE_ATTR(fan1_min, S_IRUGO, amdgpu_hwmon_get_fan1_min, NULL, 0);
3068 static SENSOR_DEVICE_ATTR(fan1_max, S_IRUGO, amdgpu_hwmon_get_fan1_max, NULL, 0);
3069 static SENSOR_DEVICE_ATTR(fan1_target, S_IRUGO | S_IWUSR, amdgpu_hwmon_get_fan1_target, amdgpu_hwmon_set_fan1_target, 0);
3070 static SENSOR_DEVICE_ATTR(fan1_enable, S_IRUGO | S_IWUSR, amdgpu_hwmon_get_fan1_enable, amdgpu_hwmon_set_fan1_enable, 0);
3071 static SENSOR_DEVICE_ATTR(in0_input, S_IRUGO, amdgpu_hwmon_show_vddgfx, NULL, 0);
3072 static SENSOR_DEVICE_ATTR(in0_label, S_IRUGO, amdgpu_hwmon_show_vddgfx_label, NULL, 0);
3073 static SENSOR_DEVICE_ATTR(in1_input, S_IRUGO, amdgpu_hwmon_show_vddnb, NULL, 0);
3074 static SENSOR_DEVICE_ATTR(in1_label, S_IRUGO, amdgpu_hwmon_show_vddnb_label, NULL, 0);
3075 static SENSOR_DEVICE_ATTR(power1_average, S_IRUGO, amdgpu_hwmon_show_power_avg, NULL, 0);
3076 static SENSOR_DEVICE_ATTR(power1_cap_max, S_IRUGO, amdgpu_hwmon_show_power_cap_max, NULL, 0);
3077 static SENSOR_DEVICE_ATTR(power1_cap_min, S_IRUGO, amdgpu_hwmon_show_power_cap_min, NULL, 0);
3078 static SENSOR_DEVICE_ATTR(power1_cap, S_IRUGO | S_IWUSR, amdgpu_hwmon_show_power_cap, amdgpu_hwmon_set_power_cap, 0);
3079 static SENSOR_DEVICE_ATTR(power1_cap_default, S_IRUGO, amdgpu_hwmon_show_power_cap_default, NULL, 0);
3080 static SENSOR_DEVICE_ATTR(power1_label, S_IRUGO, amdgpu_hwmon_show_power_label, NULL, 0);
3081 static SENSOR_DEVICE_ATTR(power2_average, S_IRUGO, amdgpu_hwmon_show_power_avg, NULL, 1);
3082 static SENSOR_DEVICE_ATTR(power2_cap_max, S_IRUGO, amdgpu_hwmon_show_power_cap_max, NULL, 1);
3083 static SENSOR_DEVICE_ATTR(power2_cap_min, S_IRUGO, amdgpu_hwmon_show_power_cap_min, NULL, 1);
3084 static SENSOR_DEVICE_ATTR(power2_cap, S_IRUGO | S_IWUSR, amdgpu_hwmon_show_power_cap, amdgpu_hwmon_set_power_cap, 1);
3085 static SENSOR_DEVICE_ATTR(power2_cap_default, S_IRUGO, amdgpu_hwmon_show_power_cap_default, NULL, 1);
3086 static SENSOR_DEVICE_ATTR(power2_label, S_IRUGO, amdgpu_hwmon_show_power_label, NULL, 1);
3087 static SENSOR_DEVICE_ATTR(freq1_input, S_IRUGO, amdgpu_hwmon_show_sclk, NULL, 0);
3088 static SENSOR_DEVICE_ATTR(freq1_label, S_IRUGO, amdgpu_hwmon_show_sclk_label, NULL, 0);
3089 static SENSOR_DEVICE_ATTR(freq2_input, S_IRUGO, amdgpu_hwmon_show_mclk, NULL, 0);
3090 static SENSOR_DEVICE_ATTR(freq2_label, S_IRUGO, amdgpu_hwmon_show_mclk_label, NULL, 0);
3092 static struct attribute *hwmon_attributes[] = {
3093 &sensor_dev_attr_temp1_input.dev_attr.attr,
3094 &sensor_dev_attr_temp1_crit.dev_attr.attr,
3095 &sensor_dev_attr_temp1_crit_hyst.dev_attr.attr,
3096 &sensor_dev_attr_temp2_input.dev_attr.attr,
3097 &sensor_dev_attr_temp2_crit.dev_attr.attr,
3098 &sensor_dev_attr_temp2_crit_hyst.dev_attr.attr,
3099 &sensor_dev_attr_temp3_input.dev_attr.attr,
3100 &sensor_dev_attr_temp3_crit.dev_attr.attr,
3101 &sensor_dev_attr_temp3_crit_hyst.dev_attr.attr,
3102 &sensor_dev_attr_temp1_emergency.dev_attr.attr,
3103 &sensor_dev_attr_temp2_emergency.dev_attr.attr,
3104 &sensor_dev_attr_temp3_emergency.dev_attr.attr,
3105 &sensor_dev_attr_temp1_label.dev_attr.attr,
3106 &sensor_dev_attr_temp2_label.dev_attr.attr,
3107 &sensor_dev_attr_temp3_label.dev_attr.attr,
3108 &sensor_dev_attr_pwm1.dev_attr.attr,
3109 &sensor_dev_attr_pwm1_enable.dev_attr.attr,
3110 &sensor_dev_attr_pwm1_min.dev_attr.attr,
3111 &sensor_dev_attr_pwm1_max.dev_attr.attr,
3112 &sensor_dev_attr_fan1_input.dev_attr.attr,
3113 &sensor_dev_attr_fan1_min.dev_attr.attr,
3114 &sensor_dev_attr_fan1_max.dev_attr.attr,
3115 &sensor_dev_attr_fan1_target.dev_attr.attr,
3116 &sensor_dev_attr_fan1_enable.dev_attr.attr,
3117 &sensor_dev_attr_in0_input.dev_attr.attr,
3118 &sensor_dev_attr_in0_label.dev_attr.attr,
3119 &sensor_dev_attr_in1_input.dev_attr.attr,
3120 &sensor_dev_attr_in1_label.dev_attr.attr,
3121 &sensor_dev_attr_power1_average.dev_attr.attr,
3122 &sensor_dev_attr_power1_cap_max.dev_attr.attr,
3123 &sensor_dev_attr_power1_cap_min.dev_attr.attr,
3124 &sensor_dev_attr_power1_cap.dev_attr.attr,
3125 &sensor_dev_attr_power1_cap_default.dev_attr.attr,
3126 &sensor_dev_attr_power1_label.dev_attr.attr,
3127 &sensor_dev_attr_power2_average.dev_attr.attr,
3128 &sensor_dev_attr_power2_cap_max.dev_attr.attr,
3129 &sensor_dev_attr_power2_cap_min.dev_attr.attr,
3130 &sensor_dev_attr_power2_cap.dev_attr.attr,
3131 &sensor_dev_attr_power2_cap_default.dev_attr.attr,
3132 &sensor_dev_attr_power2_label.dev_attr.attr,
3133 &sensor_dev_attr_freq1_input.dev_attr.attr,
3134 &sensor_dev_attr_freq1_label.dev_attr.attr,
3135 &sensor_dev_attr_freq2_input.dev_attr.attr,
3136 &sensor_dev_attr_freq2_label.dev_attr.attr,
3140 static umode_t hwmon_attributes_visible(struct kobject *kobj,
3141 struct attribute *attr, int index)
3143 struct device *dev = kobj_to_dev(kobj);
3144 struct amdgpu_device *adev = dev_get_drvdata(dev);
3145 umode_t effective_mode = attr->mode;
3147 /* under multi-vf mode, the hwmon attributes are all not supported */
3148 if (amdgpu_sriov_vf(adev) && !amdgpu_sriov_is_pp_one_vf(adev))
3151 /* there is no fan under pp one vf mode */
3152 if (amdgpu_sriov_is_pp_one_vf(adev) &&
3153 (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 if fan is not present */
3165 if (adev->pm.no_fan && (attr == &sensor_dev_attr_pwm1.dev_attr.attr ||
3166 attr == &sensor_dev_attr_pwm1_enable.dev_attr.attr ||
3167 attr == &sensor_dev_attr_pwm1_max.dev_attr.attr ||
3168 attr == &sensor_dev_attr_pwm1_min.dev_attr.attr ||
3169 attr == &sensor_dev_attr_fan1_input.dev_attr.attr ||
3170 attr == &sensor_dev_attr_fan1_min.dev_attr.attr ||
3171 attr == &sensor_dev_attr_fan1_max.dev_attr.attr ||
3172 attr == &sensor_dev_attr_fan1_target.dev_attr.attr ||
3173 attr == &sensor_dev_attr_fan1_enable.dev_attr.attr))
3176 /* Skip fan attributes on APU */
3177 if ((adev->flags & AMD_IS_APU) &&
3178 (attr == &sensor_dev_attr_pwm1.dev_attr.attr ||
3179 attr == &sensor_dev_attr_pwm1_enable.dev_attr.attr ||
3180 attr == &sensor_dev_attr_pwm1_max.dev_attr.attr ||
3181 attr == &sensor_dev_attr_pwm1_min.dev_attr.attr ||
3182 attr == &sensor_dev_attr_fan1_input.dev_attr.attr ||
3183 attr == &sensor_dev_attr_fan1_min.dev_attr.attr ||
3184 attr == &sensor_dev_attr_fan1_max.dev_attr.attr ||
3185 attr == &sensor_dev_attr_fan1_target.dev_attr.attr ||
3186 attr == &sensor_dev_attr_fan1_enable.dev_attr.attr))
3189 /* Skip crit temp on APU */
3190 if ((adev->flags & AMD_IS_APU) && (adev->family >= AMDGPU_FAMILY_CZ) &&
3191 (attr == &sensor_dev_attr_temp1_crit.dev_attr.attr ||
3192 attr == &sensor_dev_attr_temp1_crit_hyst.dev_attr.attr))
3195 /* Skip limit attributes if DPM is not enabled */
3196 if (!adev->pm.dpm_enabled &&
3197 (attr == &sensor_dev_attr_temp1_crit.dev_attr.attr ||
3198 attr == &sensor_dev_attr_temp1_crit_hyst.dev_attr.attr ||
3199 attr == &sensor_dev_attr_pwm1.dev_attr.attr ||
3200 attr == &sensor_dev_attr_pwm1_enable.dev_attr.attr ||
3201 attr == &sensor_dev_attr_pwm1_max.dev_attr.attr ||
3202 attr == &sensor_dev_attr_pwm1_min.dev_attr.attr ||
3203 attr == &sensor_dev_attr_fan1_input.dev_attr.attr ||
3204 attr == &sensor_dev_attr_fan1_min.dev_attr.attr ||
3205 attr == &sensor_dev_attr_fan1_max.dev_attr.attr ||
3206 attr == &sensor_dev_attr_fan1_target.dev_attr.attr ||
3207 attr == &sensor_dev_attr_fan1_enable.dev_attr.attr))
3210 if (!is_support_sw_smu(adev)) {
3211 /* mask fan attributes if we have no bindings for this asic to expose */
3212 if ((!adev->powerplay.pp_funcs->get_fan_speed_percent &&
3213 attr == &sensor_dev_attr_pwm1.dev_attr.attr) || /* can't query fan */
3214 (!adev->powerplay.pp_funcs->get_fan_control_mode &&
3215 attr == &sensor_dev_attr_pwm1_enable.dev_attr.attr)) /* can't query state */
3216 effective_mode &= ~S_IRUGO;
3218 if ((!adev->powerplay.pp_funcs->set_fan_speed_percent &&
3219 attr == &sensor_dev_attr_pwm1.dev_attr.attr) || /* can't manage fan */
3220 (!adev->powerplay.pp_funcs->set_fan_control_mode &&
3221 attr == &sensor_dev_attr_pwm1_enable.dev_attr.attr)) /* can't manage state */
3222 effective_mode &= ~S_IWUSR;
3225 if (((adev->family == AMDGPU_FAMILY_SI) ||
3226 ((adev->flags & AMD_IS_APU) &&
3227 (adev->asic_type != CHIP_VANGOGH))) && /* not implemented yet */
3228 (attr == &sensor_dev_attr_power1_cap_max.dev_attr.attr ||
3229 attr == &sensor_dev_attr_power1_cap_min.dev_attr.attr||
3230 attr == &sensor_dev_attr_power1_cap.dev_attr.attr ||
3231 attr == &sensor_dev_attr_power1_cap_default.dev_attr.attr))
3234 if (((adev->family == AMDGPU_FAMILY_SI) ||
3235 ((adev->flags & AMD_IS_APU) &&
3236 (adev->asic_type < CHIP_RENOIR))) && /* not implemented yet */
3237 (attr == &sensor_dev_attr_power1_average.dev_attr.attr))
3240 if (!is_support_sw_smu(adev)) {
3241 /* hide max/min values if we can't both query and manage the fan */
3242 if ((!adev->powerplay.pp_funcs->set_fan_speed_percent &&
3243 !adev->powerplay.pp_funcs->get_fan_speed_percent) &&
3244 (!adev->powerplay.pp_funcs->set_fan_speed_rpm &&
3245 !adev->powerplay.pp_funcs->get_fan_speed_rpm) &&
3246 (attr == &sensor_dev_attr_pwm1_max.dev_attr.attr ||
3247 attr == &sensor_dev_attr_pwm1_min.dev_attr.attr))
3250 if ((!adev->powerplay.pp_funcs->set_fan_speed_rpm &&
3251 !adev->powerplay.pp_funcs->get_fan_speed_rpm) &&
3252 (attr == &sensor_dev_attr_fan1_max.dev_attr.attr ||
3253 attr == &sensor_dev_attr_fan1_min.dev_attr.attr))
3257 if ((adev->family == AMDGPU_FAMILY_SI || /* not implemented yet */
3258 adev->family == AMDGPU_FAMILY_KV) && /* not implemented yet */
3259 (attr == &sensor_dev_attr_in0_input.dev_attr.attr ||
3260 attr == &sensor_dev_attr_in0_label.dev_attr.attr))
3263 /* only APUs have vddnb */
3264 if (!(adev->flags & AMD_IS_APU) &&
3265 (attr == &sensor_dev_attr_in1_input.dev_attr.attr ||
3266 attr == &sensor_dev_attr_in1_label.dev_attr.attr))
3269 /* no mclk on APUs */
3270 if ((adev->flags & AMD_IS_APU) &&
3271 (attr == &sensor_dev_attr_freq2_input.dev_attr.attr ||
3272 attr == &sensor_dev_attr_freq2_label.dev_attr.attr))
3275 /* only SOC15 dGPUs support hotspot and mem temperatures */
3276 if (((adev->flags & AMD_IS_APU) ||
3277 adev->asic_type < CHIP_VEGA10) &&
3278 (attr == &sensor_dev_attr_temp2_crit.dev_attr.attr ||
3279 attr == &sensor_dev_attr_temp2_crit_hyst.dev_attr.attr ||
3280 attr == &sensor_dev_attr_temp3_crit.dev_attr.attr ||
3281 attr == &sensor_dev_attr_temp3_crit_hyst.dev_attr.attr ||
3282 attr == &sensor_dev_attr_temp1_emergency.dev_attr.attr ||
3283 attr == &sensor_dev_attr_temp2_emergency.dev_attr.attr ||
3284 attr == &sensor_dev_attr_temp3_emergency.dev_attr.attr ||
3285 attr == &sensor_dev_attr_temp2_input.dev_attr.attr ||
3286 attr == &sensor_dev_attr_temp3_input.dev_attr.attr ||
3287 attr == &sensor_dev_attr_temp2_label.dev_attr.attr ||
3288 attr == &sensor_dev_attr_temp3_label.dev_attr.attr))
3291 /* only Vangogh has fast PPT limit and power labels */
3292 if (!(adev->asic_type == CHIP_VANGOGH) &&
3293 (attr == &sensor_dev_attr_power2_average.dev_attr.attr ||
3294 attr == &sensor_dev_attr_power2_cap_max.dev_attr.attr ||
3295 attr == &sensor_dev_attr_power2_cap_min.dev_attr.attr ||
3296 attr == &sensor_dev_attr_power2_cap.dev_attr.attr ||
3297 attr == &sensor_dev_attr_power2_cap_default.dev_attr.attr ||
3298 attr == &sensor_dev_attr_power2_label.dev_attr.attr ||
3299 attr == &sensor_dev_attr_power1_label.dev_attr.attr))
3302 return effective_mode;
3305 static const struct attribute_group hwmon_attrgroup = {
3306 .attrs = hwmon_attributes,
3307 .is_visible = hwmon_attributes_visible,
3310 static const struct attribute_group *hwmon_groups[] = {
3315 int amdgpu_pm_sysfs_init(struct amdgpu_device *adev)
3320 if (adev->pm.sysfs_initialized)
3323 if (adev->pm.dpm_enabled == 0)
3326 INIT_LIST_HEAD(&adev->pm.pm_attr_list);
3328 adev->pm.int_hwmon_dev = hwmon_device_register_with_groups(adev->dev,
3331 if (IS_ERR(adev->pm.int_hwmon_dev)) {
3332 ret = PTR_ERR(adev->pm.int_hwmon_dev);
3334 "Unable to register hwmon device: %d\n", ret);
3338 switch (amdgpu_virt_get_sriov_vf_mode(adev)) {
3339 case SRIOV_VF_MODE_ONE_VF:
3340 mask = ATTR_FLAG_ONEVF;
3342 case SRIOV_VF_MODE_MULTI_VF:
3345 case SRIOV_VF_MODE_BARE_METAL:
3347 mask = ATTR_FLAG_MASK_ALL;
3351 ret = amdgpu_device_attr_create_groups(adev,
3352 amdgpu_device_attrs,
3353 ARRAY_SIZE(amdgpu_device_attrs),
3355 &adev->pm.pm_attr_list);
3359 adev->pm.sysfs_initialized = true;
3364 void amdgpu_pm_sysfs_fini(struct amdgpu_device *adev)
3366 if (adev->pm.dpm_enabled == 0)
3369 if (adev->pm.int_hwmon_dev)
3370 hwmon_device_unregister(adev->pm.int_hwmon_dev);
3372 amdgpu_device_attr_remove_groups(adev, &adev->pm.pm_attr_list);
3378 #if defined(CONFIG_DEBUG_FS)
3380 static void amdgpu_debugfs_prints_cpu_info(struct seq_file *m,
3381 struct amdgpu_device *adev) {
3386 if (is_support_cclk_dpm(adev)) {
3387 p_val = kcalloc(adev->smu.cpu_core_num, sizeof(uint16_t),
3390 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_CPU_CLK,
3391 (void *)p_val, &size)) {
3392 for (i = 0; i < adev->smu.cpu_core_num; i++)
3393 seq_printf(m, "\t%u MHz (CPU%d)\n",
3401 static int amdgpu_debugfs_pm_info_pp(struct seq_file *m, struct amdgpu_device *adev)
3404 uint64_t value64 = 0;
3409 size = sizeof(value);
3410 seq_printf(m, "GFX Clocks and Power:\n");
3412 amdgpu_debugfs_prints_cpu_info(m, adev);
3414 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GFX_MCLK, (void *)&value, &size))
3415 seq_printf(m, "\t%u MHz (MCLK)\n", value/100);
3416 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GFX_SCLK, (void *)&value, &size))
3417 seq_printf(m, "\t%u MHz (SCLK)\n", value/100);
3418 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_STABLE_PSTATE_SCLK, (void *)&value, &size))
3419 seq_printf(m, "\t%u MHz (PSTATE_SCLK)\n", value/100);
3420 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_STABLE_PSTATE_MCLK, (void *)&value, &size))
3421 seq_printf(m, "\t%u MHz (PSTATE_MCLK)\n", value/100);
3422 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_VDDGFX, (void *)&value, &size))
3423 seq_printf(m, "\t%u mV (VDDGFX)\n", value);
3424 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_VDDNB, (void *)&value, &size))
3425 seq_printf(m, "\t%u mV (VDDNB)\n", value);
3426 size = sizeof(uint32_t);
3427 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GPU_POWER, (void *)&query, &size))
3428 seq_printf(m, "\t%u.%u W (average GPU)\n", query >> 8, query & 0xff);
3429 size = sizeof(value);
3430 seq_printf(m, "\n");
3433 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GPU_TEMP, (void *)&value, &size))
3434 seq_printf(m, "GPU Temperature: %u C\n", value/1000);
3437 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GPU_LOAD, (void *)&value, &size))
3438 seq_printf(m, "GPU Load: %u %%\n", value);
3440 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_MEM_LOAD, (void *)&value, &size))
3441 seq_printf(m, "MEM Load: %u %%\n", value);
3443 seq_printf(m, "\n");
3445 /* SMC feature mask */
3446 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_ENABLED_SMC_FEATURES_MASK, (void *)&value64, &size))
3447 seq_printf(m, "SMC Feature Mask: 0x%016llx\n", value64);
3449 if (adev->asic_type > CHIP_VEGA20) {
3451 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_VCN_POWER_STATE, (void *)&value, &size)) {
3453 seq_printf(m, "VCN: Disabled\n");
3455 seq_printf(m, "VCN: Enabled\n");
3456 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_UVD_DCLK, (void *)&value, &size))
3457 seq_printf(m, "\t%u MHz (DCLK)\n", value/100);
3458 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_UVD_VCLK, (void *)&value, &size))
3459 seq_printf(m, "\t%u MHz (VCLK)\n", value/100);
3462 seq_printf(m, "\n");
3465 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_UVD_POWER, (void *)&value, &size)) {
3467 seq_printf(m, "UVD: Disabled\n");
3469 seq_printf(m, "UVD: Enabled\n");
3470 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_UVD_DCLK, (void *)&value, &size))
3471 seq_printf(m, "\t%u MHz (DCLK)\n", value/100);
3472 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_UVD_VCLK, (void *)&value, &size))
3473 seq_printf(m, "\t%u MHz (VCLK)\n", value/100);
3476 seq_printf(m, "\n");
3479 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_VCE_POWER, (void *)&value, &size)) {
3481 seq_printf(m, "VCE: Disabled\n");
3483 seq_printf(m, "VCE: Enabled\n");
3484 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_VCE_ECCLK, (void *)&value, &size))
3485 seq_printf(m, "\t%u MHz (ECCLK)\n", value/100);
3493 static void amdgpu_parse_cg_state(struct seq_file *m, u32 flags)
3497 for (i = 0; clocks[i].flag; i++)
3498 seq_printf(m, "\t%s: %s\n", clocks[i].name,
3499 (flags & clocks[i].flag) ? "On" : "Off");
3502 static int amdgpu_debugfs_pm_info_show(struct seq_file *m, void *unused)
3504 struct amdgpu_device *adev = (struct amdgpu_device *)m->private;
3505 struct drm_device *dev = adev_to_drm(adev);
3509 if (amdgpu_in_reset(adev))
3511 if (adev->in_suspend && !adev->in_runpm)
3514 r = pm_runtime_get_sync(dev->dev);
3516 pm_runtime_put_autosuspend(dev->dev);
3520 if (!adev->pm.dpm_enabled) {
3521 seq_printf(m, "dpm not enabled\n");
3522 pm_runtime_mark_last_busy(dev->dev);
3523 pm_runtime_put_autosuspend(dev->dev);
3527 if (!is_support_sw_smu(adev) &&
3528 adev->powerplay.pp_funcs->debugfs_print_current_performance_level) {
3529 mutex_lock(&adev->pm.mutex);
3530 if (adev->powerplay.pp_funcs->debugfs_print_current_performance_level)
3531 adev->powerplay.pp_funcs->debugfs_print_current_performance_level(adev, m);
3533 seq_printf(m, "Debugfs support not implemented for this asic\n");
3534 mutex_unlock(&adev->pm.mutex);
3537 r = amdgpu_debugfs_pm_info_pp(m, adev);
3542 amdgpu_device_ip_get_clockgating_state(adev, &flags);
3544 seq_printf(m, "Clock Gating Flags Mask: 0x%x\n", flags);
3545 amdgpu_parse_cg_state(m, flags);
3546 seq_printf(m, "\n");
3549 pm_runtime_mark_last_busy(dev->dev);
3550 pm_runtime_put_autosuspend(dev->dev);
3555 DEFINE_SHOW_ATTRIBUTE(amdgpu_debugfs_pm_info);
3558 * amdgpu_pm_priv_buffer_read - Read memory region allocated to FW
3560 * Reads debug memory region allocated to PMFW
3562 static ssize_t amdgpu_pm_prv_buffer_read(struct file *f, char __user *buf,
3563 size_t size, loff_t *pos)
3565 struct amdgpu_device *adev = file_inode(f)->i_private;
3566 const struct amd_pm_funcs *pp_funcs = adev->powerplay.pp_funcs;
3567 void *pp_handle = adev->powerplay.pp_handle;
3568 size_t smu_prv_buf_size;
3571 if (amdgpu_in_reset(adev))
3573 if (adev->in_suspend && !adev->in_runpm)
3576 if (pp_funcs && pp_funcs->get_smu_prv_buf_details)
3577 pp_funcs->get_smu_prv_buf_details(pp_handle, &smu_prv_buf,
3582 if (!smu_prv_buf || !smu_prv_buf_size)
3585 return simple_read_from_buffer(buf, size, pos, smu_prv_buf,
3589 static const struct file_operations amdgpu_debugfs_pm_prv_buffer_fops = {
3590 .owner = THIS_MODULE,
3591 .open = simple_open,
3592 .read = amdgpu_pm_prv_buffer_read,
3593 .llseek = default_llseek,
3598 void amdgpu_debugfs_pm_init(struct amdgpu_device *adev)
3600 #if defined(CONFIG_DEBUG_FS)
3601 struct drm_minor *minor = adev_to_drm(adev)->primary;
3602 struct dentry *root = minor->debugfs_root;
3604 debugfs_create_file("amdgpu_pm_info", 0444, root, adev,
3605 &amdgpu_debugfs_pm_info_fops);
3607 if (adev->pm.smu_prv_buffer_size > 0)
3608 debugfs_create_file_size("amdgpu_pm_prv_buffer", 0444, root,
3610 &amdgpu_debugfs_pm_prv_buffer_fops,
3611 adev->pm.smu_prv_buffer_size);