2 * Copyright 2017 Advanced Micro Devices, Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
27 #include "amdgpu_drv.h"
28 #include "amdgpu_pm.h"
29 #include "amdgpu_dpm.h"
31 #include <linux/pci.h>
32 #include <linux/hwmon.h>
33 #include <linux/hwmon-sysfs.h>
34 #include <linux/nospec.h>
35 #include <linux/pm_runtime.h>
36 #include <asm/processor.h>
38 static const struct cg_flag_name clocks[] = {
39 {AMD_CG_SUPPORT_GFX_FGCG, "Graphics Fine Grain Clock Gating"},
40 {AMD_CG_SUPPORT_GFX_MGCG, "Graphics Medium Grain Clock Gating"},
41 {AMD_CG_SUPPORT_GFX_MGLS, "Graphics Medium Grain memory Light Sleep"},
42 {AMD_CG_SUPPORT_GFX_CGCG, "Graphics Coarse Grain Clock Gating"},
43 {AMD_CG_SUPPORT_GFX_CGLS, "Graphics Coarse Grain memory Light Sleep"},
44 {AMD_CG_SUPPORT_GFX_CGTS, "Graphics Coarse Grain Tree Shader Clock Gating"},
45 {AMD_CG_SUPPORT_GFX_CGTS_LS, "Graphics Coarse Grain Tree Shader Light Sleep"},
46 {AMD_CG_SUPPORT_GFX_CP_LS, "Graphics Command Processor Light Sleep"},
47 {AMD_CG_SUPPORT_GFX_RLC_LS, "Graphics Run List Controller Light Sleep"},
48 {AMD_CG_SUPPORT_GFX_3D_CGCG, "Graphics 3D Coarse Grain Clock Gating"},
49 {AMD_CG_SUPPORT_GFX_3D_CGLS, "Graphics 3D Coarse Grain memory Light Sleep"},
50 {AMD_CG_SUPPORT_MC_LS, "Memory Controller Light Sleep"},
51 {AMD_CG_SUPPORT_MC_MGCG, "Memory Controller Medium Grain Clock Gating"},
52 {AMD_CG_SUPPORT_SDMA_LS, "System Direct Memory Access Light Sleep"},
53 {AMD_CG_SUPPORT_SDMA_MGCG, "System Direct Memory Access Medium Grain Clock Gating"},
54 {AMD_CG_SUPPORT_BIF_MGCG, "Bus Interface Medium Grain Clock Gating"},
55 {AMD_CG_SUPPORT_BIF_LS, "Bus Interface Light Sleep"},
56 {AMD_CG_SUPPORT_UVD_MGCG, "Unified Video Decoder Medium Grain Clock Gating"},
57 {AMD_CG_SUPPORT_VCE_MGCG, "Video Compression Engine Medium Grain Clock Gating"},
58 {AMD_CG_SUPPORT_HDP_LS, "Host Data Path Light Sleep"},
59 {AMD_CG_SUPPORT_HDP_MGCG, "Host Data Path Medium Grain Clock Gating"},
60 {AMD_CG_SUPPORT_DRM_MGCG, "Digital Right Management Medium Grain Clock Gating"},
61 {AMD_CG_SUPPORT_DRM_LS, "Digital Right Management Light Sleep"},
62 {AMD_CG_SUPPORT_ROM_MGCG, "Rom Medium Grain Clock Gating"},
63 {AMD_CG_SUPPORT_DF_MGCG, "Data Fabric Medium Grain Clock Gating"},
64 {AMD_CG_SUPPORT_VCN_MGCG, "VCN Medium Grain Clock Gating"},
65 {AMD_CG_SUPPORT_HDP_DS, "Host Data Path Deep Sleep"},
66 {AMD_CG_SUPPORT_HDP_SD, "Host Data Path Shutdown"},
67 {AMD_CG_SUPPORT_IH_CG, "Interrupt Handler Clock Gating"},
68 {AMD_CG_SUPPORT_JPEG_MGCG, "JPEG Medium Grain Clock Gating"},
70 {AMD_CG_SUPPORT_ATHUB_MGCG, "Address Translation Hub Medium Grain Clock Gating"},
71 {AMD_CG_SUPPORT_ATHUB_LS, "Address Translation Hub Light Sleep"},
75 static const struct hwmon_temp_label {
76 enum PP_HWMON_TEMP channel;
79 {PP_TEMP_EDGE, "edge"},
80 {PP_TEMP_JUNCTION, "junction"},
84 const char * const amdgpu_pp_profile_name[] = {
95 * DOC: power_dpm_state
97 * The power_dpm_state file is a legacy interface and is only provided for
98 * backwards compatibility. The amdgpu driver provides a sysfs API for adjusting
99 * certain power related parameters. The file power_dpm_state is used for this.
100 * It accepts the following arguments:
110 * On older GPUs, the vbios provided a special power state for battery
111 * operation. Selecting battery switched to this state. This is no
112 * longer provided on newer GPUs so the option does nothing in that case.
116 * On older GPUs, the vbios provided a special power state for balanced
117 * operation. Selecting balanced switched to this state. This is no
118 * longer provided on newer GPUs so the option does nothing in that case.
122 * On older GPUs, the vbios provided a special power state for performance
123 * operation. Selecting performance switched to this state. This is no
124 * longer provided on newer GPUs so the option does nothing in that case.
128 static ssize_t amdgpu_get_power_dpm_state(struct device *dev,
129 struct device_attribute *attr,
132 struct drm_device *ddev = dev_get_drvdata(dev);
133 struct amdgpu_device *adev = drm_to_adev(ddev);
134 enum amd_pm_state_type pm;
137 if (amdgpu_in_reset(adev))
139 if (adev->in_suspend && !adev->in_runpm)
142 ret = pm_runtime_get_sync(ddev->dev);
144 pm_runtime_put_autosuspend(ddev->dev);
148 amdgpu_dpm_get_current_power_state(adev, &pm);
150 pm_runtime_mark_last_busy(ddev->dev);
151 pm_runtime_put_autosuspend(ddev->dev);
153 return sysfs_emit(buf, "%s\n",
154 (pm == POWER_STATE_TYPE_BATTERY) ? "battery" :
155 (pm == POWER_STATE_TYPE_BALANCED) ? "balanced" : "performance");
158 static ssize_t amdgpu_set_power_dpm_state(struct device *dev,
159 struct device_attribute *attr,
163 struct drm_device *ddev = dev_get_drvdata(dev);
164 struct amdgpu_device *adev = drm_to_adev(ddev);
165 enum amd_pm_state_type state;
168 if (amdgpu_in_reset(adev))
170 if (adev->in_suspend && !adev->in_runpm)
173 if (strncmp("battery", buf, strlen("battery")) == 0)
174 state = POWER_STATE_TYPE_BATTERY;
175 else if (strncmp("balanced", buf, strlen("balanced")) == 0)
176 state = POWER_STATE_TYPE_BALANCED;
177 else if (strncmp("performance", buf, strlen("performance")) == 0)
178 state = POWER_STATE_TYPE_PERFORMANCE;
182 ret = pm_runtime_get_sync(ddev->dev);
184 pm_runtime_put_autosuspend(ddev->dev);
188 amdgpu_dpm_set_power_state(adev, state);
190 pm_runtime_mark_last_busy(ddev->dev);
191 pm_runtime_put_autosuspend(ddev->dev);
198 * DOC: power_dpm_force_performance_level
200 * The amdgpu driver provides a sysfs API for adjusting certain power
201 * related parameters. The file power_dpm_force_performance_level is
202 * used for this. It accepts the following arguments:
222 * When auto is selected, the driver will attempt to dynamically select
223 * the optimal power profile for current conditions in the driver.
227 * When low is selected, the clocks are forced to the lowest power state.
231 * When high is selected, the clocks are forced to the highest power state.
235 * When manual is selected, the user can manually adjust which power states
236 * are enabled for each clock domain via the sysfs pp_dpm_mclk, pp_dpm_sclk,
237 * and pp_dpm_pcie files and adjust the power state transition heuristics
238 * via the pp_power_profile_mode sysfs file.
245 * When the profiling modes are selected, clock and power gating are
246 * disabled and the clocks are set for different profiling cases. This
247 * mode is recommended for profiling specific work loads where you do
248 * not want clock or power gating for clock fluctuation to interfere
249 * with your results. profile_standard sets the clocks to a fixed clock
250 * level which varies from asic to asic. profile_min_sclk forces the sclk
251 * to the lowest level. profile_min_mclk forces the mclk to the lowest level.
252 * profile_peak sets all clocks (mclk, sclk, pcie) to the highest levels.
256 static ssize_t amdgpu_get_power_dpm_force_performance_level(struct device *dev,
257 struct device_attribute *attr,
260 struct drm_device *ddev = dev_get_drvdata(dev);
261 struct amdgpu_device *adev = drm_to_adev(ddev);
262 enum amd_dpm_forced_level level = 0xff;
265 if (amdgpu_in_reset(adev))
267 if (adev->in_suspend && !adev->in_runpm)
270 ret = pm_runtime_get_sync(ddev->dev);
272 pm_runtime_put_autosuspend(ddev->dev);
276 level = amdgpu_dpm_get_performance_level(adev);
278 pm_runtime_mark_last_busy(ddev->dev);
279 pm_runtime_put_autosuspend(ddev->dev);
281 return sysfs_emit(buf, "%s\n",
282 (level == AMD_DPM_FORCED_LEVEL_AUTO) ? "auto" :
283 (level == AMD_DPM_FORCED_LEVEL_LOW) ? "low" :
284 (level == AMD_DPM_FORCED_LEVEL_HIGH) ? "high" :
285 (level == AMD_DPM_FORCED_LEVEL_MANUAL) ? "manual" :
286 (level == AMD_DPM_FORCED_LEVEL_PROFILE_STANDARD) ? "profile_standard" :
287 (level == AMD_DPM_FORCED_LEVEL_PROFILE_MIN_SCLK) ? "profile_min_sclk" :
288 (level == AMD_DPM_FORCED_LEVEL_PROFILE_MIN_MCLK) ? "profile_min_mclk" :
289 (level == AMD_DPM_FORCED_LEVEL_PROFILE_PEAK) ? "profile_peak" :
290 (level == AMD_DPM_FORCED_LEVEL_PERF_DETERMINISM) ? "perf_determinism" :
294 static ssize_t amdgpu_set_power_dpm_force_performance_level(struct device *dev,
295 struct device_attribute *attr,
299 struct drm_device *ddev = dev_get_drvdata(dev);
300 struct amdgpu_device *adev = drm_to_adev(ddev);
301 enum amd_dpm_forced_level level;
304 if (amdgpu_in_reset(adev))
306 if (adev->in_suspend && !adev->in_runpm)
309 if (strncmp("low", buf, strlen("low")) == 0) {
310 level = AMD_DPM_FORCED_LEVEL_LOW;
311 } else if (strncmp("high", buf, strlen("high")) == 0) {
312 level = AMD_DPM_FORCED_LEVEL_HIGH;
313 } else if (strncmp("auto", buf, strlen("auto")) == 0) {
314 level = AMD_DPM_FORCED_LEVEL_AUTO;
315 } else if (strncmp("manual", buf, strlen("manual")) == 0) {
316 level = AMD_DPM_FORCED_LEVEL_MANUAL;
317 } else if (strncmp("profile_exit", buf, strlen("profile_exit")) == 0) {
318 level = AMD_DPM_FORCED_LEVEL_PROFILE_EXIT;
319 } else if (strncmp("profile_standard", buf, strlen("profile_standard")) == 0) {
320 level = AMD_DPM_FORCED_LEVEL_PROFILE_STANDARD;
321 } else if (strncmp("profile_min_sclk", buf, strlen("profile_min_sclk")) == 0) {
322 level = AMD_DPM_FORCED_LEVEL_PROFILE_MIN_SCLK;
323 } else if (strncmp("profile_min_mclk", buf, strlen("profile_min_mclk")) == 0) {
324 level = AMD_DPM_FORCED_LEVEL_PROFILE_MIN_MCLK;
325 } else if (strncmp("profile_peak", buf, strlen("profile_peak")) == 0) {
326 level = AMD_DPM_FORCED_LEVEL_PROFILE_PEAK;
327 } else if (strncmp("perf_determinism", buf, strlen("perf_determinism")) == 0) {
328 level = AMD_DPM_FORCED_LEVEL_PERF_DETERMINISM;
333 ret = pm_runtime_get_sync(ddev->dev);
335 pm_runtime_put_autosuspend(ddev->dev);
339 mutex_lock(&adev->pm.stable_pstate_ctx_lock);
340 if (amdgpu_dpm_force_performance_level(adev, level)) {
341 pm_runtime_mark_last_busy(ddev->dev);
342 pm_runtime_put_autosuspend(ddev->dev);
343 mutex_unlock(&adev->pm.stable_pstate_ctx_lock);
346 /* override whatever a user ctx may have set */
347 adev->pm.stable_pstate_ctx = NULL;
348 mutex_unlock(&adev->pm.stable_pstate_ctx_lock);
350 pm_runtime_mark_last_busy(ddev->dev);
351 pm_runtime_put_autosuspend(ddev->dev);
356 static ssize_t amdgpu_get_pp_num_states(struct device *dev,
357 struct device_attribute *attr,
360 struct drm_device *ddev = dev_get_drvdata(dev);
361 struct amdgpu_device *adev = drm_to_adev(ddev);
362 struct pp_states_info data;
366 if (amdgpu_in_reset(adev))
368 if (adev->in_suspend && !adev->in_runpm)
371 ret = pm_runtime_get_sync(ddev->dev);
373 pm_runtime_put_autosuspend(ddev->dev);
377 if (amdgpu_dpm_get_pp_num_states(adev, &data))
378 memset(&data, 0, sizeof(data));
380 pm_runtime_mark_last_busy(ddev->dev);
381 pm_runtime_put_autosuspend(ddev->dev);
383 buf_len = sysfs_emit(buf, "states: %d\n", data.nums);
384 for (i = 0; i < data.nums; i++)
385 buf_len += sysfs_emit_at(buf, buf_len, "%d %s\n", i,
386 (data.states[i] == POWER_STATE_TYPE_INTERNAL_BOOT) ? "boot" :
387 (data.states[i] == POWER_STATE_TYPE_BATTERY) ? "battery" :
388 (data.states[i] == POWER_STATE_TYPE_BALANCED) ? "balanced" :
389 (data.states[i] == POWER_STATE_TYPE_PERFORMANCE) ? "performance" : "default");
394 static ssize_t amdgpu_get_pp_cur_state(struct device *dev,
395 struct device_attribute *attr,
398 struct drm_device *ddev = dev_get_drvdata(dev);
399 struct amdgpu_device *adev = drm_to_adev(ddev);
400 struct pp_states_info data = {0};
401 enum amd_pm_state_type pm = 0;
404 if (amdgpu_in_reset(adev))
406 if (adev->in_suspend && !adev->in_runpm)
409 ret = pm_runtime_get_sync(ddev->dev);
411 pm_runtime_put_autosuspend(ddev->dev);
415 amdgpu_dpm_get_current_power_state(adev, &pm);
417 ret = amdgpu_dpm_get_pp_num_states(adev, &data);
419 pm_runtime_mark_last_busy(ddev->dev);
420 pm_runtime_put_autosuspend(ddev->dev);
425 for (i = 0; i < data.nums; i++) {
426 if (pm == data.states[i])
433 return sysfs_emit(buf, "%d\n", i);
436 static ssize_t amdgpu_get_pp_force_state(struct device *dev,
437 struct device_attribute *attr,
440 struct drm_device *ddev = dev_get_drvdata(dev);
441 struct amdgpu_device *adev = drm_to_adev(ddev);
443 if (amdgpu_in_reset(adev))
445 if (adev->in_suspend && !adev->in_runpm)
448 if (adev->pm.pp_force_state_enabled)
449 return amdgpu_get_pp_cur_state(dev, attr, buf);
451 return sysfs_emit(buf, "\n");
454 static ssize_t amdgpu_set_pp_force_state(struct device *dev,
455 struct device_attribute *attr,
459 struct drm_device *ddev = dev_get_drvdata(dev);
460 struct amdgpu_device *adev = drm_to_adev(ddev);
461 enum amd_pm_state_type state = 0;
462 struct pp_states_info data;
466 if (amdgpu_in_reset(adev))
468 if (adev->in_suspend && !adev->in_runpm)
471 adev->pm.pp_force_state_enabled = false;
473 if (strlen(buf) == 1)
476 ret = kstrtoul(buf, 0, &idx);
477 if (ret || idx >= ARRAY_SIZE(data.states))
480 idx = array_index_nospec(idx, ARRAY_SIZE(data.states));
482 ret = pm_runtime_get_sync(ddev->dev);
484 pm_runtime_put_autosuspend(ddev->dev);
488 ret = amdgpu_dpm_get_pp_num_states(adev, &data);
492 state = data.states[idx];
494 /* only set user selected power states */
495 if (state != POWER_STATE_TYPE_INTERNAL_BOOT &&
496 state != POWER_STATE_TYPE_DEFAULT) {
497 ret = amdgpu_dpm_dispatch_task(adev,
498 AMD_PP_TASK_ENABLE_USER_STATE, &state);
502 adev->pm.pp_force_state_enabled = true;
505 pm_runtime_mark_last_busy(ddev->dev);
506 pm_runtime_put_autosuspend(ddev->dev);
511 pm_runtime_mark_last_busy(ddev->dev);
512 pm_runtime_put_autosuspend(ddev->dev);
519 * The amdgpu driver provides a sysfs API for uploading new powerplay
520 * tables. The file pp_table is used for this. Reading the file
521 * will dump the current power play table. Writing to the file
522 * will attempt to upload a new powerplay table and re-initialize
523 * powerplay using that new table.
527 static ssize_t amdgpu_get_pp_table(struct device *dev,
528 struct device_attribute *attr,
531 struct drm_device *ddev = dev_get_drvdata(dev);
532 struct amdgpu_device *adev = drm_to_adev(ddev);
536 if (amdgpu_in_reset(adev))
538 if (adev->in_suspend && !adev->in_runpm)
541 ret = pm_runtime_get_sync(ddev->dev);
543 pm_runtime_put_autosuspend(ddev->dev);
547 size = amdgpu_dpm_get_pp_table(adev, &table);
549 pm_runtime_mark_last_busy(ddev->dev);
550 pm_runtime_put_autosuspend(ddev->dev);
555 if (size >= PAGE_SIZE)
556 size = PAGE_SIZE - 1;
558 memcpy(buf, table, size);
563 static ssize_t amdgpu_set_pp_table(struct device *dev,
564 struct device_attribute *attr,
568 struct drm_device *ddev = dev_get_drvdata(dev);
569 struct amdgpu_device *adev = drm_to_adev(ddev);
572 if (amdgpu_in_reset(adev))
574 if (adev->in_suspend && !adev->in_runpm)
577 ret = pm_runtime_get_sync(ddev->dev);
579 pm_runtime_put_autosuspend(ddev->dev);
583 ret = amdgpu_dpm_set_pp_table(adev, buf, count);
585 pm_runtime_mark_last_busy(ddev->dev);
586 pm_runtime_put_autosuspend(ddev->dev);
595 * DOC: pp_od_clk_voltage
597 * The amdgpu driver provides a sysfs API for adjusting the clocks and voltages
598 * in each power level within a power state. The pp_od_clk_voltage is used for
601 * Note that the actual memory controller clock rate are exposed, not
602 * the effective memory clock of the DRAMs. To translate it, use the
605 * Clock conversion (Mhz):
607 * HBM: effective_memory_clock = memory_controller_clock * 1
609 * G5: effective_memory_clock = memory_controller_clock * 1
611 * G6: effective_memory_clock = memory_controller_clock * 2
613 * DRAM data rate (MT/s):
615 * HBM: effective_memory_clock * 2 = data_rate
617 * G5: effective_memory_clock * 4 = data_rate
619 * G6: effective_memory_clock * 8 = data_rate
623 * data_rate * vram_bit_width / 8 = memory_bandwidth
629 * memory_controller_clock = 1750 Mhz
631 * effective_memory_clock = 1750 Mhz * 1 = 1750 Mhz
633 * data rate = 1750 * 4 = 7000 MT/s
635 * memory_bandwidth = 7000 * 128 bits / 8 = 112000 MB/s
639 * memory_controller_clock = 875 Mhz
641 * effective_memory_clock = 875 Mhz * 2 = 1750 Mhz
643 * data rate = 1750 * 8 = 14000 MT/s
645 * memory_bandwidth = 14000 * 256 bits / 8 = 448000 MB/s
647 * < For Vega10 and previous ASICs >
649 * Reading the file will display:
651 * - a list of engine clock levels and voltages labeled OD_SCLK
653 * - a list of memory clock levels and voltages labeled OD_MCLK
655 * - a list of valid ranges for sclk, mclk, and voltage labeled OD_RANGE
657 * To manually adjust these settings, first select manual using
658 * power_dpm_force_performance_level. Enter a new value for each
659 * level by writing a string that contains "s/m level clock voltage" to
660 * the file. E.g., "s 1 500 820" will update sclk level 1 to be 500 MHz
661 * at 820 mV; "m 0 350 810" will update mclk level 0 to be 350 MHz at
662 * 810 mV. When you have edited all of the states as needed, write
663 * "c" (commit) to the file to commit your changes. If you want to reset to the
664 * default power levels, write "r" (reset) to the file to reset them.
667 * < For Vega20 and newer ASICs >
669 * Reading the file will display:
671 * - minimum and maximum engine clock labeled OD_SCLK
673 * - minimum(not available for Vega20 and Navi1x) and maximum memory
674 * clock labeled OD_MCLK
676 * - three <frequency, voltage> points labeled OD_VDDC_CURVE.
677 * They can be used to calibrate the sclk voltage curve.
679 * - voltage offset(in mV) applied on target voltage calculation.
680 * This is available for Sienna Cichlid, Navy Flounder and Dimgrey
681 * Cavefish. For these ASICs, the target voltage calculation can be
682 * illustrated by "voltage = voltage calculated from v/f curve +
683 * overdrive vddgfx offset"
685 * - a list of valid ranges for sclk, mclk, and voltage curve points
690 * Reading the file will display:
692 * - minimum and maximum engine clock labeled OD_SCLK
694 * - a list of valid ranges for sclk labeled OD_RANGE
698 * Reading the file will display:
700 * - minimum and maximum engine clock labeled OD_SCLK
701 * - minimum and maximum core clocks labeled OD_CCLK
703 * - a list of valid ranges for sclk and cclk labeled OD_RANGE
705 * To manually adjust these settings:
707 * - First select manual using power_dpm_force_performance_level
709 * - For clock frequency setting, enter a new value by writing a
710 * string that contains "s/m index clock" to the file. The index
711 * should be 0 if to set minimum clock. And 1 if to set maximum
712 * clock. E.g., "s 0 500" will update minimum sclk to be 500 MHz.
713 * "m 1 800" will update maximum mclk to be 800Mhz. For core
714 * clocks on VanGogh, the string contains "p core index clock".
715 * E.g., "p 2 0 800" would set the minimum core clock on core
718 * For sclk voltage curve, enter the new values by writing a
719 * string that contains "vc point clock voltage" to the file. The
720 * points are indexed by 0, 1 and 2. E.g., "vc 0 300 600" will
721 * update point1 with clock set as 300Mhz and voltage as
722 * 600mV. "vc 2 1000 1000" will update point3 with clock set
723 * as 1000Mhz and voltage 1000mV.
725 * To update the voltage offset applied for gfxclk/voltage calculation,
726 * enter the new value by writing a string that contains "vo offset".
727 * This is supported by Sienna Cichlid, Navy Flounder and Dimgrey Cavefish.
728 * And the offset can be a positive or negative value.
730 * - When you have edited all of the states as needed, write "c" (commit)
731 * to the file to commit your changes
733 * - If you want to reset to the default power levels, write "r" (reset)
734 * to the file to reset them
738 static ssize_t amdgpu_set_pp_od_clk_voltage(struct device *dev,
739 struct device_attribute *attr,
743 struct drm_device *ddev = dev_get_drvdata(dev);
744 struct amdgpu_device *adev = drm_to_adev(ddev);
746 uint32_t parameter_size = 0;
751 const char delimiter[3] = {' ', '\n', '\0'};
754 if (amdgpu_in_reset(adev))
756 if (adev->in_suspend && !adev->in_runpm)
763 type = PP_OD_EDIT_SCLK_VDDC_TABLE;
764 else if (*buf == 'p')
765 type = PP_OD_EDIT_CCLK_VDDC_TABLE;
766 else if (*buf == 'm')
767 type = PP_OD_EDIT_MCLK_VDDC_TABLE;
769 type = PP_OD_RESTORE_DEFAULT_TABLE;
770 else if (*buf == 'c')
771 type = PP_OD_COMMIT_DPM_TABLE;
772 else if (!strncmp(buf, "vc", 2))
773 type = PP_OD_EDIT_VDDC_CURVE;
774 else if (!strncmp(buf, "vo", 2))
775 type = PP_OD_EDIT_VDDGFX_OFFSET;
779 memcpy(buf_cpy, buf, count+1);
783 if ((type == PP_OD_EDIT_VDDC_CURVE) ||
784 (type == PP_OD_EDIT_VDDGFX_OFFSET))
786 while (isspace(*++tmp_str));
788 while ((sub_str = strsep(&tmp_str, delimiter)) != NULL) {
789 if (strlen(sub_str) == 0)
791 ret = kstrtol(sub_str, 0, ¶meter[parameter_size]);
796 while (isspace(*tmp_str))
800 ret = pm_runtime_get_sync(ddev->dev);
802 pm_runtime_put_autosuspend(ddev->dev);
806 if (amdgpu_dpm_set_fine_grain_clk_vol(adev,
812 if (amdgpu_dpm_odn_edit_dpm_table(adev, type,
813 parameter, parameter_size))
816 if (type == PP_OD_COMMIT_DPM_TABLE) {
817 if (amdgpu_dpm_dispatch_task(adev,
818 AMD_PP_TASK_READJUST_POWER_STATE,
823 pm_runtime_mark_last_busy(ddev->dev);
824 pm_runtime_put_autosuspend(ddev->dev);
829 pm_runtime_mark_last_busy(ddev->dev);
830 pm_runtime_put_autosuspend(ddev->dev);
834 static ssize_t amdgpu_get_pp_od_clk_voltage(struct device *dev,
835 struct device_attribute *attr,
838 struct drm_device *ddev = dev_get_drvdata(dev);
839 struct amdgpu_device *adev = drm_to_adev(ddev);
842 enum pp_clock_type od_clocks[6] = {
852 if (amdgpu_in_reset(adev))
854 if (adev->in_suspend && !adev->in_runpm)
857 ret = pm_runtime_get_sync(ddev->dev);
859 pm_runtime_put_autosuspend(ddev->dev);
863 for (clk_index = 0 ; clk_index < 6 ; clk_index++) {
864 ret = amdgpu_dpm_emit_clock_levels(adev, od_clocks[clk_index], buf, &size);
868 if (ret == -ENOENT) {
869 size = amdgpu_dpm_print_clock_levels(adev, OD_SCLK, buf);
871 size += amdgpu_dpm_print_clock_levels(adev, OD_MCLK, buf + size);
872 size += amdgpu_dpm_print_clock_levels(adev, OD_VDDC_CURVE, buf + size);
873 size += amdgpu_dpm_print_clock_levels(adev, OD_VDDGFX_OFFSET, buf + size);
874 size += amdgpu_dpm_print_clock_levels(adev, OD_RANGE, buf + size);
875 size += amdgpu_dpm_print_clock_levels(adev, OD_CCLK, buf + size);
880 size = sysfs_emit(buf, "\n");
882 pm_runtime_mark_last_busy(ddev->dev);
883 pm_runtime_put_autosuspend(ddev->dev);
891 * The amdgpu driver provides a sysfs API for adjusting what powerplay
892 * features to be enabled. The file pp_features is used for this. And
893 * this is only available for Vega10 and later dGPUs.
895 * Reading back the file will show you the followings:
896 * - Current ppfeature masks
897 * - List of the all supported powerplay features with their naming,
898 * bitmasks and enablement status('Y'/'N' means "enabled"/"disabled").
900 * To manually enable or disable a specific feature, just set or clear
901 * the corresponding bit from original ppfeature masks and input the
902 * new ppfeature masks.
904 static ssize_t amdgpu_set_pp_features(struct device *dev,
905 struct device_attribute *attr,
909 struct drm_device *ddev = dev_get_drvdata(dev);
910 struct amdgpu_device *adev = drm_to_adev(ddev);
911 uint64_t featuremask;
914 if (amdgpu_in_reset(adev))
916 if (adev->in_suspend && !adev->in_runpm)
919 ret = kstrtou64(buf, 0, &featuremask);
923 ret = pm_runtime_get_sync(ddev->dev);
925 pm_runtime_put_autosuspend(ddev->dev);
929 ret = amdgpu_dpm_set_ppfeature_status(adev, featuremask);
931 pm_runtime_mark_last_busy(ddev->dev);
932 pm_runtime_put_autosuspend(ddev->dev);
940 static ssize_t amdgpu_get_pp_features(struct device *dev,
941 struct device_attribute *attr,
944 struct drm_device *ddev = dev_get_drvdata(dev);
945 struct amdgpu_device *adev = drm_to_adev(ddev);
949 if (amdgpu_in_reset(adev))
951 if (adev->in_suspend && !adev->in_runpm)
954 ret = pm_runtime_get_sync(ddev->dev);
956 pm_runtime_put_autosuspend(ddev->dev);
960 size = amdgpu_dpm_get_ppfeature_status(adev, buf);
962 size = sysfs_emit(buf, "\n");
964 pm_runtime_mark_last_busy(ddev->dev);
965 pm_runtime_put_autosuspend(ddev->dev);
971 * DOC: pp_dpm_sclk pp_dpm_mclk pp_dpm_socclk pp_dpm_fclk pp_dpm_dcefclk pp_dpm_pcie
973 * The amdgpu driver provides a sysfs API for adjusting what power levels
974 * are enabled for a given power state. The files pp_dpm_sclk, pp_dpm_mclk,
975 * pp_dpm_socclk, pp_dpm_fclk, pp_dpm_dcefclk and pp_dpm_pcie are used for
978 * pp_dpm_socclk and pp_dpm_dcefclk interfaces are only available for
979 * Vega10 and later ASICs.
980 * pp_dpm_fclk interface is only available for Vega20 and later ASICs.
982 * Reading back the files will show you the available power levels within
983 * the power state and the clock information for those levels.
985 * To manually adjust these states, first select manual using
986 * power_dpm_force_performance_level.
987 * Secondly, enter a new value for each level by inputing a string that
988 * contains " echo xx xx xx > pp_dpm_sclk/mclk/pcie"
991 * .. code-block:: bash
993 * echo "4 5 6" > pp_dpm_sclk
995 * will enable sclk levels 4, 5, and 6.
997 * NOTE: change to the dcefclk max dpm level is not supported now
1000 static ssize_t amdgpu_get_pp_dpm_clock(struct device *dev,
1001 enum pp_clock_type type,
1004 struct drm_device *ddev = dev_get_drvdata(dev);
1005 struct amdgpu_device *adev = drm_to_adev(ddev);
1009 if (amdgpu_in_reset(adev))
1011 if (adev->in_suspend && !adev->in_runpm)
1014 ret = pm_runtime_get_sync(ddev->dev);
1016 pm_runtime_put_autosuspend(ddev->dev);
1020 ret = amdgpu_dpm_emit_clock_levels(adev, type, buf, &size);
1022 size = amdgpu_dpm_print_clock_levels(adev, type, buf);
1025 size = sysfs_emit(buf, "\n");
1027 pm_runtime_mark_last_busy(ddev->dev);
1028 pm_runtime_put_autosuspend(ddev->dev);
1034 * Worst case: 32 bits individually specified, in octal at 12 characters
1035 * per line (+1 for \n).
1037 #define AMDGPU_MASK_BUF_MAX (32 * 13)
1039 static ssize_t amdgpu_read_mask(const char *buf, size_t count, uint32_t *mask)
1042 unsigned long level;
1043 char *sub_str = NULL;
1045 char buf_cpy[AMDGPU_MASK_BUF_MAX + 1];
1046 const char delimiter[3] = {' ', '\n', '\0'};
1051 bytes = min(count, sizeof(buf_cpy) - 1);
1052 memcpy(buf_cpy, buf, bytes);
1053 buf_cpy[bytes] = '\0';
1055 while ((sub_str = strsep(&tmp, delimiter)) != NULL) {
1056 if (strlen(sub_str)) {
1057 ret = kstrtoul(sub_str, 0, &level);
1058 if (ret || level > 31)
1060 *mask |= 1 << level;
1068 static ssize_t amdgpu_set_pp_dpm_clock(struct device *dev,
1069 enum pp_clock_type type,
1073 struct drm_device *ddev = dev_get_drvdata(dev);
1074 struct amdgpu_device *adev = drm_to_adev(ddev);
1078 if (amdgpu_in_reset(adev))
1080 if (adev->in_suspend && !adev->in_runpm)
1083 ret = amdgpu_read_mask(buf, count, &mask);
1087 ret = pm_runtime_get_sync(ddev->dev);
1089 pm_runtime_put_autosuspend(ddev->dev);
1093 ret = amdgpu_dpm_force_clock_level(adev, type, mask);
1095 pm_runtime_mark_last_busy(ddev->dev);
1096 pm_runtime_put_autosuspend(ddev->dev);
1104 static ssize_t amdgpu_get_pp_dpm_sclk(struct device *dev,
1105 struct device_attribute *attr,
1108 return amdgpu_get_pp_dpm_clock(dev, PP_SCLK, buf);
1111 static ssize_t amdgpu_set_pp_dpm_sclk(struct device *dev,
1112 struct device_attribute *attr,
1116 return amdgpu_set_pp_dpm_clock(dev, PP_SCLK, buf, count);
1119 static ssize_t amdgpu_get_pp_dpm_mclk(struct device *dev,
1120 struct device_attribute *attr,
1123 return amdgpu_get_pp_dpm_clock(dev, PP_MCLK, buf);
1126 static ssize_t amdgpu_set_pp_dpm_mclk(struct device *dev,
1127 struct device_attribute *attr,
1131 return amdgpu_set_pp_dpm_clock(dev, PP_MCLK, buf, count);
1134 static ssize_t amdgpu_get_pp_dpm_socclk(struct device *dev,
1135 struct device_attribute *attr,
1138 return amdgpu_get_pp_dpm_clock(dev, PP_SOCCLK, buf);
1141 static ssize_t amdgpu_set_pp_dpm_socclk(struct device *dev,
1142 struct device_attribute *attr,
1146 return amdgpu_set_pp_dpm_clock(dev, PP_SOCCLK, buf, count);
1149 static ssize_t amdgpu_get_pp_dpm_fclk(struct device *dev,
1150 struct device_attribute *attr,
1153 return amdgpu_get_pp_dpm_clock(dev, PP_FCLK, buf);
1156 static ssize_t amdgpu_set_pp_dpm_fclk(struct device *dev,
1157 struct device_attribute *attr,
1161 return amdgpu_set_pp_dpm_clock(dev, PP_FCLK, buf, count);
1164 static ssize_t amdgpu_get_pp_dpm_vclk(struct device *dev,
1165 struct device_attribute *attr,
1168 return amdgpu_get_pp_dpm_clock(dev, PP_VCLK, buf);
1171 static ssize_t amdgpu_set_pp_dpm_vclk(struct device *dev,
1172 struct device_attribute *attr,
1176 return amdgpu_set_pp_dpm_clock(dev, PP_VCLK, buf, count);
1179 static ssize_t amdgpu_get_pp_dpm_dclk(struct device *dev,
1180 struct device_attribute *attr,
1183 return amdgpu_get_pp_dpm_clock(dev, PP_DCLK, buf);
1186 static ssize_t amdgpu_set_pp_dpm_dclk(struct device *dev,
1187 struct device_attribute *attr,
1191 return amdgpu_set_pp_dpm_clock(dev, PP_DCLK, buf, count);
1194 static ssize_t amdgpu_get_pp_dpm_dcefclk(struct device *dev,
1195 struct device_attribute *attr,
1198 return amdgpu_get_pp_dpm_clock(dev, PP_DCEFCLK, buf);
1201 static ssize_t amdgpu_set_pp_dpm_dcefclk(struct device *dev,
1202 struct device_attribute *attr,
1206 return amdgpu_set_pp_dpm_clock(dev, PP_DCEFCLK, buf, count);
1209 static ssize_t amdgpu_get_pp_dpm_pcie(struct device *dev,
1210 struct device_attribute *attr,
1213 return amdgpu_get_pp_dpm_clock(dev, PP_PCIE, buf);
1216 static ssize_t amdgpu_set_pp_dpm_pcie(struct device *dev,
1217 struct device_attribute *attr,
1221 return amdgpu_set_pp_dpm_clock(dev, PP_PCIE, buf, count);
1224 static ssize_t amdgpu_get_pp_sclk_od(struct device *dev,
1225 struct device_attribute *attr,
1228 struct drm_device *ddev = dev_get_drvdata(dev);
1229 struct amdgpu_device *adev = drm_to_adev(ddev);
1233 if (amdgpu_in_reset(adev))
1235 if (adev->in_suspend && !adev->in_runpm)
1238 ret = pm_runtime_get_sync(ddev->dev);
1240 pm_runtime_put_autosuspend(ddev->dev);
1244 value = amdgpu_dpm_get_sclk_od(adev);
1246 pm_runtime_mark_last_busy(ddev->dev);
1247 pm_runtime_put_autosuspend(ddev->dev);
1249 return sysfs_emit(buf, "%d\n", value);
1252 static ssize_t amdgpu_set_pp_sclk_od(struct device *dev,
1253 struct device_attribute *attr,
1257 struct drm_device *ddev = dev_get_drvdata(dev);
1258 struct amdgpu_device *adev = drm_to_adev(ddev);
1262 if (amdgpu_in_reset(adev))
1264 if (adev->in_suspend && !adev->in_runpm)
1267 ret = kstrtol(buf, 0, &value);
1272 ret = pm_runtime_get_sync(ddev->dev);
1274 pm_runtime_put_autosuspend(ddev->dev);
1278 amdgpu_dpm_set_sclk_od(adev, (uint32_t)value);
1280 pm_runtime_mark_last_busy(ddev->dev);
1281 pm_runtime_put_autosuspend(ddev->dev);
1286 static ssize_t amdgpu_get_pp_mclk_od(struct device *dev,
1287 struct device_attribute *attr,
1290 struct drm_device *ddev = dev_get_drvdata(dev);
1291 struct amdgpu_device *adev = drm_to_adev(ddev);
1295 if (amdgpu_in_reset(adev))
1297 if (adev->in_suspend && !adev->in_runpm)
1300 ret = pm_runtime_get_sync(ddev->dev);
1302 pm_runtime_put_autosuspend(ddev->dev);
1306 value = amdgpu_dpm_get_mclk_od(adev);
1308 pm_runtime_mark_last_busy(ddev->dev);
1309 pm_runtime_put_autosuspend(ddev->dev);
1311 return sysfs_emit(buf, "%d\n", value);
1314 static ssize_t amdgpu_set_pp_mclk_od(struct device *dev,
1315 struct device_attribute *attr,
1319 struct drm_device *ddev = dev_get_drvdata(dev);
1320 struct amdgpu_device *adev = drm_to_adev(ddev);
1324 if (amdgpu_in_reset(adev))
1326 if (adev->in_suspend && !adev->in_runpm)
1329 ret = kstrtol(buf, 0, &value);
1334 ret = pm_runtime_get_sync(ddev->dev);
1336 pm_runtime_put_autosuspend(ddev->dev);
1340 amdgpu_dpm_set_mclk_od(adev, (uint32_t)value);
1342 pm_runtime_mark_last_busy(ddev->dev);
1343 pm_runtime_put_autosuspend(ddev->dev);
1349 * DOC: pp_power_profile_mode
1351 * The amdgpu driver provides a sysfs API for adjusting the heuristics
1352 * related to switching between power levels in a power state. The file
1353 * pp_power_profile_mode is used for this.
1355 * Reading this file outputs a list of all of the predefined power profiles
1356 * and the relevant heuristics settings for that profile.
1358 * To select a profile or create a custom profile, first select manual using
1359 * power_dpm_force_performance_level. Writing the number of a predefined
1360 * profile to pp_power_profile_mode will enable those heuristics. To
1361 * create a custom set of heuristics, write a string of numbers to the file
1362 * starting with the number of the custom profile along with a setting
1363 * for each heuristic parameter. Due to differences across asic families
1364 * the heuristic parameters vary from family to family.
1368 static ssize_t amdgpu_get_pp_power_profile_mode(struct device *dev,
1369 struct device_attribute *attr,
1372 struct drm_device *ddev = dev_get_drvdata(dev);
1373 struct amdgpu_device *adev = drm_to_adev(ddev);
1377 if (amdgpu_in_reset(adev))
1379 if (adev->in_suspend && !adev->in_runpm)
1382 ret = pm_runtime_get_sync(ddev->dev);
1384 pm_runtime_put_autosuspend(ddev->dev);
1388 size = amdgpu_dpm_get_power_profile_mode(adev, buf);
1390 size = sysfs_emit(buf, "\n");
1392 pm_runtime_mark_last_busy(ddev->dev);
1393 pm_runtime_put_autosuspend(ddev->dev);
1399 static ssize_t amdgpu_set_pp_power_profile_mode(struct device *dev,
1400 struct device_attribute *attr,
1405 struct drm_device *ddev = dev_get_drvdata(dev);
1406 struct amdgpu_device *adev = drm_to_adev(ddev);
1407 uint32_t parameter_size = 0;
1409 char *sub_str, buf_cpy[128];
1413 long int profile_mode = 0;
1414 const char delimiter[3] = {' ', '\n', '\0'};
1416 if (amdgpu_in_reset(adev))
1418 if (adev->in_suspend && !adev->in_runpm)
1423 ret = kstrtol(tmp, 0, &profile_mode);
1427 if (profile_mode == PP_SMC_POWER_PROFILE_CUSTOM) {
1428 if (count < 2 || count > 127)
1430 while (isspace(*++buf))
1432 memcpy(buf_cpy, buf, count-i);
1434 while ((sub_str = strsep(&tmp_str, delimiter)) != NULL) {
1435 if (strlen(sub_str) == 0)
1437 ret = kstrtol(sub_str, 0, ¶meter[parameter_size]);
1441 while (isspace(*tmp_str))
1445 parameter[parameter_size] = profile_mode;
1447 ret = pm_runtime_get_sync(ddev->dev);
1449 pm_runtime_put_autosuspend(ddev->dev);
1453 ret = amdgpu_dpm_set_power_profile_mode(adev, parameter, parameter_size);
1455 pm_runtime_mark_last_busy(ddev->dev);
1456 pm_runtime_put_autosuspend(ddev->dev);
1465 * DOC: gpu_busy_percent
1467 * The amdgpu driver provides a sysfs API for reading how busy the GPU
1468 * is as a percentage. The file gpu_busy_percent is used for this.
1469 * The SMU firmware computes a percentage of load based on the
1470 * aggregate activity level in the IP cores.
1472 static ssize_t amdgpu_get_gpu_busy_percent(struct device *dev,
1473 struct device_attribute *attr,
1476 struct drm_device *ddev = dev_get_drvdata(dev);
1477 struct amdgpu_device *adev = drm_to_adev(ddev);
1478 int r, value, size = sizeof(value);
1480 if (amdgpu_in_reset(adev))
1482 if (adev->in_suspend && !adev->in_runpm)
1485 r = pm_runtime_get_sync(ddev->dev);
1487 pm_runtime_put_autosuspend(ddev->dev);
1491 /* read the IP busy sensor */
1492 r = amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GPU_LOAD,
1493 (void *)&value, &size);
1495 pm_runtime_mark_last_busy(ddev->dev);
1496 pm_runtime_put_autosuspend(ddev->dev);
1501 return sysfs_emit(buf, "%d\n", value);
1505 * DOC: mem_busy_percent
1507 * The amdgpu driver provides a sysfs API for reading how busy the VRAM
1508 * is as a percentage. The file mem_busy_percent is used for this.
1509 * The SMU firmware computes a percentage of load based on the
1510 * aggregate activity level in the IP cores.
1512 static ssize_t amdgpu_get_mem_busy_percent(struct device *dev,
1513 struct device_attribute *attr,
1516 struct drm_device *ddev = dev_get_drvdata(dev);
1517 struct amdgpu_device *adev = drm_to_adev(ddev);
1518 int r, value, size = sizeof(value);
1520 if (amdgpu_in_reset(adev))
1522 if (adev->in_suspend && !adev->in_runpm)
1525 r = pm_runtime_get_sync(ddev->dev);
1527 pm_runtime_put_autosuspend(ddev->dev);
1531 /* read the IP busy sensor */
1532 r = amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_MEM_LOAD,
1533 (void *)&value, &size);
1535 pm_runtime_mark_last_busy(ddev->dev);
1536 pm_runtime_put_autosuspend(ddev->dev);
1541 return sysfs_emit(buf, "%d\n", value);
1547 * The amdgpu driver provides a sysfs API for estimating how much data
1548 * has been received and sent by the GPU in the last second through PCIe.
1549 * The file pcie_bw is used for this.
1550 * The Perf counters count the number of received and sent messages and return
1551 * those values, as well as the maximum payload size of a PCIe packet (mps).
1552 * Note that it is not possible to easily and quickly obtain the size of each
1553 * packet transmitted, so we output the max payload size (mps) to allow for
1554 * quick estimation of the PCIe bandwidth usage
1556 static ssize_t amdgpu_get_pcie_bw(struct device *dev,
1557 struct device_attribute *attr,
1560 struct drm_device *ddev = dev_get_drvdata(dev);
1561 struct amdgpu_device *adev = drm_to_adev(ddev);
1562 uint64_t count0 = 0, count1 = 0;
1565 if (amdgpu_in_reset(adev))
1567 if (adev->in_suspend && !adev->in_runpm)
1570 if (adev->flags & AMD_IS_APU)
1573 if (!adev->asic_funcs->get_pcie_usage)
1576 ret = pm_runtime_get_sync(ddev->dev);
1578 pm_runtime_put_autosuspend(ddev->dev);
1582 amdgpu_asic_get_pcie_usage(adev, &count0, &count1);
1584 pm_runtime_mark_last_busy(ddev->dev);
1585 pm_runtime_put_autosuspend(ddev->dev);
1587 return sysfs_emit(buf, "%llu %llu %i\n",
1588 count0, count1, pcie_get_mps(adev->pdev));
1594 * The amdgpu driver provides a sysfs API for providing a unique ID for the GPU
1595 * The file unique_id is used for this.
1596 * This will provide a Unique ID that will persist from machine to machine
1598 * NOTE: This will only work for GFX9 and newer. This file will be absent
1599 * on unsupported ASICs (GFX8 and older)
1601 static ssize_t amdgpu_get_unique_id(struct device *dev,
1602 struct device_attribute *attr,
1605 struct drm_device *ddev = dev_get_drvdata(dev);
1606 struct amdgpu_device *adev = drm_to_adev(ddev);
1608 if (amdgpu_in_reset(adev))
1610 if (adev->in_suspend && !adev->in_runpm)
1613 if (adev->unique_id)
1614 return sysfs_emit(buf, "%016llx\n", adev->unique_id);
1620 * DOC: thermal_throttling_logging
1622 * Thermal throttling pulls down the clock frequency and thus the performance.
1623 * It's an useful mechanism to protect the chip from overheating. Since it
1624 * impacts performance, the user controls whether it is enabled and if so,
1625 * the log frequency.
1627 * Reading back the file shows you the status(enabled or disabled) and
1628 * the interval(in seconds) between each thermal logging.
1630 * Writing an integer to the file, sets a new logging interval, in seconds.
1631 * The value should be between 1 and 3600. If the value is less than 1,
1632 * thermal logging is disabled. Values greater than 3600 are ignored.
1634 static ssize_t amdgpu_get_thermal_throttling_logging(struct device *dev,
1635 struct device_attribute *attr,
1638 struct drm_device *ddev = dev_get_drvdata(dev);
1639 struct amdgpu_device *adev = drm_to_adev(ddev);
1641 return sysfs_emit(buf, "%s: thermal throttling logging %s, with interval %d seconds\n",
1642 adev_to_drm(adev)->unique,
1643 atomic_read(&adev->throttling_logging_enabled) ? "enabled" : "disabled",
1644 adev->throttling_logging_rs.interval / HZ + 1);
1647 static ssize_t amdgpu_set_thermal_throttling_logging(struct device *dev,
1648 struct device_attribute *attr,
1652 struct drm_device *ddev = dev_get_drvdata(dev);
1653 struct amdgpu_device *adev = drm_to_adev(ddev);
1654 long throttling_logging_interval;
1655 unsigned long flags;
1658 ret = kstrtol(buf, 0, &throttling_logging_interval);
1662 if (throttling_logging_interval > 3600)
1665 if (throttling_logging_interval > 0) {
1666 raw_spin_lock_irqsave(&adev->throttling_logging_rs.lock, flags);
1668 * Reset the ratelimit timer internals.
1669 * This can effectively restart the timer.
1671 adev->throttling_logging_rs.interval =
1672 (throttling_logging_interval - 1) * HZ;
1673 adev->throttling_logging_rs.begin = 0;
1674 adev->throttling_logging_rs.printed = 0;
1675 adev->throttling_logging_rs.missed = 0;
1676 raw_spin_unlock_irqrestore(&adev->throttling_logging_rs.lock, flags);
1678 atomic_set(&adev->throttling_logging_enabled, 1);
1680 atomic_set(&adev->throttling_logging_enabled, 0);
1689 * The amdgpu driver provides a sysfs API for retrieving current gpu
1690 * metrics data. The file gpu_metrics is used for this. Reading the
1691 * file will dump all the current gpu metrics data.
1693 * These data include temperature, frequency, engines utilization,
1694 * power consume, throttler status, fan speed and cpu core statistics(
1695 * available for APU only). That's it will give a snapshot of all sensors
1698 static ssize_t amdgpu_get_gpu_metrics(struct device *dev,
1699 struct device_attribute *attr,
1702 struct drm_device *ddev = dev_get_drvdata(dev);
1703 struct amdgpu_device *adev = drm_to_adev(ddev);
1708 if (amdgpu_in_reset(adev))
1710 if (adev->in_suspend && !adev->in_runpm)
1713 ret = pm_runtime_get_sync(ddev->dev);
1715 pm_runtime_put_autosuspend(ddev->dev);
1719 size = amdgpu_dpm_get_gpu_metrics(adev, &gpu_metrics);
1723 if (size >= PAGE_SIZE)
1724 size = PAGE_SIZE - 1;
1726 memcpy(buf, gpu_metrics, size);
1729 pm_runtime_mark_last_busy(ddev->dev);
1730 pm_runtime_put_autosuspend(ddev->dev);
1736 * DOC: smartshift_apu_power
1738 * The amdgpu driver provides a sysfs API for reporting APU power
1739 * share if it supports smartshift. The value is expressed as
1740 * the proportion of stapm limit where stapm limit is the total APU
1741 * power limit. The result is in percentage. If APU power is 130% of
1742 * STAPM, then APU is using 30% of the dGPU's headroom.
1745 static ssize_t amdgpu_get_smartshift_apu_power(struct device *dev, struct device_attribute *attr,
1748 struct drm_device *ddev = dev_get_drvdata(dev);
1749 struct amdgpu_device *adev = drm_to_adev(ddev);
1750 uint32_t ss_power, size;
1753 if (amdgpu_in_reset(adev))
1755 if (adev->in_suspend && !adev->in_runpm)
1758 r = pm_runtime_get_sync(ddev->dev);
1760 pm_runtime_put_autosuspend(ddev->dev);
1764 r = amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_SS_APU_SHARE,
1765 (void *)&ss_power, &size);
1769 r = sysfs_emit(buf, "%u%%\n", ss_power);
1772 pm_runtime_mark_last_busy(ddev->dev);
1773 pm_runtime_put_autosuspend(ddev->dev);
1778 * DOC: smartshift_dgpu_power
1780 * The amdgpu driver provides a sysfs API for reporting the dGPU power
1781 * share if the device is in HG and supports smartshift. The value
1782 * is expressed as the proportion of stapm limit where stapm limit
1783 * is the total APU power limit. The value is in percentage. If dGPU
1784 * power is 20% higher than STAPM power(120%), it's using 20% of the
1785 * APU's power headroom.
1788 static ssize_t amdgpu_get_smartshift_dgpu_power(struct device *dev, struct device_attribute *attr,
1791 struct drm_device *ddev = dev_get_drvdata(dev);
1792 struct amdgpu_device *adev = drm_to_adev(ddev);
1793 uint32_t ss_power, size;
1796 if (amdgpu_in_reset(adev))
1798 if (adev->in_suspend && !adev->in_runpm)
1801 r = pm_runtime_get_sync(ddev->dev);
1803 pm_runtime_put_autosuspend(ddev->dev);
1807 r = amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_SS_DGPU_SHARE,
1808 (void *)&ss_power, &size);
1813 r = sysfs_emit(buf, "%u%%\n", ss_power);
1816 pm_runtime_mark_last_busy(ddev->dev);
1817 pm_runtime_put_autosuspend(ddev->dev);
1822 * DOC: smartshift_bias
1824 * The amdgpu driver provides a sysfs API for reporting the
1825 * smartshift(SS2.0) bias level. The value ranges from -100 to 100
1826 * and the default is 0. -100 sets maximum preference to APU
1827 * and 100 sets max perference to dGPU.
1830 static ssize_t amdgpu_get_smartshift_bias(struct device *dev,
1831 struct device_attribute *attr,
1836 r = sysfs_emit(buf, "%d\n", amdgpu_smartshift_bias);
1841 static ssize_t amdgpu_set_smartshift_bias(struct device *dev,
1842 struct device_attribute *attr,
1843 const char *buf, size_t count)
1845 struct drm_device *ddev = dev_get_drvdata(dev);
1846 struct amdgpu_device *adev = drm_to_adev(ddev);
1850 if (amdgpu_in_reset(adev))
1852 if (adev->in_suspend && !adev->in_runpm)
1855 r = pm_runtime_get_sync(ddev->dev);
1857 pm_runtime_put_autosuspend(ddev->dev);
1861 r = kstrtoint(buf, 10, &bias);
1865 if (bias > AMDGPU_SMARTSHIFT_MAX_BIAS)
1866 bias = AMDGPU_SMARTSHIFT_MAX_BIAS;
1867 else if (bias < AMDGPU_SMARTSHIFT_MIN_BIAS)
1868 bias = AMDGPU_SMARTSHIFT_MIN_BIAS;
1870 amdgpu_smartshift_bias = bias;
1873 /* TODO: update bias level with SMU message */
1876 pm_runtime_mark_last_busy(ddev->dev);
1877 pm_runtime_put_autosuspend(ddev->dev);
1882 static int ss_power_attr_update(struct amdgpu_device *adev, struct amdgpu_device_attr *attr,
1883 uint32_t mask, enum amdgpu_device_attr_states *states)
1885 uint32_t ss_power, size;
1887 if (!amdgpu_acpi_is_power_shift_control_supported())
1888 *states = ATTR_STATE_UNSUPPORTED;
1889 else if ((adev->flags & AMD_IS_PX) &&
1890 !amdgpu_device_supports_smart_shift(adev_to_drm(adev)))
1891 *states = ATTR_STATE_UNSUPPORTED;
1892 else if (amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_SS_APU_SHARE,
1893 (void *)&ss_power, &size))
1894 *states = ATTR_STATE_UNSUPPORTED;
1895 else if (amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_SS_DGPU_SHARE,
1896 (void *)&ss_power, &size))
1897 *states = ATTR_STATE_UNSUPPORTED;
1902 static int ss_bias_attr_update(struct amdgpu_device *adev, struct amdgpu_device_attr *attr,
1903 uint32_t mask, enum amdgpu_device_attr_states *states)
1905 uint32_t ss_power, size;
1907 if (!amdgpu_device_supports_smart_shift(adev_to_drm(adev)))
1908 *states = ATTR_STATE_UNSUPPORTED;
1909 else if (amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_SS_APU_SHARE,
1910 (void *)&ss_power, &size))
1911 *states = ATTR_STATE_UNSUPPORTED;
1912 else if (amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_SS_DGPU_SHARE,
1913 (void *)&ss_power, &size))
1914 *states = ATTR_STATE_UNSUPPORTED;
1919 static struct amdgpu_device_attr amdgpu_device_attrs[] = {
1920 AMDGPU_DEVICE_ATTR_RW(power_dpm_state, ATTR_FLAG_BASIC|ATTR_FLAG_ONEVF),
1921 AMDGPU_DEVICE_ATTR_RW(power_dpm_force_performance_level, ATTR_FLAG_BASIC|ATTR_FLAG_ONEVF),
1922 AMDGPU_DEVICE_ATTR_RO(pp_num_states, ATTR_FLAG_BASIC|ATTR_FLAG_ONEVF),
1923 AMDGPU_DEVICE_ATTR_RO(pp_cur_state, ATTR_FLAG_BASIC|ATTR_FLAG_ONEVF),
1924 AMDGPU_DEVICE_ATTR_RW(pp_force_state, ATTR_FLAG_BASIC|ATTR_FLAG_ONEVF),
1925 AMDGPU_DEVICE_ATTR_RW(pp_table, ATTR_FLAG_BASIC|ATTR_FLAG_ONEVF),
1926 AMDGPU_DEVICE_ATTR_RW(pp_dpm_sclk, ATTR_FLAG_BASIC|ATTR_FLAG_ONEVF),
1927 AMDGPU_DEVICE_ATTR_RW(pp_dpm_mclk, ATTR_FLAG_BASIC|ATTR_FLAG_ONEVF),
1928 AMDGPU_DEVICE_ATTR_RW(pp_dpm_socclk, ATTR_FLAG_BASIC|ATTR_FLAG_ONEVF),
1929 AMDGPU_DEVICE_ATTR_RW(pp_dpm_fclk, ATTR_FLAG_BASIC|ATTR_FLAG_ONEVF),
1930 AMDGPU_DEVICE_ATTR_RW(pp_dpm_vclk, ATTR_FLAG_BASIC|ATTR_FLAG_ONEVF),
1931 AMDGPU_DEVICE_ATTR_RW(pp_dpm_dclk, ATTR_FLAG_BASIC|ATTR_FLAG_ONEVF),
1932 AMDGPU_DEVICE_ATTR_RW(pp_dpm_dcefclk, ATTR_FLAG_BASIC|ATTR_FLAG_ONEVF),
1933 AMDGPU_DEVICE_ATTR_RW(pp_dpm_pcie, ATTR_FLAG_BASIC|ATTR_FLAG_ONEVF),
1934 AMDGPU_DEVICE_ATTR_RW(pp_sclk_od, ATTR_FLAG_BASIC),
1935 AMDGPU_DEVICE_ATTR_RW(pp_mclk_od, ATTR_FLAG_BASIC),
1936 AMDGPU_DEVICE_ATTR_RW(pp_power_profile_mode, ATTR_FLAG_BASIC|ATTR_FLAG_ONEVF),
1937 AMDGPU_DEVICE_ATTR_RW(pp_od_clk_voltage, ATTR_FLAG_BASIC),
1938 AMDGPU_DEVICE_ATTR_RO(gpu_busy_percent, ATTR_FLAG_BASIC|ATTR_FLAG_ONEVF),
1939 AMDGPU_DEVICE_ATTR_RO(mem_busy_percent, ATTR_FLAG_BASIC|ATTR_FLAG_ONEVF),
1940 AMDGPU_DEVICE_ATTR_RO(pcie_bw, ATTR_FLAG_BASIC),
1941 AMDGPU_DEVICE_ATTR_RW(pp_features, ATTR_FLAG_BASIC|ATTR_FLAG_ONEVF),
1942 AMDGPU_DEVICE_ATTR_RO(unique_id, ATTR_FLAG_BASIC|ATTR_FLAG_ONEVF),
1943 AMDGPU_DEVICE_ATTR_RW(thermal_throttling_logging, ATTR_FLAG_BASIC|ATTR_FLAG_ONEVF),
1944 AMDGPU_DEVICE_ATTR_RO(gpu_metrics, ATTR_FLAG_BASIC|ATTR_FLAG_ONEVF),
1945 AMDGPU_DEVICE_ATTR_RO(smartshift_apu_power, ATTR_FLAG_BASIC,
1946 .attr_update = ss_power_attr_update),
1947 AMDGPU_DEVICE_ATTR_RO(smartshift_dgpu_power, ATTR_FLAG_BASIC,
1948 .attr_update = ss_power_attr_update),
1949 AMDGPU_DEVICE_ATTR_RW(smartshift_bias, ATTR_FLAG_BASIC,
1950 .attr_update = ss_bias_attr_update),
1953 static int default_attr_update(struct amdgpu_device *adev, struct amdgpu_device_attr *attr,
1954 uint32_t mask, enum amdgpu_device_attr_states *states)
1956 struct device_attribute *dev_attr = &attr->dev_attr;
1957 const char *attr_name = dev_attr->attr.name;
1958 enum amd_asic_type asic_type = adev->asic_type;
1960 if (!(attr->flags & mask)) {
1961 *states = ATTR_STATE_UNSUPPORTED;
1965 #define DEVICE_ATTR_IS(_name) (!strcmp(attr_name, #_name))
1967 if (DEVICE_ATTR_IS(pp_dpm_socclk)) {
1968 if (asic_type < CHIP_VEGA10)
1969 *states = ATTR_STATE_UNSUPPORTED;
1970 } else if (DEVICE_ATTR_IS(pp_dpm_dcefclk)) {
1971 if (asic_type < CHIP_VEGA10 ||
1972 asic_type == CHIP_ARCTURUS ||
1973 asic_type == CHIP_ALDEBARAN)
1974 *states = ATTR_STATE_UNSUPPORTED;
1975 } else if (DEVICE_ATTR_IS(pp_dpm_fclk)) {
1976 if (asic_type < CHIP_VEGA20)
1977 *states = ATTR_STATE_UNSUPPORTED;
1978 } else if (DEVICE_ATTR_IS(pp_od_clk_voltage)) {
1979 *states = ATTR_STATE_UNSUPPORTED;
1980 if (amdgpu_dpm_is_overdrive_supported(adev))
1981 *states = ATTR_STATE_SUPPORTED;
1982 } else if (DEVICE_ATTR_IS(mem_busy_percent)) {
1983 if (adev->flags & AMD_IS_APU || asic_type == CHIP_VEGA10)
1984 *states = ATTR_STATE_UNSUPPORTED;
1985 } else if (DEVICE_ATTR_IS(pcie_bw)) {
1986 /* PCIe Perf counters won't work on APU nodes */
1987 if (adev->flags & AMD_IS_APU)
1988 *states = ATTR_STATE_UNSUPPORTED;
1989 } else if (DEVICE_ATTR_IS(unique_id)) {
1990 if (asic_type != CHIP_VEGA10 &&
1991 asic_type != CHIP_VEGA20 &&
1992 asic_type != CHIP_ARCTURUS &&
1993 asic_type != CHIP_ALDEBARAN)
1994 *states = ATTR_STATE_UNSUPPORTED;
1995 } else if (DEVICE_ATTR_IS(pp_features)) {
1996 if (adev->flags & AMD_IS_APU || asic_type < CHIP_VEGA10)
1997 *states = ATTR_STATE_UNSUPPORTED;
1998 } else if (DEVICE_ATTR_IS(gpu_metrics)) {
1999 if (asic_type < CHIP_VEGA12)
2000 *states = ATTR_STATE_UNSUPPORTED;
2001 } else if (DEVICE_ATTR_IS(pp_dpm_vclk)) {
2002 if (!(asic_type == CHIP_VANGOGH || asic_type == CHIP_SIENNA_CICHLID))
2003 *states = ATTR_STATE_UNSUPPORTED;
2004 } else if (DEVICE_ATTR_IS(pp_dpm_dclk)) {
2005 if (!(asic_type == CHIP_VANGOGH || asic_type == CHIP_SIENNA_CICHLID))
2006 *states = ATTR_STATE_UNSUPPORTED;
2007 } else if (DEVICE_ATTR_IS(pp_power_profile_mode)) {
2008 if (amdgpu_dpm_get_power_profile_mode(adev, NULL) == -EOPNOTSUPP)
2009 *states = ATTR_STATE_UNSUPPORTED;
2012 switch (asic_type) {
2014 case CHIP_ALDEBARAN:
2015 /* the Mi series card does not support standalone mclk/socclk/fclk level setting */
2016 if (DEVICE_ATTR_IS(pp_dpm_mclk) ||
2017 DEVICE_ATTR_IS(pp_dpm_socclk) ||
2018 DEVICE_ATTR_IS(pp_dpm_fclk)) {
2019 dev_attr->attr.mode &= ~S_IWUGO;
2020 dev_attr->store = NULL;
2027 if (DEVICE_ATTR_IS(pp_dpm_dcefclk)) {
2028 /* SMU MP1 does not support dcefclk level setting */
2029 if (asic_type >= CHIP_NAVI10) {
2030 dev_attr->attr.mode &= ~S_IWUGO;
2031 dev_attr->store = NULL;
2035 /* setting should not be allowed from VF if not in one VF mode */
2036 if (amdgpu_sriov_vf(adev) && !amdgpu_sriov_is_pp_one_vf(adev)) {
2037 dev_attr->attr.mode &= ~S_IWUGO;
2038 dev_attr->store = NULL;
2041 #undef DEVICE_ATTR_IS
2047 static int amdgpu_device_attr_create(struct amdgpu_device *adev,
2048 struct amdgpu_device_attr *attr,
2049 uint32_t mask, struct list_head *attr_list)
2052 struct device_attribute *dev_attr = &attr->dev_attr;
2053 const char *name = dev_attr->attr.name;
2054 enum amdgpu_device_attr_states attr_states = ATTR_STATE_SUPPORTED;
2055 struct amdgpu_device_attr_entry *attr_entry;
2057 int (*attr_update)(struct amdgpu_device *adev, struct amdgpu_device_attr *attr,
2058 uint32_t mask, enum amdgpu_device_attr_states *states) = default_attr_update;
2062 attr_update = attr->attr_update ? attr->attr_update : default_attr_update;
2064 ret = attr_update(adev, attr, mask, &attr_states);
2066 dev_err(adev->dev, "failed to update device file %s, ret = %d\n",
2071 if (attr_states == ATTR_STATE_UNSUPPORTED)
2074 ret = device_create_file(adev->dev, dev_attr);
2076 dev_err(adev->dev, "failed to create device file %s, ret = %d\n",
2080 attr_entry = kmalloc(sizeof(*attr_entry), GFP_KERNEL);
2084 attr_entry->attr = attr;
2085 INIT_LIST_HEAD(&attr_entry->entry);
2087 list_add_tail(&attr_entry->entry, attr_list);
2092 static void amdgpu_device_attr_remove(struct amdgpu_device *adev, struct amdgpu_device_attr *attr)
2094 struct device_attribute *dev_attr = &attr->dev_attr;
2096 device_remove_file(adev->dev, dev_attr);
2099 static void amdgpu_device_attr_remove_groups(struct amdgpu_device *adev,
2100 struct list_head *attr_list);
2102 static int amdgpu_device_attr_create_groups(struct amdgpu_device *adev,
2103 struct amdgpu_device_attr *attrs,
2106 struct list_head *attr_list)
2111 for (i = 0; i < counts; i++) {
2112 ret = amdgpu_device_attr_create(adev, &attrs[i], mask, attr_list);
2120 amdgpu_device_attr_remove_groups(adev, attr_list);
2125 static void amdgpu_device_attr_remove_groups(struct amdgpu_device *adev,
2126 struct list_head *attr_list)
2128 struct amdgpu_device_attr_entry *entry, *entry_tmp;
2130 if (list_empty(attr_list))
2133 list_for_each_entry_safe(entry, entry_tmp, attr_list, entry) {
2134 amdgpu_device_attr_remove(adev, entry->attr);
2135 list_del(&entry->entry);
2140 static ssize_t amdgpu_hwmon_show_temp(struct device *dev,
2141 struct device_attribute *attr,
2144 struct amdgpu_device *adev = dev_get_drvdata(dev);
2145 int channel = to_sensor_dev_attr(attr)->index;
2146 int r, temp = 0, size = sizeof(temp);
2148 if (amdgpu_in_reset(adev))
2150 if (adev->in_suspend && !adev->in_runpm)
2153 if (channel >= PP_TEMP_MAX)
2156 r = pm_runtime_get_sync(adev_to_drm(adev)->dev);
2158 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2163 case PP_TEMP_JUNCTION:
2164 /* get current junction temperature */
2165 r = amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_HOTSPOT_TEMP,
2166 (void *)&temp, &size);
2169 /* get current edge temperature */
2170 r = amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_EDGE_TEMP,
2171 (void *)&temp, &size);
2174 /* get current memory temperature */
2175 r = amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_MEM_TEMP,
2176 (void *)&temp, &size);
2183 pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
2184 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2189 return sysfs_emit(buf, "%d\n", temp);
2192 static ssize_t amdgpu_hwmon_show_temp_thresh(struct device *dev,
2193 struct device_attribute *attr,
2196 struct amdgpu_device *adev = dev_get_drvdata(dev);
2197 int hyst = to_sensor_dev_attr(attr)->index;
2201 temp = adev->pm.dpm.thermal.min_temp;
2203 temp = adev->pm.dpm.thermal.max_temp;
2205 return sysfs_emit(buf, "%d\n", temp);
2208 static ssize_t amdgpu_hwmon_show_hotspot_temp_thresh(struct device *dev,
2209 struct device_attribute *attr,
2212 struct amdgpu_device *adev = dev_get_drvdata(dev);
2213 int hyst = to_sensor_dev_attr(attr)->index;
2217 temp = adev->pm.dpm.thermal.min_hotspot_temp;
2219 temp = adev->pm.dpm.thermal.max_hotspot_crit_temp;
2221 return sysfs_emit(buf, "%d\n", temp);
2224 static ssize_t amdgpu_hwmon_show_mem_temp_thresh(struct device *dev,
2225 struct device_attribute *attr,
2228 struct amdgpu_device *adev = dev_get_drvdata(dev);
2229 int hyst = to_sensor_dev_attr(attr)->index;
2233 temp = adev->pm.dpm.thermal.min_mem_temp;
2235 temp = adev->pm.dpm.thermal.max_mem_crit_temp;
2237 return sysfs_emit(buf, "%d\n", temp);
2240 static ssize_t amdgpu_hwmon_show_temp_label(struct device *dev,
2241 struct device_attribute *attr,
2244 int channel = to_sensor_dev_attr(attr)->index;
2246 if (channel >= PP_TEMP_MAX)
2249 return sysfs_emit(buf, "%s\n", temp_label[channel].label);
2252 static ssize_t amdgpu_hwmon_show_temp_emergency(struct device *dev,
2253 struct device_attribute *attr,
2256 struct amdgpu_device *adev = dev_get_drvdata(dev);
2257 int channel = to_sensor_dev_attr(attr)->index;
2260 if (channel >= PP_TEMP_MAX)
2264 case PP_TEMP_JUNCTION:
2265 temp = adev->pm.dpm.thermal.max_hotspot_emergency_temp;
2268 temp = adev->pm.dpm.thermal.max_edge_emergency_temp;
2271 temp = adev->pm.dpm.thermal.max_mem_emergency_temp;
2275 return sysfs_emit(buf, "%d\n", temp);
2278 static ssize_t amdgpu_hwmon_get_pwm1_enable(struct device *dev,
2279 struct device_attribute *attr,
2282 struct amdgpu_device *adev = dev_get_drvdata(dev);
2286 if (amdgpu_in_reset(adev))
2288 if (adev->in_suspend && !adev->in_runpm)
2291 ret = pm_runtime_get_sync(adev_to_drm(adev)->dev);
2293 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2297 ret = amdgpu_dpm_get_fan_control_mode(adev, &pwm_mode);
2299 pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
2300 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2305 return sysfs_emit(buf, "%u\n", pwm_mode);
2308 static ssize_t amdgpu_hwmon_set_pwm1_enable(struct device *dev,
2309 struct device_attribute *attr,
2313 struct amdgpu_device *adev = dev_get_drvdata(dev);
2317 if (amdgpu_in_reset(adev))
2319 if (adev->in_suspend && !adev->in_runpm)
2322 err = kstrtoint(buf, 10, &value);
2326 ret = pm_runtime_get_sync(adev_to_drm(adev)->dev);
2328 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2332 ret = amdgpu_dpm_set_fan_control_mode(adev, value);
2334 pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
2335 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2343 static ssize_t amdgpu_hwmon_get_pwm1_min(struct device *dev,
2344 struct device_attribute *attr,
2347 return sysfs_emit(buf, "%i\n", 0);
2350 static ssize_t amdgpu_hwmon_get_pwm1_max(struct device *dev,
2351 struct device_attribute *attr,
2354 return sysfs_emit(buf, "%i\n", 255);
2357 static ssize_t amdgpu_hwmon_set_pwm1(struct device *dev,
2358 struct device_attribute *attr,
2359 const char *buf, size_t count)
2361 struct amdgpu_device *adev = dev_get_drvdata(dev);
2366 if (amdgpu_in_reset(adev))
2368 if (adev->in_suspend && !adev->in_runpm)
2371 err = kstrtou32(buf, 10, &value);
2375 err = pm_runtime_get_sync(adev_to_drm(adev)->dev);
2377 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2381 err = amdgpu_dpm_get_fan_control_mode(adev, &pwm_mode);
2385 if (pwm_mode != AMD_FAN_CTRL_MANUAL) {
2386 pr_info("manual fan speed control should be enabled first\n");
2391 err = amdgpu_dpm_set_fan_speed_pwm(adev, value);
2394 pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
2395 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2403 static ssize_t amdgpu_hwmon_get_pwm1(struct device *dev,
2404 struct device_attribute *attr,
2407 struct amdgpu_device *adev = dev_get_drvdata(dev);
2411 if (amdgpu_in_reset(adev))
2413 if (adev->in_suspend && !adev->in_runpm)
2416 err = pm_runtime_get_sync(adev_to_drm(adev)->dev);
2418 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2422 err = amdgpu_dpm_get_fan_speed_pwm(adev, &speed);
2424 pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
2425 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2430 return sysfs_emit(buf, "%i\n", speed);
2433 static ssize_t amdgpu_hwmon_get_fan1_input(struct device *dev,
2434 struct device_attribute *attr,
2437 struct amdgpu_device *adev = dev_get_drvdata(dev);
2441 if (amdgpu_in_reset(adev))
2443 if (adev->in_suspend && !adev->in_runpm)
2446 err = pm_runtime_get_sync(adev_to_drm(adev)->dev);
2448 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2452 err = amdgpu_dpm_get_fan_speed_rpm(adev, &speed);
2454 pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
2455 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2460 return sysfs_emit(buf, "%i\n", speed);
2463 static ssize_t amdgpu_hwmon_get_fan1_min(struct device *dev,
2464 struct device_attribute *attr,
2467 struct amdgpu_device *adev = dev_get_drvdata(dev);
2469 u32 size = sizeof(min_rpm);
2472 if (amdgpu_in_reset(adev))
2474 if (adev->in_suspend && !adev->in_runpm)
2477 r = pm_runtime_get_sync(adev_to_drm(adev)->dev);
2479 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2483 r = amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_MIN_FAN_RPM,
2484 (void *)&min_rpm, &size);
2486 pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
2487 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2492 return sysfs_emit(buf, "%d\n", min_rpm);
2495 static ssize_t amdgpu_hwmon_get_fan1_max(struct device *dev,
2496 struct device_attribute *attr,
2499 struct amdgpu_device *adev = dev_get_drvdata(dev);
2501 u32 size = sizeof(max_rpm);
2504 if (amdgpu_in_reset(adev))
2506 if (adev->in_suspend && !adev->in_runpm)
2509 r = pm_runtime_get_sync(adev_to_drm(adev)->dev);
2511 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2515 r = amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_MAX_FAN_RPM,
2516 (void *)&max_rpm, &size);
2518 pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
2519 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2524 return sysfs_emit(buf, "%d\n", max_rpm);
2527 static ssize_t amdgpu_hwmon_get_fan1_target(struct device *dev,
2528 struct device_attribute *attr,
2531 struct amdgpu_device *adev = dev_get_drvdata(dev);
2535 if (amdgpu_in_reset(adev))
2537 if (adev->in_suspend && !adev->in_runpm)
2540 err = pm_runtime_get_sync(adev_to_drm(adev)->dev);
2542 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2546 err = amdgpu_dpm_get_fan_speed_rpm(adev, &rpm);
2548 pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
2549 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2554 return sysfs_emit(buf, "%i\n", rpm);
2557 static ssize_t amdgpu_hwmon_set_fan1_target(struct device *dev,
2558 struct device_attribute *attr,
2559 const char *buf, size_t count)
2561 struct amdgpu_device *adev = dev_get_drvdata(dev);
2566 if (amdgpu_in_reset(adev))
2568 if (adev->in_suspend && !adev->in_runpm)
2571 err = kstrtou32(buf, 10, &value);
2575 err = pm_runtime_get_sync(adev_to_drm(adev)->dev);
2577 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2581 err = amdgpu_dpm_get_fan_control_mode(adev, &pwm_mode);
2585 if (pwm_mode != AMD_FAN_CTRL_MANUAL) {
2590 err = amdgpu_dpm_set_fan_speed_rpm(adev, value);
2593 pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
2594 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2602 static ssize_t amdgpu_hwmon_get_fan1_enable(struct device *dev,
2603 struct device_attribute *attr,
2606 struct amdgpu_device *adev = dev_get_drvdata(dev);
2610 if (amdgpu_in_reset(adev))
2612 if (adev->in_suspend && !adev->in_runpm)
2615 ret = pm_runtime_get_sync(adev_to_drm(adev)->dev);
2617 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2621 ret = amdgpu_dpm_get_fan_control_mode(adev, &pwm_mode);
2623 pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
2624 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2629 return sysfs_emit(buf, "%i\n", pwm_mode == AMD_FAN_CTRL_AUTO ? 0 : 1);
2632 static ssize_t amdgpu_hwmon_set_fan1_enable(struct device *dev,
2633 struct device_attribute *attr,
2637 struct amdgpu_device *adev = dev_get_drvdata(dev);
2642 if (amdgpu_in_reset(adev))
2644 if (adev->in_suspend && !adev->in_runpm)
2647 err = kstrtoint(buf, 10, &value);
2652 pwm_mode = AMD_FAN_CTRL_AUTO;
2653 else if (value == 1)
2654 pwm_mode = AMD_FAN_CTRL_MANUAL;
2658 err = pm_runtime_get_sync(adev_to_drm(adev)->dev);
2660 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2664 err = amdgpu_dpm_set_fan_control_mode(adev, pwm_mode);
2666 pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
2667 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2675 static ssize_t amdgpu_hwmon_show_vddgfx(struct device *dev,
2676 struct device_attribute *attr,
2679 struct amdgpu_device *adev = dev_get_drvdata(dev);
2681 int r, size = sizeof(vddgfx);
2683 if (amdgpu_in_reset(adev))
2685 if (adev->in_suspend && !adev->in_runpm)
2688 r = pm_runtime_get_sync(adev_to_drm(adev)->dev);
2690 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2694 /* get the voltage */
2695 r = amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_VDDGFX,
2696 (void *)&vddgfx, &size);
2698 pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
2699 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2704 return sysfs_emit(buf, "%d\n", vddgfx);
2707 static ssize_t amdgpu_hwmon_show_vddgfx_label(struct device *dev,
2708 struct device_attribute *attr,
2711 return sysfs_emit(buf, "vddgfx\n");
2714 static ssize_t amdgpu_hwmon_show_vddnb(struct device *dev,
2715 struct device_attribute *attr,
2718 struct amdgpu_device *adev = dev_get_drvdata(dev);
2720 int r, size = sizeof(vddnb);
2722 if (amdgpu_in_reset(adev))
2724 if (adev->in_suspend && !adev->in_runpm)
2727 /* only APUs have vddnb */
2728 if (!(adev->flags & AMD_IS_APU))
2731 r = pm_runtime_get_sync(adev_to_drm(adev)->dev);
2733 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2737 /* get the voltage */
2738 r = amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_VDDNB,
2739 (void *)&vddnb, &size);
2741 pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
2742 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2747 return sysfs_emit(buf, "%d\n", vddnb);
2750 static ssize_t amdgpu_hwmon_show_vddnb_label(struct device *dev,
2751 struct device_attribute *attr,
2754 return sysfs_emit(buf, "vddnb\n");
2757 static ssize_t amdgpu_hwmon_show_power_avg(struct device *dev,
2758 struct device_attribute *attr,
2761 struct amdgpu_device *adev = dev_get_drvdata(dev);
2763 int r, size = sizeof(u32);
2766 if (amdgpu_in_reset(adev))
2768 if (adev->in_suspend && !adev->in_runpm)
2771 r = pm_runtime_get_sync(adev_to_drm(adev)->dev);
2773 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2777 /* get the voltage */
2778 r = amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GPU_POWER,
2779 (void *)&query, &size);
2781 pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
2782 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2787 /* convert to microwatts */
2788 uw = (query >> 8) * 1000000 + (query & 0xff) * 1000;
2790 return sysfs_emit(buf, "%u\n", uw);
2793 static ssize_t amdgpu_hwmon_show_power_cap_min(struct device *dev,
2794 struct device_attribute *attr,
2797 return sysfs_emit(buf, "%i\n", 0);
2801 static ssize_t amdgpu_hwmon_show_power_cap_generic(struct device *dev,
2802 struct device_attribute *attr,
2804 enum pp_power_limit_level pp_limit_level)
2806 struct amdgpu_device *adev = dev_get_drvdata(dev);
2807 enum pp_power_type power_type = to_sensor_dev_attr(attr)->index;
2812 if (amdgpu_in_reset(adev))
2814 if (adev->in_suspend && !adev->in_runpm)
2817 r = pm_runtime_get_sync(adev_to_drm(adev)->dev);
2819 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2823 r = amdgpu_dpm_get_power_limit(adev, &limit,
2824 pp_limit_level, power_type);
2827 size = sysfs_emit(buf, "%u\n", limit * 1000000);
2829 size = sysfs_emit(buf, "\n");
2831 pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
2832 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2838 static ssize_t amdgpu_hwmon_show_power_cap_max(struct device *dev,
2839 struct device_attribute *attr,
2842 return amdgpu_hwmon_show_power_cap_generic(dev, attr, buf, PP_PWR_LIMIT_MAX);
2846 static ssize_t amdgpu_hwmon_show_power_cap(struct device *dev,
2847 struct device_attribute *attr,
2850 return amdgpu_hwmon_show_power_cap_generic(dev, attr, buf, PP_PWR_LIMIT_CURRENT);
2854 static ssize_t amdgpu_hwmon_show_power_cap_default(struct device *dev,
2855 struct device_attribute *attr,
2858 return amdgpu_hwmon_show_power_cap_generic(dev, attr, buf, PP_PWR_LIMIT_DEFAULT);
2862 static ssize_t amdgpu_hwmon_show_power_label(struct device *dev,
2863 struct device_attribute *attr,
2866 struct amdgpu_device *adev = dev_get_drvdata(dev);
2868 if (adev->asic_type == CHIP_VANGOGH)
2869 return sysfs_emit(buf, "%s\n",
2870 to_sensor_dev_attr(attr)->index == PP_PWR_TYPE_FAST ?
2871 "fastPPT" : "slowPPT");
2873 return sysfs_emit(buf, "PPT\n");
2876 static ssize_t amdgpu_hwmon_set_power_cap(struct device *dev,
2877 struct device_attribute *attr,
2881 struct amdgpu_device *adev = dev_get_drvdata(dev);
2882 int limit_type = to_sensor_dev_attr(attr)->index;
2886 if (amdgpu_in_reset(adev))
2888 if (adev->in_suspend && !adev->in_runpm)
2891 if (amdgpu_sriov_vf(adev))
2894 err = kstrtou32(buf, 10, &value);
2898 value = value / 1000000; /* convert to Watt */
2899 value |= limit_type << 24;
2901 err = pm_runtime_get_sync(adev_to_drm(adev)->dev);
2903 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2907 err = amdgpu_dpm_set_power_limit(adev, value);
2909 pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
2910 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2918 static ssize_t amdgpu_hwmon_show_sclk(struct device *dev,
2919 struct device_attribute *attr,
2922 struct amdgpu_device *adev = dev_get_drvdata(dev);
2924 int r, size = sizeof(sclk);
2926 if (amdgpu_in_reset(adev))
2928 if (adev->in_suspend && !adev->in_runpm)
2931 r = pm_runtime_get_sync(adev_to_drm(adev)->dev);
2933 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2938 r = amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GFX_SCLK,
2939 (void *)&sclk, &size);
2941 pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
2942 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2947 return sysfs_emit(buf, "%u\n", sclk * 10 * 1000);
2950 static ssize_t amdgpu_hwmon_show_sclk_label(struct device *dev,
2951 struct device_attribute *attr,
2954 return sysfs_emit(buf, "sclk\n");
2957 static ssize_t amdgpu_hwmon_show_mclk(struct device *dev,
2958 struct device_attribute *attr,
2961 struct amdgpu_device *adev = dev_get_drvdata(dev);
2963 int r, size = sizeof(mclk);
2965 if (amdgpu_in_reset(adev))
2967 if (adev->in_suspend && !adev->in_runpm)
2970 r = pm_runtime_get_sync(adev_to_drm(adev)->dev);
2972 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2977 r = amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GFX_MCLK,
2978 (void *)&mclk, &size);
2980 pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
2981 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
2986 return sysfs_emit(buf, "%u\n", mclk * 10 * 1000);
2989 static ssize_t amdgpu_hwmon_show_mclk_label(struct device *dev,
2990 struct device_attribute *attr,
2993 return sysfs_emit(buf, "mclk\n");
2999 * The amdgpu driver exposes the following sensor interfaces:
3001 * - GPU temperature (via the on-die sensor)
3005 * - Northbridge voltage (APUs only)
3011 * - GPU gfx/compute engine clock
3013 * - GPU memory clock (dGPU only)
3015 * hwmon interfaces for GPU temperature:
3017 * - temp[1-3]_input: the on die GPU temperature in millidegrees Celsius
3018 * - temp2_input and temp3_input are supported on SOC15 dGPUs only
3020 * - temp[1-3]_label: temperature channel label
3021 * - temp2_label and temp3_label are supported on SOC15 dGPUs only
3023 * - temp[1-3]_crit: temperature critical max value in millidegrees Celsius
3024 * - temp2_crit and temp3_crit are supported on SOC15 dGPUs only
3026 * - temp[1-3]_crit_hyst: temperature hysteresis for critical limit in millidegrees Celsius
3027 * - temp2_crit_hyst and temp3_crit_hyst are supported on SOC15 dGPUs only
3029 * - temp[1-3]_emergency: temperature emergency max value(asic shutdown) in millidegrees Celsius
3030 * - these are supported on SOC15 dGPUs only
3032 * hwmon interfaces for GPU voltage:
3034 * - in0_input: the voltage on the GPU in millivolts
3036 * - in1_input: the voltage on the Northbridge in millivolts
3038 * hwmon interfaces for GPU power:
3040 * - power1_average: average power used by the GPU in microWatts
3042 * - power1_cap_min: minimum cap supported in microWatts
3044 * - power1_cap_max: maximum cap supported in microWatts
3046 * - power1_cap: selected power cap in microWatts
3048 * hwmon interfaces for GPU fan:
3050 * - pwm1: pulse width modulation fan level (0-255)
3052 * - 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)
3054 * - pwm1_min: pulse width modulation fan control minimum level (0)
3056 * - pwm1_max: pulse width modulation fan control maximum level (255)
3058 * - fan1_min: a minimum value Unit: revolution/min (RPM)
3060 * - fan1_max: a maximum value Unit: revolution/max (RPM)
3062 * - fan1_input: fan speed in RPM
3064 * - fan[1-\*]_target: Desired fan speed Unit: revolution/min (RPM)
3066 * - fan[1-\*]_enable: Enable or disable the sensors.1: Enable 0: Disable
3068 * NOTE: DO NOT set the fan speed via "pwm1" and "fan[1-\*]_target" interfaces at the same time.
3069 * That will get the former one overridden.
3071 * hwmon interfaces for GPU clocks:
3073 * - freq1_input: the gfx/compute clock in hertz
3075 * - freq2_input: the memory clock in hertz
3077 * You can use hwmon tools like sensors to view this information on your system.
3081 static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, amdgpu_hwmon_show_temp, NULL, PP_TEMP_EDGE);
3082 static SENSOR_DEVICE_ATTR(temp1_crit, S_IRUGO, amdgpu_hwmon_show_temp_thresh, NULL, 0);
3083 static SENSOR_DEVICE_ATTR(temp1_crit_hyst, S_IRUGO, amdgpu_hwmon_show_temp_thresh, NULL, 1);
3084 static SENSOR_DEVICE_ATTR(temp1_emergency, S_IRUGO, amdgpu_hwmon_show_temp_emergency, NULL, PP_TEMP_EDGE);
3085 static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, amdgpu_hwmon_show_temp, NULL, PP_TEMP_JUNCTION);
3086 static SENSOR_DEVICE_ATTR(temp2_crit, S_IRUGO, amdgpu_hwmon_show_hotspot_temp_thresh, NULL, 0);
3087 static SENSOR_DEVICE_ATTR(temp2_crit_hyst, S_IRUGO, amdgpu_hwmon_show_hotspot_temp_thresh, NULL, 1);
3088 static SENSOR_DEVICE_ATTR(temp2_emergency, S_IRUGO, amdgpu_hwmon_show_temp_emergency, NULL, PP_TEMP_JUNCTION);
3089 static SENSOR_DEVICE_ATTR(temp3_input, S_IRUGO, amdgpu_hwmon_show_temp, NULL, PP_TEMP_MEM);
3090 static SENSOR_DEVICE_ATTR(temp3_crit, S_IRUGO, amdgpu_hwmon_show_mem_temp_thresh, NULL, 0);
3091 static SENSOR_DEVICE_ATTR(temp3_crit_hyst, S_IRUGO, amdgpu_hwmon_show_mem_temp_thresh, NULL, 1);
3092 static SENSOR_DEVICE_ATTR(temp3_emergency, S_IRUGO, amdgpu_hwmon_show_temp_emergency, NULL, PP_TEMP_MEM);
3093 static SENSOR_DEVICE_ATTR(temp1_label, S_IRUGO, amdgpu_hwmon_show_temp_label, NULL, PP_TEMP_EDGE);
3094 static SENSOR_DEVICE_ATTR(temp2_label, S_IRUGO, amdgpu_hwmon_show_temp_label, NULL, PP_TEMP_JUNCTION);
3095 static SENSOR_DEVICE_ATTR(temp3_label, S_IRUGO, amdgpu_hwmon_show_temp_label, NULL, PP_TEMP_MEM);
3096 static SENSOR_DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, amdgpu_hwmon_get_pwm1, amdgpu_hwmon_set_pwm1, 0);
3097 static SENSOR_DEVICE_ATTR(pwm1_enable, S_IRUGO | S_IWUSR, amdgpu_hwmon_get_pwm1_enable, amdgpu_hwmon_set_pwm1_enable, 0);
3098 static SENSOR_DEVICE_ATTR(pwm1_min, S_IRUGO, amdgpu_hwmon_get_pwm1_min, NULL, 0);
3099 static SENSOR_DEVICE_ATTR(pwm1_max, S_IRUGO, amdgpu_hwmon_get_pwm1_max, NULL, 0);
3100 static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, amdgpu_hwmon_get_fan1_input, NULL, 0);
3101 static SENSOR_DEVICE_ATTR(fan1_min, S_IRUGO, amdgpu_hwmon_get_fan1_min, NULL, 0);
3102 static SENSOR_DEVICE_ATTR(fan1_max, S_IRUGO, amdgpu_hwmon_get_fan1_max, NULL, 0);
3103 static SENSOR_DEVICE_ATTR(fan1_target, S_IRUGO | S_IWUSR, amdgpu_hwmon_get_fan1_target, amdgpu_hwmon_set_fan1_target, 0);
3104 static SENSOR_DEVICE_ATTR(fan1_enable, S_IRUGO | S_IWUSR, amdgpu_hwmon_get_fan1_enable, amdgpu_hwmon_set_fan1_enable, 0);
3105 static SENSOR_DEVICE_ATTR(in0_input, S_IRUGO, amdgpu_hwmon_show_vddgfx, NULL, 0);
3106 static SENSOR_DEVICE_ATTR(in0_label, S_IRUGO, amdgpu_hwmon_show_vddgfx_label, NULL, 0);
3107 static SENSOR_DEVICE_ATTR(in1_input, S_IRUGO, amdgpu_hwmon_show_vddnb, NULL, 0);
3108 static SENSOR_DEVICE_ATTR(in1_label, S_IRUGO, amdgpu_hwmon_show_vddnb_label, NULL, 0);
3109 static SENSOR_DEVICE_ATTR(power1_average, S_IRUGO, amdgpu_hwmon_show_power_avg, NULL, 0);
3110 static SENSOR_DEVICE_ATTR(power1_cap_max, S_IRUGO, amdgpu_hwmon_show_power_cap_max, NULL, 0);
3111 static SENSOR_DEVICE_ATTR(power1_cap_min, S_IRUGO, amdgpu_hwmon_show_power_cap_min, NULL, 0);
3112 static SENSOR_DEVICE_ATTR(power1_cap, S_IRUGO | S_IWUSR, amdgpu_hwmon_show_power_cap, amdgpu_hwmon_set_power_cap, 0);
3113 static SENSOR_DEVICE_ATTR(power1_cap_default, S_IRUGO, amdgpu_hwmon_show_power_cap_default, NULL, 0);
3114 static SENSOR_DEVICE_ATTR(power1_label, S_IRUGO, amdgpu_hwmon_show_power_label, NULL, 0);
3115 static SENSOR_DEVICE_ATTR(power2_average, S_IRUGO, amdgpu_hwmon_show_power_avg, NULL, 1);
3116 static SENSOR_DEVICE_ATTR(power2_cap_max, S_IRUGO, amdgpu_hwmon_show_power_cap_max, NULL, 1);
3117 static SENSOR_DEVICE_ATTR(power2_cap_min, S_IRUGO, amdgpu_hwmon_show_power_cap_min, NULL, 1);
3118 static SENSOR_DEVICE_ATTR(power2_cap, S_IRUGO | S_IWUSR, amdgpu_hwmon_show_power_cap, amdgpu_hwmon_set_power_cap, 1);
3119 static SENSOR_DEVICE_ATTR(power2_cap_default, S_IRUGO, amdgpu_hwmon_show_power_cap_default, NULL, 1);
3120 static SENSOR_DEVICE_ATTR(power2_label, S_IRUGO, amdgpu_hwmon_show_power_label, NULL, 1);
3121 static SENSOR_DEVICE_ATTR(freq1_input, S_IRUGO, amdgpu_hwmon_show_sclk, NULL, 0);
3122 static SENSOR_DEVICE_ATTR(freq1_label, S_IRUGO, amdgpu_hwmon_show_sclk_label, NULL, 0);
3123 static SENSOR_DEVICE_ATTR(freq2_input, S_IRUGO, amdgpu_hwmon_show_mclk, NULL, 0);
3124 static SENSOR_DEVICE_ATTR(freq2_label, S_IRUGO, amdgpu_hwmon_show_mclk_label, NULL, 0);
3126 static struct attribute *hwmon_attributes[] = {
3127 &sensor_dev_attr_temp1_input.dev_attr.attr,
3128 &sensor_dev_attr_temp1_crit.dev_attr.attr,
3129 &sensor_dev_attr_temp1_crit_hyst.dev_attr.attr,
3130 &sensor_dev_attr_temp2_input.dev_attr.attr,
3131 &sensor_dev_attr_temp2_crit.dev_attr.attr,
3132 &sensor_dev_attr_temp2_crit_hyst.dev_attr.attr,
3133 &sensor_dev_attr_temp3_input.dev_attr.attr,
3134 &sensor_dev_attr_temp3_crit.dev_attr.attr,
3135 &sensor_dev_attr_temp3_crit_hyst.dev_attr.attr,
3136 &sensor_dev_attr_temp1_emergency.dev_attr.attr,
3137 &sensor_dev_attr_temp2_emergency.dev_attr.attr,
3138 &sensor_dev_attr_temp3_emergency.dev_attr.attr,
3139 &sensor_dev_attr_temp1_label.dev_attr.attr,
3140 &sensor_dev_attr_temp2_label.dev_attr.attr,
3141 &sensor_dev_attr_temp3_label.dev_attr.attr,
3142 &sensor_dev_attr_pwm1.dev_attr.attr,
3143 &sensor_dev_attr_pwm1_enable.dev_attr.attr,
3144 &sensor_dev_attr_pwm1_min.dev_attr.attr,
3145 &sensor_dev_attr_pwm1_max.dev_attr.attr,
3146 &sensor_dev_attr_fan1_input.dev_attr.attr,
3147 &sensor_dev_attr_fan1_min.dev_attr.attr,
3148 &sensor_dev_attr_fan1_max.dev_attr.attr,
3149 &sensor_dev_attr_fan1_target.dev_attr.attr,
3150 &sensor_dev_attr_fan1_enable.dev_attr.attr,
3151 &sensor_dev_attr_in0_input.dev_attr.attr,
3152 &sensor_dev_attr_in0_label.dev_attr.attr,
3153 &sensor_dev_attr_in1_input.dev_attr.attr,
3154 &sensor_dev_attr_in1_label.dev_attr.attr,
3155 &sensor_dev_attr_power1_average.dev_attr.attr,
3156 &sensor_dev_attr_power1_cap_max.dev_attr.attr,
3157 &sensor_dev_attr_power1_cap_min.dev_attr.attr,
3158 &sensor_dev_attr_power1_cap.dev_attr.attr,
3159 &sensor_dev_attr_power1_cap_default.dev_attr.attr,
3160 &sensor_dev_attr_power1_label.dev_attr.attr,
3161 &sensor_dev_attr_power2_average.dev_attr.attr,
3162 &sensor_dev_attr_power2_cap_max.dev_attr.attr,
3163 &sensor_dev_attr_power2_cap_min.dev_attr.attr,
3164 &sensor_dev_attr_power2_cap.dev_attr.attr,
3165 &sensor_dev_attr_power2_cap_default.dev_attr.attr,
3166 &sensor_dev_attr_power2_label.dev_attr.attr,
3167 &sensor_dev_attr_freq1_input.dev_attr.attr,
3168 &sensor_dev_attr_freq1_label.dev_attr.attr,
3169 &sensor_dev_attr_freq2_input.dev_attr.attr,
3170 &sensor_dev_attr_freq2_label.dev_attr.attr,
3174 static umode_t hwmon_attributes_visible(struct kobject *kobj,
3175 struct attribute *attr, int index)
3177 struct device *dev = kobj_to_dev(kobj);
3178 struct amdgpu_device *adev = dev_get_drvdata(dev);
3179 umode_t effective_mode = attr->mode;
3181 /* under multi-vf mode, the hwmon attributes are all not supported */
3182 if (amdgpu_sriov_vf(adev) && !amdgpu_sriov_is_pp_one_vf(adev))
3185 /* under pp one vf mode manage of hwmon attributes is not supported */
3186 if (amdgpu_sriov_is_pp_one_vf(adev))
3187 effective_mode &= ~S_IWUSR;
3189 /* Skip fan attributes if fan is not present */
3190 if (adev->pm.no_fan && (attr == &sensor_dev_attr_pwm1.dev_attr.attr ||
3191 attr == &sensor_dev_attr_pwm1_enable.dev_attr.attr ||
3192 attr == &sensor_dev_attr_pwm1_max.dev_attr.attr ||
3193 attr == &sensor_dev_attr_pwm1_min.dev_attr.attr ||
3194 attr == &sensor_dev_attr_fan1_input.dev_attr.attr ||
3195 attr == &sensor_dev_attr_fan1_min.dev_attr.attr ||
3196 attr == &sensor_dev_attr_fan1_max.dev_attr.attr ||
3197 attr == &sensor_dev_attr_fan1_target.dev_attr.attr ||
3198 attr == &sensor_dev_attr_fan1_enable.dev_attr.attr))
3201 /* Skip fan attributes on APU */
3202 if ((adev->flags & AMD_IS_APU) &&
3203 (attr == &sensor_dev_attr_pwm1.dev_attr.attr ||
3204 attr == &sensor_dev_attr_pwm1_enable.dev_attr.attr ||
3205 attr == &sensor_dev_attr_pwm1_max.dev_attr.attr ||
3206 attr == &sensor_dev_attr_pwm1_min.dev_attr.attr ||
3207 attr == &sensor_dev_attr_fan1_input.dev_attr.attr ||
3208 attr == &sensor_dev_attr_fan1_min.dev_attr.attr ||
3209 attr == &sensor_dev_attr_fan1_max.dev_attr.attr ||
3210 attr == &sensor_dev_attr_fan1_target.dev_attr.attr ||
3211 attr == &sensor_dev_attr_fan1_enable.dev_attr.attr))
3214 /* Skip crit temp on APU */
3215 if ((adev->flags & AMD_IS_APU) && (adev->family >= AMDGPU_FAMILY_CZ) &&
3216 (attr == &sensor_dev_attr_temp1_crit.dev_attr.attr ||
3217 attr == &sensor_dev_attr_temp1_crit_hyst.dev_attr.attr))
3220 /* Skip limit attributes if DPM is not enabled */
3221 if (!adev->pm.dpm_enabled &&
3222 (attr == &sensor_dev_attr_temp1_crit.dev_attr.attr ||
3223 attr == &sensor_dev_attr_temp1_crit_hyst.dev_attr.attr ||
3224 attr == &sensor_dev_attr_pwm1.dev_attr.attr ||
3225 attr == &sensor_dev_attr_pwm1_enable.dev_attr.attr ||
3226 attr == &sensor_dev_attr_pwm1_max.dev_attr.attr ||
3227 attr == &sensor_dev_attr_pwm1_min.dev_attr.attr ||
3228 attr == &sensor_dev_attr_fan1_input.dev_attr.attr ||
3229 attr == &sensor_dev_attr_fan1_min.dev_attr.attr ||
3230 attr == &sensor_dev_attr_fan1_max.dev_attr.attr ||
3231 attr == &sensor_dev_attr_fan1_target.dev_attr.attr ||
3232 attr == &sensor_dev_attr_fan1_enable.dev_attr.attr))
3235 /* mask fan attributes if we have no bindings for this asic to expose */
3236 if (((amdgpu_dpm_get_fan_speed_pwm(adev, NULL) == -EOPNOTSUPP) &&
3237 attr == &sensor_dev_attr_pwm1.dev_attr.attr) || /* can't query fan */
3238 ((amdgpu_dpm_get_fan_control_mode(adev, NULL) == -EOPNOTSUPP) &&
3239 attr == &sensor_dev_attr_pwm1_enable.dev_attr.attr)) /* can't query state */
3240 effective_mode &= ~S_IRUGO;
3242 if (((amdgpu_dpm_set_fan_speed_pwm(adev, U32_MAX) == -EOPNOTSUPP) &&
3243 attr == &sensor_dev_attr_pwm1.dev_attr.attr) || /* can't manage fan */
3244 ((amdgpu_dpm_set_fan_control_mode(adev, U32_MAX) == -EOPNOTSUPP) &&
3245 attr == &sensor_dev_attr_pwm1_enable.dev_attr.attr)) /* can't manage state */
3246 effective_mode &= ~S_IWUSR;
3248 if (((adev->family == AMDGPU_FAMILY_SI) ||
3249 ((adev->flags & AMD_IS_APU) &&
3250 (adev->asic_type != CHIP_VANGOGH))) && /* not implemented yet */
3251 (attr == &sensor_dev_attr_power1_cap_max.dev_attr.attr ||
3252 attr == &sensor_dev_attr_power1_cap_min.dev_attr.attr||
3253 attr == &sensor_dev_attr_power1_cap.dev_attr.attr ||
3254 attr == &sensor_dev_attr_power1_cap_default.dev_attr.attr))
3257 if (((adev->family == AMDGPU_FAMILY_SI) ||
3258 ((adev->flags & AMD_IS_APU) &&
3259 (adev->asic_type < CHIP_RENOIR))) && /* not implemented yet */
3260 (attr == &sensor_dev_attr_power1_average.dev_attr.attr))
3263 /* hide max/min values if we can't both query and manage the fan */
3264 if (((amdgpu_dpm_set_fan_speed_pwm(adev, U32_MAX) == -EOPNOTSUPP) &&
3265 (amdgpu_dpm_get_fan_speed_pwm(adev, NULL) == -EOPNOTSUPP) &&
3266 (amdgpu_dpm_set_fan_speed_rpm(adev, U32_MAX) == -EOPNOTSUPP) &&
3267 (amdgpu_dpm_get_fan_speed_rpm(adev, NULL) == -EOPNOTSUPP)) &&
3268 (attr == &sensor_dev_attr_pwm1_max.dev_attr.attr ||
3269 attr == &sensor_dev_attr_pwm1_min.dev_attr.attr))
3272 if ((amdgpu_dpm_set_fan_speed_rpm(adev, U32_MAX) == -EOPNOTSUPP) &&
3273 (amdgpu_dpm_get_fan_speed_rpm(adev, NULL) == -EOPNOTSUPP) &&
3274 (attr == &sensor_dev_attr_fan1_max.dev_attr.attr ||
3275 attr == &sensor_dev_attr_fan1_min.dev_attr.attr))
3278 if ((adev->family == AMDGPU_FAMILY_SI || /* not implemented yet */
3279 adev->family == AMDGPU_FAMILY_KV) && /* not implemented yet */
3280 (attr == &sensor_dev_attr_in0_input.dev_attr.attr ||
3281 attr == &sensor_dev_attr_in0_label.dev_attr.attr))
3284 /* only APUs have vddnb */
3285 if (!(adev->flags & AMD_IS_APU) &&
3286 (attr == &sensor_dev_attr_in1_input.dev_attr.attr ||
3287 attr == &sensor_dev_attr_in1_label.dev_attr.attr))
3290 /* no mclk on APUs */
3291 if ((adev->flags & AMD_IS_APU) &&
3292 (attr == &sensor_dev_attr_freq2_input.dev_attr.attr ||
3293 attr == &sensor_dev_attr_freq2_label.dev_attr.attr))
3296 /* only SOC15 dGPUs support hotspot and mem temperatures */
3297 if (((adev->flags & AMD_IS_APU) ||
3298 adev->asic_type < CHIP_VEGA10) &&
3299 (attr == &sensor_dev_attr_temp2_crit.dev_attr.attr ||
3300 attr == &sensor_dev_attr_temp2_crit_hyst.dev_attr.attr ||
3301 attr == &sensor_dev_attr_temp3_crit.dev_attr.attr ||
3302 attr == &sensor_dev_attr_temp3_crit_hyst.dev_attr.attr ||
3303 attr == &sensor_dev_attr_temp1_emergency.dev_attr.attr ||
3304 attr == &sensor_dev_attr_temp2_emergency.dev_attr.attr ||
3305 attr == &sensor_dev_attr_temp3_emergency.dev_attr.attr ||
3306 attr == &sensor_dev_attr_temp2_input.dev_attr.attr ||
3307 attr == &sensor_dev_attr_temp3_input.dev_attr.attr ||
3308 attr == &sensor_dev_attr_temp2_label.dev_attr.attr ||
3309 attr == &sensor_dev_attr_temp3_label.dev_attr.attr))
3312 /* only Vangogh has fast PPT limit and power labels */
3313 if (!(adev->asic_type == CHIP_VANGOGH) &&
3314 (attr == &sensor_dev_attr_power2_average.dev_attr.attr ||
3315 attr == &sensor_dev_attr_power2_cap_max.dev_attr.attr ||
3316 attr == &sensor_dev_attr_power2_cap_min.dev_attr.attr ||
3317 attr == &sensor_dev_attr_power2_cap.dev_attr.attr ||
3318 attr == &sensor_dev_attr_power2_cap_default.dev_attr.attr ||
3319 attr == &sensor_dev_attr_power2_label.dev_attr.attr))
3322 return effective_mode;
3325 static const struct attribute_group hwmon_attrgroup = {
3326 .attrs = hwmon_attributes,
3327 .is_visible = hwmon_attributes_visible,
3330 static const struct attribute_group *hwmon_groups[] = {
3335 int amdgpu_pm_sysfs_init(struct amdgpu_device *adev)
3340 if (adev->pm.sysfs_initialized)
3343 if (adev->pm.dpm_enabled == 0)
3346 INIT_LIST_HEAD(&adev->pm.pm_attr_list);
3348 adev->pm.int_hwmon_dev = hwmon_device_register_with_groups(adev->dev,
3351 if (IS_ERR(adev->pm.int_hwmon_dev)) {
3352 ret = PTR_ERR(adev->pm.int_hwmon_dev);
3354 "Unable to register hwmon device: %d\n", ret);
3358 switch (amdgpu_virt_get_sriov_vf_mode(adev)) {
3359 case SRIOV_VF_MODE_ONE_VF:
3360 mask = ATTR_FLAG_ONEVF;
3362 case SRIOV_VF_MODE_MULTI_VF:
3365 case SRIOV_VF_MODE_BARE_METAL:
3367 mask = ATTR_FLAG_MASK_ALL;
3371 ret = amdgpu_device_attr_create_groups(adev,
3372 amdgpu_device_attrs,
3373 ARRAY_SIZE(amdgpu_device_attrs),
3375 &adev->pm.pm_attr_list);
3379 adev->pm.sysfs_initialized = true;
3384 void amdgpu_pm_sysfs_fini(struct amdgpu_device *adev)
3386 if (adev->pm.dpm_enabled == 0)
3389 if (adev->pm.int_hwmon_dev)
3390 hwmon_device_unregister(adev->pm.int_hwmon_dev);
3392 amdgpu_device_attr_remove_groups(adev, &adev->pm.pm_attr_list);
3398 #if defined(CONFIG_DEBUG_FS)
3400 static void amdgpu_debugfs_prints_cpu_info(struct seq_file *m,
3401 struct amdgpu_device *adev) {
3405 uint32_t num_cpu_cores = amdgpu_dpm_get_num_cpu_cores(adev);
3407 if (amdgpu_dpm_is_cclk_dpm_supported(adev)) {
3408 p_val = kcalloc(num_cpu_cores, sizeof(uint16_t),
3411 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_CPU_CLK,
3412 (void *)p_val, &size)) {
3413 for (i = 0; i < num_cpu_cores; i++)
3414 seq_printf(m, "\t%u MHz (CPU%d)\n",
3422 static int amdgpu_debugfs_pm_info_pp(struct seq_file *m, struct amdgpu_device *adev)
3425 uint64_t value64 = 0;
3430 size = sizeof(value);
3431 seq_printf(m, "GFX Clocks and Power:\n");
3433 amdgpu_debugfs_prints_cpu_info(m, adev);
3435 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GFX_MCLK, (void *)&value, &size))
3436 seq_printf(m, "\t%u MHz (MCLK)\n", value/100);
3437 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GFX_SCLK, (void *)&value, &size))
3438 seq_printf(m, "\t%u MHz (SCLK)\n", value/100);
3439 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_STABLE_PSTATE_SCLK, (void *)&value, &size))
3440 seq_printf(m, "\t%u MHz (PSTATE_SCLK)\n", value/100);
3441 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_STABLE_PSTATE_MCLK, (void *)&value, &size))
3442 seq_printf(m, "\t%u MHz (PSTATE_MCLK)\n", value/100);
3443 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_VDDGFX, (void *)&value, &size))
3444 seq_printf(m, "\t%u mV (VDDGFX)\n", value);
3445 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_VDDNB, (void *)&value, &size))
3446 seq_printf(m, "\t%u mV (VDDNB)\n", value);
3447 size = sizeof(uint32_t);
3448 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GPU_POWER, (void *)&query, &size))
3449 seq_printf(m, "\t%u.%u W (average GPU)\n", query >> 8, query & 0xff);
3450 size = sizeof(value);
3451 seq_printf(m, "\n");
3454 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GPU_TEMP, (void *)&value, &size))
3455 seq_printf(m, "GPU Temperature: %u C\n", value/1000);
3458 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GPU_LOAD, (void *)&value, &size))
3459 seq_printf(m, "GPU Load: %u %%\n", value);
3461 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_MEM_LOAD, (void *)&value, &size))
3462 seq_printf(m, "MEM Load: %u %%\n", value);
3464 seq_printf(m, "\n");
3466 /* SMC feature mask */
3467 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_ENABLED_SMC_FEATURES_MASK, (void *)&value64, &size))
3468 seq_printf(m, "SMC Feature Mask: 0x%016llx\n", value64);
3470 if (adev->asic_type > CHIP_VEGA20) {
3472 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_VCN_POWER_STATE, (void *)&value, &size)) {
3474 seq_printf(m, "VCN: Disabled\n");
3476 seq_printf(m, "VCN: Enabled\n");
3477 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_UVD_DCLK, (void *)&value, &size))
3478 seq_printf(m, "\t%u MHz (DCLK)\n", value/100);
3479 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_UVD_VCLK, (void *)&value, &size))
3480 seq_printf(m, "\t%u MHz (VCLK)\n", value/100);
3483 seq_printf(m, "\n");
3486 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_UVD_POWER, (void *)&value, &size)) {
3488 seq_printf(m, "UVD: Disabled\n");
3490 seq_printf(m, "UVD: Enabled\n");
3491 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_UVD_DCLK, (void *)&value, &size))
3492 seq_printf(m, "\t%u MHz (DCLK)\n", value/100);
3493 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_UVD_VCLK, (void *)&value, &size))
3494 seq_printf(m, "\t%u MHz (VCLK)\n", value/100);
3497 seq_printf(m, "\n");
3500 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_VCE_POWER, (void *)&value, &size)) {
3502 seq_printf(m, "VCE: Disabled\n");
3504 seq_printf(m, "VCE: Enabled\n");
3505 if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_VCE_ECCLK, (void *)&value, &size))
3506 seq_printf(m, "\t%u MHz (ECCLK)\n", value/100);
3514 static void amdgpu_parse_cg_state(struct seq_file *m, u32 flags)
3518 for (i = 0; clocks[i].flag; i++)
3519 seq_printf(m, "\t%s: %s\n", clocks[i].name,
3520 (flags & clocks[i].flag) ? "On" : "Off");
3523 static int amdgpu_debugfs_pm_info_show(struct seq_file *m, void *unused)
3525 struct amdgpu_device *adev = (struct amdgpu_device *)m->private;
3526 struct drm_device *dev = adev_to_drm(adev);
3530 if (amdgpu_in_reset(adev))
3532 if (adev->in_suspend && !adev->in_runpm)
3535 r = pm_runtime_get_sync(dev->dev);
3537 pm_runtime_put_autosuspend(dev->dev);
3541 if (amdgpu_dpm_debugfs_print_current_performance_level(adev, m)) {
3542 r = amdgpu_debugfs_pm_info_pp(m, adev);
3547 amdgpu_device_ip_get_clockgating_state(adev, &flags);
3549 seq_printf(m, "Clock Gating Flags Mask: 0x%x\n", flags);
3550 amdgpu_parse_cg_state(m, flags);
3551 seq_printf(m, "\n");
3554 pm_runtime_mark_last_busy(dev->dev);
3555 pm_runtime_put_autosuspend(dev->dev);
3560 DEFINE_SHOW_ATTRIBUTE(amdgpu_debugfs_pm_info);
3563 * amdgpu_pm_priv_buffer_read - Read memory region allocated to FW
3565 * Reads debug memory region allocated to PMFW
3567 static ssize_t amdgpu_pm_prv_buffer_read(struct file *f, char __user *buf,
3568 size_t size, loff_t *pos)
3570 struct amdgpu_device *adev = file_inode(f)->i_private;
3571 size_t smu_prv_buf_size;
3575 if (amdgpu_in_reset(adev))
3577 if (adev->in_suspend && !adev->in_runpm)
3580 ret = amdgpu_dpm_get_smu_prv_buf_details(adev, &smu_prv_buf, &smu_prv_buf_size);
3584 if (!smu_prv_buf || !smu_prv_buf_size)
3587 return simple_read_from_buffer(buf, size, pos, smu_prv_buf,
3591 static const struct file_operations amdgpu_debugfs_pm_prv_buffer_fops = {
3592 .owner = THIS_MODULE,
3593 .open = simple_open,
3594 .read = amdgpu_pm_prv_buffer_read,
3595 .llseek = default_llseek,
3600 void amdgpu_debugfs_pm_init(struct amdgpu_device *adev)
3602 #if defined(CONFIG_DEBUG_FS)
3603 struct drm_minor *minor = adev_to_drm(adev)->primary;
3604 struct dentry *root = minor->debugfs_root;
3606 if (!adev->pm.dpm_enabled)
3609 debugfs_create_file("amdgpu_pm_info", 0444, root, adev,
3610 &amdgpu_debugfs_pm_info_fops);
3612 if (adev->pm.smu_prv_buffer_size > 0)
3613 debugfs_create_file_size("amdgpu_pm_prv_buffer", 0444, root,
3615 &amdgpu_debugfs_pm_prv_buffer_fops,
3616 adev->pm.smu_prv_buffer_size);
3618 amdgpu_dpm_stb_debug_fs_init(adev);