Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1 | /* |
Alex Deucher | 9ce6aae | 2017-11-30 21:29:47 -0500 | [diff] [blame] | 2 | * Copyright 2017 Advanced Micro Devices, Inc. |
| 3 | * |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 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: |
| 10 | * |
| 11 | * The above copyright notice and this permission notice shall be included in |
| 12 | * all copies or substantial portions of the Software. |
| 13 | * |
| 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. |
| 21 | * |
| 22 | * Authors: Rafał Miłecki <zajec5@gmail.com> |
| 23 | * Alex Deucher <alexdeucher@gmail.com> |
| 24 | */ |
| 25 | #include <drm/drmP.h> |
| 26 | #include "amdgpu.h" |
| 27 | #include "amdgpu_drv.h" |
| 28 | #include "amdgpu_pm.h" |
| 29 | #include "amdgpu_dpm.h" |
Huang Rui | 5df58525 | 2018-08-09 09:50:12 -0500 | [diff] [blame] | 30 | #include "amdgpu_display.h" |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 31 | #include "atom.h" |
| 32 | #include <linux/power_supply.h> |
| 33 | #include <linux/hwmon.h> |
| 34 | #include <linux/hwmon-sysfs.h> |
Gustavo A. R. Silva | ddf74e7 | 2018-07-23 11:32:32 -0500 | [diff] [blame] | 35 | #include <linux/nospec.h> |
Rex Zhu | 1b5708f | 2015-11-10 18:25:24 -0500 | [diff] [blame] | 36 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 37 | static int amdgpu_debugfs_pm_init(struct amdgpu_device *adev); |
| 38 | |
Huang Rui | a8503b1 | 2017-01-05 19:17:13 +0800 | [diff] [blame] | 39 | static const struct cg_flag_name clocks[] = { |
| 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"}, |
Huang Rui | 5417022 | 2017-01-11 09:55:34 +0800 | [diff] [blame] | 44 | {AMD_CG_SUPPORT_GFX_CGTS, "Graphics Coarse Grain Tree Shader Clock Gating"}, |
Huang Rui | a8503b1 | 2017-01-05 19:17:13 +0800 | [diff] [blame] | 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"}, |
Huang Rui | 12ad27f | 2017-03-24 09:58:11 +0800 | [diff] [blame] | 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"}, |
Huang Rui | a8503b1 | 2017-01-05 19:17:13 +0800 | [diff] [blame] | 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"}, |
Huang Rui | e96487a | 2017-03-24 10:12:32 +0800 | [diff] [blame] | 54 | {AMD_CG_SUPPORT_BIF_MGCG, "Bus Interface Medium Grain Clock Gating"}, |
Huang Rui | a8503b1 | 2017-01-05 19:17:13 +0800 | [diff] [blame] | 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"}, |
Huang Rui | f9abe35 | 2017-03-24 10:46:16 +0800 | [diff] [blame] | 60 | {AMD_CG_SUPPORT_DRM_MGCG, "Digital Right Management Medium Grain Clock Gating"}, |
| 61 | {AMD_CG_SUPPORT_DRM_LS, "Digital Right Management Light Sleep"}, |
Huang Rui | a8503b1 | 2017-01-05 19:17:13 +0800 | [diff] [blame] | 62 | {AMD_CG_SUPPORT_ROM_MGCG, "Rom Medium Grain Clock Gating"}, |
Huang Rui | f9abe35 | 2017-03-24 10:46:16 +0800 | [diff] [blame] | 63 | {AMD_CG_SUPPORT_DF_MGCG, "Data Fabric Medium Grain Clock Gating"}, |
Huang Rui | a8503b1 | 2017-01-05 19:17:13 +0800 | [diff] [blame] | 64 | {0, NULL}, |
| 65 | }; |
| 66 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 67 | void amdgpu_pm_acpi_event_handler(struct amdgpu_device *adev) |
| 68 | { |
| 69 | if (adev->pm.dpm_enabled) { |
| 70 | mutex_lock(&adev->pm.mutex); |
| 71 | if (power_supply_is_system_supplied() > 0) |
Rex Zhu | 600ae89 | 2018-06-04 16:39:38 +0800 | [diff] [blame] | 72 | adev->pm.ac_power = true; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 73 | else |
Rex Zhu | 600ae89 | 2018-06-04 16:39:38 +0800 | [diff] [blame] | 74 | adev->pm.ac_power = false; |
Rex Zhu | cd4d746 | 2017-09-06 18:43:52 +0800 | [diff] [blame] | 75 | if (adev->powerplay.pp_funcs->enable_bapm) |
Rex Zhu | 600ae89 | 2018-06-04 16:39:38 +0800 | [diff] [blame] | 76 | amdgpu_dpm_enable_bapm(adev, adev->pm.ac_power); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 77 | mutex_unlock(&adev->pm.mutex); |
| 78 | } |
| 79 | } |
| 80 | |
Alex Deucher | ca8d40c | 2018-04-19 13:56:41 -0500 | [diff] [blame] | 81 | /** |
| 82 | * DOC: power_dpm_state |
| 83 | * |
Alex Deucher | dc85db2 | 2018-06-01 12:28:14 -0500 | [diff] [blame] | 84 | * The power_dpm_state file is a legacy interface and is only provided for |
| 85 | * backwards compatibility. The amdgpu driver provides a sysfs API for adjusting |
| 86 | * certain power related parameters. The file power_dpm_state is used for this. |
Alex Deucher | ca8d40c | 2018-04-19 13:56:41 -0500 | [diff] [blame] | 87 | * It accepts the following arguments: |
Alex Deucher | dc85db2 | 2018-06-01 12:28:14 -0500 | [diff] [blame] | 88 | * |
Alex Deucher | ca8d40c | 2018-04-19 13:56:41 -0500 | [diff] [blame] | 89 | * - battery |
Alex Deucher | dc85db2 | 2018-06-01 12:28:14 -0500 | [diff] [blame] | 90 | * |
Alex Deucher | ca8d40c | 2018-04-19 13:56:41 -0500 | [diff] [blame] | 91 | * - balanced |
Alex Deucher | dc85db2 | 2018-06-01 12:28:14 -0500 | [diff] [blame] | 92 | * |
Alex Deucher | ca8d40c | 2018-04-19 13:56:41 -0500 | [diff] [blame] | 93 | * - performance |
| 94 | * |
| 95 | * battery |
| 96 | * |
| 97 | * On older GPUs, the vbios provided a special power state for battery |
| 98 | * operation. Selecting battery switched to this state. This is no |
| 99 | * longer provided on newer GPUs so the option does nothing in that case. |
| 100 | * |
| 101 | * balanced |
| 102 | * |
| 103 | * On older GPUs, the vbios provided a special power state for balanced |
| 104 | * operation. Selecting balanced switched to this state. This is no |
| 105 | * longer provided on newer GPUs so the option does nothing in that case. |
| 106 | * |
| 107 | * performance |
| 108 | * |
| 109 | * On older GPUs, the vbios provided a special power state for performance |
| 110 | * operation. Selecting performance switched to this state. This is no |
| 111 | * longer provided on newer GPUs so the option does nothing in that case. |
| 112 | * |
| 113 | */ |
| 114 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 115 | static ssize_t amdgpu_get_dpm_state(struct device *dev, |
| 116 | struct device_attribute *attr, |
| 117 | char *buf) |
| 118 | { |
| 119 | struct drm_device *ddev = dev_get_drvdata(dev); |
| 120 | struct amdgpu_device *adev = ddev->dev_private; |
Rex Zhu | 1b5708f | 2015-11-10 18:25:24 -0500 | [diff] [blame] | 121 | enum amd_pm_state_type pm; |
| 122 | |
Rex Zhu | cd4d746 | 2017-09-06 18:43:52 +0800 | [diff] [blame] | 123 | if (adev->powerplay.pp_funcs->get_current_power_state) |
Rex Zhu | 1b5708f | 2015-11-10 18:25:24 -0500 | [diff] [blame] | 124 | pm = amdgpu_dpm_get_current_power_state(adev); |
Rex Zhu | cd4d746 | 2017-09-06 18:43:52 +0800 | [diff] [blame] | 125 | else |
Rex Zhu | 1b5708f | 2015-11-10 18:25:24 -0500 | [diff] [blame] | 126 | pm = adev->pm.dpm.user_state; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 127 | |
| 128 | return snprintf(buf, PAGE_SIZE, "%s\n", |
| 129 | (pm == POWER_STATE_TYPE_BATTERY) ? "battery" : |
| 130 | (pm == POWER_STATE_TYPE_BALANCED) ? "balanced" : "performance"); |
| 131 | } |
| 132 | |
| 133 | static ssize_t amdgpu_set_dpm_state(struct device *dev, |
| 134 | struct device_attribute *attr, |
| 135 | const char *buf, |
| 136 | size_t count) |
| 137 | { |
| 138 | struct drm_device *ddev = dev_get_drvdata(dev); |
| 139 | struct amdgpu_device *adev = ddev->dev_private; |
Rex Zhu | 1b5708f | 2015-11-10 18:25:24 -0500 | [diff] [blame] | 140 | enum amd_pm_state_type state; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 141 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 142 | if (strncmp("battery", buf, strlen("battery")) == 0) |
Rex Zhu | 1b5708f | 2015-11-10 18:25:24 -0500 | [diff] [blame] | 143 | state = POWER_STATE_TYPE_BATTERY; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 144 | else if (strncmp("balanced", buf, strlen("balanced")) == 0) |
Rex Zhu | 1b5708f | 2015-11-10 18:25:24 -0500 | [diff] [blame] | 145 | state = POWER_STATE_TYPE_BALANCED; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 146 | else if (strncmp("performance", buf, strlen("performance")) == 0) |
Rex Zhu | 1b5708f | 2015-11-10 18:25:24 -0500 | [diff] [blame] | 147 | state = POWER_STATE_TYPE_PERFORMANCE; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 148 | else { |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 149 | count = -EINVAL; |
| 150 | goto fail; |
| 151 | } |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 152 | |
Rex Zhu | 6d07fe7 | 2017-09-25 18:51:50 +0800 | [diff] [blame] | 153 | if (adev->powerplay.pp_funcs->dispatch_tasks) { |
Evan Quan | 39199b8 | 2017-12-29 14:46:13 +0800 | [diff] [blame] | 154 | amdgpu_dpm_dispatch_task(adev, AMD_PP_TASK_ENABLE_USER_STATE, &state); |
Rex Zhu | 1b5708f | 2015-11-10 18:25:24 -0500 | [diff] [blame] | 155 | } else { |
| 156 | mutex_lock(&adev->pm.mutex); |
| 157 | adev->pm.dpm.user_state = state; |
| 158 | mutex_unlock(&adev->pm.mutex); |
| 159 | |
| 160 | /* Can't set dpm state when the card is off */ |
| 161 | if (!(adev->flags & AMD_IS_PX) || |
| 162 | (ddev->switch_power_state == DRM_SWITCH_POWER_ON)) |
| 163 | amdgpu_pm_compute_clocks(adev); |
| 164 | } |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 165 | fail: |
| 166 | return count; |
| 167 | } |
| 168 | |
Alex Deucher | 8567f68 | 2018-04-19 13:46:03 -0500 | [diff] [blame] | 169 | |
| 170 | /** |
| 171 | * DOC: power_dpm_force_performance_level |
| 172 | * |
| 173 | * The amdgpu driver provides a sysfs API for adjusting certain power |
| 174 | * related parameters. The file power_dpm_force_performance_level is |
| 175 | * used for this. It accepts the following arguments: |
Alex Deucher | dc85db2 | 2018-06-01 12:28:14 -0500 | [diff] [blame] | 176 | * |
Alex Deucher | 8567f68 | 2018-04-19 13:46:03 -0500 | [diff] [blame] | 177 | * - auto |
Alex Deucher | dc85db2 | 2018-06-01 12:28:14 -0500 | [diff] [blame] | 178 | * |
Alex Deucher | 8567f68 | 2018-04-19 13:46:03 -0500 | [diff] [blame] | 179 | * - low |
Alex Deucher | dc85db2 | 2018-06-01 12:28:14 -0500 | [diff] [blame] | 180 | * |
Alex Deucher | 8567f68 | 2018-04-19 13:46:03 -0500 | [diff] [blame] | 181 | * - high |
Alex Deucher | dc85db2 | 2018-06-01 12:28:14 -0500 | [diff] [blame] | 182 | * |
Alex Deucher | 8567f68 | 2018-04-19 13:46:03 -0500 | [diff] [blame] | 183 | * - manual |
Alex Deucher | dc85db2 | 2018-06-01 12:28:14 -0500 | [diff] [blame] | 184 | * |
Alex Deucher | 8567f68 | 2018-04-19 13:46:03 -0500 | [diff] [blame] | 185 | * - profile_standard |
Alex Deucher | dc85db2 | 2018-06-01 12:28:14 -0500 | [diff] [blame] | 186 | * |
Alex Deucher | 8567f68 | 2018-04-19 13:46:03 -0500 | [diff] [blame] | 187 | * - profile_min_sclk |
Alex Deucher | dc85db2 | 2018-06-01 12:28:14 -0500 | [diff] [blame] | 188 | * |
Alex Deucher | 8567f68 | 2018-04-19 13:46:03 -0500 | [diff] [blame] | 189 | * - profile_min_mclk |
Alex Deucher | dc85db2 | 2018-06-01 12:28:14 -0500 | [diff] [blame] | 190 | * |
Alex Deucher | 8567f68 | 2018-04-19 13:46:03 -0500 | [diff] [blame] | 191 | * - profile_peak |
| 192 | * |
| 193 | * auto |
| 194 | * |
| 195 | * When auto is selected, the driver will attempt to dynamically select |
| 196 | * the optimal power profile for current conditions in the driver. |
| 197 | * |
| 198 | * low |
| 199 | * |
| 200 | * When low is selected, the clocks are forced to the lowest power state. |
| 201 | * |
| 202 | * high |
| 203 | * |
| 204 | * When high is selected, the clocks are forced to the highest power state. |
| 205 | * |
| 206 | * manual |
| 207 | * |
| 208 | * When manual is selected, the user can manually adjust which power states |
| 209 | * are enabled for each clock domain via the sysfs pp_dpm_mclk, pp_dpm_sclk, |
| 210 | * and pp_dpm_pcie files and adjust the power state transition heuristics |
| 211 | * via the pp_power_profile_mode sysfs file. |
| 212 | * |
| 213 | * profile_standard |
| 214 | * profile_min_sclk |
| 215 | * profile_min_mclk |
| 216 | * profile_peak |
| 217 | * |
| 218 | * When the profiling modes are selected, clock and power gating are |
| 219 | * disabled and the clocks are set for different profiling cases. This |
| 220 | * mode is recommended for profiling specific work loads where you do |
| 221 | * not want clock or power gating for clock fluctuation to interfere |
| 222 | * with your results. profile_standard sets the clocks to a fixed clock |
| 223 | * level which varies from asic to asic. profile_min_sclk forces the sclk |
| 224 | * to the lowest level. profile_min_mclk forces the mclk to the lowest level. |
| 225 | * profile_peak sets all clocks (mclk, sclk, pcie) to the highest levels. |
| 226 | * |
| 227 | */ |
| 228 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 229 | static ssize_t amdgpu_get_dpm_forced_performance_level(struct device *dev, |
Rex Zhu | 1b5708f | 2015-11-10 18:25:24 -0500 | [diff] [blame] | 230 | struct device_attribute *attr, |
| 231 | char *buf) |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 232 | { |
| 233 | struct drm_device *ddev = dev_get_drvdata(dev); |
| 234 | struct amdgpu_device *adev = ddev->dev_private; |
Rex Zhu | cd4d746 | 2017-09-06 18:43:52 +0800 | [diff] [blame] | 235 | enum amd_dpm_forced_level level = 0xff; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 236 | |
Alex Deucher | 0c67df4 | 2016-02-19 15:30:15 -0500 | [diff] [blame] | 237 | if ((adev->flags & AMD_IS_PX) && |
| 238 | (ddev->switch_power_state != DRM_SWITCH_POWER_ON)) |
| 239 | return snprintf(buf, PAGE_SIZE, "off\n"); |
| 240 | |
Rex Zhu | cd4d746 | 2017-09-06 18:43:52 +0800 | [diff] [blame] | 241 | if (adev->powerplay.pp_funcs->get_performance_level) |
| 242 | level = amdgpu_dpm_get_performance_level(adev); |
| 243 | else |
| 244 | level = adev->pm.dpm.forced_level; |
| 245 | |
Rex Zhu | e5d03ac | 2016-12-23 14:39:41 +0800 | [diff] [blame] | 246 | return snprintf(buf, PAGE_SIZE, "%s\n", |
Rex Zhu | 570272d | 2017-01-06 13:32:49 +0800 | [diff] [blame] | 247 | (level == AMD_DPM_FORCED_LEVEL_AUTO) ? "auto" : |
| 248 | (level == AMD_DPM_FORCED_LEVEL_LOW) ? "low" : |
| 249 | (level == AMD_DPM_FORCED_LEVEL_HIGH) ? "high" : |
| 250 | (level == AMD_DPM_FORCED_LEVEL_MANUAL) ? "manual" : |
| 251 | (level == AMD_DPM_FORCED_LEVEL_PROFILE_STANDARD) ? "profile_standard" : |
| 252 | (level == AMD_DPM_FORCED_LEVEL_PROFILE_MIN_SCLK) ? "profile_min_sclk" : |
| 253 | (level == AMD_DPM_FORCED_LEVEL_PROFILE_MIN_MCLK) ? "profile_min_mclk" : |
| 254 | (level == AMD_DPM_FORCED_LEVEL_PROFILE_PEAK) ? "profile_peak" : |
| 255 | "unknown"); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 256 | } |
| 257 | |
| 258 | static ssize_t amdgpu_set_dpm_forced_performance_level(struct device *dev, |
| 259 | struct device_attribute *attr, |
| 260 | const char *buf, |
| 261 | size_t count) |
| 262 | { |
| 263 | struct drm_device *ddev = dev_get_drvdata(dev); |
| 264 | struct amdgpu_device *adev = ddev->dev_private; |
Rex Zhu | e5d03ac | 2016-12-23 14:39:41 +0800 | [diff] [blame] | 265 | enum amd_dpm_forced_level level; |
Rex Zhu | cd4d746 | 2017-09-06 18:43:52 +0800 | [diff] [blame] | 266 | enum amd_dpm_forced_level current_level = 0xff; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 267 | int ret = 0; |
| 268 | |
Alex Deucher | 0c67df4 | 2016-02-19 15:30:15 -0500 | [diff] [blame] | 269 | /* Can't force performance level when the card is off */ |
| 270 | if ((adev->flags & AMD_IS_PX) && |
| 271 | (ddev->switch_power_state != DRM_SWITCH_POWER_ON)) |
| 272 | return -EINVAL; |
| 273 | |
Rex Zhu | cd4d746 | 2017-09-06 18:43:52 +0800 | [diff] [blame] | 274 | if (adev->powerplay.pp_funcs->get_performance_level) |
| 275 | current_level = amdgpu_dpm_get_performance_level(adev); |
Rex Zhu | 3bd5897 | 2016-12-23 15:24:37 +0800 | [diff] [blame] | 276 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 277 | if (strncmp("low", buf, strlen("low")) == 0) { |
Rex Zhu | e5d03ac | 2016-12-23 14:39:41 +0800 | [diff] [blame] | 278 | level = AMD_DPM_FORCED_LEVEL_LOW; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 279 | } else if (strncmp("high", buf, strlen("high")) == 0) { |
Rex Zhu | e5d03ac | 2016-12-23 14:39:41 +0800 | [diff] [blame] | 280 | level = AMD_DPM_FORCED_LEVEL_HIGH; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 281 | } else if (strncmp("auto", buf, strlen("auto")) == 0) { |
Rex Zhu | e5d03ac | 2016-12-23 14:39:41 +0800 | [diff] [blame] | 282 | level = AMD_DPM_FORCED_LEVEL_AUTO; |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 283 | } else if (strncmp("manual", buf, strlen("manual")) == 0) { |
Rex Zhu | e5d03ac | 2016-12-23 14:39:41 +0800 | [diff] [blame] | 284 | level = AMD_DPM_FORCED_LEVEL_MANUAL; |
Rex Zhu | 570272d | 2017-01-06 13:32:49 +0800 | [diff] [blame] | 285 | } else if (strncmp("profile_exit", buf, strlen("profile_exit")) == 0) { |
| 286 | level = AMD_DPM_FORCED_LEVEL_PROFILE_EXIT; |
| 287 | } else if (strncmp("profile_standard", buf, strlen("profile_standard")) == 0) { |
| 288 | level = AMD_DPM_FORCED_LEVEL_PROFILE_STANDARD; |
| 289 | } else if (strncmp("profile_min_sclk", buf, strlen("profile_min_sclk")) == 0) { |
| 290 | level = AMD_DPM_FORCED_LEVEL_PROFILE_MIN_SCLK; |
| 291 | } else if (strncmp("profile_min_mclk", buf, strlen("profile_min_mclk")) == 0) { |
| 292 | level = AMD_DPM_FORCED_LEVEL_PROFILE_MIN_MCLK; |
| 293 | } else if (strncmp("profile_peak", buf, strlen("profile_peak")) == 0) { |
| 294 | level = AMD_DPM_FORCED_LEVEL_PROFILE_PEAK; |
| 295 | } else { |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 296 | count = -EINVAL; |
| 297 | goto fail; |
| 298 | } |
Rex Zhu | 1b5708f | 2015-11-10 18:25:24 -0500 | [diff] [blame] | 299 | |
Rex Zhu | 3bd5897 | 2016-12-23 15:24:37 +0800 | [diff] [blame] | 300 | if (current_level == level) |
Rex Zhu | 8e7afd3 | 2017-01-09 15:18:01 +0800 | [diff] [blame] | 301 | return count; |
Rex Zhu | 3bd5897 | 2016-12-23 15:24:37 +0800 | [diff] [blame] | 302 | |
Rex Zhu | cd4d746 | 2017-09-06 18:43:52 +0800 | [diff] [blame] | 303 | if (adev->powerplay.pp_funcs->force_performance_level) { |
Rex Zhu | 1b5708f | 2015-11-10 18:25:24 -0500 | [diff] [blame] | 304 | mutex_lock(&adev->pm.mutex); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 305 | if (adev->pm.dpm.thermal_active) { |
| 306 | count = -EINVAL; |
Alex Deucher | 10f950f | 2016-02-19 15:18:45 -0500 | [diff] [blame] | 307 | mutex_unlock(&adev->pm.mutex); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 308 | goto fail; |
| 309 | } |
| 310 | ret = amdgpu_dpm_force_performance_level(adev, level); |
| 311 | if (ret) |
| 312 | count = -EINVAL; |
Rex Zhu | 1b5708f | 2015-11-10 18:25:24 -0500 | [diff] [blame] | 313 | else |
| 314 | adev->pm.dpm.forced_level = level; |
| 315 | mutex_unlock(&adev->pm.mutex); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 316 | } |
Rex Zhu | 570272d | 2017-01-06 13:32:49 +0800 | [diff] [blame] | 317 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 318 | fail: |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 319 | return count; |
| 320 | } |
| 321 | |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 322 | static ssize_t amdgpu_get_pp_num_states(struct device *dev, |
| 323 | struct device_attribute *attr, |
| 324 | char *buf) |
| 325 | { |
| 326 | struct drm_device *ddev = dev_get_drvdata(dev); |
| 327 | struct amdgpu_device *adev = ddev->dev_private; |
| 328 | struct pp_states_info data; |
| 329 | int i, buf_len; |
| 330 | |
Rex Zhu | cd4d746 | 2017-09-06 18:43:52 +0800 | [diff] [blame] | 331 | if (adev->powerplay.pp_funcs->get_pp_num_states) |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 332 | amdgpu_dpm_get_pp_num_states(adev, &data); |
| 333 | |
| 334 | buf_len = snprintf(buf, PAGE_SIZE, "states: %d\n", data.nums); |
| 335 | for (i = 0; i < data.nums; i++) |
| 336 | buf_len += snprintf(buf + buf_len, PAGE_SIZE, "%d %s\n", i, |
| 337 | (data.states[i] == POWER_STATE_TYPE_INTERNAL_BOOT) ? "boot" : |
| 338 | (data.states[i] == POWER_STATE_TYPE_BATTERY) ? "battery" : |
| 339 | (data.states[i] == POWER_STATE_TYPE_BALANCED) ? "balanced" : |
| 340 | (data.states[i] == POWER_STATE_TYPE_PERFORMANCE) ? "performance" : "default"); |
| 341 | |
| 342 | return buf_len; |
| 343 | } |
| 344 | |
| 345 | static ssize_t amdgpu_get_pp_cur_state(struct device *dev, |
| 346 | struct device_attribute *attr, |
| 347 | char *buf) |
| 348 | { |
| 349 | struct drm_device *ddev = dev_get_drvdata(dev); |
| 350 | struct amdgpu_device *adev = ddev->dev_private; |
| 351 | struct pp_states_info data; |
| 352 | enum amd_pm_state_type pm = 0; |
| 353 | int i = 0; |
| 354 | |
Rex Zhu | cd4d746 | 2017-09-06 18:43:52 +0800 | [diff] [blame] | 355 | if (adev->powerplay.pp_funcs->get_current_power_state |
| 356 | && adev->powerplay.pp_funcs->get_pp_num_states) { |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 357 | pm = amdgpu_dpm_get_current_power_state(adev); |
| 358 | amdgpu_dpm_get_pp_num_states(adev, &data); |
| 359 | |
| 360 | for (i = 0; i < data.nums; i++) { |
| 361 | if (pm == data.states[i]) |
| 362 | break; |
| 363 | } |
| 364 | |
| 365 | if (i == data.nums) |
| 366 | i = -EINVAL; |
| 367 | } |
| 368 | |
| 369 | return snprintf(buf, PAGE_SIZE, "%d\n", i); |
| 370 | } |
| 371 | |
| 372 | static ssize_t amdgpu_get_pp_force_state(struct device *dev, |
| 373 | struct device_attribute *attr, |
| 374 | char *buf) |
| 375 | { |
| 376 | struct drm_device *ddev = dev_get_drvdata(dev); |
| 377 | struct amdgpu_device *adev = ddev->dev_private; |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 378 | |
Rex Zhu | cd4d746 | 2017-09-06 18:43:52 +0800 | [diff] [blame] | 379 | if (adev->pp_force_state_enabled) |
| 380 | return amdgpu_get_pp_cur_state(dev, attr, buf); |
| 381 | else |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 382 | return snprintf(buf, PAGE_SIZE, "\n"); |
| 383 | } |
| 384 | |
| 385 | static ssize_t amdgpu_set_pp_force_state(struct device *dev, |
| 386 | struct device_attribute *attr, |
| 387 | const char *buf, |
| 388 | size_t count) |
| 389 | { |
| 390 | struct drm_device *ddev = dev_get_drvdata(dev); |
| 391 | struct amdgpu_device *adev = ddev->dev_private; |
| 392 | enum amd_pm_state_type state = 0; |
Dan Carpenter | 041bf02 | 2016-06-16 11:30:23 +0300 | [diff] [blame] | 393 | unsigned long idx; |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 394 | int ret; |
| 395 | |
| 396 | if (strlen(buf) == 1) |
| 397 | adev->pp_force_state_enabled = false; |
Rex Zhu | 6d07fe7 | 2017-09-25 18:51:50 +0800 | [diff] [blame] | 398 | else if (adev->powerplay.pp_funcs->dispatch_tasks && |
| 399 | adev->powerplay.pp_funcs->get_pp_num_states) { |
Dan Carpenter | 041bf02 | 2016-06-16 11:30:23 +0300 | [diff] [blame] | 400 | struct pp_states_info data; |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 401 | |
Dan Carpenter | 041bf02 | 2016-06-16 11:30:23 +0300 | [diff] [blame] | 402 | ret = kstrtoul(buf, 0, &idx); |
| 403 | if (ret || idx >= ARRAY_SIZE(data.states)) { |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 404 | count = -EINVAL; |
| 405 | goto fail; |
| 406 | } |
Gustavo A. R. Silva | ddf74e7 | 2018-07-23 11:32:32 -0500 | [diff] [blame] | 407 | idx = array_index_nospec(idx, ARRAY_SIZE(data.states)); |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 408 | |
Dan Carpenter | 041bf02 | 2016-06-16 11:30:23 +0300 | [diff] [blame] | 409 | amdgpu_dpm_get_pp_num_states(adev, &data); |
| 410 | state = data.states[idx]; |
| 411 | /* only set user selected power states */ |
| 412 | if (state != POWER_STATE_TYPE_INTERNAL_BOOT && |
| 413 | state != POWER_STATE_TYPE_DEFAULT) { |
| 414 | amdgpu_dpm_dispatch_task(adev, |
Evan Quan | 39199b8 | 2017-12-29 14:46:13 +0800 | [diff] [blame] | 415 | AMD_PP_TASK_ENABLE_USER_STATE, &state); |
Dan Carpenter | 041bf02 | 2016-06-16 11:30:23 +0300 | [diff] [blame] | 416 | adev->pp_force_state_enabled = true; |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 417 | } |
| 418 | } |
| 419 | fail: |
| 420 | return count; |
| 421 | } |
| 422 | |
Alex Deucher | d54bb40 | 2018-04-19 14:02:52 -0500 | [diff] [blame] | 423 | /** |
| 424 | * DOC: pp_table |
| 425 | * |
| 426 | * The amdgpu driver provides a sysfs API for uploading new powerplay |
| 427 | * tables. The file pp_table is used for this. Reading the file |
| 428 | * will dump the current power play table. Writing to the file |
| 429 | * will attempt to upload a new powerplay table and re-initialize |
| 430 | * powerplay using that new table. |
| 431 | * |
| 432 | */ |
| 433 | |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 434 | static ssize_t amdgpu_get_pp_table(struct device *dev, |
| 435 | struct device_attribute *attr, |
| 436 | char *buf) |
| 437 | { |
| 438 | struct drm_device *ddev = dev_get_drvdata(dev); |
| 439 | struct amdgpu_device *adev = ddev->dev_private; |
| 440 | char *table = NULL; |
Eric Huang | 1684d3b | 2016-07-28 17:25:01 -0400 | [diff] [blame] | 441 | int size; |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 442 | |
Rex Zhu | cd4d746 | 2017-09-06 18:43:52 +0800 | [diff] [blame] | 443 | if (adev->powerplay.pp_funcs->get_pp_table) |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 444 | size = amdgpu_dpm_get_pp_table(adev, &table); |
| 445 | else |
| 446 | return 0; |
| 447 | |
| 448 | if (size >= PAGE_SIZE) |
| 449 | size = PAGE_SIZE - 1; |
| 450 | |
Eric Huang | 1684d3b | 2016-07-28 17:25:01 -0400 | [diff] [blame] | 451 | memcpy(buf, table, size); |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 452 | |
| 453 | return size; |
| 454 | } |
| 455 | |
| 456 | static ssize_t amdgpu_set_pp_table(struct device *dev, |
| 457 | struct device_attribute *attr, |
| 458 | const char *buf, |
| 459 | size_t count) |
| 460 | { |
| 461 | struct drm_device *ddev = dev_get_drvdata(dev); |
| 462 | struct amdgpu_device *adev = ddev->dev_private; |
| 463 | |
Rex Zhu | cd4d746 | 2017-09-06 18:43:52 +0800 | [diff] [blame] | 464 | if (adev->powerplay.pp_funcs->set_pp_table) |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 465 | amdgpu_dpm_set_pp_table(adev, buf, count); |
| 466 | |
| 467 | return count; |
| 468 | } |
| 469 | |
Alex Deucher | 4e418c3 | 2018-04-19 14:59:55 -0500 | [diff] [blame] | 470 | /** |
| 471 | * DOC: pp_od_clk_voltage |
| 472 | * |
| 473 | * The amdgpu driver provides a sysfs API for adjusting the clocks and voltages |
| 474 | * in each power level within a power state. The pp_od_clk_voltage is used for |
| 475 | * this. |
| 476 | * |
Evan Quan | d5bf265 | 2018-08-29 14:38:50 +0800 | [diff] [blame] | 477 | * < For Vega10 and previous ASICs > |
| 478 | * |
Alex Deucher | 4e418c3 | 2018-04-19 14:59:55 -0500 | [diff] [blame] | 479 | * Reading the file will display: |
Alex Deucher | dc85db2 | 2018-06-01 12:28:14 -0500 | [diff] [blame] | 480 | * |
Alex Deucher | 4e418c3 | 2018-04-19 14:59:55 -0500 | [diff] [blame] | 481 | * - a list of engine clock levels and voltages labeled OD_SCLK |
Alex Deucher | dc85db2 | 2018-06-01 12:28:14 -0500 | [diff] [blame] | 482 | * |
Alex Deucher | 4e418c3 | 2018-04-19 14:59:55 -0500 | [diff] [blame] | 483 | * - a list of memory clock levels and voltages labeled OD_MCLK |
Alex Deucher | dc85db2 | 2018-06-01 12:28:14 -0500 | [diff] [blame] | 484 | * |
Alex Deucher | 4e418c3 | 2018-04-19 14:59:55 -0500 | [diff] [blame] | 485 | * - a list of valid ranges for sclk, mclk, and voltage labeled OD_RANGE |
| 486 | * |
| 487 | * To manually adjust these settings, first select manual using |
| 488 | * power_dpm_force_performance_level. Enter a new value for each |
| 489 | * level by writing a string that contains "s/m level clock voltage" to |
| 490 | * the file. E.g., "s 1 500 820" will update sclk level 1 to be 500 MHz |
| 491 | * at 820 mV; "m 0 350 810" will update mclk level 0 to be 350 MHz at |
| 492 | * 810 mV. When you have edited all of the states as needed, write |
| 493 | * "c" (commit) to the file to commit your changes. If you want to reset to the |
| 494 | * default power levels, write "r" (reset) to the file to reset them. |
| 495 | * |
Evan Quan | d5bf265 | 2018-08-29 14:38:50 +0800 | [diff] [blame] | 496 | * |
| 497 | * < For Vega20 > |
| 498 | * |
| 499 | * Reading the file will display: |
| 500 | * |
| 501 | * - minimum and maximum engine clock labeled OD_SCLK |
| 502 | * |
| 503 | * - maximum memory clock labeled OD_MCLK |
| 504 | * |
Evan Quan | b1f82cb | 2018-09-13 16:14:33 +0800 | [diff] [blame] | 505 | * - three <frequency, voltage> points labeled OD_VDDC_CURVE. |
Evan Quan | d5bf265 | 2018-08-29 14:38:50 +0800 | [diff] [blame] | 506 | * They can be used to calibrate the sclk voltage curve. |
| 507 | * |
| 508 | * - a list of valid ranges for sclk, mclk, and voltage curve points |
| 509 | * labeled OD_RANGE |
| 510 | * |
| 511 | * To manually adjust these settings: |
| 512 | * |
| 513 | * - First select manual using power_dpm_force_performance_level |
| 514 | * |
| 515 | * - For clock frequency setting, enter a new value by writing a |
| 516 | * string that contains "s/m index clock" to the file. The index |
| 517 | * should be 0 if to set minimum clock. And 1 if to set maximum |
| 518 | * clock. E.g., "s 0 500" will update minimum sclk to be 500 MHz. |
| 519 | * "m 1 800" will update maximum mclk to be 800Mhz. |
| 520 | * |
| 521 | * For sclk voltage curve, enter the new values by writing a |
Evan Quan | b1f82cb | 2018-09-13 16:14:33 +0800 | [diff] [blame] | 522 | * string that contains "vc point clock voltage" to the file. The |
| 523 | * points are indexed by 0, 1 and 2. E.g., "vc 0 300 600" will |
| 524 | * update point1 with clock set as 300Mhz and voltage as |
| 525 | * 600mV. "vc 2 1000 1000" will update point3 with clock set |
| 526 | * as 1000Mhz and voltage 1000mV. |
Evan Quan | d5bf265 | 2018-08-29 14:38:50 +0800 | [diff] [blame] | 527 | * |
| 528 | * - When you have edited all of the states as needed, write "c" (commit) |
| 529 | * to the file to commit your changes |
| 530 | * |
| 531 | * - If you want to reset to the default power levels, write "r" (reset) |
| 532 | * to the file to reset them |
| 533 | * |
Alex Deucher | 4e418c3 | 2018-04-19 14:59:55 -0500 | [diff] [blame] | 534 | */ |
| 535 | |
Rex Zhu | e3933f2 | 2018-01-16 18:35:15 +0800 | [diff] [blame] | 536 | static ssize_t amdgpu_set_pp_od_clk_voltage(struct device *dev, |
| 537 | struct device_attribute *attr, |
| 538 | const char *buf, |
| 539 | size_t count) |
| 540 | { |
| 541 | struct drm_device *ddev = dev_get_drvdata(dev); |
| 542 | struct amdgpu_device *adev = ddev->dev_private; |
| 543 | int ret; |
| 544 | uint32_t parameter_size = 0; |
| 545 | long parameter[64]; |
| 546 | char buf_cpy[128]; |
| 547 | char *tmp_str; |
| 548 | char *sub_str; |
| 549 | const char delimiter[3] = {' ', '\n', '\0'}; |
| 550 | uint32_t type; |
| 551 | |
| 552 | if (count > 127) |
| 553 | return -EINVAL; |
| 554 | |
| 555 | if (*buf == 's') |
| 556 | type = PP_OD_EDIT_SCLK_VDDC_TABLE; |
| 557 | else if (*buf == 'm') |
| 558 | type = PP_OD_EDIT_MCLK_VDDC_TABLE; |
| 559 | else if(*buf == 'r') |
| 560 | type = PP_OD_RESTORE_DEFAULT_TABLE; |
| 561 | else if (*buf == 'c') |
| 562 | type = PP_OD_COMMIT_DPM_TABLE; |
Evan Quan | d5bf265 | 2018-08-29 14:38:50 +0800 | [diff] [blame] | 563 | else if (!strncmp(buf, "vc", 2)) |
| 564 | type = PP_OD_EDIT_VDDC_CURVE; |
Rex Zhu | e3933f2 | 2018-01-16 18:35:15 +0800 | [diff] [blame] | 565 | else |
| 566 | return -EINVAL; |
| 567 | |
| 568 | memcpy(buf_cpy, buf, count+1); |
| 569 | |
| 570 | tmp_str = buf_cpy; |
| 571 | |
Evan Quan | d5bf265 | 2018-08-29 14:38:50 +0800 | [diff] [blame] | 572 | if (type == PP_OD_EDIT_VDDC_CURVE) |
| 573 | tmp_str++; |
Rex Zhu | e3933f2 | 2018-01-16 18:35:15 +0800 | [diff] [blame] | 574 | while (isspace(*++tmp_str)); |
| 575 | |
| 576 | while (tmp_str[0]) { |
| 577 | sub_str = strsep(&tmp_str, delimiter); |
| 578 | ret = kstrtol(sub_str, 0, ¶meter[parameter_size]); |
| 579 | if (ret) |
| 580 | return -EINVAL; |
| 581 | parameter_size++; |
| 582 | |
| 583 | while (isspace(*tmp_str)) |
| 584 | tmp_str++; |
| 585 | } |
| 586 | |
| 587 | if (adev->powerplay.pp_funcs->odn_edit_dpm_table) |
| 588 | ret = amdgpu_dpm_odn_edit_dpm_table(adev, type, |
| 589 | parameter, parameter_size); |
| 590 | |
| 591 | if (ret) |
| 592 | return -EINVAL; |
| 593 | |
| 594 | if (type == PP_OD_COMMIT_DPM_TABLE) { |
| 595 | if (adev->powerplay.pp_funcs->dispatch_tasks) { |
| 596 | amdgpu_dpm_dispatch_task(adev, AMD_PP_TASK_READJUST_POWER_STATE, NULL); |
| 597 | return count; |
| 598 | } else { |
| 599 | return -EINVAL; |
| 600 | } |
| 601 | } |
| 602 | |
| 603 | return count; |
| 604 | } |
| 605 | |
| 606 | static ssize_t amdgpu_get_pp_od_clk_voltage(struct device *dev, |
| 607 | struct device_attribute *attr, |
| 608 | char *buf) |
| 609 | { |
| 610 | struct drm_device *ddev = dev_get_drvdata(dev); |
| 611 | struct amdgpu_device *adev = ddev->dev_private; |
| 612 | uint32_t size = 0; |
| 613 | |
| 614 | if (adev->powerplay.pp_funcs->print_clock_levels) { |
| 615 | size = amdgpu_dpm_print_clock_levels(adev, OD_SCLK, buf); |
| 616 | size += amdgpu_dpm_print_clock_levels(adev, OD_MCLK, buf+size); |
Evan Quan | d5bf265 | 2018-08-29 14:38:50 +0800 | [diff] [blame] | 617 | size += amdgpu_dpm_print_clock_levels(adev, OD_VDDC_CURVE, buf+size); |
Rex Zhu | a3c991f | 2018-04-19 10:39:17 +0800 | [diff] [blame] | 618 | size += amdgpu_dpm_print_clock_levels(adev, OD_RANGE, buf+size); |
Rex Zhu | e3933f2 | 2018-01-16 18:35:15 +0800 | [diff] [blame] | 619 | return size; |
| 620 | } else { |
| 621 | return snprintf(buf, PAGE_SIZE, "\n"); |
| 622 | } |
| 623 | |
| 624 | } |
| 625 | |
Alex Deucher | 271dc90 | 2018-04-19 14:22:24 -0500 | [diff] [blame] | 626 | /** |
| 627 | * DOC: pp_dpm_sclk pp_dpm_mclk pp_dpm_pcie |
| 628 | * |
| 629 | * The amdgpu driver provides a sysfs API for adjusting what power levels |
| 630 | * are enabled for a given power state. The files pp_dpm_sclk, pp_dpm_mclk, |
| 631 | * and pp_dpm_pcie are used for this. |
| 632 | * |
| 633 | * Reading back the files will show you the available power levels within |
| 634 | * the power state and the clock information for those levels. |
| 635 | * |
| 636 | * To manually adjust these states, first select manual using |
welu | 48edde3 | 2018-04-24 09:13:20 -0400 | [diff] [blame] | 637 | * power_dpm_force_performance_level. |
| 638 | * Secondly,Enter a new value for each level by inputing a string that |
| 639 | * contains " echo xx xx xx > pp_dpm_sclk/mclk/pcie" |
| 640 | * E.g., echo 4 5 6 to > pp_dpm_sclk will enable sclk levels 4, 5, and 6. |
Alex Deucher | 271dc90 | 2018-04-19 14:22:24 -0500 | [diff] [blame] | 641 | */ |
| 642 | |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 643 | static ssize_t amdgpu_get_pp_dpm_sclk(struct device *dev, |
| 644 | struct device_attribute *attr, |
| 645 | char *buf) |
| 646 | { |
| 647 | struct drm_device *ddev = dev_get_drvdata(dev); |
| 648 | struct amdgpu_device *adev = ddev->dev_private; |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 649 | |
Rex Zhu | cd4d746 | 2017-09-06 18:43:52 +0800 | [diff] [blame] | 650 | if (adev->powerplay.pp_funcs->print_clock_levels) |
| 651 | return amdgpu_dpm_print_clock_levels(adev, PP_SCLK, buf); |
| 652 | else |
| 653 | return snprintf(buf, PAGE_SIZE, "\n"); |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 654 | } |
| 655 | |
Kees Cook | 4b4bd04 | 2018-06-20 11:26:47 -0700 | [diff] [blame] | 656 | /* |
| 657 | * Worst case: 32 bits individually specified, in octal at 12 characters |
| 658 | * per line (+1 for \n). |
| 659 | */ |
| 660 | #define AMDGPU_MASK_BUF_MAX (32 * 13) |
| 661 | |
| 662 | static ssize_t amdgpu_read_mask(const char *buf, size_t count, uint32_t *mask) |
| 663 | { |
| 664 | int ret; |
| 665 | long level; |
| 666 | char *sub_str = NULL; |
| 667 | char *tmp; |
| 668 | char buf_cpy[AMDGPU_MASK_BUF_MAX + 1]; |
| 669 | const char delimiter[3] = {' ', '\n', '\0'}; |
| 670 | size_t bytes; |
| 671 | |
| 672 | *mask = 0; |
| 673 | |
| 674 | bytes = min(count, sizeof(buf_cpy) - 1); |
| 675 | memcpy(buf_cpy, buf, bytes); |
| 676 | buf_cpy[bytes] = '\0'; |
| 677 | tmp = buf_cpy; |
| 678 | while (tmp[0]) { |
| 679 | sub_str = strsep(&tmp, delimiter); |
| 680 | if (strlen(sub_str)) { |
| 681 | ret = kstrtol(sub_str, 0, &level); |
| 682 | if (ret) |
| 683 | return -EINVAL; |
| 684 | *mask |= 1 << level; |
| 685 | } else |
| 686 | break; |
| 687 | } |
| 688 | |
| 689 | return 0; |
| 690 | } |
| 691 | |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 692 | static ssize_t amdgpu_set_pp_dpm_sclk(struct device *dev, |
| 693 | struct device_attribute *attr, |
| 694 | const char *buf, |
| 695 | size_t count) |
| 696 | { |
| 697 | struct drm_device *ddev = dev_get_drvdata(dev); |
| 698 | struct amdgpu_device *adev = ddev->dev_private; |
| 699 | int ret; |
welu | 48edde3 | 2018-04-24 09:13:20 -0400 | [diff] [blame] | 700 | uint32_t mask = 0; |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 701 | |
Kees Cook | 4b4bd04 | 2018-06-20 11:26:47 -0700 | [diff] [blame] | 702 | ret = amdgpu_read_mask(buf, count, &mask); |
| 703 | if (ret) |
| 704 | return ret; |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 705 | |
Rex Zhu | cd4d746 | 2017-09-06 18:43:52 +0800 | [diff] [blame] | 706 | if (adev->powerplay.pp_funcs->force_clock_level) |
Evan Quan | 241dbbb | 2018-10-17 16:36:02 +0800 | [diff] [blame] | 707 | ret = amdgpu_dpm_force_clock_level(adev, PP_SCLK, mask); |
| 708 | |
| 709 | if (ret) |
| 710 | return -EINVAL; |
Rex Zhu | cd4d746 | 2017-09-06 18:43:52 +0800 | [diff] [blame] | 711 | |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 712 | return count; |
| 713 | } |
| 714 | |
| 715 | static ssize_t amdgpu_get_pp_dpm_mclk(struct device *dev, |
| 716 | struct device_attribute *attr, |
| 717 | char *buf) |
| 718 | { |
| 719 | struct drm_device *ddev = dev_get_drvdata(dev); |
| 720 | struct amdgpu_device *adev = ddev->dev_private; |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 721 | |
Rex Zhu | cd4d746 | 2017-09-06 18:43:52 +0800 | [diff] [blame] | 722 | if (adev->powerplay.pp_funcs->print_clock_levels) |
| 723 | return amdgpu_dpm_print_clock_levels(adev, PP_MCLK, buf); |
| 724 | else |
| 725 | return snprintf(buf, PAGE_SIZE, "\n"); |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 726 | } |
| 727 | |
| 728 | static ssize_t amdgpu_set_pp_dpm_mclk(struct device *dev, |
| 729 | struct device_attribute *attr, |
| 730 | const char *buf, |
| 731 | size_t count) |
| 732 | { |
| 733 | struct drm_device *ddev = dev_get_drvdata(dev); |
| 734 | struct amdgpu_device *adev = ddev->dev_private; |
| 735 | int ret; |
welu | 48edde3 | 2018-04-24 09:13:20 -0400 | [diff] [blame] | 736 | uint32_t mask = 0; |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 737 | |
Kees Cook | 4b4bd04 | 2018-06-20 11:26:47 -0700 | [diff] [blame] | 738 | ret = amdgpu_read_mask(buf, count, &mask); |
| 739 | if (ret) |
| 740 | return ret; |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 741 | |
Rex Zhu | cd4d746 | 2017-09-06 18:43:52 +0800 | [diff] [blame] | 742 | if (adev->powerplay.pp_funcs->force_clock_level) |
Evan Quan | 241dbbb | 2018-10-17 16:36:02 +0800 | [diff] [blame] | 743 | ret = amdgpu_dpm_force_clock_level(adev, PP_MCLK, mask); |
| 744 | |
| 745 | if (ret) |
| 746 | return -EINVAL; |
Rex Zhu | cd4d746 | 2017-09-06 18:43:52 +0800 | [diff] [blame] | 747 | |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 748 | return count; |
| 749 | } |
| 750 | |
| 751 | static ssize_t amdgpu_get_pp_dpm_pcie(struct device *dev, |
| 752 | struct device_attribute *attr, |
| 753 | char *buf) |
| 754 | { |
| 755 | struct drm_device *ddev = dev_get_drvdata(dev); |
| 756 | struct amdgpu_device *adev = ddev->dev_private; |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 757 | |
Rex Zhu | cd4d746 | 2017-09-06 18:43:52 +0800 | [diff] [blame] | 758 | if (adev->powerplay.pp_funcs->print_clock_levels) |
| 759 | return amdgpu_dpm_print_clock_levels(adev, PP_PCIE, buf); |
| 760 | else |
| 761 | return snprintf(buf, PAGE_SIZE, "\n"); |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 762 | } |
| 763 | |
| 764 | static ssize_t amdgpu_set_pp_dpm_pcie(struct device *dev, |
| 765 | struct device_attribute *attr, |
| 766 | const char *buf, |
| 767 | size_t count) |
| 768 | { |
| 769 | struct drm_device *ddev = dev_get_drvdata(dev); |
| 770 | struct amdgpu_device *adev = ddev->dev_private; |
| 771 | int ret; |
welu | 48edde3 | 2018-04-24 09:13:20 -0400 | [diff] [blame] | 772 | uint32_t mask = 0; |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 773 | |
Kees Cook | 4b4bd04 | 2018-06-20 11:26:47 -0700 | [diff] [blame] | 774 | ret = amdgpu_read_mask(buf, count, &mask); |
| 775 | if (ret) |
| 776 | return ret; |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 777 | |
Rex Zhu | cd4d746 | 2017-09-06 18:43:52 +0800 | [diff] [blame] | 778 | if (adev->powerplay.pp_funcs->force_clock_level) |
Evan Quan | 241dbbb | 2018-10-17 16:36:02 +0800 | [diff] [blame] | 779 | ret = amdgpu_dpm_force_clock_level(adev, PP_PCIE, mask); |
| 780 | |
| 781 | if (ret) |
| 782 | return -EINVAL; |
Rex Zhu | cd4d746 | 2017-09-06 18:43:52 +0800 | [diff] [blame] | 783 | |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 784 | return count; |
| 785 | } |
| 786 | |
Eric Huang | 428bafa | 2016-05-12 14:51:21 -0400 | [diff] [blame] | 787 | static ssize_t amdgpu_get_pp_sclk_od(struct device *dev, |
| 788 | struct device_attribute *attr, |
| 789 | char *buf) |
| 790 | { |
| 791 | struct drm_device *ddev = dev_get_drvdata(dev); |
| 792 | struct amdgpu_device *adev = ddev->dev_private; |
| 793 | uint32_t value = 0; |
| 794 | |
Rex Zhu | cd4d746 | 2017-09-06 18:43:52 +0800 | [diff] [blame] | 795 | if (adev->powerplay.pp_funcs->get_sclk_od) |
Eric Huang | 428bafa | 2016-05-12 14:51:21 -0400 | [diff] [blame] | 796 | value = amdgpu_dpm_get_sclk_od(adev); |
| 797 | |
| 798 | return snprintf(buf, PAGE_SIZE, "%d\n", value); |
| 799 | } |
| 800 | |
| 801 | static ssize_t amdgpu_set_pp_sclk_od(struct device *dev, |
| 802 | struct device_attribute *attr, |
| 803 | const char *buf, |
| 804 | size_t count) |
| 805 | { |
| 806 | struct drm_device *ddev = dev_get_drvdata(dev); |
| 807 | struct amdgpu_device *adev = ddev->dev_private; |
| 808 | int ret; |
| 809 | long int value; |
| 810 | |
| 811 | ret = kstrtol(buf, 0, &value); |
| 812 | |
| 813 | if (ret) { |
| 814 | count = -EINVAL; |
| 815 | goto fail; |
| 816 | } |
Rex Zhu | cd4d746 | 2017-09-06 18:43:52 +0800 | [diff] [blame] | 817 | if (adev->powerplay.pp_funcs->set_sclk_od) |
| 818 | amdgpu_dpm_set_sclk_od(adev, (uint32_t)value); |
Eric Huang | 428bafa | 2016-05-12 14:51:21 -0400 | [diff] [blame] | 819 | |
Rex Zhu | 6d07fe7 | 2017-09-25 18:51:50 +0800 | [diff] [blame] | 820 | if (adev->powerplay.pp_funcs->dispatch_tasks) { |
Evan Quan | 39199b8 | 2017-12-29 14:46:13 +0800 | [diff] [blame] | 821 | amdgpu_dpm_dispatch_task(adev, AMD_PP_TASK_READJUST_POWER_STATE, NULL); |
Rex Zhu | cd4d746 | 2017-09-06 18:43:52 +0800 | [diff] [blame] | 822 | } else { |
Eric Huang | 8b2e574 | 2016-05-19 15:46:10 -0400 | [diff] [blame] | 823 | adev->pm.dpm.current_ps = adev->pm.dpm.boot_ps; |
| 824 | amdgpu_pm_compute_clocks(adev); |
| 825 | } |
Eric Huang | 428bafa | 2016-05-12 14:51:21 -0400 | [diff] [blame] | 826 | |
| 827 | fail: |
| 828 | return count; |
| 829 | } |
| 830 | |
Eric Huang | f2bdc05 | 2016-05-24 15:11:17 -0400 | [diff] [blame] | 831 | static ssize_t amdgpu_get_pp_mclk_od(struct device *dev, |
| 832 | struct device_attribute *attr, |
| 833 | char *buf) |
| 834 | { |
| 835 | struct drm_device *ddev = dev_get_drvdata(dev); |
| 836 | struct amdgpu_device *adev = ddev->dev_private; |
| 837 | uint32_t value = 0; |
| 838 | |
Rex Zhu | cd4d746 | 2017-09-06 18:43:52 +0800 | [diff] [blame] | 839 | if (adev->powerplay.pp_funcs->get_mclk_od) |
Eric Huang | f2bdc05 | 2016-05-24 15:11:17 -0400 | [diff] [blame] | 840 | value = amdgpu_dpm_get_mclk_od(adev); |
Eric Huang | f2bdc05 | 2016-05-24 15:11:17 -0400 | [diff] [blame] | 841 | |
| 842 | return snprintf(buf, PAGE_SIZE, "%d\n", value); |
| 843 | } |
| 844 | |
| 845 | static ssize_t amdgpu_set_pp_mclk_od(struct device *dev, |
| 846 | struct device_attribute *attr, |
| 847 | const char *buf, |
| 848 | size_t count) |
| 849 | { |
| 850 | struct drm_device *ddev = dev_get_drvdata(dev); |
| 851 | struct amdgpu_device *adev = ddev->dev_private; |
| 852 | int ret; |
| 853 | long int value; |
| 854 | |
| 855 | ret = kstrtol(buf, 0, &value); |
| 856 | |
| 857 | if (ret) { |
| 858 | count = -EINVAL; |
| 859 | goto fail; |
| 860 | } |
Rex Zhu | cd4d746 | 2017-09-06 18:43:52 +0800 | [diff] [blame] | 861 | if (adev->powerplay.pp_funcs->set_mclk_od) |
| 862 | amdgpu_dpm_set_mclk_od(adev, (uint32_t)value); |
Eric Huang | f2bdc05 | 2016-05-24 15:11:17 -0400 | [diff] [blame] | 863 | |
Rex Zhu | 6d07fe7 | 2017-09-25 18:51:50 +0800 | [diff] [blame] | 864 | if (adev->powerplay.pp_funcs->dispatch_tasks) { |
Evan Quan | 39199b8 | 2017-12-29 14:46:13 +0800 | [diff] [blame] | 865 | amdgpu_dpm_dispatch_task(adev, AMD_PP_TASK_READJUST_POWER_STATE, NULL); |
Rex Zhu | cd4d746 | 2017-09-06 18:43:52 +0800 | [diff] [blame] | 866 | } else { |
Eric Huang | f2bdc05 | 2016-05-24 15:11:17 -0400 | [diff] [blame] | 867 | adev->pm.dpm.current_ps = adev->pm.dpm.boot_ps; |
| 868 | amdgpu_pm_compute_clocks(adev); |
| 869 | } |
| 870 | |
| 871 | fail: |
| 872 | return count; |
| 873 | } |
| 874 | |
Alex Deucher | 6b2576f | 2018-04-19 14:38:31 -0500 | [diff] [blame] | 875 | /** |
| 876 | * DOC: pp_power_profile_mode |
| 877 | * |
| 878 | * The amdgpu driver provides a sysfs API for adjusting the heuristics |
| 879 | * related to switching between power levels in a power state. The file |
| 880 | * pp_power_profile_mode is used for this. |
| 881 | * |
| 882 | * Reading this file outputs a list of all of the predefined power profiles |
| 883 | * and the relevant heuristics settings for that profile. |
| 884 | * |
| 885 | * To select a profile or create a custom profile, first select manual using |
| 886 | * power_dpm_force_performance_level. Writing the number of a predefined |
| 887 | * profile to pp_power_profile_mode will enable those heuristics. To |
| 888 | * create a custom set of heuristics, write a string of numbers to the file |
| 889 | * starting with the number of the custom profile along with a setting |
| 890 | * for each heuristic parameter. Due to differences across asic families |
| 891 | * the heuristic parameters vary from family to family. |
| 892 | * |
| 893 | */ |
| 894 | |
Rex Zhu | 37c5c4d | 2018-01-10 18:42:36 +0800 | [diff] [blame] | 895 | static ssize_t amdgpu_get_pp_power_profile_mode(struct device *dev, |
| 896 | struct device_attribute *attr, |
| 897 | char *buf) |
| 898 | { |
| 899 | struct drm_device *ddev = dev_get_drvdata(dev); |
| 900 | struct amdgpu_device *adev = ddev->dev_private; |
| 901 | |
| 902 | if (adev->powerplay.pp_funcs->get_power_profile_mode) |
| 903 | return amdgpu_dpm_get_power_profile_mode(adev, buf); |
| 904 | |
| 905 | return snprintf(buf, PAGE_SIZE, "\n"); |
| 906 | } |
| 907 | |
| 908 | |
| 909 | static ssize_t amdgpu_set_pp_power_profile_mode(struct device *dev, |
| 910 | struct device_attribute *attr, |
| 911 | const char *buf, |
| 912 | size_t count) |
| 913 | { |
| 914 | int ret = 0xff; |
| 915 | struct drm_device *ddev = dev_get_drvdata(dev); |
| 916 | struct amdgpu_device *adev = ddev->dev_private; |
| 917 | uint32_t parameter_size = 0; |
| 918 | long parameter[64]; |
| 919 | char *sub_str, buf_cpy[128]; |
| 920 | char *tmp_str; |
| 921 | uint32_t i = 0; |
| 922 | char tmp[2]; |
| 923 | long int profile_mode = 0; |
| 924 | const char delimiter[3] = {' ', '\n', '\0'}; |
| 925 | |
| 926 | tmp[0] = *(buf); |
| 927 | tmp[1] = '\0'; |
| 928 | ret = kstrtol(tmp, 0, &profile_mode); |
| 929 | if (ret) |
| 930 | goto fail; |
| 931 | |
| 932 | if (profile_mode == PP_SMC_POWER_PROFILE_CUSTOM) { |
| 933 | if (count < 2 || count > 127) |
| 934 | return -EINVAL; |
| 935 | while (isspace(*++buf)) |
| 936 | i++; |
| 937 | memcpy(buf_cpy, buf, count-i); |
| 938 | tmp_str = buf_cpy; |
| 939 | while (tmp_str[0]) { |
| 940 | sub_str = strsep(&tmp_str, delimiter); |
| 941 | ret = kstrtol(sub_str, 0, ¶meter[parameter_size]); |
| 942 | if (ret) { |
| 943 | count = -EINVAL; |
| 944 | goto fail; |
| 945 | } |
Rex Zhu | 37c5c4d | 2018-01-10 18:42:36 +0800 | [diff] [blame] | 946 | parameter_size++; |
| 947 | while (isspace(*tmp_str)) |
| 948 | tmp_str++; |
| 949 | } |
| 950 | } |
| 951 | parameter[parameter_size] = profile_mode; |
| 952 | if (adev->powerplay.pp_funcs->set_power_profile_mode) |
| 953 | ret = amdgpu_dpm_set_power_profile_mode(adev, parameter, parameter_size); |
| 954 | |
| 955 | if (!ret) |
| 956 | return count; |
| 957 | fail: |
| 958 | return -EINVAL; |
| 959 | } |
| 960 | |
Tom St Denis | b374d82 | 2018-06-20 07:55:39 -0400 | [diff] [blame] | 961 | /** |
| 962 | * DOC: busy_percent |
| 963 | * |
| 964 | * The amdgpu driver provides a sysfs API for reading how busy the GPU |
| 965 | * is as a percentage. The file gpu_busy_percent is used for this. |
| 966 | * The SMU firmware computes a percentage of load based on the |
| 967 | * aggregate activity level in the IP cores. |
| 968 | */ |
| 969 | static ssize_t amdgpu_get_busy_percent(struct device *dev, |
| 970 | struct device_attribute *attr, |
| 971 | char *buf) |
| 972 | { |
| 973 | struct drm_device *ddev = dev_get_drvdata(dev); |
| 974 | struct amdgpu_device *adev = ddev->dev_private; |
| 975 | int r, value, size = sizeof(value); |
| 976 | |
| 977 | /* sanity check PP is enabled */ |
| 978 | if (!(adev->powerplay.pp_funcs && |
| 979 | adev->powerplay.pp_funcs->read_sensor)) |
| 980 | return -EINVAL; |
| 981 | |
| 982 | /* read the IP busy sensor */ |
| 983 | r = amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GPU_LOAD, |
| 984 | (void *)&value, &size); |
| 985 | if (r) |
| 986 | return r; |
| 987 | |
| 988 | return snprintf(buf, PAGE_SIZE, "%d\n", value); |
| 989 | } |
| 990 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 991 | static DEVICE_ATTR(power_dpm_state, S_IRUGO | S_IWUSR, amdgpu_get_dpm_state, amdgpu_set_dpm_state); |
| 992 | static DEVICE_ATTR(power_dpm_force_performance_level, S_IRUGO | S_IWUSR, |
| 993 | amdgpu_get_dpm_forced_performance_level, |
| 994 | amdgpu_set_dpm_forced_performance_level); |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 995 | static DEVICE_ATTR(pp_num_states, S_IRUGO, amdgpu_get_pp_num_states, NULL); |
| 996 | static DEVICE_ATTR(pp_cur_state, S_IRUGO, amdgpu_get_pp_cur_state, NULL); |
| 997 | static DEVICE_ATTR(pp_force_state, S_IRUGO | S_IWUSR, |
| 998 | amdgpu_get_pp_force_state, |
| 999 | amdgpu_set_pp_force_state); |
| 1000 | static DEVICE_ATTR(pp_table, S_IRUGO | S_IWUSR, |
| 1001 | amdgpu_get_pp_table, |
| 1002 | amdgpu_set_pp_table); |
| 1003 | static DEVICE_ATTR(pp_dpm_sclk, S_IRUGO | S_IWUSR, |
| 1004 | amdgpu_get_pp_dpm_sclk, |
| 1005 | amdgpu_set_pp_dpm_sclk); |
| 1006 | static DEVICE_ATTR(pp_dpm_mclk, S_IRUGO | S_IWUSR, |
| 1007 | amdgpu_get_pp_dpm_mclk, |
| 1008 | amdgpu_set_pp_dpm_mclk); |
| 1009 | static DEVICE_ATTR(pp_dpm_pcie, S_IRUGO | S_IWUSR, |
| 1010 | amdgpu_get_pp_dpm_pcie, |
| 1011 | amdgpu_set_pp_dpm_pcie); |
Eric Huang | 428bafa | 2016-05-12 14:51:21 -0400 | [diff] [blame] | 1012 | static DEVICE_ATTR(pp_sclk_od, S_IRUGO | S_IWUSR, |
| 1013 | amdgpu_get_pp_sclk_od, |
| 1014 | amdgpu_set_pp_sclk_od); |
Eric Huang | f2bdc05 | 2016-05-24 15:11:17 -0400 | [diff] [blame] | 1015 | static DEVICE_ATTR(pp_mclk_od, S_IRUGO | S_IWUSR, |
| 1016 | amdgpu_get_pp_mclk_od, |
| 1017 | amdgpu_set_pp_mclk_od); |
Rex Zhu | 37c5c4d | 2018-01-10 18:42:36 +0800 | [diff] [blame] | 1018 | static DEVICE_ATTR(pp_power_profile_mode, S_IRUGO | S_IWUSR, |
| 1019 | amdgpu_get_pp_power_profile_mode, |
| 1020 | amdgpu_set_pp_power_profile_mode); |
Rex Zhu | e3933f2 | 2018-01-16 18:35:15 +0800 | [diff] [blame] | 1021 | static DEVICE_ATTR(pp_od_clk_voltage, S_IRUGO | S_IWUSR, |
| 1022 | amdgpu_get_pp_od_clk_voltage, |
| 1023 | amdgpu_set_pp_od_clk_voltage); |
Tom St Denis | b374d82 | 2018-06-20 07:55:39 -0400 | [diff] [blame] | 1024 | static DEVICE_ATTR(gpu_busy_percent, S_IRUGO, |
| 1025 | amdgpu_get_busy_percent, NULL); |
Rex Zhu | e3933f2 | 2018-01-16 18:35:15 +0800 | [diff] [blame] | 1026 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1027 | static ssize_t amdgpu_hwmon_show_temp(struct device *dev, |
| 1028 | struct device_attribute *attr, |
| 1029 | char *buf) |
| 1030 | { |
| 1031 | struct amdgpu_device *adev = dev_get_drvdata(dev); |
Alex Deucher | 0c67df4 | 2016-02-19 15:30:15 -0500 | [diff] [blame] | 1032 | struct drm_device *ddev = adev->ddev; |
Alex Deucher | 71c9b9a | 2018-01-24 17:27:54 -0500 | [diff] [blame] | 1033 | int r, temp, size = sizeof(temp); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1034 | |
Alex Deucher | 0c67df4 | 2016-02-19 15:30:15 -0500 | [diff] [blame] | 1035 | /* Can't get temperature when the card is off */ |
| 1036 | if ((adev->flags & AMD_IS_PX) && |
| 1037 | (ddev->switch_power_state != DRM_SWITCH_POWER_ON)) |
| 1038 | return -EINVAL; |
| 1039 | |
Alex Deucher | 71c9b9a | 2018-01-24 17:27:54 -0500 | [diff] [blame] | 1040 | /* sanity check PP is enabled */ |
| 1041 | if (!(adev->powerplay.pp_funcs && |
| 1042 | adev->powerplay.pp_funcs->read_sensor)) |
| 1043 | return -EINVAL; |
| 1044 | |
| 1045 | /* get the temperature */ |
| 1046 | r = amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GPU_TEMP, |
| 1047 | (void *)&temp, &size); |
| 1048 | if (r) |
| 1049 | return r; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1050 | |
| 1051 | return snprintf(buf, PAGE_SIZE, "%d\n", temp); |
| 1052 | } |
| 1053 | |
| 1054 | static ssize_t amdgpu_hwmon_show_temp_thresh(struct device *dev, |
| 1055 | struct device_attribute *attr, |
| 1056 | char *buf) |
| 1057 | { |
| 1058 | struct amdgpu_device *adev = dev_get_drvdata(dev); |
| 1059 | int hyst = to_sensor_dev_attr(attr)->index; |
| 1060 | int temp; |
| 1061 | |
| 1062 | if (hyst) |
| 1063 | temp = adev->pm.dpm.thermal.min_temp; |
| 1064 | else |
| 1065 | temp = adev->pm.dpm.thermal.max_temp; |
| 1066 | |
| 1067 | return snprintf(buf, PAGE_SIZE, "%d\n", temp); |
| 1068 | } |
| 1069 | |
| 1070 | static ssize_t amdgpu_hwmon_get_pwm1_enable(struct device *dev, |
| 1071 | struct device_attribute *attr, |
| 1072 | char *buf) |
| 1073 | { |
| 1074 | struct amdgpu_device *adev = dev_get_drvdata(dev); |
| 1075 | u32 pwm_mode = 0; |
| 1076 | |
Rex Zhu | cd4d746 | 2017-09-06 18:43:52 +0800 | [diff] [blame] | 1077 | if (!adev->powerplay.pp_funcs->get_fan_control_mode) |
Rex Zhu | 8804b8d | 2015-11-10 18:29:11 -0500 | [diff] [blame] | 1078 | return -EINVAL; |
| 1079 | |
| 1080 | pwm_mode = amdgpu_dpm_get_fan_control_mode(adev); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1081 | |
Rex Zhu | aad22ca | 2017-05-05 16:56:45 +0800 | [diff] [blame] | 1082 | return sprintf(buf, "%i\n", pwm_mode); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1083 | } |
| 1084 | |
| 1085 | static ssize_t amdgpu_hwmon_set_pwm1_enable(struct device *dev, |
| 1086 | struct device_attribute *attr, |
| 1087 | const char *buf, |
| 1088 | size_t count) |
| 1089 | { |
| 1090 | struct amdgpu_device *adev = dev_get_drvdata(dev); |
| 1091 | int err; |
| 1092 | int value; |
| 1093 | |
Alex Deucher | 5ec36e2 | 2018-01-24 16:41:50 -0500 | [diff] [blame] | 1094 | /* Can't adjust fan when the card is off */ |
| 1095 | if ((adev->flags & AMD_IS_PX) && |
| 1096 | (adev->ddev->switch_power_state != DRM_SWITCH_POWER_ON)) |
| 1097 | return -EINVAL; |
| 1098 | |
Rex Zhu | cd4d746 | 2017-09-06 18:43:52 +0800 | [diff] [blame] | 1099 | if (!adev->powerplay.pp_funcs->set_fan_control_mode) |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1100 | return -EINVAL; |
| 1101 | |
| 1102 | err = kstrtoint(buf, 10, &value); |
| 1103 | if (err) |
| 1104 | return err; |
| 1105 | |
Rex Zhu | aad22ca | 2017-05-05 16:56:45 +0800 | [diff] [blame] | 1106 | amdgpu_dpm_set_fan_control_mode(adev, value); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1107 | |
| 1108 | return count; |
| 1109 | } |
| 1110 | |
| 1111 | static ssize_t amdgpu_hwmon_get_pwm1_min(struct device *dev, |
| 1112 | struct device_attribute *attr, |
| 1113 | char *buf) |
| 1114 | { |
| 1115 | return sprintf(buf, "%i\n", 0); |
| 1116 | } |
| 1117 | |
| 1118 | static ssize_t amdgpu_hwmon_get_pwm1_max(struct device *dev, |
| 1119 | struct device_attribute *attr, |
| 1120 | char *buf) |
| 1121 | { |
| 1122 | return sprintf(buf, "%i\n", 255); |
| 1123 | } |
| 1124 | |
| 1125 | static ssize_t amdgpu_hwmon_set_pwm1(struct device *dev, |
| 1126 | struct device_attribute *attr, |
| 1127 | const char *buf, size_t count) |
| 1128 | { |
| 1129 | struct amdgpu_device *adev = dev_get_drvdata(dev); |
| 1130 | int err; |
| 1131 | u32 value; |
Rex Zhu | b8a9c00 | 2018-09-28 16:01:48 +0800 | [diff] [blame] | 1132 | u32 pwm_mode; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1133 | |
Alex Deucher | 5ec36e2 | 2018-01-24 16:41:50 -0500 | [diff] [blame] | 1134 | /* Can't adjust fan when the card is off */ |
| 1135 | if ((adev->flags & AMD_IS_PX) && |
| 1136 | (adev->ddev->switch_power_state != DRM_SWITCH_POWER_ON)) |
| 1137 | return -EINVAL; |
| 1138 | |
Rex Zhu | b8a9c00 | 2018-09-28 16:01:48 +0800 | [diff] [blame] | 1139 | pwm_mode = amdgpu_dpm_get_fan_control_mode(adev); |
| 1140 | if (pwm_mode != AMD_FAN_CTRL_MANUAL) { |
| 1141 | pr_info("manual fan speed control should be enabled first\n"); |
| 1142 | return -EINVAL; |
| 1143 | } |
| 1144 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1145 | err = kstrtou32(buf, 10, &value); |
| 1146 | if (err) |
| 1147 | return err; |
| 1148 | |
| 1149 | value = (value * 100) / 255; |
| 1150 | |
Rex Zhu | cd4d746 | 2017-09-06 18:43:52 +0800 | [diff] [blame] | 1151 | if (adev->powerplay.pp_funcs->set_fan_speed_percent) { |
| 1152 | err = amdgpu_dpm_set_fan_speed_percent(adev, value); |
| 1153 | if (err) |
| 1154 | return err; |
| 1155 | } |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1156 | |
| 1157 | return count; |
| 1158 | } |
| 1159 | |
| 1160 | static ssize_t amdgpu_hwmon_get_pwm1(struct device *dev, |
| 1161 | struct device_attribute *attr, |
| 1162 | char *buf) |
| 1163 | { |
| 1164 | struct amdgpu_device *adev = dev_get_drvdata(dev); |
| 1165 | int err; |
Rex Zhu | cd4d746 | 2017-09-06 18:43:52 +0800 | [diff] [blame] | 1166 | u32 speed = 0; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1167 | |
Alex Deucher | 5ec36e2 | 2018-01-24 16:41:50 -0500 | [diff] [blame] | 1168 | /* Can't adjust fan when the card is off */ |
| 1169 | if ((adev->flags & AMD_IS_PX) && |
| 1170 | (adev->ddev->switch_power_state != DRM_SWITCH_POWER_ON)) |
| 1171 | return -EINVAL; |
| 1172 | |
Rex Zhu | cd4d746 | 2017-09-06 18:43:52 +0800 | [diff] [blame] | 1173 | if (adev->powerplay.pp_funcs->get_fan_speed_percent) { |
| 1174 | err = amdgpu_dpm_get_fan_speed_percent(adev, &speed); |
| 1175 | if (err) |
| 1176 | return err; |
| 1177 | } |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1178 | |
| 1179 | speed = (speed * 255) / 100; |
| 1180 | |
| 1181 | return sprintf(buf, "%i\n", speed); |
| 1182 | } |
| 1183 | |
Grazvydas Ignotas | 81c1514 | 2016-10-29 23:28:59 +0300 | [diff] [blame] | 1184 | static ssize_t amdgpu_hwmon_get_fan1_input(struct device *dev, |
| 1185 | struct device_attribute *attr, |
| 1186 | char *buf) |
| 1187 | { |
| 1188 | struct amdgpu_device *adev = dev_get_drvdata(dev); |
| 1189 | int err; |
Rex Zhu | cd4d746 | 2017-09-06 18:43:52 +0800 | [diff] [blame] | 1190 | u32 speed = 0; |
Grazvydas Ignotas | 81c1514 | 2016-10-29 23:28:59 +0300 | [diff] [blame] | 1191 | |
Alex Deucher | 5ec36e2 | 2018-01-24 16:41:50 -0500 | [diff] [blame] | 1192 | /* Can't adjust fan when the card is off */ |
| 1193 | if ((adev->flags & AMD_IS_PX) && |
| 1194 | (adev->ddev->switch_power_state != DRM_SWITCH_POWER_ON)) |
| 1195 | return -EINVAL; |
| 1196 | |
Rex Zhu | cd4d746 | 2017-09-06 18:43:52 +0800 | [diff] [blame] | 1197 | if (adev->powerplay.pp_funcs->get_fan_speed_rpm) { |
| 1198 | err = amdgpu_dpm_get_fan_speed_rpm(adev, &speed); |
| 1199 | if (err) |
| 1200 | return err; |
| 1201 | } |
Grazvydas Ignotas | 81c1514 | 2016-10-29 23:28:59 +0300 | [diff] [blame] | 1202 | |
| 1203 | return sprintf(buf, "%i\n", speed); |
| 1204 | } |
| 1205 | |
Rex Zhu | c287052 | 2018-09-20 14:30:55 +0800 | [diff] [blame] | 1206 | static ssize_t amdgpu_hwmon_get_fan1_min(struct device *dev, |
| 1207 | struct device_attribute *attr, |
| 1208 | char *buf) |
| 1209 | { |
| 1210 | struct amdgpu_device *adev = dev_get_drvdata(dev); |
| 1211 | u32 min_rpm = 0; |
| 1212 | u32 size = sizeof(min_rpm); |
| 1213 | int r; |
| 1214 | |
| 1215 | if (!adev->powerplay.pp_funcs->read_sensor) |
| 1216 | return -EINVAL; |
| 1217 | |
| 1218 | r = amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_MIN_FAN_RPM, |
| 1219 | (void *)&min_rpm, &size); |
| 1220 | if (r) |
| 1221 | return r; |
| 1222 | |
| 1223 | return snprintf(buf, PAGE_SIZE, "%d\n", min_rpm); |
| 1224 | } |
| 1225 | |
| 1226 | static ssize_t amdgpu_hwmon_get_fan1_max(struct device *dev, |
| 1227 | struct device_attribute *attr, |
| 1228 | char *buf) |
| 1229 | { |
| 1230 | struct amdgpu_device *adev = dev_get_drvdata(dev); |
| 1231 | u32 max_rpm = 0; |
| 1232 | u32 size = sizeof(max_rpm); |
| 1233 | int r; |
| 1234 | |
| 1235 | if (!adev->powerplay.pp_funcs->read_sensor) |
| 1236 | return -EINVAL; |
| 1237 | |
| 1238 | r = amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_MAX_FAN_RPM, |
| 1239 | (void *)&max_rpm, &size); |
| 1240 | if (r) |
| 1241 | return r; |
| 1242 | |
| 1243 | return snprintf(buf, PAGE_SIZE, "%d\n", max_rpm); |
| 1244 | } |
| 1245 | |
| 1246 | static ssize_t amdgpu_hwmon_get_fan1_target(struct device *dev, |
| 1247 | struct device_attribute *attr, |
| 1248 | char *buf) |
| 1249 | { |
| 1250 | struct amdgpu_device *adev = dev_get_drvdata(dev); |
| 1251 | int err; |
| 1252 | u32 rpm = 0; |
Rex Zhu | c287052 | 2018-09-20 14:30:55 +0800 | [diff] [blame] | 1253 | |
| 1254 | /* Can't adjust fan when the card is off */ |
| 1255 | if ((adev->flags & AMD_IS_PX) && |
| 1256 | (adev->ddev->switch_power_state != DRM_SWITCH_POWER_ON)) |
| 1257 | return -EINVAL; |
| 1258 | |
| 1259 | if (adev->powerplay.pp_funcs->get_fan_speed_rpm) { |
| 1260 | err = amdgpu_dpm_get_fan_speed_rpm(adev, &rpm); |
| 1261 | if (err) |
| 1262 | return err; |
| 1263 | } |
| 1264 | |
| 1265 | return sprintf(buf, "%i\n", rpm); |
| 1266 | } |
| 1267 | |
| 1268 | static ssize_t amdgpu_hwmon_set_fan1_target(struct device *dev, |
| 1269 | struct device_attribute *attr, |
| 1270 | const char *buf, size_t count) |
| 1271 | { |
| 1272 | struct amdgpu_device *adev = dev_get_drvdata(dev); |
| 1273 | int err; |
| 1274 | u32 value; |
| 1275 | u32 pwm_mode; |
| 1276 | |
| 1277 | pwm_mode = amdgpu_dpm_get_fan_control_mode(adev); |
| 1278 | if (pwm_mode != AMD_FAN_CTRL_MANUAL) |
| 1279 | return -ENODATA; |
| 1280 | |
| 1281 | /* Can't adjust fan when the card is off */ |
| 1282 | if ((adev->flags & AMD_IS_PX) && |
| 1283 | (adev->ddev->switch_power_state != DRM_SWITCH_POWER_ON)) |
| 1284 | return -EINVAL; |
| 1285 | |
| 1286 | err = kstrtou32(buf, 10, &value); |
| 1287 | if (err) |
| 1288 | return err; |
| 1289 | |
| 1290 | if (adev->powerplay.pp_funcs->set_fan_speed_rpm) { |
| 1291 | err = amdgpu_dpm_set_fan_speed_rpm(adev, value); |
| 1292 | if (err) |
| 1293 | return err; |
| 1294 | } |
| 1295 | |
| 1296 | return count; |
| 1297 | } |
| 1298 | |
| 1299 | static ssize_t amdgpu_hwmon_get_fan1_enable(struct device *dev, |
| 1300 | struct device_attribute *attr, |
| 1301 | char *buf) |
| 1302 | { |
| 1303 | struct amdgpu_device *adev = dev_get_drvdata(dev); |
| 1304 | u32 pwm_mode = 0; |
| 1305 | |
| 1306 | if (!adev->powerplay.pp_funcs->get_fan_control_mode) |
| 1307 | return -EINVAL; |
| 1308 | |
| 1309 | pwm_mode = amdgpu_dpm_get_fan_control_mode(adev); |
| 1310 | |
| 1311 | return sprintf(buf, "%i\n", pwm_mode == AMD_FAN_CTRL_AUTO ? 0 : 1); |
| 1312 | } |
| 1313 | |
| 1314 | static ssize_t amdgpu_hwmon_set_fan1_enable(struct device *dev, |
| 1315 | struct device_attribute *attr, |
| 1316 | const char *buf, |
| 1317 | size_t count) |
| 1318 | { |
| 1319 | struct amdgpu_device *adev = dev_get_drvdata(dev); |
| 1320 | int err; |
| 1321 | int value; |
| 1322 | u32 pwm_mode; |
| 1323 | |
| 1324 | /* Can't adjust fan when the card is off */ |
| 1325 | if ((adev->flags & AMD_IS_PX) && |
| 1326 | (adev->ddev->switch_power_state != DRM_SWITCH_POWER_ON)) |
| 1327 | return -EINVAL; |
| 1328 | |
| 1329 | if (!adev->powerplay.pp_funcs->set_fan_control_mode) |
| 1330 | return -EINVAL; |
| 1331 | |
| 1332 | err = kstrtoint(buf, 10, &value); |
| 1333 | if (err) |
| 1334 | return err; |
| 1335 | |
| 1336 | if (value == 0) |
| 1337 | pwm_mode = AMD_FAN_CTRL_AUTO; |
| 1338 | else if (value == 1) |
| 1339 | pwm_mode = AMD_FAN_CTRL_MANUAL; |
| 1340 | else |
| 1341 | return -EINVAL; |
| 1342 | |
| 1343 | amdgpu_dpm_set_fan_control_mode(adev, pwm_mode); |
| 1344 | |
| 1345 | return count; |
| 1346 | } |
| 1347 | |
Alex Deucher | 2bd376b | 2018-01-24 17:19:33 -0500 | [diff] [blame] | 1348 | static ssize_t amdgpu_hwmon_show_vddgfx(struct device *dev, |
| 1349 | struct device_attribute *attr, |
| 1350 | char *buf) |
| 1351 | { |
| 1352 | struct amdgpu_device *adev = dev_get_drvdata(dev); |
| 1353 | struct drm_device *ddev = adev->ddev; |
| 1354 | u32 vddgfx; |
| 1355 | int r, size = sizeof(vddgfx); |
| 1356 | |
| 1357 | /* Can't get voltage when the card is off */ |
| 1358 | if ((adev->flags & AMD_IS_PX) && |
| 1359 | (ddev->switch_power_state != DRM_SWITCH_POWER_ON)) |
| 1360 | return -EINVAL; |
| 1361 | |
| 1362 | /* sanity check PP is enabled */ |
| 1363 | if (!(adev->powerplay.pp_funcs && |
| 1364 | adev->powerplay.pp_funcs->read_sensor)) |
| 1365 | return -EINVAL; |
| 1366 | |
| 1367 | /* get the voltage */ |
| 1368 | r = amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_VDDGFX, |
| 1369 | (void *)&vddgfx, &size); |
| 1370 | if (r) |
| 1371 | return r; |
| 1372 | |
| 1373 | return snprintf(buf, PAGE_SIZE, "%d\n", vddgfx); |
| 1374 | } |
| 1375 | |
| 1376 | static ssize_t amdgpu_hwmon_show_vddgfx_label(struct device *dev, |
| 1377 | struct device_attribute *attr, |
| 1378 | char *buf) |
| 1379 | { |
| 1380 | return snprintf(buf, PAGE_SIZE, "vddgfx\n"); |
| 1381 | } |
| 1382 | |
| 1383 | static ssize_t amdgpu_hwmon_show_vddnb(struct device *dev, |
| 1384 | struct device_attribute *attr, |
| 1385 | char *buf) |
| 1386 | { |
| 1387 | struct amdgpu_device *adev = dev_get_drvdata(dev); |
| 1388 | struct drm_device *ddev = adev->ddev; |
| 1389 | u32 vddnb; |
| 1390 | int r, size = sizeof(vddnb); |
| 1391 | |
| 1392 | /* only APUs have vddnb */ |
Rex Zhu | ccf9ef0 | 2018-07-25 11:51:46 +0800 | [diff] [blame] | 1393 | if (!(adev->flags & AMD_IS_APU)) |
Alex Deucher | 2bd376b | 2018-01-24 17:19:33 -0500 | [diff] [blame] | 1394 | return -EINVAL; |
| 1395 | |
| 1396 | /* Can't get voltage when the card is off */ |
| 1397 | if ((adev->flags & AMD_IS_PX) && |
| 1398 | (ddev->switch_power_state != DRM_SWITCH_POWER_ON)) |
| 1399 | return -EINVAL; |
| 1400 | |
| 1401 | /* sanity check PP is enabled */ |
| 1402 | if (!(adev->powerplay.pp_funcs && |
| 1403 | adev->powerplay.pp_funcs->read_sensor)) |
| 1404 | return -EINVAL; |
| 1405 | |
| 1406 | /* get the voltage */ |
| 1407 | r = amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_VDDNB, |
| 1408 | (void *)&vddnb, &size); |
| 1409 | if (r) |
| 1410 | return r; |
| 1411 | |
| 1412 | return snprintf(buf, PAGE_SIZE, "%d\n", vddnb); |
| 1413 | } |
| 1414 | |
| 1415 | static ssize_t amdgpu_hwmon_show_vddnb_label(struct device *dev, |
| 1416 | struct device_attribute *attr, |
| 1417 | char *buf) |
| 1418 | { |
| 1419 | return snprintf(buf, PAGE_SIZE, "vddnb\n"); |
| 1420 | } |
| 1421 | |
Alex Deucher | 2976fc2 | 2018-01-24 18:34:26 -0500 | [diff] [blame] | 1422 | static ssize_t amdgpu_hwmon_show_power_avg(struct device *dev, |
| 1423 | struct device_attribute *attr, |
| 1424 | char *buf) |
| 1425 | { |
| 1426 | struct amdgpu_device *adev = dev_get_drvdata(dev); |
| 1427 | struct drm_device *ddev = adev->ddev; |
Rex Zhu | 5b79d04 | 2018-04-04 15:37:35 +0800 | [diff] [blame] | 1428 | u32 query = 0; |
| 1429 | int r, size = sizeof(u32); |
Alex Deucher | 2976fc2 | 2018-01-24 18:34:26 -0500 | [diff] [blame] | 1430 | unsigned uw; |
| 1431 | |
| 1432 | /* Can't get power when the card is off */ |
| 1433 | if ((adev->flags & AMD_IS_PX) && |
| 1434 | (ddev->switch_power_state != DRM_SWITCH_POWER_ON)) |
| 1435 | return -EINVAL; |
| 1436 | |
| 1437 | /* sanity check PP is enabled */ |
| 1438 | if (!(adev->powerplay.pp_funcs && |
| 1439 | adev->powerplay.pp_funcs->read_sensor)) |
| 1440 | return -EINVAL; |
| 1441 | |
| 1442 | /* get the voltage */ |
| 1443 | r = amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GPU_POWER, |
| 1444 | (void *)&query, &size); |
| 1445 | if (r) |
| 1446 | return r; |
| 1447 | |
| 1448 | /* convert to microwatts */ |
Rex Zhu | 5b79d04 | 2018-04-04 15:37:35 +0800 | [diff] [blame] | 1449 | uw = (query >> 8) * 1000000 + (query & 0xff) * 1000; |
Alex Deucher | 2976fc2 | 2018-01-24 18:34:26 -0500 | [diff] [blame] | 1450 | |
| 1451 | return snprintf(buf, PAGE_SIZE, "%u\n", uw); |
| 1452 | } |
| 1453 | |
Rex Zhu | 8d81bce | 2018-01-29 18:07:01 +0800 | [diff] [blame] | 1454 | static ssize_t amdgpu_hwmon_show_power_cap_min(struct device *dev, |
| 1455 | struct device_attribute *attr, |
| 1456 | char *buf) |
| 1457 | { |
| 1458 | return sprintf(buf, "%i\n", 0); |
| 1459 | } |
| 1460 | |
| 1461 | static ssize_t amdgpu_hwmon_show_power_cap_max(struct device *dev, |
| 1462 | struct device_attribute *attr, |
| 1463 | char *buf) |
| 1464 | { |
| 1465 | struct amdgpu_device *adev = dev_get_drvdata(dev); |
| 1466 | uint32_t limit = 0; |
| 1467 | |
| 1468 | if (adev->powerplay.pp_funcs && adev->powerplay.pp_funcs->get_power_limit) { |
| 1469 | adev->powerplay.pp_funcs->get_power_limit(adev->powerplay.pp_handle, &limit, true); |
| 1470 | return snprintf(buf, PAGE_SIZE, "%u\n", limit * 1000000); |
| 1471 | } else { |
| 1472 | return snprintf(buf, PAGE_SIZE, "\n"); |
| 1473 | } |
| 1474 | } |
| 1475 | |
| 1476 | static ssize_t amdgpu_hwmon_show_power_cap(struct device *dev, |
| 1477 | struct device_attribute *attr, |
| 1478 | char *buf) |
| 1479 | { |
| 1480 | struct amdgpu_device *adev = dev_get_drvdata(dev); |
| 1481 | uint32_t limit = 0; |
| 1482 | |
| 1483 | if (adev->powerplay.pp_funcs && adev->powerplay.pp_funcs->get_power_limit) { |
| 1484 | adev->powerplay.pp_funcs->get_power_limit(adev->powerplay.pp_handle, &limit, false); |
| 1485 | return snprintf(buf, PAGE_SIZE, "%u\n", limit * 1000000); |
| 1486 | } else { |
| 1487 | return snprintf(buf, PAGE_SIZE, "\n"); |
| 1488 | } |
| 1489 | } |
| 1490 | |
| 1491 | |
| 1492 | static ssize_t amdgpu_hwmon_set_power_cap(struct device *dev, |
| 1493 | struct device_attribute *attr, |
| 1494 | const char *buf, |
| 1495 | size_t count) |
| 1496 | { |
| 1497 | struct amdgpu_device *adev = dev_get_drvdata(dev); |
| 1498 | int err; |
| 1499 | u32 value; |
| 1500 | |
| 1501 | err = kstrtou32(buf, 10, &value); |
| 1502 | if (err) |
| 1503 | return err; |
| 1504 | |
| 1505 | value = value / 1000000; /* convert to Watt */ |
| 1506 | if (adev->powerplay.pp_funcs && adev->powerplay.pp_funcs->set_power_limit) { |
| 1507 | err = adev->powerplay.pp_funcs->set_power_limit(adev->powerplay.pp_handle, value); |
| 1508 | if (err) |
| 1509 | return err; |
| 1510 | } else { |
| 1511 | return -EINVAL; |
| 1512 | } |
| 1513 | |
| 1514 | return count; |
| 1515 | } |
| 1516 | |
Alex Deucher | 844c541 | 2018-03-26 12:56:56 -0500 | [diff] [blame] | 1517 | |
| 1518 | /** |
| 1519 | * DOC: hwmon |
| 1520 | * |
| 1521 | * The amdgpu driver exposes the following sensor interfaces: |
Alex Deucher | dc85db2 | 2018-06-01 12:28:14 -0500 | [diff] [blame] | 1522 | * |
Alex Deucher | 844c541 | 2018-03-26 12:56:56 -0500 | [diff] [blame] | 1523 | * - GPU temperature (via the on-die sensor) |
Alex Deucher | dc85db2 | 2018-06-01 12:28:14 -0500 | [diff] [blame] | 1524 | * |
Alex Deucher | 844c541 | 2018-03-26 12:56:56 -0500 | [diff] [blame] | 1525 | * - GPU voltage |
Alex Deucher | dc85db2 | 2018-06-01 12:28:14 -0500 | [diff] [blame] | 1526 | * |
Alex Deucher | 844c541 | 2018-03-26 12:56:56 -0500 | [diff] [blame] | 1527 | * - Northbridge voltage (APUs only) |
Alex Deucher | dc85db2 | 2018-06-01 12:28:14 -0500 | [diff] [blame] | 1528 | * |
Alex Deucher | 844c541 | 2018-03-26 12:56:56 -0500 | [diff] [blame] | 1529 | * - GPU power |
Alex Deucher | dc85db2 | 2018-06-01 12:28:14 -0500 | [diff] [blame] | 1530 | * |
Alex Deucher | 844c541 | 2018-03-26 12:56:56 -0500 | [diff] [blame] | 1531 | * - GPU fan |
| 1532 | * |
| 1533 | * hwmon interfaces for GPU temperature: |
Alex Deucher | dc85db2 | 2018-06-01 12:28:14 -0500 | [diff] [blame] | 1534 | * |
Alex Deucher | 844c541 | 2018-03-26 12:56:56 -0500 | [diff] [blame] | 1535 | * - temp1_input: the on die GPU temperature in millidegrees Celsius |
Alex Deucher | dc85db2 | 2018-06-01 12:28:14 -0500 | [diff] [blame] | 1536 | * |
Alex Deucher | 844c541 | 2018-03-26 12:56:56 -0500 | [diff] [blame] | 1537 | * - temp1_crit: temperature critical max value in millidegrees Celsius |
Alex Deucher | dc85db2 | 2018-06-01 12:28:14 -0500 | [diff] [blame] | 1538 | * |
Alex Deucher | 844c541 | 2018-03-26 12:56:56 -0500 | [diff] [blame] | 1539 | * - temp1_crit_hyst: temperature hysteresis for critical limit in millidegrees Celsius |
| 1540 | * |
| 1541 | * hwmon interfaces for GPU voltage: |
Alex Deucher | dc85db2 | 2018-06-01 12:28:14 -0500 | [diff] [blame] | 1542 | * |
Alex Deucher | 844c541 | 2018-03-26 12:56:56 -0500 | [diff] [blame] | 1543 | * - in0_input: the voltage on the GPU in millivolts |
Alex Deucher | dc85db2 | 2018-06-01 12:28:14 -0500 | [diff] [blame] | 1544 | * |
Alex Deucher | 844c541 | 2018-03-26 12:56:56 -0500 | [diff] [blame] | 1545 | * - in1_input: the voltage on the Northbridge in millivolts |
| 1546 | * |
| 1547 | * hwmon interfaces for GPU power: |
Alex Deucher | dc85db2 | 2018-06-01 12:28:14 -0500 | [diff] [blame] | 1548 | * |
Alex Deucher | 844c541 | 2018-03-26 12:56:56 -0500 | [diff] [blame] | 1549 | * - power1_average: average power used by the GPU in microWatts |
Alex Deucher | dc85db2 | 2018-06-01 12:28:14 -0500 | [diff] [blame] | 1550 | * |
Alex Deucher | 844c541 | 2018-03-26 12:56:56 -0500 | [diff] [blame] | 1551 | * - power1_cap_min: minimum cap supported in microWatts |
Alex Deucher | dc85db2 | 2018-06-01 12:28:14 -0500 | [diff] [blame] | 1552 | * |
Alex Deucher | 844c541 | 2018-03-26 12:56:56 -0500 | [diff] [blame] | 1553 | * - power1_cap_max: maximum cap supported in microWatts |
Alex Deucher | dc85db2 | 2018-06-01 12:28:14 -0500 | [diff] [blame] | 1554 | * |
Alex Deucher | 844c541 | 2018-03-26 12:56:56 -0500 | [diff] [blame] | 1555 | * - power1_cap: selected power cap in microWatts |
| 1556 | * |
| 1557 | * hwmon interfaces for GPU fan: |
Alex Deucher | dc85db2 | 2018-06-01 12:28:14 -0500 | [diff] [blame] | 1558 | * |
Alex Deucher | 844c541 | 2018-03-26 12:56:56 -0500 | [diff] [blame] | 1559 | * - pwm1: pulse width modulation fan level (0-255) |
Alex Deucher | dc85db2 | 2018-06-01 12:28:14 -0500 | [diff] [blame] | 1560 | * |
| 1561 | * - 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) |
| 1562 | * |
Alex Deucher | 844c541 | 2018-03-26 12:56:56 -0500 | [diff] [blame] | 1563 | * - pwm1_min: pulse width modulation fan control minimum level (0) |
Alex Deucher | dc85db2 | 2018-06-01 12:28:14 -0500 | [diff] [blame] | 1564 | * |
Alex Deucher | 844c541 | 2018-03-26 12:56:56 -0500 | [diff] [blame] | 1565 | * - pwm1_max: pulse width modulation fan control maximum level (255) |
Alex Deucher | dc85db2 | 2018-06-01 12:28:14 -0500 | [diff] [blame] | 1566 | * |
Rex Zhu | c287052 | 2018-09-20 14:30:55 +0800 | [diff] [blame] | 1567 | * - fan1_min: an minimum value Unit: revolution/min (RPM) |
| 1568 | * |
| 1569 | * - fan1_max: an maxmum value Unit: revolution/max (RPM) |
| 1570 | * |
Alex Deucher | 844c541 | 2018-03-26 12:56:56 -0500 | [diff] [blame] | 1571 | * - fan1_input: fan speed in RPM |
| 1572 | * |
Rex Zhu | c287052 | 2018-09-20 14:30:55 +0800 | [diff] [blame] | 1573 | * - fan[1-*]_target: Desired fan speed Unit: revolution/min (RPM) |
| 1574 | * |
| 1575 | * - fan[1-*]_enable: Enable or disable the sensors.1: Enable 0: Disable |
| 1576 | * |
Alex Deucher | 844c541 | 2018-03-26 12:56:56 -0500 | [diff] [blame] | 1577 | * You can use hwmon tools like sensors to view this information on your system. |
| 1578 | * |
| 1579 | */ |
| 1580 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1581 | static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, amdgpu_hwmon_show_temp, NULL, 0); |
| 1582 | static SENSOR_DEVICE_ATTR(temp1_crit, S_IRUGO, amdgpu_hwmon_show_temp_thresh, NULL, 0); |
| 1583 | static SENSOR_DEVICE_ATTR(temp1_crit_hyst, S_IRUGO, amdgpu_hwmon_show_temp_thresh, NULL, 1); |
| 1584 | static SENSOR_DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, amdgpu_hwmon_get_pwm1, amdgpu_hwmon_set_pwm1, 0); |
| 1585 | static SENSOR_DEVICE_ATTR(pwm1_enable, S_IRUGO | S_IWUSR, amdgpu_hwmon_get_pwm1_enable, amdgpu_hwmon_set_pwm1_enable, 0); |
| 1586 | static SENSOR_DEVICE_ATTR(pwm1_min, S_IRUGO, amdgpu_hwmon_get_pwm1_min, NULL, 0); |
| 1587 | static SENSOR_DEVICE_ATTR(pwm1_max, S_IRUGO, amdgpu_hwmon_get_pwm1_max, NULL, 0); |
Grazvydas Ignotas | 81c1514 | 2016-10-29 23:28:59 +0300 | [diff] [blame] | 1588 | static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, amdgpu_hwmon_get_fan1_input, NULL, 0); |
Rex Zhu | c287052 | 2018-09-20 14:30:55 +0800 | [diff] [blame] | 1589 | static SENSOR_DEVICE_ATTR(fan1_min, S_IRUGO, amdgpu_hwmon_get_fan1_min, NULL, 0); |
| 1590 | static SENSOR_DEVICE_ATTR(fan1_max, S_IRUGO, amdgpu_hwmon_get_fan1_max, NULL, 0); |
| 1591 | static SENSOR_DEVICE_ATTR(fan1_target, S_IRUGO | S_IWUSR, amdgpu_hwmon_get_fan1_target, amdgpu_hwmon_set_fan1_target, 0); |
| 1592 | static SENSOR_DEVICE_ATTR(fan1_enable, S_IRUGO | S_IWUSR, amdgpu_hwmon_get_fan1_enable, amdgpu_hwmon_set_fan1_enable, 0); |
Alex Deucher | 2bd376b | 2018-01-24 17:19:33 -0500 | [diff] [blame] | 1593 | static SENSOR_DEVICE_ATTR(in0_input, S_IRUGO, amdgpu_hwmon_show_vddgfx, NULL, 0); |
| 1594 | static SENSOR_DEVICE_ATTR(in0_label, S_IRUGO, amdgpu_hwmon_show_vddgfx_label, NULL, 0); |
| 1595 | static SENSOR_DEVICE_ATTR(in1_input, S_IRUGO, amdgpu_hwmon_show_vddnb, NULL, 0); |
| 1596 | static SENSOR_DEVICE_ATTR(in1_label, S_IRUGO, amdgpu_hwmon_show_vddnb_label, NULL, 0); |
Alex Deucher | 2976fc2 | 2018-01-24 18:34:26 -0500 | [diff] [blame] | 1597 | static SENSOR_DEVICE_ATTR(power1_average, S_IRUGO, amdgpu_hwmon_show_power_avg, NULL, 0); |
Rex Zhu | 8d81bce | 2018-01-29 18:07:01 +0800 | [diff] [blame] | 1598 | static SENSOR_DEVICE_ATTR(power1_cap_max, S_IRUGO, amdgpu_hwmon_show_power_cap_max, NULL, 0); |
| 1599 | static SENSOR_DEVICE_ATTR(power1_cap_min, S_IRUGO, amdgpu_hwmon_show_power_cap_min, NULL, 0); |
| 1600 | static SENSOR_DEVICE_ATTR(power1_cap, S_IRUGO | S_IWUSR, amdgpu_hwmon_show_power_cap, amdgpu_hwmon_set_power_cap, 0); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1601 | |
| 1602 | static struct attribute *hwmon_attributes[] = { |
| 1603 | &sensor_dev_attr_temp1_input.dev_attr.attr, |
| 1604 | &sensor_dev_attr_temp1_crit.dev_attr.attr, |
| 1605 | &sensor_dev_attr_temp1_crit_hyst.dev_attr.attr, |
| 1606 | &sensor_dev_attr_pwm1.dev_attr.attr, |
| 1607 | &sensor_dev_attr_pwm1_enable.dev_attr.attr, |
| 1608 | &sensor_dev_attr_pwm1_min.dev_attr.attr, |
| 1609 | &sensor_dev_attr_pwm1_max.dev_attr.attr, |
Grazvydas Ignotas | 81c1514 | 2016-10-29 23:28:59 +0300 | [diff] [blame] | 1610 | &sensor_dev_attr_fan1_input.dev_attr.attr, |
Rex Zhu | c287052 | 2018-09-20 14:30:55 +0800 | [diff] [blame] | 1611 | &sensor_dev_attr_fan1_min.dev_attr.attr, |
| 1612 | &sensor_dev_attr_fan1_max.dev_attr.attr, |
| 1613 | &sensor_dev_attr_fan1_target.dev_attr.attr, |
| 1614 | &sensor_dev_attr_fan1_enable.dev_attr.attr, |
Alex Deucher | 2bd376b | 2018-01-24 17:19:33 -0500 | [diff] [blame] | 1615 | &sensor_dev_attr_in0_input.dev_attr.attr, |
| 1616 | &sensor_dev_attr_in0_label.dev_attr.attr, |
| 1617 | &sensor_dev_attr_in1_input.dev_attr.attr, |
| 1618 | &sensor_dev_attr_in1_label.dev_attr.attr, |
Alex Deucher | 2976fc2 | 2018-01-24 18:34:26 -0500 | [diff] [blame] | 1619 | &sensor_dev_attr_power1_average.dev_attr.attr, |
Rex Zhu | 8d81bce | 2018-01-29 18:07:01 +0800 | [diff] [blame] | 1620 | &sensor_dev_attr_power1_cap_max.dev_attr.attr, |
| 1621 | &sensor_dev_attr_power1_cap_min.dev_attr.attr, |
| 1622 | &sensor_dev_attr_power1_cap.dev_attr.attr, |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1623 | NULL |
| 1624 | }; |
| 1625 | |
| 1626 | static umode_t hwmon_attributes_visible(struct kobject *kobj, |
| 1627 | struct attribute *attr, int index) |
| 1628 | { |
Geliang Tang | cc29ec8 | 2016-01-13 22:48:42 +0800 | [diff] [blame] | 1629 | struct device *dev = kobj_to_dev(kobj); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1630 | struct amdgpu_device *adev = dev_get_drvdata(dev); |
| 1631 | umode_t effective_mode = attr->mode; |
| 1632 | |
Rex Zhu | fc5a136 | 2018-04-27 13:46:08 +0800 | [diff] [blame] | 1633 | /* Skip fan attributes if fan is not present */ |
| 1634 | if (adev->pm.no_fan && (attr == &sensor_dev_attr_pwm1.dev_attr.attr || |
| 1635 | attr == &sensor_dev_attr_pwm1_enable.dev_attr.attr || |
| 1636 | attr == &sensor_dev_attr_pwm1_max.dev_attr.attr || |
| 1637 | attr == &sensor_dev_attr_pwm1_min.dev_attr.attr || |
Rex Zhu | c287052 | 2018-09-20 14:30:55 +0800 | [diff] [blame] | 1638 | attr == &sensor_dev_attr_fan1_input.dev_attr.attr || |
| 1639 | attr == &sensor_dev_attr_fan1_min.dev_attr.attr || |
| 1640 | attr == &sensor_dev_attr_fan1_max.dev_attr.attr || |
| 1641 | attr == &sensor_dev_attr_fan1_target.dev_attr.attr || |
| 1642 | attr == &sensor_dev_attr_fan1_enable.dev_attr.attr)) |
Rex Zhu | fc5a136 | 2018-04-27 13:46:08 +0800 | [diff] [blame] | 1643 | return 0; |
Alex Deucher | 135f971 | 2017-11-20 17:49:53 -0500 | [diff] [blame] | 1644 | |
Rex Zhu | 1b5708f | 2015-11-10 18:25:24 -0500 | [diff] [blame] | 1645 | /* Skip limit attributes if DPM is not enabled */ |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1646 | if (!adev->pm.dpm_enabled && |
| 1647 | (attr == &sensor_dev_attr_temp1_crit.dev_attr.attr || |
Alex Deucher | 2710073 | 2015-10-19 15:49:11 -0400 | [diff] [blame] | 1648 | attr == &sensor_dev_attr_temp1_crit_hyst.dev_attr.attr || |
| 1649 | attr == &sensor_dev_attr_pwm1.dev_attr.attr || |
| 1650 | attr == &sensor_dev_attr_pwm1_enable.dev_attr.attr || |
| 1651 | attr == &sensor_dev_attr_pwm1_max.dev_attr.attr || |
Rex Zhu | c287052 | 2018-09-20 14:30:55 +0800 | [diff] [blame] | 1652 | attr == &sensor_dev_attr_pwm1_min.dev_attr.attr || |
| 1653 | attr == &sensor_dev_attr_fan1_input.dev_attr.attr || |
| 1654 | attr == &sensor_dev_attr_fan1_min.dev_attr.attr || |
| 1655 | attr == &sensor_dev_attr_fan1_max.dev_attr.attr || |
| 1656 | attr == &sensor_dev_attr_fan1_target.dev_attr.attr || |
| 1657 | attr == &sensor_dev_attr_fan1_enable.dev_attr.attr)) |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1658 | return 0; |
| 1659 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1660 | /* mask fan attributes if we have no bindings for this asic to expose */ |
Rex Zhu | cd4d746 | 2017-09-06 18:43:52 +0800 | [diff] [blame] | 1661 | if ((!adev->powerplay.pp_funcs->get_fan_speed_percent && |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1662 | attr == &sensor_dev_attr_pwm1.dev_attr.attr) || /* can't query fan */ |
Rex Zhu | cd4d746 | 2017-09-06 18:43:52 +0800 | [diff] [blame] | 1663 | (!adev->powerplay.pp_funcs->get_fan_control_mode && |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1664 | attr == &sensor_dev_attr_pwm1_enable.dev_attr.attr)) /* can't query state */ |
| 1665 | effective_mode &= ~S_IRUGO; |
| 1666 | |
Rex Zhu | cd4d746 | 2017-09-06 18:43:52 +0800 | [diff] [blame] | 1667 | if ((!adev->powerplay.pp_funcs->set_fan_speed_percent && |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1668 | attr == &sensor_dev_attr_pwm1.dev_attr.attr) || /* can't manage fan */ |
Rex Zhu | cd4d746 | 2017-09-06 18:43:52 +0800 | [diff] [blame] | 1669 | (!adev->powerplay.pp_funcs->set_fan_control_mode && |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1670 | attr == &sensor_dev_attr_pwm1_enable.dev_attr.attr)) /* can't manage state */ |
| 1671 | effective_mode &= ~S_IWUSR; |
| 1672 | |
Rex Zhu | 8d81bce | 2018-01-29 18:07:01 +0800 | [diff] [blame] | 1673 | if ((adev->flags & AMD_IS_APU) && |
| 1674 | (attr == &sensor_dev_attr_power1_cap_max.dev_attr.attr || |
| 1675 | attr == &sensor_dev_attr_power1_cap_min.dev_attr.attr|| |
| 1676 | attr == &sensor_dev_attr_power1_cap.dev_attr.attr)) |
| 1677 | return 0; |
| 1678 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1679 | /* hide max/min values if we can't both query and manage the fan */ |
Rex Zhu | cd4d746 | 2017-09-06 18:43:52 +0800 | [diff] [blame] | 1680 | if ((!adev->powerplay.pp_funcs->set_fan_speed_percent && |
| 1681 | !adev->powerplay.pp_funcs->get_fan_speed_percent) && |
Rex Zhu | c287052 | 2018-09-20 14:30:55 +0800 | [diff] [blame] | 1682 | (!adev->powerplay.pp_funcs->set_fan_speed_rpm && |
| 1683 | !adev->powerplay.pp_funcs->get_fan_speed_rpm) && |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1684 | (attr == &sensor_dev_attr_pwm1_max.dev_attr.attr || |
| 1685 | attr == &sensor_dev_attr_pwm1_min.dev_attr.attr)) |
| 1686 | return 0; |
| 1687 | |
Rex Zhu | c287052 | 2018-09-20 14:30:55 +0800 | [diff] [blame] | 1688 | if ((!adev->powerplay.pp_funcs->set_fan_speed_rpm && |
| 1689 | !adev->powerplay.pp_funcs->get_fan_speed_rpm) && |
| 1690 | (attr == &sensor_dev_attr_fan1_max.dev_attr.attr || |
| 1691 | attr == &sensor_dev_attr_fan1_min.dev_attr.attr)) |
| 1692 | return 0; |
| 1693 | |
Alex Deucher | 0d35bc78 | 2018-01-24 17:57:19 -0500 | [diff] [blame] | 1694 | /* only APUs have vddnb */ |
| 1695 | if (!(adev->flags & AMD_IS_APU) && |
| 1696 | (attr == &sensor_dev_attr_in1_input.dev_attr.attr || |
| 1697 | attr == &sensor_dev_attr_in1_label.dev_attr.attr)) |
Grazvydas Ignotas | 81c1514 | 2016-10-29 23:28:59 +0300 | [diff] [blame] | 1698 | return 0; |
| 1699 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1700 | return effective_mode; |
| 1701 | } |
| 1702 | |
| 1703 | static const struct attribute_group hwmon_attrgroup = { |
| 1704 | .attrs = hwmon_attributes, |
| 1705 | .is_visible = hwmon_attributes_visible, |
| 1706 | }; |
| 1707 | |
| 1708 | static const struct attribute_group *hwmon_groups[] = { |
| 1709 | &hwmon_attrgroup, |
| 1710 | NULL |
| 1711 | }; |
| 1712 | |
| 1713 | void amdgpu_dpm_thermal_work_handler(struct work_struct *work) |
| 1714 | { |
| 1715 | struct amdgpu_device *adev = |
| 1716 | container_of(work, struct amdgpu_device, |
| 1717 | pm.dpm.thermal.work); |
| 1718 | /* switch to the thermal state */ |
Rex Zhu | 3a2c788 | 2015-08-25 15:57:43 +0800 | [diff] [blame] | 1719 | enum amd_pm_state_type dpm_state = POWER_STATE_TYPE_INTERNAL_THERMAL; |
Alex Deucher | 71c9b9a | 2018-01-24 17:27:54 -0500 | [diff] [blame] | 1720 | int temp, size = sizeof(temp); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1721 | |
| 1722 | if (!adev->pm.dpm_enabled) |
| 1723 | return; |
| 1724 | |
Alex Deucher | 71c9b9a | 2018-01-24 17:27:54 -0500 | [diff] [blame] | 1725 | if (adev->powerplay.pp_funcs && |
| 1726 | adev->powerplay.pp_funcs->read_sensor && |
| 1727 | !amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GPU_TEMP, |
| 1728 | (void *)&temp, &size)) { |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1729 | if (temp < adev->pm.dpm.thermal.min_temp) |
| 1730 | /* switch back the user state */ |
| 1731 | dpm_state = adev->pm.dpm.user_state; |
| 1732 | } else { |
| 1733 | if (adev->pm.dpm.thermal.high_to_low) |
| 1734 | /* switch back the user state */ |
| 1735 | dpm_state = adev->pm.dpm.user_state; |
| 1736 | } |
| 1737 | mutex_lock(&adev->pm.mutex); |
| 1738 | if (dpm_state == POWER_STATE_TYPE_INTERNAL_THERMAL) |
| 1739 | adev->pm.dpm.thermal_active = true; |
| 1740 | else |
| 1741 | adev->pm.dpm.thermal_active = false; |
| 1742 | adev->pm.dpm.state = dpm_state; |
| 1743 | mutex_unlock(&adev->pm.mutex); |
| 1744 | |
| 1745 | amdgpu_pm_compute_clocks(adev); |
| 1746 | } |
| 1747 | |
| 1748 | static struct amdgpu_ps *amdgpu_dpm_pick_power_state(struct amdgpu_device *adev, |
Rex Zhu | 3a2c788 | 2015-08-25 15:57:43 +0800 | [diff] [blame] | 1749 | enum amd_pm_state_type dpm_state) |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1750 | { |
| 1751 | int i; |
| 1752 | struct amdgpu_ps *ps; |
| 1753 | u32 ui_class; |
| 1754 | bool single_display = (adev->pm.dpm.new_active_crtc_count < 2) ? |
| 1755 | true : false; |
| 1756 | |
| 1757 | /* check if the vblank period is too short to adjust the mclk */ |
Rex Zhu | cd4d746 | 2017-09-06 18:43:52 +0800 | [diff] [blame] | 1758 | if (single_display && adev->powerplay.pp_funcs->vblank_too_short) { |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1759 | if (amdgpu_dpm_vblank_too_short(adev)) |
| 1760 | single_display = false; |
| 1761 | } |
| 1762 | |
| 1763 | /* certain older asics have a separare 3D performance state, |
| 1764 | * so try that first if the user selected performance |
| 1765 | */ |
| 1766 | if (dpm_state == POWER_STATE_TYPE_PERFORMANCE) |
| 1767 | dpm_state = POWER_STATE_TYPE_INTERNAL_3DPERF; |
| 1768 | /* balanced states don't exist at the moment */ |
| 1769 | if (dpm_state == POWER_STATE_TYPE_BALANCED) |
| 1770 | dpm_state = POWER_STATE_TYPE_PERFORMANCE; |
| 1771 | |
| 1772 | restart_search: |
| 1773 | /* Pick the best power state based on current conditions */ |
| 1774 | for (i = 0; i < adev->pm.dpm.num_ps; i++) { |
| 1775 | ps = &adev->pm.dpm.ps[i]; |
| 1776 | ui_class = ps->class & ATOM_PPLIB_CLASSIFICATION_UI_MASK; |
| 1777 | switch (dpm_state) { |
| 1778 | /* user states */ |
| 1779 | case POWER_STATE_TYPE_BATTERY: |
| 1780 | if (ui_class == ATOM_PPLIB_CLASSIFICATION_UI_BATTERY) { |
| 1781 | if (ps->caps & ATOM_PPLIB_SINGLE_DISPLAY_ONLY) { |
| 1782 | if (single_display) |
| 1783 | return ps; |
| 1784 | } else |
| 1785 | return ps; |
| 1786 | } |
| 1787 | break; |
| 1788 | case POWER_STATE_TYPE_BALANCED: |
| 1789 | if (ui_class == ATOM_PPLIB_CLASSIFICATION_UI_BALANCED) { |
| 1790 | if (ps->caps & ATOM_PPLIB_SINGLE_DISPLAY_ONLY) { |
| 1791 | if (single_display) |
| 1792 | return ps; |
| 1793 | } else |
| 1794 | return ps; |
| 1795 | } |
| 1796 | break; |
| 1797 | case POWER_STATE_TYPE_PERFORMANCE: |
| 1798 | if (ui_class == ATOM_PPLIB_CLASSIFICATION_UI_PERFORMANCE) { |
| 1799 | if (ps->caps & ATOM_PPLIB_SINGLE_DISPLAY_ONLY) { |
| 1800 | if (single_display) |
| 1801 | return ps; |
| 1802 | } else |
| 1803 | return ps; |
| 1804 | } |
| 1805 | break; |
| 1806 | /* internal states */ |
| 1807 | case POWER_STATE_TYPE_INTERNAL_UVD: |
| 1808 | if (adev->pm.dpm.uvd_ps) |
| 1809 | return adev->pm.dpm.uvd_ps; |
| 1810 | else |
| 1811 | break; |
| 1812 | case POWER_STATE_TYPE_INTERNAL_UVD_SD: |
| 1813 | if (ps->class & ATOM_PPLIB_CLASSIFICATION_SDSTATE) |
| 1814 | return ps; |
| 1815 | break; |
| 1816 | case POWER_STATE_TYPE_INTERNAL_UVD_HD: |
| 1817 | if (ps->class & ATOM_PPLIB_CLASSIFICATION_HDSTATE) |
| 1818 | return ps; |
| 1819 | break; |
| 1820 | case POWER_STATE_TYPE_INTERNAL_UVD_HD2: |
| 1821 | if (ps->class & ATOM_PPLIB_CLASSIFICATION_HD2STATE) |
| 1822 | return ps; |
| 1823 | break; |
| 1824 | case POWER_STATE_TYPE_INTERNAL_UVD_MVC: |
| 1825 | if (ps->class2 & ATOM_PPLIB_CLASSIFICATION2_MVC) |
| 1826 | return ps; |
| 1827 | break; |
| 1828 | case POWER_STATE_TYPE_INTERNAL_BOOT: |
| 1829 | return adev->pm.dpm.boot_ps; |
| 1830 | case POWER_STATE_TYPE_INTERNAL_THERMAL: |
| 1831 | if (ps->class & ATOM_PPLIB_CLASSIFICATION_THERMAL) |
| 1832 | return ps; |
| 1833 | break; |
| 1834 | case POWER_STATE_TYPE_INTERNAL_ACPI: |
| 1835 | if (ps->class & ATOM_PPLIB_CLASSIFICATION_ACPI) |
| 1836 | return ps; |
| 1837 | break; |
| 1838 | case POWER_STATE_TYPE_INTERNAL_ULV: |
| 1839 | if (ps->class2 & ATOM_PPLIB_CLASSIFICATION2_ULV) |
| 1840 | return ps; |
| 1841 | break; |
| 1842 | case POWER_STATE_TYPE_INTERNAL_3DPERF: |
| 1843 | if (ps->class & ATOM_PPLIB_CLASSIFICATION_3DPERFORMANCE) |
| 1844 | return ps; |
| 1845 | break; |
| 1846 | default: |
| 1847 | break; |
| 1848 | } |
| 1849 | } |
| 1850 | /* use a fallback state if we didn't match */ |
| 1851 | switch (dpm_state) { |
| 1852 | case POWER_STATE_TYPE_INTERNAL_UVD_SD: |
| 1853 | dpm_state = POWER_STATE_TYPE_INTERNAL_UVD_HD; |
| 1854 | goto restart_search; |
| 1855 | case POWER_STATE_TYPE_INTERNAL_UVD_HD: |
| 1856 | case POWER_STATE_TYPE_INTERNAL_UVD_HD2: |
| 1857 | case POWER_STATE_TYPE_INTERNAL_UVD_MVC: |
| 1858 | if (adev->pm.dpm.uvd_ps) { |
| 1859 | return adev->pm.dpm.uvd_ps; |
| 1860 | } else { |
| 1861 | dpm_state = POWER_STATE_TYPE_PERFORMANCE; |
| 1862 | goto restart_search; |
| 1863 | } |
| 1864 | case POWER_STATE_TYPE_INTERNAL_THERMAL: |
| 1865 | dpm_state = POWER_STATE_TYPE_INTERNAL_ACPI; |
| 1866 | goto restart_search; |
| 1867 | case POWER_STATE_TYPE_INTERNAL_ACPI: |
| 1868 | dpm_state = POWER_STATE_TYPE_BATTERY; |
| 1869 | goto restart_search; |
| 1870 | case POWER_STATE_TYPE_BATTERY: |
| 1871 | case POWER_STATE_TYPE_BALANCED: |
| 1872 | case POWER_STATE_TYPE_INTERNAL_3DPERF: |
| 1873 | dpm_state = POWER_STATE_TYPE_PERFORMANCE; |
| 1874 | goto restart_search; |
| 1875 | default: |
| 1876 | break; |
| 1877 | } |
| 1878 | |
| 1879 | return NULL; |
| 1880 | } |
| 1881 | |
| 1882 | static void amdgpu_dpm_change_power_state_locked(struct amdgpu_device *adev) |
| 1883 | { |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1884 | struct amdgpu_ps *ps; |
Rex Zhu | 3a2c788 | 2015-08-25 15:57:43 +0800 | [diff] [blame] | 1885 | enum amd_pm_state_type dpm_state; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1886 | int ret; |
Rex Zhu | cd4d746 | 2017-09-06 18:43:52 +0800 | [diff] [blame] | 1887 | bool equal = false; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1888 | |
| 1889 | /* if dpm init failed */ |
| 1890 | if (!adev->pm.dpm_enabled) |
| 1891 | return; |
| 1892 | |
| 1893 | if (adev->pm.dpm.user_state != adev->pm.dpm.state) { |
| 1894 | /* add other state override checks here */ |
| 1895 | if ((!adev->pm.dpm.thermal_active) && |
| 1896 | (!adev->pm.dpm.uvd_active)) |
| 1897 | adev->pm.dpm.state = adev->pm.dpm.user_state; |
| 1898 | } |
| 1899 | dpm_state = adev->pm.dpm.state; |
| 1900 | |
| 1901 | ps = amdgpu_dpm_pick_power_state(adev, dpm_state); |
| 1902 | if (ps) |
| 1903 | adev->pm.dpm.requested_ps = ps; |
| 1904 | else |
| 1905 | return; |
| 1906 | |
Rex Zhu | cd4d746 | 2017-09-06 18:43:52 +0800 | [diff] [blame] | 1907 | if (amdgpu_dpm == 1 && adev->powerplay.pp_funcs->print_power_state) { |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1908 | printk("switching from power state:\n"); |
| 1909 | amdgpu_dpm_print_power_state(adev, adev->pm.dpm.current_ps); |
| 1910 | printk("switching to power state:\n"); |
| 1911 | amdgpu_dpm_print_power_state(adev, adev->pm.dpm.requested_ps); |
| 1912 | } |
| 1913 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1914 | /* update whether vce is active */ |
| 1915 | ps->vce_active = adev->pm.dpm.vce_active; |
Rex Zhu | cd4d746 | 2017-09-06 18:43:52 +0800 | [diff] [blame] | 1916 | if (adev->powerplay.pp_funcs->display_configuration_changed) |
| 1917 | amdgpu_dpm_display_configuration_changed(adev); |
Rex Zhu | 5e876c6 | 2016-10-14 19:23:34 +0800 | [diff] [blame] | 1918 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1919 | ret = amdgpu_dpm_pre_set_power_state(adev); |
| 1920 | if (ret) |
Christian König | a27de35 | 2016-01-21 11:28:53 +0100 | [diff] [blame] | 1921 | return; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1922 | |
Rex Zhu | cd4d746 | 2017-09-06 18:43:52 +0800 | [diff] [blame] | 1923 | if (adev->powerplay.pp_funcs->check_state_equal) { |
| 1924 | if (0 != amdgpu_dpm_check_state_equal(adev, adev->pm.dpm.current_ps, adev->pm.dpm.requested_ps, &equal)) |
| 1925 | equal = false; |
| 1926 | } |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1927 | |
Rex Zhu | 5e876c6 | 2016-10-14 19:23:34 +0800 | [diff] [blame] | 1928 | if (equal) |
| 1929 | return; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1930 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1931 | amdgpu_dpm_set_power_state(adev); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1932 | amdgpu_dpm_post_set_power_state(adev); |
| 1933 | |
Alex Deucher | eda1d1c | 2016-02-24 17:18:25 -0500 | [diff] [blame] | 1934 | adev->pm.dpm.current_active_crtcs = adev->pm.dpm.new_active_crtcs; |
| 1935 | adev->pm.dpm.current_active_crtc_count = adev->pm.dpm.new_active_crtc_count; |
| 1936 | |
Rex Zhu | cd4d746 | 2017-09-06 18:43:52 +0800 | [diff] [blame] | 1937 | if (adev->powerplay.pp_funcs->force_performance_level) { |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1938 | if (adev->pm.dpm.thermal_active) { |
Rex Zhu | e5d03ac | 2016-12-23 14:39:41 +0800 | [diff] [blame] | 1939 | enum amd_dpm_forced_level level = adev->pm.dpm.forced_level; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1940 | /* force low perf level for thermal */ |
Rex Zhu | e5d03ac | 2016-12-23 14:39:41 +0800 | [diff] [blame] | 1941 | amdgpu_dpm_force_performance_level(adev, AMD_DPM_FORCED_LEVEL_LOW); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1942 | /* save the user's level */ |
| 1943 | adev->pm.dpm.forced_level = level; |
| 1944 | } else { |
| 1945 | /* otherwise, user selected level */ |
| 1946 | amdgpu_dpm_force_performance_level(adev, adev->pm.dpm.forced_level); |
| 1947 | } |
| 1948 | } |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1949 | } |
| 1950 | |
| 1951 | void amdgpu_dpm_enable_uvd(struct amdgpu_device *adev, bool enable) |
| 1952 | { |
Rex Zhu | b92c628 | 2018-06-05 13:06:11 +0800 | [diff] [blame] | 1953 | if (adev->powerplay.pp_funcs->set_powergating_by_smu) { |
Tom St Denis | e95a14a | 2016-07-28 09:40:07 -0400 | [diff] [blame] | 1954 | /* enable/disable UVD */ |
| 1955 | mutex_lock(&adev->pm.mutex); |
Rex Zhu | b92c628 | 2018-06-05 13:06:11 +0800 | [diff] [blame] | 1956 | amdgpu_dpm_set_powergating_by_smu(adev, AMD_IP_BLOCK_TYPE_UVD, !enable); |
Tom St Denis | e95a14a | 2016-07-28 09:40:07 -0400 | [diff] [blame] | 1957 | mutex_unlock(&adev->pm.mutex); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1958 | } |
| 1959 | } |
| 1960 | |
| 1961 | void amdgpu_dpm_enable_vce(struct amdgpu_device *adev, bool enable) |
| 1962 | { |
Rex Zhu | b92c628 | 2018-06-05 13:06:11 +0800 | [diff] [blame] | 1963 | if (adev->powerplay.pp_funcs->set_powergating_by_smu) { |
Tom St Denis | e95a14a | 2016-07-28 09:40:07 -0400 | [diff] [blame] | 1964 | /* enable/disable VCE */ |
| 1965 | mutex_lock(&adev->pm.mutex); |
Rex Zhu | b92c628 | 2018-06-05 13:06:11 +0800 | [diff] [blame] | 1966 | amdgpu_dpm_set_powergating_by_smu(adev, AMD_IP_BLOCK_TYPE_VCE, !enable); |
Tom St Denis | e95a14a | 2016-07-28 09:40:07 -0400 | [diff] [blame] | 1967 | mutex_unlock(&adev->pm.mutex); |
Sonny Jiang | b7a07769 | 2015-05-28 15:47:53 -0400 | [diff] [blame] | 1968 | } |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1969 | } |
| 1970 | |
| 1971 | void amdgpu_pm_print_power_states(struct amdgpu_device *adev) |
| 1972 | { |
| 1973 | int i; |
| 1974 | |
Rex Zhu | cd4d746 | 2017-09-06 18:43:52 +0800 | [diff] [blame] | 1975 | if (adev->powerplay.pp_funcs->print_power_state == NULL) |
Rex Zhu | 1b5708f | 2015-11-10 18:25:24 -0500 | [diff] [blame] | 1976 | return; |
| 1977 | |
| 1978 | for (i = 0; i < adev->pm.dpm.num_ps; i++) |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1979 | amdgpu_dpm_print_power_state(adev, &adev->pm.dpm.ps[i]); |
Rex Zhu | 1b5708f | 2015-11-10 18:25:24 -0500 | [diff] [blame] | 1980 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1981 | } |
| 1982 | |
| 1983 | int amdgpu_pm_sysfs_init(struct amdgpu_device *adev) |
| 1984 | { |
| 1985 | int ret; |
| 1986 | |
Alex Deucher | c86f5ebf | 2015-10-23 10:45:14 -0400 | [diff] [blame] | 1987 | if (adev->pm.sysfs_initialized) |
| 1988 | return 0; |
| 1989 | |
Rex Zhu | d2f52ac | 2017-09-22 17:47:27 +0800 | [diff] [blame] | 1990 | if (adev->pm.dpm_enabled == 0) |
| 1991 | return 0; |
| 1992 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1993 | adev->pm.int_hwmon_dev = hwmon_device_register_with_groups(adev->dev, |
| 1994 | DRIVER_NAME, adev, |
| 1995 | hwmon_groups); |
| 1996 | if (IS_ERR(adev->pm.int_hwmon_dev)) { |
| 1997 | ret = PTR_ERR(adev->pm.int_hwmon_dev); |
| 1998 | dev_err(adev->dev, |
| 1999 | "Unable to register hwmon device: %d\n", ret); |
| 2000 | return ret; |
| 2001 | } |
| 2002 | |
| 2003 | ret = device_create_file(adev->dev, &dev_attr_power_dpm_state); |
| 2004 | if (ret) { |
| 2005 | DRM_ERROR("failed to create device file for dpm state\n"); |
| 2006 | return ret; |
| 2007 | } |
| 2008 | ret = device_create_file(adev->dev, &dev_attr_power_dpm_force_performance_level); |
| 2009 | if (ret) { |
| 2010 | DRM_ERROR("failed to create device file for dpm state\n"); |
| 2011 | return ret; |
| 2012 | } |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 2013 | |
Rex Zhu | 6d07fe7 | 2017-09-25 18:51:50 +0800 | [diff] [blame] | 2014 | |
| 2015 | ret = device_create_file(adev->dev, &dev_attr_pp_num_states); |
| 2016 | if (ret) { |
| 2017 | DRM_ERROR("failed to create device file pp_num_states\n"); |
| 2018 | return ret; |
| 2019 | } |
| 2020 | ret = device_create_file(adev->dev, &dev_attr_pp_cur_state); |
| 2021 | if (ret) { |
| 2022 | DRM_ERROR("failed to create device file pp_cur_state\n"); |
| 2023 | return ret; |
| 2024 | } |
| 2025 | ret = device_create_file(adev->dev, &dev_attr_pp_force_state); |
| 2026 | if (ret) { |
| 2027 | DRM_ERROR("failed to create device file pp_force_state\n"); |
| 2028 | return ret; |
| 2029 | } |
| 2030 | ret = device_create_file(adev->dev, &dev_attr_pp_table); |
| 2031 | if (ret) { |
| 2032 | DRM_ERROR("failed to create device file pp_table\n"); |
| 2033 | return ret; |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 2034 | } |
Eric Huang | c85e299 | 2016-05-19 15:41:25 -0400 | [diff] [blame] | 2035 | |
| 2036 | ret = device_create_file(adev->dev, &dev_attr_pp_dpm_sclk); |
| 2037 | if (ret) { |
| 2038 | DRM_ERROR("failed to create device file pp_dpm_sclk\n"); |
| 2039 | return ret; |
| 2040 | } |
| 2041 | ret = device_create_file(adev->dev, &dev_attr_pp_dpm_mclk); |
| 2042 | if (ret) { |
| 2043 | DRM_ERROR("failed to create device file pp_dpm_mclk\n"); |
| 2044 | return ret; |
| 2045 | } |
| 2046 | ret = device_create_file(adev->dev, &dev_attr_pp_dpm_pcie); |
| 2047 | if (ret) { |
| 2048 | DRM_ERROR("failed to create device file pp_dpm_pcie\n"); |
| 2049 | return ret; |
| 2050 | } |
Eric Huang | 8b2e574 | 2016-05-19 15:46:10 -0400 | [diff] [blame] | 2051 | ret = device_create_file(adev->dev, &dev_attr_pp_sclk_od); |
| 2052 | if (ret) { |
| 2053 | DRM_ERROR("failed to create device file pp_sclk_od\n"); |
| 2054 | return ret; |
| 2055 | } |
Eric Huang | f2bdc05 | 2016-05-24 15:11:17 -0400 | [diff] [blame] | 2056 | ret = device_create_file(adev->dev, &dev_attr_pp_mclk_od); |
| 2057 | if (ret) { |
| 2058 | DRM_ERROR("failed to create device file pp_mclk_od\n"); |
| 2059 | return ret; |
| 2060 | } |
Eric Huang | 34bb273 | 2016-09-12 16:17:44 -0400 | [diff] [blame] | 2061 | ret = device_create_file(adev->dev, |
Rex Zhu | 37c5c4d | 2018-01-10 18:42:36 +0800 | [diff] [blame] | 2062 | &dev_attr_pp_power_profile_mode); |
| 2063 | if (ret) { |
| 2064 | DRM_ERROR("failed to create device file " |
| 2065 | "pp_power_profile_mode\n"); |
| 2066 | return ret; |
| 2067 | } |
Rex Zhu | e3933f2 | 2018-01-16 18:35:15 +0800 | [diff] [blame] | 2068 | ret = device_create_file(adev->dev, |
| 2069 | &dev_attr_pp_od_clk_voltage); |
| 2070 | if (ret) { |
| 2071 | DRM_ERROR("failed to create device file " |
| 2072 | "pp_od_clk_voltage\n"); |
| 2073 | return ret; |
| 2074 | } |
Tom St Denis | b374d82 | 2018-06-20 07:55:39 -0400 | [diff] [blame] | 2075 | ret = device_create_file(adev->dev, |
| 2076 | &dev_attr_gpu_busy_percent); |
| 2077 | if (ret) { |
| 2078 | DRM_ERROR("failed to create device file " |
| 2079 | "gpu_busy_level\n"); |
| 2080 | return ret; |
| 2081 | } |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2082 | ret = amdgpu_debugfs_pm_init(adev); |
| 2083 | if (ret) { |
| 2084 | DRM_ERROR("Failed to register debugfs file for dpm!\n"); |
| 2085 | return ret; |
| 2086 | } |
| 2087 | |
Alex Deucher | c86f5ebf | 2015-10-23 10:45:14 -0400 | [diff] [blame] | 2088 | adev->pm.sysfs_initialized = true; |
| 2089 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2090 | return 0; |
| 2091 | } |
| 2092 | |
| 2093 | void amdgpu_pm_sysfs_fini(struct amdgpu_device *adev) |
| 2094 | { |
Rex Zhu | d2f52ac | 2017-09-22 17:47:27 +0800 | [diff] [blame] | 2095 | if (adev->pm.dpm_enabled == 0) |
| 2096 | return; |
| 2097 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2098 | if (adev->pm.int_hwmon_dev) |
| 2099 | hwmon_device_unregister(adev->pm.int_hwmon_dev); |
| 2100 | device_remove_file(adev->dev, &dev_attr_power_dpm_state); |
| 2101 | device_remove_file(adev->dev, &dev_attr_power_dpm_force_performance_level); |
Rex Zhu | 6d07fe7 | 2017-09-25 18:51:50 +0800 | [diff] [blame] | 2102 | |
| 2103 | device_remove_file(adev->dev, &dev_attr_pp_num_states); |
| 2104 | device_remove_file(adev->dev, &dev_attr_pp_cur_state); |
| 2105 | device_remove_file(adev->dev, &dev_attr_pp_force_state); |
| 2106 | device_remove_file(adev->dev, &dev_attr_pp_table); |
| 2107 | |
Eric Huang | c85e299 | 2016-05-19 15:41:25 -0400 | [diff] [blame] | 2108 | device_remove_file(adev->dev, &dev_attr_pp_dpm_sclk); |
| 2109 | device_remove_file(adev->dev, &dev_attr_pp_dpm_mclk); |
| 2110 | device_remove_file(adev->dev, &dev_attr_pp_dpm_pcie); |
Eric Huang | 8b2e574 | 2016-05-19 15:46:10 -0400 | [diff] [blame] | 2111 | device_remove_file(adev->dev, &dev_attr_pp_sclk_od); |
Eric Huang | f2bdc05 | 2016-05-24 15:11:17 -0400 | [diff] [blame] | 2112 | device_remove_file(adev->dev, &dev_attr_pp_mclk_od); |
Eric Huang | 34bb273 | 2016-09-12 16:17:44 -0400 | [diff] [blame] | 2113 | device_remove_file(adev->dev, |
Rex Zhu | 37c5c4d | 2018-01-10 18:42:36 +0800 | [diff] [blame] | 2114 | &dev_attr_pp_power_profile_mode); |
Rex Zhu | e3933f2 | 2018-01-16 18:35:15 +0800 | [diff] [blame] | 2115 | device_remove_file(adev->dev, |
| 2116 | &dev_attr_pp_od_clk_voltage); |
Tom St Denis | b374d82 | 2018-06-20 07:55:39 -0400 | [diff] [blame] | 2117 | device_remove_file(adev->dev, &dev_attr_gpu_busy_percent); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2118 | } |
| 2119 | |
| 2120 | void amdgpu_pm_compute_clocks(struct amdgpu_device *adev) |
| 2121 | { |
Rex Zhu | 5e876c6 | 2016-10-14 19:23:34 +0800 | [diff] [blame] | 2122 | int i = 0; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2123 | |
| 2124 | if (!adev->pm.dpm_enabled) |
| 2125 | return; |
| 2126 | |
Alex Deucher | c10c8f7 | 2017-02-10 18:09:32 -0500 | [diff] [blame] | 2127 | if (adev->mode_info.num_crtc) |
| 2128 | amdgpu_display_bandwidth_update(adev); |
Rex Zhu | 5e876c6 | 2016-10-14 19:23:34 +0800 | [diff] [blame] | 2129 | |
| 2130 | for (i = 0; i < AMDGPU_MAX_RINGS; i++) { |
| 2131 | struct amdgpu_ring *ring = adev->rings[i]; |
| 2132 | if (ring && ring->ready) |
| 2133 | amdgpu_fence_wait_empty(ring); |
| 2134 | } |
| 2135 | |
Rex Zhu | 6d07fe7 | 2017-09-25 18:51:50 +0800 | [diff] [blame] | 2136 | if (adev->powerplay.pp_funcs->dispatch_tasks) { |
Rex Zhu | 51d45cb | 2018-04-27 14:09:30 +0800 | [diff] [blame] | 2137 | if (!amdgpu_device_has_dc_support(adev)) { |
| 2138 | mutex_lock(&adev->pm.mutex); |
| 2139 | amdgpu_dpm_get_active_displays(adev); |
Alex Deucher | 70eb46d | 2018-06-28 12:44:25 -0500 | [diff] [blame] | 2140 | adev->pm.pm_display_cfg.num_display = adev->pm.dpm.new_active_crtc_count; |
Rex Zhu | 51d45cb | 2018-04-27 14:09:30 +0800 | [diff] [blame] | 2141 | adev->pm.pm_display_cfg.vrefresh = amdgpu_dpm_get_vrefresh(adev); |
| 2142 | adev->pm.pm_display_cfg.min_vblank_time = amdgpu_dpm_get_vblank_time(adev); |
| 2143 | /* we have issues with mclk switching with refresh rates over 120 hz on the non-DC code. */ |
| 2144 | if (adev->pm.pm_display_cfg.vrefresh > 120) |
| 2145 | adev->pm.pm_display_cfg.min_vblank_time = 0; |
| 2146 | if (adev->powerplay.pp_funcs->display_configuration_change) |
| 2147 | adev->powerplay.pp_funcs->display_configuration_change( |
| 2148 | adev->powerplay.pp_handle, |
| 2149 | &adev->pm.pm_display_cfg); |
| 2150 | mutex_unlock(&adev->pm.mutex); |
| 2151 | } |
Evan Quan | 39199b8 | 2017-12-29 14:46:13 +0800 | [diff] [blame] | 2152 | amdgpu_dpm_dispatch_task(adev, AMD_PP_TASK_DISPLAY_CONFIG_CHANGE, NULL); |
Rex Zhu | 1b5708f | 2015-11-10 18:25:24 -0500 | [diff] [blame] | 2153 | } else { |
| 2154 | mutex_lock(&adev->pm.mutex); |
Rex Zhu | 51d45cb | 2018-04-27 14:09:30 +0800 | [diff] [blame] | 2155 | amdgpu_dpm_get_active_displays(adev); |
Rex Zhu | 1b5708f | 2015-11-10 18:25:24 -0500 | [diff] [blame] | 2156 | amdgpu_dpm_change_power_state_locked(adev); |
Rex Zhu | 1b5708f | 2015-11-10 18:25:24 -0500 | [diff] [blame] | 2157 | mutex_unlock(&adev->pm.mutex); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2158 | } |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2159 | } |
| 2160 | |
| 2161 | /* |
| 2162 | * Debugfs info |
| 2163 | */ |
| 2164 | #if defined(CONFIG_DEBUG_FS) |
| 2165 | |
Tom St Denis | 3de4ec5 | 2016-09-19 12:48:52 -0400 | [diff] [blame] | 2166 | static int amdgpu_debugfs_pm_info_pp(struct seq_file *m, struct amdgpu_device *adev) |
| 2167 | { |
Eric Huang | cd7b0c6 | 2017-02-07 16:37:48 -0500 | [diff] [blame] | 2168 | uint32_t value; |
Alex Deucher | 505f8db | 2018-09-20 22:50:07 -0500 | [diff] [blame] | 2169 | uint64_t value64; |
Rex Zhu | 5b79d04 | 2018-04-04 15:37:35 +0800 | [diff] [blame] | 2170 | uint32_t query = 0; |
Tom St Denis | 9f8df7d | 2017-02-09 14:29:01 -0500 | [diff] [blame] | 2171 | int size; |
Tom St Denis | 3de4ec5 | 2016-09-19 12:48:52 -0400 | [diff] [blame] | 2172 | |
| 2173 | /* sanity check PP is enabled */ |
| 2174 | if (!(adev->powerplay.pp_funcs && |
| 2175 | adev->powerplay.pp_funcs->read_sensor)) |
| 2176 | return -EINVAL; |
| 2177 | |
| 2178 | /* GPU Clocks */ |
Tom St Denis | 9f8df7d | 2017-02-09 14:29:01 -0500 | [diff] [blame] | 2179 | size = sizeof(value); |
Tom St Denis | 3de4ec5 | 2016-09-19 12:48:52 -0400 | [diff] [blame] | 2180 | seq_printf(m, "GFX Clocks and Power:\n"); |
Tom St Denis | 9f8df7d | 2017-02-09 14:29:01 -0500 | [diff] [blame] | 2181 | if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GFX_MCLK, (void *)&value, &size)) |
Tom St Denis | 3de4ec5 | 2016-09-19 12:48:52 -0400 | [diff] [blame] | 2182 | seq_printf(m, "\t%u MHz (MCLK)\n", value/100); |
Tom St Denis | 9f8df7d | 2017-02-09 14:29:01 -0500 | [diff] [blame] | 2183 | if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GFX_SCLK, (void *)&value, &size)) |
Tom St Denis | 3de4ec5 | 2016-09-19 12:48:52 -0400 | [diff] [blame] | 2184 | seq_printf(m, "\t%u MHz (SCLK)\n", value/100); |
Rex Zhu | 5ed8d65 | 2018-01-08 13:59:05 +0800 | [diff] [blame] | 2185 | if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_STABLE_PSTATE_SCLK, (void *)&value, &size)) |
| 2186 | seq_printf(m, "\t%u MHz (PSTATE_SCLK)\n", value/100); |
| 2187 | if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_STABLE_PSTATE_MCLK, (void *)&value, &size)) |
| 2188 | seq_printf(m, "\t%u MHz (PSTATE_MCLK)\n", value/100); |
Tom St Denis | 9f8df7d | 2017-02-09 14:29:01 -0500 | [diff] [blame] | 2189 | if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_VDDGFX, (void *)&value, &size)) |
Tom St Denis | 3de4ec5 | 2016-09-19 12:48:52 -0400 | [diff] [blame] | 2190 | seq_printf(m, "\t%u mV (VDDGFX)\n", value); |
Tom St Denis | 9f8df7d | 2017-02-09 14:29:01 -0500 | [diff] [blame] | 2191 | if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_VDDNB, (void *)&value, &size)) |
Tom St Denis | 3de4ec5 | 2016-09-19 12:48:52 -0400 | [diff] [blame] | 2192 | seq_printf(m, "\t%u mV (VDDNB)\n", value); |
Rex Zhu | 5b79d04 | 2018-04-04 15:37:35 +0800 | [diff] [blame] | 2193 | size = sizeof(uint32_t); |
| 2194 | if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GPU_POWER, (void *)&query, &size)) |
| 2195 | seq_printf(m, "\t%u.%u W (average GPU)\n", query >> 8, query & 0xff); |
Tom St Denis | 9f8df7d | 2017-02-09 14:29:01 -0500 | [diff] [blame] | 2196 | size = sizeof(value); |
Tom St Denis | 3de4ec5 | 2016-09-19 12:48:52 -0400 | [diff] [blame] | 2197 | seq_printf(m, "\n"); |
| 2198 | |
| 2199 | /* GPU Temp */ |
Tom St Denis | 9f8df7d | 2017-02-09 14:29:01 -0500 | [diff] [blame] | 2200 | if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GPU_TEMP, (void *)&value, &size)) |
Tom St Denis | 3de4ec5 | 2016-09-19 12:48:52 -0400 | [diff] [blame] | 2201 | seq_printf(m, "GPU Temperature: %u C\n", value/1000); |
| 2202 | |
| 2203 | /* GPU Load */ |
Tom St Denis | 9f8df7d | 2017-02-09 14:29:01 -0500 | [diff] [blame] | 2204 | if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GPU_LOAD, (void *)&value, &size)) |
Tom St Denis | 3de4ec5 | 2016-09-19 12:48:52 -0400 | [diff] [blame] | 2205 | seq_printf(m, "GPU Load: %u %%\n", value); |
| 2206 | seq_printf(m, "\n"); |
| 2207 | |
Alex Deucher | 505f8db | 2018-09-20 22:50:07 -0500 | [diff] [blame] | 2208 | /* SMC feature mask */ |
| 2209 | if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_ENABLED_SMC_FEATURES_MASK, (void *)&value64, &size)) |
| 2210 | seq_printf(m, "SMC Feature Mask: 0x%016llx\n", value64); |
| 2211 | |
Tom St Denis | 3de4ec5 | 2016-09-19 12:48:52 -0400 | [diff] [blame] | 2212 | /* UVD clocks */ |
Tom St Denis | 9f8df7d | 2017-02-09 14:29:01 -0500 | [diff] [blame] | 2213 | if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_UVD_POWER, (void *)&value, &size)) { |
Tom St Denis | 3de4ec5 | 2016-09-19 12:48:52 -0400 | [diff] [blame] | 2214 | if (!value) { |
| 2215 | seq_printf(m, "UVD: Disabled\n"); |
| 2216 | } else { |
| 2217 | seq_printf(m, "UVD: Enabled\n"); |
Tom St Denis | 9f8df7d | 2017-02-09 14:29:01 -0500 | [diff] [blame] | 2218 | if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_UVD_DCLK, (void *)&value, &size)) |
Tom St Denis | 3de4ec5 | 2016-09-19 12:48:52 -0400 | [diff] [blame] | 2219 | seq_printf(m, "\t%u MHz (DCLK)\n", value/100); |
Tom St Denis | 9f8df7d | 2017-02-09 14:29:01 -0500 | [diff] [blame] | 2220 | if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_UVD_VCLK, (void *)&value, &size)) |
Tom St Denis | 3de4ec5 | 2016-09-19 12:48:52 -0400 | [diff] [blame] | 2221 | seq_printf(m, "\t%u MHz (VCLK)\n", value/100); |
| 2222 | } |
| 2223 | } |
| 2224 | seq_printf(m, "\n"); |
| 2225 | |
| 2226 | /* VCE clocks */ |
Tom St Denis | 9f8df7d | 2017-02-09 14:29:01 -0500 | [diff] [blame] | 2227 | if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_VCE_POWER, (void *)&value, &size)) { |
Tom St Denis | 3de4ec5 | 2016-09-19 12:48:52 -0400 | [diff] [blame] | 2228 | if (!value) { |
| 2229 | seq_printf(m, "VCE: Disabled\n"); |
| 2230 | } else { |
| 2231 | seq_printf(m, "VCE: Enabled\n"); |
Tom St Denis | 9f8df7d | 2017-02-09 14:29:01 -0500 | [diff] [blame] | 2232 | if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_VCE_ECCLK, (void *)&value, &size)) |
Tom St Denis | 3de4ec5 | 2016-09-19 12:48:52 -0400 | [diff] [blame] | 2233 | seq_printf(m, "\t%u MHz (ECCLK)\n", value/100); |
| 2234 | } |
| 2235 | } |
| 2236 | |
| 2237 | return 0; |
| 2238 | } |
| 2239 | |
Huang Rui | a8503b1 | 2017-01-05 19:17:13 +0800 | [diff] [blame] | 2240 | static void amdgpu_parse_cg_state(struct seq_file *m, u32 flags) |
| 2241 | { |
| 2242 | int i; |
| 2243 | |
| 2244 | for (i = 0; clocks[i].flag; i++) |
| 2245 | seq_printf(m, "\t%s: %s\n", clocks[i].name, |
| 2246 | (flags & clocks[i].flag) ? "On" : "Off"); |
| 2247 | } |
| 2248 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2249 | static int amdgpu_debugfs_pm_info(struct seq_file *m, void *data) |
| 2250 | { |
| 2251 | struct drm_info_node *node = (struct drm_info_node *) m->private; |
| 2252 | struct drm_device *dev = node->minor->dev; |
| 2253 | struct amdgpu_device *adev = dev->dev_private; |
Alex Deucher | 0c67df4 | 2016-02-19 15:30:15 -0500 | [diff] [blame] | 2254 | struct drm_device *ddev = adev->ddev; |
Huang Rui | 6cb2d4e | 2017-01-05 18:44:41 +0800 | [diff] [blame] | 2255 | u32 flags = 0; |
| 2256 | |
Alex Deucher | 2990a1f | 2017-12-15 16:18:00 -0500 | [diff] [blame] | 2257 | amdgpu_device_ip_get_clockgating_state(adev, &flags); |
Huang Rui | 6cb2d4e | 2017-01-05 18:44:41 +0800 | [diff] [blame] | 2258 | seq_printf(m, "Clock Gating Flags Mask: 0x%x\n", flags); |
Huang Rui | a8503b1 | 2017-01-05 19:17:13 +0800 | [diff] [blame] | 2259 | amdgpu_parse_cg_state(m, flags); |
| 2260 | seq_printf(m, "\n"); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2261 | |
Rex Zhu | 1b5708f | 2015-11-10 18:25:24 -0500 | [diff] [blame] | 2262 | if (!adev->pm.dpm_enabled) { |
| 2263 | seq_printf(m, "dpm not enabled\n"); |
| 2264 | return 0; |
| 2265 | } |
Alex Deucher | 0c67df4 | 2016-02-19 15:30:15 -0500 | [diff] [blame] | 2266 | if ((adev->flags & AMD_IS_PX) && |
| 2267 | (ddev->switch_power_state != DRM_SWITCH_POWER_ON)) { |
| 2268 | seq_printf(m, "PX asic powered off\n"); |
Rex Zhu | 6d07fe7 | 2017-09-25 18:51:50 +0800 | [diff] [blame] | 2269 | } else if (adev->powerplay.pp_funcs->debugfs_print_current_performance_level) { |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2270 | mutex_lock(&adev->pm.mutex); |
Rex Zhu | cd4d746 | 2017-09-06 18:43:52 +0800 | [diff] [blame] | 2271 | if (adev->powerplay.pp_funcs->debugfs_print_current_performance_level) |
| 2272 | adev->powerplay.pp_funcs->debugfs_print_current_performance_level(adev, m); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2273 | else |
| 2274 | seq_printf(m, "Debugfs support not implemented for this asic\n"); |
| 2275 | mutex_unlock(&adev->pm.mutex); |
Rex Zhu | 6d07fe7 | 2017-09-25 18:51:50 +0800 | [diff] [blame] | 2276 | } else { |
| 2277 | return amdgpu_debugfs_pm_info_pp(m, adev); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2278 | } |
| 2279 | |
| 2280 | return 0; |
| 2281 | } |
| 2282 | |
Nils Wallménius | 06ab683 | 2016-05-02 12:46:15 -0400 | [diff] [blame] | 2283 | static const struct drm_info_list amdgpu_pm_info_list[] = { |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 2284 | {"amdgpu_pm_info", amdgpu_debugfs_pm_info, 0, NULL}, |
| 2285 | }; |
| 2286 | #endif |
| 2287 | |
| 2288 | static int amdgpu_debugfs_pm_init(struct amdgpu_device *adev) |
| 2289 | { |
| 2290 | #if defined(CONFIG_DEBUG_FS) |
| 2291 | return amdgpu_debugfs_add_files(adev, amdgpu_pm_info_list, ARRAY_SIZE(amdgpu_pm_info_list)); |
| 2292 | #else |
| 2293 | return 0; |
| 2294 | #endif |
| 2295 | } |