2 * Copyright 2017 Advanced Micro Devices, Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
26 #include <drm/drm_debugfs.h>
29 #include "amdgpu_drv.h"
30 #include "amdgpu_pm.h"
31 #include "amdgpu_dpm.h"
32 #include "amdgpu_display.h"
33 #include "amdgpu_smu.h"
35 #include <linux/power_supply.h>
36 #include <linux/pci.h>
37 #include <linux/hwmon.h>
38 #include <linux/hwmon-sysfs.h>
39 #include <linux/nospec.h>
40 #include <linux/pm_runtime.h>
44 static const struct cg_flag_name clocks[] = {
45 {AMD_CG_SUPPORT_GFX_MGCG, "Graphics Medium Grain Clock Gating"},
46 {AMD_CG_SUPPORT_GFX_MGLS, "Graphics Medium Grain memory Light Sleep"},
47 {AMD_CG_SUPPORT_GFX_CGCG, "Graphics Coarse Grain Clock Gating"},
48 {AMD_CG_SUPPORT_GFX_CGLS, "Graphics Coarse Grain memory Light Sleep"},
49 {AMD_CG_SUPPORT_GFX_CGTS, "Graphics Coarse Grain Tree Shader Clock Gating"},
50 {AMD_CG_SUPPORT_GFX_CGTS_LS, "Graphics Coarse Grain Tree Shader Light Sleep"},
51 {AMD_CG_SUPPORT_GFX_CP_LS, "Graphics Command Processor Light Sleep"},
52 {AMD_CG_SUPPORT_GFX_RLC_LS, "Graphics Run List Controller Light Sleep"},
53 {AMD_CG_SUPPORT_GFX_3D_CGCG, "Graphics 3D Coarse Grain Clock Gating"},
54 {AMD_CG_SUPPORT_GFX_3D_CGLS, "Graphics 3D Coarse Grain memory Light Sleep"},
55 {AMD_CG_SUPPORT_MC_LS, "Memory Controller Light Sleep"},
56 {AMD_CG_SUPPORT_MC_MGCG, "Memory Controller Medium Grain Clock Gating"},
57 {AMD_CG_SUPPORT_SDMA_LS, "System Direct Memory Access Light Sleep"},
58 {AMD_CG_SUPPORT_SDMA_MGCG, "System Direct Memory Access Medium Grain Clock Gating"},
59 {AMD_CG_SUPPORT_BIF_MGCG, "Bus Interface Medium Grain Clock Gating"},
60 {AMD_CG_SUPPORT_BIF_LS, "Bus Interface Light Sleep"},
61 {AMD_CG_SUPPORT_UVD_MGCG, "Unified Video Decoder Medium Grain Clock Gating"},
62 {AMD_CG_SUPPORT_VCE_MGCG, "Video Compression Engine Medium Grain Clock Gating"},
63 {AMD_CG_SUPPORT_HDP_LS, "Host Data Path Light Sleep"},
64 {AMD_CG_SUPPORT_HDP_MGCG, "Host Data Path Medium Grain Clock Gating"},
65 {AMD_CG_SUPPORT_DRM_MGCG, "Digital Right Management Medium Grain Clock Gating"},
66 {AMD_CG_SUPPORT_DRM_LS, "Digital Right Management Light Sleep"},
67 {AMD_CG_SUPPORT_ROM_MGCG, "Rom Medium Grain Clock Gating"},
68 {AMD_CG_SUPPORT_DF_MGCG, "Data Fabric Medium Grain Clock Gating"},
70 {AMD_CG_SUPPORT_ATHUB_MGCG, "Address Translation Hub Medium Grain Clock Gating"},
71 {AMD_CG_SUPPORT_ATHUB_LS, "Address Translation Hub Light Sleep"},
75 static const struct hwmon_temp_label {
76 enum PP_HWMON_TEMP channel;
79 {PP_TEMP_EDGE, "edge"},
80 {PP_TEMP_JUNCTION, "junction"},
84 void amdgpu_pm_acpi_event_handler(struct amdgpu_device *adev)
86 if (adev->pm.dpm_enabled) {
87 mutex_lock(&adev->pm.mutex);
88 if (power_supply_is_system_supplied() > 0)
89 adev->pm.ac_power = true;
91 adev->pm.ac_power = false;
92 if (adev->powerplay.pp_funcs &&
93 adev->powerplay.pp_funcs->enable_bapm)
94 amdgpu_dpm_enable_bapm(adev, adev->pm.ac_power);
95 mutex_unlock(&adev->pm.mutex);
97 if (is_support_sw_smu(adev))
98 smu_set_ac_dc(&adev->smu);
102 int amdgpu_dpm_read_sensor(struct amdgpu_device *adev, enum amd_pp_sensors sensor,
103 void *data, uint32_t *size)
110 if (is_support_sw_smu(adev))
111 ret = smu_read_sensor(&adev->smu, sensor, data, size);
113 if (adev->powerplay.pp_funcs && adev->powerplay.pp_funcs->read_sensor)
114 ret = adev->powerplay.pp_funcs->read_sensor((adev)->powerplay.pp_handle,
124 * DOC: power_dpm_state
126 * The power_dpm_state file is a legacy interface and is only provided for
127 * backwards compatibility. The amdgpu driver provides a sysfs API for adjusting
128 * certain power related parameters. The file power_dpm_state is used for this.
129 * It accepts the following arguments:
139 * On older GPUs, the vbios provided a special power state for battery
140 * operation. Selecting battery switched to this state. This is no
141 * longer provided on newer GPUs so the option does nothing in that case.
145 * On older GPUs, the vbios provided a special power state for balanced
146 * operation. Selecting balanced switched to this state. This is no
147 * longer provided on newer GPUs so the option does nothing in that case.
151 * On older GPUs, the vbios provided a special power state for performance
152 * operation. Selecting performance switched to this state. This is no
153 * longer provided on newer GPUs so the option does nothing in that case.
157 static ssize_t amdgpu_get_power_dpm_state(struct device *dev,
158 struct device_attribute *attr,
161 struct drm_device *ddev = dev_get_drvdata(dev);
162 struct amdgpu_device *adev = ddev->dev_private;
163 enum amd_pm_state_type pm;
166 if (adev->in_gpu_reset)
169 ret = pm_runtime_get_sync(ddev->dev);
173 if (is_support_sw_smu(adev)) {
174 if (adev->smu.ppt_funcs->get_current_power_state)
175 pm = smu_get_current_power_state(&adev->smu);
177 pm = adev->pm.dpm.user_state;
178 } else if (adev->powerplay.pp_funcs->get_current_power_state) {
179 pm = amdgpu_dpm_get_current_power_state(adev);
181 pm = adev->pm.dpm.user_state;
184 pm_runtime_mark_last_busy(ddev->dev);
185 pm_runtime_put_autosuspend(ddev->dev);
187 return snprintf(buf, PAGE_SIZE, "%s\n",
188 (pm == POWER_STATE_TYPE_BATTERY) ? "battery" :
189 (pm == POWER_STATE_TYPE_BALANCED) ? "balanced" : "performance");
192 static ssize_t amdgpu_set_power_dpm_state(struct device *dev,
193 struct device_attribute *attr,
197 struct drm_device *ddev = dev_get_drvdata(dev);
198 struct amdgpu_device *adev = ddev->dev_private;
199 enum amd_pm_state_type state;
202 if (adev->in_gpu_reset)
205 if (strncmp("battery", buf, strlen("battery")) == 0)
206 state = POWER_STATE_TYPE_BATTERY;
207 else if (strncmp("balanced", buf, strlen("balanced")) == 0)
208 state = POWER_STATE_TYPE_BALANCED;
209 else if (strncmp("performance", buf, strlen("performance")) == 0)
210 state = POWER_STATE_TYPE_PERFORMANCE;
214 ret = pm_runtime_get_sync(ddev->dev);
218 if (is_support_sw_smu(adev)) {
219 mutex_lock(&adev->pm.mutex);
220 adev->pm.dpm.user_state = state;
221 mutex_unlock(&adev->pm.mutex);
222 } else if (adev->powerplay.pp_funcs->dispatch_tasks) {
223 amdgpu_dpm_dispatch_task(adev, AMD_PP_TASK_ENABLE_USER_STATE, &state);
225 mutex_lock(&adev->pm.mutex);
226 adev->pm.dpm.user_state = state;
227 mutex_unlock(&adev->pm.mutex);
229 amdgpu_pm_compute_clocks(adev);
231 pm_runtime_mark_last_busy(ddev->dev);
232 pm_runtime_put_autosuspend(ddev->dev);
239 * DOC: power_dpm_force_performance_level
241 * The amdgpu driver provides a sysfs API for adjusting certain power
242 * related parameters. The file power_dpm_force_performance_level is
243 * used for this. It accepts the following arguments:
263 * When auto is selected, the driver will attempt to dynamically select
264 * the optimal power profile for current conditions in the driver.
268 * When low is selected, the clocks are forced to the lowest power state.
272 * When high is selected, the clocks are forced to the highest power state.
276 * When manual is selected, the user can manually adjust which power states
277 * are enabled for each clock domain via the sysfs pp_dpm_mclk, pp_dpm_sclk,
278 * and pp_dpm_pcie files and adjust the power state transition heuristics
279 * via the pp_power_profile_mode sysfs file.
286 * When the profiling modes are selected, clock and power gating are
287 * disabled and the clocks are set for different profiling cases. This
288 * mode is recommended for profiling specific work loads where you do
289 * not want clock or power gating for clock fluctuation to interfere
290 * with your results. profile_standard sets the clocks to a fixed clock
291 * level which varies from asic to asic. profile_min_sclk forces the sclk
292 * to the lowest level. profile_min_mclk forces the mclk to the lowest level.
293 * profile_peak sets all clocks (mclk, sclk, pcie) to the highest levels.
297 static ssize_t amdgpu_get_power_dpm_force_performance_level(struct device *dev,
298 struct device_attribute *attr,
301 struct drm_device *ddev = dev_get_drvdata(dev);
302 struct amdgpu_device *adev = ddev->dev_private;
303 enum amd_dpm_forced_level level = 0xff;
306 if (adev->in_gpu_reset)
309 ret = pm_runtime_get_sync(ddev->dev);
313 if (is_support_sw_smu(adev))
314 level = smu_get_performance_level(&adev->smu);
315 else if (adev->powerplay.pp_funcs->get_performance_level)
316 level = amdgpu_dpm_get_performance_level(adev);
318 level = adev->pm.dpm.forced_level;
320 pm_runtime_mark_last_busy(ddev->dev);
321 pm_runtime_put_autosuspend(ddev->dev);
323 return snprintf(buf, PAGE_SIZE, "%s\n",
324 (level == AMD_DPM_FORCED_LEVEL_AUTO) ? "auto" :
325 (level == AMD_DPM_FORCED_LEVEL_LOW) ? "low" :
326 (level == AMD_DPM_FORCED_LEVEL_HIGH) ? "high" :
327 (level == AMD_DPM_FORCED_LEVEL_MANUAL) ? "manual" :
328 (level == AMD_DPM_FORCED_LEVEL_PROFILE_STANDARD) ? "profile_standard" :
329 (level == AMD_DPM_FORCED_LEVEL_PROFILE_MIN_SCLK) ? "profile_min_sclk" :
330 (level == AMD_DPM_FORCED_LEVEL_PROFILE_MIN_MCLK) ? "profile_min_mclk" :
331 (level == AMD_DPM_FORCED_LEVEL_PROFILE_PEAK) ? "profile_peak" :
335 static ssize_t amdgpu_set_power_dpm_force_performance_level(struct device *dev,
336 struct device_attribute *attr,
340 struct drm_device *ddev = dev_get_drvdata(dev);
341 struct amdgpu_device *adev = ddev->dev_private;
342 enum amd_dpm_forced_level level;
343 enum amd_dpm_forced_level current_level = 0xff;
346 if (adev->in_gpu_reset)
349 if (strncmp("low", buf, strlen("low")) == 0) {
350 level = AMD_DPM_FORCED_LEVEL_LOW;
351 } else if (strncmp("high", buf, strlen("high")) == 0) {
352 level = AMD_DPM_FORCED_LEVEL_HIGH;
353 } else if (strncmp("auto", buf, strlen("auto")) == 0) {
354 level = AMD_DPM_FORCED_LEVEL_AUTO;
355 } else if (strncmp("manual", buf, strlen("manual")) == 0) {
356 level = AMD_DPM_FORCED_LEVEL_MANUAL;
357 } else if (strncmp("profile_exit", buf, strlen("profile_exit")) == 0) {
358 level = AMD_DPM_FORCED_LEVEL_PROFILE_EXIT;
359 } else if (strncmp("profile_standard", buf, strlen("profile_standard")) == 0) {
360 level = AMD_DPM_FORCED_LEVEL_PROFILE_STANDARD;
361 } else if (strncmp("profile_min_sclk", buf, strlen("profile_min_sclk")) == 0) {
362 level = AMD_DPM_FORCED_LEVEL_PROFILE_MIN_SCLK;
363 } else if (strncmp("profile_min_mclk", buf, strlen("profile_min_mclk")) == 0) {
364 level = AMD_DPM_FORCED_LEVEL_PROFILE_MIN_MCLK;
365 } else if (strncmp("profile_peak", buf, strlen("profile_peak")) == 0) {
366 level = AMD_DPM_FORCED_LEVEL_PROFILE_PEAK;
371 ret = pm_runtime_get_sync(ddev->dev);
375 if (is_support_sw_smu(adev))
376 current_level = smu_get_performance_level(&adev->smu);
377 else if (adev->powerplay.pp_funcs->get_performance_level)
378 current_level = amdgpu_dpm_get_performance_level(adev);
380 if (current_level == level) {
381 pm_runtime_mark_last_busy(ddev->dev);
382 pm_runtime_put_autosuspend(ddev->dev);
386 if (adev->asic_type == CHIP_RAVEN) {
387 if (!(adev->apu_flags & AMD_APU_IS_RAVEN2)) {
388 if (current_level != AMD_DPM_FORCED_LEVEL_MANUAL && level == AMD_DPM_FORCED_LEVEL_MANUAL)
389 amdgpu_gfx_off_ctrl(adev, false);
390 else if (current_level == AMD_DPM_FORCED_LEVEL_MANUAL && level != AMD_DPM_FORCED_LEVEL_MANUAL)
391 amdgpu_gfx_off_ctrl(adev, true);
395 /* profile_exit setting is valid only when current mode is in profile mode */
396 if (!(current_level & (AMD_DPM_FORCED_LEVEL_PROFILE_STANDARD |
397 AMD_DPM_FORCED_LEVEL_PROFILE_MIN_SCLK |
398 AMD_DPM_FORCED_LEVEL_PROFILE_MIN_MCLK |
399 AMD_DPM_FORCED_LEVEL_PROFILE_PEAK)) &&
400 (level == AMD_DPM_FORCED_LEVEL_PROFILE_EXIT)) {
401 pr_err("Currently not in any profile mode!\n");
402 pm_runtime_mark_last_busy(ddev->dev);
403 pm_runtime_put_autosuspend(ddev->dev);
407 if (is_support_sw_smu(adev)) {
408 ret = smu_force_performance_level(&adev->smu, level);
410 pm_runtime_mark_last_busy(ddev->dev);
411 pm_runtime_put_autosuspend(ddev->dev);
414 } else if (adev->powerplay.pp_funcs->force_performance_level) {
415 mutex_lock(&adev->pm.mutex);
416 if (adev->pm.dpm.thermal_active) {
417 mutex_unlock(&adev->pm.mutex);
418 pm_runtime_mark_last_busy(ddev->dev);
419 pm_runtime_put_autosuspend(ddev->dev);
422 ret = amdgpu_dpm_force_performance_level(adev, level);
424 mutex_unlock(&adev->pm.mutex);
425 pm_runtime_mark_last_busy(ddev->dev);
426 pm_runtime_put_autosuspend(ddev->dev);
429 adev->pm.dpm.forced_level = level;
431 mutex_unlock(&adev->pm.mutex);
433 pm_runtime_mark_last_busy(ddev->dev);
434 pm_runtime_put_autosuspend(ddev->dev);
439 static ssize_t amdgpu_get_pp_num_states(struct device *dev,
440 struct device_attribute *attr,
443 struct drm_device *ddev = dev_get_drvdata(dev);
444 struct amdgpu_device *adev = ddev->dev_private;
445 struct pp_states_info data;
448 if (adev->in_gpu_reset)
451 ret = pm_runtime_get_sync(ddev->dev);
455 if (is_support_sw_smu(adev)) {
456 ret = smu_get_power_num_states(&adev->smu, &data);
459 } else if (adev->powerplay.pp_funcs->get_pp_num_states) {
460 amdgpu_dpm_get_pp_num_states(adev, &data);
462 memset(&data, 0, sizeof(data));
465 pm_runtime_mark_last_busy(ddev->dev);
466 pm_runtime_put_autosuspend(ddev->dev);
468 buf_len = snprintf(buf, PAGE_SIZE, "states: %d\n", data.nums);
469 for (i = 0; i < data.nums; i++)
470 buf_len += snprintf(buf + buf_len, PAGE_SIZE, "%d %s\n", i,
471 (data.states[i] == POWER_STATE_TYPE_INTERNAL_BOOT) ? "boot" :
472 (data.states[i] == POWER_STATE_TYPE_BATTERY) ? "battery" :
473 (data.states[i] == POWER_STATE_TYPE_BALANCED) ? "balanced" :
474 (data.states[i] == POWER_STATE_TYPE_PERFORMANCE) ? "performance" : "default");
479 static ssize_t amdgpu_get_pp_cur_state(struct device *dev,
480 struct device_attribute *attr,
483 struct drm_device *ddev = dev_get_drvdata(dev);
484 struct amdgpu_device *adev = ddev->dev_private;
485 struct pp_states_info data;
486 struct smu_context *smu = &adev->smu;
487 enum amd_pm_state_type pm = 0;
490 if (adev->in_gpu_reset)
493 ret = pm_runtime_get_sync(ddev->dev);
497 if (is_support_sw_smu(adev)) {
498 pm = smu_get_current_power_state(smu);
499 ret = smu_get_power_num_states(smu, &data);
502 } else if (adev->powerplay.pp_funcs->get_current_power_state
503 && adev->powerplay.pp_funcs->get_pp_num_states) {
504 pm = amdgpu_dpm_get_current_power_state(adev);
505 amdgpu_dpm_get_pp_num_states(adev, &data);
508 pm_runtime_mark_last_busy(ddev->dev);
509 pm_runtime_put_autosuspend(ddev->dev);
511 for (i = 0; i < data.nums; i++) {
512 if (pm == data.states[i])
519 return snprintf(buf, PAGE_SIZE, "%d\n", i);
522 static ssize_t amdgpu_get_pp_force_state(struct device *dev,
523 struct device_attribute *attr,
526 struct drm_device *ddev = dev_get_drvdata(dev);
527 struct amdgpu_device *adev = ddev->dev_private;
529 if (adev->in_gpu_reset)
532 if (adev->pp_force_state_enabled)
533 return amdgpu_get_pp_cur_state(dev, attr, buf);
535 return snprintf(buf, PAGE_SIZE, "\n");
538 static ssize_t amdgpu_set_pp_force_state(struct device *dev,
539 struct device_attribute *attr,
543 struct drm_device *ddev = dev_get_drvdata(dev);
544 struct amdgpu_device *adev = ddev->dev_private;
545 enum amd_pm_state_type state = 0;
549 if (adev->in_gpu_reset)
552 if (strlen(buf) == 1)
553 adev->pp_force_state_enabled = false;
554 else if (is_support_sw_smu(adev))
555 adev->pp_force_state_enabled = false;
556 else if (adev->powerplay.pp_funcs->dispatch_tasks &&
557 adev->powerplay.pp_funcs->get_pp_num_states) {
558 struct pp_states_info data;
560 ret = kstrtoul(buf, 0, &idx);
561 if (ret || idx >= ARRAY_SIZE(data.states))
564 idx = array_index_nospec(idx, ARRAY_SIZE(data.states));
566 amdgpu_dpm_get_pp_num_states(adev, &data);
567 state = data.states[idx];
569 ret = pm_runtime_get_sync(ddev->dev);
573 /* only set user selected power states */
574 if (state != POWER_STATE_TYPE_INTERNAL_BOOT &&
575 state != POWER_STATE_TYPE_DEFAULT) {
576 amdgpu_dpm_dispatch_task(adev,
577 AMD_PP_TASK_ENABLE_USER_STATE, &state);
578 adev->pp_force_state_enabled = true;
580 pm_runtime_mark_last_busy(ddev->dev);
581 pm_runtime_put_autosuspend(ddev->dev);
590 * The amdgpu driver provides a sysfs API for uploading new powerplay
591 * tables. The file pp_table is used for this. Reading the file
592 * will dump the current power play table. Writing to the file
593 * will attempt to upload a new powerplay table and re-initialize
594 * powerplay using that new table.
598 static ssize_t amdgpu_get_pp_table(struct device *dev,
599 struct device_attribute *attr,
602 struct drm_device *ddev = dev_get_drvdata(dev);
603 struct amdgpu_device *adev = ddev->dev_private;
607 if (adev->in_gpu_reset)
610 ret = pm_runtime_get_sync(ddev->dev);
614 if (is_support_sw_smu(adev)) {
615 size = smu_sys_get_pp_table(&adev->smu, (void **)&table);
616 pm_runtime_mark_last_busy(ddev->dev);
617 pm_runtime_put_autosuspend(ddev->dev);
620 } else if (adev->powerplay.pp_funcs->get_pp_table) {
621 size = amdgpu_dpm_get_pp_table(adev, &table);
622 pm_runtime_mark_last_busy(ddev->dev);
623 pm_runtime_put_autosuspend(ddev->dev);
627 pm_runtime_mark_last_busy(ddev->dev);
628 pm_runtime_put_autosuspend(ddev->dev);
632 if (size >= PAGE_SIZE)
633 size = PAGE_SIZE - 1;
635 memcpy(buf, table, size);
640 static ssize_t amdgpu_set_pp_table(struct device *dev,
641 struct device_attribute *attr,
645 struct drm_device *ddev = dev_get_drvdata(dev);
646 struct amdgpu_device *adev = ddev->dev_private;
649 if (adev->in_gpu_reset)
652 ret = pm_runtime_get_sync(ddev->dev);
656 if (is_support_sw_smu(adev)) {
657 ret = smu_sys_set_pp_table(&adev->smu, (void *)buf, count);
659 pm_runtime_mark_last_busy(ddev->dev);
660 pm_runtime_put_autosuspend(ddev->dev);
663 } else if (adev->powerplay.pp_funcs->set_pp_table)
664 amdgpu_dpm_set_pp_table(adev, buf, count);
666 pm_runtime_mark_last_busy(ddev->dev);
667 pm_runtime_put_autosuspend(ddev->dev);
673 * DOC: pp_od_clk_voltage
675 * The amdgpu driver provides a sysfs API for adjusting the clocks and voltages
676 * in each power level within a power state. The pp_od_clk_voltage is used for
679 * < For Vega10 and previous ASICs >
681 * Reading the file will display:
683 * - a list of engine clock levels and voltages labeled OD_SCLK
685 * - a list of memory clock levels and voltages labeled OD_MCLK
687 * - a list of valid ranges for sclk, mclk, and voltage labeled OD_RANGE
689 * To manually adjust these settings, first select manual using
690 * power_dpm_force_performance_level. Enter a new value for each
691 * level by writing a string that contains "s/m level clock voltage" to
692 * the file. E.g., "s 1 500 820" will update sclk level 1 to be 500 MHz
693 * at 820 mV; "m 0 350 810" will update mclk level 0 to be 350 MHz at
694 * 810 mV. When you have edited all of the states as needed, write
695 * "c" (commit) to the file to commit your changes. If you want to reset to the
696 * default power levels, write "r" (reset) to the file to reset them.
701 * Reading the file will display:
703 * - minimum and maximum engine clock labeled OD_SCLK
705 * - maximum memory clock labeled OD_MCLK
707 * - three <frequency, voltage> points labeled OD_VDDC_CURVE.
708 * They can be used to calibrate the sclk voltage curve.
710 * - a list of valid ranges for sclk, mclk, and voltage curve points
713 * To manually adjust these settings:
715 * - First select manual using power_dpm_force_performance_level
717 * - For clock frequency setting, enter a new value by writing a
718 * string that contains "s/m index clock" to the file. The index
719 * should be 0 if to set minimum clock. And 1 if to set maximum
720 * clock. E.g., "s 0 500" will update minimum sclk to be 500 MHz.
721 * "m 1 800" will update maximum mclk to be 800Mhz.
723 * For sclk voltage curve, enter the new values by writing a
724 * string that contains "vc point clock voltage" to the file. The
725 * points are indexed by 0, 1 and 2. E.g., "vc 0 300 600" will
726 * update point1 with clock set as 300Mhz and voltage as
727 * 600mV. "vc 2 1000 1000" will update point3 with clock set
728 * as 1000Mhz and voltage 1000mV.
730 * - When you have edited all of the states as needed, write "c" (commit)
731 * to the file to commit your changes
733 * - If you want to reset to the default power levels, write "r" (reset)
734 * to the file to reset them
738 static ssize_t amdgpu_set_pp_od_clk_voltage(struct device *dev,
739 struct device_attribute *attr,
743 struct drm_device *ddev = dev_get_drvdata(dev);
744 struct amdgpu_device *adev = ddev->dev_private;
746 uint32_t parameter_size = 0;
751 const char delimiter[3] = {' ', '\n', '\0'};
754 if (adev->in_gpu_reset)
761 type = PP_OD_EDIT_SCLK_VDDC_TABLE;
762 else if (*buf == 'm')
763 type = PP_OD_EDIT_MCLK_VDDC_TABLE;
765 type = PP_OD_RESTORE_DEFAULT_TABLE;
766 else if (*buf == 'c')
767 type = PP_OD_COMMIT_DPM_TABLE;
768 else if (!strncmp(buf, "vc", 2))
769 type = PP_OD_EDIT_VDDC_CURVE;
773 memcpy(buf_cpy, buf, count+1);
777 if (type == PP_OD_EDIT_VDDC_CURVE)
779 while (isspace(*++tmp_str));
782 sub_str = strsep(&tmp_str, delimiter);
783 ret = kstrtol(sub_str, 0, ¶meter[parameter_size]);
788 while (isspace(*tmp_str))
792 ret = pm_runtime_get_sync(ddev->dev);
796 if (is_support_sw_smu(adev)) {
797 ret = smu_od_edit_dpm_table(&adev->smu, type,
798 parameter, parameter_size);
801 pm_runtime_mark_last_busy(ddev->dev);
802 pm_runtime_put_autosuspend(ddev->dev);
806 if (adev->powerplay.pp_funcs->odn_edit_dpm_table) {
807 ret = amdgpu_dpm_odn_edit_dpm_table(adev, type,
808 parameter, parameter_size);
810 pm_runtime_mark_last_busy(ddev->dev);
811 pm_runtime_put_autosuspend(ddev->dev);
816 if (type == PP_OD_COMMIT_DPM_TABLE) {
817 if (adev->powerplay.pp_funcs->dispatch_tasks) {
818 amdgpu_dpm_dispatch_task(adev,
819 AMD_PP_TASK_READJUST_POWER_STATE,
821 pm_runtime_mark_last_busy(ddev->dev);
822 pm_runtime_put_autosuspend(ddev->dev);
825 pm_runtime_mark_last_busy(ddev->dev);
826 pm_runtime_put_autosuspend(ddev->dev);
831 pm_runtime_mark_last_busy(ddev->dev);
832 pm_runtime_put_autosuspend(ddev->dev);
837 static ssize_t amdgpu_get_pp_od_clk_voltage(struct device *dev,
838 struct device_attribute *attr,
841 struct drm_device *ddev = dev_get_drvdata(dev);
842 struct amdgpu_device *adev = ddev->dev_private;
846 if (adev->in_gpu_reset)
849 ret = pm_runtime_get_sync(ddev->dev);
853 if (is_support_sw_smu(adev)) {
854 size = smu_print_clk_levels(&adev->smu, SMU_OD_SCLK, buf);
855 size += smu_print_clk_levels(&adev->smu, SMU_OD_MCLK, buf+size);
856 size += smu_print_clk_levels(&adev->smu, SMU_OD_VDDC_CURVE, buf+size);
857 size += smu_print_clk_levels(&adev->smu, SMU_OD_RANGE, buf+size);
858 } else if (adev->powerplay.pp_funcs->print_clock_levels) {
859 size = amdgpu_dpm_print_clock_levels(adev, OD_SCLK, buf);
860 size += amdgpu_dpm_print_clock_levels(adev, OD_MCLK, buf+size);
861 size += amdgpu_dpm_print_clock_levels(adev, OD_VDDC_CURVE, buf+size);
862 size += amdgpu_dpm_print_clock_levels(adev, OD_RANGE, buf+size);
864 size = snprintf(buf, PAGE_SIZE, "\n");
866 pm_runtime_mark_last_busy(ddev->dev);
867 pm_runtime_put_autosuspend(ddev->dev);
875 * The amdgpu driver provides a sysfs API for adjusting what powerplay
876 * features to be enabled. The file pp_features is used for this. And
877 * this is only available for Vega10 and later dGPUs.
879 * Reading back the file will show you the followings:
880 * - Current ppfeature masks
881 * - List of the all supported powerplay features with their naming,
882 * bitmasks and enablement status('Y'/'N' means "enabled"/"disabled").
884 * To manually enable or disable a specific feature, just set or clear
885 * the corresponding bit from original ppfeature masks and input the
886 * new ppfeature masks.
888 static ssize_t amdgpu_set_pp_features(struct device *dev,
889 struct device_attribute *attr,
893 struct drm_device *ddev = dev_get_drvdata(dev);
894 struct amdgpu_device *adev = ddev->dev_private;
895 uint64_t featuremask;
898 if (adev->in_gpu_reset)
901 ret = kstrtou64(buf, 0, &featuremask);
905 pr_debug("featuremask = 0x%llx\n", featuremask);
907 ret = pm_runtime_get_sync(ddev->dev);
911 if (is_support_sw_smu(adev)) {
912 ret = smu_sys_set_pp_feature_mask(&adev->smu, featuremask);
914 pm_runtime_mark_last_busy(ddev->dev);
915 pm_runtime_put_autosuspend(ddev->dev);
918 } else if (adev->powerplay.pp_funcs->set_ppfeature_status) {
919 ret = amdgpu_dpm_set_ppfeature_status(adev, featuremask);
921 pm_runtime_mark_last_busy(ddev->dev);
922 pm_runtime_put_autosuspend(ddev->dev);
926 pm_runtime_mark_last_busy(ddev->dev);
927 pm_runtime_put_autosuspend(ddev->dev);
932 static ssize_t amdgpu_get_pp_features(struct device *dev,
933 struct device_attribute *attr,
936 struct drm_device *ddev = dev_get_drvdata(dev);
937 struct amdgpu_device *adev = ddev->dev_private;
941 if (adev->in_gpu_reset)
944 ret = pm_runtime_get_sync(ddev->dev);
948 if (is_support_sw_smu(adev))
949 size = smu_sys_get_pp_feature_mask(&adev->smu, buf);
950 else if (adev->powerplay.pp_funcs->get_ppfeature_status)
951 size = amdgpu_dpm_get_ppfeature_status(adev, buf);
953 size = snprintf(buf, PAGE_SIZE, "\n");
955 pm_runtime_mark_last_busy(ddev->dev);
956 pm_runtime_put_autosuspend(ddev->dev);
962 * DOC: pp_dpm_sclk pp_dpm_mclk pp_dpm_socclk pp_dpm_fclk pp_dpm_dcefclk pp_dpm_pcie
964 * The amdgpu driver provides a sysfs API for adjusting what power levels
965 * are enabled for a given power state. The files pp_dpm_sclk, pp_dpm_mclk,
966 * pp_dpm_socclk, pp_dpm_fclk, pp_dpm_dcefclk and pp_dpm_pcie are used for
969 * pp_dpm_socclk and pp_dpm_dcefclk interfaces are only available for
970 * Vega10 and later ASICs.
971 * pp_dpm_fclk interface is only available for Vega20 and later ASICs.
973 * Reading back the files will show you the available power levels within
974 * the power state and the clock information for those levels.
976 * To manually adjust these states, first select manual using
977 * power_dpm_force_performance_level.
978 * Secondly, enter a new value for each level by inputing a string that
979 * contains " echo xx xx xx > pp_dpm_sclk/mclk/pcie"
982 * .. code-block:: bash
984 * echo "4 5 6" > pp_dpm_sclk
986 * will enable sclk levels 4, 5, and 6.
988 * NOTE: change to the dcefclk max dpm level is not supported now
991 static ssize_t amdgpu_get_pp_dpm_sclk(struct device *dev,
992 struct device_attribute *attr,
995 struct drm_device *ddev = dev_get_drvdata(dev);
996 struct amdgpu_device *adev = ddev->dev_private;
1000 if (adev->in_gpu_reset)
1003 ret = pm_runtime_get_sync(ddev->dev);
1007 if (is_support_sw_smu(adev))
1008 size = smu_print_clk_levels(&adev->smu, SMU_SCLK, buf);
1009 else if (adev->powerplay.pp_funcs->print_clock_levels)
1010 size = amdgpu_dpm_print_clock_levels(adev, PP_SCLK, buf);
1012 size = snprintf(buf, PAGE_SIZE, "\n");
1014 pm_runtime_mark_last_busy(ddev->dev);
1015 pm_runtime_put_autosuspend(ddev->dev);
1021 * Worst case: 32 bits individually specified, in octal at 12 characters
1022 * per line (+1 for \n).
1024 #define AMDGPU_MASK_BUF_MAX (32 * 13)
1026 static ssize_t amdgpu_read_mask(const char *buf, size_t count, uint32_t *mask)
1030 char *sub_str = NULL;
1032 char buf_cpy[AMDGPU_MASK_BUF_MAX + 1];
1033 const char delimiter[3] = {' ', '\n', '\0'};
1038 bytes = min(count, sizeof(buf_cpy) - 1);
1039 memcpy(buf_cpy, buf, bytes);
1040 buf_cpy[bytes] = '\0';
1043 sub_str = strsep(&tmp, delimiter);
1044 if (strlen(sub_str)) {
1045 ret = kstrtol(sub_str, 0, &level);
1048 *mask |= 1 << level;
1056 static ssize_t amdgpu_set_pp_dpm_sclk(struct device *dev,
1057 struct device_attribute *attr,
1061 struct drm_device *ddev = dev_get_drvdata(dev);
1062 struct amdgpu_device *adev = ddev->dev_private;
1066 if (adev->in_gpu_reset)
1069 ret = amdgpu_read_mask(buf, count, &mask);
1073 ret = pm_runtime_get_sync(ddev->dev);
1077 if (is_support_sw_smu(adev))
1078 ret = smu_force_clk_levels(&adev->smu, SMU_SCLK, mask, true);
1079 else if (adev->powerplay.pp_funcs->force_clock_level)
1080 ret = amdgpu_dpm_force_clock_level(adev, PP_SCLK, mask);
1082 pm_runtime_mark_last_busy(ddev->dev);
1083 pm_runtime_put_autosuspend(ddev->dev);
1091 static ssize_t amdgpu_get_pp_dpm_mclk(struct device *dev,
1092 struct device_attribute *attr,
1095 struct drm_device *ddev = dev_get_drvdata(dev);
1096 struct amdgpu_device *adev = ddev->dev_private;
1100 if (adev->in_gpu_reset)
1103 ret = pm_runtime_get_sync(ddev->dev);
1107 if (is_support_sw_smu(adev))
1108 size = smu_print_clk_levels(&adev->smu, SMU_MCLK, buf);
1109 else if (adev->powerplay.pp_funcs->print_clock_levels)
1110 size = amdgpu_dpm_print_clock_levels(adev, PP_MCLK, buf);
1112 size = snprintf(buf, PAGE_SIZE, "\n");
1114 pm_runtime_mark_last_busy(ddev->dev);
1115 pm_runtime_put_autosuspend(ddev->dev);
1120 static ssize_t amdgpu_set_pp_dpm_mclk(struct device *dev,
1121 struct device_attribute *attr,
1125 struct drm_device *ddev = dev_get_drvdata(dev);
1126 struct amdgpu_device *adev = ddev->dev_private;
1130 if (adev->in_gpu_reset)
1133 ret = amdgpu_read_mask(buf, count, &mask);
1137 ret = pm_runtime_get_sync(ddev->dev);
1141 if (is_support_sw_smu(adev))
1142 ret = smu_force_clk_levels(&adev->smu, SMU_MCLK, mask, true);
1143 else if (adev->powerplay.pp_funcs->force_clock_level)
1144 ret = amdgpu_dpm_force_clock_level(adev, PP_MCLK, mask);
1146 pm_runtime_mark_last_busy(ddev->dev);
1147 pm_runtime_put_autosuspend(ddev->dev);
1155 static ssize_t amdgpu_get_pp_dpm_socclk(struct device *dev,
1156 struct device_attribute *attr,
1159 struct drm_device *ddev = dev_get_drvdata(dev);
1160 struct amdgpu_device *adev = ddev->dev_private;
1164 if (adev->in_gpu_reset)
1167 ret = pm_runtime_get_sync(ddev->dev);
1171 if (is_support_sw_smu(adev))
1172 size = smu_print_clk_levels(&adev->smu, SMU_SOCCLK, buf);
1173 else if (adev->powerplay.pp_funcs->print_clock_levels)
1174 size = amdgpu_dpm_print_clock_levels(adev, PP_SOCCLK, buf);
1176 size = snprintf(buf, PAGE_SIZE, "\n");
1178 pm_runtime_mark_last_busy(ddev->dev);
1179 pm_runtime_put_autosuspend(ddev->dev);
1184 static ssize_t amdgpu_set_pp_dpm_socclk(struct device *dev,
1185 struct device_attribute *attr,
1189 struct drm_device *ddev = dev_get_drvdata(dev);
1190 struct amdgpu_device *adev = ddev->dev_private;
1194 if (adev->in_gpu_reset)
1197 ret = amdgpu_read_mask(buf, count, &mask);
1201 ret = pm_runtime_get_sync(ddev->dev);
1205 if (is_support_sw_smu(adev))
1206 ret = smu_force_clk_levels(&adev->smu, SMU_SOCCLK, mask, true);
1207 else if (adev->powerplay.pp_funcs->force_clock_level)
1208 ret = amdgpu_dpm_force_clock_level(adev, PP_SOCCLK, mask);
1212 pm_runtime_mark_last_busy(ddev->dev);
1213 pm_runtime_put_autosuspend(ddev->dev);
1221 static ssize_t amdgpu_get_pp_dpm_fclk(struct device *dev,
1222 struct device_attribute *attr,
1225 struct drm_device *ddev = dev_get_drvdata(dev);
1226 struct amdgpu_device *adev = ddev->dev_private;
1230 if (adev->in_gpu_reset)
1233 ret = pm_runtime_get_sync(ddev->dev);
1237 if (is_support_sw_smu(adev))
1238 size = smu_print_clk_levels(&adev->smu, SMU_FCLK, buf);
1239 else if (adev->powerplay.pp_funcs->print_clock_levels)
1240 size = amdgpu_dpm_print_clock_levels(adev, PP_FCLK, buf);
1242 size = snprintf(buf, PAGE_SIZE, "\n");
1244 pm_runtime_mark_last_busy(ddev->dev);
1245 pm_runtime_put_autosuspend(ddev->dev);
1250 static ssize_t amdgpu_set_pp_dpm_fclk(struct device *dev,
1251 struct device_attribute *attr,
1255 struct drm_device *ddev = dev_get_drvdata(dev);
1256 struct amdgpu_device *adev = ddev->dev_private;
1260 if (adev->in_gpu_reset)
1263 ret = amdgpu_read_mask(buf, count, &mask);
1267 ret = pm_runtime_get_sync(ddev->dev);
1271 if (is_support_sw_smu(adev))
1272 ret = smu_force_clk_levels(&adev->smu, SMU_FCLK, mask, true);
1273 else if (adev->powerplay.pp_funcs->force_clock_level)
1274 ret = amdgpu_dpm_force_clock_level(adev, PP_FCLK, mask);
1278 pm_runtime_mark_last_busy(ddev->dev);
1279 pm_runtime_put_autosuspend(ddev->dev);
1287 static ssize_t amdgpu_get_pp_dpm_dcefclk(struct device *dev,
1288 struct device_attribute *attr,
1291 struct drm_device *ddev = dev_get_drvdata(dev);
1292 struct amdgpu_device *adev = ddev->dev_private;
1296 if (adev->in_gpu_reset)
1299 ret = pm_runtime_get_sync(ddev->dev);
1303 if (is_support_sw_smu(adev))
1304 size = smu_print_clk_levels(&adev->smu, SMU_DCEFCLK, buf);
1305 else if (adev->powerplay.pp_funcs->print_clock_levels)
1306 size = amdgpu_dpm_print_clock_levels(adev, PP_DCEFCLK, buf);
1308 size = snprintf(buf, PAGE_SIZE, "\n");
1310 pm_runtime_mark_last_busy(ddev->dev);
1311 pm_runtime_put_autosuspend(ddev->dev);
1316 static ssize_t amdgpu_set_pp_dpm_dcefclk(struct device *dev,
1317 struct device_attribute *attr,
1321 struct drm_device *ddev = dev_get_drvdata(dev);
1322 struct amdgpu_device *adev = ddev->dev_private;
1326 if (adev->in_gpu_reset)
1329 ret = amdgpu_read_mask(buf, count, &mask);
1333 ret = pm_runtime_get_sync(ddev->dev);
1337 if (is_support_sw_smu(adev))
1338 ret = smu_force_clk_levels(&adev->smu, SMU_DCEFCLK, mask, true);
1339 else if (adev->powerplay.pp_funcs->force_clock_level)
1340 ret = amdgpu_dpm_force_clock_level(adev, PP_DCEFCLK, mask);
1344 pm_runtime_mark_last_busy(ddev->dev);
1345 pm_runtime_put_autosuspend(ddev->dev);
1353 static ssize_t amdgpu_get_pp_dpm_pcie(struct device *dev,
1354 struct device_attribute *attr,
1357 struct drm_device *ddev = dev_get_drvdata(dev);
1358 struct amdgpu_device *adev = ddev->dev_private;
1362 if (adev->in_gpu_reset)
1365 ret = pm_runtime_get_sync(ddev->dev);
1369 if (is_support_sw_smu(adev))
1370 size = smu_print_clk_levels(&adev->smu, SMU_PCIE, buf);
1371 else if (adev->powerplay.pp_funcs->print_clock_levels)
1372 size = amdgpu_dpm_print_clock_levels(adev, PP_PCIE, buf);
1374 size = snprintf(buf, PAGE_SIZE, "\n");
1376 pm_runtime_mark_last_busy(ddev->dev);
1377 pm_runtime_put_autosuspend(ddev->dev);
1382 static ssize_t amdgpu_set_pp_dpm_pcie(struct device *dev,
1383 struct device_attribute *attr,
1387 struct drm_device *ddev = dev_get_drvdata(dev);
1388 struct amdgpu_device *adev = ddev->dev_private;
1392 if (adev->in_gpu_reset)
1395 ret = amdgpu_read_mask(buf, count, &mask);
1399 ret = pm_runtime_get_sync(ddev->dev);
1403 if (is_support_sw_smu(adev))
1404 ret = smu_force_clk_levels(&adev->smu, SMU_PCIE, mask, true);
1405 else if (adev->powerplay.pp_funcs->force_clock_level)
1406 ret = amdgpu_dpm_force_clock_level(adev, PP_PCIE, mask);
1410 pm_runtime_mark_last_busy(ddev->dev);
1411 pm_runtime_put_autosuspend(ddev->dev);
1419 static ssize_t amdgpu_get_pp_sclk_od(struct device *dev,
1420 struct device_attribute *attr,
1423 struct drm_device *ddev = dev_get_drvdata(dev);
1424 struct amdgpu_device *adev = ddev->dev_private;
1428 if (adev->in_gpu_reset)
1431 ret = pm_runtime_get_sync(ddev->dev);
1435 if (is_support_sw_smu(adev))
1436 value = smu_get_od_percentage(&(adev->smu), SMU_OD_SCLK);
1437 else if (adev->powerplay.pp_funcs->get_sclk_od)
1438 value = amdgpu_dpm_get_sclk_od(adev);
1440 pm_runtime_mark_last_busy(ddev->dev);
1441 pm_runtime_put_autosuspend(ddev->dev);
1443 return snprintf(buf, PAGE_SIZE, "%d\n", value);
1446 static ssize_t amdgpu_set_pp_sclk_od(struct device *dev,
1447 struct device_attribute *attr,
1451 struct drm_device *ddev = dev_get_drvdata(dev);
1452 struct amdgpu_device *adev = ddev->dev_private;
1456 if (adev->in_gpu_reset)
1459 ret = kstrtol(buf, 0, &value);
1464 ret = pm_runtime_get_sync(ddev->dev);
1468 if (is_support_sw_smu(adev)) {
1469 value = smu_set_od_percentage(&(adev->smu), SMU_OD_SCLK, (uint32_t)value);
1471 if (adev->powerplay.pp_funcs->set_sclk_od)
1472 amdgpu_dpm_set_sclk_od(adev, (uint32_t)value);
1474 if (adev->powerplay.pp_funcs->dispatch_tasks) {
1475 amdgpu_dpm_dispatch_task(adev, AMD_PP_TASK_READJUST_POWER_STATE, NULL);
1477 adev->pm.dpm.current_ps = adev->pm.dpm.boot_ps;
1478 amdgpu_pm_compute_clocks(adev);
1482 pm_runtime_mark_last_busy(ddev->dev);
1483 pm_runtime_put_autosuspend(ddev->dev);
1488 static ssize_t amdgpu_get_pp_mclk_od(struct device *dev,
1489 struct device_attribute *attr,
1492 struct drm_device *ddev = dev_get_drvdata(dev);
1493 struct amdgpu_device *adev = ddev->dev_private;
1497 if (adev->in_gpu_reset)
1500 ret = pm_runtime_get_sync(ddev->dev);
1504 if (is_support_sw_smu(adev))
1505 value = smu_get_od_percentage(&(adev->smu), SMU_OD_MCLK);
1506 else if (adev->powerplay.pp_funcs->get_mclk_od)
1507 value = amdgpu_dpm_get_mclk_od(adev);
1509 pm_runtime_mark_last_busy(ddev->dev);
1510 pm_runtime_put_autosuspend(ddev->dev);
1512 return snprintf(buf, PAGE_SIZE, "%d\n", value);
1515 static ssize_t amdgpu_set_pp_mclk_od(struct device *dev,
1516 struct device_attribute *attr,
1520 struct drm_device *ddev = dev_get_drvdata(dev);
1521 struct amdgpu_device *adev = ddev->dev_private;
1525 if (adev->in_gpu_reset)
1528 ret = kstrtol(buf, 0, &value);
1533 ret = pm_runtime_get_sync(ddev->dev);
1537 if (is_support_sw_smu(adev)) {
1538 value = smu_set_od_percentage(&(adev->smu), SMU_OD_MCLK, (uint32_t)value);
1540 if (adev->powerplay.pp_funcs->set_mclk_od)
1541 amdgpu_dpm_set_mclk_od(adev, (uint32_t)value);
1543 if (adev->powerplay.pp_funcs->dispatch_tasks) {
1544 amdgpu_dpm_dispatch_task(adev, AMD_PP_TASK_READJUST_POWER_STATE, NULL);
1546 adev->pm.dpm.current_ps = adev->pm.dpm.boot_ps;
1547 amdgpu_pm_compute_clocks(adev);
1551 pm_runtime_mark_last_busy(ddev->dev);
1552 pm_runtime_put_autosuspend(ddev->dev);
1558 * DOC: pp_power_profile_mode
1560 * The amdgpu driver provides a sysfs API for adjusting the heuristics
1561 * related to switching between power levels in a power state. The file
1562 * pp_power_profile_mode is used for this.
1564 * Reading this file outputs a list of all of the predefined power profiles
1565 * and the relevant heuristics settings for that profile.
1567 * To select a profile or create a custom profile, first select manual using
1568 * power_dpm_force_performance_level. Writing the number of a predefined
1569 * profile to pp_power_profile_mode will enable those heuristics. To
1570 * create a custom set of heuristics, write a string of numbers to the file
1571 * starting with the number of the custom profile along with a setting
1572 * for each heuristic parameter. Due to differences across asic families
1573 * the heuristic parameters vary from family to family.
1577 static ssize_t amdgpu_get_pp_power_profile_mode(struct device *dev,
1578 struct device_attribute *attr,
1581 struct drm_device *ddev = dev_get_drvdata(dev);
1582 struct amdgpu_device *adev = ddev->dev_private;
1586 if (adev->in_gpu_reset)
1589 ret = pm_runtime_get_sync(ddev->dev);
1593 if (is_support_sw_smu(adev))
1594 size = smu_get_power_profile_mode(&adev->smu, buf);
1595 else if (adev->powerplay.pp_funcs->get_power_profile_mode)
1596 size = amdgpu_dpm_get_power_profile_mode(adev, buf);
1598 size = snprintf(buf, PAGE_SIZE, "\n");
1600 pm_runtime_mark_last_busy(ddev->dev);
1601 pm_runtime_put_autosuspend(ddev->dev);
1607 static ssize_t amdgpu_set_pp_power_profile_mode(struct device *dev,
1608 struct device_attribute *attr,
1613 struct drm_device *ddev = dev_get_drvdata(dev);
1614 struct amdgpu_device *adev = ddev->dev_private;
1615 uint32_t parameter_size = 0;
1617 char *sub_str, buf_cpy[128];
1621 long int profile_mode = 0;
1622 const char delimiter[3] = {' ', '\n', '\0'};
1624 if (adev->in_gpu_reset)
1629 ret = kstrtol(tmp, 0, &profile_mode);
1633 if (profile_mode == PP_SMC_POWER_PROFILE_CUSTOM) {
1634 if (count < 2 || count > 127)
1636 while (isspace(*++buf))
1638 memcpy(buf_cpy, buf, count-i);
1640 while (tmp_str[0]) {
1641 sub_str = strsep(&tmp_str, delimiter);
1642 ret = kstrtol(sub_str, 0, ¶meter[parameter_size]);
1646 while (isspace(*tmp_str))
1650 parameter[parameter_size] = profile_mode;
1652 ret = pm_runtime_get_sync(ddev->dev);
1656 if (is_support_sw_smu(adev))
1657 ret = smu_set_power_profile_mode(&adev->smu, parameter, parameter_size, true);
1658 else if (adev->powerplay.pp_funcs->set_power_profile_mode)
1659 ret = amdgpu_dpm_set_power_profile_mode(adev, parameter, parameter_size);
1661 pm_runtime_mark_last_busy(ddev->dev);
1662 pm_runtime_put_autosuspend(ddev->dev);
1673 * The amdgpu driver provides a sysfs API for reading how busy the GPU
1674 * is as a percentage. The file gpu_busy_percent is used for this.
1675 * The SMU firmware computes a percentage of load based on the
1676 * aggregate activity level in the IP cores.
1678 static ssize_t amdgpu_get_gpu_busy_percent(struct device *dev,
1679 struct device_attribute *attr,
1682 struct drm_device *ddev = dev_get_drvdata(dev);
1683 struct amdgpu_device *adev = ddev->dev_private;
1684 int r, value, size = sizeof(value);
1686 if (adev->in_gpu_reset)
1689 r = pm_runtime_get_sync(ddev->dev);
1693 /* read the IP busy sensor */
1694 r = amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GPU_LOAD,
1695 (void *)&value, &size);
1697 pm_runtime_mark_last_busy(ddev->dev);
1698 pm_runtime_put_autosuspend(ddev->dev);
1703 return snprintf(buf, PAGE_SIZE, "%d\n", value);
1707 * DOC: mem_busy_percent
1709 * The amdgpu driver provides a sysfs API for reading how busy the VRAM
1710 * is as a percentage. The file mem_busy_percent is used for this.
1711 * The SMU firmware computes a percentage of load based on the
1712 * aggregate activity level in the IP cores.
1714 static ssize_t amdgpu_get_mem_busy_percent(struct device *dev,
1715 struct device_attribute *attr,
1718 struct drm_device *ddev = dev_get_drvdata(dev);
1719 struct amdgpu_device *adev = ddev->dev_private;
1720 int r, value, size = sizeof(value);
1722 if (adev->in_gpu_reset)
1725 r = pm_runtime_get_sync(ddev->dev);
1729 /* read the IP busy sensor */
1730 r = amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_MEM_LOAD,
1731 (void *)&value, &size);
1733 pm_runtime_mark_last_busy(ddev->dev);
1734 pm_runtime_put_autosuspend(ddev->dev);
1739 return snprintf(buf, PAGE_SIZE, "%d\n", value);
1745 * The amdgpu driver provides a sysfs API for estimating how much data
1746 * has been received and sent by the GPU in the last second through PCIe.
1747 * The file pcie_bw is used for this.
1748 * The Perf counters count the number of received and sent messages and return
1749 * those values, as well as the maximum payload size of a PCIe packet (mps).
1750 * Note that it is not possible to easily and quickly obtain the size of each
1751 * packet transmitted, so we output the max payload size (mps) to allow for
1752 * quick estimation of the PCIe bandwidth usage
1754 static ssize_t amdgpu_get_pcie_bw(struct device *dev,
1755 struct device_attribute *attr,
1758 struct drm_device *ddev = dev_get_drvdata(dev);
1759 struct amdgpu_device *adev = ddev->dev_private;
1760 uint64_t count0 = 0, count1 = 0;
1763 if (adev->in_gpu_reset)
1766 if (adev->flags & AMD_IS_APU)
1769 if (!adev->asic_funcs->get_pcie_usage)
1772 ret = pm_runtime_get_sync(ddev->dev);
1776 amdgpu_asic_get_pcie_usage(adev, &count0, &count1);
1778 pm_runtime_mark_last_busy(ddev->dev);
1779 pm_runtime_put_autosuspend(ddev->dev);
1781 return snprintf(buf, PAGE_SIZE, "%llu %llu %i\n",
1782 count0, count1, pcie_get_mps(adev->pdev));
1788 * The amdgpu driver provides a sysfs API for providing a unique ID for the GPU
1789 * The file unique_id is used for this.
1790 * This will provide a Unique ID that will persist from machine to machine
1792 * NOTE: This will only work for GFX9 and newer. This file will be absent
1793 * on unsupported ASICs (GFX8 and older)
1795 static ssize_t amdgpu_get_unique_id(struct device *dev,
1796 struct device_attribute *attr,
1799 struct drm_device *ddev = dev_get_drvdata(dev);
1800 struct amdgpu_device *adev = ddev->dev_private;
1802 if (adev->in_gpu_reset)
1805 if (adev->unique_id)
1806 return snprintf(buf, PAGE_SIZE, "%016llx\n", adev->unique_id);
1811 static struct amdgpu_device_attr amdgpu_device_attrs[] = {
1812 AMDGPU_DEVICE_ATTR_RW(power_dpm_state, ATTR_FLAG_BASIC|ATTR_FLAG_ONEVF),
1813 AMDGPU_DEVICE_ATTR_RW(power_dpm_force_performance_level, ATTR_FLAG_BASIC|ATTR_FLAG_ONEVF),
1814 AMDGPU_DEVICE_ATTR_RO(pp_num_states, ATTR_FLAG_BASIC),
1815 AMDGPU_DEVICE_ATTR_RO(pp_cur_state, ATTR_FLAG_BASIC),
1816 AMDGPU_DEVICE_ATTR_RW(pp_force_state, ATTR_FLAG_BASIC),
1817 AMDGPU_DEVICE_ATTR_RW(pp_table, ATTR_FLAG_BASIC),
1818 AMDGPU_DEVICE_ATTR_RW(pp_dpm_sclk, ATTR_FLAG_BASIC|ATTR_FLAG_ONEVF),
1819 AMDGPU_DEVICE_ATTR_RW(pp_dpm_mclk, ATTR_FLAG_BASIC|ATTR_FLAG_ONEVF),
1820 AMDGPU_DEVICE_ATTR_RW(pp_dpm_socclk, ATTR_FLAG_BASIC|ATTR_FLAG_ONEVF),
1821 AMDGPU_DEVICE_ATTR_RW(pp_dpm_fclk, ATTR_FLAG_BASIC|ATTR_FLAG_ONEVF),
1822 AMDGPU_DEVICE_ATTR_RW(pp_dpm_dcefclk, ATTR_FLAG_BASIC),
1823 AMDGPU_DEVICE_ATTR_RW(pp_dpm_pcie, ATTR_FLAG_BASIC),
1824 AMDGPU_DEVICE_ATTR_RW(pp_sclk_od, ATTR_FLAG_BASIC),
1825 AMDGPU_DEVICE_ATTR_RW(pp_mclk_od, ATTR_FLAG_BASIC),
1826 AMDGPU_DEVICE_ATTR_RW(pp_power_profile_mode, ATTR_FLAG_BASIC),
1827 AMDGPU_DEVICE_ATTR_RW(pp_od_clk_voltage, ATTR_FLAG_BASIC),
1828 AMDGPU_DEVICE_ATTR_RO(gpu_busy_percent, ATTR_FLAG_BASIC),
1829 AMDGPU_DEVICE_ATTR_RO(mem_busy_percent, ATTR_FLAG_BASIC),
1830 AMDGPU_DEVICE_ATTR_RO(pcie_bw, ATTR_FLAG_BASIC),
1831 AMDGPU_DEVICE_ATTR_RW(pp_features, ATTR_FLAG_BASIC),
1832 AMDGPU_DEVICE_ATTR_RO(unique_id, ATTR_FLAG_BASIC),
1835 static int default_attr_update(struct amdgpu_device *adev, struct amdgpu_device_attr *attr,
1836 uint32_t mask, enum amdgpu_device_attr_states *states)
1838 struct device_attribute *dev_attr = &attr->dev_attr;
1839 const char *attr_name = dev_attr->attr.name;
1840 struct pp_hwmgr *hwmgr = adev->powerplay.pp_handle;
1841 enum amd_asic_type asic_type = adev->asic_type;
1843 if (!(attr->flags & mask)) {
1844 *states = ATTR_STATE_UNSUPPORTED;
1848 #define DEVICE_ATTR_IS(_name) (!strcmp(attr_name, #_name))
1850 if (DEVICE_ATTR_IS(pp_dpm_socclk)) {
1851 if (asic_type < CHIP_VEGA10)
1852 *states = ATTR_STATE_UNSUPPORTED;
1853 } else if (DEVICE_ATTR_IS(pp_dpm_dcefclk)) {
1854 if (asic_type < CHIP_VEGA10 || asic_type == CHIP_ARCTURUS)
1855 *states = ATTR_STATE_UNSUPPORTED;
1856 } else if (DEVICE_ATTR_IS(pp_dpm_fclk)) {
1857 if (asic_type < CHIP_VEGA20)
1858 *states = ATTR_STATE_UNSUPPORTED;
1859 } else if (DEVICE_ATTR_IS(pp_dpm_pcie)) {
1860 if (asic_type == CHIP_ARCTURUS)
1861 *states = ATTR_STATE_UNSUPPORTED;
1862 } else if (DEVICE_ATTR_IS(pp_od_clk_voltage)) {
1863 *states = ATTR_STATE_UNSUPPORTED;
1864 if ((is_support_sw_smu(adev) && adev->smu.od_enabled) ||
1865 (!is_support_sw_smu(adev) && hwmgr->od_enabled))
1866 *states = ATTR_STATE_SUPPORTED;
1867 } else if (DEVICE_ATTR_IS(mem_busy_percent)) {
1868 if (adev->flags & AMD_IS_APU || asic_type == CHIP_VEGA10)
1869 *states = ATTR_STATE_UNSUPPORTED;
1870 } else if (DEVICE_ATTR_IS(pcie_bw)) {
1871 /* PCIe Perf counters won't work on APU nodes */
1872 if (adev->flags & AMD_IS_APU)
1873 *states = ATTR_STATE_UNSUPPORTED;
1874 } else if (DEVICE_ATTR_IS(unique_id)) {
1875 if (!adev->unique_id)
1876 *states = ATTR_STATE_UNSUPPORTED;
1877 } else if (DEVICE_ATTR_IS(pp_features)) {
1878 if (adev->flags & AMD_IS_APU || asic_type < CHIP_VEGA10)
1879 *states = ATTR_STATE_UNSUPPORTED;
1882 if (asic_type == CHIP_ARCTURUS) {
1883 /* Arcturus does not support standalone mclk/socclk/fclk level setting */
1884 if (DEVICE_ATTR_IS(pp_dpm_mclk) ||
1885 DEVICE_ATTR_IS(pp_dpm_socclk) ||
1886 DEVICE_ATTR_IS(pp_dpm_fclk)) {
1887 dev_attr->attr.mode &= ~S_IWUGO;
1888 dev_attr->store = NULL;
1892 #undef DEVICE_ATTR_IS
1898 static int amdgpu_device_attr_create(struct amdgpu_device *adev,
1899 struct amdgpu_device_attr *attr,
1900 uint32_t mask, struct list_head *attr_list)
1903 struct device_attribute *dev_attr = &attr->dev_attr;
1904 const char *name = dev_attr->attr.name;
1905 enum amdgpu_device_attr_states attr_states = ATTR_STATE_SUPPORTED;
1906 struct amdgpu_device_attr_entry *attr_entry;
1908 int (*attr_update)(struct amdgpu_device *adev, struct amdgpu_device_attr *attr,
1909 uint32_t mask, enum amdgpu_device_attr_states *states) = default_attr_update;
1913 attr_update = attr->attr_update ? attr_update : default_attr_update;
1915 ret = attr_update(adev, attr, mask, &attr_states);
1917 dev_err(adev->dev, "failed to update device file %s, ret = %d\n",
1922 if (attr_states == ATTR_STATE_UNSUPPORTED)
1925 ret = device_create_file(adev->dev, dev_attr);
1927 dev_err(adev->dev, "failed to create device file %s, ret = %d\n",
1931 attr_entry = kmalloc(sizeof(*attr_entry), GFP_KERNEL);
1935 attr_entry->attr = attr;
1936 INIT_LIST_HEAD(&attr_entry->entry);
1938 list_add_tail(&attr_entry->entry, attr_list);
1943 static void amdgpu_device_attr_remove(struct amdgpu_device *adev, struct amdgpu_device_attr *attr)
1945 struct device_attribute *dev_attr = &attr->dev_attr;
1947 device_remove_file(adev->dev, dev_attr);
1950 static void amdgpu_device_attr_remove_groups(struct amdgpu_device *adev,
1951 struct list_head *attr_list);
1953 static int amdgpu_device_attr_create_groups(struct amdgpu_device *adev,
1954 struct amdgpu_device_attr *attrs,
1957 struct list_head *attr_list)
1962 for (i = 0; i < counts; i++) {
1963 ret = amdgpu_device_attr_create(adev, &attrs[i], mask, attr_list);
1971 amdgpu_device_attr_remove_groups(adev, attr_list);
1976 static void amdgpu_device_attr_remove_groups(struct amdgpu_device *adev,
1977 struct list_head *attr_list)
1979 struct amdgpu_device_attr_entry *entry, *entry_tmp;
1981 if (list_empty(attr_list))
1984 list_for_each_entry_safe(entry, entry_tmp, attr_list, entry) {
1985 amdgpu_device_attr_remove(adev, entry->attr);
1986 list_del(&entry->entry);
1991 static ssize_t amdgpu_hwmon_show_temp(struct device *dev,
1992 struct device_attribute *attr,
1995 struct amdgpu_device *adev = dev_get_drvdata(dev);
1996 int channel = to_sensor_dev_attr(attr)->index;
1997 int r, temp = 0, size = sizeof(temp);
1999 if (adev->in_gpu_reset)
2002 if (channel >= PP_TEMP_MAX)
2005 r = pm_runtime_get_sync(adev->ddev->dev);
2010 case PP_TEMP_JUNCTION:
2011 /* get current junction temperature */
2012 r = amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_HOTSPOT_TEMP,
2013 (void *)&temp, &size);
2016 /* get current edge temperature */
2017 r = amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_EDGE_TEMP,
2018 (void *)&temp, &size);
2021 /* get current memory temperature */
2022 r = amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_MEM_TEMP,
2023 (void *)&temp, &size);
2030 pm_runtime_mark_last_busy(adev->ddev->dev);
2031 pm_runtime_put_autosuspend(adev->ddev->dev);
2036 return snprintf(buf, PAGE_SIZE, "%d\n", temp);
2039 static ssize_t amdgpu_hwmon_show_temp_thresh(struct device *dev,
2040 struct device_attribute *attr,
2043 struct amdgpu_device *adev = dev_get_drvdata(dev);
2044 int hyst = to_sensor_dev_attr(attr)->index;
2048 temp = adev->pm.dpm.thermal.min_temp;
2050 temp = adev->pm.dpm.thermal.max_temp;
2052 return snprintf(buf, PAGE_SIZE, "%d\n", temp);
2055 static ssize_t amdgpu_hwmon_show_hotspot_temp_thresh(struct device *dev,
2056 struct device_attribute *attr,
2059 struct amdgpu_device *adev = dev_get_drvdata(dev);
2060 int hyst = to_sensor_dev_attr(attr)->index;
2064 temp = adev->pm.dpm.thermal.min_hotspot_temp;
2066 temp = adev->pm.dpm.thermal.max_hotspot_crit_temp;
2068 return snprintf(buf, PAGE_SIZE, "%d\n", temp);
2071 static ssize_t amdgpu_hwmon_show_mem_temp_thresh(struct device *dev,
2072 struct device_attribute *attr,
2075 struct amdgpu_device *adev = dev_get_drvdata(dev);
2076 int hyst = to_sensor_dev_attr(attr)->index;
2080 temp = adev->pm.dpm.thermal.min_mem_temp;
2082 temp = adev->pm.dpm.thermal.max_mem_crit_temp;
2084 return snprintf(buf, PAGE_SIZE, "%d\n", temp);
2087 static ssize_t amdgpu_hwmon_show_temp_label(struct device *dev,
2088 struct device_attribute *attr,
2091 int channel = to_sensor_dev_attr(attr)->index;
2093 if (channel >= PP_TEMP_MAX)
2096 return snprintf(buf, PAGE_SIZE, "%s\n", temp_label[channel].label);
2099 static ssize_t amdgpu_hwmon_show_temp_emergency(struct device *dev,
2100 struct device_attribute *attr,
2103 struct amdgpu_device *adev = dev_get_drvdata(dev);
2104 int channel = to_sensor_dev_attr(attr)->index;
2107 if (channel >= PP_TEMP_MAX)
2111 case PP_TEMP_JUNCTION:
2112 temp = adev->pm.dpm.thermal.max_hotspot_emergency_temp;
2115 temp = adev->pm.dpm.thermal.max_edge_emergency_temp;
2118 temp = adev->pm.dpm.thermal.max_mem_emergency_temp;
2122 return snprintf(buf, PAGE_SIZE, "%d\n", temp);
2125 static ssize_t amdgpu_hwmon_get_pwm1_enable(struct device *dev,
2126 struct device_attribute *attr,
2129 struct amdgpu_device *adev = dev_get_drvdata(dev);
2133 if (adev->in_gpu_reset)
2136 ret = pm_runtime_get_sync(adev->ddev->dev);
2140 if (is_support_sw_smu(adev)) {
2141 pwm_mode = smu_get_fan_control_mode(&adev->smu);
2143 if (!adev->powerplay.pp_funcs->get_fan_control_mode) {
2144 pm_runtime_mark_last_busy(adev->ddev->dev);
2145 pm_runtime_put_autosuspend(adev->ddev->dev);
2149 pwm_mode = amdgpu_dpm_get_fan_control_mode(adev);
2152 pm_runtime_mark_last_busy(adev->ddev->dev);
2153 pm_runtime_put_autosuspend(adev->ddev->dev);
2155 return sprintf(buf, "%i\n", pwm_mode);
2158 static ssize_t amdgpu_hwmon_set_pwm1_enable(struct device *dev,
2159 struct device_attribute *attr,
2163 struct amdgpu_device *adev = dev_get_drvdata(dev);
2167 if (adev->in_gpu_reset)
2170 err = kstrtoint(buf, 10, &value);
2174 ret = pm_runtime_get_sync(adev->ddev->dev);
2178 if (is_support_sw_smu(adev)) {
2179 smu_set_fan_control_mode(&adev->smu, value);
2181 if (!adev->powerplay.pp_funcs->set_fan_control_mode) {
2182 pm_runtime_mark_last_busy(adev->ddev->dev);
2183 pm_runtime_put_autosuspend(adev->ddev->dev);
2187 amdgpu_dpm_set_fan_control_mode(adev, value);
2190 pm_runtime_mark_last_busy(adev->ddev->dev);
2191 pm_runtime_put_autosuspend(adev->ddev->dev);
2196 static ssize_t amdgpu_hwmon_get_pwm1_min(struct device *dev,
2197 struct device_attribute *attr,
2200 return sprintf(buf, "%i\n", 0);
2203 static ssize_t amdgpu_hwmon_get_pwm1_max(struct device *dev,
2204 struct device_attribute *attr,
2207 return sprintf(buf, "%i\n", 255);
2210 static ssize_t amdgpu_hwmon_set_pwm1(struct device *dev,
2211 struct device_attribute *attr,
2212 const char *buf, size_t count)
2214 struct amdgpu_device *adev = dev_get_drvdata(dev);
2219 if (adev->in_gpu_reset)
2222 err = pm_runtime_get_sync(adev->ddev->dev);
2226 if (is_support_sw_smu(adev))
2227 pwm_mode = smu_get_fan_control_mode(&adev->smu);
2229 pwm_mode = amdgpu_dpm_get_fan_control_mode(adev);
2231 if (pwm_mode != AMD_FAN_CTRL_MANUAL) {
2232 pr_info("manual fan speed control should be enabled first\n");
2233 pm_runtime_mark_last_busy(adev->ddev->dev);
2234 pm_runtime_put_autosuspend(adev->ddev->dev);
2238 err = kstrtou32(buf, 10, &value);
2240 pm_runtime_mark_last_busy(adev->ddev->dev);
2241 pm_runtime_put_autosuspend(adev->ddev->dev);
2245 value = (value * 100) / 255;
2247 if (is_support_sw_smu(adev))
2248 err = smu_set_fan_speed_percent(&adev->smu, value);
2249 else if (adev->powerplay.pp_funcs->set_fan_speed_percent)
2250 err = amdgpu_dpm_set_fan_speed_percent(adev, value);
2254 pm_runtime_mark_last_busy(adev->ddev->dev);
2255 pm_runtime_put_autosuspend(adev->ddev->dev);
2263 static ssize_t amdgpu_hwmon_get_pwm1(struct device *dev,
2264 struct device_attribute *attr,
2267 struct amdgpu_device *adev = dev_get_drvdata(dev);
2271 if (adev->in_gpu_reset)
2274 err = pm_runtime_get_sync(adev->ddev->dev);
2278 if (is_support_sw_smu(adev))
2279 err = smu_get_fan_speed_percent(&adev->smu, &speed);
2280 else if (adev->powerplay.pp_funcs->get_fan_speed_percent)
2281 err = amdgpu_dpm_get_fan_speed_percent(adev, &speed);
2285 pm_runtime_mark_last_busy(adev->ddev->dev);
2286 pm_runtime_put_autosuspend(adev->ddev->dev);
2291 speed = (speed * 255) / 100;
2293 return sprintf(buf, "%i\n", speed);
2296 static ssize_t amdgpu_hwmon_get_fan1_input(struct device *dev,
2297 struct device_attribute *attr,
2300 struct amdgpu_device *adev = dev_get_drvdata(dev);
2304 if (adev->in_gpu_reset)
2307 err = pm_runtime_get_sync(adev->ddev->dev);
2311 if (is_support_sw_smu(adev))
2312 err = smu_get_fan_speed_rpm(&adev->smu, &speed);
2313 else if (adev->powerplay.pp_funcs->get_fan_speed_rpm)
2314 err = amdgpu_dpm_get_fan_speed_rpm(adev, &speed);
2318 pm_runtime_mark_last_busy(adev->ddev->dev);
2319 pm_runtime_put_autosuspend(adev->ddev->dev);
2324 return sprintf(buf, "%i\n", speed);
2327 static ssize_t amdgpu_hwmon_get_fan1_min(struct device *dev,
2328 struct device_attribute *attr,
2331 struct amdgpu_device *adev = dev_get_drvdata(dev);
2333 u32 size = sizeof(min_rpm);
2336 if (adev->in_gpu_reset)
2339 r = pm_runtime_get_sync(adev->ddev->dev);
2343 r = amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_MIN_FAN_RPM,
2344 (void *)&min_rpm, &size);
2346 pm_runtime_mark_last_busy(adev->ddev->dev);
2347 pm_runtime_put_autosuspend(adev->ddev->dev);
2352 return snprintf(buf, PAGE_SIZE, "%d\n", min_rpm);
2355 static ssize_t amdgpu_hwmon_get_fan1_max(struct device *dev,
2356 struct device_attribute *attr,
2359 struct amdgpu_device *adev = dev_get_drvdata(dev);
2361 u32 size = sizeof(max_rpm);
2364 if (adev->in_gpu_reset)
2367 r = pm_runtime_get_sync(adev->ddev->dev);
2371 r = amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_MAX_FAN_RPM,
2372 (void *)&max_rpm, &size);
2374 pm_runtime_mark_last_busy(adev->ddev->dev);
2375 pm_runtime_put_autosuspend(adev->ddev->dev);
2380 return snprintf(buf, PAGE_SIZE, "%d\n", max_rpm);
2383 static ssize_t amdgpu_hwmon_get_fan1_target(struct device *dev,
2384 struct device_attribute *attr,
2387 struct amdgpu_device *adev = dev_get_drvdata(dev);
2391 if (adev->in_gpu_reset)
2394 err = pm_runtime_get_sync(adev->ddev->dev);
2398 if (is_support_sw_smu(adev))
2399 err = smu_get_fan_speed_rpm(&adev->smu, &rpm);
2400 else if (adev->powerplay.pp_funcs->get_fan_speed_rpm)
2401 err = amdgpu_dpm_get_fan_speed_rpm(adev, &rpm);
2405 pm_runtime_mark_last_busy(adev->ddev->dev);
2406 pm_runtime_put_autosuspend(adev->ddev->dev);
2411 return sprintf(buf, "%i\n", rpm);
2414 static ssize_t amdgpu_hwmon_set_fan1_target(struct device *dev,
2415 struct device_attribute *attr,
2416 const char *buf, size_t count)
2418 struct amdgpu_device *adev = dev_get_drvdata(dev);
2423 if (adev->in_gpu_reset)
2426 err = pm_runtime_get_sync(adev->ddev->dev);
2430 if (is_support_sw_smu(adev))
2431 pwm_mode = smu_get_fan_control_mode(&adev->smu);
2433 pwm_mode = amdgpu_dpm_get_fan_control_mode(adev);
2435 if (pwm_mode != AMD_FAN_CTRL_MANUAL) {
2436 pm_runtime_mark_last_busy(adev->ddev->dev);
2437 pm_runtime_put_autosuspend(adev->ddev->dev);
2441 err = kstrtou32(buf, 10, &value);
2443 pm_runtime_mark_last_busy(adev->ddev->dev);
2444 pm_runtime_put_autosuspend(adev->ddev->dev);
2448 if (is_support_sw_smu(adev))
2449 err = smu_set_fan_speed_rpm(&adev->smu, value);
2450 else if (adev->powerplay.pp_funcs->set_fan_speed_rpm)
2451 err = amdgpu_dpm_set_fan_speed_rpm(adev, value);
2455 pm_runtime_mark_last_busy(adev->ddev->dev);
2456 pm_runtime_put_autosuspend(adev->ddev->dev);
2464 static ssize_t amdgpu_hwmon_get_fan1_enable(struct device *dev,
2465 struct device_attribute *attr,
2468 struct amdgpu_device *adev = dev_get_drvdata(dev);
2472 if (adev->in_gpu_reset)
2475 ret = pm_runtime_get_sync(adev->ddev->dev);
2479 if (is_support_sw_smu(adev)) {
2480 pwm_mode = smu_get_fan_control_mode(&adev->smu);
2482 if (!adev->powerplay.pp_funcs->get_fan_control_mode) {
2483 pm_runtime_mark_last_busy(adev->ddev->dev);
2484 pm_runtime_put_autosuspend(adev->ddev->dev);
2488 pwm_mode = amdgpu_dpm_get_fan_control_mode(adev);
2491 pm_runtime_mark_last_busy(adev->ddev->dev);
2492 pm_runtime_put_autosuspend(adev->ddev->dev);
2494 return sprintf(buf, "%i\n", pwm_mode == AMD_FAN_CTRL_AUTO ? 0 : 1);
2497 static ssize_t amdgpu_hwmon_set_fan1_enable(struct device *dev,
2498 struct device_attribute *attr,
2502 struct amdgpu_device *adev = dev_get_drvdata(dev);
2507 if (adev->in_gpu_reset)
2510 err = kstrtoint(buf, 10, &value);
2515 pwm_mode = AMD_FAN_CTRL_AUTO;
2516 else if (value == 1)
2517 pwm_mode = AMD_FAN_CTRL_MANUAL;
2521 err = pm_runtime_get_sync(adev->ddev->dev);
2525 if (is_support_sw_smu(adev)) {
2526 smu_set_fan_control_mode(&adev->smu, pwm_mode);
2528 if (!adev->powerplay.pp_funcs->set_fan_control_mode) {
2529 pm_runtime_mark_last_busy(adev->ddev->dev);
2530 pm_runtime_put_autosuspend(adev->ddev->dev);
2533 amdgpu_dpm_set_fan_control_mode(adev, pwm_mode);
2536 pm_runtime_mark_last_busy(adev->ddev->dev);
2537 pm_runtime_put_autosuspend(adev->ddev->dev);
2542 static ssize_t amdgpu_hwmon_show_vddgfx(struct device *dev,
2543 struct device_attribute *attr,
2546 struct amdgpu_device *adev = dev_get_drvdata(dev);
2548 int r, size = sizeof(vddgfx);
2550 if (adev->in_gpu_reset)
2553 r = pm_runtime_get_sync(adev->ddev->dev);
2557 /* get the voltage */
2558 r = amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_VDDGFX,
2559 (void *)&vddgfx, &size);
2561 pm_runtime_mark_last_busy(adev->ddev->dev);
2562 pm_runtime_put_autosuspend(adev->ddev->dev);
2567 return snprintf(buf, PAGE_SIZE, "%d\n", vddgfx);
2570 static ssize_t amdgpu_hwmon_show_vddgfx_label(struct device *dev,
2571 struct device_attribute *attr,
2574 return snprintf(buf, PAGE_SIZE, "vddgfx\n");
2577 static ssize_t amdgpu_hwmon_show_vddnb(struct device *dev,
2578 struct device_attribute *attr,
2581 struct amdgpu_device *adev = dev_get_drvdata(dev);
2583 int r, size = sizeof(vddnb);
2585 if (adev->in_gpu_reset)
2588 /* only APUs have vddnb */
2589 if (!(adev->flags & AMD_IS_APU))
2592 r = pm_runtime_get_sync(adev->ddev->dev);
2596 /* get the voltage */
2597 r = amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_VDDNB,
2598 (void *)&vddnb, &size);
2600 pm_runtime_mark_last_busy(adev->ddev->dev);
2601 pm_runtime_put_autosuspend(adev->ddev->dev);
2606 return snprintf(buf, PAGE_SIZE, "%d\n", vddnb);
2609 static ssize_t amdgpu_hwmon_show_vddnb_label(struct device *dev,
2610 struct device_attribute *attr,
2613 return snprintf(buf, PAGE_SIZE, "vddnb\n");
2616 static ssize_t amdgpu_hwmon_show_power_avg(struct device *dev,
2617 struct device_attribute *attr,
2620 struct amdgpu_device *adev = dev_get_drvdata(dev);
2622 int r, size = sizeof(u32);
2625 if (adev->in_gpu_reset)
2628 r = pm_runtime_get_sync(adev->ddev->dev);
2632 /* get the voltage */
2633 r = amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GPU_POWER,
2634 (void *)&query, &size);
2636 pm_runtime_mark_last_busy(adev->ddev->dev);
2637 pm_runtime_put_autosuspend(adev->ddev->dev);
2642 /* convert to microwatts */
2643 uw = (query >> 8) * 1000000 + (query & 0xff) * 1000;
2645 return snprintf(buf, PAGE_SIZE, "%u\n", uw);
2648 static ssize_t amdgpu_hwmon_show_power_cap_min(struct device *dev,
2649 struct device_attribute *attr,
2652 return sprintf(buf, "%i\n", 0);
2655 static ssize_t amdgpu_hwmon_show_power_cap_max(struct device *dev,
2656 struct device_attribute *attr,
2659 struct amdgpu_device *adev = dev_get_drvdata(dev);
2664 if (adev->in_gpu_reset)
2667 r = pm_runtime_get_sync(adev->ddev->dev);
2671 if (is_support_sw_smu(adev)) {
2672 smu_get_power_limit(&adev->smu, &limit, true, true);
2673 size = snprintf(buf, PAGE_SIZE, "%u\n", limit * 1000000);
2674 } else if (adev->powerplay.pp_funcs && adev->powerplay.pp_funcs->get_power_limit) {
2675 adev->powerplay.pp_funcs->get_power_limit(adev->powerplay.pp_handle, &limit, true);
2676 size = snprintf(buf, PAGE_SIZE, "%u\n", limit * 1000000);
2678 size = snprintf(buf, PAGE_SIZE, "\n");
2681 pm_runtime_mark_last_busy(adev->ddev->dev);
2682 pm_runtime_put_autosuspend(adev->ddev->dev);
2687 static ssize_t amdgpu_hwmon_show_power_cap(struct device *dev,
2688 struct device_attribute *attr,
2691 struct amdgpu_device *adev = dev_get_drvdata(dev);
2696 if (adev->in_gpu_reset)
2699 r = pm_runtime_get_sync(adev->ddev->dev);
2703 if (is_support_sw_smu(adev)) {
2704 smu_get_power_limit(&adev->smu, &limit, false, true);
2705 size = snprintf(buf, PAGE_SIZE, "%u\n", limit * 1000000);
2706 } else if (adev->powerplay.pp_funcs && adev->powerplay.pp_funcs->get_power_limit) {
2707 adev->powerplay.pp_funcs->get_power_limit(adev->powerplay.pp_handle, &limit, false);
2708 size = snprintf(buf, PAGE_SIZE, "%u\n", limit * 1000000);
2710 size = snprintf(buf, PAGE_SIZE, "\n");
2713 pm_runtime_mark_last_busy(adev->ddev->dev);
2714 pm_runtime_put_autosuspend(adev->ddev->dev);
2720 static ssize_t amdgpu_hwmon_set_power_cap(struct device *dev,
2721 struct device_attribute *attr,
2725 struct amdgpu_device *adev = dev_get_drvdata(dev);
2729 if (adev->in_gpu_reset)
2732 if (amdgpu_sriov_vf(adev))
2735 err = kstrtou32(buf, 10, &value);
2739 value = value / 1000000; /* convert to Watt */
2742 err = pm_runtime_get_sync(adev->ddev->dev);
2746 if (is_support_sw_smu(adev))
2747 err = smu_set_power_limit(&adev->smu, value);
2748 else if (adev->powerplay.pp_funcs && adev->powerplay.pp_funcs->set_power_limit)
2749 err = adev->powerplay.pp_funcs->set_power_limit(adev->powerplay.pp_handle, value);
2753 pm_runtime_mark_last_busy(adev->ddev->dev);
2754 pm_runtime_put_autosuspend(adev->ddev->dev);
2762 static ssize_t amdgpu_hwmon_show_sclk(struct device *dev,
2763 struct device_attribute *attr,
2766 struct amdgpu_device *adev = dev_get_drvdata(dev);
2768 int r, size = sizeof(sclk);
2770 if (adev->in_gpu_reset)
2773 r = pm_runtime_get_sync(adev->ddev->dev);
2778 r = amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GFX_SCLK,
2779 (void *)&sclk, &size);
2781 pm_runtime_mark_last_busy(adev->ddev->dev);
2782 pm_runtime_put_autosuspend(adev->ddev->dev);
2787 return snprintf(buf, PAGE_SIZE, "%d\n", sclk * 10 * 1000);
2790 static ssize_t amdgpu_hwmon_show_sclk_label(struct device *dev,
2791 struct device_attribute *attr,
2794 return snprintf(buf, PAGE_SIZE, "sclk\n");
2797 static ssize_t amdgpu_hwmon_show_mclk(struct device *dev,
2798 struct device_attribute *attr,
2801 struct amdgpu_device *adev = dev_get_drvdata(dev);
2803 int r, size = sizeof(mclk);
2805 if (adev->in_gpu_reset)
2808 r = pm_runtime_get_sync(adev->ddev->dev);
2813 r = amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GFX_MCLK,
2814 (void *)&mclk, &size);
2816 pm_runtime_mark_last_busy(adev->ddev->dev);
2817 pm_runtime_put_autosuspend(adev->ddev->dev);
2822 return snprintf(buf, PAGE_SIZE, "%d\n", mclk * 10 * 1000);
2825 static ssize_t amdgpu_hwmon_show_mclk_label(struct device *dev,
2826 struct device_attribute *attr,
2829 return snprintf(buf, PAGE_SIZE, "mclk\n");
2835 * The amdgpu driver exposes the following sensor interfaces:
2837 * - GPU temperature (via the on-die sensor)
2841 * - Northbridge voltage (APUs only)
2847 * - GPU gfx/compute engine clock
2849 * - GPU memory clock (dGPU only)
2851 * hwmon interfaces for GPU temperature:
2853 * - temp[1-3]_input: the on die GPU temperature in millidegrees Celsius
2854 * - temp2_input and temp3_input are supported on SOC15 dGPUs only
2856 * - temp[1-3]_label: temperature channel label
2857 * - temp2_label and temp3_label are supported on SOC15 dGPUs only
2859 * - temp[1-3]_crit: temperature critical max value in millidegrees Celsius
2860 * - temp2_crit and temp3_crit are supported on SOC15 dGPUs only
2862 * - temp[1-3]_crit_hyst: temperature hysteresis for critical limit in millidegrees Celsius
2863 * - temp2_crit_hyst and temp3_crit_hyst are supported on SOC15 dGPUs only
2865 * - temp[1-3]_emergency: temperature emergency max value(asic shutdown) in millidegrees Celsius
2866 * - these are supported on SOC15 dGPUs only
2868 * hwmon interfaces for GPU voltage:
2870 * - in0_input: the voltage on the GPU in millivolts
2872 * - in1_input: the voltage on the Northbridge in millivolts
2874 * hwmon interfaces for GPU power:
2876 * - power1_average: average power used by the GPU in microWatts
2878 * - power1_cap_min: minimum cap supported in microWatts
2880 * - power1_cap_max: maximum cap supported in microWatts
2882 * - power1_cap: selected power cap in microWatts
2884 * hwmon interfaces for GPU fan:
2886 * - pwm1: pulse width modulation fan level (0-255)
2888 * - 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)
2890 * - pwm1_min: pulse width modulation fan control minimum level (0)
2892 * - pwm1_max: pulse width modulation fan control maximum level (255)
2894 * - fan1_min: an minimum value Unit: revolution/min (RPM)
2896 * - fan1_max: an maxmum value Unit: revolution/max (RPM)
2898 * - fan1_input: fan speed in RPM
2900 * - fan[1-\*]_target: Desired fan speed Unit: revolution/min (RPM)
2902 * - fan[1-\*]_enable: Enable or disable the sensors.1: Enable 0: Disable
2904 * hwmon interfaces for GPU clocks:
2906 * - freq1_input: the gfx/compute clock in hertz
2908 * - freq2_input: the memory clock in hertz
2910 * You can use hwmon tools like sensors to view this information on your system.
2914 static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, amdgpu_hwmon_show_temp, NULL, PP_TEMP_EDGE);
2915 static SENSOR_DEVICE_ATTR(temp1_crit, S_IRUGO, amdgpu_hwmon_show_temp_thresh, NULL, 0);
2916 static SENSOR_DEVICE_ATTR(temp1_crit_hyst, S_IRUGO, amdgpu_hwmon_show_temp_thresh, NULL, 1);
2917 static SENSOR_DEVICE_ATTR(temp1_emergency, S_IRUGO, amdgpu_hwmon_show_temp_emergency, NULL, PP_TEMP_EDGE);
2918 static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, amdgpu_hwmon_show_temp, NULL, PP_TEMP_JUNCTION);
2919 static SENSOR_DEVICE_ATTR(temp2_crit, S_IRUGO, amdgpu_hwmon_show_hotspot_temp_thresh, NULL, 0);
2920 static SENSOR_DEVICE_ATTR(temp2_crit_hyst, S_IRUGO, amdgpu_hwmon_show_hotspot_temp_thresh, NULL, 1);
2921 static SENSOR_DEVICE_ATTR(temp2_emergency, S_IRUGO, amdgpu_hwmon_show_temp_emergency, NULL, PP_TEMP_JUNCTION);
2922 static SENSOR_DEVICE_ATTR(temp3_input, S_IRUGO, amdgpu_hwmon_show_temp, NULL, PP_TEMP_MEM);
2923 static SENSOR_DEVICE_ATTR(temp3_crit, S_IRUGO, amdgpu_hwmon_show_mem_temp_thresh, NULL, 0);
2924 static SENSOR_DEVICE_ATTR(temp3_crit_hyst, S_IRUGO, amdgpu_hwmon_show_mem_temp_thresh, NULL, 1);
2925 static SENSOR_DEVICE_ATTR(temp3_emergency, S_IRUGO, amdgpu_hwmon_show_temp_emergency, NULL, PP_TEMP_MEM);
2926 static SENSOR_DEVICE_ATTR(temp1_label, S_IRUGO, amdgpu_hwmon_show_temp_label, NULL, PP_TEMP_EDGE);
2927 static SENSOR_DEVICE_ATTR(temp2_label, S_IRUGO, amdgpu_hwmon_show_temp_label, NULL, PP_TEMP_JUNCTION);
2928 static SENSOR_DEVICE_ATTR(temp3_label, S_IRUGO, amdgpu_hwmon_show_temp_label, NULL, PP_TEMP_MEM);
2929 static SENSOR_DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, amdgpu_hwmon_get_pwm1, amdgpu_hwmon_set_pwm1, 0);
2930 static SENSOR_DEVICE_ATTR(pwm1_enable, S_IRUGO | S_IWUSR, amdgpu_hwmon_get_pwm1_enable, amdgpu_hwmon_set_pwm1_enable, 0);
2931 static SENSOR_DEVICE_ATTR(pwm1_min, S_IRUGO, amdgpu_hwmon_get_pwm1_min, NULL, 0);
2932 static SENSOR_DEVICE_ATTR(pwm1_max, S_IRUGO, amdgpu_hwmon_get_pwm1_max, NULL, 0);
2933 static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, amdgpu_hwmon_get_fan1_input, NULL, 0);
2934 static SENSOR_DEVICE_ATTR(fan1_min, S_IRUGO, amdgpu_hwmon_get_fan1_min, NULL, 0);
2935 static SENSOR_DEVICE_ATTR(fan1_max, S_IRUGO, amdgpu_hwmon_get_fan1_max, NULL, 0);
2936 static SENSOR_DEVICE_ATTR(fan1_target, S_IRUGO | S_IWUSR, amdgpu_hwmon_get_fan1_target, amdgpu_hwmon_set_fan1_target, 0);
2937 static SENSOR_DEVICE_ATTR(fan1_enable, S_IRUGO | S_IWUSR, amdgpu_hwmon_get_fan1_enable, amdgpu_hwmon_set_fan1_enable, 0);
2938 static SENSOR_DEVICE_ATTR(in0_input, S_IRUGO, amdgpu_hwmon_show_vddgfx, NULL, 0);
2939 static SENSOR_DEVICE_ATTR(in0_label, S_IRUGO, amdgpu_hwmon_show_vddgfx_label, NULL, 0);
2940 static SENSOR_DEVICE_ATTR(in1_input, S_IRUGO, amdgpu_hwmon_show_vddnb, NULL, 0);
2941 static SENSOR_DEVICE_ATTR(in1_label, S_IRUGO, amdgpu_hwmon_show_vddnb_label, NULL, 0);
2942 static SENSOR_DEVICE_ATTR(power1_average, S_IRUGO, amdgpu_hwmon_show_power_avg, NULL, 0);
2943 static SENSOR_DEVICE_ATTR(power1_cap_max, S_IRUGO, amdgpu_hwmon_show_power_cap_max, NULL, 0);
2944 static SENSOR_DEVICE_ATTR(power1_cap_min, S_IRUGO, amdgpu_hwmon_show_power_cap_min, NULL, 0);
2945 static SENSOR_DEVICE_ATTR(power1_cap, S_IRUGO | S_IWUSR, amdgpu_hwmon_show_power_cap, amdgpu_hwmon_set_power_cap, 0);
2946 static SENSOR_DEVICE_ATTR(freq1_input, S_IRUGO, amdgpu_hwmon_show_sclk, NULL, 0);
2947 static SENSOR_DEVICE_ATTR(freq1_label, S_IRUGO, amdgpu_hwmon_show_sclk_label, NULL, 0);
2948 static SENSOR_DEVICE_ATTR(freq2_input, S_IRUGO, amdgpu_hwmon_show_mclk, NULL, 0);
2949 static SENSOR_DEVICE_ATTR(freq2_label, S_IRUGO, amdgpu_hwmon_show_mclk_label, NULL, 0);
2951 static struct attribute *hwmon_attributes[] = {
2952 &sensor_dev_attr_temp1_input.dev_attr.attr,
2953 &sensor_dev_attr_temp1_crit.dev_attr.attr,
2954 &sensor_dev_attr_temp1_crit_hyst.dev_attr.attr,
2955 &sensor_dev_attr_temp2_input.dev_attr.attr,
2956 &sensor_dev_attr_temp2_crit.dev_attr.attr,
2957 &sensor_dev_attr_temp2_crit_hyst.dev_attr.attr,
2958 &sensor_dev_attr_temp3_input.dev_attr.attr,
2959 &sensor_dev_attr_temp3_crit.dev_attr.attr,
2960 &sensor_dev_attr_temp3_crit_hyst.dev_attr.attr,
2961 &sensor_dev_attr_temp1_emergency.dev_attr.attr,
2962 &sensor_dev_attr_temp2_emergency.dev_attr.attr,
2963 &sensor_dev_attr_temp3_emergency.dev_attr.attr,
2964 &sensor_dev_attr_temp1_label.dev_attr.attr,
2965 &sensor_dev_attr_temp2_label.dev_attr.attr,
2966 &sensor_dev_attr_temp3_label.dev_attr.attr,
2967 &sensor_dev_attr_pwm1.dev_attr.attr,
2968 &sensor_dev_attr_pwm1_enable.dev_attr.attr,
2969 &sensor_dev_attr_pwm1_min.dev_attr.attr,
2970 &sensor_dev_attr_pwm1_max.dev_attr.attr,
2971 &sensor_dev_attr_fan1_input.dev_attr.attr,
2972 &sensor_dev_attr_fan1_min.dev_attr.attr,
2973 &sensor_dev_attr_fan1_max.dev_attr.attr,
2974 &sensor_dev_attr_fan1_target.dev_attr.attr,
2975 &sensor_dev_attr_fan1_enable.dev_attr.attr,
2976 &sensor_dev_attr_in0_input.dev_attr.attr,
2977 &sensor_dev_attr_in0_label.dev_attr.attr,
2978 &sensor_dev_attr_in1_input.dev_attr.attr,
2979 &sensor_dev_attr_in1_label.dev_attr.attr,
2980 &sensor_dev_attr_power1_average.dev_attr.attr,
2981 &sensor_dev_attr_power1_cap_max.dev_attr.attr,
2982 &sensor_dev_attr_power1_cap_min.dev_attr.attr,
2983 &sensor_dev_attr_power1_cap.dev_attr.attr,
2984 &sensor_dev_attr_freq1_input.dev_attr.attr,
2985 &sensor_dev_attr_freq1_label.dev_attr.attr,
2986 &sensor_dev_attr_freq2_input.dev_attr.attr,
2987 &sensor_dev_attr_freq2_label.dev_attr.attr,
2991 static umode_t hwmon_attributes_visible(struct kobject *kobj,
2992 struct attribute *attr, int index)
2994 struct device *dev = kobj_to_dev(kobj);
2995 struct amdgpu_device *adev = dev_get_drvdata(dev);
2996 umode_t effective_mode = attr->mode;
2998 /* under multi-vf mode, the hwmon attributes are all not supported */
2999 if (amdgpu_sriov_vf(adev) && !amdgpu_sriov_is_pp_one_vf(adev))
3002 /* there is no fan under pp one vf mode */
3003 if (amdgpu_sriov_is_pp_one_vf(adev) &&
3004 (attr == &sensor_dev_attr_pwm1.dev_attr.attr ||
3005 attr == &sensor_dev_attr_pwm1_enable.dev_attr.attr ||
3006 attr == &sensor_dev_attr_pwm1_max.dev_attr.attr ||
3007 attr == &sensor_dev_attr_pwm1_min.dev_attr.attr ||
3008 attr == &sensor_dev_attr_fan1_input.dev_attr.attr ||
3009 attr == &sensor_dev_attr_fan1_min.dev_attr.attr ||
3010 attr == &sensor_dev_attr_fan1_max.dev_attr.attr ||
3011 attr == &sensor_dev_attr_fan1_target.dev_attr.attr ||
3012 attr == &sensor_dev_attr_fan1_enable.dev_attr.attr))
3015 /* Skip fan attributes if fan is not present */
3016 if (adev->pm.no_fan && (attr == &sensor_dev_attr_pwm1.dev_attr.attr ||
3017 attr == &sensor_dev_attr_pwm1_enable.dev_attr.attr ||
3018 attr == &sensor_dev_attr_pwm1_max.dev_attr.attr ||
3019 attr == &sensor_dev_attr_pwm1_min.dev_attr.attr ||
3020 attr == &sensor_dev_attr_fan1_input.dev_attr.attr ||
3021 attr == &sensor_dev_attr_fan1_min.dev_attr.attr ||
3022 attr == &sensor_dev_attr_fan1_max.dev_attr.attr ||
3023 attr == &sensor_dev_attr_fan1_target.dev_attr.attr ||
3024 attr == &sensor_dev_attr_fan1_enable.dev_attr.attr))
3027 /* Skip fan attributes on APU */
3028 if ((adev->flags & AMD_IS_APU) &&
3029 (attr == &sensor_dev_attr_pwm1.dev_attr.attr ||
3030 attr == &sensor_dev_attr_pwm1_enable.dev_attr.attr ||
3031 attr == &sensor_dev_attr_pwm1_max.dev_attr.attr ||
3032 attr == &sensor_dev_attr_pwm1_min.dev_attr.attr ||
3033 attr == &sensor_dev_attr_fan1_input.dev_attr.attr ||
3034 attr == &sensor_dev_attr_fan1_min.dev_attr.attr ||
3035 attr == &sensor_dev_attr_fan1_max.dev_attr.attr ||
3036 attr == &sensor_dev_attr_fan1_target.dev_attr.attr ||
3037 attr == &sensor_dev_attr_fan1_enable.dev_attr.attr))
3040 /* Skip limit attributes if DPM is not enabled */
3041 if (!adev->pm.dpm_enabled &&
3042 (attr == &sensor_dev_attr_temp1_crit.dev_attr.attr ||
3043 attr == &sensor_dev_attr_temp1_crit_hyst.dev_attr.attr ||
3044 attr == &sensor_dev_attr_pwm1.dev_attr.attr ||
3045 attr == &sensor_dev_attr_pwm1_enable.dev_attr.attr ||
3046 attr == &sensor_dev_attr_pwm1_max.dev_attr.attr ||
3047 attr == &sensor_dev_attr_pwm1_min.dev_attr.attr ||
3048 attr == &sensor_dev_attr_fan1_input.dev_attr.attr ||
3049 attr == &sensor_dev_attr_fan1_min.dev_attr.attr ||
3050 attr == &sensor_dev_attr_fan1_max.dev_attr.attr ||
3051 attr == &sensor_dev_attr_fan1_target.dev_attr.attr ||
3052 attr == &sensor_dev_attr_fan1_enable.dev_attr.attr))
3055 if (!is_support_sw_smu(adev)) {
3056 /* mask fan attributes if we have no bindings for this asic to expose */
3057 if ((!adev->powerplay.pp_funcs->get_fan_speed_percent &&
3058 attr == &sensor_dev_attr_pwm1.dev_attr.attr) || /* can't query fan */
3059 (!adev->powerplay.pp_funcs->get_fan_control_mode &&
3060 attr == &sensor_dev_attr_pwm1_enable.dev_attr.attr)) /* can't query state */
3061 effective_mode &= ~S_IRUGO;
3063 if ((!adev->powerplay.pp_funcs->set_fan_speed_percent &&
3064 attr == &sensor_dev_attr_pwm1.dev_attr.attr) || /* can't manage fan */
3065 (!adev->powerplay.pp_funcs->set_fan_control_mode &&
3066 attr == &sensor_dev_attr_pwm1_enable.dev_attr.attr)) /* can't manage state */
3067 effective_mode &= ~S_IWUSR;
3070 if (((adev->flags & AMD_IS_APU) ||
3071 adev->family == AMDGPU_FAMILY_SI || /* not implemented yet */
3072 adev->family == AMDGPU_FAMILY_KV) && /* not implemented yet */
3073 (attr == &sensor_dev_attr_power1_average.dev_attr.attr ||
3074 attr == &sensor_dev_attr_power1_cap_max.dev_attr.attr ||
3075 attr == &sensor_dev_attr_power1_cap_min.dev_attr.attr||
3076 attr == &sensor_dev_attr_power1_cap.dev_attr.attr))
3079 if (!is_support_sw_smu(adev)) {
3080 /* hide max/min values if we can't both query and manage the fan */
3081 if ((!adev->powerplay.pp_funcs->set_fan_speed_percent &&
3082 !adev->powerplay.pp_funcs->get_fan_speed_percent) &&
3083 (!adev->powerplay.pp_funcs->set_fan_speed_rpm &&
3084 !adev->powerplay.pp_funcs->get_fan_speed_rpm) &&
3085 (attr == &sensor_dev_attr_pwm1_max.dev_attr.attr ||
3086 attr == &sensor_dev_attr_pwm1_min.dev_attr.attr))
3089 if ((!adev->powerplay.pp_funcs->set_fan_speed_rpm &&
3090 !adev->powerplay.pp_funcs->get_fan_speed_rpm) &&
3091 (attr == &sensor_dev_attr_fan1_max.dev_attr.attr ||
3092 attr == &sensor_dev_attr_fan1_min.dev_attr.attr))
3096 if ((adev->family == AMDGPU_FAMILY_SI || /* not implemented yet */
3097 adev->family == AMDGPU_FAMILY_KV) && /* not implemented yet */
3098 (attr == &sensor_dev_attr_in0_input.dev_attr.attr ||
3099 attr == &sensor_dev_attr_in0_label.dev_attr.attr))
3102 /* only APUs have vddnb */
3103 if (!(adev->flags & AMD_IS_APU) &&
3104 (attr == &sensor_dev_attr_in1_input.dev_attr.attr ||
3105 attr == &sensor_dev_attr_in1_label.dev_attr.attr))
3108 /* no mclk on APUs */
3109 if ((adev->flags & AMD_IS_APU) &&
3110 (attr == &sensor_dev_attr_freq2_input.dev_attr.attr ||
3111 attr == &sensor_dev_attr_freq2_label.dev_attr.attr))
3114 /* only SOC15 dGPUs support hotspot and mem temperatures */
3115 if (((adev->flags & AMD_IS_APU) ||
3116 adev->asic_type < CHIP_VEGA10) &&
3117 (attr == &sensor_dev_attr_temp2_crit.dev_attr.attr ||
3118 attr == &sensor_dev_attr_temp2_crit_hyst.dev_attr.attr ||
3119 attr == &sensor_dev_attr_temp3_crit.dev_attr.attr ||
3120 attr == &sensor_dev_attr_temp3_crit_hyst.dev_attr.attr ||
3121 attr == &sensor_dev_attr_temp1_emergency.dev_attr.attr ||
3122 attr == &sensor_dev_attr_temp2_emergency.dev_attr.attr ||
3123 attr == &sensor_dev_attr_temp3_emergency.dev_attr.attr ||
3124 attr == &sensor_dev_attr_temp2_input.dev_attr.attr ||
3125 attr == &sensor_dev_attr_temp3_input.dev_attr.attr ||
3126 attr == &sensor_dev_attr_temp2_label.dev_attr.attr ||
3127 attr == &sensor_dev_attr_temp3_label.dev_attr.attr))
3130 return effective_mode;
3133 static const struct attribute_group hwmon_attrgroup = {
3134 .attrs = hwmon_attributes,
3135 .is_visible = hwmon_attributes_visible,
3138 static const struct attribute_group *hwmon_groups[] = {
3143 void amdgpu_dpm_thermal_work_handler(struct work_struct *work)
3145 struct amdgpu_device *adev =
3146 container_of(work, struct amdgpu_device,
3147 pm.dpm.thermal.work);
3148 /* switch to the thermal state */
3149 enum amd_pm_state_type dpm_state = POWER_STATE_TYPE_INTERNAL_THERMAL;
3150 int temp, size = sizeof(temp);
3152 if (!adev->pm.dpm_enabled)
3155 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GPU_TEMP,
3156 (void *)&temp, &size)) {
3157 if (temp < adev->pm.dpm.thermal.min_temp)
3158 /* switch back the user state */
3159 dpm_state = adev->pm.dpm.user_state;
3161 if (adev->pm.dpm.thermal.high_to_low)
3162 /* switch back the user state */
3163 dpm_state = adev->pm.dpm.user_state;
3165 mutex_lock(&adev->pm.mutex);
3166 if (dpm_state == POWER_STATE_TYPE_INTERNAL_THERMAL)
3167 adev->pm.dpm.thermal_active = true;
3169 adev->pm.dpm.thermal_active = false;
3170 adev->pm.dpm.state = dpm_state;
3171 mutex_unlock(&adev->pm.mutex);
3173 amdgpu_pm_compute_clocks(adev);
3176 static struct amdgpu_ps *amdgpu_dpm_pick_power_state(struct amdgpu_device *adev,
3177 enum amd_pm_state_type dpm_state)
3180 struct amdgpu_ps *ps;
3182 bool single_display = (adev->pm.dpm.new_active_crtc_count < 2) ?
3185 /* check if the vblank period is too short to adjust the mclk */
3186 if (single_display && adev->powerplay.pp_funcs->vblank_too_short) {
3187 if (amdgpu_dpm_vblank_too_short(adev))
3188 single_display = false;
3191 /* certain older asics have a separare 3D performance state,
3192 * so try that first if the user selected performance
3194 if (dpm_state == POWER_STATE_TYPE_PERFORMANCE)
3195 dpm_state = POWER_STATE_TYPE_INTERNAL_3DPERF;
3196 /* balanced states don't exist at the moment */
3197 if (dpm_state == POWER_STATE_TYPE_BALANCED)
3198 dpm_state = POWER_STATE_TYPE_PERFORMANCE;
3201 /* Pick the best power state based on current conditions */
3202 for (i = 0; i < adev->pm.dpm.num_ps; i++) {
3203 ps = &adev->pm.dpm.ps[i];
3204 ui_class = ps->class & ATOM_PPLIB_CLASSIFICATION_UI_MASK;
3205 switch (dpm_state) {
3207 case POWER_STATE_TYPE_BATTERY:
3208 if (ui_class == ATOM_PPLIB_CLASSIFICATION_UI_BATTERY) {
3209 if (ps->caps & ATOM_PPLIB_SINGLE_DISPLAY_ONLY) {
3216 case POWER_STATE_TYPE_BALANCED:
3217 if (ui_class == ATOM_PPLIB_CLASSIFICATION_UI_BALANCED) {
3218 if (ps->caps & ATOM_PPLIB_SINGLE_DISPLAY_ONLY) {
3225 case POWER_STATE_TYPE_PERFORMANCE:
3226 if (ui_class == ATOM_PPLIB_CLASSIFICATION_UI_PERFORMANCE) {
3227 if (ps->caps & ATOM_PPLIB_SINGLE_DISPLAY_ONLY) {
3234 /* internal states */
3235 case POWER_STATE_TYPE_INTERNAL_UVD:
3236 if (adev->pm.dpm.uvd_ps)
3237 return adev->pm.dpm.uvd_ps;
3240 case POWER_STATE_TYPE_INTERNAL_UVD_SD:
3241 if (ps->class & ATOM_PPLIB_CLASSIFICATION_SDSTATE)
3244 case POWER_STATE_TYPE_INTERNAL_UVD_HD:
3245 if (ps->class & ATOM_PPLIB_CLASSIFICATION_HDSTATE)
3248 case POWER_STATE_TYPE_INTERNAL_UVD_HD2:
3249 if (ps->class & ATOM_PPLIB_CLASSIFICATION_HD2STATE)
3252 case POWER_STATE_TYPE_INTERNAL_UVD_MVC:
3253 if (ps->class2 & ATOM_PPLIB_CLASSIFICATION2_MVC)
3256 case POWER_STATE_TYPE_INTERNAL_BOOT:
3257 return adev->pm.dpm.boot_ps;
3258 case POWER_STATE_TYPE_INTERNAL_THERMAL:
3259 if (ps->class & ATOM_PPLIB_CLASSIFICATION_THERMAL)
3262 case POWER_STATE_TYPE_INTERNAL_ACPI:
3263 if (ps->class & ATOM_PPLIB_CLASSIFICATION_ACPI)
3266 case POWER_STATE_TYPE_INTERNAL_ULV:
3267 if (ps->class2 & ATOM_PPLIB_CLASSIFICATION2_ULV)
3270 case POWER_STATE_TYPE_INTERNAL_3DPERF:
3271 if (ps->class & ATOM_PPLIB_CLASSIFICATION_3DPERFORMANCE)
3278 /* use a fallback state if we didn't match */
3279 switch (dpm_state) {
3280 case POWER_STATE_TYPE_INTERNAL_UVD_SD:
3281 dpm_state = POWER_STATE_TYPE_INTERNAL_UVD_HD;
3282 goto restart_search;
3283 case POWER_STATE_TYPE_INTERNAL_UVD_HD:
3284 case POWER_STATE_TYPE_INTERNAL_UVD_HD2:
3285 case POWER_STATE_TYPE_INTERNAL_UVD_MVC:
3286 if (adev->pm.dpm.uvd_ps) {
3287 return adev->pm.dpm.uvd_ps;
3289 dpm_state = POWER_STATE_TYPE_PERFORMANCE;
3290 goto restart_search;
3292 case POWER_STATE_TYPE_INTERNAL_THERMAL:
3293 dpm_state = POWER_STATE_TYPE_INTERNAL_ACPI;
3294 goto restart_search;
3295 case POWER_STATE_TYPE_INTERNAL_ACPI:
3296 dpm_state = POWER_STATE_TYPE_BATTERY;
3297 goto restart_search;
3298 case POWER_STATE_TYPE_BATTERY:
3299 case POWER_STATE_TYPE_BALANCED:
3300 case POWER_STATE_TYPE_INTERNAL_3DPERF:
3301 dpm_state = POWER_STATE_TYPE_PERFORMANCE;
3302 goto restart_search;
3310 static void amdgpu_dpm_change_power_state_locked(struct amdgpu_device *adev)
3312 struct amdgpu_ps *ps;
3313 enum amd_pm_state_type dpm_state;
3317 /* if dpm init failed */
3318 if (!adev->pm.dpm_enabled)
3321 if (adev->pm.dpm.user_state != adev->pm.dpm.state) {
3322 /* add other state override checks here */
3323 if ((!adev->pm.dpm.thermal_active) &&
3324 (!adev->pm.dpm.uvd_active))
3325 adev->pm.dpm.state = adev->pm.dpm.user_state;
3327 dpm_state = adev->pm.dpm.state;
3329 ps = amdgpu_dpm_pick_power_state(adev, dpm_state);
3331 adev->pm.dpm.requested_ps = ps;
3335 if (amdgpu_dpm == 1 && adev->powerplay.pp_funcs->print_power_state) {
3336 printk("switching from power state:\n");
3337 amdgpu_dpm_print_power_state(adev, adev->pm.dpm.current_ps);
3338 printk("switching to power state:\n");
3339 amdgpu_dpm_print_power_state(adev, adev->pm.dpm.requested_ps);
3342 /* update whether vce is active */
3343 ps->vce_active = adev->pm.dpm.vce_active;
3344 if (adev->powerplay.pp_funcs->display_configuration_changed)
3345 amdgpu_dpm_display_configuration_changed(adev);
3347 ret = amdgpu_dpm_pre_set_power_state(adev);
3351 if (adev->powerplay.pp_funcs->check_state_equal) {
3352 if (0 != amdgpu_dpm_check_state_equal(adev, adev->pm.dpm.current_ps, adev->pm.dpm.requested_ps, &equal))
3359 amdgpu_dpm_set_power_state(adev);
3360 amdgpu_dpm_post_set_power_state(adev);
3362 adev->pm.dpm.current_active_crtcs = adev->pm.dpm.new_active_crtcs;
3363 adev->pm.dpm.current_active_crtc_count = adev->pm.dpm.new_active_crtc_count;
3365 if (adev->powerplay.pp_funcs->force_performance_level) {
3366 if (adev->pm.dpm.thermal_active) {
3367 enum amd_dpm_forced_level level = adev->pm.dpm.forced_level;
3368 /* force low perf level for thermal */
3369 amdgpu_dpm_force_performance_level(adev, AMD_DPM_FORCED_LEVEL_LOW);
3370 /* save the user's level */
3371 adev->pm.dpm.forced_level = level;
3373 /* otherwise, user selected level */
3374 amdgpu_dpm_force_performance_level(adev, adev->pm.dpm.forced_level);
3379 void amdgpu_dpm_enable_uvd(struct amdgpu_device *adev, bool enable)
3383 ret = amdgpu_dpm_set_powergating_by_smu(adev, AMD_IP_BLOCK_TYPE_UVD, !enable);
3385 DRM_ERROR("Dpm %s uvd failed, ret = %d. \n",
3386 enable ? "enable" : "disable", ret);
3388 /* enable/disable Low Memory PState for UVD (4k videos) */
3389 if (adev->asic_type == CHIP_STONEY &&
3390 adev->uvd.decode_image_width >= WIDTH_4K) {
3391 struct pp_hwmgr *hwmgr = adev->powerplay.pp_handle;
3393 if (hwmgr && hwmgr->hwmgr_func &&
3394 hwmgr->hwmgr_func->update_nbdpm_pstate)
3395 hwmgr->hwmgr_func->update_nbdpm_pstate(hwmgr,
3401 void amdgpu_dpm_enable_vce(struct amdgpu_device *adev, bool enable)
3405 ret = amdgpu_dpm_set_powergating_by_smu(adev, AMD_IP_BLOCK_TYPE_VCE, !enable);
3407 DRM_ERROR("Dpm %s vce failed, ret = %d. \n",
3408 enable ? "enable" : "disable", ret);
3411 void amdgpu_pm_print_power_states(struct amdgpu_device *adev)
3415 if (adev->powerplay.pp_funcs->print_power_state == NULL)
3418 for (i = 0; i < adev->pm.dpm.num_ps; i++)
3419 amdgpu_dpm_print_power_state(adev, &adev->pm.dpm.ps[i]);
3423 void amdgpu_dpm_enable_jpeg(struct amdgpu_device *adev, bool enable)
3427 ret = amdgpu_dpm_set_powergating_by_smu(adev, AMD_IP_BLOCK_TYPE_JPEG, !enable);
3429 DRM_ERROR("Dpm %s jpeg failed, ret = %d. \n",
3430 enable ? "enable" : "disable", ret);
3433 int amdgpu_pm_load_smu_firmware(struct amdgpu_device *adev, uint32_t *smu_version)
3437 if (adev->powerplay.pp_funcs && adev->powerplay.pp_funcs->load_firmware) {
3438 r = adev->powerplay.pp_funcs->load_firmware(adev->powerplay.pp_handle);
3440 pr_err("smu firmware loading failed\n");
3443 *smu_version = adev->pm.fw_version;
3448 int amdgpu_pm_sysfs_init(struct amdgpu_device *adev)
3453 if (adev->pm.sysfs_initialized)
3456 if (adev->pm.dpm_enabled == 0)
3459 INIT_LIST_HEAD(&adev->pm.pm_attr_list);
3461 adev->pm.int_hwmon_dev = hwmon_device_register_with_groups(adev->dev,
3464 if (IS_ERR(adev->pm.int_hwmon_dev)) {
3465 ret = PTR_ERR(adev->pm.int_hwmon_dev);
3467 "Unable to register hwmon device: %d\n", ret);
3471 switch (amdgpu_virt_get_sriov_vf_mode(adev)) {
3472 case SRIOV_VF_MODE_ONE_VF:
3473 mask = ATTR_FLAG_ONEVF;
3475 case SRIOV_VF_MODE_MULTI_VF:
3478 case SRIOV_VF_MODE_BARE_METAL:
3480 mask = ATTR_FLAG_MASK_ALL;
3484 ret = amdgpu_device_attr_create_groups(adev,
3485 amdgpu_device_attrs,
3486 ARRAY_SIZE(amdgpu_device_attrs),
3488 &adev->pm.pm_attr_list);
3492 adev->pm.sysfs_initialized = true;
3497 void amdgpu_pm_sysfs_fini(struct amdgpu_device *adev)
3499 if (adev->pm.dpm_enabled == 0)
3502 if (adev->pm.int_hwmon_dev)
3503 hwmon_device_unregister(adev->pm.int_hwmon_dev);
3505 amdgpu_device_attr_remove_groups(adev, &adev->pm.pm_attr_list);
3508 void amdgpu_pm_compute_clocks(struct amdgpu_device *adev)
3512 if (!adev->pm.dpm_enabled)
3515 if (adev->mode_info.num_crtc)
3516 amdgpu_display_bandwidth_update(adev);
3518 for (i = 0; i < AMDGPU_MAX_RINGS; i++) {
3519 struct amdgpu_ring *ring = adev->rings[i];
3520 if (ring && ring->sched.ready)
3521 amdgpu_fence_wait_empty(ring);
3524 if (is_support_sw_smu(adev)) {
3525 struct smu_dpm_context *smu_dpm = &adev->smu.smu_dpm;
3526 smu_handle_task(&adev->smu,
3528 AMD_PP_TASK_DISPLAY_CONFIG_CHANGE,
3531 if (adev->powerplay.pp_funcs->dispatch_tasks) {
3532 if (!amdgpu_device_has_dc_support(adev)) {
3533 mutex_lock(&adev->pm.mutex);
3534 amdgpu_dpm_get_active_displays(adev);
3535 adev->pm.pm_display_cfg.num_display = adev->pm.dpm.new_active_crtc_count;
3536 adev->pm.pm_display_cfg.vrefresh = amdgpu_dpm_get_vrefresh(adev);
3537 adev->pm.pm_display_cfg.min_vblank_time = amdgpu_dpm_get_vblank_time(adev);
3538 /* we have issues with mclk switching with refresh rates over 120 hz on the non-DC code. */
3539 if (adev->pm.pm_display_cfg.vrefresh > 120)
3540 adev->pm.pm_display_cfg.min_vblank_time = 0;
3541 if (adev->powerplay.pp_funcs->display_configuration_change)
3542 adev->powerplay.pp_funcs->display_configuration_change(
3543 adev->powerplay.pp_handle,
3544 &adev->pm.pm_display_cfg);
3545 mutex_unlock(&adev->pm.mutex);
3547 amdgpu_dpm_dispatch_task(adev, AMD_PP_TASK_DISPLAY_CONFIG_CHANGE, NULL);
3549 mutex_lock(&adev->pm.mutex);
3550 amdgpu_dpm_get_active_displays(adev);
3551 amdgpu_dpm_change_power_state_locked(adev);
3552 mutex_unlock(&adev->pm.mutex);
3560 #if defined(CONFIG_DEBUG_FS)
3562 static int amdgpu_debugfs_pm_info_pp(struct seq_file *m, struct amdgpu_device *adev)
3570 size = sizeof(value);
3571 seq_printf(m, "GFX Clocks and Power:\n");
3572 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GFX_MCLK, (void *)&value, &size))
3573 seq_printf(m, "\t%u MHz (MCLK)\n", value/100);
3574 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GFX_SCLK, (void *)&value, &size))
3575 seq_printf(m, "\t%u MHz (SCLK)\n", value/100);
3576 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_STABLE_PSTATE_SCLK, (void *)&value, &size))
3577 seq_printf(m, "\t%u MHz (PSTATE_SCLK)\n", value/100);
3578 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_STABLE_PSTATE_MCLK, (void *)&value, &size))
3579 seq_printf(m, "\t%u MHz (PSTATE_MCLK)\n", value/100);
3580 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_VDDGFX, (void *)&value, &size))
3581 seq_printf(m, "\t%u mV (VDDGFX)\n", value);
3582 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_VDDNB, (void *)&value, &size))
3583 seq_printf(m, "\t%u mV (VDDNB)\n", value);
3584 size = sizeof(uint32_t);
3585 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GPU_POWER, (void *)&query, &size))
3586 seq_printf(m, "\t%u.%u W (average GPU)\n", query >> 8, query & 0xff);
3587 size = sizeof(value);
3588 seq_printf(m, "\n");
3591 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GPU_TEMP, (void *)&value, &size))
3592 seq_printf(m, "GPU Temperature: %u C\n", value/1000);
3595 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GPU_LOAD, (void *)&value, &size))
3596 seq_printf(m, "GPU Load: %u %%\n", value);
3598 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_MEM_LOAD, (void *)&value, &size))
3599 seq_printf(m, "MEM Load: %u %%\n", value);
3601 seq_printf(m, "\n");
3603 /* SMC feature mask */
3604 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_ENABLED_SMC_FEATURES_MASK, (void *)&value64, &size))
3605 seq_printf(m, "SMC Feature Mask: 0x%016llx\n", value64);
3607 if (adev->asic_type > CHIP_VEGA20) {
3609 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_VCN_POWER_STATE, (void *)&value, &size)) {
3611 seq_printf(m, "VCN: Disabled\n");
3613 seq_printf(m, "VCN: Enabled\n");
3614 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_UVD_DCLK, (void *)&value, &size))
3615 seq_printf(m, "\t%u MHz (DCLK)\n", value/100);
3616 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_UVD_VCLK, (void *)&value, &size))
3617 seq_printf(m, "\t%u MHz (VCLK)\n", value/100);
3620 seq_printf(m, "\n");
3623 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_UVD_POWER, (void *)&value, &size)) {
3625 seq_printf(m, "UVD: Disabled\n");
3627 seq_printf(m, "UVD: Enabled\n");
3628 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_UVD_DCLK, (void *)&value, &size))
3629 seq_printf(m, "\t%u MHz (DCLK)\n", value/100);
3630 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_UVD_VCLK, (void *)&value, &size))
3631 seq_printf(m, "\t%u MHz (VCLK)\n", value/100);
3634 seq_printf(m, "\n");
3637 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_VCE_POWER, (void *)&value, &size)) {
3639 seq_printf(m, "VCE: Disabled\n");
3641 seq_printf(m, "VCE: Enabled\n");
3642 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_VCE_ECCLK, (void *)&value, &size))
3643 seq_printf(m, "\t%u MHz (ECCLK)\n", value/100);
3651 static void amdgpu_parse_cg_state(struct seq_file *m, u32 flags)
3655 for (i = 0; clocks[i].flag; i++)
3656 seq_printf(m, "\t%s: %s\n", clocks[i].name,
3657 (flags & clocks[i].flag) ? "On" : "Off");
3660 static int amdgpu_debugfs_pm_info(struct seq_file *m, void *data)
3662 struct drm_info_node *node = (struct drm_info_node *) m->private;
3663 struct drm_device *dev = node->minor->dev;
3664 struct amdgpu_device *adev = dev->dev_private;
3668 if (adev->in_gpu_reset)
3671 r = pm_runtime_get_sync(dev->dev);
3675 amdgpu_device_ip_get_clockgating_state(adev, &flags);
3676 seq_printf(m, "Clock Gating Flags Mask: 0x%x\n", flags);
3677 amdgpu_parse_cg_state(m, flags);
3678 seq_printf(m, "\n");
3680 if (!adev->pm.dpm_enabled) {
3681 seq_printf(m, "dpm not enabled\n");
3682 pm_runtime_mark_last_busy(dev->dev);
3683 pm_runtime_put_autosuspend(dev->dev);
3687 if (!is_support_sw_smu(adev) &&
3688 adev->powerplay.pp_funcs->debugfs_print_current_performance_level) {
3689 mutex_lock(&adev->pm.mutex);
3690 if (adev->powerplay.pp_funcs->debugfs_print_current_performance_level)
3691 adev->powerplay.pp_funcs->debugfs_print_current_performance_level(adev, m);
3693 seq_printf(m, "Debugfs support not implemented for this asic\n");
3694 mutex_unlock(&adev->pm.mutex);
3697 r = amdgpu_debugfs_pm_info_pp(m, adev);
3700 pm_runtime_mark_last_busy(dev->dev);
3701 pm_runtime_put_autosuspend(dev->dev);
3706 static const struct drm_info_list amdgpu_pm_info_list[] = {
3707 {"amdgpu_pm_info", amdgpu_debugfs_pm_info, 0, NULL},
3711 int amdgpu_debugfs_pm_init(struct amdgpu_device *adev)
3713 #if defined(CONFIG_DEBUG_FS)
3714 return amdgpu_debugfs_add_files(adev, amdgpu_pm_info_list, ARRAY_SIZE(amdgpu_pm_info_list));