blob: 6b3674554fbff985a2e94d661960311e4bda4340 [file] [log] [blame]
Dhaval Patel4d424602017-02-18 19:40:14 -08001/* Copyright (c) 2016-2017, The Linux Foundation. All rights reserved.
Alan Kwong67a3f792016-11-01 23:16:53 -04002 *
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 Patel49ef6d72017-03-26 09:35:53 -070021#include <linux/sde_rsc.h>
Alan Kwong67a3f792016-11-01 23:16:53 -040022
23#include "msm_prop.h"
24
25#include "sde_kms.h"
Alan Kwong67a3f792016-11-01 23:16:53 -040026#include "sde_trace.h"
27#include "sde_crtc.h"
Alan Kwong67a3f792016-11-01 23:16:53 -040028#include "sde_core_perf.h"
Alan Kwong67a3f792016-11-01 23:16:53 -040029
Alan Kwong97abd432017-05-11 14:52:23 -070030#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 */
38enum 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 Pateldd2032a2017-04-11 10:50:36 -070045/**
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 */
56enum sde_perf_vote_mode {
57 APPS_RSC_MODE,
58 DISP_RSC_MODE,
59 DISP_RSC_PRIMARY_MODE,
60};
61
Alan Kwong9aa061c2016-11-06 21:17:12 -050062static 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
80static bool _sde_core_perf_crtc_is_power_on(struct drm_crtc *crtc)
81{
82 return sde_crtc_is_enabled(crtc);
83}
84
85static bool _sde_core_video_mode_intf_connected(struct drm_crtc *crtc)
86{
87 struct drm_crtc *tmp_crtc;
Dhaval Patel4d424602017-02-18 19:40:14 -080088 bool intf_connected = false;
Alan Kwong9aa061c2016-11-06 21:17:12 -050089
90 if (!crtc)
Dhaval Patel4d424602017-02-18 19:40:14 -080091 goto end;
Alan Kwong9aa061c2016-11-06 21:17:12 -050092
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 Patel4d424602017-02-18 19:40:14 -080098 intf_connected = true;
99 goto end;
Alan Kwong9aa061c2016-11-06 21:17:12 -0500100 }
101 }
102
Dhaval Patel4d424602017-02-18 19:40:14 -0800103end:
104 return intf_connected;
Alan Kwong9aa061c2016-11-06 21:17:12 -0500105}
106
Alan Kwong8411a9112017-06-06 19:29:01 -0400107static void _sde_core_perf_calc_crtc(struct sde_kms *kms,
108 struct drm_crtc *crtc,
Alan Kwonga1939682017-05-05 11:30:08 -0700109 struct drm_crtc_state *state,
110 struct sde_core_perf_params *perf)
111{
112 struct sde_crtc_state *sde_cstate;
Alan Kwong0230a102017-05-16 11:36:44 -0700113 int i;
Alan Kwonga1939682017-05-05 11:30:08 -0700114
Alan Kwong8411a9112017-06-06 19:29:01 -0400115 if (!kms || !kms->catalog || !crtc || !state || !perf) {
Alan Kwonga1939682017-05-05 11:30:08 -0700116 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 Kwong0230a102017-05-16 11:36:44 -0700123 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 Kwonga1939682017-05-05 11:30:08 -0700141 sde_crtc_get_property(sde_cstate, CRTC_PROP_CORE_IB);
Alan Kwong0230a102017-05-16 11:36:44 -0700142 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 Kwonga1939682017-05-05 11:30:08 -0700148 perf->core_clk_rate =
149 sde_crtc_get_property(sde_cstate, CRTC_PROP_CORE_CLK);
150
Alan Kwong8411a9112017-06-06 19:29:01 -0400151 if (!sde_cstate->bw_control) {
Alan Kwong0230a102017-05-16 11:36:44 -0700152 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 Kwong8411a9112017-06-06 19:29:01 -0400157 perf->core_clk_rate = kms->perf.max_core_clk_rate;
158 } else if (kms->perf.perf_tune.mode == SDE_PERF_MODE_MINIMUM) {
Alan Kwong0230a102017-05-16 11:36:44 -0700159 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 Kwong8411a9112017-06-06 19:29:01 -0400163 perf->core_clk_rate = 0;
164 } else if (kms->perf.perf_tune.mode == SDE_PERF_MODE_FIXED) {
Alan Kwong0230a102017-05-16 11:36:44 -0700165 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 Kwong8411a9112017-06-06 19:29:01 -0400169 perf->core_clk_rate = kms->perf.fix_core_clk_rate;
170 }
171
Ingrid Gallardo27d45122017-10-05 11:53:11 -0700172 SDE_EVT32(crtc->base.id, perf->core_clk_rate);
Alan Kwong0230a102017-05-16 11:36:44 -0700173 SDE_DEBUG(
174 "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 Kwonga1939682017-05-05 11:30:08 -0700175 crtc->base.id, perf->core_clk_rate,
Alan Kwong0230a102017-05-16 11:36:44 -0700176 perf->max_per_pipe_ib[SDE_POWER_HANDLE_DBUS_ID_MNOC],
177 perf->bw_ctl[SDE_POWER_HANDLE_DBUS_ID_MNOC],
178 perf->max_per_pipe_ib[SDE_POWER_HANDLE_DBUS_ID_LLCC],
179 perf->bw_ctl[SDE_POWER_HANDLE_DBUS_ID_LLCC],
180 perf->max_per_pipe_ib[SDE_POWER_HANDLE_DBUS_ID_EBI],
181 perf->bw_ctl[SDE_POWER_HANDLE_DBUS_ID_EBI]);
Alan Kwonga1939682017-05-05 11:30:08 -0700182}
183
Alan Kwong9aa061c2016-11-06 21:17:12 -0500184int sde_core_perf_crtc_check(struct drm_crtc *crtc,
185 struct drm_crtc_state *state)
186{
187 u32 bw, threshold;
188 u64 bw_sum_of_intfs = 0;
Dhaval Patel4d424602017-02-18 19:40:14 -0800189 enum sde_crtc_client_type curr_client_type;
Alan Kwong9aa061c2016-11-06 21:17:12 -0500190 bool is_video_mode;
191 struct sde_crtc_state *sde_cstate;
192 struct drm_crtc *tmp_crtc;
193 struct sde_kms *kms;
Alan Kwong0230a102017-05-16 11:36:44 -0700194 int i;
Alan Kwong9aa061c2016-11-06 21:17:12 -0500195
196 if (!crtc || !state) {
197 SDE_ERROR("invalid crtc\n");
198 return -EINVAL;
199 }
200
201 kms = _sde_crtc_get_kms(crtc);
202 if (!kms || !kms->catalog) {
203 SDE_ERROR("invalid parameters\n");
204 return 0;
205 }
206
207 /* we only need bandwidth check on real-time clients (interfaces) */
Dhaval Patel4d424602017-02-18 19:40:14 -0800208 if (sde_crtc_get_client_type(crtc) == NRT_CLIENT)
Alan Kwong9aa061c2016-11-06 21:17:12 -0500209 return 0;
210
211 sde_cstate = to_sde_crtc_state(state);
212
Alan Kwong751cf462017-06-08 10:26:46 -0400213 /* obtain new values */
Alan Kwong8411a9112017-06-06 19:29:01 -0400214 _sde_core_perf_calc_crtc(kms, crtc, state, &sde_cstate->new_perf);
Alan Kwonga1939682017-05-05 11:30:08 -0700215
Alan Kwong0230a102017-05-16 11:36:44 -0700216 for (i = SDE_POWER_HANDLE_DBUS_ID_MNOC;
217 i < SDE_POWER_HANDLE_DBUS_ID_MAX; i++) {
218 bw_sum_of_intfs = sde_cstate->new_perf.bw_ctl[i];
219 curr_client_type = sde_crtc_get_client_type(crtc);
Alan Kwong9aa061c2016-11-06 21:17:12 -0500220
Alan Kwong0230a102017-05-16 11:36:44 -0700221 drm_for_each_crtc(tmp_crtc, crtc->dev) {
222 if (_sde_core_perf_crtc_is_power_on(tmp_crtc) &&
223 (sde_crtc_get_client_type(tmp_crtc) ==
224 curr_client_type) &&
225 (tmp_crtc != crtc)) {
226 struct sde_crtc_state *tmp_cstate =
Alan Kwong9aa061c2016-11-06 21:17:12 -0500227 to_sde_crtc_state(tmp_crtc->state);
228
Ingrid Gallardo8d326b92017-06-29 18:05:53 -0700229 SDE_DEBUG("crtc:%d bw:%llu ctrl:%d\n",
230 tmp_crtc->base.id,
231 tmp_cstate->new_perf.bw_ctl[i],
232 tmp_cstate->bw_control);
233 /*
234 * For bw check only use the bw if the
235 * atomic property has been already set
236 */
237 if (tmp_cstate->bw_control)
238 bw_sum_of_intfs +=
239 tmp_cstate->new_perf.bw_ctl[i];
Alan Kwong0230a102017-05-16 11:36:44 -0700240 }
Alan Kwong9aa061c2016-11-06 21:17:12 -0500241 }
Alan Kwong9aa061c2016-11-06 21:17:12 -0500242
Alan Kwong0230a102017-05-16 11:36:44 -0700243 /* convert bandwidth to kb */
244 bw = DIV_ROUND_UP_ULL(bw_sum_of_intfs, 1000);
245 SDE_DEBUG("calculated bandwidth=%uk\n", bw);
Alan Kwong9aa061c2016-11-06 21:17:12 -0500246
Alan Kwong0230a102017-05-16 11:36:44 -0700247 is_video_mode = sde_crtc_get_intf_mode(crtc) == INTF_MODE_VIDEO;
248 threshold = (is_video_mode ||
249 _sde_core_video_mode_intf_connected(crtc)) ?
250 kms->catalog->perf.max_bw_low :
251 kms->catalog->perf.max_bw_high;
Alan Kwong9aa061c2016-11-06 21:17:12 -0500252
Alan Kwong0230a102017-05-16 11:36:44 -0700253 SDE_DEBUG("final threshold bw limit = %d\n", threshold);
Alan Kwong9aa061c2016-11-06 21:17:12 -0500254
Alan Kwong0230a102017-05-16 11:36:44 -0700255 if (!sde_cstate->bw_control) {
256 SDE_DEBUG("bypass bandwidth check\n");
257 } else if (!threshold) {
258 SDE_ERROR("no bandwidth limits specified\n");
259 return -E2BIG;
260 } else if (bw > threshold) {
261 SDE_ERROR("exceeds bandwidth: %ukb > %ukb\n", bw,
262 threshold);
263 return -E2BIG;
264 }
Alan Kwong9aa061c2016-11-06 21:17:12 -0500265 }
266
267 return 0;
268}
269
Dhaval Pateldd2032a2017-04-11 10:50:36 -0700270static inline bool _is_crtc_client_type_matches(struct drm_crtc *tmp_crtc,
271 enum sde_crtc_client_type curr_client_type,
272 struct sde_core_perf *perf)
273{
274 if (!tmp_crtc)
275 return false;
276 else if (perf->bw_vote_mode == DISP_RSC_PRIMARY_MODE &&
277 perf->sde_rsc_available)
278 return curr_client_type == sde_crtc_get_client_type(tmp_crtc);
279 else
280 return true;
281}
282
283static inline enum sde_crtc_client_type _get_sde_client_type(
284 enum sde_crtc_client_type curr_client_type,
285 struct sde_core_perf *perf)
286{
287 if (perf->bw_vote_mode == DISP_RSC_PRIMARY_MODE &&
288 perf->sde_rsc_available)
289 return curr_client_type;
290 else if (perf->bw_vote_mode != APPS_RSC_MODE && perf->sde_rsc_available)
291 return RT_RSC_CLIENT;
292 else
293 return RT_CLIENT;
294}
295
Dhaval Patel4d424602017-02-18 19:40:14 -0800296static void _sde_core_perf_crtc_update_bus(struct sde_kms *kms,
Ingrid Gallardo27d45122017-10-05 11:53:11 -0700297 struct drm_crtc *crtc, u32 bus_id,
298 struct sde_core_perf_params *crtc_perf)
Alan Kwong9aa061c2016-11-06 21:17:12 -0500299{
Dhaval Patel4d424602017-02-18 19:40:14 -0800300 u64 bw_sum_of_intfs = 0, bus_ab_quota, bus_ib_quota;
Alan Kwong0230a102017-05-16 11:36:44 -0700301 struct sde_core_perf_params perf = { { 0 } };
Dhaval Pateldd2032a2017-04-11 10:50:36 -0700302 enum sde_crtc_client_type client_vote, curr_client_type
Dhaval Patel4d424602017-02-18 19:40:14 -0800303 = sde_crtc_get_client_type(crtc);
Alan Kwong9aa061c2016-11-06 21:17:12 -0500304 struct drm_crtc *tmp_crtc;
Dhaval Patel4d424602017-02-18 19:40:14 -0800305 struct sde_crtc_state *sde_cstate;
306 struct msm_drm_private *priv = kms->dev->dev_private;
Alan Kwong9aa061c2016-11-06 21:17:12 -0500307
Ingrid Gallardo27d45122017-10-05 11:53:11 -0700308 u64 tmp_max_per_pipe_ib;
309 u64 tmp_bw_ctl;
310
Alan Kwong9aa061c2016-11-06 21:17:12 -0500311 drm_for_each_crtc(tmp_crtc, crtc->dev) {
Dhaval Patel4d424602017-02-18 19:40:14 -0800312 if (_sde_core_perf_crtc_is_power_on(tmp_crtc) &&
Dhaval Pateldd2032a2017-04-11 10:50:36 -0700313 _is_crtc_client_type_matches(tmp_crtc, curr_client_type,
314 &kms->perf)) {
Ingrid Gallardo27d45122017-10-05 11:53:11 -0700315
316 if (crtc->base.id == tmp_crtc->base.id) {
317 /* for current crtc use the cached values */
318 tmp_max_per_pipe_ib =
319 crtc_perf->max_per_pipe_ib[bus_id];
320 tmp_bw_ctl = crtc_perf->bw_ctl[bus_id];
321 } else {
322 sde_cstate = to_sde_crtc_state(tmp_crtc->state);
323 tmp_max_per_pipe_ib =
324 sde_cstate->new_perf.max_per_pipe_ib[bus_id];
325 tmp_bw_ctl =
326 sde_cstate->new_perf.bw_ctl[bus_id];
327 }
Alan Kwong9aa061c2016-11-06 21:17:12 -0500328
Alan Kwong0230a102017-05-16 11:36:44 -0700329 perf.max_per_pipe_ib[bus_id] =
330 max(perf.max_per_pipe_ib[bus_id],
Ingrid Gallardo27d45122017-10-05 11:53:11 -0700331 tmp_max_per_pipe_ib);
Alan Kwong9aa061c2016-11-06 21:17:12 -0500332
Ingrid Gallardo27d45122017-10-05 11:53:11 -0700333 bw_sum_of_intfs += tmp_bw_ctl;
Alan Kwong9aa061c2016-11-06 21:17:12 -0500334
Ingrid Gallardo27d45122017-10-05 11:53:11 -0700335 SDE_DEBUG("crtc=%d bus_id=%d bw=%llu perf_pipe:%llu\n",
Alan Kwong0230a102017-05-16 11:36:44 -0700336 tmp_crtc->base.id, bus_id,
Ingrid Gallardo27d45122017-10-05 11:53:11 -0700337 tmp_bw_ctl, tmp_max_per_pipe_ib);
Alan Kwong9aa061c2016-11-06 21:17:12 -0500338 }
339 }
340
Dhaval Patel4d424602017-02-18 19:40:14 -0800341 bus_ab_quota = max(bw_sum_of_intfs, kms->perf.perf_tune.min_bus_vote);
Alan Kwong0230a102017-05-16 11:36:44 -0700342 bus_ib_quota = perf.max_per_pipe_ib[bus_id];
Alan Kwong9aa061c2016-11-06 21:17:12 -0500343
Alan Kwong97abd432017-05-11 14:52:23 -0700344 if (kms->perf.perf_tune.mode == SDE_PERF_MODE_FIXED) {
345 bus_ab_quota = kms->perf.fix_core_ab_vote;
346 bus_ib_quota = kms->perf.fix_core_ib_vote;
347 }
348
Dhaval Pateldd2032a2017-04-11 10:50:36 -0700349 client_vote = _get_sde_client_type(curr_client_type, &kms->perf);
350 switch (client_vote) {
Dhaval Patel4d424602017-02-18 19:40:14 -0800351 case NRT_CLIENT:
352 sde_power_data_bus_set_quota(&priv->phandle, kms->core_client,
353 SDE_POWER_HANDLE_DATA_BUS_CLIENT_NRT,
Alan Kwong0230a102017-05-16 11:36:44 -0700354 bus_id, bus_ab_quota, bus_ib_quota);
355 SDE_DEBUG("client:%s bus_id=%d ab=%llu ib=%llu\n", "nrt",
356 bus_id, bus_ab_quota, bus_ib_quota);
Dhaval Patel4d424602017-02-18 19:40:14 -0800357 break;
Alan Kwong9aa061c2016-11-06 21:17:12 -0500358
Dhaval Patel4d424602017-02-18 19:40:14 -0800359 case RT_CLIENT:
360 sde_power_data_bus_set_quota(&priv->phandle, kms->core_client,
Alan Kwong9aa061c2016-11-06 21:17:12 -0500361 SDE_POWER_HANDLE_DATA_BUS_CLIENT_RT,
Alan Kwong0230a102017-05-16 11:36:44 -0700362 bus_id, bus_ab_quota, bus_ib_quota);
363 SDE_DEBUG("client:%s bus_id=%d ab=%llu ib=%llu\n", "rt",
364 bus_id, bus_ab_quota, bus_ib_quota);
Dhaval Patel4d424602017-02-18 19:40:14 -0800365 break;
Alan Kwong9aa061c2016-11-06 21:17:12 -0500366
Dhaval Patel4d424602017-02-18 19:40:14 -0800367 case RT_RSC_CLIENT:
368 sde_cstate = to_sde_crtc_state(crtc->state);
Alan Kwong0230a102017-05-16 11:36:44 -0700369 sde_rsc_client_vote(sde_cstate->rsc_client,
370 bus_id, bus_ab_quota, bus_ib_quota);
371 SDE_DEBUG("client:%s bus_id=%d ab=%llu ib=%llu\n", "rt_rsc",
372 bus_id, bus_ab_quota, bus_ib_quota);
Dhaval Patel4d424602017-02-18 19:40:14 -0800373 break;
Alan Kwong9aa061c2016-11-06 21:17:12 -0500374
Dhaval Patel4d424602017-02-18 19:40:14 -0800375 default:
376 SDE_ERROR("invalid client type:%d\n", curr_client_type);
377 break;
Alan Kwong9aa061c2016-11-06 21:17:12 -0500378 }
Dhaval Pateldd2032a2017-04-11 10:50:36 -0700379
380 if (kms->perf.bw_vote_mode_updated) {
381 switch (kms->perf.bw_vote_mode) {
382 case DISP_RSC_MODE:
383 sde_power_data_bus_set_quota(&priv->phandle,
384 kms->core_client,
Alan Kwong0230a102017-05-16 11:36:44 -0700385 SDE_POWER_HANDLE_DATA_BUS_CLIENT_NRT,
386 bus_id, 0, 0);
Dhaval Pateldd2032a2017-04-11 10:50:36 -0700387 sde_power_data_bus_set_quota(&priv->phandle,
388 kms->core_client,
Alan Kwong0230a102017-05-16 11:36:44 -0700389 SDE_POWER_HANDLE_DATA_BUS_CLIENT_RT,
390 bus_id, 0, 0);
Dhaval Pateldd2032a2017-04-11 10:50:36 -0700391 kms->perf.bw_vote_mode_updated = false;
392 break;
393
394 case APPS_RSC_MODE:
395 sde_cstate = to_sde_crtc_state(crtc->state);
396 if (sde_cstate->rsc_client) {
397 sde_rsc_client_vote(sde_cstate->rsc_client,
Alan Kwong0230a102017-05-16 11:36:44 -0700398 bus_id, 0, 0);
Dhaval Pateldd2032a2017-04-11 10:50:36 -0700399 kms->perf.bw_vote_mode_updated = false;
400 }
401 break;
402
403 default:
404 break;
405 }
406 }
Alan Kwong9aa061c2016-11-06 21:17:12 -0500407}
408
409/**
410 * @sde_core_perf_crtc_release_bw() - request zero bandwidth
411 * @crtc - pointer to a crtc
412 *
413 * Function checks a state variable for the crtc, if all pending commit
414 * requests are done, meaning no more bandwidth is needed, release
415 * bandwidth request.
416 */
417void sde_core_perf_crtc_release_bw(struct drm_crtc *crtc)
418{
419 struct drm_crtc *tmp_crtc;
Alan Kwong751cf462017-06-08 10:26:46 -0400420 struct sde_crtc *sde_crtc;
Alan Kwong9aa061c2016-11-06 21:17:12 -0500421 struct sde_crtc_state *sde_cstate;
422 struct sde_kms *kms;
Alan Kwong0230a102017-05-16 11:36:44 -0700423 int i;
Alan Kwong9aa061c2016-11-06 21:17:12 -0500424
425 if (!crtc) {
426 SDE_ERROR("invalid crtc\n");
427 return;
428 }
429
430 kms = _sde_crtc_get_kms(crtc);
431 if (!kms || !kms->catalog) {
432 SDE_ERROR("invalid kms\n");
433 return;
434 }
435
Alan Kwong751cf462017-06-08 10:26:46 -0400436 sde_crtc = to_sde_crtc(crtc);
Alan Kwong9aa061c2016-11-06 21:17:12 -0500437 sde_cstate = to_sde_crtc_state(crtc->state);
438
Dhaval Patel4d424602017-02-18 19:40:14 -0800439 /* only do this for command mode rt client (non-rsc client) */
Alan Kwong9aa061c2016-11-06 21:17:12 -0500440 if ((sde_crtc_get_intf_mode(crtc) != INTF_MODE_CMD) &&
Dhaval Patel4d424602017-02-18 19:40:14 -0800441 (sde_crtc_get_client_type(crtc) != RT_RSC_CLIENT))
Alan Kwong9aa061c2016-11-06 21:17:12 -0500442 return;
443
444 /*
445 * If video interface present, cmd panel bandwidth cannot be
446 * released.
447 */
448 if (sde_crtc_get_intf_mode(crtc) == INTF_MODE_CMD)
449 drm_for_each_crtc(tmp_crtc, crtc->dev) {
450 if (_sde_core_perf_crtc_is_power_on(tmp_crtc) &&
451 sde_crtc_get_intf_mode(tmp_crtc) ==
452 INTF_MODE_VIDEO)
453 return;
454 }
455
456 /* Release the bandwidth */
457 if (kms->perf.enable_bw_release) {
458 trace_sde_cmd_release_bw(crtc->base.id);
Alan Kwong9aa061c2016-11-06 21:17:12 -0500459 SDE_DEBUG("Release BW crtc=%d\n", crtc->base.id);
Alan Kwong0230a102017-05-16 11:36:44 -0700460 for (i = 0; i < SDE_POWER_HANDLE_DBUS_ID_MAX; i++) {
461 sde_crtc->cur_perf.bw_ctl[i] = 0;
Ingrid Gallardo27d45122017-10-05 11:53:11 -0700462 _sde_core_perf_crtc_update_bus(kms, crtc, i,
463 &sde_crtc->cur_perf);
Alan Kwong0230a102017-05-16 11:36:44 -0700464 }
Alan Kwong9aa061c2016-11-06 21:17:12 -0500465 }
466}
467
Ingrid Gallardo27d45122017-10-05 11:53:11 -0700468static u64 _sde_core_perf_get_core_clk_rate(struct sde_kms *kms,
469 struct sde_core_perf_params *crct_perf, struct drm_crtc *crtc)
Alan Kwong9aa061c2016-11-06 21:17:12 -0500470{
Alan Kwong97abd432017-05-11 14:52:23 -0700471 u64 clk_rate = kms->perf.perf_tune.min_core_clk;
Ingrid Gallardo27d45122017-10-05 11:53:11 -0700472 struct drm_crtc *tmp_crtc;
Alan Kwong9aa061c2016-11-06 21:17:12 -0500473 struct sde_crtc_state *sde_cstate;
Ingrid Gallardo27d45122017-10-05 11:53:11 -0700474 u64 tmp_rate;
Alan Kwong9aa061c2016-11-06 21:17:12 -0500475
Ingrid Gallardo27d45122017-10-05 11:53:11 -0700476 drm_for_each_crtc(tmp_crtc, kms->dev) {
477 if (_sde_core_perf_crtc_is_power_on(tmp_crtc)) {
478
479 if (crtc->base.id == tmp_crtc->base.id) {
480 /* for current CRTC, use the cached value */
481 tmp_rate = crct_perf->core_clk_rate;
482 } else {
483 sde_cstate = to_sde_crtc_state(tmp_crtc->state);
484 tmp_rate = sde_cstate->new_perf.core_clk_rate;
485 }
486 clk_rate = max(tmp_rate, clk_rate);
487
Alan Kwong9aa061c2016-11-06 21:17:12 -0500488 clk_rate = clk_round_rate(kms->perf.core_clk, clk_rate);
489 }
Alan Kwong9aa061c2016-11-06 21:17:12 -0500490 }
Alan Kwong9aa061c2016-11-06 21:17:12 -0500491
Alan Kwong97abd432017-05-11 14:52:23 -0700492 if (kms->perf.perf_tune.mode == SDE_PERF_MODE_FIXED)
493 clk_rate = kms->perf.fix_core_clk_rate;
494
495 SDE_DEBUG("clk:%llu\n", clk_rate);
Alan Kwong9aa061c2016-11-06 21:17:12 -0500496
497 return clk_rate;
498}
499
500void sde_core_perf_crtc_update(struct drm_crtc *crtc,
501 int params_changed, bool stop_req)
502{
503 struct sde_core_perf_params *new, *old;
504 int update_bus = 0, update_clk = 0;
Alan Kwong97abd432017-05-11 14:52:23 -0700505 u64 clk_rate = 0;
Alan Kwong9aa061c2016-11-06 21:17:12 -0500506 struct sde_crtc *sde_crtc;
507 struct sde_crtc_state *sde_cstate;
Alan Kwong0230a102017-05-16 11:36:44 -0700508 int ret, i;
Alan Kwong9aa061c2016-11-06 21:17:12 -0500509 struct msm_drm_private *priv;
510 struct sde_kms *kms;
511
512 if (!crtc) {
513 SDE_ERROR("invalid crtc\n");
514 return;
515 }
516
517 kms = _sde_crtc_get_kms(crtc);
518 if (!kms || !kms->catalog) {
519 SDE_ERROR("invalid kms\n");
520 return;
521 }
522 priv = kms->dev->dev_private;
523
Dhaval Patel378a9b42017-05-23 13:11:24 -0700524 /* wake vote update is not required with display rsc */
525 if (kms->perf.bw_vote_mode == DISP_RSC_MODE && stop_req)
526 return;
527
Alan Kwong9aa061c2016-11-06 21:17:12 -0500528 sde_crtc = to_sde_crtc(crtc);
529 sde_cstate = to_sde_crtc_state(crtc->state);
530
Alan Kwong97abd432017-05-11 14:52:23 -0700531 SDE_DEBUG("crtc:%d stop_req:%d core_clk:%llu\n",
Alan Kwong9aa061c2016-11-06 21:17:12 -0500532 crtc->base.id, stop_req, kms->perf.core_clk_rate);
533
Ingrid Gallardo27d45122017-10-05 11:53:11 -0700534 /*
535 * cache the performance numbers in the crtc prior to the
536 * crtc kickoff, so the same numbers are used during the
537 * perf update that happens post kickoff.
538 */
539 if (params_changed)
540 memcpy(&sde_crtc->new_perf, &sde_cstate->new_perf,
541 sizeof(struct sde_core_perf_params));
542
Alan Kwong751cf462017-06-08 10:26:46 -0400543 old = &sde_crtc->cur_perf;
Ingrid Gallardo27d45122017-10-05 11:53:11 -0700544 new = &sde_crtc->new_perf;
Alan Kwong9aa061c2016-11-06 21:17:12 -0500545
546 if (_sde_core_perf_crtc_is_power_on(crtc) && !stop_req) {
Alan Kwong0230a102017-05-16 11:36:44 -0700547 for (i = 0; i < SDE_POWER_HANDLE_DBUS_ID_MAX; i++) {
548 /*
549 * cases for bus bandwidth update.
550 * 1. new bandwidth vote - "ab or ib vote" is higher
551 * than current vote for update request.
552 * 2. new bandwidth vote - "ab or ib vote" is lower
553 * than current vote at end of commit or stop.
554 */
555 if ((params_changed && ((new->bw_ctl[i] >
556 old->bw_ctl[i]) ||
557 (new->max_per_pipe_ib[i] >
558 old->max_per_pipe_ib[i]))) ||
559 (!params_changed && ((new->bw_ctl[i] <
560 old->bw_ctl[i]) ||
561 (new->max_per_pipe_ib[i] <
562 old->max_per_pipe_ib[i])))) {
563 SDE_DEBUG(
564 "crtc=%d p=%d new_bw=%llu,old_bw=%llu\n",
565 crtc->base.id, params_changed,
566 new->bw_ctl[i], old->bw_ctl[i]);
567 old->bw_ctl[i] = new->bw_ctl[i];
568 old->max_per_pipe_ib[i] =
569 new->max_per_pipe_ib[i];
570 update_bus |= BIT(i);
571 }
Alan Kwong9aa061c2016-11-06 21:17:12 -0500572
Alan Kwong0230a102017-05-16 11:36:44 -0700573 /* display rsc override during solver mode */
574 if (kms->perf.bw_vote_mode == DISP_RSC_MODE &&
Dhaval Patel378a9b42017-05-23 13:11:24 -0700575 get_sde_rsc_current_state(SDE_RSC_INDEX) ==
Alan Kwong0230a102017-05-16 11:36:44 -0700576 SDE_RSC_CMD_STATE) {
577 /* update new bandwidth in all cases */
578 if (params_changed && ((new->bw_ctl[i] !=
579 old->bw_ctl[i]) ||
580 (new->max_per_pipe_ib[i] !=
581 old->max_per_pipe_ib[i]))) {
582 old->bw_ctl[i] = new->bw_ctl[i];
583 old->max_per_pipe_ib[i] =
584 new->max_per_pipe_ib[i];
585 update_bus |= BIT(i);
586 /*
587 * reduce bw vote is not required in solver
588 * mode
589 */
590 } else if (!params_changed) {
591 update_bus &= ~BIT(i);
592 }
Dhaval Patel378a9b42017-05-23 13:11:24 -0700593 }
594 }
595
Alan Kwong9aa061c2016-11-06 21:17:12 -0500596 if ((params_changed &&
597 (new->core_clk_rate > old->core_clk_rate)) ||
598 (!params_changed &&
599 (new->core_clk_rate < old->core_clk_rate))) {
600 old->core_clk_rate = new->core_clk_rate;
601 update_clk = 1;
602 }
603 } else {
604 SDE_DEBUG("crtc=%d disable\n", crtc->base.id);
605 memset(old, 0, sizeof(*old));
606 memset(new, 0, sizeof(*new));
Alan Kwong0230a102017-05-16 11:36:44 -0700607 update_bus = ~0;
Alan Kwong9aa061c2016-11-06 21:17:12 -0500608 update_clk = 1;
609 }
Alan Kwong0230a102017-05-16 11:36:44 -0700610 trace_sde_perf_crtc_update(crtc->base.id,
611 new->bw_ctl[SDE_POWER_HANDLE_DBUS_ID_MNOC],
612 new->bw_ctl[SDE_POWER_HANDLE_DBUS_ID_LLCC],
613 new->bw_ctl[SDE_POWER_HANDLE_DBUS_ID_EBI],
Narendra Muppalla8f2a1262017-05-23 20:02:34 -0700614 new->core_clk_rate, stop_req,
615 update_bus, update_clk);
Alan Kwong9aa061c2016-11-06 21:17:12 -0500616
Alan Kwong0230a102017-05-16 11:36:44 -0700617 for (i = 0; i < SDE_POWER_HANDLE_DBUS_ID_MAX; i++) {
618 if (update_bus & BIT(i))
Ingrid Gallardo27d45122017-10-05 11:53:11 -0700619 _sde_core_perf_crtc_update_bus(kms, crtc, i, old);
Alan Kwong0230a102017-05-16 11:36:44 -0700620 }
Alan Kwong9aa061c2016-11-06 21:17:12 -0500621
622 /*
623 * Update the clock after bandwidth vote to ensure
624 * bandwidth is available before clock rate is increased.
625 */
626 if (update_clk) {
Ingrid Gallardo27d45122017-10-05 11:53:11 -0700627 clk_rate = _sde_core_perf_get_core_clk_rate(kms, old, crtc);
Dhaval Patel4d424602017-02-18 19:40:14 -0800628
Ingrid Gallardo27d45122017-10-05 11:53:11 -0700629 SDE_EVT32(kms->dev, stop_req, clk_rate, params_changed,
630 old->core_clk_rate, new->core_clk_rate);
Alan Kwong9aa061c2016-11-06 21:17:12 -0500631 ret = sde_power_clk_set_rate(&priv->phandle,
632 kms->perf.clk_name, clk_rate);
633 if (ret) {
Alan Kwong97abd432017-05-11 14:52:23 -0700634 SDE_ERROR("failed to set %s clock rate %llu\n",
Alan Kwong9aa061c2016-11-06 21:17:12 -0500635 kms->perf.clk_name, clk_rate);
Dhaval Patel4d424602017-02-18 19:40:14 -0800636 return;
Alan Kwong9aa061c2016-11-06 21:17:12 -0500637 }
638
639 kms->perf.core_clk_rate = clk_rate;
Alan Kwong97abd432017-05-11 14:52:23 -0700640 SDE_DEBUG("update clk rate = %lld HZ\n", clk_rate);
Alan Kwong9aa061c2016-11-06 21:17:12 -0500641 }
Alan Kwong9aa061c2016-11-06 21:17:12 -0500642}
643
Alan Kwong67a3f792016-11-01 23:16:53 -0400644#ifdef CONFIG_DEBUG_FS
645
Alan Kwong9aa061c2016-11-06 21:17:12 -0500646static ssize_t _sde_core_perf_mode_write(struct file *file,
647 const char __user *user_buf, size_t count, loff_t *ppos)
648{
649 struct sde_core_perf *perf = file->private_data;
650 struct sde_perf_cfg *cfg = &perf->catalog->perf;
Alan Kwong97abd432017-05-11 14:52:23 -0700651 u32 perf_mode = 0;
Alan Kwong9aa061c2016-11-06 21:17:12 -0500652 char buf[10];
653
654 if (!perf)
655 return -ENODEV;
656
657 if (count >= sizeof(buf))
658 return -EFAULT;
659
660 if (copy_from_user(buf, user_buf, count))
661 return -EFAULT;
662
663 buf[count] = 0; /* end of string */
664
Alan Kwong97abd432017-05-11 14:52:23 -0700665 if (kstrtouint(buf, 0, &perf_mode))
Alan Kwong9aa061c2016-11-06 21:17:12 -0500666 return -EFAULT;
667
Alan Kwong97abd432017-05-11 14:52:23 -0700668 if (perf_mode >= SDE_PERF_MODE_MAX)
669 return -EFAULT;
670
671 if (perf_mode == SDE_PERF_MODE_FIXED) {
672 DRM_INFO("fix performance mode\n");
673 } else if (perf_mode == SDE_PERF_MODE_MINIMUM) {
Alan Kwong9aa061c2016-11-06 21:17:12 -0500674 /* run the driver with max clk and BW vote */
675 perf->perf_tune.min_core_clk = perf->max_core_clk_rate;
676 perf->perf_tune.min_bus_vote =
677 (u64) cfg->max_bw_high * 1000;
Alan Kwong97abd432017-05-11 14:52:23 -0700678 DRM_INFO("minimum performance mode\n");
679 } else if (perf_mode == SDE_PERF_MODE_NORMAL) {
Alan Kwong9aa061c2016-11-06 21:17:12 -0500680 /* reset the perf tune params to 0 */
681 perf->perf_tune.min_core_clk = 0;
682 perf->perf_tune.min_bus_vote = 0;
Alan Kwong97abd432017-05-11 14:52:23 -0700683 DRM_INFO("normal performance mode\n");
Alan Kwong9aa061c2016-11-06 21:17:12 -0500684 }
Alan Kwong97abd432017-05-11 14:52:23 -0700685 perf->perf_tune.mode = perf_mode;
686
Alan Kwong9aa061c2016-11-06 21:17:12 -0500687 return count;
688}
689
690static ssize_t _sde_core_perf_mode_read(struct file *file,
691 char __user *buff, size_t count, loff_t *ppos)
692{
693 struct sde_core_perf *perf = file->private_data;
694 int len = 0;
Alan Kwong97abd432017-05-11 14:52:23 -0700695 char buf[SDE_PERF_MODE_STRING_SIZE] = {'\0'};
Alan Kwong9aa061c2016-11-06 21:17:12 -0500696
697 if (!perf)
698 return -ENODEV;
699
700 if (*ppos)
701 return 0; /* the end */
702
Alan Kwong97abd432017-05-11 14:52:23 -0700703 len = snprintf(buf, sizeof(buf),
704 "mode %d min_mdp_clk %llu min_bus_vote %llu\n",
705 perf->perf_tune.mode,
Alan Kwong9aa061c2016-11-06 21:17:12 -0500706 perf->perf_tune.min_core_clk,
707 perf->perf_tune.min_bus_vote);
708 if (len < 0 || len >= sizeof(buf))
709 return 0;
710
711 if ((count < sizeof(buf)) || copy_to_user(buff, buf, len))
712 return -EFAULT;
713
714 *ppos += len; /* increase offset */
715
716 return len;
717}
718
719static const struct file_operations sde_core_perf_mode_fops = {
720 .open = simple_open,
721 .read = _sde_core_perf_mode_read,
722 .write = _sde_core_perf_mode_write,
723};
724
Lloyd Atkinsonb020e0f2017-03-14 08:05:18 -0700725static void sde_core_perf_debugfs_destroy(struct sde_core_perf *perf)
Alan Kwong67a3f792016-11-01 23:16:53 -0400726{
727 debugfs_remove_recursive(perf->debugfs_root);
728 perf->debugfs_root = NULL;
729}
730
Lloyd Atkinsonb020e0f2017-03-14 08:05:18 -0700731int sde_core_perf_debugfs_init(struct sde_core_perf *perf,
Alan Kwong67a3f792016-11-01 23:16:53 -0400732 struct dentry *parent)
733{
Alan Kwong9aa061c2016-11-06 21:17:12 -0500734 struct sde_mdss_cfg *catalog = perf->catalog;
Alan Kwong67a3f792016-11-01 23:16:53 -0400735 struct msm_drm_private *priv;
736 struct sde_kms *sde_kms;
737
738 priv = perf->dev->dev_private;
739 if (!priv || !priv->kms) {
740 SDE_ERROR("invalid KMS reference\n");
741 return -EINVAL;
742 }
743
744 sde_kms = to_sde_kms(priv->kms);
745
746 perf->debugfs_root = debugfs_create_dir("core_perf", parent);
747 if (!perf->debugfs_root) {
748 SDE_ERROR("failed to create core perf debugfs\n");
749 return -EINVAL;
750 }
751
Lloyd Atkinson8de415a2017-05-23 11:31:16 -0400752 debugfs_create_u64("max_core_clk_rate", 0600, perf->debugfs_root,
Alan Kwong67a3f792016-11-01 23:16:53 -0400753 &perf->max_core_clk_rate);
Lloyd Atkinson8de415a2017-05-23 11:31:16 -0400754 debugfs_create_u64("core_clk_rate", 0600, perf->debugfs_root,
Alan Kwong67a3f792016-11-01 23:16:53 -0400755 &perf->core_clk_rate);
Lloyd Atkinson8de415a2017-05-23 11:31:16 -0400756 debugfs_create_u32("enable_bw_release", 0600, perf->debugfs_root,
Alan Kwong9aa061c2016-11-06 21:17:12 -0500757 (u32 *)&perf->enable_bw_release);
Lloyd Atkinson8de415a2017-05-23 11:31:16 -0400758 debugfs_create_u32("threshold_low", 0600, perf->debugfs_root,
Alan Kwong9aa061c2016-11-06 21:17:12 -0500759 (u32 *)&catalog->perf.max_bw_low);
Lloyd Atkinson8de415a2017-05-23 11:31:16 -0400760 debugfs_create_u32("threshold_high", 0600, perf->debugfs_root,
Alan Kwong9aa061c2016-11-06 21:17:12 -0500761 (u32 *)&catalog->perf.max_bw_high);
Narendra Muppallaa50934b2017-08-15 19:43:37 -0700762 debugfs_create_u32("min_core_ib", 0600, perf->debugfs_root,
763 (u32 *)&catalog->perf.min_core_ib);
764 debugfs_create_u32("min_llcc_ib", 0600, perf->debugfs_root,
765 (u32 *)&catalog->perf.min_llcc_ib);
766 debugfs_create_u32("min_dram_ib", 0600, perf->debugfs_root,
767 (u32 *)&catalog->perf.min_dram_ib);
Lloyd Atkinson8de415a2017-05-23 11:31:16 -0400768 debugfs_create_file("perf_mode", 0600, perf->debugfs_root,
Alan Kwong9aa061c2016-11-06 21:17:12 -0500769 (u32 *)perf, &sde_core_perf_mode_fops);
Dhaval Pateldd2032a2017-04-11 10:50:36 -0700770 debugfs_create_u32("bw_vote_mode", 0600, perf->debugfs_root,
771 &perf->bw_vote_mode);
772 debugfs_create_bool("bw_vote_mode_updated", 0600, perf->debugfs_root,
773 &perf->bw_vote_mode_updated);
Lloyd Atkinson8de415a2017-05-23 11:31:16 -0400774 debugfs_create_u64("fix_core_clk_rate", 0600, perf->debugfs_root,
Alan Kwong97abd432017-05-11 14:52:23 -0700775 &perf->fix_core_clk_rate);
Lloyd Atkinson8de415a2017-05-23 11:31:16 -0400776 debugfs_create_u64("fix_core_ib_vote", 0600, perf->debugfs_root,
Alan Kwong97abd432017-05-11 14:52:23 -0700777 &perf->fix_core_ib_vote);
Lloyd Atkinson8de415a2017-05-23 11:31:16 -0400778 debugfs_create_u64("fix_core_ab_vote", 0600, perf->debugfs_root,
Alan Kwong97abd432017-05-11 14:52:23 -0700779 &perf->fix_core_ab_vote);
Alan Kwong67a3f792016-11-01 23:16:53 -0400780
781 return 0;
782}
783#else
Lloyd Atkinsonb020e0f2017-03-14 08:05:18 -0700784static void sde_core_perf_debugfs_destroy(struct sde_core_perf *perf)
Alan Kwong67a3f792016-11-01 23:16:53 -0400785{
786}
787
Lloyd Atkinsonb020e0f2017-03-14 08:05:18 -0700788int sde_core_perf_debugfs_init(struct sde_core_perf *perf,
Alan Kwong67a3f792016-11-01 23:16:53 -0400789 struct dentry *parent)
790{
791 return 0;
792}
793#endif
794
795void sde_core_perf_destroy(struct sde_core_perf *perf)
796{
797 if (!perf) {
798 SDE_ERROR("invalid parameters\n");
799 return;
800 }
801
Lloyd Atkinsonb020e0f2017-03-14 08:05:18 -0700802 sde_core_perf_debugfs_destroy(perf);
Alan Kwong67a3f792016-11-01 23:16:53 -0400803 perf->max_core_clk_rate = 0;
804 perf->core_clk = NULL;
Alan Kwong67a3f792016-11-01 23:16:53 -0400805 perf->clk_name = NULL;
806 perf->phandle = NULL;
807 perf->catalog = NULL;
808 perf->dev = NULL;
809}
810
811int sde_core_perf_init(struct sde_core_perf *perf,
812 struct drm_device *dev,
813 struct sde_mdss_cfg *catalog,
814 struct sde_power_handle *phandle,
815 struct sde_power_client *pclient,
Lloyd Atkinsonb020e0f2017-03-14 08:05:18 -0700816 char *clk_name)
Alan Kwong67a3f792016-11-01 23:16:53 -0400817{
Lloyd Atkinsonb020e0f2017-03-14 08:05:18 -0700818 if (!perf || !dev || !catalog || !phandle || !pclient || !clk_name) {
Alan Kwong67a3f792016-11-01 23:16:53 -0400819 SDE_ERROR("invalid parameters\n");
820 return -EINVAL;
821 }
822
823 perf->dev = dev;
824 perf->catalog = catalog;
825 perf->phandle = phandle;
826 perf->pclient = pclient;
827 perf->clk_name = clk_name;
Dhaval Pateldd2032a2017-04-11 10:50:36 -0700828 perf->sde_rsc_available = is_sde_rsc_available(SDE_RSC_INDEX);
829 /* set default mode */
830 if (perf->sde_rsc_available)
831 perf->bw_vote_mode = DISP_RSC_MODE;
832 else
833 perf->bw_vote_mode = APPS_RSC_MODE;
Alan Kwong67a3f792016-11-01 23:16:53 -0400834
835 perf->core_clk = sde_power_clk_get_clk(phandle, clk_name);
836 if (!perf->core_clk) {
837 SDE_ERROR("invalid core clk\n");
838 goto err;
839 }
840
841 perf->max_core_clk_rate = sde_power_clk_get_max_rate(phandle, clk_name);
842 if (!perf->max_core_clk_rate) {
Alan Kwong6259a382017-04-04 06:18:02 -0700843 SDE_DEBUG("optional max core clk rate, use default\n");
844 perf->max_core_clk_rate = SDE_PERF_DEFAULT_MAX_CORE_CLK_RATE;
Alan Kwong67a3f792016-11-01 23:16:53 -0400845 }
846
Alan Kwong67a3f792016-11-01 23:16:53 -0400847 return 0;
848
849err:
850 sde_core_perf_destroy(perf);
851 return -ENODEV;
852}