Dhaval Patel | 4d42460 | 2017-02-18 19:40:14 -0800 | [diff] [blame] | 1 | /* Copyright (c) 2016-2017, The Linux Foundation. All rights reserved. |
Alan Kwong | 67a3f79 | 2016-11-01 23:16:53 -0400 | [diff] [blame] | 2 | * |
| 3 | * This program is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License version 2 and |
| 5 | * only version 2 as published by the Free Software Foundation. |
| 6 | * |
| 7 | * This program is distributed in the hope that it will be useful, |
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | * GNU General Public License for more details. |
| 11 | */ |
| 12 | |
| 13 | #define pr_fmt(fmt) "[drm:%s:%d] " fmt, __func__, __LINE__ |
| 14 | |
| 15 | #include <linux/debugfs.h> |
| 16 | #include <linux/errno.h> |
| 17 | #include <linux/mutex.h> |
| 18 | #include <linux/sort.h> |
| 19 | #include <linux/clk.h> |
| 20 | #include <linux/bitmap.h> |
Dhaval Patel | 49ef6d7 | 2017-03-26 09:35:53 -0700 | [diff] [blame] | 21 | #include <linux/sde_rsc.h> |
Alan Kwong | 67a3f79 | 2016-11-01 23:16:53 -0400 | [diff] [blame] | 22 | |
| 23 | #include "msm_prop.h" |
| 24 | |
| 25 | #include "sde_kms.h" |
Alan Kwong | 67a3f79 | 2016-11-01 23:16:53 -0400 | [diff] [blame] | 26 | #include "sde_trace.h" |
| 27 | #include "sde_crtc.h" |
Alan Kwong | 67a3f79 | 2016-11-01 23:16:53 -0400 | [diff] [blame] | 28 | #include "sde_core_perf.h" |
Alan Kwong | 67a3f79 | 2016-11-01 23:16:53 -0400 | [diff] [blame] | 29 | |
Alan Kwong | 97abd43 | 2017-05-11 14:52:23 -0700 | [diff] [blame] | 30 | #define SDE_PERF_MODE_STRING_SIZE 128 |
| 31 | |
| 32 | /** |
| 33 | * enum sde_perf_mode - performance tuning mode |
| 34 | * @SDE_PERF_MODE_NORMAL: performance controlled by user mode client |
| 35 | * @SDE_PERF_MODE_MINIMUM: performance bounded by minimum setting |
| 36 | * @SDE_PERF_MODE_FIXED: performance bounded by fixed setting |
| 37 | */ |
| 38 | enum sde_perf_mode { |
| 39 | SDE_PERF_MODE_NORMAL, |
| 40 | SDE_PERF_MODE_MINIMUM, |
| 41 | SDE_PERF_MODE_FIXED, |
| 42 | SDE_PERF_MODE_MAX |
| 43 | }; |
| 44 | |
Dhaval Patel | dd2032a | 2017-04-11 10:50:36 -0700 | [diff] [blame] | 45 | /** |
| 46 | * enum sde_perf_vote_mode: perf vote mode. |
| 47 | * @APPS_RSC_MODE: It combines the vote for all displays and votes it |
| 48 | * through APPS rsc. This is default mode when display |
| 49 | * rsc is not available. |
| 50 | * @DISP_RSC_MODE: It combines the vote for all displays and votes it |
| 51 | * through display rsc. This is default configuration |
| 52 | * when display rsc is available. |
| 53 | * @DISP_RSC_PRIMARY_MODE: The primary display votes through display rsc |
| 54 | * while all other displays votes through apps rsc. |
| 55 | */ |
| 56 | enum sde_perf_vote_mode { |
| 57 | APPS_RSC_MODE, |
| 58 | DISP_RSC_MODE, |
| 59 | DISP_RSC_PRIMARY_MODE, |
| 60 | }; |
| 61 | |
Alan Kwong | 9aa061c | 2016-11-06 21:17:12 -0500 | [diff] [blame] | 62 | static struct sde_kms *_sde_crtc_get_kms(struct drm_crtc *crtc) |
| 63 | { |
| 64 | struct msm_drm_private *priv; |
| 65 | |
| 66 | if (!crtc->dev || !crtc->dev->dev_private) { |
| 67 | SDE_ERROR("invalid device\n"); |
| 68 | return NULL; |
| 69 | } |
| 70 | |
| 71 | priv = crtc->dev->dev_private; |
| 72 | if (!priv || !priv->kms) { |
| 73 | SDE_ERROR("invalid kms\n"); |
| 74 | return NULL; |
| 75 | } |
| 76 | |
| 77 | return to_sde_kms(priv->kms); |
| 78 | } |
| 79 | |
| 80 | static bool _sde_core_perf_crtc_is_power_on(struct drm_crtc *crtc) |
| 81 | { |
| 82 | return sde_crtc_is_enabled(crtc); |
| 83 | } |
| 84 | |
| 85 | static bool _sde_core_video_mode_intf_connected(struct drm_crtc *crtc) |
| 86 | { |
| 87 | struct drm_crtc *tmp_crtc; |
Dhaval Patel | 4d42460 | 2017-02-18 19:40:14 -0800 | [diff] [blame] | 88 | bool intf_connected = false; |
Alan Kwong | 9aa061c | 2016-11-06 21:17:12 -0500 | [diff] [blame] | 89 | |
| 90 | if (!crtc) |
Dhaval Patel | 4d42460 | 2017-02-18 19:40:14 -0800 | [diff] [blame] | 91 | goto end; |
Alan Kwong | 9aa061c | 2016-11-06 21:17:12 -0500 | [diff] [blame] | 92 | |
| 93 | drm_for_each_crtc(tmp_crtc, crtc->dev) { |
| 94 | if ((sde_crtc_get_intf_mode(tmp_crtc) == INTF_MODE_VIDEO) && |
| 95 | _sde_core_perf_crtc_is_power_on(tmp_crtc)) { |
| 96 | SDE_DEBUG("video interface connected crtc:%d\n", |
| 97 | tmp_crtc->base.id); |
Dhaval Patel | 4d42460 | 2017-02-18 19:40:14 -0800 | [diff] [blame] | 98 | intf_connected = true; |
| 99 | goto end; |
Alan Kwong | 9aa061c | 2016-11-06 21:17:12 -0500 | [diff] [blame] | 100 | } |
| 101 | } |
| 102 | |
Dhaval Patel | 4d42460 | 2017-02-18 19:40:14 -0800 | [diff] [blame] | 103 | end: |
| 104 | return intf_connected; |
Alan Kwong | 9aa061c | 2016-11-06 21:17:12 -0500 | [diff] [blame] | 105 | } |
| 106 | |
Alan Kwong | 8411a911 | 2017-06-06 19:29:01 -0400 | [diff] [blame] | 107 | static void _sde_core_perf_calc_crtc(struct sde_kms *kms, |
| 108 | struct drm_crtc *crtc, |
Alan Kwong | a193968 | 2017-05-05 11:30:08 -0700 | [diff] [blame] | 109 | struct drm_crtc_state *state, |
| 110 | struct sde_core_perf_params *perf) |
| 111 | { |
| 112 | struct sde_crtc_state *sde_cstate; |
Alan Kwong | 0230a10 | 2017-05-16 11:36:44 -0700 | [diff] [blame] | 113 | int i; |
Alan Kwong | a193968 | 2017-05-05 11:30:08 -0700 | [diff] [blame] | 114 | |
Alan Kwong | 8411a911 | 2017-06-06 19:29:01 -0400 | [diff] [blame] | 115 | if (!kms || !kms->catalog || !crtc || !state || !perf) { |
Alan Kwong | a193968 | 2017-05-05 11:30:08 -0700 | [diff] [blame] | 116 | SDE_ERROR("invalid parameters\n"); |
| 117 | return; |
| 118 | } |
| 119 | |
| 120 | sde_cstate = to_sde_crtc_state(state); |
| 121 | memset(perf, 0, sizeof(struct sde_core_perf_params)); |
| 122 | |
Alan Kwong | 0230a10 | 2017-05-16 11:36:44 -0700 | [diff] [blame] | 123 | perf->bw_ctl[SDE_POWER_HANDLE_DBUS_ID_MNOC] = |
| 124 | sde_crtc_get_property(sde_cstate, CRTC_PROP_CORE_AB); |
| 125 | perf->max_per_pipe_ib[SDE_POWER_HANDLE_DBUS_ID_MNOC] = |
| 126 | sde_crtc_get_property(sde_cstate, CRTC_PROP_CORE_IB); |
| 127 | |
| 128 | if (sde_cstate->bw_split_vote) { |
| 129 | perf->bw_ctl[SDE_POWER_HANDLE_DBUS_ID_LLCC] = |
| 130 | sde_crtc_get_property(sde_cstate, CRTC_PROP_LLCC_AB); |
| 131 | perf->max_per_pipe_ib[SDE_POWER_HANDLE_DBUS_ID_LLCC] = |
| 132 | sde_crtc_get_property(sde_cstate, CRTC_PROP_LLCC_IB); |
| 133 | perf->bw_ctl[SDE_POWER_HANDLE_DBUS_ID_EBI] = |
| 134 | sde_crtc_get_property(sde_cstate, CRTC_PROP_DRAM_AB); |
| 135 | perf->max_per_pipe_ib[SDE_POWER_HANDLE_DBUS_ID_EBI] = |
| 136 | sde_crtc_get_property(sde_cstate, CRTC_PROP_DRAM_IB); |
| 137 | } else { |
| 138 | perf->bw_ctl[SDE_POWER_HANDLE_DBUS_ID_LLCC] = |
| 139 | sde_crtc_get_property(sde_cstate, CRTC_PROP_CORE_AB); |
| 140 | perf->max_per_pipe_ib[SDE_POWER_HANDLE_DBUS_ID_LLCC] = |
Alan Kwong | a193968 | 2017-05-05 11:30:08 -0700 | [diff] [blame] | 141 | sde_crtc_get_property(sde_cstate, CRTC_PROP_CORE_IB); |
Alan Kwong | 0230a10 | 2017-05-16 11:36:44 -0700 | [diff] [blame] | 142 | perf->bw_ctl[SDE_POWER_HANDLE_DBUS_ID_EBI] = |
| 143 | sde_crtc_get_property(sde_cstate, CRTC_PROP_CORE_AB); |
| 144 | perf->max_per_pipe_ib[SDE_POWER_HANDLE_DBUS_ID_EBI] = |
| 145 | sde_crtc_get_property(sde_cstate, CRTC_PROP_CORE_IB); |
| 146 | } |
| 147 | |
Alan Kwong | a193968 | 2017-05-05 11:30:08 -0700 | [diff] [blame] | 148 | perf->core_clk_rate = |
| 149 | sde_crtc_get_property(sde_cstate, CRTC_PROP_CORE_CLK); |
| 150 | |
Alan Kwong | 8411a911 | 2017-06-06 19:29:01 -0400 | [diff] [blame] | 151 | if (!sde_cstate->bw_control) { |
Alan Kwong | 0230a10 | 2017-05-16 11:36:44 -0700 | [diff] [blame] | 152 | for (i = 0; i < SDE_POWER_HANDLE_DBUS_ID_MAX; i++) { |
| 153 | perf->bw_ctl[i] = kms->catalog->perf.max_bw_high * |
| 154 | 1000ULL; |
| 155 | perf->max_per_pipe_ib[i] = perf->bw_ctl[i]; |
| 156 | } |
Alan Kwong | 8411a911 | 2017-06-06 19:29:01 -0400 | [diff] [blame] | 157 | perf->core_clk_rate = kms->perf.max_core_clk_rate; |
| 158 | } else if (kms->perf.perf_tune.mode == SDE_PERF_MODE_MINIMUM) { |
Alan Kwong | 0230a10 | 2017-05-16 11:36:44 -0700 | [diff] [blame] | 159 | for (i = 0; i < SDE_POWER_HANDLE_DBUS_ID_MAX; i++) { |
| 160 | perf->bw_ctl[i] = 0; |
| 161 | perf->max_per_pipe_ib[i] = 0; |
| 162 | } |
Alan Kwong | 8411a911 | 2017-06-06 19:29:01 -0400 | [diff] [blame] | 163 | perf->core_clk_rate = 0; |
| 164 | } else if (kms->perf.perf_tune.mode == SDE_PERF_MODE_FIXED) { |
Alan Kwong | 0230a10 | 2017-05-16 11:36:44 -0700 | [diff] [blame] | 165 | for (i = 0; i < SDE_POWER_HANDLE_DBUS_ID_MAX; i++) { |
| 166 | perf->bw_ctl[i] = kms->perf.fix_core_ab_vote; |
| 167 | perf->max_per_pipe_ib[i] = kms->perf.fix_core_ib_vote; |
| 168 | } |
Alan Kwong | 8411a911 | 2017-06-06 19:29:01 -0400 | [diff] [blame] | 169 | perf->core_clk_rate = kms->perf.fix_core_clk_rate; |
| 170 | } |
| 171 | |
Ingrid Gallardo | 27d4512 | 2017-10-05 11:53:11 -0700 | [diff] [blame] | 172 | SDE_EVT32(crtc->base.id, perf->core_clk_rate); |
Ingrid Gallardo | ac3d09b | 2017-12-01 17:42:50 -0800 | [diff] [blame] | 173 | trace_sde_perf_calc_crtc(crtc->base.id, |
| 174 | perf->bw_ctl[SDE_POWER_HANDLE_DBUS_ID_MNOC], |
| 175 | perf->bw_ctl[SDE_POWER_HANDLE_DBUS_ID_LLCC], |
| 176 | perf->bw_ctl[SDE_POWER_HANDLE_DBUS_ID_EBI], |
| 177 | perf->max_per_pipe_ib[SDE_POWER_HANDLE_DBUS_ID_MNOC], |
| 178 | perf->max_per_pipe_ib[SDE_POWER_HANDLE_DBUS_ID_LLCC], |
| 179 | perf->max_per_pipe_ib[SDE_POWER_HANDLE_DBUS_ID_EBI], |
| 180 | perf->core_clk_rate); |
| 181 | |
Alan Kwong | 0230a10 | 2017-05-16 11:36:44 -0700 | [diff] [blame] | 182 | SDE_DEBUG( |
| 183 | "crtc=%d clk_rate=%llu core_ib=%llu core_ab=%llu llcc_ib=%llu llcc_ab=%llu mem_ib=%llu mem_ab=%llu\n", |
Alan Kwong | a193968 | 2017-05-05 11:30:08 -0700 | [diff] [blame] | 184 | crtc->base.id, perf->core_clk_rate, |
Alan Kwong | 0230a10 | 2017-05-16 11:36:44 -0700 | [diff] [blame] | 185 | perf->max_per_pipe_ib[SDE_POWER_HANDLE_DBUS_ID_MNOC], |
| 186 | perf->bw_ctl[SDE_POWER_HANDLE_DBUS_ID_MNOC], |
| 187 | perf->max_per_pipe_ib[SDE_POWER_HANDLE_DBUS_ID_LLCC], |
| 188 | perf->bw_ctl[SDE_POWER_HANDLE_DBUS_ID_LLCC], |
| 189 | perf->max_per_pipe_ib[SDE_POWER_HANDLE_DBUS_ID_EBI], |
| 190 | perf->bw_ctl[SDE_POWER_HANDLE_DBUS_ID_EBI]); |
Alan Kwong | a193968 | 2017-05-05 11:30:08 -0700 | [diff] [blame] | 191 | } |
| 192 | |
Alan Kwong | 9aa061c | 2016-11-06 21:17:12 -0500 | [diff] [blame] | 193 | int sde_core_perf_crtc_check(struct drm_crtc *crtc, |
| 194 | struct drm_crtc_state *state) |
| 195 | { |
| 196 | u32 bw, threshold; |
| 197 | u64 bw_sum_of_intfs = 0; |
Dhaval Patel | 4d42460 | 2017-02-18 19:40:14 -0800 | [diff] [blame] | 198 | enum sde_crtc_client_type curr_client_type; |
Alan Kwong | 9aa061c | 2016-11-06 21:17:12 -0500 | [diff] [blame] | 199 | bool is_video_mode; |
| 200 | struct sde_crtc_state *sde_cstate; |
| 201 | struct drm_crtc *tmp_crtc; |
| 202 | struct sde_kms *kms; |
Alan Kwong | 0230a10 | 2017-05-16 11:36:44 -0700 | [diff] [blame] | 203 | int i; |
Alan Kwong | 9aa061c | 2016-11-06 21:17:12 -0500 | [diff] [blame] | 204 | |
| 205 | if (!crtc || !state) { |
| 206 | SDE_ERROR("invalid crtc\n"); |
| 207 | return -EINVAL; |
| 208 | } |
| 209 | |
| 210 | kms = _sde_crtc_get_kms(crtc); |
| 211 | if (!kms || !kms->catalog) { |
| 212 | SDE_ERROR("invalid parameters\n"); |
| 213 | return 0; |
| 214 | } |
| 215 | |
| 216 | /* we only need bandwidth check on real-time clients (interfaces) */ |
Dhaval Patel | 4d42460 | 2017-02-18 19:40:14 -0800 | [diff] [blame] | 217 | if (sde_crtc_get_client_type(crtc) == NRT_CLIENT) |
Alan Kwong | 9aa061c | 2016-11-06 21:17:12 -0500 | [diff] [blame] | 218 | return 0; |
| 219 | |
| 220 | sde_cstate = to_sde_crtc_state(state); |
| 221 | |
Alan Kwong | 751cf46 | 2017-06-08 10:26:46 -0400 | [diff] [blame] | 222 | /* obtain new values */ |
Alan Kwong | 8411a911 | 2017-06-06 19:29:01 -0400 | [diff] [blame] | 223 | _sde_core_perf_calc_crtc(kms, crtc, state, &sde_cstate->new_perf); |
Alan Kwong | a193968 | 2017-05-05 11:30:08 -0700 | [diff] [blame] | 224 | |
Alan Kwong | 0230a10 | 2017-05-16 11:36:44 -0700 | [diff] [blame] | 225 | for (i = SDE_POWER_HANDLE_DBUS_ID_MNOC; |
| 226 | i < SDE_POWER_HANDLE_DBUS_ID_MAX; i++) { |
| 227 | bw_sum_of_intfs = sde_cstate->new_perf.bw_ctl[i]; |
| 228 | curr_client_type = sde_crtc_get_client_type(crtc); |
Alan Kwong | 9aa061c | 2016-11-06 21:17:12 -0500 | [diff] [blame] | 229 | |
Alan Kwong | 0230a10 | 2017-05-16 11:36:44 -0700 | [diff] [blame] | 230 | drm_for_each_crtc(tmp_crtc, crtc->dev) { |
| 231 | if (_sde_core_perf_crtc_is_power_on(tmp_crtc) && |
| 232 | (sde_crtc_get_client_type(tmp_crtc) == |
| 233 | curr_client_type) && |
| 234 | (tmp_crtc != crtc)) { |
| 235 | struct sde_crtc_state *tmp_cstate = |
Alan Kwong | 9aa061c | 2016-11-06 21:17:12 -0500 | [diff] [blame] | 236 | to_sde_crtc_state(tmp_crtc->state); |
| 237 | |
Ingrid Gallardo | 8d326b9 | 2017-06-29 18:05:53 -0700 | [diff] [blame] | 238 | SDE_DEBUG("crtc:%d bw:%llu ctrl:%d\n", |
| 239 | tmp_crtc->base.id, |
| 240 | tmp_cstate->new_perf.bw_ctl[i], |
| 241 | tmp_cstate->bw_control); |
| 242 | /* |
| 243 | * For bw check only use the bw if the |
| 244 | * atomic property has been already set |
| 245 | */ |
| 246 | if (tmp_cstate->bw_control) |
| 247 | bw_sum_of_intfs += |
| 248 | tmp_cstate->new_perf.bw_ctl[i]; |
Alan Kwong | 0230a10 | 2017-05-16 11:36:44 -0700 | [diff] [blame] | 249 | } |
Alan Kwong | 9aa061c | 2016-11-06 21:17:12 -0500 | [diff] [blame] | 250 | } |
Alan Kwong | 9aa061c | 2016-11-06 21:17:12 -0500 | [diff] [blame] | 251 | |
Alan Kwong | 0230a10 | 2017-05-16 11:36:44 -0700 | [diff] [blame] | 252 | /* convert bandwidth to kb */ |
| 253 | bw = DIV_ROUND_UP_ULL(bw_sum_of_intfs, 1000); |
| 254 | SDE_DEBUG("calculated bandwidth=%uk\n", bw); |
Alan Kwong | 9aa061c | 2016-11-06 21:17:12 -0500 | [diff] [blame] | 255 | |
Alan Kwong | 0230a10 | 2017-05-16 11:36:44 -0700 | [diff] [blame] | 256 | is_video_mode = sde_crtc_get_intf_mode(crtc) == INTF_MODE_VIDEO; |
| 257 | threshold = (is_video_mode || |
| 258 | _sde_core_video_mode_intf_connected(crtc)) ? |
| 259 | kms->catalog->perf.max_bw_low : |
| 260 | kms->catalog->perf.max_bw_high; |
Alan Kwong | 9aa061c | 2016-11-06 21:17:12 -0500 | [diff] [blame] | 261 | |
Alan Kwong | 0230a10 | 2017-05-16 11:36:44 -0700 | [diff] [blame] | 262 | SDE_DEBUG("final threshold bw limit = %d\n", threshold); |
Alan Kwong | 9aa061c | 2016-11-06 21:17:12 -0500 | [diff] [blame] | 263 | |
Alan Kwong | 0230a10 | 2017-05-16 11:36:44 -0700 | [diff] [blame] | 264 | if (!sde_cstate->bw_control) { |
| 265 | SDE_DEBUG("bypass bandwidth check\n"); |
| 266 | } else if (!threshold) { |
| 267 | SDE_ERROR("no bandwidth limits specified\n"); |
| 268 | return -E2BIG; |
| 269 | } else if (bw > threshold) { |
| 270 | SDE_ERROR("exceeds bandwidth: %ukb > %ukb\n", bw, |
| 271 | threshold); |
| 272 | return -E2BIG; |
| 273 | } |
Alan Kwong | 9aa061c | 2016-11-06 21:17:12 -0500 | [diff] [blame] | 274 | } |
| 275 | |
| 276 | return 0; |
| 277 | } |
| 278 | |
Dhaval Patel | dd2032a | 2017-04-11 10:50:36 -0700 | [diff] [blame] | 279 | static inline bool _is_crtc_client_type_matches(struct drm_crtc *tmp_crtc, |
| 280 | enum sde_crtc_client_type curr_client_type, |
| 281 | struct sde_core_perf *perf) |
| 282 | { |
| 283 | if (!tmp_crtc) |
| 284 | return false; |
| 285 | else if (perf->bw_vote_mode == DISP_RSC_PRIMARY_MODE && |
| 286 | perf->sde_rsc_available) |
| 287 | return curr_client_type == sde_crtc_get_client_type(tmp_crtc); |
| 288 | else |
| 289 | return true; |
| 290 | } |
| 291 | |
| 292 | static inline enum sde_crtc_client_type _get_sde_client_type( |
| 293 | enum sde_crtc_client_type curr_client_type, |
| 294 | struct sde_core_perf *perf) |
| 295 | { |
| 296 | if (perf->bw_vote_mode == DISP_RSC_PRIMARY_MODE && |
| 297 | perf->sde_rsc_available) |
| 298 | return curr_client_type; |
| 299 | else if (perf->bw_vote_mode != APPS_RSC_MODE && perf->sde_rsc_available) |
| 300 | return RT_RSC_CLIENT; |
| 301 | else |
| 302 | return RT_CLIENT; |
| 303 | } |
| 304 | |
Dhaval Patel | 4d42460 | 2017-02-18 19:40:14 -0800 | [diff] [blame] | 305 | static void _sde_core_perf_crtc_update_bus(struct sde_kms *kms, |
Ingrid Gallardo | 27d4512 | 2017-10-05 11:53:11 -0700 | [diff] [blame] | 306 | struct drm_crtc *crtc, u32 bus_id, |
| 307 | struct sde_core_perf_params *crtc_perf) |
Alan Kwong | 9aa061c | 2016-11-06 21:17:12 -0500 | [diff] [blame] | 308 | { |
Dhaval Patel | 4d42460 | 2017-02-18 19:40:14 -0800 | [diff] [blame] | 309 | u64 bw_sum_of_intfs = 0, bus_ab_quota, bus_ib_quota; |
Alan Kwong | 0230a10 | 2017-05-16 11:36:44 -0700 | [diff] [blame] | 310 | struct sde_core_perf_params perf = { { 0 } }; |
Dhaval Patel | dd2032a | 2017-04-11 10:50:36 -0700 | [diff] [blame] | 311 | enum sde_crtc_client_type client_vote, curr_client_type |
Dhaval Patel | 4d42460 | 2017-02-18 19:40:14 -0800 | [diff] [blame] | 312 | = sde_crtc_get_client_type(crtc); |
Alan Kwong | 9aa061c | 2016-11-06 21:17:12 -0500 | [diff] [blame] | 313 | struct drm_crtc *tmp_crtc; |
Dhaval Patel | 4d42460 | 2017-02-18 19:40:14 -0800 | [diff] [blame] | 314 | struct sde_crtc_state *sde_cstate; |
| 315 | struct msm_drm_private *priv = kms->dev->dev_private; |
Alan Kwong | 9aa061c | 2016-11-06 21:17:12 -0500 | [diff] [blame] | 316 | |
Ingrid Gallardo | 27d4512 | 2017-10-05 11:53:11 -0700 | [diff] [blame] | 317 | u64 tmp_max_per_pipe_ib; |
| 318 | u64 tmp_bw_ctl; |
| 319 | |
Alan Kwong | 9aa061c | 2016-11-06 21:17:12 -0500 | [diff] [blame] | 320 | drm_for_each_crtc(tmp_crtc, crtc->dev) { |
Dhaval Patel | 4d42460 | 2017-02-18 19:40:14 -0800 | [diff] [blame] | 321 | if (_sde_core_perf_crtc_is_power_on(tmp_crtc) && |
Dhaval Patel | dd2032a | 2017-04-11 10:50:36 -0700 | [diff] [blame] | 322 | _is_crtc_client_type_matches(tmp_crtc, curr_client_type, |
| 323 | &kms->perf)) { |
Ingrid Gallardo | 27d4512 | 2017-10-05 11:53:11 -0700 | [diff] [blame] | 324 | |
| 325 | if (crtc->base.id == tmp_crtc->base.id) { |
| 326 | /* for current crtc use the cached values */ |
| 327 | tmp_max_per_pipe_ib = |
| 328 | crtc_perf->max_per_pipe_ib[bus_id]; |
| 329 | tmp_bw_ctl = crtc_perf->bw_ctl[bus_id]; |
| 330 | } else { |
| 331 | sde_cstate = to_sde_crtc_state(tmp_crtc->state); |
| 332 | tmp_max_per_pipe_ib = |
| 333 | sde_cstate->new_perf.max_per_pipe_ib[bus_id]; |
| 334 | tmp_bw_ctl = |
| 335 | sde_cstate->new_perf.bw_ctl[bus_id]; |
| 336 | } |
Alan Kwong | 9aa061c | 2016-11-06 21:17:12 -0500 | [diff] [blame] | 337 | |
Alan Kwong | 0230a10 | 2017-05-16 11:36:44 -0700 | [diff] [blame] | 338 | perf.max_per_pipe_ib[bus_id] = |
| 339 | max(perf.max_per_pipe_ib[bus_id], |
Ingrid Gallardo | 27d4512 | 2017-10-05 11:53:11 -0700 | [diff] [blame] | 340 | tmp_max_per_pipe_ib); |
Alan Kwong | 9aa061c | 2016-11-06 21:17:12 -0500 | [diff] [blame] | 341 | |
Ingrid Gallardo | 27d4512 | 2017-10-05 11:53:11 -0700 | [diff] [blame] | 342 | bw_sum_of_intfs += tmp_bw_ctl; |
Alan Kwong | 9aa061c | 2016-11-06 21:17:12 -0500 | [diff] [blame] | 343 | |
Ingrid Gallardo | 27d4512 | 2017-10-05 11:53:11 -0700 | [diff] [blame] | 344 | SDE_DEBUG("crtc=%d bus_id=%d bw=%llu perf_pipe:%llu\n", |
Alan Kwong | 0230a10 | 2017-05-16 11:36:44 -0700 | [diff] [blame] | 345 | tmp_crtc->base.id, bus_id, |
Ingrid Gallardo | 27d4512 | 2017-10-05 11:53:11 -0700 | [diff] [blame] | 346 | tmp_bw_ctl, tmp_max_per_pipe_ib); |
Alan Kwong | 9aa061c | 2016-11-06 21:17:12 -0500 | [diff] [blame] | 347 | } |
| 348 | } |
| 349 | |
Dhaval Patel | 4d42460 | 2017-02-18 19:40:14 -0800 | [diff] [blame] | 350 | bus_ab_quota = max(bw_sum_of_intfs, kms->perf.perf_tune.min_bus_vote); |
Alan Kwong | 0230a10 | 2017-05-16 11:36:44 -0700 | [diff] [blame] | 351 | bus_ib_quota = perf.max_per_pipe_ib[bus_id]; |
Alan Kwong | 9aa061c | 2016-11-06 21:17:12 -0500 | [diff] [blame] | 352 | |
Alan Kwong | 97abd43 | 2017-05-11 14:52:23 -0700 | [diff] [blame] | 353 | if (kms->perf.perf_tune.mode == SDE_PERF_MODE_FIXED) { |
| 354 | bus_ab_quota = kms->perf.fix_core_ab_vote; |
| 355 | bus_ib_quota = kms->perf.fix_core_ib_vote; |
| 356 | } |
| 357 | |
Dhaval Patel | dd2032a | 2017-04-11 10:50:36 -0700 | [diff] [blame] | 358 | client_vote = _get_sde_client_type(curr_client_type, &kms->perf); |
| 359 | switch (client_vote) { |
Dhaval Patel | 4d42460 | 2017-02-18 19:40:14 -0800 | [diff] [blame] | 360 | case NRT_CLIENT: |
| 361 | sde_power_data_bus_set_quota(&priv->phandle, kms->core_client, |
| 362 | SDE_POWER_HANDLE_DATA_BUS_CLIENT_NRT, |
Alan Kwong | 0230a10 | 2017-05-16 11:36:44 -0700 | [diff] [blame] | 363 | bus_id, bus_ab_quota, bus_ib_quota); |
| 364 | SDE_DEBUG("client:%s bus_id=%d ab=%llu ib=%llu\n", "nrt", |
| 365 | bus_id, bus_ab_quota, bus_ib_quota); |
Dhaval Patel | 4d42460 | 2017-02-18 19:40:14 -0800 | [diff] [blame] | 366 | break; |
Alan Kwong | 9aa061c | 2016-11-06 21:17:12 -0500 | [diff] [blame] | 367 | |
Dhaval Patel | 4d42460 | 2017-02-18 19:40:14 -0800 | [diff] [blame] | 368 | case RT_CLIENT: |
| 369 | sde_power_data_bus_set_quota(&priv->phandle, kms->core_client, |
Alan Kwong | 9aa061c | 2016-11-06 21:17:12 -0500 | [diff] [blame] | 370 | SDE_POWER_HANDLE_DATA_BUS_CLIENT_RT, |
Alan Kwong | 0230a10 | 2017-05-16 11:36:44 -0700 | [diff] [blame] | 371 | bus_id, bus_ab_quota, bus_ib_quota); |
| 372 | SDE_DEBUG("client:%s bus_id=%d ab=%llu ib=%llu\n", "rt", |
| 373 | bus_id, bus_ab_quota, bus_ib_quota); |
Dhaval Patel | 4d42460 | 2017-02-18 19:40:14 -0800 | [diff] [blame] | 374 | break; |
Alan Kwong | 9aa061c | 2016-11-06 21:17:12 -0500 | [diff] [blame] | 375 | |
Dhaval Patel | 4d42460 | 2017-02-18 19:40:14 -0800 | [diff] [blame] | 376 | case RT_RSC_CLIENT: |
| 377 | sde_cstate = to_sde_crtc_state(crtc->state); |
Alan Kwong | 0230a10 | 2017-05-16 11:36:44 -0700 | [diff] [blame] | 378 | sde_rsc_client_vote(sde_cstate->rsc_client, |
| 379 | bus_id, bus_ab_quota, bus_ib_quota); |
| 380 | SDE_DEBUG("client:%s bus_id=%d ab=%llu ib=%llu\n", "rt_rsc", |
| 381 | bus_id, bus_ab_quota, bus_ib_quota); |
Dhaval Patel | 4d42460 | 2017-02-18 19:40:14 -0800 | [diff] [blame] | 382 | break; |
Alan Kwong | 9aa061c | 2016-11-06 21:17:12 -0500 | [diff] [blame] | 383 | |
Dhaval Patel | 4d42460 | 2017-02-18 19:40:14 -0800 | [diff] [blame] | 384 | default: |
| 385 | SDE_ERROR("invalid client type:%d\n", curr_client_type); |
| 386 | break; |
Alan Kwong | 9aa061c | 2016-11-06 21:17:12 -0500 | [diff] [blame] | 387 | } |
Dhaval Patel | dd2032a | 2017-04-11 10:50:36 -0700 | [diff] [blame] | 388 | |
| 389 | if (kms->perf.bw_vote_mode_updated) { |
| 390 | switch (kms->perf.bw_vote_mode) { |
| 391 | case DISP_RSC_MODE: |
| 392 | sde_power_data_bus_set_quota(&priv->phandle, |
| 393 | kms->core_client, |
Alan Kwong | 0230a10 | 2017-05-16 11:36:44 -0700 | [diff] [blame] | 394 | SDE_POWER_HANDLE_DATA_BUS_CLIENT_NRT, |
| 395 | bus_id, 0, 0); |
Dhaval Patel | dd2032a | 2017-04-11 10:50:36 -0700 | [diff] [blame] | 396 | sde_power_data_bus_set_quota(&priv->phandle, |
| 397 | kms->core_client, |
Alan Kwong | 0230a10 | 2017-05-16 11:36:44 -0700 | [diff] [blame] | 398 | SDE_POWER_HANDLE_DATA_BUS_CLIENT_RT, |
| 399 | bus_id, 0, 0); |
Dhaval Patel | dd2032a | 2017-04-11 10:50:36 -0700 | [diff] [blame] | 400 | kms->perf.bw_vote_mode_updated = false; |
| 401 | break; |
| 402 | |
| 403 | case APPS_RSC_MODE: |
| 404 | sde_cstate = to_sde_crtc_state(crtc->state); |
| 405 | if (sde_cstate->rsc_client) { |
| 406 | sde_rsc_client_vote(sde_cstate->rsc_client, |
Alan Kwong | 0230a10 | 2017-05-16 11:36:44 -0700 | [diff] [blame] | 407 | bus_id, 0, 0); |
Dhaval Patel | dd2032a | 2017-04-11 10:50:36 -0700 | [diff] [blame] | 408 | kms->perf.bw_vote_mode_updated = false; |
| 409 | } |
| 410 | break; |
| 411 | |
| 412 | default: |
| 413 | break; |
| 414 | } |
| 415 | } |
Alan Kwong | 9aa061c | 2016-11-06 21:17:12 -0500 | [diff] [blame] | 416 | } |
| 417 | |
| 418 | /** |
| 419 | * @sde_core_perf_crtc_release_bw() - request zero bandwidth |
| 420 | * @crtc - pointer to a crtc |
| 421 | * |
| 422 | * Function checks a state variable for the crtc, if all pending commit |
| 423 | * requests are done, meaning no more bandwidth is needed, release |
| 424 | * bandwidth request. |
| 425 | */ |
| 426 | void sde_core_perf_crtc_release_bw(struct drm_crtc *crtc) |
| 427 | { |
| 428 | struct drm_crtc *tmp_crtc; |
Alan Kwong | 751cf46 | 2017-06-08 10:26:46 -0400 | [diff] [blame] | 429 | struct sde_crtc *sde_crtc; |
Alan Kwong | 9aa061c | 2016-11-06 21:17:12 -0500 | [diff] [blame] | 430 | struct sde_crtc_state *sde_cstate; |
| 431 | struct sde_kms *kms; |
Alan Kwong | 0230a10 | 2017-05-16 11:36:44 -0700 | [diff] [blame] | 432 | int i; |
Alan Kwong | 9aa061c | 2016-11-06 21:17:12 -0500 | [diff] [blame] | 433 | |
| 434 | if (!crtc) { |
| 435 | SDE_ERROR("invalid crtc\n"); |
| 436 | return; |
| 437 | } |
| 438 | |
| 439 | kms = _sde_crtc_get_kms(crtc); |
| 440 | if (!kms || !kms->catalog) { |
| 441 | SDE_ERROR("invalid kms\n"); |
| 442 | return; |
| 443 | } |
| 444 | |
Alan Kwong | 751cf46 | 2017-06-08 10:26:46 -0400 | [diff] [blame] | 445 | sde_crtc = to_sde_crtc(crtc); |
Alan Kwong | 9aa061c | 2016-11-06 21:17:12 -0500 | [diff] [blame] | 446 | sde_cstate = to_sde_crtc_state(crtc->state); |
| 447 | |
Dhaval Patel | 4d42460 | 2017-02-18 19:40:14 -0800 | [diff] [blame] | 448 | /* only do this for command mode rt client (non-rsc client) */ |
Alan Kwong | 9aa061c | 2016-11-06 21:17:12 -0500 | [diff] [blame] | 449 | if ((sde_crtc_get_intf_mode(crtc) != INTF_MODE_CMD) && |
Dhaval Patel | 4d42460 | 2017-02-18 19:40:14 -0800 | [diff] [blame] | 450 | (sde_crtc_get_client_type(crtc) != RT_RSC_CLIENT)) |
Alan Kwong | 9aa061c | 2016-11-06 21:17:12 -0500 | [diff] [blame] | 451 | return; |
| 452 | |
| 453 | /* |
| 454 | * If video interface present, cmd panel bandwidth cannot be |
| 455 | * released. |
| 456 | */ |
| 457 | if (sde_crtc_get_intf_mode(crtc) == INTF_MODE_CMD) |
| 458 | drm_for_each_crtc(tmp_crtc, crtc->dev) { |
| 459 | if (_sde_core_perf_crtc_is_power_on(tmp_crtc) && |
| 460 | sde_crtc_get_intf_mode(tmp_crtc) == |
| 461 | INTF_MODE_VIDEO) |
| 462 | return; |
| 463 | } |
| 464 | |
| 465 | /* Release the bandwidth */ |
| 466 | if (kms->perf.enable_bw_release) { |
| 467 | trace_sde_cmd_release_bw(crtc->base.id); |
Alan Kwong | 9aa061c | 2016-11-06 21:17:12 -0500 | [diff] [blame] | 468 | SDE_DEBUG("Release BW crtc=%d\n", crtc->base.id); |
Alan Kwong | 0230a10 | 2017-05-16 11:36:44 -0700 | [diff] [blame] | 469 | for (i = 0; i < SDE_POWER_HANDLE_DBUS_ID_MAX; i++) { |
| 470 | sde_crtc->cur_perf.bw_ctl[i] = 0; |
Ingrid Gallardo | 27d4512 | 2017-10-05 11:53:11 -0700 | [diff] [blame] | 471 | _sde_core_perf_crtc_update_bus(kms, crtc, i, |
| 472 | &sde_crtc->cur_perf); |
Alan Kwong | 0230a10 | 2017-05-16 11:36:44 -0700 | [diff] [blame] | 473 | } |
Alan Kwong | 9aa061c | 2016-11-06 21:17:12 -0500 | [diff] [blame] | 474 | } |
| 475 | } |
| 476 | |
Ingrid Gallardo | 27d4512 | 2017-10-05 11:53:11 -0700 | [diff] [blame] | 477 | static u64 _sde_core_perf_get_core_clk_rate(struct sde_kms *kms, |
| 478 | struct sde_core_perf_params *crct_perf, struct drm_crtc *crtc) |
Alan Kwong | 9aa061c | 2016-11-06 21:17:12 -0500 | [diff] [blame] | 479 | { |
Alan Kwong | 97abd43 | 2017-05-11 14:52:23 -0700 | [diff] [blame] | 480 | u64 clk_rate = kms->perf.perf_tune.min_core_clk; |
Ingrid Gallardo | 27d4512 | 2017-10-05 11:53:11 -0700 | [diff] [blame] | 481 | struct drm_crtc *tmp_crtc; |
Alan Kwong | 9aa061c | 2016-11-06 21:17:12 -0500 | [diff] [blame] | 482 | struct sde_crtc_state *sde_cstate; |
Ingrid Gallardo | 27d4512 | 2017-10-05 11:53:11 -0700 | [diff] [blame] | 483 | u64 tmp_rate; |
Alan Kwong | 9aa061c | 2016-11-06 21:17:12 -0500 | [diff] [blame] | 484 | |
Ingrid Gallardo | 27d4512 | 2017-10-05 11:53:11 -0700 | [diff] [blame] | 485 | drm_for_each_crtc(tmp_crtc, kms->dev) { |
| 486 | if (_sde_core_perf_crtc_is_power_on(tmp_crtc)) { |
| 487 | |
| 488 | if (crtc->base.id == tmp_crtc->base.id) { |
| 489 | /* for current CRTC, use the cached value */ |
| 490 | tmp_rate = crct_perf->core_clk_rate; |
| 491 | } else { |
| 492 | sde_cstate = to_sde_crtc_state(tmp_crtc->state); |
| 493 | tmp_rate = sde_cstate->new_perf.core_clk_rate; |
| 494 | } |
| 495 | clk_rate = max(tmp_rate, clk_rate); |
| 496 | |
Alan Kwong | 9aa061c | 2016-11-06 21:17:12 -0500 | [diff] [blame] | 497 | clk_rate = clk_round_rate(kms->perf.core_clk, clk_rate); |
| 498 | } |
Alan Kwong | 9aa061c | 2016-11-06 21:17:12 -0500 | [diff] [blame] | 499 | } |
Alan Kwong | 9aa061c | 2016-11-06 21:17:12 -0500 | [diff] [blame] | 500 | |
Alan Kwong | 97abd43 | 2017-05-11 14:52:23 -0700 | [diff] [blame] | 501 | if (kms->perf.perf_tune.mode == SDE_PERF_MODE_FIXED) |
| 502 | clk_rate = kms->perf.fix_core_clk_rate; |
| 503 | |
| 504 | SDE_DEBUG("clk:%llu\n", clk_rate); |
Alan Kwong | 9aa061c | 2016-11-06 21:17:12 -0500 | [diff] [blame] | 505 | |
| 506 | return clk_rate; |
| 507 | } |
| 508 | |
| 509 | void sde_core_perf_crtc_update(struct drm_crtc *crtc, |
| 510 | int params_changed, bool stop_req) |
| 511 | { |
| 512 | struct sde_core_perf_params *new, *old; |
| 513 | int update_bus = 0, update_clk = 0; |
Alan Kwong | 97abd43 | 2017-05-11 14:52:23 -0700 | [diff] [blame] | 514 | u64 clk_rate = 0; |
Alan Kwong | 9aa061c | 2016-11-06 21:17:12 -0500 | [diff] [blame] | 515 | struct sde_crtc *sde_crtc; |
| 516 | struct sde_crtc_state *sde_cstate; |
Alan Kwong | 0230a10 | 2017-05-16 11:36:44 -0700 | [diff] [blame] | 517 | int ret, i; |
Alan Kwong | 9aa061c | 2016-11-06 21:17:12 -0500 | [diff] [blame] | 518 | struct msm_drm_private *priv; |
| 519 | struct sde_kms *kms; |
| 520 | |
| 521 | if (!crtc) { |
| 522 | SDE_ERROR("invalid crtc\n"); |
| 523 | return; |
| 524 | } |
| 525 | |
| 526 | kms = _sde_crtc_get_kms(crtc); |
| 527 | if (!kms || !kms->catalog) { |
| 528 | SDE_ERROR("invalid kms\n"); |
| 529 | return; |
| 530 | } |
| 531 | priv = kms->dev->dev_private; |
| 532 | |
Dhaval Patel | 378a9b4 | 2017-05-23 13:11:24 -0700 | [diff] [blame] | 533 | /* wake vote update is not required with display rsc */ |
| 534 | if (kms->perf.bw_vote_mode == DISP_RSC_MODE && stop_req) |
| 535 | return; |
| 536 | |
Alan Kwong | 9aa061c | 2016-11-06 21:17:12 -0500 | [diff] [blame] | 537 | sde_crtc = to_sde_crtc(crtc); |
| 538 | sde_cstate = to_sde_crtc_state(crtc->state); |
| 539 | |
Alan Kwong | 97abd43 | 2017-05-11 14:52:23 -0700 | [diff] [blame] | 540 | SDE_DEBUG("crtc:%d stop_req:%d core_clk:%llu\n", |
Alan Kwong | 9aa061c | 2016-11-06 21:17:12 -0500 | [diff] [blame] | 541 | crtc->base.id, stop_req, kms->perf.core_clk_rate); |
| 542 | |
Ingrid Gallardo | 27d4512 | 2017-10-05 11:53:11 -0700 | [diff] [blame] | 543 | /* |
| 544 | * cache the performance numbers in the crtc prior to the |
| 545 | * crtc kickoff, so the same numbers are used during the |
| 546 | * perf update that happens post kickoff. |
| 547 | */ |
| 548 | if (params_changed) |
| 549 | memcpy(&sde_crtc->new_perf, &sde_cstate->new_perf, |
| 550 | sizeof(struct sde_core_perf_params)); |
| 551 | |
Alan Kwong | 751cf46 | 2017-06-08 10:26:46 -0400 | [diff] [blame] | 552 | old = &sde_crtc->cur_perf; |
Ingrid Gallardo | 27d4512 | 2017-10-05 11:53:11 -0700 | [diff] [blame] | 553 | new = &sde_crtc->new_perf; |
Alan Kwong | 9aa061c | 2016-11-06 21:17:12 -0500 | [diff] [blame] | 554 | |
| 555 | if (_sde_core_perf_crtc_is_power_on(crtc) && !stop_req) { |
Alan Kwong | 0230a10 | 2017-05-16 11:36:44 -0700 | [diff] [blame] | 556 | for (i = 0; i < SDE_POWER_HANDLE_DBUS_ID_MAX; i++) { |
| 557 | /* |
| 558 | * cases for bus bandwidth update. |
| 559 | * 1. new bandwidth vote - "ab or ib vote" is higher |
| 560 | * than current vote for update request. |
| 561 | * 2. new bandwidth vote - "ab or ib vote" is lower |
| 562 | * than current vote at end of commit or stop. |
| 563 | */ |
Ingrid Gallardo | 17bac47 | 2017-12-01 17:42:11 -0800 | [diff] [blame] | 564 | |
| 565 | if ((params_changed && |
| 566 | (new->bw_ctl[i] > old->bw_ctl[i])) || |
| 567 | (!params_changed && |
| 568 | (new->bw_ctl[i] < old->bw_ctl[i]))) { |
| 569 | |
Alan Kwong | 0230a10 | 2017-05-16 11:36:44 -0700 | [diff] [blame] | 570 | SDE_DEBUG( |
| 571 | "crtc=%d p=%d new_bw=%llu,old_bw=%llu\n", |
| 572 | crtc->base.id, params_changed, |
| 573 | new->bw_ctl[i], old->bw_ctl[i]); |
| 574 | old->bw_ctl[i] = new->bw_ctl[i]; |
Ingrid Gallardo | 17bac47 | 2017-12-01 17:42:11 -0800 | [diff] [blame] | 575 | update_bus |= BIT(i); |
| 576 | } |
| 577 | |
| 578 | if ((params_changed && |
| 579 | (new->max_per_pipe_ib[i] > |
| 580 | old->max_per_pipe_ib[i])) || |
| 581 | (!params_changed && |
| 582 | (new->max_per_pipe_ib[i] < |
| 583 | old->max_per_pipe_ib[i]))) { |
| 584 | |
| 585 | SDE_DEBUG( |
| 586 | "crtc=%d p=%d new_ib=%llu,old_ib=%llu\n", |
| 587 | crtc->base.id, params_changed, |
| 588 | new->max_per_pipe_ib[i], |
| 589 | old->max_per_pipe_ib[i]); |
Alan Kwong | 0230a10 | 2017-05-16 11:36:44 -0700 | [diff] [blame] | 590 | old->max_per_pipe_ib[i] = |
| 591 | new->max_per_pipe_ib[i]; |
| 592 | update_bus |= BIT(i); |
| 593 | } |
Alan Kwong | 9aa061c | 2016-11-06 21:17:12 -0500 | [diff] [blame] | 594 | |
Alan Kwong | 0230a10 | 2017-05-16 11:36:44 -0700 | [diff] [blame] | 595 | /* display rsc override during solver mode */ |
| 596 | if (kms->perf.bw_vote_mode == DISP_RSC_MODE && |
Dhaval Patel | 378a9b4 | 2017-05-23 13:11:24 -0700 | [diff] [blame] | 597 | get_sde_rsc_current_state(SDE_RSC_INDEX) == |
Alan Kwong | 0230a10 | 2017-05-16 11:36:44 -0700 | [diff] [blame] | 598 | SDE_RSC_CMD_STATE) { |
| 599 | /* update new bandwidth in all cases */ |
| 600 | if (params_changed && ((new->bw_ctl[i] != |
| 601 | old->bw_ctl[i]) || |
| 602 | (new->max_per_pipe_ib[i] != |
| 603 | old->max_per_pipe_ib[i]))) { |
| 604 | old->bw_ctl[i] = new->bw_ctl[i]; |
| 605 | old->max_per_pipe_ib[i] = |
| 606 | new->max_per_pipe_ib[i]; |
| 607 | update_bus |= BIT(i); |
| 608 | /* |
| 609 | * reduce bw vote is not required in solver |
| 610 | * mode |
| 611 | */ |
| 612 | } else if (!params_changed) { |
| 613 | update_bus &= ~BIT(i); |
| 614 | } |
Dhaval Patel | 378a9b4 | 2017-05-23 13:11:24 -0700 | [diff] [blame] | 615 | } |
| 616 | } |
| 617 | |
Alan Kwong | 9aa061c | 2016-11-06 21:17:12 -0500 | [diff] [blame] | 618 | if ((params_changed && |
| 619 | (new->core_clk_rate > old->core_clk_rate)) || |
| 620 | (!params_changed && |
| 621 | (new->core_clk_rate < old->core_clk_rate))) { |
| 622 | old->core_clk_rate = new->core_clk_rate; |
| 623 | update_clk = 1; |
| 624 | } |
| 625 | } else { |
| 626 | SDE_DEBUG("crtc=%d disable\n", crtc->base.id); |
| 627 | memset(old, 0, sizeof(*old)); |
| 628 | memset(new, 0, sizeof(*new)); |
Alan Kwong | 0230a10 | 2017-05-16 11:36:44 -0700 | [diff] [blame] | 629 | update_bus = ~0; |
Alan Kwong | 9aa061c | 2016-11-06 21:17:12 -0500 | [diff] [blame] | 630 | update_clk = 1; |
| 631 | } |
Alan Kwong | 0230a10 | 2017-05-16 11:36:44 -0700 | [diff] [blame] | 632 | trace_sde_perf_crtc_update(crtc->base.id, |
Ingrid Gallardo | ac3d09b | 2017-12-01 17:42:50 -0800 | [diff] [blame] | 633 | new->bw_ctl[SDE_POWER_HANDLE_DBUS_ID_MNOC], |
| 634 | new->max_per_pipe_ib[SDE_POWER_HANDLE_DBUS_ID_MNOC], |
| 635 | new->bw_ctl[SDE_POWER_HANDLE_DBUS_ID_LLCC], |
| 636 | new->max_per_pipe_ib[SDE_POWER_HANDLE_DBUS_ID_LLCC], |
| 637 | new->bw_ctl[SDE_POWER_HANDLE_DBUS_ID_EBI], |
| 638 | new->max_per_pipe_ib[SDE_POWER_HANDLE_DBUS_ID_EBI], |
| 639 | new->core_clk_rate, stop_req, |
| 640 | update_bus, update_clk, params_changed); |
Alan Kwong | 9aa061c | 2016-11-06 21:17:12 -0500 | [diff] [blame] | 641 | |
Alan Kwong | 0230a10 | 2017-05-16 11:36:44 -0700 | [diff] [blame] | 642 | for (i = 0; i < SDE_POWER_HANDLE_DBUS_ID_MAX; i++) { |
| 643 | if (update_bus & BIT(i)) |
Ingrid Gallardo | 27d4512 | 2017-10-05 11:53:11 -0700 | [diff] [blame] | 644 | _sde_core_perf_crtc_update_bus(kms, crtc, i, old); |
Alan Kwong | 0230a10 | 2017-05-16 11:36:44 -0700 | [diff] [blame] | 645 | } |
Alan Kwong | 9aa061c | 2016-11-06 21:17:12 -0500 | [diff] [blame] | 646 | |
| 647 | /* |
| 648 | * Update the clock after bandwidth vote to ensure |
| 649 | * bandwidth is available before clock rate is increased. |
| 650 | */ |
| 651 | if (update_clk) { |
Ingrid Gallardo | 27d4512 | 2017-10-05 11:53:11 -0700 | [diff] [blame] | 652 | clk_rate = _sde_core_perf_get_core_clk_rate(kms, old, crtc); |
Dhaval Patel | 4d42460 | 2017-02-18 19:40:14 -0800 | [diff] [blame] | 653 | |
Ingrid Gallardo | 27d4512 | 2017-10-05 11:53:11 -0700 | [diff] [blame] | 654 | SDE_EVT32(kms->dev, stop_req, clk_rate, params_changed, |
| 655 | old->core_clk_rate, new->core_clk_rate); |
Alan Kwong | 9aa061c | 2016-11-06 21:17:12 -0500 | [diff] [blame] | 656 | ret = sde_power_clk_set_rate(&priv->phandle, |
| 657 | kms->perf.clk_name, clk_rate); |
| 658 | if (ret) { |
Alan Kwong | 97abd43 | 2017-05-11 14:52:23 -0700 | [diff] [blame] | 659 | SDE_ERROR("failed to set %s clock rate %llu\n", |
Alan Kwong | 9aa061c | 2016-11-06 21:17:12 -0500 | [diff] [blame] | 660 | kms->perf.clk_name, clk_rate); |
Dhaval Patel | 4d42460 | 2017-02-18 19:40:14 -0800 | [diff] [blame] | 661 | return; |
Alan Kwong | 9aa061c | 2016-11-06 21:17:12 -0500 | [diff] [blame] | 662 | } |
| 663 | |
| 664 | kms->perf.core_clk_rate = clk_rate; |
Alan Kwong | 97abd43 | 2017-05-11 14:52:23 -0700 | [diff] [blame] | 665 | SDE_DEBUG("update clk rate = %lld HZ\n", clk_rate); |
Alan Kwong | 9aa061c | 2016-11-06 21:17:12 -0500 | [diff] [blame] | 666 | } |
Alan Kwong | 9aa061c | 2016-11-06 21:17:12 -0500 | [diff] [blame] | 667 | } |
| 668 | |
Alan Kwong | 67a3f79 | 2016-11-01 23:16:53 -0400 | [diff] [blame] | 669 | #ifdef CONFIG_DEBUG_FS |
| 670 | |
Alan Kwong | 9aa061c | 2016-11-06 21:17:12 -0500 | [diff] [blame] | 671 | static ssize_t _sde_core_perf_mode_write(struct file *file, |
| 672 | const char __user *user_buf, size_t count, loff_t *ppos) |
| 673 | { |
| 674 | struct sde_core_perf *perf = file->private_data; |
| 675 | struct sde_perf_cfg *cfg = &perf->catalog->perf; |
Alan Kwong | 97abd43 | 2017-05-11 14:52:23 -0700 | [diff] [blame] | 676 | u32 perf_mode = 0; |
Alan Kwong | 9aa061c | 2016-11-06 21:17:12 -0500 | [diff] [blame] | 677 | char buf[10]; |
| 678 | |
| 679 | if (!perf) |
| 680 | return -ENODEV; |
| 681 | |
| 682 | if (count >= sizeof(buf)) |
| 683 | return -EFAULT; |
| 684 | |
| 685 | if (copy_from_user(buf, user_buf, count)) |
| 686 | return -EFAULT; |
| 687 | |
| 688 | buf[count] = 0; /* end of string */ |
| 689 | |
Alan Kwong | 97abd43 | 2017-05-11 14:52:23 -0700 | [diff] [blame] | 690 | if (kstrtouint(buf, 0, &perf_mode)) |
Alan Kwong | 9aa061c | 2016-11-06 21:17:12 -0500 | [diff] [blame] | 691 | return -EFAULT; |
| 692 | |
Alan Kwong | 97abd43 | 2017-05-11 14:52:23 -0700 | [diff] [blame] | 693 | if (perf_mode >= SDE_PERF_MODE_MAX) |
| 694 | return -EFAULT; |
| 695 | |
| 696 | if (perf_mode == SDE_PERF_MODE_FIXED) { |
| 697 | DRM_INFO("fix performance mode\n"); |
| 698 | } else if (perf_mode == SDE_PERF_MODE_MINIMUM) { |
Alan Kwong | 9aa061c | 2016-11-06 21:17:12 -0500 | [diff] [blame] | 699 | /* run the driver with max clk and BW vote */ |
| 700 | perf->perf_tune.min_core_clk = perf->max_core_clk_rate; |
| 701 | perf->perf_tune.min_bus_vote = |
| 702 | (u64) cfg->max_bw_high * 1000; |
Alan Kwong | 97abd43 | 2017-05-11 14:52:23 -0700 | [diff] [blame] | 703 | DRM_INFO("minimum performance mode\n"); |
| 704 | } else if (perf_mode == SDE_PERF_MODE_NORMAL) { |
Alan Kwong | 9aa061c | 2016-11-06 21:17:12 -0500 | [diff] [blame] | 705 | /* reset the perf tune params to 0 */ |
| 706 | perf->perf_tune.min_core_clk = 0; |
| 707 | perf->perf_tune.min_bus_vote = 0; |
Alan Kwong | 97abd43 | 2017-05-11 14:52:23 -0700 | [diff] [blame] | 708 | DRM_INFO("normal performance mode\n"); |
Alan Kwong | 9aa061c | 2016-11-06 21:17:12 -0500 | [diff] [blame] | 709 | } |
Alan Kwong | 97abd43 | 2017-05-11 14:52:23 -0700 | [diff] [blame] | 710 | perf->perf_tune.mode = perf_mode; |
| 711 | |
Alan Kwong | 9aa061c | 2016-11-06 21:17:12 -0500 | [diff] [blame] | 712 | return count; |
| 713 | } |
| 714 | |
| 715 | static ssize_t _sde_core_perf_mode_read(struct file *file, |
| 716 | char __user *buff, size_t count, loff_t *ppos) |
| 717 | { |
| 718 | struct sde_core_perf *perf = file->private_data; |
| 719 | int len = 0; |
Alan Kwong | 97abd43 | 2017-05-11 14:52:23 -0700 | [diff] [blame] | 720 | char buf[SDE_PERF_MODE_STRING_SIZE] = {'\0'}; |
Alan Kwong | 9aa061c | 2016-11-06 21:17:12 -0500 | [diff] [blame] | 721 | |
| 722 | if (!perf) |
| 723 | return -ENODEV; |
| 724 | |
| 725 | if (*ppos) |
| 726 | return 0; /* the end */ |
| 727 | |
Alan Kwong | 97abd43 | 2017-05-11 14:52:23 -0700 | [diff] [blame] | 728 | len = snprintf(buf, sizeof(buf), |
| 729 | "mode %d min_mdp_clk %llu min_bus_vote %llu\n", |
| 730 | perf->perf_tune.mode, |
Alan Kwong | 9aa061c | 2016-11-06 21:17:12 -0500 | [diff] [blame] | 731 | perf->perf_tune.min_core_clk, |
| 732 | perf->perf_tune.min_bus_vote); |
| 733 | if (len < 0 || len >= sizeof(buf)) |
| 734 | return 0; |
| 735 | |
| 736 | if ((count < sizeof(buf)) || copy_to_user(buff, buf, len)) |
| 737 | return -EFAULT; |
| 738 | |
| 739 | *ppos += len; /* increase offset */ |
| 740 | |
| 741 | return len; |
| 742 | } |
| 743 | |
| 744 | static const struct file_operations sde_core_perf_mode_fops = { |
| 745 | .open = simple_open, |
| 746 | .read = _sde_core_perf_mode_read, |
| 747 | .write = _sde_core_perf_mode_write, |
| 748 | }; |
| 749 | |
Lloyd Atkinson | b020e0f | 2017-03-14 08:05:18 -0700 | [diff] [blame] | 750 | static void sde_core_perf_debugfs_destroy(struct sde_core_perf *perf) |
Alan Kwong | 67a3f79 | 2016-11-01 23:16:53 -0400 | [diff] [blame] | 751 | { |
| 752 | debugfs_remove_recursive(perf->debugfs_root); |
| 753 | perf->debugfs_root = NULL; |
| 754 | } |
| 755 | |
Lloyd Atkinson | b020e0f | 2017-03-14 08:05:18 -0700 | [diff] [blame] | 756 | int sde_core_perf_debugfs_init(struct sde_core_perf *perf, |
Alan Kwong | 67a3f79 | 2016-11-01 23:16:53 -0400 | [diff] [blame] | 757 | struct dentry *parent) |
| 758 | { |
Alan Kwong | 9aa061c | 2016-11-06 21:17:12 -0500 | [diff] [blame] | 759 | struct sde_mdss_cfg *catalog = perf->catalog; |
Alan Kwong | 67a3f79 | 2016-11-01 23:16:53 -0400 | [diff] [blame] | 760 | struct msm_drm_private *priv; |
| 761 | struct sde_kms *sde_kms; |
| 762 | |
| 763 | priv = perf->dev->dev_private; |
| 764 | if (!priv || !priv->kms) { |
| 765 | SDE_ERROR("invalid KMS reference\n"); |
| 766 | return -EINVAL; |
| 767 | } |
| 768 | |
| 769 | sde_kms = to_sde_kms(priv->kms); |
| 770 | |
| 771 | perf->debugfs_root = debugfs_create_dir("core_perf", parent); |
| 772 | if (!perf->debugfs_root) { |
| 773 | SDE_ERROR("failed to create core perf debugfs\n"); |
| 774 | return -EINVAL; |
| 775 | } |
| 776 | |
Lloyd Atkinson | 8de415a | 2017-05-23 11:31:16 -0400 | [diff] [blame] | 777 | debugfs_create_u64("max_core_clk_rate", 0600, perf->debugfs_root, |
Alan Kwong | 67a3f79 | 2016-11-01 23:16:53 -0400 | [diff] [blame] | 778 | &perf->max_core_clk_rate); |
Lloyd Atkinson | 8de415a | 2017-05-23 11:31:16 -0400 | [diff] [blame] | 779 | debugfs_create_u64("core_clk_rate", 0600, perf->debugfs_root, |
Alan Kwong | 67a3f79 | 2016-11-01 23:16:53 -0400 | [diff] [blame] | 780 | &perf->core_clk_rate); |
Lloyd Atkinson | 8de415a | 2017-05-23 11:31:16 -0400 | [diff] [blame] | 781 | debugfs_create_u32("enable_bw_release", 0600, perf->debugfs_root, |
Alan Kwong | 9aa061c | 2016-11-06 21:17:12 -0500 | [diff] [blame] | 782 | (u32 *)&perf->enable_bw_release); |
Lloyd Atkinson | 8de415a | 2017-05-23 11:31:16 -0400 | [diff] [blame] | 783 | debugfs_create_u32("threshold_low", 0600, perf->debugfs_root, |
Alan Kwong | 9aa061c | 2016-11-06 21:17:12 -0500 | [diff] [blame] | 784 | (u32 *)&catalog->perf.max_bw_low); |
Lloyd Atkinson | 8de415a | 2017-05-23 11:31:16 -0400 | [diff] [blame] | 785 | debugfs_create_u32("threshold_high", 0600, perf->debugfs_root, |
Alan Kwong | 9aa061c | 2016-11-06 21:17:12 -0500 | [diff] [blame] | 786 | (u32 *)&catalog->perf.max_bw_high); |
Narendra Muppalla | a50934b | 2017-08-15 19:43:37 -0700 | [diff] [blame] | 787 | debugfs_create_u32("min_core_ib", 0600, perf->debugfs_root, |
| 788 | (u32 *)&catalog->perf.min_core_ib); |
| 789 | debugfs_create_u32("min_llcc_ib", 0600, perf->debugfs_root, |
| 790 | (u32 *)&catalog->perf.min_llcc_ib); |
| 791 | debugfs_create_u32("min_dram_ib", 0600, perf->debugfs_root, |
| 792 | (u32 *)&catalog->perf.min_dram_ib); |
Lloyd Atkinson | 8de415a | 2017-05-23 11:31:16 -0400 | [diff] [blame] | 793 | debugfs_create_file("perf_mode", 0600, perf->debugfs_root, |
Alan Kwong | 9aa061c | 2016-11-06 21:17:12 -0500 | [diff] [blame] | 794 | (u32 *)perf, &sde_core_perf_mode_fops); |
Dhaval Patel | dd2032a | 2017-04-11 10:50:36 -0700 | [diff] [blame] | 795 | debugfs_create_u32("bw_vote_mode", 0600, perf->debugfs_root, |
| 796 | &perf->bw_vote_mode); |
| 797 | debugfs_create_bool("bw_vote_mode_updated", 0600, perf->debugfs_root, |
| 798 | &perf->bw_vote_mode_updated); |
Lloyd Atkinson | 8de415a | 2017-05-23 11:31:16 -0400 | [diff] [blame] | 799 | debugfs_create_u64("fix_core_clk_rate", 0600, perf->debugfs_root, |
Alan Kwong | 97abd43 | 2017-05-11 14:52:23 -0700 | [diff] [blame] | 800 | &perf->fix_core_clk_rate); |
Lloyd Atkinson | 8de415a | 2017-05-23 11:31:16 -0400 | [diff] [blame] | 801 | debugfs_create_u64("fix_core_ib_vote", 0600, perf->debugfs_root, |
Alan Kwong | 97abd43 | 2017-05-11 14:52:23 -0700 | [diff] [blame] | 802 | &perf->fix_core_ib_vote); |
Lloyd Atkinson | 8de415a | 2017-05-23 11:31:16 -0400 | [diff] [blame] | 803 | debugfs_create_u64("fix_core_ab_vote", 0600, perf->debugfs_root, |
Alan Kwong | 97abd43 | 2017-05-11 14:52:23 -0700 | [diff] [blame] | 804 | &perf->fix_core_ab_vote); |
Alan Kwong | 67a3f79 | 2016-11-01 23:16:53 -0400 | [diff] [blame] | 805 | |
| 806 | return 0; |
| 807 | } |
| 808 | #else |
Lloyd Atkinson | b020e0f | 2017-03-14 08:05:18 -0700 | [diff] [blame] | 809 | static void sde_core_perf_debugfs_destroy(struct sde_core_perf *perf) |
Alan Kwong | 67a3f79 | 2016-11-01 23:16:53 -0400 | [diff] [blame] | 810 | { |
| 811 | } |
| 812 | |
Lloyd Atkinson | b020e0f | 2017-03-14 08:05:18 -0700 | [diff] [blame] | 813 | int sde_core_perf_debugfs_init(struct sde_core_perf *perf, |
Alan Kwong | 67a3f79 | 2016-11-01 23:16:53 -0400 | [diff] [blame] | 814 | struct dentry *parent) |
| 815 | { |
| 816 | return 0; |
| 817 | } |
| 818 | #endif |
| 819 | |
| 820 | void sde_core_perf_destroy(struct sde_core_perf *perf) |
| 821 | { |
| 822 | if (!perf) { |
| 823 | SDE_ERROR("invalid parameters\n"); |
| 824 | return; |
| 825 | } |
| 826 | |
Lloyd Atkinson | b020e0f | 2017-03-14 08:05:18 -0700 | [diff] [blame] | 827 | sde_core_perf_debugfs_destroy(perf); |
Alan Kwong | 67a3f79 | 2016-11-01 23:16:53 -0400 | [diff] [blame] | 828 | perf->max_core_clk_rate = 0; |
| 829 | perf->core_clk = NULL; |
Alan Kwong | 67a3f79 | 2016-11-01 23:16:53 -0400 | [diff] [blame] | 830 | perf->clk_name = NULL; |
| 831 | perf->phandle = NULL; |
| 832 | perf->catalog = NULL; |
| 833 | perf->dev = NULL; |
| 834 | } |
| 835 | |
| 836 | int sde_core_perf_init(struct sde_core_perf *perf, |
| 837 | struct drm_device *dev, |
| 838 | struct sde_mdss_cfg *catalog, |
| 839 | struct sde_power_handle *phandle, |
| 840 | struct sde_power_client *pclient, |
Lloyd Atkinson | b020e0f | 2017-03-14 08:05:18 -0700 | [diff] [blame] | 841 | char *clk_name) |
Alan Kwong | 67a3f79 | 2016-11-01 23:16:53 -0400 | [diff] [blame] | 842 | { |
Lloyd Atkinson | b020e0f | 2017-03-14 08:05:18 -0700 | [diff] [blame] | 843 | if (!perf || !dev || !catalog || !phandle || !pclient || !clk_name) { |
Alan Kwong | 67a3f79 | 2016-11-01 23:16:53 -0400 | [diff] [blame] | 844 | SDE_ERROR("invalid parameters\n"); |
| 845 | return -EINVAL; |
| 846 | } |
| 847 | |
| 848 | perf->dev = dev; |
| 849 | perf->catalog = catalog; |
| 850 | perf->phandle = phandle; |
| 851 | perf->pclient = pclient; |
| 852 | perf->clk_name = clk_name; |
Dhaval Patel | dd2032a | 2017-04-11 10:50:36 -0700 | [diff] [blame] | 853 | perf->sde_rsc_available = is_sde_rsc_available(SDE_RSC_INDEX); |
| 854 | /* set default mode */ |
| 855 | if (perf->sde_rsc_available) |
| 856 | perf->bw_vote_mode = DISP_RSC_MODE; |
| 857 | else |
| 858 | perf->bw_vote_mode = APPS_RSC_MODE; |
Alan Kwong | 67a3f79 | 2016-11-01 23:16:53 -0400 | [diff] [blame] | 859 | |
| 860 | perf->core_clk = sde_power_clk_get_clk(phandle, clk_name); |
| 861 | if (!perf->core_clk) { |
| 862 | SDE_ERROR("invalid core clk\n"); |
| 863 | goto err; |
| 864 | } |
| 865 | |
| 866 | perf->max_core_clk_rate = sde_power_clk_get_max_rate(phandle, clk_name); |
| 867 | if (!perf->max_core_clk_rate) { |
Alan Kwong | 6259a38 | 2017-04-04 06:18:02 -0700 | [diff] [blame] | 868 | SDE_DEBUG("optional max core clk rate, use default\n"); |
| 869 | perf->max_core_clk_rate = SDE_PERF_DEFAULT_MAX_CORE_CLK_RATE; |
Alan Kwong | 67a3f79 | 2016-11-01 23:16:53 -0400 | [diff] [blame] | 870 | } |
| 871 | |
Alan Kwong | 67a3f79 | 2016-11-01 23:16:53 -0400 | [diff] [blame] | 872 | return 0; |
| 873 | |
| 874 | err: |
| 875 | sde_core_perf_destroy(perf); |
| 876 | return -ENODEV; |
| 877 | } |