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 | */ |
Huang Rui | 7bd5542 | 2016-12-26 14:05:30 +0800 | [diff] [blame] | 23 | #include "pp_debug.h" |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 24 | #include <linux/types.h> |
| 25 | #include <linux/kernel.h> |
| 26 | #include <linux/gfp.h> |
Jammy Zhou | ac885b3 | 2015-07-21 17:43:02 +0800 | [diff] [blame] | 27 | #include <linux/slab.h> |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 28 | #include "amd_shared.h" |
| 29 | #include "amd_powerplay.h" |
Jammy Zhou | ac885b3 | 2015-07-21 17:43:02 +0800 | [diff] [blame] | 30 | #include "pp_instance.h" |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 31 | #include "power_state.h" |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 32 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 33 | static inline int pp_check(struct pp_instance *handle) |
| 34 | { |
| 35 | if (handle == NULL || handle->pp_valid != PP_VALID) |
| 36 | return -EINVAL; |
Rex Zhu | a969e16 | 2015-12-29 13:56:03 +0800 | [diff] [blame] | 37 | |
Rex Zhu | b3b0305 | 2017-09-26 13:28:27 -0400 | [diff] [blame^] | 38 | if (handle->hwmgr == NULL || handle->hwmgr->smumgr_funcs == NULL) |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 39 | return -EINVAL; |
| 40 | |
| 41 | if (handle->pm_en == 0) |
| 42 | return PP_DPM_DISABLED; |
| 43 | |
Rex Zhu | b3b0305 | 2017-09-26 13:28:27 -0400 | [diff] [blame^] | 44 | if (handle->hwmgr->hwmgr_func == NULL) |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 45 | return PP_DPM_DISABLED; |
| 46 | |
| 47 | return 0; |
| 48 | } |
Rex Zhu | 7383bcb | 2016-03-30 11:35:50 +0800 | [diff] [blame] | 49 | |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 50 | static int pp_early_init(void *handle) |
| 51 | { |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 52 | int ret; |
| 53 | struct pp_instance *pp_handle = (struct pp_instance *)handle; |
| 54 | |
Rex Zhu | b3b0305 | 2017-09-26 13:28:27 -0400 | [diff] [blame^] | 55 | ret = hwmgr_early_init(pp_handle); |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 56 | if (ret) |
Rex Zhu | b3b0305 | 2017-09-26 13:28:27 -0400 | [diff] [blame^] | 57 | return -EINVAL; |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 58 | |
| 59 | if ((pp_handle->pm_en == 0) |
| 60 | || cgs_is_virtualization_enabled(pp_handle->device)) |
| 61 | return PP_DPM_DISABLED; |
| 62 | |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 63 | return 0; |
| 64 | } |
| 65 | |
| 66 | static int pp_sw_init(void *handle) |
| 67 | { |
Rex Zhu | b3b0305 | 2017-09-26 13:28:27 -0400 | [diff] [blame^] | 68 | struct pp_hwmgr *hwmgr; |
Jammy Zhou | 3bace35 | 2015-07-21 21:18:15 +0800 | [diff] [blame] | 69 | int ret = 0; |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 70 | struct pp_instance *pp_handle = (struct pp_instance *)handle; |
Jammy Zhou | 3bace35 | 2015-07-21 21:18:15 +0800 | [diff] [blame] | 71 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 72 | ret = pp_check(pp_handle); |
Jammy Zhou | 3bace35 | 2015-07-21 21:18:15 +0800 | [diff] [blame] | 73 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 74 | if (ret == 0 || ret == PP_DPM_DISABLED) { |
Rex Zhu | b3b0305 | 2017-09-26 13:28:27 -0400 | [diff] [blame^] | 75 | hwmgr = pp_handle->hwmgr; |
Jammy Zhou | 3bace35 | 2015-07-21 21:18:15 +0800 | [diff] [blame] | 76 | |
Rex Zhu | b3b0305 | 2017-09-26 13:28:27 -0400 | [diff] [blame^] | 77 | if (hwmgr->smumgr_funcs->smu_init == NULL) |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 78 | return -EINVAL; |
Rex Zhu | 7383bcb | 2016-03-30 11:35:50 +0800 | [diff] [blame] | 79 | |
Rex Zhu | b3b0305 | 2017-09-26 13:28:27 -0400 | [diff] [blame^] | 80 | ret = hwmgr->smumgr_funcs->smu_init(hwmgr); |
Jammy Zhou | 3bace35 | 2015-07-21 21:18:15 +0800 | [diff] [blame] | 81 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 82 | pr_info("amdgpu: powerplay sw initialized\n"); |
Huang Rui | 167112b | 2016-12-14 16:26:54 +0800 | [diff] [blame] | 83 | } |
Jammy Zhou | 3bace35 | 2015-07-21 21:18:15 +0800 | [diff] [blame] | 84 | return ret; |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | static int pp_sw_fini(void *handle) |
| 88 | { |
Rex Zhu | b3b0305 | 2017-09-26 13:28:27 -0400 | [diff] [blame^] | 89 | struct pp_hwmgr *hwmgr; |
Jammy Zhou | 3bace35 | 2015-07-21 21:18:15 +0800 | [diff] [blame] | 90 | int ret = 0; |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 91 | struct pp_instance *pp_handle = (struct pp_instance *)handle; |
Jammy Zhou | 3bace35 | 2015-07-21 21:18:15 +0800 | [diff] [blame] | 92 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 93 | ret = pp_check(pp_handle); |
| 94 | if (ret == 0 || ret == PP_DPM_DISABLED) { |
Rex Zhu | b3b0305 | 2017-09-26 13:28:27 -0400 | [diff] [blame^] | 95 | hwmgr = pp_handle->hwmgr; |
Jammy Zhou | 3bace35 | 2015-07-21 21:18:15 +0800 | [diff] [blame] | 96 | |
Rex Zhu | b3b0305 | 2017-09-26 13:28:27 -0400 | [diff] [blame^] | 97 | if (hwmgr->smumgr_funcs->smu_fini == NULL) |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 98 | return -EINVAL; |
Jammy Zhou | 3bace35 | 2015-07-21 21:18:15 +0800 | [diff] [blame] | 99 | |
Rex Zhu | b3b0305 | 2017-09-26 13:28:27 -0400 | [diff] [blame^] | 100 | ret = hwmgr->smumgr_funcs->smu_fini(pp_handle->hwmgr); |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 101 | } |
Jammy Zhou | 3bace35 | 2015-07-21 21:18:15 +0800 | [diff] [blame] | 102 | return ret; |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | static int pp_hw_init(void *handle) |
| 106 | { |
Jammy Zhou | ac885b3 | 2015-07-21 17:43:02 +0800 | [diff] [blame] | 107 | int ret = 0; |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 108 | struct pp_instance *pp_handle = (struct pp_instance *)handle; |
Rex Zhu | b3b0305 | 2017-09-26 13:28:27 -0400 | [diff] [blame^] | 109 | struct pp_hwmgr *hwmgr; |
Jammy Zhou | ac885b3 | 2015-07-21 17:43:02 +0800 | [diff] [blame] | 110 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 111 | ret = pp_check(pp_handle); |
Jammy Zhou | ac885b3 | 2015-07-21 17:43:02 +0800 | [diff] [blame] | 112 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 113 | if (ret == 0 || ret == PP_DPM_DISABLED) { |
Rex Zhu | b3b0305 | 2017-09-26 13:28:27 -0400 | [diff] [blame^] | 114 | hwmgr = pp_handle->hwmgr; |
Jammy Zhou | ac885b3 | 2015-07-21 17:43:02 +0800 | [diff] [blame] | 115 | |
Rex Zhu | b3b0305 | 2017-09-26 13:28:27 -0400 | [diff] [blame^] | 116 | if (hwmgr->smumgr_funcs->start_smu == NULL) |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 117 | return -EINVAL; |
Jammy Zhou | ac885b3 | 2015-07-21 17:43:02 +0800 | [diff] [blame] | 118 | |
Rex Zhu | b3b0305 | 2017-09-26 13:28:27 -0400 | [diff] [blame^] | 119 | if(hwmgr->smumgr_funcs->start_smu(pp_handle->hwmgr)) { |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 120 | pr_err("smc start failed\n"); |
Rex Zhu | b3b0305 | 2017-09-26 13:28:27 -0400 | [diff] [blame^] | 121 | hwmgr->smumgr_funcs->smu_fini(pp_handle->hwmgr); |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 122 | return -EINVAL;; |
| 123 | } |
| 124 | if (ret == PP_DPM_DISABLED) |
| 125 | return PP_DPM_DISABLED; |
Jammy Zhou | ac885b3 | 2015-07-21 17:43:02 +0800 | [diff] [blame] | 126 | } |
| 127 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 128 | ret = hwmgr_hw_init(pp_handle); |
| 129 | if (ret) |
| 130 | goto err; |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 131 | return 0; |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 132 | err: |
| 133 | pp_handle->pm_en = 0; |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 134 | return PP_DPM_DISABLED; |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | static int pp_hw_fini(void *handle) |
| 138 | { |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 139 | struct pp_instance *pp_handle = (struct pp_instance *)handle; |
| 140 | int ret = 0; |
Jammy Zhou | ac885b3 | 2015-07-21 17:43:02 +0800 | [diff] [blame] | 141 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 142 | ret = pp_check(pp_handle); |
Rex Zhu | df1e639 | 2017-09-01 13:46:20 +0800 | [diff] [blame] | 143 | if (ret == 0) |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 144 | hwmgr_hw_fini(pp_handle); |
Rex Zhu | df1e639 | 2017-09-01 13:46:20 +0800 | [diff] [blame] | 145 | |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 146 | return 0; |
| 147 | } |
| 148 | |
| 149 | static bool pp_is_idle(void *handle) |
| 150 | { |
Edward O'Callaghan | ed5121a | 2016-07-12 10:17:52 +1000 | [diff] [blame] | 151 | return false; |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | static int pp_wait_for_idle(void *handle) |
| 155 | { |
| 156 | return 0; |
| 157 | } |
| 158 | |
| 159 | static int pp_sw_reset(void *handle) |
| 160 | { |
| 161 | return 0; |
| 162 | } |
| 163 | |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 164 | |
Rex Zhu | 465f96e | 2016-09-18 16:52:03 +0800 | [diff] [blame] | 165 | int amd_set_clockgating_by_smu(void *handle, uint32_t msg_id) |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 166 | { |
Eric Huang | 03e3905 | 2016-02-09 16:26:00 -0500 | [diff] [blame] | 167 | struct pp_hwmgr *hwmgr; |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 168 | struct pp_instance *pp_handle = (struct pp_instance *)handle; |
| 169 | int ret = 0; |
Eric Huang | 03e3905 | 2016-02-09 16:26:00 -0500 | [diff] [blame] | 170 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 171 | ret = pp_check(pp_handle); |
Eric Huang | 03e3905 | 2016-02-09 16:26:00 -0500 | [diff] [blame] | 172 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 173 | if (ret != 0) |
| 174 | return ret; |
Eric Huang | 03e3905 | 2016-02-09 16:26:00 -0500 | [diff] [blame] | 175 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 176 | hwmgr = pp_handle->hwmgr; |
Eric Huang | 03e3905 | 2016-02-09 16:26:00 -0500 | [diff] [blame] | 177 | |
Rex Zhu | 7383bcb | 2016-03-30 11:35:50 +0800 | [diff] [blame] | 178 | if (hwmgr->hwmgr_func->update_clock_gatings == NULL) { |
Huang Rui | 0fb829d | 2016-12-26 14:24:05 +0800 | [diff] [blame] | 179 | pr_info("%s was not implemented.\n", __func__); |
Flora Cui | 538333f | 2016-02-15 15:45:59 +0800 | [diff] [blame] | 180 | return 0; |
Rex Zhu | 7383bcb | 2016-03-30 11:35:50 +0800 | [diff] [blame] | 181 | } |
Flora Cui | 538333f | 2016-02-15 15:45:59 +0800 | [diff] [blame] | 182 | |
Rex Zhu | 465f96e | 2016-09-18 16:52:03 +0800 | [diff] [blame] | 183 | return hwmgr->hwmgr_func->update_clock_gatings(hwmgr, &msg_id); |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 184 | } |
| 185 | |
| 186 | static int pp_set_powergating_state(void *handle, |
| 187 | enum amd_powergating_state state) |
| 188 | { |
Eric Huang | 65f85e7 | 2016-02-11 15:54:45 -0500 | [diff] [blame] | 189 | struct pp_hwmgr *hwmgr; |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 190 | struct pp_instance *pp_handle = (struct pp_instance *)handle; |
| 191 | int ret = 0; |
Eric Huang | 65f85e7 | 2016-02-11 15:54:45 -0500 | [diff] [blame] | 192 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 193 | ret = pp_check(pp_handle); |
Eric Huang | 65f85e7 | 2016-02-11 15:54:45 -0500 | [diff] [blame] | 194 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 195 | if (ret != 0) |
| 196 | return ret; |
Eric Huang | 65f85e7 | 2016-02-11 15:54:45 -0500 | [diff] [blame] | 197 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 198 | hwmgr = pp_handle->hwmgr; |
Rex Zhu | 7383bcb | 2016-03-30 11:35:50 +0800 | [diff] [blame] | 199 | |
| 200 | if (hwmgr->hwmgr_func->enable_per_cu_power_gating == NULL) { |
Huang Rui | 0fb829d | 2016-12-26 14:24:05 +0800 | [diff] [blame] | 201 | pr_info("%s was not implemented.\n", __func__); |
Rex Zhu | 7383bcb | 2016-03-30 11:35:50 +0800 | [diff] [blame] | 202 | return 0; |
| 203 | } |
Eric Huang | 65f85e7 | 2016-02-11 15:54:45 -0500 | [diff] [blame] | 204 | |
| 205 | /* Enable/disable GFX per cu powergating through SMU */ |
| 206 | return hwmgr->hwmgr_func->enable_per_cu_power_gating(hwmgr, |
Andrew F. Davis | 93a4aec | 2017-03-15 11:20:24 -0500 | [diff] [blame] | 207 | state == AMD_PG_STATE_GATE); |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | static int pp_suspend(void *handle) |
| 211 | { |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 212 | struct pp_instance *pp_handle = (struct pp_instance *)handle; |
| 213 | int ret = 0; |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 214 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 215 | ret = pp_check(pp_handle); |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 216 | |
Huang Rui | 4573f0f | 2017-04-10 14:40:51 +0800 | [diff] [blame] | 217 | if (ret == PP_DPM_DISABLED) |
| 218 | return 0; |
| 219 | else if (ret != 0) |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 220 | return ret; |
| 221 | |
Rex Zhu | df1e639 | 2017-09-01 13:46:20 +0800 | [diff] [blame] | 222 | return hwmgr_hw_suspend(pp_handle); |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 223 | } |
| 224 | |
| 225 | static int pp_resume(void *handle) |
| 226 | { |
Rex Zhu | b3b0305 | 2017-09-26 13:28:27 -0400 | [diff] [blame^] | 227 | struct pp_hwmgr *hwmgr; |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 228 | int ret, ret1; |
| 229 | struct pp_instance *pp_handle = (struct pp_instance *)handle; |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 230 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 231 | ret1 = pp_check(pp_handle); |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 232 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 233 | if (ret1 != 0 && ret1 != PP_DPM_DISABLED) |
| 234 | return ret1; |
| 235 | |
Rex Zhu | b3b0305 | 2017-09-26 13:28:27 -0400 | [diff] [blame^] | 236 | hwmgr = pp_handle->hwmgr; |
Rex Zhu | e0b71a7 | 2015-12-29 10:25:19 +0800 | [diff] [blame] | 237 | |
Rex Zhu | b3b0305 | 2017-09-26 13:28:27 -0400 | [diff] [blame^] | 238 | if (hwmgr->smumgr_funcs->start_smu == NULL) |
Rex Zhu | e0b71a7 | 2015-12-29 10:25:19 +0800 | [diff] [blame] | 239 | return -EINVAL; |
| 240 | |
Rex Zhu | b3b0305 | 2017-09-26 13:28:27 -0400 | [diff] [blame^] | 241 | ret = hwmgr->smumgr_funcs->start_smu(pp_handle->hwmgr); |
Rex Zhu | e0b71a7 | 2015-12-29 10:25:19 +0800 | [diff] [blame] | 242 | if (ret) { |
Huang Rui | 0fb829d | 2016-12-26 14:24:05 +0800 | [diff] [blame] | 243 | pr_err("smc start failed\n"); |
Rex Zhu | b3b0305 | 2017-09-26 13:28:27 -0400 | [diff] [blame^] | 244 | hwmgr->smumgr_funcs->smu_fini(pp_handle->hwmgr); |
Rex Zhu | e0b71a7 | 2015-12-29 10:25:19 +0800 | [diff] [blame] | 245 | return ret; |
| 246 | } |
| 247 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 248 | if (ret1 == PP_DPM_DISABLED) |
Monk Liu | 8fdf269 | 2017-01-25 15:55:30 +0800 | [diff] [blame] | 249 | return 0; |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 250 | |
Rex Zhu | df1e639 | 2017-09-01 13:46:20 +0800 | [diff] [blame] | 251 | return hwmgr_hw_resume(pp_handle); |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 252 | } |
| 253 | |
| 254 | const struct amd_ip_funcs pp_ip_funcs = { |
Tom St Denis | 88a907d | 2016-05-04 14:28:35 -0400 | [diff] [blame] | 255 | .name = "powerplay", |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 256 | .early_init = pp_early_init, |
| 257 | .late_init = NULL, |
| 258 | .sw_init = pp_sw_init, |
| 259 | .sw_fini = pp_sw_fini, |
| 260 | .hw_init = pp_hw_init, |
| 261 | .hw_fini = pp_hw_fini, |
| 262 | .suspend = pp_suspend, |
| 263 | .resume = pp_resume, |
| 264 | .is_idle = pp_is_idle, |
| 265 | .wait_for_idle = pp_wait_for_idle, |
| 266 | .soft_reset = pp_sw_reset, |
Rex Zhu | 465f96e | 2016-09-18 16:52:03 +0800 | [diff] [blame] | 267 | .set_clockgating_state = NULL, |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 268 | .set_powergating_state = pp_set_powergating_state, |
| 269 | }; |
| 270 | |
| 271 | static int pp_dpm_load_fw(void *handle) |
| 272 | { |
| 273 | return 0; |
| 274 | } |
| 275 | |
| 276 | static int pp_dpm_fw_loading_complete(void *handle) |
| 277 | { |
| 278 | return 0; |
| 279 | } |
| 280 | |
Rex Zhu | 9947f70 | 2017-08-29 16:08:56 +0800 | [diff] [blame] | 281 | static void pp_dpm_en_umd_pstate(struct pp_hwmgr *hwmgr, |
| 282 | enum amd_dpm_forced_level *level) |
| 283 | { |
| 284 | uint32_t profile_mode_mask = AMD_DPM_FORCED_LEVEL_PROFILE_STANDARD | |
| 285 | AMD_DPM_FORCED_LEVEL_PROFILE_MIN_SCLK | |
| 286 | AMD_DPM_FORCED_LEVEL_PROFILE_MIN_MCLK | |
| 287 | AMD_DPM_FORCED_LEVEL_PROFILE_PEAK; |
| 288 | |
| 289 | if (!(hwmgr->dpm_level & profile_mode_mask)) { |
| 290 | /* enter umd pstate, save current level, disable gfx cg*/ |
| 291 | if (*level & profile_mode_mask) { |
| 292 | hwmgr->saved_dpm_level = hwmgr->dpm_level; |
| 293 | hwmgr->en_umd_pstate = true; |
| 294 | cgs_set_clockgating_state(hwmgr->device, |
| 295 | AMD_IP_BLOCK_TYPE_GFX, |
| 296 | AMD_CG_STATE_UNGATE); |
| 297 | cgs_set_powergating_state(hwmgr->device, |
| 298 | AMD_IP_BLOCK_TYPE_GFX, |
| 299 | AMD_PG_STATE_UNGATE); |
| 300 | } |
| 301 | } else { |
| 302 | /* exit umd pstate, restore level, enable gfx cg*/ |
| 303 | if (!(*level & profile_mode_mask)) { |
| 304 | if (*level == AMD_DPM_FORCED_LEVEL_PROFILE_EXIT) |
| 305 | *level = hwmgr->saved_dpm_level; |
| 306 | hwmgr->en_umd_pstate = false; |
| 307 | cgs_set_clockgating_state(hwmgr->device, |
| 308 | AMD_IP_BLOCK_TYPE_GFX, |
| 309 | AMD_CG_STATE_GATE); |
| 310 | cgs_set_powergating_state(hwmgr->device, |
| 311 | AMD_IP_BLOCK_TYPE_GFX, |
| 312 | AMD_PG_STATE_GATE); |
| 313 | } |
| 314 | } |
| 315 | } |
| 316 | |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 317 | static int pp_dpm_force_performance_level(void *handle, |
| 318 | enum amd_dpm_forced_level level) |
| 319 | { |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 320 | struct pp_hwmgr *hwmgr; |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 321 | struct pp_instance *pp_handle = (struct pp_instance *)handle; |
| 322 | int ret = 0; |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 323 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 324 | ret = pp_check(pp_handle); |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 325 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 326 | if (ret != 0) |
| 327 | return ret; |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 328 | |
| 329 | hwmgr = pp_handle->hwmgr; |
| 330 | |
Rex Zhu | 9947f70 | 2017-08-29 16:08:56 +0800 | [diff] [blame] | 331 | if (level == hwmgr->dpm_level) |
| 332 | return 0; |
| 333 | |
Rex Zhu | 7383bcb | 2016-03-30 11:35:50 +0800 | [diff] [blame] | 334 | if (hwmgr->hwmgr_func->force_dpm_level == NULL) { |
Huang Rui | 0fb829d | 2016-12-26 14:24:05 +0800 | [diff] [blame] | 335 | pr_info("%s was not implemented.\n", __func__); |
Rex Zhu | 7383bcb | 2016-03-30 11:35:50 +0800 | [diff] [blame] | 336 | return 0; |
| 337 | } |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 338 | |
Rex Zhu | 2a50710 | 2017-02-20 17:07:36 +0800 | [diff] [blame] | 339 | mutex_lock(&pp_handle->pp_lock); |
Rex Zhu | 9947f70 | 2017-08-29 16:08:56 +0800 | [diff] [blame] | 340 | pp_dpm_en_umd_pstate(hwmgr, &level); |
| 341 | hwmgr->request_dpm_level = level; |
Rex Zhu | df1e639 | 2017-09-01 13:46:20 +0800 | [diff] [blame] | 342 | hwmgr_handle_task(pp_handle, AMD_PP_TASK_READJUST_POWER_STATE, NULL, NULL); |
Rex Zhu | 9947f70 | 2017-08-29 16:08:56 +0800 | [diff] [blame] | 343 | ret = hwmgr->hwmgr_func->force_dpm_level(hwmgr, level); |
| 344 | if (!ret) |
| 345 | hwmgr->dpm_level = hwmgr->request_dpm_level; |
| 346 | |
Rex Zhu | 2a50710 | 2017-02-20 17:07:36 +0800 | [diff] [blame] | 347 | mutex_unlock(&pp_handle->pp_lock); |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 348 | return 0; |
| 349 | } |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 350 | |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 351 | static enum amd_dpm_forced_level pp_dpm_get_performance_level( |
| 352 | void *handle) |
| 353 | { |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 354 | struct pp_hwmgr *hwmgr; |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 355 | struct pp_instance *pp_handle = (struct pp_instance *)handle; |
| 356 | int ret = 0; |
Rex Zhu | 2a50710 | 2017-02-20 17:07:36 +0800 | [diff] [blame] | 357 | enum amd_dpm_forced_level level; |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 358 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 359 | ret = pp_check(pp_handle); |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 360 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 361 | if (ret != 0) |
| 362 | return ret; |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 363 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 364 | hwmgr = pp_handle->hwmgr; |
Rex Zhu | 2a50710 | 2017-02-20 17:07:36 +0800 | [diff] [blame] | 365 | mutex_lock(&pp_handle->pp_lock); |
| 366 | level = hwmgr->dpm_level; |
| 367 | mutex_unlock(&pp_handle->pp_lock); |
| 368 | return level; |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 369 | } |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 370 | |
Rex Zhu | f93f0c3 | 2017-09-06 16:08:03 +0800 | [diff] [blame] | 371 | static uint32_t pp_dpm_get_sclk(void *handle, bool low) |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 372 | { |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 373 | struct pp_hwmgr *hwmgr; |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 374 | struct pp_instance *pp_handle = (struct pp_instance *)handle; |
| 375 | int ret = 0; |
Rex Zhu | f93f0c3 | 2017-09-06 16:08:03 +0800 | [diff] [blame] | 376 | uint32_t clk = 0; |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 377 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 378 | ret = pp_check(pp_handle); |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 379 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 380 | if (ret != 0) |
| 381 | return ret; |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 382 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 383 | hwmgr = pp_handle->hwmgr; |
Rex Zhu | 7383bcb | 2016-03-30 11:35:50 +0800 | [diff] [blame] | 384 | |
| 385 | if (hwmgr->hwmgr_func->get_sclk == NULL) { |
Huang Rui | 0fb829d | 2016-12-26 14:24:05 +0800 | [diff] [blame] | 386 | pr_info("%s was not implemented.\n", __func__); |
Rex Zhu | 7383bcb | 2016-03-30 11:35:50 +0800 | [diff] [blame] | 387 | return 0; |
| 388 | } |
Rex Zhu | 2a50710 | 2017-02-20 17:07:36 +0800 | [diff] [blame] | 389 | mutex_lock(&pp_handle->pp_lock); |
Rex Zhu | f93f0c3 | 2017-09-06 16:08:03 +0800 | [diff] [blame] | 390 | clk = hwmgr->hwmgr_func->get_sclk(hwmgr, low); |
Rex Zhu | 2a50710 | 2017-02-20 17:07:36 +0800 | [diff] [blame] | 391 | mutex_unlock(&pp_handle->pp_lock); |
Rex Zhu | f93f0c3 | 2017-09-06 16:08:03 +0800 | [diff] [blame] | 392 | return clk; |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 393 | } |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 394 | |
Rex Zhu | f93f0c3 | 2017-09-06 16:08:03 +0800 | [diff] [blame] | 395 | static uint32_t pp_dpm_get_mclk(void *handle, bool low) |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 396 | { |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 397 | struct pp_hwmgr *hwmgr; |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 398 | struct pp_instance *pp_handle = (struct pp_instance *)handle; |
| 399 | int ret = 0; |
Rex Zhu | f93f0c3 | 2017-09-06 16:08:03 +0800 | [diff] [blame] | 400 | uint32_t clk = 0; |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 401 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 402 | ret = pp_check(pp_handle); |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 403 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 404 | if (ret != 0) |
| 405 | return ret; |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 406 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 407 | hwmgr = pp_handle->hwmgr; |
Rex Zhu | 7383bcb | 2016-03-30 11:35:50 +0800 | [diff] [blame] | 408 | |
| 409 | if (hwmgr->hwmgr_func->get_mclk == NULL) { |
Huang Rui | 0fb829d | 2016-12-26 14:24:05 +0800 | [diff] [blame] | 410 | pr_info("%s was not implemented.\n", __func__); |
Rex Zhu | 7383bcb | 2016-03-30 11:35:50 +0800 | [diff] [blame] | 411 | return 0; |
| 412 | } |
Rex Zhu | 2a50710 | 2017-02-20 17:07:36 +0800 | [diff] [blame] | 413 | mutex_lock(&pp_handle->pp_lock); |
Rex Zhu | f93f0c3 | 2017-09-06 16:08:03 +0800 | [diff] [blame] | 414 | clk = hwmgr->hwmgr_func->get_mclk(hwmgr, low); |
Rex Zhu | 2a50710 | 2017-02-20 17:07:36 +0800 | [diff] [blame] | 415 | mutex_unlock(&pp_handle->pp_lock); |
Rex Zhu | f93f0c3 | 2017-09-06 16:08:03 +0800 | [diff] [blame] | 416 | return clk; |
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 | |
Rex Zhu | f93f0c3 | 2017-09-06 16:08:03 +0800 | [diff] [blame] | 419 | static void pp_dpm_powergate_vce(void *handle, bool gate) |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 420 | { |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 421 | struct pp_hwmgr *hwmgr; |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 422 | struct pp_instance *pp_handle = (struct pp_instance *)handle; |
| 423 | int ret = 0; |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 424 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 425 | ret = pp_check(pp_handle); |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 426 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 427 | if (ret != 0) |
Rex Zhu | f93f0c3 | 2017-09-06 16:08:03 +0800 | [diff] [blame] | 428 | return; |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 429 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 430 | hwmgr = pp_handle->hwmgr; |
Rex Zhu | 7383bcb | 2016-03-30 11:35:50 +0800 | [diff] [blame] | 431 | |
| 432 | if (hwmgr->hwmgr_func->powergate_vce == NULL) { |
Huang Rui | 0fb829d | 2016-12-26 14:24:05 +0800 | [diff] [blame] | 433 | pr_info("%s was not implemented.\n", __func__); |
Rex Zhu | f93f0c3 | 2017-09-06 16:08:03 +0800 | [diff] [blame] | 434 | return; |
Rex Zhu | 7383bcb | 2016-03-30 11:35:50 +0800 | [diff] [blame] | 435 | } |
Rex Zhu | 2a50710 | 2017-02-20 17:07:36 +0800 | [diff] [blame] | 436 | mutex_lock(&pp_handle->pp_lock); |
Rex Zhu | f93f0c3 | 2017-09-06 16:08:03 +0800 | [diff] [blame] | 437 | hwmgr->hwmgr_func->powergate_vce(hwmgr, gate); |
Rex Zhu | 2a50710 | 2017-02-20 17:07:36 +0800 | [diff] [blame] | 438 | mutex_unlock(&pp_handle->pp_lock); |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 439 | } |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 440 | |
Rex Zhu | f93f0c3 | 2017-09-06 16:08:03 +0800 | [diff] [blame] | 441 | static void pp_dpm_powergate_uvd(void *handle, bool gate) |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 442 | { |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 443 | struct pp_hwmgr *hwmgr; |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 444 | struct pp_instance *pp_handle = (struct pp_instance *)handle; |
| 445 | int ret = 0; |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 446 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 447 | ret = pp_check(pp_handle); |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 448 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 449 | if (ret != 0) |
Rex Zhu | f93f0c3 | 2017-09-06 16:08:03 +0800 | [diff] [blame] | 450 | return; |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 451 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 452 | hwmgr = pp_handle->hwmgr; |
Rex Zhu | 7383bcb | 2016-03-30 11:35:50 +0800 | [diff] [blame] | 453 | |
| 454 | if (hwmgr->hwmgr_func->powergate_uvd == NULL) { |
Huang Rui | 0fb829d | 2016-12-26 14:24:05 +0800 | [diff] [blame] | 455 | pr_info("%s was not implemented.\n", __func__); |
Rex Zhu | f93f0c3 | 2017-09-06 16:08:03 +0800 | [diff] [blame] | 456 | return; |
Rex Zhu | 7383bcb | 2016-03-30 11:35:50 +0800 | [diff] [blame] | 457 | } |
Rex Zhu | 2a50710 | 2017-02-20 17:07:36 +0800 | [diff] [blame] | 458 | mutex_lock(&pp_handle->pp_lock); |
Rex Zhu | f93f0c3 | 2017-09-06 16:08:03 +0800 | [diff] [blame] | 459 | hwmgr->hwmgr_func->powergate_uvd(hwmgr, gate); |
Rex Zhu | 2a50710 | 2017-02-20 17:07:36 +0800 | [diff] [blame] | 460 | mutex_unlock(&pp_handle->pp_lock); |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 461 | } |
| 462 | |
Rex Zhu | df1e639 | 2017-09-01 13:46:20 +0800 | [diff] [blame] | 463 | static int pp_dpm_dispatch_tasks(void *handle, enum amd_pp_task task_id, |
Baoyou Xie | f8a4c11 | 2016-09-30 17:58:42 +0800 | [diff] [blame] | 464 | void *input, void *output) |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 465 | { |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 466 | int ret = 0; |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 467 | struct pp_instance *pp_handle = (struct pp_instance *)handle; |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 468 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 469 | ret = pp_check(pp_handle); |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 470 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 471 | if (ret != 0) |
| 472 | return ret; |
Rex Zhu | df1e639 | 2017-09-01 13:46:20 +0800 | [diff] [blame] | 473 | |
Rex Zhu | 2a50710 | 2017-02-20 17:07:36 +0800 | [diff] [blame] | 474 | mutex_lock(&pp_handle->pp_lock); |
Rex Zhu | df1e639 | 2017-09-01 13:46:20 +0800 | [diff] [blame] | 475 | ret = hwmgr_handle_task(pp_handle, task_id, input, output); |
Rex Zhu | 2a50710 | 2017-02-20 17:07:36 +0800 | [diff] [blame] | 476 | mutex_unlock(&pp_handle->pp_lock); |
Rex Zhu | df1e639 | 2017-09-01 13:46:20 +0800 | [diff] [blame] | 477 | |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 478 | return ret; |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 479 | } |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 480 | |
Baoyou Xie | f8a4c11 | 2016-09-30 17:58:42 +0800 | [diff] [blame] | 481 | static enum amd_pm_state_type pp_dpm_get_current_power_state(void *handle) |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 482 | { |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 483 | struct pp_hwmgr *hwmgr; |
| 484 | struct pp_power_state *state; |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 485 | struct pp_instance *pp_handle = (struct pp_instance *)handle; |
| 486 | int ret = 0; |
Rex Zhu | 2a50710 | 2017-02-20 17:07:36 +0800 | [diff] [blame] | 487 | enum amd_pm_state_type pm_type; |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 488 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 489 | ret = pp_check(pp_handle); |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 490 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 491 | if (ret != 0) |
| 492 | return ret; |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 493 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 494 | hwmgr = pp_handle->hwmgr; |
| 495 | |
| 496 | if (hwmgr->current_ps == NULL) |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 497 | return -EINVAL; |
| 498 | |
Rex Zhu | 2a50710 | 2017-02-20 17:07:36 +0800 | [diff] [blame] | 499 | mutex_lock(&pp_handle->pp_lock); |
| 500 | |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 501 | state = hwmgr->current_ps; |
| 502 | |
| 503 | switch (state->classification.ui_label) { |
| 504 | case PP_StateUILabel_Battery: |
Rex Zhu | 2a50710 | 2017-02-20 17:07:36 +0800 | [diff] [blame] | 505 | pm_type = POWER_STATE_TYPE_BATTERY; |
Dan Carpenter | 0f987cd | 2017-04-03 21:41:47 +0300 | [diff] [blame] | 506 | break; |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 507 | case PP_StateUILabel_Balanced: |
Rex Zhu | 2a50710 | 2017-02-20 17:07:36 +0800 | [diff] [blame] | 508 | pm_type = POWER_STATE_TYPE_BALANCED; |
Dan Carpenter | 0f987cd | 2017-04-03 21:41:47 +0300 | [diff] [blame] | 509 | break; |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 510 | case PP_StateUILabel_Performance: |
Rex Zhu | 2a50710 | 2017-02-20 17:07:36 +0800 | [diff] [blame] | 511 | pm_type = POWER_STATE_TYPE_PERFORMANCE; |
Dan Carpenter | 0f987cd | 2017-04-03 21:41:47 +0300 | [diff] [blame] | 512 | break; |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 513 | default: |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 514 | if (state->classification.flags & PP_StateClassificationFlag_Boot) |
Rex Zhu | 2a50710 | 2017-02-20 17:07:36 +0800 | [diff] [blame] | 515 | pm_type = POWER_STATE_TYPE_INTERNAL_BOOT; |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 516 | else |
Rex Zhu | 2a50710 | 2017-02-20 17:07:36 +0800 | [diff] [blame] | 517 | pm_type = POWER_STATE_TYPE_DEFAULT; |
Dan Carpenter | 0f987cd | 2017-04-03 21:41:47 +0300 | [diff] [blame] | 518 | break; |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 519 | } |
Rex Zhu | 2a50710 | 2017-02-20 17:07:36 +0800 | [diff] [blame] | 520 | mutex_unlock(&pp_handle->pp_lock); |
| 521 | |
| 522 | return pm_type; |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 523 | } |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 524 | |
Rex Zhu | f93f0c3 | 2017-09-06 16:08:03 +0800 | [diff] [blame] | 525 | static void pp_dpm_set_fan_control_mode(void *handle, uint32_t mode) |
Rex Zhu | cac9a19 | 2015-10-16 11:48:21 +0800 | [diff] [blame] | 526 | { |
| 527 | struct pp_hwmgr *hwmgr; |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 528 | struct pp_instance *pp_handle = (struct pp_instance *)handle; |
| 529 | int ret = 0; |
Rex Zhu | cac9a19 | 2015-10-16 11:48:21 +0800 | [diff] [blame] | 530 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 531 | ret = pp_check(pp_handle); |
Rex Zhu | cac9a19 | 2015-10-16 11:48:21 +0800 | [diff] [blame] | 532 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 533 | if (ret != 0) |
Rex Zhu | f93f0c3 | 2017-09-06 16:08:03 +0800 | [diff] [blame] | 534 | return; |
Rex Zhu | cac9a19 | 2015-10-16 11:48:21 +0800 | [diff] [blame] | 535 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 536 | hwmgr = pp_handle->hwmgr; |
Rex Zhu | 7383bcb | 2016-03-30 11:35:50 +0800 | [diff] [blame] | 537 | |
| 538 | if (hwmgr->hwmgr_func->set_fan_control_mode == NULL) { |
Huang Rui | 0fb829d | 2016-12-26 14:24:05 +0800 | [diff] [blame] | 539 | pr_info("%s was not implemented.\n", __func__); |
Rex Zhu | f93f0c3 | 2017-09-06 16:08:03 +0800 | [diff] [blame] | 540 | return; |
Rex Zhu | 7383bcb | 2016-03-30 11:35:50 +0800 | [diff] [blame] | 541 | } |
Rex Zhu | 2a50710 | 2017-02-20 17:07:36 +0800 | [diff] [blame] | 542 | mutex_lock(&pp_handle->pp_lock); |
Rex Zhu | f93f0c3 | 2017-09-06 16:08:03 +0800 | [diff] [blame] | 543 | hwmgr->hwmgr_func->set_fan_control_mode(hwmgr, mode); |
Rex Zhu | 2a50710 | 2017-02-20 17:07:36 +0800 | [diff] [blame] | 544 | mutex_unlock(&pp_handle->pp_lock); |
Rex Zhu | cac9a19 | 2015-10-16 11:48:21 +0800 | [diff] [blame] | 545 | } |
| 546 | |
Rex Zhu | f93f0c3 | 2017-09-06 16:08:03 +0800 | [diff] [blame] | 547 | static uint32_t pp_dpm_get_fan_control_mode(void *handle) |
Rex Zhu | cac9a19 | 2015-10-16 11:48:21 +0800 | [diff] [blame] | 548 | { |
| 549 | struct pp_hwmgr *hwmgr; |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 550 | struct pp_instance *pp_handle = (struct pp_instance *)handle; |
| 551 | int ret = 0; |
Rex Zhu | f93f0c3 | 2017-09-06 16:08:03 +0800 | [diff] [blame] | 552 | uint32_t mode = 0; |
Rex Zhu | cac9a19 | 2015-10-16 11:48:21 +0800 | [diff] [blame] | 553 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 554 | ret = pp_check(pp_handle); |
Rex Zhu | cac9a19 | 2015-10-16 11:48:21 +0800 | [diff] [blame] | 555 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 556 | if (ret != 0) |
| 557 | return ret; |
Rex Zhu | cac9a19 | 2015-10-16 11:48:21 +0800 | [diff] [blame] | 558 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 559 | hwmgr = pp_handle->hwmgr; |
Rex Zhu | 7383bcb | 2016-03-30 11:35:50 +0800 | [diff] [blame] | 560 | |
| 561 | if (hwmgr->hwmgr_func->get_fan_control_mode == NULL) { |
Huang Rui | 0fb829d | 2016-12-26 14:24:05 +0800 | [diff] [blame] | 562 | pr_info("%s was not implemented.\n", __func__); |
Rex Zhu | 7383bcb | 2016-03-30 11:35:50 +0800 | [diff] [blame] | 563 | return 0; |
| 564 | } |
Rex Zhu | 2a50710 | 2017-02-20 17:07:36 +0800 | [diff] [blame] | 565 | mutex_lock(&pp_handle->pp_lock); |
Rex Zhu | f93f0c3 | 2017-09-06 16:08:03 +0800 | [diff] [blame] | 566 | mode = hwmgr->hwmgr_func->get_fan_control_mode(hwmgr); |
Rex Zhu | 2a50710 | 2017-02-20 17:07:36 +0800 | [diff] [blame] | 567 | mutex_unlock(&pp_handle->pp_lock); |
Rex Zhu | f93f0c3 | 2017-09-06 16:08:03 +0800 | [diff] [blame] | 568 | return mode; |
Rex Zhu | cac9a19 | 2015-10-16 11:48:21 +0800 | [diff] [blame] | 569 | } |
| 570 | |
| 571 | static int pp_dpm_set_fan_speed_percent(void *handle, uint32_t percent) |
| 572 | { |
| 573 | struct pp_hwmgr *hwmgr; |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 574 | struct pp_instance *pp_handle = (struct pp_instance *)handle; |
| 575 | int ret = 0; |
Rex Zhu | cac9a19 | 2015-10-16 11:48:21 +0800 | [diff] [blame] | 576 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 577 | ret = pp_check(pp_handle); |
Rex Zhu | cac9a19 | 2015-10-16 11:48:21 +0800 | [diff] [blame] | 578 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 579 | if (ret != 0) |
| 580 | return ret; |
Rex Zhu | cac9a19 | 2015-10-16 11:48:21 +0800 | [diff] [blame] | 581 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 582 | hwmgr = pp_handle->hwmgr; |
Rex Zhu | 7383bcb | 2016-03-30 11:35:50 +0800 | [diff] [blame] | 583 | |
| 584 | if (hwmgr->hwmgr_func->set_fan_speed_percent == NULL) { |
Huang Rui | 0fb829d | 2016-12-26 14:24:05 +0800 | [diff] [blame] | 585 | pr_info("%s was not implemented.\n", __func__); |
Rex Zhu | 7383bcb | 2016-03-30 11:35:50 +0800 | [diff] [blame] | 586 | return 0; |
| 587 | } |
Rex Zhu | 2a50710 | 2017-02-20 17:07:36 +0800 | [diff] [blame] | 588 | mutex_lock(&pp_handle->pp_lock); |
| 589 | ret = hwmgr->hwmgr_func->set_fan_speed_percent(hwmgr, percent); |
| 590 | mutex_unlock(&pp_handle->pp_lock); |
| 591 | return ret; |
Rex Zhu | cac9a19 | 2015-10-16 11:48:21 +0800 | [diff] [blame] | 592 | } |
| 593 | |
| 594 | static int pp_dpm_get_fan_speed_percent(void *handle, uint32_t *speed) |
| 595 | { |
| 596 | struct pp_hwmgr *hwmgr; |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 597 | struct pp_instance *pp_handle = (struct pp_instance *)handle; |
| 598 | int ret = 0; |
Rex Zhu | cac9a19 | 2015-10-16 11:48:21 +0800 | [diff] [blame] | 599 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 600 | ret = pp_check(pp_handle); |
Rex Zhu | cac9a19 | 2015-10-16 11:48:21 +0800 | [diff] [blame] | 601 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 602 | if (ret != 0) |
| 603 | return ret; |
Rex Zhu | cac9a19 | 2015-10-16 11:48:21 +0800 | [diff] [blame] | 604 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 605 | hwmgr = pp_handle->hwmgr; |
Rex Zhu | 7383bcb | 2016-03-30 11:35:50 +0800 | [diff] [blame] | 606 | |
| 607 | if (hwmgr->hwmgr_func->get_fan_speed_percent == NULL) { |
Huang Rui | 0fb829d | 2016-12-26 14:24:05 +0800 | [diff] [blame] | 608 | pr_info("%s was not implemented.\n", __func__); |
Rex Zhu | 7383bcb | 2016-03-30 11:35:50 +0800 | [diff] [blame] | 609 | return 0; |
| 610 | } |
Rex Zhu | cac9a19 | 2015-10-16 11:48:21 +0800 | [diff] [blame] | 611 | |
Rex Zhu | 2a50710 | 2017-02-20 17:07:36 +0800 | [diff] [blame] | 612 | mutex_lock(&pp_handle->pp_lock); |
| 613 | ret = hwmgr->hwmgr_func->get_fan_speed_percent(hwmgr, speed); |
| 614 | mutex_unlock(&pp_handle->pp_lock); |
| 615 | return ret; |
Rex Zhu | cac9a19 | 2015-10-16 11:48:21 +0800 | [diff] [blame] | 616 | } |
| 617 | |
Grazvydas Ignotas | 72a16a9 | 2016-10-29 23:28:58 +0300 | [diff] [blame] | 618 | static int pp_dpm_get_fan_speed_rpm(void *handle, uint32_t *rpm) |
| 619 | { |
| 620 | struct pp_hwmgr *hwmgr; |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 621 | struct pp_instance *pp_handle = (struct pp_instance *)handle; |
| 622 | int ret = 0; |
Grazvydas Ignotas | 72a16a9 | 2016-10-29 23:28:58 +0300 | [diff] [blame] | 623 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 624 | ret = pp_check(pp_handle); |
Grazvydas Ignotas | 72a16a9 | 2016-10-29 23:28:58 +0300 | [diff] [blame] | 625 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 626 | if (ret != 0) |
| 627 | return ret; |
Grazvydas Ignotas | 72a16a9 | 2016-10-29 23:28:58 +0300 | [diff] [blame] | 628 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 629 | hwmgr = pp_handle->hwmgr; |
Grazvydas Ignotas | 72a16a9 | 2016-10-29 23:28:58 +0300 | [diff] [blame] | 630 | |
| 631 | if (hwmgr->hwmgr_func->get_fan_speed_rpm == NULL) |
| 632 | return -EINVAL; |
| 633 | |
Rex Zhu | 2a50710 | 2017-02-20 17:07:36 +0800 | [diff] [blame] | 634 | mutex_lock(&pp_handle->pp_lock); |
| 635 | ret = hwmgr->hwmgr_func->get_fan_speed_rpm(hwmgr, rpm); |
| 636 | mutex_unlock(&pp_handle->pp_lock); |
| 637 | return ret; |
Grazvydas Ignotas | 72a16a9 | 2016-10-29 23:28:58 +0300 | [diff] [blame] | 638 | } |
| 639 | |
Rex Zhu | cac9a19 | 2015-10-16 11:48:21 +0800 | [diff] [blame] | 640 | static int pp_dpm_get_temperature(void *handle) |
| 641 | { |
| 642 | struct pp_hwmgr *hwmgr; |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 643 | struct pp_instance *pp_handle = (struct pp_instance *)handle; |
| 644 | int ret = 0; |
Rex Zhu | cac9a19 | 2015-10-16 11:48:21 +0800 | [diff] [blame] | 645 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 646 | ret = pp_check(pp_handle); |
Rex Zhu | cac9a19 | 2015-10-16 11:48:21 +0800 | [diff] [blame] | 647 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 648 | if (ret != 0) |
| 649 | return ret; |
Rex Zhu | cac9a19 | 2015-10-16 11:48:21 +0800 | [diff] [blame] | 650 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 651 | hwmgr = pp_handle->hwmgr; |
Rex Zhu | 7383bcb | 2016-03-30 11:35:50 +0800 | [diff] [blame] | 652 | |
| 653 | if (hwmgr->hwmgr_func->get_temperature == NULL) { |
Huang Rui | 0fb829d | 2016-12-26 14:24:05 +0800 | [diff] [blame] | 654 | pr_info("%s was not implemented.\n", __func__); |
Rex Zhu | 7383bcb | 2016-03-30 11:35:50 +0800 | [diff] [blame] | 655 | return 0; |
| 656 | } |
Rex Zhu | 2a50710 | 2017-02-20 17:07:36 +0800 | [diff] [blame] | 657 | mutex_lock(&pp_handle->pp_lock); |
| 658 | ret = hwmgr->hwmgr_func->get_temperature(hwmgr); |
| 659 | mutex_unlock(&pp_handle->pp_lock); |
| 660 | return ret; |
Rex Zhu | cac9a19 | 2015-10-16 11:48:21 +0800 | [diff] [blame] | 661 | } |
Rex Zhu | 577bbe0 | 2015-08-28 12:56:43 +0800 | [diff] [blame] | 662 | |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 663 | static int pp_dpm_get_pp_num_states(void *handle, |
| 664 | struct pp_states_info *data) |
| 665 | { |
| 666 | struct pp_hwmgr *hwmgr; |
| 667 | int i; |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 668 | struct pp_instance *pp_handle = (struct pp_instance *)handle; |
| 669 | int ret = 0; |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 670 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 671 | ret = pp_check(pp_handle); |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 672 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 673 | if (ret != 0) |
| 674 | return ret; |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 675 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 676 | hwmgr = pp_handle->hwmgr; |
| 677 | |
| 678 | if (hwmgr->ps == NULL) |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 679 | return -EINVAL; |
| 680 | |
Rex Zhu | 2a50710 | 2017-02-20 17:07:36 +0800 | [diff] [blame] | 681 | mutex_lock(&pp_handle->pp_lock); |
| 682 | |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 683 | data->nums = hwmgr->num_ps; |
| 684 | |
| 685 | for (i = 0; i < hwmgr->num_ps; i++) { |
| 686 | struct pp_power_state *state = (struct pp_power_state *) |
| 687 | ((unsigned long)hwmgr->ps + i * hwmgr->ps_size); |
| 688 | switch (state->classification.ui_label) { |
| 689 | case PP_StateUILabel_Battery: |
| 690 | data->states[i] = POWER_STATE_TYPE_BATTERY; |
| 691 | break; |
| 692 | case PP_StateUILabel_Balanced: |
| 693 | data->states[i] = POWER_STATE_TYPE_BALANCED; |
| 694 | break; |
| 695 | case PP_StateUILabel_Performance: |
| 696 | data->states[i] = POWER_STATE_TYPE_PERFORMANCE; |
| 697 | break; |
| 698 | default: |
| 699 | if (state->classification.flags & PP_StateClassificationFlag_Boot) |
| 700 | data->states[i] = POWER_STATE_TYPE_INTERNAL_BOOT; |
| 701 | else |
| 702 | data->states[i] = POWER_STATE_TYPE_DEFAULT; |
| 703 | } |
| 704 | } |
Rex Zhu | 2a50710 | 2017-02-20 17:07:36 +0800 | [diff] [blame] | 705 | mutex_unlock(&pp_handle->pp_lock); |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 706 | return 0; |
| 707 | } |
| 708 | |
| 709 | static int pp_dpm_get_pp_table(void *handle, char **table) |
| 710 | { |
| 711 | struct pp_hwmgr *hwmgr; |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 712 | struct pp_instance *pp_handle = (struct pp_instance *)handle; |
| 713 | int ret = 0; |
Rex Zhu | 2a50710 | 2017-02-20 17:07:36 +0800 | [diff] [blame] | 714 | int size = 0; |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 715 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 716 | ret = pp_check(pp_handle); |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 717 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 718 | if (ret != 0) |
| 719 | return ret; |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 720 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 721 | hwmgr = pp_handle->hwmgr; |
Rex Zhu | 7383bcb | 2016-03-30 11:35:50 +0800 | [diff] [blame] | 722 | |
Eric Huang | 4dcf9e6 | 2016-06-01 17:08:07 -0400 | [diff] [blame] | 723 | if (!hwmgr->soft_pp_table) |
| 724 | return -EINVAL; |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 725 | |
Rex Zhu | 2a50710 | 2017-02-20 17:07:36 +0800 | [diff] [blame] | 726 | mutex_lock(&pp_handle->pp_lock); |
Eric Huang | 4dcf9e6 | 2016-06-01 17:08:07 -0400 | [diff] [blame] | 727 | *table = (char *)hwmgr->soft_pp_table; |
Rex Zhu | 2a50710 | 2017-02-20 17:07:36 +0800 | [diff] [blame] | 728 | size = hwmgr->soft_pp_table_size; |
| 729 | mutex_unlock(&pp_handle->pp_lock); |
| 730 | return size; |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 731 | } |
| 732 | |
| 733 | static int pp_dpm_set_pp_table(void *handle, const char *buf, size_t size) |
| 734 | { |
| 735 | struct pp_hwmgr *hwmgr; |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 736 | struct pp_instance *pp_handle = (struct pp_instance *)handle; |
| 737 | int ret = 0; |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 738 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 739 | ret = pp_check(pp_handle); |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 740 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 741 | if (ret != 0) |
| 742 | return ret; |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 743 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 744 | hwmgr = pp_handle->hwmgr; |
Rex Zhu | 2a50710 | 2017-02-20 17:07:36 +0800 | [diff] [blame] | 745 | mutex_lock(&pp_handle->pp_lock); |
Eric Huang | 4dcf9e6 | 2016-06-01 17:08:07 -0400 | [diff] [blame] | 746 | if (!hwmgr->hardcode_pp_table) { |
Edward O'Callaghan | efdf7a93 | 2016-09-04 12:36:19 +1000 | [diff] [blame] | 747 | hwmgr->hardcode_pp_table = kmemdup(hwmgr->soft_pp_table, |
| 748 | hwmgr->soft_pp_table_size, |
| 749 | GFP_KERNEL); |
Rex Zhu | 2a50710 | 2017-02-20 17:07:36 +0800 | [diff] [blame] | 750 | if (!hwmgr->hardcode_pp_table) { |
| 751 | mutex_unlock(&pp_handle->pp_lock); |
Eric Huang | 4dcf9e6 | 2016-06-01 17:08:07 -0400 | [diff] [blame] | 752 | return -ENOMEM; |
Rex Zhu | 2a50710 | 2017-02-20 17:07:36 +0800 | [diff] [blame] | 753 | } |
Rex Zhu | 7383bcb | 2016-03-30 11:35:50 +0800 | [diff] [blame] | 754 | } |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 755 | |
Eric Huang | 4dcf9e6 | 2016-06-01 17:08:07 -0400 | [diff] [blame] | 756 | memcpy(hwmgr->hardcode_pp_table, buf, size); |
| 757 | |
| 758 | hwmgr->soft_pp_table = hwmgr->hardcode_pp_table; |
Rex Zhu | 2a50710 | 2017-02-20 17:07:36 +0800 | [diff] [blame] | 759 | mutex_unlock(&pp_handle->pp_lock); |
Eric Huang | 4dcf9e6 | 2016-06-01 17:08:07 -0400 | [diff] [blame] | 760 | |
Eric Huang | dd4bdf3 | 2017-03-01 15:49:31 -0500 | [diff] [blame] | 761 | ret = amd_powerplay_reset(handle); |
| 762 | if (ret) |
| 763 | return ret; |
| 764 | |
| 765 | if (hwmgr->hwmgr_func->avfs_control) { |
| 766 | ret = hwmgr->hwmgr_func->avfs_control(hwmgr, false); |
| 767 | if (ret) |
| 768 | return ret; |
| 769 | } |
| 770 | |
| 771 | return 0; |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 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; |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 778 | struct pp_instance *pp_handle = (struct pp_instance *)handle; |
| 779 | int ret = 0; |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 780 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 781 | ret = pp_check(pp_handle); |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 782 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 783 | if (ret != 0) |
| 784 | return ret; |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 785 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 786 | hwmgr = pp_handle->hwmgr; |
Rex Zhu | 7383bcb | 2016-03-30 11:35:50 +0800 | [diff] [blame] | 787 | |
| 788 | if (hwmgr->hwmgr_func->force_clock_level == NULL) { |
Huang Rui | 0fb829d | 2016-12-26 14:24:05 +0800 | [diff] [blame] | 789 | pr_info("%s was not implemented.\n", __func__); |
Rex Zhu | 7383bcb | 2016-03-30 11:35:50 +0800 | [diff] [blame] | 790 | return 0; |
| 791 | } |
Rex Zhu | 2a50710 | 2017-02-20 17:07:36 +0800 | [diff] [blame] | 792 | mutex_lock(&pp_handle->pp_lock); |
| 793 | hwmgr->hwmgr_func->force_clock_level(hwmgr, type, mask); |
| 794 | mutex_unlock(&pp_handle->pp_lock); |
| 795 | return ret; |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 796 | } |
| 797 | |
| 798 | static int pp_dpm_print_clock_levels(void *handle, |
| 799 | enum pp_clock_type type, char *buf) |
| 800 | { |
| 801 | struct pp_hwmgr *hwmgr; |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 802 | struct pp_instance *pp_handle = (struct pp_instance *)handle; |
| 803 | int ret = 0; |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 804 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 805 | ret = pp_check(pp_handle); |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 806 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 807 | if (ret != 0) |
| 808 | return ret; |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 809 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 810 | hwmgr = pp_handle->hwmgr; |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 811 | |
Rex Zhu | 7383bcb | 2016-03-30 11:35:50 +0800 | [diff] [blame] | 812 | if (hwmgr->hwmgr_func->print_clock_levels == NULL) { |
Huang Rui | 0fb829d | 2016-12-26 14:24:05 +0800 | [diff] [blame] | 813 | pr_info("%s was not implemented.\n", __func__); |
Rex Zhu | 7383bcb | 2016-03-30 11:35:50 +0800 | [diff] [blame] | 814 | return 0; |
| 815 | } |
Rex Zhu | 2a50710 | 2017-02-20 17:07:36 +0800 | [diff] [blame] | 816 | mutex_lock(&pp_handle->pp_lock); |
| 817 | ret = hwmgr->hwmgr_func->print_clock_levels(hwmgr, type, buf); |
| 818 | mutex_unlock(&pp_handle->pp_lock); |
| 819 | return ret; |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 820 | } |
| 821 | |
Eric Huang | 428bafa | 2016-05-12 14:51:21 -0400 | [diff] [blame] | 822 | static int pp_dpm_get_sclk_od(void *handle) |
| 823 | { |
| 824 | struct pp_hwmgr *hwmgr; |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 825 | struct pp_instance *pp_handle = (struct pp_instance *)handle; |
| 826 | int ret = 0; |
Eric Huang | 428bafa | 2016-05-12 14:51:21 -0400 | [diff] [blame] | 827 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 828 | ret = pp_check(pp_handle); |
Eric Huang | 428bafa | 2016-05-12 14:51:21 -0400 | [diff] [blame] | 829 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 830 | if (ret != 0) |
| 831 | return ret; |
Eric Huang | 428bafa | 2016-05-12 14:51:21 -0400 | [diff] [blame] | 832 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 833 | hwmgr = pp_handle->hwmgr; |
Eric Huang | 428bafa | 2016-05-12 14:51:21 -0400 | [diff] [blame] | 834 | |
| 835 | if (hwmgr->hwmgr_func->get_sclk_od == NULL) { |
Huang Rui | 0fb829d | 2016-12-26 14:24:05 +0800 | [diff] [blame] | 836 | pr_info("%s was not implemented.\n", __func__); |
Eric Huang | 428bafa | 2016-05-12 14:51:21 -0400 | [diff] [blame] | 837 | return 0; |
| 838 | } |
Rex Zhu | 2a50710 | 2017-02-20 17:07:36 +0800 | [diff] [blame] | 839 | mutex_lock(&pp_handle->pp_lock); |
| 840 | ret = hwmgr->hwmgr_func->get_sclk_od(hwmgr); |
| 841 | mutex_unlock(&pp_handle->pp_lock); |
| 842 | return ret; |
Eric Huang | 428bafa | 2016-05-12 14:51:21 -0400 | [diff] [blame] | 843 | } |
| 844 | |
| 845 | static int pp_dpm_set_sclk_od(void *handle, uint32_t value) |
| 846 | { |
| 847 | struct pp_hwmgr *hwmgr; |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 848 | struct pp_instance *pp_handle = (struct pp_instance *)handle; |
| 849 | int ret = 0; |
Eric Huang | 428bafa | 2016-05-12 14:51:21 -0400 | [diff] [blame] | 850 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 851 | ret = pp_check(pp_handle); |
Eric Huang | 428bafa | 2016-05-12 14:51:21 -0400 | [diff] [blame] | 852 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 853 | if (ret != 0) |
| 854 | return ret; |
Eric Huang | 428bafa | 2016-05-12 14:51:21 -0400 | [diff] [blame] | 855 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 856 | hwmgr = pp_handle->hwmgr; |
Eric Huang | 428bafa | 2016-05-12 14:51:21 -0400 | [diff] [blame] | 857 | |
| 858 | if (hwmgr->hwmgr_func->set_sclk_od == NULL) { |
Huang Rui | 0fb829d | 2016-12-26 14:24:05 +0800 | [diff] [blame] | 859 | pr_info("%s was not implemented.\n", __func__); |
Eric Huang | 428bafa | 2016-05-12 14:51:21 -0400 | [diff] [blame] | 860 | return 0; |
| 861 | } |
| 862 | |
Rex Zhu | 2a50710 | 2017-02-20 17:07:36 +0800 | [diff] [blame] | 863 | mutex_lock(&pp_handle->pp_lock); |
| 864 | ret = hwmgr->hwmgr_func->set_sclk_od(hwmgr, value); |
Alex Deucher | ad4febd | 2017-03-31 10:51:29 -0400 | [diff] [blame] | 865 | mutex_unlock(&pp_handle->pp_lock); |
Rex Zhu | 2a50710 | 2017-02-20 17:07:36 +0800 | [diff] [blame] | 866 | return ret; |
Eric Huang | 428bafa | 2016-05-12 14:51:21 -0400 | [diff] [blame] | 867 | } |
| 868 | |
Eric Huang | f2bdc05 | 2016-05-24 15:11:17 -0400 | [diff] [blame] | 869 | static int pp_dpm_get_mclk_od(void *handle) |
| 870 | { |
| 871 | struct pp_hwmgr *hwmgr; |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 872 | struct pp_instance *pp_handle = (struct pp_instance *)handle; |
| 873 | int ret = 0; |
Eric Huang | f2bdc05 | 2016-05-24 15:11:17 -0400 | [diff] [blame] | 874 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 875 | ret = pp_check(pp_handle); |
Eric Huang | f2bdc05 | 2016-05-24 15:11:17 -0400 | [diff] [blame] | 876 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 877 | if (ret != 0) |
| 878 | return ret; |
Eric Huang | f2bdc05 | 2016-05-24 15:11:17 -0400 | [diff] [blame] | 879 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 880 | hwmgr = pp_handle->hwmgr; |
Eric Huang | f2bdc05 | 2016-05-24 15:11:17 -0400 | [diff] [blame] | 881 | |
| 882 | if (hwmgr->hwmgr_func->get_mclk_od == NULL) { |
Huang Rui | 0fb829d | 2016-12-26 14:24:05 +0800 | [diff] [blame] | 883 | pr_info("%s was not implemented.\n", __func__); |
Eric Huang | f2bdc05 | 2016-05-24 15:11:17 -0400 | [diff] [blame] | 884 | return 0; |
| 885 | } |
Rex Zhu | 2a50710 | 2017-02-20 17:07:36 +0800 | [diff] [blame] | 886 | mutex_lock(&pp_handle->pp_lock); |
| 887 | ret = hwmgr->hwmgr_func->get_mclk_od(hwmgr); |
| 888 | mutex_unlock(&pp_handle->pp_lock); |
| 889 | return ret; |
Eric Huang | f2bdc05 | 2016-05-24 15:11:17 -0400 | [diff] [blame] | 890 | } |
| 891 | |
| 892 | static int pp_dpm_set_mclk_od(void *handle, uint32_t value) |
| 893 | { |
| 894 | struct pp_hwmgr *hwmgr; |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 895 | struct pp_instance *pp_handle = (struct pp_instance *)handle; |
| 896 | int ret = 0; |
Eric Huang | f2bdc05 | 2016-05-24 15:11:17 -0400 | [diff] [blame] | 897 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 898 | ret = pp_check(pp_handle); |
Eric Huang | f2bdc05 | 2016-05-24 15:11:17 -0400 | [diff] [blame] | 899 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 900 | if (ret != 0) |
| 901 | return ret; |
Eric Huang | f2bdc05 | 2016-05-24 15:11:17 -0400 | [diff] [blame] | 902 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 903 | hwmgr = pp_handle->hwmgr; |
Eric Huang | f2bdc05 | 2016-05-24 15:11:17 -0400 | [diff] [blame] | 904 | |
| 905 | if (hwmgr->hwmgr_func->set_mclk_od == NULL) { |
Huang Rui | 0fb829d | 2016-12-26 14:24:05 +0800 | [diff] [blame] | 906 | pr_info("%s was not implemented.\n", __func__); |
Eric Huang | f2bdc05 | 2016-05-24 15:11:17 -0400 | [diff] [blame] | 907 | return 0; |
| 908 | } |
Rex Zhu | 2a50710 | 2017-02-20 17:07:36 +0800 | [diff] [blame] | 909 | mutex_lock(&pp_handle->pp_lock); |
| 910 | ret = hwmgr->hwmgr_func->set_mclk_od(hwmgr, value); |
| 911 | mutex_unlock(&pp_handle->pp_lock); |
| 912 | return ret; |
Eric Huang | f2bdc05 | 2016-05-24 15:11:17 -0400 | [diff] [blame] | 913 | } |
| 914 | |
Tom St Denis | 9f8df7d | 2017-02-09 14:29:01 -0500 | [diff] [blame] | 915 | static int pp_dpm_read_sensor(void *handle, int idx, |
| 916 | void *value, int *size) |
Tom St Denis | a6e3695 | 2016-09-15 10:07:34 -0400 | [diff] [blame] | 917 | { |
| 918 | struct pp_hwmgr *hwmgr; |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 919 | struct pp_instance *pp_handle = (struct pp_instance *)handle; |
| 920 | int ret = 0; |
Tom St Denis | a6e3695 | 2016-09-15 10:07:34 -0400 | [diff] [blame] | 921 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 922 | ret = pp_check(pp_handle); |
Tom St Denis | a6e3695 | 2016-09-15 10:07:34 -0400 | [diff] [blame] | 923 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 924 | if (ret != 0) |
| 925 | return ret; |
Tom St Denis | a6e3695 | 2016-09-15 10:07:34 -0400 | [diff] [blame] | 926 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 927 | hwmgr = pp_handle->hwmgr; |
Tom St Denis | a6e3695 | 2016-09-15 10:07:34 -0400 | [diff] [blame] | 928 | |
| 929 | if (hwmgr->hwmgr_func->read_sensor == NULL) { |
Huang Rui | 0fb829d | 2016-12-26 14:24:05 +0800 | [diff] [blame] | 930 | pr_info("%s was not implemented.\n", __func__); |
Tom St Denis | a6e3695 | 2016-09-15 10:07:34 -0400 | [diff] [blame] | 931 | return 0; |
| 932 | } |
| 933 | |
Rex Zhu | 2a50710 | 2017-02-20 17:07:36 +0800 | [diff] [blame] | 934 | mutex_lock(&pp_handle->pp_lock); |
| 935 | ret = hwmgr->hwmgr_func->read_sensor(hwmgr, idx, value, size); |
| 936 | mutex_unlock(&pp_handle->pp_lock); |
| 937 | |
| 938 | return ret; |
Tom St Denis | a6e3695 | 2016-09-15 10:07:34 -0400 | [diff] [blame] | 939 | } |
| 940 | |
Alex Deucher | 597be30 | 2016-10-07 13:52:43 -0400 | [diff] [blame] | 941 | static struct amd_vce_state* |
| 942 | pp_dpm_get_vce_clock_state(void *handle, unsigned idx) |
| 943 | { |
| 944 | struct pp_hwmgr *hwmgr; |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 945 | struct pp_instance *pp_handle = (struct pp_instance *)handle; |
| 946 | int ret = 0; |
Alex Deucher | 597be30 | 2016-10-07 13:52:43 -0400 | [diff] [blame] | 947 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 948 | ret = pp_check(pp_handle); |
Alex Deucher | 597be30 | 2016-10-07 13:52:43 -0400 | [diff] [blame] | 949 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 950 | if (ret != 0) |
| 951 | return NULL; |
| 952 | |
| 953 | hwmgr = pp_handle->hwmgr; |
| 954 | |
| 955 | if (hwmgr && idx < hwmgr->num_vce_state_tables) |
| 956 | return &hwmgr->vce_states[idx]; |
Alex Deucher | 597be30 | 2016-10-07 13:52:43 -0400 | [diff] [blame] | 957 | return NULL; |
| 958 | } |
| 959 | |
Eric Huang | 34bb273 | 2016-09-12 16:17:44 -0400 | [diff] [blame] | 960 | static int pp_dpm_reset_power_profile_state(void *handle, |
| 961 | struct amd_pp_profile *request) |
| 962 | { |
| 963 | struct pp_hwmgr *hwmgr; |
| 964 | struct pp_instance *pp_handle = (struct pp_instance *)handle; |
| 965 | |
| 966 | if (!request || pp_check(pp_handle)) |
| 967 | return -EINVAL; |
| 968 | |
| 969 | hwmgr = pp_handle->hwmgr; |
| 970 | |
| 971 | if (hwmgr->hwmgr_func->set_power_profile_state == NULL) { |
| 972 | pr_info("%s was not implemented.\n", __func__); |
| 973 | return 0; |
| 974 | } |
| 975 | |
| 976 | if (request->type == AMD_PP_GFX_PROFILE) { |
| 977 | hwmgr->gfx_power_profile = hwmgr->default_gfx_power_profile; |
| 978 | return hwmgr->hwmgr_func->set_power_profile_state(hwmgr, |
| 979 | &hwmgr->gfx_power_profile); |
| 980 | } else if (request->type == AMD_PP_COMPUTE_PROFILE) { |
| 981 | hwmgr->compute_power_profile = |
| 982 | hwmgr->default_compute_power_profile; |
| 983 | return hwmgr->hwmgr_func->set_power_profile_state(hwmgr, |
| 984 | &hwmgr->compute_power_profile); |
| 985 | } else |
| 986 | return -EINVAL; |
| 987 | } |
| 988 | |
| 989 | static int pp_dpm_get_power_profile_state(void *handle, |
| 990 | struct amd_pp_profile *query) |
| 991 | { |
| 992 | struct pp_hwmgr *hwmgr; |
| 993 | struct pp_instance *pp_handle = (struct pp_instance *)handle; |
| 994 | |
| 995 | if (!query || pp_check(pp_handle)) |
| 996 | return -EINVAL; |
| 997 | |
| 998 | hwmgr = pp_handle->hwmgr; |
| 999 | |
| 1000 | if (query->type == AMD_PP_GFX_PROFILE) |
| 1001 | memcpy(query, &hwmgr->gfx_power_profile, |
| 1002 | sizeof(struct amd_pp_profile)); |
| 1003 | else if (query->type == AMD_PP_COMPUTE_PROFILE) |
| 1004 | memcpy(query, &hwmgr->compute_power_profile, |
| 1005 | sizeof(struct amd_pp_profile)); |
| 1006 | else |
| 1007 | return -EINVAL; |
| 1008 | |
| 1009 | return 0; |
| 1010 | } |
| 1011 | |
| 1012 | static int pp_dpm_set_power_profile_state(void *handle, |
| 1013 | struct amd_pp_profile *request) |
| 1014 | { |
| 1015 | struct pp_hwmgr *hwmgr; |
| 1016 | struct pp_instance *pp_handle = (struct pp_instance *)handle; |
| 1017 | int ret = -1; |
| 1018 | |
| 1019 | if (!request || pp_check(pp_handle)) |
| 1020 | return -EINVAL; |
| 1021 | |
| 1022 | hwmgr = pp_handle->hwmgr; |
| 1023 | |
| 1024 | if (hwmgr->hwmgr_func->set_power_profile_state == NULL) { |
| 1025 | pr_info("%s was not implemented.\n", __func__); |
| 1026 | return 0; |
| 1027 | } |
| 1028 | |
| 1029 | if (request->min_sclk || |
| 1030 | request->min_mclk || |
| 1031 | request->activity_threshold || |
| 1032 | request->up_hyst || |
| 1033 | request->down_hyst) { |
| 1034 | if (request->type == AMD_PP_GFX_PROFILE) |
| 1035 | memcpy(&hwmgr->gfx_power_profile, request, |
| 1036 | sizeof(struct amd_pp_profile)); |
| 1037 | else if (request->type == AMD_PP_COMPUTE_PROFILE) |
| 1038 | memcpy(&hwmgr->compute_power_profile, request, |
| 1039 | sizeof(struct amd_pp_profile)); |
| 1040 | else |
| 1041 | return -EINVAL; |
| 1042 | |
| 1043 | if (request->type == hwmgr->current_power_profile) |
| 1044 | ret = hwmgr->hwmgr_func->set_power_profile_state( |
| 1045 | hwmgr, |
| 1046 | request); |
| 1047 | } else { |
| 1048 | /* set power profile if it exists */ |
| 1049 | switch (request->type) { |
| 1050 | case AMD_PP_GFX_PROFILE: |
| 1051 | ret = hwmgr->hwmgr_func->set_power_profile_state( |
| 1052 | hwmgr, |
| 1053 | &hwmgr->gfx_power_profile); |
| 1054 | break; |
| 1055 | case AMD_PP_COMPUTE_PROFILE: |
| 1056 | ret = hwmgr->hwmgr_func->set_power_profile_state( |
| 1057 | hwmgr, |
| 1058 | &hwmgr->compute_power_profile); |
| 1059 | break; |
| 1060 | default: |
| 1061 | return -EINVAL; |
| 1062 | } |
| 1063 | } |
| 1064 | |
| 1065 | if (!ret) |
| 1066 | hwmgr->current_power_profile = request->type; |
| 1067 | |
| 1068 | return 0; |
| 1069 | } |
| 1070 | |
| 1071 | static int pp_dpm_switch_power_profile(void *handle, |
| 1072 | enum amd_pp_profile_type type) |
| 1073 | { |
| 1074 | struct pp_hwmgr *hwmgr; |
| 1075 | struct amd_pp_profile request = {0}; |
| 1076 | struct pp_instance *pp_handle = (struct pp_instance *)handle; |
| 1077 | |
| 1078 | if (pp_check(pp_handle)) |
| 1079 | return -EINVAL; |
| 1080 | |
| 1081 | hwmgr = pp_handle->hwmgr; |
| 1082 | |
| 1083 | if (hwmgr->current_power_profile != type) { |
| 1084 | request.type = type; |
| 1085 | pp_dpm_set_power_profile_state(handle, &request); |
| 1086 | } |
| 1087 | |
| 1088 | return 0; |
| 1089 | } |
| 1090 | |
Rex Zhu | f93f0c3 | 2017-09-06 16:08:03 +0800 | [diff] [blame] | 1091 | const struct amd_pm_funcs pp_dpm_funcs = { |
Rex Zhu | cac9a19 | 2015-10-16 11:48:21 +0800 | [diff] [blame] | 1092 | .get_temperature = pp_dpm_get_temperature, |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 1093 | .load_firmware = pp_dpm_load_fw, |
| 1094 | .wait_for_fw_loading_complete = pp_dpm_fw_loading_complete, |
| 1095 | .force_performance_level = pp_dpm_force_performance_level, |
| 1096 | .get_performance_level = pp_dpm_get_performance_level, |
| 1097 | .get_current_power_state = pp_dpm_get_current_power_state, |
| 1098 | .get_sclk = pp_dpm_get_sclk, |
| 1099 | .get_mclk = pp_dpm_get_mclk, |
| 1100 | .powergate_vce = pp_dpm_powergate_vce, |
| 1101 | .powergate_uvd = pp_dpm_powergate_uvd, |
| 1102 | .dispatch_tasks = pp_dpm_dispatch_tasks, |
Rex Zhu | cac9a19 | 2015-10-16 11:48:21 +0800 | [diff] [blame] | 1103 | .set_fan_control_mode = pp_dpm_set_fan_control_mode, |
| 1104 | .get_fan_control_mode = pp_dpm_get_fan_control_mode, |
| 1105 | .set_fan_speed_percent = pp_dpm_set_fan_speed_percent, |
| 1106 | .get_fan_speed_percent = pp_dpm_get_fan_speed_percent, |
Grazvydas Ignotas | 72a16a9 | 2016-10-29 23:28:58 +0300 | [diff] [blame] | 1107 | .get_fan_speed_rpm = pp_dpm_get_fan_speed_rpm, |
Eric Huang | f3898ea | 2015-12-11 16:24:34 -0500 | [diff] [blame] | 1108 | .get_pp_num_states = pp_dpm_get_pp_num_states, |
| 1109 | .get_pp_table = pp_dpm_get_pp_table, |
| 1110 | .set_pp_table = pp_dpm_set_pp_table, |
| 1111 | .force_clock_level = pp_dpm_force_clock_level, |
| 1112 | .print_clock_levels = pp_dpm_print_clock_levels, |
Eric Huang | 428bafa | 2016-05-12 14:51:21 -0400 | [diff] [blame] | 1113 | .get_sclk_od = pp_dpm_get_sclk_od, |
| 1114 | .set_sclk_od = pp_dpm_set_sclk_od, |
Eric Huang | f2bdc05 | 2016-05-24 15:11:17 -0400 | [diff] [blame] | 1115 | .get_mclk_od = pp_dpm_get_mclk_od, |
| 1116 | .set_mclk_od = pp_dpm_set_mclk_od, |
Tom St Denis | a6e3695 | 2016-09-15 10:07:34 -0400 | [diff] [blame] | 1117 | .read_sensor = pp_dpm_read_sensor, |
Alex Deucher | 597be30 | 2016-10-07 13:52:43 -0400 | [diff] [blame] | 1118 | .get_vce_clock_state = pp_dpm_get_vce_clock_state, |
Eric Huang | 34bb273 | 2016-09-12 16:17:44 -0400 | [diff] [blame] | 1119 | .reset_power_profile_state = pp_dpm_reset_power_profile_state, |
| 1120 | .get_power_profile_state = pp_dpm_get_power_profile_state, |
| 1121 | .set_power_profile_state = pp_dpm_set_power_profile_state, |
| 1122 | .switch_power_profile = pp_dpm_switch_power_profile, |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 1123 | }; |
| 1124 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 1125 | int amd_powerplay_create(struct amd_pp_init *pp_init, |
| 1126 | void **handle) |
Jammy Zhou | ac885b3 | 2015-07-21 17:43:02 +0800 | [diff] [blame] | 1127 | { |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 1128 | struct pp_instance *instance; |
Jammy Zhou | ac885b3 | 2015-07-21 17:43:02 +0800 | [diff] [blame] | 1129 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 1130 | if (pp_init == NULL || handle == NULL) |
| 1131 | return -EINVAL; |
| 1132 | |
| 1133 | instance = kzalloc(sizeof(struct pp_instance), GFP_KERNEL); |
| 1134 | if (instance == NULL) |
Jammy Zhou | ac885b3 | 2015-07-21 17:43:02 +0800 | [diff] [blame] | 1135 | return -ENOMEM; |
| 1136 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 1137 | instance->pp_valid = PP_VALID; |
| 1138 | instance->chip_family = pp_init->chip_family; |
| 1139 | instance->chip_id = pp_init->chip_id; |
| 1140 | instance->pm_en = pp_init->pm_en; |
| 1141 | instance->feature_mask = pp_init->feature_mask; |
| 1142 | instance->device = pp_init->device; |
Rex Zhu | 2a50710 | 2017-02-20 17:07:36 +0800 | [diff] [blame] | 1143 | mutex_init(&instance->pp_lock); |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 1144 | *handle = instance; |
Jammy Zhou | ac885b3 | 2015-07-21 17:43:02 +0800 | [diff] [blame] | 1145 | return 0; |
| 1146 | } |
| 1147 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 1148 | int amd_powerplay_destroy(void *handle) |
Jammy Zhou | ac885b3 | 2015-07-21 17:43:02 +0800 | [diff] [blame] | 1149 | { |
| 1150 | struct pp_instance *instance = (struct pp_instance *)handle; |
Rex Zhu | e92a037 | 2015-09-23 15:14:54 +0800 | [diff] [blame] | 1151 | |
Rex Zhu | b3b0305 | 2017-09-26 13:28:27 -0400 | [diff] [blame^] | 1152 | kfree(instance->hwmgr); |
| 1153 | instance->hwmgr = NULL; |
Jammy Zhou | 3bace35 | 2015-07-21 21:18:15 +0800 | [diff] [blame] | 1154 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 1155 | kfree(instance); |
| 1156 | instance = NULL; |
Alex Deucher | 1f7371b | 2015-12-02 17:46:21 -0500 | [diff] [blame] | 1157 | return 0; |
| 1158 | } |
Rex Zhu | 7fb72a1 | 2015-11-19 13:35:30 +0800 | [diff] [blame] | 1159 | |
Eric Huang | 4dcf9e6 | 2016-06-01 17:08:07 -0400 | [diff] [blame] | 1160 | int amd_powerplay_reset(void *handle) |
| 1161 | { |
| 1162 | struct pp_instance *instance = (struct pp_instance *)handle; |
Eric Huang | 4dcf9e6 | 2016-06-01 17:08:07 -0400 | [diff] [blame] | 1163 | int ret; |
| 1164 | |
Rex Zhu | b3b0305 | 2017-09-26 13:28:27 -0400 | [diff] [blame^] | 1165 | if (cgs_is_virtualization_enabled(instance->hwmgr->device)) |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 1166 | return PP_DPM_DISABLED; |
| 1167 | |
| 1168 | ret = pp_check(instance); |
| 1169 | if (ret != 0) |
| 1170 | return ret; |
| 1171 | |
Rex Zhu | df1e639 | 2017-09-01 13:46:20 +0800 | [diff] [blame] | 1172 | ret = pp_hw_fini(instance); |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 1173 | if (ret) |
| 1174 | return ret; |
| 1175 | |
| 1176 | ret = hwmgr_hw_init(instance); |
| 1177 | if (ret) |
| 1178 | return PP_DPM_DISABLED; |
Eric Huang | 4dcf9e6 | 2016-06-01 17:08:07 -0400 | [diff] [blame] | 1179 | |
Rex Zhu | df1e639 | 2017-09-01 13:46:20 +0800 | [diff] [blame] | 1180 | return hwmgr_handle_task(instance, AMD_PP_TASK_COMPLETE_INIT, NULL, NULL); |
Eric Huang | 4dcf9e6 | 2016-06-01 17:08:07 -0400 | [diff] [blame] | 1181 | } |
| 1182 | |
Rex Zhu | 7fb72a1 | 2015-11-19 13:35:30 +0800 | [diff] [blame] | 1183 | /* export this function to DAL */ |
| 1184 | |
David Rokhvarg | 155f1127c | 2015-12-14 10:51:39 -0500 | [diff] [blame] | 1185 | int amd_powerplay_display_configuration_change(void *handle, |
| 1186 | const struct amd_pp_display_configuration *display_config) |
Rex Zhu | 7fb72a1 | 2015-11-19 13:35:30 +0800 | [diff] [blame] | 1187 | { |
| 1188 | struct pp_hwmgr *hwmgr; |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 1189 | struct pp_instance *pp_handle = (struct pp_instance *)handle; |
| 1190 | int ret = 0; |
Rex Zhu | 7fb72a1 | 2015-11-19 13:35:30 +0800 | [diff] [blame] | 1191 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 1192 | ret = pp_check(pp_handle); |
Rex Zhu | 7fb72a1 | 2015-11-19 13:35:30 +0800 | [diff] [blame] | 1193 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 1194 | if (ret != 0) |
| 1195 | return ret; |
Rex Zhu | 7fb72a1 | 2015-11-19 13:35:30 +0800 | [diff] [blame] | 1196 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 1197 | hwmgr = pp_handle->hwmgr; |
Rex Zhu | 2a50710 | 2017-02-20 17:07:36 +0800 | [diff] [blame] | 1198 | mutex_lock(&pp_handle->pp_lock); |
Rex Zhu | 7fb72a1 | 2015-11-19 13:35:30 +0800 | [diff] [blame] | 1199 | phm_store_dal_configuration_data(hwmgr, display_config); |
Rex Zhu | 2a50710 | 2017-02-20 17:07:36 +0800 | [diff] [blame] | 1200 | mutex_unlock(&pp_handle->pp_lock); |
Rex Zhu | 7fb72a1 | 2015-11-19 13:35:30 +0800 | [diff] [blame] | 1201 | return 0; |
| 1202 | } |
Vitaly Prosyak | c4dd206 | 2015-11-30 16:39:53 -0500 | [diff] [blame] | 1203 | |
Vitaly Prosyak | 1c9a908 | 2015-12-03 10:27:57 -0500 | [diff] [blame] | 1204 | int amd_powerplay_get_display_power_level(void *handle, |
Rex Zhu | 4732913 | 2015-12-10 16:49:50 +0800 | [diff] [blame] | 1205 | struct amd_pp_simple_clock_info *output) |
Vitaly Prosyak | c4dd206 | 2015-11-30 16:39:53 -0500 | [diff] [blame] | 1206 | { |
| 1207 | struct pp_hwmgr *hwmgr; |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 1208 | struct pp_instance *pp_handle = (struct pp_instance *)handle; |
| 1209 | int ret = 0; |
Vitaly Prosyak | c4dd206 | 2015-11-30 16:39:53 -0500 | [diff] [blame] | 1210 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 1211 | ret = pp_check(pp_handle); |
| 1212 | |
| 1213 | if (ret != 0) |
| 1214 | return ret; |
| 1215 | |
| 1216 | hwmgr = pp_handle->hwmgr; |
Rex Zhu | a969e16 | 2015-12-29 13:56:03 +0800 | [diff] [blame] | 1217 | |
| 1218 | if (output == NULL) |
Vitaly Prosyak | c4dd206 | 2015-11-30 16:39:53 -0500 | [diff] [blame] | 1219 | return -EINVAL; |
| 1220 | |
Rex Zhu | 2a50710 | 2017-02-20 17:07:36 +0800 | [diff] [blame] | 1221 | mutex_lock(&pp_handle->pp_lock); |
| 1222 | ret = phm_get_dal_power_level(hwmgr, output); |
| 1223 | mutex_unlock(&pp_handle->pp_lock); |
| 1224 | return ret; |
Vitaly Prosyak | c4dd206 | 2015-11-30 16:39:53 -0500 | [diff] [blame] | 1225 | } |
Rex Zhu | e273b04 | 2015-12-07 18:44:23 +0800 | [diff] [blame] | 1226 | |
| 1227 | int amd_powerplay_get_current_clocks(void *handle, |
David Rokhvarg | 155f1127c | 2015-12-14 10:51:39 -0500 | [diff] [blame] | 1228 | struct amd_pp_clock_info *clocks) |
Rex Zhu | e273b04 | 2015-12-07 18:44:23 +0800 | [diff] [blame] | 1229 | { |
Rex Zhu | e273b04 | 2015-12-07 18:44:23 +0800 | [diff] [blame] | 1230 | struct amd_pp_simple_clock_info simple_clocks; |
| 1231 | struct pp_clock_info hw_clocks; |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 1232 | struct pp_hwmgr *hwmgr; |
| 1233 | struct pp_instance *pp_handle = (struct pp_instance *)handle; |
| 1234 | int ret = 0; |
Rex Zhu | e273b04 | 2015-12-07 18:44:23 +0800 | [diff] [blame] | 1235 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 1236 | ret = pp_check(pp_handle); |
Rex Zhu | fa9e699 | 2015-12-29 13:56:03 +0800 | [diff] [blame] | 1237 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 1238 | if (ret != 0) |
| 1239 | return ret; |
Rex Zhu | e273b04 | 2015-12-07 18:44:23 +0800 | [diff] [blame] | 1240 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 1241 | hwmgr = pp_handle->hwmgr; |
Rex Zhu | ba5f884 | 2016-10-27 15:29:57 +0800 | [diff] [blame] | 1242 | |
Rex Zhu | 2a50710 | 2017-02-20 17:07:36 +0800 | [diff] [blame] | 1243 | mutex_lock(&pp_handle->pp_lock); |
| 1244 | |
Rex Zhu | e273b04 | 2015-12-07 18:44:23 +0800 | [diff] [blame] | 1245 | phm_get_dal_power_level(hwmgr, &simple_clocks); |
| 1246 | |
Rex Zhu | 2a50710 | 2017-02-20 17:07:36 +0800 | [diff] [blame] | 1247 | if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, |
| 1248 | PHM_PlatformCaps_PowerContainment)) |
| 1249 | ret = phm_get_clock_info(hwmgr, &hwmgr->current_ps->hardware, |
| 1250 | &hw_clocks, PHM_PerformanceLevelDesignation_PowerContainment); |
| 1251 | else |
| 1252 | ret = phm_get_clock_info(hwmgr, &hwmgr->current_ps->hardware, |
| 1253 | &hw_clocks, PHM_PerformanceLevelDesignation_Activity); |
| 1254 | |
| 1255 | if (ret != 0) { |
| 1256 | pr_info("Error in phm_get_clock_info \n"); |
| 1257 | mutex_unlock(&pp_handle->pp_lock); |
| 1258 | return -EINVAL; |
Rex Zhu | e273b04 | 2015-12-07 18:44:23 +0800 | [diff] [blame] | 1259 | } |
| 1260 | |
| 1261 | clocks->min_engine_clock = hw_clocks.min_eng_clk; |
| 1262 | clocks->max_engine_clock = hw_clocks.max_eng_clk; |
| 1263 | clocks->min_memory_clock = hw_clocks.min_mem_clk; |
| 1264 | clocks->max_memory_clock = hw_clocks.max_mem_clk; |
| 1265 | clocks->min_bus_bandwidth = hw_clocks.min_bus_bandwidth; |
| 1266 | clocks->max_bus_bandwidth = hw_clocks.max_bus_bandwidth; |
| 1267 | |
| 1268 | clocks->max_engine_clock_in_sr = hw_clocks.max_eng_clk; |
| 1269 | clocks->min_engine_clock_in_sr = hw_clocks.min_eng_clk; |
| 1270 | |
| 1271 | clocks->max_clocks_state = simple_clocks.level; |
| 1272 | |
| 1273 | if (0 == phm_get_current_shallow_sleep_clocks(hwmgr, &hwmgr->current_ps->hardware, &hw_clocks)) { |
| 1274 | clocks->max_engine_clock_in_sr = hw_clocks.max_eng_clk; |
| 1275 | clocks->min_engine_clock_in_sr = hw_clocks.min_eng_clk; |
| 1276 | } |
Rex Zhu | 2a50710 | 2017-02-20 17:07:36 +0800 | [diff] [blame] | 1277 | mutex_unlock(&pp_handle->pp_lock); |
Rex Zhu | e273b04 | 2015-12-07 18:44:23 +0800 | [diff] [blame] | 1278 | return 0; |
Rex Zhu | e273b04 | 2015-12-07 18:44:23 +0800 | [diff] [blame] | 1279 | } |
| 1280 | |
| 1281 | int amd_powerplay_get_clock_by_type(void *handle, enum amd_pp_clock_type type, struct amd_pp_clocks *clocks) |
| 1282 | { |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 1283 | struct pp_hwmgr *hwmgr; |
| 1284 | struct pp_instance *pp_handle = (struct pp_instance *)handle; |
| 1285 | int ret = 0; |
Rex Zhu | e273b04 | 2015-12-07 18:44:23 +0800 | [diff] [blame] | 1286 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 1287 | ret = pp_check(pp_handle); |
Rex Zhu | e273b04 | 2015-12-07 18:44:23 +0800 | [diff] [blame] | 1288 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 1289 | if (ret != 0) |
| 1290 | return ret; |
| 1291 | |
| 1292 | hwmgr = pp_handle->hwmgr; |
Rex Zhu | fa9e699 | 2015-12-29 13:56:03 +0800 | [diff] [blame] | 1293 | |
| 1294 | if (clocks == NULL) |
Rex Zhu | e273b04 | 2015-12-07 18:44:23 +0800 | [diff] [blame] | 1295 | return -EINVAL; |
| 1296 | |
Rex Zhu | 2a50710 | 2017-02-20 17:07:36 +0800 | [diff] [blame] | 1297 | mutex_lock(&pp_handle->pp_lock); |
| 1298 | ret = phm_get_clock_by_type(hwmgr, type, clocks); |
| 1299 | mutex_unlock(&pp_handle->pp_lock); |
| 1300 | return ret; |
Rex Zhu | e273b04 | 2015-12-07 18:44:23 +0800 | [diff] [blame] | 1301 | } |
| 1302 | |
Eric Huang | d018772 | 2017-03-06 13:13:48 -0500 | [diff] [blame] | 1303 | int amd_powerplay_get_clock_by_type_with_latency(void *handle, |
| 1304 | enum amd_pp_clock_type type, |
| 1305 | struct pp_clock_levels_with_latency *clocks) |
| 1306 | { |
| 1307 | struct pp_hwmgr *hwmgr; |
| 1308 | struct pp_instance *pp_handle = (struct pp_instance *)handle; |
| 1309 | int ret = 0; |
| 1310 | |
| 1311 | ret = pp_check(pp_handle); |
| 1312 | if (ret != 0) |
| 1313 | return ret; |
| 1314 | |
| 1315 | if (!clocks) |
| 1316 | return -EINVAL; |
| 1317 | |
| 1318 | mutex_lock(&pp_handle->pp_lock); |
| 1319 | hwmgr = ((struct pp_instance *)handle)->hwmgr; |
| 1320 | ret = phm_get_clock_by_type_with_latency(hwmgr, type, clocks); |
| 1321 | mutex_unlock(&pp_handle->pp_lock); |
| 1322 | return ret; |
| 1323 | } |
| 1324 | |
| 1325 | int amd_powerplay_get_clock_by_type_with_voltage(void *handle, |
| 1326 | enum amd_pp_clock_type type, |
| 1327 | struct pp_clock_levels_with_voltage *clocks) |
| 1328 | { |
| 1329 | struct pp_hwmgr *hwmgr; |
| 1330 | struct pp_instance *pp_handle = (struct pp_instance *)handle; |
| 1331 | int ret = 0; |
| 1332 | |
| 1333 | ret = pp_check(pp_handle); |
| 1334 | if (ret != 0) |
| 1335 | return ret; |
| 1336 | |
| 1337 | if (!clocks) |
| 1338 | return -EINVAL; |
| 1339 | |
| 1340 | hwmgr = ((struct pp_instance *)handle)->hwmgr; |
| 1341 | |
| 1342 | mutex_lock(&pp_handle->pp_lock); |
| 1343 | |
| 1344 | ret = phm_get_clock_by_type_with_voltage(hwmgr, type, clocks); |
| 1345 | |
| 1346 | mutex_unlock(&pp_handle->pp_lock); |
| 1347 | return ret; |
| 1348 | } |
| 1349 | |
| 1350 | int amd_powerplay_set_watermarks_for_clocks_ranges(void *handle, |
| 1351 | struct pp_wm_sets_with_clock_ranges_soc15 *wm_with_clock_ranges) |
| 1352 | { |
| 1353 | struct pp_hwmgr *hwmgr; |
| 1354 | struct pp_instance *pp_handle = (struct pp_instance *)handle; |
| 1355 | int ret = 0; |
| 1356 | |
| 1357 | ret = pp_check(pp_handle); |
| 1358 | if (ret != 0) |
| 1359 | return ret; |
| 1360 | |
| 1361 | if (!wm_with_clock_ranges) |
| 1362 | return -EINVAL; |
| 1363 | |
| 1364 | hwmgr = ((struct pp_instance *)handle)->hwmgr; |
| 1365 | |
| 1366 | mutex_lock(&pp_handle->pp_lock); |
| 1367 | ret = phm_set_watermarks_for_clocks_ranges(hwmgr, |
| 1368 | wm_with_clock_ranges); |
| 1369 | mutex_unlock(&pp_handle->pp_lock); |
| 1370 | |
| 1371 | return ret; |
| 1372 | } |
| 1373 | |
| 1374 | int amd_powerplay_display_clock_voltage_request(void *handle, |
| 1375 | struct pp_display_clock_request *clock) |
| 1376 | { |
| 1377 | struct pp_hwmgr *hwmgr; |
| 1378 | struct pp_instance *pp_handle = (struct pp_instance *)handle; |
| 1379 | int ret = 0; |
| 1380 | |
| 1381 | ret = pp_check(pp_handle); |
| 1382 | if (ret != 0) |
| 1383 | return ret; |
| 1384 | |
| 1385 | if (!clock) |
| 1386 | return -EINVAL; |
| 1387 | |
| 1388 | hwmgr = ((struct pp_instance *)handle)->hwmgr; |
| 1389 | |
| 1390 | mutex_lock(&pp_handle->pp_lock); |
| 1391 | ret = phm_display_clock_voltage_request(hwmgr, clock); |
| 1392 | mutex_unlock(&pp_handle->pp_lock); |
| 1393 | |
| 1394 | return ret; |
| 1395 | } |
| 1396 | |
David Rokhvarg | 155f1127c | 2015-12-14 10:51:39 -0500 | [diff] [blame] | 1397 | int amd_powerplay_get_display_mode_validation_clocks(void *handle, |
| 1398 | struct amd_pp_simple_clock_info *clocks) |
Rex Zhu | e273b04 | 2015-12-07 18:44:23 +0800 | [diff] [blame] | 1399 | { |
Rex Zhu | e273b04 | 2015-12-07 18:44:23 +0800 | [diff] [blame] | 1400 | struct pp_hwmgr *hwmgr; |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 1401 | struct pp_instance *pp_handle = (struct pp_instance *)handle; |
| 1402 | int ret = 0; |
Rex Zhu | e273b04 | 2015-12-07 18:44:23 +0800 | [diff] [blame] | 1403 | |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 1404 | ret = pp_check(pp_handle); |
| 1405 | |
| 1406 | if (ret != 0) |
| 1407 | return ret; |
| 1408 | |
| 1409 | hwmgr = pp_handle->hwmgr; |
| 1410 | |
Rex Zhu | fa9e699 | 2015-12-29 13:56:03 +0800 | [diff] [blame] | 1411 | if (clocks == NULL) |
Rex Zhu | e273b04 | 2015-12-07 18:44:23 +0800 | [diff] [blame] | 1412 | return -EINVAL; |
| 1413 | |
Rex Zhu | 2a50710 | 2017-02-20 17:07:36 +0800 | [diff] [blame] | 1414 | mutex_lock(&pp_handle->pp_lock); |
| 1415 | |
Rex Zhu | e273b04 | 2015-12-07 18:44:23 +0800 | [diff] [blame] | 1416 | if (phm_cap_enabled(hwmgr->platform_descriptor.platformCaps, PHM_PlatformCaps_DynamicPatchPowerState)) |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 1417 | ret = phm_get_max_high_clocks(hwmgr, clocks); |
Rex Zhu | e273b04 | 2015-12-07 18:44:23 +0800 | [diff] [blame] | 1418 | |
Rex Zhu | 2a50710 | 2017-02-20 17:07:36 +0800 | [diff] [blame] | 1419 | mutex_unlock(&pp_handle->pp_lock); |
Rex Zhu | 1c86380 | 2016-12-28 19:43:23 +0800 | [diff] [blame] | 1420 | return ret; |
Rex Zhu | e273b04 | 2015-12-07 18:44:23 +0800 | [diff] [blame] | 1421 | } |
| 1422 | |