]>
git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blob - drivers/gpu/drm/msm/disp/dpu1/dpu_vbif.c
1 // SPDX-License-Identifier: GPL-2.0-only
2 /* Copyright (c) 2015-2018, The Linux Foundation. All rights reserved.
5 #define pr_fmt(fmt) "[drm:%s:%d] " fmt, __func__, __LINE__
7 #include <linux/debugfs.h>
10 #include "dpu_hw_vbif.h"
11 #include "dpu_trace.h"
14 * _dpu_vbif_wait_for_xin_halt - wait for the xin to halt
15 * @vbif: Pointer to hardware vbif driver
16 * @xin_id: Client interface identifier
17 * @return: 0 if success; error code otherwise
19 static int _dpu_vbif_wait_for_xin_halt(struct dpu_hw_vbif
*vbif
, u32 xin_id
)
25 if (!vbif
|| !vbif
->cap
|| !vbif
->ops
.get_halt_ctrl
) {
26 DPU_ERROR("invalid arguments vbif %d\n", vbif
!= 0);
30 timeout
= ktime_add_us(ktime_get(), vbif
->cap
->xin_halt_timeout
);
32 status
= vbif
->ops
.get_halt_ctrl(vbif
, xin_id
);
35 if (ktime_compare_safe(ktime_get(), timeout
) > 0) {
36 status
= vbif
->ops
.get_halt_ctrl(vbif
, xin_id
);
39 usleep_range(501, 1000);
44 DPU_ERROR("VBIF %d client %d not halting. TIMEDOUT.\n",
45 vbif
->idx
- VBIF_0
, xin_id
);
48 DPU_DEBUG("VBIF %d client %d is halted\n",
49 vbif
->idx
- VBIF_0
, xin_id
);
56 * _dpu_vbif_apply_dynamic_ot_limit - determine OT based on usecase parameters
57 * @vbif: Pointer to hardware vbif driver
58 * @ot_lim: Pointer to OT limit to be modified
59 * @params: Pointer to usecase parameters
61 static void _dpu_vbif_apply_dynamic_ot_limit(struct dpu_hw_vbif
*vbif
,
62 u32
*ot_lim
, struct dpu_vbif_set_ot_params
*params
)
65 const struct dpu_vbif_dynamic_ot_tbl
*tbl
;
68 if (!vbif
|| !(vbif
->cap
->features
& BIT(DPU_VBIF_QOS_OTLIM
)))
71 /* Dynamic OT setting done only for WFD */
75 pps
= params
->frame_rate
;
77 pps
*= params
->height
;
79 tbl
= params
->rd
? &vbif
->cap
->dynamic_ot_rd_tbl
:
80 &vbif
->cap
->dynamic_ot_wr_tbl
;
82 for (i
= 0; i
< tbl
->count
; i
++) {
83 if (pps
<= tbl
->cfg
[i
].pps
) {
84 *ot_lim
= tbl
->cfg
[i
].ot_limit
;
89 DPU_DEBUG("vbif:%d xin:%d w:%d h:%d fps:%d pps:%llu ot:%u\n",
90 vbif
->idx
- VBIF_0
, params
->xin_id
,
91 params
->width
, params
->height
, params
->frame_rate
,
96 * _dpu_vbif_get_ot_limit - get OT based on usecase & configuration parameters
97 * @vbif: Pointer to hardware vbif driver
98 * @params: Pointer to usecase parameters
101 static u32
_dpu_vbif_get_ot_limit(struct dpu_hw_vbif
*vbif
,
102 struct dpu_vbif_set_ot_params
*params
)
107 if (!vbif
|| !vbif
->cap
) {
108 DPU_ERROR("invalid arguments vbif %d\n", vbif
!= 0);
112 if (vbif
->cap
->default_ot_wr_limit
&& !params
->rd
)
113 ot_lim
= vbif
->cap
->default_ot_wr_limit
;
114 else if (vbif
->cap
->default_ot_rd_limit
&& params
->rd
)
115 ot_lim
= vbif
->cap
->default_ot_rd_limit
;
118 * If default ot is not set from dt/catalog,
119 * then do not configure it.
124 /* Modify the limits if the target and the use case requires it */
125 _dpu_vbif_apply_dynamic_ot_limit(vbif
, &ot_lim
, params
);
127 if (vbif
&& vbif
->ops
.get_limit_conf
) {
128 val
= vbif
->ops
.get_limit_conf(vbif
,
129 params
->xin_id
, params
->rd
);
135 DPU_DEBUG("vbif:%d xin:%d ot_lim:%d\n",
136 vbif
->idx
- VBIF_0
, params
->xin_id
, ot_lim
);
141 * dpu_vbif_set_ot_limit - set OT based on usecase & configuration parameters
142 * @vbif: Pointer to hardware vbif driver
143 * @params: Pointer to usecase parameters
145 * Note this function would block waiting for bus halt.
147 void dpu_vbif_set_ot_limit(struct dpu_kms
*dpu_kms
,
148 struct dpu_vbif_set_ot_params
*params
)
150 struct dpu_hw_vbif
*vbif
= NULL
;
151 struct dpu_hw_mdp
*mdp
;
152 bool forced_on
= false;
157 DPU_ERROR("invalid arguments\n");
160 mdp
= dpu_kms
->hw_mdp
;
162 for (i
= 0; i
< ARRAY_SIZE(dpu_kms
->hw_vbif
); i
++) {
163 if (dpu_kms
->hw_vbif
[i
] &&
164 dpu_kms
->hw_vbif
[i
]->idx
== params
->vbif_idx
)
165 vbif
= dpu_kms
->hw_vbif
[i
];
169 DPU_DEBUG("invalid arguments vbif %d mdp %d\n",
170 vbif
!= 0, mdp
!= 0);
174 if (!mdp
->ops
.setup_clk_force_ctrl
||
175 !vbif
->ops
.set_limit_conf
||
176 !vbif
->ops
.set_halt_ctrl
)
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
);
183 ot_lim
= _dpu_vbif_get_ot_limit(vbif
, params
) & 0xFF;
188 trace_dpu_perf_set_ot(params
->num
, params
->xin_id
, ot_lim
,
191 forced_on
= mdp
->ops
.setup_clk_force_ctrl(mdp
, params
->clk_ctrl
, true);
193 vbif
->ops
.set_limit_conf(vbif
, params
->xin_id
, params
->rd
, ot_lim
);
195 vbif
->ops
.set_halt_ctrl(vbif
, params
->xin_id
, true);
197 ret
= _dpu_vbif_wait_for_xin_halt(vbif
, params
->xin_id
);
199 trace_dpu_vbif_wait_xin_halt_fail(vbif
->idx
, params
->xin_id
);
201 vbif
->ops
.set_halt_ctrl(vbif
, params
->xin_id
, false);
204 mdp
->ops
.setup_clk_force_ctrl(mdp
, params
->clk_ctrl
, false);
207 void dpu_vbif_set_qos_remap(struct dpu_kms
*dpu_kms
,
208 struct dpu_vbif_set_qos_params
*params
)
210 struct dpu_hw_vbif
*vbif
= NULL
;
211 struct dpu_hw_mdp
*mdp
;
212 bool forced_on
= false;
213 const struct dpu_vbif_qos_tbl
*qos_tbl
;
216 if (!dpu_kms
|| !params
|| !dpu_kms
->hw_mdp
) {
217 DPU_ERROR("invalid arguments\n");
220 mdp
= dpu_kms
->hw_mdp
;
222 for (i
= 0; i
< ARRAY_SIZE(dpu_kms
->hw_vbif
); i
++) {
223 if (dpu_kms
->hw_vbif
[i
] &&
224 dpu_kms
->hw_vbif
[i
]->idx
== params
->vbif_idx
) {
225 vbif
= dpu_kms
->hw_vbif
[i
];
230 if (!vbif
|| !vbif
->cap
) {
231 DPU_ERROR("invalid vbif %d\n", params
->vbif_idx
);
235 if (!vbif
->ops
.set_qos_remap
|| !mdp
->ops
.setup_clk_force_ctrl
) {
236 DPU_DEBUG("qos remap not supported\n");
240 qos_tbl
= params
->is_rt
? &vbif
->cap
->qos_rt_tbl
:
241 &vbif
->cap
->qos_nrt_tbl
;
243 if (!qos_tbl
->npriority_lvl
|| !qos_tbl
->priority_lvl
) {
244 DPU_DEBUG("qos tbl not defined\n");
248 forced_on
= mdp
->ops
.setup_clk_force_ctrl(mdp
, params
->clk_ctrl
, true);
250 for (i
= 0; i
< qos_tbl
->npriority_lvl
; i
++) {
251 DPU_DEBUG("vbif:%d xin:%d lvl:%d/%d\n",
252 params
->vbif_idx
, params
->xin_id
, i
,
253 qos_tbl
->priority_lvl
[i
]);
254 vbif
->ops
.set_qos_remap(vbif
, params
->xin_id
, i
,
255 qos_tbl
->priority_lvl
[i
]);
259 mdp
->ops
.setup_clk_force_ctrl(mdp
, params
->clk_ctrl
, false);
262 void dpu_vbif_clear_errors(struct dpu_kms
*dpu_kms
)
264 struct dpu_hw_vbif
*vbif
;
268 DPU_ERROR("invalid argument\n");
272 for (i
= 0; i
< ARRAY_SIZE(dpu_kms
->hw_vbif
); i
++) {
273 vbif
= dpu_kms
->hw_vbif
[i
];
274 if (vbif
&& vbif
->ops
.clear_errors
) {
275 vbif
->ops
.clear_errors(vbif
, &pnd
, &src
);
277 DRM_DEBUG_KMS("VBIF %d: pnd 0x%X, src 0x%X\n",
278 vbif
->idx
- VBIF_0
, pnd
, src
);
284 void dpu_vbif_init_memtypes(struct dpu_kms
*dpu_kms
)
286 struct dpu_hw_vbif
*vbif
;
290 DPU_ERROR("invalid argument\n");
294 for (i
= 0; i
< ARRAY_SIZE(dpu_kms
->hw_vbif
); i
++) {
295 vbif
= dpu_kms
->hw_vbif
[i
];
296 if (vbif
&& vbif
->cap
&& vbif
->ops
.set_mem_type
) {
297 for (j
= 0; j
< vbif
->cap
->memtype_count
; j
++)
298 vbif
->ops
.set_mem_type(
299 vbif
, j
, vbif
->cap
->memtype
[j
]);
304 #ifdef CONFIG_DEBUG_FS
306 void dpu_debugfs_vbif_init(struct dpu_kms
*dpu_kms
, struct dentry
*debugfs_root
)
309 struct dentry
*entry
, *debugfs_vbif
;
312 entry
= debugfs_create_dir("vbif", debugfs_root
);
313 if (IS_ERR_OR_NULL(entry
))
316 for (i
= 0; i
< dpu_kms
->catalog
->vbif_count
; i
++) {
317 struct dpu_vbif_cfg
*vbif
= &dpu_kms
->catalog
->vbif
[i
];
319 snprintf(vbif_name
, sizeof(vbif_name
), "%d", vbif
->id
);
321 debugfs_vbif
= debugfs_create_dir(vbif_name
, entry
);
322 if (IS_ERR_OR_NULL(debugfs_vbif
))
325 debugfs_create_u32("features", 0600, debugfs_vbif
,
326 (u32
*)&vbif
->features
);
328 debugfs_create_u32("xin_halt_timeout", 0400, debugfs_vbif
,
329 (u32
*)&vbif
->xin_halt_timeout
);
331 debugfs_create_u32("default_rd_ot_limit", 0400, debugfs_vbif
,
332 (u32
*)&vbif
->default_ot_rd_limit
);
334 debugfs_create_u32("default_wr_ot_limit", 0400, debugfs_vbif
,
335 (u32
*)&vbif
->default_ot_wr_limit
);
337 for (j
= 0; j
< vbif
->dynamic_ot_rd_tbl
.count
; j
++) {
338 struct dpu_vbif_dynamic_ot_cfg
*cfg
=
339 &vbif
->dynamic_ot_rd_tbl
.cfg
[j
];
341 snprintf(vbif_name
, sizeof(vbif_name
),
342 "dynamic_ot_rd_%d_pps", j
);
343 debugfs_create_u64(vbif_name
, 0400, debugfs_vbif
,
345 snprintf(vbif_name
, sizeof(vbif_name
),
346 "dynamic_ot_rd_%d_ot_limit", j
);
347 debugfs_create_u32(vbif_name
, 0400, debugfs_vbif
,
348 (u32
*)&cfg
->ot_limit
);
351 for (j
= 0; j
< vbif
->dynamic_ot_wr_tbl
.count
; j
++) {
352 struct dpu_vbif_dynamic_ot_cfg
*cfg
=
353 &vbif
->dynamic_ot_wr_tbl
.cfg
[j
];
355 snprintf(vbif_name
, sizeof(vbif_name
),
356 "dynamic_ot_wr_%d_pps", j
);
357 debugfs_create_u64(vbif_name
, 0400, debugfs_vbif
,
359 snprintf(vbif_name
, sizeof(vbif_name
),
360 "dynamic_ot_wr_%d_ot_limit", j
);
361 debugfs_create_u32(vbif_name
, 0400, debugfs_vbif
,
362 (u32
*)&cfg
->ot_limit
);