blob: 3879d4d774f482f09e23a51bcf2634098bc17b1f [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);
Ingrid Gallardoac3d09b2017-12-01 17:42:50 -0800173 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 Kwong0230a102017-05-16 11:36:44 -0700182 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 Kwonga1939682017-05-05 11:30:08 -0700184 crtc->base.id, perf->core_clk_rate,
Alan Kwong0230a102017-05-16 11:36:44 -0700185 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 Kwonga1939682017-05-05 11:30:08 -0700191}
192
Alan Kwong9aa061c2016-11-06 21:17:12 -0500193int 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 Patel4d424602017-02-18 19:40:14 -0800198 enum sde_crtc_client_type curr_client_type;
Alan Kwong9aa061c2016-11-06 21:17:12 -0500199 bool is_video_mode;
200 struct sde_crtc_state *sde_cstate;
201 struct drm_crtc *tmp_crtc;
202 struct sde_kms *kms;
Alan Kwong0230a102017-05-16 11:36:44 -0700203 int i;
Alan Kwong9aa061c2016-11-06 21:17:12 -0500204
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 Patel4d424602017-02-18 19:40:14 -0800217 if (sde_crtc_get_client_type(crtc) == NRT_CLIENT)
Alan Kwong9aa061c2016-11-06 21:17:12 -0500218 return 0;
219
220 sde_cstate = to_sde_crtc_state(state);
221
Alan Kwong751cf462017-06-08 10:26:46 -0400222 /* obtain new values */
Alan Kwong8411a9112017-06-06 19:29:01 -0400223 _sde_core_perf_calc_crtc(kms, crtc, state, &sde_cstate->new_perf);
Alan Kwonga1939682017-05-05 11:30:08 -0700224
Alan Kwong0230a102017-05-16 11:36:44 -0700225 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 Kwong9aa061c2016-11-06 21:17:12 -0500229
Alan Kwong0230a102017-05-16 11:36:44 -0700230 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 Kwong9aa061c2016-11-06 21:17:12 -0500236 to_sde_crtc_state(tmp_crtc->state);
237
Ingrid Gallardo8d326b92017-06-29 18:05:53 -0700238 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 Kwong0230a102017-05-16 11:36:44 -0700249 }
Alan Kwong9aa061c2016-11-06 21:17:12 -0500250 }
Alan Kwong9aa061c2016-11-06 21:17:12 -0500251
Alan Kwong0230a102017-05-16 11:36:44 -0700252 /* convert bandwidth to kb */
253 bw = DIV_ROUND_UP_ULL(bw_sum_of_intfs, 1000);
254 SDE_DEBUG("calculated bandwidth=%uk\n", bw);
Alan Kwong9aa061c2016-11-06 21:17:12 -0500255
Alan Kwong0230a102017-05-16 11:36:44 -0700256 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 Kwong9aa061c2016-11-06 21:17:12 -0500261
Alan Kwong0230a102017-05-16 11:36:44 -0700262 SDE_DEBUG("final threshold bw limit = %d\n", threshold);
Alan Kwong9aa061c2016-11-06 21:17:12 -0500263
Alan Kwong0230a102017-05-16 11:36:44 -0700264 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 Kwong9aa061c2016-11-06 21:17:12 -0500274 }
275
276 return 0;
277}
278
Dhaval Pateldd2032a2017-04-11 10:50:36 -0700279static 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
292static 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 Patel4d424602017-02-18 19:40:14 -0800305static void _sde_core_perf_crtc_update_bus(struct sde_kms *kms,
Ingrid Gallardo27d45122017-10-05 11:53:11 -0700306 struct drm_crtc *crtc, u32 bus_id,
307 struct sde_core_perf_params *crtc_perf)
Alan Kwong9aa061c2016-11-06 21:17:12 -0500308{
Dhaval Patel4d424602017-02-18 19:40:14 -0800309 u64 bw_sum_of_intfs = 0, bus_ab_quota, bus_ib_quota;
Alan Kwong0230a102017-05-16 11:36:44 -0700310 struct sde_core_perf_params perf = { { 0 } };
Dhaval Pateldd2032a2017-04-11 10:50:36 -0700311 enum sde_crtc_client_type client_vote, curr_client_type
Dhaval Patel4d424602017-02-18 19:40:14 -0800312 = sde_crtc_get_client_type(crtc);
Alan Kwong9aa061c2016-11-06 21:17:12 -0500313 struct drm_crtc *tmp_crtc;
Dhaval Patel4d424602017-02-18 19:40:14 -0800314 struct sde_crtc_state *sde_cstate;
315 struct msm_drm_private *priv = kms->dev->dev_private;
Alan Kwong9aa061c2016-11-06 21:17:12 -0500316
Ingrid Gallardo27d45122017-10-05 11:53:11 -0700317 u64 tmp_max_per_pipe_ib;
318 u64 tmp_bw_ctl;
319
Alan Kwong9aa061c2016-11-06 21:17:12 -0500320 drm_for_each_crtc(tmp_crtc, crtc->dev) {
Dhaval Patel4d424602017-02-18 19:40:14 -0800321 if (_sde_core_perf_crtc_is_power_on(tmp_crtc) &&
Dhaval Pateldd2032a2017-04-11 10:50:36 -0700322 _is_crtc_client_type_matches(tmp_crtc, curr_client_type,
323 &kms->perf)) {
Ingrid Gallardo27d45122017-10-05 11:53:11 -0700324
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 Kwong9aa061c2016-11-06 21:17:12 -0500337
Alan Kwong0230a102017-05-16 11:36:44 -0700338 perf.max_per_pipe_ib[bus_id] =
339 max(perf.max_per_pipe_ib[bus_id],
Ingrid Gallardo27d45122017-10-05 11:53:11 -0700340 tmp_max_per_pipe_ib);
Alan Kwong9aa061c2016-11-06 21:17:12 -0500341
Ingrid Gallardo27d45122017-10-05 11:53:11 -0700342 bw_sum_of_intfs += tmp_bw_ctl;
Alan Kwong9aa061c2016-11-06 21:17:12 -0500343
Ingrid Gallardo27d45122017-10-05 11:53:11 -0700344 SDE_DEBUG("crtc=%d bus_id=%d bw=%llu perf_pipe:%llu\n",
Alan Kwong0230a102017-05-16 11:36:44 -0700345 tmp_crtc->base.id, bus_id,
Ingrid Gallardo27d45122017-10-05 11:53:11 -0700346 tmp_bw_ctl, tmp_max_per_pipe_ib);
Alan Kwong9aa061c2016-11-06 21:17:12 -0500347 }
348 }
349
Dhaval Patel4d424602017-02-18 19:40:14 -0800350 bus_ab_quota = max(bw_sum_of_intfs, kms->perf.perf_tune.min_bus_vote);
Alan Kwong0230a102017-05-16 11:36:44 -0700351 bus_ib_quota = perf.max_per_pipe_ib[bus_id];
Alan Kwong9aa061c2016-11-06 21:17:12 -0500352
Alan Kwong97abd432017-05-11 14:52:23 -0700353 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 Pateldd2032a2017-04-11 10:50:36 -0700358 client_vote = _get_sde_client_type(curr_client_type, &kms->perf);
359 switch (client_vote) {
Dhaval Patel4d424602017-02-18 19:40:14 -0800360 case NRT_CLIENT:
361 sde_power_data_bus_set_quota(&priv->phandle, kms->core_client,
362 SDE_POWER_HANDLE_DATA_BUS_CLIENT_NRT,
Alan Kwong0230a102017-05-16 11:36:44 -0700363 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 Patel4d424602017-02-18 19:40:14 -0800366 break;
Alan Kwong9aa061c2016-11-06 21:17:12 -0500367
Dhaval Patel4d424602017-02-18 19:40:14 -0800368 case RT_CLIENT:
369 sde_power_data_bus_set_quota(&priv->phandle, kms->core_client,
Alan Kwong9aa061c2016-11-06 21:17:12 -0500370 SDE_POWER_HANDLE_DATA_BUS_CLIENT_RT,
Alan Kwong0230a102017-05-16 11:36:44 -0700371 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 Patel4d424602017-02-18 19:40:14 -0800374 break;
Alan Kwong9aa061c2016-11-06 21:17:12 -0500375
Dhaval Patel4d424602017-02-18 19:40:14 -0800376 case RT_RSC_CLIENT:
377 sde_cstate = to_sde_crtc_state(crtc->state);
Alan Kwong0230a102017-05-16 11:36:44 -0700378 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 Patel4d424602017-02-18 19:40:14 -0800382 break;
Alan Kwong9aa061c2016-11-06 21:17:12 -0500383
Dhaval Patel4d424602017-02-18 19:40:14 -0800384 default:
385 SDE_ERROR("invalid client type:%d\n", curr_client_type);
386 break;
Alan Kwong9aa061c2016-11-06 21:17:12 -0500387 }
Dhaval Pateldd2032a2017-04-11 10:50:36 -0700388
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 Kwong0230a102017-05-16 11:36:44 -0700394 SDE_POWER_HANDLE_DATA_BUS_CLIENT_NRT,
395 bus_id, 0, 0);
Dhaval Pateldd2032a2017-04-11 10:50:36 -0700396 sde_power_data_bus_set_quota(&priv->phandle,
397 kms->core_client,
Alan Kwong0230a102017-05-16 11:36:44 -0700398 SDE_POWER_HANDLE_DATA_BUS_CLIENT_RT,
399 bus_id, 0, 0);
Dhaval Pateldd2032a2017-04-11 10:50:36 -0700400 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 Kwong0230a102017-05-16 11:36:44 -0700407 bus_id, 0, 0);
Dhaval Pateldd2032a2017-04-11 10:50:36 -0700408 kms->perf.bw_vote_mode_updated = false;
409 }
410 break;
411
412 default:
413 break;
414 }
415 }
Alan Kwong9aa061c2016-11-06 21:17:12 -0500416}
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 */
426void sde_core_perf_crtc_release_bw(struct drm_crtc *crtc)
427{
428 struct drm_crtc *tmp_crtc;
Alan Kwong751cf462017-06-08 10:26:46 -0400429 struct sde_crtc *sde_crtc;
Alan Kwong9aa061c2016-11-06 21:17:12 -0500430 struct sde_crtc_state *sde_cstate;
431 struct sde_kms *kms;
Alan Kwong0230a102017-05-16 11:36:44 -0700432 int i;
Alan Kwong9aa061c2016-11-06 21:17:12 -0500433
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 Kwong751cf462017-06-08 10:26:46 -0400445 sde_crtc = to_sde_crtc(crtc);
Alan Kwong9aa061c2016-11-06 21:17:12 -0500446 sde_cstate = to_sde_crtc_state(crtc->state);
447
Dhaval Patel4d424602017-02-18 19:40:14 -0800448 /* only do this for command mode rt client (non-rsc client) */
Alan Kwong9aa061c2016-11-06 21:17:12 -0500449 if ((sde_crtc_get_intf_mode(crtc) != INTF_MODE_CMD) &&
Dhaval Patel4d424602017-02-18 19:40:14 -0800450 (sde_crtc_get_client_type(crtc) != RT_RSC_CLIENT))
Alan Kwong9aa061c2016-11-06 21:17:12 -0500451 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 Kwong9aa061c2016-11-06 21:17:12 -0500468 SDE_DEBUG("Release BW crtc=%d\n", crtc->base.id);
Alan Kwong0230a102017-05-16 11:36:44 -0700469 for (i = 0; i < SDE_POWER_HANDLE_DBUS_ID_MAX; i++) {
470 sde_crtc->cur_perf.bw_ctl[i] = 0;
Ingrid Gallardo27d45122017-10-05 11:53:11 -0700471 _sde_core_perf_crtc_update_bus(kms, crtc, i,
472 &sde_crtc->cur_perf);
Alan Kwong0230a102017-05-16 11:36:44 -0700473 }
Alan Kwong9aa061c2016-11-06 21:17:12 -0500474 }
475}
476
Ingrid Gallardo27d45122017-10-05 11:53:11 -0700477static 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 Kwong9aa061c2016-11-06 21:17:12 -0500479{
Alan Kwong97abd432017-05-11 14:52:23 -0700480 u64 clk_rate = kms->perf.perf_tune.min_core_clk;
Ingrid Gallardo27d45122017-10-05 11:53:11 -0700481 struct drm_crtc *tmp_crtc;
Alan Kwong9aa061c2016-11-06 21:17:12 -0500482 struct sde_crtc_state *sde_cstate;
Ingrid Gallardo27d45122017-10-05 11:53:11 -0700483 u64 tmp_rate;
Alan Kwong9aa061c2016-11-06 21:17:12 -0500484
Ingrid Gallardo27d45122017-10-05 11:53:11 -0700485 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 Kwong9aa061c2016-11-06 21:17:12 -0500497 clk_rate = clk_round_rate(kms->perf.core_clk, clk_rate);
498 }
Alan Kwong9aa061c2016-11-06 21:17:12 -0500499 }
Alan Kwong9aa061c2016-11-06 21:17:12 -0500500
Alan Kwong97abd432017-05-11 14:52:23 -0700501 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 Kwong9aa061c2016-11-06 21:17:12 -0500505
506 return clk_rate;
507}
508
509void 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 Kwong97abd432017-05-11 14:52:23 -0700514 u64 clk_rate = 0;
Alan Kwong9aa061c2016-11-06 21:17:12 -0500515 struct sde_crtc *sde_crtc;
516 struct sde_crtc_state *sde_cstate;
Alan Kwong0230a102017-05-16 11:36:44 -0700517 int ret, i;
Alan Kwong9aa061c2016-11-06 21:17:12 -0500518 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 Patel378a9b42017-05-23 13:11:24 -0700533 /* 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 Kwong9aa061c2016-11-06 21:17:12 -0500537 sde_crtc = to_sde_crtc(crtc);
538 sde_cstate = to_sde_crtc_state(crtc->state);
539
Alan Kwong97abd432017-05-11 14:52:23 -0700540 SDE_DEBUG("crtc:%d stop_req:%d core_clk:%llu\n",
Alan Kwong9aa061c2016-11-06 21:17:12 -0500541 crtc->base.id, stop_req, kms->perf.core_clk_rate);
542
Ingrid Gallardo27d45122017-10-05 11:53:11 -0700543 /*
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 Kwong751cf462017-06-08 10:26:46 -0400552 old = &sde_crtc->cur_perf;
Ingrid Gallardo27d45122017-10-05 11:53:11 -0700553 new = &sde_crtc->new_perf;
Alan Kwong9aa061c2016-11-06 21:17:12 -0500554
555 if (_sde_core_perf_crtc_is_power_on(crtc) && !stop_req) {
Alan Kwong0230a102017-05-16 11:36:44 -0700556 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 Gallardo17bac472017-12-01 17:42:11 -0800564
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 Kwong0230a102017-05-16 11:36:44 -0700570 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 Gallardo17bac472017-12-01 17:42:11 -0800575 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 Kwong0230a102017-05-16 11:36:44 -0700590 old->max_per_pipe_ib[i] =
591 new->max_per_pipe_ib[i];
592 update_bus |= BIT(i);
593 }
Alan Kwong9aa061c2016-11-06 21:17:12 -0500594
Alan Kwong0230a102017-05-16 11:36:44 -0700595 /* display rsc override during solver mode */
596 if (kms->perf.bw_vote_mode == DISP_RSC_MODE &&
Dhaval Patel378a9b42017-05-23 13:11:24 -0700597 get_sde_rsc_current_state(SDE_RSC_INDEX) ==
Alan Kwong0230a102017-05-16 11:36:44 -0700598 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 Patel378a9b42017-05-23 13:11:24 -0700615 }
616 }
617
Alan Kwong9aa061c2016-11-06 21:17:12 -0500618 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 Kwong0230a102017-05-16 11:36:44 -0700629 update_bus = ~0;
Alan Kwong9aa061c2016-11-06 21:17:12 -0500630 update_clk = 1;
631 }
Alan Kwong0230a102017-05-16 11:36:44 -0700632 trace_sde_perf_crtc_update(crtc->base.id,
Ingrid Gallardoac3d09b2017-12-01 17:42:50 -0800633 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 Kwong9aa061c2016-11-06 21:17:12 -0500641
Alan Kwong0230a102017-05-16 11:36:44 -0700642 for (i = 0; i < SDE_POWER_HANDLE_DBUS_ID_MAX; i++) {
643 if (update_bus & BIT(i))
Ingrid Gallardo27d45122017-10-05 11:53:11 -0700644 _sde_core_perf_crtc_update_bus(kms, crtc, i, old);
Alan Kwong0230a102017-05-16 11:36:44 -0700645 }
Alan Kwong9aa061c2016-11-06 21:17:12 -0500646
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 Gallardo27d45122017-10-05 11:53:11 -0700652 clk_rate = _sde_core_perf_get_core_clk_rate(kms, old, crtc);
Dhaval Patel4d424602017-02-18 19:40:14 -0800653
Ingrid Gallardo27d45122017-10-05 11:53:11 -0700654 SDE_EVT32(kms->dev, stop_req, clk_rate, params_changed,
655 old->core_clk_rate, new->core_clk_rate);
Alan Kwong9aa061c2016-11-06 21:17:12 -0500656 ret = sde_power_clk_set_rate(&priv->phandle,
657 kms->perf.clk_name, clk_rate);
658 if (ret) {
Alan Kwong97abd432017-05-11 14:52:23 -0700659 SDE_ERROR("failed to set %s clock rate %llu\n",
Alan Kwong9aa061c2016-11-06 21:17:12 -0500660 kms->perf.clk_name, clk_rate);
Dhaval Patel4d424602017-02-18 19:40:14 -0800661 return;
Alan Kwong9aa061c2016-11-06 21:17:12 -0500662 }
663
664 kms->perf.core_clk_rate = clk_rate;
Alan Kwong97abd432017-05-11 14:52:23 -0700665 SDE_DEBUG("update clk rate = %lld HZ\n", clk_rate);
Alan Kwong9aa061c2016-11-06 21:17:12 -0500666 }
Alan Kwong9aa061c2016-11-06 21:17:12 -0500667}
668
Alan Kwong67a3f792016-11-01 23:16:53 -0400669#ifdef CONFIG_DEBUG_FS
670
Alan Kwong9aa061c2016-11-06 21:17:12 -0500671static 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 Kwong97abd432017-05-11 14:52:23 -0700676 u32 perf_mode = 0;
Alan Kwong9aa061c2016-11-06 21:17:12 -0500677 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 Kwong97abd432017-05-11 14:52:23 -0700690 if (kstrtouint(buf, 0, &perf_mode))
Alan Kwong9aa061c2016-11-06 21:17:12 -0500691 return -EFAULT;
692
Alan Kwong97abd432017-05-11 14:52:23 -0700693 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 Kwong9aa061c2016-11-06 21:17:12 -0500699 /* 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 Kwong97abd432017-05-11 14:52:23 -0700703 DRM_INFO("minimum performance mode\n");
704 } else if (perf_mode == SDE_PERF_MODE_NORMAL) {
Alan Kwong9aa061c2016-11-06 21:17:12 -0500705 /* reset the perf tune params to 0 */
706 perf->perf_tune.min_core_clk = 0;
707 perf->perf_tune.min_bus_vote = 0;
Alan Kwong97abd432017-05-11 14:52:23 -0700708 DRM_INFO("normal performance mode\n");
Alan Kwong9aa061c2016-11-06 21:17:12 -0500709 }
Alan Kwong97abd432017-05-11 14:52:23 -0700710 perf->perf_tune.mode = perf_mode;
711
Alan Kwong9aa061c2016-11-06 21:17:12 -0500712 return count;
713}
714
715static 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 Kwong97abd432017-05-11 14:52:23 -0700720 char buf[SDE_PERF_MODE_STRING_SIZE] = {'\0'};
Alan Kwong9aa061c2016-11-06 21:17:12 -0500721
722 if (!perf)
723 return -ENODEV;
724
725 if (*ppos)
726 return 0; /* the end */
727
Alan Kwong97abd432017-05-11 14:52:23 -0700728 len = snprintf(buf, sizeof(buf),
729 "mode %d min_mdp_clk %llu min_bus_vote %llu\n",
730 perf->perf_tune.mode,
Alan Kwong9aa061c2016-11-06 21:17:12 -0500731 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
744static 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 Atkinsonb020e0f2017-03-14 08:05:18 -0700750static void sde_core_perf_debugfs_destroy(struct sde_core_perf *perf)
Alan Kwong67a3f792016-11-01 23:16:53 -0400751{
752 debugfs_remove_recursive(perf->debugfs_root);
753 perf->debugfs_root = NULL;
754}
755
Lloyd Atkinsonb020e0f2017-03-14 08:05:18 -0700756int sde_core_perf_debugfs_init(struct sde_core_perf *perf,
Alan Kwong67a3f792016-11-01 23:16:53 -0400757 struct dentry *parent)
758{
Alan Kwong9aa061c2016-11-06 21:17:12 -0500759 struct sde_mdss_cfg *catalog = perf->catalog;
Alan Kwong67a3f792016-11-01 23:16:53 -0400760 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 Atkinson8de415a2017-05-23 11:31:16 -0400777 debugfs_create_u64("max_core_clk_rate", 0600, perf->debugfs_root,
Alan Kwong67a3f792016-11-01 23:16:53 -0400778 &perf->max_core_clk_rate);
Lloyd Atkinson8de415a2017-05-23 11:31:16 -0400779 debugfs_create_u64("core_clk_rate", 0600, perf->debugfs_root,
Alan Kwong67a3f792016-11-01 23:16:53 -0400780 &perf->core_clk_rate);
Lloyd Atkinson8de415a2017-05-23 11:31:16 -0400781 debugfs_create_u32("enable_bw_release", 0600, perf->debugfs_root,
Alan Kwong9aa061c2016-11-06 21:17:12 -0500782 (u32 *)&perf->enable_bw_release);
Lloyd Atkinson8de415a2017-05-23 11:31:16 -0400783 debugfs_create_u32("threshold_low", 0600, perf->debugfs_root,
Alan Kwong9aa061c2016-11-06 21:17:12 -0500784 (u32 *)&catalog->perf.max_bw_low);
Lloyd Atkinson8de415a2017-05-23 11:31:16 -0400785 debugfs_create_u32("threshold_high", 0600, perf->debugfs_root,
Alan Kwong9aa061c2016-11-06 21:17:12 -0500786 (u32 *)&catalog->perf.max_bw_high);
Narendra Muppallaa50934b2017-08-15 19:43:37 -0700787 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 Atkinson8de415a2017-05-23 11:31:16 -0400793 debugfs_create_file("perf_mode", 0600, perf->debugfs_root,
Alan Kwong9aa061c2016-11-06 21:17:12 -0500794 (u32 *)perf, &sde_core_perf_mode_fops);
Dhaval Pateldd2032a2017-04-11 10:50:36 -0700795 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 Atkinson8de415a2017-05-23 11:31:16 -0400799 debugfs_create_u64("fix_core_clk_rate", 0600, perf->debugfs_root,
Alan Kwong97abd432017-05-11 14:52:23 -0700800 &perf->fix_core_clk_rate);
Lloyd Atkinson8de415a2017-05-23 11:31:16 -0400801 debugfs_create_u64("fix_core_ib_vote", 0600, perf->debugfs_root,
Alan Kwong97abd432017-05-11 14:52:23 -0700802 &perf->fix_core_ib_vote);
Lloyd Atkinson8de415a2017-05-23 11:31:16 -0400803 debugfs_create_u64("fix_core_ab_vote", 0600, perf->debugfs_root,
Alan Kwong97abd432017-05-11 14:52:23 -0700804 &perf->fix_core_ab_vote);
Alan Kwong67a3f792016-11-01 23:16:53 -0400805
806 return 0;
807}
808#else
Lloyd Atkinsonb020e0f2017-03-14 08:05:18 -0700809static void sde_core_perf_debugfs_destroy(struct sde_core_perf *perf)
Alan Kwong67a3f792016-11-01 23:16:53 -0400810{
811}
812
Lloyd Atkinsonb020e0f2017-03-14 08:05:18 -0700813int sde_core_perf_debugfs_init(struct sde_core_perf *perf,
Alan Kwong67a3f792016-11-01 23:16:53 -0400814 struct dentry *parent)
815{
816 return 0;
817}
818#endif
819
820void sde_core_perf_destroy(struct sde_core_perf *perf)
821{
822 if (!perf) {
823 SDE_ERROR("invalid parameters\n");
824 return;
825 }
826
Lloyd Atkinsonb020e0f2017-03-14 08:05:18 -0700827 sde_core_perf_debugfs_destroy(perf);
Alan Kwong67a3f792016-11-01 23:16:53 -0400828 perf->max_core_clk_rate = 0;
829 perf->core_clk = NULL;
Alan Kwong67a3f792016-11-01 23:16:53 -0400830 perf->clk_name = NULL;
831 perf->phandle = NULL;
832 perf->catalog = NULL;
833 perf->dev = NULL;
834}
835
836int 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 Atkinsonb020e0f2017-03-14 08:05:18 -0700841 char *clk_name)
Alan Kwong67a3f792016-11-01 23:16:53 -0400842{
Lloyd Atkinsonb020e0f2017-03-14 08:05:18 -0700843 if (!perf || !dev || !catalog || !phandle || !pclient || !clk_name) {
Alan Kwong67a3f792016-11-01 23:16:53 -0400844 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 Pateldd2032a2017-04-11 10:50:36 -0700853 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 Kwong67a3f792016-11-01 23:16:53 -0400859
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 Kwong6259a382017-04-04 06:18:02 -0700868 SDE_DEBUG("optional max core clk rate, use default\n");
869 perf->max_core_clk_rate = SDE_PERF_DEFAULT_MAX_CORE_CLK_RATE;
Alan Kwong67a3f792016-11-01 23:16:53 -0400870 }
871
Alan Kwong67a3f792016-11-01 23:16:53 -0400872 return 0;
873
874err:
875 sde_core_perf_destroy(perf);
876 return -ENODEV;
877}