• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0-only
2 /* Copyright (c) 2015-2018, The Linux Foundation. All rights reserved.
3  */
4 
5 #define pr_fmt(fmt)	"[drm:%s:%d] " fmt, __func__, __LINE__
6 
7 #include <linux/debugfs.h>
8 #include <linux/delay.h>
9 
10 #include "dpu_vbif.h"
11 #include "dpu_hw_vbif.h"
12 #include "dpu_trace.h"
13 
dpu_get_vbif(struct dpu_kms * dpu_kms,enum dpu_vbif vbif_idx)14 static struct dpu_hw_vbif *dpu_get_vbif(struct dpu_kms *dpu_kms, enum dpu_vbif vbif_idx)
15 {
16 	if (vbif_idx < ARRAY_SIZE(dpu_kms->hw_vbif))
17 		return dpu_kms->hw_vbif[vbif_idx];
18 
19 	return NULL;
20 }
21 
22 /**
23  * _dpu_vbif_wait_for_xin_halt - wait for the xin to halt
24  * @vbif:	Pointer to hardware vbif driver
25  * @xin_id:	Client interface identifier
26  * @return:	0 if success; error code otherwise
27  */
_dpu_vbif_wait_for_xin_halt(struct dpu_hw_vbif * vbif,u32 xin_id)28 static int _dpu_vbif_wait_for_xin_halt(struct dpu_hw_vbif *vbif, u32 xin_id)
29 {
30 	ktime_t timeout;
31 	bool status;
32 	int rc;
33 
34 	if (!vbif || !vbif->cap || !vbif->ops.get_halt_ctrl) {
35 		DPU_ERROR("invalid arguments vbif %d\n", vbif != NULL);
36 		return -EINVAL;
37 	}
38 
39 	timeout = ktime_add_us(ktime_get(), vbif->cap->xin_halt_timeout);
40 	for (;;) {
41 		status = vbif->ops.get_halt_ctrl(vbif, xin_id);
42 		if (status)
43 			break;
44 		if (ktime_compare_safe(ktime_get(), timeout) > 0) {
45 			status = vbif->ops.get_halt_ctrl(vbif, xin_id);
46 			break;
47 		}
48 		usleep_range(501, 1000);
49 	}
50 
51 	if (!status) {
52 		rc = -ETIMEDOUT;
53 		DPU_ERROR("VBIF %d client %d not halting. TIMEDOUT.\n",
54 				vbif->idx - VBIF_0, xin_id);
55 	} else {
56 		rc = 0;
57 		DPU_DEBUG("VBIF %d client %d is halted\n",
58 				vbif->idx - VBIF_0, xin_id);
59 	}
60 
61 	return rc;
62 }
63 
64 /**
65  * _dpu_vbif_apply_dynamic_ot_limit - determine OT based on usecase parameters
66  * @vbif:	Pointer to hardware vbif driver
67  * @ot_lim:	Pointer to OT limit to be modified
68  * @params:	Pointer to usecase parameters
69  */
_dpu_vbif_apply_dynamic_ot_limit(struct dpu_hw_vbif * vbif,u32 * ot_lim,struct dpu_vbif_set_ot_params * params)70 static void _dpu_vbif_apply_dynamic_ot_limit(struct dpu_hw_vbif *vbif,
71 		u32 *ot_lim, struct dpu_vbif_set_ot_params *params)
72 {
73 	u64 pps;
74 	const struct dpu_vbif_dynamic_ot_tbl *tbl;
75 	u32 i;
76 
77 	if (!vbif || !(vbif->cap->features & BIT(DPU_VBIF_QOS_OTLIM)))
78 		return;
79 
80 	/* Dynamic OT setting done only for WFD */
81 	if (!params->is_wfd)
82 		return;
83 
84 	pps = params->frame_rate;
85 	pps *= params->width;
86 	pps *= params->height;
87 
88 	tbl = params->rd ? &vbif->cap->dynamic_ot_rd_tbl :
89 			&vbif->cap->dynamic_ot_wr_tbl;
90 
91 	for (i = 0; i < tbl->count; i++) {
92 		if (pps <= tbl->cfg[i].pps) {
93 			*ot_lim = tbl->cfg[i].ot_limit;
94 			break;
95 		}
96 	}
97 
98 	DPU_DEBUG("vbif:%d xin:%d w:%d h:%d fps:%d pps:%llu ot:%u\n",
99 			vbif->idx - VBIF_0, params->xin_id,
100 			params->width, params->height, params->frame_rate,
101 			pps, *ot_lim);
102 }
103 
104 /**
105  * _dpu_vbif_get_ot_limit - get OT based on usecase & configuration parameters
106  * @vbif:	Pointer to hardware vbif driver
107  * @params:	Pointer to usecase parameters
108  * @return:	OT limit
109  */
_dpu_vbif_get_ot_limit(struct dpu_hw_vbif * vbif,struct dpu_vbif_set_ot_params * params)110 static u32 _dpu_vbif_get_ot_limit(struct dpu_hw_vbif *vbif,
111 	struct dpu_vbif_set_ot_params *params)
112 {
113 	u32 ot_lim = 0;
114 	u32 val;
115 
116 	if (!vbif || !vbif->cap) {
117 		DPU_ERROR("invalid arguments vbif %d\n", vbif != NULL);
118 		return -EINVAL;
119 	}
120 
121 	if (vbif->cap->default_ot_wr_limit && !params->rd)
122 		ot_lim = vbif->cap->default_ot_wr_limit;
123 	else if (vbif->cap->default_ot_rd_limit && params->rd)
124 		ot_lim = vbif->cap->default_ot_rd_limit;
125 
126 	/*
127 	 * If default ot is not set from dt/catalog,
128 	 * then do not configure it.
129 	 */
130 	if (ot_lim == 0)
131 		goto exit;
132 
133 	/* Modify the limits if the target and the use case requires it */
134 	_dpu_vbif_apply_dynamic_ot_limit(vbif, &ot_lim, params);
135 
136 	if (vbif && vbif->ops.get_limit_conf) {
137 		val = vbif->ops.get_limit_conf(vbif,
138 				params->xin_id, params->rd);
139 		if (val == ot_lim)
140 			ot_lim = 0;
141 	}
142 
143 exit:
144 	DPU_DEBUG("vbif:%d xin:%d ot_lim:%d\n",
145 			vbif->idx - VBIF_0, params->xin_id, ot_lim);
146 	return ot_lim;
147 }
148 
149 /**
150  * dpu_vbif_set_ot_limit - set OT based on usecase & configuration parameters
151  * @vbif:	Pointer to hardware vbif driver
152  * @params:	Pointer to usecase parameters
153  *
154  * Note this function would block waiting for bus halt.
155  */
dpu_vbif_set_ot_limit(struct dpu_kms * dpu_kms,struct dpu_vbif_set_ot_params * params)156 void dpu_vbif_set_ot_limit(struct dpu_kms *dpu_kms,
157 		struct dpu_vbif_set_ot_params *params)
158 {
159 	struct dpu_hw_vbif *vbif;
160 	struct dpu_hw_mdp *mdp;
161 	bool forced_on = false;
162 	u32 ot_lim;
163 	int ret;
164 
165 	mdp = dpu_kms->hw_mdp;
166 
167 	vbif = dpu_get_vbif(dpu_kms, params->vbif_idx);
168 	if (!vbif || !mdp) {
169 		DPU_DEBUG("invalid arguments vbif %d mdp %d\n",
170 				vbif != NULL, mdp != NULL);
171 		return;
172 	}
173 
174 	if (!mdp->ops.setup_clk_force_ctrl ||
175 			!vbif->ops.set_limit_conf ||
176 			!vbif->ops.set_halt_ctrl)
177 		return;
178 
179 	/* set write_gather_en for all write clients */
180 	if (vbif->ops.set_write_gather_en && !params->rd)
181 		vbif->ops.set_write_gather_en(vbif, params->xin_id);
182 
183 	ot_lim = _dpu_vbif_get_ot_limit(vbif, params) & 0xFF;
184 
185 	if (ot_lim == 0)
186 		return;
187 
188 	trace_dpu_perf_set_ot(params->num, params->xin_id, ot_lim,
189 		params->vbif_idx);
190 
191 	forced_on = mdp->ops.setup_clk_force_ctrl(mdp, params->clk_ctrl, true);
192 
193 	vbif->ops.set_limit_conf(vbif, params->xin_id, params->rd, ot_lim);
194 
195 	vbif->ops.set_halt_ctrl(vbif, params->xin_id, true);
196 
197 	ret = _dpu_vbif_wait_for_xin_halt(vbif, params->xin_id);
198 	if (ret)
199 		trace_dpu_vbif_wait_xin_halt_fail(vbif->idx, params->xin_id);
200 
201 	vbif->ops.set_halt_ctrl(vbif, params->xin_id, false);
202 
203 	if (forced_on)
204 		mdp->ops.setup_clk_force_ctrl(mdp, params->clk_ctrl, false);
205 }
206 
dpu_vbif_set_qos_remap(struct dpu_kms * dpu_kms,struct dpu_vbif_set_qos_params * params)207 void dpu_vbif_set_qos_remap(struct dpu_kms *dpu_kms,
208 		struct dpu_vbif_set_qos_params *params)
209 {
210 	struct dpu_hw_vbif *vbif;
211 	struct dpu_hw_mdp *mdp;
212 	bool forced_on = false;
213 	const struct dpu_vbif_qos_tbl *qos_tbl;
214 	int i;
215 
216 	if (!params || !dpu_kms->hw_mdp) {
217 		DPU_ERROR("invalid arguments\n");
218 		return;
219 	}
220 	mdp = dpu_kms->hw_mdp;
221 
222 	vbif = dpu_get_vbif(dpu_kms, params->vbif_idx);
223 
224 	if (!vbif || !vbif->cap) {
225 		DPU_ERROR("invalid vbif %d\n", params->vbif_idx);
226 		return;
227 	}
228 
229 	if (!vbif->ops.set_qos_remap || !mdp->ops.setup_clk_force_ctrl) {
230 		DPU_DEBUG("qos remap not supported\n");
231 		return;
232 	}
233 
234 	qos_tbl = params->is_rt ? &vbif->cap->qos_rt_tbl :
235 			&vbif->cap->qos_nrt_tbl;
236 
237 	if (!qos_tbl->npriority_lvl || !qos_tbl->priority_lvl) {
238 		DPU_DEBUG("qos tbl not defined\n");
239 		return;
240 	}
241 
242 	forced_on = mdp->ops.setup_clk_force_ctrl(mdp, params->clk_ctrl, true);
243 
244 	for (i = 0; i < qos_tbl->npriority_lvl; i++) {
245 		DPU_DEBUG("vbif:%d xin:%d lvl:%d/%d\n",
246 				params->vbif_idx, params->xin_id, i,
247 				qos_tbl->priority_lvl[i]);
248 		vbif->ops.set_qos_remap(vbif, params->xin_id, i,
249 				qos_tbl->priority_lvl[i]);
250 	}
251 
252 	if (forced_on)
253 		mdp->ops.setup_clk_force_ctrl(mdp, params->clk_ctrl, false);
254 }
255 
dpu_vbif_clear_errors(struct dpu_kms * dpu_kms)256 void dpu_vbif_clear_errors(struct dpu_kms *dpu_kms)
257 {
258 	struct dpu_hw_vbif *vbif;
259 	u32 i, pnd, src;
260 
261 	for (i = 0; i < ARRAY_SIZE(dpu_kms->hw_vbif); i++) {
262 		vbif = dpu_kms->hw_vbif[i];
263 		if (vbif && vbif->ops.clear_errors) {
264 			vbif->ops.clear_errors(vbif, &pnd, &src);
265 			if (pnd || src) {
266 				DRM_DEBUG_KMS("VBIF %d: pnd 0x%X, src 0x%X\n",
267 					      vbif->idx - VBIF_0, pnd, src);
268 			}
269 		}
270 	}
271 }
272 
dpu_vbif_init_memtypes(struct dpu_kms * dpu_kms)273 void dpu_vbif_init_memtypes(struct dpu_kms *dpu_kms)
274 {
275 	struct dpu_hw_vbif *vbif;
276 	int i, j;
277 
278 	for (i = 0; i < ARRAY_SIZE(dpu_kms->hw_vbif); i++) {
279 		vbif = dpu_kms->hw_vbif[i];
280 		if (vbif && vbif->cap && vbif->ops.set_mem_type) {
281 			for (j = 0; j < vbif->cap->memtype_count; j++)
282 				vbif->ops.set_mem_type(
283 						vbif, j, vbif->cap->memtype[j]);
284 		}
285 	}
286 }
287 
288 #ifdef CONFIG_DEBUG_FS
289 
dpu_debugfs_vbif_init(struct dpu_kms * dpu_kms,struct dentry * debugfs_root)290 void dpu_debugfs_vbif_init(struct dpu_kms *dpu_kms, struct dentry *debugfs_root)
291 {
292 	char vbif_name[32];
293 	struct dentry *entry, *debugfs_vbif;
294 	int i, j;
295 
296 	entry = debugfs_create_dir("vbif", debugfs_root);
297 
298 	for (i = 0; i < dpu_kms->catalog->vbif_count; i++) {
299 		const struct dpu_vbif_cfg *vbif = &dpu_kms->catalog->vbif[i];
300 
301 		snprintf(vbif_name, sizeof(vbif_name), "%d", vbif->id);
302 
303 		debugfs_vbif = debugfs_create_dir(vbif_name, entry);
304 
305 		debugfs_create_u32("features", 0600, debugfs_vbif,
306 			(u32 *)&vbif->features);
307 
308 		debugfs_create_u32("xin_halt_timeout", 0400, debugfs_vbif,
309 			(u32 *)&vbif->xin_halt_timeout);
310 
311 		debugfs_create_u32("default_rd_ot_limit", 0400, debugfs_vbif,
312 			(u32 *)&vbif->default_ot_rd_limit);
313 
314 		debugfs_create_u32("default_wr_ot_limit", 0400, debugfs_vbif,
315 			(u32 *)&vbif->default_ot_wr_limit);
316 
317 		for (j = 0; j < vbif->dynamic_ot_rd_tbl.count; j++) {
318 			const struct dpu_vbif_dynamic_ot_cfg *cfg =
319 					&vbif->dynamic_ot_rd_tbl.cfg[j];
320 
321 			snprintf(vbif_name, sizeof(vbif_name),
322 					"dynamic_ot_rd_%d_pps", j);
323 			debugfs_create_u64(vbif_name, 0400, debugfs_vbif,
324 					(u64 *)&cfg->pps);
325 			snprintf(vbif_name, sizeof(vbif_name),
326 					"dynamic_ot_rd_%d_ot_limit", j);
327 			debugfs_create_u32(vbif_name, 0400, debugfs_vbif,
328 					(u32 *)&cfg->ot_limit);
329 		}
330 
331 		for (j = 0; j < vbif->dynamic_ot_wr_tbl.count; j++) {
332 			const struct dpu_vbif_dynamic_ot_cfg *cfg =
333 					&vbif->dynamic_ot_wr_tbl.cfg[j];
334 
335 			snprintf(vbif_name, sizeof(vbif_name),
336 					"dynamic_ot_wr_%d_pps", j);
337 			debugfs_create_u64(vbif_name, 0400, debugfs_vbif,
338 					(u64 *)&cfg->pps);
339 			snprintf(vbif_name, sizeof(vbif_name),
340 					"dynamic_ot_wr_%d_ot_limit", j);
341 			debugfs_create_u32(vbif_name, 0400, debugfs_vbif,
342 					(u32 *)&cfg->ot_limit);
343 		}
344 	}
345 }
346 #endif
347