2 * Copyright (C) 2014-2018 The Linux Foundation. All rights reserved.
3 * Copyright (C) 2013 Red Hat
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 as published by
8 * the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * You should have received a copy of the GNU General Public License along with
16 * this program. If not, see <http://www.gnu.org/licenses/>.
19 #define pr_fmt(fmt) "[drm:%s:%d] " fmt, __func__, __LINE__
21 #include <linux/debugfs.h>
22 #include <linux/dma-buf.h>
26 #include "dpu_formats.h"
27 #include "dpu_hw_sspp.h"
28 #include "dpu_hw_catalog_format.h"
29 #include "dpu_trace.h"
32 #include "dpu_plane.h"
34 #define DPU_DEBUG_PLANE(pl, fmt, ...) DPU_DEBUG("plane%d " fmt,\
35 (pl) ? (pl)->base.base.id : -1, ##__VA_ARGS__)
37 #define DPU_ERROR_PLANE(pl, fmt, ...) DPU_ERROR("plane%d " fmt,\
38 (pl) ? (pl)->base.base.id : -1, ##__VA_ARGS__)
40 #define DECIMATED_DIMENSION(dim, deci) (((dim) + ((1 << (deci)) - 1)) >> (deci))
41 #define PHASE_STEP_SHIFT 21
42 #define PHASE_STEP_UNIT_SCALE ((int) (1 << PHASE_STEP_SHIFT))
43 #define PHASE_RESIDUAL 15
45 #define SHARP_STRENGTH_DEFAULT 32
46 #define SHARP_EDGE_THR_DEFAULT 112
47 #define SHARP_SMOOTH_THR_DEFAULT 8
48 #define SHARP_NOISE_THR_DEFAULT 2
50 #define DPU_NAME_SIZE 12
52 #define DPU_PLANE_COLOR_FILL_FLAG BIT(31)
53 #define DPU_ZPOS_MAX 255
55 /* multirect rect index */
62 #define DPU_QSEED3_DEFAULT_PRELOAD_H 0x4
63 #define DPU_QSEED3_DEFAULT_PRELOAD_V 0x3
65 #define DEFAULT_REFRESH_RATE 60
68 * enum dpu_plane_qos - Different qos configurations for each pipe
70 * @DPU_PLANE_QOS_VBLANK_CTRL: Setup VBLANK qos for the pipe.
71 * @DPU_PLANE_QOS_VBLANK_AMORTIZE: Enables Amortization within pipe.
72 * this configuration is mutually exclusive from VBLANK_CTRL.
73 * @DPU_PLANE_QOS_PANIC_CTRL: Setup panic for the pipe.
76 DPU_PLANE_QOS_VBLANK_CTRL = BIT(0),
77 DPU_PLANE_QOS_VBLANK_AMORTIZE = BIT(1),
78 DPU_PLANE_QOS_PANIC_CTRL = BIT(2),
82 * struct dpu_plane - local dpu plane structure
83 * @aspace: address space pointer
84 * @csc_ptr: Points to dpu_csc_cfg structure to use for current
85 * @mplane_list: List of multirect planes of the same pipe
86 * @catalog: Points to dpu catalog structure
87 * @revalidate: force revalidation of all the plane properties
90 struct drm_plane base;
95 uint32_t features; /* capabilities from catalog */
99 struct dpu_hw_pipe *pipe_hw;
100 struct dpu_hw_pipe_cfg pipe_cfg;
101 struct dpu_hw_pipe_qos_cfg pipe_qos_cfg;
106 struct list_head mplane_list;
107 struct dpu_mdss_cfg *catalog;
109 struct dpu_csc_cfg *csc_ptr;
111 const struct dpu_sspp_sub_blks *pipe_sblk;
112 char pipe_name[DPU_NAME_SIZE];
114 /* debugfs related stuff */
115 struct dentry *debugfs_root;
116 struct dpu_debugfs_regset32 debugfs_src;
117 struct dpu_debugfs_regset32 debugfs_scaler;
118 struct dpu_debugfs_regset32 debugfs_csc;
119 bool debugfs_default_scale;
122 #define to_dpu_plane(x) container_of(x, struct dpu_plane, base)
124 static struct dpu_kms *_dpu_plane_get_kms(struct drm_plane *plane)
126 struct msm_drm_private *priv;
128 if (!plane || !plane->dev)
130 priv = plane->dev->dev_private;
133 return to_dpu_kms(priv->kms);
136 static bool dpu_plane_enabled(struct drm_plane_state *state)
138 return state && state->fb && state->crtc;
141 static bool dpu_plane_sspp_enabled(struct drm_plane_state *state)
143 return state && state->crtc;
147 * _dpu_plane_calc_fill_level - calculate fill level of the given source format
148 * @plane: Pointer to drm plane
149 * @fmt: Pointer to source buffer format
150 * @src_wdith: width of source buffer
151 * Return: fill level corresponding to the source buffer/format or 0 if error
153 static inline int _dpu_plane_calc_fill_level(struct drm_plane *plane,
154 const struct dpu_format *fmt, u32 src_width)
156 struct dpu_plane *pdpu, *tmp;
157 struct dpu_plane_state *pstate;
161 if (!plane || !fmt || !plane->state || !src_width || !fmt->bpp) {
162 DPU_ERROR("invalid arguments\n");
166 pdpu = to_dpu_plane(plane);
167 pstate = to_dpu_plane_state(plane->state);
168 fixed_buff_size = pdpu->pipe_sblk->common->pixel_ram_size;
170 list_for_each_entry(tmp, &pdpu->mplane_list, mplane_list) {
171 if (!dpu_plane_enabled(tmp->base.state))
173 DPU_DEBUG("plane%d/%d src_width:%d/%d\n",
174 pdpu->base.base.id, tmp->base.base.id,
176 drm_rect_width(&tmp->pipe_cfg.src_rect));
177 src_width = max_t(u32, src_width,
178 drm_rect_width(&tmp->pipe_cfg.src_rect));
181 if (fmt->fetch_planes == DPU_PLANE_PSEUDO_PLANAR) {
182 if (fmt->chroma_sample == DPU_CHROMA_420) {
184 total_fl = (fixed_buff_size / 2) /
185 ((src_width + 32) * fmt->bpp);
188 total_fl = (fixed_buff_size / 2) * 2 /
189 ((src_width + 32) * fmt->bpp);
192 if (pstate->multirect_mode == DPU_SSPP_MULTIRECT_PARALLEL) {
193 total_fl = (fixed_buff_size / 2) * 2 /
194 ((src_width + 32) * fmt->bpp);
196 total_fl = (fixed_buff_size) * 2 /
197 ((src_width + 32) * fmt->bpp);
201 DPU_DEBUG("plane%u: pnum:%d fmt: %4.4s w:%u fl:%u\n",
202 plane->base.id, pdpu->pipe - SSPP_VIG0,
203 (char *)&fmt->base.pixel_format,
204 src_width, total_fl);
210 * _dpu_plane_get_qos_lut - get LUT mapping based on fill level
211 * @tbl: Pointer to LUT table
212 * @total_fl: fill level
213 * Return: LUT setting corresponding to the fill level
215 static u64 _dpu_plane_get_qos_lut(const struct dpu_qos_lut_tbl *tbl,
220 if (!tbl || !tbl->nentry || !tbl->entries)
223 for (i = 0; i < tbl->nentry; i++)
224 if (total_fl <= tbl->entries[i].fl)
225 return tbl->entries[i].lut;
227 /* if last fl is zero, use as default */
228 if (!tbl->entries[i-1].fl)
229 return tbl->entries[i-1].lut;
235 * _dpu_plane_set_qos_lut - set QoS LUT of the given plane
236 * @plane: Pointer to drm plane
237 * @fb: Pointer to framebuffer associated with the given plane
239 static void _dpu_plane_set_qos_lut(struct drm_plane *plane,
240 struct drm_framebuffer *fb)
242 struct dpu_plane *pdpu;
243 const struct dpu_format *fmt = NULL;
245 u32 total_fl = 0, lut_usage;
248 DPU_ERROR("invalid arguments plane %d fb %d\n",
249 plane != 0, fb != 0);
253 pdpu = to_dpu_plane(plane);
255 if (!pdpu->pipe_hw || !pdpu->pipe_sblk || !pdpu->catalog) {
256 DPU_ERROR("invalid arguments\n");
258 } else if (!pdpu->pipe_hw->ops.setup_creq_lut) {
262 if (!pdpu->is_rt_pipe) {
263 lut_usage = DPU_QOS_LUT_USAGE_NRT;
265 fmt = dpu_get_dpu_format_ext(
268 total_fl = _dpu_plane_calc_fill_level(plane, fmt,
269 drm_rect_width(&pdpu->pipe_cfg.src_rect));
271 if (fmt && DPU_FORMAT_IS_LINEAR(fmt))
272 lut_usage = DPU_QOS_LUT_USAGE_LINEAR;
274 lut_usage = DPU_QOS_LUT_USAGE_MACROTILE;
277 qos_lut = _dpu_plane_get_qos_lut(
278 &pdpu->catalog->perf.qos_lut_tbl[lut_usage], total_fl);
280 pdpu->pipe_qos_cfg.creq_lut = qos_lut;
282 trace_dpu_perf_set_qos_luts(pdpu->pipe - SSPP_VIG0,
283 (fmt) ? fmt->base.pixel_format : 0,
284 pdpu->is_rt_pipe, total_fl, qos_lut, lut_usage);
286 DPU_DEBUG("plane%u: pnum:%d fmt: %4.4s rt:%d fl:%u lut:0x%llx\n",
288 pdpu->pipe - SSPP_VIG0,
289 fmt ? (char *)&fmt->base.pixel_format : NULL,
290 pdpu->is_rt_pipe, total_fl, qos_lut);
292 pdpu->pipe_hw->ops.setup_creq_lut(pdpu->pipe_hw, &pdpu->pipe_qos_cfg);
296 * _dpu_plane_set_panic_lut - set danger/safe LUT of the given plane
297 * @plane: Pointer to drm plane
298 * @fb: Pointer to framebuffer associated with the given plane
300 static void _dpu_plane_set_danger_lut(struct drm_plane *plane,
301 struct drm_framebuffer *fb)
303 struct dpu_plane *pdpu;
304 const struct dpu_format *fmt = NULL;
305 u32 danger_lut, safe_lut;
308 DPU_ERROR("invalid arguments\n");
312 pdpu = to_dpu_plane(plane);
314 if (!pdpu->pipe_hw || !pdpu->pipe_sblk || !pdpu->catalog) {
315 DPU_ERROR("invalid arguments\n");
317 } else if (!pdpu->pipe_hw->ops.setup_danger_safe_lut) {
321 if (!pdpu->is_rt_pipe) {
322 danger_lut = pdpu->catalog->perf.danger_lut_tbl
323 [DPU_QOS_LUT_USAGE_NRT];
324 safe_lut = pdpu->catalog->perf.safe_lut_tbl
325 [DPU_QOS_LUT_USAGE_NRT];
327 fmt = dpu_get_dpu_format_ext(
331 if (fmt && DPU_FORMAT_IS_LINEAR(fmt)) {
332 danger_lut = pdpu->catalog->perf.danger_lut_tbl
333 [DPU_QOS_LUT_USAGE_LINEAR];
334 safe_lut = pdpu->catalog->perf.safe_lut_tbl
335 [DPU_QOS_LUT_USAGE_LINEAR];
337 danger_lut = pdpu->catalog->perf.danger_lut_tbl
338 [DPU_QOS_LUT_USAGE_MACROTILE];
339 safe_lut = pdpu->catalog->perf.safe_lut_tbl
340 [DPU_QOS_LUT_USAGE_MACROTILE];
344 pdpu->pipe_qos_cfg.danger_lut = danger_lut;
345 pdpu->pipe_qos_cfg.safe_lut = safe_lut;
347 trace_dpu_perf_set_danger_luts(pdpu->pipe - SSPP_VIG0,
348 (fmt) ? fmt->base.pixel_format : 0,
349 (fmt) ? fmt->fetch_mode : 0,
350 pdpu->pipe_qos_cfg.danger_lut,
351 pdpu->pipe_qos_cfg.safe_lut);
353 DPU_DEBUG("plane%u: pnum:%d fmt: %4.4s mode:%d luts[0x%x, 0x%x]\n",
355 pdpu->pipe - SSPP_VIG0,
356 fmt ? (char *)&fmt->base.pixel_format : NULL,
357 fmt ? fmt->fetch_mode : -1,
358 pdpu->pipe_qos_cfg.danger_lut,
359 pdpu->pipe_qos_cfg.safe_lut);
361 pdpu->pipe_hw->ops.setup_danger_safe_lut(pdpu->pipe_hw,
362 &pdpu->pipe_qos_cfg);
366 * _dpu_plane_set_qos_ctrl - set QoS control of the given plane
367 * @plane: Pointer to drm plane
368 * @enable: true to enable QoS control
369 * @flags: QoS control mode (enum dpu_plane_qos)
371 static void _dpu_plane_set_qos_ctrl(struct drm_plane *plane,
372 bool enable, u32 flags)
374 struct dpu_plane *pdpu;
377 DPU_ERROR("invalid arguments\n");
381 pdpu = to_dpu_plane(plane);
383 if (!pdpu->pipe_hw || !pdpu->pipe_sblk) {
384 DPU_ERROR("invalid arguments\n");
386 } else if (!pdpu->pipe_hw->ops.setup_qos_ctrl) {
390 if (flags & DPU_PLANE_QOS_VBLANK_CTRL) {
391 pdpu->pipe_qos_cfg.creq_vblank = pdpu->pipe_sblk->creq_vblank;
392 pdpu->pipe_qos_cfg.danger_vblank =
393 pdpu->pipe_sblk->danger_vblank;
394 pdpu->pipe_qos_cfg.vblank_en = enable;
397 if (flags & DPU_PLANE_QOS_VBLANK_AMORTIZE) {
398 /* this feature overrules previous VBLANK_CTRL */
399 pdpu->pipe_qos_cfg.vblank_en = false;
400 pdpu->pipe_qos_cfg.creq_vblank = 0; /* clear vblank bits */
403 if (flags & DPU_PLANE_QOS_PANIC_CTRL)
404 pdpu->pipe_qos_cfg.danger_safe_en = enable;
406 if (!pdpu->is_rt_pipe) {
407 pdpu->pipe_qos_cfg.vblank_en = false;
408 pdpu->pipe_qos_cfg.danger_safe_en = false;
411 DPU_DEBUG("plane%u: pnum:%d ds:%d vb:%d pri[0x%x, 0x%x] is_rt:%d\n",
413 pdpu->pipe - SSPP_VIG0,
414 pdpu->pipe_qos_cfg.danger_safe_en,
415 pdpu->pipe_qos_cfg.vblank_en,
416 pdpu->pipe_qos_cfg.creq_vblank,
417 pdpu->pipe_qos_cfg.danger_vblank,
420 pdpu->pipe_hw->ops.setup_qos_ctrl(pdpu->pipe_hw,
421 &pdpu->pipe_qos_cfg);
424 int dpu_plane_danger_signal_ctrl(struct drm_plane *plane, bool enable)
426 struct dpu_plane *pdpu;
427 struct msm_drm_private *priv;
428 struct dpu_kms *dpu_kms;
430 if (!plane || !plane->dev) {
431 DPU_ERROR("invalid arguments\n");
435 priv = plane->dev->dev_private;
436 if (!priv || !priv->kms) {
437 DPU_ERROR("invalid KMS reference\n");
441 dpu_kms = to_dpu_kms(priv->kms);
442 pdpu = to_dpu_plane(plane);
444 if (!pdpu->is_rt_pipe)
447 pm_runtime_get_sync(&dpu_kms->pdev->dev);
448 _dpu_plane_set_qos_ctrl(plane, enable, DPU_PLANE_QOS_PANIC_CTRL);
449 pm_runtime_put_sync(&dpu_kms->pdev->dev);
456 * _dpu_plane_set_ot_limit - set OT limit for the given plane
457 * @plane: Pointer to drm plane
458 * @crtc: Pointer to drm crtc
460 static void _dpu_plane_set_ot_limit(struct drm_plane *plane,
461 struct drm_crtc *crtc)
463 struct dpu_plane *pdpu;
464 struct dpu_vbif_set_ot_params ot_params;
465 struct msm_drm_private *priv;
466 struct dpu_kms *dpu_kms;
468 if (!plane || !plane->dev || !crtc) {
469 DPU_ERROR("invalid arguments plane %d crtc %d\n",
470 plane != 0, crtc != 0);
474 priv = plane->dev->dev_private;
475 if (!priv || !priv->kms) {
476 DPU_ERROR("invalid KMS reference\n");
480 dpu_kms = to_dpu_kms(priv->kms);
481 pdpu = to_dpu_plane(plane);
482 if (!pdpu->pipe_hw) {
483 DPU_ERROR("invalid pipe reference\n");
487 memset(&ot_params, 0, sizeof(ot_params));
488 ot_params.xin_id = pdpu->pipe_hw->cap->xin_id;
489 ot_params.num = pdpu->pipe_hw->idx - SSPP_NONE;
490 ot_params.width = drm_rect_width(&pdpu->pipe_cfg.src_rect);
491 ot_params.height = drm_rect_height(&pdpu->pipe_cfg.src_rect);
492 ot_params.is_wfd = !pdpu->is_rt_pipe;
493 ot_params.frame_rate = crtc->mode.vrefresh;
494 ot_params.vbif_idx = VBIF_RT;
495 ot_params.clk_ctrl = pdpu->pipe_hw->cap->clk_ctrl;
498 dpu_vbif_set_ot_limit(dpu_kms, &ot_params);
502 * _dpu_plane_set_vbif_qos - set vbif QoS for the given plane
503 * @plane: Pointer to drm plane
505 static void _dpu_plane_set_qos_remap(struct drm_plane *plane)
507 struct dpu_plane *pdpu;
508 struct dpu_vbif_set_qos_params qos_params;
509 struct msm_drm_private *priv;
510 struct dpu_kms *dpu_kms;
512 if (!plane || !plane->dev) {
513 DPU_ERROR("invalid arguments\n");
517 priv = plane->dev->dev_private;
518 if (!priv || !priv->kms) {
519 DPU_ERROR("invalid KMS reference\n");
523 dpu_kms = to_dpu_kms(priv->kms);
524 pdpu = to_dpu_plane(plane);
525 if (!pdpu->pipe_hw) {
526 DPU_ERROR("invalid pipe reference\n");
530 memset(&qos_params, 0, sizeof(qos_params));
531 qos_params.vbif_idx = VBIF_RT;
532 qos_params.clk_ctrl = pdpu->pipe_hw->cap->clk_ctrl;
533 qos_params.xin_id = pdpu->pipe_hw->cap->xin_id;
534 qos_params.num = pdpu->pipe_hw->idx - SSPP_VIG0;
535 qos_params.is_rt = pdpu->is_rt_pipe;
537 DPU_DEBUG("plane%d pipe:%d vbif:%d xin:%d rt:%d, clk_ctrl:%d\n",
538 plane->base.id, qos_params.num,
540 qos_params.xin_id, qos_params.is_rt,
541 qos_params.clk_ctrl);
543 dpu_vbif_set_qos_remap(dpu_kms, &qos_params);
547 * _dpu_plane_get_aspace: gets the address space
549 static int _dpu_plane_get_aspace(
550 struct dpu_plane *pdpu,
551 struct dpu_plane_state *pstate,
552 struct msm_gem_address_space **aspace)
556 if (!pdpu || !pstate || !aspace) {
557 DPU_ERROR("invalid parameters\n");
561 kms = _dpu_plane_get_kms(&pdpu->base);
563 DPU_ERROR("invalid kms\n");
567 *aspace = kms->base.aspace;
572 static inline void _dpu_plane_set_scanout(struct drm_plane *plane,
573 struct dpu_plane_state *pstate,
574 struct dpu_hw_pipe_cfg *pipe_cfg,
575 struct drm_framebuffer *fb)
577 struct dpu_plane *pdpu;
578 struct msm_gem_address_space *aspace = NULL;
581 if (!plane || !pstate || !pipe_cfg || !fb) {
583 "invalid arg(s), plane %d state %d cfg %d fb %d\n",
584 plane != 0, pstate != 0, pipe_cfg != 0, fb != 0);
588 pdpu = to_dpu_plane(plane);
589 if (!pdpu->pipe_hw) {
590 DPU_ERROR_PLANE(pdpu, "invalid pipe_hw\n");
594 ret = _dpu_plane_get_aspace(pdpu, pstate, &aspace);
596 DPU_ERROR_PLANE(pdpu, "Failed to get aspace %d\n", ret);
600 ret = dpu_format_populate_layout(aspace, fb, &pipe_cfg->layout);
602 DPU_DEBUG_PLANE(pdpu, "not updating same src addrs\n");
604 DPU_ERROR_PLANE(pdpu, "failed to get format layout, %d\n", ret);
605 else if (pdpu->pipe_hw->ops.setup_sourceaddress) {
606 trace_dpu_plane_set_scanout(pdpu->pipe_hw->idx,
608 pstate->multirect_index);
609 pdpu->pipe_hw->ops.setup_sourceaddress(pdpu->pipe_hw, pipe_cfg,
610 pstate->multirect_index);
614 static void _dpu_plane_setup_scaler3(struct dpu_plane *pdpu,
615 struct dpu_plane_state *pstate,
616 uint32_t src_w, uint32_t src_h, uint32_t dst_w, uint32_t dst_h,
617 struct dpu_hw_scaler3_cfg *scale_cfg,
618 const struct dpu_format *fmt,
619 uint32_t chroma_subsmpl_h, uint32_t chroma_subsmpl_v)
623 if (!pdpu || !pstate || !scale_cfg || !fmt || !chroma_subsmpl_h ||
626 "pdpu %d pstate %d scale_cfg %d fmt %d smp_h %d smp_v %d\n",
627 !!pdpu, !!pstate, !!scale_cfg, !!fmt, chroma_subsmpl_h,
632 memset(scale_cfg, 0, sizeof(*scale_cfg));
633 memset(&pstate->pixel_ext, 0, sizeof(struct dpu_hw_pixel_ext));
635 scale_cfg->phase_step_x[DPU_SSPP_COMP_0] =
636 mult_frac((1 << PHASE_STEP_SHIFT), src_w, dst_w);
637 scale_cfg->phase_step_y[DPU_SSPP_COMP_0] =
638 mult_frac((1 << PHASE_STEP_SHIFT), src_h, dst_h);
641 scale_cfg->phase_step_y[DPU_SSPP_COMP_1_2] =
642 scale_cfg->phase_step_y[DPU_SSPP_COMP_0] / chroma_subsmpl_v;
643 scale_cfg->phase_step_x[DPU_SSPP_COMP_1_2] =
644 scale_cfg->phase_step_x[DPU_SSPP_COMP_0] / chroma_subsmpl_h;
646 scale_cfg->phase_step_x[DPU_SSPP_COMP_2] =
647 scale_cfg->phase_step_x[DPU_SSPP_COMP_1_2];
648 scale_cfg->phase_step_y[DPU_SSPP_COMP_2] =
649 scale_cfg->phase_step_y[DPU_SSPP_COMP_1_2];
651 scale_cfg->phase_step_x[DPU_SSPP_COMP_3] =
652 scale_cfg->phase_step_x[DPU_SSPP_COMP_0];
653 scale_cfg->phase_step_y[DPU_SSPP_COMP_3] =
654 scale_cfg->phase_step_y[DPU_SSPP_COMP_0];
656 for (i = 0; i < DPU_MAX_PLANES; i++) {
657 scale_cfg->src_width[i] = src_w;
658 scale_cfg->src_height[i] = src_h;
659 if (i == DPU_SSPP_COMP_1_2 || i == DPU_SSPP_COMP_2) {
660 scale_cfg->src_width[i] /= chroma_subsmpl_h;
661 scale_cfg->src_height[i] /= chroma_subsmpl_v;
663 scale_cfg->preload_x[i] = DPU_QSEED3_DEFAULT_PRELOAD_H;
664 scale_cfg->preload_y[i] = DPU_QSEED3_DEFAULT_PRELOAD_V;
665 pstate->pixel_ext.num_ext_pxls_top[i] =
666 scale_cfg->src_height[i];
667 pstate->pixel_ext.num_ext_pxls_left[i] =
668 scale_cfg->src_width[i];
670 if (!(DPU_FORMAT_IS_YUV(fmt)) && (src_h == dst_h)
674 scale_cfg->dst_width = dst_w;
675 scale_cfg->dst_height = dst_h;
676 scale_cfg->y_rgb_filter_cfg = DPU_SCALE_BIL;
677 scale_cfg->uv_filter_cfg = DPU_SCALE_BIL;
678 scale_cfg->alpha_filter_cfg = DPU_SCALE_ALPHA_BIL;
679 scale_cfg->lut_flag = 0;
680 scale_cfg->blend_cfg = 1;
681 scale_cfg->enable = 1;
684 static inline void _dpu_plane_setup_csc(struct dpu_plane *pdpu)
686 static const struct dpu_csc_cfg dpu_csc_YUV2RGB_601L = {
689 0x00012A00, 0x00000000, 0x00019880,
690 0x00012A00, 0xFFFF9B80, 0xFFFF3000,
691 0x00012A00, 0x00020480, 0x00000000,
694 { 0xfff0, 0xff80, 0xff80,},
697 { 0x10, 0xeb, 0x10, 0xf0, 0x10, 0xf0,},
698 { 0x00, 0xff, 0x00, 0xff, 0x00, 0xff,},
700 static const struct dpu_csc_cfg dpu_csc10_YUV2RGB_601L = {
703 0x00012A00, 0x00000000, 0x00019880,
704 0x00012A00, 0xFFFF9B80, 0xFFFF3000,
705 0x00012A00, 0x00020480, 0x00000000,
708 { 0xffc0, 0xfe00, 0xfe00,},
711 { 0x40, 0x3ac, 0x40, 0x3c0, 0x40, 0x3c0,},
712 { 0x00, 0x3ff, 0x00, 0x3ff, 0x00, 0x3ff,},
716 DPU_ERROR("invalid plane\n");
720 if (BIT(DPU_SSPP_CSC_10BIT) & pdpu->features)
721 pdpu->csc_ptr = (struct dpu_csc_cfg *)&dpu_csc10_YUV2RGB_601L;
723 pdpu->csc_ptr = (struct dpu_csc_cfg *)&dpu_csc_YUV2RGB_601L;
725 DPU_DEBUG_PLANE(pdpu, "using 0x%X 0x%X 0x%X...\n",
726 pdpu->csc_ptr->csc_mv[0],
727 pdpu->csc_ptr->csc_mv[1],
728 pdpu->csc_ptr->csc_mv[2]);
731 static void _dpu_plane_setup_scaler(struct dpu_plane *pdpu,
732 struct dpu_plane_state *pstate,
733 const struct dpu_format *fmt, bool color_fill)
735 struct dpu_hw_pixel_ext *pe;
736 uint32_t chroma_subsmpl_h, chroma_subsmpl_v;
738 if (!pdpu || !fmt || !pstate) {
739 DPU_ERROR("invalid arg(s), plane %d fmt %d state %d\n",
740 pdpu != 0, fmt != 0, pstate != 0);
744 pe = &pstate->pixel_ext;
746 /* don't chroma subsample if decimating */
748 drm_format_horz_chroma_subsampling(fmt->base.pixel_format);
750 drm_format_vert_chroma_subsampling(fmt->base.pixel_format);
752 /* update scaler. calculate default config for QSEED3 */
753 _dpu_plane_setup_scaler3(pdpu, pstate,
754 drm_rect_width(&pdpu->pipe_cfg.src_rect),
755 drm_rect_height(&pdpu->pipe_cfg.src_rect),
756 drm_rect_width(&pdpu->pipe_cfg.dst_rect),
757 drm_rect_height(&pdpu->pipe_cfg.dst_rect),
758 &pstate->scaler3_cfg, fmt,
759 chroma_subsmpl_h, chroma_subsmpl_v);
763 * _dpu_plane_color_fill - enables color fill on plane
764 * @pdpu: Pointer to DPU plane object
765 * @color: RGB fill color value, [23..16] Blue, [15..8] Green, [7..0] Red
766 * @alpha: 8-bit fill alpha value, 255 selects 100% alpha
767 * Returns: 0 on success
769 static int _dpu_plane_color_fill(struct dpu_plane *pdpu,
770 uint32_t color, uint32_t alpha)
772 const struct dpu_format *fmt;
773 const struct drm_plane *plane;
774 struct dpu_plane_state *pstate;
776 if (!pdpu || !pdpu->base.state) {
777 DPU_ERROR("invalid plane\n");
781 if (!pdpu->pipe_hw) {
782 DPU_ERROR_PLANE(pdpu, "invalid plane h/w pointer\n");
787 pstate = to_dpu_plane_state(plane->state);
789 DPU_DEBUG_PLANE(pdpu, "\n");
792 * select fill format to match user property expectation,
793 * h/w only supports RGB variants
795 fmt = dpu_get_dpu_format(DRM_FORMAT_ABGR8888);
798 if (fmt && pdpu->pipe_hw->ops.setup_solidfill) {
799 pdpu->pipe_hw->ops.setup_solidfill(pdpu->pipe_hw,
800 (color & 0xFFFFFF) | ((alpha & 0xFF) << 24),
801 pstate->multirect_index);
803 /* override scaler/decimation if solid fill */
804 pdpu->pipe_cfg.src_rect.x1 = 0;
805 pdpu->pipe_cfg.src_rect.y1 = 0;
806 pdpu->pipe_cfg.src_rect.x2 =
807 drm_rect_width(&pdpu->pipe_cfg.dst_rect);
808 pdpu->pipe_cfg.src_rect.y2 =
809 drm_rect_height(&pdpu->pipe_cfg.dst_rect);
810 _dpu_plane_setup_scaler(pdpu, pstate, fmt, true);
812 if (pdpu->pipe_hw->ops.setup_format)
813 pdpu->pipe_hw->ops.setup_format(pdpu->pipe_hw,
814 fmt, DPU_SSPP_SOLID_FILL,
815 pstate->multirect_index);
817 if (pdpu->pipe_hw->ops.setup_rects)
818 pdpu->pipe_hw->ops.setup_rects(pdpu->pipe_hw,
820 pstate->multirect_index);
822 if (pdpu->pipe_hw->ops.setup_pe)
823 pdpu->pipe_hw->ops.setup_pe(pdpu->pipe_hw,
826 if (pdpu->pipe_hw->ops.setup_scaler &&
827 pstate->multirect_index != DPU_SSPP_RECT_1)
828 pdpu->pipe_hw->ops.setup_scaler(pdpu->pipe_hw,
829 &pdpu->pipe_cfg, &pstate->pixel_ext,
830 &pstate->scaler3_cfg);
836 void dpu_plane_clear_multirect(const struct drm_plane_state *drm_state)
838 struct dpu_plane_state *pstate;
843 pstate = to_dpu_plane_state(drm_state);
845 pstate->multirect_index = DPU_SSPP_RECT_SOLO;
846 pstate->multirect_mode = DPU_SSPP_MULTIRECT_NONE;
849 int dpu_plane_validate_multirect_v2(struct dpu_multirect_plane_states *plane)
851 struct dpu_plane_state *pstate[R_MAX];
852 const struct drm_plane_state *drm_state[R_MAX];
853 struct drm_rect src[R_MAX], dst[R_MAX];
854 struct dpu_plane *dpu_plane[R_MAX];
855 const struct dpu_format *fmt[R_MAX];
857 unsigned int max_tile_height = 1;
858 bool parallel_fetch_qualified = true;
859 bool has_tiled_rect = false;
861 for (i = 0; i < R_MAX; i++) {
862 const struct msm_format *msm_fmt;
864 drm_state[i] = i ? plane->r1 : plane->r0;
865 msm_fmt = msm_framebuffer_format(drm_state[i]->fb);
866 fmt[i] = to_dpu_format(msm_fmt);
868 if (DPU_FORMAT_IS_UBWC(fmt[i])) {
869 has_tiled_rect = true;
870 if (fmt[i]->tile_height > max_tile_height)
871 max_tile_height = fmt[i]->tile_height;
875 for (i = 0; i < R_MAX; i++) {
878 pstate[i] = to_dpu_plane_state(drm_state[i]);
879 dpu_plane[i] = to_dpu_plane(drm_state[i]->plane);
881 if (pstate[i] == NULL) {
882 DPU_ERROR("DPU plane state of plane id %d is NULL\n",
883 drm_state[i]->plane->base.id);
887 src[i].x1 = drm_state[i]->src_x >> 16;
888 src[i].y1 = drm_state[i]->src_y >> 16;
889 src[i].x2 = src[i].x1 + (drm_state[i]->src_w >> 16);
890 src[i].y2 = src[i].y1 + (drm_state[i]->src_h >> 16);
892 dst[i] = drm_plane_state_dest(drm_state[i]);
894 if (drm_rect_calc_hscale(&src[i], &dst[i], 1, 1) != 1 ||
895 drm_rect_calc_vscale(&src[i], &dst[i], 1, 1) != 1) {
896 DPU_ERROR_PLANE(dpu_plane[i],
897 "scaling is not supported in multirect mode\n");
901 if (DPU_FORMAT_IS_YUV(fmt[i])) {
902 DPU_ERROR_PLANE(dpu_plane[i],
903 "Unsupported format for multirect mode\n");
908 * SSPP PD_MEM is split half - one for each RECT.
909 * Tiled formats need 5 lines of buffering while fetching
910 * whereas linear formats need only 2 lines.
911 * So we cannot support more than half of the supported SSPP
912 * width for tiled formats.
914 width_threshold = dpu_plane[i]->pipe_sblk->common->maxlinewidth;
916 width_threshold /= 2;
918 if (parallel_fetch_qualified &&
919 drm_rect_width(&src[i]) > width_threshold)
920 parallel_fetch_qualified = false;
924 /* Validate RECT's and set the mode */
926 /* Prefer PARALLEL FETCH Mode over TIME_MX Mode */
927 if (parallel_fetch_qualified) {
928 pstate[R0]->multirect_mode = DPU_SSPP_MULTIRECT_PARALLEL;
929 pstate[R1]->multirect_mode = DPU_SSPP_MULTIRECT_PARALLEL;
935 buffer_lines = 2 * max_tile_height;
937 if (dst[R1].y1 >= dst[R0].y2 + buffer_lines ||
938 dst[R0].y1 >= dst[R1].y2 + buffer_lines) {
939 pstate[R0]->multirect_mode = DPU_SSPP_MULTIRECT_TIME_MX;
940 pstate[R1]->multirect_mode = DPU_SSPP_MULTIRECT_TIME_MX;
943 "No multirect mode possible for the planes (%d - %d)\n",
944 drm_state[R0]->plane->base.id,
945 drm_state[R1]->plane->base.id);
950 if (dpu_plane[R0]->is_virtual) {
951 pstate[R0]->multirect_index = DPU_SSPP_RECT_1;
952 pstate[R1]->multirect_index = DPU_SSPP_RECT_0;
954 pstate[R0]->multirect_index = DPU_SSPP_RECT_0;
955 pstate[R1]->multirect_index = DPU_SSPP_RECT_1;
958 DPU_DEBUG_PLANE(dpu_plane[R0], "R0: %d - %d\n",
959 pstate[R0]->multirect_mode, pstate[R0]->multirect_index);
960 DPU_DEBUG_PLANE(dpu_plane[R1], "R1: %d - %d\n",
961 pstate[R1]->multirect_mode, pstate[R1]->multirect_index);
966 * dpu_plane_get_ctl_flush - get control flush for the given plane
967 * @plane: Pointer to drm plane structure
968 * @ctl: Pointer to hardware control driver
969 * @flush_sspp: Pointer to sspp flush control word
971 void dpu_plane_get_ctl_flush(struct drm_plane *plane, struct dpu_hw_ctl *ctl,
974 struct dpu_plane_state *pstate;
976 if (!plane || !flush_sspp) {
977 DPU_ERROR("invalid parameters\n");
981 pstate = to_dpu_plane_state(plane->state);
983 *flush_sspp = ctl->ops.get_bitmask_sspp(ctl, dpu_plane_pipe(plane));
986 static int dpu_plane_prepare_fb(struct drm_plane *plane,
987 struct drm_plane_state *new_state)
989 struct drm_framebuffer *fb = new_state->fb;
990 struct dpu_plane *pdpu = to_dpu_plane(plane);
991 struct dpu_plane_state *pstate = to_dpu_plane_state(new_state);
992 struct dpu_hw_fmt_layout layout;
993 struct drm_gem_object *obj;
994 struct msm_gem_object *msm_obj;
995 struct dma_fence *fence;
996 struct msm_gem_address_space *aspace;
1002 DPU_DEBUG_PLANE(pdpu, "FB[%u]\n", fb->base.id);
1004 ret = _dpu_plane_get_aspace(pdpu, pstate, &aspace);
1006 DPU_ERROR_PLANE(pdpu, "Failed to get aspace\n");
1011 pstate->aspace = aspace;
1014 * TODO: Need to sort out the msm_framebuffer_prepare() call below so
1015 * we can use msm_atomic_prepare_fb() instead of doing the
1016 * implicit fence and fb prepare by hand here.
1018 obj = msm_framebuffer_bo(new_state->fb, 0);
1019 msm_obj = to_msm_bo(obj);
1020 fence = reservation_object_get_excl_rcu(msm_obj->resv);
1022 drm_atomic_set_fence_for_plane(new_state, fence);
1024 if (pstate->aspace) {
1025 ret = msm_framebuffer_prepare(new_state->fb,
1028 DPU_ERROR("failed to prepare framebuffer\n");
1033 /* validate framebuffer layout before commit */
1034 ret = dpu_format_populate_layout(pstate->aspace,
1035 new_state->fb, &layout);
1037 DPU_ERROR_PLANE(pdpu, "failed to get format layout, %d\n", ret);
1044 static void dpu_plane_cleanup_fb(struct drm_plane *plane,
1045 struct drm_plane_state *old_state)
1047 struct dpu_plane *pdpu = to_dpu_plane(plane);
1048 struct dpu_plane_state *old_pstate;
1050 if (!old_state || !old_state->fb)
1053 old_pstate = to_dpu_plane_state(old_state);
1055 DPU_DEBUG_PLANE(pdpu, "FB[%u]\n", old_state->fb->base.id);
1057 msm_framebuffer_cleanup(old_state->fb, old_pstate->aspace);
1060 static bool dpu_plane_validate_src(struct drm_rect *src,
1061 struct drm_rect *fb_rect,
1062 uint32_t min_src_size)
1064 /* Ensure fb size is supported */
1065 if (drm_rect_width(fb_rect) > MAX_IMG_WIDTH ||
1066 drm_rect_height(fb_rect) > MAX_IMG_HEIGHT)
1069 /* Ensure src rect is above the minimum size */
1070 if (drm_rect_width(src) < min_src_size ||
1071 drm_rect_height(src) < min_src_size)
1074 /* Ensure src is fully encapsulated in fb */
1075 return drm_rect_intersect(fb_rect, src) &&
1076 drm_rect_equals(fb_rect, src);
1079 static int dpu_plane_sspp_atomic_check(struct drm_plane *plane,
1080 struct drm_plane_state *state)
1083 struct dpu_plane *pdpu;
1084 struct dpu_plane_state *pstate;
1085 const struct dpu_format *fmt;
1086 struct drm_rect src, dst, fb_rect = { 0 };
1087 uint32_t max_upscale = 1, max_downscale = 1;
1088 uint32_t min_src_size, max_linewidth;
1089 int hscale = 1, vscale = 1;
1091 if (!plane || !state) {
1092 DPU_ERROR("invalid arg(s), plane %d state %d\n",
1093 plane != 0, state != 0);
1098 pdpu = to_dpu_plane(plane);
1099 pstate = to_dpu_plane_state(state);
1101 if (!pdpu->pipe_sblk) {
1102 DPU_ERROR_PLANE(pdpu, "invalid catalog\n");
1107 src.x1 = state->src_x >> 16;
1108 src.y1 = state->src_y >> 16;
1109 src.x2 = src.x1 + (state->src_w >> 16);
1110 src.y2 = src.y1 + (state->src_h >> 16);
1112 dst = drm_plane_state_dest(state);
1114 fb_rect.x2 = state->fb->width;
1115 fb_rect.y2 = state->fb->height;
1117 max_linewidth = pdpu->pipe_sblk->common->maxlinewidth;
1119 if (pdpu->features & DPU_SSPP_SCALER) {
1120 max_downscale = pdpu->pipe_sblk->maxdwnscale;
1121 max_upscale = pdpu->pipe_sblk->maxupscale;
1123 if (drm_rect_width(&src) < drm_rect_width(&dst))
1124 hscale = drm_rect_calc_hscale(&src, &dst, 1, max_upscale);
1126 hscale = drm_rect_calc_hscale(&dst, &src, 1, max_downscale);
1127 if (drm_rect_height(&src) < drm_rect_height(&dst))
1128 vscale = drm_rect_calc_vscale(&src, &dst, 1, max_upscale);
1130 vscale = drm_rect_calc_vscale(&dst, &src, 1, max_downscale);
1132 DPU_DEBUG_PLANE(pdpu, "check %d -> %d\n",
1133 dpu_plane_enabled(plane->state), dpu_plane_enabled(state));
1135 if (!dpu_plane_enabled(state))
1138 fmt = to_dpu_format(msm_framebuffer_format(state->fb));
1140 min_src_size = DPU_FORMAT_IS_YUV(fmt) ? 2 : 1;
1142 if (DPU_FORMAT_IS_YUV(fmt) &&
1143 (!(pdpu->features & DPU_SSPP_SCALER) ||
1144 !(pdpu->features & (BIT(DPU_SSPP_CSC)
1145 | BIT(DPU_SSPP_CSC_10BIT))))) {
1146 DPU_ERROR_PLANE(pdpu,
1147 "plane doesn't have scaler/csc for yuv\n");
1150 /* check src bounds */
1151 } else if (!dpu_plane_validate_src(&src, &fb_rect, min_src_size)) {
1152 DPU_ERROR_PLANE(pdpu, "invalid source " DRM_RECT_FMT "\n",
1153 DRM_RECT_ARG(&src));
1156 /* valid yuv image */
1157 } else if (DPU_FORMAT_IS_YUV(fmt) &&
1158 (src.x1 & 0x1 || src.y1 & 0x1 ||
1159 drm_rect_width(&src) & 0x1 ||
1160 drm_rect_height(&src) & 0x1)) {
1161 DPU_ERROR_PLANE(pdpu, "invalid yuv source " DRM_RECT_FMT "\n",
1162 DRM_RECT_ARG(&src));
1165 /* min dst support */
1166 } else if (drm_rect_width(&dst) < 0x1 || drm_rect_height(&dst) < 0x1) {
1167 DPU_ERROR_PLANE(pdpu, "invalid dest rect " DRM_RECT_FMT "\n",
1168 DRM_RECT_ARG(&dst));
1171 /* check decimated source width */
1172 } else if (drm_rect_width(&src) > max_linewidth) {
1173 DPU_ERROR_PLANE(pdpu, "invalid src " DRM_RECT_FMT " line:%u\n",
1174 DRM_RECT_ARG(&src), max_linewidth);
1177 /* check scaler capability */
1178 } else if (hscale < 0 || vscale < 0) {
1179 DPU_ERROR_PLANE(pdpu, "invalid scaling requested src="
1180 DRM_RECT_FMT " dst=" DRM_RECT_FMT "\n",
1181 DRM_RECT_ARG(&src), DRM_RECT_ARG(&dst));
1189 static int dpu_plane_atomic_check(struct drm_plane *plane,
1190 struct drm_plane_state *state)
1195 DPU_DEBUG_PLANE(to_dpu_plane(plane), "\n");
1197 return dpu_plane_sspp_atomic_check(plane, state);
1200 void dpu_plane_flush(struct drm_plane *plane)
1202 struct dpu_plane *pdpu;
1203 struct dpu_plane_state *pstate;
1205 if (!plane || !plane->state) {
1206 DPU_ERROR("invalid plane\n");
1210 pdpu = to_dpu_plane(plane);
1211 pstate = to_dpu_plane_state(plane->state);
1214 * These updates have to be done immediately before the plane flush
1215 * timing, and may not be moved to the atomic_update/mode_set functions.
1218 /* force white frame with 100% alpha pipe output on error */
1219 _dpu_plane_color_fill(pdpu, 0xFFFFFF, 0xFF);
1220 else if (pdpu->color_fill & DPU_PLANE_COLOR_FILL_FLAG)
1221 /* force 100% alpha */
1222 _dpu_plane_color_fill(pdpu, pdpu->color_fill, 0xFF);
1223 else if (pdpu->pipe_hw && pdpu->csc_ptr && pdpu->pipe_hw->ops.setup_csc)
1224 pdpu->pipe_hw->ops.setup_csc(pdpu->pipe_hw, pdpu->csc_ptr);
1226 /* flag h/w flush complete */
1228 pstate->pending = false;
1232 * dpu_plane_set_error: enable/disable error condition
1233 * @plane: pointer to drm_plane structure
1235 void dpu_plane_set_error(struct drm_plane *plane, bool error)
1237 struct dpu_plane *pdpu;
1242 pdpu = to_dpu_plane(plane);
1243 pdpu->is_error = error;
1246 static int dpu_plane_sspp_atomic_update(struct drm_plane *plane,
1247 struct drm_plane_state *old_state)
1249 uint32_t nplanes, src_flags;
1250 struct dpu_plane *pdpu;
1251 struct drm_plane_state *state;
1252 struct dpu_plane_state *pstate;
1253 struct dpu_plane_state *old_pstate;
1254 const struct dpu_format *fmt;
1255 struct drm_crtc *crtc;
1256 struct drm_framebuffer *fb;
1257 struct drm_rect src, dst;
1260 DPU_ERROR("invalid plane\n");
1262 } else if (!plane->state) {
1263 DPU_ERROR("invalid plane state\n");
1265 } else if (!old_state) {
1266 DPU_ERROR("invalid old state\n");
1270 pdpu = to_dpu_plane(plane);
1271 state = plane->state;
1273 pstate = to_dpu_plane_state(state);
1275 old_pstate = to_dpu_plane_state(old_state);
1280 DPU_ERROR_PLANE(pdpu, "invalid crtc %d or fb %d\n",
1281 crtc != 0, fb != 0);
1284 fmt = to_dpu_format(msm_framebuffer_format(fb));
1285 nplanes = fmt->num_planes;
1287 memset(&(pdpu->pipe_cfg), 0, sizeof(struct dpu_hw_pipe_cfg));
1289 _dpu_plane_set_scanout(plane, pstate, &pdpu->pipe_cfg, fb);
1291 pstate->pending = true;
1293 pdpu->is_rt_pipe = (dpu_crtc_get_client_type(crtc) != NRT_CLIENT);
1294 _dpu_plane_set_qos_ctrl(plane, false, DPU_PLANE_QOS_PANIC_CTRL);
1296 src.x1 = state->src_x >> 16;
1297 src.y1 = state->src_y >> 16;
1298 src.x2 = src.x1 + (state->src_w >> 16);
1299 src.y2 = src.y1 + (state->src_h >> 16);
1301 dst = drm_plane_state_dest(state);
1303 DPU_DEBUG_PLANE(pdpu, "FB[%u] " DRM_RECT_FMT "->crtc%u " DRM_RECT_FMT
1304 ", %4.4s ubwc %d\n", fb->base.id, DRM_RECT_ARG(&src),
1305 crtc->base.id, DRM_RECT_ARG(&dst),
1306 (char *)&fmt->base.pixel_format,
1307 DPU_FORMAT_IS_UBWC(fmt));
1309 pdpu->pipe_cfg.src_rect = src;
1310 pdpu->pipe_cfg.dst_rect = dst;
1312 _dpu_plane_setup_scaler(pdpu, pstate, fmt, false);
1314 /* override for color fill */
1315 if (pdpu->color_fill & DPU_PLANE_COLOR_FILL_FLAG) {
1316 /* skip remaining processing on color fill */
1320 if (pdpu->pipe_hw->ops.setup_rects) {
1321 pdpu->pipe_hw->ops.setup_rects(pdpu->pipe_hw,
1323 pstate->multirect_index);
1326 if (pdpu->pipe_hw->ops.setup_pe &&
1327 (pstate->multirect_index != DPU_SSPP_RECT_1))
1328 pdpu->pipe_hw->ops.setup_pe(pdpu->pipe_hw,
1329 &pstate->pixel_ext);
1332 * when programmed in multirect mode, scalar block will be
1333 * bypassed. Still we need to update alpha and bitwidth
1336 if (pdpu->pipe_hw->ops.setup_scaler &&
1337 pstate->multirect_index != DPU_SSPP_RECT_1)
1338 pdpu->pipe_hw->ops.setup_scaler(pdpu->pipe_hw,
1339 &pdpu->pipe_cfg, &pstate->pixel_ext,
1340 &pstate->scaler3_cfg);
1342 if (pdpu->pipe_hw->ops.setup_multirect)
1343 pdpu->pipe_hw->ops.setup_multirect(
1345 pstate->multirect_index,
1346 pstate->multirect_mode);
1348 if (pdpu->pipe_hw->ops.setup_format) {
1352 pdpu->pipe_hw->ops.setup_format(pdpu->pipe_hw, fmt, src_flags,
1353 pstate->multirect_index);
1355 if (pdpu->pipe_hw->ops.setup_cdp) {
1356 struct dpu_hw_pipe_cdp_cfg *cdp_cfg = &pstate->cdp_cfg;
1358 memset(cdp_cfg, 0, sizeof(struct dpu_hw_pipe_cdp_cfg));
1360 cdp_cfg->enable = pdpu->catalog->perf.cdp_cfg
1361 [DPU_PERF_CDP_USAGE_RT].rd_enable;
1362 cdp_cfg->ubwc_meta_enable =
1363 DPU_FORMAT_IS_UBWC(fmt);
1364 cdp_cfg->tile_amortize_enable =
1365 DPU_FORMAT_IS_UBWC(fmt) ||
1366 DPU_FORMAT_IS_TILE(fmt);
1367 cdp_cfg->preload_ahead = DPU_SSPP_CDP_PRELOAD_AHEAD_64;
1369 pdpu->pipe_hw->ops.setup_cdp(pdpu->pipe_hw, cdp_cfg);
1373 if (DPU_FORMAT_IS_YUV(fmt))
1374 _dpu_plane_setup_csc(pdpu);
1379 _dpu_plane_set_qos_lut(plane, fb);
1380 _dpu_plane_set_danger_lut(plane, fb);
1382 if (plane->type != DRM_PLANE_TYPE_CURSOR) {
1383 _dpu_plane_set_qos_ctrl(plane, true, DPU_PLANE_QOS_PANIC_CTRL);
1384 _dpu_plane_set_ot_limit(plane, crtc);
1387 _dpu_plane_set_qos_remap(plane);
1391 static void _dpu_plane_atomic_disable(struct drm_plane *plane,
1392 struct drm_plane_state *old_state)
1394 struct dpu_plane *pdpu;
1395 struct drm_plane_state *state;
1396 struct dpu_plane_state *pstate;
1399 DPU_ERROR("invalid plane\n");
1401 } else if (!plane->state) {
1402 DPU_ERROR("invalid plane state\n");
1404 } else if (!old_state) {
1405 DPU_ERROR("invalid old state\n");
1409 pdpu = to_dpu_plane(plane);
1410 state = plane->state;
1411 pstate = to_dpu_plane_state(state);
1413 trace_dpu_plane_disable(DRMID(plane), is_dpu_plane_virtual(plane),
1414 pstate->multirect_mode);
1416 pstate->pending = true;
1418 if (is_dpu_plane_virtual(plane) &&
1419 pdpu->pipe_hw && pdpu->pipe_hw->ops.setup_multirect)
1420 pdpu->pipe_hw->ops.setup_multirect(pdpu->pipe_hw,
1421 DPU_SSPP_RECT_SOLO, DPU_SSPP_MULTIRECT_NONE);
1424 static void dpu_plane_atomic_update(struct drm_plane *plane,
1425 struct drm_plane_state *old_state)
1427 struct dpu_plane *pdpu;
1428 struct drm_plane_state *state;
1431 DPU_ERROR("invalid plane\n");
1433 } else if (!plane->state) {
1434 DPU_ERROR("invalid plane state\n");
1438 pdpu = to_dpu_plane(plane);
1439 pdpu->is_error = false;
1440 state = plane->state;
1442 DPU_DEBUG_PLANE(pdpu, "\n");
1444 if (!dpu_plane_sspp_enabled(state)) {
1445 _dpu_plane_atomic_disable(plane, old_state);
1449 ret = dpu_plane_sspp_atomic_update(plane, old_state);
1450 /* atomic_check should have ensured that this doesn't fail */
1455 void dpu_plane_restore(struct drm_plane *plane)
1457 struct dpu_plane *pdpu;
1459 if (!plane || !plane->state) {
1460 DPU_ERROR("invalid plane\n");
1464 pdpu = to_dpu_plane(plane);
1466 DPU_DEBUG_PLANE(pdpu, "\n");
1468 /* last plane state is same as current state */
1469 dpu_plane_atomic_update(plane, plane->state);
1472 static void dpu_plane_destroy(struct drm_plane *plane)
1474 struct dpu_plane *pdpu = plane ? to_dpu_plane(plane) : NULL;
1476 DPU_DEBUG_PLANE(pdpu, "\n");
1479 _dpu_plane_set_qos_ctrl(plane, false, DPU_PLANE_QOS_PANIC_CTRL);
1481 mutex_destroy(&pdpu->lock);
1483 drm_plane_helper_disable(plane, NULL);
1485 /* this will destroy the states as well */
1486 drm_plane_cleanup(plane);
1489 dpu_hw_sspp_destroy(pdpu->pipe_hw);
1495 static void dpu_plane_destroy_state(struct drm_plane *plane,
1496 struct drm_plane_state *state)
1498 struct dpu_plane_state *pstate;
1500 if (!plane || !state) {
1501 DPU_ERROR("invalid arg(s), plane %d state %d\n",
1502 plane != 0, state != 0);
1506 pstate = to_dpu_plane_state(state);
1508 /* remove ref count for frame buffers */
1510 drm_framebuffer_put(state->fb);
1515 static struct drm_plane_state *
1516 dpu_plane_duplicate_state(struct drm_plane *plane)
1518 struct dpu_plane *pdpu;
1519 struct dpu_plane_state *pstate;
1520 struct dpu_plane_state *old_state;
1523 DPU_ERROR("invalid plane\n");
1525 } else if (!plane->state) {
1526 DPU_ERROR("invalid plane state\n");
1530 old_state = to_dpu_plane_state(plane->state);
1531 pdpu = to_dpu_plane(plane);
1532 pstate = kmemdup(old_state, sizeof(*old_state), GFP_KERNEL);
1534 DPU_ERROR_PLANE(pdpu, "failed to allocate state\n");
1538 DPU_DEBUG_PLANE(pdpu, "\n");
1540 pstate->pending = false;
1542 __drm_atomic_helper_plane_duplicate_state(plane, &pstate->base);
1544 return &pstate->base;
1547 static void dpu_plane_reset(struct drm_plane *plane)
1549 struct dpu_plane *pdpu;
1550 struct dpu_plane_state *pstate;
1553 DPU_ERROR("invalid plane\n");
1557 pdpu = to_dpu_plane(plane);
1558 DPU_DEBUG_PLANE(pdpu, "\n");
1560 /* remove previous state, if present */
1562 dpu_plane_destroy_state(plane, plane->state);
1566 pstate = kzalloc(sizeof(*pstate), GFP_KERNEL);
1568 DPU_ERROR_PLANE(pdpu, "failed to allocate state\n");
1572 pstate->base.plane = plane;
1574 plane->state = &pstate->base;
1577 #ifdef CONFIG_DEBUG_FS
1578 static ssize_t _dpu_plane_danger_read(struct file *file,
1579 char __user *buff, size_t count, loff_t *ppos)
1581 struct dpu_kms *kms = file->private_data;
1582 struct dpu_mdss_cfg *cfg = kms->catalog;
1584 char buf[40] = {'\0'};
1590 return 0; /* the end */
1592 len = snprintf(buf, sizeof(buf), "%d\n", !kms->has_danger_ctrl);
1593 if (len < 0 || len >= sizeof(buf))
1596 if ((count < sizeof(buf)) || copy_to_user(buff, buf, len))
1599 *ppos += len; /* increase offset */
1604 static void _dpu_plane_set_danger_state(struct dpu_kms *kms, bool enable)
1606 struct drm_plane *plane;
1608 drm_for_each_plane(plane, kms->dev) {
1609 if (plane->fb && plane->state) {
1610 dpu_plane_danger_signal_ctrl(plane, enable);
1611 DPU_DEBUG("plane:%d img:%dx%d ",
1612 plane->base.id, plane->fb->width,
1614 DPU_DEBUG("src[%d,%d,%d,%d] dst[%d,%d,%d,%d]\n",
1615 plane->state->src_x >> 16,
1616 plane->state->src_y >> 16,
1617 plane->state->src_w >> 16,
1618 plane->state->src_h >> 16,
1619 plane->state->crtc_x, plane->state->crtc_y,
1620 plane->state->crtc_w, plane->state->crtc_h);
1622 DPU_DEBUG("Inactive plane:%d\n", plane->base.id);
1627 static ssize_t _dpu_plane_danger_write(struct file *file,
1628 const char __user *user_buf, size_t count, loff_t *ppos)
1630 struct dpu_kms *kms = file->private_data;
1631 struct dpu_mdss_cfg *cfg = kms->catalog;
1638 if (count >= sizeof(buf))
1641 if (copy_from_user(buf, user_buf, count))
1644 buf[count] = 0; /* end of string */
1646 if (kstrtoint(buf, 0, &disable_panic))
1649 if (disable_panic) {
1650 /* Disable panic signal for all active pipes */
1651 DPU_DEBUG("Disabling danger:\n");
1652 _dpu_plane_set_danger_state(kms, false);
1653 kms->has_danger_ctrl = false;
1655 /* Enable panic signal for all active pipes */
1656 DPU_DEBUG("Enabling danger:\n");
1657 kms->has_danger_ctrl = true;
1658 _dpu_plane_set_danger_state(kms, true);
1664 static const struct file_operations dpu_plane_danger_enable = {
1665 .open = simple_open,
1666 .read = _dpu_plane_danger_read,
1667 .write = _dpu_plane_danger_write,
1670 static int _dpu_plane_init_debugfs(struct drm_plane *plane)
1672 struct dpu_plane *pdpu;
1673 struct dpu_kms *kms;
1674 struct msm_drm_private *priv;
1675 const struct dpu_sspp_sub_blks *sblk = 0;
1676 const struct dpu_sspp_cfg *cfg = 0;
1678 if (!plane || !plane->dev) {
1679 DPU_ERROR("invalid arguments\n");
1683 priv = plane->dev->dev_private;
1684 if (!priv || !priv->kms) {
1685 DPU_ERROR("invalid KMS reference\n");
1689 kms = to_dpu_kms(priv->kms);
1690 pdpu = to_dpu_plane(plane);
1692 if (pdpu && pdpu->pipe_hw)
1693 cfg = pdpu->pipe_hw->cap;
1700 /* create overall sub-directory for the pipe */
1701 pdpu->debugfs_root =
1702 debugfs_create_dir(pdpu->pipe_name,
1703 plane->dev->primary->debugfs_root);
1705 if (!pdpu->debugfs_root)
1708 /* don't error check these */
1709 debugfs_create_x32("features", 0600,
1710 pdpu->debugfs_root, &pdpu->features);
1712 /* add register dump support */
1713 dpu_debugfs_setup_regset32(&pdpu->debugfs_src,
1714 sblk->src_blk.base + cfg->base,
1717 dpu_debugfs_create_regset32("src_blk", 0400,
1718 pdpu->debugfs_root, &pdpu->debugfs_src);
1720 if (cfg->features & BIT(DPU_SSPP_SCALER_QSEED3) ||
1721 cfg->features & BIT(DPU_SSPP_SCALER_QSEED2)) {
1722 dpu_debugfs_setup_regset32(&pdpu->debugfs_scaler,
1723 sblk->scaler_blk.base + cfg->base,
1724 sblk->scaler_blk.len,
1726 dpu_debugfs_create_regset32("scaler_blk", 0400,
1728 &pdpu->debugfs_scaler);
1729 debugfs_create_bool("default_scaling",
1732 &pdpu->debugfs_default_scale);
1735 if (cfg->features & BIT(DPU_SSPP_CSC) ||
1736 cfg->features & BIT(DPU_SSPP_CSC_10BIT)) {
1737 dpu_debugfs_setup_regset32(&pdpu->debugfs_csc,
1738 sblk->csc_blk.base + cfg->base,
1741 dpu_debugfs_create_regset32("csc_blk", 0400,
1742 pdpu->debugfs_root, &pdpu->debugfs_csc);
1745 debugfs_create_u32("xin_id",
1748 (u32 *) &cfg->xin_id);
1749 debugfs_create_u32("clk_ctrl",
1752 (u32 *) &cfg->clk_ctrl);
1753 debugfs_create_x32("creq_vblank",
1756 (u32 *) &sblk->creq_vblank);
1757 debugfs_create_x32("danger_vblank",
1760 (u32 *) &sblk->danger_vblank);
1762 debugfs_create_file("disable_danger",
1765 kms, &dpu_plane_danger_enable);
1770 static void _dpu_plane_destroy_debugfs(struct drm_plane *plane)
1772 struct dpu_plane *pdpu;
1776 pdpu = to_dpu_plane(plane);
1778 debugfs_remove_recursive(pdpu->debugfs_root);
1781 static int _dpu_plane_init_debugfs(struct drm_plane *plane)
1785 static void _dpu_plane_destroy_debugfs(struct drm_plane *plane)
1790 static int dpu_plane_late_register(struct drm_plane *plane)
1792 return _dpu_plane_init_debugfs(plane);
1795 static void dpu_plane_early_unregister(struct drm_plane *plane)
1797 _dpu_plane_destroy_debugfs(plane);
1800 static const struct drm_plane_funcs dpu_plane_funcs = {
1801 .update_plane = drm_atomic_helper_update_plane,
1802 .disable_plane = drm_atomic_helper_disable_plane,
1803 .destroy = dpu_plane_destroy,
1804 .reset = dpu_plane_reset,
1805 .atomic_duplicate_state = dpu_plane_duplicate_state,
1806 .atomic_destroy_state = dpu_plane_destroy_state,
1807 .late_register = dpu_plane_late_register,
1808 .early_unregister = dpu_plane_early_unregister,
1811 static const struct drm_plane_helper_funcs dpu_plane_helper_funcs = {
1812 .prepare_fb = dpu_plane_prepare_fb,
1813 .cleanup_fb = dpu_plane_cleanup_fb,
1814 .atomic_check = dpu_plane_atomic_check,
1815 .atomic_update = dpu_plane_atomic_update,
1818 enum dpu_sspp dpu_plane_pipe(struct drm_plane *plane)
1820 return plane ? to_dpu_plane(plane)->pipe : SSPP_NONE;
1823 bool is_dpu_plane_virtual(struct drm_plane *plane)
1825 return plane ? to_dpu_plane(plane)->is_virtual : false;
1828 /* initialize plane */
1829 struct drm_plane *dpu_plane_init(struct drm_device *dev,
1830 uint32_t pipe, bool primary_plane,
1831 unsigned long possible_crtcs, u32 master_plane_id)
1833 struct drm_plane *plane = NULL, *master_plane = NULL;
1834 const struct dpu_format_extended *format_list;
1835 struct dpu_plane *pdpu;
1836 struct msm_drm_private *priv;
1837 struct dpu_kms *kms;
1838 enum drm_plane_type type;
1839 int zpos_max = DPU_ZPOS_MAX;
1843 DPU_ERROR("[%u]device is NULL\n", pipe);
1847 priv = dev->dev_private;
1849 DPU_ERROR("[%u]private data is NULL\n", pipe);
1854 DPU_ERROR("[%u]invalid KMS reference\n", pipe);
1857 kms = to_dpu_kms(priv->kms);
1859 if (!kms->catalog) {
1860 DPU_ERROR("[%u]invalid catalog reference\n", pipe);
1864 /* create and zero local structure */
1865 pdpu = kzalloc(sizeof(*pdpu), GFP_KERNEL);
1867 DPU_ERROR("[%u]failed to allocate local plane struct\n", pipe);
1872 /* cache local stuff for later */
1873 plane = &pdpu->base;
1875 pdpu->is_virtual = (master_plane_id != 0);
1876 INIT_LIST_HEAD(&pdpu->mplane_list);
1877 master_plane = drm_plane_find(dev, NULL, master_plane_id);
1879 struct dpu_plane *mpdpu = to_dpu_plane(master_plane);
1881 list_add_tail(&pdpu->mplane_list, &mpdpu->mplane_list);
1884 /* initialize underlying h/w driver */
1885 pdpu->pipe_hw = dpu_hw_sspp_init(pipe, kms->mmio, kms->catalog,
1886 master_plane_id != 0);
1887 if (IS_ERR(pdpu->pipe_hw)) {
1888 DPU_ERROR("[%u]SSPP init failed\n", pipe);
1889 ret = PTR_ERR(pdpu->pipe_hw);
1891 } else if (!pdpu->pipe_hw->cap || !pdpu->pipe_hw->cap->sblk) {
1892 DPU_ERROR("[%u]SSPP init returned invalid cfg\n", pipe);
1896 /* cache features mask for later */
1897 pdpu->features = pdpu->pipe_hw->cap->features;
1898 pdpu->pipe_sblk = pdpu->pipe_hw->cap->sblk;
1899 if (!pdpu->pipe_sblk) {
1900 DPU_ERROR("[%u]invalid sblk\n", pipe);
1904 if (!master_plane_id)
1905 format_list = pdpu->pipe_sblk->format_list;
1907 format_list = pdpu->pipe_sblk->virt_format_list;
1909 pdpu->nformats = dpu_populate_formats(format_list,
1912 ARRAY_SIZE(pdpu->formats));
1914 if (!pdpu->nformats) {
1915 DPU_ERROR("[%u]no valid formats for plane\n", pipe);
1919 if (pdpu->features & BIT(DPU_SSPP_CURSOR))
1920 type = DRM_PLANE_TYPE_CURSOR;
1921 else if (primary_plane)
1922 type = DRM_PLANE_TYPE_PRIMARY;
1924 type = DRM_PLANE_TYPE_OVERLAY;
1925 ret = drm_universal_plane_init(dev, plane, 0xff, &dpu_plane_funcs,
1926 pdpu->formats, pdpu->nformats,
1931 pdpu->catalog = kms->catalog;
1933 if (kms->catalog->mixer_count &&
1934 kms->catalog->mixer[0].sblk->maxblendstages) {
1935 zpos_max = kms->catalog->mixer[0].sblk->maxblendstages - 1;
1936 if (zpos_max > DPU_STAGE_MAX - DPU_STAGE_0 - 1)
1937 zpos_max = DPU_STAGE_MAX - DPU_STAGE_0 - 1;
1940 ret = drm_plane_create_zpos_property(plane, 0, 0, zpos_max);
1942 DPU_ERROR("failed to install zpos property, rc = %d\n", ret);
1944 /* success! finalize initialization */
1945 drm_plane_helper_add(plane, &dpu_plane_helper_funcs);
1947 /* save user friendly pipe name for later */
1948 snprintf(pdpu->pipe_name, DPU_NAME_SIZE, "plane%u", plane->base.id);
1950 mutex_init(&pdpu->lock);
1952 DPU_DEBUG("%s created for pipe:%u id:%u virtual:%u\n", pdpu->pipe_name,
1953 pipe, plane->base.id, master_plane_id);
1957 if (pdpu && pdpu->pipe_hw)
1958 dpu_hw_sspp_destroy(pdpu->pipe_hw);
1962 return ERR_PTR(ret);