Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 3 | * copy of this software and associated documentation files (the "Software"), |
| 4 | * to deal in the Software without restriction, including without limitation |
| 5 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 6 | * and/or sell copies of the Software, and to permit persons to whom the |
| 7 | * Software is furnished to do so, subject to the following conditions: |
| 8 | * |
| 9 | * The above copyright notice and this permission notice shall be included in |
| 10 | * all copies or substantial portions of the Software. |
| 11 | * |
| 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 13 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 14 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 15 | * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR |
| 16 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
| 17 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 18 | * OTHER DEALINGS IN THE SOFTWARE. |
| 19 | * |
| 20 | * Authors: Rafał Miłecki <zajec5@gmail.com> |
| 21 | * Alex Deucher <alexdeucher@gmail.com> |
| 22 | */ |
| 23 | #include <drm/drmP.h> |
| 24 | #include "amdgpu.h" |
| 25 | #include "amdgpu_drv.h" |
| 26 | #include "amdgpu_pm.h" |
| 27 | #include "amdgpu_dpm.h" |
| 28 | #include "atom.h" |
| 29 | #include <linux/power_supply.h> |
| 30 | #include <linux/hwmon.h> |
| 31 | #include <linux/hwmon-sysfs.h> |
| 32 | |
Rex Zhu | 1b5708f | 2015-11-10 18:25:24 -0500 | [diff] [blame] | 33 | #include "amd_powerplay.h" |
| 34 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 35 | static int amdgpu_debugfs_pm_init(struct amdgpu_device *adev); |
| 36 | |
Huang Rui | a8503b1 | 2017-01-05 19:17:13 +0800 | [diff] [blame] | 37 | static const struct cg_flag_name clocks[] = { |
| 38 | {AMD_CG_SUPPORT_GFX_MGCG, "Graphics Medium Grain Clock Gating"}, |
| 39 | {AMD_CG_SUPPORT_GFX_MGLS, "Graphics Medium Grain memory Light Sleep"}, |
| 40 | {AMD_CG_SUPPORT_GFX_CGCG, "Graphics Coarse Grain Clock Gating"}, |
| 41 | {AMD_CG_SUPPORT_GFX_CGLS, "Graphics Coarse Grain memory Light Sleep"}, |
Huang Rui | 5417022 | 2017-01-11 09:55:34 +0800 | [diff] [blame] | 42 | {AMD_CG_SUPPORT_GFX_CGTS, "Graphics Coarse Grain Tree Shader Clock Gating"}, |
Huang Rui | a8503b1 | 2017-01-05 19:17:13 +0800 | [diff] [blame] | 43 | {AMD_CG_SUPPORT_GFX_CGTS_LS, "Graphics Coarse Grain Tree Shader Light Sleep"}, |
| 44 | {AMD_CG_SUPPORT_GFX_CP_LS, "Graphics Command Processor Light Sleep"}, |
| 45 | {AMD_CG_SUPPORT_GFX_RLC_LS, "Graphics Run List Controller Light Sleep"}, |
Huang Rui | 12ad27f | 2017-03-24 09:58:11 +0800 | [diff] [blame] | 46 | {AMD_CG_SUPPORT_GFX_3D_CGCG, "Graphics 3D Coarse Grain Clock Gating"}, |
| 47 | {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] | 48 | {AMD_CG_SUPPORT_MC_LS, "Memory Controller Light Sleep"}, |
| 49 | {AMD_CG_SUPPORT_MC_MGCG, "Memory Controller Medium Grain Clock Gating"}, |
| 50 | {AMD_CG_SUPPORT_SDMA_LS, "System Direct Memory Access Light Sleep"}, |
| 51 | {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] | 52 | {AMD_CG_SUPPORT_BIF_MGCG, "Bus Interface Medium Grain Clock Gating"}, |
Huang Rui | a8503b1 | 2017-01-05 19:17:13 +0800 | [diff] [blame] | 53 | {AMD_CG_SUPPORT_BIF_LS, "Bus Interface Light Sleep"}, |
| 54 | {AMD_CG_SUPPORT_UVD_MGCG, "Unified Video Decoder Medium Grain Clock Gating"}, |
| 55 | {AMD_CG_SUPPORT_VCE_MGCG, "Video Compression Engine Medium Grain Clock Gating"}, |
| 56 | {AMD_CG_SUPPORT_HDP_LS, "Host Data Path Light Sleep"}, |
| 57 | {AMD_CG_SUPPORT_HDP_MGCG, "Host Data Path Medium Grain Clock Gating"}, |
Huang Rui | f9abe35 | 2017-03-24 10:46:16 +0800 | [diff] [blame] | 58 | {AMD_CG_SUPPORT_DRM_MGCG, "Digital Right Management Medium Grain Clock Gating"}, |
| 59 | {AMD_CG_SUPPORT_DRM_LS, "Digital Right Management Light Sleep"}, |
Huang Rui | a8503b1 | 2017-01-05 19:17:13 +0800 | [diff] [blame] | 60 | {AMD_CG_SUPPORT_ROM_MGCG, "Rom Medium Grain Clock Gating"}, |
Huang Rui | f9abe35 | 2017-03-24 10:46:16 +0800 | [diff] [blame] | 61 | {AMD_CG_SUPPORT_DF_MGCG, "Data Fabric Medium Grain Clock Gating"}, |
Huang Rui | a8503b1 | 2017-01-05 19:17:13 +0800 | [diff] [blame] | 62 | {0, NULL}, |
| 63 | }; |
| 64 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 65 | void amdgpu_pm_acpi_event_handler(struct amdgpu_device *adev) |
| 66 | { |
Jammy Zhou | e61710c | 2015-11-10 18:31:08 -0500 | [diff] [blame] | 67 | if (adev->pp_enabled) |
Rex Zhu | 1b5708f | 2015-11-10 18:25:24 -0500 | [diff] [blame] | 68 | /* TODO */ |
| 69 | return; |
| 70 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 71 | if (adev->pm.dpm_enabled) { |
| 72 | mutex_lock(&adev->pm.mutex); |
| 73 | if (power_supply_is_system_supplied() > 0) |
| 74 | adev->pm.dpm.ac_power = true; |
| 75 | else |
| 76 | adev->pm.dpm.ac_power = false; |
Rex Zhu | cd4d746 | 2017-09-06 18:43:52 +0800 | [diff] [blame] | 77 | if (adev->powerplay.pp_funcs->enable_bapm) |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 78 | amdgpu_dpm_enable_bapm(adev, adev->pm.dpm.ac_power); |
| 79 | mutex_unlock(&adev->pm.mutex); |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | static ssize_t amdgpu_get_dpm_state(struct device *dev, |
| 84 | struct device_attribute *attr, |
| 85 | char *buf) |
| 86 | { |
| 87 | struct drm_device *ddev = dev_get_drvdata(dev); |
| 88 | struct amdgpu_device *adev = ddev->dev_private; |
Rex Zhu | 1b5708f | 2015-11-10 18:25:24 -0500 | [diff] [blame] | 89 | enum amd_pm_state_type pm; |
| 90 | |
Rex Zhu | cd4d746 | 2017-09-06 18:43:52 +0800 | [diff] [blame] | 91 | if (adev->powerplay.pp_funcs->get_current_power_state) |
Rex Zhu | 1b5708f | 2015-11-10 18:25:24 -0500 | [diff] [blame] | 92 | pm = amdgpu_dpm_get_current_power_state(adev); |
Rex Zhu | cd4d746 | 2017-09-06 18:43:52 +0800 | [diff] [blame] | 93 | else |
Rex Zhu | 1b5708f | 2015-11-10 18:25:24 -0500 | [diff] [blame] | 94 | pm = adev->pm.dpm.user_state; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 95 | |
| 96 | return snprintf(buf, PAGE_SIZE, "%s\n", |
| 97 | (pm == POWER_STATE_TYPE_BATTERY) ? "battery" : |
| 98 | (pm == POWER_STATE_TYPE_BALANCED) ? "balanced" : "performance"); |
| 99 | } |
| 100 | |
| 101 | static ssize_t amdgpu_set_dpm_state(struct device *dev, |
| 102 | struct device_attribute *attr, |
| 103 | const char *buf, |
| 104 | size_t count) |
| 105 | { |
| 106 | struct drm_device *ddev = dev_get_drvdata(dev); |
| 107 | struct amdgpu_device *adev = ddev->dev_private; |
Rex Zhu | 1b5708f | 2015-11-10 18:25:24 -0500 | [diff] [blame] | 108 | enum amd_pm_state_type state; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 109 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 110 | if (strncmp("battery", buf, strlen("battery")) == 0) |
Rex Zhu | 1b5708f | 2015-11-10 18:25:24 -0500 | [diff] [blame] | 111 | state = POWER_STATE_TYPE_BATTERY; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 112 | else if (strncmp("balanced", buf, strlen("balanced")) == 0) |
Rex Zhu | 1b5708f | 2015-11-10 18:25:24 -0500 | [diff] [blame] | 113 | state = POWER_STATE_TYPE_BALANCED; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 114 | else if (strncmp("performance", buf, strlen("performance")) == 0) |
Rex Zhu | 1b5708f | 2015-11-10 18:25:24 -0500 | [diff] [blame] | 115 | state = POWER_STATE_TYPE_PERFORMANCE; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 116 | else { |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 117 | count = -EINVAL; |
| 118 | goto fail; |
| 119 | } |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 120 | |
Jammy Zhou | e61710c | 2015-11-10 18:31:08 -0500 | [diff] [blame] | 121 | if (adev->pp_enabled) { |
Rex Zhu | df1e639 | 2017-09-01 13:46:20 +0800 | [diff] [blame] | 122 | amdgpu_dpm_dispatch_task(adev, AMD_PP_TASK_ENABLE_USER_STATE, &state, NULL); |
Rex Zhu | 1b5708f | 2015-11-10 18:25:24 -0500 | [diff] [blame] | 123 | } else { |
| 124 | mutex_lock(&adev->pm.mutex); |
| 125 | adev->pm.dpm.user_state = state; |
| 126 | mutex_unlock(&adev->pm.mutex); |
| 127 | |
| 128 | /* Can't set dpm state when the card is off */ |
| 129 | if (!(adev->flags & AMD_IS_PX) || |
| 130 | (ddev->switch_power_state == DRM_SWITCH_POWER_ON)) |
| 131 | amdgpu_pm_compute_clocks(adev); |
| 132 | } |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 133 | fail: |
| 134 | return count; |
| 135 | } |
| 136 | |
| 137 | static ssize_t amdgpu_get_dpm_forced_performance_level(struct device *dev, |
Rex Zhu | 1b5708f | 2015-11-10 18:25:24 -0500 | [diff] [blame] | 138 | struct device_attribute *attr, |
| 139 | char *buf) |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 140 | { |
| 141 | struct drm_device *ddev = dev_get_drvdata(dev); |
| 142 | struct amdgpu_device *adev = ddev->dev_private; |
Rex Zhu | cd4d746 | 2017-09-06 18:43:52 +0800 | [diff] [blame] | 143 | enum amd_dpm_forced_level level = 0xff; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 144 | |
Alex Deucher | 0c67df4 | 2016-02-19 15:30:15 -0500 | [diff] [blame] | 145 | if ((adev->flags & AMD_IS_PX) && |
| 146 | (ddev->switch_power_state != DRM_SWITCH_POWER_ON)) |
| 147 | return snprintf(buf, PAGE_SIZE, "off\n"); |
| 148 | |
Rex Zhu | cd4d746 | 2017-09-06 18:43:52 +0800 | [diff] [blame] | 149 | if (adev->powerplay.pp_funcs->get_performance_level) |
| 150 | level = amdgpu_dpm_get_performance_level(adev); |
| 151 | else |
| 152 | level = adev->pm.dpm.forced_level; |
| 153 | |
Rex Zhu | e5d03ac | 2016-12-23 14:39:41 +0800 | [diff] [blame] | 154 | return snprintf(buf, PAGE_SIZE, "%s\n", |
Rex Zhu | 570272d | 2017-01-06 13:32:49 +0800 | [diff] [blame] | 155 | (level == AMD_DPM_FORCED_LEVEL_AUTO) ? "auto" : |
| 156 | (level == AMD_DPM_FORCED_LEVEL_LOW) ? "low" : |
| 157 | (level == AMD_DPM_FORCED_LEVEL_HIGH) ? "high" : |
| 158 | (level == AMD_DPM_FORCED_LEVEL_MANUAL) ? "manual" : |
| 159 | (level == AMD_DPM_FORCED_LEVEL_PROFILE_STANDARD) ? "profile_standard" : |
| 160 | (level == AMD_DPM_FORCED_LEVEL_PROFILE_MIN_SCLK) ? "profile_min_sclk" : |
| 161 | (level == AMD_DPM_FORCED_LEVEL_PROFILE_MIN_MCLK) ? "profile_min_mclk" : |
| 162 | (level == AMD_DPM_FORCED_LEVEL_PROFILE_PEAK) ? "profile_peak" : |
| 163 | "unknown"); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 164 | } |
| 165 | |
| 166 | static ssize_t amdgpu_set_dpm_forced_performance_level(struct device *dev, |
| 167 | struct device_attribute *attr, |
| 168 | const char *buf, |
| 169 | size_t count) |
| 170 | { |
| 171 | struct drm_device *ddev = dev_get_drvdata(dev); |
| 172 | struct amdgpu_device *adev = ddev->dev_private; |
Rex Zhu | e5d03ac | 2016-12-23 14:39:41 +0800 | [diff] [blame] | 173 | enum amd_dpm_forced_level level; |
Rex Zhu | cd4d746 | 2017-09-06 18:43:52 +0800 | [diff] [blame] | 174 | enum amd_dpm_forced_level current_level = 0xff; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 175 | int ret = 0; |
| 176 | |
Alex Deucher | 0c67df4 | 2016-02-19 15:30:15 -0500 | [diff] [blame] | 177 | /* Can't force performance level when the card is off */ |
| 178 | if ((adev->flags & AMD_IS_PX) && |
| 179 | (ddev->switch_power_state != DRM_SWITCH_POWER_ON)) |
| 180 | return -EINVAL; |
| 181 | |
Rex Zhu | cd4d746 | 2017-09-06 18:43:52 +0800 | [diff] [blame] | 182 | if (adev->powerplay.pp_funcs->get_performance_level) |
| 183 | current_level = amdgpu_dpm_get_performance_level(adev); |
Rex Zhu | 3bd5897 | 2016-12-23 15:24:37 +0800 | [diff] [blame] | 184 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 185 | if (strncmp("low", buf, strlen("low")) == 0) { |
Rex Zhu | e5d03ac | 2016-12-23 14:39:41 +0800 | [diff] [blame] | 186 | level = AMD_DPM_FORCED_LEVEL_LOW; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 187 | } else if (strncmp("high", buf, strlen("high")) == 0) { |
Rex Zhu | e5d03ac | 2016-12-23 14:39:41 +0800 | [diff] [blame] | 188 | level = AMD_DPM_FORCED_LEVEL_HIGH; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 189 | } else if (strncmp("auto", buf, strlen("auto")) == 0) { |
Rex Zhu | e5d03ac | 2016-12-23 14:39:41 +0800 | [diff] [blame] | 190 | level = AMD_DPM_FORCED_LEVEL_AUTO; |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 191 | } else if (strncmp("manual", buf, strlen("manual")) == 0) { |
Rex Zhu | e5d03ac | 2016-12-23 14:39:41 +0800 | [diff] [blame] | 192 | level = AMD_DPM_FORCED_LEVEL_MANUAL; |
Rex Zhu | 570272d | 2017-01-06 13:32:49 +0800 | [diff] [blame] | 193 | } else if (strncmp("profile_exit", buf, strlen("profile_exit")) == 0) { |
| 194 | level = AMD_DPM_FORCED_LEVEL_PROFILE_EXIT; |
| 195 | } else if (strncmp("profile_standard", buf, strlen("profile_standard")) == 0) { |
| 196 | level = AMD_DPM_FORCED_LEVEL_PROFILE_STANDARD; |
| 197 | } else if (strncmp("profile_min_sclk", buf, strlen("profile_min_sclk")) == 0) { |
| 198 | level = AMD_DPM_FORCED_LEVEL_PROFILE_MIN_SCLK; |
| 199 | } else if (strncmp("profile_min_mclk", buf, strlen("profile_min_mclk")) == 0) { |
| 200 | level = AMD_DPM_FORCED_LEVEL_PROFILE_MIN_MCLK; |
| 201 | } else if (strncmp("profile_peak", buf, strlen("profile_peak")) == 0) { |
| 202 | level = AMD_DPM_FORCED_LEVEL_PROFILE_PEAK; |
| 203 | } else { |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 204 | count = -EINVAL; |
| 205 | goto fail; |
| 206 | } |
Rex Zhu | 1b5708f | 2015-11-10 18:25:24 -0500 | [diff] [blame] | 207 | |
Rex Zhu | 3bd5897 | 2016-12-23 15:24:37 +0800 | [diff] [blame] | 208 | if (current_level == level) |
Rex Zhu | 8e7afd3 | 2017-01-09 15:18:01 +0800 | [diff] [blame] | 209 | return count; |
Rex Zhu | 3bd5897 | 2016-12-23 15:24:37 +0800 | [diff] [blame] | 210 | |
Rex Zhu | cd4d746 | 2017-09-06 18:43:52 +0800 | [diff] [blame] | 211 | if (adev->powerplay.pp_funcs->force_performance_level) { |
Rex Zhu | 1b5708f | 2015-11-10 18:25:24 -0500 | [diff] [blame] | 212 | mutex_lock(&adev->pm.mutex); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 213 | if (adev->pm.dpm.thermal_active) { |
| 214 | count = -EINVAL; |
Alex Deucher | 10f950f | 2016-02-19 15:18:45 -0500 | [diff] [blame] | 215 | mutex_unlock(&adev->pm.mutex); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 216 | goto fail; |
| 217 | } |
| 218 | ret = amdgpu_dpm_force_performance_level(adev, level); |
| 219 | if (ret) |
| 220 | count = -EINVAL; |
Rex Zhu | 1b5708f | 2015-11-10 18:25:24 -0500 | [diff] [blame] | 221 | else |
| 222 | adev->pm.dpm.forced_level = level; |
| 223 | mutex_unlock(&adev->pm.mutex); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 224 | } |
Rex Zhu | 570272d | 2017-01-06 13:32:49 +0800 | [diff] [blame] | 225 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 226 | fail: |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 227 | return count; |
| 228 | } |
| 229 | |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 230 | static ssize_t amdgpu_get_pp_num_states(struct device *dev, |
| 231 | struct device_attribute *attr, |
| 232 | char *buf) |
| 233 | { |
| 234 | struct drm_device *ddev = dev_get_drvdata(dev); |
| 235 | struct amdgpu_device *adev = ddev->dev_private; |
| 236 | struct pp_states_info data; |
| 237 | int i, buf_len; |
| 238 | |
Rex Zhu | cd4d746 | 2017-09-06 18:43:52 +0800 | [diff] [blame] | 239 | if (adev->powerplay.pp_funcs->get_pp_num_states) |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 240 | amdgpu_dpm_get_pp_num_states(adev, &data); |
| 241 | |
| 242 | buf_len = snprintf(buf, PAGE_SIZE, "states: %d\n", data.nums); |
| 243 | for (i = 0; i < data.nums; i++) |
| 244 | buf_len += snprintf(buf + buf_len, PAGE_SIZE, "%d %s\n", i, |
| 245 | (data.states[i] == POWER_STATE_TYPE_INTERNAL_BOOT) ? "boot" : |
| 246 | (data.states[i] == POWER_STATE_TYPE_BATTERY) ? "battery" : |
| 247 | (data.states[i] == POWER_STATE_TYPE_BALANCED) ? "balanced" : |
| 248 | (data.states[i] == POWER_STATE_TYPE_PERFORMANCE) ? "performance" : "default"); |
| 249 | |
| 250 | return buf_len; |
| 251 | } |
| 252 | |
| 253 | static ssize_t amdgpu_get_pp_cur_state(struct device *dev, |
| 254 | struct device_attribute *attr, |
| 255 | char *buf) |
| 256 | { |
| 257 | struct drm_device *ddev = dev_get_drvdata(dev); |
| 258 | struct amdgpu_device *adev = ddev->dev_private; |
| 259 | struct pp_states_info data; |
| 260 | enum amd_pm_state_type pm = 0; |
| 261 | int i = 0; |
| 262 | |
Rex Zhu | cd4d746 | 2017-09-06 18:43:52 +0800 | [diff] [blame] | 263 | if (adev->powerplay.pp_funcs->get_current_power_state |
| 264 | && adev->powerplay.pp_funcs->get_pp_num_states) { |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 265 | pm = amdgpu_dpm_get_current_power_state(adev); |
| 266 | amdgpu_dpm_get_pp_num_states(adev, &data); |
| 267 | |
| 268 | for (i = 0; i < data.nums; i++) { |
| 269 | if (pm == data.states[i]) |
| 270 | break; |
| 271 | } |
| 272 | |
| 273 | if (i == data.nums) |
| 274 | i = -EINVAL; |
| 275 | } |
| 276 | |
| 277 | return snprintf(buf, PAGE_SIZE, "%d\n", i); |
| 278 | } |
| 279 | |
| 280 | static ssize_t amdgpu_get_pp_force_state(struct device *dev, |
| 281 | struct device_attribute *attr, |
| 282 | char *buf) |
| 283 | { |
| 284 | struct drm_device *ddev = dev_get_drvdata(dev); |
| 285 | struct amdgpu_device *adev = ddev->dev_private; |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 286 | |
Rex Zhu | cd4d746 | 2017-09-06 18:43:52 +0800 | [diff] [blame] | 287 | if (adev->pp_force_state_enabled) |
| 288 | return amdgpu_get_pp_cur_state(dev, attr, buf); |
| 289 | else |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 290 | return snprintf(buf, PAGE_SIZE, "\n"); |
| 291 | } |
| 292 | |
| 293 | static ssize_t amdgpu_set_pp_force_state(struct device *dev, |
| 294 | struct device_attribute *attr, |
| 295 | const char *buf, |
| 296 | size_t count) |
| 297 | { |
| 298 | struct drm_device *ddev = dev_get_drvdata(dev); |
| 299 | struct amdgpu_device *adev = ddev->dev_private; |
| 300 | enum amd_pm_state_type state = 0; |
Dan Carpenter | 041bf02 | 2016-06-16 11:30:23 +0300 | [diff] [blame] | 301 | unsigned long idx; |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 302 | int ret; |
| 303 | |
| 304 | if (strlen(buf) == 1) |
| 305 | adev->pp_force_state_enabled = false; |
Dan Carpenter | 041bf02 | 2016-06-16 11:30:23 +0300 | [diff] [blame] | 306 | else if (adev->pp_enabled) { |
| 307 | struct pp_states_info data; |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 308 | |
Dan Carpenter | 041bf02 | 2016-06-16 11:30:23 +0300 | [diff] [blame] | 309 | ret = kstrtoul(buf, 0, &idx); |
| 310 | if (ret || idx >= ARRAY_SIZE(data.states)) { |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 311 | count = -EINVAL; |
| 312 | goto fail; |
| 313 | } |
| 314 | |
Dan Carpenter | 041bf02 | 2016-06-16 11:30:23 +0300 | [diff] [blame] | 315 | amdgpu_dpm_get_pp_num_states(adev, &data); |
| 316 | state = data.states[idx]; |
| 317 | /* only set user selected power states */ |
| 318 | if (state != POWER_STATE_TYPE_INTERNAL_BOOT && |
| 319 | state != POWER_STATE_TYPE_DEFAULT) { |
| 320 | amdgpu_dpm_dispatch_task(adev, |
Rex Zhu | df1e639 | 2017-09-01 13:46:20 +0800 | [diff] [blame] | 321 | AMD_PP_TASK_ENABLE_USER_STATE, &state, NULL); |
Dan Carpenter | 041bf02 | 2016-06-16 11:30:23 +0300 | [diff] [blame] | 322 | adev->pp_force_state_enabled = true; |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 323 | } |
| 324 | } |
| 325 | fail: |
| 326 | return count; |
| 327 | } |
| 328 | |
| 329 | static ssize_t amdgpu_get_pp_table(struct device *dev, |
| 330 | struct device_attribute *attr, |
| 331 | char *buf) |
| 332 | { |
| 333 | struct drm_device *ddev = dev_get_drvdata(dev); |
| 334 | struct amdgpu_device *adev = ddev->dev_private; |
| 335 | char *table = NULL; |
Eric Huang | 1684d3b | 2016-07-28 17:25:01 -0400 | [diff] [blame] | 336 | int size; |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 337 | |
Rex Zhu | cd4d746 | 2017-09-06 18:43:52 +0800 | [diff] [blame] | 338 | if (adev->powerplay.pp_funcs->get_pp_table) |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 339 | size = amdgpu_dpm_get_pp_table(adev, &table); |
| 340 | else |
| 341 | return 0; |
| 342 | |
| 343 | if (size >= PAGE_SIZE) |
| 344 | size = PAGE_SIZE - 1; |
| 345 | |
Eric Huang | 1684d3b | 2016-07-28 17:25:01 -0400 | [diff] [blame] | 346 | memcpy(buf, table, size); |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 347 | |
| 348 | return size; |
| 349 | } |
| 350 | |
| 351 | static ssize_t amdgpu_set_pp_table(struct device *dev, |
| 352 | struct device_attribute *attr, |
| 353 | const char *buf, |
| 354 | size_t count) |
| 355 | { |
| 356 | struct drm_device *ddev = dev_get_drvdata(dev); |
| 357 | struct amdgpu_device *adev = ddev->dev_private; |
| 358 | |
Rex Zhu | cd4d746 | 2017-09-06 18:43:52 +0800 | [diff] [blame] | 359 | if (adev->powerplay.pp_funcs->set_pp_table) |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 360 | amdgpu_dpm_set_pp_table(adev, buf, count); |
| 361 | |
| 362 | return count; |
| 363 | } |
| 364 | |
| 365 | static ssize_t amdgpu_get_pp_dpm_sclk(struct device *dev, |
| 366 | struct device_attribute *attr, |
| 367 | char *buf) |
| 368 | { |
| 369 | struct drm_device *ddev = dev_get_drvdata(dev); |
| 370 | struct amdgpu_device *adev = ddev->dev_private; |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 371 | |
Rex Zhu | cd4d746 | 2017-09-06 18:43:52 +0800 | [diff] [blame] | 372 | if (adev->powerplay.pp_funcs->print_clock_levels) |
| 373 | return amdgpu_dpm_print_clock_levels(adev, PP_SCLK, buf); |
| 374 | else |
| 375 | return snprintf(buf, PAGE_SIZE, "\n"); |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 376 | } |
| 377 | |
| 378 | static ssize_t amdgpu_set_pp_dpm_sclk(struct device *dev, |
| 379 | struct device_attribute *attr, |
| 380 | const char *buf, |
| 381 | size_t count) |
| 382 | { |
| 383 | struct drm_device *ddev = dev_get_drvdata(dev); |
| 384 | struct amdgpu_device *adev = ddev->dev_private; |
| 385 | int ret; |
| 386 | long level; |
Eric Huang | 5632708 | 2016-04-12 14:57:23 -0400 | [diff] [blame] | 387 | uint32_t i, mask = 0; |
| 388 | char sub_str[2]; |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 389 | |
Eric Huang | 14b3307 | 2016-06-14 15:08:22 -0400 | [diff] [blame] | 390 | for (i = 0; i < strlen(buf); i++) { |
| 391 | if (*(buf + i) == '\n') |
| 392 | continue; |
Eric Huang | 5632708 | 2016-04-12 14:57:23 -0400 | [diff] [blame] | 393 | sub_str[0] = *(buf + i); |
| 394 | sub_str[1] = '\0'; |
| 395 | ret = kstrtol(sub_str, 0, &level); |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 396 | |
Eric Huang | 5632708 | 2016-04-12 14:57:23 -0400 | [diff] [blame] | 397 | if (ret) { |
| 398 | count = -EINVAL; |
| 399 | goto fail; |
| 400 | } |
| 401 | mask |= 1 << level; |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 402 | } |
| 403 | |
Rex Zhu | cd4d746 | 2017-09-06 18:43:52 +0800 | [diff] [blame] | 404 | if (adev->powerplay.pp_funcs->force_clock_level) |
Eric Huang | 5632708 | 2016-04-12 14:57:23 -0400 | [diff] [blame] | 405 | amdgpu_dpm_force_clock_level(adev, PP_SCLK, mask); |
Rex Zhu | cd4d746 | 2017-09-06 18:43:52 +0800 | [diff] [blame] | 406 | |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 407 | fail: |
| 408 | return count; |
| 409 | } |
| 410 | |
| 411 | static ssize_t amdgpu_get_pp_dpm_mclk(struct device *dev, |
| 412 | struct device_attribute *attr, |
| 413 | char *buf) |
| 414 | { |
| 415 | struct drm_device *ddev = dev_get_drvdata(dev); |
| 416 | struct amdgpu_device *adev = ddev->dev_private; |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 417 | |
Rex Zhu | cd4d746 | 2017-09-06 18:43:52 +0800 | [diff] [blame] | 418 | if (adev->powerplay.pp_funcs->print_clock_levels) |
| 419 | return amdgpu_dpm_print_clock_levels(adev, PP_MCLK, buf); |
| 420 | else |
| 421 | return snprintf(buf, PAGE_SIZE, "\n"); |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 422 | } |
| 423 | |
| 424 | static ssize_t amdgpu_set_pp_dpm_mclk(struct device *dev, |
| 425 | struct device_attribute *attr, |
| 426 | const char *buf, |
| 427 | size_t count) |
| 428 | { |
| 429 | struct drm_device *ddev = dev_get_drvdata(dev); |
| 430 | struct amdgpu_device *adev = ddev->dev_private; |
| 431 | int ret; |
| 432 | long level; |
Eric Huang | 5632708 | 2016-04-12 14:57:23 -0400 | [diff] [blame] | 433 | uint32_t i, mask = 0; |
| 434 | char sub_str[2]; |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 435 | |
Eric Huang | 14b3307 | 2016-06-14 15:08:22 -0400 | [diff] [blame] | 436 | for (i = 0; i < strlen(buf); i++) { |
| 437 | if (*(buf + i) == '\n') |
| 438 | continue; |
Eric Huang | 5632708 | 2016-04-12 14:57:23 -0400 | [diff] [blame] | 439 | sub_str[0] = *(buf + i); |
| 440 | sub_str[1] = '\0'; |
| 441 | ret = kstrtol(sub_str, 0, &level); |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 442 | |
Eric Huang | 5632708 | 2016-04-12 14:57:23 -0400 | [diff] [blame] | 443 | if (ret) { |
| 444 | count = -EINVAL; |
| 445 | goto fail; |
| 446 | } |
| 447 | mask |= 1 << level; |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 448 | } |
Rex Zhu | cd4d746 | 2017-09-06 18:43:52 +0800 | [diff] [blame] | 449 | if (adev->powerplay.pp_funcs->force_clock_level) |
Eric Huang | 5632708 | 2016-04-12 14:57:23 -0400 | [diff] [blame] | 450 | amdgpu_dpm_force_clock_level(adev, PP_MCLK, mask); |
Rex Zhu | cd4d746 | 2017-09-06 18:43:52 +0800 | [diff] [blame] | 451 | |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 452 | fail: |
| 453 | return count; |
| 454 | } |
| 455 | |
| 456 | static ssize_t amdgpu_get_pp_dpm_pcie(struct device *dev, |
| 457 | struct device_attribute *attr, |
| 458 | char *buf) |
| 459 | { |
| 460 | struct drm_device *ddev = dev_get_drvdata(dev); |
| 461 | struct amdgpu_device *adev = ddev->dev_private; |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 462 | |
Rex Zhu | cd4d746 | 2017-09-06 18:43:52 +0800 | [diff] [blame] | 463 | if (adev->powerplay.pp_funcs->print_clock_levels) |
| 464 | return amdgpu_dpm_print_clock_levels(adev, PP_PCIE, buf); |
| 465 | else |
| 466 | return snprintf(buf, PAGE_SIZE, "\n"); |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 467 | } |
| 468 | |
| 469 | static ssize_t amdgpu_set_pp_dpm_pcie(struct device *dev, |
| 470 | struct device_attribute *attr, |
| 471 | const char *buf, |
| 472 | size_t count) |
| 473 | { |
| 474 | struct drm_device *ddev = dev_get_drvdata(dev); |
| 475 | struct amdgpu_device *adev = ddev->dev_private; |
| 476 | int ret; |
| 477 | long level; |
Eric Huang | 5632708 | 2016-04-12 14:57:23 -0400 | [diff] [blame] | 478 | uint32_t i, mask = 0; |
| 479 | char sub_str[2]; |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 480 | |
Eric Huang | 14b3307 | 2016-06-14 15:08:22 -0400 | [diff] [blame] | 481 | for (i = 0; i < strlen(buf); i++) { |
| 482 | if (*(buf + i) == '\n') |
| 483 | continue; |
Eric Huang | 5632708 | 2016-04-12 14:57:23 -0400 | [diff] [blame] | 484 | sub_str[0] = *(buf + i); |
| 485 | sub_str[1] = '\0'; |
| 486 | ret = kstrtol(sub_str, 0, &level); |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 487 | |
Eric Huang | 5632708 | 2016-04-12 14:57:23 -0400 | [diff] [blame] | 488 | if (ret) { |
| 489 | count = -EINVAL; |
| 490 | goto fail; |
| 491 | } |
| 492 | mask |= 1 << level; |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 493 | } |
Rex Zhu | cd4d746 | 2017-09-06 18:43:52 +0800 | [diff] [blame] | 494 | if (adev->powerplay.pp_funcs->force_clock_level) |
Eric Huang | 5632708 | 2016-04-12 14:57:23 -0400 | [diff] [blame] | 495 | amdgpu_dpm_force_clock_level(adev, PP_PCIE, mask); |
Rex Zhu | cd4d746 | 2017-09-06 18:43:52 +0800 | [diff] [blame] | 496 | |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 497 | fail: |
| 498 | return count; |
| 499 | } |
| 500 | |
Eric Huang | 428bafa | 2016-05-12 14:51:21 -0400 | [diff] [blame] | 501 | static ssize_t amdgpu_get_pp_sclk_od(struct device *dev, |
| 502 | struct device_attribute *attr, |
| 503 | char *buf) |
| 504 | { |
| 505 | struct drm_device *ddev = dev_get_drvdata(dev); |
| 506 | struct amdgpu_device *adev = ddev->dev_private; |
| 507 | uint32_t value = 0; |
| 508 | |
Rex Zhu | cd4d746 | 2017-09-06 18:43:52 +0800 | [diff] [blame] | 509 | if (adev->powerplay.pp_funcs->get_sclk_od) |
Eric Huang | 428bafa | 2016-05-12 14:51:21 -0400 | [diff] [blame] | 510 | value = amdgpu_dpm_get_sclk_od(adev); |
| 511 | |
| 512 | return snprintf(buf, PAGE_SIZE, "%d\n", value); |
| 513 | } |
| 514 | |
| 515 | static ssize_t amdgpu_set_pp_sclk_od(struct device *dev, |
| 516 | struct device_attribute *attr, |
| 517 | const char *buf, |
| 518 | size_t count) |
| 519 | { |
| 520 | struct drm_device *ddev = dev_get_drvdata(dev); |
| 521 | struct amdgpu_device *adev = ddev->dev_private; |
| 522 | int ret; |
| 523 | long int value; |
| 524 | |
| 525 | ret = kstrtol(buf, 0, &value); |
| 526 | |
| 527 | if (ret) { |
| 528 | count = -EINVAL; |
| 529 | goto fail; |
| 530 | } |
Rex Zhu | cd4d746 | 2017-09-06 18:43:52 +0800 | [diff] [blame] | 531 | if (adev->powerplay.pp_funcs->set_sclk_od) |
| 532 | amdgpu_dpm_set_sclk_od(adev, (uint32_t)value); |
Eric Huang | 428bafa | 2016-05-12 14:51:21 -0400 | [diff] [blame] | 533 | |
Eric Huang | 8b2e574 | 2016-05-19 15:46:10 -0400 | [diff] [blame] | 534 | if (adev->pp_enabled) { |
Rex Zhu | df1e639 | 2017-09-01 13:46:20 +0800 | [diff] [blame] | 535 | amdgpu_dpm_dispatch_task(adev, AMD_PP_TASK_READJUST_POWER_STATE, NULL, NULL); |
Rex Zhu | cd4d746 | 2017-09-06 18:43:52 +0800 | [diff] [blame] | 536 | } else { |
Eric Huang | 8b2e574 | 2016-05-19 15:46:10 -0400 | [diff] [blame] | 537 | adev->pm.dpm.current_ps = adev->pm.dpm.boot_ps; |
| 538 | amdgpu_pm_compute_clocks(adev); |
| 539 | } |
Eric Huang | 428bafa | 2016-05-12 14:51:21 -0400 | [diff] [blame] | 540 | |
| 541 | fail: |
| 542 | return count; |
| 543 | } |
| 544 | |
Eric Huang | f2bdc05 | 2016-05-24 15:11:17 -0400 | [diff] [blame] | 545 | static ssize_t amdgpu_get_pp_mclk_od(struct device *dev, |
| 546 | struct device_attribute *attr, |
| 547 | char *buf) |
| 548 | { |
| 549 | struct drm_device *ddev = dev_get_drvdata(dev); |
| 550 | struct amdgpu_device *adev = ddev->dev_private; |
| 551 | uint32_t value = 0; |
| 552 | |
Rex Zhu | cd4d746 | 2017-09-06 18:43:52 +0800 | [diff] [blame] | 553 | if (adev->powerplay.pp_funcs->get_mclk_od) |
Eric Huang | f2bdc05 | 2016-05-24 15:11:17 -0400 | [diff] [blame] | 554 | value = amdgpu_dpm_get_mclk_od(adev); |
Eric Huang | f2bdc05 | 2016-05-24 15:11:17 -0400 | [diff] [blame] | 555 | |
| 556 | return snprintf(buf, PAGE_SIZE, "%d\n", value); |
| 557 | } |
| 558 | |
| 559 | static ssize_t amdgpu_set_pp_mclk_od(struct device *dev, |
| 560 | struct device_attribute *attr, |
| 561 | const char *buf, |
| 562 | size_t count) |
| 563 | { |
| 564 | struct drm_device *ddev = dev_get_drvdata(dev); |
| 565 | struct amdgpu_device *adev = ddev->dev_private; |
| 566 | int ret; |
| 567 | long int value; |
| 568 | |
| 569 | ret = kstrtol(buf, 0, &value); |
| 570 | |
| 571 | if (ret) { |
| 572 | count = -EINVAL; |
| 573 | goto fail; |
| 574 | } |
Rex Zhu | cd4d746 | 2017-09-06 18:43:52 +0800 | [diff] [blame] | 575 | if (adev->powerplay.pp_funcs->set_mclk_od) |
| 576 | amdgpu_dpm_set_mclk_od(adev, (uint32_t)value); |
Eric Huang | f2bdc05 | 2016-05-24 15:11:17 -0400 | [diff] [blame] | 577 | |
| 578 | if (adev->pp_enabled) { |
Rex Zhu | df1e639 | 2017-09-01 13:46:20 +0800 | [diff] [blame] | 579 | amdgpu_dpm_dispatch_task(adev, AMD_PP_TASK_READJUST_POWER_STATE, NULL, NULL); |
Rex Zhu | cd4d746 | 2017-09-06 18:43:52 +0800 | [diff] [blame] | 580 | } else { |
Eric Huang | f2bdc05 | 2016-05-24 15:11:17 -0400 | [diff] [blame] | 581 | adev->pm.dpm.current_ps = adev->pm.dpm.boot_ps; |
| 582 | amdgpu_pm_compute_clocks(adev); |
| 583 | } |
| 584 | |
| 585 | fail: |
| 586 | return count; |
| 587 | } |
| 588 | |
Eric Huang | 34bb273 | 2016-09-12 16:17:44 -0400 | [diff] [blame] | 589 | static ssize_t amdgpu_get_pp_power_profile(struct device *dev, |
| 590 | char *buf, struct amd_pp_profile *query) |
| 591 | { |
| 592 | struct drm_device *ddev = dev_get_drvdata(dev); |
| 593 | struct amdgpu_device *adev = ddev->dev_private; |
Rex Zhu | cd4d746 | 2017-09-06 18:43:52 +0800 | [diff] [blame] | 594 | int ret = 0xff; |
Eric Huang | 34bb273 | 2016-09-12 16:17:44 -0400 | [diff] [blame] | 595 | |
Rex Zhu | cd4d746 | 2017-09-06 18:43:52 +0800 | [diff] [blame] | 596 | if (adev->powerplay.pp_funcs->get_power_profile_state) |
Eric Huang | 34bb273 | 2016-09-12 16:17:44 -0400 | [diff] [blame] | 597 | ret = amdgpu_dpm_get_power_profile_state( |
| 598 | adev, query); |
Eric Huang | 34bb273 | 2016-09-12 16:17:44 -0400 | [diff] [blame] | 599 | |
| 600 | if (ret) |
| 601 | return ret; |
| 602 | |
| 603 | return snprintf(buf, PAGE_SIZE, |
| 604 | "%d %d %d %d %d\n", |
| 605 | query->min_sclk / 100, |
| 606 | query->min_mclk / 100, |
| 607 | query->activity_threshold, |
| 608 | query->up_hyst, |
| 609 | query->down_hyst); |
| 610 | } |
| 611 | |
| 612 | static ssize_t amdgpu_get_pp_gfx_power_profile(struct device *dev, |
| 613 | struct device_attribute *attr, |
| 614 | char *buf) |
| 615 | { |
| 616 | struct amd_pp_profile query = {0}; |
| 617 | |
| 618 | query.type = AMD_PP_GFX_PROFILE; |
| 619 | |
| 620 | return amdgpu_get_pp_power_profile(dev, buf, &query); |
| 621 | } |
| 622 | |
| 623 | static ssize_t amdgpu_get_pp_compute_power_profile(struct device *dev, |
| 624 | struct device_attribute *attr, |
| 625 | char *buf) |
| 626 | { |
| 627 | struct amd_pp_profile query = {0}; |
| 628 | |
| 629 | query.type = AMD_PP_COMPUTE_PROFILE; |
| 630 | |
| 631 | return amdgpu_get_pp_power_profile(dev, buf, &query); |
| 632 | } |
| 633 | |
| 634 | static ssize_t amdgpu_set_pp_power_profile(struct device *dev, |
| 635 | const char *buf, |
| 636 | size_t count, |
| 637 | struct amd_pp_profile *request) |
| 638 | { |
| 639 | struct drm_device *ddev = dev_get_drvdata(dev); |
| 640 | struct amdgpu_device *adev = ddev->dev_private; |
| 641 | uint32_t loop = 0; |
| 642 | char *sub_str, buf_cpy[128], *tmp_str; |
| 643 | const char delimiter[3] = {' ', '\n', '\0'}; |
| 644 | long int value; |
Rex Zhu | cd4d746 | 2017-09-06 18:43:52 +0800 | [diff] [blame] | 645 | int ret = 0xff; |
Eric Huang | 34bb273 | 2016-09-12 16:17:44 -0400 | [diff] [blame] | 646 | |
| 647 | if (strncmp("reset", buf, strlen("reset")) == 0) { |
Rex Zhu | cd4d746 | 2017-09-06 18:43:52 +0800 | [diff] [blame] | 648 | if (adev->powerplay.pp_funcs->reset_power_profile_state) |
Eric Huang | 34bb273 | 2016-09-12 16:17:44 -0400 | [diff] [blame] | 649 | ret = amdgpu_dpm_reset_power_profile_state( |
| 650 | adev, request); |
Eric Huang | 34bb273 | 2016-09-12 16:17:44 -0400 | [diff] [blame] | 651 | if (ret) { |
| 652 | count = -EINVAL; |
| 653 | goto fail; |
| 654 | } |
| 655 | return count; |
| 656 | } |
| 657 | |
| 658 | if (strncmp("set", buf, strlen("set")) == 0) { |
Rex Zhu | cd4d746 | 2017-09-06 18:43:52 +0800 | [diff] [blame] | 659 | if (adev->powerplay.pp_funcs->set_power_profile_state) |
Eric Huang | 34bb273 | 2016-09-12 16:17:44 -0400 | [diff] [blame] | 660 | ret = amdgpu_dpm_set_power_profile_state( |
| 661 | adev, request); |
Rex Zhu | cd4d746 | 2017-09-06 18:43:52 +0800 | [diff] [blame] | 662 | |
Eric Huang | 34bb273 | 2016-09-12 16:17:44 -0400 | [diff] [blame] | 663 | if (ret) { |
| 664 | count = -EINVAL; |
| 665 | goto fail; |
| 666 | } |
| 667 | return count; |
| 668 | } |
| 669 | |
| 670 | if (count + 1 >= 128) { |
| 671 | count = -EINVAL; |
| 672 | goto fail; |
| 673 | } |
| 674 | |
| 675 | memcpy(buf_cpy, buf, count + 1); |
| 676 | tmp_str = buf_cpy; |
| 677 | |
| 678 | while (tmp_str[0]) { |
| 679 | sub_str = strsep(&tmp_str, delimiter); |
| 680 | ret = kstrtol(sub_str, 0, &value); |
| 681 | if (ret) { |
| 682 | count = -EINVAL; |
| 683 | goto fail; |
| 684 | } |
| 685 | |
| 686 | switch (loop) { |
| 687 | case 0: |
| 688 | /* input unit MHz convert to dpm table unit 10KHz*/ |
| 689 | request->min_sclk = (uint32_t)value * 100; |
| 690 | break; |
| 691 | case 1: |
| 692 | /* input unit MHz convert to dpm table unit 10KHz*/ |
| 693 | request->min_mclk = (uint32_t)value * 100; |
| 694 | break; |
| 695 | case 2: |
| 696 | request->activity_threshold = (uint16_t)value; |
| 697 | break; |
| 698 | case 3: |
| 699 | request->up_hyst = (uint8_t)value; |
| 700 | break; |
| 701 | case 4: |
| 702 | request->down_hyst = (uint8_t)value; |
| 703 | break; |
| 704 | default: |
| 705 | break; |
| 706 | } |
| 707 | |
| 708 | loop++; |
| 709 | } |
Rex Zhu | cd4d746 | 2017-09-06 18:43:52 +0800 | [diff] [blame] | 710 | if (adev->powerplay.pp_funcs->set_power_profile_state) |
| 711 | ret = amdgpu_dpm_set_power_profile_state(adev, request); |
Eric Huang | 34bb273 | 2016-09-12 16:17:44 -0400 | [diff] [blame] | 712 | |
| 713 | if (ret) |
| 714 | count = -EINVAL; |
| 715 | |
| 716 | fail: |
| 717 | return count; |
| 718 | } |
| 719 | |
| 720 | static ssize_t amdgpu_set_pp_gfx_power_profile(struct device *dev, |
| 721 | struct device_attribute *attr, |
| 722 | const char *buf, |
| 723 | size_t count) |
| 724 | { |
| 725 | struct amd_pp_profile request = {0}; |
| 726 | |
| 727 | request.type = AMD_PP_GFX_PROFILE; |
| 728 | |
| 729 | return amdgpu_set_pp_power_profile(dev, buf, count, &request); |
| 730 | } |
| 731 | |
| 732 | static ssize_t amdgpu_set_pp_compute_power_profile(struct device *dev, |
| 733 | struct device_attribute *attr, |
| 734 | const char *buf, |
| 735 | size_t count) |
| 736 | { |
| 737 | struct amd_pp_profile request = {0}; |
| 738 | |
| 739 | request.type = AMD_PP_COMPUTE_PROFILE; |
| 740 | |
| 741 | return amdgpu_set_pp_power_profile(dev, buf, count, &request); |
| 742 | } |
| 743 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 744 | static DEVICE_ATTR(power_dpm_state, S_IRUGO | S_IWUSR, amdgpu_get_dpm_state, amdgpu_set_dpm_state); |
| 745 | static DEVICE_ATTR(power_dpm_force_performance_level, S_IRUGO | S_IWUSR, |
| 746 | amdgpu_get_dpm_forced_performance_level, |
| 747 | amdgpu_set_dpm_forced_performance_level); |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 748 | static DEVICE_ATTR(pp_num_states, S_IRUGO, amdgpu_get_pp_num_states, NULL); |
| 749 | static DEVICE_ATTR(pp_cur_state, S_IRUGO, amdgpu_get_pp_cur_state, NULL); |
| 750 | static DEVICE_ATTR(pp_force_state, S_IRUGO | S_IWUSR, |
| 751 | amdgpu_get_pp_force_state, |
| 752 | amdgpu_set_pp_force_state); |
| 753 | static DEVICE_ATTR(pp_table, S_IRUGO | S_IWUSR, |
| 754 | amdgpu_get_pp_table, |
| 755 | amdgpu_set_pp_table); |
| 756 | static DEVICE_ATTR(pp_dpm_sclk, S_IRUGO | S_IWUSR, |
| 757 | amdgpu_get_pp_dpm_sclk, |
| 758 | amdgpu_set_pp_dpm_sclk); |
| 759 | static DEVICE_ATTR(pp_dpm_mclk, S_IRUGO | S_IWUSR, |
| 760 | amdgpu_get_pp_dpm_mclk, |
| 761 | amdgpu_set_pp_dpm_mclk); |
| 762 | static DEVICE_ATTR(pp_dpm_pcie, S_IRUGO | S_IWUSR, |
| 763 | amdgpu_get_pp_dpm_pcie, |
| 764 | amdgpu_set_pp_dpm_pcie); |
Eric Huang | 428bafa | 2016-05-12 14:51:21 -0400 | [diff] [blame] | 765 | static DEVICE_ATTR(pp_sclk_od, S_IRUGO | S_IWUSR, |
| 766 | amdgpu_get_pp_sclk_od, |
| 767 | amdgpu_set_pp_sclk_od); |
Eric Huang | f2bdc05 | 2016-05-24 15:11:17 -0400 | [diff] [blame] | 768 | static DEVICE_ATTR(pp_mclk_od, S_IRUGO | S_IWUSR, |
| 769 | amdgpu_get_pp_mclk_od, |
| 770 | amdgpu_set_pp_mclk_od); |
Eric Huang | 34bb273 | 2016-09-12 16:17:44 -0400 | [diff] [blame] | 771 | static DEVICE_ATTR(pp_gfx_power_profile, S_IRUGO | S_IWUSR, |
| 772 | amdgpu_get_pp_gfx_power_profile, |
| 773 | amdgpu_set_pp_gfx_power_profile); |
| 774 | static DEVICE_ATTR(pp_compute_power_profile, S_IRUGO | S_IWUSR, |
| 775 | amdgpu_get_pp_compute_power_profile, |
| 776 | amdgpu_set_pp_compute_power_profile); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 777 | |
| 778 | static ssize_t amdgpu_hwmon_show_temp(struct device *dev, |
| 779 | struct device_attribute *attr, |
| 780 | char *buf) |
| 781 | { |
| 782 | struct amdgpu_device *adev = dev_get_drvdata(dev); |
Alex Deucher | 0c67df4 | 2016-02-19 15:30:15 -0500 | [diff] [blame] | 783 | struct drm_device *ddev = adev->ddev; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 784 | int temp; |
| 785 | |
Alex Deucher | 0c67df4 | 2016-02-19 15:30:15 -0500 | [diff] [blame] | 786 | /* Can't get temperature when the card is off */ |
| 787 | if ((adev->flags & AMD_IS_PX) && |
| 788 | (ddev->switch_power_state != DRM_SWITCH_POWER_ON)) |
| 789 | return -EINVAL; |
| 790 | |
Rex Zhu | cd4d746 | 2017-09-06 18:43:52 +0800 | [diff] [blame] | 791 | if (!adev->powerplay.pp_funcs->get_temperature) |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 792 | temp = 0; |
Rex Zhu | 8804b8d | 2015-11-10 18:29:11 -0500 | [diff] [blame] | 793 | else |
| 794 | temp = amdgpu_dpm_get_temperature(adev); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 795 | |
| 796 | return snprintf(buf, PAGE_SIZE, "%d\n", temp); |
| 797 | } |
| 798 | |
| 799 | static ssize_t amdgpu_hwmon_show_temp_thresh(struct device *dev, |
| 800 | struct device_attribute *attr, |
| 801 | char *buf) |
| 802 | { |
| 803 | struct amdgpu_device *adev = dev_get_drvdata(dev); |
| 804 | int hyst = to_sensor_dev_attr(attr)->index; |
| 805 | int temp; |
| 806 | |
| 807 | if (hyst) |
| 808 | temp = adev->pm.dpm.thermal.min_temp; |
| 809 | else |
| 810 | temp = adev->pm.dpm.thermal.max_temp; |
| 811 | |
| 812 | return snprintf(buf, PAGE_SIZE, "%d\n", temp); |
| 813 | } |
| 814 | |
| 815 | static ssize_t amdgpu_hwmon_get_pwm1_enable(struct device *dev, |
| 816 | struct device_attribute *attr, |
| 817 | char *buf) |
| 818 | { |
| 819 | struct amdgpu_device *adev = dev_get_drvdata(dev); |
| 820 | u32 pwm_mode = 0; |
| 821 | |
Rex Zhu | cd4d746 | 2017-09-06 18:43:52 +0800 | [diff] [blame] | 822 | if (!adev->powerplay.pp_funcs->get_fan_control_mode) |
Rex Zhu | 8804b8d | 2015-11-10 18:29:11 -0500 | [diff] [blame] | 823 | return -EINVAL; |
| 824 | |
| 825 | pwm_mode = amdgpu_dpm_get_fan_control_mode(adev); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 826 | |
Rex Zhu | aad22ca | 2017-05-05 16:56:45 +0800 | [diff] [blame] | 827 | return sprintf(buf, "%i\n", pwm_mode); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 828 | } |
| 829 | |
| 830 | static ssize_t amdgpu_hwmon_set_pwm1_enable(struct device *dev, |
| 831 | struct device_attribute *attr, |
| 832 | const char *buf, |
| 833 | size_t count) |
| 834 | { |
| 835 | struct amdgpu_device *adev = dev_get_drvdata(dev); |
| 836 | int err; |
| 837 | int value; |
| 838 | |
Rex Zhu | cd4d746 | 2017-09-06 18:43:52 +0800 | [diff] [blame] | 839 | if (!adev->powerplay.pp_funcs->set_fan_control_mode) |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 840 | return -EINVAL; |
| 841 | |
| 842 | err = kstrtoint(buf, 10, &value); |
| 843 | if (err) |
| 844 | return err; |
| 845 | |
Rex Zhu | aad22ca | 2017-05-05 16:56:45 +0800 | [diff] [blame] | 846 | amdgpu_dpm_set_fan_control_mode(adev, value); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 847 | |
| 848 | return count; |
| 849 | } |
| 850 | |
| 851 | static ssize_t amdgpu_hwmon_get_pwm1_min(struct device *dev, |
| 852 | struct device_attribute *attr, |
| 853 | char *buf) |
| 854 | { |
| 855 | return sprintf(buf, "%i\n", 0); |
| 856 | } |
| 857 | |
| 858 | static ssize_t amdgpu_hwmon_get_pwm1_max(struct device *dev, |
| 859 | struct device_attribute *attr, |
| 860 | char *buf) |
| 861 | { |
| 862 | return sprintf(buf, "%i\n", 255); |
| 863 | } |
| 864 | |
| 865 | static ssize_t amdgpu_hwmon_set_pwm1(struct device *dev, |
| 866 | struct device_attribute *attr, |
| 867 | const char *buf, size_t count) |
| 868 | { |
| 869 | struct amdgpu_device *adev = dev_get_drvdata(dev); |
| 870 | int err; |
| 871 | u32 value; |
| 872 | |
| 873 | err = kstrtou32(buf, 10, &value); |
| 874 | if (err) |
| 875 | return err; |
| 876 | |
| 877 | value = (value * 100) / 255; |
| 878 | |
Rex Zhu | cd4d746 | 2017-09-06 18:43:52 +0800 | [diff] [blame] | 879 | if (adev->powerplay.pp_funcs->set_fan_speed_percent) { |
| 880 | err = amdgpu_dpm_set_fan_speed_percent(adev, value); |
| 881 | if (err) |
| 882 | return err; |
| 883 | } |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 884 | |
| 885 | return count; |
| 886 | } |
| 887 | |
| 888 | static ssize_t amdgpu_hwmon_get_pwm1(struct device *dev, |
| 889 | struct device_attribute *attr, |
| 890 | char *buf) |
| 891 | { |
| 892 | struct amdgpu_device *adev = dev_get_drvdata(dev); |
| 893 | int err; |
Rex Zhu | cd4d746 | 2017-09-06 18:43:52 +0800 | [diff] [blame] | 894 | u32 speed = 0; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 895 | |
Rex Zhu | cd4d746 | 2017-09-06 18:43:52 +0800 | [diff] [blame] | 896 | if (adev->powerplay.pp_funcs->get_fan_speed_percent) { |
| 897 | err = amdgpu_dpm_get_fan_speed_percent(adev, &speed); |
| 898 | if (err) |
| 899 | return err; |
| 900 | } |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 901 | |
| 902 | speed = (speed * 255) / 100; |
| 903 | |
| 904 | return sprintf(buf, "%i\n", speed); |
| 905 | } |
| 906 | |
Grazvydas Ignotas | 81c1514 | 2016-10-29 23:28:59 +0300 | [diff] [blame] | 907 | static ssize_t amdgpu_hwmon_get_fan1_input(struct device *dev, |
| 908 | struct device_attribute *attr, |
| 909 | char *buf) |
| 910 | { |
| 911 | struct amdgpu_device *adev = dev_get_drvdata(dev); |
| 912 | int err; |
Rex Zhu | cd4d746 | 2017-09-06 18:43:52 +0800 | [diff] [blame] | 913 | u32 speed = 0; |
Grazvydas Ignotas | 81c1514 | 2016-10-29 23:28:59 +0300 | [diff] [blame] | 914 | |
Rex Zhu | cd4d746 | 2017-09-06 18:43:52 +0800 | [diff] [blame] | 915 | if (adev->powerplay.pp_funcs->get_fan_speed_rpm) { |
| 916 | err = amdgpu_dpm_get_fan_speed_rpm(adev, &speed); |
| 917 | if (err) |
| 918 | return err; |
| 919 | } |
Grazvydas Ignotas | 81c1514 | 2016-10-29 23:28:59 +0300 | [diff] [blame] | 920 | |
| 921 | return sprintf(buf, "%i\n", speed); |
| 922 | } |
| 923 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 924 | static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, amdgpu_hwmon_show_temp, NULL, 0); |
| 925 | static SENSOR_DEVICE_ATTR(temp1_crit, S_IRUGO, amdgpu_hwmon_show_temp_thresh, NULL, 0); |
| 926 | static SENSOR_DEVICE_ATTR(temp1_crit_hyst, S_IRUGO, amdgpu_hwmon_show_temp_thresh, NULL, 1); |
| 927 | static SENSOR_DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, amdgpu_hwmon_get_pwm1, amdgpu_hwmon_set_pwm1, 0); |
| 928 | static SENSOR_DEVICE_ATTR(pwm1_enable, S_IRUGO | S_IWUSR, amdgpu_hwmon_get_pwm1_enable, amdgpu_hwmon_set_pwm1_enable, 0); |
| 929 | static SENSOR_DEVICE_ATTR(pwm1_min, S_IRUGO, amdgpu_hwmon_get_pwm1_min, NULL, 0); |
| 930 | 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] | 931 | static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, amdgpu_hwmon_get_fan1_input, NULL, 0); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 932 | |
| 933 | static struct attribute *hwmon_attributes[] = { |
| 934 | &sensor_dev_attr_temp1_input.dev_attr.attr, |
| 935 | &sensor_dev_attr_temp1_crit.dev_attr.attr, |
| 936 | &sensor_dev_attr_temp1_crit_hyst.dev_attr.attr, |
| 937 | &sensor_dev_attr_pwm1.dev_attr.attr, |
| 938 | &sensor_dev_attr_pwm1_enable.dev_attr.attr, |
| 939 | &sensor_dev_attr_pwm1_min.dev_attr.attr, |
| 940 | &sensor_dev_attr_pwm1_max.dev_attr.attr, |
Grazvydas Ignotas | 81c1514 | 2016-10-29 23:28:59 +0300 | [diff] [blame] | 941 | &sensor_dev_attr_fan1_input.dev_attr.attr, |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 942 | NULL |
| 943 | }; |
| 944 | |
| 945 | static umode_t hwmon_attributes_visible(struct kobject *kobj, |
| 946 | struct attribute *attr, int index) |
| 947 | { |
Geliang Tang | cc29ec8 | 2016-01-13 22:48:42 +0800 | [diff] [blame] | 948 | struct device *dev = kobj_to_dev(kobj); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 949 | struct amdgpu_device *adev = dev_get_drvdata(dev); |
| 950 | umode_t effective_mode = attr->mode; |
| 951 | |
Rex Zhu | 1b5708f | 2015-11-10 18:25:24 -0500 | [diff] [blame] | 952 | /* Skip limit attributes if DPM is not enabled */ |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 953 | if (!adev->pm.dpm_enabled && |
| 954 | (attr == &sensor_dev_attr_temp1_crit.dev_attr.attr || |
Alex Deucher | 2710073 | 2015-10-19 15:49:11 -0400 | [diff] [blame] | 955 | attr == &sensor_dev_attr_temp1_crit_hyst.dev_attr.attr || |
| 956 | attr == &sensor_dev_attr_pwm1.dev_attr.attr || |
| 957 | attr == &sensor_dev_attr_pwm1_enable.dev_attr.attr || |
| 958 | attr == &sensor_dev_attr_pwm1_max.dev_attr.attr || |
| 959 | attr == &sensor_dev_attr_pwm1_min.dev_attr.attr)) |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 960 | return 0; |
| 961 | |
Jammy Zhou | e61710c | 2015-11-10 18:31:08 -0500 | [diff] [blame] | 962 | if (adev->pp_enabled) |
Rex Zhu | 8804b8d | 2015-11-10 18:29:11 -0500 | [diff] [blame] | 963 | return effective_mode; |
| 964 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 965 | /* Skip fan attributes if fan is not present */ |
| 966 | if (adev->pm.no_fan && |
| 967 | (attr == &sensor_dev_attr_pwm1.dev_attr.attr || |
| 968 | attr == &sensor_dev_attr_pwm1_enable.dev_attr.attr || |
| 969 | attr == &sensor_dev_attr_pwm1_max.dev_attr.attr || |
| 970 | attr == &sensor_dev_attr_pwm1_min.dev_attr.attr)) |
| 971 | return 0; |
| 972 | |
| 973 | /* 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] | 974 | if ((!adev->powerplay.pp_funcs->get_fan_speed_percent && |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 975 | attr == &sensor_dev_attr_pwm1.dev_attr.attr) || /* can't query fan */ |
Rex Zhu | cd4d746 | 2017-09-06 18:43:52 +0800 | [diff] [blame] | 976 | (!adev->powerplay.pp_funcs->get_fan_control_mode && |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 977 | attr == &sensor_dev_attr_pwm1_enable.dev_attr.attr)) /* can't query state */ |
| 978 | effective_mode &= ~S_IRUGO; |
| 979 | |
Rex Zhu | cd4d746 | 2017-09-06 18:43:52 +0800 | [diff] [blame] | 980 | if ((!adev->powerplay.pp_funcs->set_fan_speed_percent && |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 981 | attr == &sensor_dev_attr_pwm1.dev_attr.attr) || /* can't manage fan */ |
Rex Zhu | cd4d746 | 2017-09-06 18:43:52 +0800 | [diff] [blame] | 982 | (!adev->powerplay.pp_funcs->set_fan_control_mode && |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 983 | attr == &sensor_dev_attr_pwm1_enable.dev_attr.attr)) /* can't manage state */ |
| 984 | effective_mode &= ~S_IWUSR; |
| 985 | |
| 986 | /* 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] | 987 | if ((!adev->powerplay.pp_funcs->set_fan_speed_percent && |
| 988 | !adev->powerplay.pp_funcs->get_fan_speed_percent) && |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 989 | (attr == &sensor_dev_attr_pwm1_max.dev_attr.attr || |
| 990 | attr == &sensor_dev_attr_pwm1_min.dev_attr.attr)) |
| 991 | return 0; |
| 992 | |
Grazvydas Ignotas | 81c1514 | 2016-10-29 23:28:59 +0300 | [diff] [blame] | 993 | /* requires powerplay */ |
| 994 | if (attr == &sensor_dev_attr_fan1_input.dev_attr.attr) |
| 995 | return 0; |
| 996 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 997 | return effective_mode; |
| 998 | } |
| 999 | |
| 1000 | static const struct attribute_group hwmon_attrgroup = { |
| 1001 | .attrs = hwmon_attributes, |
| 1002 | .is_visible = hwmon_attributes_visible, |
| 1003 | }; |
| 1004 | |
| 1005 | static const struct attribute_group *hwmon_groups[] = { |
| 1006 | &hwmon_attrgroup, |
| 1007 | NULL |
| 1008 | }; |
| 1009 | |
| 1010 | void amdgpu_dpm_thermal_work_handler(struct work_struct *work) |
| 1011 | { |
| 1012 | struct amdgpu_device *adev = |
| 1013 | container_of(work, struct amdgpu_device, |
| 1014 | pm.dpm.thermal.work); |
| 1015 | /* switch to the thermal state */ |
Rex Zhu | 3a2c788 | 2015-08-25 15:57:43 +0800 | [diff] [blame] | 1016 | enum amd_pm_state_type dpm_state = POWER_STATE_TYPE_INTERNAL_THERMAL; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1017 | |
| 1018 | if (!adev->pm.dpm_enabled) |
| 1019 | return; |
| 1020 | |
Rex Zhu | cd4d746 | 2017-09-06 18:43:52 +0800 | [diff] [blame] | 1021 | if (adev->powerplay.pp_funcs->get_temperature) { |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1022 | int temp = amdgpu_dpm_get_temperature(adev); |
| 1023 | |
| 1024 | if (temp < adev->pm.dpm.thermal.min_temp) |
| 1025 | /* switch back the user state */ |
| 1026 | dpm_state = adev->pm.dpm.user_state; |
| 1027 | } else { |
| 1028 | if (adev->pm.dpm.thermal.high_to_low) |
| 1029 | /* switch back the user state */ |
| 1030 | dpm_state = adev->pm.dpm.user_state; |
| 1031 | } |
| 1032 | mutex_lock(&adev->pm.mutex); |
| 1033 | if (dpm_state == POWER_STATE_TYPE_INTERNAL_THERMAL) |
| 1034 | adev->pm.dpm.thermal_active = true; |
| 1035 | else |
| 1036 | adev->pm.dpm.thermal_active = false; |
| 1037 | adev->pm.dpm.state = dpm_state; |
| 1038 | mutex_unlock(&adev->pm.mutex); |
| 1039 | |
| 1040 | amdgpu_pm_compute_clocks(adev); |
| 1041 | } |
| 1042 | |
| 1043 | 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] | 1044 | enum amd_pm_state_type dpm_state) |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1045 | { |
| 1046 | int i; |
| 1047 | struct amdgpu_ps *ps; |
| 1048 | u32 ui_class; |
| 1049 | bool single_display = (adev->pm.dpm.new_active_crtc_count < 2) ? |
| 1050 | true : false; |
| 1051 | |
| 1052 | /* check if the vblank period is too short to adjust the mclk */ |
Rex Zhu | cd4d746 | 2017-09-06 18:43:52 +0800 | [diff] [blame] | 1053 | if (single_display && adev->powerplay.pp_funcs->vblank_too_short) { |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1054 | if (amdgpu_dpm_vblank_too_short(adev)) |
| 1055 | single_display = false; |
| 1056 | } |
| 1057 | |
| 1058 | /* certain older asics have a separare 3D performance state, |
| 1059 | * so try that first if the user selected performance |
| 1060 | */ |
| 1061 | if (dpm_state == POWER_STATE_TYPE_PERFORMANCE) |
| 1062 | dpm_state = POWER_STATE_TYPE_INTERNAL_3DPERF; |
| 1063 | /* balanced states don't exist at the moment */ |
| 1064 | if (dpm_state == POWER_STATE_TYPE_BALANCED) |
| 1065 | dpm_state = POWER_STATE_TYPE_PERFORMANCE; |
| 1066 | |
| 1067 | restart_search: |
| 1068 | /* Pick the best power state based on current conditions */ |
| 1069 | for (i = 0; i < adev->pm.dpm.num_ps; i++) { |
| 1070 | ps = &adev->pm.dpm.ps[i]; |
| 1071 | ui_class = ps->class & ATOM_PPLIB_CLASSIFICATION_UI_MASK; |
| 1072 | switch (dpm_state) { |
| 1073 | /* user states */ |
| 1074 | case POWER_STATE_TYPE_BATTERY: |
| 1075 | if (ui_class == ATOM_PPLIB_CLASSIFICATION_UI_BATTERY) { |
| 1076 | if (ps->caps & ATOM_PPLIB_SINGLE_DISPLAY_ONLY) { |
| 1077 | if (single_display) |
| 1078 | return ps; |
| 1079 | } else |
| 1080 | return ps; |
| 1081 | } |
| 1082 | break; |
| 1083 | case POWER_STATE_TYPE_BALANCED: |
| 1084 | if (ui_class == ATOM_PPLIB_CLASSIFICATION_UI_BALANCED) { |
| 1085 | if (ps->caps & ATOM_PPLIB_SINGLE_DISPLAY_ONLY) { |
| 1086 | if (single_display) |
| 1087 | return ps; |
| 1088 | } else |
| 1089 | return ps; |
| 1090 | } |
| 1091 | break; |
| 1092 | case POWER_STATE_TYPE_PERFORMANCE: |
| 1093 | if (ui_class == ATOM_PPLIB_CLASSIFICATION_UI_PERFORMANCE) { |
| 1094 | if (ps->caps & ATOM_PPLIB_SINGLE_DISPLAY_ONLY) { |
| 1095 | if (single_display) |
| 1096 | return ps; |
| 1097 | } else |
| 1098 | return ps; |
| 1099 | } |
| 1100 | break; |
| 1101 | /* internal states */ |
| 1102 | case POWER_STATE_TYPE_INTERNAL_UVD: |
| 1103 | if (adev->pm.dpm.uvd_ps) |
| 1104 | return adev->pm.dpm.uvd_ps; |
| 1105 | else |
| 1106 | break; |
| 1107 | case POWER_STATE_TYPE_INTERNAL_UVD_SD: |
| 1108 | if (ps->class & ATOM_PPLIB_CLASSIFICATION_SDSTATE) |
| 1109 | return ps; |
| 1110 | break; |
| 1111 | case POWER_STATE_TYPE_INTERNAL_UVD_HD: |
| 1112 | if (ps->class & ATOM_PPLIB_CLASSIFICATION_HDSTATE) |
| 1113 | return ps; |
| 1114 | break; |
| 1115 | case POWER_STATE_TYPE_INTERNAL_UVD_HD2: |
| 1116 | if (ps->class & ATOM_PPLIB_CLASSIFICATION_HD2STATE) |
| 1117 | return ps; |
| 1118 | break; |
| 1119 | case POWER_STATE_TYPE_INTERNAL_UVD_MVC: |
| 1120 | if (ps->class2 & ATOM_PPLIB_CLASSIFICATION2_MVC) |
| 1121 | return ps; |
| 1122 | break; |
| 1123 | case POWER_STATE_TYPE_INTERNAL_BOOT: |
| 1124 | return adev->pm.dpm.boot_ps; |
| 1125 | case POWER_STATE_TYPE_INTERNAL_THERMAL: |
| 1126 | if (ps->class & ATOM_PPLIB_CLASSIFICATION_THERMAL) |
| 1127 | return ps; |
| 1128 | break; |
| 1129 | case POWER_STATE_TYPE_INTERNAL_ACPI: |
| 1130 | if (ps->class & ATOM_PPLIB_CLASSIFICATION_ACPI) |
| 1131 | return ps; |
| 1132 | break; |
| 1133 | case POWER_STATE_TYPE_INTERNAL_ULV: |
| 1134 | if (ps->class2 & ATOM_PPLIB_CLASSIFICATION2_ULV) |
| 1135 | return ps; |
| 1136 | break; |
| 1137 | case POWER_STATE_TYPE_INTERNAL_3DPERF: |
| 1138 | if (ps->class & ATOM_PPLIB_CLASSIFICATION_3DPERFORMANCE) |
| 1139 | return ps; |
| 1140 | break; |
| 1141 | default: |
| 1142 | break; |
| 1143 | } |
| 1144 | } |
| 1145 | /* use a fallback state if we didn't match */ |
| 1146 | switch (dpm_state) { |
| 1147 | case POWER_STATE_TYPE_INTERNAL_UVD_SD: |
| 1148 | dpm_state = POWER_STATE_TYPE_INTERNAL_UVD_HD; |
| 1149 | goto restart_search; |
| 1150 | case POWER_STATE_TYPE_INTERNAL_UVD_HD: |
| 1151 | case POWER_STATE_TYPE_INTERNAL_UVD_HD2: |
| 1152 | case POWER_STATE_TYPE_INTERNAL_UVD_MVC: |
| 1153 | if (adev->pm.dpm.uvd_ps) { |
| 1154 | return adev->pm.dpm.uvd_ps; |
| 1155 | } else { |
| 1156 | dpm_state = POWER_STATE_TYPE_PERFORMANCE; |
| 1157 | goto restart_search; |
| 1158 | } |
| 1159 | case POWER_STATE_TYPE_INTERNAL_THERMAL: |
| 1160 | dpm_state = POWER_STATE_TYPE_INTERNAL_ACPI; |
| 1161 | goto restart_search; |
| 1162 | case POWER_STATE_TYPE_INTERNAL_ACPI: |
| 1163 | dpm_state = POWER_STATE_TYPE_BATTERY; |
| 1164 | goto restart_search; |
| 1165 | case POWER_STATE_TYPE_BATTERY: |
| 1166 | case POWER_STATE_TYPE_BALANCED: |
| 1167 | case POWER_STATE_TYPE_INTERNAL_3DPERF: |
| 1168 | dpm_state = POWER_STATE_TYPE_PERFORMANCE; |
| 1169 | goto restart_search; |
| 1170 | default: |
| 1171 | break; |
| 1172 | } |
| 1173 | |
| 1174 | return NULL; |
| 1175 | } |
| 1176 | |
| 1177 | static void amdgpu_dpm_change_power_state_locked(struct amdgpu_device *adev) |
| 1178 | { |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1179 | struct amdgpu_ps *ps; |
Rex Zhu | 3a2c788 | 2015-08-25 15:57:43 +0800 | [diff] [blame] | 1180 | enum amd_pm_state_type dpm_state; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1181 | int ret; |
Rex Zhu | cd4d746 | 2017-09-06 18:43:52 +0800 | [diff] [blame] | 1182 | bool equal = false; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1183 | |
| 1184 | /* if dpm init failed */ |
| 1185 | if (!adev->pm.dpm_enabled) |
| 1186 | return; |
| 1187 | |
| 1188 | if (adev->pm.dpm.user_state != adev->pm.dpm.state) { |
| 1189 | /* add other state override checks here */ |
| 1190 | if ((!adev->pm.dpm.thermal_active) && |
| 1191 | (!adev->pm.dpm.uvd_active)) |
| 1192 | adev->pm.dpm.state = adev->pm.dpm.user_state; |
| 1193 | } |
| 1194 | dpm_state = adev->pm.dpm.state; |
| 1195 | |
| 1196 | ps = amdgpu_dpm_pick_power_state(adev, dpm_state); |
| 1197 | if (ps) |
| 1198 | adev->pm.dpm.requested_ps = ps; |
| 1199 | else |
| 1200 | return; |
| 1201 | |
Rex Zhu | cd4d746 | 2017-09-06 18:43:52 +0800 | [diff] [blame] | 1202 | if (amdgpu_dpm == 1 && adev->powerplay.pp_funcs->print_power_state) { |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1203 | printk("switching from power state:\n"); |
| 1204 | amdgpu_dpm_print_power_state(adev, adev->pm.dpm.current_ps); |
| 1205 | printk("switching to power state:\n"); |
| 1206 | amdgpu_dpm_print_power_state(adev, adev->pm.dpm.requested_ps); |
| 1207 | } |
| 1208 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1209 | /* update whether vce is active */ |
| 1210 | ps->vce_active = adev->pm.dpm.vce_active; |
Rex Zhu | cd4d746 | 2017-09-06 18:43:52 +0800 | [diff] [blame] | 1211 | if (adev->powerplay.pp_funcs->display_configuration_changed) |
| 1212 | amdgpu_dpm_display_configuration_changed(adev); |
Rex Zhu | 5e876c6 | 2016-10-14 19:23:34 +0800 | [diff] [blame] | 1213 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1214 | ret = amdgpu_dpm_pre_set_power_state(adev); |
| 1215 | if (ret) |
Christian König | a27de35 | 2016-01-21 11:28:53 +0100 | [diff] [blame] | 1216 | return; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1217 | |
Rex Zhu | cd4d746 | 2017-09-06 18:43:52 +0800 | [diff] [blame] | 1218 | if (adev->powerplay.pp_funcs->check_state_equal) { |
| 1219 | if (0 != amdgpu_dpm_check_state_equal(adev, adev->pm.dpm.current_ps, adev->pm.dpm.requested_ps, &equal)) |
| 1220 | equal = false; |
| 1221 | } |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1222 | |
Rex Zhu | 5e876c6 | 2016-10-14 19:23:34 +0800 | [diff] [blame] | 1223 | if (equal) |
| 1224 | return; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1225 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1226 | amdgpu_dpm_set_power_state(adev); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1227 | amdgpu_dpm_post_set_power_state(adev); |
| 1228 | |
Alex Deucher | eda1d1c | 2016-02-24 17:18:25 -0500 | [diff] [blame] | 1229 | adev->pm.dpm.current_active_crtcs = adev->pm.dpm.new_active_crtcs; |
| 1230 | adev->pm.dpm.current_active_crtc_count = adev->pm.dpm.new_active_crtc_count; |
| 1231 | |
Rex Zhu | cd4d746 | 2017-09-06 18:43:52 +0800 | [diff] [blame] | 1232 | if (adev->powerplay.pp_funcs->force_performance_level) { |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1233 | if (adev->pm.dpm.thermal_active) { |
Rex Zhu | e5d03ac | 2016-12-23 14:39:41 +0800 | [diff] [blame] | 1234 | enum amd_dpm_forced_level level = adev->pm.dpm.forced_level; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1235 | /* force low perf level for thermal */ |
Rex Zhu | e5d03ac | 2016-12-23 14:39:41 +0800 | [diff] [blame] | 1236 | amdgpu_dpm_force_performance_level(adev, AMD_DPM_FORCED_LEVEL_LOW); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1237 | /* save the user's level */ |
| 1238 | adev->pm.dpm.forced_level = level; |
| 1239 | } else { |
| 1240 | /* otherwise, user selected level */ |
| 1241 | amdgpu_dpm_force_performance_level(adev, adev->pm.dpm.forced_level); |
| 1242 | } |
| 1243 | } |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1244 | } |
| 1245 | |
| 1246 | void amdgpu_dpm_enable_uvd(struct amdgpu_device *adev, bool enable) |
| 1247 | { |
Rex Zhu | cd4d746 | 2017-09-06 18:43:52 +0800 | [diff] [blame] | 1248 | if (adev->powerplay.pp_funcs->powergate_uvd) { |
Tom St Denis | e95a14a | 2016-07-28 09:40:07 -0400 | [diff] [blame] | 1249 | /* enable/disable UVD */ |
| 1250 | mutex_lock(&adev->pm.mutex); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1251 | amdgpu_dpm_powergate_uvd(adev, !enable); |
Tom St Denis | e95a14a | 2016-07-28 09:40:07 -0400 | [diff] [blame] | 1252 | mutex_unlock(&adev->pm.mutex); |
| 1253 | } else { |
| 1254 | if (enable) { |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1255 | mutex_lock(&adev->pm.mutex); |
Tom St Denis | e95a14a | 2016-07-28 09:40:07 -0400 | [diff] [blame] | 1256 | adev->pm.dpm.uvd_active = true; |
| 1257 | adev->pm.dpm.state = POWER_STATE_TYPE_INTERNAL_UVD; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1258 | mutex_unlock(&adev->pm.mutex); |
| 1259 | } else { |
Tom St Denis | e95a14a | 2016-07-28 09:40:07 -0400 | [diff] [blame] | 1260 | mutex_lock(&adev->pm.mutex); |
| 1261 | adev->pm.dpm.uvd_active = false; |
| 1262 | mutex_unlock(&adev->pm.mutex); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1263 | } |
Tom St Denis | e95a14a | 2016-07-28 09:40:07 -0400 | [diff] [blame] | 1264 | amdgpu_pm_compute_clocks(adev); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1265 | } |
| 1266 | } |
| 1267 | |
| 1268 | void amdgpu_dpm_enable_vce(struct amdgpu_device *adev, bool enable) |
| 1269 | { |
Rex Zhu | cd4d746 | 2017-09-06 18:43:52 +0800 | [diff] [blame] | 1270 | if (adev->powerplay.pp_funcs->powergate_vce) { |
Tom St Denis | e95a14a | 2016-07-28 09:40:07 -0400 | [diff] [blame] | 1271 | /* enable/disable VCE */ |
| 1272 | mutex_lock(&adev->pm.mutex); |
Sonny Jiang | b7a0776 | 2015-05-28 15:47:53 -0400 | [diff] [blame] | 1273 | amdgpu_dpm_powergate_vce(adev, !enable); |
Tom St Denis | e95a14a | 2016-07-28 09:40:07 -0400 | [diff] [blame] | 1274 | mutex_unlock(&adev->pm.mutex); |
| 1275 | } else { |
| 1276 | if (enable) { |
Sonny Jiang | b7a0776 | 2015-05-28 15:47:53 -0400 | [diff] [blame] | 1277 | mutex_lock(&adev->pm.mutex); |
Tom St Denis | e95a14a | 2016-07-28 09:40:07 -0400 | [diff] [blame] | 1278 | adev->pm.dpm.vce_active = true; |
| 1279 | /* XXX select vce level based on ring/task */ |
Rex Zhu | 0d8de7c | 2016-10-12 15:13:29 +0800 | [diff] [blame] | 1280 | adev->pm.dpm.vce_level = AMD_VCE_LEVEL_AC_ALL; |
Sonny Jiang | b7a0776 | 2015-05-28 15:47:53 -0400 | [diff] [blame] | 1281 | mutex_unlock(&adev->pm.mutex); |
Rex Zhu | beeea98 | 2017-01-26 16:25:05 +0800 | [diff] [blame] | 1282 | amdgpu_set_clockgating_state(adev, AMD_IP_BLOCK_TYPE_VCE, |
| 1283 | AMD_CG_STATE_UNGATE); |
Rex Zhu | 03a5f1d | 2017-03-06 11:29:26 +0800 | [diff] [blame] | 1284 | amdgpu_set_powergating_state(adev, AMD_IP_BLOCK_TYPE_VCE, |
| 1285 | AMD_PG_STATE_UNGATE); |
| 1286 | amdgpu_pm_compute_clocks(adev); |
Sonny Jiang | b7a0776 | 2015-05-28 15:47:53 -0400 | [diff] [blame] | 1287 | } else { |
Rex Zhu | beeea98 | 2017-01-26 16:25:05 +0800 | [diff] [blame] | 1288 | amdgpu_set_powergating_state(adev, AMD_IP_BLOCK_TYPE_VCE, |
| 1289 | AMD_PG_STATE_GATE); |
| 1290 | amdgpu_set_clockgating_state(adev, AMD_IP_BLOCK_TYPE_VCE, |
| 1291 | AMD_CG_STATE_GATE); |
Tom St Denis | e95a14a | 2016-07-28 09:40:07 -0400 | [diff] [blame] | 1292 | mutex_lock(&adev->pm.mutex); |
| 1293 | adev->pm.dpm.vce_active = false; |
| 1294 | mutex_unlock(&adev->pm.mutex); |
Rex Zhu | beeea98 | 2017-01-26 16:25:05 +0800 | [diff] [blame] | 1295 | amdgpu_pm_compute_clocks(adev); |
Sonny Jiang | b7a0776 | 2015-05-28 15:47:53 -0400 | [diff] [blame] | 1296 | } |
Rex Zhu | beeea98 | 2017-01-26 16:25:05 +0800 | [diff] [blame] | 1297 | |
Sonny Jiang | b7a0776 | 2015-05-28 15:47:53 -0400 | [diff] [blame] | 1298 | } |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1299 | } |
| 1300 | |
| 1301 | void amdgpu_pm_print_power_states(struct amdgpu_device *adev) |
| 1302 | { |
| 1303 | int i; |
| 1304 | |
Rex Zhu | cd4d746 | 2017-09-06 18:43:52 +0800 | [diff] [blame] | 1305 | if (adev->powerplay.pp_funcs->print_power_state == NULL) |
Rex Zhu | 1b5708f | 2015-11-10 18:25:24 -0500 | [diff] [blame] | 1306 | return; |
| 1307 | |
| 1308 | for (i = 0; i < adev->pm.dpm.num_ps; i++) |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1309 | amdgpu_dpm_print_power_state(adev, &adev->pm.dpm.ps[i]); |
Rex Zhu | 1b5708f | 2015-11-10 18:25:24 -0500 | [diff] [blame] | 1310 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1311 | } |
| 1312 | |
| 1313 | int amdgpu_pm_sysfs_init(struct amdgpu_device *adev) |
| 1314 | { |
| 1315 | int ret; |
| 1316 | |
Alex Deucher | c86f5ebf | 2015-10-23 10:45:14 -0400 | [diff] [blame] | 1317 | if (adev->pm.sysfs_initialized) |
| 1318 | return 0; |
| 1319 | |
Rex Zhu | d2f52ac | 2017-09-22 17:47:27 +0800 | [diff] [blame^] | 1320 | if (adev->pm.dpm_enabled == 0) |
| 1321 | return 0; |
| 1322 | |
Rex Zhu | cd4d746 | 2017-09-06 18:43:52 +0800 | [diff] [blame] | 1323 | if (adev->powerplay.pp_funcs->get_temperature == NULL) |
| 1324 | return 0; |
Rex Zhu | 1b5708f | 2015-11-10 18:25:24 -0500 | [diff] [blame] | 1325 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1326 | adev->pm.int_hwmon_dev = hwmon_device_register_with_groups(adev->dev, |
| 1327 | DRIVER_NAME, adev, |
| 1328 | hwmon_groups); |
| 1329 | if (IS_ERR(adev->pm.int_hwmon_dev)) { |
| 1330 | ret = PTR_ERR(adev->pm.int_hwmon_dev); |
| 1331 | dev_err(adev->dev, |
| 1332 | "Unable to register hwmon device: %d\n", ret); |
| 1333 | return ret; |
| 1334 | } |
| 1335 | |
| 1336 | ret = device_create_file(adev->dev, &dev_attr_power_dpm_state); |
| 1337 | if (ret) { |
| 1338 | DRM_ERROR("failed to create device file for dpm state\n"); |
| 1339 | return ret; |
| 1340 | } |
| 1341 | ret = device_create_file(adev->dev, &dev_attr_power_dpm_force_performance_level); |
| 1342 | if (ret) { |
| 1343 | DRM_ERROR("failed to create device file for dpm state\n"); |
| 1344 | return ret; |
| 1345 | } |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 1346 | |
| 1347 | if (adev->pp_enabled) { |
| 1348 | ret = device_create_file(adev->dev, &dev_attr_pp_num_states); |
| 1349 | if (ret) { |
| 1350 | DRM_ERROR("failed to create device file pp_num_states\n"); |
| 1351 | return ret; |
| 1352 | } |
| 1353 | ret = device_create_file(adev->dev, &dev_attr_pp_cur_state); |
| 1354 | if (ret) { |
| 1355 | DRM_ERROR("failed to create device file pp_cur_state\n"); |
| 1356 | return ret; |
| 1357 | } |
| 1358 | ret = device_create_file(adev->dev, &dev_attr_pp_force_state); |
| 1359 | if (ret) { |
| 1360 | DRM_ERROR("failed to create device file pp_force_state\n"); |
| 1361 | return ret; |
| 1362 | } |
| 1363 | ret = device_create_file(adev->dev, &dev_attr_pp_table); |
| 1364 | if (ret) { |
| 1365 | DRM_ERROR("failed to create device file pp_table\n"); |
| 1366 | return ret; |
| 1367 | } |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 1368 | } |
Eric Huang | c85e299 | 2016-05-19 15:41:25 -0400 | [diff] [blame] | 1369 | |
| 1370 | ret = device_create_file(adev->dev, &dev_attr_pp_dpm_sclk); |
| 1371 | if (ret) { |
| 1372 | DRM_ERROR("failed to create device file pp_dpm_sclk\n"); |
| 1373 | return ret; |
| 1374 | } |
| 1375 | ret = device_create_file(adev->dev, &dev_attr_pp_dpm_mclk); |
| 1376 | if (ret) { |
| 1377 | DRM_ERROR("failed to create device file pp_dpm_mclk\n"); |
| 1378 | return ret; |
| 1379 | } |
| 1380 | ret = device_create_file(adev->dev, &dev_attr_pp_dpm_pcie); |
| 1381 | if (ret) { |
| 1382 | DRM_ERROR("failed to create device file pp_dpm_pcie\n"); |
| 1383 | return ret; |
| 1384 | } |
Eric Huang | 8b2e574 | 2016-05-19 15:46:10 -0400 | [diff] [blame] | 1385 | ret = device_create_file(adev->dev, &dev_attr_pp_sclk_od); |
| 1386 | if (ret) { |
| 1387 | DRM_ERROR("failed to create device file pp_sclk_od\n"); |
| 1388 | return ret; |
| 1389 | } |
Eric Huang | f2bdc05 | 2016-05-24 15:11:17 -0400 | [diff] [blame] | 1390 | ret = device_create_file(adev->dev, &dev_attr_pp_mclk_od); |
| 1391 | if (ret) { |
| 1392 | DRM_ERROR("failed to create device file pp_mclk_od\n"); |
| 1393 | return ret; |
| 1394 | } |
Eric Huang | 34bb273 | 2016-09-12 16:17:44 -0400 | [diff] [blame] | 1395 | ret = device_create_file(adev->dev, |
| 1396 | &dev_attr_pp_gfx_power_profile); |
| 1397 | if (ret) { |
| 1398 | DRM_ERROR("failed to create device file " |
| 1399 | "pp_gfx_power_profile\n"); |
| 1400 | return ret; |
| 1401 | } |
| 1402 | ret = device_create_file(adev->dev, |
| 1403 | &dev_attr_pp_compute_power_profile); |
| 1404 | if (ret) { |
| 1405 | DRM_ERROR("failed to create device file " |
| 1406 | "pp_compute_power_profile\n"); |
| 1407 | return ret; |
| 1408 | } |
Eric Huang | c85e299 | 2016-05-19 15:41:25 -0400 | [diff] [blame] | 1409 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1410 | ret = amdgpu_debugfs_pm_init(adev); |
| 1411 | if (ret) { |
| 1412 | DRM_ERROR("Failed to register debugfs file for dpm!\n"); |
| 1413 | return ret; |
| 1414 | } |
| 1415 | |
Alex Deucher | c86f5ebf | 2015-10-23 10:45:14 -0400 | [diff] [blame] | 1416 | adev->pm.sysfs_initialized = true; |
| 1417 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1418 | return 0; |
| 1419 | } |
| 1420 | |
| 1421 | void amdgpu_pm_sysfs_fini(struct amdgpu_device *adev) |
| 1422 | { |
Rex Zhu | d2f52ac | 2017-09-22 17:47:27 +0800 | [diff] [blame^] | 1423 | if (adev->pm.dpm_enabled == 0) |
| 1424 | return; |
| 1425 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1426 | if (adev->pm.int_hwmon_dev) |
| 1427 | hwmon_device_unregister(adev->pm.int_hwmon_dev); |
| 1428 | device_remove_file(adev->dev, &dev_attr_power_dpm_state); |
| 1429 | device_remove_file(adev->dev, &dev_attr_power_dpm_force_performance_level); |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 1430 | if (adev->pp_enabled) { |
| 1431 | device_remove_file(adev->dev, &dev_attr_pp_num_states); |
| 1432 | device_remove_file(adev->dev, &dev_attr_pp_cur_state); |
| 1433 | device_remove_file(adev->dev, &dev_attr_pp_force_state); |
| 1434 | device_remove_file(adev->dev, &dev_attr_pp_table); |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 1435 | } |
Eric Huang | c85e299 | 2016-05-19 15:41:25 -0400 | [diff] [blame] | 1436 | device_remove_file(adev->dev, &dev_attr_pp_dpm_sclk); |
| 1437 | device_remove_file(adev->dev, &dev_attr_pp_dpm_mclk); |
| 1438 | device_remove_file(adev->dev, &dev_attr_pp_dpm_pcie); |
Eric Huang | 8b2e574 | 2016-05-19 15:46:10 -0400 | [diff] [blame] | 1439 | device_remove_file(adev->dev, &dev_attr_pp_sclk_od); |
Eric Huang | f2bdc05 | 2016-05-24 15:11:17 -0400 | [diff] [blame] | 1440 | device_remove_file(adev->dev, &dev_attr_pp_mclk_od); |
Eric Huang | 34bb273 | 2016-09-12 16:17:44 -0400 | [diff] [blame] | 1441 | device_remove_file(adev->dev, |
| 1442 | &dev_attr_pp_gfx_power_profile); |
| 1443 | device_remove_file(adev->dev, |
| 1444 | &dev_attr_pp_compute_power_profile); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1445 | } |
| 1446 | |
| 1447 | void amdgpu_pm_compute_clocks(struct amdgpu_device *adev) |
| 1448 | { |
| 1449 | struct drm_device *ddev = adev->ddev; |
| 1450 | struct drm_crtc *crtc; |
| 1451 | struct amdgpu_crtc *amdgpu_crtc; |
Rex Zhu | 5e876c6 | 2016-10-14 19:23:34 +0800 | [diff] [blame] | 1452 | int i = 0; |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1453 | |
| 1454 | if (!adev->pm.dpm_enabled) |
| 1455 | return; |
| 1456 | |
Alex Deucher | c10c8f7 | 2017-02-10 18:09:32 -0500 | [diff] [blame] | 1457 | if (adev->mode_info.num_crtc) |
| 1458 | amdgpu_display_bandwidth_update(adev); |
Rex Zhu | 5e876c6 | 2016-10-14 19:23:34 +0800 | [diff] [blame] | 1459 | |
| 1460 | for (i = 0; i < AMDGPU_MAX_RINGS; i++) { |
| 1461 | struct amdgpu_ring *ring = adev->rings[i]; |
| 1462 | if (ring && ring->ready) |
| 1463 | amdgpu_fence_wait_empty(ring); |
| 1464 | } |
| 1465 | |
Jammy Zhou | e61710c | 2015-11-10 18:31:08 -0500 | [diff] [blame] | 1466 | if (adev->pp_enabled) { |
Rex Zhu | df1e639 | 2017-09-01 13:46:20 +0800 | [diff] [blame] | 1467 | amdgpu_dpm_dispatch_task(adev, AMD_PP_TASK_DISPLAY_CONFIG_CHANGE, NULL, NULL); |
Rex Zhu | 1b5708f | 2015-11-10 18:25:24 -0500 | [diff] [blame] | 1468 | } else { |
| 1469 | mutex_lock(&adev->pm.mutex); |
| 1470 | adev->pm.dpm.new_active_crtcs = 0; |
| 1471 | adev->pm.dpm.new_active_crtc_count = 0; |
| 1472 | if (adev->mode_info.num_crtc && adev->mode_info.mode_config_initialized) { |
| 1473 | list_for_each_entry(crtc, |
| 1474 | &ddev->mode_config.crtc_list, head) { |
| 1475 | amdgpu_crtc = to_amdgpu_crtc(crtc); |
| 1476 | if (crtc->enabled) { |
| 1477 | adev->pm.dpm.new_active_crtcs |= (1 << amdgpu_crtc->crtc_id); |
| 1478 | adev->pm.dpm.new_active_crtc_count++; |
| 1479 | } |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1480 | } |
| 1481 | } |
Rex Zhu | 1b5708f | 2015-11-10 18:25:24 -0500 | [diff] [blame] | 1482 | /* update battery/ac status */ |
| 1483 | if (power_supply_is_system_supplied() > 0) |
| 1484 | adev->pm.dpm.ac_power = true; |
| 1485 | else |
| 1486 | adev->pm.dpm.ac_power = false; |
| 1487 | |
| 1488 | amdgpu_dpm_change_power_state_locked(adev); |
| 1489 | |
| 1490 | mutex_unlock(&adev->pm.mutex); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1491 | } |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1492 | } |
| 1493 | |
| 1494 | /* |
| 1495 | * Debugfs info |
| 1496 | */ |
| 1497 | #if defined(CONFIG_DEBUG_FS) |
| 1498 | |
Tom St Denis | 3de4ec5 | 2016-09-19 12:48:52 -0400 | [diff] [blame] | 1499 | static int amdgpu_debugfs_pm_info_pp(struct seq_file *m, struct amdgpu_device *adev) |
| 1500 | { |
Eric Huang | cd7b0c6 | 2017-02-07 16:37:48 -0500 | [diff] [blame] | 1501 | uint32_t value; |
Eric Huang | 4f9afc9 | 2017-01-24 16:59:27 -0500 | [diff] [blame] | 1502 | struct pp_gpu_power query = {0}; |
Tom St Denis | 9f8df7d | 2017-02-09 14:29:01 -0500 | [diff] [blame] | 1503 | int size; |
Tom St Denis | 3de4ec5 | 2016-09-19 12:48:52 -0400 | [diff] [blame] | 1504 | |
| 1505 | /* sanity check PP is enabled */ |
| 1506 | if (!(adev->powerplay.pp_funcs && |
| 1507 | adev->powerplay.pp_funcs->read_sensor)) |
| 1508 | return -EINVAL; |
| 1509 | |
| 1510 | /* GPU Clocks */ |
Tom St Denis | 9f8df7d | 2017-02-09 14:29:01 -0500 | [diff] [blame] | 1511 | size = sizeof(value); |
Tom St Denis | 3de4ec5 | 2016-09-19 12:48:52 -0400 | [diff] [blame] | 1512 | seq_printf(m, "GFX Clocks and Power:\n"); |
Tom St Denis | 9f8df7d | 2017-02-09 14:29:01 -0500 | [diff] [blame] | 1513 | 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] | 1514 | seq_printf(m, "\t%u MHz (MCLK)\n", value/100); |
Tom St Denis | 9f8df7d | 2017-02-09 14:29:01 -0500 | [diff] [blame] | 1515 | 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] | 1516 | seq_printf(m, "\t%u MHz (SCLK)\n", value/100); |
Tom St Denis | 9f8df7d | 2017-02-09 14:29:01 -0500 | [diff] [blame] | 1517 | 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] | 1518 | seq_printf(m, "\t%u mV (VDDGFX)\n", value); |
Tom St Denis | 9f8df7d | 2017-02-09 14:29:01 -0500 | [diff] [blame] | 1519 | 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] | 1520 | seq_printf(m, "\t%u mV (VDDNB)\n", value); |
Tom St Denis | 9f8df7d | 2017-02-09 14:29:01 -0500 | [diff] [blame] | 1521 | size = sizeof(query); |
| 1522 | if (!amdgpu_dpm_read_sensor(adev, AMDGPU_PP_SENSOR_GPU_POWER, (void *)&query, &size)) { |
Eric Huang | 4f9afc9 | 2017-01-24 16:59:27 -0500 | [diff] [blame] | 1523 | seq_printf(m, "\t%u.%u W (VDDC)\n", query.vddc_power >> 8, |
| 1524 | query.vddc_power & 0xff); |
| 1525 | seq_printf(m, "\t%u.%u W (VDDCI)\n", query.vddci_power >> 8, |
| 1526 | query.vddci_power & 0xff); |
| 1527 | seq_printf(m, "\t%u.%u W (max GPU)\n", query.max_gpu_power >> 8, |
| 1528 | query.max_gpu_power & 0xff); |
| 1529 | seq_printf(m, "\t%u.%u W (average GPU)\n", query.average_gpu_power >> 8, |
| 1530 | query.average_gpu_power & 0xff); |
| 1531 | } |
Tom St Denis | 9f8df7d | 2017-02-09 14:29:01 -0500 | [diff] [blame] | 1532 | size = sizeof(value); |
Tom St Denis | 3de4ec5 | 2016-09-19 12:48:52 -0400 | [diff] [blame] | 1533 | seq_printf(m, "\n"); |
| 1534 | |
| 1535 | /* GPU Temp */ |
Tom St Denis | 9f8df7d | 2017-02-09 14:29:01 -0500 | [diff] [blame] | 1536 | 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] | 1537 | seq_printf(m, "GPU Temperature: %u C\n", value/1000); |
| 1538 | |
| 1539 | /* GPU Load */ |
Tom St Denis | 9f8df7d | 2017-02-09 14:29:01 -0500 | [diff] [blame] | 1540 | 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] | 1541 | seq_printf(m, "GPU Load: %u %%\n", value); |
| 1542 | seq_printf(m, "\n"); |
| 1543 | |
| 1544 | /* UVD clocks */ |
Tom St Denis | 9f8df7d | 2017-02-09 14:29:01 -0500 | [diff] [blame] | 1545 | 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] | 1546 | if (!value) { |
| 1547 | seq_printf(m, "UVD: Disabled\n"); |
| 1548 | } else { |
| 1549 | seq_printf(m, "UVD: Enabled\n"); |
Tom St Denis | 9f8df7d | 2017-02-09 14:29:01 -0500 | [diff] [blame] | 1550 | 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] | 1551 | seq_printf(m, "\t%u MHz (DCLK)\n", value/100); |
Tom St Denis | 9f8df7d | 2017-02-09 14:29:01 -0500 | [diff] [blame] | 1552 | 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] | 1553 | seq_printf(m, "\t%u MHz (VCLK)\n", value/100); |
| 1554 | } |
| 1555 | } |
| 1556 | seq_printf(m, "\n"); |
| 1557 | |
| 1558 | /* VCE clocks */ |
Tom St Denis | 9f8df7d | 2017-02-09 14:29:01 -0500 | [diff] [blame] | 1559 | 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] | 1560 | if (!value) { |
| 1561 | seq_printf(m, "VCE: Disabled\n"); |
| 1562 | } else { |
| 1563 | seq_printf(m, "VCE: Enabled\n"); |
Tom St Denis | 9f8df7d | 2017-02-09 14:29:01 -0500 | [diff] [blame] | 1564 | 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] | 1565 | seq_printf(m, "\t%u MHz (ECCLK)\n", value/100); |
| 1566 | } |
| 1567 | } |
| 1568 | |
| 1569 | return 0; |
| 1570 | } |
| 1571 | |
Huang Rui | a8503b1 | 2017-01-05 19:17:13 +0800 | [diff] [blame] | 1572 | static void amdgpu_parse_cg_state(struct seq_file *m, u32 flags) |
| 1573 | { |
| 1574 | int i; |
| 1575 | |
| 1576 | for (i = 0; clocks[i].flag; i++) |
| 1577 | seq_printf(m, "\t%s: %s\n", clocks[i].name, |
| 1578 | (flags & clocks[i].flag) ? "On" : "Off"); |
| 1579 | } |
| 1580 | |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1581 | static int amdgpu_debugfs_pm_info(struct seq_file *m, void *data) |
| 1582 | { |
| 1583 | struct drm_info_node *node = (struct drm_info_node *) m->private; |
| 1584 | struct drm_device *dev = node->minor->dev; |
| 1585 | struct amdgpu_device *adev = dev->dev_private; |
Alex Deucher | 0c67df4 | 2016-02-19 15:30:15 -0500 | [diff] [blame] | 1586 | struct drm_device *ddev = adev->ddev; |
Huang Rui | 6cb2d4e | 2017-01-05 18:44:41 +0800 | [diff] [blame] | 1587 | u32 flags = 0; |
| 1588 | |
| 1589 | amdgpu_get_clockgating_state(adev, &flags); |
| 1590 | seq_printf(m, "Clock Gating Flags Mask: 0x%x\n", flags); |
Huang Rui | a8503b1 | 2017-01-05 19:17:13 +0800 | [diff] [blame] | 1591 | amdgpu_parse_cg_state(m, flags); |
| 1592 | seq_printf(m, "\n"); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1593 | |
Rex Zhu | 1b5708f | 2015-11-10 18:25:24 -0500 | [diff] [blame] | 1594 | if (!adev->pm.dpm_enabled) { |
| 1595 | seq_printf(m, "dpm not enabled\n"); |
| 1596 | return 0; |
| 1597 | } |
Alex Deucher | 0c67df4 | 2016-02-19 15:30:15 -0500 | [diff] [blame] | 1598 | if ((adev->flags & AMD_IS_PX) && |
| 1599 | (ddev->switch_power_state != DRM_SWITCH_POWER_ON)) { |
| 1600 | seq_printf(m, "PX asic powered off\n"); |
| 1601 | } else if (adev->pp_enabled) { |
Tom St Denis | 3de4ec5 | 2016-09-19 12:48:52 -0400 | [diff] [blame] | 1602 | return amdgpu_debugfs_pm_info_pp(m, adev); |
Rex Zhu | 1b5708f | 2015-11-10 18:25:24 -0500 | [diff] [blame] | 1603 | } else { |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1604 | mutex_lock(&adev->pm.mutex); |
Rex Zhu | cd4d746 | 2017-09-06 18:43:52 +0800 | [diff] [blame] | 1605 | if (adev->powerplay.pp_funcs->debugfs_print_current_performance_level) |
| 1606 | adev->powerplay.pp_funcs->debugfs_print_current_performance_level(adev, m); |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1607 | else |
| 1608 | seq_printf(m, "Debugfs support not implemented for this asic\n"); |
| 1609 | mutex_unlock(&adev->pm.mutex); |
| 1610 | } |
| 1611 | |
| 1612 | return 0; |
| 1613 | } |
| 1614 | |
Nils Wallménius | 06ab683 | 2016-05-02 12:46:15 -0400 | [diff] [blame] | 1615 | static const struct drm_info_list amdgpu_pm_info_list[] = { |
Alex Deucher | d38ceaf | 2015-04-20 16:55:21 -0400 | [diff] [blame] | 1616 | {"amdgpu_pm_info", amdgpu_debugfs_pm_info, 0, NULL}, |
| 1617 | }; |
| 1618 | #endif |
| 1619 | |
| 1620 | static int amdgpu_debugfs_pm_init(struct amdgpu_device *adev) |
| 1621 | { |
| 1622 | #if defined(CONFIG_DEBUG_FS) |
| 1623 | return amdgpu_debugfs_add_files(adev, amdgpu_pm_info_list, ARRAY_SIZE(amdgpu_pm_info_list)); |
| 1624 | #else |
| 1625 | return 0; |
| 1626 | #endif |
| 1627 | } |