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.
26 #include <drm/drm_debugfs.h>
29 #include "amdgpu_drv.h"
30 #include "amdgpu_pm.h"
31 #include "amdgpu_dpm.h"
32 #include "amdgpu_display.h"
33 #include "amdgpu_smu.h"
35 #include <linux/power_supply.h>
36 #include <linux/pci.h>
37 #include <linux/hwmon.h>
38 #include <linux/hwmon-sysfs.h>
39 #include <linux/nospec.h>
40 #include <linux/pm_runtime.h>
44 static const struct cg_flag_name clocks[] = {
45 {AMD_CG_SUPPORT_GFX_MGCG, "Graphics Medium Grain Clock Gating"},
46 {AMD_CG_SUPPORT_GFX_MGLS, "Graphics Medium Grain memory Light Sleep"},
47 {AMD_CG_SUPPORT_GFX_CGCG, "Graphics Coarse Grain Clock Gating"},
48 {AMD_CG_SUPPORT_GFX_CGLS, "Graphics Coarse Grain memory Light Sleep"},
49 {AMD_CG_SUPPORT_GFX_CGTS, "Graphics Coarse Grain Tree Shader Clock Gating"},
50 {AMD_CG_SUPPORT_GFX_CGTS_LS, "Graphics Coarse Grain Tree Shader Light Sleep"},
51 {AMD_CG_SUPPORT_GFX_CP_LS, "Graphics Command Processor Light Sleep"},
52 {AMD_CG_SUPPORT_GFX_RLC_LS, "Graphics Run List Controller Light Sleep"},
53 {AMD_CG_SUPPORT_GFX_3D_CGCG, "Graphics 3D Coarse Grain Clock Gating"},
54 {AMD_CG_SUPPORT_GFX_3D_CGLS, "Graphics 3D Coarse Grain memory Light Sleep"},
55 {AMD_CG_SUPPORT_MC_LS, "Memory Controller Light Sleep"},
56 {AMD_CG_SUPPORT_MC_MGCG, "Memory Controller Medium Grain Clock Gating"},
57 {AMD_CG_SUPPORT_SDMA_LS, "System Direct Memory Access Light Sleep"},
58 {AMD_CG_SUPPORT_SDMA_MGCG, "System Direct Memory Access Medium Grain Clock Gating"},
59 {AMD_CG_SUPPORT_BIF_MGCG, "Bus Interface Medium Grain Clock Gating"},
60 {AMD_CG_SUPPORT_BIF_LS, "Bus Interface Light Sleep"},
61 {AMD_CG_SUPPORT_UVD_MGCG, "Unified Video Decoder Medium Grain Clock Gating"},
62 {AMD_CG_SUPPORT_VCE_MGCG, "Video Compression Engine Medium Grain Clock Gating"},
63 {AMD_CG_SUPPORT_HDP_LS, "Host Data Path Light Sleep"},
64 {AMD_CG_SUPPORT_HDP_MGCG, "Host Data Path Medium Grain Clock Gating"},
65 {AMD_CG_SUPPORT_DRM_MGCG, "Digital Right Management Medium Grain Clock Gating"},
66 {AMD_CG_SUPPORT_DRM_LS, "Digital Right Management Light Sleep"},
67 {AMD_CG_SUPPORT_ROM_MGCG, "Rom Medium Grain Clock Gating"},
68 {AMD_CG_SUPPORT_DF_MGCG, "Data Fabric Medium Grain Clock Gating"},
70 {AMD_CG_SUPPORT_ATHUB_MGCG, "Address Translation Hub Medium Grain Clock Gating"},
71 {AMD_CG_SUPPORT_ATHUB_LS, "Address Translation Hub Light Sleep"},
75 static const struct hwmon_temp_label {
76 enum PP_HWMON_TEMP channel;
79 {PP_TEMP_EDGE, "edge"},
80 {PP_TEMP_JUNCTION, "junction"},
84 void amdgpu_pm_acpi_event_handler(struct amdgpu_device *adev)
86 if (adev->pm.dpm_enabled) {
87 mutex_lock(&adev->pm.mutex);
88 if (power_supply_is_system_supplied() > 0)
89 adev->pm.ac_power = true;
91 adev->pm.ac_power = false;
92 if (adev->powerplay.pp_funcs &&
93 adev->powerplay.pp_funcs->enable_bapm)
94 amdgpu_dpm_enable_bapm(adev, adev->pm.ac_power);
95 mutex_unlock(&adev->pm.mutex);
97 if (is_support_sw_smu(adev))
98 smu_set_ac_dc(&adev->smu);
102 int amdgpu_dpm_read_sensor(struct amdgpu_device *adev, enum amd_pp_sensors sensor,
103 void *data, uint32_t *size)
110 if (is_support_sw_smu(adev))
111 ret = smu_read_sensor(&adev->smu, sensor, data, size);
113 if (adev->powerplay.pp_funcs && adev->powerplay.pp_funcs->read_sensor)
114 ret = adev->powerplay.pp_funcs->read_sensor((adev)->powerplay.pp_handle,
124 * DOC: power_dpm_state
126 * The power_dpm_state file is a legacy interface and is only provided for
127 * backwards compatibility. The amdgpu driver provides a sysfs API for adjusting
128 * certain power related parameters. The file power_dpm_state is used for this.
129 * It accepts the following arguments:
139 * On older GPUs, the vbios provided a special power state for battery
140 * operation. Selecting battery switched to this state. This is no
141 * longer provided on newer GPUs so the option does nothing in that case.
145 * On older GPUs, the vbios provided a special power state for balanced
146 * operation. Selecting balanced switched to this state. This is no
147 * longer provided on newer GPUs so the option does nothing in that case.
151 * On older GPUs, the vbios provided a special power state for performance
152 * operation. Selecting performance switched to this state. This is no
153 * longer provided on newer GPUs so the option does nothing in that case.
157 static ssize_t amdgpu_get_power_dpm_state(struct device *dev,
158 struct device_attribute *attr,
161 struct drm_device *ddev = dev_get_drvdata(dev);
162 struct amdgpu_device *adev = ddev->dev_private;
163 enum amd_pm_state_type pm;
166 ret = pm_runtime_get_sync(ddev->dev);
170 if (is_support_sw_smu(adev)) {
171 if (adev->smu.ppt_funcs->get_current_power_state)
172 pm = smu_get_current_power_state(&adev->smu);
174 pm = adev->pm.dpm.user_state;
175 } else if (adev->powerplay.pp_funcs->get_current_power_state) {
176 pm = amdgpu_dpm_get_current_power_state(adev);
178 pm = adev->pm.dpm.user_state;
181 pm_runtime_mark_last_busy(ddev->dev);
182 pm_runtime_put_autosuspend(ddev->dev);
184 return snprintf(buf, PAGE_SIZE, "%s\n",
185 (pm == POWER_STATE_TYPE_BATTERY) ? "battery" :
186 (pm == POWER_STATE_TYPE_BALANCED) ? "balanced" : "performance");
189 static ssize_t amdgpu_set_power_dpm_state(struct device *dev,
190 struct device_attribute *attr,
194 struct drm_device *ddev = dev_get_drvdata(dev);
195 struct amdgpu_device *adev = ddev->dev_private;
196 enum amd_pm_state_type state;
199 if (strncmp("battery", buf, strlen("battery")) == 0)
200 state = POWER_STATE_TYPE_BATTERY;
201 else if (strncmp("balanced", buf, strlen("balanced")) == 0)
202 state = POWER_STATE_TYPE_BALANCED;
203 else if (strncmp("performance", buf, strlen("performance")) == 0)
204 state = POWER_STATE_TYPE_PERFORMANCE;
208 ret = pm_runtime_get_sync(ddev->dev);
212 if (is_support_sw_smu(adev)) {
213 mutex_lock(&adev->pm.mutex);
214 adev->pm.dpm.user_state = state;
215 mutex_unlock(&adev->pm.mutex);
216 } else if (adev->powerplay.pp_funcs->dispatch_tasks) {
217 amdgpu_dpm_dispatch_task(adev, AMD_PP_TASK_ENABLE_USER_STATE, &state);
219 mutex_lock(&adev->pm.mutex);
220 adev->pm.dpm.user_state = state;
221 mutex_unlock(&adev->pm.mutex);
223 amdgpu_pm_compute_clocks(adev);
225 pm_runtime_mark_last_busy(ddev->dev);
226 pm_runtime_put_autosuspend(ddev->dev);
233 * DOC: power_dpm_force_performance_level
235 * The amdgpu driver provides a sysfs API for adjusting certain power
236 * related parameters. The file power_dpm_force_performance_level is
237 * used for this. It accepts the following arguments:
257 * When auto is selected, the driver will attempt to dynamically select
258 * the optimal power profile for current conditions in the driver.
262 * When low is selected, the clocks are forced to the lowest power state.
266 * When high is selected, the clocks are forced to the highest power state.
270 * When manual is selected, the user can manually adjust which power states
271 * are enabled for each clock domain via the sysfs pp_dpm_mclk, pp_dpm_sclk,
272 * and pp_dpm_pcie files and adjust the power state transition heuristics
273 * via the pp_power_profile_mode sysfs file.
280 * When the profiling modes are selected, clock and power gating are
281 * disabled and the clocks are set for different profiling cases. This
282 * mode is recommended for profiling specific work loads where you do
283 * not want clock or power gating for clock fluctuation to interfere
284 * with your results. profile_standard sets the clocks to a fixed clock
285 * level which varies from asic to asic. profile_min_sclk forces the sclk
286 * to the lowest level. profile_min_mclk forces the mclk to the lowest level.
287 * profile_peak sets all clocks (mclk, sclk, pcie) to the highest levels.
291 static ssize_t amdgpu_get_power_dpm_force_performance_level(struct device *dev,
292 struct device_attribute *attr,
295 struct drm_device *ddev = dev_get_drvdata(dev);
296 struct amdgpu_device *adev = ddev->dev_private;
297 enum amd_dpm_forced_level level = 0xff;
300 ret = pm_runtime_get_sync(ddev->dev);
304 if (is_support_sw_smu(adev))
305 level = smu_get_performance_level(&adev->smu);
306 else if (adev->powerplay.pp_funcs->get_performance_level)
307 level = amdgpu_dpm_get_performance_level(adev);
309 level = adev->pm.dpm.forced_level;
311 pm_runtime_mark_last_busy(ddev->dev);
312 pm_runtime_put_autosuspend(ddev->dev);
314 return snprintf(buf, PAGE_SIZE, "%s\n",
315 (level == AMD_DPM_FORCED_LEVEL_AUTO) ? "auto" :
316 (level == AMD_DPM_FORCED_LEVEL_LOW) ? "low" :
317 (level == AMD_DPM_FORCED_LEVEL_HIGH) ? "high" :
318 (level == AMD_DPM_FORCED_LEVEL_MANUAL) ? "manual" :
319 (level == AMD_DPM_FORCED_LEVEL_PROFILE_STANDARD) ? "profile_standard" :
320 (level == AMD_DPM_FORCED_LEVEL_PROFILE_MIN_SCLK) ? "profile_min_sclk" :
321 (level == AMD_DPM_FORCED_LEVEL_PROFILE_MIN_MCLK) ? "profile_min_mclk" :
322 (level == AMD_DPM_FORCED_LEVEL_PROFILE_PEAK) ? "profile_peak" :
326 static ssize_t amdgpu_set_power_dpm_force_performance_level(struct device *dev,
327 struct device_attribute *attr,
331 struct drm_device *ddev = dev_get_drvdata(dev);
332 struct amdgpu_device *adev = ddev->dev_private;
333 enum amd_dpm_forced_level level;
334 enum amd_dpm_forced_level current_level = 0xff;
337 if (strncmp("low", buf, strlen("low")) == 0) {
338 level = AMD_DPM_FORCED_LEVEL_LOW;
339 } else if (strncmp("high", buf, strlen("high")) == 0) {
340 level = AMD_DPM_FORCED_LEVEL_HIGH;
341 } else if (strncmp("auto", buf, strlen("auto")) == 0) {
342 level = AMD_DPM_FORCED_LEVEL_AUTO;
343 } else if (strncmp("manual", buf, strlen("manual")) == 0) {
344 level = AMD_DPM_FORCED_LEVEL_MANUAL;
345 } else if (strncmp("profile_exit", buf, strlen("profile_exit")) == 0) {
346 level = AMD_DPM_FORCED_LEVEL_PROFILE_EXIT;
347 } else if (strncmp("profile_standard", buf, strlen("profile_standard")) == 0) {
348 level = AMD_DPM_FORCED_LEVEL_PROFILE_STANDARD;
349 } else if (strncmp("profile_min_sclk", buf, strlen("profile_min_sclk")) == 0) {
350 level = AMD_DPM_FORCED_LEVEL_PROFILE_MIN_SCLK;
351 } else if (strncmp("profile_min_mclk", buf, strlen("profile_min_mclk")) == 0) {
352 level = AMD_DPM_FORCED_LEVEL_PROFILE_MIN_MCLK;
353 } else if (strncmp("profile_peak", buf, strlen("profile_peak")) == 0) {
354 level = AMD_DPM_FORCED_LEVEL_PROFILE_PEAK;
359 ret = pm_runtime_get_sync(ddev->dev);
363 if (is_support_sw_smu(adev))
364 current_level = smu_get_performance_level(&adev->smu);
365 else if (adev->powerplay.pp_funcs->get_performance_level)
366 current_level = amdgpu_dpm_get_performance_level(adev);
368 if (current_level == level) {
369 pm_runtime_mark_last_busy(ddev->dev);
370 pm_runtime_put_autosuspend(ddev->dev);
374 if (adev->asic_type == CHIP_RAVEN) {
375 if (!(adev->apu_flags & AMD_APU_IS_RAVEN2)) {
376 if (current_level != AMD_DPM_FORCED_LEVEL_MANUAL && level == AMD_DPM_FORCED_LEVEL_MANUAL)
377 amdgpu_gfx_off_ctrl(adev, false);
378 else if (current_level == AMD_DPM_FORCED_LEVEL_MANUAL && level != AMD_DPM_FORCED_LEVEL_MANUAL)
379 amdgpu_gfx_off_ctrl(adev, true);
383 /* profile_exit setting is valid only when current mode is in profile mode */
384 if (!(current_level & (AMD_DPM_FORCED_LEVEL_PROFILE_STANDARD |
385 AMD_DPM_FORCED_LEVEL_PROFILE_MIN_SCLK |
386 AMD_DPM_FORCED_LEVEL_PROFILE_MIN_MCLK |
387 AMD_DPM_FORCED_LEVEL_PROFILE_PEAK)) &&
388 (level == AMD_DPM_FORCED_LEVEL_PROFILE_EXIT)) {
389 pr_err("Currently not in any profile mode!\n");
390 pm_runtime_mark_last_busy(ddev->dev);
391 pm_runtime_put_autosuspend(ddev->dev);
395 if (is_support_sw_smu(adev)) {
396 ret = smu_force_performance_level(&adev->smu, level);
398 pm_runtime_mark_last_busy(ddev->dev);
399 pm_runtime_put_autosuspend(ddev->dev);
402 } else if (adev->powerplay.pp_funcs->force_performance_level) {
403 mutex_lock(&adev->pm.mutex);
404 if (adev->pm.dpm.thermal_active) {
405 mutex_unlock(&adev->pm.mutex);
406 pm_runtime_mark_last_busy(ddev->dev);
407 pm_runtime_put_autosuspend(ddev->dev);
410 ret = amdgpu_dpm_force_performance_level(adev, level);
412 mutex_unlock(&adev->pm.mutex);
413 pm_runtime_mark_last_busy(ddev->dev);
414 pm_runtime_put_autosuspend(ddev->dev);
417 adev->pm.dpm.forced_level = level;
419 mutex_unlock(&adev->pm.mutex);
421 pm_runtime_mark_last_busy(ddev->dev);
422 pm_runtime_put_autosuspend(ddev->dev);
427 static ssize_t amdgpu_get_pp_num_states(struct device *dev,
428 struct device_attribute *attr,
431 struct drm_device *ddev = dev_get_drvdata(dev);
432 struct amdgpu_device *adev = ddev->dev_private;
433 struct pp_states_info data;
436 ret = pm_runtime_get_sync(ddev->dev);
440 if (is_support_sw_smu(adev)) {
441 ret = smu_get_power_num_states(&adev->smu, &data);
444 } else if (adev->powerplay.pp_funcs->get_pp_num_states) {
445 amdgpu_dpm_get_pp_num_states(adev, &data);
447 memset(&data, 0, sizeof(data));
450 pm_runtime_mark_last_busy(ddev->dev);
451 pm_runtime_put_autosuspend(ddev->dev);
453 buf_len = snprintf(buf, PAGE_SIZE, "states: %d\n", data.nums);
454 for (i = 0; i < data.nums; i++)
455 buf_len += snprintf(buf + buf_len, PAGE_SIZE, "%d %s\n", i,
456 (data.states[i] == POWER_STATE_TYPE_INTERNAL_BOOT) ? "boot" :
457 (data.states[i] == POWER_STATE_TYPE_BATTERY) ? "battery" :
458 (data.states[i] == POWER_STATE_TYPE_BALANCED) ? "balanced" :
459 (data.states[i] == POWER_STATE_TYPE_PERFORMANCE) ? "performance" : "default");
464 static ssize_t amdgpu_get_pp_cur_state(struct device *dev,
465 struct device_attribute *attr,
468 struct drm_device *ddev = dev_get_drvdata(dev);
469 struct amdgpu_device *adev = ddev->dev_private;
470 struct pp_states_info data;
471 struct smu_context *smu = &adev->smu;
472 enum amd_pm_state_type pm = 0;
475 ret = pm_runtime_get_sync(ddev->dev);
479 if (is_support_sw_smu(adev)) {
480 pm = smu_get_current_power_state(smu);
481 ret = smu_get_power_num_states(smu, &data);
484 } else if (adev->powerplay.pp_funcs->get_current_power_state
485 && adev->powerplay.pp_funcs->get_pp_num_states) {
486 pm = amdgpu_dpm_get_current_power_state(adev);
487 amdgpu_dpm_get_pp_num_states(adev, &data);
490 pm_runtime_mark_last_busy(ddev->dev);
491 pm_runtime_put_autosuspend(ddev->dev);
493 for (i = 0; i < data.nums; i++) {
494 if (pm == data.states[i])
501 return snprintf(buf, PAGE_SIZE, "%d\n", i);
504 static ssize_t amdgpu_get_pp_force_state(struct device *dev,
505 struct device_attribute *attr,
508 struct drm_device *ddev = dev_get_drvdata(dev);
509 struct amdgpu_device *adev = ddev->dev_private;
511 if (adev->pp_force_state_enabled)
512 return amdgpu_get_pp_cur_state(dev, attr, buf);
514 return snprintf(buf, PAGE_SIZE, "\n");
517 static ssize_t amdgpu_set_pp_force_state(struct device *dev,
518 struct device_attribute *attr,
522 struct drm_device *ddev = dev_get_drvdata(dev);
523 struct amdgpu_device *adev = ddev->dev_private;
524 enum amd_pm_state_type state = 0;
528 if (strlen(buf) == 1)
529 adev->pp_force_state_enabled = false;
530 else if (is_support_sw_smu(adev))
531 adev->pp_force_state_enabled = false;
532 else if (adev->powerplay.pp_funcs->dispatch_tasks &&
533 adev->powerplay.pp_funcs->get_pp_num_states) {
534 struct pp_states_info data;
536 ret = kstrtoul(buf, 0, &idx);
537 if (ret || idx >= ARRAY_SIZE(data.states))
540 idx = array_index_nospec(idx, ARRAY_SIZE(data.states));
542 amdgpu_dpm_get_pp_num_states(adev, &data);
543 state = data.states[idx];
545 ret = pm_runtime_get_sync(ddev->dev);
549 /* only set user selected power states */
550 if (state != POWER_STATE_TYPE_INTERNAL_BOOT &&
551 state != POWER_STATE_TYPE_DEFAULT) {
552 amdgpu_dpm_dispatch_task(adev,
553 AMD_PP_TASK_ENABLE_USER_STATE, &state);
554 adev->pp_force_state_enabled = true;
556 pm_runtime_mark_last_busy(ddev->dev);
557 pm_runtime_put_autosuspend(ddev->dev);
566 * The amdgpu driver provides a sysfs API for uploading new powerplay
567 * tables. The file pp_table is used for this. Reading the file
568 * will dump the current power play table. Writing to the file
569 * will attempt to upload a new powerplay table and re-initialize
570 * powerplay using that new table.
574 static ssize_t amdgpu_get_pp_table(struct device *dev,
575 struct device_attribute *attr,
578 struct drm_device *ddev = dev_get_drvdata(dev);
579 struct amdgpu_device *adev = ddev->dev_private;
583 ret = pm_runtime_get_sync(ddev->dev);
587 if (is_support_sw_smu(adev)) {
588 size = smu_sys_get_pp_table(&adev->smu, (void **)&table);
589 pm_runtime_mark_last_busy(ddev->dev);
590 pm_runtime_put_autosuspend(ddev->dev);
593 } else if (adev->powerplay.pp_funcs->get_pp_table) {
594 size = amdgpu_dpm_get_pp_table(adev, &table);
595 pm_runtime_mark_last_busy(ddev->dev);
596 pm_runtime_put_autosuspend(ddev->dev);
600 pm_runtime_mark_last_busy(ddev->dev);
601 pm_runtime_put_autosuspend(ddev->dev);
605 if (size >= PAGE_SIZE)
606 size = PAGE_SIZE - 1;
608 memcpy(buf, table, size);
613 static ssize_t amdgpu_set_pp_table(struct device *dev,
614 struct device_attribute *attr,
618 struct drm_device *ddev = dev_get_drvdata(dev);
619 struct amdgpu_device *adev = ddev->dev_private;
622 ret = pm_runtime_get_sync(ddev->dev);
626 if (is_support_sw_smu(adev)) {
627 ret = smu_sys_set_pp_table(&adev->smu, (void *)buf, count);
629 pm_runtime_mark_last_busy(ddev->dev);
630 pm_runtime_put_autosuspend(ddev->dev);
633 } else if (adev->powerplay.pp_funcs->set_pp_table)
634 amdgpu_dpm_set_pp_table(adev, buf, count);
636 pm_runtime_mark_last_busy(ddev->dev);
637 pm_runtime_put_autosuspend(ddev->dev);
643 * DOC: pp_od_clk_voltage
645 * The amdgpu driver provides a sysfs API for adjusting the clocks and voltages
646 * in each power level within a power state. The pp_od_clk_voltage is used for
649 * < For Vega10 and previous ASICs >
651 * Reading the file will display:
653 * - a list of engine clock levels and voltages labeled OD_SCLK
655 * - a list of memory clock levels and voltages labeled OD_MCLK
657 * - a list of valid ranges for sclk, mclk, and voltage labeled OD_RANGE
659 * To manually adjust these settings, first select manual using
660 * power_dpm_force_performance_level. Enter a new value for each
661 * level by writing a string that contains "s/m level clock voltage" to
662 * the file. E.g., "s 1 500 820" will update sclk level 1 to be 500 MHz
663 * at 820 mV; "m 0 350 810" will update mclk level 0 to be 350 MHz at
664 * 810 mV. When you have edited all of the states as needed, write
665 * "c" (commit) to the file to commit your changes. If you want to reset to the
666 * default power levels, write "r" (reset) to the file to reset them.
671 * Reading the file will display:
673 * - minimum and maximum engine clock labeled OD_SCLK
675 * - maximum memory clock labeled OD_MCLK
677 * - three <frequency, voltage> points labeled OD_VDDC_CURVE.
678 * They can be used to calibrate the sclk voltage curve.
680 * - a list of valid ranges for sclk, mclk, and voltage curve points
683 * To manually adjust these settings:
685 * - First select manual using power_dpm_force_performance_level
687 * - For clock frequency setting, enter a new value by writing a
688 * string that contains "s/m index clock" to the file. The index
689 * should be 0 if to set minimum clock. And 1 if to set maximum
690 * clock. E.g., "s 0 500" will update minimum sclk to be 500 MHz.
691 * "m 1 800" will update maximum mclk to be 800Mhz.
693 * For sclk voltage curve, enter the new values by writing a
694 * string that contains "vc point clock voltage" to the file. The
695 * points are indexed by 0, 1 and 2. E.g., "vc 0 300 600" will
696 * update point1 with clock set as 300Mhz and voltage as
697 * 600mV. "vc 2 1000 1000" will update point3 with clock set
698 * as 1000Mhz and voltage 1000mV.
700 * - When you have edited all of the states as needed, write "c" (commit)
701 * to the file to commit your changes
703 * - If you want to reset to the default power levels, write "r" (reset)
704 * to the file to reset them
708 static ssize_t amdgpu_set_pp_od_clk_voltage(struct device *dev,
709 struct device_attribute *attr,
713 struct drm_device *ddev = dev_get_drvdata(dev);
714 struct amdgpu_device *adev = ddev->dev_private;
716 uint32_t parameter_size = 0;
721 const char delimiter[3] = {' ', '\n', '\0'};
728 type = PP_OD_EDIT_SCLK_VDDC_TABLE;
729 else if (*buf == 'm')
730 type = PP_OD_EDIT_MCLK_VDDC_TABLE;
732 type = PP_OD_RESTORE_DEFAULT_TABLE;
733 else if (*buf == 'c')
734 type = PP_OD_COMMIT_DPM_TABLE;
735 else if (!strncmp(buf, "vc", 2))
736 type = PP_OD_EDIT_VDDC_CURVE;
740 memcpy(buf_cpy, buf, count+1);
744 if (type == PP_OD_EDIT_VDDC_CURVE)
746 while (isspace(*++tmp_str));
749 sub_str = strsep(&tmp_str, delimiter);
750 ret = kstrtol(sub_str, 0, ¶meter[parameter_size]);
755 while (isspace(*tmp_str))
759 ret = pm_runtime_get_sync(ddev->dev);
763 if (is_support_sw_smu(adev)) {
764 ret = smu_od_edit_dpm_table(&adev->smu, type,
765 parameter, parameter_size);
768 pm_runtime_mark_last_busy(ddev->dev);
769 pm_runtime_put_autosuspend(ddev->dev);
773 if (adev->powerplay.pp_funcs->odn_edit_dpm_table) {
774 ret = amdgpu_dpm_odn_edit_dpm_table(adev, type,
775 parameter, parameter_size);
777 pm_runtime_mark_last_busy(ddev->dev);
778 pm_runtime_put_autosuspend(ddev->dev);
783 if (type == PP_OD_COMMIT_DPM_TABLE) {
784 if (adev->powerplay.pp_funcs->dispatch_tasks) {
785 amdgpu_dpm_dispatch_task(adev,
786 AMD_PP_TASK_READJUST_POWER_STATE,
788 pm_runtime_mark_last_busy(ddev->dev);
789 pm_runtime_put_autosuspend(ddev->dev);
792 pm_runtime_mark_last_busy(ddev->dev);
793 pm_runtime_put_autosuspend(ddev->dev);
798 pm_runtime_mark_last_busy(ddev->dev);
799 pm_runtime_put_autosuspend(ddev->dev);
804 static ssize_t amdgpu_get_pp_od_clk_voltage(struct device *dev,
805 struct device_attribute *attr,
808 struct drm_device *ddev = dev_get_drvdata(dev);
809 struct amdgpu_device *adev = ddev->dev_private;
813 ret = pm_runtime_get_sync(ddev->dev);
817 if (is_support_sw_smu(adev)) {
818 size = smu_print_clk_levels(&adev->smu, SMU_OD_SCLK, buf);
819 size += smu_print_clk_levels(&adev->smu, SMU_OD_MCLK, buf+size);
820 size += smu_print_clk_levels(&adev->smu, SMU_OD_VDDC_CURVE, buf+size);
821 size += smu_print_clk_levels(&adev->smu, SMU_OD_RANGE, buf+size);
822 } else if (adev->powerplay.pp_funcs->print_clock_levels) {
823 size = amdgpu_dpm_print_clock_levels(adev, OD_SCLK, buf);
824 size += amdgpu_dpm_print_clock_levels(adev, OD_MCLK, buf+size);
825 size += amdgpu_dpm_print_clock_levels(adev, OD_VDDC_CURVE, buf+size);
826 size += amdgpu_dpm_print_clock_levels(adev, OD_RANGE, buf+size);
828 size = snprintf(buf, PAGE_SIZE, "\n");
830 pm_runtime_mark_last_busy(ddev->dev);
831 pm_runtime_put_autosuspend(ddev->dev);
839 * The amdgpu driver provides a sysfs API for adjusting what powerplay
840 * features to be enabled. The file pp_features is used for this. And
841 * this is only available for Vega10 and later dGPUs.
843 * Reading back the file will show you the followings:
844 * - Current ppfeature masks
845 * - List of the all supported powerplay features with their naming,
846 * bitmasks and enablement status('Y'/'N' means "enabled"/"disabled").
848 * To manually enable or disable a specific feature, just set or clear
849 * the corresponding bit from original ppfeature masks and input the
850 * new ppfeature masks.
852 static ssize_t amdgpu_set_pp_features(struct device *dev,
853 struct device_attribute *attr,
857 struct drm_device *ddev = dev_get_drvdata(dev);
858 struct amdgpu_device *adev = ddev->dev_private;
859 uint64_t featuremask;
862 ret = kstrtou64(buf, 0, &featuremask);
866 pr_debug("featuremask = 0x%llx\n", featuremask);
868 ret = pm_runtime_get_sync(ddev->dev);
872 if (is_support_sw_smu(adev)) {
873 ret = smu_sys_set_pp_feature_mask(&adev->smu, featuremask);
875 pm_runtime_mark_last_busy(ddev->dev);
876 pm_runtime_put_autosuspend(ddev->dev);
879 } else if (adev->powerplay.pp_funcs->set_ppfeature_status) {
880 ret = amdgpu_dpm_set_ppfeature_status(adev, featuremask);
882 pm_runtime_mark_last_busy(ddev->dev);
883 pm_runtime_put_autosuspend(ddev->dev);
887 pm_runtime_mark_last_busy(ddev->dev);
888 pm_runtime_put_autosuspend(ddev->dev);
893 static ssize_t amdgpu_get_pp_features(struct device *dev,
894 struct device_attribute *attr,
897 struct drm_device *ddev = dev_get_drvdata(dev);
898 struct amdgpu_device *adev = ddev->dev_private;
902 ret = pm_runtime_get_sync(ddev->dev);
906 if (is_support_sw_smu(adev))
907 size = smu_sys_get_pp_feature_mask(&adev->smu, buf);
908 else if (adev->powerplay.pp_funcs->get_ppfeature_status)
909 size = amdgpu_dpm_get_ppfeature_status(adev, buf);
911 size = snprintf(buf, PAGE_SIZE, "\n");
913 pm_runtime_mark_last_busy(ddev->dev);
914 pm_runtime_put_autosuspend(ddev->dev);
920 * DOC: pp_dpm_sclk pp_dpm_mclk pp_dpm_socclk pp_dpm_fclk pp_dpm_dcefclk pp_dpm_pcie
922 * The amdgpu driver provides a sysfs API for adjusting what power levels
923 * are enabled for a given power state. The files pp_dpm_sclk, pp_dpm_mclk,
924 * pp_dpm_socclk, pp_dpm_fclk, pp_dpm_dcefclk and pp_dpm_pcie are used for
927 * pp_dpm_socclk and pp_dpm_dcefclk interfaces are only available for
928 * Vega10 and later ASICs.
929 * pp_dpm_fclk interface is only available for Vega20 and later ASICs.
931 * Reading back the files will show you the available power levels within
932 * the power state and the clock information for those levels.
934 * To manually adjust these states, first select manual using
935 * power_dpm_force_performance_level.
936 * Secondly, enter a new value for each level by inputing a string that
937 * contains " echo xx xx xx > pp_dpm_sclk/mclk/pcie"
940 * .. code-block:: bash
942 * echo "4 5 6" > pp_dpm_sclk
944 * will enable sclk levels 4, 5, and 6.
946 * NOTE: change to the dcefclk max dpm level is not supported now
949 static ssize_t amdgpu_get_pp_dpm_sclk(struct device *dev,
950 struct device_attribute *attr,
953 struct drm_device *ddev = dev_get_drvdata(dev);
954 struct amdgpu_device *adev = ddev->dev_private;
958 ret = pm_runtime_get_sync(ddev->dev);
962 if (is_support_sw_smu(adev))
963 size = smu_print_clk_levels(&adev->smu, SMU_SCLK, buf);
964 else if (adev->powerplay.pp_funcs->print_clock_levels)
965 size = amdgpu_dpm_print_clock_levels(adev, PP_SCLK, buf);
967 size = snprintf(buf, PAGE_SIZE, "\n");
969 pm_runtime_mark_last_busy(ddev->dev);
970 pm_runtime_put_autosuspend(ddev->dev);
976 * Worst case: 32 bits individually specified, in octal at 12 characters
977 * per line (+1 for \n).
979 #define AMDGPU_MASK_BUF_MAX (32 * 13)
981 static ssize_t amdgpu_read_mask(const char *buf, size_t count, uint32_t *mask)
985 char *sub_str = NULL;
987 char buf_cpy[AMDGPU_MASK_BUF_MAX + 1];
988 const char delimiter[3] = {' ', '\n', '\0'};
993 bytes = min(count, sizeof(buf_cpy) - 1);
994 memcpy(buf_cpy, buf, bytes);
995 buf_cpy[bytes] = '\0';
998 sub_str = strsep(&tmp, delimiter);
999 if (strlen(sub_str)) {
1000 ret = kstrtol(sub_str, 0, &level);
1003 *mask |= 1 << level;
1011 static ssize_t amdgpu_set_pp_dpm_sclk(struct device *dev,
1012 struct device_attribute *attr,
1016 struct drm_device *ddev = dev_get_drvdata(dev);
1017 struct amdgpu_device *adev = ddev->dev_private;
1021 ret = amdgpu_read_mask(buf, count, &mask);
1025 ret = pm_runtime_get_sync(ddev->dev);
1029 if (is_support_sw_smu(adev))
1030 ret = smu_force_clk_levels(&adev->smu, SMU_SCLK, mask, true);
1031 else if (adev->powerplay.pp_funcs->force_clock_level)
1032 ret = amdgpu_dpm_force_clock_level(adev, PP_SCLK, mask);
1034 pm_runtime_mark_last_busy(ddev->dev);
1035 pm_runtime_put_autosuspend(ddev->dev);
1043 static ssize_t amdgpu_get_pp_dpm_mclk(struct device *dev,
1044 struct device_attribute *attr,
1047 struct drm_device *ddev = dev_get_drvdata(dev);
1048 struct amdgpu_device *adev = ddev->dev_private;
1052 ret = pm_runtime_get_sync(ddev->dev);
1056 if (is_support_sw_smu(adev))
1057 size = smu_print_clk_levels(&adev->smu, SMU_MCLK, buf);
1058 else if (adev->powerplay.pp_funcs->print_clock_levels)
1059 size = amdgpu_dpm_print_clock_levels(adev, PP_MCLK, buf);
1061 size = snprintf(buf, PAGE_SIZE, "\n");
1063 pm_runtime_mark_last_busy(ddev->dev);
1064 pm_runtime_put_autosuspend(ddev->dev);
1069 static ssize_t amdgpu_set_pp_dpm_mclk(struct device *dev,
1070 struct device_attribute *attr,
1074 struct drm_device *ddev = dev_get_drvdata(dev);
1075 struct amdgpu_device *adev = ddev->dev_private;
1079 ret = amdgpu_read_mask(buf, count, &mask);
1083 ret = pm_runtime_get_sync(ddev->dev);
1087 if (is_support_sw_smu(adev))
1088 ret = smu_force_clk_levels(&adev->smu, SMU_MCLK, mask, true);
1089 else if (adev->powerplay.pp_funcs->force_clock_level)
1090 ret = amdgpu_dpm_force_clock_level(adev, PP_MCLK, mask);
1092 pm_runtime_mark_last_busy(ddev->dev);
1093 pm_runtime_put_autosuspend(ddev->dev);
1101 static ssize_t amdgpu_get_pp_dpm_socclk(struct device *dev,
1102 struct device_attribute *attr,
1105 struct drm_device *ddev = dev_get_drvdata(dev);
1106 struct amdgpu_device *adev = ddev->dev_private;
1110 ret = pm_runtime_get_sync(ddev->dev);
1114 if (is_support_sw_smu(adev))
1115 size = smu_print_clk_levels(&adev->smu, SMU_SOCCLK, buf);
1116 else if (adev->powerplay.pp_funcs->print_clock_levels)
1117 size = amdgpu_dpm_print_clock_levels(adev, PP_SOCCLK, buf);
1119 size = snprintf(buf, PAGE_SIZE, "\n");
1121 pm_runtime_mark_last_busy(ddev->dev);
1122 pm_runtime_put_autosuspend(ddev->dev);
1127 static ssize_t amdgpu_set_pp_dpm_socclk(struct device *dev,
1128 struct device_attribute *attr,
1132 struct drm_device *ddev = dev_get_drvdata(dev);
1133 struct amdgpu_device *adev = ddev->dev_private;
1137 ret = amdgpu_read_mask(buf, count, &mask);
1141 ret = pm_runtime_get_sync(ddev->dev);
1145 if (is_support_sw_smu(adev))
1146 ret = smu_force_clk_levels(&adev->smu, SMU_SOCCLK, mask, true);
1147 else if (adev->powerplay.pp_funcs->force_clock_level)
1148 ret = amdgpu_dpm_force_clock_level(adev, PP_SOCCLK, mask);
1152 pm_runtime_mark_last_busy(ddev->dev);
1153 pm_runtime_put_autosuspend(ddev->dev);
1161 static ssize_t amdgpu_get_pp_dpm_fclk(struct device *dev,
1162 struct device_attribute *attr,
1165 struct drm_device *ddev = dev_get_drvdata(dev);
1166 struct amdgpu_device *adev = ddev->dev_private;
1170 ret = pm_runtime_get_sync(ddev->dev);
1174 if (is_support_sw_smu(adev))
1175 size = smu_print_clk_levels(&adev->smu, SMU_FCLK, buf);
1176 else if (adev->powerplay.pp_funcs->print_clock_levels)
1177 size = amdgpu_dpm_print_clock_levels(adev, PP_FCLK, buf);
1179 size = snprintf(buf, PAGE_SIZE, "\n");
1181 pm_runtime_mark_last_busy(ddev->dev);
1182 pm_runtime_put_autosuspend(ddev->dev);
1187 static ssize_t amdgpu_set_pp_dpm_fclk(struct device *dev,
1188 struct device_attribute *attr,
1192 struct drm_device *ddev = dev_get_drvdata(dev);
1193 struct amdgpu_device *adev = ddev->dev_private;
1197 ret = amdgpu_read_mask(buf, count, &mask);
1201 ret = pm_runtime_get_sync(ddev->dev);
1205 if (is_support_sw_smu(adev))
1206 ret = smu_force_clk_levels(&adev->smu, SMU_FCLK, mask, true);
1207 else if (adev->powerplay.pp_funcs->force_clock_level)
1208 ret = amdgpu_dpm_force_clock_level(adev, PP_FCLK, mask);
1212 pm_runtime_mark_last_busy(ddev->dev);
1213 pm_runtime_put_autosuspend(ddev->dev);
1221 static ssize_t amdgpu_get_pp_dpm_dcefclk(struct device *dev,
1222 struct device_attribute *attr,
1225 struct drm_device *ddev = dev_get_drvdata(dev);
1226 struct amdgpu_device *adev = ddev->dev_private;
1230 ret = pm_runtime_get_sync(ddev->dev);
1234 if (is_support_sw_smu(adev))
1235 size = smu_print_clk_levels(&adev->smu, SMU_DCEFCLK, buf);
1236 else if (adev->powerplay.pp_funcs->print_clock_levels)
1237 size = amdgpu_dpm_print_clock_levels(adev, PP_DCEFCLK, buf);
1239 size = snprintf(buf, PAGE_SIZE, "\n");
1241 pm_runtime_mark_last_busy(ddev->dev);
1242 pm_runtime_put_autosuspend(ddev->dev);
1247 static ssize_t amdgpu_set_pp_dpm_dcefclk(struct device *dev,
1248 struct device_attribute *attr,
1252 struct drm_device *ddev = dev_get_drvdata(dev);
1253 struct amdgpu_device *adev = ddev->dev_private;
1257 ret = amdgpu_read_mask(buf, count, &mask);
1261 ret = pm_runtime_get_sync(ddev->dev);
1265 if (is_support_sw_smu(adev))
1266 ret = smu_force_clk_levels(&adev->smu, SMU_DCEFCLK, mask, true);
1267 else if (adev->powerplay.pp_funcs->force_clock_level)
1268 ret = amdgpu_dpm_force_clock_level(adev, PP_DCEFCLK, mask);
1272 pm_runtime_mark_last_busy(ddev->dev);
1273 pm_runtime_put_autosuspend(ddev->dev);
1281 static ssize_t amdgpu_get_pp_dpm_pcie(struct device *dev,
1282 struct device_attribute *attr,
1285 struct drm_device *ddev = dev_get_drvdata(dev);
1286 struct amdgpu_device *adev = ddev->dev_private;
1290 ret = pm_runtime_get_sync(ddev->dev);
1294 if (is_support_sw_smu(adev))
1295 size = smu_print_clk_levels(&adev->smu, SMU_PCIE, buf);
1296 else if (adev->powerplay.pp_funcs->print_clock_levels)
1297 size = amdgpu_dpm_print_clock_levels(adev, PP_PCIE, buf);
1299 size = snprintf(buf, PAGE_SIZE, "\n");
1301 pm_runtime_mark_last_busy(ddev->dev);
1302 pm_runtime_put_autosuspend(ddev->dev);
1307 static ssize_t amdgpu_set_pp_dpm_pcie(struct device *dev,
1308 struct device_attribute *attr,
1312 struct drm_device *ddev = dev_get_drvdata(dev);
1313 struct amdgpu_device *adev = ddev->dev_private;
1317 ret = amdgpu_read_mask(buf, count, &mask);
1321 ret = pm_runtime_get_sync(ddev->dev);
1325 if (is_support_sw_smu(adev))
1326 ret = smu_force_clk_levels(&adev->smu, SMU_PCIE, mask, true);
1327 else if (adev->powerplay.pp_funcs->force_clock_level)
1328 ret = amdgpu_dpm_force_clock_level(adev, PP_PCIE, mask);
1332 pm_runtime_mark_last_busy(ddev->dev);
1333 pm_runtime_put_autosuspend(ddev->dev);
1341 static ssize_t amdgpu_get_pp_sclk_od(struct device *dev,
1342 struct device_attribute *attr,
1345 struct drm_device *ddev = dev_get_drvdata(dev);
1346 struct amdgpu_device *adev = ddev->dev_private;
1350 ret = pm_runtime_get_sync(ddev->dev);
1354 if (is_support_sw_smu(adev))
1355 value = smu_get_od_percentage(&(adev->smu), SMU_OD_SCLK);
1356 else if (adev->powerplay.pp_funcs->get_sclk_od)
1357 value = amdgpu_dpm_get_sclk_od(adev);
1359 pm_runtime_mark_last_busy(ddev->dev);
1360 pm_runtime_put_autosuspend(ddev->dev);
1362 return snprintf(buf, PAGE_SIZE, "%d\n", value);
1365 static ssize_t amdgpu_set_pp_sclk_od(struct device *dev,
1366 struct device_attribute *attr,
1370 struct drm_device *ddev = dev_get_drvdata(dev);
1371 struct amdgpu_device *adev = ddev->dev_private;
1375 ret = kstrtol(buf, 0, &value);
1380 ret = pm_runtime_get_sync(ddev->dev);
1384 if (is_support_sw_smu(adev)) {
1385 value = smu_set_od_percentage(&(adev->smu), SMU_OD_SCLK, (uint32_t)value);
1387 if (adev->powerplay.pp_funcs->set_sclk_od)
1388 amdgpu_dpm_set_sclk_od(adev, (uint32_t)value);
1390 if (adev->powerplay.pp_funcs->dispatch_tasks) {
1391 amdgpu_dpm_dispatch_task(adev, AMD_PP_TASK_READJUST_POWER_STATE, NULL);
1393 adev->pm.dpm.current_ps = adev->pm.dpm.boot_ps;
1394 amdgpu_pm_compute_clocks(adev);
1398 pm_runtime_mark_last_busy(ddev->dev);
1399 pm_runtime_put_autosuspend(ddev->dev);
1404 static ssize_t amdgpu_get_pp_mclk_od(struct device *dev,
1405 struct device_attribute *attr,
1408 struct drm_device *ddev = dev_get_drvdata(dev);
1409 struct amdgpu_device *adev = ddev->dev_private;
1413 ret = pm_runtime_get_sync(ddev->dev);
1417 if (is_support_sw_smu(adev))
1418 value = smu_get_od_percentage(&(adev->smu), SMU_OD_MCLK);
1419 else if (adev->powerplay.pp_funcs->get_mclk_od)
1420 value = amdgpu_dpm_get_mclk_od(adev);
1422 pm_runtime_mark_last_busy(ddev->dev);
1423 pm_runtime_put_autosuspend(ddev->dev);
1425 return snprintf(buf, PAGE_SIZE, "%d\n", value);
1428 static ssize_t amdgpu_set_pp_mclk_od(struct device *dev,
1429 struct device_attribute *attr,
1433 struct drm_device *ddev = dev_get_drvdata(dev);
1434 struct amdgpu_device *adev = ddev->dev_private;
1438 ret = kstrtol(buf, 0, &value);
1443 ret = pm_runtime_get_sync(ddev->dev);
1447 if (is_support_sw_smu(adev)) {
1448 value = smu_set_od_percentage(&(adev->smu), SMU_OD_MCLK, (uint32_t)value);
1450 if (adev->powerplay.pp_funcs->set_mclk_od)
1451 amdgpu_dpm_set_mclk_od(adev, (uint32_t)value);
1453 if (adev->powerplay.pp_funcs->dispatch_tasks) {
1454 amdgpu_dpm_dispatch_task(adev, AMD_PP_TASK_READJUST_POWER_STATE, NULL);
1456 adev->pm.dpm.current_ps = adev->pm.dpm.boot_ps;
1457 amdgpu_pm_compute_clocks(adev);
1461 pm_runtime_mark_last_busy(ddev->dev);
1462 pm_runtime_put_autosuspend(ddev->dev);
1468 * DOC: pp_power_profile_mode
1470 * The amdgpu driver provides a sysfs API for adjusting the heuristics
1471 * related to switching between power levels in a power state. The file
1472 * pp_power_profile_mode is used for this.
1474 * Reading this file outputs a list of all of the predefined power profiles
1475 * and the relevant heuristics settings for that profile.
1477 * To select a profile or create a custom profile, first select manual using
1478 * power_dpm_force_performance_level. Writing the number of a predefined
1479 * profile to pp_power_profile_mode will enable those heuristics. To
1480 * create a custom set of heuristics, write a string of numbers to the file
1481 * starting with the number of the custom profile along with a setting
1482 * for each heuristic parameter. Due to differences across asic families
1483 * the heuristic parameters vary from family to family.
1487 static ssize_t amdgpu_get_pp_power_profile_mode(struct device *dev,
1488 struct device_attribute *attr,
1491 struct drm_device *ddev = dev_get_drvdata(dev);
1492 struct amdgpu_device *adev = ddev->dev_private;
1496 ret = pm_runtime_get_sync(ddev->dev);
1500 if (is_support_sw_smu(adev))
1501 size = smu_get_power_profile_mode(&adev->smu, buf);
1502 else if (adev->powerplay.pp_funcs->get_power_profile_mode)
1503 size = amdgpu_dpm_get_power_profile_mode(adev, buf);
1505 size = snprintf(buf, PAGE_SIZE, "\n");
1507 pm_runtime_mark_last_busy(ddev->dev);
1508 pm_runtime_put_autosuspend(ddev->dev);
1514 static ssize_t amdgpu_set_pp_power_profile_mode(struct device *dev,
1515 struct device_attribute *attr,
1520 struct drm_device *ddev = dev_get_drvdata(dev);
1521 struct amdgpu_device *adev = ddev->dev_private;
1522 uint32_t parameter_size = 0;
1524 char *sub_str, buf_cpy[128];
1528 long int profile_mode = 0;
1529 const char delimiter[3] = {' ', '\n', '\0'};
1533 ret = kstrtol(tmp, 0, &profile_mode);
1537 if (profile_mode == PP_SMC_POWER_PROFILE_CUSTOM) {
1538 if (count < 2 || count > 127)
1540 while (isspace(*++buf))
1542 memcpy(buf_cpy, buf, count-i);
1544 while (tmp_str[0]) {
1545 sub_str = strsep(&tmp_str, delimiter);
1546 ret = kstrtol(sub_str, 0, ¶meter[parameter_size]);
1550 while (isspace(*tmp_str))
1554 parameter[parameter_size] = profile_mode;
1556 ret = pm_runtime_get_sync(ddev->dev);
1560 if (is_support_sw_smu(adev))
1561 ret = smu_set_power_profile_mode(&adev->smu, parameter, parameter_size, true);
1562 else if (adev->powerplay.pp_funcs->set_power_profile_mode)
1563 ret = amdgpu_dpm_set_power_profile_mode(adev, parameter, parameter_size);
1565 pm_runtime_mark_last_busy(ddev->dev);
1566 pm_runtime_put_autosuspend(ddev->dev);
1577 * The amdgpu driver provides a sysfs API for reading how busy the GPU
1578 * is as a percentage. The file gpu_busy_percent is used for this.
1579 * The SMU firmware computes a percentage of load based on the
1580 * aggregate activity level in the IP cores.
1582 static ssize_t amdgpu_get_gpu_busy_percent(struct device *dev,
1583 struct device_attribute *attr,
1586 struct drm_device *ddev = dev_get_drvdata(dev);
1587 struct amdgpu_device *adev = ddev->dev_private;
1588 int r, value, size = sizeof(value);
1590 r = pm_runtime_get_sync(ddev->dev);
1594 /* read the IP busy sensor */
1595 r = amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GPU_LOAD,
1596 (void *)&value, &size);
1598 pm_runtime_mark_last_busy(ddev->dev);
1599 pm_runtime_put_autosuspend(ddev->dev);
1604 return snprintf(buf, PAGE_SIZE, "%d\n", value);
1608 * DOC: mem_busy_percent
1610 * The amdgpu driver provides a sysfs API for reading how busy the VRAM
1611 * is as a percentage. The file mem_busy_percent is used for this.
1612 * The SMU firmware computes a percentage of load based on the
1613 * aggregate activity level in the IP cores.
1615 static ssize_t amdgpu_get_mem_busy_percent(struct device *dev,
1616 struct device_attribute *attr,
1619 struct drm_device *ddev = dev_get_drvdata(dev);
1620 struct amdgpu_device *adev = ddev->dev_private;
1621 int r, value, size = sizeof(value);
1623 r = pm_runtime_get_sync(ddev->dev);
1627 /* read the IP busy sensor */
1628 r = amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_MEM_LOAD,
1629 (void *)&value, &size);
1631 pm_runtime_mark_last_busy(ddev->dev);
1632 pm_runtime_put_autosuspend(ddev->dev);
1637 return snprintf(buf, PAGE_SIZE, "%d\n", value);
1643 * The amdgpu driver provides a sysfs API for estimating how much data
1644 * has been received and sent by the GPU in the last second through PCIe.
1645 * The file pcie_bw is used for this.
1646 * The Perf counters count the number of received and sent messages and return
1647 * those values, as well as the maximum payload size of a PCIe packet (mps).
1648 * Note that it is not possible to easily and quickly obtain the size of each
1649 * packet transmitted, so we output the max payload size (mps) to allow for
1650 * quick estimation of the PCIe bandwidth usage
1652 static ssize_t amdgpu_get_pcie_bw(struct device *dev,
1653 struct device_attribute *attr,
1656 struct drm_device *ddev = dev_get_drvdata(dev);
1657 struct amdgpu_device *adev = ddev->dev_private;
1658 uint64_t count0 = 0, count1 = 0;
1661 if (adev->flags & AMD_IS_APU)
1664 if (!adev->asic_funcs->get_pcie_usage)
1667 ret = pm_runtime_get_sync(ddev->dev);
1671 amdgpu_asic_get_pcie_usage(adev, &count0, &count1);
1673 pm_runtime_mark_last_busy(ddev->dev);
1674 pm_runtime_put_autosuspend(ddev->dev);
1676 return snprintf(buf, PAGE_SIZE, "%llu %llu %i\n",
1677 count0, count1, pcie_get_mps(adev->pdev));
1683 * The amdgpu driver provides a sysfs API for providing a unique ID for the GPU
1684 * The file unique_id is used for this.
1685 * This will provide a Unique ID that will persist from machine to machine
1687 * NOTE: This will only work for GFX9 and newer. This file will be absent
1688 * on unsupported ASICs (GFX8 and older)
1690 static ssize_t amdgpu_get_unique_id(struct device *dev,
1691 struct device_attribute *attr,
1694 struct drm_device *ddev = dev_get_drvdata(dev);
1695 struct amdgpu_device *adev = ddev->dev_private;
1697 if (adev->unique_id)
1698 return snprintf(buf, PAGE_SIZE, "%016llx\n", adev->unique_id);
1703 static struct amdgpu_device_attr amdgpu_device_attrs[] = {
1704 AMDGPU_DEVICE_ATTR_RW(power_dpm_state, ATTR_FLAG_BASIC|ATTR_FLAG_ONEVF),
1705 AMDGPU_DEVICE_ATTR_RW(power_dpm_force_performance_level, ATTR_FLAG_BASIC|ATTR_FLAG_ONEVF),
1706 AMDGPU_DEVICE_ATTR_RO(pp_num_states, ATTR_FLAG_BASIC),
1707 AMDGPU_DEVICE_ATTR_RO(pp_cur_state, ATTR_FLAG_BASIC),
1708 AMDGPU_DEVICE_ATTR_RW(pp_force_state, ATTR_FLAG_BASIC),
1709 AMDGPU_DEVICE_ATTR_RW(pp_table, ATTR_FLAG_BASIC),
1710 AMDGPU_DEVICE_ATTR_RW(pp_dpm_sclk, ATTR_FLAG_BASIC|ATTR_FLAG_ONEVF),
1711 AMDGPU_DEVICE_ATTR_RW(pp_dpm_mclk, ATTR_FLAG_BASIC|ATTR_FLAG_ONEVF),
1712 AMDGPU_DEVICE_ATTR_RW(pp_dpm_socclk, ATTR_FLAG_BASIC|ATTR_FLAG_ONEVF),
1713 AMDGPU_DEVICE_ATTR_RW(pp_dpm_fclk, ATTR_FLAG_BASIC|ATTR_FLAG_ONEVF),
1714 AMDGPU_DEVICE_ATTR_RW(pp_dpm_dcefclk, ATTR_FLAG_BASIC),
1715 AMDGPU_DEVICE_ATTR_RW(pp_dpm_pcie, ATTR_FLAG_BASIC),
1716 AMDGPU_DEVICE_ATTR_RW(pp_sclk_od, ATTR_FLAG_BASIC),
1717 AMDGPU_DEVICE_ATTR_RW(pp_mclk_od, ATTR_FLAG_BASIC),
1718 AMDGPU_DEVICE_ATTR_RW(pp_power_profile_mode, ATTR_FLAG_BASIC),
1719 AMDGPU_DEVICE_ATTR_RW(pp_od_clk_voltage, ATTR_FLAG_BASIC),
1720 AMDGPU_DEVICE_ATTR_RO(gpu_busy_percent, ATTR_FLAG_BASIC),
1721 AMDGPU_DEVICE_ATTR_RO(mem_busy_percent, ATTR_FLAG_BASIC),
1722 AMDGPU_DEVICE_ATTR_RO(pcie_bw, ATTR_FLAG_BASIC),
1723 AMDGPU_DEVICE_ATTR_RW(pp_features, ATTR_FLAG_BASIC),
1724 AMDGPU_DEVICE_ATTR_RO(unique_id, ATTR_FLAG_BASIC),
1727 static int default_attr_update(struct amdgpu_device *adev, struct amdgpu_device_attr *attr,
1728 uint32_t mask, enum amdgpu_device_attr_states *states)
1730 struct device_attribute *dev_attr = &attr->dev_attr;
1731 const char *attr_name = dev_attr->attr.name;
1732 struct pp_hwmgr *hwmgr = adev->powerplay.pp_handle;
1733 enum amd_asic_type asic_type = adev->asic_type;
1735 if (!(attr->flags & mask)) {
1736 *states = ATTR_STATE_UNSUPPORTED;
1740 #define DEVICE_ATTR_IS(_name) (!strcmp(attr_name, #_name))
1742 if (DEVICE_ATTR_IS(pp_dpm_socclk)) {
1743 if (asic_type < CHIP_VEGA10)
1744 *states = ATTR_STATE_UNSUPPORTED;
1745 } else if (DEVICE_ATTR_IS(pp_dpm_dcefclk)) {
1746 if (asic_type < CHIP_VEGA10 || asic_type == CHIP_ARCTURUS)
1747 *states = ATTR_STATE_UNSUPPORTED;
1748 } else if (DEVICE_ATTR_IS(pp_dpm_fclk)) {
1749 if (asic_type < CHIP_VEGA20)
1750 *states = ATTR_STATE_UNSUPPORTED;
1751 } else if (DEVICE_ATTR_IS(pp_dpm_pcie)) {
1752 if (asic_type == CHIP_ARCTURUS)
1753 *states = ATTR_STATE_UNSUPPORTED;
1754 } else if (DEVICE_ATTR_IS(pp_od_clk_voltage)) {
1755 *states = ATTR_STATE_UNSUPPORTED;
1756 if ((is_support_sw_smu(adev) && adev->smu.od_enabled) ||
1757 (!is_support_sw_smu(adev) && hwmgr->od_enabled))
1758 *states = ATTR_STATE_SUPPORTED;
1759 } else if (DEVICE_ATTR_IS(mem_busy_percent)) {
1760 if (adev->flags & AMD_IS_APU || asic_type == CHIP_VEGA10)
1761 *states = ATTR_STATE_UNSUPPORTED;
1762 } else if (DEVICE_ATTR_IS(pcie_bw)) {
1763 /* PCIe Perf counters won't work on APU nodes */
1764 if (adev->flags & AMD_IS_APU)
1765 *states = ATTR_STATE_UNSUPPORTED;
1766 } else if (DEVICE_ATTR_IS(unique_id)) {
1767 if (!adev->unique_id)
1768 *states = ATTR_STATE_UNSUPPORTED;
1769 } else if (DEVICE_ATTR_IS(pp_features)) {
1770 if (adev->flags & AMD_IS_APU || asic_type < CHIP_VEGA10)
1771 *states = ATTR_STATE_UNSUPPORTED;
1774 if (asic_type == CHIP_ARCTURUS) {
1775 /* Arcturus does not support standalone mclk/socclk/fclk level setting */
1776 if (DEVICE_ATTR_IS(pp_dpm_mclk) ||
1777 DEVICE_ATTR_IS(pp_dpm_socclk) ||
1778 DEVICE_ATTR_IS(pp_dpm_fclk)) {
1779 dev_attr->attr.mode &= ~S_IWUGO;
1780 dev_attr->store = NULL;
1784 #undef DEVICE_ATTR_IS
1790 static int amdgpu_device_attr_create(struct amdgpu_device *adev,
1791 struct amdgpu_device_attr *attr,
1792 uint32_t mask, struct list_head *attr_list)
1795 struct device_attribute *dev_attr = &attr->dev_attr;
1796 const char *name = dev_attr->attr.name;
1797 enum amdgpu_device_attr_states attr_states = ATTR_STATE_SUPPORTED;
1798 struct amdgpu_device_attr_entry *attr_entry;
1800 int (*attr_update)(struct amdgpu_device *adev, struct amdgpu_device_attr *attr,
1801 uint32_t mask, enum amdgpu_device_attr_states *states) = default_attr_update;
1805 attr_update = attr->attr_update ? attr_update : default_attr_update;
1807 ret = attr_update(adev, attr, mask, &attr_states);
1809 dev_err(adev->dev, "failed to update device file %s, ret = %d\n",
1814 if (attr_states == ATTR_STATE_UNSUPPORTED)
1817 ret = device_create_file(adev->dev, dev_attr);
1819 dev_err(adev->dev, "failed to create device file %s, ret = %d\n",
1823 attr_entry = kmalloc(sizeof(*attr_entry), GFP_KERNEL);
1827 attr_entry->attr = attr;
1828 INIT_LIST_HEAD(&attr_entry->entry);
1830 list_add_tail(&attr_entry->entry, attr_list);
1835 static void amdgpu_device_attr_remove(struct amdgpu_device *adev, struct amdgpu_device_attr *attr)
1837 struct device_attribute *dev_attr = &attr->dev_attr;
1839 device_remove_file(adev->dev, dev_attr);
1842 static void amdgpu_device_attr_remove_groups(struct amdgpu_device *adev,
1843 struct list_head *attr_list);
1845 static int amdgpu_device_attr_create_groups(struct amdgpu_device *adev,
1846 struct amdgpu_device_attr *attrs,
1849 struct list_head *attr_list)
1854 for (i = 0; i < counts; i++) {
1855 ret = amdgpu_device_attr_create(adev, &attrs[i], mask, attr_list);
1863 amdgpu_device_attr_remove_groups(adev, attr_list);
1868 static void amdgpu_device_attr_remove_groups(struct amdgpu_device *adev,
1869 struct list_head *attr_list)
1871 struct amdgpu_device_attr_entry *entry, *entry_tmp;
1873 if (list_empty(attr_list))
1876 list_for_each_entry_safe(entry, entry_tmp, attr_list, entry) {
1877 amdgpu_device_attr_remove(adev, entry->attr);
1878 list_del(&entry->entry);
1883 static ssize_t amdgpu_hwmon_show_temp(struct device *dev,
1884 struct device_attribute *attr,
1887 struct amdgpu_device *adev = dev_get_drvdata(dev);
1888 int channel = to_sensor_dev_attr(attr)->index;
1889 int r, temp = 0, size = sizeof(temp);
1891 if (channel >= PP_TEMP_MAX)
1894 r = pm_runtime_get_sync(adev->ddev->dev);
1899 case PP_TEMP_JUNCTION:
1900 /* get current junction temperature */
1901 r = amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_HOTSPOT_TEMP,
1902 (void *)&temp, &size);
1905 /* get current edge temperature */
1906 r = amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_EDGE_TEMP,
1907 (void *)&temp, &size);
1910 /* get current memory temperature */
1911 r = amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_MEM_TEMP,
1912 (void *)&temp, &size);
1919 pm_runtime_mark_last_busy(adev->ddev->dev);
1920 pm_runtime_put_autosuspend(adev->ddev->dev);
1925 return snprintf(buf, PAGE_SIZE, "%d\n", temp);
1928 static ssize_t amdgpu_hwmon_show_temp_thresh(struct device *dev,
1929 struct device_attribute *attr,
1932 struct amdgpu_device *adev = dev_get_drvdata(dev);
1933 int hyst = to_sensor_dev_attr(attr)->index;
1937 temp = adev->pm.dpm.thermal.min_temp;
1939 temp = adev->pm.dpm.thermal.max_temp;
1941 return snprintf(buf, PAGE_SIZE, "%d\n", temp);
1944 static ssize_t amdgpu_hwmon_show_hotspot_temp_thresh(struct device *dev,
1945 struct device_attribute *attr,
1948 struct amdgpu_device *adev = dev_get_drvdata(dev);
1949 int hyst = to_sensor_dev_attr(attr)->index;
1953 temp = adev->pm.dpm.thermal.min_hotspot_temp;
1955 temp = adev->pm.dpm.thermal.max_hotspot_crit_temp;
1957 return snprintf(buf, PAGE_SIZE, "%d\n", temp);
1960 static ssize_t amdgpu_hwmon_show_mem_temp_thresh(struct device *dev,
1961 struct device_attribute *attr,
1964 struct amdgpu_device *adev = dev_get_drvdata(dev);
1965 int hyst = to_sensor_dev_attr(attr)->index;
1969 temp = adev->pm.dpm.thermal.min_mem_temp;
1971 temp = adev->pm.dpm.thermal.max_mem_crit_temp;
1973 return snprintf(buf, PAGE_SIZE, "%d\n", temp);
1976 static ssize_t amdgpu_hwmon_show_temp_label(struct device *dev,
1977 struct device_attribute *attr,
1980 int channel = to_sensor_dev_attr(attr)->index;
1982 if (channel >= PP_TEMP_MAX)
1985 return snprintf(buf, PAGE_SIZE, "%s\n", temp_label[channel].label);
1988 static ssize_t amdgpu_hwmon_show_temp_emergency(struct device *dev,
1989 struct device_attribute *attr,
1992 struct amdgpu_device *adev = dev_get_drvdata(dev);
1993 int channel = to_sensor_dev_attr(attr)->index;
1996 if (channel >= PP_TEMP_MAX)
2000 case PP_TEMP_JUNCTION:
2001 temp = adev->pm.dpm.thermal.max_hotspot_emergency_temp;
2004 temp = adev->pm.dpm.thermal.max_edge_emergency_temp;
2007 temp = adev->pm.dpm.thermal.max_mem_emergency_temp;
2011 return snprintf(buf, PAGE_SIZE, "%d\n", temp);
2014 static ssize_t amdgpu_hwmon_get_pwm1_enable(struct device *dev,
2015 struct device_attribute *attr,
2018 struct amdgpu_device *adev = dev_get_drvdata(dev);
2022 ret = pm_runtime_get_sync(adev->ddev->dev);
2026 if (is_support_sw_smu(adev)) {
2027 pwm_mode = smu_get_fan_control_mode(&adev->smu);
2029 if (!adev->powerplay.pp_funcs->get_fan_control_mode) {
2030 pm_runtime_mark_last_busy(adev->ddev->dev);
2031 pm_runtime_put_autosuspend(adev->ddev->dev);
2035 pwm_mode = amdgpu_dpm_get_fan_control_mode(adev);
2038 pm_runtime_mark_last_busy(adev->ddev->dev);
2039 pm_runtime_put_autosuspend(adev->ddev->dev);
2041 return sprintf(buf, "%i\n", pwm_mode);
2044 static ssize_t amdgpu_hwmon_set_pwm1_enable(struct device *dev,
2045 struct device_attribute *attr,
2049 struct amdgpu_device *adev = dev_get_drvdata(dev);
2053 err = kstrtoint(buf, 10, &value);
2057 ret = pm_runtime_get_sync(adev->ddev->dev);
2061 if (is_support_sw_smu(adev)) {
2062 smu_set_fan_control_mode(&adev->smu, value);
2064 if (!adev->powerplay.pp_funcs->set_fan_control_mode) {
2065 pm_runtime_mark_last_busy(adev->ddev->dev);
2066 pm_runtime_put_autosuspend(adev->ddev->dev);
2070 amdgpu_dpm_set_fan_control_mode(adev, value);
2073 pm_runtime_mark_last_busy(adev->ddev->dev);
2074 pm_runtime_put_autosuspend(adev->ddev->dev);
2079 static ssize_t amdgpu_hwmon_get_pwm1_min(struct device *dev,
2080 struct device_attribute *attr,
2083 return sprintf(buf, "%i\n", 0);
2086 static ssize_t amdgpu_hwmon_get_pwm1_max(struct device *dev,
2087 struct device_attribute *attr,
2090 return sprintf(buf, "%i\n", 255);
2093 static ssize_t amdgpu_hwmon_set_pwm1(struct device *dev,
2094 struct device_attribute *attr,
2095 const char *buf, size_t count)
2097 struct amdgpu_device *adev = dev_get_drvdata(dev);
2102 err = pm_runtime_get_sync(adev->ddev->dev);
2106 if (is_support_sw_smu(adev))
2107 pwm_mode = smu_get_fan_control_mode(&adev->smu);
2109 pwm_mode = amdgpu_dpm_get_fan_control_mode(adev);
2111 if (pwm_mode != AMD_FAN_CTRL_MANUAL) {
2112 pr_info("manual fan speed control should be enabled first\n");
2113 pm_runtime_mark_last_busy(adev->ddev->dev);
2114 pm_runtime_put_autosuspend(adev->ddev->dev);
2118 err = kstrtou32(buf, 10, &value);
2120 pm_runtime_mark_last_busy(adev->ddev->dev);
2121 pm_runtime_put_autosuspend(adev->ddev->dev);
2125 value = (value * 100) / 255;
2127 if (is_support_sw_smu(adev))
2128 err = smu_set_fan_speed_percent(&adev->smu, value);
2129 else if (adev->powerplay.pp_funcs->set_fan_speed_percent)
2130 err = amdgpu_dpm_set_fan_speed_percent(adev, value);
2134 pm_runtime_mark_last_busy(adev->ddev->dev);
2135 pm_runtime_put_autosuspend(adev->ddev->dev);
2143 static ssize_t amdgpu_hwmon_get_pwm1(struct device *dev,
2144 struct device_attribute *attr,
2147 struct amdgpu_device *adev = dev_get_drvdata(dev);
2151 err = pm_runtime_get_sync(adev->ddev->dev);
2155 if (is_support_sw_smu(adev))
2156 err = smu_get_fan_speed_percent(&adev->smu, &speed);
2157 else if (adev->powerplay.pp_funcs->get_fan_speed_percent)
2158 err = amdgpu_dpm_get_fan_speed_percent(adev, &speed);
2162 pm_runtime_mark_last_busy(adev->ddev->dev);
2163 pm_runtime_put_autosuspend(adev->ddev->dev);
2168 speed = (speed * 255) / 100;
2170 return sprintf(buf, "%i\n", speed);
2173 static ssize_t amdgpu_hwmon_get_fan1_input(struct device *dev,
2174 struct device_attribute *attr,
2177 struct amdgpu_device *adev = dev_get_drvdata(dev);
2181 err = pm_runtime_get_sync(adev->ddev->dev);
2185 if (is_support_sw_smu(adev))
2186 err = smu_get_fan_speed_rpm(&adev->smu, &speed);
2187 else if (adev->powerplay.pp_funcs->get_fan_speed_rpm)
2188 err = amdgpu_dpm_get_fan_speed_rpm(adev, &speed);
2192 pm_runtime_mark_last_busy(adev->ddev->dev);
2193 pm_runtime_put_autosuspend(adev->ddev->dev);
2198 return sprintf(buf, "%i\n", speed);
2201 static ssize_t amdgpu_hwmon_get_fan1_min(struct device *dev,
2202 struct device_attribute *attr,
2205 struct amdgpu_device *adev = dev_get_drvdata(dev);
2207 u32 size = sizeof(min_rpm);
2210 r = pm_runtime_get_sync(adev->ddev->dev);
2214 r = amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_MIN_FAN_RPM,
2215 (void *)&min_rpm, &size);
2217 pm_runtime_mark_last_busy(adev->ddev->dev);
2218 pm_runtime_put_autosuspend(adev->ddev->dev);
2223 return snprintf(buf, PAGE_SIZE, "%d\n", min_rpm);
2226 static ssize_t amdgpu_hwmon_get_fan1_max(struct device *dev,
2227 struct device_attribute *attr,
2230 struct amdgpu_device *adev = dev_get_drvdata(dev);
2232 u32 size = sizeof(max_rpm);
2235 r = pm_runtime_get_sync(adev->ddev->dev);
2239 r = amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_MAX_FAN_RPM,
2240 (void *)&max_rpm, &size);
2242 pm_runtime_mark_last_busy(adev->ddev->dev);
2243 pm_runtime_put_autosuspend(adev->ddev->dev);
2248 return snprintf(buf, PAGE_SIZE, "%d\n", max_rpm);
2251 static ssize_t amdgpu_hwmon_get_fan1_target(struct device *dev,
2252 struct device_attribute *attr,
2255 struct amdgpu_device *adev = dev_get_drvdata(dev);
2259 err = pm_runtime_get_sync(adev->ddev->dev);
2263 if (is_support_sw_smu(adev))
2264 err = smu_get_fan_speed_rpm(&adev->smu, &rpm);
2265 else if (adev->powerplay.pp_funcs->get_fan_speed_rpm)
2266 err = amdgpu_dpm_get_fan_speed_rpm(adev, &rpm);
2270 pm_runtime_mark_last_busy(adev->ddev->dev);
2271 pm_runtime_put_autosuspend(adev->ddev->dev);
2276 return sprintf(buf, "%i\n", rpm);
2279 static ssize_t amdgpu_hwmon_set_fan1_target(struct device *dev,
2280 struct device_attribute *attr,
2281 const char *buf, size_t count)
2283 struct amdgpu_device *adev = dev_get_drvdata(dev);
2288 err = pm_runtime_get_sync(adev->ddev->dev);
2292 if (is_support_sw_smu(adev))
2293 pwm_mode = smu_get_fan_control_mode(&adev->smu);
2295 pwm_mode = amdgpu_dpm_get_fan_control_mode(adev);
2297 if (pwm_mode != AMD_FAN_CTRL_MANUAL) {
2298 pm_runtime_mark_last_busy(adev->ddev->dev);
2299 pm_runtime_put_autosuspend(adev->ddev->dev);
2303 err = kstrtou32(buf, 10, &value);
2305 pm_runtime_mark_last_busy(adev->ddev->dev);
2306 pm_runtime_put_autosuspend(adev->ddev->dev);
2310 if (is_support_sw_smu(adev))
2311 err = smu_set_fan_speed_rpm(&adev->smu, value);
2312 else if (adev->powerplay.pp_funcs->set_fan_speed_rpm)
2313 err = amdgpu_dpm_set_fan_speed_rpm(adev, value);
2317 pm_runtime_mark_last_busy(adev->ddev->dev);
2318 pm_runtime_put_autosuspend(adev->ddev->dev);
2326 static ssize_t amdgpu_hwmon_get_fan1_enable(struct device *dev,
2327 struct device_attribute *attr,
2330 struct amdgpu_device *adev = dev_get_drvdata(dev);
2334 ret = pm_runtime_get_sync(adev->ddev->dev);
2338 if (is_support_sw_smu(adev)) {
2339 pwm_mode = smu_get_fan_control_mode(&adev->smu);
2341 if (!adev->powerplay.pp_funcs->get_fan_control_mode) {
2342 pm_runtime_mark_last_busy(adev->ddev->dev);
2343 pm_runtime_put_autosuspend(adev->ddev->dev);
2347 pwm_mode = amdgpu_dpm_get_fan_control_mode(adev);
2350 pm_runtime_mark_last_busy(adev->ddev->dev);
2351 pm_runtime_put_autosuspend(adev->ddev->dev);
2353 return sprintf(buf, "%i\n", pwm_mode == AMD_FAN_CTRL_AUTO ? 0 : 1);
2356 static ssize_t amdgpu_hwmon_set_fan1_enable(struct device *dev,
2357 struct device_attribute *attr,
2361 struct amdgpu_device *adev = dev_get_drvdata(dev);
2366 err = kstrtoint(buf, 10, &value);
2371 pwm_mode = AMD_FAN_CTRL_AUTO;
2372 else if (value == 1)
2373 pwm_mode = AMD_FAN_CTRL_MANUAL;
2377 err = pm_runtime_get_sync(adev->ddev->dev);
2381 if (is_support_sw_smu(adev)) {
2382 smu_set_fan_control_mode(&adev->smu, pwm_mode);
2384 if (!adev->powerplay.pp_funcs->set_fan_control_mode) {
2385 pm_runtime_mark_last_busy(adev->ddev->dev);
2386 pm_runtime_put_autosuspend(adev->ddev->dev);
2389 amdgpu_dpm_set_fan_control_mode(adev, pwm_mode);
2392 pm_runtime_mark_last_busy(adev->ddev->dev);
2393 pm_runtime_put_autosuspend(adev->ddev->dev);
2398 static ssize_t amdgpu_hwmon_show_vddgfx(struct device *dev,
2399 struct device_attribute *attr,
2402 struct amdgpu_device *adev = dev_get_drvdata(dev);
2404 int r, size = sizeof(vddgfx);
2406 r = pm_runtime_get_sync(adev->ddev->dev);
2410 /* get the voltage */
2411 r = amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_VDDGFX,
2412 (void *)&vddgfx, &size);
2414 pm_runtime_mark_last_busy(adev->ddev->dev);
2415 pm_runtime_put_autosuspend(adev->ddev->dev);
2420 return snprintf(buf, PAGE_SIZE, "%d\n", vddgfx);
2423 static ssize_t amdgpu_hwmon_show_vddgfx_label(struct device *dev,
2424 struct device_attribute *attr,
2427 return snprintf(buf, PAGE_SIZE, "vddgfx\n");
2430 static ssize_t amdgpu_hwmon_show_vddnb(struct device *dev,
2431 struct device_attribute *attr,
2434 struct amdgpu_device *adev = dev_get_drvdata(dev);
2436 int r, size = sizeof(vddnb);
2438 /* only APUs have vddnb */
2439 if (!(adev->flags & AMD_IS_APU))
2442 r = pm_runtime_get_sync(adev->ddev->dev);
2446 /* get the voltage */
2447 r = amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_VDDNB,
2448 (void *)&vddnb, &size);
2450 pm_runtime_mark_last_busy(adev->ddev->dev);
2451 pm_runtime_put_autosuspend(adev->ddev->dev);
2456 return snprintf(buf, PAGE_SIZE, "%d\n", vddnb);
2459 static ssize_t amdgpu_hwmon_show_vddnb_label(struct device *dev,
2460 struct device_attribute *attr,
2463 return snprintf(buf, PAGE_SIZE, "vddnb\n");
2466 static ssize_t amdgpu_hwmon_show_power_avg(struct device *dev,
2467 struct device_attribute *attr,
2470 struct amdgpu_device *adev = dev_get_drvdata(dev);
2472 int r, size = sizeof(u32);
2475 r = pm_runtime_get_sync(adev->ddev->dev);
2479 /* get the voltage */
2480 r = amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GPU_POWER,
2481 (void *)&query, &size);
2483 pm_runtime_mark_last_busy(adev->ddev->dev);
2484 pm_runtime_put_autosuspend(adev->ddev->dev);
2489 /* convert to microwatts */
2490 uw = (query >> 8) * 1000000 + (query & 0xff) * 1000;
2492 return snprintf(buf, PAGE_SIZE, "%u\n", uw);
2495 static ssize_t amdgpu_hwmon_show_power_cap_min(struct device *dev,
2496 struct device_attribute *attr,
2499 return sprintf(buf, "%i\n", 0);
2502 static ssize_t amdgpu_hwmon_show_power_cap_max(struct device *dev,
2503 struct device_attribute *attr,
2506 struct amdgpu_device *adev = dev_get_drvdata(dev);
2511 r = pm_runtime_get_sync(adev->ddev->dev);
2515 if (is_support_sw_smu(adev)) {
2516 smu_get_power_limit(&adev->smu, &limit, true, true);
2517 size = snprintf(buf, PAGE_SIZE, "%u\n", limit * 1000000);
2518 } else if (adev->powerplay.pp_funcs && adev->powerplay.pp_funcs->get_power_limit) {
2519 adev->powerplay.pp_funcs->get_power_limit(adev->powerplay.pp_handle, &limit, true);
2520 size = snprintf(buf, PAGE_SIZE, "%u\n", limit * 1000000);
2522 size = snprintf(buf, PAGE_SIZE, "\n");
2525 pm_runtime_mark_last_busy(adev->ddev->dev);
2526 pm_runtime_put_autosuspend(adev->ddev->dev);
2531 static ssize_t amdgpu_hwmon_show_power_cap(struct device *dev,
2532 struct device_attribute *attr,
2535 struct amdgpu_device *adev = dev_get_drvdata(dev);
2540 r = pm_runtime_get_sync(adev->ddev->dev);
2544 if (is_support_sw_smu(adev)) {
2545 smu_get_power_limit(&adev->smu, &limit, false, true);
2546 size = snprintf(buf, PAGE_SIZE, "%u\n", limit * 1000000);
2547 } else if (adev->powerplay.pp_funcs && adev->powerplay.pp_funcs->get_power_limit) {
2548 adev->powerplay.pp_funcs->get_power_limit(adev->powerplay.pp_handle, &limit, false);
2549 size = snprintf(buf, PAGE_SIZE, "%u\n", limit * 1000000);
2551 size = snprintf(buf, PAGE_SIZE, "\n");
2554 pm_runtime_mark_last_busy(adev->ddev->dev);
2555 pm_runtime_put_autosuspend(adev->ddev->dev);
2561 static ssize_t amdgpu_hwmon_set_power_cap(struct device *dev,
2562 struct device_attribute *attr,
2566 struct amdgpu_device *adev = dev_get_drvdata(dev);
2570 if (amdgpu_sriov_vf(adev))
2573 err = kstrtou32(buf, 10, &value);
2577 value = value / 1000000; /* convert to Watt */
2580 err = pm_runtime_get_sync(adev->ddev->dev);
2584 if (is_support_sw_smu(adev))
2585 err = smu_set_power_limit(&adev->smu, value);
2586 else if (adev->powerplay.pp_funcs && adev->powerplay.pp_funcs->set_power_limit)
2587 err = adev->powerplay.pp_funcs->set_power_limit(adev->powerplay.pp_handle, value);
2591 pm_runtime_mark_last_busy(adev->ddev->dev);
2592 pm_runtime_put_autosuspend(adev->ddev->dev);
2600 static ssize_t amdgpu_hwmon_show_sclk(struct device *dev,
2601 struct device_attribute *attr,
2604 struct amdgpu_device *adev = dev_get_drvdata(dev);
2606 int r, size = sizeof(sclk);
2608 r = pm_runtime_get_sync(adev->ddev->dev);
2613 r = amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GFX_SCLK,
2614 (void *)&sclk, &size);
2616 pm_runtime_mark_last_busy(adev->ddev->dev);
2617 pm_runtime_put_autosuspend(adev->ddev->dev);
2622 return snprintf(buf, PAGE_SIZE, "%d\n", sclk * 10 * 1000);
2625 static ssize_t amdgpu_hwmon_show_sclk_label(struct device *dev,
2626 struct device_attribute *attr,
2629 return snprintf(buf, PAGE_SIZE, "sclk\n");
2632 static ssize_t amdgpu_hwmon_show_mclk(struct device *dev,
2633 struct device_attribute *attr,
2636 struct amdgpu_device *adev = dev_get_drvdata(dev);
2638 int r, size = sizeof(mclk);
2640 r = pm_runtime_get_sync(adev->ddev->dev);
2645 r = amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GFX_MCLK,
2646 (void *)&mclk, &size);
2648 pm_runtime_mark_last_busy(adev->ddev->dev);
2649 pm_runtime_put_autosuspend(adev->ddev->dev);
2654 return snprintf(buf, PAGE_SIZE, "%d\n", mclk * 10 * 1000);
2657 static ssize_t amdgpu_hwmon_show_mclk_label(struct device *dev,
2658 struct device_attribute *attr,
2661 return snprintf(buf, PAGE_SIZE, "mclk\n");
2667 * The amdgpu driver exposes the following sensor interfaces:
2669 * - GPU temperature (via the on-die sensor)
2673 * - Northbridge voltage (APUs only)
2679 * - GPU gfx/compute engine clock
2681 * - GPU memory clock (dGPU only)
2683 * hwmon interfaces for GPU temperature:
2685 * - temp[1-3]_input: the on die GPU temperature in millidegrees Celsius
2686 * - temp2_input and temp3_input are supported on SOC15 dGPUs only
2688 * - temp[1-3]_label: temperature channel label
2689 * - temp2_label and temp3_label are supported on SOC15 dGPUs only
2691 * - temp[1-3]_crit: temperature critical max value in millidegrees Celsius
2692 * - temp2_crit and temp3_crit are supported on SOC15 dGPUs only
2694 * - temp[1-3]_crit_hyst: temperature hysteresis for critical limit in millidegrees Celsius
2695 * - temp2_crit_hyst and temp3_crit_hyst are supported on SOC15 dGPUs only
2697 * - temp[1-3]_emergency: temperature emergency max value(asic shutdown) in millidegrees Celsius
2698 * - these are supported on SOC15 dGPUs only
2700 * hwmon interfaces for GPU voltage:
2702 * - in0_input: the voltage on the GPU in millivolts
2704 * - in1_input: the voltage on the Northbridge in millivolts
2706 * hwmon interfaces for GPU power:
2708 * - power1_average: average power used by the GPU in microWatts
2710 * - power1_cap_min: minimum cap supported in microWatts
2712 * - power1_cap_max: maximum cap supported in microWatts
2714 * - power1_cap: selected power cap in microWatts
2716 * hwmon interfaces for GPU fan:
2718 * - pwm1: pulse width modulation fan level (0-255)
2720 * - 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)
2722 * - pwm1_min: pulse width modulation fan control minimum level (0)
2724 * - pwm1_max: pulse width modulation fan control maximum level (255)
2726 * - fan1_min: an minimum value Unit: revolution/min (RPM)
2728 * - fan1_max: an maxmum value Unit: revolution/max (RPM)
2730 * - fan1_input: fan speed in RPM
2732 * - fan[1-\*]_target: Desired fan speed Unit: revolution/min (RPM)
2734 * - fan[1-\*]_enable: Enable or disable the sensors.1: Enable 0: Disable
2736 * hwmon interfaces for GPU clocks:
2738 * - freq1_input: the gfx/compute clock in hertz
2740 * - freq2_input: the memory clock in hertz
2742 * You can use hwmon tools like sensors to view this information on your system.
2746 static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, amdgpu_hwmon_show_temp, NULL, PP_TEMP_EDGE);
2747 static SENSOR_DEVICE_ATTR(temp1_crit, S_IRUGO, amdgpu_hwmon_show_temp_thresh, NULL, 0);
2748 static SENSOR_DEVICE_ATTR(temp1_crit_hyst, S_IRUGO, amdgpu_hwmon_show_temp_thresh, NULL, 1);
2749 static SENSOR_DEVICE_ATTR(temp1_emergency, S_IRUGO, amdgpu_hwmon_show_temp_emergency, NULL, PP_TEMP_EDGE);
2750 static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, amdgpu_hwmon_show_temp, NULL, PP_TEMP_JUNCTION);
2751 static SENSOR_DEVICE_ATTR(temp2_crit, S_IRUGO, amdgpu_hwmon_show_hotspot_temp_thresh, NULL, 0);
2752 static SENSOR_DEVICE_ATTR(temp2_crit_hyst, S_IRUGO, amdgpu_hwmon_show_hotspot_temp_thresh, NULL, 1);
2753 static SENSOR_DEVICE_ATTR(temp2_emergency, S_IRUGO, amdgpu_hwmon_show_temp_emergency, NULL, PP_TEMP_JUNCTION);
2754 static SENSOR_DEVICE_ATTR(temp3_input, S_IRUGO, amdgpu_hwmon_show_temp, NULL, PP_TEMP_MEM);
2755 static SENSOR_DEVICE_ATTR(temp3_crit, S_IRUGO, amdgpu_hwmon_show_mem_temp_thresh, NULL, 0);
2756 static SENSOR_DEVICE_ATTR(temp3_crit_hyst, S_IRUGO, amdgpu_hwmon_show_mem_temp_thresh, NULL, 1);
2757 static SENSOR_DEVICE_ATTR(temp3_emergency, S_IRUGO, amdgpu_hwmon_show_temp_emergency, NULL, PP_TEMP_MEM);
2758 static SENSOR_DEVICE_ATTR(temp1_label, S_IRUGO, amdgpu_hwmon_show_temp_label, NULL, PP_TEMP_EDGE);
2759 static SENSOR_DEVICE_ATTR(temp2_label, S_IRUGO, amdgpu_hwmon_show_temp_label, NULL, PP_TEMP_JUNCTION);
2760 static SENSOR_DEVICE_ATTR(temp3_label, S_IRUGO, amdgpu_hwmon_show_temp_label, NULL, PP_TEMP_MEM);
2761 static SENSOR_DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, amdgpu_hwmon_get_pwm1, amdgpu_hwmon_set_pwm1, 0);
2762 static SENSOR_DEVICE_ATTR(pwm1_enable, S_IRUGO | S_IWUSR, amdgpu_hwmon_get_pwm1_enable, amdgpu_hwmon_set_pwm1_enable, 0);
2763 static SENSOR_DEVICE_ATTR(pwm1_min, S_IRUGO, amdgpu_hwmon_get_pwm1_min, NULL, 0);
2764 static SENSOR_DEVICE_ATTR(pwm1_max, S_IRUGO, amdgpu_hwmon_get_pwm1_max, NULL, 0);
2765 static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, amdgpu_hwmon_get_fan1_input, NULL, 0);
2766 static SENSOR_DEVICE_ATTR(fan1_min, S_IRUGO, amdgpu_hwmon_get_fan1_min, NULL, 0);
2767 static SENSOR_DEVICE_ATTR(fan1_max, S_IRUGO, amdgpu_hwmon_get_fan1_max, NULL, 0);
2768 static SENSOR_DEVICE_ATTR(fan1_target, S_IRUGO | S_IWUSR, amdgpu_hwmon_get_fan1_target, amdgpu_hwmon_set_fan1_target, 0);
2769 static SENSOR_DEVICE_ATTR(fan1_enable, S_IRUGO | S_IWUSR, amdgpu_hwmon_get_fan1_enable, amdgpu_hwmon_set_fan1_enable, 0);
2770 static SENSOR_DEVICE_ATTR(in0_input, S_IRUGO, amdgpu_hwmon_show_vddgfx, NULL, 0);
2771 static SENSOR_DEVICE_ATTR(in0_label, S_IRUGO, amdgpu_hwmon_show_vddgfx_label, NULL, 0);
2772 static SENSOR_DEVICE_ATTR(in1_input, S_IRUGO, amdgpu_hwmon_show_vddnb, NULL, 0);
2773 static SENSOR_DEVICE_ATTR(in1_label, S_IRUGO, amdgpu_hwmon_show_vddnb_label, NULL, 0);
2774 static SENSOR_DEVICE_ATTR(power1_average, S_IRUGO, amdgpu_hwmon_show_power_avg, NULL, 0);
2775 static SENSOR_DEVICE_ATTR(power1_cap_max, S_IRUGO, amdgpu_hwmon_show_power_cap_max, NULL, 0);
2776 static SENSOR_DEVICE_ATTR(power1_cap_min, S_IRUGO, amdgpu_hwmon_show_power_cap_min, NULL, 0);
2777 static SENSOR_DEVICE_ATTR(power1_cap, S_IRUGO | S_IWUSR, amdgpu_hwmon_show_power_cap, amdgpu_hwmon_set_power_cap, 0);
2778 static SENSOR_DEVICE_ATTR(freq1_input, S_IRUGO, amdgpu_hwmon_show_sclk, NULL, 0);
2779 static SENSOR_DEVICE_ATTR(freq1_label, S_IRUGO, amdgpu_hwmon_show_sclk_label, NULL, 0);
2780 static SENSOR_DEVICE_ATTR(freq2_input, S_IRUGO, amdgpu_hwmon_show_mclk, NULL, 0);
2781 static SENSOR_DEVICE_ATTR(freq2_label, S_IRUGO, amdgpu_hwmon_show_mclk_label, NULL, 0);
2783 static struct attribute *hwmon_attributes[] = {
2784 &sensor_dev_attr_temp1_input.dev_attr.attr,
2785 &sensor_dev_attr_temp1_crit.dev_attr.attr,
2786 &sensor_dev_attr_temp1_crit_hyst.dev_attr.attr,
2787 &sensor_dev_attr_temp2_input.dev_attr.attr,
2788 &sensor_dev_attr_temp2_crit.dev_attr.attr,
2789 &sensor_dev_attr_temp2_crit_hyst.dev_attr.attr,
2790 &sensor_dev_attr_temp3_input.dev_attr.attr,
2791 &sensor_dev_attr_temp3_crit.dev_attr.attr,
2792 &sensor_dev_attr_temp3_crit_hyst.dev_attr.attr,
2793 &sensor_dev_attr_temp1_emergency.dev_attr.attr,
2794 &sensor_dev_attr_temp2_emergency.dev_attr.attr,
2795 &sensor_dev_attr_temp3_emergency.dev_attr.attr,
2796 &sensor_dev_attr_temp1_label.dev_attr.attr,
2797 &sensor_dev_attr_temp2_label.dev_attr.attr,
2798 &sensor_dev_attr_temp3_label.dev_attr.attr,
2799 &sensor_dev_attr_pwm1.dev_attr.attr,
2800 &sensor_dev_attr_pwm1_enable.dev_attr.attr,
2801 &sensor_dev_attr_pwm1_min.dev_attr.attr,
2802 &sensor_dev_attr_pwm1_max.dev_attr.attr,
2803 &sensor_dev_attr_fan1_input.dev_attr.attr,
2804 &sensor_dev_attr_fan1_min.dev_attr.attr,
2805 &sensor_dev_attr_fan1_max.dev_attr.attr,
2806 &sensor_dev_attr_fan1_target.dev_attr.attr,
2807 &sensor_dev_attr_fan1_enable.dev_attr.attr,
2808 &sensor_dev_attr_in0_input.dev_attr.attr,
2809 &sensor_dev_attr_in0_label.dev_attr.attr,
2810 &sensor_dev_attr_in1_input.dev_attr.attr,
2811 &sensor_dev_attr_in1_label.dev_attr.attr,
2812 &sensor_dev_attr_power1_average.dev_attr.attr,
2813 &sensor_dev_attr_power1_cap_max.dev_attr.attr,
2814 &sensor_dev_attr_power1_cap_min.dev_attr.attr,
2815 &sensor_dev_attr_power1_cap.dev_attr.attr,
2816 &sensor_dev_attr_freq1_input.dev_attr.attr,
2817 &sensor_dev_attr_freq1_label.dev_attr.attr,
2818 &sensor_dev_attr_freq2_input.dev_attr.attr,
2819 &sensor_dev_attr_freq2_label.dev_attr.attr,
2823 static umode_t hwmon_attributes_visible(struct kobject *kobj,
2824 struct attribute *attr, int index)
2826 struct device *dev = kobj_to_dev(kobj);
2827 struct amdgpu_device *adev = dev_get_drvdata(dev);
2828 umode_t effective_mode = attr->mode;
2830 /* under multi-vf mode, the hwmon attributes are all not supported */
2831 if (amdgpu_sriov_vf(adev) && !amdgpu_sriov_is_pp_one_vf(adev))
2834 /* there is no fan under pp one vf mode */
2835 if (amdgpu_sriov_is_pp_one_vf(adev) &&
2836 (attr == &sensor_dev_attr_pwm1.dev_attr.attr ||
2837 attr == &sensor_dev_attr_pwm1_enable.dev_attr.attr ||
2838 attr == &sensor_dev_attr_pwm1_max.dev_attr.attr ||
2839 attr == &sensor_dev_attr_pwm1_min.dev_attr.attr ||
2840 attr == &sensor_dev_attr_fan1_input.dev_attr.attr ||
2841 attr == &sensor_dev_attr_fan1_min.dev_attr.attr ||
2842 attr == &sensor_dev_attr_fan1_max.dev_attr.attr ||
2843 attr == &sensor_dev_attr_fan1_target.dev_attr.attr ||
2844 attr == &sensor_dev_attr_fan1_enable.dev_attr.attr))
2847 /* Skip fan attributes if fan is not present */
2848 if (adev->pm.no_fan && (attr == &sensor_dev_attr_pwm1.dev_attr.attr ||
2849 attr == &sensor_dev_attr_pwm1_enable.dev_attr.attr ||
2850 attr == &sensor_dev_attr_pwm1_max.dev_attr.attr ||
2851 attr == &sensor_dev_attr_pwm1_min.dev_attr.attr ||
2852 attr == &sensor_dev_attr_fan1_input.dev_attr.attr ||
2853 attr == &sensor_dev_attr_fan1_min.dev_attr.attr ||
2854 attr == &sensor_dev_attr_fan1_max.dev_attr.attr ||
2855 attr == &sensor_dev_attr_fan1_target.dev_attr.attr ||
2856 attr == &sensor_dev_attr_fan1_enable.dev_attr.attr))
2859 /* Skip fan attributes on APU */
2860 if ((adev->flags & AMD_IS_APU) &&
2861 (attr == &sensor_dev_attr_pwm1.dev_attr.attr ||
2862 attr == &sensor_dev_attr_pwm1_enable.dev_attr.attr ||
2863 attr == &sensor_dev_attr_pwm1_max.dev_attr.attr ||
2864 attr == &sensor_dev_attr_pwm1_min.dev_attr.attr ||
2865 attr == &sensor_dev_attr_fan1_input.dev_attr.attr ||
2866 attr == &sensor_dev_attr_fan1_min.dev_attr.attr ||
2867 attr == &sensor_dev_attr_fan1_max.dev_attr.attr ||
2868 attr == &sensor_dev_attr_fan1_target.dev_attr.attr ||
2869 attr == &sensor_dev_attr_fan1_enable.dev_attr.attr))
2872 /* Skip limit attributes if DPM is not enabled */
2873 if (!adev->pm.dpm_enabled &&
2874 (attr == &sensor_dev_attr_temp1_crit.dev_attr.attr ||
2875 attr == &sensor_dev_attr_temp1_crit_hyst.dev_attr.attr ||
2876 attr == &sensor_dev_attr_pwm1.dev_attr.attr ||
2877 attr == &sensor_dev_attr_pwm1_enable.dev_attr.attr ||
2878 attr == &sensor_dev_attr_pwm1_max.dev_attr.attr ||
2879 attr == &sensor_dev_attr_pwm1_min.dev_attr.attr ||
2880 attr == &sensor_dev_attr_fan1_input.dev_attr.attr ||
2881 attr == &sensor_dev_attr_fan1_min.dev_attr.attr ||
2882 attr == &sensor_dev_attr_fan1_max.dev_attr.attr ||
2883 attr == &sensor_dev_attr_fan1_target.dev_attr.attr ||
2884 attr == &sensor_dev_attr_fan1_enable.dev_attr.attr))
2887 if (!is_support_sw_smu(adev)) {
2888 /* mask fan attributes if we have no bindings for this asic to expose */
2889 if ((!adev->powerplay.pp_funcs->get_fan_speed_percent &&
2890 attr == &sensor_dev_attr_pwm1.dev_attr.attr) || /* can't query fan */
2891 (!adev->powerplay.pp_funcs->get_fan_control_mode &&
2892 attr == &sensor_dev_attr_pwm1_enable.dev_attr.attr)) /* can't query state */
2893 effective_mode &= ~S_IRUGO;
2895 if ((!adev->powerplay.pp_funcs->set_fan_speed_percent &&
2896 attr == &sensor_dev_attr_pwm1.dev_attr.attr) || /* can't manage fan */
2897 (!adev->powerplay.pp_funcs->set_fan_control_mode &&
2898 attr == &sensor_dev_attr_pwm1_enable.dev_attr.attr)) /* can't manage state */
2899 effective_mode &= ~S_IWUSR;
2902 if (((adev->flags & AMD_IS_APU) ||
2903 adev->family == AMDGPU_FAMILY_SI || /* not implemented yet */
2904 adev->family == AMDGPU_FAMILY_KV) && /* not implemented yet */
2905 (attr == &sensor_dev_attr_power1_average.dev_attr.attr ||
2906 attr == &sensor_dev_attr_power1_cap_max.dev_attr.attr ||
2907 attr == &sensor_dev_attr_power1_cap_min.dev_attr.attr||
2908 attr == &sensor_dev_attr_power1_cap.dev_attr.attr))
2911 if (!is_support_sw_smu(adev)) {
2912 /* hide max/min values if we can't both query and manage the fan */
2913 if ((!adev->powerplay.pp_funcs->set_fan_speed_percent &&
2914 !adev->powerplay.pp_funcs->get_fan_speed_percent) &&
2915 (!adev->powerplay.pp_funcs->set_fan_speed_rpm &&
2916 !adev->powerplay.pp_funcs->get_fan_speed_rpm) &&
2917 (attr == &sensor_dev_attr_pwm1_max.dev_attr.attr ||
2918 attr == &sensor_dev_attr_pwm1_min.dev_attr.attr))
2921 if ((!adev->powerplay.pp_funcs->set_fan_speed_rpm &&
2922 !adev->powerplay.pp_funcs->get_fan_speed_rpm) &&
2923 (attr == &sensor_dev_attr_fan1_max.dev_attr.attr ||
2924 attr == &sensor_dev_attr_fan1_min.dev_attr.attr))
2928 if ((adev->family == AMDGPU_FAMILY_SI || /* not implemented yet */
2929 adev->family == AMDGPU_FAMILY_KV) && /* not implemented yet */
2930 (attr == &sensor_dev_attr_in0_input.dev_attr.attr ||
2931 attr == &sensor_dev_attr_in0_label.dev_attr.attr))
2934 /* only APUs have vddnb */
2935 if (!(adev->flags & AMD_IS_APU) &&
2936 (attr == &sensor_dev_attr_in1_input.dev_attr.attr ||
2937 attr == &sensor_dev_attr_in1_label.dev_attr.attr))
2940 /* no mclk on APUs */
2941 if ((adev->flags & AMD_IS_APU) &&
2942 (attr == &sensor_dev_attr_freq2_input.dev_attr.attr ||
2943 attr == &sensor_dev_attr_freq2_label.dev_attr.attr))
2946 /* only SOC15 dGPUs support hotspot and mem temperatures */
2947 if (((adev->flags & AMD_IS_APU) ||
2948 adev->asic_type < CHIP_VEGA10) &&
2949 (attr == &sensor_dev_attr_temp2_crit.dev_attr.attr ||
2950 attr == &sensor_dev_attr_temp2_crit_hyst.dev_attr.attr ||
2951 attr == &sensor_dev_attr_temp3_crit.dev_attr.attr ||
2952 attr == &sensor_dev_attr_temp3_crit_hyst.dev_attr.attr ||
2953 attr == &sensor_dev_attr_temp1_emergency.dev_attr.attr ||
2954 attr == &sensor_dev_attr_temp2_emergency.dev_attr.attr ||
2955 attr == &sensor_dev_attr_temp3_emergency.dev_attr.attr ||
2956 attr == &sensor_dev_attr_temp2_input.dev_attr.attr ||
2957 attr == &sensor_dev_attr_temp3_input.dev_attr.attr ||
2958 attr == &sensor_dev_attr_temp2_label.dev_attr.attr ||
2959 attr == &sensor_dev_attr_temp3_label.dev_attr.attr))
2962 return effective_mode;
2965 static const struct attribute_group hwmon_attrgroup = {
2966 .attrs = hwmon_attributes,
2967 .is_visible = hwmon_attributes_visible,
2970 static const struct attribute_group *hwmon_groups[] = {
2975 void amdgpu_dpm_thermal_work_handler(struct work_struct *work)
2977 struct amdgpu_device *adev =
2978 container_of(work, struct amdgpu_device,
2979 pm.dpm.thermal.work);
2980 /* switch to the thermal state */
2981 enum amd_pm_state_type dpm_state = POWER_STATE_TYPE_INTERNAL_THERMAL;
2982 int temp, size = sizeof(temp);
2984 if (!adev->pm.dpm_enabled)
2987 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GPU_TEMP,
2988 (void *)&temp, &size)) {
2989 if (temp < adev->pm.dpm.thermal.min_temp)
2990 /* switch back the user state */
2991 dpm_state = adev->pm.dpm.user_state;
2993 if (adev->pm.dpm.thermal.high_to_low)
2994 /* switch back the user state */
2995 dpm_state = adev->pm.dpm.user_state;
2997 mutex_lock(&adev->pm.mutex);
2998 if (dpm_state == POWER_STATE_TYPE_INTERNAL_THERMAL)
2999 adev->pm.dpm.thermal_active = true;
3001 adev->pm.dpm.thermal_active = false;
3002 adev->pm.dpm.state = dpm_state;
3003 mutex_unlock(&adev->pm.mutex);
3005 amdgpu_pm_compute_clocks(adev);
3008 static struct amdgpu_ps *amdgpu_dpm_pick_power_state(struct amdgpu_device *adev,
3009 enum amd_pm_state_type dpm_state)
3012 struct amdgpu_ps *ps;
3014 bool single_display = (adev->pm.dpm.new_active_crtc_count < 2) ?
3017 /* check if the vblank period is too short to adjust the mclk */
3018 if (single_display && adev->powerplay.pp_funcs->vblank_too_short) {
3019 if (amdgpu_dpm_vblank_too_short(adev))
3020 single_display = false;
3023 /* certain older asics have a separare 3D performance state,
3024 * so try that first if the user selected performance
3026 if (dpm_state == POWER_STATE_TYPE_PERFORMANCE)
3027 dpm_state = POWER_STATE_TYPE_INTERNAL_3DPERF;
3028 /* balanced states don't exist at the moment */
3029 if (dpm_state == POWER_STATE_TYPE_BALANCED)
3030 dpm_state = POWER_STATE_TYPE_PERFORMANCE;
3033 /* Pick the best power state based on current conditions */
3034 for (i = 0; i < adev->pm.dpm.num_ps; i++) {
3035 ps = &adev->pm.dpm.ps[i];
3036 ui_class = ps->class & ATOM_PPLIB_CLASSIFICATION_UI_MASK;
3037 switch (dpm_state) {
3039 case POWER_STATE_TYPE_BATTERY:
3040 if (ui_class == ATOM_PPLIB_CLASSIFICATION_UI_BATTERY) {
3041 if (ps->caps & ATOM_PPLIB_SINGLE_DISPLAY_ONLY) {
3048 case POWER_STATE_TYPE_BALANCED:
3049 if (ui_class == ATOM_PPLIB_CLASSIFICATION_UI_BALANCED) {
3050 if (ps->caps & ATOM_PPLIB_SINGLE_DISPLAY_ONLY) {
3057 case POWER_STATE_TYPE_PERFORMANCE:
3058 if (ui_class == ATOM_PPLIB_CLASSIFICATION_UI_PERFORMANCE) {
3059 if (ps->caps & ATOM_PPLIB_SINGLE_DISPLAY_ONLY) {
3066 /* internal states */
3067 case POWER_STATE_TYPE_INTERNAL_UVD:
3068 if (adev->pm.dpm.uvd_ps)
3069 return adev->pm.dpm.uvd_ps;
3072 case POWER_STATE_TYPE_INTERNAL_UVD_SD:
3073 if (ps->class & ATOM_PPLIB_CLASSIFICATION_SDSTATE)
3076 case POWER_STATE_TYPE_INTERNAL_UVD_HD:
3077 if (ps->class & ATOM_PPLIB_CLASSIFICATION_HDSTATE)
3080 case POWER_STATE_TYPE_INTERNAL_UVD_HD2:
3081 if (ps->class & ATOM_PPLIB_CLASSIFICATION_HD2STATE)
3084 case POWER_STATE_TYPE_INTERNAL_UVD_MVC:
3085 if (ps->class2 & ATOM_PPLIB_CLASSIFICATION2_MVC)
3088 case POWER_STATE_TYPE_INTERNAL_BOOT:
3089 return adev->pm.dpm.boot_ps;
3090 case POWER_STATE_TYPE_INTERNAL_THERMAL:
3091 if (ps->class & ATOM_PPLIB_CLASSIFICATION_THERMAL)
3094 case POWER_STATE_TYPE_INTERNAL_ACPI:
3095 if (ps->class & ATOM_PPLIB_CLASSIFICATION_ACPI)
3098 case POWER_STATE_TYPE_INTERNAL_ULV:
3099 if (ps->class2 & ATOM_PPLIB_CLASSIFICATION2_ULV)
3102 case POWER_STATE_TYPE_INTERNAL_3DPERF:
3103 if (ps->class & ATOM_PPLIB_CLASSIFICATION_3DPERFORMANCE)
3110 /* use a fallback state if we didn't match */
3111 switch (dpm_state) {
3112 case POWER_STATE_TYPE_INTERNAL_UVD_SD:
3113 dpm_state = POWER_STATE_TYPE_INTERNAL_UVD_HD;
3114 goto restart_search;
3115 case POWER_STATE_TYPE_INTERNAL_UVD_HD:
3116 case POWER_STATE_TYPE_INTERNAL_UVD_HD2:
3117 case POWER_STATE_TYPE_INTERNAL_UVD_MVC:
3118 if (adev->pm.dpm.uvd_ps) {
3119 return adev->pm.dpm.uvd_ps;
3121 dpm_state = POWER_STATE_TYPE_PERFORMANCE;
3122 goto restart_search;
3124 case POWER_STATE_TYPE_INTERNAL_THERMAL:
3125 dpm_state = POWER_STATE_TYPE_INTERNAL_ACPI;
3126 goto restart_search;
3127 case POWER_STATE_TYPE_INTERNAL_ACPI:
3128 dpm_state = POWER_STATE_TYPE_BATTERY;
3129 goto restart_search;
3130 case POWER_STATE_TYPE_BATTERY:
3131 case POWER_STATE_TYPE_BALANCED:
3132 case POWER_STATE_TYPE_INTERNAL_3DPERF:
3133 dpm_state = POWER_STATE_TYPE_PERFORMANCE;
3134 goto restart_search;
3142 static void amdgpu_dpm_change_power_state_locked(struct amdgpu_device *adev)
3144 struct amdgpu_ps *ps;
3145 enum amd_pm_state_type dpm_state;
3149 /* if dpm init failed */
3150 if (!adev->pm.dpm_enabled)
3153 if (adev->pm.dpm.user_state != adev->pm.dpm.state) {
3154 /* add other state override checks here */
3155 if ((!adev->pm.dpm.thermal_active) &&
3156 (!adev->pm.dpm.uvd_active))
3157 adev->pm.dpm.state = adev->pm.dpm.user_state;
3159 dpm_state = adev->pm.dpm.state;
3161 ps = amdgpu_dpm_pick_power_state(adev, dpm_state);
3163 adev->pm.dpm.requested_ps = ps;
3167 if (amdgpu_dpm == 1 && adev->powerplay.pp_funcs->print_power_state) {
3168 printk("switching from power state:\n");
3169 amdgpu_dpm_print_power_state(adev, adev->pm.dpm.current_ps);
3170 printk("switching to power state:\n");
3171 amdgpu_dpm_print_power_state(adev, adev->pm.dpm.requested_ps);
3174 /* update whether vce is active */
3175 ps->vce_active = adev->pm.dpm.vce_active;
3176 if (adev->powerplay.pp_funcs->display_configuration_changed)
3177 amdgpu_dpm_display_configuration_changed(adev);
3179 ret = amdgpu_dpm_pre_set_power_state(adev);
3183 if (adev->powerplay.pp_funcs->check_state_equal) {
3184 if (0 != amdgpu_dpm_check_state_equal(adev, adev->pm.dpm.current_ps, adev->pm.dpm.requested_ps, &equal))
3191 amdgpu_dpm_set_power_state(adev);
3192 amdgpu_dpm_post_set_power_state(adev);
3194 adev->pm.dpm.current_active_crtcs = adev->pm.dpm.new_active_crtcs;
3195 adev->pm.dpm.current_active_crtc_count = adev->pm.dpm.new_active_crtc_count;
3197 if (adev->powerplay.pp_funcs->force_performance_level) {
3198 if (adev->pm.dpm.thermal_active) {
3199 enum amd_dpm_forced_level level = adev->pm.dpm.forced_level;
3200 /* force low perf level for thermal */
3201 amdgpu_dpm_force_performance_level(adev, AMD_DPM_FORCED_LEVEL_LOW);
3202 /* save the user's level */
3203 adev->pm.dpm.forced_level = level;
3205 /* otherwise, user selected level */
3206 amdgpu_dpm_force_performance_level(adev, adev->pm.dpm.forced_level);
3211 void amdgpu_dpm_enable_uvd(struct amdgpu_device *adev, bool enable)
3215 ret = amdgpu_dpm_set_powergating_by_smu(adev, AMD_IP_BLOCK_TYPE_UVD, !enable);
3217 DRM_ERROR("Dpm %s uvd failed, ret = %d. \n",
3218 enable ? "enable" : "disable", ret);
3220 /* enable/disable Low Memory PState for UVD (4k videos) */
3221 if (adev->asic_type == CHIP_STONEY &&
3222 adev->uvd.decode_image_width >= WIDTH_4K) {
3223 struct pp_hwmgr *hwmgr = adev->powerplay.pp_handle;
3225 if (hwmgr && hwmgr->hwmgr_func &&
3226 hwmgr->hwmgr_func->update_nbdpm_pstate)
3227 hwmgr->hwmgr_func->update_nbdpm_pstate(hwmgr,
3233 void amdgpu_dpm_enable_vce(struct amdgpu_device *adev, bool enable)
3237 ret = amdgpu_dpm_set_powergating_by_smu(adev, AMD_IP_BLOCK_TYPE_VCE, !enable);
3239 DRM_ERROR("Dpm %s vce failed, ret = %d. \n",
3240 enable ? "enable" : "disable", ret);
3243 void amdgpu_pm_print_power_states(struct amdgpu_device *adev)
3247 if (adev->powerplay.pp_funcs->print_power_state == NULL)
3250 for (i = 0; i < adev->pm.dpm.num_ps; i++)
3251 amdgpu_dpm_print_power_state(adev, &adev->pm.dpm.ps[i]);
3255 void amdgpu_dpm_enable_jpeg(struct amdgpu_device *adev, bool enable)
3259 ret = amdgpu_dpm_set_powergating_by_smu(adev, AMD_IP_BLOCK_TYPE_JPEG, !enable);
3261 DRM_ERROR("Dpm %s jpeg failed, ret = %d. \n",
3262 enable ? "enable" : "disable", ret);
3265 int amdgpu_pm_load_smu_firmware(struct amdgpu_device *adev, uint32_t *smu_version)
3269 if (adev->powerplay.pp_funcs && adev->powerplay.pp_funcs->load_firmware) {
3270 r = adev->powerplay.pp_funcs->load_firmware(adev->powerplay.pp_handle);
3272 pr_err("smu firmware loading failed\n");
3275 *smu_version = adev->pm.fw_version;
3280 int amdgpu_pm_sysfs_init(struct amdgpu_device *adev)
3285 if (adev->pm.sysfs_initialized)
3288 if (adev->pm.dpm_enabled == 0)
3291 INIT_LIST_HEAD(&adev->pm.pm_attr_list);
3293 adev->pm.int_hwmon_dev = hwmon_device_register_with_groups(adev->dev,
3296 if (IS_ERR(adev->pm.int_hwmon_dev)) {
3297 ret = PTR_ERR(adev->pm.int_hwmon_dev);
3299 "Unable to register hwmon device: %d\n", ret);
3303 switch (amdgpu_virt_get_sriov_vf_mode(adev)) {
3304 case SRIOV_VF_MODE_ONE_VF:
3305 mask = ATTR_FLAG_ONEVF;
3307 case SRIOV_VF_MODE_MULTI_VF:
3310 case SRIOV_VF_MODE_BARE_METAL:
3312 mask = ATTR_FLAG_MASK_ALL;
3316 ret = amdgpu_device_attr_create_groups(adev,
3317 amdgpu_device_attrs,
3318 ARRAY_SIZE(amdgpu_device_attrs),
3320 &adev->pm.pm_attr_list);
3324 adev->pm.sysfs_initialized = true;
3329 void amdgpu_pm_sysfs_fini(struct amdgpu_device *adev)
3331 if (adev->pm.dpm_enabled == 0)
3334 if (adev->pm.int_hwmon_dev)
3335 hwmon_device_unregister(adev->pm.int_hwmon_dev);
3337 amdgpu_device_attr_remove_groups(adev, &adev->pm.pm_attr_list);
3340 void amdgpu_pm_compute_clocks(struct amdgpu_device *adev)
3344 if (!adev->pm.dpm_enabled)
3347 if (adev->mode_info.num_crtc)
3348 amdgpu_display_bandwidth_update(adev);
3350 for (i = 0; i < AMDGPU_MAX_RINGS; i++) {
3351 struct amdgpu_ring *ring = adev->rings[i];
3352 if (ring && ring->sched.ready)
3353 amdgpu_fence_wait_empty(ring);
3356 if (is_support_sw_smu(adev)) {
3357 struct smu_dpm_context *smu_dpm = &adev->smu.smu_dpm;
3358 smu_handle_task(&adev->smu,
3360 AMD_PP_TASK_DISPLAY_CONFIG_CHANGE,
3363 if (adev->powerplay.pp_funcs->dispatch_tasks) {
3364 if (!amdgpu_device_has_dc_support(adev)) {
3365 mutex_lock(&adev->pm.mutex);
3366 amdgpu_dpm_get_active_displays(adev);
3367 adev->pm.pm_display_cfg.num_display = adev->pm.dpm.new_active_crtc_count;
3368 adev->pm.pm_display_cfg.vrefresh = amdgpu_dpm_get_vrefresh(adev);
3369 adev->pm.pm_display_cfg.min_vblank_time = amdgpu_dpm_get_vblank_time(adev);
3370 /* we have issues with mclk switching with refresh rates over 120 hz on the non-DC code. */
3371 if (adev->pm.pm_display_cfg.vrefresh > 120)
3372 adev->pm.pm_display_cfg.min_vblank_time = 0;
3373 if (adev->powerplay.pp_funcs->display_configuration_change)
3374 adev->powerplay.pp_funcs->display_configuration_change(
3375 adev->powerplay.pp_handle,
3376 &adev->pm.pm_display_cfg);
3377 mutex_unlock(&adev->pm.mutex);
3379 amdgpu_dpm_dispatch_task(adev, AMD_PP_TASK_DISPLAY_CONFIG_CHANGE, NULL);
3381 mutex_lock(&adev->pm.mutex);
3382 amdgpu_dpm_get_active_displays(adev);
3383 amdgpu_dpm_change_power_state_locked(adev);
3384 mutex_unlock(&adev->pm.mutex);
3392 #if defined(CONFIG_DEBUG_FS)
3394 static int amdgpu_debugfs_pm_info_pp(struct seq_file *m, struct amdgpu_device *adev)
3402 size = sizeof(value);
3403 seq_printf(m, "GFX Clocks and Power:\n");
3404 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GFX_MCLK, (void *)&value, &size))
3405 seq_printf(m, "\t%u MHz (MCLK)\n", value/100);
3406 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GFX_SCLK, (void *)&value, &size))
3407 seq_printf(m, "\t%u MHz (SCLK)\n", value/100);
3408 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_STABLE_PSTATE_SCLK, (void *)&value, &size))
3409 seq_printf(m, "\t%u MHz (PSTATE_SCLK)\n", value/100);
3410 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_STABLE_PSTATE_MCLK, (void *)&value, &size))
3411 seq_printf(m, "\t%u MHz (PSTATE_MCLK)\n", value/100);
3412 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_VDDGFX, (void *)&value, &size))
3413 seq_printf(m, "\t%u mV (VDDGFX)\n", value);
3414 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_VDDNB, (void *)&value, &size))
3415 seq_printf(m, "\t%u mV (VDDNB)\n", value);
3416 size = sizeof(uint32_t);
3417 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GPU_POWER, (void *)&query, &size))
3418 seq_printf(m, "\t%u.%u W (average GPU)\n", query >> 8, query & 0xff);
3419 size = sizeof(value);
3420 seq_printf(m, "\n");
3423 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GPU_TEMP, (void *)&value, &size))
3424 seq_printf(m, "GPU Temperature: %u C\n", value/1000);
3427 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GPU_LOAD, (void *)&value, &size))
3428 seq_printf(m, "GPU Load: %u %%\n", value);
3430 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_MEM_LOAD, (void *)&value, &size))
3431 seq_printf(m, "MEM Load: %u %%\n", value);
3433 seq_printf(m, "\n");
3435 /* SMC feature mask */
3436 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_ENABLED_SMC_FEATURES_MASK, (void *)&value64, &size))
3437 seq_printf(m, "SMC Feature Mask: 0x%016llx\n", value64);
3439 if (adev->asic_type > CHIP_VEGA20) {
3441 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_VCN_POWER_STATE, (void *)&value, &size)) {
3443 seq_printf(m, "VCN: Disabled\n");
3445 seq_printf(m, "VCN: Enabled\n");
3446 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_UVD_DCLK, (void *)&value, &size))
3447 seq_printf(m, "\t%u MHz (DCLK)\n", value/100);
3448 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_UVD_VCLK, (void *)&value, &size))
3449 seq_printf(m, "\t%u MHz (VCLK)\n", value/100);
3452 seq_printf(m, "\n");
3455 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_UVD_POWER, (void *)&value, &size)) {
3457 seq_printf(m, "UVD: Disabled\n");
3459 seq_printf(m, "UVD: Enabled\n");
3460 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_UVD_DCLK, (void *)&value, &size))
3461 seq_printf(m, "\t%u MHz (DCLK)\n", value/100);
3462 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_UVD_VCLK, (void *)&value, &size))
3463 seq_printf(m, "\t%u MHz (VCLK)\n", value/100);
3466 seq_printf(m, "\n");
3469 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_VCE_POWER, (void *)&value, &size)) {
3471 seq_printf(m, "VCE: Disabled\n");
3473 seq_printf(m, "VCE: Enabled\n");
3474 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_VCE_ECCLK, (void *)&value, &size))
3475 seq_printf(m, "\t%u MHz (ECCLK)\n", value/100);
3483 static void amdgpu_parse_cg_state(struct seq_file *m, u32 flags)
3487 for (i = 0; clocks[i].flag; i++)
3488 seq_printf(m, "\t%s: %s\n", clocks[i].name,
3489 (flags & clocks[i].flag) ? "On" : "Off");
3492 static int amdgpu_debugfs_pm_info(struct seq_file *m, void *data)
3494 struct drm_info_node *node = (struct drm_info_node *) m->private;
3495 struct drm_device *dev = node->minor->dev;
3496 struct amdgpu_device *adev = dev->dev_private;
3500 r = pm_runtime_get_sync(dev->dev);
3504 amdgpu_device_ip_get_clockgating_state(adev, &flags);
3505 seq_printf(m, "Clock Gating Flags Mask: 0x%x\n", flags);
3506 amdgpu_parse_cg_state(m, flags);
3507 seq_printf(m, "\n");
3509 if (!adev->pm.dpm_enabled) {
3510 seq_printf(m, "dpm not enabled\n");
3511 pm_runtime_mark_last_busy(dev->dev);
3512 pm_runtime_put_autosuspend(dev->dev);
3516 if (!is_support_sw_smu(adev) &&
3517 adev->powerplay.pp_funcs->debugfs_print_current_performance_level) {
3518 mutex_lock(&adev->pm.mutex);
3519 if (adev->powerplay.pp_funcs->debugfs_print_current_performance_level)
3520 adev->powerplay.pp_funcs->debugfs_print_current_performance_level(adev, m);
3522 seq_printf(m, "Debugfs support not implemented for this asic\n");
3523 mutex_unlock(&adev->pm.mutex);
3526 r = amdgpu_debugfs_pm_info_pp(m, adev);
3529 pm_runtime_mark_last_busy(dev->dev);
3530 pm_runtime_put_autosuspend(dev->dev);
3535 static const struct drm_info_list amdgpu_pm_info_list[] = {
3536 {"amdgpu_pm_info", amdgpu_debugfs_pm_info, 0, NULL},
3540 int amdgpu_debugfs_pm_init(struct amdgpu_device *adev)
3542 #if defined(CONFIG_DEBUG_FS)
3543 return amdgpu_debugfs_add_files(adev, amdgpu_pm_info_list, ARRAY_SIZE(amdgpu_pm_info_list));