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