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.
27 #include "amdgpu_drv.h"
28 #include "amdgpu_pm.h"
29 #include "amdgpu_dpm.h"
30 #include "amdgpu_display.h"
31 #include "amdgpu_smu.h"
33 #include <linux/power_supply.h>
34 #include <linux/hwmon.h>
35 #include <linux/hwmon-sysfs.h>
36 #include <linux/nospec.h>
40 static int amdgpu_debugfs_pm_init(struct amdgpu_device *adev);
42 static const struct cg_flag_name clocks[] = {
43 {AMD_CG_SUPPORT_GFX_MGCG, "Graphics Medium Grain Clock Gating"},
44 {AMD_CG_SUPPORT_GFX_MGLS, "Graphics Medium Grain memory Light Sleep"},
45 {AMD_CG_SUPPORT_GFX_CGCG, "Graphics Coarse Grain Clock Gating"},
46 {AMD_CG_SUPPORT_GFX_CGLS, "Graphics Coarse Grain memory Light Sleep"},
47 {AMD_CG_SUPPORT_GFX_CGTS, "Graphics Coarse Grain Tree Shader Clock Gating"},
48 {AMD_CG_SUPPORT_GFX_CGTS_LS, "Graphics Coarse Grain Tree Shader Light Sleep"},
49 {AMD_CG_SUPPORT_GFX_CP_LS, "Graphics Command Processor Light Sleep"},
50 {AMD_CG_SUPPORT_GFX_RLC_LS, "Graphics Run List Controller Light Sleep"},
51 {AMD_CG_SUPPORT_GFX_3D_CGCG, "Graphics 3D Coarse Grain Clock Gating"},
52 {AMD_CG_SUPPORT_GFX_3D_CGLS, "Graphics 3D Coarse Grain memory Light Sleep"},
53 {AMD_CG_SUPPORT_MC_LS, "Memory Controller Light Sleep"},
54 {AMD_CG_SUPPORT_MC_MGCG, "Memory Controller Medium Grain Clock Gating"},
55 {AMD_CG_SUPPORT_SDMA_LS, "System Direct Memory Access Light Sleep"},
56 {AMD_CG_SUPPORT_SDMA_MGCG, "System Direct Memory Access Medium Grain Clock Gating"},
57 {AMD_CG_SUPPORT_BIF_MGCG, "Bus Interface Medium Grain Clock Gating"},
58 {AMD_CG_SUPPORT_BIF_LS, "Bus Interface Light Sleep"},
59 {AMD_CG_SUPPORT_UVD_MGCG, "Unified Video Decoder Medium Grain Clock Gating"},
60 {AMD_CG_SUPPORT_VCE_MGCG, "Video Compression Engine Medium Grain Clock Gating"},
61 {AMD_CG_SUPPORT_HDP_LS, "Host Data Path Light Sleep"},
62 {AMD_CG_SUPPORT_HDP_MGCG, "Host Data Path Medium Grain Clock Gating"},
63 {AMD_CG_SUPPORT_DRM_MGCG, "Digital Right Management Medium Grain Clock Gating"},
64 {AMD_CG_SUPPORT_DRM_LS, "Digital Right Management Light Sleep"},
65 {AMD_CG_SUPPORT_ROM_MGCG, "Rom Medium Grain Clock Gating"},
66 {AMD_CG_SUPPORT_DF_MGCG, "Data Fabric Medium Grain Clock Gating"},
70 void amdgpu_pm_acpi_event_handler(struct amdgpu_device *adev)
72 if (adev->pm.dpm_enabled) {
73 mutex_lock(&adev->pm.mutex);
74 if (power_supply_is_system_supplied() > 0)
75 adev->pm.ac_power = true;
77 adev->pm.ac_power = false;
78 if (adev->powerplay.pp_funcs->enable_bapm)
79 amdgpu_dpm_enable_bapm(adev, adev->pm.ac_power);
80 mutex_unlock(&adev->pm.mutex);
84 int amdgpu_dpm_read_sensor(struct amdgpu_device *adev, enum amd_pp_sensors sensor,
85 void *data, uint32_t *size)
92 if (is_support_sw_smu(adev))
93 ret = smu_read_sensor(&adev->smu, sensor, data, size);
95 if (adev->powerplay.pp_funcs && adev->powerplay.pp_funcs->read_sensor)
96 ret = adev->powerplay.pp_funcs->read_sensor((adev)->powerplay.pp_handle,
106 * DOC: power_dpm_state
108 * The power_dpm_state file is a legacy interface and is only provided for
109 * backwards compatibility. The amdgpu driver provides a sysfs API for adjusting
110 * certain power related parameters. The file power_dpm_state is used for this.
111 * It accepts the following arguments:
121 * On older GPUs, the vbios provided a special power state for battery
122 * operation. Selecting battery switched to this state. This is no
123 * longer provided on newer GPUs so the option does nothing in that case.
127 * On older GPUs, the vbios provided a special power state for balanced
128 * operation. Selecting balanced switched to this state. This is no
129 * longer provided on newer GPUs so the option does nothing in that case.
133 * On older GPUs, the vbios provided a special power state for performance
134 * operation. Selecting performance switched to this state. This is no
135 * longer provided on newer GPUs so the option does nothing in that case.
139 static ssize_t amdgpu_get_dpm_state(struct device *dev,
140 struct device_attribute *attr,
143 struct drm_device *ddev = dev_get_drvdata(dev);
144 struct amdgpu_device *adev = ddev->dev_private;
145 enum amd_pm_state_type pm;
147 if (adev->smu.ppt_funcs->get_current_power_state)
148 pm = amdgpu_smu_get_current_power_state(adev);
149 else if (adev->powerplay.pp_funcs->get_current_power_state)
150 pm = amdgpu_dpm_get_current_power_state(adev);
152 pm = adev->pm.dpm.user_state;
154 return snprintf(buf, PAGE_SIZE, "%s\n",
155 (pm == POWER_STATE_TYPE_BATTERY) ? "battery" :
156 (pm == POWER_STATE_TYPE_BALANCED) ? "balanced" : "performance");
159 static ssize_t amdgpu_set_dpm_state(struct device *dev,
160 struct device_attribute *attr,
164 struct drm_device *ddev = dev_get_drvdata(dev);
165 struct amdgpu_device *adev = ddev->dev_private;
166 enum amd_pm_state_type state;
168 if (strncmp("battery", buf, strlen("battery")) == 0)
169 state = POWER_STATE_TYPE_BATTERY;
170 else if (strncmp("balanced", buf, strlen("balanced")) == 0)
171 state = POWER_STATE_TYPE_BALANCED;
172 else if (strncmp("performance", buf, strlen("performance")) == 0)
173 state = POWER_STATE_TYPE_PERFORMANCE;
179 if (adev->powerplay.pp_funcs->dispatch_tasks) {
180 amdgpu_dpm_dispatch_task(adev, AMD_PP_TASK_ENABLE_USER_STATE, &state);
182 mutex_lock(&adev->pm.mutex);
183 adev->pm.dpm.user_state = state;
184 mutex_unlock(&adev->pm.mutex);
186 /* Can't set dpm state when the card is off */
187 if (!(adev->flags & AMD_IS_PX) ||
188 (ddev->switch_power_state == DRM_SWITCH_POWER_ON))
189 amdgpu_pm_compute_clocks(adev);
197 * DOC: power_dpm_force_performance_level
199 * The amdgpu driver provides a sysfs API for adjusting certain power
200 * related parameters. The file power_dpm_force_performance_level is
201 * used for this. It accepts the following arguments:
221 * When auto is selected, the driver will attempt to dynamically select
222 * the optimal power profile for current conditions in the driver.
226 * When low is selected, the clocks are forced to the lowest power state.
230 * When high is selected, the clocks are forced to the highest power state.
234 * When manual is selected, the user can manually adjust which power states
235 * are enabled for each clock domain via the sysfs pp_dpm_mclk, pp_dpm_sclk,
236 * and pp_dpm_pcie files and adjust the power state transition heuristics
237 * via the pp_power_profile_mode sysfs file.
244 * When the profiling modes are selected, clock and power gating are
245 * disabled and the clocks are set for different profiling cases. This
246 * mode is recommended for profiling specific work loads where you do
247 * not want clock or power gating for clock fluctuation to interfere
248 * with your results. profile_standard sets the clocks to a fixed clock
249 * level which varies from asic to asic. profile_min_sclk forces the sclk
250 * to the lowest level. profile_min_mclk forces the mclk to the lowest level.
251 * profile_peak sets all clocks (mclk, sclk, pcie) to the highest levels.
255 static ssize_t amdgpu_get_dpm_forced_performance_level(struct device *dev,
256 struct device_attribute *attr,
259 struct drm_device *ddev = dev_get_drvdata(dev);
260 struct amdgpu_device *adev = ddev->dev_private;
261 enum amd_dpm_forced_level level = 0xff;
263 if ((adev->flags & AMD_IS_PX) &&
264 (ddev->switch_power_state != DRM_SWITCH_POWER_ON))
265 return snprintf(buf, PAGE_SIZE, "off\n");
267 if (is_support_sw_smu(adev))
268 level = smu_get_performance_level(&adev->smu);
269 else if (adev->powerplay.pp_funcs->get_performance_level)
270 level = amdgpu_dpm_get_performance_level(adev);
272 level = adev->pm.dpm.forced_level;
274 return snprintf(buf, PAGE_SIZE, "%s\n",
275 (level == AMD_DPM_FORCED_LEVEL_AUTO) ? "auto" :
276 (level == AMD_DPM_FORCED_LEVEL_LOW) ? "low" :
277 (level == AMD_DPM_FORCED_LEVEL_HIGH) ? "high" :
278 (level == AMD_DPM_FORCED_LEVEL_MANUAL) ? "manual" :
279 (level == AMD_DPM_FORCED_LEVEL_PROFILE_STANDARD) ? "profile_standard" :
280 (level == AMD_DPM_FORCED_LEVEL_PROFILE_MIN_SCLK) ? "profile_min_sclk" :
281 (level == AMD_DPM_FORCED_LEVEL_PROFILE_MIN_MCLK) ? "profile_min_mclk" :
282 (level == AMD_DPM_FORCED_LEVEL_PROFILE_PEAK) ? "profile_peak" :
286 static ssize_t amdgpu_set_dpm_forced_performance_level(struct device *dev,
287 struct device_attribute *attr,
291 struct drm_device *ddev = dev_get_drvdata(dev);
292 struct amdgpu_device *adev = ddev->dev_private;
293 enum amd_dpm_forced_level level;
294 enum amd_dpm_forced_level current_level = 0xff;
297 /* Can't force performance level when the card is off */
298 if ((adev->flags & AMD_IS_PX) &&
299 (ddev->switch_power_state != DRM_SWITCH_POWER_ON))
302 if (is_support_sw_smu(adev))
303 current_level = smu_get_performance_level(&adev->smu);
304 else if (adev->powerplay.pp_funcs->get_performance_level)
305 current_level = amdgpu_dpm_get_performance_level(adev);
307 if (strncmp("low", buf, strlen("low")) == 0) {
308 level = AMD_DPM_FORCED_LEVEL_LOW;
309 } else if (strncmp("high", buf, strlen("high")) == 0) {
310 level = AMD_DPM_FORCED_LEVEL_HIGH;
311 } else if (strncmp("auto", buf, strlen("auto")) == 0) {
312 level = AMD_DPM_FORCED_LEVEL_AUTO;
313 } else if (strncmp("manual", buf, strlen("manual")) == 0) {
314 level = AMD_DPM_FORCED_LEVEL_MANUAL;
315 } else if (strncmp("profile_exit", buf, strlen("profile_exit")) == 0) {
316 level = AMD_DPM_FORCED_LEVEL_PROFILE_EXIT;
317 } else if (strncmp("profile_standard", buf, strlen("profile_standard")) == 0) {
318 level = AMD_DPM_FORCED_LEVEL_PROFILE_STANDARD;
319 } else if (strncmp("profile_min_sclk", buf, strlen("profile_min_sclk")) == 0) {
320 level = AMD_DPM_FORCED_LEVEL_PROFILE_MIN_SCLK;
321 } else if (strncmp("profile_min_mclk", buf, strlen("profile_min_mclk")) == 0) {
322 level = AMD_DPM_FORCED_LEVEL_PROFILE_MIN_MCLK;
323 } else if (strncmp("profile_peak", buf, strlen("profile_peak")) == 0) {
324 level = AMD_DPM_FORCED_LEVEL_PROFILE_PEAK;
330 if (current_level == level)
333 if (is_support_sw_smu(adev)) {
334 mutex_lock(&adev->pm.mutex);
335 if (adev->pm.dpm.thermal_active) {
337 mutex_unlock(&adev->pm.mutex);
340 ret = smu_force_performance_level(&adev->smu, level);
344 adev->pm.dpm.forced_level = level;
345 mutex_unlock(&adev->pm.mutex);
346 } else if (adev->powerplay.pp_funcs->force_performance_level) {
347 mutex_lock(&adev->pm.mutex);
348 if (adev->pm.dpm.thermal_active) {
350 mutex_unlock(&adev->pm.mutex);
353 ret = amdgpu_dpm_force_performance_level(adev, level);
357 adev->pm.dpm.forced_level = level;
358 mutex_unlock(&adev->pm.mutex);
365 static ssize_t amdgpu_get_pp_num_states(struct device *dev,
366 struct device_attribute *attr,
369 struct drm_device *ddev = dev_get_drvdata(dev);
370 struct amdgpu_device *adev = ddev->dev_private;
371 struct pp_states_info data;
374 if (is_support_sw_smu(adev)) {
375 ret = smu_get_power_num_states(&adev->smu, &data);
378 } else if (adev->powerplay.pp_funcs->get_pp_num_states)
379 amdgpu_dpm_get_pp_num_states(adev, &data);
381 buf_len = snprintf(buf, PAGE_SIZE, "states: %d\n", data.nums);
382 for (i = 0; i < data.nums; i++)
383 buf_len += snprintf(buf + buf_len, PAGE_SIZE, "%d %s\n", i,
384 (data.states[i] == POWER_STATE_TYPE_INTERNAL_BOOT) ? "boot" :
385 (data.states[i] == POWER_STATE_TYPE_BATTERY) ? "battery" :
386 (data.states[i] == POWER_STATE_TYPE_BALANCED) ? "balanced" :
387 (data.states[i] == POWER_STATE_TYPE_PERFORMANCE) ? "performance" : "default");
392 static ssize_t amdgpu_get_pp_cur_state(struct device *dev,
393 struct device_attribute *attr,
396 struct drm_device *ddev = dev_get_drvdata(dev);
397 struct amdgpu_device *adev = ddev->dev_private;
398 struct pp_states_info data;
399 struct smu_context *smu = &adev->smu;
400 enum amd_pm_state_type pm = 0;
403 if (is_support_sw_smu(adev)) {
404 pm = smu_get_current_power_state(smu);
405 ret = smu_get_power_num_states(smu, &data);
408 } else if (adev->powerplay.pp_funcs->get_current_power_state
409 && adev->powerplay.pp_funcs->get_pp_num_states) {
410 pm = amdgpu_dpm_get_current_power_state(adev);
411 amdgpu_dpm_get_pp_num_states(adev, &data);
414 for (i = 0; i < data.nums; i++) {
415 if (pm == data.states[i])
422 return snprintf(buf, PAGE_SIZE, "%d\n", i);
425 static ssize_t amdgpu_get_pp_force_state(struct device *dev,
426 struct device_attribute *attr,
429 struct drm_device *ddev = dev_get_drvdata(dev);
430 struct amdgpu_device *adev = ddev->dev_private;
432 if (adev->pp_force_state_enabled)
433 return amdgpu_get_pp_cur_state(dev, attr, buf);
435 return snprintf(buf, PAGE_SIZE, "\n");
438 static ssize_t amdgpu_set_pp_force_state(struct device *dev,
439 struct device_attribute *attr,
443 struct drm_device *ddev = dev_get_drvdata(dev);
444 struct amdgpu_device *adev = ddev->dev_private;
445 enum amd_pm_state_type state = 0;
449 if (strlen(buf) == 1)
450 adev->pp_force_state_enabled = false;
451 else if (is_support_sw_smu(adev))
452 adev->pp_force_state_enabled = false;
453 else if (adev->powerplay.pp_funcs->dispatch_tasks &&
454 adev->powerplay.pp_funcs->get_pp_num_states) {
455 struct pp_states_info data;
457 ret = kstrtoul(buf, 0, &idx);
458 if (ret || idx >= ARRAY_SIZE(data.states)) {
462 idx = array_index_nospec(idx, ARRAY_SIZE(data.states));
464 amdgpu_dpm_get_pp_num_states(adev, &data);
465 state = data.states[idx];
466 /* only set user selected power states */
467 if (state != POWER_STATE_TYPE_INTERNAL_BOOT &&
468 state != POWER_STATE_TYPE_DEFAULT) {
469 amdgpu_dpm_dispatch_task(adev,
470 AMD_PP_TASK_ENABLE_USER_STATE, &state);
471 adev->pp_force_state_enabled = true;
481 * The amdgpu driver provides a sysfs API for uploading new powerplay
482 * tables. The file pp_table is used for this. Reading the file
483 * will dump the current power play table. Writing to the file
484 * will attempt to upload a new powerplay table and re-initialize
485 * powerplay using that new table.
489 static ssize_t amdgpu_get_pp_table(struct device *dev,
490 struct device_attribute *attr,
493 struct drm_device *ddev = dev_get_drvdata(dev);
494 struct amdgpu_device *adev = ddev->dev_private;
498 if (is_support_sw_smu(adev)) {
499 size = smu_sys_get_pp_table(&adev->smu, (void **)&table);
503 else if (adev->powerplay.pp_funcs->get_pp_table)
504 size = amdgpu_dpm_get_pp_table(adev, &table);
508 if (size >= PAGE_SIZE)
509 size = PAGE_SIZE - 1;
511 memcpy(buf, table, size);
516 static ssize_t amdgpu_set_pp_table(struct device *dev,
517 struct device_attribute *attr,
521 struct drm_device *ddev = dev_get_drvdata(dev);
522 struct amdgpu_device *adev = ddev->dev_private;
525 if (is_support_sw_smu(adev)) {
526 ret = smu_sys_set_pp_table(&adev->smu, (void *)buf, count);
529 } else if (adev->powerplay.pp_funcs->set_pp_table)
530 amdgpu_dpm_set_pp_table(adev, buf, count);
536 * DOC: pp_od_clk_voltage
538 * The amdgpu driver provides a sysfs API for adjusting the clocks and voltages
539 * in each power level within a power state. The pp_od_clk_voltage is used for
542 * < For Vega10 and previous ASICs >
544 * Reading the file will display:
546 * - a list of engine clock levels and voltages labeled OD_SCLK
548 * - a list of memory clock levels and voltages labeled OD_MCLK
550 * - a list of valid ranges for sclk, mclk, and voltage labeled OD_RANGE
552 * To manually adjust these settings, first select manual using
553 * power_dpm_force_performance_level. Enter a new value for each
554 * level by writing a string that contains "s/m level clock voltage" to
555 * the file. E.g., "s 1 500 820" will update sclk level 1 to be 500 MHz
556 * at 820 mV; "m 0 350 810" will update mclk level 0 to be 350 MHz at
557 * 810 mV. When you have edited all of the states as needed, write
558 * "c" (commit) to the file to commit your changes. If you want to reset to the
559 * default power levels, write "r" (reset) to the file to reset them.
564 * Reading the file will display:
566 * - minimum and maximum engine clock labeled OD_SCLK
568 * - maximum memory clock labeled OD_MCLK
570 * - three <frequency, voltage> points labeled OD_VDDC_CURVE.
571 * They can be used to calibrate the sclk voltage curve.
573 * - a list of valid ranges for sclk, mclk, and voltage curve points
576 * To manually adjust these settings:
578 * - First select manual using power_dpm_force_performance_level
580 * - For clock frequency setting, enter a new value by writing a
581 * string that contains "s/m index clock" to the file. The index
582 * should be 0 if to set minimum clock. And 1 if to set maximum
583 * clock. E.g., "s 0 500" will update minimum sclk to be 500 MHz.
584 * "m 1 800" will update maximum mclk to be 800Mhz.
586 * For sclk voltage curve, enter the new values by writing a
587 * string that contains "vc point clock voltage" to the file. The
588 * points are indexed by 0, 1 and 2. E.g., "vc 0 300 600" will
589 * update point1 with clock set as 300Mhz and voltage as
590 * 600mV. "vc 2 1000 1000" will update point3 with clock set
591 * as 1000Mhz and voltage 1000mV.
593 * - When you have edited all of the states as needed, write "c" (commit)
594 * to the file to commit your changes
596 * - If you want to reset to the default power levels, write "r" (reset)
597 * to the file to reset them
601 static ssize_t amdgpu_set_pp_od_clk_voltage(struct device *dev,
602 struct device_attribute *attr,
606 struct drm_device *ddev = dev_get_drvdata(dev);
607 struct amdgpu_device *adev = ddev->dev_private;
609 uint32_t parameter_size = 0;
614 const char delimiter[3] = {' ', '\n', '\0'};
621 type = PP_OD_EDIT_SCLK_VDDC_TABLE;
622 else if (*buf == 'm')
623 type = PP_OD_EDIT_MCLK_VDDC_TABLE;
625 type = PP_OD_RESTORE_DEFAULT_TABLE;
626 else if (*buf == 'c')
627 type = PP_OD_COMMIT_DPM_TABLE;
628 else if (!strncmp(buf, "vc", 2))
629 type = PP_OD_EDIT_VDDC_CURVE;
633 memcpy(buf_cpy, buf, count+1);
637 if (type == PP_OD_EDIT_VDDC_CURVE)
639 while (isspace(*++tmp_str));
642 sub_str = strsep(&tmp_str, delimiter);
643 ret = kstrtol(sub_str, 0, ¶meter[parameter_size]);
648 while (isspace(*tmp_str))
652 if (is_support_sw_smu(adev)) {
653 ret = smu_od_edit_dpm_table(&adev->smu, type,
654 parameter, parameter_size);
659 if (adev->powerplay.pp_funcs->odn_edit_dpm_table)
660 ret = amdgpu_dpm_odn_edit_dpm_table(adev, type,
661 parameter, parameter_size);
666 if (type == PP_OD_COMMIT_DPM_TABLE) {
667 if (adev->powerplay.pp_funcs->dispatch_tasks) {
668 amdgpu_dpm_dispatch_task(adev,
669 AMD_PP_TASK_READJUST_POWER_STATE,
681 static ssize_t amdgpu_get_pp_od_clk_voltage(struct device *dev,
682 struct device_attribute *attr,
685 struct drm_device *ddev = dev_get_drvdata(dev);
686 struct amdgpu_device *adev = ddev->dev_private;
689 if (is_support_sw_smu(adev)) {
690 size = smu_print_clk_levels(&adev->smu, OD_SCLK, buf);
691 size += smu_print_clk_levels(&adev->smu, OD_MCLK, buf+size);
692 size += smu_print_clk_levels(&adev->smu, OD_VDDC_CURVE, buf+size);
693 size += smu_print_clk_levels(&adev->smu, OD_RANGE, buf+size);
695 } else if (adev->powerplay.pp_funcs->print_clock_levels) {
696 size = amdgpu_dpm_print_clock_levels(adev, OD_SCLK, buf);
697 size += amdgpu_dpm_print_clock_levels(adev, OD_MCLK, buf+size);
698 size += amdgpu_dpm_print_clock_levels(adev, OD_VDDC_CURVE, buf+size);
699 size += amdgpu_dpm_print_clock_levels(adev, OD_RANGE, buf+size);
702 return snprintf(buf, PAGE_SIZE, "\n");
710 * The amdgpu driver provides a sysfs API for adjusting what powerplay
711 * features to be enabled. The file ppfeatures is used for this. And
712 * this is only available for Vega10 and later dGPUs.
714 * Reading back the file will show you the followings:
715 * - Current ppfeature masks
716 * - List of the all supported powerplay features with their naming,
717 * bitmasks and enablement status('Y'/'N' means "enabled"/"disabled").
719 * To manually enable or disable a specific feature, just set or clear
720 * the corresponding bit from original ppfeature masks and input the
721 * new ppfeature masks.
723 static ssize_t amdgpu_set_ppfeature_status(struct device *dev,
724 struct device_attribute *attr,
728 struct drm_device *ddev = dev_get_drvdata(dev);
729 struct amdgpu_device *adev = ddev->dev_private;
730 uint64_t featuremask;
733 ret = kstrtou64(buf, 0, &featuremask);
737 pr_debug("featuremask = 0x%llx\n", featuremask);
739 if (adev->powerplay.pp_funcs->set_ppfeature_status) {
740 ret = amdgpu_dpm_set_ppfeature_status(adev, featuremask);
748 static ssize_t amdgpu_get_ppfeature_status(struct device *dev,
749 struct device_attribute *attr,
752 struct drm_device *ddev = dev_get_drvdata(dev);
753 struct amdgpu_device *adev = ddev->dev_private;
755 if (adev->powerplay.pp_funcs->get_ppfeature_status)
756 return amdgpu_dpm_get_ppfeature_status(adev, buf);
758 return snprintf(buf, PAGE_SIZE, "\n");
762 * DOC: pp_dpm_sclk pp_dpm_mclk pp_dpm_socclk pp_dpm_fclk pp_dpm_dcefclk
765 * The amdgpu driver provides a sysfs API for adjusting what power levels
766 * are enabled for a given power state. The files pp_dpm_sclk, pp_dpm_mclk,
767 * pp_dpm_socclk, pp_dpm_fclk, pp_dpm_dcefclk and pp_dpm_pcie are used for
770 * pp_dpm_socclk and pp_dpm_dcefclk interfaces are only available for
771 * Vega10 and later ASICs.
772 * pp_dpm_fclk interface is only available for Vega20 and later ASICs.
774 * Reading back the files will show you the available power levels within
775 * the power state and the clock information for those levels.
777 * To manually adjust these states, first select manual using
778 * power_dpm_force_performance_level.
779 * Secondly,Enter a new value for each level by inputing a string that
780 * contains " echo xx xx xx > pp_dpm_sclk/mclk/pcie"
781 * E.g., echo 4 5 6 to > pp_dpm_sclk will enable sclk levels 4, 5, and 6.
783 * NOTE: change to the dcefclk max dpm level is not supported now
786 static ssize_t amdgpu_get_pp_dpm_sclk(struct device *dev,
787 struct device_attribute *attr,
790 struct drm_device *ddev = dev_get_drvdata(dev);
791 struct amdgpu_device *adev = ddev->dev_private;
793 if (is_support_sw_smu(adev))
794 return smu_print_clk_levels(&adev->smu, PP_SCLK, buf);
795 else if (adev->powerplay.pp_funcs->print_clock_levels)
796 return amdgpu_dpm_print_clock_levels(adev, PP_SCLK, buf);
798 return snprintf(buf, PAGE_SIZE, "\n");
802 * Worst case: 32 bits individually specified, in octal at 12 characters
803 * per line (+1 for \n).
805 #define AMDGPU_MASK_BUF_MAX (32 * 13)
807 static ssize_t amdgpu_read_mask(const char *buf, size_t count, uint32_t *mask)
811 char *sub_str = NULL;
813 char buf_cpy[AMDGPU_MASK_BUF_MAX + 1];
814 const char delimiter[3] = {' ', '\n', '\0'};
819 bytes = min(count, sizeof(buf_cpy) - 1);
820 memcpy(buf_cpy, buf, bytes);
821 buf_cpy[bytes] = '\0';
824 sub_str = strsep(&tmp, delimiter);
825 if (strlen(sub_str)) {
826 ret = kstrtol(sub_str, 0, &level);
837 static ssize_t amdgpu_set_pp_dpm_sclk(struct device *dev,
838 struct device_attribute *attr,
842 struct drm_device *ddev = dev_get_drvdata(dev);
843 struct amdgpu_device *adev = ddev->dev_private;
847 ret = amdgpu_read_mask(buf, count, &mask);
851 if (is_support_sw_smu(adev))
852 ret = smu_force_clk_levels(&adev->smu, PP_SCLK, mask);
853 else if (adev->powerplay.pp_funcs->force_clock_level)
854 ret = amdgpu_dpm_force_clock_level(adev, PP_SCLK, mask);
862 static ssize_t amdgpu_get_pp_dpm_mclk(struct device *dev,
863 struct device_attribute *attr,
866 struct drm_device *ddev = dev_get_drvdata(dev);
867 struct amdgpu_device *adev = ddev->dev_private;
869 if (is_support_sw_smu(adev))
870 return smu_print_clk_levels(&adev->smu, PP_MCLK, buf);
871 else if (adev->powerplay.pp_funcs->print_clock_levels)
872 return amdgpu_dpm_print_clock_levels(adev, PP_MCLK, buf);
874 return snprintf(buf, PAGE_SIZE, "\n");
877 static ssize_t amdgpu_set_pp_dpm_mclk(struct device *dev,
878 struct device_attribute *attr,
882 struct drm_device *ddev = dev_get_drvdata(dev);
883 struct amdgpu_device *adev = ddev->dev_private;
887 ret = amdgpu_read_mask(buf, count, &mask);
891 if (is_support_sw_smu(adev))
892 ret = smu_force_clk_levels(&adev->smu, PP_MCLK, mask);
893 else if (adev->powerplay.pp_funcs->force_clock_level)
894 ret = amdgpu_dpm_force_clock_level(adev, PP_MCLK, mask);
902 static ssize_t amdgpu_get_pp_dpm_socclk(struct device *dev,
903 struct device_attribute *attr,
906 struct drm_device *ddev = dev_get_drvdata(dev);
907 struct amdgpu_device *adev = ddev->dev_private;
909 if (is_support_sw_smu(adev))
910 return smu_print_clk_levels(&adev->smu, PP_SOCCLK, buf);
911 else if (adev->powerplay.pp_funcs->print_clock_levels)
912 return amdgpu_dpm_print_clock_levels(adev, PP_SOCCLK, buf);
914 return snprintf(buf, PAGE_SIZE, "\n");
917 static ssize_t amdgpu_set_pp_dpm_socclk(struct device *dev,
918 struct device_attribute *attr,
922 struct drm_device *ddev = dev_get_drvdata(dev);
923 struct amdgpu_device *adev = ddev->dev_private;
927 ret = amdgpu_read_mask(buf, count, &mask);
931 if (adev->powerplay.pp_funcs->force_clock_level)
932 ret = amdgpu_dpm_force_clock_level(adev, PP_SOCCLK, mask);
940 static ssize_t amdgpu_get_pp_dpm_fclk(struct device *dev,
941 struct device_attribute *attr,
944 struct drm_device *ddev = dev_get_drvdata(dev);
945 struct amdgpu_device *adev = ddev->dev_private;
947 if (is_support_sw_smu(adev))
948 return smu_print_clk_levels(&adev->smu, PP_FCLK, buf);
949 else if (adev->powerplay.pp_funcs->print_clock_levels)
950 return amdgpu_dpm_print_clock_levels(adev, PP_FCLK, buf);
952 return snprintf(buf, PAGE_SIZE, "\n");
955 static ssize_t amdgpu_set_pp_dpm_fclk(struct device *dev,
956 struct device_attribute *attr,
960 struct drm_device *ddev = dev_get_drvdata(dev);
961 struct amdgpu_device *adev = ddev->dev_private;
965 ret = amdgpu_read_mask(buf, count, &mask);
969 if (adev->powerplay.pp_funcs->force_clock_level)
970 ret = amdgpu_dpm_force_clock_level(adev, PP_FCLK, mask);
978 static ssize_t amdgpu_get_pp_dpm_dcefclk(struct device *dev,
979 struct device_attribute *attr,
982 struct drm_device *ddev = dev_get_drvdata(dev);
983 struct amdgpu_device *adev = ddev->dev_private;
985 if (is_support_sw_smu(adev))
986 return smu_print_clk_levels(&adev->smu, PP_DCEFCLK, buf);
987 else if (adev->powerplay.pp_funcs->print_clock_levels)
988 return amdgpu_dpm_print_clock_levels(adev, PP_DCEFCLK, buf);
990 return snprintf(buf, PAGE_SIZE, "\n");
993 static ssize_t amdgpu_set_pp_dpm_dcefclk(struct device *dev,
994 struct device_attribute *attr,
998 struct drm_device *ddev = dev_get_drvdata(dev);
999 struct amdgpu_device *adev = ddev->dev_private;
1003 ret = amdgpu_read_mask(buf, count, &mask);
1007 if (adev->powerplay.pp_funcs->force_clock_level)
1008 ret = amdgpu_dpm_force_clock_level(adev, PP_DCEFCLK, mask);
1016 static ssize_t amdgpu_get_pp_dpm_pcie(struct device *dev,
1017 struct device_attribute *attr,
1020 struct drm_device *ddev = dev_get_drvdata(dev);
1021 struct amdgpu_device *adev = ddev->dev_private;
1023 if (is_support_sw_smu(adev))
1024 return smu_print_clk_levels(&adev->smu, PP_PCIE, buf);
1025 else if (adev->powerplay.pp_funcs->print_clock_levels)
1026 return amdgpu_dpm_print_clock_levels(adev, PP_PCIE, buf);
1028 return snprintf(buf, PAGE_SIZE, "\n");
1031 static ssize_t amdgpu_set_pp_dpm_pcie(struct device *dev,
1032 struct device_attribute *attr,
1036 struct drm_device *ddev = dev_get_drvdata(dev);
1037 struct amdgpu_device *adev = ddev->dev_private;
1041 ret = amdgpu_read_mask(buf, count, &mask);
1045 if (is_support_sw_smu(adev))
1046 ret = smu_force_clk_levels(&adev->smu, PP_PCIE, mask);
1047 else if (adev->powerplay.pp_funcs->force_clock_level)
1048 ret = amdgpu_dpm_force_clock_level(adev, PP_PCIE, mask);
1056 static ssize_t amdgpu_get_pp_sclk_od(struct device *dev,
1057 struct device_attribute *attr,
1060 struct drm_device *ddev = dev_get_drvdata(dev);
1061 struct amdgpu_device *adev = ddev->dev_private;
1064 if (is_support_sw_smu(adev))
1065 value = smu_get_od_percentage(&(adev->smu), OD_SCLK);
1066 else if (adev->powerplay.pp_funcs->get_sclk_od)
1067 value = amdgpu_dpm_get_sclk_od(adev);
1069 return snprintf(buf, PAGE_SIZE, "%d\n", value);
1072 static ssize_t amdgpu_set_pp_sclk_od(struct device *dev,
1073 struct device_attribute *attr,
1077 struct drm_device *ddev = dev_get_drvdata(dev);
1078 struct amdgpu_device *adev = ddev->dev_private;
1082 ret = kstrtol(buf, 0, &value);
1089 if (is_support_sw_smu(adev)) {
1090 value = smu_set_od_percentage(&(adev->smu), OD_SCLK, (uint32_t)value);
1092 if (adev->powerplay.pp_funcs->set_sclk_od)
1093 amdgpu_dpm_set_sclk_od(adev, (uint32_t)value);
1095 if (adev->powerplay.pp_funcs->dispatch_tasks) {
1096 amdgpu_dpm_dispatch_task(adev, AMD_PP_TASK_READJUST_POWER_STATE, NULL);
1098 adev->pm.dpm.current_ps = adev->pm.dpm.boot_ps;
1099 amdgpu_pm_compute_clocks(adev);
1107 static ssize_t amdgpu_get_pp_mclk_od(struct device *dev,
1108 struct device_attribute *attr,
1111 struct drm_device *ddev = dev_get_drvdata(dev);
1112 struct amdgpu_device *adev = ddev->dev_private;
1115 if (is_support_sw_smu(adev))
1116 value = smu_get_od_percentage(&(adev->smu), OD_MCLK);
1117 else if (adev->powerplay.pp_funcs->get_mclk_od)
1118 value = amdgpu_dpm_get_mclk_od(adev);
1120 return snprintf(buf, PAGE_SIZE, "%d\n", value);
1123 static ssize_t amdgpu_set_pp_mclk_od(struct device *dev,
1124 struct device_attribute *attr,
1128 struct drm_device *ddev = dev_get_drvdata(dev);
1129 struct amdgpu_device *adev = ddev->dev_private;
1133 ret = kstrtol(buf, 0, &value);
1140 if (is_support_sw_smu(adev)) {
1141 value = smu_set_od_percentage(&(adev->smu), OD_MCLK, (uint32_t)value);
1143 if (adev->powerplay.pp_funcs->set_mclk_od)
1144 amdgpu_dpm_set_mclk_od(adev, (uint32_t)value);
1146 if (adev->powerplay.pp_funcs->dispatch_tasks) {
1147 amdgpu_dpm_dispatch_task(adev, AMD_PP_TASK_READJUST_POWER_STATE, NULL);
1149 adev->pm.dpm.current_ps = adev->pm.dpm.boot_ps;
1150 amdgpu_pm_compute_clocks(adev);
1159 * DOC: pp_power_profile_mode
1161 * The amdgpu driver provides a sysfs API for adjusting the heuristics
1162 * related to switching between power levels in a power state. The file
1163 * pp_power_profile_mode is used for this.
1165 * Reading this file outputs a list of all of the predefined power profiles
1166 * and the relevant heuristics settings for that profile.
1168 * To select a profile or create a custom profile, first select manual using
1169 * power_dpm_force_performance_level. Writing the number of a predefined
1170 * profile to pp_power_profile_mode will enable those heuristics. To
1171 * create a custom set of heuristics, write a string of numbers to the file
1172 * starting with the number of the custom profile along with a setting
1173 * for each heuristic parameter. Due to differences across asic families
1174 * the heuristic parameters vary from family to family.
1178 static ssize_t amdgpu_get_pp_power_profile_mode(struct device *dev,
1179 struct device_attribute *attr,
1182 struct drm_device *ddev = dev_get_drvdata(dev);
1183 struct amdgpu_device *adev = ddev->dev_private;
1185 if (is_support_sw_smu(adev))
1186 return smu_get_power_profile_mode(&adev->smu, buf);
1187 else if (adev->powerplay.pp_funcs->get_power_profile_mode)
1188 return amdgpu_dpm_get_power_profile_mode(adev, buf);
1190 return snprintf(buf, PAGE_SIZE, "\n");
1194 static ssize_t amdgpu_set_pp_power_profile_mode(struct device *dev,
1195 struct device_attribute *attr,
1200 struct drm_device *ddev = dev_get_drvdata(dev);
1201 struct amdgpu_device *adev = ddev->dev_private;
1202 uint32_t parameter_size = 0;
1204 char *sub_str, buf_cpy[128];
1208 long int profile_mode = 0;
1209 const char delimiter[3] = {' ', '\n', '\0'};
1213 ret = kstrtol(tmp, 0, &profile_mode);
1217 if (profile_mode == PP_SMC_POWER_PROFILE_CUSTOM) {
1218 if (count < 2 || count > 127)
1220 while (isspace(*++buf))
1222 memcpy(buf_cpy, buf, count-i);
1224 while (tmp_str[0]) {
1225 sub_str = strsep(&tmp_str, delimiter);
1226 ret = kstrtol(sub_str, 0, ¶meter[parameter_size]);
1232 while (isspace(*tmp_str))
1236 parameter[parameter_size] = profile_mode;
1237 if (is_support_sw_smu(adev))
1238 ret = smu_set_power_profile_mode(&adev->smu, parameter, parameter_size);
1239 else if (adev->powerplay.pp_funcs->set_power_profile_mode)
1240 ret = amdgpu_dpm_set_power_profile_mode(adev, parameter, parameter_size);
1250 * The amdgpu driver provides a sysfs API for reading how busy the GPU
1251 * is as a percentage. The file gpu_busy_percent is used for this.
1252 * The SMU firmware computes a percentage of load based on the
1253 * aggregate activity level in the IP cores.
1255 static ssize_t amdgpu_get_busy_percent(struct device *dev,
1256 struct device_attribute *attr,
1259 struct drm_device *ddev = dev_get_drvdata(dev);
1260 struct amdgpu_device *adev = ddev->dev_private;
1261 int r, value, size = sizeof(value);
1263 /* read the IP busy sensor */
1264 r = amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GPU_LOAD,
1265 (void *)&value, &size);
1270 return snprintf(buf, PAGE_SIZE, "%d\n", value);
1276 * The amdgpu driver provides a sysfs API for estimating how much data
1277 * has been received and sent by the GPU in the last second through PCIe.
1278 * The file pcie_bw is used for this.
1279 * The Perf counters count the number of received and sent messages and return
1280 * those values, as well as the maximum payload size of a PCIe packet (mps).
1281 * Note that it is not possible to easily and quickly obtain the size of each
1282 * packet transmitted, so we output the max payload size (mps) to allow for
1283 * quick estimation of the PCIe bandwidth usage
1285 static ssize_t amdgpu_get_pcie_bw(struct device *dev,
1286 struct device_attribute *attr,
1289 struct drm_device *ddev = dev_get_drvdata(dev);
1290 struct amdgpu_device *adev = ddev->dev_private;
1291 uint64_t count0, count1;
1293 amdgpu_asic_get_pcie_usage(adev, &count0, &count1);
1294 return snprintf(buf, PAGE_SIZE, "%llu %llu %i\n",
1295 count0, count1, pcie_get_mps(adev->pdev));
1298 static DEVICE_ATTR(power_dpm_state, S_IRUGO | S_IWUSR, amdgpu_get_dpm_state, amdgpu_set_dpm_state);
1299 static DEVICE_ATTR(power_dpm_force_performance_level, S_IRUGO | S_IWUSR,
1300 amdgpu_get_dpm_forced_performance_level,
1301 amdgpu_set_dpm_forced_performance_level);
1302 static DEVICE_ATTR(pp_num_states, S_IRUGO, amdgpu_get_pp_num_states, NULL);
1303 static DEVICE_ATTR(pp_cur_state, S_IRUGO, amdgpu_get_pp_cur_state, NULL);
1304 static DEVICE_ATTR(pp_force_state, S_IRUGO | S_IWUSR,
1305 amdgpu_get_pp_force_state,
1306 amdgpu_set_pp_force_state);
1307 static DEVICE_ATTR(pp_table, S_IRUGO | S_IWUSR,
1308 amdgpu_get_pp_table,
1309 amdgpu_set_pp_table);
1310 static DEVICE_ATTR(pp_dpm_sclk, S_IRUGO | S_IWUSR,
1311 amdgpu_get_pp_dpm_sclk,
1312 amdgpu_set_pp_dpm_sclk);
1313 static DEVICE_ATTR(pp_dpm_mclk, S_IRUGO | S_IWUSR,
1314 amdgpu_get_pp_dpm_mclk,
1315 amdgpu_set_pp_dpm_mclk);
1316 static DEVICE_ATTR(pp_dpm_socclk, S_IRUGO | S_IWUSR,
1317 amdgpu_get_pp_dpm_socclk,
1318 amdgpu_set_pp_dpm_socclk);
1319 static DEVICE_ATTR(pp_dpm_fclk, S_IRUGO | S_IWUSR,
1320 amdgpu_get_pp_dpm_fclk,
1321 amdgpu_set_pp_dpm_fclk);
1322 static DEVICE_ATTR(pp_dpm_dcefclk, S_IRUGO | S_IWUSR,
1323 amdgpu_get_pp_dpm_dcefclk,
1324 amdgpu_set_pp_dpm_dcefclk);
1325 static DEVICE_ATTR(pp_dpm_pcie, S_IRUGO | S_IWUSR,
1326 amdgpu_get_pp_dpm_pcie,
1327 amdgpu_set_pp_dpm_pcie);
1328 static DEVICE_ATTR(pp_sclk_od, S_IRUGO | S_IWUSR,
1329 amdgpu_get_pp_sclk_od,
1330 amdgpu_set_pp_sclk_od);
1331 static DEVICE_ATTR(pp_mclk_od, S_IRUGO | S_IWUSR,
1332 amdgpu_get_pp_mclk_od,
1333 amdgpu_set_pp_mclk_od);
1334 static DEVICE_ATTR(pp_power_profile_mode, S_IRUGO | S_IWUSR,
1335 amdgpu_get_pp_power_profile_mode,
1336 amdgpu_set_pp_power_profile_mode);
1337 static DEVICE_ATTR(pp_od_clk_voltage, S_IRUGO | S_IWUSR,
1338 amdgpu_get_pp_od_clk_voltage,
1339 amdgpu_set_pp_od_clk_voltage);
1340 static DEVICE_ATTR(gpu_busy_percent, S_IRUGO,
1341 amdgpu_get_busy_percent, NULL);
1342 static DEVICE_ATTR(pcie_bw, S_IRUGO, amdgpu_get_pcie_bw, NULL);
1343 static DEVICE_ATTR(ppfeatures, S_IRUGO | S_IWUSR,
1344 amdgpu_get_ppfeature_status,
1345 amdgpu_set_ppfeature_status);
1347 static ssize_t amdgpu_hwmon_show_temp(struct device *dev,
1348 struct device_attribute *attr,
1351 struct amdgpu_device *adev = dev_get_drvdata(dev);
1352 struct drm_device *ddev = adev->ddev;
1353 int r, temp, size = sizeof(temp);
1355 /* Can't get temperature when the card is off */
1356 if ((adev->flags & AMD_IS_PX) &&
1357 (ddev->switch_power_state != DRM_SWITCH_POWER_ON))
1360 /* get the temperature */
1361 r = amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GPU_TEMP,
1362 (void *)&temp, &size);
1366 return snprintf(buf, PAGE_SIZE, "%d\n", temp);
1369 static ssize_t amdgpu_hwmon_show_temp_thresh(struct device *dev,
1370 struct device_attribute *attr,
1373 struct amdgpu_device *adev = dev_get_drvdata(dev);
1374 int hyst = to_sensor_dev_attr(attr)->index;
1378 temp = adev->pm.dpm.thermal.min_temp;
1380 temp = adev->pm.dpm.thermal.max_temp;
1382 return snprintf(buf, PAGE_SIZE, "%d\n", temp);
1385 static ssize_t amdgpu_hwmon_get_pwm1_enable(struct device *dev,
1386 struct device_attribute *attr,
1389 struct amdgpu_device *adev = dev_get_drvdata(dev);
1391 if (is_support_sw_smu(adev)) {
1392 pwm_mode = smu_get_fan_control_mode(&adev->smu);
1394 if (!adev->powerplay.pp_funcs->get_fan_control_mode)
1397 pwm_mode = amdgpu_dpm_get_fan_control_mode(adev);
1400 return sprintf(buf, "%i\n", pwm_mode);
1403 static ssize_t amdgpu_hwmon_set_pwm1_enable(struct device *dev,
1404 struct device_attribute *attr,
1408 struct amdgpu_device *adev = dev_get_drvdata(dev);
1412 /* Can't adjust fan when the card is off */
1413 if ((adev->flags & AMD_IS_PX) &&
1414 (adev->ddev->switch_power_state != DRM_SWITCH_POWER_ON))
1417 if (is_support_sw_smu(adev)) {
1418 err = kstrtoint(buf, 10, &value);
1422 smu_set_fan_control_mode(&adev->smu, value);
1424 if (!adev->powerplay.pp_funcs->set_fan_control_mode)
1427 err = kstrtoint(buf, 10, &value);
1431 amdgpu_dpm_set_fan_control_mode(adev, value);
1437 static ssize_t amdgpu_hwmon_get_pwm1_min(struct device *dev,
1438 struct device_attribute *attr,
1441 return sprintf(buf, "%i\n", 0);
1444 static ssize_t amdgpu_hwmon_get_pwm1_max(struct device *dev,
1445 struct device_attribute *attr,
1448 return sprintf(buf, "%i\n", 255);
1451 static ssize_t amdgpu_hwmon_set_pwm1(struct device *dev,
1452 struct device_attribute *attr,
1453 const char *buf, size_t count)
1455 struct amdgpu_device *adev = dev_get_drvdata(dev);
1460 /* Can't adjust fan when the card is off */
1461 if ((adev->flags & AMD_IS_PX) &&
1462 (adev->ddev->switch_power_state != DRM_SWITCH_POWER_ON))
1464 if (is_support_sw_smu(adev))
1465 pwm_mode = smu_get_fan_control_mode(&adev->smu);
1467 pwm_mode = amdgpu_dpm_get_fan_control_mode(adev);
1468 if (pwm_mode != AMD_FAN_CTRL_MANUAL) {
1469 pr_info("manual fan speed control should be enabled first\n");
1473 err = kstrtou32(buf, 10, &value);
1477 value = (value * 100) / 255;
1479 if (is_support_sw_smu(adev)) {
1480 err = smu_set_fan_speed_percent(&adev->smu, value);
1483 } else if (adev->powerplay.pp_funcs->set_fan_speed_percent) {
1484 err = amdgpu_dpm_set_fan_speed_percent(adev, value);
1492 static ssize_t amdgpu_hwmon_get_pwm1(struct device *dev,
1493 struct device_attribute *attr,
1496 struct amdgpu_device *adev = dev_get_drvdata(dev);
1500 /* Can't adjust fan when the card is off */
1501 if ((adev->flags & AMD_IS_PX) &&
1502 (adev->ddev->switch_power_state != DRM_SWITCH_POWER_ON))
1505 if (is_support_sw_smu(adev)) {
1506 err = smu_get_fan_speed_percent(&adev->smu, &speed);
1509 } else if (adev->powerplay.pp_funcs->get_fan_speed_percent) {
1510 err = amdgpu_dpm_get_fan_speed_percent(adev, &speed);
1515 speed = (speed * 255) / 100;
1517 return sprintf(buf, "%i\n", speed);
1520 static ssize_t amdgpu_hwmon_get_fan1_input(struct device *dev,
1521 struct device_attribute *attr,
1524 struct amdgpu_device *adev = dev_get_drvdata(dev);
1528 /* Can't adjust fan when the card is off */
1529 if ((adev->flags & AMD_IS_PX) &&
1530 (adev->ddev->switch_power_state != DRM_SWITCH_POWER_ON))
1533 if (is_support_sw_smu(adev)) {
1534 err = smu_get_current_rpm(&adev->smu, &speed);
1537 } else if (adev->powerplay.pp_funcs->get_fan_speed_rpm) {
1538 err = amdgpu_dpm_get_fan_speed_rpm(adev, &speed);
1543 return sprintf(buf, "%i\n", speed);
1546 static ssize_t amdgpu_hwmon_get_fan1_min(struct device *dev,
1547 struct device_attribute *attr,
1550 struct amdgpu_device *adev = dev_get_drvdata(dev);
1552 u32 size = sizeof(min_rpm);
1555 r = amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_MIN_FAN_RPM,
1556 (void *)&min_rpm, &size);
1560 return snprintf(buf, PAGE_SIZE, "%d\n", min_rpm);
1563 static ssize_t amdgpu_hwmon_get_fan1_max(struct device *dev,
1564 struct device_attribute *attr,
1567 struct amdgpu_device *adev = dev_get_drvdata(dev);
1569 u32 size = sizeof(max_rpm);
1572 r = amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_MAX_FAN_RPM,
1573 (void *)&max_rpm, &size);
1577 return snprintf(buf, PAGE_SIZE, "%d\n", max_rpm);
1580 static ssize_t amdgpu_hwmon_get_fan1_target(struct device *dev,
1581 struct device_attribute *attr,
1584 struct amdgpu_device *adev = dev_get_drvdata(dev);
1588 /* Can't adjust fan when the card is off */
1589 if ((adev->flags & AMD_IS_PX) &&
1590 (adev->ddev->switch_power_state != DRM_SWITCH_POWER_ON))
1593 if (is_support_sw_smu(adev)) {
1594 err = smu_get_current_rpm(&adev->smu, &rpm);
1597 } else if (adev->powerplay.pp_funcs->get_fan_speed_rpm) {
1598 err = amdgpu_dpm_get_fan_speed_rpm(adev, &rpm);
1603 return sprintf(buf, "%i\n", rpm);
1606 static ssize_t amdgpu_hwmon_set_fan1_target(struct device *dev,
1607 struct device_attribute *attr,
1608 const char *buf, size_t count)
1610 struct amdgpu_device *adev = dev_get_drvdata(dev);
1615 if (is_support_sw_smu(adev))
1616 pwm_mode = smu_get_fan_control_mode(&adev->smu);
1618 pwm_mode = amdgpu_dpm_get_fan_control_mode(adev);
1620 if (pwm_mode != AMD_FAN_CTRL_MANUAL)
1623 /* Can't adjust fan when the card is off */
1624 if ((adev->flags & AMD_IS_PX) &&
1625 (adev->ddev->switch_power_state != DRM_SWITCH_POWER_ON))
1628 err = kstrtou32(buf, 10, &value);
1632 if (is_support_sw_smu(adev)) {
1633 err = smu_set_fan_speed_rpm(&adev->smu, value);
1636 } else if (adev->powerplay.pp_funcs->set_fan_speed_rpm) {
1637 err = amdgpu_dpm_set_fan_speed_rpm(adev, value);
1645 static ssize_t amdgpu_hwmon_get_fan1_enable(struct device *dev,
1646 struct device_attribute *attr,
1649 struct amdgpu_device *adev = dev_get_drvdata(dev);
1652 if (is_support_sw_smu(adev)) {
1653 pwm_mode = smu_get_fan_control_mode(&adev->smu);
1655 if (!adev->powerplay.pp_funcs->get_fan_control_mode)
1658 pwm_mode = amdgpu_dpm_get_fan_control_mode(adev);
1660 return sprintf(buf, "%i\n", pwm_mode == AMD_FAN_CTRL_AUTO ? 0 : 1);
1663 static ssize_t amdgpu_hwmon_set_fan1_enable(struct device *dev,
1664 struct device_attribute *attr,
1668 struct amdgpu_device *adev = dev_get_drvdata(dev);
1673 /* Can't adjust fan when the card is off */
1674 if ((adev->flags & AMD_IS_PX) &&
1675 (adev->ddev->switch_power_state != DRM_SWITCH_POWER_ON))
1679 err = kstrtoint(buf, 10, &value);
1684 pwm_mode = AMD_FAN_CTRL_AUTO;
1685 else if (value == 1)
1686 pwm_mode = AMD_FAN_CTRL_MANUAL;
1690 if (is_support_sw_smu(adev)) {
1691 smu_set_fan_control_mode(&adev->smu, pwm_mode);
1693 if (!adev->powerplay.pp_funcs->set_fan_control_mode)
1695 amdgpu_dpm_set_fan_control_mode(adev, pwm_mode);
1701 static ssize_t amdgpu_hwmon_show_vddgfx(struct device *dev,
1702 struct device_attribute *attr,
1705 struct amdgpu_device *adev = dev_get_drvdata(dev);
1706 struct drm_device *ddev = adev->ddev;
1708 int r, size = sizeof(vddgfx);
1710 /* Can't get voltage when the card is off */
1711 if ((adev->flags & AMD_IS_PX) &&
1712 (ddev->switch_power_state != DRM_SWITCH_POWER_ON))
1715 /* get the voltage */
1716 r = amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_VDDGFX,
1717 (void *)&vddgfx, &size);
1721 return snprintf(buf, PAGE_SIZE, "%d\n", vddgfx);
1724 static ssize_t amdgpu_hwmon_show_vddgfx_label(struct device *dev,
1725 struct device_attribute *attr,
1728 return snprintf(buf, PAGE_SIZE, "vddgfx\n");
1731 static ssize_t amdgpu_hwmon_show_vddnb(struct device *dev,
1732 struct device_attribute *attr,
1735 struct amdgpu_device *adev = dev_get_drvdata(dev);
1736 struct drm_device *ddev = adev->ddev;
1738 int r, size = sizeof(vddnb);
1740 /* only APUs have vddnb */
1741 if (!(adev->flags & AMD_IS_APU))
1744 /* Can't get voltage when the card is off */
1745 if ((adev->flags & AMD_IS_PX) &&
1746 (ddev->switch_power_state != DRM_SWITCH_POWER_ON))
1749 /* get the voltage */
1750 r = amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_VDDNB,
1751 (void *)&vddnb, &size);
1755 return snprintf(buf, PAGE_SIZE, "%d\n", vddnb);
1758 static ssize_t amdgpu_hwmon_show_vddnb_label(struct device *dev,
1759 struct device_attribute *attr,
1762 return snprintf(buf, PAGE_SIZE, "vddnb\n");
1765 static ssize_t amdgpu_hwmon_show_power_avg(struct device *dev,
1766 struct device_attribute *attr,
1769 struct amdgpu_device *adev = dev_get_drvdata(dev);
1770 struct drm_device *ddev = adev->ddev;
1772 int r, size = sizeof(u32);
1775 /* Can't get power when the card is off */
1776 if ((adev->flags & AMD_IS_PX) &&
1777 (ddev->switch_power_state != DRM_SWITCH_POWER_ON))
1780 /* get the voltage */
1781 r = amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GPU_POWER,
1782 (void *)&query, &size);
1786 /* convert to microwatts */
1787 uw = (query >> 8) * 1000000 + (query & 0xff) * 1000;
1789 return snprintf(buf, PAGE_SIZE, "%u\n", uw);
1792 static ssize_t amdgpu_hwmon_show_power_cap_min(struct device *dev,
1793 struct device_attribute *attr,
1796 return sprintf(buf, "%i\n", 0);
1799 static ssize_t amdgpu_hwmon_show_power_cap_max(struct device *dev,
1800 struct device_attribute *attr,
1803 struct amdgpu_device *adev = dev_get_drvdata(dev);
1806 if (is_support_sw_smu(adev)) {
1807 smu_get_power_limit(&adev->smu, &limit, true);
1808 return snprintf(buf, PAGE_SIZE, "%u\n", limit * 1000000);
1809 } else if (adev->powerplay.pp_funcs && adev->powerplay.pp_funcs->get_power_limit) {
1810 adev->powerplay.pp_funcs->get_power_limit(adev->powerplay.pp_handle, &limit, true);
1811 return snprintf(buf, PAGE_SIZE, "%u\n", limit * 1000000);
1813 return snprintf(buf, PAGE_SIZE, "\n");
1817 static ssize_t amdgpu_hwmon_show_power_cap(struct device *dev,
1818 struct device_attribute *attr,
1821 struct amdgpu_device *adev = dev_get_drvdata(dev);
1824 if (is_support_sw_smu(adev)) {
1825 smu_get_power_limit(&adev->smu, &limit, false);
1826 return snprintf(buf, PAGE_SIZE, "%u\n", limit * 1000000);
1827 } else if (adev->powerplay.pp_funcs && adev->powerplay.pp_funcs->get_power_limit) {
1828 adev->powerplay.pp_funcs->get_power_limit(adev->powerplay.pp_handle, &limit, false);
1829 return snprintf(buf, PAGE_SIZE, "%u\n", limit * 1000000);
1831 return snprintf(buf, PAGE_SIZE, "\n");
1836 static ssize_t amdgpu_hwmon_set_power_cap(struct device *dev,
1837 struct device_attribute *attr,
1841 struct amdgpu_device *adev = dev_get_drvdata(dev);
1845 err = kstrtou32(buf, 10, &value);
1849 value = value / 1000000; /* convert to Watt */
1850 if (is_support_sw_smu(adev)) {
1851 adev->smu.funcs->set_power_limit(&adev->smu, value);
1852 } else if (adev->powerplay.pp_funcs && adev->powerplay.pp_funcs->set_power_limit) {
1853 err = adev->powerplay.pp_funcs->set_power_limit(adev->powerplay.pp_handle, value);
1863 static ssize_t amdgpu_hwmon_show_sclk(struct device *dev,
1864 struct device_attribute *attr,
1867 struct amdgpu_device *adev = dev_get_drvdata(dev);
1868 struct drm_device *ddev = adev->ddev;
1870 int r, size = sizeof(sclk);
1872 /* Can't get voltage when the card is off */
1873 if ((adev->flags & AMD_IS_PX) &&
1874 (ddev->switch_power_state != DRM_SWITCH_POWER_ON))
1877 /* sanity check PP is enabled */
1878 if (!(adev->powerplay.pp_funcs &&
1879 adev->powerplay.pp_funcs->read_sensor))
1883 r = amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GFX_SCLK,
1884 (void *)&sclk, &size);
1888 return snprintf(buf, PAGE_SIZE, "%d\n", sclk * 10 * 1000);
1891 static ssize_t amdgpu_hwmon_show_sclk_label(struct device *dev,
1892 struct device_attribute *attr,
1895 return snprintf(buf, PAGE_SIZE, "sclk\n");
1898 static ssize_t amdgpu_hwmon_show_mclk(struct device *dev,
1899 struct device_attribute *attr,
1902 struct amdgpu_device *adev = dev_get_drvdata(dev);
1903 struct drm_device *ddev = adev->ddev;
1905 int r, size = sizeof(mclk);
1907 /* Can't get voltage when the card is off */
1908 if ((adev->flags & AMD_IS_PX) &&
1909 (ddev->switch_power_state != DRM_SWITCH_POWER_ON))
1912 /* sanity check PP is enabled */
1913 if (!(adev->powerplay.pp_funcs &&
1914 adev->powerplay.pp_funcs->read_sensor))
1918 r = amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GFX_MCLK,
1919 (void *)&mclk, &size);
1923 return snprintf(buf, PAGE_SIZE, "%d\n", mclk * 10 * 1000);
1926 static ssize_t amdgpu_hwmon_show_mclk_label(struct device *dev,
1927 struct device_attribute *attr,
1930 return snprintf(buf, PAGE_SIZE, "mclk\n");
1936 * The amdgpu driver exposes the following sensor interfaces:
1938 * - GPU temperature (via the on-die sensor)
1942 * - Northbridge voltage (APUs only)
1948 * - GPU gfx/compute engine clock
1950 * - GPU memory clock (dGPU only)
1952 * hwmon interfaces for GPU temperature:
1954 * - temp1_input: the on die GPU temperature in millidegrees Celsius
1956 * - temp1_crit: temperature critical max value in millidegrees Celsius
1958 * - temp1_crit_hyst: temperature hysteresis for critical limit in millidegrees Celsius
1960 * hwmon interfaces for GPU voltage:
1962 * - in0_input: the voltage on the GPU in millivolts
1964 * - in1_input: the voltage on the Northbridge in millivolts
1966 * hwmon interfaces for GPU power:
1968 * - power1_average: average power used by the GPU in microWatts
1970 * - power1_cap_min: minimum cap supported in microWatts
1972 * - power1_cap_max: maximum cap supported in microWatts
1974 * - power1_cap: selected power cap in microWatts
1976 * hwmon interfaces for GPU fan:
1978 * - pwm1: pulse width modulation fan level (0-255)
1980 * - 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)
1982 * - pwm1_min: pulse width modulation fan control minimum level (0)
1984 * - pwm1_max: pulse width modulation fan control maximum level (255)
1986 * - fan1_min: an minimum value Unit: revolution/min (RPM)
1988 * - fan1_max: an maxmum value Unit: revolution/max (RPM)
1990 * - fan1_input: fan speed in RPM
1992 * - fan[1-*]_target: Desired fan speed Unit: revolution/min (RPM)
1994 * - fan[1-*]_enable: Enable or disable the sensors.1: Enable 0: Disable
1996 * hwmon interfaces for GPU clocks:
1998 * - freq1_input: the gfx/compute clock in hertz
2000 * - freq2_input: the memory clock in hertz
2002 * You can use hwmon tools like sensors to view this information on your system.
2006 static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, amdgpu_hwmon_show_temp, NULL, 0);
2007 static SENSOR_DEVICE_ATTR(temp1_crit, S_IRUGO, amdgpu_hwmon_show_temp_thresh, NULL, 0);
2008 static SENSOR_DEVICE_ATTR(temp1_crit_hyst, S_IRUGO, amdgpu_hwmon_show_temp_thresh, NULL, 1);
2009 static SENSOR_DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, amdgpu_hwmon_get_pwm1, amdgpu_hwmon_set_pwm1, 0);
2010 static SENSOR_DEVICE_ATTR(pwm1_enable, S_IRUGO | S_IWUSR, amdgpu_hwmon_get_pwm1_enable, amdgpu_hwmon_set_pwm1_enable, 0);
2011 static SENSOR_DEVICE_ATTR(pwm1_min, S_IRUGO, amdgpu_hwmon_get_pwm1_min, NULL, 0);
2012 static SENSOR_DEVICE_ATTR(pwm1_max, S_IRUGO, amdgpu_hwmon_get_pwm1_max, NULL, 0);
2013 static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, amdgpu_hwmon_get_fan1_input, NULL, 0);
2014 static SENSOR_DEVICE_ATTR(fan1_min, S_IRUGO, amdgpu_hwmon_get_fan1_min, NULL, 0);
2015 static SENSOR_DEVICE_ATTR(fan1_max, S_IRUGO, amdgpu_hwmon_get_fan1_max, NULL, 0);
2016 static SENSOR_DEVICE_ATTR(fan1_target, S_IRUGO | S_IWUSR, amdgpu_hwmon_get_fan1_target, amdgpu_hwmon_set_fan1_target, 0);
2017 static SENSOR_DEVICE_ATTR(fan1_enable, S_IRUGO | S_IWUSR, amdgpu_hwmon_get_fan1_enable, amdgpu_hwmon_set_fan1_enable, 0);
2018 static SENSOR_DEVICE_ATTR(in0_input, S_IRUGO, amdgpu_hwmon_show_vddgfx, NULL, 0);
2019 static SENSOR_DEVICE_ATTR(in0_label, S_IRUGO, amdgpu_hwmon_show_vddgfx_label, NULL, 0);
2020 static SENSOR_DEVICE_ATTR(in1_input, S_IRUGO, amdgpu_hwmon_show_vddnb, NULL, 0);
2021 static SENSOR_DEVICE_ATTR(in1_label, S_IRUGO, amdgpu_hwmon_show_vddnb_label, NULL, 0);
2022 static SENSOR_DEVICE_ATTR(power1_average, S_IRUGO, amdgpu_hwmon_show_power_avg, NULL, 0);
2023 static SENSOR_DEVICE_ATTR(power1_cap_max, S_IRUGO, amdgpu_hwmon_show_power_cap_max, NULL, 0);
2024 static SENSOR_DEVICE_ATTR(power1_cap_min, S_IRUGO, amdgpu_hwmon_show_power_cap_min, NULL, 0);
2025 static SENSOR_DEVICE_ATTR(power1_cap, S_IRUGO | S_IWUSR, amdgpu_hwmon_show_power_cap, amdgpu_hwmon_set_power_cap, 0);
2026 static SENSOR_DEVICE_ATTR(freq1_input, S_IRUGO, amdgpu_hwmon_show_sclk, NULL, 0);
2027 static SENSOR_DEVICE_ATTR(freq1_label, S_IRUGO, amdgpu_hwmon_show_sclk_label, NULL, 0);
2028 static SENSOR_DEVICE_ATTR(freq2_input, S_IRUGO, amdgpu_hwmon_show_mclk, NULL, 0);
2029 static SENSOR_DEVICE_ATTR(freq2_label, S_IRUGO, amdgpu_hwmon_show_mclk_label, NULL, 0);
2031 static struct attribute *hwmon_attributes[] = {
2032 &sensor_dev_attr_temp1_input.dev_attr.attr,
2033 &sensor_dev_attr_temp1_crit.dev_attr.attr,
2034 &sensor_dev_attr_temp1_crit_hyst.dev_attr.attr,
2035 &sensor_dev_attr_pwm1.dev_attr.attr,
2036 &sensor_dev_attr_pwm1_enable.dev_attr.attr,
2037 &sensor_dev_attr_pwm1_min.dev_attr.attr,
2038 &sensor_dev_attr_pwm1_max.dev_attr.attr,
2039 &sensor_dev_attr_fan1_input.dev_attr.attr,
2040 &sensor_dev_attr_fan1_min.dev_attr.attr,
2041 &sensor_dev_attr_fan1_max.dev_attr.attr,
2042 &sensor_dev_attr_fan1_target.dev_attr.attr,
2043 &sensor_dev_attr_fan1_enable.dev_attr.attr,
2044 &sensor_dev_attr_in0_input.dev_attr.attr,
2045 &sensor_dev_attr_in0_label.dev_attr.attr,
2046 &sensor_dev_attr_in1_input.dev_attr.attr,
2047 &sensor_dev_attr_in1_label.dev_attr.attr,
2048 &sensor_dev_attr_power1_average.dev_attr.attr,
2049 &sensor_dev_attr_power1_cap_max.dev_attr.attr,
2050 &sensor_dev_attr_power1_cap_min.dev_attr.attr,
2051 &sensor_dev_attr_power1_cap.dev_attr.attr,
2052 &sensor_dev_attr_freq1_input.dev_attr.attr,
2053 &sensor_dev_attr_freq1_label.dev_attr.attr,
2054 &sensor_dev_attr_freq2_input.dev_attr.attr,
2055 &sensor_dev_attr_freq2_label.dev_attr.attr,
2059 static umode_t hwmon_attributes_visible(struct kobject *kobj,
2060 struct attribute *attr, int index)
2062 struct device *dev = kobj_to_dev(kobj);
2063 struct amdgpu_device *adev = dev_get_drvdata(dev);
2064 umode_t effective_mode = attr->mode;
2066 /* Skip fan attributes if fan is not present */
2067 if (adev->pm.no_fan && (attr == &sensor_dev_attr_pwm1.dev_attr.attr ||
2068 attr == &sensor_dev_attr_pwm1_enable.dev_attr.attr ||
2069 attr == &sensor_dev_attr_pwm1_max.dev_attr.attr ||
2070 attr == &sensor_dev_attr_pwm1_min.dev_attr.attr ||
2071 attr == &sensor_dev_attr_fan1_input.dev_attr.attr ||
2072 attr == &sensor_dev_attr_fan1_min.dev_attr.attr ||
2073 attr == &sensor_dev_attr_fan1_max.dev_attr.attr ||
2074 attr == &sensor_dev_attr_fan1_target.dev_attr.attr ||
2075 attr == &sensor_dev_attr_fan1_enable.dev_attr.attr))
2078 /* Skip fan attributes on APU */
2079 if ((adev->flags & AMD_IS_APU) &&
2080 (attr == &sensor_dev_attr_pwm1.dev_attr.attr ||
2081 attr == &sensor_dev_attr_pwm1_enable.dev_attr.attr ||
2082 attr == &sensor_dev_attr_pwm1_max.dev_attr.attr ||
2083 attr == &sensor_dev_attr_pwm1_min.dev_attr.attr ||
2084 attr == &sensor_dev_attr_fan1_input.dev_attr.attr ||
2085 attr == &sensor_dev_attr_fan1_min.dev_attr.attr ||
2086 attr == &sensor_dev_attr_fan1_max.dev_attr.attr ||
2087 attr == &sensor_dev_attr_fan1_target.dev_attr.attr ||
2088 attr == &sensor_dev_attr_fan1_enable.dev_attr.attr))
2091 /* Skip limit attributes if DPM is not enabled */
2092 if (!adev->pm.dpm_enabled &&
2093 (attr == &sensor_dev_attr_temp1_crit.dev_attr.attr ||
2094 attr == &sensor_dev_attr_temp1_crit_hyst.dev_attr.attr ||
2095 attr == &sensor_dev_attr_pwm1.dev_attr.attr ||
2096 attr == &sensor_dev_attr_pwm1_enable.dev_attr.attr ||
2097 attr == &sensor_dev_attr_pwm1_max.dev_attr.attr ||
2098 attr == &sensor_dev_attr_pwm1_min.dev_attr.attr ||
2099 attr == &sensor_dev_attr_fan1_input.dev_attr.attr ||
2100 attr == &sensor_dev_attr_fan1_min.dev_attr.attr ||
2101 attr == &sensor_dev_attr_fan1_max.dev_attr.attr ||
2102 attr == &sensor_dev_attr_fan1_target.dev_attr.attr ||
2103 attr == &sensor_dev_attr_fan1_enable.dev_attr.attr))
2106 if (!is_support_sw_smu(adev)) {
2107 /* mask fan attributes if we have no bindings for this asic to expose */
2108 if ((!adev->powerplay.pp_funcs->get_fan_speed_percent &&
2109 attr == &sensor_dev_attr_pwm1.dev_attr.attr) || /* can't query fan */
2110 (!adev->powerplay.pp_funcs->get_fan_control_mode &&
2111 attr == &sensor_dev_attr_pwm1_enable.dev_attr.attr)) /* can't query state */
2112 effective_mode &= ~S_IRUGO;
2114 if ((!adev->powerplay.pp_funcs->set_fan_speed_percent &&
2115 attr == &sensor_dev_attr_pwm1.dev_attr.attr) || /* can't manage fan */
2116 (!adev->powerplay.pp_funcs->set_fan_control_mode &&
2117 attr == &sensor_dev_attr_pwm1_enable.dev_attr.attr)) /* can't manage state */
2118 effective_mode &= ~S_IWUSR;
2121 if ((adev->flags & AMD_IS_APU) &&
2122 (attr == &sensor_dev_attr_power1_average.dev_attr.attr ||
2123 attr == &sensor_dev_attr_power1_cap_max.dev_attr.attr ||
2124 attr == &sensor_dev_attr_power1_cap_min.dev_attr.attr||
2125 attr == &sensor_dev_attr_power1_cap.dev_attr.attr))
2128 if (!is_support_sw_smu(adev)) {
2129 /* hide max/min values if we can't both query and manage the fan */
2130 if ((!adev->powerplay.pp_funcs->set_fan_speed_percent &&
2131 !adev->powerplay.pp_funcs->get_fan_speed_percent) &&
2132 (!adev->powerplay.pp_funcs->set_fan_speed_rpm &&
2133 !adev->powerplay.pp_funcs->get_fan_speed_rpm) &&
2134 (attr == &sensor_dev_attr_pwm1_max.dev_attr.attr ||
2135 attr == &sensor_dev_attr_pwm1_min.dev_attr.attr))
2138 if ((!adev->powerplay.pp_funcs->set_fan_speed_rpm &&
2139 !adev->powerplay.pp_funcs->get_fan_speed_rpm) &&
2140 (attr == &sensor_dev_attr_fan1_max.dev_attr.attr ||
2141 attr == &sensor_dev_attr_fan1_min.dev_attr.attr))
2145 /* only APUs have vddnb */
2146 if (!(adev->flags & AMD_IS_APU) &&
2147 (attr == &sensor_dev_attr_in1_input.dev_attr.attr ||
2148 attr == &sensor_dev_attr_in1_label.dev_attr.attr))
2151 /* no mclk on APUs */
2152 if ((adev->flags & AMD_IS_APU) &&
2153 (attr == &sensor_dev_attr_freq2_input.dev_attr.attr ||
2154 attr == &sensor_dev_attr_freq2_label.dev_attr.attr))
2157 return effective_mode;
2160 static const struct attribute_group hwmon_attrgroup = {
2161 .attrs = hwmon_attributes,
2162 .is_visible = hwmon_attributes_visible,
2165 static const struct attribute_group *hwmon_groups[] = {
2170 void amdgpu_dpm_thermal_work_handler(struct work_struct *work)
2172 struct amdgpu_device *adev =
2173 container_of(work, struct amdgpu_device,
2174 pm.dpm.thermal.work);
2175 /* switch to the thermal state */
2176 enum amd_pm_state_type dpm_state = POWER_STATE_TYPE_INTERNAL_THERMAL;
2177 int temp, size = sizeof(temp);
2179 if (!adev->pm.dpm_enabled)
2182 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GPU_TEMP,
2183 (void *)&temp, &size)) {
2184 if (temp < adev->pm.dpm.thermal.min_temp)
2185 /* switch back the user state */
2186 dpm_state = adev->pm.dpm.user_state;
2188 if (adev->pm.dpm.thermal.high_to_low)
2189 /* switch back the user state */
2190 dpm_state = adev->pm.dpm.user_state;
2192 mutex_lock(&adev->pm.mutex);
2193 if (dpm_state == POWER_STATE_TYPE_INTERNAL_THERMAL)
2194 adev->pm.dpm.thermal_active = true;
2196 adev->pm.dpm.thermal_active = false;
2197 adev->pm.dpm.state = dpm_state;
2198 mutex_unlock(&adev->pm.mutex);
2200 amdgpu_pm_compute_clocks(adev);
2203 static struct amdgpu_ps *amdgpu_dpm_pick_power_state(struct amdgpu_device *adev,
2204 enum amd_pm_state_type dpm_state)
2207 struct amdgpu_ps *ps;
2209 bool single_display = (adev->pm.dpm.new_active_crtc_count < 2) ?
2212 /* check if the vblank period is too short to adjust the mclk */
2213 if (single_display && adev->powerplay.pp_funcs->vblank_too_short) {
2214 if (amdgpu_dpm_vblank_too_short(adev))
2215 single_display = false;
2218 /* certain older asics have a separare 3D performance state,
2219 * so try that first if the user selected performance
2221 if (dpm_state == POWER_STATE_TYPE_PERFORMANCE)
2222 dpm_state = POWER_STATE_TYPE_INTERNAL_3DPERF;
2223 /* balanced states don't exist at the moment */
2224 if (dpm_state == POWER_STATE_TYPE_BALANCED)
2225 dpm_state = POWER_STATE_TYPE_PERFORMANCE;
2228 /* Pick the best power state based on current conditions */
2229 for (i = 0; i < adev->pm.dpm.num_ps; i++) {
2230 ps = &adev->pm.dpm.ps[i];
2231 ui_class = ps->class & ATOM_PPLIB_CLASSIFICATION_UI_MASK;
2232 switch (dpm_state) {
2234 case POWER_STATE_TYPE_BATTERY:
2235 if (ui_class == ATOM_PPLIB_CLASSIFICATION_UI_BATTERY) {
2236 if (ps->caps & ATOM_PPLIB_SINGLE_DISPLAY_ONLY) {
2243 case POWER_STATE_TYPE_BALANCED:
2244 if (ui_class == ATOM_PPLIB_CLASSIFICATION_UI_BALANCED) {
2245 if (ps->caps & ATOM_PPLIB_SINGLE_DISPLAY_ONLY) {
2252 case POWER_STATE_TYPE_PERFORMANCE:
2253 if (ui_class == ATOM_PPLIB_CLASSIFICATION_UI_PERFORMANCE) {
2254 if (ps->caps & ATOM_PPLIB_SINGLE_DISPLAY_ONLY) {
2261 /* internal states */
2262 case POWER_STATE_TYPE_INTERNAL_UVD:
2263 if (adev->pm.dpm.uvd_ps)
2264 return adev->pm.dpm.uvd_ps;
2267 case POWER_STATE_TYPE_INTERNAL_UVD_SD:
2268 if (ps->class & ATOM_PPLIB_CLASSIFICATION_SDSTATE)
2271 case POWER_STATE_TYPE_INTERNAL_UVD_HD:
2272 if (ps->class & ATOM_PPLIB_CLASSIFICATION_HDSTATE)
2275 case POWER_STATE_TYPE_INTERNAL_UVD_HD2:
2276 if (ps->class & ATOM_PPLIB_CLASSIFICATION_HD2STATE)
2279 case POWER_STATE_TYPE_INTERNAL_UVD_MVC:
2280 if (ps->class2 & ATOM_PPLIB_CLASSIFICATION2_MVC)
2283 case POWER_STATE_TYPE_INTERNAL_BOOT:
2284 return adev->pm.dpm.boot_ps;
2285 case POWER_STATE_TYPE_INTERNAL_THERMAL:
2286 if (ps->class & ATOM_PPLIB_CLASSIFICATION_THERMAL)
2289 case POWER_STATE_TYPE_INTERNAL_ACPI:
2290 if (ps->class & ATOM_PPLIB_CLASSIFICATION_ACPI)
2293 case POWER_STATE_TYPE_INTERNAL_ULV:
2294 if (ps->class2 & ATOM_PPLIB_CLASSIFICATION2_ULV)
2297 case POWER_STATE_TYPE_INTERNAL_3DPERF:
2298 if (ps->class & ATOM_PPLIB_CLASSIFICATION_3DPERFORMANCE)
2305 /* use a fallback state if we didn't match */
2306 switch (dpm_state) {
2307 case POWER_STATE_TYPE_INTERNAL_UVD_SD:
2308 dpm_state = POWER_STATE_TYPE_INTERNAL_UVD_HD;
2309 goto restart_search;
2310 case POWER_STATE_TYPE_INTERNAL_UVD_HD:
2311 case POWER_STATE_TYPE_INTERNAL_UVD_HD2:
2312 case POWER_STATE_TYPE_INTERNAL_UVD_MVC:
2313 if (adev->pm.dpm.uvd_ps) {
2314 return adev->pm.dpm.uvd_ps;
2316 dpm_state = POWER_STATE_TYPE_PERFORMANCE;
2317 goto restart_search;
2319 case POWER_STATE_TYPE_INTERNAL_THERMAL:
2320 dpm_state = POWER_STATE_TYPE_INTERNAL_ACPI;
2321 goto restart_search;
2322 case POWER_STATE_TYPE_INTERNAL_ACPI:
2323 dpm_state = POWER_STATE_TYPE_BATTERY;
2324 goto restart_search;
2325 case POWER_STATE_TYPE_BATTERY:
2326 case POWER_STATE_TYPE_BALANCED:
2327 case POWER_STATE_TYPE_INTERNAL_3DPERF:
2328 dpm_state = POWER_STATE_TYPE_PERFORMANCE;
2329 goto restart_search;
2337 static void amdgpu_dpm_change_power_state_locked(struct amdgpu_device *adev)
2339 struct amdgpu_ps *ps;
2340 enum amd_pm_state_type dpm_state;
2344 /* if dpm init failed */
2345 if (!adev->pm.dpm_enabled)
2348 if (adev->pm.dpm.user_state != adev->pm.dpm.state) {
2349 /* add other state override checks here */
2350 if ((!adev->pm.dpm.thermal_active) &&
2351 (!adev->pm.dpm.uvd_active))
2352 adev->pm.dpm.state = adev->pm.dpm.user_state;
2354 dpm_state = adev->pm.dpm.state;
2356 ps = amdgpu_dpm_pick_power_state(adev, dpm_state);
2358 adev->pm.dpm.requested_ps = ps;
2362 if (amdgpu_dpm == 1 && adev->powerplay.pp_funcs->print_power_state) {
2363 printk("switching from power state:\n");
2364 amdgpu_dpm_print_power_state(adev, adev->pm.dpm.current_ps);
2365 printk("switching to power state:\n");
2366 amdgpu_dpm_print_power_state(adev, adev->pm.dpm.requested_ps);
2369 /* update whether vce is active */
2370 ps->vce_active = adev->pm.dpm.vce_active;
2371 if (adev->powerplay.pp_funcs->display_configuration_changed)
2372 amdgpu_dpm_display_configuration_changed(adev);
2374 ret = amdgpu_dpm_pre_set_power_state(adev);
2378 if (adev->powerplay.pp_funcs->check_state_equal) {
2379 if (0 != amdgpu_dpm_check_state_equal(adev, adev->pm.dpm.current_ps, adev->pm.dpm.requested_ps, &equal))
2386 amdgpu_dpm_set_power_state(adev);
2387 amdgpu_dpm_post_set_power_state(adev);
2389 adev->pm.dpm.current_active_crtcs = adev->pm.dpm.new_active_crtcs;
2390 adev->pm.dpm.current_active_crtc_count = adev->pm.dpm.new_active_crtc_count;
2392 if (adev->powerplay.pp_funcs->force_performance_level) {
2393 if (adev->pm.dpm.thermal_active) {
2394 enum amd_dpm_forced_level level = adev->pm.dpm.forced_level;
2395 /* force low perf level for thermal */
2396 amdgpu_dpm_force_performance_level(adev, AMD_DPM_FORCED_LEVEL_LOW);
2397 /* save the user's level */
2398 adev->pm.dpm.forced_level = level;
2400 /* otherwise, user selected level */
2401 amdgpu_dpm_force_performance_level(adev, adev->pm.dpm.forced_level);
2406 void amdgpu_dpm_enable_uvd(struct amdgpu_device *adev, bool enable)
2409 if (is_support_sw_smu(adev)) {
2410 ret = smu_dpm_set_power_gate(&adev->smu, AMD_IP_BLOCK_TYPE_UVD, enable);
2412 DRM_ERROR("[SW SMU]: dpm enable uvd failed, state = %s, ret = %d. \n",
2413 enable ? "true" : "false", ret);
2414 } else if (adev->powerplay.pp_funcs->set_powergating_by_smu) {
2415 /* enable/disable UVD */
2416 mutex_lock(&adev->pm.mutex);
2417 amdgpu_dpm_set_powergating_by_smu(adev, AMD_IP_BLOCK_TYPE_UVD, !enable);
2418 mutex_unlock(&adev->pm.mutex);
2420 /* enable/disable Low Memory PState for UVD (4k videos) */
2421 if (adev->asic_type == CHIP_STONEY &&
2422 adev->uvd.decode_image_width >= WIDTH_4K) {
2423 struct pp_hwmgr *hwmgr = adev->powerplay.pp_handle;
2425 if (hwmgr && hwmgr->hwmgr_func &&
2426 hwmgr->hwmgr_func->update_nbdpm_pstate)
2427 hwmgr->hwmgr_func->update_nbdpm_pstate(hwmgr,
2433 void amdgpu_dpm_enable_vce(struct amdgpu_device *adev, bool enable)
2436 if (is_support_sw_smu(adev)) {
2437 ret = smu_dpm_set_power_gate(&adev->smu, AMD_IP_BLOCK_TYPE_VCE, enable);
2439 DRM_ERROR("[SW SMU]: dpm enable vce failed, state = %s, ret = %d. \n",
2440 enable ? "true" : "false", ret);
2441 } else if (adev->powerplay.pp_funcs->set_powergating_by_smu) {
2442 /* enable/disable VCE */
2443 mutex_lock(&adev->pm.mutex);
2444 amdgpu_dpm_set_powergating_by_smu(adev, AMD_IP_BLOCK_TYPE_VCE, !enable);
2445 mutex_unlock(&adev->pm.mutex);
2449 void amdgpu_pm_print_power_states(struct amdgpu_device *adev)
2453 if (adev->powerplay.pp_funcs->print_power_state == NULL)
2456 for (i = 0; i < adev->pm.dpm.num_ps; i++)
2457 amdgpu_dpm_print_power_state(adev, &adev->pm.dpm.ps[i]);
2461 int amdgpu_pm_sysfs_init(struct amdgpu_device *adev)
2463 struct pp_hwmgr *hwmgr = adev->powerplay.pp_handle;
2466 if (adev->pm.sysfs_initialized)
2469 if (adev->pm.dpm_enabled == 0)
2472 adev->pm.int_hwmon_dev = hwmon_device_register_with_groups(adev->dev,
2475 if (IS_ERR(adev->pm.int_hwmon_dev)) {
2476 ret = PTR_ERR(adev->pm.int_hwmon_dev);
2478 "Unable to register hwmon device: %d\n", ret);
2482 ret = device_create_file(adev->dev, &dev_attr_power_dpm_state);
2484 DRM_ERROR("failed to create device file for dpm state\n");
2487 ret = device_create_file(adev->dev, &dev_attr_power_dpm_force_performance_level);
2489 DRM_ERROR("failed to create device file for dpm state\n");
2494 ret = device_create_file(adev->dev, &dev_attr_pp_num_states);
2496 DRM_ERROR("failed to create device file pp_num_states\n");
2499 ret = device_create_file(adev->dev, &dev_attr_pp_cur_state);
2501 DRM_ERROR("failed to create device file pp_cur_state\n");
2504 ret = device_create_file(adev->dev, &dev_attr_pp_force_state);
2506 DRM_ERROR("failed to create device file pp_force_state\n");
2509 ret = device_create_file(adev->dev, &dev_attr_pp_table);
2511 DRM_ERROR("failed to create device file pp_table\n");
2515 ret = device_create_file(adev->dev, &dev_attr_pp_dpm_sclk);
2517 DRM_ERROR("failed to create device file pp_dpm_sclk\n");
2520 ret = device_create_file(adev->dev, &dev_attr_pp_dpm_mclk);
2522 DRM_ERROR("failed to create device file pp_dpm_mclk\n");
2525 if (adev->asic_type >= CHIP_VEGA10) {
2526 ret = device_create_file(adev->dev, &dev_attr_pp_dpm_socclk);
2528 DRM_ERROR("failed to create device file pp_dpm_socclk\n");
2531 ret = device_create_file(adev->dev, &dev_attr_pp_dpm_dcefclk);
2533 DRM_ERROR("failed to create device file pp_dpm_dcefclk\n");
2537 if (adev->asic_type >= CHIP_VEGA20) {
2538 ret = device_create_file(adev->dev, &dev_attr_pp_dpm_fclk);
2540 DRM_ERROR("failed to create device file pp_dpm_fclk\n");
2544 ret = device_create_file(adev->dev, &dev_attr_pp_dpm_pcie);
2546 DRM_ERROR("failed to create device file pp_dpm_pcie\n");
2549 ret = device_create_file(adev->dev, &dev_attr_pp_sclk_od);
2551 DRM_ERROR("failed to create device file pp_sclk_od\n");
2554 ret = device_create_file(adev->dev, &dev_attr_pp_mclk_od);
2556 DRM_ERROR("failed to create device file pp_mclk_od\n");
2559 ret = device_create_file(adev->dev,
2560 &dev_attr_pp_power_profile_mode);
2562 DRM_ERROR("failed to create device file "
2563 "pp_power_profile_mode\n");
2566 if (is_support_sw_smu(adev) || hwmgr->od_enabled) {
2567 ret = device_create_file(adev->dev,
2568 &dev_attr_pp_od_clk_voltage);
2570 DRM_ERROR("failed to create device file "
2571 "pp_od_clk_voltage\n");
2575 ret = device_create_file(adev->dev,
2576 &dev_attr_gpu_busy_percent);
2578 DRM_ERROR("failed to create device file "
2579 "gpu_busy_level\n");
2582 /* PCIe Perf counters won't work on APU nodes */
2583 if (!(adev->flags & AMD_IS_APU)) {
2584 ret = device_create_file(adev->dev, &dev_attr_pcie_bw);
2586 DRM_ERROR("failed to create device file pcie_bw\n");
2590 ret = amdgpu_debugfs_pm_init(adev);
2592 DRM_ERROR("Failed to register debugfs file for dpm!\n");
2596 if ((adev->asic_type >= CHIP_VEGA10) &&
2597 !(adev->flags & AMD_IS_APU)) {
2598 ret = device_create_file(adev->dev,
2599 &dev_attr_ppfeatures);
2601 DRM_ERROR("failed to create device file "
2607 adev->pm.sysfs_initialized = true;
2612 void amdgpu_pm_sysfs_fini(struct amdgpu_device *adev)
2614 struct pp_hwmgr *hwmgr = adev->powerplay.pp_handle;
2616 if (adev->pm.dpm_enabled == 0)
2619 if (adev->pm.int_hwmon_dev)
2620 hwmon_device_unregister(adev->pm.int_hwmon_dev);
2621 device_remove_file(adev->dev, &dev_attr_power_dpm_state);
2622 device_remove_file(adev->dev, &dev_attr_power_dpm_force_performance_level);
2624 device_remove_file(adev->dev, &dev_attr_pp_num_states);
2625 device_remove_file(adev->dev, &dev_attr_pp_cur_state);
2626 device_remove_file(adev->dev, &dev_attr_pp_force_state);
2627 device_remove_file(adev->dev, &dev_attr_pp_table);
2629 device_remove_file(adev->dev, &dev_attr_pp_dpm_sclk);
2630 device_remove_file(adev->dev, &dev_attr_pp_dpm_mclk);
2631 if (adev->asic_type >= CHIP_VEGA10) {
2632 device_remove_file(adev->dev, &dev_attr_pp_dpm_socclk);
2633 device_remove_file(adev->dev, &dev_attr_pp_dpm_dcefclk);
2635 device_remove_file(adev->dev, &dev_attr_pp_dpm_pcie);
2636 if (adev->asic_type >= CHIP_VEGA20)
2637 device_remove_file(adev->dev, &dev_attr_pp_dpm_fclk);
2638 device_remove_file(adev->dev, &dev_attr_pp_sclk_od);
2639 device_remove_file(adev->dev, &dev_attr_pp_mclk_od);
2640 device_remove_file(adev->dev,
2641 &dev_attr_pp_power_profile_mode);
2642 if (hwmgr->od_enabled)
2643 device_remove_file(adev->dev,
2644 &dev_attr_pp_od_clk_voltage);
2645 device_remove_file(adev->dev, &dev_attr_gpu_busy_percent);
2646 if (!(adev->flags & AMD_IS_APU))
2647 device_remove_file(adev->dev, &dev_attr_pcie_bw);
2648 if ((adev->asic_type >= CHIP_VEGA10) &&
2649 !(adev->flags & AMD_IS_APU))
2650 device_remove_file(adev->dev, &dev_attr_ppfeatures);
2653 void amdgpu_pm_compute_clocks(struct amdgpu_device *adev)
2657 if (!adev->pm.dpm_enabled)
2660 if (adev->mode_info.num_crtc)
2661 amdgpu_display_bandwidth_update(adev);
2663 for (i = 0; i < AMDGPU_MAX_RINGS; i++) {
2664 struct amdgpu_ring *ring = adev->rings[i];
2665 if (ring && ring->sched.ready)
2666 amdgpu_fence_wait_empty(ring);
2669 if (is_support_sw_smu(adev)) {
2670 struct smu_context *smu = &adev->smu;
2671 struct smu_dpm_context *smu_dpm = &adev->smu.smu_dpm;
2672 mutex_lock(&(smu->mutex));
2673 smu_handle_task(&adev->smu,
2675 AMD_PP_TASK_DISPLAY_CONFIG_CHANGE);
2676 mutex_unlock(&(smu->mutex));
2678 if (adev->powerplay.pp_funcs->dispatch_tasks) {
2679 if (!amdgpu_device_has_dc_support(adev)) {
2680 mutex_lock(&adev->pm.mutex);
2681 amdgpu_dpm_get_active_displays(adev);
2682 adev->pm.pm_display_cfg.num_display = adev->pm.dpm.new_active_crtc_count;
2683 adev->pm.pm_display_cfg.vrefresh = amdgpu_dpm_get_vrefresh(adev);
2684 adev->pm.pm_display_cfg.min_vblank_time = amdgpu_dpm_get_vblank_time(adev);
2685 /* we have issues with mclk switching with refresh rates over 120 hz on the non-DC code. */
2686 if (adev->pm.pm_display_cfg.vrefresh > 120)
2687 adev->pm.pm_display_cfg.min_vblank_time = 0;
2688 if (adev->powerplay.pp_funcs->display_configuration_change)
2689 adev->powerplay.pp_funcs->display_configuration_change(
2690 adev->powerplay.pp_handle,
2691 &adev->pm.pm_display_cfg);
2692 mutex_unlock(&adev->pm.mutex);
2694 amdgpu_dpm_dispatch_task(adev, AMD_PP_TASK_DISPLAY_CONFIG_CHANGE, NULL);
2696 mutex_lock(&adev->pm.mutex);
2697 amdgpu_dpm_get_active_displays(adev);
2698 amdgpu_dpm_change_power_state_locked(adev);
2699 mutex_unlock(&adev->pm.mutex);
2707 #if defined(CONFIG_DEBUG_FS)
2709 static int amdgpu_debugfs_pm_info_pp(struct seq_file *m, struct amdgpu_device *adev)
2717 size = sizeof(value);
2718 seq_printf(m, "GFX Clocks and Power:\n");
2719 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GFX_MCLK, (void *)&value, &size))
2720 seq_printf(m, "\t%u MHz (MCLK)\n", value/100);
2721 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GFX_SCLK, (void *)&value, &size))
2722 seq_printf(m, "\t%u MHz (SCLK)\n", value/100);
2723 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_STABLE_PSTATE_SCLK, (void *)&value, &size))
2724 seq_printf(m, "\t%u MHz (PSTATE_SCLK)\n", value/100);
2725 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_STABLE_PSTATE_MCLK, (void *)&value, &size))
2726 seq_printf(m, "\t%u MHz (PSTATE_MCLK)\n", value/100);
2727 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_VDDGFX, (void *)&value, &size))
2728 seq_printf(m, "\t%u mV (VDDGFX)\n", value);
2729 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_VDDNB, (void *)&value, &size))
2730 seq_printf(m, "\t%u mV (VDDNB)\n", value);
2731 size = sizeof(uint32_t);
2732 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GPU_POWER, (void *)&query, &size))
2733 seq_printf(m, "\t%u.%u W (average GPU)\n", query >> 8, query & 0xff);
2734 size = sizeof(value);
2735 seq_printf(m, "\n");
2738 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GPU_TEMP, (void *)&value, &size))
2739 seq_printf(m, "GPU Temperature: %u C\n", value/1000);
2742 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GPU_LOAD, (void *)&value, &size))
2743 seq_printf(m, "GPU Load: %u %%\n", value);
2744 seq_printf(m, "\n");
2746 /* SMC feature mask */
2747 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_ENABLED_SMC_FEATURES_MASK, (void *)&value64, &size))
2748 seq_printf(m, "SMC Feature Mask: 0x%016llx\n", value64);
2751 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_UVD_POWER, (void *)&value, &size)) {
2753 seq_printf(m, "UVD: Disabled\n");
2755 seq_printf(m, "UVD: Enabled\n");
2756 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_UVD_DCLK, (void *)&value, &size))
2757 seq_printf(m, "\t%u MHz (DCLK)\n", value/100);
2758 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_UVD_VCLK, (void *)&value, &size))
2759 seq_printf(m, "\t%u MHz (VCLK)\n", value/100);
2762 seq_printf(m, "\n");
2765 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_VCE_POWER, (void *)&value, &size)) {
2767 seq_printf(m, "VCE: Disabled\n");
2769 seq_printf(m, "VCE: Enabled\n");
2770 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_VCE_ECCLK, (void *)&value, &size))
2771 seq_printf(m, "\t%u MHz (ECCLK)\n", value/100);
2778 static void amdgpu_parse_cg_state(struct seq_file *m, u32 flags)
2782 for (i = 0; clocks[i].flag; i++)
2783 seq_printf(m, "\t%s: %s\n", clocks[i].name,
2784 (flags & clocks[i].flag) ? "On" : "Off");
2787 static int amdgpu_debugfs_pm_info(struct seq_file *m, void *data)
2789 struct drm_info_node *node = (struct drm_info_node *) m->private;
2790 struct drm_device *dev = node->minor->dev;
2791 struct amdgpu_device *adev = dev->dev_private;
2792 struct drm_device *ddev = adev->ddev;
2795 amdgpu_device_ip_get_clockgating_state(adev, &flags);
2796 seq_printf(m, "Clock Gating Flags Mask: 0x%x\n", flags);
2797 amdgpu_parse_cg_state(m, flags);
2798 seq_printf(m, "\n");
2800 if (!adev->pm.dpm_enabled) {
2801 seq_printf(m, "dpm not enabled\n");
2804 if ((adev->flags & AMD_IS_PX) &&
2805 (ddev->switch_power_state != DRM_SWITCH_POWER_ON)) {
2806 seq_printf(m, "PX asic powered off\n");
2807 } else if (!is_support_sw_smu(adev) && adev->powerplay.pp_funcs->debugfs_print_current_performance_level) {
2808 mutex_lock(&adev->pm.mutex);
2809 if (adev->powerplay.pp_funcs->debugfs_print_current_performance_level)
2810 adev->powerplay.pp_funcs->debugfs_print_current_performance_level(adev, m);
2812 seq_printf(m, "Debugfs support not implemented for this asic\n");
2813 mutex_unlock(&adev->pm.mutex);
2815 return amdgpu_debugfs_pm_info_pp(m, adev);
2821 static const struct drm_info_list amdgpu_pm_info_list[] = {
2822 {"amdgpu_pm_info", amdgpu_debugfs_pm_info, 0, NULL},
2826 static int amdgpu_debugfs_pm_init(struct amdgpu_device *adev)
2828 #if defined(CONFIG_DEBUG_FS)
2829 return amdgpu_debugfs_add_files(adev, amdgpu_pm_info_list, ARRAY_SIZE(amdgpu_pm_info_list));