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" |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 32 | |
| 33 | static int pp_early_init(void *handle) |
| 34 | { |
| 35 | return 0; |
| 36 | } |
| 37 | |
| 38 | static int pp_sw_init(void *handle) |
| 39 | { |
Jammy Zhou | 3bace35 | 2015-07-21 21:18:15 +0800 | [diff] [blame] | 40 | struct pp_instance *pp_handle; |
| 41 | struct pp_hwmgr *hwmgr; |
| 42 | int ret = 0; |
| 43 | |
| 44 | if (handle == NULL) |
| 45 | return -EINVAL; |
| 46 | |
| 47 | pp_handle = (struct pp_instance *)handle; |
| 48 | hwmgr = pp_handle->hwmgr; |
| 49 | |
| 50 | if (hwmgr == NULL || hwmgr->pptable_func == NULL || |
| 51 | hwmgr->hwmgr_func == NULL || |
| 52 | hwmgr->pptable_func->pptable_init == NULL || |
| 53 | hwmgr->hwmgr_func->backend_init == NULL) |
| 54 | return -EINVAL; |
| 55 | |
| 56 | ret = hwmgr->pptable_func->pptable_init(hwmgr); |
Rex Zhu | e92a037 | 2015-09-23 15:14:54 +0800 | [diff] [blame] | 57 | |
Jammy Zhou | 3bace35 | 2015-07-21 21:18:15 +0800 | [diff] [blame] | 58 | if (ret == 0) |
| 59 | ret = hwmgr->hwmgr_func->backend_init(hwmgr); |
| 60 | |
| 61 | return ret; |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | static int pp_sw_fini(void *handle) |
| 65 | { |
Jammy Zhou | 3bace35 | 2015-07-21 21:18:15 +0800 | [diff] [blame] | 66 | struct pp_instance *pp_handle; |
| 67 | struct pp_hwmgr *hwmgr; |
| 68 | int ret = 0; |
| 69 | |
| 70 | if (handle == NULL) |
| 71 | return -EINVAL; |
| 72 | |
| 73 | pp_handle = (struct pp_instance *)handle; |
| 74 | hwmgr = pp_handle->hwmgr; |
| 75 | |
| 76 | if (hwmgr != NULL || hwmgr->hwmgr_func != NULL || |
| 77 | hwmgr->hwmgr_func->backend_fini != NULL) |
| 78 | ret = hwmgr->hwmgr_func->backend_fini(hwmgr); |
| 79 | |
| 80 | return ret; |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | static int pp_hw_init(void *handle) |
| 84 | { |
Jammy Zhou | ac885b3 | 2015-07-21 17:43:02 +0800 | [diff] [blame] | 85 | struct pp_instance *pp_handle; |
| 86 | struct pp_smumgr *smumgr; |
Rex Zhu | e92a037 | 2015-09-23 15:14:54 +0800 | [diff] [blame] | 87 | struct pp_eventmgr *eventmgr; |
Jammy Zhou | ac885b3 | 2015-07-21 17:43:02 +0800 | [diff] [blame] | 88 | int ret = 0; |
| 89 | |
| 90 | if (handle == NULL) |
| 91 | return -EINVAL; |
| 92 | |
| 93 | pp_handle = (struct pp_instance *)handle; |
| 94 | smumgr = pp_handle->smu_mgr; |
| 95 | |
| 96 | if (smumgr == NULL || smumgr->smumgr_funcs == NULL || |
| 97 | smumgr->smumgr_funcs->smu_init == NULL || |
| 98 | smumgr->smumgr_funcs->start_smu == NULL) |
| 99 | return -EINVAL; |
| 100 | |
| 101 | ret = smumgr->smumgr_funcs->smu_init(smumgr); |
| 102 | if (ret) { |
| 103 | printk(KERN_ERR "[ powerplay ] smc initialization failed\n"); |
| 104 | return ret; |
| 105 | } |
| 106 | |
| 107 | ret = smumgr->smumgr_funcs->start_smu(smumgr); |
| 108 | if (ret) { |
| 109 | printk(KERN_ERR "[ powerplay ] smc start failed\n"); |
| 110 | smumgr->smumgr_funcs->smu_fini(smumgr); |
| 111 | return ret; |
| 112 | } |
Jammy Zhou | 3bace35 | 2015-07-21 21:18:15 +0800 | [diff] [blame] | 113 | |
Rex Zhu | e92a037 | 2015-09-23 15:14:54 +0800 | [diff] [blame] | 114 | hw_init_power_state_table(pp_handle->hwmgr); |
| 115 | eventmgr = pp_handle->eventmgr; |
| 116 | |
| 117 | if (eventmgr == NULL || eventmgr->pp_eventmgr_init == NULL) |
| 118 | return -EINVAL; |
| 119 | |
| 120 | ret = eventmgr->pp_eventmgr_init(eventmgr); |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 121 | return 0; |
| 122 | } |
| 123 | |
| 124 | static int pp_hw_fini(void *handle) |
| 125 | { |
Jammy Zhou | ac885b3 | 2015-07-21 17:43:02 +0800 | [diff] [blame] | 126 | struct pp_instance *pp_handle; |
| 127 | struct pp_smumgr *smumgr; |
Rex Zhu | e92a037 | 2015-09-23 15:14:54 +0800 | [diff] [blame] | 128 | struct pp_eventmgr *eventmgr; |
Jammy Zhou | ac885b3 | 2015-07-21 17:43:02 +0800 | [diff] [blame] | 129 | |
| 130 | if (handle == NULL) |
| 131 | return -EINVAL; |
| 132 | |
| 133 | pp_handle = (struct pp_instance *)handle; |
Rex Zhu | e92a037 | 2015-09-23 15:14:54 +0800 | [diff] [blame] | 134 | eventmgr = pp_handle->eventmgr; |
| 135 | |
| 136 | if (eventmgr != NULL || eventmgr->pp_eventmgr_fini != NULL) |
| 137 | eventmgr->pp_eventmgr_fini(eventmgr); |
| 138 | |
Jammy Zhou | ac885b3 | 2015-07-21 17:43:02 +0800 | [diff] [blame] | 139 | smumgr = pp_handle->smu_mgr; |
| 140 | |
| 141 | if (smumgr != NULL || smumgr->smumgr_funcs != NULL || |
| 142 | smumgr->smumgr_funcs->smu_fini != NULL) |
| 143 | smumgr->smumgr_funcs->smu_fini(smumgr); |
| 144 | |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 145 | return 0; |
| 146 | } |
| 147 | |
| 148 | static bool pp_is_idle(void *handle) |
| 149 | { |
| 150 | return 0; |
| 151 | } |
| 152 | |
| 153 | static int pp_wait_for_idle(void *handle) |
| 154 | { |
| 155 | return 0; |
| 156 | } |
| 157 | |
| 158 | static int pp_sw_reset(void *handle) |
| 159 | { |
| 160 | return 0; |
| 161 | } |
| 162 | |
| 163 | static void pp_print_status(void *handle) |
| 164 | { |
| 165 | |
| 166 | } |
| 167 | |
| 168 | static int pp_set_clockgating_state(void *handle, |
| 169 | enum amd_clockgating_state state) |
| 170 | { |
| 171 | return 0; |
| 172 | } |
| 173 | |
| 174 | static int pp_set_powergating_state(void *handle, |
| 175 | enum amd_powergating_state state) |
| 176 | { |
| 177 | return 0; |
| 178 | } |
| 179 | |
| 180 | static int pp_suspend(void *handle) |
| 181 | { |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame^] | 182 | struct pp_instance *pp_handle; |
| 183 | struct pp_eventmgr *eventmgr; |
| 184 | struct pem_event_data event_data = { {0} }; |
| 185 | |
| 186 | if (handle == NULL) |
| 187 | return -EINVAL; |
| 188 | |
| 189 | pp_handle = (struct pp_instance *)handle; |
| 190 | eventmgr = pp_handle->eventmgr; |
| 191 | pem_handle_event(eventmgr, AMD_PP_EVENT_SUSPEND, &event_data); |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 192 | return 0; |
| 193 | } |
| 194 | |
| 195 | static int pp_resume(void *handle) |
| 196 | { |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame^] | 197 | struct pp_instance *pp_handle; |
| 198 | struct pp_eventmgr *eventmgr; |
| 199 | struct pem_event_data event_data = { {0} }; |
| 200 | |
| 201 | if (handle == NULL) |
| 202 | return -EINVAL; |
| 203 | |
| 204 | pp_handle = (struct pp_instance *)handle; |
| 205 | eventmgr = pp_handle->eventmgr; |
| 206 | pem_handle_event(eventmgr, AMD_PP_EVENT_RESUME, &event_data); |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 207 | return 0; |
| 208 | } |
| 209 | |
| 210 | const struct amd_ip_funcs pp_ip_funcs = { |
| 211 | .early_init = pp_early_init, |
| 212 | .late_init = NULL, |
| 213 | .sw_init = pp_sw_init, |
| 214 | .sw_fini = pp_sw_fini, |
| 215 | .hw_init = pp_hw_init, |
| 216 | .hw_fini = pp_hw_fini, |
| 217 | .suspend = pp_suspend, |
| 218 | .resume = pp_resume, |
| 219 | .is_idle = pp_is_idle, |
| 220 | .wait_for_idle = pp_wait_for_idle, |
| 221 | .soft_reset = pp_sw_reset, |
| 222 | .print_status = pp_print_status, |
| 223 | .set_clockgating_state = pp_set_clockgating_state, |
| 224 | .set_powergating_state = pp_set_powergating_state, |
| 225 | }; |
| 226 | |
| 227 | static int pp_dpm_load_fw(void *handle) |
| 228 | { |
| 229 | return 0; |
| 230 | } |
| 231 | |
| 232 | static int pp_dpm_fw_loading_complete(void *handle) |
| 233 | { |
| 234 | return 0; |
| 235 | } |
| 236 | |
| 237 | static int pp_dpm_force_performance_level(void *handle, |
| 238 | enum amd_dpm_forced_level level) |
| 239 | { |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame^] | 240 | struct pp_instance *pp_handle; |
| 241 | struct pp_hwmgr *hwmgr; |
| 242 | |
| 243 | if (handle == NULL) |
| 244 | return -EINVAL; |
| 245 | |
| 246 | pp_handle = (struct pp_instance *)handle; |
| 247 | |
| 248 | hwmgr = pp_handle->hwmgr; |
| 249 | |
| 250 | if (hwmgr == NULL || hwmgr->hwmgr_func == NULL || |
| 251 | hwmgr->hwmgr_func->force_dpm_level == NULL) |
| 252 | return -EINVAL; |
| 253 | |
| 254 | hwmgr->hwmgr_func->force_dpm_level(hwmgr, level); |
| 255 | |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 256 | return 0; |
| 257 | } |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame^] | 258 | |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 259 | static enum amd_dpm_forced_level pp_dpm_get_performance_level( |
| 260 | void *handle) |
| 261 | { |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame^] | 262 | struct pp_hwmgr *hwmgr; |
| 263 | |
| 264 | if (handle == NULL) |
| 265 | return -EINVAL; |
| 266 | |
| 267 | hwmgr = ((struct pp_instance *)handle)->hwmgr; |
| 268 | |
| 269 | if (hwmgr == NULL) |
| 270 | return -EINVAL; |
| 271 | |
| 272 | return (((struct pp_instance *)handle)->hwmgr->dpm_level); |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 273 | } |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame^] | 274 | |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 275 | static int pp_dpm_get_sclk(void *handle, bool low) |
| 276 | { |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame^] | 277 | struct pp_hwmgr *hwmgr; |
| 278 | |
| 279 | if (handle == NULL) |
| 280 | return -EINVAL; |
| 281 | |
| 282 | hwmgr = ((struct pp_instance *)handle)->hwmgr; |
| 283 | |
| 284 | if (hwmgr == NULL || hwmgr->hwmgr_func == NULL || |
| 285 | hwmgr->hwmgr_func->get_sclk == NULL) |
| 286 | return -EINVAL; |
| 287 | |
| 288 | return hwmgr->hwmgr_func->get_sclk(hwmgr, low); |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 289 | } |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame^] | 290 | |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 291 | static int pp_dpm_get_mclk(void *handle, bool low) |
| 292 | { |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame^] | 293 | struct pp_hwmgr *hwmgr; |
| 294 | |
| 295 | if (handle == NULL) |
| 296 | return -EINVAL; |
| 297 | |
| 298 | hwmgr = ((struct pp_instance *)handle)->hwmgr; |
| 299 | |
| 300 | if (hwmgr == NULL || hwmgr->hwmgr_func == NULL || |
| 301 | hwmgr->hwmgr_func->get_mclk == NULL) |
| 302 | return -EINVAL; |
| 303 | |
| 304 | return hwmgr->hwmgr_func->get_mclk(hwmgr, low); |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 305 | } |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame^] | 306 | |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 307 | static int pp_dpm_powergate_vce(void *handle, bool gate) |
| 308 | { |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame^] | 309 | struct pp_hwmgr *hwmgr; |
| 310 | |
| 311 | if (handle == NULL) |
| 312 | return -EINVAL; |
| 313 | |
| 314 | hwmgr = ((struct pp_instance *)handle)->hwmgr; |
| 315 | |
| 316 | if (hwmgr == NULL || hwmgr->hwmgr_func == NULL || |
| 317 | hwmgr->hwmgr_func->powergate_vce == NULL) |
| 318 | return -EINVAL; |
| 319 | |
| 320 | return hwmgr->hwmgr_func->powergate_vce(hwmgr, gate); |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 321 | } |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame^] | 322 | |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 323 | static int pp_dpm_powergate_uvd(void *handle, bool gate) |
| 324 | { |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame^] | 325 | struct pp_hwmgr *hwmgr; |
| 326 | |
| 327 | if (handle == NULL) |
| 328 | return -EINVAL; |
| 329 | |
| 330 | hwmgr = ((struct pp_instance *)handle)->hwmgr; |
| 331 | |
| 332 | if (hwmgr == NULL || hwmgr->hwmgr_func == NULL || |
| 333 | hwmgr->hwmgr_func->powergate_uvd == NULL) |
| 334 | return -EINVAL; |
| 335 | |
| 336 | return hwmgr->hwmgr_func->powergate_uvd(hwmgr, gate); |
| 337 | } |
| 338 | |
| 339 | static enum PP_StateUILabel power_state_convert(enum amd_pm_state_type state) |
| 340 | { |
| 341 | switch (state) { |
| 342 | case POWER_STATE_TYPE_BATTERY: |
| 343 | return PP_StateUILabel_Battery; |
| 344 | case POWER_STATE_TYPE_BALANCED: |
| 345 | return PP_StateUILabel_Balanced; |
| 346 | case POWER_STATE_TYPE_PERFORMANCE: |
| 347 | return PP_StateUILabel_Performance; |
| 348 | default: |
| 349 | return PP_StateUILabel_None; |
| 350 | } |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 351 | } |
| 352 | |
| 353 | int pp_dpm_dispatch_tasks(void *handle, enum amd_pp_event event_id, void *input, void *output) |
| 354 | { |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame^] | 355 | int ret = 0; |
| 356 | struct pp_instance *pp_handle; |
| 357 | struct pem_event_data data = { {0} }; |
| 358 | |
| 359 | pp_handle = (struct pp_instance *)handle; |
| 360 | |
| 361 | if (pp_handle == NULL) |
| 362 | return -EINVAL; |
| 363 | |
| 364 | switch (event_id) { |
| 365 | case AMD_PP_EVENT_DISPLAY_CONFIG_CHANGE: |
| 366 | ret = pem_handle_event(pp_handle->eventmgr, event_id, &data); |
| 367 | break; |
| 368 | case AMD_PP_EVENT_ENABLE_USER_STATE: |
| 369 | { |
| 370 | enum amd_pm_state_type ps; |
| 371 | |
| 372 | if (input == NULL) |
| 373 | return -EINVAL; |
| 374 | ps = *(unsigned long *)input; |
| 375 | |
| 376 | data.requested_ui_label = power_state_convert(ps); |
| 377 | ret = pem_handle_event(pp_handle->eventmgr, event_id, &data); |
| 378 | } |
| 379 | break; |
| 380 | default: |
| 381 | break; |
| 382 | } |
| 383 | return ret; |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 384 | } |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame^] | 385 | |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 386 | enum amd_pm_state_type pp_dpm_get_current_power_state(void *handle) |
| 387 | { |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame^] | 388 | struct pp_hwmgr *hwmgr; |
| 389 | struct pp_power_state *state; |
| 390 | |
| 391 | if (handle == NULL) |
| 392 | return -EINVAL; |
| 393 | |
| 394 | hwmgr = ((struct pp_instance *)handle)->hwmgr; |
| 395 | |
| 396 | if (hwmgr == NULL || hwmgr->current_ps == NULL) |
| 397 | return -EINVAL; |
| 398 | |
| 399 | state = hwmgr->current_ps; |
| 400 | |
| 401 | switch (state->classification.ui_label) { |
| 402 | case PP_StateUILabel_Battery: |
| 403 | return POWER_STATE_TYPE_BATTERY; |
| 404 | case PP_StateUILabel_Balanced: |
| 405 | return POWER_STATE_TYPE_BALANCED; |
| 406 | case PP_StateUILabel_Performance: |
| 407 | return POWER_STATE_TYPE_PERFORMANCE; |
| 408 | default: |
| 409 | return POWER_STATE_TYPE_DEFAULT; |
| 410 | } |
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 void |
| 414 | pp_debugfs_print_current_performance_level(void *handle, |
| 415 | struct seq_file *m) |
| 416 | { |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame^] | 417 | struct pp_hwmgr *hwmgr; |
| 418 | |
| 419 | if (handle == NULL) |
| 420 | return; |
| 421 | |
| 422 | hwmgr = ((struct pp_instance *)handle)->hwmgr; |
| 423 | |
| 424 | if (hwmgr == NULL || hwmgr->hwmgr_func == NULL || |
| 425 | hwmgr->hwmgr_func->print_current_perforce_level == NULL) |
| 426 | return; |
| 427 | |
| 428 | hwmgr->hwmgr_func->print_current_perforce_level(hwmgr, m); |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 429 | } |
Jammy Zhou | 3bace35 | 2015-07-21 21:18:15 +0800 | [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 | const struct amd_powerplay_funcs pp_dpm_funcs = { |
| 433 | .get_temperature = NULL, |
| 434 | .load_firmware = pp_dpm_load_fw, |
| 435 | .wait_for_fw_loading_complete = pp_dpm_fw_loading_complete, |
| 436 | .force_performance_level = pp_dpm_force_performance_level, |
| 437 | .get_performance_level = pp_dpm_get_performance_level, |
| 438 | .get_current_power_state = pp_dpm_get_current_power_state, |
| 439 | .get_sclk = pp_dpm_get_sclk, |
| 440 | .get_mclk = pp_dpm_get_mclk, |
| 441 | .powergate_vce = pp_dpm_powergate_vce, |
| 442 | .powergate_uvd = pp_dpm_powergate_uvd, |
| 443 | .dispatch_tasks = pp_dpm_dispatch_tasks, |
| 444 | .print_current_performance_level = pp_debugfs_print_current_performance_level, |
| 445 | }; |
| 446 | |
Jammy Zhou | ac885b3 | 2015-07-21 17:43:02 +0800 | [diff] [blame] | 447 | static int amd_pp_instance_init(struct amd_pp_init *pp_init, |
| 448 | struct amd_powerplay *amd_pp) |
| 449 | { |
| 450 | int ret; |
| 451 | struct pp_instance *handle; |
| 452 | |
| 453 | handle = kzalloc(sizeof(struct pp_instance), GFP_KERNEL); |
| 454 | if (handle == NULL) |
| 455 | return -ENOMEM; |
| 456 | |
| 457 | ret = smum_init(pp_init, handle); |
| 458 | if (ret) |
Jammy Zhou | 3bace35 | 2015-07-21 21:18:15 +0800 | [diff] [blame] | 459 | goto fail_smum; |
| 460 | |
| 461 | ret = hwmgr_init(pp_init, handle); |
| 462 | if (ret) |
| 463 | goto fail_hwmgr; |
Jammy Zhou | ac885b3 | 2015-07-21 17:43:02 +0800 | [diff] [blame] | 464 | |
Rex Zhu | e92a037 | 2015-09-23 15:14:54 +0800 | [diff] [blame] | 465 | ret = eventmgr_init(handle); |
| 466 | if (ret) |
| 467 | goto fail_eventmgr; |
| 468 | |
Jammy Zhou | ac885b3 | 2015-07-21 17:43:02 +0800 | [diff] [blame] | 469 | amd_pp->pp_handle = handle; |
| 470 | return 0; |
Jammy Zhou | 3bace35 | 2015-07-21 21:18:15 +0800 | [diff] [blame] | 471 | |
Rex Zhu | e92a037 | 2015-09-23 15:14:54 +0800 | [diff] [blame] | 472 | fail_eventmgr: |
| 473 | hwmgr_fini(handle->hwmgr); |
Jammy Zhou | 3bace35 | 2015-07-21 21:18:15 +0800 | [diff] [blame] | 474 | fail_hwmgr: |
| 475 | smum_fini(handle->smu_mgr); |
| 476 | fail_smum: |
| 477 | kfree(handle); |
| 478 | return ret; |
Jammy Zhou | ac885b3 | 2015-07-21 17:43:02 +0800 | [diff] [blame] | 479 | } |
| 480 | |
| 481 | static int amd_pp_instance_fini(void *handle) |
| 482 | { |
| 483 | struct pp_instance *instance = (struct pp_instance *)handle; |
Rex Zhu | e92a037 | 2015-09-23 15:14:54 +0800 | [diff] [blame] | 484 | |
Jammy Zhou | ac885b3 | 2015-07-21 17:43:02 +0800 | [diff] [blame] | 485 | if (instance == NULL) |
| 486 | return -EINVAL; |
| 487 | |
Rex Zhu | e92a037 | 2015-09-23 15:14:54 +0800 | [diff] [blame] | 488 | eventmgr_fini(instance->eventmgr); |
| 489 | |
Jammy Zhou | 3bace35 | 2015-07-21 21:18:15 +0800 | [diff] [blame] | 490 | hwmgr_fini(instance->hwmgr); |
| 491 | |
Jammy Zhou | ac885b3 | 2015-07-21 17:43:02 +0800 | [diff] [blame] | 492 | smum_fini(instance->smu_mgr); |
| 493 | |
| 494 | kfree(handle); |
| 495 | return 0; |
| 496 | } |
| 497 | |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 498 | int amd_powerplay_init(struct amd_pp_init *pp_init, |
| 499 | struct amd_powerplay *amd_pp) |
| 500 | { |
Jammy Zhou | ac885b3 | 2015-07-21 17:43:02 +0800 | [diff] [blame] | 501 | int ret; |
| 502 | |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 503 | if (pp_init == NULL || amd_pp == NULL) |
| 504 | return -EINVAL; |
| 505 | |
Jammy Zhou | ac885b3 | 2015-07-21 17:43:02 +0800 | [diff] [blame] | 506 | ret = amd_pp_instance_init(pp_init, amd_pp); |
| 507 | |
| 508 | if (ret) |
| 509 | return ret; |
| 510 | |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 511 | amd_pp->ip_funcs = &pp_ip_funcs; |
| 512 | amd_pp->pp_funcs = &pp_dpm_funcs; |
| 513 | |
| 514 | return 0; |
| 515 | } |
| 516 | |
| 517 | int amd_powerplay_fini(void *handle) |
| 518 | { |
Jammy Zhou | ac885b3 | 2015-07-21 17:43:02 +0800 | [diff] [blame] | 519 | amd_pp_instance_fini(handle); |
| 520 | |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 521 | return 0; |
| 522 | } |