Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 Advanced Micro Devices, Inc. |
| 3 | * |
| 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 | */ |
| 23 | #include <linux/types.h> |
| 24 | #include <linux/kernel.h> |
| 25 | #include <linux/gfp.h> |
Jammy Zhou | ac885b3 | 2015-07-21 17:43:02 +0800 | [diff] [blame] | 26 | #include <linux/slab.h> |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 27 | #include "amd_shared.h" |
| 28 | #include "amd_powerplay.h" |
Jammy Zhou | ac885b3 | 2015-07-21 17:43:02 +0800 | [diff] [blame] | 29 | #include "pp_instance.h" |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 30 | #include "power_state.h" |
| 31 | #include "eventmanager.h" |
Rex Zhu | e273b04 | 2015-12-07 18:44:23 +0800 | [diff] [blame] | 32 | #include "pp_debug.h" |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 33 | |
Rex Zhu | a969e16 | 2015-12-29 13:56:03 +0800 | [diff] [blame] | 34 | #define PP_CHECK(handle) \ |
| 35 | do { \ |
| 36 | if ((handle) == NULL || (handle)->pp_valid != PP_VALID) \ |
| 37 | return -EINVAL; \ |
| 38 | } while (0) |
| 39 | |
Rex Zhu | 7383bcb | 2016-03-30 11:35:50 +0800 | [diff] [blame] | 40 | #define PP_CHECK_HW(hwmgr) \ |
| 41 | do { \ |
| 42 | if ((hwmgr) == NULL || (hwmgr)->hwmgr_func == NULL) \ |
| 43 | return -EINVAL; \ |
| 44 | } while (0) |
| 45 | |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 46 | static int pp_early_init(void *handle) |
| 47 | { |
| 48 | return 0; |
| 49 | } |
| 50 | |
| 51 | static int pp_sw_init(void *handle) |
| 52 | { |
Jammy Zhou | 3bace35 | 2015-07-21 21:18:15 +0800 | [diff] [blame] | 53 | struct pp_instance *pp_handle; |
| 54 | struct pp_hwmgr *hwmgr; |
| 55 | int ret = 0; |
| 56 | |
| 57 | if (handle == NULL) |
| 58 | return -EINVAL; |
| 59 | |
| 60 | pp_handle = (struct pp_instance *)handle; |
| 61 | hwmgr = pp_handle->hwmgr; |
| 62 | |
Rex Zhu | 7383bcb | 2016-03-30 11:35:50 +0800 | [diff] [blame] | 63 | PP_CHECK_HW(hwmgr); |
| 64 | |
| 65 | if (hwmgr->pptable_func == NULL || |
Jammy Zhou | 3bace35 | 2015-07-21 21:18:15 +0800 | [diff] [blame] | 66 | hwmgr->pptable_func->pptable_init == NULL || |
| 67 | hwmgr->hwmgr_func->backend_init == NULL) |
| 68 | return -EINVAL; |
| 69 | |
| 70 | ret = hwmgr->pptable_func->pptable_init(hwmgr); |
Alex Deucher | 9441f96 | 2016-01-20 12:15:09 -0500 | [diff] [blame] | 71 | if (ret) |
Huang Rui | b4eeed5 | 2016-05-09 17:29:41 +0800 | [diff] [blame] | 72 | goto err; |
Alex Deucher | 9441f96 | 2016-01-20 12:15:09 -0500 | [diff] [blame] | 73 | |
Huang Rui | b4eeed5 | 2016-05-09 17:29:41 +0800 | [diff] [blame] | 74 | ret = hwmgr->hwmgr_func->backend_init(hwmgr); |
| 75 | if (ret) |
| 76 | goto err; |
| 77 | |
| 78 | pr_info("amdgpu: powerplay initialized\n"); |
| 79 | |
| 80 | return 0; |
| 81 | err: |
| 82 | pr_err("amdgpu: powerplay initialization failed\n"); |
Jammy Zhou | 3bace35 | 2015-07-21 21:18:15 +0800 | [diff] [blame] | 83 | return ret; |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | static int pp_sw_fini(void *handle) |
| 87 | { |
Jammy Zhou | 3bace35 | 2015-07-21 21:18:15 +0800 | [diff] [blame] | 88 | struct pp_instance *pp_handle; |
| 89 | struct pp_hwmgr *hwmgr; |
| 90 | int ret = 0; |
| 91 | |
| 92 | if (handle == NULL) |
| 93 | return -EINVAL; |
| 94 | |
| 95 | pp_handle = (struct pp_instance *)handle; |
| 96 | hwmgr = pp_handle->hwmgr; |
| 97 | |
Rex Zhu | 7383bcb | 2016-03-30 11:35:50 +0800 | [diff] [blame] | 98 | PP_CHECK_HW(hwmgr); |
| 99 | |
| 100 | if (hwmgr->hwmgr_func->backend_fini != NULL) |
Jammy Zhou | 3bace35 | 2015-07-21 21:18:15 +0800 | [diff] [blame] | 101 | ret = hwmgr->hwmgr_func->backend_fini(hwmgr); |
| 102 | |
| 103 | return ret; |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | static int pp_hw_init(void *handle) |
| 107 | { |
Jammy Zhou | ac885b3 | 2015-07-21 17:43:02 +0800 | [diff] [blame] | 108 | struct pp_instance *pp_handle; |
| 109 | struct pp_smumgr *smumgr; |
Rex Zhu | e92a037 | 2015-09-23 15:14:54 +0800 | [diff] [blame] | 110 | struct pp_eventmgr *eventmgr; |
Jammy Zhou | ac885b3 | 2015-07-21 17:43:02 +0800 | [diff] [blame] | 111 | int ret = 0; |
| 112 | |
| 113 | if (handle == NULL) |
| 114 | return -EINVAL; |
| 115 | |
| 116 | pp_handle = (struct pp_instance *)handle; |
| 117 | smumgr = pp_handle->smu_mgr; |
| 118 | |
| 119 | if (smumgr == NULL || smumgr->smumgr_funcs == NULL || |
| 120 | smumgr->smumgr_funcs->smu_init == NULL || |
| 121 | smumgr->smumgr_funcs->start_smu == NULL) |
| 122 | return -EINVAL; |
| 123 | |
| 124 | ret = smumgr->smumgr_funcs->smu_init(smumgr); |
| 125 | if (ret) { |
| 126 | printk(KERN_ERR "[ powerplay ] smc initialization failed\n"); |
| 127 | return ret; |
| 128 | } |
| 129 | |
| 130 | ret = smumgr->smumgr_funcs->start_smu(smumgr); |
| 131 | if (ret) { |
| 132 | printk(KERN_ERR "[ powerplay ] smc start failed\n"); |
| 133 | smumgr->smumgr_funcs->smu_fini(smumgr); |
| 134 | return ret; |
| 135 | } |
Jammy Zhou | 3bace35 | 2015-07-21 21:18:15 +0800 | [diff] [blame] | 136 | |
Rex Zhu | e92a037 | 2015-09-23 15:14:54 +0800 | [diff] [blame] | 137 | hw_init_power_state_table(pp_handle->hwmgr); |
| 138 | eventmgr = pp_handle->eventmgr; |
| 139 | |
| 140 | if (eventmgr == NULL || eventmgr->pp_eventmgr_init == NULL) |
| 141 | return -EINVAL; |
| 142 | |
| 143 | ret = eventmgr->pp_eventmgr_init(eventmgr); |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 144 | return 0; |
| 145 | } |
| 146 | |
| 147 | static int pp_hw_fini(void *handle) |
| 148 | { |
Jammy Zhou | ac885b3 | 2015-07-21 17:43:02 +0800 | [diff] [blame] | 149 | struct pp_instance *pp_handle; |
| 150 | struct pp_smumgr *smumgr; |
Rex Zhu | e92a037 | 2015-09-23 15:14:54 +0800 | [diff] [blame] | 151 | struct pp_eventmgr *eventmgr; |
Jammy Zhou | ac885b3 | 2015-07-21 17:43:02 +0800 | [diff] [blame] | 152 | |
| 153 | if (handle == NULL) |
| 154 | return -EINVAL; |
| 155 | |
| 156 | pp_handle = (struct pp_instance *)handle; |
Rex Zhu | e92a037 | 2015-09-23 15:14:54 +0800 | [diff] [blame] | 157 | eventmgr = pp_handle->eventmgr; |
| 158 | |
| 159 | if (eventmgr != NULL || eventmgr->pp_eventmgr_fini != NULL) |
| 160 | eventmgr->pp_eventmgr_fini(eventmgr); |
| 161 | |
Jammy Zhou | ac885b3 | 2015-07-21 17:43:02 +0800 | [diff] [blame] | 162 | smumgr = pp_handle->smu_mgr; |
| 163 | |
| 164 | if (smumgr != NULL || smumgr->smumgr_funcs != NULL || |
| 165 | smumgr->smumgr_funcs->smu_fini != NULL) |
| 166 | smumgr->smumgr_funcs->smu_fini(smumgr); |
| 167 | |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 168 | return 0; |
| 169 | } |
| 170 | |
| 171 | static bool pp_is_idle(void *handle) |
| 172 | { |
| 173 | return 0; |
| 174 | } |
| 175 | |
| 176 | static int pp_wait_for_idle(void *handle) |
| 177 | { |
| 178 | return 0; |
| 179 | } |
| 180 | |
| 181 | static int pp_sw_reset(void *handle) |
| 182 | { |
| 183 | return 0; |
| 184 | } |
| 185 | |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 186 | |
| 187 | static int pp_set_clockgating_state(void *handle, |
| 188 | enum amd_clockgating_state state) |
| 189 | { |
Eric Huang | 03e3905 | 2016-02-09 16:26:00 -0500 | [diff] [blame] | 190 | struct pp_hwmgr *hwmgr; |
| 191 | uint32_t msg_id, pp_state; |
| 192 | |
| 193 | if (handle == NULL) |
| 194 | return -EINVAL; |
| 195 | |
| 196 | hwmgr = ((struct pp_instance *)handle)->hwmgr; |
| 197 | |
Rex Zhu | 7383bcb | 2016-03-30 11:35:50 +0800 | [diff] [blame] | 198 | PP_CHECK_HW(hwmgr); |
Eric Huang | 03e3905 | 2016-02-09 16:26:00 -0500 | [diff] [blame] | 199 | |
Rex Zhu | 7383bcb | 2016-03-30 11:35:50 +0800 | [diff] [blame] | 200 | if (hwmgr->hwmgr_func->update_clock_gatings == NULL) { |
| 201 | printk(KERN_INFO "%s was not implemented.\n", __func__); |
Flora Cui | 538333f | 2016-02-15 15:45:59 +0800 | [diff] [blame] | 202 | return 0; |
Rex Zhu | 7383bcb | 2016-03-30 11:35:50 +0800 | [diff] [blame] | 203 | } |
Flora Cui | 538333f | 2016-02-15 15:45:59 +0800 | [diff] [blame] | 204 | |
Eric Huang | 03e3905 | 2016-02-09 16:26:00 -0500 | [diff] [blame] | 205 | if (state == AMD_CG_STATE_UNGATE) |
| 206 | pp_state = 0; |
| 207 | else |
| 208 | pp_state = PP_STATE_CG | PP_STATE_LS; |
| 209 | |
| 210 | /* Enable/disable GFX blocks clock gating through SMU */ |
| 211 | msg_id = PP_CG_MSG_ID(PP_GROUP_GFX, |
| 212 | PP_BLOCK_GFX_CG, |
| 213 | PP_STATE_SUPPORT_CG | PP_STATE_SUPPORT_LS, |
| 214 | pp_state); |
| 215 | hwmgr->hwmgr_func->update_clock_gatings(hwmgr, &msg_id); |
| 216 | msg_id = PP_CG_MSG_ID(PP_GROUP_GFX, |
| 217 | PP_BLOCK_GFX_3D, |
| 218 | PP_STATE_SUPPORT_CG | PP_STATE_SUPPORT_LS, |
| 219 | pp_state); |
| 220 | hwmgr->hwmgr_func->update_clock_gatings(hwmgr, &msg_id); |
| 221 | msg_id = PP_CG_MSG_ID(PP_GROUP_GFX, |
| 222 | PP_BLOCK_GFX_RLC, |
| 223 | PP_STATE_SUPPORT_CG | PP_STATE_SUPPORT_LS, |
| 224 | pp_state); |
| 225 | hwmgr->hwmgr_func->update_clock_gatings(hwmgr, &msg_id); |
| 226 | msg_id = PP_CG_MSG_ID(PP_GROUP_GFX, |
| 227 | PP_BLOCK_GFX_CP, |
| 228 | PP_STATE_SUPPORT_CG | PP_STATE_SUPPORT_LS, |
| 229 | pp_state); |
| 230 | hwmgr->hwmgr_func->update_clock_gatings(hwmgr, &msg_id); |
| 231 | msg_id = PP_CG_MSG_ID(PP_GROUP_GFX, |
| 232 | PP_BLOCK_GFX_MG, |
| 233 | PP_STATE_SUPPORT_CG | PP_STATE_SUPPORT_LS, |
| 234 | pp_state); |
| 235 | hwmgr->hwmgr_func->update_clock_gatings(hwmgr, &msg_id); |
| 236 | |
| 237 | /* Enable/disable System blocks clock gating through SMU */ |
| 238 | msg_id = PP_CG_MSG_ID(PP_GROUP_SYS, |
| 239 | PP_BLOCK_SYS_BIF, |
| 240 | PP_STATE_SUPPORT_CG | PP_STATE_SUPPORT_LS, |
| 241 | pp_state); |
| 242 | hwmgr->hwmgr_func->update_clock_gatings(hwmgr, &msg_id); |
| 243 | msg_id = PP_CG_MSG_ID(PP_GROUP_SYS, |
| 244 | PP_BLOCK_SYS_BIF, |
| 245 | PP_STATE_SUPPORT_CG | PP_STATE_SUPPORT_LS, |
| 246 | pp_state); |
| 247 | hwmgr->hwmgr_func->update_clock_gatings(hwmgr, &msg_id); |
| 248 | msg_id = PP_CG_MSG_ID(PP_GROUP_SYS, |
| 249 | PP_BLOCK_SYS_MC, |
| 250 | PP_STATE_SUPPORT_CG | PP_STATE_SUPPORT_LS, |
| 251 | pp_state); |
| 252 | hwmgr->hwmgr_func->update_clock_gatings(hwmgr, &msg_id); |
| 253 | msg_id = PP_CG_MSG_ID(PP_GROUP_SYS, |
| 254 | PP_BLOCK_SYS_ROM, |
| 255 | PP_STATE_SUPPORT_CG | PP_STATE_SUPPORT_LS, |
| 256 | pp_state); |
| 257 | hwmgr->hwmgr_func->update_clock_gatings(hwmgr, &msg_id); |
| 258 | msg_id = PP_CG_MSG_ID(PP_GROUP_SYS, |
| 259 | PP_BLOCK_SYS_DRM, |
| 260 | PP_STATE_SUPPORT_CG | PP_STATE_SUPPORT_LS, |
| 261 | pp_state); |
| 262 | hwmgr->hwmgr_func->update_clock_gatings(hwmgr, &msg_id); |
| 263 | msg_id = PP_CG_MSG_ID(PP_GROUP_SYS, |
| 264 | PP_BLOCK_SYS_HDP, |
| 265 | PP_STATE_SUPPORT_CG | PP_STATE_SUPPORT_LS, |
| 266 | pp_state); |
| 267 | hwmgr->hwmgr_func->update_clock_gatings(hwmgr, &msg_id); |
| 268 | msg_id = PP_CG_MSG_ID(PP_GROUP_SYS, |
| 269 | PP_BLOCK_SYS_SDMA, |
| 270 | PP_STATE_SUPPORT_CG | PP_STATE_SUPPORT_LS, |
| 271 | pp_state); |
| 272 | hwmgr->hwmgr_func->update_clock_gatings(hwmgr, &msg_id); |
| 273 | |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 274 | return 0; |
| 275 | } |
| 276 | |
| 277 | static int pp_set_powergating_state(void *handle, |
| 278 | enum amd_powergating_state state) |
| 279 | { |
Eric Huang | 65f85e7 | 2016-02-11 15:54:45 -0500 | [diff] [blame] | 280 | struct pp_hwmgr *hwmgr; |
| 281 | |
| 282 | if (handle == NULL) |
| 283 | return -EINVAL; |
| 284 | |
| 285 | hwmgr = ((struct pp_instance *)handle)->hwmgr; |
| 286 | |
Rex Zhu | 7383bcb | 2016-03-30 11:35:50 +0800 | [diff] [blame] | 287 | PP_CHECK_HW(hwmgr); |
| 288 | |
| 289 | if (hwmgr->hwmgr_func->enable_per_cu_power_gating == NULL) { |
| 290 | printk(KERN_INFO "%s was not implemented.\n", __func__); |
| 291 | return 0; |
| 292 | } |
Eric Huang | 65f85e7 | 2016-02-11 15:54:45 -0500 | [diff] [blame] | 293 | |
| 294 | /* Enable/disable GFX per cu powergating through SMU */ |
| 295 | return hwmgr->hwmgr_func->enable_per_cu_power_gating(hwmgr, |
| 296 | state == AMD_PG_STATE_GATE ? true : false); |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 297 | } |
| 298 | |
| 299 | static int pp_suspend(void *handle) |
| 300 | { |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 301 | struct pp_instance *pp_handle; |
| 302 | struct pp_eventmgr *eventmgr; |
| 303 | struct pem_event_data event_data = { {0} }; |
| 304 | |
| 305 | if (handle == NULL) |
| 306 | return -EINVAL; |
| 307 | |
| 308 | pp_handle = (struct pp_instance *)handle; |
| 309 | eventmgr = pp_handle->eventmgr; |
| 310 | pem_handle_event(eventmgr, AMD_PP_EVENT_SUSPEND, &event_data); |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 311 | return 0; |
| 312 | } |
| 313 | |
| 314 | static int pp_resume(void *handle) |
| 315 | { |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 316 | struct pp_instance *pp_handle; |
| 317 | struct pp_eventmgr *eventmgr; |
| 318 | struct pem_event_data event_data = { {0} }; |
Rex Zhu | e0b71a7 | 2015-12-29 10:25:19 +0800 | [diff] [blame] | 319 | struct pp_smumgr *smumgr; |
| 320 | int ret; |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 321 | |
| 322 | if (handle == NULL) |
| 323 | return -EINVAL; |
| 324 | |
| 325 | pp_handle = (struct pp_instance *)handle; |
Rex Zhu | e0b71a7 | 2015-12-29 10:25:19 +0800 | [diff] [blame] | 326 | smumgr = pp_handle->smu_mgr; |
| 327 | |
| 328 | if (smumgr == NULL || smumgr->smumgr_funcs == NULL || |
| 329 | smumgr->smumgr_funcs->start_smu == NULL) |
| 330 | return -EINVAL; |
| 331 | |
| 332 | ret = smumgr->smumgr_funcs->start_smu(smumgr); |
| 333 | if (ret) { |
| 334 | printk(KERN_ERR "[ powerplay ] smc start failed\n"); |
| 335 | smumgr->smumgr_funcs->smu_fini(smumgr); |
| 336 | return ret; |
| 337 | } |
| 338 | |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 339 | eventmgr = pp_handle->eventmgr; |
| 340 | pem_handle_event(eventmgr, AMD_PP_EVENT_RESUME, &event_data); |
Rex Zhu | e0b71a7 | 2015-12-29 10:25:19 +0800 | [diff] [blame] | 341 | |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 342 | return 0; |
| 343 | } |
| 344 | |
| 345 | const struct amd_ip_funcs pp_ip_funcs = { |
Tom St Denis | 88a907d | 2016-05-04 14:28:35 -0400 | [diff] [blame] | 346 | .name = "powerplay", |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 347 | .early_init = pp_early_init, |
| 348 | .late_init = NULL, |
| 349 | .sw_init = pp_sw_init, |
| 350 | .sw_fini = pp_sw_fini, |
| 351 | .hw_init = pp_hw_init, |
| 352 | .hw_fini = pp_hw_fini, |
| 353 | .suspend = pp_suspend, |
| 354 | .resume = pp_resume, |
| 355 | .is_idle = pp_is_idle, |
| 356 | .wait_for_idle = pp_wait_for_idle, |
| 357 | .soft_reset = pp_sw_reset, |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 358 | .set_clockgating_state = pp_set_clockgating_state, |
| 359 | .set_powergating_state = pp_set_powergating_state, |
| 360 | }; |
| 361 | |
| 362 | static int pp_dpm_load_fw(void *handle) |
| 363 | { |
| 364 | return 0; |
| 365 | } |
| 366 | |
| 367 | static int pp_dpm_fw_loading_complete(void *handle) |
| 368 | { |
| 369 | return 0; |
| 370 | } |
| 371 | |
| 372 | static int pp_dpm_force_performance_level(void *handle, |
| 373 | enum amd_dpm_forced_level level) |
| 374 | { |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 375 | struct pp_instance *pp_handle; |
| 376 | struct pp_hwmgr *hwmgr; |
| 377 | |
| 378 | if (handle == NULL) |
| 379 | return -EINVAL; |
| 380 | |
| 381 | pp_handle = (struct pp_instance *)handle; |
| 382 | |
| 383 | hwmgr = pp_handle->hwmgr; |
| 384 | |
Rex Zhu | 7383bcb | 2016-03-30 11:35:50 +0800 | [diff] [blame] | 385 | PP_CHECK_HW(hwmgr); |
| 386 | |
| 387 | if (hwmgr->hwmgr_func->force_dpm_level == NULL) { |
| 388 | printk(KERN_INFO "%s was not implemented.\n", __func__); |
| 389 | return 0; |
| 390 | } |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 391 | |
| 392 | hwmgr->hwmgr_func->force_dpm_level(hwmgr, level); |
| 393 | |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 394 | return 0; |
| 395 | } |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 396 | |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 397 | static enum amd_dpm_forced_level pp_dpm_get_performance_level( |
| 398 | void *handle) |
| 399 | { |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 400 | struct pp_hwmgr *hwmgr; |
| 401 | |
| 402 | if (handle == NULL) |
| 403 | return -EINVAL; |
| 404 | |
| 405 | hwmgr = ((struct pp_instance *)handle)->hwmgr; |
| 406 | |
| 407 | if (hwmgr == NULL) |
| 408 | return -EINVAL; |
| 409 | |
| 410 | return (((struct pp_instance *)handle)->hwmgr->dpm_level); |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 411 | } |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 412 | |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 413 | static int pp_dpm_get_sclk(void *handle, bool low) |
| 414 | { |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 415 | struct pp_hwmgr *hwmgr; |
| 416 | |
| 417 | if (handle == NULL) |
| 418 | return -EINVAL; |
| 419 | |
| 420 | hwmgr = ((struct pp_instance *)handle)->hwmgr; |
| 421 | |
Rex Zhu | 7383bcb | 2016-03-30 11:35:50 +0800 | [diff] [blame] | 422 | PP_CHECK_HW(hwmgr); |
| 423 | |
| 424 | if (hwmgr->hwmgr_func->get_sclk == NULL) { |
| 425 | printk(KERN_INFO "%s was not implemented.\n", __func__); |
| 426 | return 0; |
| 427 | } |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 428 | |
| 429 | return hwmgr->hwmgr_func->get_sclk(hwmgr, low); |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 430 | } |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 431 | |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 432 | static int pp_dpm_get_mclk(void *handle, bool low) |
| 433 | { |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 434 | struct pp_hwmgr *hwmgr; |
| 435 | |
| 436 | if (handle == NULL) |
| 437 | return -EINVAL; |
| 438 | |
| 439 | hwmgr = ((struct pp_instance *)handle)->hwmgr; |
| 440 | |
Rex Zhu | 7383bcb | 2016-03-30 11:35:50 +0800 | [diff] [blame] | 441 | PP_CHECK_HW(hwmgr); |
| 442 | |
| 443 | if (hwmgr->hwmgr_func->get_mclk == NULL) { |
| 444 | printk(KERN_INFO "%s was not implemented.\n", __func__); |
| 445 | return 0; |
| 446 | } |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 447 | |
| 448 | return hwmgr->hwmgr_func->get_mclk(hwmgr, low); |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 449 | } |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 450 | |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 451 | static int pp_dpm_powergate_vce(void *handle, bool gate) |
| 452 | { |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 453 | struct pp_hwmgr *hwmgr; |
| 454 | |
| 455 | if (handle == NULL) |
| 456 | return -EINVAL; |
| 457 | |
| 458 | hwmgr = ((struct pp_instance *)handle)->hwmgr; |
| 459 | |
Rex Zhu | 7383bcb | 2016-03-30 11:35:50 +0800 | [diff] [blame] | 460 | PP_CHECK_HW(hwmgr); |
| 461 | |
| 462 | if (hwmgr->hwmgr_func->powergate_vce == NULL) { |
| 463 | printk(KERN_INFO "%s was not implemented.\n", __func__); |
| 464 | return 0; |
| 465 | } |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 466 | |
| 467 | return hwmgr->hwmgr_func->powergate_vce(hwmgr, gate); |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 468 | } |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 469 | |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 470 | static int pp_dpm_powergate_uvd(void *handle, bool gate) |
| 471 | { |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 472 | struct pp_hwmgr *hwmgr; |
| 473 | |
| 474 | if (handle == NULL) |
| 475 | return -EINVAL; |
| 476 | |
| 477 | hwmgr = ((struct pp_instance *)handle)->hwmgr; |
| 478 | |
Rex Zhu | 7383bcb | 2016-03-30 11:35:50 +0800 | [diff] [blame] | 479 | PP_CHECK_HW(hwmgr); |
| 480 | |
| 481 | if (hwmgr->hwmgr_func->powergate_uvd == NULL) { |
| 482 | printk(KERN_INFO "%s was not implemented.\n", __func__); |
| 483 | return 0; |
| 484 | } |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 485 | |
| 486 | return hwmgr->hwmgr_func->powergate_uvd(hwmgr, gate); |
| 487 | } |
| 488 | |
| 489 | static enum PP_StateUILabel power_state_convert(enum amd_pm_state_type state) |
| 490 | { |
| 491 | switch (state) { |
| 492 | case POWER_STATE_TYPE_BATTERY: |
| 493 | return PP_StateUILabel_Battery; |
| 494 | case POWER_STATE_TYPE_BALANCED: |
| 495 | return PP_StateUILabel_Balanced; |
| 496 | case POWER_STATE_TYPE_PERFORMANCE: |
| 497 | return PP_StateUILabel_Performance; |
| 498 | default: |
| 499 | return PP_StateUILabel_None; |
| 500 | } |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 501 | } |
| 502 | |
| 503 | int pp_dpm_dispatch_tasks(void *handle, enum amd_pp_event event_id, void *input, void *output) |
| 504 | { |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 505 | int ret = 0; |
| 506 | struct pp_instance *pp_handle; |
| 507 | struct pem_event_data data = { {0} }; |
| 508 | |
| 509 | pp_handle = (struct pp_instance *)handle; |
| 510 | |
| 511 | if (pp_handle == NULL) |
| 512 | return -EINVAL; |
| 513 | |
| 514 | switch (event_id) { |
| 515 | case AMD_PP_EVENT_DISPLAY_CONFIG_CHANGE: |
| 516 | ret = pem_handle_event(pp_handle->eventmgr, event_id, &data); |
| 517 | break; |
| 518 | case AMD_PP_EVENT_ENABLE_USER_STATE: |
| 519 | { |
| 520 | enum amd_pm_state_type ps; |
| 521 | |
| 522 | if (input == NULL) |
| 523 | return -EINVAL; |
| 524 | ps = *(unsigned long *)input; |
| 525 | |
| 526 | data.requested_ui_label = power_state_convert(ps); |
| 527 | ret = pem_handle_event(pp_handle->eventmgr, event_id, &data); |
Rex Zhu | dc26a2a | 2016-02-25 17:16:52 +0800 | [diff] [blame] | 528 | break; |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 529 | } |
Rex Zhu | dc26a2a | 2016-02-25 17:16:52 +0800 | [diff] [blame] | 530 | case AMD_PP_EVENT_COMPLETE_INIT: |
| 531 | ret = pem_handle_event(pp_handle->eventmgr, event_id, &data); |
| 532 | break; |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 533 | default: |
| 534 | break; |
| 535 | } |
| 536 | return ret; |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 537 | } |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 538 | |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 539 | enum amd_pm_state_type pp_dpm_get_current_power_state(void *handle) |
| 540 | { |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 541 | struct pp_hwmgr *hwmgr; |
| 542 | struct pp_power_state *state; |
| 543 | |
| 544 | if (handle == NULL) |
| 545 | return -EINVAL; |
| 546 | |
| 547 | hwmgr = ((struct pp_instance *)handle)->hwmgr; |
| 548 | |
| 549 | if (hwmgr == NULL || hwmgr->current_ps == NULL) |
| 550 | return -EINVAL; |
| 551 | |
| 552 | state = hwmgr->current_ps; |
| 553 | |
| 554 | switch (state->classification.ui_label) { |
| 555 | case PP_StateUILabel_Battery: |
| 556 | return POWER_STATE_TYPE_BATTERY; |
| 557 | case PP_StateUILabel_Balanced: |
| 558 | return POWER_STATE_TYPE_BALANCED; |
| 559 | case PP_StateUILabel_Performance: |
| 560 | return POWER_STATE_TYPE_PERFORMANCE; |
| 561 | default: |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 562 | if (state->classification.flags & PP_StateClassificationFlag_Boot) |
| 563 | return POWER_STATE_TYPE_INTERNAL_BOOT; |
| 564 | else |
| 565 | return POWER_STATE_TYPE_DEFAULT; |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 566 | } |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 567 | } |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 568 | |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 569 | static void |
| 570 | pp_debugfs_print_current_performance_level(void *handle, |
| 571 | struct seq_file *m) |
| 572 | { |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 573 | struct pp_hwmgr *hwmgr; |
| 574 | |
| 575 | if (handle == NULL) |
| 576 | return; |
| 577 | |
| 578 | hwmgr = ((struct pp_instance *)handle)->hwmgr; |
| 579 | |
Rex Zhu | 7383bcb | 2016-03-30 11:35:50 +0800 | [diff] [blame] | 580 | if (hwmgr == NULL || hwmgr->hwmgr_func == NULL) |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 581 | return; |
| 582 | |
Rex Zhu | 7383bcb | 2016-03-30 11:35:50 +0800 | [diff] [blame] | 583 | if (hwmgr->hwmgr_func->print_current_perforce_level == NULL) { |
| 584 | printk(KERN_INFO "%s was not implemented.\n", __func__); |
| 585 | return; |
| 586 | } |
| 587 | |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 588 | hwmgr->hwmgr_func->print_current_perforce_level(hwmgr, m); |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 589 | } |
Jammy Zhou | 3bace35 | 2015-07-21 21:18:15 +0800 | [diff] [blame] | 590 | |
Rex Zhu | cac9a19 | 2015-10-16 11:48:21 +0800 | [diff] [blame] | 591 | static int pp_dpm_set_fan_control_mode(void *handle, uint32_t mode) |
| 592 | { |
| 593 | struct pp_hwmgr *hwmgr; |
| 594 | |
| 595 | if (handle == NULL) |
| 596 | return -EINVAL; |
| 597 | |
| 598 | hwmgr = ((struct pp_instance *)handle)->hwmgr; |
| 599 | |
Rex Zhu | 7383bcb | 2016-03-30 11:35:50 +0800 | [diff] [blame] | 600 | PP_CHECK_HW(hwmgr); |
| 601 | |
| 602 | if (hwmgr->hwmgr_func->set_fan_control_mode == NULL) { |
| 603 | printk(KERN_INFO "%s was not implemented.\n", __func__); |
| 604 | return 0; |
| 605 | } |
Rex Zhu | cac9a19 | 2015-10-16 11:48:21 +0800 | [diff] [blame] | 606 | |
| 607 | return hwmgr->hwmgr_func->set_fan_control_mode(hwmgr, mode); |
| 608 | } |
| 609 | |
| 610 | static int pp_dpm_get_fan_control_mode(void *handle) |
| 611 | { |
| 612 | struct pp_hwmgr *hwmgr; |
| 613 | |
| 614 | if (handle == NULL) |
| 615 | return -EINVAL; |
| 616 | |
| 617 | hwmgr = ((struct pp_instance *)handle)->hwmgr; |
| 618 | |
Rex Zhu | 7383bcb | 2016-03-30 11:35:50 +0800 | [diff] [blame] | 619 | PP_CHECK_HW(hwmgr); |
| 620 | |
| 621 | if (hwmgr->hwmgr_func->get_fan_control_mode == NULL) { |
| 622 | printk(KERN_INFO "%s was not implemented.\n", __func__); |
| 623 | return 0; |
| 624 | } |
Rex Zhu | cac9a19 | 2015-10-16 11:48:21 +0800 | [diff] [blame] | 625 | |
| 626 | return hwmgr->hwmgr_func->get_fan_control_mode(hwmgr); |
| 627 | } |
| 628 | |
| 629 | static int pp_dpm_set_fan_speed_percent(void *handle, uint32_t percent) |
| 630 | { |
| 631 | struct pp_hwmgr *hwmgr; |
| 632 | |
| 633 | if (handle == NULL) |
| 634 | return -EINVAL; |
| 635 | |
| 636 | hwmgr = ((struct pp_instance *)handle)->hwmgr; |
| 637 | |
Rex Zhu | 7383bcb | 2016-03-30 11:35:50 +0800 | [diff] [blame] | 638 | PP_CHECK_HW(hwmgr); |
| 639 | |
| 640 | if (hwmgr->hwmgr_func->set_fan_speed_percent == NULL) { |
| 641 | printk(KERN_INFO "%s was not implemented.\n", __func__); |
| 642 | return 0; |
| 643 | } |
Rex Zhu | cac9a19 | 2015-10-16 11:48:21 +0800 | [diff] [blame] | 644 | |
| 645 | return hwmgr->hwmgr_func->set_fan_speed_percent(hwmgr, percent); |
| 646 | } |
| 647 | |
| 648 | static int pp_dpm_get_fan_speed_percent(void *handle, uint32_t *speed) |
| 649 | { |
| 650 | struct pp_hwmgr *hwmgr; |
| 651 | |
| 652 | if (handle == NULL) |
| 653 | return -EINVAL; |
| 654 | |
| 655 | hwmgr = ((struct pp_instance *)handle)->hwmgr; |
| 656 | |
Rex Zhu | 7383bcb | 2016-03-30 11:35:50 +0800 | [diff] [blame] | 657 | PP_CHECK_HW(hwmgr); |
| 658 | |
| 659 | if (hwmgr->hwmgr_func->get_fan_speed_percent == NULL) { |
| 660 | printk(KERN_INFO "%s was not implemented.\n", __func__); |
| 661 | return 0; |
| 662 | } |
Rex Zhu | cac9a19 | 2015-10-16 11:48:21 +0800 | [diff] [blame] | 663 | |
| 664 | return hwmgr->hwmgr_func->get_fan_speed_percent(hwmgr, speed); |
| 665 | } |
| 666 | |
| 667 | static int pp_dpm_get_temperature(void *handle) |
| 668 | { |
| 669 | struct pp_hwmgr *hwmgr; |
| 670 | |
| 671 | if (handle == NULL) |
| 672 | return -EINVAL; |
| 673 | |
| 674 | hwmgr = ((struct pp_instance *)handle)->hwmgr; |
| 675 | |
Rex Zhu | 7383bcb | 2016-03-30 11:35:50 +0800 | [diff] [blame] | 676 | PP_CHECK_HW(hwmgr); |
| 677 | |
| 678 | if (hwmgr->hwmgr_func->get_temperature == NULL) { |
| 679 | printk(KERN_INFO "%s was not implemented.\n", __func__); |
| 680 | return 0; |
| 681 | } |
Rex Zhu | cac9a19 | 2015-10-16 11:48:21 +0800 | [diff] [blame] | 682 | |
| 683 | return hwmgr->hwmgr_func->get_temperature(hwmgr); |
| 684 | } |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 685 | |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 686 | static int pp_dpm_get_pp_num_states(void *handle, |
| 687 | struct pp_states_info *data) |
| 688 | { |
| 689 | struct pp_hwmgr *hwmgr; |
| 690 | int i; |
| 691 | |
| 692 | if (!handle) |
| 693 | return -EINVAL; |
| 694 | |
| 695 | hwmgr = ((struct pp_instance *)handle)->hwmgr; |
| 696 | |
| 697 | if (hwmgr == NULL || hwmgr->ps == NULL) |
| 698 | return -EINVAL; |
| 699 | |
| 700 | data->nums = hwmgr->num_ps; |
| 701 | |
| 702 | for (i = 0; i < hwmgr->num_ps; i++) { |
| 703 | struct pp_power_state *state = (struct pp_power_state *) |
| 704 | ((unsigned long)hwmgr->ps + i * hwmgr->ps_size); |
| 705 | switch (state->classification.ui_label) { |
| 706 | case PP_StateUILabel_Battery: |
| 707 | data->states[i] = POWER_STATE_TYPE_BATTERY; |
| 708 | break; |
| 709 | case PP_StateUILabel_Balanced: |
| 710 | data->states[i] = POWER_STATE_TYPE_BALANCED; |
| 711 | break; |
| 712 | case PP_StateUILabel_Performance: |
| 713 | data->states[i] = POWER_STATE_TYPE_PERFORMANCE; |
| 714 | break; |
| 715 | default: |
| 716 | if (state->classification.flags & PP_StateClassificationFlag_Boot) |
| 717 | data->states[i] = POWER_STATE_TYPE_INTERNAL_BOOT; |
| 718 | else |
| 719 | data->states[i] = POWER_STATE_TYPE_DEFAULT; |
| 720 | } |
| 721 | } |
| 722 | |
| 723 | return 0; |
| 724 | } |
| 725 | |
| 726 | static int pp_dpm_get_pp_table(void *handle, char **table) |
| 727 | { |
| 728 | struct pp_hwmgr *hwmgr; |
| 729 | |
| 730 | if (!handle) |
| 731 | return -EINVAL; |
| 732 | |
| 733 | hwmgr = ((struct pp_instance *)handle)->hwmgr; |
| 734 | |
Rex Zhu | 7383bcb | 2016-03-30 11:35:50 +0800 | [diff] [blame] | 735 | PP_CHECK_HW(hwmgr); |
| 736 | |
| 737 | if (hwmgr->hwmgr_func->get_pp_table == NULL) { |
| 738 | printk(KERN_INFO "%s was not implemented.\n", __func__); |
| 739 | return 0; |
| 740 | } |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 741 | |
| 742 | return hwmgr->hwmgr_func->get_pp_table(hwmgr, table); |
| 743 | } |
| 744 | |
| 745 | static int pp_dpm_set_pp_table(void *handle, const char *buf, size_t size) |
| 746 | { |
| 747 | struct pp_hwmgr *hwmgr; |
| 748 | |
| 749 | if (!handle) |
| 750 | return -EINVAL; |
| 751 | |
| 752 | hwmgr = ((struct pp_instance *)handle)->hwmgr; |
| 753 | |
Rex Zhu | 7383bcb | 2016-03-30 11:35:50 +0800 | [diff] [blame] | 754 | PP_CHECK_HW(hwmgr); |
| 755 | |
| 756 | if (hwmgr->hwmgr_func->set_pp_table == NULL) { |
| 757 | printk(KERN_INFO "%s was not implemented.\n", __func__); |
| 758 | return 0; |
| 759 | } |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 760 | |
| 761 | return hwmgr->hwmgr_func->set_pp_table(hwmgr, buf, size); |
| 762 | } |
| 763 | |
| 764 | static int pp_dpm_force_clock_level(void *handle, |
Eric Huang | 5632708 | 2016-04-12 14:57:23 -0400 | [diff] [blame] | 765 | enum pp_clock_type type, uint32_t mask) |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 766 | { |
| 767 | struct pp_hwmgr *hwmgr; |
| 768 | |
| 769 | if (!handle) |
| 770 | return -EINVAL; |
| 771 | |
| 772 | hwmgr = ((struct pp_instance *)handle)->hwmgr; |
| 773 | |
Rex Zhu | 7383bcb | 2016-03-30 11:35:50 +0800 | [diff] [blame] | 774 | PP_CHECK_HW(hwmgr); |
| 775 | |
| 776 | if (hwmgr->hwmgr_func->force_clock_level == NULL) { |
| 777 | printk(KERN_INFO "%s was not implemented.\n", __func__); |
| 778 | return 0; |
| 779 | } |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 780 | |
Eric Huang | 5632708 | 2016-04-12 14:57:23 -0400 | [diff] [blame] | 781 | return hwmgr->hwmgr_func->force_clock_level(hwmgr, type, mask); |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 782 | } |
| 783 | |
| 784 | static int pp_dpm_print_clock_levels(void *handle, |
| 785 | enum pp_clock_type type, char *buf) |
| 786 | { |
| 787 | struct pp_hwmgr *hwmgr; |
| 788 | |
| 789 | if (!handle) |
| 790 | return -EINVAL; |
| 791 | |
| 792 | hwmgr = ((struct pp_instance *)handle)->hwmgr; |
| 793 | |
Rex Zhu | 7383bcb | 2016-03-30 11:35:50 +0800 | [diff] [blame] | 794 | PP_CHECK_HW(hwmgr); |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 795 | |
Rex Zhu | 7383bcb | 2016-03-30 11:35:50 +0800 | [diff] [blame] | 796 | if (hwmgr->hwmgr_func->print_clock_levels == NULL) { |
| 797 | printk(KERN_INFO "%s was not implemented.\n", __func__); |
| 798 | return 0; |
| 799 | } |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 800 | return hwmgr->hwmgr_func->print_clock_levels(hwmgr, type, buf); |
| 801 | } |
| 802 | |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 803 | const struct amd_powerplay_funcs pp_dpm_funcs = { |
Rex Zhu | cac9a19 | 2015-10-16 11:48:21 +0800 | [diff] [blame] | 804 | .get_temperature = pp_dpm_get_temperature, |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 805 | .load_firmware = pp_dpm_load_fw, |
| 806 | .wait_for_fw_loading_complete = pp_dpm_fw_loading_complete, |
| 807 | .force_performance_level = pp_dpm_force_performance_level, |
| 808 | .get_performance_level = pp_dpm_get_performance_level, |
| 809 | .get_current_power_state = pp_dpm_get_current_power_state, |
| 810 | .get_sclk = pp_dpm_get_sclk, |
| 811 | .get_mclk = pp_dpm_get_mclk, |
| 812 | .powergate_vce = pp_dpm_powergate_vce, |
| 813 | .powergate_uvd = pp_dpm_powergate_uvd, |
| 814 | .dispatch_tasks = pp_dpm_dispatch_tasks, |
| 815 | .print_current_performance_level = pp_debugfs_print_current_performance_level, |
Rex Zhu | cac9a19 | 2015-10-16 11:48:21 +0800 | [diff] [blame] | 816 | .set_fan_control_mode = pp_dpm_set_fan_control_mode, |
| 817 | .get_fan_control_mode = pp_dpm_get_fan_control_mode, |
| 818 | .set_fan_speed_percent = pp_dpm_set_fan_speed_percent, |
| 819 | .get_fan_speed_percent = pp_dpm_get_fan_speed_percent, |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 820 | .get_pp_num_states = pp_dpm_get_pp_num_states, |
| 821 | .get_pp_table = pp_dpm_get_pp_table, |
| 822 | .set_pp_table = pp_dpm_set_pp_table, |
| 823 | .force_clock_level = pp_dpm_force_clock_level, |
| 824 | .print_clock_levels = pp_dpm_print_clock_levels, |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 825 | }; |
| 826 | |
Jammy Zhou | ac885b3 | 2015-07-21 17:43:02 +0800 | [diff] [blame] | 827 | static int amd_pp_instance_init(struct amd_pp_init *pp_init, |
| 828 | struct amd_powerplay *amd_pp) |
| 829 | { |
| 830 | int ret; |
| 831 | struct pp_instance *handle; |
| 832 | |
| 833 | handle = kzalloc(sizeof(struct pp_instance), GFP_KERNEL); |
| 834 | if (handle == NULL) |
| 835 | return -ENOMEM; |
| 836 | |
Rex Zhu | a969e16 | 2015-12-29 13:56:03 +0800 | [diff] [blame] | 837 | handle->pp_valid = PP_VALID; |
| 838 | |
Jammy Zhou | ac885b3 | 2015-07-21 17:43:02 +0800 | [diff] [blame] | 839 | ret = smum_init(pp_init, handle); |
| 840 | if (ret) |
Jammy Zhou | 3bace35 | 2015-07-21 21:18:15 +0800 | [diff] [blame] | 841 | goto fail_smum; |
| 842 | |
| 843 | ret = hwmgr_init(pp_init, handle); |
| 844 | if (ret) |
| 845 | goto fail_hwmgr; |
Jammy Zhou | ac885b3 | 2015-07-21 17:43:02 +0800 | [diff] [blame] | 846 | |
Rex Zhu | e92a037 | 2015-09-23 15:14:54 +0800 | [diff] [blame] | 847 | ret = eventmgr_init(handle); |
| 848 | if (ret) |
| 849 | goto fail_eventmgr; |
| 850 | |
Jammy Zhou | ac885b3 | 2015-07-21 17:43:02 +0800 | [diff] [blame] | 851 | amd_pp->pp_handle = handle; |
| 852 | return 0; |
Jammy Zhou | 3bace35 | 2015-07-21 21:18:15 +0800 | [diff] [blame] | 853 | |
Rex Zhu | e92a037 | 2015-09-23 15:14:54 +0800 | [diff] [blame] | 854 | fail_eventmgr: |
| 855 | hwmgr_fini(handle->hwmgr); |
Jammy Zhou | 3bace35 | 2015-07-21 21:18:15 +0800 | [diff] [blame] | 856 | fail_hwmgr: |
| 857 | smum_fini(handle->smu_mgr); |
| 858 | fail_smum: |
| 859 | kfree(handle); |
| 860 | return ret; |
Jammy Zhou | ac885b3 | 2015-07-21 17:43:02 +0800 | [diff] [blame] | 861 | } |
| 862 | |
| 863 | static int amd_pp_instance_fini(void *handle) |
| 864 | { |
| 865 | struct pp_instance *instance = (struct pp_instance *)handle; |
Rex Zhu | e92a037 | 2015-09-23 15:14:54 +0800 | [diff] [blame] | 866 | |
Jammy Zhou | ac885b3 | 2015-07-21 17:43:02 +0800 | [diff] [blame] | 867 | if (instance == NULL) |
| 868 | return -EINVAL; |
| 869 | |
Rex Zhu | e92a037 | 2015-09-23 15:14:54 +0800 | [diff] [blame] | 870 | eventmgr_fini(instance->eventmgr); |
| 871 | |
Jammy Zhou | 3bace35 | 2015-07-21 21:18:15 +0800 | [diff] [blame] | 872 | hwmgr_fini(instance->hwmgr); |
| 873 | |
Jammy Zhou | ac885b3 | 2015-07-21 17:43:02 +0800 | [diff] [blame] | 874 | smum_fini(instance->smu_mgr); |
| 875 | |
| 876 | kfree(handle); |
| 877 | return 0; |
| 878 | } |
| 879 | |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 880 | int amd_powerplay_init(struct amd_pp_init *pp_init, |
| 881 | struct amd_powerplay *amd_pp) |
| 882 | { |
Jammy Zhou | ac885b3 | 2015-07-21 17:43:02 +0800 | [diff] [blame] | 883 | int ret; |
| 884 | |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 885 | if (pp_init == NULL || amd_pp == NULL) |
| 886 | return -EINVAL; |
| 887 | |
Jammy Zhou | ac885b3 | 2015-07-21 17:43:02 +0800 | [diff] [blame] | 888 | ret = amd_pp_instance_init(pp_init, amd_pp); |
| 889 | |
| 890 | if (ret) |
| 891 | return ret; |
| 892 | |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 893 | amd_pp->ip_funcs = &pp_ip_funcs; |
| 894 | amd_pp->pp_funcs = &pp_dpm_funcs; |
| 895 | |
| 896 | return 0; |
| 897 | } |
| 898 | |
| 899 | int amd_powerplay_fini(void *handle) |
| 900 | { |
Jammy Zhou | ac885b3 | 2015-07-21 17:43:02 +0800 | [diff] [blame] | 901 | amd_pp_instance_fini(handle); |
| 902 | |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 903 | return 0; |
| 904 | } |
Rex Zhu | 7fb72a1 | 2015-11-19 13:35:30 +0800 | [diff] [blame] | 905 | |
| 906 | /* export this function to DAL */ |
| 907 | |
David Rokhvarg | 155f1127c | 2015-12-14 10:51:39 -0500 | [diff] [blame] | 908 | int amd_powerplay_display_configuration_change(void *handle, |
| 909 | const struct amd_pp_display_configuration *display_config) |
Rex Zhu | 7fb72a1 | 2015-11-19 13:35:30 +0800 | [diff] [blame] | 910 | { |
| 911 | struct pp_hwmgr *hwmgr; |
Rex Zhu | 7fb72a1 | 2015-11-19 13:35:30 +0800 | [diff] [blame] | 912 | |
Rex Zhu | a969e16 | 2015-12-29 13:56:03 +0800 | [diff] [blame] | 913 | PP_CHECK((struct pp_instance *)handle); |
Rex Zhu | 7fb72a1 | 2015-11-19 13:35:30 +0800 | [diff] [blame] | 914 | |
| 915 | hwmgr = ((struct pp_instance *)handle)->hwmgr; |
| 916 | |
| 917 | phm_store_dal_configuration_data(hwmgr, display_config); |
Rex Zhu | e0b71a7 | 2015-12-29 10:25:19 +0800 | [diff] [blame] | 918 | |
Rex Zhu | 7fb72a1 | 2015-11-19 13:35:30 +0800 | [diff] [blame] | 919 | return 0; |
| 920 | } |
Vitaly Prosyak | c4dd206 | 2015-11-30 16:39:53 -0500 | [diff] [blame] | 921 | |
Vitaly Prosyak | 1c9a908 | 2015-12-03 10:27:57 -0500 | [diff] [blame] | 922 | int amd_powerplay_get_display_power_level(void *handle, |
Rex Zhu | 4732913 | 2015-12-10 16:49:50 +0800 | [diff] [blame] | 923 | struct amd_pp_simple_clock_info *output) |
Vitaly Prosyak | c4dd206 | 2015-11-30 16:39:53 -0500 | [diff] [blame] | 924 | { |
| 925 | struct pp_hwmgr *hwmgr; |
| 926 | |
Rex Zhu | a969e16 | 2015-12-29 13:56:03 +0800 | [diff] [blame] | 927 | PP_CHECK((struct pp_instance *)handle); |
| 928 | |
| 929 | if (output == NULL) |
Vitaly Prosyak | c4dd206 | 2015-11-30 16:39:53 -0500 | [diff] [blame] | 930 | return -EINVAL; |
| 931 | |
| 932 | hwmgr = ((struct pp_instance *)handle)->hwmgr; |
| 933 | |
Vitaly Prosyak | 1c9a908 | 2015-12-03 10:27:57 -0500 | [diff] [blame] | 934 | return phm_get_dal_power_level(hwmgr, output); |
Vitaly Prosyak | c4dd206 | 2015-11-30 16:39:53 -0500 | [diff] [blame] | 935 | } |
Rex Zhu | e273b04 | 2015-12-07 18:44:23 +0800 | [diff] [blame] | 936 | |
| 937 | int amd_powerplay_get_current_clocks(void *handle, |
David Rokhvarg | 155f1127c | 2015-12-14 10:51:39 -0500 | [diff] [blame] | 938 | struct amd_pp_clock_info *clocks) |
Rex Zhu | e273b04 | 2015-12-07 18:44:23 +0800 | [diff] [blame] | 939 | { |
| 940 | struct pp_hwmgr *hwmgr; |
| 941 | struct amd_pp_simple_clock_info simple_clocks; |
| 942 | struct pp_clock_info hw_clocks; |
Rex Zhu | e273b04 | 2015-12-07 18:44:23 +0800 | [diff] [blame] | 943 | |
Rex Zhu | fa9e699 | 2015-12-29 13:56:03 +0800 | [diff] [blame] | 944 | PP_CHECK((struct pp_instance *)handle); |
| 945 | |
| 946 | if (clocks == NULL) |
Rex Zhu | e273b04 | 2015-12-07 18:44:23 +0800 | [diff] [blame] | 947 | return -EINVAL; |
| 948 | |
| 949 | hwmgr = ((struct pp_instance *)handle)->hwmgr; |
| 950 | |
| 951 | phm_get_dal_power_level(hwmgr, &simple_clocks); |
| 952 | |
| 953 | if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_PowerContainment)) { |
| 954 | if (0 != phm_get_clock_info(hwmgr, &hwmgr->current_ps->hardware, &hw_clocks, PHM_PerformanceLevelDesignation_PowerContainment)) |
| 955 | PP_ASSERT_WITH_CODE(0, "Error in PHM_GetPowerContainmentClockInfo", return -1); |
| 956 | } else { |
| 957 | if (0 != phm_get_clock_info(hwmgr, &hwmgr->current_ps->hardware, &hw_clocks, PHM_PerformanceLevelDesignation_Activity)) |
| 958 | PP_ASSERT_WITH_CODE(0, "Error in PHM_GetClockInfo", return -1); |
| 959 | } |
| 960 | |
| 961 | clocks->min_engine_clock = hw_clocks.min_eng_clk; |
| 962 | clocks->max_engine_clock = hw_clocks.max_eng_clk; |
| 963 | clocks->min_memory_clock = hw_clocks.min_mem_clk; |
| 964 | clocks->max_memory_clock = hw_clocks.max_mem_clk; |
| 965 | clocks->min_bus_bandwidth = hw_clocks.min_bus_bandwidth; |
| 966 | clocks->max_bus_bandwidth = hw_clocks.max_bus_bandwidth; |
| 967 | |
| 968 | clocks->max_engine_clock_in_sr = hw_clocks.max_eng_clk; |
| 969 | clocks->min_engine_clock_in_sr = hw_clocks.min_eng_clk; |
| 970 | |
| 971 | clocks->max_clocks_state = simple_clocks.level; |
| 972 | |
| 973 | if (0 == phm_get_current_shallow_sleep_clocks(hwmgr, &hwmgr->current_ps->hardware, &hw_clocks)) { |
| 974 | clocks->max_engine_clock_in_sr = hw_clocks.max_eng_clk; |
| 975 | clocks->min_engine_clock_in_sr = hw_clocks.min_eng_clk; |
| 976 | } |
| 977 | |
| 978 | return 0; |
| 979 | |
| 980 | } |
| 981 | |
| 982 | int amd_powerplay_get_clock_by_type(void *handle, enum amd_pp_clock_type type, struct amd_pp_clocks *clocks) |
| 983 | { |
| 984 | int result = -1; |
| 985 | |
| 986 | struct pp_hwmgr *hwmgr; |
| 987 | |
Rex Zhu | fa9e699 | 2015-12-29 13:56:03 +0800 | [diff] [blame] | 988 | PP_CHECK((struct pp_instance *)handle); |
| 989 | |
| 990 | if (clocks == NULL) |
Rex Zhu | e273b04 | 2015-12-07 18:44:23 +0800 | [diff] [blame] | 991 | return -EINVAL; |
| 992 | |
| 993 | hwmgr = ((struct pp_instance *)handle)->hwmgr; |
| 994 | |
| 995 | result = phm_get_clock_by_type(hwmgr, type, clocks); |
| 996 | |
| 997 | return result; |
| 998 | } |
| 999 | |
David Rokhvarg | 155f1127c | 2015-12-14 10:51:39 -0500 | [diff] [blame] | 1000 | int amd_powerplay_get_display_mode_validation_clocks(void *handle, |
| 1001 | struct amd_pp_simple_clock_info *clocks) |
Rex Zhu | e273b04 | 2015-12-07 18:44:23 +0800 | [diff] [blame] | 1002 | { |
| 1003 | int result = -1; |
Rex Zhu | e273b04 | 2015-12-07 18:44:23 +0800 | [diff] [blame] | 1004 | struct pp_hwmgr *hwmgr; |
| 1005 | |
Rex Zhu | fa9e699 | 2015-12-29 13:56:03 +0800 | [diff] [blame] | 1006 | PP_CHECK((struct pp_instance *)handle); |
| 1007 | |
| 1008 | if (clocks == NULL) |
Rex Zhu | e273b04 | 2015-12-07 18:44:23 +0800 | [diff] [blame] | 1009 | return -EINVAL; |
| 1010 | |
| 1011 | hwmgr = ((struct pp_instance *)handle)->hwmgr; |
| 1012 | |
| 1013 | if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_DynamicPatchPowerState)) |
| 1014 | result = phm_get_max_high_clocks(hwmgr, clocks); |
| 1015 | |
| 1016 | return result; |
| 1017 | } |
| 1018 | |