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_smu.h"
34 #include <linux/pci.h>
35 #include <linux/hwmon.h>
36 #include <linux/hwmon-sysfs.h>
37 #include <linux/nospec.h>
38 #include <linux/pm_runtime.h>
41 static const struct cg_flag_name clocks[] = {
42 {AMD_CG_SUPPORT_GFX_MGCG, "Graphics Medium Grain Clock Gating"},
43 {AMD_CG_SUPPORT_GFX_MGLS, "Graphics Medium Grain memory Light Sleep"},
44 {AMD_CG_SUPPORT_GFX_CGCG, "Graphics Coarse Grain Clock Gating"},
45 {AMD_CG_SUPPORT_GFX_CGLS, "Graphics Coarse Grain memory Light Sleep"},
46 {AMD_CG_SUPPORT_GFX_CGTS, "Graphics Coarse Grain Tree Shader Clock Gating"},
47 {AMD_CG_SUPPORT_GFX_CGTS_LS, "Graphics Coarse Grain Tree Shader Light Sleep"},
48 {AMD_CG_SUPPORT_GFX_CP_LS, "Graphics Command Processor Light Sleep"},
49 {AMD_CG_SUPPORT_GFX_RLC_LS, "Graphics Run List Controller Light Sleep"},
50 {AMD_CG_SUPPORT_GFX_3D_CGCG, "Graphics 3D Coarse Grain Clock Gating"},
51 {AMD_CG_SUPPORT_GFX_3D_CGLS, "Graphics 3D Coarse Grain memory Light Sleep"},
52 {AMD_CG_SUPPORT_MC_LS, "Memory Controller Light Sleep"},
53 {AMD_CG_SUPPORT_MC_MGCG, "Memory Controller Medium Grain Clock Gating"},
54 {AMD_CG_SUPPORT_SDMA_LS, "System Direct Memory Access Light Sleep"},
55 {AMD_CG_SUPPORT_SDMA_MGCG, "System Direct Memory Access Medium Grain Clock Gating"},
56 {AMD_CG_SUPPORT_BIF_MGCG, "Bus Interface Medium Grain Clock Gating"},
57 {AMD_CG_SUPPORT_BIF_LS, "Bus Interface Light Sleep"},
58 {AMD_CG_SUPPORT_UVD_MGCG, "Unified Video Decoder Medium Grain Clock Gating"},
59 {AMD_CG_SUPPORT_VCE_MGCG, "Video Compression Engine Medium Grain Clock Gating"},
60 {AMD_CG_SUPPORT_HDP_LS, "Host Data Path Light Sleep"},
61 {AMD_CG_SUPPORT_HDP_MGCG, "Host Data Path Medium Grain Clock Gating"},
62 {AMD_CG_SUPPORT_DRM_MGCG, "Digital Right Management Medium Grain Clock Gating"},
63 {AMD_CG_SUPPORT_DRM_LS, "Digital Right Management Light Sleep"},
64 {AMD_CG_SUPPORT_ROM_MGCG, "Rom Medium Grain Clock Gating"},
65 {AMD_CG_SUPPORT_DF_MGCG, "Data Fabric Medium Grain Clock Gating"},
67 {AMD_CG_SUPPORT_ATHUB_MGCG, "Address Translation Hub Medium Grain Clock Gating"},
68 {AMD_CG_SUPPORT_ATHUB_LS, "Address Translation Hub Light Sleep"},
72 static const struct hwmon_temp_label {
73 enum PP_HWMON_TEMP channel;
76 {PP_TEMP_EDGE, "edge"},
77 {PP_TEMP_JUNCTION, "junction"},
82 * DOC: power_dpm_state
84 * The power_dpm_state file is a legacy interface and is only provided for
85 * backwards compatibility. The amdgpu driver provides a sysfs API for adjusting
86 * certain power related parameters. The file power_dpm_state is used for this.
87 * It accepts the following arguments:
97 * On older GPUs, the vbios provided a special power state for battery
98 * operation. Selecting battery switched to this state. This is no
99 * longer provided on newer GPUs so the option does nothing in that case.
103 * On older GPUs, the vbios provided a special power state for balanced
104 * operation. Selecting balanced switched to this state. This is no
105 * longer provided on newer GPUs so the option does nothing in that case.
109 * On older GPUs, the vbios provided a special power state for performance
110 * operation. Selecting performance switched to this state. This is no
111 * longer provided on newer GPUs so the option does nothing in that case.
115 static ssize_t amdgpu_get_power_dpm_state(struct device *dev,
116 struct device_attribute *attr,
119 struct drm_device *ddev = dev_get_drvdata(dev);
120 struct amdgpu_device *adev = drm_to_adev(ddev);
121 enum amd_pm_state_type pm;
124 if (amdgpu_in_reset(adev))
127 ret = pm_runtime_get_sync(ddev->dev);
129 pm_runtime_put_autosuspend(ddev->dev);
133 if (is_support_sw_smu(adev)) {
134 if (adev->smu.ppt_funcs->get_current_power_state)
135 pm = smu_get_current_power_state(&adev->smu);
137 pm = adev->pm.dpm.user_state;
138 } else if (adev->powerplay.pp_funcs->get_current_power_state) {
139 pm = amdgpu_dpm_get_current_power_state(adev);
141 pm = adev->pm.dpm.user_state;
144 pm_runtime_mark_last_busy(ddev->dev);
145 pm_runtime_put_autosuspend(ddev->dev);
147 return snprintf(buf, PAGE_SIZE, "%s\n",
148 (pm == POWER_STATE_TYPE_BATTERY) ? "battery" :
149 (pm == POWER_STATE_TYPE_BALANCED) ? "balanced" : "performance");
152 static ssize_t amdgpu_set_power_dpm_state(struct device *dev,
153 struct device_attribute *attr,
157 struct drm_device *ddev = dev_get_drvdata(dev);
158 struct amdgpu_device *adev = drm_to_adev(ddev);
159 enum amd_pm_state_type state;
162 if (amdgpu_in_reset(adev))
165 if (strncmp("battery", buf, strlen("battery")) == 0)
166 state = POWER_STATE_TYPE_BATTERY;
167 else if (strncmp("balanced", buf, strlen("balanced")) == 0)
168 state = POWER_STATE_TYPE_BALANCED;
169 else if (strncmp("performance", buf, strlen("performance")) == 0)
170 state = POWER_STATE_TYPE_PERFORMANCE;
174 ret = pm_runtime_get_sync(ddev->dev);
176 pm_runtime_put_autosuspend(ddev->dev);
180 if (is_support_sw_smu(adev)) {
181 mutex_lock(&adev->pm.mutex);
182 adev->pm.dpm.user_state = state;
183 mutex_unlock(&adev->pm.mutex);
184 } else if (adev->powerplay.pp_funcs->dispatch_tasks) {
185 amdgpu_dpm_dispatch_task(adev, AMD_PP_TASK_ENABLE_USER_STATE, &state);
187 mutex_lock(&adev->pm.mutex);
188 adev->pm.dpm.user_state = state;
189 mutex_unlock(&adev->pm.mutex);
191 amdgpu_pm_compute_clocks(adev);
193 pm_runtime_mark_last_busy(ddev->dev);
194 pm_runtime_put_autosuspend(ddev->dev);
201 * DOC: power_dpm_force_performance_level
203 * The amdgpu driver provides a sysfs API for adjusting certain power
204 * related parameters. The file power_dpm_force_performance_level is
205 * used for this. It accepts the following arguments:
225 * When auto is selected, the driver will attempt to dynamically select
226 * the optimal power profile for current conditions in the driver.
230 * When low is selected, the clocks are forced to the lowest power state.
234 * When high is selected, the clocks are forced to the highest power state.
238 * When manual is selected, the user can manually adjust which power states
239 * are enabled for each clock domain via the sysfs pp_dpm_mclk, pp_dpm_sclk,
240 * and pp_dpm_pcie files and adjust the power state transition heuristics
241 * via the pp_power_profile_mode sysfs file.
248 * When the profiling modes are selected, clock and power gating are
249 * disabled and the clocks are set for different profiling cases. This
250 * mode is recommended for profiling specific work loads where you do
251 * not want clock or power gating for clock fluctuation to interfere
252 * with your results. profile_standard sets the clocks to a fixed clock
253 * level which varies from asic to asic. profile_min_sclk forces the sclk
254 * to the lowest level. profile_min_mclk forces the mclk to the lowest level.
255 * profile_peak sets all clocks (mclk, sclk, pcie) to the highest levels.
259 static ssize_t amdgpu_get_power_dpm_force_performance_level(struct device *dev,
260 struct device_attribute *attr,
263 struct drm_device *ddev = dev_get_drvdata(dev);
264 struct amdgpu_device *adev = drm_to_adev(ddev);
265 enum amd_dpm_forced_level level = 0xff;
268 if (amdgpu_in_reset(adev))
271 ret = pm_runtime_get_sync(ddev->dev);
273 pm_runtime_put_autosuspend(ddev->dev);
277 if (is_support_sw_smu(adev))
278 level = smu_get_performance_level(&adev->smu);
279 else if (adev->powerplay.pp_funcs->get_performance_level)
280 level = amdgpu_dpm_get_performance_level(adev);
282 level = adev->pm.dpm.forced_level;
284 pm_runtime_mark_last_busy(ddev->dev);
285 pm_runtime_put_autosuspend(ddev->dev);
287 return snprintf(buf, PAGE_SIZE, "%s\n",
288 (level == AMD_DPM_FORCED_LEVEL_AUTO) ? "auto" :
289 (level == AMD_DPM_FORCED_LEVEL_LOW) ? "low" :
290 (level == AMD_DPM_FORCED_LEVEL_HIGH) ? "high" :
291 (level == AMD_DPM_FORCED_LEVEL_MANUAL) ? "manual" :
292 (level == AMD_DPM_FORCED_LEVEL_PROFILE_STANDARD) ? "profile_standard" :
293 (level == AMD_DPM_FORCED_LEVEL_PROFILE_MIN_SCLK) ? "profile_min_sclk" :
294 (level == AMD_DPM_FORCED_LEVEL_PROFILE_MIN_MCLK) ? "profile_min_mclk" :
295 (level == AMD_DPM_FORCED_LEVEL_PROFILE_PEAK) ? "profile_peak" :
299 static ssize_t amdgpu_set_power_dpm_force_performance_level(struct device *dev,
300 struct device_attribute *attr,
304 struct drm_device *ddev = dev_get_drvdata(dev);
305 struct amdgpu_device *adev = drm_to_adev(ddev);
306 enum amd_dpm_forced_level level;
307 enum amd_dpm_forced_level current_level = 0xff;
310 if (amdgpu_in_reset(adev))
313 if (strncmp("low", buf, strlen("low")) == 0) {
314 level = AMD_DPM_FORCED_LEVEL_LOW;
315 } else if (strncmp("high", buf, strlen("high")) == 0) {
316 level = AMD_DPM_FORCED_LEVEL_HIGH;
317 } else if (strncmp("auto", buf, strlen("auto")) == 0) {
318 level = AMD_DPM_FORCED_LEVEL_AUTO;
319 } else if (strncmp("manual", buf, strlen("manual")) == 0) {
320 level = AMD_DPM_FORCED_LEVEL_MANUAL;
321 } else if (strncmp("profile_exit", buf, strlen("profile_exit")) == 0) {
322 level = AMD_DPM_FORCED_LEVEL_PROFILE_EXIT;
323 } else if (strncmp("profile_standard", buf, strlen("profile_standard")) == 0) {
324 level = AMD_DPM_FORCED_LEVEL_PROFILE_STANDARD;
325 } else if (strncmp("profile_min_sclk", buf, strlen("profile_min_sclk")) == 0) {
326 level = AMD_DPM_FORCED_LEVEL_PROFILE_MIN_SCLK;
327 } else if (strncmp("profile_min_mclk", buf, strlen("profile_min_mclk")) == 0) {
328 level = AMD_DPM_FORCED_LEVEL_PROFILE_MIN_MCLK;
329 } else if (strncmp("profile_peak", buf, strlen("profile_peak")) == 0) {
330 level = AMD_DPM_FORCED_LEVEL_PROFILE_PEAK;
335 ret = pm_runtime_get_sync(ddev->dev);
337 pm_runtime_put_autosuspend(ddev->dev);
341 if (is_support_sw_smu(adev))
342 current_level = smu_get_performance_level(&adev->smu);
343 else if (adev->powerplay.pp_funcs->get_performance_level)
344 current_level = amdgpu_dpm_get_performance_level(adev);
346 if (current_level == level) {
347 pm_runtime_mark_last_busy(ddev->dev);
348 pm_runtime_put_autosuspend(ddev->dev);
352 if (adev->asic_type == CHIP_RAVEN) {
353 if (!(adev->apu_flags & AMD_APU_IS_RAVEN2)) {
354 if (current_level != AMD_DPM_FORCED_LEVEL_MANUAL && level == AMD_DPM_FORCED_LEVEL_MANUAL)
355 amdgpu_gfx_off_ctrl(adev, false);
356 else if (current_level == AMD_DPM_FORCED_LEVEL_MANUAL && level != AMD_DPM_FORCED_LEVEL_MANUAL)
357 amdgpu_gfx_off_ctrl(adev, true);
361 /* profile_exit setting is valid only when current mode is in profile mode */
362 if (!(current_level & (AMD_DPM_FORCED_LEVEL_PROFILE_STANDARD |
363 AMD_DPM_FORCED_LEVEL_PROFILE_MIN_SCLK |
364 AMD_DPM_FORCED_LEVEL_PROFILE_MIN_MCLK |
365 AMD_DPM_FORCED_LEVEL_PROFILE_PEAK)) &&
366 (level == AMD_DPM_FORCED_LEVEL_PROFILE_EXIT)) {
367 pr_err("Currently not in any profile mode!\n");
368 pm_runtime_mark_last_busy(ddev->dev);
369 pm_runtime_put_autosuspend(ddev->dev);
373 if (is_support_sw_smu(adev)) {
374 ret = smu_force_performance_level(&adev->smu, level);
376 pm_runtime_mark_last_busy(ddev->dev);
377 pm_runtime_put_autosuspend(ddev->dev);
380 } else if (adev->powerplay.pp_funcs->force_performance_level) {
381 mutex_lock(&adev->pm.mutex);
382 if (adev->pm.dpm.thermal_active) {
383 mutex_unlock(&adev->pm.mutex);
384 pm_runtime_mark_last_busy(ddev->dev);
385 pm_runtime_put_autosuspend(ddev->dev);
388 ret = amdgpu_dpm_force_performance_level(adev, level);
390 mutex_unlock(&adev->pm.mutex);
391 pm_runtime_mark_last_busy(ddev->dev);
392 pm_runtime_put_autosuspend(ddev->dev);
395 adev->pm.dpm.forced_level = level;
397 mutex_unlock(&adev->pm.mutex);
399 pm_runtime_mark_last_busy(ddev->dev);
400 pm_runtime_put_autosuspend(ddev->dev);
405 static ssize_t amdgpu_get_pp_num_states(struct device *dev,
406 struct device_attribute *attr,
409 struct drm_device *ddev = dev_get_drvdata(dev);
410 struct amdgpu_device *adev = drm_to_adev(ddev);
411 struct pp_states_info data;
414 if (amdgpu_in_reset(adev))
417 ret = pm_runtime_get_sync(ddev->dev);
419 pm_runtime_put_autosuspend(ddev->dev);
423 if (is_support_sw_smu(adev)) {
424 ret = smu_get_power_num_states(&adev->smu, &data);
427 } else if (adev->powerplay.pp_funcs->get_pp_num_states) {
428 amdgpu_dpm_get_pp_num_states(adev, &data);
430 memset(&data, 0, sizeof(data));
433 pm_runtime_mark_last_busy(ddev->dev);
434 pm_runtime_put_autosuspend(ddev->dev);
436 buf_len = snprintf(buf, PAGE_SIZE, "states: %d\n", data.nums);
437 for (i = 0; i < data.nums; i++)
438 buf_len += snprintf(buf + buf_len, PAGE_SIZE, "%d %s\n", i,
439 (data.states[i] == POWER_STATE_TYPE_INTERNAL_BOOT) ? "boot" :
440 (data.states[i] == POWER_STATE_TYPE_BATTERY) ? "battery" :
441 (data.states[i] == POWER_STATE_TYPE_BALANCED) ? "balanced" :
442 (data.states[i] == POWER_STATE_TYPE_PERFORMANCE) ? "performance" : "default");
447 static ssize_t amdgpu_get_pp_cur_state(struct device *dev,
448 struct device_attribute *attr,
451 struct drm_device *ddev = dev_get_drvdata(dev);
452 struct amdgpu_device *adev = drm_to_adev(ddev);
453 struct pp_states_info data;
454 struct smu_context *smu = &adev->smu;
455 enum amd_pm_state_type pm = 0;
458 if (amdgpu_in_reset(adev))
461 ret = pm_runtime_get_sync(ddev->dev);
463 pm_runtime_put_autosuspend(ddev->dev);
467 if (is_support_sw_smu(adev)) {
468 pm = smu_get_current_power_state(smu);
469 ret = smu_get_power_num_states(smu, &data);
472 } else if (adev->powerplay.pp_funcs->get_current_power_state
473 && adev->powerplay.pp_funcs->get_pp_num_states) {
474 pm = amdgpu_dpm_get_current_power_state(adev);
475 amdgpu_dpm_get_pp_num_states(adev, &data);
478 pm_runtime_mark_last_busy(ddev->dev);
479 pm_runtime_put_autosuspend(ddev->dev);
481 for (i = 0; i < data.nums; i++) {
482 if (pm == data.states[i])
489 return snprintf(buf, PAGE_SIZE, "%d\n", i);
492 static ssize_t amdgpu_get_pp_force_state(struct device *dev,
493 struct device_attribute *attr,
496 struct drm_device *ddev = dev_get_drvdata(dev);
497 struct amdgpu_device *adev = drm_to_adev(ddev);
499 if (amdgpu_in_reset(adev))
502 if (adev->pp_force_state_enabled)
503 return amdgpu_get_pp_cur_state(dev, attr, buf);
505 return snprintf(buf, PAGE_SIZE, "\n");
508 static ssize_t amdgpu_set_pp_force_state(struct device *dev,
509 struct device_attribute *attr,
513 struct drm_device *ddev = dev_get_drvdata(dev);
514 struct amdgpu_device *adev = drm_to_adev(ddev);
515 enum amd_pm_state_type state = 0;
519 if (amdgpu_in_reset(adev))
522 if (strlen(buf) == 1)
523 adev->pp_force_state_enabled = false;
524 else if (is_support_sw_smu(adev))
525 adev->pp_force_state_enabled = false;
526 else if (adev->powerplay.pp_funcs->dispatch_tasks &&
527 adev->powerplay.pp_funcs->get_pp_num_states) {
528 struct pp_states_info data;
530 ret = kstrtoul(buf, 0, &idx);
531 if (ret || idx >= ARRAY_SIZE(data.states))
534 idx = array_index_nospec(idx, ARRAY_SIZE(data.states));
536 amdgpu_dpm_get_pp_num_states(adev, &data);
537 state = data.states[idx];
539 ret = pm_runtime_get_sync(ddev->dev);
541 pm_runtime_put_autosuspend(ddev->dev);
545 /* only set user selected power states */
546 if (state != POWER_STATE_TYPE_INTERNAL_BOOT &&
547 state != POWER_STATE_TYPE_DEFAULT) {
548 amdgpu_dpm_dispatch_task(adev,
549 AMD_PP_TASK_ENABLE_USER_STATE, &state);
550 adev->pp_force_state_enabled = true;
552 pm_runtime_mark_last_busy(ddev->dev);
553 pm_runtime_put_autosuspend(ddev->dev);
562 * The amdgpu driver provides a sysfs API for uploading new powerplay
563 * tables. The file pp_table is used for this. Reading the file
564 * will dump the current power play table. Writing to the file
565 * will attempt to upload a new powerplay table and re-initialize
566 * powerplay using that new table.
570 static ssize_t amdgpu_get_pp_table(struct device *dev,
571 struct device_attribute *attr,
574 struct drm_device *ddev = dev_get_drvdata(dev);
575 struct amdgpu_device *adev = drm_to_adev(ddev);
579 if (amdgpu_in_reset(adev))
582 ret = pm_runtime_get_sync(ddev->dev);
584 pm_runtime_put_autosuspend(ddev->dev);
588 if (is_support_sw_smu(adev)) {
589 size = smu_sys_get_pp_table(&adev->smu, (void **)&table);
590 pm_runtime_mark_last_busy(ddev->dev);
591 pm_runtime_put_autosuspend(ddev->dev);
594 } else if (adev->powerplay.pp_funcs->get_pp_table) {
595 size = amdgpu_dpm_get_pp_table(adev, &table);
596 pm_runtime_mark_last_busy(ddev->dev);
597 pm_runtime_put_autosuspend(ddev->dev);
601 pm_runtime_mark_last_busy(ddev->dev);
602 pm_runtime_put_autosuspend(ddev->dev);
606 if (size >= PAGE_SIZE)
607 size = PAGE_SIZE - 1;
609 memcpy(buf, table, size);
614 static ssize_t amdgpu_set_pp_table(struct device *dev,
615 struct device_attribute *attr,
619 struct drm_device *ddev = dev_get_drvdata(dev);
620 struct amdgpu_device *adev = drm_to_adev(ddev);
623 if (amdgpu_in_reset(adev))
626 ret = pm_runtime_get_sync(ddev->dev);
628 pm_runtime_put_autosuspend(ddev->dev);
632 if (is_support_sw_smu(adev)) {
633 ret = smu_sys_set_pp_table(&adev->smu, (void *)buf, count);
635 pm_runtime_mark_last_busy(ddev->dev);
636 pm_runtime_put_autosuspend(ddev->dev);
639 } else if (adev->powerplay.pp_funcs->set_pp_table)
640 amdgpu_dpm_set_pp_table(adev, buf, count);
642 pm_runtime_mark_last_busy(ddev->dev);
643 pm_runtime_put_autosuspend(ddev->dev);
649 * DOC: pp_od_clk_voltage
651 * The amdgpu driver provides a sysfs API for adjusting the clocks and voltages
652 * in each power level within a power state. The pp_od_clk_voltage is used for
655 * Note that the actual memory controller clock rate are exposed, not
656 * the effective memory clock of the DRAMs. To translate it, use the
659 * Clock conversion (Mhz):
661 * HBM: effective_memory_clock = memory_controller_clock * 1
663 * G5: effective_memory_clock = memory_controller_clock * 1
665 * G6: effective_memory_clock = memory_controller_clock * 2
667 * DRAM data rate (MT/s):
669 * HBM: effective_memory_clock * 2 = data_rate
671 * G5: effective_memory_clock * 4 = data_rate
673 * G6: effective_memory_clock * 8 = data_rate
677 * data_rate * vram_bit_width / 8 = memory_bandwidth
683 * memory_controller_clock = 1750 Mhz
685 * effective_memory_clock = 1750 Mhz * 1 = 1750 Mhz
687 * data rate = 1750 * 4 = 7000 MT/s
689 * memory_bandwidth = 7000 * 128 bits / 8 = 112000 MB/s
693 * memory_controller_clock = 875 Mhz
695 * effective_memory_clock = 875 Mhz * 2 = 1750 Mhz
697 * data rate = 1750 * 8 = 14000 MT/s
699 * memory_bandwidth = 14000 * 256 bits / 8 = 448000 MB/s
701 * < For Vega10 and previous ASICs >
703 * Reading the file will display:
705 * - a list of engine clock levels and voltages labeled OD_SCLK
707 * - a list of memory clock levels and voltages labeled OD_MCLK
709 * - a list of valid ranges for sclk, mclk, and voltage labeled OD_RANGE
711 * To manually adjust these settings, first select manual using
712 * power_dpm_force_performance_level. Enter a new value for each
713 * level by writing a string that contains "s/m level clock voltage" to
714 * the file. E.g., "s 1 500 820" will update sclk level 1 to be 500 MHz
715 * at 820 mV; "m 0 350 810" will update mclk level 0 to be 350 MHz at
716 * 810 mV. When you have edited all of the states as needed, write
717 * "c" (commit) to the file to commit your changes. If you want to reset to the
718 * default power levels, write "r" (reset) to the file to reset them.
721 * < For Vega20 and newer ASICs >
723 * Reading the file will display:
725 * - minimum and maximum engine clock labeled OD_SCLK
727 * - maximum memory clock labeled OD_MCLK
729 * - three <frequency, voltage> points labeled OD_VDDC_CURVE.
730 * They can be used to calibrate the sclk voltage curve.
732 * - a list of valid ranges for sclk, mclk, and voltage curve points
735 * To manually adjust these settings:
737 * - First select manual using power_dpm_force_performance_level
739 * - For clock frequency setting, enter a new value by writing a
740 * string that contains "s/m index clock" to the file. The index
741 * should be 0 if to set minimum clock. And 1 if to set maximum
742 * clock. E.g., "s 0 500" will update minimum sclk to be 500 MHz.
743 * "m 1 800" will update maximum mclk to be 800Mhz.
745 * For sclk voltage curve, enter the new values by writing a
746 * string that contains "vc point clock voltage" to the file. The
747 * points are indexed by 0, 1 and 2. E.g., "vc 0 300 600" will
748 * update point1 with clock set as 300Mhz and voltage as
749 * 600mV. "vc 2 1000 1000" will update point3 with clock set
750 * as 1000Mhz and voltage 1000mV.
752 * - When you have edited all of the states as needed, write "c" (commit)
753 * to the file to commit your changes
755 * - If you want to reset to the default power levels, write "r" (reset)
756 * to the file to reset them
760 static ssize_t amdgpu_set_pp_od_clk_voltage(struct device *dev,
761 struct device_attribute *attr,
765 struct drm_device *ddev = dev_get_drvdata(dev);
766 struct amdgpu_device *adev = drm_to_adev(ddev);
768 uint32_t parameter_size = 0;
773 const char delimiter[3] = {' ', '\n', '\0'};
776 if (amdgpu_in_reset(adev))
783 type = PP_OD_EDIT_SCLK_VDDC_TABLE;
784 else if (*buf == 'm')
785 type = PP_OD_EDIT_MCLK_VDDC_TABLE;
787 type = PP_OD_RESTORE_DEFAULT_TABLE;
788 else if (*buf == 'c')
789 type = PP_OD_COMMIT_DPM_TABLE;
790 else if (!strncmp(buf, "vc", 2))
791 type = PP_OD_EDIT_VDDC_CURVE;
795 memcpy(buf_cpy, buf, count+1);
799 if (type == PP_OD_EDIT_VDDC_CURVE)
801 while (isspace(*++tmp_str));
804 sub_str = strsep(&tmp_str, delimiter);
805 ret = kstrtol(sub_str, 0, ¶meter[parameter_size]);
810 while (isspace(*tmp_str))
814 ret = pm_runtime_get_sync(ddev->dev);
816 pm_runtime_put_autosuspend(ddev->dev);
820 if (is_support_sw_smu(adev)) {
821 ret = smu_od_edit_dpm_table(&adev->smu, type,
822 parameter, parameter_size);
825 pm_runtime_mark_last_busy(ddev->dev);
826 pm_runtime_put_autosuspend(ddev->dev);
831 if (adev->powerplay.pp_funcs->set_fine_grain_clk_vol) {
832 ret = amdgpu_dpm_set_fine_grain_clk_vol(adev, type,
836 pm_runtime_mark_last_busy(ddev->dev);
837 pm_runtime_put_autosuspend(ddev->dev);
842 if (adev->powerplay.pp_funcs->odn_edit_dpm_table) {
843 ret = amdgpu_dpm_odn_edit_dpm_table(adev, type,
844 parameter, parameter_size);
846 pm_runtime_mark_last_busy(ddev->dev);
847 pm_runtime_put_autosuspend(ddev->dev);
852 if (type == PP_OD_COMMIT_DPM_TABLE) {
853 if (adev->powerplay.pp_funcs->dispatch_tasks) {
854 amdgpu_dpm_dispatch_task(adev,
855 AMD_PP_TASK_READJUST_POWER_STATE,
857 pm_runtime_mark_last_busy(ddev->dev);
858 pm_runtime_put_autosuspend(ddev->dev);
861 pm_runtime_mark_last_busy(ddev->dev);
862 pm_runtime_put_autosuspend(ddev->dev);
867 pm_runtime_mark_last_busy(ddev->dev);
868 pm_runtime_put_autosuspend(ddev->dev);
873 static ssize_t amdgpu_get_pp_od_clk_voltage(struct device *dev,
874 struct device_attribute *attr,
877 struct drm_device *ddev = dev_get_drvdata(dev);
878 struct amdgpu_device *adev = drm_to_adev(ddev);
882 if (amdgpu_in_reset(adev))
885 ret = pm_runtime_get_sync(ddev->dev);
887 pm_runtime_put_autosuspend(ddev->dev);
891 if (is_support_sw_smu(adev)) {
892 size = smu_print_clk_levels(&adev->smu, SMU_OD_SCLK, buf);
893 size += smu_print_clk_levels(&adev->smu, SMU_OD_MCLK, buf+size);
894 size += smu_print_clk_levels(&adev->smu, SMU_OD_VDDC_CURVE, buf+size);
895 size += smu_print_clk_levels(&adev->smu, SMU_OD_RANGE, buf+size);
896 } else if (adev->powerplay.pp_funcs->print_clock_levels) {
897 size = amdgpu_dpm_print_clock_levels(adev, OD_SCLK, buf);
898 size += amdgpu_dpm_print_clock_levels(adev, OD_MCLK, buf+size);
899 size += amdgpu_dpm_print_clock_levels(adev, OD_VDDC_CURVE, buf+size);
900 size += amdgpu_dpm_print_clock_levels(adev, OD_RANGE, buf+size);
902 size = snprintf(buf, PAGE_SIZE, "\n");
904 pm_runtime_mark_last_busy(ddev->dev);
905 pm_runtime_put_autosuspend(ddev->dev);
913 * The amdgpu driver provides a sysfs API for adjusting what powerplay
914 * features to be enabled. The file pp_features is used for this. And
915 * this is only available for Vega10 and later dGPUs.
917 * Reading back the file will show you the followings:
918 * - Current ppfeature masks
919 * - List of the all supported powerplay features with their naming,
920 * bitmasks and enablement status('Y'/'N' means "enabled"/"disabled").
922 * To manually enable or disable a specific feature, just set or clear
923 * the corresponding bit from original ppfeature masks and input the
924 * new ppfeature masks.
926 static ssize_t amdgpu_set_pp_features(struct device *dev,
927 struct device_attribute *attr,
931 struct drm_device *ddev = dev_get_drvdata(dev);
932 struct amdgpu_device *adev = drm_to_adev(ddev);
933 uint64_t featuremask;
936 if (amdgpu_in_reset(adev))
939 ret = kstrtou64(buf, 0, &featuremask);
943 pr_debug("featuremask = 0x%llx\n", featuremask);
945 ret = pm_runtime_get_sync(ddev->dev);
947 pm_runtime_put_autosuspend(ddev->dev);
951 if (is_support_sw_smu(adev)) {
952 ret = smu_sys_set_pp_feature_mask(&adev->smu, featuremask);
954 pm_runtime_mark_last_busy(ddev->dev);
955 pm_runtime_put_autosuspend(ddev->dev);
958 } else if (adev->powerplay.pp_funcs->set_ppfeature_status) {
959 ret = amdgpu_dpm_set_ppfeature_status(adev, featuremask);
961 pm_runtime_mark_last_busy(ddev->dev);
962 pm_runtime_put_autosuspend(ddev->dev);
966 pm_runtime_mark_last_busy(ddev->dev);
967 pm_runtime_put_autosuspend(ddev->dev);
972 static ssize_t amdgpu_get_pp_features(struct device *dev,
973 struct device_attribute *attr,
976 struct drm_device *ddev = dev_get_drvdata(dev);
977 struct amdgpu_device *adev = drm_to_adev(ddev);
981 if (amdgpu_in_reset(adev))
984 ret = pm_runtime_get_sync(ddev->dev);
986 pm_runtime_put_autosuspend(ddev->dev);
990 if (is_support_sw_smu(adev))
991 size = smu_sys_get_pp_feature_mask(&adev->smu, buf);
992 else if (adev->powerplay.pp_funcs->get_ppfeature_status)
993 size = amdgpu_dpm_get_ppfeature_status(adev, buf);
995 size = snprintf(buf, PAGE_SIZE, "\n");
997 pm_runtime_mark_last_busy(ddev->dev);
998 pm_runtime_put_autosuspend(ddev->dev);
1004 * DOC: pp_dpm_sclk pp_dpm_mclk pp_dpm_socclk pp_dpm_fclk pp_dpm_dcefclk pp_dpm_pcie
1006 * The amdgpu driver provides a sysfs API for adjusting what power levels
1007 * are enabled for a given power state. The files pp_dpm_sclk, pp_dpm_mclk,
1008 * pp_dpm_socclk, pp_dpm_fclk, pp_dpm_dcefclk and pp_dpm_pcie are used for
1011 * pp_dpm_socclk and pp_dpm_dcefclk interfaces are only available for
1012 * Vega10 and later ASICs.
1013 * pp_dpm_fclk interface is only available for Vega20 and later ASICs.
1015 * Reading back the files will show you the available power levels within
1016 * the power state and the clock information for those levels.
1018 * To manually adjust these states, first select manual using
1019 * power_dpm_force_performance_level.
1020 * Secondly, enter a new value for each level by inputing a string that
1021 * contains " echo xx xx xx > pp_dpm_sclk/mclk/pcie"
1024 * .. code-block:: bash
1026 * echo "4 5 6" > pp_dpm_sclk
1028 * will enable sclk levels 4, 5, and 6.
1030 * NOTE: change to the dcefclk max dpm level is not supported now
1033 static ssize_t amdgpu_get_pp_dpm_sclk(struct device *dev,
1034 struct device_attribute *attr,
1037 struct drm_device *ddev = dev_get_drvdata(dev);
1038 struct amdgpu_device *adev = drm_to_adev(ddev);
1042 if (amdgpu_in_reset(adev))
1045 ret = pm_runtime_get_sync(ddev->dev);
1047 pm_runtime_put_autosuspend(ddev->dev);
1051 if (is_support_sw_smu(adev))
1052 size = smu_print_clk_levels(&adev->smu, SMU_SCLK, buf);
1053 else if (adev->powerplay.pp_funcs->print_clock_levels)
1054 size = amdgpu_dpm_print_clock_levels(adev, PP_SCLK, buf);
1056 size = snprintf(buf, PAGE_SIZE, "\n");
1058 pm_runtime_mark_last_busy(ddev->dev);
1059 pm_runtime_put_autosuspend(ddev->dev);
1065 * Worst case: 32 bits individually specified, in octal at 12 characters
1066 * per line (+1 for \n).
1068 #define AMDGPU_MASK_BUF_MAX (32 * 13)
1070 static ssize_t amdgpu_read_mask(const char *buf, size_t count, uint32_t *mask)
1074 char *sub_str = NULL;
1076 char buf_cpy[AMDGPU_MASK_BUF_MAX + 1];
1077 const char delimiter[3] = {' ', '\n', '\0'};
1082 bytes = min(count, sizeof(buf_cpy) - 1);
1083 memcpy(buf_cpy, buf, bytes);
1084 buf_cpy[bytes] = '\0';
1087 sub_str = strsep(&tmp, delimiter);
1088 if (strlen(sub_str)) {
1089 ret = kstrtol(sub_str, 0, &level);
1092 *mask |= 1 << level;
1100 static ssize_t amdgpu_set_pp_dpm_sclk(struct device *dev,
1101 struct device_attribute *attr,
1105 struct drm_device *ddev = dev_get_drvdata(dev);
1106 struct amdgpu_device *adev = drm_to_adev(ddev);
1110 if (amdgpu_in_reset(adev))
1113 ret = amdgpu_read_mask(buf, count, &mask);
1117 ret = pm_runtime_get_sync(ddev->dev);
1119 pm_runtime_put_autosuspend(ddev->dev);
1123 if (is_support_sw_smu(adev))
1124 ret = smu_force_clk_levels(&adev->smu, SMU_SCLK, mask);
1125 else if (adev->powerplay.pp_funcs->force_clock_level)
1126 ret = amdgpu_dpm_force_clock_level(adev, PP_SCLK, mask);
1128 pm_runtime_mark_last_busy(ddev->dev);
1129 pm_runtime_put_autosuspend(ddev->dev);
1137 static ssize_t amdgpu_get_pp_dpm_mclk(struct device *dev,
1138 struct device_attribute *attr,
1141 struct drm_device *ddev = dev_get_drvdata(dev);
1142 struct amdgpu_device *adev = drm_to_adev(ddev);
1146 if (amdgpu_in_reset(adev))
1149 ret = pm_runtime_get_sync(ddev->dev);
1151 pm_runtime_put_autosuspend(ddev->dev);
1155 if (is_support_sw_smu(adev))
1156 size = smu_print_clk_levels(&adev->smu, SMU_MCLK, buf);
1157 else if (adev->powerplay.pp_funcs->print_clock_levels)
1158 size = amdgpu_dpm_print_clock_levels(adev, PP_MCLK, buf);
1160 size = snprintf(buf, PAGE_SIZE, "\n");
1162 pm_runtime_mark_last_busy(ddev->dev);
1163 pm_runtime_put_autosuspend(ddev->dev);
1168 static ssize_t amdgpu_set_pp_dpm_mclk(struct device *dev,
1169 struct device_attribute *attr,
1173 struct drm_device *ddev = dev_get_drvdata(dev);
1174 struct amdgpu_device *adev = drm_to_adev(ddev);
1178 if (amdgpu_in_reset(adev))
1181 ret = amdgpu_read_mask(buf, count, &mask);
1185 ret = pm_runtime_get_sync(ddev->dev);
1187 pm_runtime_put_autosuspend(ddev->dev);
1191 if (is_support_sw_smu(adev))
1192 ret = smu_force_clk_levels(&adev->smu, SMU_MCLK, mask);
1193 else if (adev->powerplay.pp_funcs->force_clock_level)
1194 ret = amdgpu_dpm_force_clock_level(adev, PP_MCLK, mask);
1196 pm_runtime_mark_last_busy(ddev->dev);
1197 pm_runtime_put_autosuspend(ddev->dev);
1205 static ssize_t amdgpu_get_pp_dpm_socclk(struct device *dev,
1206 struct device_attribute *attr,
1209 struct drm_device *ddev = dev_get_drvdata(dev);
1210 struct amdgpu_device *adev = drm_to_adev(ddev);
1214 if (amdgpu_in_reset(adev))
1217 ret = pm_runtime_get_sync(ddev->dev);
1219 pm_runtime_put_autosuspend(ddev->dev);
1223 if (is_support_sw_smu(adev))
1224 size = smu_print_clk_levels(&adev->smu, SMU_SOCCLK, buf);
1225 else if (adev->powerplay.pp_funcs->print_clock_levels)
1226 size = amdgpu_dpm_print_clock_levels(adev, PP_SOCCLK, buf);
1228 size = snprintf(buf, PAGE_SIZE, "\n");
1230 pm_runtime_mark_last_busy(ddev->dev);
1231 pm_runtime_put_autosuspend(ddev->dev);
1236 static ssize_t amdgpu_set_pp_dpm_socclk(struct device *dev,
1237 struct device_attribute *attr,
1241 struct drm_device *ddev = dev_get_drvdata(dev);
1242 struct amdgpu_device *adev = drm_to_adev(ddev);
1246 if (amdgpu_in_reset(adev))
1249 ret = amdgpu_read_mask(buf, count, &mask);
1253 ret = pm_runtime_get_sync(ddev->dev);
1255 pm_runtime_put_autosuspend(ddev->dev);
1259 if (is_support_sw_smu(adev))
1260 ret = smu_force_clk_levels(&adev->smu, SMU_SOCCLK, mask);
1261 else if (adev->powerplay.pp_funcs->force_clock_level)
1262 ret = amdgpu_dpm_force_clock_level(adev, PP_SOCCLK, mask);
1266 pm_runtime_mark_last_busy(ddev->dev);
1267 pm_runtime_put_autosuspend(ddev->dev);
1275 static ssize_t amdgpu_get_pp_dpm_fclk(struct device *dev,
1276 struct device_attribute *attr,
1279 struct drm_device *ddev = dev_get_drvdata(dev);
1280 struct amdgpu_device *adev = drm_to_adev(ddev);
1284 if (amdgpu_in_reset(adev))
1287 ret = pm_runtime_get_sync(ddev->dev);
1289 pm_runtime_put_autosuspend(ddev->dev);
1293 if (is_support_sw_smu(adev))
1294 size = smu_print_clk_levels(&adev->smu, SMU_FCLK, buf);
1295 else if (adev->powerplay.pp_funcs->print_clock_levels)
1296 size = amdgpu_dpm_print_clock_levels(adev, PP_FCLK, buf);
1298 size = snprintf(buf, PAGE_SIZE, "\n");
1300 pm_runtime_mark_last_busy(ddev->dev);
1301 pm_runtime_put_autosuspend(ddev->dev);
1306 static ssize_t amdgpu_set_pp_dpm_fclk(struct device *dev,
1307 struct device_attribute *attr,
1311 struct drm_device *ddev = dev_get_drvdata(dev);
1312 struct amdgpu_device *adev = drm_to_adev(ddev);
1316 if (amdgpu_in_reset(adev))
1319 ret = amdgpu_read_mask(buf, count, &mask);
1323 ret = pm_runtime_get_sync(ddev->dev);
1325 pm_runtime_put_autosuspend(ddev->dev);
1329 if (is_support_sw_smu(adev))
1330 ret = smu_force_clk_levels(&adev->smu, SMU_FCLK, mask);
1331 else if (adev->powerplay.pp_funcs->force_clock_level)
1332 ret = amdgpu_dpm_force_clock_level(adev, PP_FCLK, mask);
1336 pm_runtime_mark_last_busy(ddev->dev);
1337 pm_runtime_put_autosuspend(ddev->dev);
1345 static ssize_t amdgpu_get_pp_dpm_dcefclk(struct device *dev,
1346 struct device_attribute *attr,
1349 struct drm_device *ddev = dev_get_drvdata(dev);
1350 struct amdgpu_device *adev = drm_to_adev(ddev);
1354 if (amdgpu_in_reset(adev))
1357 ret = pm_runtime_get_sync(ddev->dev);
1359 pm_runtime_put_autosuspend(ddev->dev);
1363 if (is_support_sw_smu(adev))
1364 size = smu_print_clk_levels(&adev->smu, SMU_DCEFCLK, buf);
1365 else if (adev->powerplay.pp_funcs->print_clock_levels)
1366 size = amdgpu_dpm_print_clock_levels(adev, PP_DCEFCLK, buf);
1368 size = snprintf(buf, PAGE_SIZE, "\n");
1370 pm_runtime_mark_last_busy(ddev->dev);
1371 pm_runtime_put_autosuspend(ddev->dev);
1376 static ssize_t amdgpu_set_pp_dpm_dcefclk(struct device *dev,
1377 struct device_attribute *attr,
1381 struct drm_device *ddev = dev_get_drvdata(dev);
1382 struct amdgpu_device *adev = drm_to_adev(ddev);
1386 if (amdgpu_in_reset(adev))
1389 ret = amdgpu_read_mask(buf, count, &mask);
1393 ret = pm_runtime_get_sync(ddev->dev);
1395 pm_runtime_put_autosuspend(ddev->dev);
1399 if (is_support_sw_smu(adev))
1400 ret = smu_force_clk_levels(&adev->smu, SMU_DCEFCLK, mask);
1401 else if (adev->powerplay.pp_funcs->force_clock_level)
1402 ret = amdgpu_dpm_force_clock_level(adev, PP_DCEFCLK, mask);
1406 pm_runtime_mark_last_busy(ddev->dev);
1407 pm_runtime_put_autosuspend(ddev->dev);
1415 static ssize_t amdgpu_get_pp_dpm_pcie(struct device *dev,
1416 struct device_attribute *attr,
1419 struct drm_device *ddev = dev_get_drvdata(dev);
1420 struct amdgpu_device *adev = drm_to_adev(ddev);
1424 if (amdgpu_in_reset(adev))
1427 ret = pm_runtime_get_sync(ddev->dev);
1429 pm_runtime_put_autosuspend(ddev->dev);
1433 if (is_support_sw_smu(adev))
1434 size = smu_print_clk_levels(&adev->smu, SMU_PCIE, buf);
1435 else if (adev->powerplay.pp_funcs->print_clock_levels)
1436 size = amdgpu_dpm_print_clock_levels(adev, PP_PCIE, buf);
1438 size = snprintf(buf, PAGE_SIZE, "\n");
1440 pm_runtime_mark_last_busy(ddev->dev);
1441 pm_runtime_put_autosuspend(ddev->dev);
1446 static ssize_t amdgpu_set_pp_dpm_pcie(struct device *dev,
1447 struct device_attribute *attr,
1451 struct drm_device *ddev = dev_get_drvdata(dev);
1452 struct amdgpu_device *adev = drm_to_adev(ddev);
1456 if (amdgpu_in_reset(adev))
1459 ret = amdgpu_read_mask(buf, count, &mask);
1463 ret = pm_runtime_get_sync(ddev->dev);
1465 pm_runtime_put_autosuspend(ddev->dev);
1469 if (is_support_sw_smu(adev))
1470 ret = smu_force_clk_levels(&adev->smu, SMU_PCIE, mask);
1471 else if (adev->powerplay.pp_funcs->force_clock_level)
1472 ret = amdgpu_dpm_force_clock_level(adev, PP_PCIE, mask);
1476 pm_runtime_mark_last_busy(ddev->dev);
1477 pm_runtime_put_autosuspend(ddev->dev);
1485 static ssize_t amdgpu_get_pp_sclk_od(struct device *dev,
1486 struct device_attribute *attr,
1489 struct drm_device *ddev = dev_get_drvdata(dev);
1490 struct amdgpu_device *adev = drm_to_adev(ddev);
1494 if (amdgpu_in_reset(adev))
1497 ret = pm_runtime_get_sync(ddev->dev);
1499 pm_runtime_put_autosuspend(ddev->dev);
1503 if (is_support_sw_smu(adev))
1504 value = smu_get_od_percentage(&(adev->smu), SMU_OD_SCLK);
1505 else if (adev->powerplay.pp_funcs->get_sclk_od)
1506 value = amdgpu_dpm_get_sclk_od(adev);
1508 pm_runtime_mark_last_busy(ddev->dev);
1509 pm_runtime_put_autosuspend(ddev->dev);
1511 return snprintf(buf, PAGE_SIZE, "%d\n", value);
1514 static ssize_t amdgpu_set_pp_sclk_od(struct device *dev,
1515 struct device_attribute *attr,
1519 struct drm_device *ddev = dev_get_drvdata(dev);
1520 struct amdgpu_device *adev = drm_to_adev(ddev);
1524 if (amdgpu_in_reset(adev))
1527 ret = kstrtol(buf, 0, &value);
1532 ret = pm_runtime_get_sync(ddev->dev);
1534 pm_runtime_put_autosuspend(ddev->dev);
1538 if (is_support_sw_smu(adev)) {
1539 value = smu_set_od_percentage(&(adev->smu), SMU_OD_SCLK, (uint32_t)value);
1541 if (adev->powerplay.pp_funcs->set_sclk_od)
1542 amdgpu_dpm_set_sclk_od(adev, (uint32_t)value);
1544 if (adev->powerplay.pp_funcs->dispatch_tasks) {
1545 amdgpu_dpm_dispatch_task(adev, AMD_PP_TASK_READJUST_POWER_STATE, NULL);
1547 adev->pm.dpm.current_ps = adev->pm.dpm.boot_ps;
1548 amdgpu_pm_compute_clocks(adev);
1552 pm_runtime_mark_last_busy(ddev->dev);
1553 pm_runtime_put_autosuspend(ddev->dev);
1558 static ssize_t amdgpu_get_pp_mclk_od(struct device *dev,
1559 struct device_attribute *attr,
1562 struct drm_device *ddev = dev_get_drvdata(dev);
1563 struct amdgpu_device *adev = drm_to_adev(ddev);
1567 if (amdgpu_in_reset(adev))
1570 ret = pm_runtime_get_sync(ddev->dev);
1572 pm_runtime_put_autosuspend(ddev->dev);
1576 if (is_support_sw_smu(adev))
1577 value = smu_get_od_percentage(&(adev->smu), SMU_OD_MCLK);
1578 else if (adev->powerplay.pp_funcs->get_mclk_od)
1579 value = amdgpu_dpm_get_mclk_od(adev);
1581 pm_runtime_mark_last_busy(ddev->dev);
1582 pm_runtime_put_autosuspend(ddev->dev);
1584 return snprintf(buf, PAGE_SIZE, "%d\n", value);
1587 static ssize_t amdgpu_set_pp_mclk_od(struct device *dev,
1588 struct device_attribute *attr,
1592 struct drm_device *ddev = dev_get_drvdata(dev);
1593 struct amdgpu_device *adev = drm_to_adev(ddev);
1597 if (amdgpu_in_reset(adev))
1600 ret = kstrtol(buf, 0, &value);
1605 ret = pm_runtime_get_sync(ddev->dev);
1607 pm_runtime_put_autosuspend(ddev->dev);
1611 if (is_support_sw_smu(adev)) {
1612 value = smu_set_od_percentage(&(adev->smu), SMU_OD_MCLK, (uint32_t)value);
1614 if (adev->powerplay.pp_funcs->set_mclk_od)
1615 amdgpu_dpm_set_mclk_od(adev, (uint32_t)value);
1617 if (adev->powerplay.pp_funcs->dispatch_tasks) {
1618 amdgpu_dpm_dispatch_task(adev, AMD_PP_TASK_READJUST_POWER_STATE, NULL);
1620 adev->pm.dpm.current_ps = adev->pm.dpm.boot_ps;
1621 amdgpu_pm_compute_clocks(adev);
1625 pm_runtime_mark_last_busy(ddev->dev);
1626 pm_runtime_put_autosuspend(ddev->dev);
1632 * DOC: pp_power_profile_mode
1634 * The amdgpu driver provides a sysfs API for adjusting the heuristics
1635 * related to switching between power levels in a power state. The file
1636 * pp_power_profile_mode is used for this.
1638 * Reading this file outputs a list of all of the predefined power profiles
1639 * and the relevant heuristics settings for that profile.
1641 * To select a profile or create a custom profile, first select manual using
1642 * power_dpm_force_performance_level. Writing the number of a predefined
1643 * profile to pp_power_profile_mode will enable those heuristics. To
1644 * create a custom set of heuristics, write a string of numbers to the file
1645 * starting with the number of the custom profile along with a setting
1646 * for each heuristic parameter. Due to differences across asic families
1647 * the heuristic parameters vary from family to family.
1651 static ssize_t amdgpu_get_pp_power_profile_mode(struct device *dev,
1652 struct device_attribute *attr,
1655 struct drm_device *ddev = dev_get_drvdata(dev);
1656 struct amdgpu_device *adev = drm_to_adev(ddev);
1660 if (amdgpu_in_reset(adev))
1663 ret = pm_runtime_get_sync(ddev->dev);
1665 pm_runtime_put_autosuspend(ddev->dev);
1669 if (is_support_sw_smu(adev))
1670 size = smu_get_power_profile_mode(&adev->smu, buf);
1671 else if (adev->powerplay.pp_funcs->get_power_profile_mode)
1672 size = amdgpu_dpm_get_power_profile_mode(adev, buf);
1674 size = snprintf(buf, PAGE_SIZE, "\n");
1676 pm_runtime_mark_last_busy(ddev->dev);
1677 pm_runtime_put_autosuspend(ddev->dev);
1683 static ssize_t amdgpu_set_pp_power_profile_mode(struct device *dev,
1684 struct device_attribute *attr,
1689 struct drm_device *ddev = dev_get_drvdata(dev);
1690 struct amdgpu_device *adev = drm_to_adev(ddev);
1691 uint32_t parameter_size = 0;
1693 char *sub_str, buf_cpy[128];
1697 long int profile_mode = 0;
1698 const char delimiter[3] = {' ', '\n', '\0'};
1700 if (amdgpu_in_reset(adev))
1705 ret = kstrtol(tmp, 0, &profile_mode);
1709 if (profile_mode == PP_SMC_POWER_PROFILE_CUSTOM) {
1710 if (count < 2 || count > 127)
1712 while (isspace(*++buf))
1714 memcpy(buf_cpy, buf, count-i);
1716 while (tmp_str[0]) {
1717 sub_str = strsep(&tmp_str, delimiter);
1718 ret = kstrtol(sub_str, 0, ¶meter[parameter_size]);
1722 while (isspace(*tmp_str))
1726 parameter[parameter_size] = profile_mode;
1728 ret = pm_runtime_get_sync(ddev->dev);
1730 pm_runtime_put_autosuspend(ddev->dev);
1734 if (is_support_sw_smu(adev))
1735 ret = smu_set_power_profile_mode(&adev->smu, parameter, parameter_size, true);
1736 else if (adev->powerplay.pp_funcs->set_power_profile_mode)
1737 ret = amdgpu_dpm_set_power_profile_mode(adev, parameter, parameter_size);
1739 pm_runtime_mark_last_busy(ddev->dev);
1740 pm_runtime_put_autosuspend(ddev->dev);
1749 * DOC: gpu_busy_percent
1751 * The amdgpu driver provides a sysfs API for reading how busy the GPU
1752 * is as a percentage. The file gpu_busy_percent is used for this.
1753 * The SMU firmware computes a percentage of load based on the
1754 * aggregate activity level in the IP cores.
1756 static ssize_t amdgpu_get_gpu_busy_percent(struct device *dev,
1757 struct device_attribute *attr,
1760 struct drm_device *ddev = dev_get_drvdata(dev);
1761 struct amdgpu_device *adev = drm_to_adev(ddev);
1762 int r, value, size = sizeof(value);
1764 if (amdgpu_in_reset(adev))
1767 r = pm_runtime_get_sync(ddev->dev);
1769 pm_runtime_put_autosuspend(ddev->dev);
1773 /* read the IP busy sensor */
1774 r = amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GPU_LOAD,
1775 (void *)&value, &size);
1777 pm_runtime_mark_last_busy(ddev->dev);
1778 pm_runtime_put_autosuspend(ddev->dev);
1783 return snprintf(buf, PAGE_SIZE, "%d\n", value);
1787 * DOC: mem_busy_percent
1789 * The amdgpu driver provides a sysfs API for reading how busy the VRAM
1790 * is as a percentage. The file mem_busy_percent is used for this.
1791 * The SMU firmware computes a percentage of load based on the
1792 * aggregate activity level in the IP cores.
1794 static ssize_t amdgpu_get_mem_busy_percent(struct device *dev,
1795 struct device_attribute *attr,
1798 struct drm_device *ddev = dev_get_drvdata(dev);
1799 struct amdgpu_device *adev = drm_to_adev(ddev);
1800 int r, value, size = sizeof(value);
1802 if (amdgpu_in_reset(adev))
1805 r = pm_runtime_get_sync(ddev->dev);
1807 pm_runtime_put_autosuspend(ddev->dev);
1811 /* read the IP busy sensor */
1812 r = amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_MEM_LOAD,
1813 (void *)&value, &size);
1815 pm_runtime_mark_last_busy(ddev->dev);
1816 pm_runtime_put_autosuspend(ddev->dev);
1821 return snprintf(buf, PAGE_SIZE, "%d\n", value);
1827 * The amdgpu driver provides a sysfs API for estimating how much data
1828 * has been received and sent by the GPU in the last second through PCIe.
1829 * The file pcie_bw is used for this.
1830 * The Perf counters count the number of received and sent messages and return
1831 * those values, as well as the maximum payload size of a PCIe packet (mps).
1832 * Note that it is not possible to easily and quickly obtain the size of each
1833 * packet transmitted, so we output the max payload size (mps) to allow for
1834 * quick estimation of the PCIe bandwidth usage
1836 static ssize_t amdgpu_get_pcie_bw(struct device *dev,
1837 struct device_attribute *attr,
1840 struct drm_device *ddev = dev_get_drvdata(dev);
1841 struct amdgpu_device *adev = drm_to_adev(ddev);
1842 uint64_t count0 = 0, count1 = 0;
1845 if (amdgpu_in_reset(adev))
1848 if (adev->flags & AMD_IS_APU)
1851 if (!adev->asic_funcs->get_pcie_usage)
1854 ret = pm_runtime_get_sync(ddev->dev);
1856 pm_runtime_put_autosuspend(ddev->dev);
1860 amdgpu_asic_get_pcie_usage(adev, &count0, &count1);
1862 pm_runtime_mark_last_busy(ddev->dev);
1863 pm_runtime_put_autosuspend(ddev->dev);
1865 return snprintf(buf, PAGE_SIZE, "%llu %llu %i\n",
1866 count0, count1, pcie_get_mps(adev->pdev));
1872 * The amdgpu driver provides a sysfs API for providing a unique ID for the GPU
1873 * The file unique_id is used for this.
1874 * This will provide a Unique ID that will persist from machine to machine
1876 * NOTE: This will only work for GFX9 and newer. This file will be absent
1877 * on unsupported ASICs (GFX8 and older)
1879 static ssize_t amdgpu_get_unique_id(struct device *dev,
1880 struct device_attribute *attr,
1883 struct drm_device *ddev = dev_get_drvdata(dev);
1884 struct amdgpu_device *adev = drm_to_adev(ddev);
1886 if (amdgpu_in_reset(adev))
1889 if (adev->unique_id)
1890 return snprintf(buf, PAGE_SIZE, "%016llx\n", adev->unique_id);
1896 * DOC: thermal_throttling_logging
1898 * Thermal throttling pulls down the clock frequency and thus the performance.
1899 * It's an useful mechanism to protect the chip from overheating. Since it
1900 * impacts performance, the user controls whether it is enabled and if so,
1901 * the log frequency.
1903 * Reading back the file shows you the status(enabled or disabled) and
1904 * the interval(in seconds) between each thermal logging.
1906 * Writing an integer to the file, sets a new logging interval, in seconds.
1907 * The value should be between 1 and 3600. If the value is less than 1,
1908 * thermal logging is disabled. Values greater than 3600 are ignored.
1910 static ssize_t amdgpu_get_thermal_throttling_logging(struct device *dev,
1911 struct device_attribute *attr,
1914 struct drm_device *ddev = dev_get_drvdata(dev);
1915 struct amdgpu_device *adev = drm_to_adev(ddev);
1917 return snprintf(buf, PAGE_SIZE, "%s: thermal throttling logging %s, with interval %d seconds\n",
1918 adev_to_drm(adev)->unique,
1919 atomic_read(&adev->throttling_logging_enabled) ? "enabled" : "disabled",
1920 adev->throttling_logging_rs.interval / HZ + 1);
1923 static ssize_t amdgpu_set_thermal_throttling_logging(struct device *dev,
1924 struct device_attribute *attr,
1928 struct drm_device *ddev = dev_get_drvdata(dev);
1929 struct amdgpu_device *adev = drm_to_adev(ddev);
1930 long throttling_logging_interval;
1931 unsigned long flags;
1934 ret = kstrtol(buf, 0, &throttling_logging_interval);
1938 if (throttling_logging_interval > 3600)
1941 if (throttling_logging_interval > 0) {
1942 raw_spin_lock_irqsave(&adev->throttling_logging_rs.lock, flags);
1944 * Reset the ratelimit timer internals.
1945 * This can effectively restart the timer.
1947 adev->throttling_logging_rs.interval =
1948 (throttling_logging_interval - 1) * HZ;
1949 adev->throttling_logging_rs.begin = 0;
1950 adev->throttling_logging_rs.printed = 0;
1951 adev->throttling_logging_rs.missed = 0;
1952 raw_spin_unlock_irqrestore(&adev->throttling_logging_rs.lock, flags);
1954 atomic_set(&adev->throttling_logging_enabled, 1);
1956 atomic_set(&adev->throttling_logging_enabled, 0);
1965 * The amdgpu driver provides a sysfs API for retrieving current gpu
1966 * metrics data. The file gpu_metrics is used for this. Reading the
1967 * file will dump all the current gpu metrics data.
1969 * These data include temperature, frequency, engines utilization,
1970 * power consume, throttler status, fan speed and cpu core statistics(
1971 * available for APU only). That's it will give a snapshot of all sensors
1974 static ssize_t amdgpu_get_gpu_metrics(struct device *dev,
1975 struct device_attribute *attr,
1978 struct drm_device *ddev = dev_get_drvdata(dev);
1979 struct amdgpu_device *adev = drm_to_adev(ddev);
1984 if (amdgpu_in_reset(adev))
1987 ret = pm_runtime_get_sync(ddev->dev);
1989 pm_runtime_put_autosuspend(ddev->dev);
1993 if (is_support_sw_smu(adev))
1994 size = smu_sys_get_gpu_metrics(&adev->smu, &gpu_metrics);
1995 else if (adev->powerplay.pp_funcs->get_gpu_metrics)
1996 size = amdgpu_dpm_get_gpu_metrics(adev, &gpu_metrics);
2001 if (size >= PAGE_SIZE)
2002 size = PAGE_SIZE - 1;
2004 memcpy(buf, gpu_metrics, size);
2007 pm_runtime_mark_last_busy(ddev->dev);
2008 pm_runtime_put_autosuspend(ddev->dev);
2013 static struct amdgpu_device_attr amdgpu_device_attrs[] = {
2014 AMDGPU_DEVICE_ATTR_RW(power_dpm_state, ATTR_FLAG_BASIC|ATTR_FLAG_ONEVF),
2015 AMDGPU_DEVICE_ATTR_RW(power_dpm_force_performance_level, ATTR_FLAG_BASIC),
2016 AMDGPU_DEVICE_ATTR_RO(pp_num_states, ATTR_FLAG_BASIC),
2017 AMDGPU_DEVICE_ATTR_RO(pp_cur_state, ATTR_FLAG_BASIC),
2018 AMDGPU_DEVICE_ATTR_RW(pp_force_state, ATTR_FLAG_BASIC),
2019 AMDGPU_DEVICE_ATTR_RW(pp_table, ATTR_FLAG_BASIC),
2020 AMDGPU_DEVICE_ATTR_RW(pp_dpm_sclk, ATTR_FLAG_BASIC|ATTR_FLAG_ONEVF),
2021 AMDGPU_DEVICE_ATTR_RW(pp_dpm_mclk, ATTR_FLAG_BASIC|ATTR_FLAG_ONEVF),
2022 AMDGPU_DEVICE_ATTR_RW(pp_dpm_socclk, ATTR_FLAG_BASIC|ATTR_FLAG_ONEVF),
2023 AMDGPU_DEVICE_ATTR_RW(pp_dpm_fclk, ATTR_FLAG_BASIC|ATTR_FLAG_ONEVF),
2024 AMDGPU_DEVICE_ATTR_RW(pp_dpm_dcefclk, ATTR_FLAG_BASIC),
2025 AMDGPU_DEVICE_ATTR_RW(pp_dpm_pcie, ATTR_FLAG_BASIC),
2026 AMDGPU_DEVICE_ATTR_RW(pp_sclk_od, ATTR_FLAG_BASIC),
2027 AMDGPU_DEVICE_ATTR_RW(pp_mclk_od, ATTR_FLAG_BASIC),
2028 AMDGPU_DEVICE_ATTR_RW(pp_power_profile_mode, ATTR_FLAG_BASIC),
2029 AMDGPU_DEVICE_ATTR_RW(pp_od_clk_voltage, ATTR_FLAG_BASIC),
2030 AMDGPU_DEVICE_ATTR_RO(gpu_busy_percent, ATTR_FLAG_BASIC),
2031 AMDGPU_DEVICE_ATTR_RO(mem_busy_percent, ATTR_FLAG_BASIC),
2032 AMDGPU_DEVICE_ATTR_RO(pcie_bw, ATTR_FLAG_BASIC),
2033 AMDGPU_DEVICE_ATTR_RW(pp_features, ATTR_FLAG_BASIC),
2034 AMDGPU_DEVICE_ATTR_RO(unique_id, ATTR_FLAG_BASIC),
2035 AMDGPU_DEVICE_ATTR_RW(thermal_throttling_logging, ATTR_FLAG_BASIC),
2036 AMDGPU_DEVICE_ATTR_RO(gpu_metrics, ATTR_FLAG_BASIC),
2039 static int default_attr_update(struct amdgpu_device *adev, struct amdgpu_device_attr *attr,
2040 uint32_t mask, enum amdgpu_device_attr_states *states)
2042 struct device_attribute *dev_attr = &attr->dev_attr;
2043 const char *attr_name = dev_attr->attr.name;
2044 struct pp_hwmgr *hwmgr = adev->powerplay.pp_handle;
2045 enum amd_asic_type asic_type = adev->asic_type;
2047 if (!(attr->flags & mask)) {
2048 *states = ATTR_STATE_UNSUPPORTED;
2052 #define DEVICE_ATTR_IS(_name) (!strcmp(attr_name, #_name))
2054 if (DEVICE_ATTR_IS(pp_dpm_socclk)) {
2055 if (asic_type < CHIP_VEGA10)
2056 *states = ATTR_STATE_UNSUPPORTED;
2057 } else if (DEVICE_ATTR_IS(pp_dpm_dcefclk)) {
2058 if (asic_type < CHIP_VEGA10 || asic_type == CHIP_ARCTURUS)
2059 *states = ATTR_STATE_UNSUPPORTED;
2060 } else if (DEVICE_ATTR_IS(pp_dpm_fclk)) {
2061 if (asic_type < CHIP_VEGA20)
2062 *states = ATTR_STATE_UNSUPPORTED;
2063 } else if (DEVICE_ATTR_IS(pp_dpm_pcie)) {
2064 if (asic_type == CHIP_ARCTURUS)
2065 *states = ATTR_STATE_UNSUPPORTED;
2066 } else if (DEVICE_ATTR_IS(pp_od_clk_voltage)) {
2067 *states = ATTR_STATE_UNSUPPORTED;
2068 if ((is_support_sw_smu(adev) && adev->smu.od_enabled) ||
2069 (!is_support_sw_smu(adev) && hwmgr->od_enabled))
2070 *states = ATTR_STATE_SUPPORTED;
2071 } else if (DEVICE_ATTR_IS(mem_busy_percent)) {
2072 if (adev->flags & AMD_IS_APU || asic_type == CHIP_VEGA10)
2073 *states = ATTR_STATE_UNSUPPORTED;
2074 } else if (DEVICE_ATTR_IS(pcie_bw)) {
2075 /* PCIe Perf counters won't work on APU nodes */
2076 if (adev->flags & AMD_IS_APU)
2077 *states = ATTR_STATE_UNSUPPORTED;
2078 } else if (DEVICE_ATTR_IS(unique_id)) {
2079 if (asic_type != CHIP_VEGA10 &&
2080 asic_type != CHIP_VEGA20 &&
2081 asic_type != CHIP_ARCTURUS)
2082 *states = ATTR_STATE_UNSUPPORTED;
2083 } else if (DEVICE_ATTR_IS(pp_features)) {
2084 if (adev->flags & AMD_IS_APU || asic_type < CHIP_VEGA10)
2085 *states = ATTR_STATE_UNSUPPORTED;
2086 } else if (DEVICE_ATTR_IS(gpu_metrics)) {
2087 if (asic_type < CHIP_VEGA12)
2088 *states = ATTR_STATE_UNSUPPORTED;
2091 if (asic_type == CHIP_ARCTURUS) {
2092 /* Arcturus does not support standalone mclk/socclk/fclk level setting */
2093 if (DEVICE_ATTR_IS(pp_dpm_mclk) ||
2094 DEVICE_ATTR_IS(pp_dpm_socclk) ||
2095 DEVICE_ATTR_IS(pp_dpm_fclk)) {
2096 dev_attr->attr.mode &= ~S_IWUGO;
2097 dev_attr->store = NULL;
2101 #undef DEVICE_ATTR_IS
2107 static int amdgpu_device_attr_create(struct amdgpu_device *adev,
2108 struct amdgpu_device_attr *attr,
2109 uint32_t mask, struct list_head *attr_list)
2112 struct device_attribute *dev_attr = &attr->dev_attr;
2113 const char *name = dev_attr->attr.name;
2114 enum amdgpu_device_attr_states attr_states = ATTR_STATE_SUPPORTED;
2115 struct amdgpu_device_attr_entry *attr_entry;
2117 int (*attr_update)(struct amdgpu_device *adev, struct amdgpu_device_attr *attr,
2118 uint32_t mask, enum amdgpu_device_attr_states *states) = default_attr_update;
2122 attr_update = attr->attr_update ? attr_update : default_attr_update;
2124 ret = attr_update(adev, attr, mask, &attr_states);
2126 dev_err(adev->dev, "failed to update device file %s, ret = %d\n",
2131 if (attr_states == ATTR_STATE_UNSUPPORTED)
2134 ret = device_create_file(adev->dev, dev_attr);
2136 dev_err(adev->dev, "failed to create device file %s, ret = %d\n",
2140 attr_entry = kmalloc(sizeof(*attr_entry), GFP_KERNEL);
2144 attr_entry->attr = attr;
2145 INIT_LIST_HEAD(&attr_entry->entry);
2147 list_add_tail(&attr_entry->entry, attr_list);
2152 static void amdgpu_device_attr_remove(struct amdgpu_device *adev, struct amdgpu_device_attr *attr)
2154 struct device_attribute *dev_attr = &attr->dev_attr;
2156 device_remove_file(adev->dev, dev_attr);
2159 static void amdgpu_device_attr_remove_groups(struct amdgpu_device *adev,
2160 struct list_head *attr_list);
2162 static int amdgpu_device_attr_create_groups(struct amdgpu_device *adev,
2163 struct amdgpu_device_attr *attrs,
2166 struct list_head *attr_list)
2171 for (i = 0; i < counts; i++) {
2172 ret = amdgpu_device_attr_create(adev, &attrs[i], mask, attr_list);
2180 amdgpu_device_attr_remove_groups(adev, attr_list);
2185 static void amdgpu_device_attr_remove_groups(struct amdgpu_device *adev,
2186 struct list_head *attr_list)
2188 struct amdgpu_device_attr_entry *entry, *entry_tmp;
2190 if (list_empty(attr_list))
2193 list_for_each_entry_safe(entry, entry_tmp, attr_list, entry) {
2194 amdgpu_device_attr_remove(adev, entry->attr);
2195 list_del(&entry->entry);
2200 static ssize_t amdgpu_hwmon_show_temp(struct device *dev,
2201 struct device_attribute *attr,
2204 struct amdgpu_device *adev = dev_get_drvdata(dev);
2205 int channel = to_sensor_dev_attr(attr)->index;
2206 int r, temp = 0, size = sizeof(temp);
2208 if (amdgpu_in_reset(adev))
2211 if (channel >= PP_TEMP_MAX)
2214 r = pm_runtime_get_sync(adev_to_drm(adev)->dev);
2216 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2221 case PP_TEMP_JUNCTION:
2222 /* get current junction temperature */
2223 r = amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_HOTSPOT_TEMP,
2224 (void *)&temp, &size);
2227 /* get current edge temperature */
2228 r = amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_EDGE_TEMP,
2229 (void *)&temp, &size);
2232 /* get current memory temperature */
2233 r = amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_MEM_TEMP,
2234 (void *)&temp, &size);
2241 pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
2242 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2247 return snprintf(buf, PAGE_SIZE, "%d\n", temp);
2250 static ssize_t amdgpu_hwmon_show_temp_thresh(struct device *dev,
2251 struct device_attribute *attr,
2254 struct amdgpu_device *adev = dev_get_drvdata(dev);
2255 int hyst = to_sensor_dev_attr(attr)->index;
2259 temp = adev->pm.dpm.thermal.min_temp;
2261 temp = adev->pm.dpm.thermal.max_temp;
2263 return snprintf(buf, PAGE_SIZE, "%d\n", temp);
2266 static ssize_t amdgpu_hwmon_show_hotspot_temp_thresh(struct device *dev,
2267 struct device_attribute *attr,
2270 struct amdgpu_device *adev = dev_get_drvdata(dev);
2271 int hyst = to_sensor_dev_attr(attr)->index;
2275 temp = adev->pm.dpm.thermal.min_hotspot_temp;
2277 temp = adev->pm.dpm.thermal.max_hotspot_crit_temp;
2279 return snprintf(buf, PAGE_SIZE, "%d\n", temp);
2282 static ssize_t amdgpu_hwmon_show_mem_temp_thresh(struct device *dev,
2283 struct device_attribute *attr,
2286 struct amdgpu_device *adev = dev_get_drvdata(dev);
2287 int hyst = to_sensor_dev_attr(attr)->index;
2291 temp = adev->pm.dpm.thermal.min_mem_temp;
2293 temp = adev->pm.dpm.thermal.max_mem_crit_temp;
2295 return snprintf(buf, PAGE_SIZE, "%d\n", temp);
2298 static ssize_t amdgpu_hwmon_show_temp_label(struct device *dev,
2299 struct device_attribute *attr,
2302 int channel = to_sensor_dev_attr(attr)->index;
2304 if (channel >= PP_TEMP_MAX)
2307 return snprintf(buf, PAGE_SIZE, "%s\n", temp_label[channel].label);
2310 static ssize_t amdgpu_hwmon_show_temp_emergency(struct device *dev,
2311 struct device_attribute *attr,
2314 struct amdgpu_device *adev = dev_get_drvdata(dev);
2315 int channel = to_sensor_dev_attr(attr)->index;
2318 if (channel >= PP_TEMP_MAX)
2322 case PP_TEMP_JUNCTION:
2323 temp = adev->pm.dpm.thermal.max_hotspot_emergency_temp;
2326 temp = adev->pm.dpm.thermal.max_edge_emergency_temp;
2329 temp = adev->pm.dpm.thermal.max_mem_emergency_temp;
2333 return snprintf(buf, PAGE_SIZE, "%d\n", temp);
2336 static ssize_t amdgpu_hwmon_get_pwm1_enable(struct device *dev,
2337 struct device_attribute *attr,
2340 struct amdgpu_device *adev = dev_get_drvdata(dev);
2344 if (amdgpu_in_reset(adev))
2347 ret = pm_runtime_get_sync(adev_to_drm(adev)->dev);
2349 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2353 if (is_support_sw_smu(adev)) {
2354 pwm_mode = smu_get_fan_control_mode(&adev->smu);
2356 if (!adev->powerplay.pp_funcs->get_fan_control_mode) {
2357 pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
2358 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2362 pwm_mode = amdgpu_dpm_get_fan_control_mode(adev);
2365 pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
2366 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2368 return sprintf(buf, "%i\n", pwm_mode);
2371 static ssize_t amdgpu_hwmon_set_pwm1_enable(struct device *dev,
2372 struct device_attribute *attr,
2376 struct amdgpu_device *adev = dev_get_drvdata(dev);
2380 if (amdgpu_in_reset(adev))
2383 err = kstrtoint(buf, 10, &value);
2387 ret = pm_runtime_get_sync(adev_to_drm(adev)->dev);
2389 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2393 if (is_support_sw_smu(adev)) {
2394 smu_set_fan_control_mode(&adev->smu, value);
2396 if (!adev->powerplay.pp_funcs->set_fan_control_mode) {
2397 pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
2398 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2402 amdgpu_dpm_set_fan_control_mode(adev, value);
2405 pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
2406 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2411 static ssize_t amdgpu_hwmon_get_pwm1_min(struct device *dev,
2412 struct device_attribute *attr,
2415 return sprintf(buf, "%i\n", 0);
2418 static ssize_t amdgpu_hwmon_get_pwm1_max(struct device *dev,
2419 struct device_attribute *attr,
2422 return sprintf(buf, "%i\n", 255);
2425 static ssize_t amdgpu_hwmon_set_pwm1(struct device *dev,
2426 struct device_attribute *attr,
2427 const char *buf, size_t count)
2429 struct amdgpu_device *adev = dev_get_drvdata(dev);
2434 if (amdgpu_in_reset(adev))
2437 err = pm_runtime_get_sync(adev_to_drm(adev)->dev);
2439 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2443 if (is_support_sw_smu(adev))
2444 pwm_mode = smu_get_fan_control_mode(&adev->smu);
2446 pwm_mode = amdgpu_dpm_get_fan_control_mode(adev);
2448 if (pwm_mode != AMD_FAN_CTRL_MANUAL) {
2449 pr_info("manual fan speed control should be enabled first\n");
2450 pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
2451 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2455 err = kstrtou32(buf, 10, &value);
2457 pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
2458 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2462 value = (value * 100) / 255;
2464 if (is_support_sw_smu(adev))
2465 err = smu_set_fan_speed_percent(&adev->smu, value);
2466 else if (adev->powerplay.pp_funcs->set_fan_speed_percent)
2467 err = amdgpu_dpm_set_fan_speed_percent(adev, value);
2471 pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
2472 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2480 static ssize_t amdgpu_hwmon_get_pwm1(struct device *dev,
2481 struct device_attribute *attr,
2484 struct amdgpu_device *adev = dev_get_drvdata(dev);
2488 if (amdgpu_in_reset(adev))
2491 err = pm_runtime_get_sync(adev_to_drm(adev)->dev);
2493 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2497 if (is_support_sw_smu(adev))
2498 err = smu_get_fan_speed_percent(&adev->smu, &speed);
2499 else if (adev->powerplay.pp_funcs->get_fan_speed_percent)
2500 err = amdgpu_dpm_get_fan_speed_percent(adev, &speed);
2504 pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
2505 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2510 speed = (speed * 255) / 100;
2512 return sprintf(buf, "%i\n", speed);
2515 static ssize_t amdgpu_hwmon_get_fan1_input(struct device *dev,
2516 struct device_attribute *attr,
2519 struct amdgpu_device *adev = dev_get_drvdata(dev);
2523 if (amdgpu_in_reset(adev))
2526 err = pm_runtime_get_sync(adev_to_drm(adev)->dev);
2528 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2532 if (is_support_sw_smu(adev))
2533 err = smu_get_fan_speed_rpm(&adev->smu, &speed);
2534 else if (adev->powerplay.pp_funcs->get_fan_speed_rpm)
2535 err = amdgpu_dpm_get_fan_speed_rpm(adev, &speed);
2539 pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
2540 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2545 return sprintf(buf, "%i\n", speed);
2548 static ssize_t amdgpu_hwmon_get_fan1_min(struct device *dev,
2549 struct device_attribute *attr,
2552 struct amdgpu_device *adev = dev_get_drvdata(dev);
2554 u32 size = sizeof(min_rpm);
2557 if (amdgpu_in_reset(adev))
2560 r = pm_runtime_get_sync(adev_to_drm(adev)->dev);
2562 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2566 r = amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_MIN_FAN_RPM,
2567 (void *)&min_rpm, &size);
2569 pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
2570 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2575 return snprintf(buf, PAGE_SIZE, "%d\n", min_rpm);
2578 static ssize_t amdgpu_hwmon_get_fan1_max(struct device *dev,
2579 struct device_attribute *attr,
2582 struct amdgpu_device *adev = dev_get_drvdata(dev);
2584 u32 size = sizeof(max_rpm);
2587 if (amdgpu_in_reset(adev))
2590 r = pm_runtime_get_sync(adev_to_drm(adev)->dev);
2592 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2596 r = amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_MAX_FAN_RPM,
2597 (void *)&max_rpm, &size);
2599 pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
2600 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2605 return snprintf(buf, PAGE_SIZE, "%d\n", max_rpm);
2608 static ssize_t amdgpu_hwmon_get_fan1_target(struct device *dev,
2609 struct device_attribute *attr,
2612 struct amdgpu_device *adev = dev_get_drvdata(dev);
2616 if (amdgpu_in_reset(adev))
2619 err = pm_runtime_get_sync(adev_to_drm(adev)->dev);
2621 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2625 if (is_support_sw_smu(adev))
2626 err = smu_get_fan_speed_rpm(&adev->smu, &rpm);
2627 else if (adev->powerplay.pp_funcs->get_fan_speed_rpm)
2628 err = amdgpu_dpm_get_fan_speed_rpm(adev, &rpm);
2632 pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
2633 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2638 return sprintf(buf, "%i\n", rpm);
2641 static ssize_t amdgpu_hwmon_set_fan1_target(struct device *dev,
2642 struct device_attribute *attr,
2643 const char *buf, size_t count)
2645 struct amdgpu_device *adev = dev_get_drvdata(dev);
2650 if (amdgpu_in_reset(adev))
2653 err = pm_runtime_get_sync(adev_to_drm(adev)->dev);
2655 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2659 if (is_support_sw_smu(adev))
2660 pwm_mode = smu_get_fan_control_mode(&adev->smu);
2662 pwm_mode = amdgpu_dpm_get_fan_control_mode(adev);
2664 if (pwm_mode != AMD_FAN_CTRL_MANUAL) {
2665 pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
2666 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2670 err = kstrtou32(buf, 10, &value);
2672 pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
2673 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2677 if (is_support_sw_smu(adev))
2678 err = smu_set_fan_speed_rpm(&adev->smu, value);
2679 else if (adev->powerplay.pp_funcs->set_fan_speed_rpm)
2680 err = amdgpu_dpm_set_fan_speed_rpm(adev, value);
2684 pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
2685 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2693 static ssize_t amdgpu_hwmon_get_fan1_enable(struct device *dev,
2694 struct device_attribute *attr,
2697 struct amdgpu_device *adev = dev_get_drvdata(dev);
2701 if (amdgpu_in_reset(adev))
2704 ret = pm_runtime_get_sync(adev_to_drm(adev)->dev);
2706 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2710 if (is_support_sw_smu(adev)) {
2711 pwm_mode = smu_get_fan_control_mode(&adev->smu);
2713 if (!adev->powerplay.pp_funcs->get_fan_control_mode) {
2714 pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
2715 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2719 pwm_mode = amdgpu_dpm_get_fan_control_mode(adev);
2722 pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
2723 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2725 return sprintf(buf, "%i\n", pwm_mode == AMD_FAN_CTRL_AUTO ? 0 : 1);
2728 static ssize_t amdgpu_hwmon_set_fan1_enable(struct device *dev,
2729 struct device_attribute *attr,
2733 struct amdgpu_device *adev = dev_get_drvdata(dev);
2738 if (amdgpu_in_reset(adev))
2741 err = kstrtoint(buf, 10, &value);
2746 pwm_mode = AMD_FAN_CTRL_AUTO;
2747 else if (value == 1)
2748 pwm_mode = AMD_FAN_CTRL_MANUAL;
2752 err = pm_runtime_get_sync(adev_to_drm(adev)->dev);
2754 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2758 if (is_support_sw_smu(adev)) {
2759 smu_set_fan_control_mode(&adev->smu, pwm_mode);
2761 if (!adev->powerplay.pp_funcs->set_fan_control_mode) {
2762 pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
2763 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2766 amdgpu_dpm_set_fan_control_mode(adev, pwm_mode);
2769 pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
2770 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2775 static ssize_t amdgpu_hwmon_show_vddgfx(struct device *dev,
2776 struct device_attribute *attr,
2779 struct amdgpu_device *adev = dev_get_drvdata(dev);
2781 int r, size = sizeof(vddgfx);
2783 if (amdgpu_in_reset(adev))
2786 r = pm_runtime_get_sync(adev_to_drm(adev)->dev);
2788 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2792 /* get the voltage */
2793 r = amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_VDDGFX,
2794 (void *)&vddgfx, &size);
2796 pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
2797 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2802 return snprintf(buf, PAGE_SIZE, "%d\n", vddgfx);
2805 static ssize_t amdgpu_hwmon_show_vddgfx_label(struct device *dev,
2806 struct device_attribute *attr,
2809 return snprintf(buf, PAGE_SIZE, "vddgfx\n");
2812 static ssize_t amdgpu_hwmon_show_vddnb(struct device *dev,
2813 struct device_attribute *attr,
2816 struct amdgpu_device *adev = dev_get_drvdata(dev);
2818 int r, size = sizeof(vddnb);
2820 if (amdgpu_in_reset(adev))
2823 /* only APUs have vddnb */
2824 if (!(adev->flags & AMD_IS_APU))
2827 r = pm_runtime_get_sync(adev_to_drm(adev)->dev);
2829 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2833 /* get the voltage */
2834 r = amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_VDDNB,
2835 (void *)&vddnb, &size);
2837 pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
2838 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2843 return snprintf(buf, PAGE_SIZE, "%d\n", vddnb);
2846 static ssize_t amdgpu_hwmon_show_vddnb_label(struct device *dev,
2847 struct device_attribute *attr,
2850 return snprintf(buf, PAGE_SIZE, "vddnb\n");
2853 static ssize_t amdgpu_hwmon_show_power_avg(struct device *dev,
2854 struct device_attribute *attr,
2857 struct amdgpu_device *adev = dev_get_drvdata(dev);
2859 int r, size = sizeof(u32);
2862 if (amdgpu_in_reset(adev))
2865 r = pm_runtime_get_sync(adev_to_drm(adev)->dev);
2867 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2871 /* get the voltage */
2872 r = amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GPU_POWER,
2873 (void *)&query, &size);
2875 pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
2876 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2881 /* convert to microwatts */
2882 uw = (query >> 8) * 1000000 + (query & 0xff) * 1000;
2884 return snprintf(buf, PAGE_SIZE, "%u\n", uw);
2887 static ssize_t amdgpu_hwmon_show_power_cap_min(struct device *dev,
2888 struct device_attribute *attr,
2891 return sprintf(buf, "%i\n", 0);
2894 static ssize_t amdgpu_hwmon_show_power_cap_max(struct device *dev,
2895 struct device_attribute *attr,
2898 struct amdgpu_device *adev = dev_get_drvdata(dev);
2903 if (amdgpu_in_reset(adev))
2906 r = pm_runtime_get_sync(adev_to_drm(adev)->dev);
2908 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2912 if (is_support_sw_smu(adev)) {
2913 smu_get_power_limit(&adev->smu, &limit, true);
2914 size = snprintf(buf, PAGE_SIZE, "%u\n", limit * 1000000);
2915 } else if (adev->powerplay.pp_funcs && adev->powerplay.pp_funcs->get_power_limit) {
2916 adev->powerplay.pp_funcs->get_power_limit(adev->powerplay.pp_handle, &limit, true);
2917 size = snprintf(buf, PAGE_SIZE, "%u\n", limit * 1000000);
2919 size = snprintf(buf, PAGE_SIZE, "\n");
2922 pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
2923 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2928 static ssize_t amdgpu_hwmon_show_power_cap(struct device *dev,
2929 struct device_attribute *attr,
2932 struct amdgpu_device *adev = dev_get_drvdata(dev);
2937 if (amdgpu_in_reset(adev))
2940 r = pm_runtime_get_sync(adev_to_drm(adev)->dev);
2942 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2946 if (is_support_sw_smu(adev)) {
2947 smu_get_power_limit(&adev->smu, &limit, false);
2948 size = snprintf(buf, PAGE_SIZE, "%u\n", limit * 1000000);
2949 } else if (adev->powerplay.pp_funcs && adev->powerplay.pp_funcs->get_power_limit) {
2950 adev->powerplay.pp_funcs->get_power_limit(adev->powerplay.pp_handle, &limit, false);
2951 size = snprintf(buf, PAGE_SIZE, "%u\n", limit * 1000000);
2953 size = snprintf(buf, PAGE_SIZE, "\n");
2956 pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
2957 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2963 static ssize_t amdgpu_hwmon_set_power_cap(struct device *dev,
2964 struct device_attribute *attr,
2968 struct amdgpu_device *adev = dev_get_drvdata(dev);
2972 if (amdgpu_in_reset(adev))
2975 if (amdgpu_sriov_vf(adev))
2978 err = kstrtou32(buf, 10, &value);
2982 value = value / 1000000; /* convert to Watt */
2985 err = pm_runtime_get_sync(adev_to_drm(adev)->dev);
2987 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2991 if (is_support_sw_smu(adev))
2992 err = smu_set_power_limit(&adev->smu, value);
2993 else if (adev->powerplay.pp_funcs && adev->powerplay.pp_funcs->set_power_limit)
2994 err = adev->powerplay.pp_funcs->set_power_limit(adev->powerplay.pp_handle, value);
2998 pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
2999 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
3007 static ssize_t amdgpu_hwmon_show_sclk(struct device *dev,
3008 struct device_attribute *attr,
3011 struct amdgpu_device *adev = dev_get_drvdata(dev);
3013 int r, size = sizeof(sclk);
3015 if (amdgpu_in_reset(adev))
3018 r = pm_runtime_get_sync(adev_to_drm(adev)->dev);
3020 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
3025 r = amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GFX_SCLK,
3026 (void *)&sclk, &size);
3028 pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
3029 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
3034 return snprintf(buf, PAGE_SIZE, "%u\n", sclk * 10 * 1000);
3037 static ssize_t amdgpu_hwmon_show_sclk_label(struct device *dev,
3038 struct device_attribute *attr,
3041 return snprintf(buf, PAGE_SIZE, "sclk\n");
3044 static ssize_t amdgpu_hwmon_show_mclk(struct device *dev,
3045 struct device_attribute *attr,
3048 struct amdgpu_device *adev = dev_get_drvdata(dev);
3050 int r, size = sizeof(mclk);
3052 if (amdgpu_in_reset(adev))
3055 r = pm_runtime_get_sync(adev_to_drm(adev)->dev);
3057 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
3062 r = amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GFX_MCLK,
3063 (void *)&mclk, &size);
3065 pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
3066 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
3071 return snprintf(buf, PAGE_SIZE, "%u\n", mclk * 10 * 1000);
3074 static ssize_t amdgpu_hwmon_show_mclk_label(struct device *dev,
3075 struct device_attribute *attr,
3078 return snprintf(buf, PAGE_SIZE, "mclk\n");
3084 * The amdgpu driver exposes the following sensor interfaces:
3086 * - GPU temperature (via the on-die sensor)
3090 * - Northbridge voltage (APUs only)
3096 * - GPU gfx/compute engine clock
3098 * - GPU memory clock (dGPU only)
3100 * hwmon interfaces for GPU temperature:
3102 * - temp[1-3]_input: the on die GPU temperature in millidegrees Celsius
3103 * - temp2_input and temp3_input are supported on SOC15 dGPUs only
3105 * - temp[1-3]_label: temperature channel label
3106 * - temp2_label and temp3_label are supported on SOC15 dGPUs only
3108 * - temp[1-3]_crit: temperature critical max value in millidegrees Celsius
3109 * - temp2_crit and temp3_crit are supported on SOC15 dGPUs only
3111 * - temp[1-3]_crit_hyst: temperature hysteresis for critical limit in millidegrees Celsius
3112 * - temp2_crit_hyst and temp3_crit_hyst are supported on SOC15 dGPUs only
3114 * - temp[1-3]_emergency: temperature emergency max value(asic shutdown) in millidegrees Celsius
3115 * - these are supported on SOC15 dGPUs only
3117 * hwmon interfaces for GPU voltage:
3119 * - in0_input: the voltage on the GPU in millivolts
3121 * - in1_input: the voltage on the Northbridge in millivolts
3123 * hwmon interfaces for GPU power:
3125 * - power1_average: average power used by the GPU in microWatts
3127 * - power1_cap_min: minimum cap supported in microWatts
3129 * - power1_cap_max: maximum cap supported in microWatts
3131 * - power1_cap: selected power cap in microWatts
3133 * hwmon interfaces for GPU fan:
3135 * - pwm1: pulse width modulation fan level (0-255)
3137 * - 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)
3139 * - pwm1_min: pulse width modulation fan control minimum level (0)
3141 * - pwm1_max: pulse width modulation fan control maximum level (255)
3143 * - fan1_min: an minimum value Unit: revolution/min (RPM)
3145 * - fan1_max: an maxmum value Unit: revolution/max (RPM)
3147 * - fan1_input: fan speed in RPM
3149 * - fan[1-\*]_target: Desired fan speed Unit: revolution/min (RPM)
3151 * - fan[1-\*]_enable: Enable or disable the sensors.1: Enable 0: Disable
3153 * hwmon interfaces for GPU clocks:
3155 * - freq1_input: the gfx/compute clock in hertz
3157 * - freq2_input: the memory clock in hertz
3159 * You can use hwmon tools like sensors to view this information on your system.
3163 static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, amdgpu_hwmon_show_temp, NULL, PP_TEMP_EDGE);
3164 static SENSOR_DEVICE_ATTR(temp1_crit, S_IRUGO, amdgpu_hwmon_show_temp_thresh, NULL, 0);
3165 static SENSOR_DEVICE_ATTR(temp1_crit_hyst, S_IRUGO, amdgpu_hwmon_show_temp_thresh, NULL, 1);
3166 static SENSOR_DEVICE_ATTR(temp1_emergency, S_IRUGO, amdgpu_hwmon_show_temp_emergency, NULL, PP_TEMP_EDGE);
3167 static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, amdgpu_hwmon_show_temp, NULL, PP_TEMP_JUNCTION);
3168 static SENSOR_DEVICE_ATTR(temp2_crit, S_IRUGO, amdgpu_hwmon_show_hotspot_temp_thresh, NULL, 0);
3169 static SENSOR_DEVICE_ATTR(temp2_crit_hyst, S_IRUGO, amdgpu_hwmon_show_hotspot_temp_thresh, NULL, 1);
3170 static SENSOR_DEVICE_ATTR(temp2_emergency, S_IRUGO, amdgpu_hwmon_show_temp_emergency, NULL, PP_TEMP_JUNCTION);
3171 static SENSOR_DEVICE_ATTR(temp3_input, S_IRUGO, amdgpu_hwmon_show_temp, NULL, PP_TEMP_MEM);
3172 static SENSOR_DEVICE_ATTR(temp3_crit, S_IRUGO, amdgpu_hwmon_show_mem_temp_thresh, NULL, 0);
3173 static SENSOR_DEVICE_ATTR(temp3_crit_hyst, S_IRUGO, amdgpu_hwmon_show_mem_temp_thresh, NULL, 1);
3174 static SENSOR_DEVICE_ATTR(temp3_emergency, S_IRUGO, amdgpu_hwmon_show_temp_emergency, NULL, PP_TEMP_MEM);
3175 static SENSOR_DEVICE_ATTR(temp1_label, S_IRUGO, amdgpu_hwmon_show_temp_label, NULL, PP_TEMP_EDGE);
3176 static SENSOR_DEVICE_ATTR(temp2_label, S_IRUGO, amdgpu_hwmon_show_temp_label, NULL, PP_TEMP_JUNCTION);
3177 static SENSOR_DEVICE_ATTR(temp3_label, S_IRUGO, amdgpu_hwmon_show_temp_label, NULL, PP_TEMP_MEM);
3178 static SENSOR_DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, amdgpu_hwmon_get_pwm1, amdgpu_hwmon_set_pwm1, 0);
3179 static SENSOR_DEVICE_ATTR(pwm1_enable, S_IRUGO | S_IWUSR, amdgpu_hwmon_get_pwm1_enable, amdgpu_hwmon_set_pwm1_enable, 0);
3180 static SENSOR_DEVICE_ATTR(pwm1_min, S_IRUGO, amdgpu_hwmon_get_pwm1_min, NULL, 0);
3181 static SENSOR_DEVICE_ATTR(pwm1_max, S_IRUGO, amdgpu_hwmon_get_pwm1_max, NULL, 0);
3182 static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, amdgpu_hwmon_get_fan1_input, NULL, 0);
3183 static SENSOR_DEVICE_ATTR(fan1_min, S_IRUGO, amdgpu_hwmon_get_fan1_min, NULL, 0);
3184 static SENSOR_DEVICE_ATTR(fan1_max, S_IRUGO, amdgpu_hwmon_get_fan1_max, NULL, 0);
3185 static SENSOR_DEVICE_ATTR(fan1_target, S_IRUGO | S_IWUSR, amdgpu_hwmon_get_fan1_target, amdgpu_hwmon_set_fan1_target, 0);
3186 static SENSOR_DEVICE_ATTR(fan1_enable, S_IRUGO | S_IWUSR, amdgpu_hwmon_get_fan1_enable, amdgpu_hwmon_set_fan1_enable, 0);
3187 static SENSOR_DEVICE_ATTR(in0_input, S_IRUGO, amdgpu_hwmon_show_vddgfx, NULL, 0);
3188 static SENSOR_DEVICE_ATTR(in0_label, S_IRUGO, amdgpu_hwmon_show_vddgfx_label, NULL, 0);
3189 static SENSOR_DEVICE_ATTR(in1_input, S_IRUGO, amdgpu_hwmon_show_vddnb, NULL, 0);
3190 static SENSOR_DEVICE_ATTR(in1_label, S_IRUGO, amdgpu_hwmon_show_vddnb_label, NULL, 0);
3191 static SENSOR_DEVICE_ATTR(power1_average, S_IRUGO, amdgpu_hwmon_show_power_avg, NULL, 0);
3192 static SENSOR_DEVICE_ATTR(power1_cap_max, S_IRUGO, amdgpu_hwmon_show_power_cap_max, NULL, 0);
3193 static SENSOR_DEVICE_ATTR(power1_cap_min, S_IRUGO, amdgpu_hwmon_show_power_cap_min, NULL, 0);
3194 static SENSOR_DEVICE_ATTR(power1_cap, S_IRUGO | S_IWUSR, amdgpu_hwmon_show_power_cap, amdgpu_hwmon_set_power_cap, 0);
3195 static SENSOR_DEVICE_ATTR(freq1_input, S_IRUGO, amdgpu_hwmon_show_sclk, NULL, 0);
3196 static SENSOR_DEVICE_ATTR(freq1_label, S_IRUGO, amdgpu_hwmon_show_sclk_label, NULL, 0);
3197 static SENSOR_DEVICE_ATTR(freq2_input, S_IRUGO, amdgpu_hwmon_show_mclk, NULL, 0);
3198 static SENSOR_DEVICE_ATTR(freq2_label, S_IRUGO, amdgpu_hwmon_show_mclk_label, NULL, 0);
3200 static struct attribute *hwmon_attributes[] = {
3201 &sensor_dev_attr_temp1_input.dev_attr.attr,
3202 &sensor_dev_attr_temp1_crit.dev_attr.attr,
3203 &sensor_dev_attr_temp1_crit_hyst.dev_attr.attr,
3204 &sensor_dev_attr_temp2_input.dev_attr.attr,
3205 &sensor_dev_attr_temp2_crit.dev_attr.attr,
3206 &sensor_dev_attr_temp2_crit_hyst.dev_attr.attr,
3207 &sensor_dev_attr_temp3_input.dev_attr.attr,
3208 &sensor_dev_attr_temp3_crit.dev_attr.attr,
3209 &sensor_dev_attr_temp3_crit_hyst.dev_attr.attr,
3210 &sensor_dev_attr_temp1_emergency.dev_attr.attr,
3211 &sensor_dev_attr_temp2_emergency.dev_attr.attr,
3212 &sensor_dev_attr_temp3_emergency.dev_attr.attr,
3213 &sensor_dev_attr_temp1_label.dev_attr.attr,
3214 &sensor_dev_attr_temp2_label.dev_attr.attr,
3215 &sensor_dev_attr_temp3_label.dev_attr.attr,
3216 &sensor_dev_attr_pwm1.dev_attr.attr,
3217 &sensor_dev_attr_pwm1_enable.dev_attr.attr,
3218 &sensor_dev_attr_pwm1_min.dev_attr.attr,
3219 &sensor_dev_attr_pwm1_max.dev_attr.attr,
3220 &sensor_dev_attr_fan1_input.dev_attr.attr,
3221 &sensor_dev_attr_fan1_min.dev_attr.attr,
3222 &sensor_dev_attr_fan1_max.dev_attr.attr,
3223 &sensor_dev_attr_fan1_target.dev_attr.attr,
3224 &sensor_dev_attr_fan1_enable.dev_attr.attr,
3225 &sensor_dev_attr_in0_input.dev_attr.attr,
3226 &sensor_dev_attr_in0_label.dev_attr.attr,
3227 &sensor_dev_attr_in1_input.dev_attr.attr,
3228 &sensor_dev_attr_in1_label.dev_attr.attr,
3229 &sensor_dev_attr_power1_average.dev_attr.attr,
3230 &sensor_dev_attr_power1_cap_max.dev_attr.attr,
3231 &sensor_dev_attr_power1_cap_min.dev_attr.attr,
3232 &sensor_dev_attr_power1_cap.dev_attr.attr,
3233 &sensor_dev_attr_freq1_input.dev_attr.attr,
3234 &sensor_dev_attr_freq1_label.dev_attr.attr,
3235 &sensor_dev_attr_freq2_input.dev_attr.attr,
3236 &sensor_dev_attr_freq2_label.dev_attr.attr,
3240 static umode_t hwmon_attributes_visible(struct kobject *kobj,
3241 struct attribute *attr, int index)
3243 struct device *dev = kobj_to_dev(kobj);
3244 struct amdgpu_device *adev = dev_get_drvdata(dev);
3245 umode_t effective_mode = attr->mode;
3247 /* under multi-vf mode, the hwmon attributes are all not supported */
3248 if (amdgpu_sriov_vf(adev) && !amdgpu_sriov_is_pp_one_vf(adev))
3251 /* there is no fan under pp one vf mode */
3252 if (amdgpu_sriov_is_pp_one_vf(adev) &&
3253 (attr == &sensor_dev_attr_pwm1.dev_attr.attr ||
3254 attr == &sensor_dev_attr_pwm1_enable.dev_attr.attr ||
3255 attr == &sensor_dev_attr_pwm1_max.dev_attr.attr ||
3256 attr == &sensor_dev_attr_pwm1_min.dev_attr.attr ||
3257 attr == &sensor_dev_attr_fan1_input.dev_attr.attr ||
3258 attr == &sensor_dev_attr_fan1_min.dev_attr.attr ||
3259 attr == &sensor_dev_attr_fan1_max.dev_attr.attr ||
3260 attr == &sensor_dev_attr_fan1_target.dev_attr.attr ||
3261 attr == &sensor_dev_attr_fan1_enable.dev_attr.attr))
3264 /* Skip fan attributes if fan is not present */
3265 if (adev->pm.no_fan && (attr == &sensor_dev_attr_pwm1.dev_attr.attr ||
3266 attr == &sensor_dev_attr_pwm1_enable.dev_attr.attr ||
3267 attr == &sensor_dev_attr_pwm1_max.dev_attr.attr ||
3268 attr == &sensor_dev_attr_pwm1_min.dev_attr.attr ||
3269 attr == &sensor_dev_attr_fan1_input.dev_attr.attr ||
3270 attr == &sensor_dev_attr_fan1_min.dev_attr.attr ||
3271 attr == &sensor_dev_attr_fan1_max.dev_attr.attr ||
3272 attr == &sensor_dev_attr_fan1_target.dev_attr.attr ||
3273 attr == &sensor_dev_attr_fan1_enable.dev_attr.attr))
3276 /* Skip fan attributes on APU */
3277 if ((adev->flags & AMD_IS_APU) &&
3278 (attr == &sensor_dev_attr_pwm1.dev_attr.attr ||
3279 attr == &sensor_dev_attr_pwm1_enable.dev_attr.attr ||
3280 attr == &sensor_dev_attr_pwm1_max.dev_attr.attr ||
3281 attr == &sensor_dev_attr_pwm1_min.dev_attr.attr ||
3282 attr == &sensor_dev_attr_fan1_input.dev_attr.attr ||
3283 attr == &sensor_dev_attr_fan1_min.dev_attr.attr ||
3284 attr == &sensor_dev_attr_fan1_max.dev_attr.attr ||
3285 attr == &sensor_dev_attr_fan1_target.dev_attr.attr ||
3286 attr == &sensor_dev_attr_fan1_enable.dev_attr.attr))
3289 /* Skip crit temp on APU */
3290 if ((adev->flags & AMD_IS_APU) && (adev->family >= AMDGPU_FAMILY_CZ) &&
3291 (attr == &sensor_dev_attr_temp1_crit.dev_attr.attr ||
3292 attr == &sensor_dev_attr_temp1_crit_hyst.dev_attr.attr))
3295 /* Skip limit attributes if DPM is not enabled */
3296 if (!adev->pm.dpm_enabled &&
3297 (attr == &sensor_dev_attr_temp1_crit.dev_attr.attr ||
3298 attr == &sensor_dev_attr_temp1_crit_hyst.dev_attr.attr ||
3299 attr == &sensor_dev_attr_pwm1.dev_attr.attr ||
3300 attr == &sensor_dev_attr_pwm1_enable.dev_attr.attr ||
3301 attr == &sensor_dev_attr_pwm1_max.dev_attr.attr ||
3302 attr == &sensor_dev_attr_pwm1_min.dev_attr.attr ||
3303 attr == &sensor_dev_attr_fan1_input.dev_attr.attr ||
3304 attr == &sensor_dev_attr_fan1_min.dev_attr.attr ||
3305 attr == &sensor_dev_attr_fan1_max.dev_attr.attr ||
3306 attr == &sensor_dev_attr_fan1_target.dev_attr.attr ||
3307 attr == &sensor_dev_attr_fan1_enable.dev_attr.attr))
3310 if (!is_support_sw_smu(adev)) {
3311 /* mask fan attributes if we have no bindings for this asic to expose */
3312 if ((!adev->powerplay.pp_funcs->get_fan_speed_percent &&
3313 attr == &sensor_dev_attr_pwm1.dev_attr.attr) || /* can't query fan */
3314 (!adev->powerplay.pp_funcs->get_fan_control_mode &&
3315 attr == &sensor_dev_attr_pwm1_enable.dev_attr.attr)) /* can't query state */
3316 effective_mode &= ~S_IRUGO;
3318 if ((!adev->powerplay.pp_funcs->set_fan_speed_percent &&
3319 attr == &sensor_dev_attr_pwm1.dev_attr.attr) || /* can't manage fan */
3320 (!adev->powerplay.pp_funcs->set_fan_control_mode &&
3321 attr == &sensor_dev_attr_pwm1_enable.dev_attr.attr)) /* can't manage state */
3322 effective_mode &= ~S_IWUSR;
3325 if (((adev->flags & AMD_IS_APU) ||
3326 adev->family == AMDGPU_FAMILY_SI) && /* not implemented yet */
3327 (attr == &sensor_dev_attr_power1_cap_max.dev_attr.attr ||
3328 attr == &sensor_dev_attr_power1_cap_min.dev_attr.attr||
3329 attr == &sensor_dev_attr_power1_cap.dev_attr.attr))
3332 if (((adev->family == AMDGPU_FAMILY_SI) ||
3333 ((adev->flags & AMD_IS_APU) &&
3334 (adev->asic_type < CHIP_RENOIR))) && /* not implemented yet */
3335 (attr == &sensor_dev_attr_power1_average.dev_attr.attr))
3338 if (!is_support_sw_smu(adev)) {
3339 /* hide max/min values if we can't both query and manage the fan */
3340 if ((!adev->powerplay.pp_funcs->set_fan_speed_percent &&
3341 !adev->powerplay.pp_funcs->get_fan_speed_percent) &&
3342 (!adev->powerplay.pp_funcs->set_fan_speed_rpm &&
3343 !adev->powerplay.pp_funcs->get_fan_speed_rpm) &&
3344 (attr == &sensor_dev_attr_pwm1_max.dev_attr.attr ||
3345 attr == &sensor_dev_attr_pwm1_min.dev_attr.attr))
3348 if ((!adev->powerplay.pp_funcs->set_fan_speed_rpm &&
3349 !adev->powerplay.pp_funcs->get_fan_speed_rpm) &&
3350 (attr == &sensor_dev_attr_fan1_max.dev_attr.attr ||
3351 attr == &sensor_dev_attr_fan1_min.dev_attr.attr))
3355 if ((adev->family == AMDGPU_FAMILY_SI || /* not implemented yet */
3356 adev->family == AMDGPU_FAMILY_KV) && /* not implemented yet */
3357 (attr == &sensor_dev_attr_in0_input.dev_attr.attr ||
3358 attr == &sensor_dev_attr_in0_label.dev_attr.attr))
3361 /* only APUs have vddnb */
3362 if (!(adev->flags & AMD_IS_APU) &&
3363 (attr == &sensor_dev_attr_in1_input.dev_attr.attr ||
3364 attr == &sensor_dev_attr_in1_label.dev_attr.attr))
3367 /* no mclk on APUs */
3368 if ((adev->flags & AMD_IS_APU) &&
3369 (attr == &sensor_dev_attr_freq2_input.dev_attr.attr ||
3370 attr == &sensor_dev_attr_freq2_label.dev_attr.attr))
3373 /* only SOC15 dGPUs support hotspot and mem temperatures */
3374 if (((adev->flags & AMD_IS_APU) ||
3375 adev->asic_type < CHIP_VEGA10) &&
3376 (attr == &sensor_dev_attr_temp2_crit.dev_attr.attr ||
3377 attr == &sensor_dev_attr_temp2_crit_hyst.dev_attr.attr ||
3378 attr == &sensor_dev_attr_temp3_crit.dev_attr.attr ||
3379 attr == &sensor_dev_attr_temp3_crit_hyst.dev_attr.attr ||
3380 attr == &sensor_dev_attr_temp1_emergency.dev_attr.attr ||
3381 attr == &sensor_dev_attr_temp2_emergency.dev_attr.attr ||
3382 attr == &sensor_dev_attr_temp3_emergency.dev_attr.attr ||
3383 attr == &sensor_dev_attr_temp2_input.dev_attr.attr ||
3384 attr == &sensor_dev_attr_temp3_input.dev_attr.attr ||
3385 attr == &sensor_dev_attr_temp2_label.dev_attr.attr ||
3386 attr == &sensor_dev_attr_temp3_label.dev_attr.attr))
3389 return effective_mode;
3392 static const struct attribute_group hwmon_attrgroup = {
3393 .attrs = hwmon_attributes,
3394 .is_visible = hwmon_attributes_visible,
3397 static const struct attribute_group *hwmon_groups[] = {
3402 int amdgpu_pm_sysfs_init(struct amdgpu_device *adev)
3407 if (adev->pm.sysfs_initialized)
3410 if (adev->pm.dpm_enabled == 0)
3413 INIT_LIST_HEAD(&adev->pm.pm_attr_list);
3415 adev->pm.int_hwmon_dev = hwmon_device_register_with_groups(adev->dev,
3418 if (IS_ERR(adev->pm.int_hwmon_dev)) {
3419 ret = PTR_ERR(adev->pm.int_hwmon_dev);
3421 "Unable to register hwmon device: %d\n", ret);
3425 switch (amdgpu_virt_get_sriov_vf_mode(adev)) {
3426 case SRIOV_VF_MODE_ONE_VF:
3427 mask = ATTR_FLAG_ONEVF;
3429 case SRIOV_VF_MODE_MULTI_VF:
3432 case SRIOV_VF_MODE_BARE_METAL:
3434 mask = ATTR_FLAG_MASK_ALL;
3438 ret = amdgpu_device_attr_create_groups(adev,
3439 amdgpu_device_attrs,
3440 ARRAY_SIZE(amdgpu_device_attrs),
3442 &adev->pm.pm_attr_list);
3446 adev->pm.sysfs_initialized = true;
3451 void amdgpu_pm_sysfs_fini(struct amdgpu_device *adev)
3453 if (adev->pm.dpm_enabled == 0)
3456 if (adev->pm.int_hwmon_dev)
3457 hwmon_device_unregister(adev->pm.int_hwmon_dev);
3459 amdgpu_device_attr_remove_groups(adev, &adev->pm.pm_attr_list);
3465 #if defined(CONFIG_DEBUG_FS)
3467 static int amdgpu_debugfs_pm_info_pp(struct seq_file *m, struct amdgpu_device *adev)
3475 size = sizeof(value);
3476 seq_printf(m, "GFX Clocks and Power:\n");
3477 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GFX_MCLK, (void *)&value, &size))
3478 seq_printf(m, "\t%u MHz (MCLK)\n", value/100);
3479 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GFX_SCLK, (void *)&value, &size))
3480 seq_printf(m, "\t%u MHz (SCLK)\n", value/100);
3481 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_STABLE_PSTATE_SCLK, (void *)&value, &size))
3482 seq_printf(m, "\t%u MHz (PSTATE_SCLK)\n", value/100);
3483 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_STABLE_PSTATE_MCLK, (void *)&value, &size))
3484 seq_printf(m, "\t%u MHz (PSTATE_MCLK)\n", value/100);
3485 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_VDDGFX, (void *)&value, &size))
3486 seq_printf(m, "\t%u mV (VDDGFX)\n", value);
3487 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_VDDNB, (void *)&value, &size))
3488 seq_printf(m, "\t%u mV (VDDNB)\n", value);
3489 size = sizeof(uint32_t);
3490 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GPU_POWER, (void *)&query, &size))
3491 seq_printf(m, "\t%u.%u W (average GPU)\n", query >> 8, query & 0xff);
3492 size = sizeof(value);
3493 seq_printf(m, "\n");
3496 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GPU_TEMP, (void *)&value, &size))
3497 seq_printf(m, "GPU Temperature: %u C\n", value/1000);
3500 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GPU_LOAD, (void *)&value, &size))
3501 seq_printf(m, "GPU Load: %u %%\n", value);
3503 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_MEM_LOAD, (void *)&value, &size))
3504 seq_printf(m, "MEM Load: %u %%\n", value);
3506 seq_printf(m, "\n");
3508 /* SMC feature mask */
3509 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_ENABLED_SMC_FEATURES_MASK, (void *)&value64, &size))
3510 seq_printf(m, "SMC Feature Mask: 0x%016llx\n", value64);
3512 if (adev->asic_type > CHIP_VEGA20) {
3514 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_VCN_POWER_STATE, (void *)&value, &size)) {
3516 seq_printf(m, "VCN: Disabled\n");
3518 seq_printf(m, "VCN: Enabled\n");
3519 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_UVD_DCLK, (void *)&value, &size))
3520 seq_printf(m, "\t%u MHz (DCLK)\n", value/100);
3521 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_UVD_VCLK, (void *)&value, &size))
3522 seq_printf(m, "\t%u MHz (VCLK)\n", value/100);
3525 seq_printf(m, "\n");
3528 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_UVD_POWER, (void *)&value, &size)) {
3530 seq_printf(m, "UVD: Disabled\n");
3532 seq_printf(m, "UVD: Enabled\n");
3533 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_UVD_DCLK, (void *)&value, &size))
3534 seq_printf(m, "\t%u MHz (DCLK)\n", value/100);
3535 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_UVD_VCLK, (void *)&value, &size))
3536 seq_printf(m, "\t%u MHz (VCLK)\n", value/100);
3539 seq_printf(m, "\n");
3542 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_VCE_POWER, (void *)&value, &size)) {
3544 seq_printf(m, "VCE: Disabled\n");
3546 seq_printf(m, "VCE: Enabled\n");
3547 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_VCE_ECCLK, (void *)&value, &size))
3548 seq_printf(m, "\t%u MHz (ECCLK)\n", value/100);
3556 static void amdgpu_parse_cg_state(struct seq_file *m, u32 flags)
3560 for (i = 0; clocks[i].flag; i++)
3561 seq_printf(m, "\t%s: %s\n", clocks[i].name,
3562 (flags & clocks[i].flag) ? "On" : "Off");
3565 static int amdgpu_debugfs_pm_info(struct seq_file *m, void *data)
3567 struct drm_info_node *node = (struct drm_info_node *) m->private;
3568 struct drm_device *dev = node->minor->dev;
3569 struct amdgpu_device *adev = drm_to_adev(dev);
3573 if (amdgpu_in_reset(adev))
3576 r = pm_runtime_get_sync(dev->dev);
3578 pm_runtime_put_autosuspend(dev->dev);
3582 if (!adev->pm.dpm_enabled) {
3583 seq_printf(m, "dpm not enabled\n");
3584 pm_runtime_mark_last_busy(dev->dev);
3585 pm_runtime_put_autosuspend(dev->dev);
3589 if (!is_support_sw_smu(adev) &&
3590 adev->powerplay.pp_funcs->debugfs_print_current_performance_level) {
3591 mutex_lock(&adev->pm.mutex);
3592 if (adev->powerplay.pp_funcs->debugfs_print_current_performance_level)
3593 adev->powerplay.pp_funcs->debugfs_print_current_performance_level(adev, m);
3595 seq_printf(m, "Debugfs support not implemented for this asic\n");
3596 mutex_unlock(&adev->pm.mutex);
3599 r = amdgpu_debugfs_pm_info_pp(m, adev);
3604 amdgpu_device_ip_get_clockgating_state(adev, &flags);
3606 seq_printf(m, "Clock Gating Flags Mask: 0x%x\n", flags);
3607 amdgpu_parse_cg_state(m, flags);
3608 seq_printf(m, "\n");
3611 pm_runtime_mark_last_busy(dev->dev);
3612 pm_runtime_put_autosuspend(dev->dev);
3617 static const struct drm_info_list amdgpu_pm_info_list[] = {
3618 {"amdgpu_pm_info", amdgpu_debugfs_pm_info, 0, NULL},
3622 int amdgpu_debugfs_pm_init(struct amdgpu_device *adev)
3624 #if defined(CONFIG_DEBUG_FS)
3625 return amdgpu_debugfs_add_files(adev, amdgpu_pm_info_list, ARRAY_SIZE(amdgpu_pm_info_list));