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->enable_bapm)
93 amdgpu_dpm_enable_bapm(adev, adev->pm.ac_power);
94 mutex_unlock(&adev->pm.mutex);
96 if (is_support_sw_smu(adev))
97 smu_set_ac_dc(&adev->smu);
101 int amdgpu_dpm_read_sensor(struct amdgpu_device *adev, enum amd_pp_sensors sensor,
102 void *data, uint32_t *size)
109 if (is_support_sw_smu(adev))
110 ret = smu_read_sensor(&adev->smu, sensor, data, size);
112 if (adev->powerplay.pp_funcs && adev->powerplay.pp_funcs->read_sensor)
113 ret = adev->powerplay.pp_funcs->read_sensor((adev)->powerplay.pp_handle,
123 * DOC: power_dpm_state
125 * The power_dpm_state file is a legacy interface and is only provided for
126 * backwards compatibility. The amdgpu driver provides a sysfs API for adjusting
127 * certain power related parameters. The file power_dpm_state is used for this.
128 * It accepts the following arguments:
138 * On older GPUs, the vbios provided a special power state for battery
139 * operation. Selecting battery switched to this state. This is no
140 * longer provided on newer GPUs so the option does nothing in that case.
144 * On older GPUs, the vbios provided a special power state for balanced
145 * operation. Selecting balanced switched to this state. This is no
146 * longer provided on newer GPUs so the option does nothing in that case.
150 * On older GPUs, the vbios provided a special power state for performance
151 * operation. Selecting performance switched to this state. This is no
152 * longer provided on newer GPUs so the option does nothing in that case.
156 static ssize_t amdgpu_get_dpm_state(struct device *dev,
157 struct device_attribute *attr,
160 struct drm_device *ddev = dev_get_drvdata(dev);
161 struct amdgpu_device *adev = ddev->dev_private;
162 enum amd_pm_state_type pm;
165 if (amdgpu_sriov_vf(adev) && !amdgpu_sriov_is_pp_one_vf(adev))
168 ret = pm_runtime_get_sync(ddev->dev);
172 if (is_support_sw_smu(adev)) {
173 if (adev->smu.ppt_funcs->get_current_power_state)
174 pm = smu_get_current_power_state(&adev->smu);
176 pm = adev->pm.dpm.user_state;
177 } else if (adev->powerplay.pp_funcs->get_current_power_state) {
178 pm = amdgpu_dpm_get_current_power_state(adev);
180 pm = adev->pm.dpm.user_state;
183 pm_runtime_mark_last_busy(ddev->dev);
184 pm_runtime_put_autosuspend(ddev->dev);
186 return snprintf(buf, PAGE_SIZE, "%s\n",
187 (pm == POWER_STATE_TYPE_BATTERY) ? "battery" :
188 (pm == POWER_STATE_TYPE_BALANCED) ? "balanced" : "performance");
191 static ssize_t amdgpu_set_dpm_state(struct device *dev,
192 struct device_attribute *attr,
196 struct drm_device *ddev = dev_get_drvdata(dev);
197 struct amdgpu_device *adev = ddev->dev_private;
198 enum amd_pm_state_type state;
201 if (amdgpu_sriov_vf(adev) && !amdgpu_sriov_is_pp_one_vf(adev))
204 if (strncmp("battery", buf, strlen("battery")) == 0)
205 state = POWER_STATE_TYPE_BATTERY;
206 else if (strncmp("balanced", buf, strlen("balanced")) == 0)
207 state = POWER_STATE_TYPE_BALANCED;
208 else if (strncmp("performance", buf, strlen("performance")) == 0)
209 state = POWER_STATE_TYPE_PERFORMANCE;
213 ret = pm_runtime_get_sync(ddev->dev);
217 if (is_support_sw_smu(adev)) {
218 mutex_lock(&adev->pm.mutex);
219 adev->pm.dpm.user_state = state;
220 mutex_unlock(&adev->pm.mutex);
221 } else if (adev->powerplay.pp_funcs->dispatch_tasks) {
222 amdgpu_dpm_dispatch_task(adev, AMD_PP_TASK_ENABLE_USER_STATE, &state);
224 mutex_lock(&adev->pm.mutex);
225 adev->pm.dpm.user_state = state;
226 mutex_unlock(&adev->pm.mutex);
228 amdgpu_pm_compute_clocks(adev);
230 pm_runtime_mark_last_busy(ddev->dev);
231 pm_runtime_put_autosuspend(ddev->dev);
238 * DOC: power_dpm_force_performance_level
240 * The amdgpu driver provides a sysfs API for adjusting certain power
241 * related parameters. The file power_dpm_force_performance_level is
242 * used for this. It accepts the following arguments:
262 * When auto is selected, the driver will attempt to dynamically select
263 * the optimal power profile for current conditions in the driver.
267 * When low is selected, the clocks are forced to the lowest power state.
271 * When high is selected, the clocks are forced to the highest power state.
275 * When manual is selected, the user can manually adjust which power states
276 * are enabled for each clock domain via the sysfs pp_dpm_mclk, pp_dpm_sclk,
277 * and pp_dpm_pcie files and adjust the power state transition heuristics
278 * via the pp_power_profile_mode sysfs file.
285 * When the profiling modes are selected, clock and power gating are
286 * disabled and the clocks are set for different profiling cases. This
287 * mode is recommended for profiling specific work loads where you do
288 * not want clock or power gating for clock fluctuation to interfere
289 * with your results. profile_standard sets the clocks to a fixed clock
290 * level which varies from asic to asic. profile_min_sclk forces the sclk
291 * to the lowest level. profile_min_mclk forces the mclk to the lowest level.
292 * profile_peak sets all clocks (mclk, sclk, pcie) to the highest levels.
296 static ssize_t amdgpu_get_dpm_forced_performance_level(struct device *dev,
297 struct device_attribute *attr,
300 struct drm_device *ddev = dev_get_drvdata(dev);
301 struct amdgpu_device *adev = ddev->dev_private;
302 enum amd_dpm_forced_level level = 0xff;
305 if (amdgpu_sriov_vf(adev) && !amdgpu_sriov_is_pp_one_vf(adev))
308 ret = pm_runtime_get_sync(ddev->dev);
312 if (is_support_sw_smu(adev))
313 level = smu_get_performance_level(&adev->smu);
314 else if (adev->powerplay.pp_funcs->get_performance_level)
315 level = amdgpu_dpm_get_performance_level(adev);
317 level = adev->pm.dpm.forced_level;
319 pm_runtime_mark_last_busy(ddev->dev);
320 pm_runtime_put_autosuspend(ddev->dev);
322 return snprintf(buf, PAGE_SIZE, "%s\n",
323 (level == AMD_DPM_FORCED_LEVEL_AUTO) ? "auto" :
324 (level == AMD_DPM_FORCED_LEVEL_LOW) ? "low" :
325 (level == AMD_DPM_FORCED_LEVEL_HIGH) ? "high" :
326 (level == AMD_DPM_FORCED_LEVEL_MANUAL) ? "manual" :
327 (level == AMD_DPM_FORCED_LEVEL_PROFILE_STANDARD) ? "profile_standard" :
328 (level == AMD_DPM_FORCED_LEVEL_PROFILE_MIN_SCLK) ? "profile_min_sclk" :
329 (level == AMD_DPM_FORCED_LEVEL_PROFILE_MIN_MCLK) ? "profile_min_mclk" :
330 (level == AMD_DPM_FORCED_LEVEL_PROFILE_PEAK) ? "profile_peak" :
334 static ssize_t amdgpu_set_dpm_forced_performance_level(struct device *dev,
335 struct device_attribute *attr,
339 struct drm_device *ddev = dev_get_drvdata(dev);
340 struct amdgpu_device *adev = ddev->dev_private;
341 enum amd_dpm_forced_level level;
342 enum amd_dpm_forced_level current_level = 0xff;
345 if (amdgpu_sriov_vf(adev) && !amdgpu_sriov_is_pp_one_vf(adev))
348 if (strncmp("low", buf, strlen("low")) == 0) {
349 level = AMD_DPM_FORCED_LEVEL_LOW;
350 } else if (strncmp("high", buf, strlen("high")) == 0) {
351 level = AMD_DPM_FORCED_LEVEL_HIGH;
352 } else if (strncmp("auto", buf, strlen("auto")) == 0) {
353 level = AMD_DPM_FORCED_LEVEL_AUTO;
354 } else if (strncmp("manual", buf, strlen("manual")) == 0) {
355 level = AMD_DPM_FORCED_LEVEL_MANUAL;
356 } else if (strncmp("profile_exit", buf, strlen("profile_exit")) == 0) {
357 level = AMD_DPM_FORCED_LEVEL_PROFILE_EXIT;
358 } else if (strncmp("profile_standard", buf, strlen("profile_standard")) == 0) {
359 level = AMD_DPM_FORCED_LEVEL_PROFILE_STANDARD;
360 } else if (strncmp("profile_min_sclk", buf, strlen("profile_min_sclk")) == 0) {
361 level = AMD_DPM_FORCED_LEVEL_PROFILE_MIN_SCLK;
362 } else if (strncmp("profile_min_mclk", buf, strlen("profile_min_mclk")) == 0) {
363 level = AMD_DPM_FORCED_LEVEL_PROFILE_MIN_MCLK;
364 } else if (strncmp("profile_peak", buf, strlen("profile_peak")) == 0) {
365 level = AMD_DPM_FORCED_LEVEL_PROFILE_PEAK;
370 ret = pm_runtime_get_sync(ddev->dev);
374 if (is_support_sw_smu(adev))
375 current_level = smu_get_performance_level(&adev->smu);
376 else if (adev->powerplay.pp_funcs->get_performance_level)
377 current_level = amdgpu_dpm_get_performance_level(adev);
379 if (current_level == level) {
380 pm_runtime_mark_last_busy(ddev->dev);
381 pm_runtime_put_autosuspend(ddev->dev);
385 /* profile_exit setting is valid only when current mode is in profile mode */
386 if (!(current_level & (AMD_DPM_FORCED_LEVEL_PROFILE_STANDARD |
387 AMD_DPM_FORCED_LEVEL_PROFILE_MIN_SCLK |
388 AMD_DPM_FORCED_LEVEL_PROFILE_MIN_MCLK |
389 AMD_DPM_FORCED_LEVEL_PROFILE_PEAK)) &&
390 (level == AMD_DPM_FORCED_LEVEL_PROFILE_EXIT)) {
391 pr_err("Currently not in any profile mode!\n");
392 pm_runtime_mark_last_busy(ddev->dev);
393 pm_runtime_put_autosuspend(ddev->dev);
397 if (is_support_sw_smu(adev)) {
398 ret = smu_force_performance_level(&adev->smu, level);
400 pm_runtime_mark_last_busy(ddev->dev);
401 pm_runtime_put_autosuspend(ddev->dev);
404 } else if (adev->powerplay.pp_funcs->force_performance_level) {
405 mutex_lock(&adev->pm.mutex);
406 if (adev->pm.dpm.thermal_active) {
407 mutex_unlock(&adev->pm.mutex);
408 pm_runtime_mark_last_busy(ddev->dev);
409 pm_runtime_put_autosuspend(ddev->dev);
412 ret = amdgpu_dpm_force_performance_level(adev, level);
414 mutex_unlock(&adev->pm.mutex);
415 pm_runtime_mark_last_busy(ddev->dev);
416 pm_runtime_put_autosuspend(ddev->dev);
419 adev->pm.dpm.forced_level = level;
421 mutex_unlock(&adev->pm.mutex);
423 pm_runtime_mark_last_busy(ddev->dev);
424 pm_runtime_put_autosuspend(ddev->dev);
429 static ssize_t amdgpu_get_pp_num_states(struct device *dev,
430 struct device_attribute *attr,
433 struct drm_device *ddev = dev_get_drvdata(dev);
434 struct amdgpu_device *adev = ddev->dev_private;
435 struct pp_states_info data;
438 ret = pm_runtime_get_sync(ddev->dev);
442 if (is_support_sw_smu(adev)) {
443 ret = smu_get_power_num_states(&adev->smu, &data);
446 } else if (adev->powerplay.pp_funcs->get_pp_num_states)
447 amdgpu_dpm_get_pp_num_states(adev, &data);
449 pm_runtime_mark_last_busy(ddev->dev);
450 pm_runtime_put_autosuspend(ddev->dev);
452 buf_len = snprintf(buf, PAGE_SIZE, "states: %d\n", data.nums);
453 for (i = 0; i < data.nums; i++)
454 buf_len += snprintf(buf + buf_len, PAGE_SIZE, "%d %s\n", i,
455 (data.states[i] == POWER_STATE_TYPE_INTERNAL_BOOT) ? "boot" :
456 (data.states[i] == POWER_STATE_TYPE_BATTERY) ? "battery" :
457 (data.states[i] == POWER_STATE_TYPE_BALANCED) ? "balanced" :
458 (data.states[i] == POWER_STATE_TYPE_PERFORMANCE) ? "performance" : "default");
463 static ssize_t amdgpu_get_pp_cur_state(struct device *dev,
464 struct device_attribute *attr,
467 struct drm_device *ddev = dev_get_drvdata(dev);
468 struct amdgpu_device *adev = ddev->dev_private;
469 struct pp_states_info data;
470 struct smu_context *smu = &adev->smu;
471 enum amd_pm_state_type pm = 0;
474 if (amdgpu_sriov_vf(adev) && !amdgpu_sriov_is_pp_one_vf(adev))
477 ret = pm_runtime_get_sync(ddev->dev);
481 if (is_support_sw_smu(adev)) {
482 pm = smu_get_current_power_state(smu);
483 ret = smu_get_power_num_states(smu, &data);
486 } else if (adev->powerplay.pp_funcs->get_current_power_state
487 && adev->powerplay.pp_funcs->get_pp_num_states) {
488 pm = amdgpu_dpm_get_current_power_state(adev);
489 amdgpu_dpm_get_pp_num_states(adev, &data);
492 pm_runtime_mark_last_busy(ddev->dev);
493 pm_runtime_put_autosuspend(ddev->dev);
495 for (i = 0; i < data.nums; i++) {
496 if (pm == data.states[i])
503 return snprintf(buf, PAGE_SIZE, "%d\n", i);
506 static ssize_t amdgpu_get_pp_force_state(struct device *dev,
507 struct device_attribute *attr,
510 struct drm_device *ddev = dev_get_drvdata(dev);
511 struct amdgpu_device *adev = ddev->dev_private;
513 if (amdgpu_sriov_vf(adev) && !amdgpu_sriov_is_pp_one_vf(adev))
516 if (adev->pp_force_state_enabled)
517 return amdgpu_get_pp_cur_state(dev, attr, buf);
519 return snprintf(buf, PAGE_SIZE, "\n");
522 static ssize_t amdgpu_set_pp_force_state(struct device *dev,
523 struct device_attribute *attr,
527 struct drm_device *ddev = dev_get_drvdata(dev);
528 struct amdgpu_device *adev = ddev->dev_private;
529 enum amd_pm_state_type state = 0;
533 if (amdgpu_sriov_vf(adev) && !amdgpu_sriov_is_pp_one_vf(adev))
536 if (strlen(buf) == 1)
537 adev->pp_force_state_enabled = false;
538 else if (is_support_sw_smu(adev))
539 adev->pp_force_state_enabled = false;
540 else if (adev->powerplay.pp_funcs->dispatch_tasks &&
541 adev->powerplay.pp_funcs->get_pp_num_states) {
542 struct pp_states_info data;
544 ret = kstrtoul(buf, 0, &idx);
545 if (ret || idx >= ARRAY_SIZE(data.states))
548 idx = array_index_nospec(idx, ARRAY_SIZE(data.states));
550 amdgpu_dpm_get_pp_num_states(adev, &data);
551 state = data.states[idx];
553 ret = pm_runtime_get_sync(ddev->dev);
557 /* only set user selected power states */
558 if (state != POWER_STATE_TYPE_INTERNAL_BOOT &&
559 state != POWER_STATE_TYPE_DEFAULT) {
560 amdgpu_dpm_dispatch_task(adev,
561 AMD_PP_TASK_ENABLE_USER_STATE, &state);
562 adev->pp_force_state_enabled = true;
564 pm_runtime_mark_last_busy(ddev->dev);
565 pm_runtime_put_autosuspend(ddev->dev);
574 * The amdgpu driver provides a sysfs API for uploading new powerplay
575 * tables. The file pp_table is used for this. Reading the file
576 * will dump the current power play table. Writing to the file
577 * will attempt to upload a new powerplay table and re-initialize
578 * powerplay using that new table.
582 static ssize_t amdgpu_get_pp_table(struct device *dev,
583 struct device_attribute *attr,
586 struct drm_device *ddev = dev_get_drvdata(dev);
587 struct amdgpu_device *adev = ddev->dev_private;
591 if (amdgpu_sriov_vf(adev) && !amdgpu_sriov_is_pp_one_vf(adev))
594 ret = pm_runtime_get_sync(ddev->dev);
598 if (is_support_sw_smu(adev)) {
599 size = smu_sys_get_pp_table(&adev->smu, (void **)&table);
600 pm_runtime_mark_last_busy(ddev->dev);
601 pm_runtime_put_autosuspend(ddev->dev);
604 } else if (adev->powerplay.pp_funcs->get_pp_table) {
605 size = amdgpu_dpm_get_pp_table(adev, &table);
606 pm_runtime_mark_last_busy(ddev->dev);
607 pm_runtime_put_autosuspend(ddev->dev);
611 pm_runtime_mark_last_busy(ddev->dev);
612 pm_runtime_put_autosuspend(ddev->dev);
616 if (size >= PAGE_SIZE)
617 size = PAGE_SIZE - 1;
619 memcpy(buf, table, size);
624 static ssize_t amdgpu_set_pp_table(struct device *dev,
625 struct device_attribute *attr,
629 struct drm_device *ddev = dev_get_drvdata(dev);
630 struct amdgpu_device *adev = ddev->dev_private;
633 if (amdgpu_sriov_vf(adev) && !amdgpu_sriov_is_pp_one_vf(adev))
636 ret = pm_runtime_get_sync(ddev->dev);
640 if (is_support_sw_smu(adev)) {
641 ret = smu_sys_set_pp_table(&adev->smu, (void *)buf, count);
643 pm_runtime_mark_last_busy(ddev->dev);
644 pm_runtime_put_autosuspend(ddev->dev);
647 } else if (adev->powerplay.pp_funcs->set_pp_table)
648 amdgpu_dpm_set_pp_table(adev, buf, count);
650 pm_runtime_mark_last_busy(ddev->dev);
651 pm_runtime_put_autosuspend(ddev->dev);
657 * DOC: pp_od_clk_voltage
659 * The amdgpu driver provides a sysfs API for adjusting the clocks and voltages
660 * in each power level within a power state. The pp_od_clk_voltage is used for
663 * < For Vega10 and previous ASICs >
665 * Reading the file will display:
667 * - a list of engine clock levels and voltages labeled OD_SCLK
669 * - a list of memory clock levels and voltages labeled OD_MCLK
671 * - a list of valid ranges for sclk, mclk, and voltage labeled OD_RANGE
673 * To manually adjust these settings, first select manual using
674 * power_dpm_force_performance_level. Enter a new value for each
675 * level by writing a string that contains "s/m level clock voltage" to
676 * the file. E.g., "s 1 500 820" will update sclk level 1 to be 500 MHz
677 * at 820 mV; "m 0 350 810" will update mclk level 0 to be 350 MHz at
678 * 810 mV. When you have edited all of the states as needed, write
679 * "c" (commit) to the file to commit your changes. If you want to reset to the
680 * default power levels, write "r" (reset) to the file to reset them.
685 * Reading the file will display:
687 * - minimum and maximum engine clock labeled OD_SCLK
689 * - maximum memory clock labeled OD_MCLK
691 * - three <frequency, voltage> points labeled OD_VDDC_CURVE.
692 * They can be used to calibrate the sclk voltage curve.
694 * - a list of valid ranges for sclk, mclk, and voltage curve points
697 * To manually adjust these settings:
699 * - First select manual using power_dpm_force_performance_level
701 * - For clock frequency setting, enter a new value by writing a
702 * string that contains "s/m index clock" to the file. The index
703 * should be 0 if to set minimum clock. And 1 if to set maximum
704 * clock. E.g., "s 0 500" will update minimum sclk to be 500 MHz.
705 * "m 1 800" will update maximum mclk to be 800Mhz.
707 * For sclk voltage curve, enter the new values by writing a
708 * string that contains "vc point clock voltage" to the file. The
709 * points are indexed by 0, 1 and 2. E.g., "vc 0 300 600" will
710 * update point1 with clock set as 300Mhz and voltage as
711 * 600mV. "vc 2 1000 1000" will update point3 with clock set
712 * as 1000Mhz and voltage 1000mV.
714 * - When you have edited all of the states as needed, write "c" (commit)
715 * to the file to commit your changes
717 * - If you want to reset to the default power levels, write "r" (reset)
718 * to the file to reset them
722 static ssize_t amdgpu_set_pp_od_clk_voltage(struct device *dev,
723 struct device_attribute *attr,
727 struct drm_device *ddev = dev_get_drvdata(dev);
728 struct amdgpu_device *adev = ddev->dev_private;
730 uint32_t parameter_size = 0;
735 const char delimiter[3] = {' ', '\n', '\0'};
738 if (amdgpu_sriov_vf(adev))
745 type = PP_OD_EDIT_SCLK_VDDC_TABLE;
746 else if (*buf == 'm')
747 type = PP_OD_EDIT_MCLK_VDDC_TABLE;
749 type = PP_OD_RESTORE_DEFAULT_TABLE;
750 else if (*buf == 'c')
751 type = PP_OD_COMMIT_DPM_TABLE;
752 else if (!strncmp(buf, "vc", 2))
753 type = PP_OD_EDIT_VDDC_CURVE;
757 memcpy(buf_cpy, buf, count+1);
761 if (type == PP_OD_EDIT_VDDC_CURVE)
763 while (isspace(*++tmp_str));
766 sub_str = strsep(&tmp_str, delimiter);
767 ret = kstrtol(sub_str, 0, ¶meter[parameter_size]);
772 while (isspace(*tmp_str))
776 ret = pm_runtime_get_sync(ddev->dev);
780 if (is_support_sw_smu(adev)) {
781 ret = smu_od_edit_dpm_table(&adev->smu, type,
782 parameter, parameter_size);
785 pm_runtime_mark_last_busy(ddev->dev);
786 pm_runtime_put_autosuspend(ddev->dev);
790 if (adev->powerplay.pp_funcs->odn_edit_dpm_table) {
791 ret = amdgpu_dpm_odn_edit_dpm_table(adev, type,
792 parameter, parameter_size);
794 pm_runtime_mark_last_busy(ddev->dev);
795 pm_runtime_put_autosuspend(ddev->dev);
800 if (type == PP_OD_COMMIT_DPM_TABLE) {
801 if (adev->powerplay.pp_funcs->dispatch_tasks) {
802 amdgpu_dpm_dispatch_task(adev,
803 AMD_PP_TASK_READJUST_POWER_STATE,
805 pm_runtime_mark_last_busy(ddev->dev);
806 pm_runtime_put_autosuspend(ddev->dev);
809 pm_runtime_mark_last_busy(ddev->dev);
810 pm_runtime_put_autosuspend(ddev->dev);
815 pm_runtime_mark_last_busy(ddev->dev);
816 pm_runtime_put_autosuspend(ddev->dev);
821 static ssize_t amdgpu_get_pp_od_clk_voltage(struct device *dev,
822 struct device_attribute *attr,
825 struct drm_device *ddev = dev_get_drvdata(dev);
826 struct amdgpu_device *adev = ddev->dev_private;
830 if (amdgpu_sriov_vf(adev))
833 ret = pm_runtime_get_sync(ddev->dev);
837 if (is_support_sw_smu(adev)) {
838 size = smu_print_clk_levels(&adev->smu, SMU_OD_SCLK, buf);
839 size += smu_print_clk_levels(&adev->smu, SMU_OD_MCLK, buf+size);
840 size += smu_print_clk_levels(&adev->smu, SMU_OD_VDDC_CURVE, buf+size);
841 size += smu_print_clk_levels(&adev->smu, SMU_OD_RANGE, buf+size);
842 } else if (adev->powerplay.pp_funcs->print_clock_levels) {
843 size = amdgpu_dpm_print_clock_levels(adev, OD_SCLK, buf);
844 size += amdgpu_dpm_print_clock_levels(adev, OD_MCLK, buf+size);
845 size += amdgpu_dpm_print_clock_levels(adev, OD_VDDC_CURVE, buf+size);
846 size += amdgpu_dpm_print_clock_levels(adev, OD_RANGE, buf+size);
848 size = snprintf(buf, PAGE_SIZE, "\n");
850 pm_runtime_mark_last_busy(ddev->dev);
851 pm_runtime_put_autosuspend(ddev->dev);
859 * The amdgpu driver provides a sysfs API for adjusting what powerplay
860 * features to be enabled. The file pp_features is used for this. And
861 * this is only available for Vega10 and later dGPUs.
863 * Reading back the file will show you the followings:
864 * - Current ppfeature masks
865 * - List of the all supported powerplay features with their naming,
866 * bitmasks and enablement status('Y'/'N' means "enabled"/"disabled").
868 * To manually enable or disable a specific feature, just set or clear
869 * the corresponding bit from original ppfeature masks and input the
870 * new ppfeature masks.
872 static ssize_t amdgpu_set_pp_feature_status(struct device *dev,
873 struct device_attribute *attr,
877 struct drm_device *ddev = dev_get_drvdata(dev);
878 struct amdgpu_device *adev = ddev->dev_private;
879 uint64_t featuremask;
882 if (amdgpu_sriov_vf(adev))
885 ret = kstrtou64(buf, 0, &featuremask);
889 pr_debug("featuremask = 0x%llx\n", featuremask);
891 ret = pm_runtime_get_sync(ddev->dev);
895 if (is_support_sw_smu(adev)) {
896 ret = smu_sys_set_pp_feature_mask(&adev->smu, featuremask);
898 pm_runtime_mark_last_busy(ddev->dev);
899 pm_runtime_put_autosuspend(ddev->dev);
902 } else if (adev->powerplay.pp_funcs->set_ppfeature_status) {
903 ret = amdgpu_dpm_set_ppfeature_status(adev, featuremask);
905 pm_runtime_mark_last_busy(ddev->dev);
906 pm_runtime_put_autosuspend(ddev->dev);
910 pm_runtime_mark_last_busy(ddev->dev);
911 pm_runtime_put_autosuspend(ddev->dev);
916 static ssize_t amdgpu_get_pp_feature_status(struct device *dev,
917 struct device_attribute *attr,
920 struct drm_device *ddev = dev_get_drvdata(dev);
921 struct amdgpu_device *adev = ddev->dev_private;
925 if (amdgpu_sriov_vf(adev))
928 ret = pm_runtime_get_sync(ddev->dev);
932 if (is_support_sw_smu(adev))
933 size = smu_sys_get_pp_feature_mask(&adev->smu, buf);
934 else if (adev->powerplay.pp_funcs->get_ppfeature_status)
935 size = amdgpu_dpm_get_ppfeature_status(adev, buf);
937 size = snprintf(buf, PAGE_SIZE, "\n");
939 pm_runtime_mark_last_busy(ddev->dev);
940 pm_runtime_put_autosuspend(ddev->dev);
946 * DOC: pp_dpm_sclk pp_dpm_mclk pp_dpm_socclk pp_dpm_fclk pp_dpm_dcefclk pp_dpm_pcie
948 * The amdgpu driver provides a sysfs API for adjusting what power levels
949 * are enabled for a given power state. The files pp_dpm_sclk, pp_dpm_mclk,
950 * pp_dpm_socclk, pp_dpm_fclk, pp_dpm_dcefclk and pp_dpm_pcie are used for
953 * pp_dpm_socclk and pp_dpm_dcefclk interfaces are only available for
954 * Vega10 and later ASICs.
955 * pp_dpm_fclk interface is only available for Vega20 and later ASICs.
957 * Reading back the files will show you the available power levels within
958 * the power state and the clock information for those levels.
960 * To manually adjust these states, first select manual using
961 * power_dpm_force_performance_level.
962 * Secondly, enter a new value for each level by inputing a string that
963 * contains " echo xx xx xx > pp_dpm_sclk/mclk/pcie"
966 * .. code-block:: bash
968 * echo "4 5 6" > pp_dpm_sclk
970 * will enable sclk levels 4, 5, and 6.
972 * NOTE: change to the dcefclk max dpm level is not supported now
975 static ssize_t amdgpu_get_pp_dpm_sclk(struct device *dev,
976 struct device_attribute *attr,
979 struct drm_device *ddev = dev_get_drvdata(dev);
980 struct amdgpu_device *adev = ddev->dev_private;
984 if (amdgpu_sriov_vf(adev) && !amdgpu_sriov_is_pp_one_vf(adev))
987 ret = pm_runtime_get_sync(ddev->dev);
991 if (is_support_sw_smu(adev))
992 size = smu_print_clk_levels(&adev->smu, SMU_SCLK, buf);
993 else if (adev->powerplay.pp_funcs->print_clock_levels)
994 size = amdgpu_dpm_print_clock_levels(adev, PP_SCLK, buf);
996 size = snprintf(buf, PAGE_SIZE, "\n");
998 pm_runtime_mark_last_busy(ddev->dev);
999 pm_runtime_put_autosuspend(ddev->dev);
1005 * Worst case: 32 bits individually specified, in octal at 12 characters
1006 * per line (+1 for \n).
1008 #define AMDGPU_MASK_BUF_MAX (32 * 13)
1010 static ssize_t amdgpu_read_mask(const char *buf, size_t count, uint32_t *mask)
1014 char *sub_str = NULL;
1016 char buf_cpy[AMDGPU_MASK_BUF_MAX + 1];
1017 const char delimiter[3] = {' ', '\n', '\0'};
1022 bytes = min(count, sizeof(buf_cpy) - 1);
1023 memcpy(buf_cpy, buf, bytes);
1024 buf_cpy[bytes] = '\0';
1027 sub_str = strsep(&tmp, delimiter);
1028 if (strlen(sub_str)) {
1029 ret = kstrtol(sub_str, 0, &level);
1032 *mask |= 1 << level;
1040 static ssize_t amdgpu_set_pp_dpm_sclk(struct device *dev,
1041 struct device_attribute *attr,
1045 struct drm_device *ddev = dev_get_drvdata(dev);
1046 struct amdgpu_device *adev = ddev->dev_private;
1050 if (amdgpu_sriov_vf(adev) && !amdgpu_sriov_is_pp_one_vf(adev))
1053 ret = amdgpu_read_mask(buf, count, &mask);
1057 ret = pm_runtime_get_sync(ddev->dev);
1061 if (is_support_sw_smu(adev))
1062 ret = smu_force_clk_levels(&adev->smu, SMU_SCLK, mask, true);
1063 else if (adev->powerplay.pp_funcs->force_clock_level)
1064 ret = amdgpu_dpm_force_clock_level(adev, PP_SCLK, mask);
1066 pm_runtime_mark_last_busy(ddev->dev);
1067 pm_runtime_put_autosuspend(ddev->dev);
1075 static ssize_t amdgpu_get_pp_dpm_mclk(struct device *dev,
1076 struct device_attribute *attr,
1079 struct drm_device *ddev = dev_get_drvdata(dev);
1080 struct amdgpu_device *adev = ddev->dev_private;
1084 if (amdgpu_sriov_vf(adev) && !amdgpu_sriov_is_pp_one_vf(adev))
1087 ret = pm_runtime_get_sync(ddev->dev);
1091 if (is_support_sw_smu(adev))
1092 size = smu_print_clk_levels(&adev->smu, SMU_MCLK, buf);
1093 else if (adev->powerplay.pp_funcs->print_clock_levels)
1094 size = amdgpu_dpm_print_clock_levels(adev, PP_MCLK, buf);
1096 size = snprintf(buf, PAGE_SIZE, "\n");
1098 pm_runtime_mark_last_busy(ddev->dev);
1099 pm_runtime_put_autosuspend(ddev->dev);
1104 static ssize_t amdgpu_set_pp_dpm_mclk(struct device *dev,
1105 struct device_attribute *attr,
1109 struct drm_device *ddev = dev_get_drvdata(dev);
1110 struct amdgpu_device *adev = ddev->dev_private;
1114 if (amdgpu_sriov_vf(adev) && !amdgpu_sriov_is_pp_one_vf(adev))
1117 ret = amdgpu_read_mask(buf, count, &mask);
1121 ret = pm_runtime_get_sync(ddev->dev);
1125 if (is_support_sw_smu(adev))
1126 ret = smu_force_clk_levels(&adev->smu, SMU_MCLK, mask, true);
1127 else if (adev->powerplay.pp_funcs->force_clock_level)
1128 ret = amdgpu_dpm_force_clock_level(adev, PP_MCLK, mask);
1130 pm_runtime_mark_last_busy(ddev->dev);
1131 pm_runtime_put_autosuspend(ddev->dev);
1139 static ssize_t amdgpu_get_pp_dpm_socclk(struct device *dev,
1140 struct device_attribute *attr,
1143 struct drm_device *ddev = dev_get_drvdata(dev);
1144 struct amdgpu_device *adev = ddev->dev_private;
1148 if (amdgpu_sriov_vf(adev) && !amdgpu_sriov_is_pp_one_vf(adev))
1151 ret = pm_runtime_get_sync(ddev->dev);
1155 if (is_support_sw_smu(adev))
1156 size = smu_print_clk_levels(&adev->smu, SMU_SOCCLK, buf);
1157 else if (adev->powerplay.pp_funcs->print_clock_levels)
1158 size = amdgpu_dpm_print_clock_levels(adev, PP_SOCCLK, buf);
1160 size = snprintf(buf, PAGE_SIZE, "\n");
1162 pm_runtime_mark_last_busy(ddev->dev);
1163 pm_runtime_put_autosuspend(ddev->dev);
1168 static ssize_t amdgpu_set_pp_dpm_socclk(struct device *dev,
1169 struct device_attribute *attr,
1173 struct drm_device *ddev = dev_get_drvdata(dev);
1174 struct amdgpu_device *adev = ddev->dev_private;
1178 if (amdgpu_sriov_vf(adev) && !amdgpu_sriov_is_pp_one_vf(adev))
1181 ret = amdgpu_read_mask(buf, count, &mask);
1185 ret = pm_runtime_get_sync(ddev->dev);
1189 if (is_support_sw_smu(adev))
1190 ret = smu_force_clk_levels(&adev->smu, SMU_SOCCLK, mask, true);
1191 else if (adev->powerplay.pp_funcs->force_clock_level)
1192 ret = amdgpu_dpm_force_clock_level(adev, PP_SOCCLK, mask);
1196 pm_runtime_mark_last_busy(ddev->dev);
1197 pm_runtime_put_autosuspend(ddev->dev);
1205 static ssize_t amdgpu_get_pp_dpm_fclk(struct device *dev,
1206 struct device_attribute *attr,
1209 struct drm_device *ddev = dev_get_drvdata(dev);
1210 struct amdgpu_device *adev = ddev->dev_private;
1214 if (amdgpu_sriov_vf(adev) && !amdgpu_sriov_is_pp_one_vf(adev))
1217 ret = pm_runtime_get_sync(ddev->dev);
1221 if (is_support_sw_smu(adev))
1222 size = smu_print_clk_levels(&adev->smu, SMU_FCLK, buf);
1223 else if (adev->powerplay.pp_funcs->print_clock_levels)
1224 size = amdgpu_dpm_print_clock_levels(adev, PP_FCLK, buf);
1226 size = snprintf(buf, PAGE_SIZE, "\n");
1228 pm_runtime_mark_last_busy(ddev->dev);
1229 pm_runtime_put_autosuspend(ddev->dev);
1234 static ssize_t amdgpu_set_pp_dpm_fclk(struct device *dev,
1235 struct device_attribute *attr,
1239 struct drm_device *ddev = dev_get_drvdata(dev);
1240 struct amdgpu_device *adev = ddev->dev_private;
1244 if (amdgpu_sriov_vf(adev) && !amdgpu_sriov_is_pp_one_vf(adev))
1247 ret = amdgpu_read_mask(buf, count, &mask);
1251 ret = pm_runtime_get_sync(ddev->dev);
1255 if (is_support_sw_smu(adev))
1256 ret = smu_force_clk_levels(&adev->smu, SMU_FCLK, mask, true);
1257 else if (adev->powerplay.pp_funcs->force_clock_level)
1258 ret = amdgpu_dpm_force_clock_level(adev, PP_FCLK, mask);
1262 pm_runtime_mark_last_busy(ddev->dev);
1263 pm_runtime_put_autosuspend(ddev->dev);
1271 static ssize_t amdgpu_get_pp_dpm_dcefclk(struct device *dev,
1272 struct device_attribute *attr,
1275 struct drm_device *ddev = dev_get_drvdata(dev);
1276 struct amdgpu_device *adev = ddev->dev_private;
1280 if (amdgpu_sriov_vf(adev))
1283 ret = pm_runtime_get_sync(ddev->dev);
1287 if (is_support_sw_smu(adev))
1288 size = smu_print_clk_levels(&adev->smu, SMU_DCEFCLK, buf);
1289 else if (adev->powerplay.pp_funcs->print_clock_levels)
1290 size = amdgpu_dpm_print_clock_levels(adev, PP_DCEFCLK, buf);
1292 size = snprintf(buf, PAGE_SIZE, "\n");
1294 pm_runtime_mark_last_busy(ddev->dev);
1295 pm_runtime_put_autosuspend(ddev->dev);
1300 static ssize_t amdgpu_set_pp_dpm_dcefclk(struct device *dev,
1301 struct device_attribute *attr,
1305 struct drm_device *ddev = dev_get_drvdata(dev);
1306 struct amdgpu_device *adev = ddev->dev_private;
1310 if (amdgpu_sriov_vf(adev))
1313 ret = amdgpu_read_mask(buf, count, &mask);
1317 ret = pm_runtime_get_sync(ddev->dev);
1321 if (is_support_sw_smu(adev))
1322 ret = smu_force_clk_levels(&adev->smu, SMU_DCEFCLK, mask, true);
1323 else if (adev->powerplay.pp_funcs->force_clock_level)
1324 ret = amdgpu_dpm_force_clock_level(adev, PP_DCEFCLK, mask);
1328 pm_runtime_mark_last_busy(ddev->dev);
1329 pm_runtime_put_autosuspend(ddev->dev);
1337 static ssize_t amdgpu_get_pp_dpm_pcie(struct device *dev,
1338 struct device_attribute *attr,
1341 struct drm_device *ddev = dev_get_drvdata(dev);
1342 struct amdgpu_device *adev = ddev->dev_private;
1346 if (amdgpu_sriov_vf(adev) && !amdgpu_sriov_is_pp_one_vf(adev))
1349 ret = pm_runtime_get_sync(ddev->dev);
1353 if (is_support_sw_smu(adev))
1354 size = smu_print_clk_levels(&adev->smu, SMU_PCIE, buf);
1355 else if (adev->powerplay.pp_funcs->print_clock_levels)
1356 size = amdgpu_dpm_print_clock_levels(adev, PP_PCIE, buf);
1358 size = snprintf(buf, PAGE_SIZE, "\n");
1360 pm_runtime_mark_last_busy(ddev->dev);
1361 pm_runtime_put_autosuspend(ddev->dev);
1366 static ssize_t amdgpu_set_pp_dpm_pcie(struct device *dev,
1367 struct device_attribute *attr,
1371 struct drm_device *ddev = dev_get_drvdata(dev);
1372 struct amdgpu_device *adev = ddev->dev_private;
1376 if (amdgpu_sriov_vf(adev) && !amdgpu_sriov_is_pp_one_vf(adev))
1379 ret = amdgpu_read_mask(buf, count, &mask);
1383 ret = pm_runtime_get_sync(ddev->dev);
1387 if (is_support_sw_smu(adev))
1388 ret = smu_force_clk_levels(&adev->smu, SMU_PCIE, mask, true);
1389 else if (adev->powerplay.pp_funcs->force_clock_level)
1390 ret = amdgpu_dpm_force_clock_level(adev, PP_PCIE, mask);
1394 pm_runtime_mark_last_busy(ddev->dev);
1395 pm_runtime_put_autosuspend(ddev->dev);
1403 static ssize_t amdgpu_get_pp_sclk_od(struct device *dev,
1404 struct device_attribute *attr,
1407 struct drm_device *ddev = dev_get_drvdata(dev);
1408 struct amdgpu_device *adev = ddev->dev_private;
1412 if (amdgpu_sriov_vf(adev))
1415 ret = pm_runtime_get_sync(ddev->dev);
1419 if (is_support_sw_smu(adev))
1420 value = smu_get_od_percentage(&(adev->smu), SMU_OD_SCLK);
1421 else if (adev->powerplay.pp_funcs->get_sclk_od)
1422 value = amdgpu_dpm_get_sclk_od(adev);
1424 pm_runtime_mark_last_busy(ddev->dev);
1425 pm_runtime_put_autosuspend(ddev->dev);
1427 return snprintf(buf, PAGE_SIZE, "%d\n", value);
1430 static ssize_t amdgpu_set_pp_sclk_od(struct device *dev,
1431 struct device_attribute *attr,
1435 struct drm_device *ddev = dev_get_drvdata(dev);
1436 struct amdgpu_device *adev = ddev->dev_private;
1440 if (amdgpu_sriov_vf(adev))
1443 ret = kstrtol(buf, 0, &value);
1448 ret = pm_runtime_get_sync(ddev->dev);
1452 if (is_support_sw_smu(adev)) {
1453 value = smu_set_od_percentage(&(adev->smu), SMU_OD_SCLK, (uint32_t)value);
1455 if (adev->powerplay.pp_funcs->set_sclk_od)
1456 amdgpu_dpm_set_sclk_od(adev, (uint32_t)value);
1458 if (adev->powerplay.pp_funcs->dispatch_tasks) {
1459 amdgpu_dpm_dispatch_task(adev, AMD_PP_TASK_READJUST_POWER_STATE, NULL);
1461 adev->pm.dpm.current_ps = adev->pm.dpm.boot_ps;
1462 amdgpu_pm_compute_clocks(adev);
1466 pm_runtime_mark_last_busy(ddev->dev);
1467 pm_runtime_put_autosuspend(ddev->dev);
1472 static ssize_t amdgpu_get_pp_mclk_od(struct device *dev,
1473 struct device_attribute *attr,
1476 struct drm_device *ddev = dev_get_drvdata(dev);
1477 struct amdgpu_device *adev = ddev->dev_private;
1481 if (amdgpu_sriov_vf(adev))
1484 ret = pm_runtime_get_sync(ddev->dev);
1488 if (is_support_sw_smu(adev))
1489 value = smu_get_od_percentage(&(adev->smu), SMU_OD_MCLK);
1490 else if (adev->powerplay.pp_funcs->get_mclk_od)
1491 value = amdgpu_dpm_get_mclk_od(adev);
1493 pm_runtime_mark_last_busy(ddev->dev);
1494 pm_runtime_put_autosuspend(ddev->dev);
1496 return snprintf(buf, PAGE_SIZE, "%d\n", value);
1499 static ssize_t amdgpu_set_pp_mclk_od(struct device *dev,
1500 struct device_attribute *attr,
1504 struct drm_device *ddev = dev_get_drvdata(dev);
1505 struct amdgpu_device *adev = ddev->dev_private;
1509 if (amdgpu_sriov_vf(adev))
1512 ret = kstrtol(buf, 0, &value);
1517 ret = pm_runtime_get_sync(ddev->dev);
1521 if (is_support_sw_smu(adev)) {
1522 value = smu_set_od_percentage(&(adev->smu), SMU_OD_MCLK, (uint32_t)value);
1524 if (adev->powerplay.pp_funcs->set_mclk_od)
1525 amdgpu_dpm_set_mclk_od(adev, (uint32_t)value);
1527 if (adev->powerplay.pp_funcs->dispatch_tasks) {
1528 amdgpu_dpm_dispatch_task(adev, AMD_PP_TASK_READJUST_POWER_STATE, NULL);
1530 adev->pm.dpm.current_ps = adev->pm.dpm.boot_ps;
1531 amdgpu_pm_compute_clocks(adev);
1535 pm_runtime_mark_last_busy(ddev->dev);
1536 pm_runtime_put_autosuspend(ddev->dev);
1542 * DOC: pp_power_profile_mode
1544 * The amdgpu driver provides a sysfs API for adjusting the heuristics
1545 * related to switching between power levels in a power state. The file
1546 * pp_power_profile_mode is used for this.
1548 * Reading this file outputs a list of all of the predefined power profiles
1549 * and the relevant heuristics settings for that profile.
1551 * To select a profile or create a custom profile, first select manual using
1552 * power_dpm_force_performance_level. Writing the number of a predefined
1553 * profile to pp_power_profile_mode will enable those heuristics. To
1554 * create a custom set of heuristics, write a string of numbers to the file
1555 * starting with the number of the custom profile along with a setting
1556 * for each heuristic parameter. Due to differences across asic families
1557 * the heuristic parameters vary from family to family.
1561 static ssize_t amdgpu_get_pp_power_profile_mode(struct device *dev,
1562 struct device_attribute *attr,
1565 struct drm_device *ddev = dev_get_drvdata(dev);
1566 struct amdgpu_device *adev = ddev->dev_private;
1570 if (amdgpu_sriov_vf(adev) && !amdgpu_sriov_is_pp_one_vf(adev))
1573 ret = pm_runtime_get_sync(ddev->dev);
1577 if (is_support_sw_smu(adev))
1578 size = smu_get_power_profile_mode(&adev->smu, buf);
1579 else if (adev->powerplay.pp_funcs->get_power_profile_mode)
1580 size = amdgpu_dpm_get_power_profile_mode(adev, buf);
1582 size = snprintf(buf, PAGE_SIZE, "\n");
1584 pm_runtime_mark_last_busy(ddev->dev);
1585 pm_runtime_put_autosuspend(ddev->dev);
1591 static ssize_t amdgpu_set_pp_power_profile_mode(struct device *dev,
1592 struct device_attribute *attr,
1597 struct drm_device *ddev = dev_get_drvdata(dev);
1598 struct amdgpu_device *adev = ddev->dev_private;
1599 uint32_t parameter_size = 0;
1601 char *sub_str, buf_cpy[128];
1605 long int profile_mode = 0;
1606 const char delimiter[3] = {' ', '\n', '\0'};
1610 ret = kstrtol(tmp, 0, &profile_mode);
1614 if (amdgpu_sriov_vf(adev) && !amdgpu_sriov_is_pp_one_vf(adev))
1617 if (profile_mode == PP_SMC_POWER_PROFILE_CUSTOM) {
1618 if (count < 2 || count > 127)
1620 while (isspace(*++buf))
1622 memcpy(buf_cpy, buf, count-i);
1624 while (tmp_str[0]) {
1625 sub_str = strsep(&tmp_str, delimiter);
1626 ret = kstrtol(sub_str, 0, ¶meter[parameter_size]);
1630 while (isspace(*tmp_str))
1634 parameter[parameter_size] = profile_mode;
1636 ret = pm_runtime_get_sync(ddev->dev);
1640 if (is_support_sw_smu(adev))
1641 ret = smu_set_power_profile_mode(&adev->smu, parameter, parameter_size, true);
1642 else if (adev->powerplay.pp_funcs->set_power_profile_mode)
1643 ret = amdgpu_dpm_set_power_profile_mode(adev, parameter, parameter_size);
1645 pm_runtime_mark_last_busy(ddev->dev);
1646 pm_runtime_put_autosuspend(ddev->dev);
1657 * The amdgpu driver provides a sysfs API for reading how busy the GPU
1658 * is as a percentage. The file gpu_busy_percent is used for this.
1659 * The SMU firmware computes a percentage of load based on the
1660 * aggregate activity level in the IP cores.
1662 static ssize_t amdgpu_get_busy_percent(struct device *dev,
1663 struct device_attribute *attr,
1666 struct drm_device *ddev = dev_get_drvdata(dev);
1667 struct amdgpu_device *adev = ddev->dev_private;
1668 int r, value, size = sizeof(value);
1670 if (amdgpu_sriov_vf(adev) && !amdgpu_sriov_is_pp_one_vf(adev))
1673 r = pm_runtime_get_sync(ddev->dev);
1677 /* read the IP busy sensor */
1678 r = amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GPU_LOAD,
1679 (void *)&value, &size);
1681 pm_runtime_mark_last_busy(ddev->dev);
1682 pm_runtime_put_autosuspend(ddev->dev);
1687 return snprintf(buf, PAGE_SIZE, "%d\n", value);
1691 * DOC: mem_busy_percent
1693 * The amdgpu driver provides a sysfs API for reading how busy the VRAM
1694 * is as a percentage. The file mem_busy_percent is used for this.
1695 * The SMU firmware computes a percentage of load based on the
1696 * aggregate activity level in the IP cores.
1698 static ssize_t amdgpu_get_memory_busy_percent(struct device *dev,
1699 struct device_attribute *attr,
1702 struct drm_device *ddev = dev_get_drvdata(dev);
1703 struct amdgpu_device *adev = ddev->dev_private;
1704 int r, value, size = sizeof(value);
1706 if (amdgpu_sriov_vf(adev) && !amdgpu_sriov_is_pp_one_vf(adev))
1709 r = pm_runtime_get_sync(ddev->dev);
1713 /* read the IP busy sensor */
1714 r = amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_MEM_LOAD,
1715 (void *)&value, &size);
1717 pm_runtime_mark_last_busy(ddev->dev);
1718 pm_runtime_put_autosuspend(ddev->dev);
1723 return snprintf(buf, PAGE_SIZE, "%d\n", value);
1729 * The amdgpu driver provides a sysfs API for estimating how much data
1730 * has been received and sent by the GPU in the last second through PCIe.
1731 * The file pcie_bw is used for this.
1732 * The Perf counters count the number of received and sent messages and return
1733 * those values, as well as the maximum payload size of a PCIe packet (mps).
1734 * Note that it is not possible to easily and quickly obtain the size of each
1735 * packet transmitted, so we output the max payload size (mps) to allow for
1736 * quick estimation of the PCIe bandwidth usage
1738 static ssize_t amdgpu_get_pcie_bw(struct device *dev,
1739 struct device_attribute *attr,
1742 struct drm_device *ddev = dev_get_drvdata(dev);
1743 struct amdgpu_device *adev = ddev->dev_private;
1744 uint64_t count0, count1;
1747 if (amdgpu_sriov_vf(adev) && !amdgpu_sriov_is_pp_one_vf(adev))
1750 ret = pm_runtime_get_sync(ddev->dev);
1754 amdgpu_asic_get_pcie_usage(adev, &count0, &count1);
1756 pm_runtime_mark_last_busy(ddev->dev);
1757 pm_runtime_put_autosuspend(ddev->dev);
1759 return snprintf(buf, PAGE_SIZE, "%llu %llu %i\n",
1760 count0, count1, pcie_get_mps(adev->pdev));
1766 * The amdgpu driver provides a sysfs API for providing a unique ID for the GPU
1767 * The file unique_id is used for this.
1768 * This will provide a Unique ID that will persist from machine to machine
1770 * NOTE: This will only work for GFX9 and newer. This file will be absent
1771 * on unsupported ASICs (GFX8 and older)
1773 static ssize_t amdgpu_get_unique_id(struct device *dev,
1774 struct device_attribute *attr,
1777 struct drm_device *ddev = dev_get_drvdata(dev);
1778 struct amdgpu_device *adev = ddev->dev_private;
1780 if (amdgpu_sriov_vf(adev) && !amdgpu_sriov_is_pp_one_vf(adev))
1783 if (adev->unique_id)
1784 return snprintf(buf, PAGE_SIZE, "%016llx\n", adev->unique_id);
1789 static DEVICE_ATTR(power_dpm_state, S_IRUGO | S_IWUSR, amdgpu_get_dpm_state, amdgpu_set_dpm_state);
1790 static DEVICE_ATTR(power_dpm_force_performance_level, S_IRUGO | S_IWUSR,
1791 amdgpu_get_dpm_forced_performance_level,
1792 amdgpu_set_dpm_forced_performance_level);
1793 static DEVICE_ATTR(pp_num_states, S_IRUGO, amdgpu_get_pp_num_states, NULL);
1794 static DEVICE_ATTR(pp_cur_state, S_IRUGO, amdgpu_get_pp_cur_state, NULL);
1795 static DEVICE_ATTR(pp_force_state, S_IRUGO | S_IWUSR,
1796 amdgpu_get_pp_force_state,
1797 amdgpu_set_pp_force_state);
1798 static DEVICE_ATTR(pp_table, S_IRUGO | S_IWUSR,
1799 amdgpu_get_pp_table,
1800 amdgpu_set_pp_table);
1801 static DEVICE_ATTR(pp_dpm_sclk, S_IRUGO | S_IWUSR,
1802 amdgpu_get_pp_dpm_sclk,
1803 amdgpu_set_pp_dpm_sclk);
1804 static DEVICE_ATTR(pp_dpm_mclk, S_IRUGO | S_IWUSR,
1805 amdgpu_get_pp_dpm_mclk,
1806 amdgpu_set_pp_dpm_mclk);
1807 static DEVICE_ATTR(pp_dpm_socclk, S_IRUGO | S_IWUSR,
1808 amdgpu_get_pp_dpm_socclk,
1809 amdgpu_set_pp_dpm_socclk);
1810 static DEVICE_ATTR(pp_dpm_fclk, S_IRUGO | S_IWUSR,
1811 amdgpu_get_pp_dpm_fclk,
1812 amdgpu_set_pp_dpm_fclk);
1813 static DEVICE_ATTR(pp_dpm_dcefclk, S_IRUGO | S_IWUSR,
1814 amdgpu_get_pp_dpm_dcefclk,
1815 amdgpu_set_pp_dpm_dcefclk);
1816 static DEVICE_ATTR(pp_dpm_pcie, S_IRUGO | S_IWUSR,
1817 amdgpu_get_pp_dpm_pcie,
1818 amdgpu_set_pp_dpm_pcie);
1819 static DEVICE_ATTR(pp_sclk_od, S_IRUGO | S_IWUSR,
1820 amdgpu_get_pp_sclk_od,
1821 amdgpu_set_pp_sclk_od);
1822 static DEVICE_ATTR(pp_mclk_od, S_IRUGO | S_IWUSR,
1823 amdgpu_get_pp_mclk_od,
1824 amdgpu_set_pp_mclk_od);
1825 static DEVICE_ATTR(pp_power_profile_mode, S_IRUGO | S_IWUSR,
1826 amdgpu_get_pp_power_profile_mode,
1827 amdgpu_set_pp_power_profile_mode);
1828 static DEVICE_ATTR(pp_od_clk_voltage, S_IRUGO | S_IWUSR,
1829 amdgpu_get_pp_od_clk_voltage,
1830 amdgpu_set_pp_od_clk_voltage);
1831 static DEVICE_ATTR(gpu_busy_percent, S_IRUGO,
1832 amdgpu_get_busy_percent, NULL);
1833 static DEVICE_ATTR(mem_busy_percent, S_IRUGO,
1834 amdgpu_get_memory_busy_percent, NULL);
1835 static DEVICE_ATTR(pcie_bw, S_IRUGO, amdgpu_get_pcie_bw, NULL);
1836 static DEVICE_ATTR(pp_features, S_IRUGO | S_IWUSR,
1837 amdgpu_get_pp_feature_status,
1838 amdgpu_set_pp_feature_status);
1839 static DEVICE_ATTR(unique_id, S_IRUGO, amdgpu_get_unique_id, NULL);
1841 static ssize_t amdgpu_hwmon_show_temp(struct device *dev,
1842 struct device_attribute *attr,
1845 struct amdgpu_device *adev = dev_get_drvdata(dev);
1846 int channel = to_sensor_dev_attr(attr)->index;
1847 int r, temp = 0, size = sizeof(temp);
1849 if (channel >= PP_TEMP_MAX)
1852 r = pm_runtime_get_sync(adev->ddev->dev);
1857 case PP_TEMP_JUNCTION:
1858 /* get current junction temperature */
1859 r = amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_HOTSPOT_TEMP,
1860 (void *)&temp, &size);
1863 /* get current edge temperature */
1864 r = amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_EDGE_TEMP,
1865 (void *)&temp, &size);
1868 /* get current memory temperature */
1869 r = amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_MEM_TEMP,
1870 (void *)&temp, &size);
1877 pm_runtime_mark_last_busy(adev->ddev->dev);
1878 pm_runtime_put_autosuspend(adev->ddev->dev);
1883 return snprintf(buf, PAGE_SIZE, "%d\n", temp);
1886 static ssize_t amdgpu_hwmon_show_temp_thresh(struct device *dev,
1887 struct device_attribute *attr,
1890 struct amdgpu_device *adev = dev_get_drvdata(dev);
1891 int hyst = to_sensor_dev_attr(attr)->index;
1895 temp = adev->pm.dpm.thermal.min_temp;
1897 temp = adev->pm.dpm.thermal.max_temp;
1899 return snprintf(buf, PAGE_SIZE, "%d\n", temp);
1902 static ssize_t amdgpu_hwmon_show_hotspot_temp_thresh(struct device *dev,
1903 struct device_attribute *attr,
1906 struct amdgpu_device *adev = dev_get_drvdata(dev);
1907 int hyst = to_sensor_dev_attr(attr)->index;
1911 temp = adev->pm.dpm.thermal.min_hotspot_temp;
1913 temp = adev->pm.dpm.thermal.max_hotspot_crit_temp;
1915 return snprintf(buf, PAGE_SIZE, "%d\n", temp);
1918 static ssize_t amdgpu_hwmon_show_mem_temp_thresh(struct device *dev,
1919 struct device_attribute *attr,
1922 struct amdgpu_device *adev = dev_get_drvdata(dev);
1923 int hyst = to_sensor_dev_attr(attr)->index;
1927 temp = adev->pm.dpm.thermal.min_mem_temp;
1929 temp = adev->pm.dpm.thermal.max_mem_crit_temp;
1931 return snprintf(buf, PAGE_SIZE, "%d\n", temp);
1934 static ssize_t amdgpu_hwmon_show_temp_label(struct device *dev,
1935 struct device_attribute *attr,
1938 int channel = to_sensor_dev_attr(attr)->index;
1940 if (channel >= PP_TEMP_MAX)
1943 return snprintf(buf, PAGE_SIZE, "%s\n", temp_label[channel].label);
1946 static ssize_t amdgpu_hwmon_show_temp_emergency(struct device *dev,
1947 struct device_attribute *attr,
1950 struct amdgpu_device *adev = dev_get_drvdata(dev);
1951 int channel = to_sensor_dev_attr(attr)->index;
1954 if (channel >= PP_TEMP_MAX)
1958 case PP_TEMP_JUNCTION:
1959 temp = adev->pm.dpm.thermal.max_hotspot_emergency_temp;
1962 temp = adev->pm.dpm.thermal.max_edge_emergency_temp;
1965 temp = adev->pm.dpm.thermal.max_mem_emergency_temp;
1969 return snprintf(buf, PAGE_SIZE, "%d\n", temp);
1972 static ssize_t amdgpu_hwmon_get_pwm1_enable(struct device *dev,
1973 struct device_attribute *attr,
1976 struct amdgpu_device *adev = dev_get_drvdata(dev);
1980 ret = pm_runtime_get_sync(adev->ddev->dev);
1984 if (is_support_sw_smu(adev)) {
1985 pwm_mode = smu_get_fan_control_mode(&adev->smu);
1987 if (!adev->powerplay.pp_funcs->get_fan_control_mode) {
1988 pm_runtime_mark_last_busy(adev->ddev->dev);
1989 pm_runtime_put_autosuspend(adev->ddev->dev);
1993 pwm_mode = amdgpu_dpm_get_fan_control_mode(adev);
1996 pm_runtime_mark_last_busy(adev->ddev->dev);
1997 pm_runtime_put_autosuspend(adev->ddev->dev);
1999 return sprintf(buf, "%i\n", pwm_mode);
2002 static ssize_t amdgpu_hwmon_set_pwm1_enable(struct device *dev,
2003 struct device_attribute *attr,
2007 struct amdgpu_device *adev = dev_get_drvdata(dev);
2011 err = kstrtoint(buf, 10, &value);
2015 ret = pm_runtime_get_sync(adev->ddev->dev);
2019 if (is_support_sw_smu(adev)) {
2020 smu_set_fan_control_mode(&adev->smu, value);
2022 if (!adev->powerplay.pp_funcs->set_fan_control_mode) {
2023 pm_runtime_mark_last_busy(adev->ddev->dev);
2024 pm_runtime_put_autosuspend(adev->ddev->dev);
2028 amdgpu_dpm_set_fan_control_mode(adev, value);
2031 pm_runtime_mark_last_busy(adev->ddev->dev);
2032 pm_runtime_put_autosuspend(adev->ddev->dev);
2037 static ssize_t amdgpu_hwmon_get_pwm1_min(struct device *dev,
2038 struct device_attribute *attr,
2041 return sprintf(buf, "%i\n", 0);
2044 static ssize_t amdgpu_hwmon_get_pwm1_max(struct device *dev,
2045 struct device_attribute *attr,
2048 return sprintf(buf, "%i\n", 255);
2051 static ssize_t amdgpu_hwmon_set_pwm1(struct device *dev,
2052 struct device_attribute *attr,
2053 const char *buf, size_t count)
2055 struct amdgpu_device *adev = dev_get_drvdata(dev);
2060 err = pm_runtime_get_sync(adev->ddev->dev);
2064 if (is_support_sw_smu(adev))
2065 pwm_mode = smu_get_fan_control_mode(&adev->smu);
2067 pwm_mode = amdgpu_dpm_get_fan_control_mode(adev);
2069 if (pwm_mode != AMD_FAN_CTRL_MANUAL) {
2070 pr_info("manual fan speed control should be enabled first\n");
2071 pm_runtime_mark_last_busy(adev->ddev->dev);
2072 pm_runtime_put_autosuspend(adev->ddev->dev);
2076 err = kstrtou32(buf, 10, &value);
2078 pm_runtime_mark_last_busy(adev->ddev->dev);
2079 pm_runtime_put_autosuspend(adev->ddev->dev);
2083 value = (value * 100) / 255;
2085 if (is_support_sw_smu(adev))
2086 err = smu_set_fan_speed_percent(&adev->smu, value);
2087 else if (adev->powerplay.pp_funcs->set_fan_speed_percent)
2088 err = amdgpu_dpm_set_fan_speed_percent(adev, value);
2092 pm_runtime_mark_last_busy(adev->ddev->dev);
2093 pm_runtime_put_autosuspend(adev->ddev->dev);
2101 static ssize_t amdgpu_hwmon_get_pwm1(struct device *dev,
2102 struct device_attribute *attr,
2105 struct amdgpu_device *adev = dev_get_drvdata(dev);
2109 err = pm_runtime_get_sync(adev->ddev->dev);
2113 if (is_support_sw_smu(adev))
2114 err = smu_get_fan_speed_percent(&adev->smu, &speed);
2115 else if (adev->powerplay.pp_funcs->get_fan_speed_percent)
2116 err = amdgpu_dpm_get_fan_speed_percent(adev, &speed);
2120 pm_runtime_mark_last_busy(adev->ddev->dev);
2121 pm_runtime_put_autosuspend(adev->ddev->dev);
2126 speed = (speed * 255) / 100;
2128 return sprintf(buf, "%i\n", speed);
2131 static ssize_t amdgpu_hwmon_get_fan1_input(struct device *dev,
2132 struct device_attribute *attr,
2135 struct amdgpu_device *adev = dev_get_drvdata(dev);
2139 err = pm_runtime_get_sync(adev->ddev->dev);
2143 if (is_support_sw_smu(adev))
2144 err = smu_get_fan_speed_rpm(&adev->smu, &speed);
2145 else if (adev->powerplay.pp_funcs->get_fan_speed_rpm)
2146 err = amdgpu_dpm_get_fan_speed_rpm(adev, &speed);
2150 pm_runtime_mark_last_busy(adev->ddev->dev);
2151 pm_runtime_put_autosuspend(adev->ddev->dev);
2156 return sprintf(buf, "%i\n", speed);
2159 static ssize_t amdgpu_hwmon_get_fan1_min(struct device *dev,
2160 struct device_attribute *attr,
2163 struct amdgpu_device *adev = dev_get_drvdata(dev);
2165 u32 size = sizeof(min_rpm);
2168 r = pm_runtime_get_sync(adev->ddev->dev);
2172 r = amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_MIN_FAN_RPM,
2173 (void *)&min_rpm, &size);
2175 pm_runtime_mark_last_busy(adev->ddev->dev);
2176 pm_runtime_put_autosuspend(adev->ddev->dev);
2181 return snprintf(buf, PAGE_SIZE, "%d\n", min_rpm);
2184 static ssize_t amdgpu_hwmon_get_fan1_max(struct device *dev,
2185 struct device_attribute *attr,
2188 struct amdgpu_device *adev = dev_get_drvdata(dev);
2190 u32 size = sizeof(max_rpm);
2193 r = pm_runtime_get_sync(adev->ddev->dev);
2197 r = amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_MAX_FAN_RPM,
2198 (void *)&max_rpm, &size);
2200 pm_runtime_mark_last_busy(adev->ddev->dev);
2201 pm_runtime_put_autosuspend(adev->ddev->dev);
2206 return snprintf(buf, PAGE_SIZE, "%d\n", max_rpm);
2209 static ssize_t amdgpu_hwmon_get_fan1_target(struct device *dev,
2210 struct device_attribute *attr,
2213 struct amdgpu_device *adev = dev_get_drvdata(dev);
2217 err = pm_runtime_get_sync(adev->ddev->dev);
2221 if (is_support_sw_smu(adev))
2222 err = smu_get_fan_speed_rpm(&adev->smu, &rpm);
2223 else if (adev->powerplay.pp_funcs->get_fan_speed_rpm)
2224 err = amdgpu_dpm_get_fan_speed_rpm(adev, &rpm);
2228 pm_runtime_mark_last_busy(adev->ddev->dev);
2229 pm_runtime_put_autosuspend(adev->ddev->dev);
2234 return sprintf(buf, "%i\n", rpm);
2237 static ssize_t amdgpu_hwmon_set_fan1_target(struct device *dev,
2238 struct device_attribute *attr,
2239 const char *buf, size_t count)
2241 struct amdgpu_device *adev = dev_get_drvdata(dev);
2246 err = pm_runtime_get_sync(adev->ddev->dev);
2250 if (is_support_sw_smu(adev))
2251 pwm_mode = smu_get_fan_control_mode(&adev->smu);
2253 pwm_mode = amdgpu_dpm_get_fan_control_mode(adev);
2255 if (pwm_mode != AMD_FAN_CTRL_MANUAL) {
2256 pm_runtime_mark_last_busy(adev->ddev->dev);
2257 pm_runtime_put_autosuspend(adev->ddev->dev);
2261 err = kstrtou32(buf, 10, &value);
2263 pm_runtime_mark_last_busy(adev->ddev->dev);
2264 pm_runtime_put_autosuspend(adev->ddev->dev);
2268 if (is_support_sw_smu(adev))
2269 err = smu_set_fan_speed_rpm(&adev->smu, value);
2270 else if (adev->powerplay.pp_funcs->set_fan_speed_rpm)
2271 err = amdgpu_dpm_set_fan_speed_rpm(adev, value);
2275 pm_runtime_mark_last_busy(adev->ddev->dev);
2276 pm_runtime_put_autosuspend(adev->ddev->dev);
2284 static ssize_t amdgpu_hwmon_get_fan1_enable(struct device *dev,
2285 struct device_attribute *attr,
2288 struct amdgpu_device *adev = dev_get_drvdata(dev);
2292 ret = pm_runtime_get_sync(adev->ddev->dev);
2296 if (is_support_sw_smu(adev)) {
2297 pwm_mode = smu_get_fan_control_mode(&adev->smu);
2299 if (!adev->powerplay.pp_funcs->get_fan_control_mode) {
2300 pm_runtime_mark_last_busy(adev->ddev->dev);
2301 pm_runtime_put_autosuspend(adev->ddev->dev);
2305 pwm_mode = amdgpu_dpm_get_fan_control_mode(adev);
2308 pm_runtime_mark_last_busy(adev->ddev->dev);
2309 pm_runtime_put_autosuspend(adev->ddev->dev);
2311 return sprintf(buf, "%i\n", pwm_mode == AMD_FAN_CTRL_AUTO ? 0 : 1);
2314 static ssize_t amdgpu_hwmon_set_fan1_enable(struct device *dev,
2315 struct device_attribute *attr,
2319 struct amdgpu_device *adev = dev_get_drvdata(dev);
2324 err = kstrtoint(buf, 10, &value);
2329 pwm_mode = AMD_FAN_CTRL_AUTO;
2330 else if (value == 1)
2331 pwm_mode = AMD_FAN_CTRL_MANUAL;
2335 err = pm_runtime_get_sync(adev->ddev->dev);
2339 if (is_support_sw_smu(adev)) {
2340 smu_set_fan_control_mode(&adev->smu, pwm_mode);
2342 if (!adev->powerplay.pp_funcs->set_fan_control_mode) {
2343 pm_runtime_mark_last_busy(adev->ddev->dev);
2344 pm_runtime_put_autosuspend(adev->ddev->dev);
2347 amdgpu_dpm_set_fan_control_mode(adev, pwm_mode);
2350 pm_runtime_mark_last_busy(adev->ddev->dev);
2351 pm_runtime_put_autosuspend(adev->ddev->dev);
2356 static ssize_t amdgpu_hwmon_show_vddgfx(struct device *dev,
2357 struct device_attribute *attr,
2360 struct amdgpu_device *adev = dev_get_drvdata(dev);
2362 int r, size = sizeof(vddgfx);
2364 r = pm_runtime_get_sync(adev->ddev->dev);
2368 /* get the voltage */
2369 r = amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_VDDGFX,
2370 (void *)&vddgfx, &size);
2372 pm_runtime_mark_last_busy(adev->ddev->dev);
2373 pm_runtime_put_autosuspend(adev->ddev->dev);
2378 return snprintf(buf, PAGE_SIZE, "%d\n", vddgfx);
2381 static ssize_t amdgpu_hwmon_show_vddgfx_label(struct device *dev,
2382 struct device_attribute *attr,
2385 return snprintf(buf, PAGE_SIZE, "vddgfx\n");
2388 static ssize_t amdgpu_hwmon_show_vddnb(struct device *dev,
2389 struct device_attribute *attr,
2392 struct amdgpu_device *adev = dev_get_drvdata(dev);
2394 int r, size = sizeof(vddnb);
2396 /* only APUs have vddnb */
2397 if (!(adev->flags & AMD_IS_APU))
2400 r = pm_runtime_get_sync(adev->ddev->dev);
2404 /* get the voltage */
2405 r = amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_VDDNB,
2406 (void *)&vddnb, &size);
2408 pm_runtime_mark_last_busy(adev->ddev->dev);
2409 pm_runtime_put_autosuspend(adev->ddev->dev);
2414 return snprintf(buf, PAGE_SIZE, "%d\n", vddnb);
2417 static ssize_t amdgpu_hwmon_show_vddnb_label(struct device *dev,
2418 struct device_attribute *attr,
2421 return snprintf(buf, PAGE_SIZE, "vddnb\n");
2424 static ssize_t amdgpu_hwmon_show_power_avg(struct device *dev,
2425 struct device_attribute *attr,
2428 struct amdgpu_device *adev = dev_get_drvdata(dev);
2430 int r, size = sizeof(u32);
2433 r = pm_runtime_get_sync(adev->ddev->dev);
2437 /* get the voltage */
2438 r = amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GPU_POWER,
2439 (void *)&query, &size);
2441 pm_runtime_mark_last_busy(adev->ddev->dev);
2442 pm_runtime_put_autosuspend(adev->ddev->dev);
2447 /* convert to microwatts */
2448 uw = (query >> 8) * 1000000 + (query & 0xff) * 1000;
2450 return snprintf(buf, PAGE_SIZE, "%u\n", uw);
2453 static ssize_t amdgpu_hwmon_show_power_cap_min(struct device *dev,
2454 struct device_attribute *attr,
2457 return sprintf(buf, "%i\n", 0);
2460 static ssize_t amdgpu_hwmon_show_power_cap_max(struct device *dev,
2461 struct device_attribute *attr,
2464 struct amdgpu_device *adev = dev_get_drvdata(dev);
2469 r = pm_runtime_get_sync(adev->ddev->dev);
2473 if (is_support_sw_smu(adev)) {
2474 smu_get_power_limit(&adev->smu, &limit, true, true);
2475 size = snprintf(buf, PAGE_SIZE, "%u\n", limit * 1000000);
2476 } else if (adev->powerplay.pp_funcs && adev->powerplay.pp_funcs->get_power_limit) {
2477 adev->powerplay.pp_funcs->get_power_limit(adev->powerplay.pp_handle, &limit, true);
2478 size = snprintf(buf, PAGE_SIZE, "%u\n", limit * 1000000);
2480 size = snprintf(buf, PAGE_SIZE, "\n");
2483 pm_runtime_mark_last_busy(adev->ddev->dev);
2484 pm_runtime_put_autosuspend(adev->ddev->dev);
2489 static ssize_t amdgpu_hwmon_show_power_cap(struct device *dev,
2490 struct device_attribute *attr,
2493 struct amdgpu_device *adev = dev_get_drvdata(dev);
2498 r = pm_runtime_get_sync(adev->ddev->dev);
2502 if (is_support_sw_smu(adev)) {
2503 smu_get_power_limit(&adev->smu, &limit, false, true);
2504 size = snprintf(buf, PAGE_SIZE, "%u\n", limit * 1000000);
2505 } else if (adev->powerplay.pp_funcs && adev->powerplay.pp_funcs->get_power_limit) {
2506 adev->powerplay.pp_funcs->get_power_limit(adev->powerplay.pp_handle, &limit, false);
2507 size = snprintf(buf, PAGE_SIZE, "%u\n", limit * 1000000);
2509 size = snprintf(buf, PAGE_SIZE, "\n");
2512 pm_runtime_mark_last_busy(adev->ddev->dev);
2513 pm_runtime_put_autosuspend(adev->ddev->dev);
2519 static ssize_t amdgpu_hwmon_set_power_cap(struct device *dev,
2520 struct device_attribute *attr,
2524 struct amdgpu_device *adev = dev_get_drvdata(dev);
2528 if (amdgpu_sriov_vf(adev))
2531 err = kstrtou32(buf, 10, &value);
2535 value = value / 1000000; /* convert to Watt */
2538 err = pm_runtime_get_sync(adev->ddev->dev);
2542 if (is_support_sw_smu(adev))
2543 err = smu_set_power_limit(&adev->smu, value);
2544 else if (adev->powerplay.pp_funcs && adev->powerplay.pp_funcs->set_power_limit)
2545 err = adev->powerplay.pp_funcs->set_power_limit(adev->powerplay.pp_handle, value);
2549 pm_runtime_mark_last_busy(adev->ddev->dev);
2550 pm_runtime_put_autosuspend(adev->ddev->dev);
2558 static ssize_t amdgpu_hwmon_show_sclk(struct device *dev,
2559 struct device_attribute *attr,
2562 struct amdgpu_device *adev = dev_get_drvdata(dev);
2564 int r, size = sizeof(sclk);
2566 r = pm_runtime_get_sync(adev->ddev->dev);
2571 r = amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GFX_SCLK,
2572 (void *)&sclk, &size);
2574 pm_runtime_mark_last_busy(adev->ddev->dev);
2575 pm_runtime_put_autosuspend(adev->ddev->dev);
2580 return snprintf(buf, PAGE_SIZE, "%d\n", sclk * 10 * 1000);
2583 static ssize_t amdgpu_hwmon_show_sclk_label(struct device *dev,
2584 struct device_attribute *attr,
2587 return snprintf(buf, PAGE_SIZE, "sclk\n");
2590 static ssize_t amdgpu_hwmon_show_mclk(struct device *dev,
2591 struct device_attribute *attr,
2594 struct amdgpu_device *adev = dev_get_drvdata(dev);
2596 int r, size = sizeof(mclk);
2598 r = pm_runtime_get_sync(adev->ddev->dev);
2603 r = amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GFX_MCLK,
2604 (void *)&mclk, &size);
2606 pm_runtime_mark_last_busy(adev->ddev->dev);
2607 pm_runtime_put_autosuspend(adev->ddev->dev);
2612 return snprintf(buf, PAGE_SIZE, "%d\n", mclk * 10 * 1000);
2615 static ssize_t amdgpu_hwmon_show_mclk_label(struct device *dev,
2616 struct device_attribute *attr,
2619 return snprintf(buf, PAGE_SIZE, "mclk\n");
2625 * The amdgpu driver exposes the following sensor interfaces:
2627 * - GPU temperature (via the on-die sensor)
2631 * - Northbridge voltage (APUs only)
2637 * - GPU gfx/compute engine clock
2639 * - GPU memory clock (dGPU only)
2641 * hwmon interfaces for GPU temperature:
2643 * - temp[1-3]_input: the on die GPU temperature in millidegrees Celsius
2644 * - temp2_input and temp3_input are supported on SOC15 dGPUs only
2646 * - temp[1-3]_label: temperature channel label
2647 * - temp2_label and temp3_label are supported on SOC15 dGPUs only
2649 * - temp[1-3]_crit: temperature critical max value in millidegrees Celsius
2650 * - temp2_crit and temp3_crit are supported on SOC15 dGPUs only
2652 * - temp[1-3]_crit_hyst: temperature hysteresis for critical limit in millidegrees Celsius
2653 * - temp2_crit_hyst and temp3_crit_hyst are supported on SOC15 dGPUs only
2655 * - temp[1-3]_emergency: temperature emergency max value(asic shutdown) in millidegrees Celsius
2656 * - these are supported on SOC15 dGPUs only
2658 * hwmon interfaces for GPU voltage:
2660 * - in0_input: the voltage on the GPU in millivolts
2662 * - in1_input: the voltage on the Northbridge in millivolts
2664 * hwmon interfaces for GPU power:
2666 * - power1_average: average power used by the GPU in microWatts
2668 * - power1_cap_min: minimum cap supported in microWatts
2670 * - power1_cap_max: maximum cap supported in microWatts
2672 * - power1_cap: selected power cap in microWatts
2674 * hwmon interfaces for GPU fan:
2676 * - pwm1: pulse width modulation fan level (0-255)
2678 * - 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)
2680 * - pwm1_min: pulse width modulation fan control minimum level (0)
2682 * - pwm1_max: pulse width modulation fan control maximum level (255)
2684 * - fan1_min: an minimum value Unit: revolution/min (RPM)
2686 * - fan1_max: an maxmum value Unit: revolution/max (RPM)
2688 * - fan1_input: fan speed in RPM
2690 * - fan[1-\*]_target: Desired fan speed Unit: revolution/min (RPM)
2692 * - fan[1-\*]_enable: Enable or disable the sensors.1: Enable 0: Disable
2694 * hwmon interfaces for GPU clocks:
2696 * - freq1_input: the gfx/compute clock in hertz
2698 * - freq2_input: the memory clock in hertz
2700 * You can use hwmon tools like sensors to view this information on your system.
2704 static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, amdgpu_hwmon_show_temp, NULL, PP_TEMP_EDGE);
2705 static SENSOR_DEVICE_ATTR(temp1_crit, S_IRUGO, amdgpu_hwmon_show_temp_thresh, NULL, 0);
2706 static SENSOR_DEVICE_ATTR(temp1_crit_hyst, S_IRUGO, amdgpu_hwmon_show_temp_thresh, NULL, 1);
2707 static SENSOR_DEVICE_ATTR(temp1_emergency, S_IRUGO, amdgpu_hwmon_show_temp_emergency, NULL, PP_TEMP_EDGE);
2708 static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, amdgpu_hwmon_show_temp, NULL, PP_TEMP_JUNCTION);
2709 static SENSOR_DEVICE_ATTR(temp2_crit, S_IRUGO, amdgpu_hwmon_show_hotspot_temp_thresh, NULL, 0);
2710 static SENSOR_DEVICE_ATTR(temp2_crit_hyst, S_IRUGO, amdgpu_hwmon_show_hotspot_temp_thresh, NULL, 1);
2711 static SENSOR_DEVICE_ATTR(temp2_emergency, S_IRUGO, amdgpu_hwmon_show_temp_emergency, NULL, PP_TEMP_JUNCTION);
2712 static SENSOR_DEVICE_ATTR(temp3_input, S_IRUGO, amdgpu_hwmon_show_temp, NULL, PP_TEMP_MEM);
2713 static SENSOR_DEVICE_ATTR(temp3_crit, S_IRUGO, amdgpu_hwmon_show_mem_temp_thresh, NULL, 0);
2714 static SENSOR_DEVICE_ATTR(temp3_crit_hyst, S_IRUGO, amdgpu_hwmon_show_mem_temp_thresh, NULL, 1);
2715 static SENSOR_DEVICE_ATTR(temp3_emergency, S_IRUGO, amdgpu_hwmon_show_temp_emergency, NULL, PP_TEMP_MEM);
2716 static SENSOR_DEVICE_ATTR(temp1_label, S_IRUGO, amdgpu_hwmon_show_temp_label, NULL, PP_TEMP_EDGE);
2717 static SENSOR_DEVICE_ATTR(temp2_label, S_IRUGO, amdgpu_hwmon_show_temp_label, NULL, PP_TEMP_JUNCTION);
2718 static SENSOR_DEVICE_ATTR(temp3_label, S_IRUGO, amdgpu_hwmon_show_temp_label, NULL, PP_TEMP_MEM);
2719 static SENSOR_DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, amdgpu_hwmon_get_pwm1, amdgpu_hwmon_set_pwm1, 0);
2720 static SENSOR_DEVICE_ATTR(pwm1_enable, S_IRUGO | S_IWUSR, amdgpu_hwmon_get_pwm1_enable, amdgpu_hwmon_set_pwm1_enable, 0);
2721 static SENSOR_DEVICE_ATTR(pwm1_min, S_IRUGO, amdgpu_hwmon_get_pwm1_min, NULL, 0);
2722 static SENSOR_DEVICE_ATTR(pwm1_max, S_IRUGO, amdgpu_hwmon_get_pwm1_max, NULL, 0);
2723 static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, amdgpu_hwmon_get_fan1_input, NULL, 0);
2724 static SENSOR_DEVICE_ATTR(fan1_min, S_IRUGO, amdgpu_hwmon_get_fan1_min, NULL, 0);
2725 static SENSOR_DEVICE_ATTR(fan1_max, S_IRUGO, amdgpu_hwmon_get_fan1_max, NULL, 0);
2726 static SENSOR_DEVICE_ATTR(fan1_target, S_IRUGO | S_IWUSR, amdgpu_hwmon_get_fan1_target, amdgpu_hwmon_set_fan1_target, 0);
2727 static SENSOR_DEVICE_ATTR(fan1_enable, S_IRUGO | S_IWUSR, amdgpu_hwmon_get_fan1_enable, amdgpu_hwmon_set_fan1_enable, 0);
2728 static SENSOR_DEVICE_ATTR(in0_input, S_IRUGO, amdgpu_hwmon_show_vddgfx, NULL, 0);
2729 static SENSOR_DEVICE_ATTR(in0_label, S_IRUGO, amdgpu_hwmon_show_vddgfx_label, NULL, 0);
2730 static SENSOR_DEVICE_ATTR(in1_input, S_IRUGO, amdgpu_hwmon_show_vddnb, NULL, 0);
2731 static SENSOR_DEVICE_ATTR(in1_label, S_IRUGO, amdgpu_hwmon_show_vddnb_label, NULL, 0);
2732 static SENSOR_DEVICE_ATTR(power1_average, S_IRUGO, amdgpu_hwmon_show_power_avg, NULL, 0);
2733 static SENSOR_DEVICE_ATTR(power1_cap_max, S_IRUGO, amdgpu_hwmon_show_power_cap_max, NULL, 0);
2734 static SENSOR_DEVICE_ATTR(power1_cap_min, S_IRUGO, amdgpu_hwmon_show_power_cap_min, NULL, 0);
2735 static SENSOR_DEVICE_ATTR(power1_cap, S_IRUGO | S_IWUSR, amdgpu_hwmon_show_power_cap, amdgpu_hwmon_set_power_cap, 0);
2736 static SENSOR_DEVICE_ATTR(freq1_input, S_IRUGO, amdgpu_hwmon_show_sclk, NULL, 0);
2737 static SENSOR_DEVICE_ATTR(freq1_label, S_IRUGO, amdgpu_hwmon_show_sclk_label, NULL, 0);
2738 static SENSOR_DEVICE_ATTR(freq2_input, S_IRUGO, amdgpu_hwmon_show_mclk, NULL, 0);
2739 static SENSOR_DEVICE_ATTR(freq2_label, S_IRUGO, amdgpu_hwmon_show_mclk_label, NULL, 0);
2741 static struct attribute *hwmon_attributes[] = {
2742 &sensor_dev_attr_temp1_input.dev_attr.attr,
2743 &sensor_dev_attr_temp1_crit.dev_attr.attr,
2744 &sensor_dev_attr_temp1_crit_hyst.dev_attr.attr,
2745 &sensor_dev_attr_temp2_input.dev_attr.attr,
2746 &sensor_dev_attr_temp2_crit.dev_attr.attr,
2747 &sensor_dev_attr_temp2_crit_hyst.dev_attr.attr,
2748 &sensor_dev_attr_temp3_input.dev_attr.attr,
2749 &sensor_dev_attr_temp3_crit.dev_attr.attr,
2750 &sensor_dev_attr_temp3_crit_hyst.dev_attr.attr,
2751 &sensor_dev_attr_temp1_emergency.dev_attr.attr,
2752 &sensor_dev_attr_temp2_emergency.dev_attr.attr,
2753 &sensor_dev_attr_temp3_emergency.dev_attr.attr,
2754 &sensor_dev_attr_temp1_label.dev_attr.attr,
2755 &sensor_dev_attr_temp2_label.dev_attr.attr,
2756 &sensor_dev_attr_temp3_label.dev_attr.attr,
2757 &sensor_dev_attr_pwm1.dev_attr.attr,
2758 &sensor_dev_attr_pwm1_enable.dev_attr.attr,
2759 &sensor_dev_attr_pwm1_min.dev_attr.attr,
2760 &sensor_dev_attr_pwm1_max.dev_attr.attr,
2761 &sensor_dev_attr_fan1_input.dev_attr.attr,
2762 &sensor_dev_attr_fan1_min.dev_attr.attr,
2763 &sensor_dev_attr_fan1_max.dev_attr.attr,
2764 &sensor_dev_attr_fan1_target.dev_attr.attr,
2765 &sensor_dev_attr_fan1_enable.dev_attr.attr,
2766 &sensor_dev_attr_in0_input.dev_attr.attr,
2767 &sensor_dev_attr_in0_label.dev_attr.attr,
2768 &sensor_dev_attr_in1_input.dev_attr.attr,
2769 &sensor_dev_attr_in1_label.dev_attr.attr,
2770 &sensor_dev_attr_power1_average.dev_attr.attr,
2771 &sensor_dev_attr_power1_cap_max.dev_attr.attr,
2772 &sensor_dev_attr_power1_cap_min.dev_attr.attr,
2773 &sensor_dev_attr_power1_cap.dev_attr.attr,
2774 &sensor_dev_attr_freq1_input.dev_attr.attr,
2775 &sensor_dev_attr_freq1_label.dev_attr.attr,
2776 &sensor_dev_attr_freq2_input.dev_attr.attr,
2777 &sensor_dev_attr_freq2_label.dev_attr.attr,
2781 static umode_t hwmon_attributes_visible(struct kobject *kobj,
2782 struct attribute *attr, int index)
2784 struct device *dev = kobj_to_dev(kobj);
2785 struct amdgpu_device *adev = dev_get_drvdata(dev);
2786 umode_t effective_mode = attr->mode;
2788 /* under multi-vf mode, the hwmon attributes are all not supported */
2789 if (amdgpu_sriov_vf(adev) && !amdgpu_sriov_is_pp_one_vf(adev))
2792 /* there is no fan under pp one vf mode */
2793 if (amdgpu_sriov_is_pp_one_vf(adev) &&
2794 (attr == &sensor_dev_attr_pwm1.dev_attr.attr ||
2795 attr == &sensor_dev_attr_pwm1_enable.dev_attr.attr ||
2796 attr == &sensor_dev_attr_pwm1_max.dev_attr.attr ||
2797 attr == &sensor_dev_attr_pwm1_min.dev_attr.attr ||
2798 attr == &sensor_dev_attr_fan1_input.dev_attr.attr ||
2799 attr == &sensor_dev_attr_fan1_min.dev_attr.attr ||
2800 attr == &sensor_dev_attr_fan1_max.dev_attr.attr ||
2801 attr == &sensor_dev_attr_fan1_target.dev_attr.attr ||
2802 attr == &sensor_dev_attr_fan1_enable.dev_attr.attr))
2805 /* Skip fan attributes if fan is not present */
2806 if (adev->pm.no_fan && (attr == &sensor_dev_attr_pwm1.dev_attr.attr ||
2807 attr == &sensor_dev_attr_pwm1_enable.dev_attr.attr ||
2808 attr == &sensor_dev_attr_pwm1_max.dev_attr.attr ||
2809 attr == &sensor_dev_attr_pwm1_min.dev_attr.attr ||
2810 attr == &sensor_dev_attr_fan1_input.dev_attr.attr ||
2811 attr == &sensor_dev_attr_fan1_min.dev_attr.attr ||
2812 attr == &sensor_dev_attr_fan1_max.dev_attr.attr ||
2813 attr == &sensor_dev_attr_fan1_target.dev_attr.attr ||
2814 attr == &sensor_dev_attr_fan1_enable.dev_attr.attr))
2817 /* Skip fan attributes on APU */
2818 if ((adev->flags & AMD_IS_APU) &&
2819 (attr == &sensor_dev_attr_pwm1.dev_attr.attr ||
2820 attr == &sensor_dev_attr_pwm1_enable.dev_attr.attr ||
2821 attr == &sensor_dev_attr_pwm1_max.dev_attr.attr ||
2822 attr == &sensor_dev_attr_pwm1_min.dev_attr.attr ||
2823 attr == &sensor_dev_attr_fan1_input.dev_attr.attr ||
2824 attr == &sensor_dev_attr_fan1_min.dev_attr.attr ||
2825 attr == &sensor_dev_attr_fan1_max.dev_attr.attr ||
2826 attr == &sensor_dev_attr_fan1_target.dev_attr.attr ||
2827 attr == &sensor_dev_attr_fan1_enable.dev_attr.attr))
2830 /* Skip limit attributes if DPM is not enabled */
2831 if (!adev->pm.dpm_enabled &&
2832 (attr == &sensor_dev_attr_temp1_crit.dev_attr.attr ||
2833 attr == &sensor_dev_attr_temp1_crit_hyst.dev_attr.attr ||
2834 attr == &sensor_dev_attr_pwm1.dev_attr.attr ||
2835 attr == &sensor_dev_attr_pwm1_enable.dev_attr.attr ||
2836 attr == &sensor_dev_attr_pwm1_max.dev_attr.attr ||
2837 attr == &sensor_dev_attr_pwm1_min.dev_attr.attr ||
2838 attr == &sensor_dev_attr_fan1_input.dev_attr.attr ||
2839 attr == &sensor_dev_attr_fan1_min.dev_attr.attr ||
2840 attr == &sensor_dev_attr_fan1_max.dev_attr.attr ||
2841 attr == &sensor_dev_attr_fan1_target.dev_attr.attr ||
2842 attr == &sensor_dev_attr_fan1_enable.dev_attr.attr))
2845 if (!is_support_sw_smu(adev)) {
2846 /* mask fan attributes if we have no bindings for this asic to expose */
2847 if ((!adev->powerplay.pp_funcs->get_fan_speed_percent &&
2848 attr == &sensor_dev_attr_pwm1.dev_attr.attr) || /* can't query fan */
2849 (!adev->powerplay.pp_funcs->get_fan_control_mode &&
2850 attr == &sensor_dev_attr_pwm1_enable.dev_attr.attr)) /* can't query state */
2851 effective_mode &= ~S_IRUGO;
2853 if ((!adev->powerplay.pp_funcs->set_fan_speed_percent &&
2854 attr == &sensor_dev_attr_pwm1.dev_attr.attr) || /* can't manage fan */
2855 (!adev->powerplay.pp_funcs->set_fan_control_mode &&
2856 attr == &sensor_dev_attr_pwm1_enable.dev_attr.attr)) /* can't manage state */
2857 effective_mode &= ~S_IWUSR;
2860 if (((adev->flags & AMD_IS_APU) ||
2861 adev->family == AMDGPU_FAMILY_SI || /* not implemented yet */
2862 adev->family == AMDGPU_FAMILY_KV) && /* not implemented yet */
2863 (attr == &sensor_dev_attr_power1_average.dev_attr.attr ||
2864 attr == &sensor_dev_attr_power1_cap_max.dev_attr.attr ||
2865 attr == &sensor_dev_attr_power1_cap_min.dev_attr.attr||
2866 attr == &sensor_dev_attr_power1_cap.dev_attr.attr))
2869 if (!is_support_sw_smu(adev)) {
2870 /* hide max/min values if we can't both query and manage the fan */
2871 if ((!adev->powerplay.pp_funcs->set_fan_speed_percent &&
2872 !adev->powerplay.pp_funcs->get_fan_speed_percent) &&
2873 (!adev->powerplay.pp_funcs->set_fan_speed_rpm &&
2874 !adev->powerplay.pp_funcs->get_fan_speed_rpm) &&
2875 (attr == &sensor_dev_attr_pwm1_max.dev_attr.attr ||
2876 attr == &sensor_dev_attr_pwm1_min.dev_attr.attr))
2879 if ((!adev->powerplay.pp_funcs->set_fan_speed_rpm &&
2880 !adev->powerplay.pp_funcs->get_fan_speed_rpm) &&
2881 (attr == &sensor_dev_attr_fan1_max.dev_attr.attr ||
2882 attr == &sensor_dev_attr_fan1_min.dev_attr.attr))
2886 if ((adev->family == AMDGPU_FAMILY_SI || /* not implemented yet */
2887 adev->family == AMDGPU_FAMILY_KV) && /* not implemented yet */
2888 (attr == &sensor_dev_attr_in0_input.dev_attr.attr ||
2889 attr == &sensor_dev_attr_in0_label.dev_attr.attr))
2892 /* only APUs have vddnb */
2893 if (!(adev->flags & AMD_IS_APU) &&
2894 (attr == &sensor_dev_attr_in1_input.dev_attr.attr ||
2895 attr == &sensor_dev_attr_in1_label.dev_attr.attr))
2898 /* no mclk on APUs */
2899 if ((adev->flags & AMD_IS_APU) &&
2900 (attr == &sensor_dev_attr_freq2_input.dev_attr.attr ||
2901 attr == &sensor_dev_attr_freq2_label.dev_attr.attr))
2904 /* only SOC15 dGPUs support hotspot and mem temperatures */
2905 if (((adev->flags & AMD_IS_APU) ||
2906 adev->asic_type < CHIP_VEGA10) &&
2907 (attr == &sensor_dev_attr_temp2_crit.dev_attr.attr ||
2908 attr == &sensor_dev_attr_temp2_crit_hyst.dev_attr.attr ||
2909 attr == &sensor_dev_attr_temp3_crit.dev_attr.attr ||
2910 attr == &sensor_dev_attr_temp3_crit_hyst.dev_attr.attr ||
2911 attr == &sensor_dev_attr_temp1_emergency.dev_attr.attr ||
2912 attr == &sensor_dev_attr_temp2_emergency.dev_attr.attr ||
2913 attr == &sensor_dev_attr_temp3_emergency.dev_attr.attr ||
2914 attr == &sensor_dev_attr_temp2_input.dev_attr.attr ||
2915 attr == &sensor_dev_attr_temp3_input.dev_attr.attr ||
2916 attr == &sensor_dev_attr_temp2_label.dev_attr.attr ||
2917 attr == &sensor_dev_attr_temp3_label.dev_attr.attr))
2920 return effective_mode;
2923 static const struct attribute_group hwmon_attrgroup = {
2924 .attrs = hwmon_attributes,
2925 .is_visible = hwmon_attributes_visible,
2928 static const struct attribute_group *hwmon_groups[] = {
2933 void amdgpu_dpm_thermal_work_handler(struct work_struct *work)
2935 struct amdgpu_device *adev =
2936 container_of(work, struct amdgpu_device,
2937 pm.dpm.thermal.work);
2938 /* switch to the thermal state */
2939 enum amd_pm_state_type dpm_state = POWER_STATE_TYPE_INTERNAL_THERMAL;
2940 int temp, size = sizeof(temp);
2942 if (!adev->pm.dpm_enabled)
2945 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GPU_TEMP,
2946 (void *)&temp, &size)) {
2947 if (temp < adev->pm.dpm.thermal.min_temp)
2948 /* switch back the user state */
2949 dpm_state = adev->pm.dpm.user_state;
2951 if (adev->pm.dpm.thermal.high_to_low)
2952 /* switch back the user state */
2953 dpm_state = adev->pm.dpm.user_state;
2955 mutex_lock(&adev->pm.mutex);
2956 if (dpm_state == POWER_STATE_TYPE_INTERNAL_THERMAL)
2957 adev->pm.dpm.thermal_active = true;
2959 adev->pm.dpm.thermal_active = false;
2960 adev->pm.dpm.state = dpm_state;
2961 mutex_unlock(&adev->pm.mutex);
2963 amdgpu_pm_compute_clocks(adev);
2966 static struct amdgpu_ps *amdgpu_dpm_pick_power_state(struct amdgpu_device *adev,
2967 enum amd_pm_state_type dpm_state)
2970 struct amdgpu_ps *ps;
2972 bool single_display = (adev->pm.dpm.new_active_crtc_count < 2) ?
2975 /* check if the vblank period is too short to adjust the mclk */
2976 if (single_display && adev->powerplay.pp_funcs->vblank_too_short) {
2977 if (amdgpu_dpm_vblank_too_short(adev))
2978 single_display = false;
2981 /* certain older asics have a separare 3D performance state,
2982 * so try that first if the user selected performance
2984 if (dpm_state == POWER_STATE_TYPE_PERFORMANCE)
2985 dpm_state = POWER_STATE_TYPE_INTERNAL_3DPERF;
2986 /* balanced states don't exist at the moment */
2987 if (dpm_state == POWER_STATE_TYPE_BALANCED)
2988 dpm_state = POWER_STATE_TYPE_PERFORMANCE;
2991 /* Pick the best power state based on current conditions */
2992 for (i = 0; i < adev->pm.dpm.num_ps; i++) {
2993 ps = &adev->pm.dpm.ps[i];
2994 ui_class = ps->class & ATOM_PPLIB_CLASSIFICATION_UI_MASK;
2995 switch (dpm_state) {
2997 case POWER_STATE_TYPE_BATTERY:
2998 if (ui_class == ATOM_PPLIB_CLASSIFICATION_UI_BATTERY) {
2999 if (ps->caps & ATOM_PPLIB_SINGLE_DISPLAY_ONLY) {
3006 case POWER_STATE_TYPE_BALANCED:
3007 if (ui_class == ATOM_PPLIB_CLASSIFICATION_UI_BALANCED) {
3008 if (ps->caps & ATOM_PPLIB_SINGLE_DISPLAY_ONLY) {
3015 case POWER_STATE_TYPE_PERFORMANCE:
3016 if (ui_class == ATOM_PPLIB_CLASSIFICATION_UI_PERFORMANCE) {
3017 if (ps->caps & ATOM_PPLIB_SINGLE_DISPLAY_ONLY) {
3024 /* internal states */
3025 case POWER_STATE_TYPE_INTERNAL_UVD:
3026 if (adev->pm.dpm.uvd_ps)
3027 return adev->pm.dpm.uvd_ps;
3030 case POWER_STATE_TYPE_INTERNAL_UVD_SD:
3031 if (ps->class & ATOM_PPLIB_CLASSIFICATION_SDSTATE)
3034 case POWER_STATE_TYPE_INTERNAL_UVD_HD:
3035 if (ps->class & ATOM_PPLIB_CLASSIFICATION_HDSTATE)
3038 case POWER_STATE_TYPE_INTERNAL_UVD_HD2:
3039 if (ps->class & ATOM_PPLIB_CLASSIFICATION_HD2STATE)
3042 case POWER_STATE_TYPE_INTERNAL_UVD_MVC:
3043 if (ps->class2 & ATOM_PPLIB_CLASSIFICATION2_MVC)
3046 case POWER_STATE_TYPE_INTERNAL_BOOT:
3047 return adev->pm.dpm.boot_ps;
3048 case POWER_STATE_TYPE_INTERNAL_THERMAL:
3049 if (ps->class & ATOM_PPLIB_CLASSIFICATION_THERMAL)
3052 case POWER_STATE_TYPE_INTERNAL_ACPI:
3053 if (ps->class & ATOM_PPLIB_CLASSIFICATION_ACPI)
3056 case POWER_STATE_TYPE_INTERNAL_ULV:
3057 if (ps->class2 & ATOM_PPLIB_CLASSIFICATION2_ULV)
3060 case POWER_STATE_TYPE_INTERNAL_3DPERF:
3061 if (ps->class & ATOM_PPLIB_CLASSIFICATION_3DPERFORMANCE)
3068 /* use a fallback state if we didn't match */
3069 switch (dpm_state) {
3070 case POWER_STATE_TYPE_INTERNAL_UVD_SD:
3071 dpm_state = POWER_STATE_TYPE_INTERNAL_UVD_HD;
3072 goto restart_search;
3073 case POWER_STATE_TYPE_INTERNAL_UVD_HD:
3074 case POWER_STATE_TYPE_INTERNAL_UVD_HD2:
3075 case POWER_STATE_TYPE_INTERNAL_UVD_MVC:
3076 if (adev->pm.dpm.uvd_ps) {
3077 return adev->pm.dpm.uvd_ps;
3079 dpm_state = POWER_STATE_TYPE_PERFORMANCE;
3080 goto restart_search;
3082 case POWER_STATE_TYPE_INTERNAL_THERMAL:
3083 dpm_state = POWER_STATE_TYPE_INTERNAL_ACPI;
3084 goto restart_search;
3085 case POWER_STATE_TYPE_INTERNAL_ACPI:
3086 dpm_state = POWER_STATE_TYPE_BATTERY;
3087 goto restart_search;
3088 case POWER_STATE_TYPE_BATTERY:
3089 case POWER_STATE_TYPE_BALANCED:
3090 case POWER_STATE_TYPE_INTERNAL_3DPERF:
3091 dpm_state = POWER_STATE_TYPE_PERFORMANCE;
3092 goto restart_search;
3100 static void amdgpu_dpm_change_power_state_locked(struct amdgpu_device *adev)
3102 struct amdgpu_ps *ps;
3103 enum amd_pm_state_type dpm_state;
3107 /* if dpm init failed */
3108 if (!adev->pm.dpm_enabled)
3111 if (adev->pm.dpm.user_state != adev->pm.dpm.state) {
3112 /* add other state override checks here */
3113 if ((!adev->pm.dpm.thermal_active) &&
3114 (!adev->pm.dpm.uvd_active))
3115 adev->pm.dpm.state = adev->pm.dpm.user_state;
3117 dpm_state = adev->pm.dpm.state;
3119 ps = amdgpu_dpm_pick_power_state(adev, dpm_state);
3121 adev->pm.dpm.requested_ps = ps;
3125 if (amdgpu_dpm == 1 && adev->powerplay.pp_funcs->print_power_state) {
3126 printk("switching from power state:\n");
3127 amdgpu_dpm_print_power_state(adev, adev->pm.dpm.current_ps);
3128 printk("switching to power state:\n");
3129 amdgpu_dpm_print_power_state(adev, adev->pm.dpm.requested_ps);
3132 /* update whether vce is active */
3133 ps->vce_active = adev->pm.dpm.vce_active;
3134 if (adev->powerplay.pp_funcs->display_configuration_changed)
3135 amdgpu_dpm_display_configuration_changed(adev);
3137 ret = amdgpu_dpm_pre_set_power_state(adev);
3141 if (adev->powerplay.pp_funcs->check_state_equal) {
3142 if (0 != amdgpu_dpm_check_state_equal(adev, adev->pm.dpm.current_ps, adev->pm.dpm.requested_ps, &equal))
3149 amdgpu_dpm_set_power_state(adev);
3150 amdgpu_dpm_post_set_power_state(adev);
3152 adev->pm.dpm.current_active_crtcs = adev->pm.dpm.new_active_crtcs;
3153 adev->pm.dpm.current_active_crtc_count = adev->pm.dpm.new_active_crtc_count;
3155 if (adev->powerplay.pp_funcs->force_performance_level) {
3156 if (adev->pm.dpm.thermal_active) {
3157 enum amd_dpm_forced_level level = adev->pm.dpm.forced_level;
3158 /* force low perf level for thermal */
3159 amdgpu_dpm_force_performance_level(adev, AMD_DPM_FORCED_LEVEL_LOW);
3160 /* save the user's level */
3161 adev->pm.dpm.forced_level = level;
3163 /* otherwise, user selected level */
3164 amdgpu_dpm_force_performance_level(adev, adev->pm.dpm.forced_level);
3169 void amdgpu_dpm_enable_uvd(struct amdgpu_device *adev, bool enable)
3173 ret = amdgpu_dpm_set_powergating_by_smu(adev, AMD_IP_BLOCK_TYPE_UVD, !enable);
3175 DRM_ERROR("Dpm %s uvd failed, ret = %d. \n",
3176 enable ? "enable" : "disable", ret);
3178 /* enable/disable Low Memory PState for UVD (4k videos) */
3179 if (adev->asic_type == CHIP_STONEY &&
3180 adev->uvd.decode_image_width >= WIDTH_4K) {
3181 struct pp_hwmgr *hwmgr = adev->powerplay.pp_handle;
3183 if (hwmgr && hwmgr->hwmgr_func &&
3184 hwmgr->hwmgr_func->update_nbdpm_pstate)
3185 hwmgr->hwmgr_func->update_nbdpm_pstate(hwmgr,
3191 void amdgpu_dpm_enable_vce(struct amdgpu_device *adev, bool enable)
3195 ret = amdgpu_dpm_set_powergating_by_smu(adev, AMD_IP_BLOCK_TYPE_VCE, !enable);
3197 DRM_ERROR("Dpm %s vce failed, ret = %d. \n",
3198 enable ? "enable" : "disable", ret);
3201 void amdgpu_pm_print_power_states(struct amdgpu_device *adev)
3205 if (adev->powerplay.pp_funcs->print_power_state == NULL)
3208 for (i = 0; i < adev->pm.dpm.num_ps; i++)
3209 amdgpu_dpm_print_power_state(adev, &adev->pm.dpm.ps[i]);
3213 void amdgpu_dpm_enable_jpeg(struct amdgpu_device *adev, bool enable)
3217 ret = amdgpu_dpm_set_powergating_by_smu(adev, AMD_IP_BLOCK_TYPE_JPEG, !enable);
3219 DRM_ERROR("Dpm %s jpeg failed, ret = %d. \n",
3220 enable ? "enable" : "disable", ret);
3223 int amdgpu_pm_load_smu_firmware(struct amdgpu_device *adev, uint32_t *smu_version)
3227 if (adev->powerplay.pp_funcs && adev->powerplay.pp_funcs->load_firmware) {
3228 r = adev->powerplay.pp_funcs->load_firmware(adev->powerplay.pp_handle);
3230 pr_err("smu firmware loading failed\n");
3233 *smu_version = adev->pm.fw_version;
3238 int amdgpu_pm_sysfs_init(struct amdgpu_device *adev)
3240 struct pp_hwmgr *hwmgr = adev->powerplay.pp_handle;
3243 if (adev->pm.sysfs_initialized)
3246 if (adev->pm.dpm_enabled == 0)
3249 adev->pm.int_hwmon_dev = hwmon_device_register_with_groups(adev->dev,
3252 if (IS_ERR(adev->pm.int_hwmon_dev)) {
3253 ret = PTR_ERR(adev->pm.int_hwmon_dev);
3255 "Unable to register hwmon device: %d\n", ret);
3259 ret = device_create_file(adev->dev, &dev_attr_power_dpm_state);
3261 DRM_ERROR("failed to create device file for dpm state\n");
3264 ret = device_create_file(adev->dev, &dev_attr_power_dpm_force_performance_level);
3266 DRM_ERROR("failed to create device file for dpm state\n");
3271 ret = device_create_file(adev->dev, &dev_attr_pp_num_states);
3273 DRM_ERROR("failed to create device file pp_num_states\n");
3276 ret = device_create_file(adev->dev, &dev_attr_pp_cur_state);
3278 DRM_ERROR("failed to create device file pp_cur_state\n");
3281 ret = device_create_file(adev->dev, &dev_attr_pp_force_state);
3283 DRM_ERROR("failed to create device file pp_force_state\n");
3286 ret = device_create_file(adev->dev, &dev_attr_pp_table);
3288 DRM_ERROR("failed to create device file pp_table\n");
3292 ret = device_create_file(adev->dev, &dev_attr_pp_dpm_sclk);
3294 DRM_ERROR("failed to create device file pp_dpm_sclk\n");
3298 /* Arcturus does not support standalone mclk/socclk/fclk level setting */
3299 if (adev->asic_type == CHIP_ARCTURUS) {
3300 dev_attr_pp_dpm_mclk.attr.mode &= ~S_IWUGO;
3301 dev_attr_pp_dpm_mclk.store = NULL;
3303 dev_attr_pp_dpm_socclk.attr.mode &= ~S_IWUGO;
3304 dev_attr_pp_dpm_socclk.store = NULL;
3306 dev_attr_pp_dpm_fclk.attr.mode &= ~S_IWUGO;
3307 dev_attr_pp_dpm_fclk.store = NULL;
3310 ret = device_create_file(adev->dev, &dev_attr_pp_dpm_mclk);
3312 DRM_ERROR("failed to create device file pp_dpm_mclk\n");
3315 if (adev->asic_type >= CHIP_VEGA10) {
3316 ret = device_create_file(adev->dev, &dev_attr_pp_dpm_socclk);
3318 DRM_ERROR("failed to create device file pp_dpm_socclk\n");
3321 if (adev->asic_type != CHIP_ARCTURUS) {
3322 ret = device_create_file(adev->dev, &dev_attr_pp_dpm_dcefclk);
3324 DRM_ERROR("failed to create device file pp_dpm_dcefclk\n");
3329 if (adev->asic_type >= CHIP_VEGA20) {
3330 ret = device_create_file(adev->dev, &dev_attr_pp_dpm_fclk);
3332 DRM_ERROR("failed to create device file pp_dpm_fclk\n");
3336 if (adev->asic_type != CHIP_ARCTURUS) {
3337 ret = device_create_file(adev->dev, &dev_attr_pp_dpm_pcie);
3339 DRM_ERROR("failed to create device file pp_dpm_pcie\n");
3343 ret = device_create_file(adev->dev, &dev_attr_pp_sclk_od);
3345 DRM_ERROR("failed to create device file pp_sclk_od\n");
3348 ret = device_create_file(adev->dev, &dev_attr_pp_mclk_od);
3350 DRM_ERROR("failed to create device file pp_mclk_od\n");
3353 ret = device_create_file(adev->dev,
3354 &dev_attr_pp_power_profile_mode);
3356 DRM_ERROR("failed to create device file "
3357 "pp_power_profile_mode\n");
3360 if ((is_support_sw_smu(adev) && adev->smu.od_enabled) ||
3361 (!is_support_sw_smu(adev) && hwmgr->od_enabled)) {
3362 ret = device_create_file(adev->dev,
3363 &dev_attr_pp_od_clk_voltage);
3365 DRM_ERROR("failed to create device file "
3366 "pp_od_clk_voltage\n");
3370 ret = device_create_file(adev->dev,
3371 &dev_attr_gpu_busy_percent);
3373 DRM_ERROR("failed to create device file "
3374 "gpu_busy_level\n");
3377 /* APU does not have its own dedicated memory */
3378 if (!(adev->flags & AMD_IS_APU) &&
3379 (adev->asic_type != CHIP_VEGA10)) {
3380 ret = device_create_file(adev->dev,
3381 &dev_attr_mem_busy_percent);
3383 DRM_ERROR("failed to create device file "
3384 "mem_busy_percent\n");
3388 /* PCIe Perf counters won't work on APU nodes */
3389 if (!(adev->flags & AMD_IS_APU)) {
3390 ret = device_create_file(adev->dev, &dev_attr_pcie_bw);
3392 DRM_ERROR("failed to create device file pcie_bw\n");
3396 if (adev->unique_id)
3397 ret = device_create_file(adev->dev, &dev_attr_unique_id);
3399 DRM_ERROR("failed to create device file unique_id\n");
3403 if ((adev->asic_type >= CHIP_VEGA10) &&
3404 !(adev->flags & AMD_IS_APU)) {
3405 ret = device_create_file(adev->dev,
3406 &dev_attr_pp_features);
3408 DRM_ERROR("failed to create device file "
3414 adev->pm.sysfs_initialized = true;
3419 void amdgpu_pm_sysfs_fini(struct amdgpu_device *adev)
3421 struct pp_hwmgr *hwmgr = adev->powerplay.pp_handle;
3423 if (adev->pm.dpm_enabled == 0)
3426 if (adev->pm.int_hwmon_dev)
3427 hwmon_device_unregister(adev->pm.int_hwmon_dev);
3428 device_remove_file(adev->dev, &dev_attr_power_dpm_state);
3429 device_remove_file(adev->dev, &dev_attr_power_dpm_force_performance_level);
3431 device_remove_file(adev->dev, &dev_attr_pp_num_states);
3432 device_remove_file(adev->dev, &dev_attr_pp_cur_state);
3433 device_remove_file(adev->dev, &dev_attr_pp_force_state);
3434 device_remove_file(adev->dev, &dev_attr_pp_table);
3436 device_remove_file(adev->dev, &dev_attr_pp_dpm_sclk);
3437 device_remove_file(adev->dev, &dev_attr_pp_dpm_mclk);
3438 if (adev->asic_type >= CHIP_VEGA10) {
3439 device_remove_file(adev->dev, &dev_attr_pp_dpm_socclk);
3440 if (adev->asic_type != CHIP_ARCTURUS)
3441 device_remove_file(adev->dev, &dev_attr_pp_dpm_dcefclk);
3443 if (adev->asic_type != CHIP_ARCTURUS)
3444 device_remove_file(adev->dev, &dev_attr_pp_dpm_pcie);
3445 if (adev->asic_type >= CHIP_VEGA20)
3446 device_remove_file(adev->dev, &dev_attr_pp_dpm_fclk);
3447 device_remove_file(adev->dev, &dev_attr_pp_sclk_od);
3448 device_remove_file(adev->dev, &dev_attr_pp_mclk_od);
3449 device_remove_file(adev->dev,
3450 &dev_attr_pp_power_profile_mode);
3451 if ((is_support_sw_smu(adev) && adev->smu.od_enabled) ||
3452 (!is_support_sw_smu(adev) && hwmgr->od_enabled))
3453 device_remove_file(adev->dev,
3454 &dev_attr_pp_od_clk_voltage);
3455 device_remove_file(adev->dev, &dev_attr_gpu_busy_percent);
3456 if (!(adev->flags & AMD_IS_APU) &&
3457 (adev->asic_type != CHIP_VEGA10))
3458 device_remove_file(adev->dev, &dev_attr_mem_busy_percent);
3459 if (!(adev->flags & AMD_IS_APU))
3460 device_remove_file(adev->dev, &dev_attr_pcie_bw);
3461 if (adev->unique_id)
3462 device_remove_file(adev->dev, &dev_attr_unique_id);
3463 if ((adev->asic_type >= CHIP_VEGA10) &&
3464 !(adev->flags & AMD_IS_APU))
3465 device_remove_file(adev->dev, &dev_attr_pp_features);
3468 void amdgpu_pm_compute_clocks(struct amdgpu_device *adev)
3472 if (!adev->pm.dpm_enabled)
3475 if (adev->mode_info.num_crtc)
3476 amdgpu_display_bandwidth_update(adev);
3478 for (i = 0; i < AMDGPU_MAX_RINGS; i++) {
3479 struct amdgpu_ring *ring = adev->rings[i];
3480 if (ring && ring->sched.ready)
3481 amdgpu_fence_wait_empty(ring);
3484 if (is_support_sw_smu(adev)) {
3485 struct smu_dpm_context *smu_dpm = &adev->smu.smu_dpm;
3486 smu_handle_task(&adev->smu,
3488 AMD_PP_TASK_DISPLAY_CONFIG_CHANGE,
3491 if (adev->powerplay.pp_funcs->dispatch_tasks) {
3492 if (!amdgpu_device_has_dc_support(adev)) {
3493 mutex_lock(&adev->pm.mutex);
3494 amdgpu_dpm_get_active_displays(adev);
3495 adev->pm.pm_display_cfg.num_display = adev->pm.dpm.new_active_crtc_count;
3496 adev->pm.pm_display_cfg.vrefresh = amdgpu_dpm_get_vrefresh(adev);
3497 adev->pm.pm_display_cfg.min_vblank_time = amdgpu_dpm_get_vblank_time(adev);
3498 /* we have issues with mclk switching with refresh rates over 120 hz on the non-DC code. */
3499 if (adev->pm.pm_display_cfg.vrefresh > 120)
3500 adev->pm.pm_display_cfg.min_vblank_time = 0;
3501 if (adev->powerplay.pp_funcs->display_configuration_change)
3502 adev->powerplay.pp_funcs->display_configuration_change(
3503 adev->powerplay.pp_handle,
3504 &adev->pm.pm_display_cfg);
3505 mutex_unlock(&adev->pm.mutex);
3507 amdgpu_dpm_dispatch_task(adev, AMD_PP_TASK_DISPLAY_CONFIG_CHANGE, NULL);
3509 mutex_lock(&adev->pm.mutex);
3510 amdgpu_dpm_get_active_displays(adev);
3511 amdgpu_dpm_change_power_state_locked(adev);
3512 mutex_unlock(&adev->pm.mutex);
3520 #if defined(CONFIG_DEBUG_FS)
3522 static int amdgpu_debugfs_pm_info_pp(struct seq_file *m, struct amdgpu_device *adev)
3530 size = sizeof(value);
3531 seq_printf(m, "GFX Clocks and Power:\n");
3532 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GFX_MCLK, (void *)&value, &size))
3533 seq_printf(m, "\t%u MHz (MCLK)\n", value/100);
3534 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GFX_SCLK, (void *)&value, &size))
3535 seq_printf(m, "\t%u MHz (SCLK)\n", value/100);
3536 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_STABLE_PSTATE_SCLK, (void *)&value, &size))
3537 seq_printf(m, "\t%u MHz (PSTATE_SCLK)\n", value/100);
3538 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_STABLE_PSTATE_MCLK, (void *)&value, &size))
3539 seq_printf(m, "\t%u MHz (PSTATE_MCLK)\n", value/100);
3540 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_VDDGFX, (void *)&value, &size))
3541 seq_printf(m, "\t%u mV (VDDGFX)\n", value);
3542 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_VDDNB, (void *)&value, &size))
3543 seq_printf(m, "\t%u mV (VDDNB)\n", value);
3544 size = sizeof(uint32_t);
3545 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GPU_POWER, (void *)&query, &size))
3546 seq_printf(m, "\t%u.%u W (average GPU)\n", query >> 8, query & 0xff);
3547 size = sizeof(value);
3548 seq_printf(m, "\n");
3551 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GPU_TEMP, (void *)&value, &size))
3552 seq_printf(m, "GPU Temperature: %u C\n", value/1000);
3555 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GPU_LOAD, (void *)&value, &size))
3556 seq_printf(m, "GPU Load: %u %%\n", value);
3558 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_MEM_LOAD, (void *)&value, &size))
3559 seq_printf(m, "MEM Load: %u %%\n", value);
3561 seq_printf(m, "\n");
3563 /* SMC feature mask */
3564 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_ENABLED_SMC_FEATURES_MASK, (void *)&value64, &size))
3565 seq_printf(m, "SMC Feature Mask: 0x%016llx\n", value64);
3567 if (adev->asic_type > CHIP_VEGA20) {
3569 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_VCN_POWER_STATE, (void *)&value, &size)) {
3571 seq_printf(m, "VCN: Disabled\n");
3573 seq_printf(m, "VCN: Enabled\n");
3574 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_UVD_DCLK, (void *)&value, &size))
3575 seq_printf(m, "\t%u MHz (DCLK)\n", value/100);
3576 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_UVD_VCLK, (void *)&value, &size))
3577 seq_printf(m, "\t%u MHz (VCLK)\n", value/100);
3580 seq_printf(m, "\n");
3583 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_UVD_POWER, (void *)&value, &size)) {
3585 seq_printf(m, "UVD: Disabled\n");
3587 seq_printf(m, "UVD: Enabled\n");
3588 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_UVD_DCLK, (void *)&value, &size))
3589 seq_printf(m, "\t%u MHz (DCLK)\n", value/100);
3590 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_UVD_VCLK, (void *)&value, &size))
3591 seq_printf(m, "\t%u MHz (VCLK)\n", value/100);
3594 seq_printf(m, "\n");
3597 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_VCE_POWER, (void *)&value, &size)) {
3599 seq_printf(m, "VCE: Disabled\n");
3601 seq_printf(m, "VCE: Enabled\n");
3602 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_VCE_ECCLK, (void *)&value, &size))
3603 seq_printf(m, "\t%u MHz (ECCLK)\n", value/100);
3611 static void amdgpu_parse_cg_state(struct seq_file *m, u32 flags)
3615 for (i = 0; clocks[i].flag; i++)
3616 seq_printf(m, "\t%s: %s\n", clocks[i].name,
3617 (flags & clocks[i].flag) ? "On" : "Off");
3620 static int amdgpu_debugfs_pm_info(struct seq_file *m, void *data)
3622 struct drm_info_node *node = (struct drm_info_node *) m->private;
3623 struct drm_device *dev = node->minor->dev;
3624 struct amdgpu_device *adev = dev->dev_private;
3628 r = pm_runtime_get_sync(dev->dev);
3632 amdgpu_device_ip_get_clockgating_state(adev, &flags);
3633 seq_printf(m, "Clock Gating Flags Mask: 0x%x\n", flags);
3634 amdgpu_parse_cg_state(m, flags);
3635 seq_printf(m, "\n");
3637 if (!adev->pm.dpm_enabled) {
3638 seq_printf(m, "dpm not enabled\n");
3639 pm_runtime_mark_last_busy(dev->dev);
3640 pm_runtime_put_autosuspend(dev->dev);
3644 if (!is_support_sw_smu(adev) &&
3645 adev->powerplay.pp_funcs->debugfs_print_current_performance_level) {
3646 mutex_lock(&adev->pm.mutex);
3647 if (adev->powerplay.pp_funcs->debugfs_print_current_performance_level)
3648 adev->powerplay.pp_funcs->debugfs_print_current_performance_level(adev, m);
3650 seq_printf(m, "Debugfs support not implemented for this asic\n");
3651 mutex_unlock(&adev->pm.mutex);
3654 r = amdgpu_debugfs_pm_info_pp(m, adev);
3657 pm_runtime_mark_last_busy(dev->dev);
3658 pm_runtime_put_autosuspend(dev->dev);
3663 static const struct drm_info_list amdgpu_pm_info_list[] = {
3664 {"amdgpu_pm_info", amdgpu_debugfs_pm_info, 0, NULL},
3668 int amdgpu_debugfs_pm_init(struct amdgpu_device *adev)
3670 #if defined(CONFIG_DEBUG_FS)
3671 return amdgpu_debugfs_add_files(adev, amdgpu_pm_info_list, ARRAY_SIZE(amdgpu_pm_info_list));