1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) 2014-2018 The Linux Foundation. All rights reserved.
4 * Copyright (C) 2013 Red Hat
5 * Author: Rob Clark <robdclark@gmail.com>
8 #define pr_fmt(fmt) "[drm:%s:%d] " fmt, __func__, __LINE__
10 #include <linux/debugfs.h>
11 #include <linux/dma-buf.h>
13 #include <drm/drm_atomic.h>
14 #include <drm/drm_atomic_uapi.h>
15 #include <drm/drm_blend.h>
16 #include <drm/drm_damage_helper.h>
17 #include <drm/drm_framebuffer.h>
18 #include <drm/drm_gem_atomic_helper.h>
22 #include "dpu_formats.h"
23 #include "dpu_hw_sspp.h"
24 #include "dpu_trace.h"
27 #include "dpu_plane.h"
29 #define DPU_DEBUG_PLANE(pl, fmt, ...) DRM_DEBUG_ATOMIC("plane%d " fmt,\
30 (pl) ? (pl)->base.base.id : -1, ##__VA_ARGS__)
32 #define DPU_ERROR_PLANE(pl, fmt, ...) DPU_ERROR("plane%d " fmt,\
33 (pl) ? (pl)->base.base.id : -1, ##__VA_ARGS__)
35 #define DECIMATED_DIMENSION(dim, deci) (((dim) + ((1 << (deci)) - 1)) >> (deci))
36 #define PHASE_STEP_SHIFT 21
37 #define PHASE_STEP_UNIT_SCALE ((int) (1 << PHASE_STEP_SHIFT))
38 #define PHASE_RESIDUAL 15
40 #define SHARP_STRENGTH_DEFAULT 32
41 #define SHARP_EDGE_THR_DEFAULT 112
42 #define SHARP_SMOOTH_THR_DEFAULT 8
43 #define SHARP_NOISE_THR_DEFAULT 2
45 #define DPU_NAME_SIZE 12
47 #define DPU_PLANE_COLOR_FILL_FLAG BIT(31)
48 #define DPU_ZPOS_MAX 255
50 /* multirect rect index */
58 * Default Preload Values
60 #define DPU_QSEED3_DEFAULT_PRELOAD_H 0x4
61 #define DPU_QSEED3_DEFAULT_PRELOAD_V 0x3
62 #define DPU_QSEED4_DEFAULT_PRELOAD_V 0x2
63 #define DPU_QSEED4_DEFAULT_PRELOAD_H 0x4
65 #define DEFAULT_REFRESH_RATE 60
67 static const uint32_t qcom_compressed_supported_formats[] = {
72 DRM_FORMAT_ARGB2101010,
73 DRM_FORMAT_XRGB2101010,
81 * enum dpu_plane_qos - Different qos configurations for each pipe
83 * @DPU_PLANE_QOS_VBLANK_CTRL: Setup VBLANK qos for the pipe.
84 * @DPU_PLANE_QOS_VBLANK_AMORTIZE: Enables Amortization within pipe.
85 * this configuration is mutually exclusive from VBLANK_CTRL.
86 * @DPU_PLANE_QOS_PANIC_CTRL: Setup panic for the pipe.
89 DPU_PLANE_QOS_VBLANK_CTRL = BIT(0),
90 DPU_PLANE_QOS_VBLANK_AMORTIZE = BIT(1),
91 DPU_PLANE_QOS_PANIC_CTRL = BIT(2),
95 * struct dpu_plane - local dpu plane structure
96 * @aspace: address space pointer
97 * @csc_ptr: Points to dpu_csc_cfg structure to use for current
98 * @catalog: Points to dpu catalog structure
99 * @revalidate: force revalidation of all the plane properties
102 struct drm_plane base;
111 const struct dpu_mdss_cfg *catalog;
114 static const uint64_t supported_format_modifiers[] = {
115 DRM_FORMAT_MOD_QCOM_COMPRESSED,
116 DRM_FORMAT_MOD_LINEAR,
117 DRM_FORMAT_MOD_INVALID
120 #define to_dpu_plane(x) container_of(x, struct dpu_plane, base)
122 static struct dpu_kms *_dpu_plane_get_kms(struct drm_plane *plane)
124 struct msm_drm_private *priv = plane->dev->dev_private;
126 return to_dpu_kms(priv->kms);
130 * _dpu_plane_calc_bw - calculate bandwidth required for a plane
131 * @catalog: Points to dpu catalog structure
132 * @fmt: Pointer to source buffer format
133 * @mode: Pointer to drm display mode
134 * @pipe_cfg: Pointer to pipe configuration
135 * Result: Updates calculated bandwidth in the plane state.
136 * BW Equation: src_w * src_h * bpp * fps * (v_total / v_dest)
137 * Prefill BW Equation: line src bytes * line_time
139 static u64 _dpu_plane_calc_bw(const struct dpu_mdss_cfg *catalog,
140 const struct dpu_format *fmt,
141 const struct drm_display_mode *mode,
142 struct dpu_sw_pipe_cfg *pipe_cfg)
144 int src_width, src_height, dst_height, fps;
145 u64 plane_prefill_bw;
147 u32 hw_latency_lines;
151 src_width = drm_rect_width(&pipe_cfg->src_rect);
152 src_height = drm_rect_height(&pipe_cfg->src_rect);
153 dst_height = drm_rect_height(&pipe_cfg->dst_rect);
154 fps = drm_mode_vrefresh(mode);
155 vbp = mode->vtotal - mode->vsync_end;
156 vpw = mode->vsync_end - mode->vsync_start;
157 vfp = mode->vsync_start - mode->vdisplay;
158 hw_latency_lines = catalog->perf->min_prefill_lines;
159 scale_factor = src_height > dst_height ?
160 mult_frac(src_height, 1, dst_height) : 1;
163 src_width * mode->vtotal * fps * fmt->bpp *
167 src_width * hw_latency_lines * fps * fmt->bpp *
168 scale_factor * mode->vtotal;
170 if ((vbp+vpw) > hw_latency_lines)
171 do_div(plane_prefill_bw, (vbp+vpw));
172 else if ((vbp+vpw+vfp) < hw_latency_lines)
173 do_div(plane_prefill_bw, (vbp+vpw+vfp));
175 do_div(plane_prefill_bw, hw_latency_lines);
178 return max(plane_bw, plane_prefill_bw);
182 * _dpu_plane_calc_clk - calculate clock required for a plane
183 * @mode: Pointer to drm display mode
184 * @pipe_cfg: Pointer to pipe configuration
185 * Result: Updates calculated clock in the plane state.
186 * Clock equation: dst_w * v_total * fps * (src_h / dst_h)
188 static u64 _dpu_plane_calc_clk(const struct drm_display_mode *mode,
189 struct dpu_sw_pipe_cfg *pipe_cfg)
191 int dst_width, src_height, dst_height, fps;
194 src_height = drm_rect_height(&pipe_cfg->src_rect);
195 dst_width = drm_rect_width(&pipe_cfg->dst_rect);
196 dst_height = drm_rect_height(&pipe_cfg->dst_rect);
197 fps = drm_mode_vrefresh(mode);
200 dst_width * mode->vtotal * fps;
202 if (src_height > dst_height) {
203 plane_clk *= src_height;
204 do_div(plane_clk, dst_height);
211 * _dpu_plane_calc_fill_level - calculate fill level of the given source format
212 * @plane: Pointer to drm plane
213 * @pipe: Pointer to software pipe
214 * @fmt: Pointer to source buffer format
215 * @src_width: width of source buffer
216 * Return: fill level corresponding to the source buffer/format or 0 if error
218 static int _dpu_plane_calc_fill_level(struct drm_plane *plane,
219 struct dpu_sw_pipe *pipe,
220 const struct dpu_format *fmt, u32 src_width)
222 struct dpu_plane *pdpu;
226 if (!fmt || !pipe || !src_width || !fmt->bpp) {
227 DPU_ERROR("invalid arguments\n");
231 pdpu = to_dpu_plane(plane);
232 fixed_buff_size = pdpu->catalog->caps->pixel_ram_size;
234 /* FIXME: in multirect case account for the src_width of all the planes */
236 if (fmt->fetch_planes == DPU_PLANE_PSEUDO_PLANAR) {
237 if (fmt->chroma_sample == DPU_CHROMA_420) {
239 total_fl = (fixed_buff_size / 2) /
240 ((src_width + 32) * fmt->bpp);
243 total_fl = (fixed_buff_size / 2) * 2 /
244 ((src_width + 32) * fmt->bpp);
247 if (pipe->multirect_mode == DPU_SSPP_MULTIRECT_PARALLEL) {
248 total_fl = (fixed_buff_size / 2) * 2 /
249 ((src_width + 32) * fmt->bpp);
251 total_fl = (fixed_buff_size) * 2 /
252 ((src_width + 32) * fmt->bpp);
256 DPU_DEBUG_PLANE(pdpu, "pnum:%d fmt: %4.4s w:%u fl:%u\n",
257 pipe->sspp->idx - SSPP_VIG0,
258 (char *)&fmt->base.pixel_format,
259 src_width, total_fl);
265 * _dpu_plane_set_qos_lut - set QoS LUT of the given plane
266 * @plane: Pointer to drm plane
267 * @pipe: Pointer to software pipe
268 * @fmt: Pointer to source buffer format
269 * @pipe_cfg: Pointer to pipe configuration
271 static void _dpu_plane_set_qos_lut(struct drm_plane *plane,
272 struct dpu_sw_pipe *pipe,
273 const struct dpu_format *fmt, struct dpu_sw_pipe_cfg *pipe_cfg)
275 struct dpu_plane *pdpu = to_dpu_plane(plane);
277 u32 total_fl = 0, lut_usage;
279 if (!pdpu->is_rt_pipe) {
280 lut_usage = DPU_QOS_LUT_USAGE_NRT;
282 total_fl = _dpu_plane_calc_fill_level(plane, pipe, fmt,
283 drm_rect_width(&pipe_cfg->src_rect));
285 if (fmt && DPU_FORMAT_IS_LINEAR(fmt))
286 lut_usage = DPU_QOS_LUT_USAGE_LINEAR;
288 lut_usage = DPU_QOS_LUT_USAGE_MACROTILE;
291 qos_lut = _dpu_hw_get_qos_lut(
292 &pdpu->catalog->perf->qos_lut_tbl[lut_usage], total_fl);
294 trace_dpu_perf_set_qos_luts(pipe->sspp->idx - SSPP_VIG0,
295 (fmt) ? fmt->base.pixel_format : 0,
296 pdpu->is_rt_pipe, total_fl, qos_lut, lut_usage);
298 DPU_DEBUG_PLANE(pdpu, "pnum:%d fmt: %4.4s rt:%d fl:%u lut:0x%llx\n",
299 pdpu->pipe - SSPP_VIG0,
300 fmt ? (char *)&fmt->base.pixel_format : NULL,
301 pdpu->is_rt_pipe, total_fl, qos_lut);
303 pipe->sspp->ops.setup_creq_lut(pipe->sspp, qos_lut);
307 * _dpu_plane_set_danger_lut - set danger/safe LUT of the given plane
308 * @plane: Pointer to drm plane
309 * @pipe: Pointer to software pipe
310 * @fmt: Pointer to source buffer format
312 static void _dpu_plane_set_danger_lut(struct drm_plane *plane,
313 struct dpu_sw_pipe *pipe,
314 const struct dpu_format *fmt)
316 struct dpu_plane *pdpu = to_dpu_plane(plane);
317 u32 danger_lut, safe_lut;
319 if (!pdpu->is_rt_pipe) {
320 danger_lut = pdpu->catalog->perf->danger_lut_tbl
321 [DPU_QOS_LUT_USAGE_NRT];
322 safe_lut = pdpu->catalog->perf->safe_lut_tbl
323 [DPU_QOS_LUT_USAGE_NRT];
325 if (fmt && DPU_FORMAT_IS_LINEAR(fmt)) {
326 danger_lut = pdpu->catalog->perf->danger_lut_tbl
327 [DPU_QOS_LUT_USAGE_LINEAR];
328 safe_lut = pdpu->catalog->perf->safe_lut_tbl
329 [DPU_QOS_LUT_USAGE_LINEAR];
331 danger_lut = pdpu->catalog->perf->danger_lut_tbl
332 [DPU_QOS_LUT_USAGE_MACROTILE];
333 safe_lut = pdpu->catalog->perf->safe_lut_tbl
334 [DPU_QOS_LUT_USAGE_MACROTILE];
338 trace_dpu_perf_set_danger_luts(pdpu->pipe - SSPP_VIG0,
339 (fmt) ? fmt->base.pixel_format : 0,
340 (fmt) ? fmt->fetch_mode : 0,
344 DPU_DEBUG_PLANE(pdpu, "pnum:%d fmt: %4.4s mode:%d luts[0x%x, 0x%x]\n",
345 pdpu->pipe - SSPP_VIG0,
346 fmt ? (char *)&fmt->base.pixel_format : NULL,
347 fmt ? fmt->fetch_mode : -1,
351 pipe->sspp->ops.setup_danger_safe_lut(pipe->sspp,
352 danger_lut, safe_lut);
356 * _dpu_plane_set_qos_ctrl - set QoS control of the given plane
357 * @plane: Pointer to drm plane
358 * @pipe: Pointer to software pipe
359 * @enable: true to enable QoS control
360 * @flags: QoS control mode (enum dpu_plane_qos)
362 static void _dpu_plane_set_qos_ctrl(struct drm_plane *plane,
363 struct dpu_sw_pipe *pipe,
364 bool enable, u32 flags)
366 struct dpu_plane *pdpu = to_dpu_plane(plane);
367 struct dpu_hw_pipe_qos_cfg pipe_qos_cfg;
369 memset(&pipe_qos_cfg, 0, sizeof(pipe_qos_cfg));
371 if (flags & DPU_PLANE_QOS_VBLANK_CTRL) {
372 pipe_qos_cfg.creq_vblank = pipe->sspp->cap->sblk->creq_vblank;
373 pipe_qos_cfg.danger_vblank =
374 pipe->sspp->cap->sblk->danger_vblank;
375 pipe_qos_cfg.vblank_en = enable;
378 if (flags & DPU_PLANE_QOS_VBLANK_AMORTIZE) {
379 /* this feature overrules previous VBLANK_CTRL */
380 pipe_qos_cfg.vblank_en = false;
381 pipe_qos_cfg.creq_vblank = 0; /* clear vblank bits */
384 if (flags & DPU_PLANE_QOS_PANIC_CTRL)
385 pipe_qos_cfg.danger_safe_en = enable;
387 if (!pdpu->is_rt_pipe) {
388 pipe_qos_cfg.vblank_en = false;
389 pipe_qos_cfg.danger_safe_en = false;
392 DPU_DEBUG_PLANE(pdpu, "pnum:%d ds:%d vb:%d pri[0x%x, 0x%x] is_rt:%d\n",
393 pdpu->pipe - SSPP_VIG0,
394 pipe_qos_cfg.danger_safe_en,
395 pipe_qos_cfg.vblank_en,
396 pipe_qos_cfg.creq_vblank,
397 pipe_qos_cfg.danger_vblank,
400 pipe->sspp->ops.setup_qos_ctrl(pipe->sspp,
405 * _dpu_plane_set_ot_limit - set OT limit for the given plane
406 * @plane: Pointer to drm plane
407 * @pipe: Pointer to software pipe
408 * @pipe_cfg: Pointer to pipe configuration
409 * @frame_rate: CRTC's frame rate
411 static void _dpu_plane_set_ot_limit(struct drm_plane *plane,
412 struct dpu_sw_pipe *pipe,
413 struct dpu_sw_pipe_cfg *pipe_cfg,
416 struct dpu_plane *pdpu = to_dpu_plane(plane);
417 struct dpu_vbif_set_ot_params ot_params;
418 struct dpu_kms *dpu_kms = _dpu_plane_get_kms(plane);
420 memset(&ot_params, 0, sizeof(ot_params));
421 ot_params.xin_id = pipe->sspp->cap->xin_id;
422 ot_params.num = pipe->sspp->idx - SSPP_NONE;
423 ot_params.width = drm_rect_width(&pipe_cfg->src_rect);
424 ot_params.height = drm_rect_height(&pipe_cfg->src_rect);
425 ot_params.is_wfd = !pdpu->is_rt_pipe;
426 ot_params.frame_rate = frame_rate;
427 ot_params.vbif_idx = VBIF_RT;
428 ot_params.clk_ctrl = pipe->sspp->cap->clk_ctrl;
431 dpu_vbif_set_ot_limit(dpu_kms, &ot_params);
435 * _dpu_plane_set_qos_remap - set vbif QoS for the given plane
436 * @plane: Pointer to drm plane
437 * @pipe: Pointer to software pipe
439 static void _dpu_plane_set_qos_remap(struct drm_plane *plane,
440 struct dpu_sw_pipe *pipe)
442 struct dpu_plane *pdpu = to_dpu_plane(plane);
443 struct dpu_vbif_set_qos_params qos_params;
444 struct dpu_kms *dpu_kms = _dpu_plane_get_kms(plane);
446 memset(&qos_params, 0, sizeof(qos_params));
447 qos_params.vbif_idx = VBIF_RT;
448 qos_params.clk_ctrl = pipe->sspp->cap->clk_ctrl;
449 qos_params.xin_id = pipe->sspp->cap->xin_id;
450 qos_params.num = pipe->sspp->idx - SSPP_VIG0;
451 qos_params.is_rt = pdpu->is_rt_pipe;
453 DPU_DEBUG_PLANE(pdpu, "pipe:%d vbif:%d xin:%d rt:%d, clk_ctrl:%d\n",
456 qos_params.xin_id, qos_params.is_rt,
457 qos_params.clk_ctrl);
459 dpu_vbif_set_qos_remap(dpu_kms, &qos_params);
462 static void _dpu_plane_setup_scaler3(struct dpu_hw_sspp *pipe_hw,
463 uint32_t src_w, uint32_t src_h, uint32_t dst_w, uint32_t dst_h,
464 struct dpu_hw_scaler3_cfg *scale_cfg,
465 const struct dpu_format *fmt,
466 uint32_t chroma_subsmpl_h, uint32_t chroma_subsmpl_v,
467 unsigned int rotation)
470 bool inline_rotation = rotation & DRM_MODE_ROTATE_90;
473 * For inline rotation cases, scaler config is post-rotation,
474 * so swap the dimensions here. However, pixel extension will
475 * need pre-rotation settings.
480 scale_cfg->phase_step_x[DPU_SSPP_COMP_0] =
481 mult_frac((1 << PHASE_STEP_SHIFT), src_w, dst_w);
482 scale_cfg->phase_step_y[DPU_SSPP_COMP_0] =
483 mult_frac((1 << PHASE_STEP_SHIFT), src_h, dst_h);
486 scale_cfg->phase_step_y[DPU_SSPP_COMP_1_2] =
487 scale_cfg->phase_step_y[DPU_SSPP_COMP_0] / chroma_subsmpl_v;
488 scale_cfg->phase_step_x[DPU_SSPP_COMP_1_2] =
489 scale_cfg->phase_step_x[DPU_SSPP_COMP_0] / chroma_subsmpl_h;
491 scale_cfg->phase_step_x[DPU_SSPP_COMP_2] =
492 scale_cfg->phase_step_x[DPU_SSPP_COMP_1_2];
493 scale_cfg->phase_step_y[DPU_SSPP_COMP_2] =
494 scale_cfg->phase_step_y[DPU_SSPP_COMP_1_2];
496 scale_cfg->phase_step_x[DPU_SSPP_COMP_3] =
497 scale_cfg->phase_step_x[DPU_SSPP_COMP_0];
498 scale_cfg->phase_step_y[DPU_SSPP_COMP_3] =
499 scale_cfg->phase_step_y[DPU_SSPP_COMP_0];
501 for (i = 0; i < DPU_MAX_PLANES; i++) {
502 scale_cfg->src_width[i] = src_w;
503 scale_cfg->src_height[i] = src_h;
504 if (i == DPU_SSPP_COMP_1_2 || i == DPU_SSPP_COMP_2) {
505 scale_cfg->src_width[i] /= chroma_subsmpl_h;
506 scale_cfg->src_height[i] /= chroma_subsmpl_v;
509 if (pipe_hw->cap->features &
510 BIT(DPU_SSPP_SCALER_QSEED4)) {
511 scale_cfg->preload_x[i] = DPU_QSEED4_DEFAULT_PRELOAD_H;
512 scale_cfg->preload_y[i] = DPU_QSEED4_DEFAULT_PRELOAD_V;
514 scale_cfg->preload_x[i] = DPU_QSEED3_DEFAULT_PRELOAD_H;
515 scale_cfg->preload_y[i] = DPU_QSEED3_DEFAULT_PRELOAD_V;
518 if (!(DPU_FORMAT_IS_YUV(fmt)) && (src_h == dst_h)
522 scale_cfg->dst_width = dst_w;
523 scale_cfg->dst_height = dst_h;
524 scale_cfg->y_rgb_filter_cfg = DPU_SCALE_BIL;
525 scale_cfg->uv_filter_cfg = DPU_SCALE_BIL;
526 scale_cfg->alpha_filter_cfg = DPU_SCALE_ALPHA_BIL;
527 scale_cfg->lut_flag = 0;
528 scale_cfg->blend_cfg = 1;
529 scale_cfg->enable = 1;
532 static void _dpu_plane_setup_pixel_ext(struct dpu_hw_scaler3_cfg *scale_cfg,
533 struct dpu_hw_pixel_ext *pixel_ext,
534 uint32_t src_w, uint32_t src_h,
535 uint32_t chroma_subsmpl_h, uint32_t chroma_subsmpl_v)
539 for (i = 0; i < DPU_MAX_PLANES; i++) {
540 if (i == DPU_SSPP_COMP_1_2 || i == DPU_SSPP_COMP_2) {
541 src_w /= chroma_subsmpl_h;
542 src_h /= chroma_subsmpl_v;
545 pixel_ext->num_ext_pxls_top[i] = src_h;
546 pixel_ext->num_ext_pxls_left[i] = src_w;
550 static const struct dpu_csc_cfg dpu_csc_YUV2RGB_601L = {
553 0x00012A00, 0x00000000, 0x00019880,
554 0x00012A00, 0xFFFF9B80, 0xFFFF3000,
555 0x00012A00, 0x00020480, 0x00000000,
558 { 0xfff0, 0xff80, 0xff80,},
561 { 0x10, 0xeb, 0x10, 0xf0, 0x10, 0xf0,},
562 { 0x00, 0xff, 0x00, 0xff, 0x00, 0xff,},
565 static const struct dpu_csc_cfg dpu_csc10_YUV2RGB_601L = {
568 0x00012A00, 0x00000000, 0x00019880,
569 0x00012A00, 0xFFFF9B80, 0xFFFF3000,
570 0x00012A00, 0x00020480, 0x00000000,
573 { 0xffc0, 0xfe00, 0xfe00,},
576 { 0x40, 0x3ac, 0x40, 0x3c0, 0x40, 0x3c0,},
577 { 0x00, 0x3ff, 0x00, 0x3ff, 0x00, 0x3ff,},
580 static const struct dpu_csc_cfg *_dpu_plane_get_csc(struct dpu_sw_pipe *pipe,
581 const struct dpu_format *fmt)
583 const struct dpu_csc_cfg *csc_ptr;
585 if (!DPU_FORMAT_IS_YUV(fmt))
588 if (BIT(DPU_SSPP_CSC_10BIT) & pipe->sspp->cap->features)
589 csc_ptr = &dpu_csc10_YUV2RGB_601L;
591 csc_ptr = &dpu_csc_YUV2RGB_601L;
596 static void _dpu_plane_setup_scaler(struct dpu_sw_pipe *pipe,
597 const struct dpu_format *fmt, bool color_fill,
598 struct dpu_sw_pipe_cfg *pipe_cfg,
599 unsigned int rotation)
601 struct dpu_hw_sspp *pipe_hw = pipe->sspp;
602 const struct drm_format_info *info = drm_format_info(fmt->base.pixel_format);
603 struct dpu_hw_scaler3_cfg scaler3_cfg;
604 struct dpu_hw_pixel_ext pixel_ext;
605 u32 src_width = drm_rect_width(&pipe_cfg->src_rect);
606 u32 src_height = drm_rect_height(&pipe_cfg->src_rect);
607 u32 dst_width = drm_rect_width(&pipe_cfg->dst_rect);
608 u32 dst_height = drm_rect_height(&pipe_cfg->dst_rect);
610 memset(&scaler3_cfg, 0, sizeof(scaler3_cfg));
611 memset(&pixel_ext, 0, sizeof(pixel_ext));
613 /* don't chroma subsample if decimating */
614 /* update scaler. calculate default config for QSEED3 */
615 _dpu_plane_setup_scaler3(pipe_hw,
621 info->hsub, info->vsub,
624 /* configure pixel extension based on scalar config */
625 _dpu_plane_setup_pixel_ext(&scaler3_cfg, &pixel_ext,
626 src_width, src_height, info->hsub, info->vsub);
628 if (pipe_hw->ops.setup_pe)
629 pipe_hw->ops.setup_pe(pipe_hw,
633 * when programmed in multirect mode, scalar block will be
634 * bypassed. Still we need to update alpha and bitwidth
637 if (pipe_hw->ops.setup_scaler &&
638 pipe->multirect_index != DPU_SSPP_RECT_1)
639 pipe_hw->ops.setup_scaler(pipe_hw,
644 static void _dpu_plane_color_fill_pipe(struct dpu_plane_state *pstate,
645 struct dpu_sw_pipe *pipe,
646 struct drm_rect *dst_rect,
648 const struct dpu_format *fmt)
650 struct dpu_sw_pipe_cfg pipe_cfg;
653 if (!pipe->sspp->ops.setup_solidfill)
656 pipe->sspp->ops.setup_solidfill(pipe, fill_color);
658 /* override scaler/decimation if solid fill */
659 pipe_cfg.dst_rect = *dst_rect;
661 pipe_cfg.src_rect.x1 = 0;
662 pipe_cfg.src_rect.y1 = 0;
663 pipe_cfg.src_rect.x2 =
664 drm_rect_width(&pipe_cfg.dst_rect);
665 pipe_cfg.src_rect.y2 =
666 drm_rect_height(&pipe_cfg.dst_rect);
668 if (pipe->sspp->ops.setup_format)
669 pipe->sspp->ops.setup_format(pipe, fmt, DPU_SSPP_SOLID_FILL);
671 if (pipe->sspp->ops.setup_rects)
672 pipe->sspp->ops.setup_rects(pipe, &pipe_cfg);
674 _dpu_plane_setup_scaler(pipe, fmt, true, &pipe_cfg, pstate->rotation);
678 * _dpu_plane_color_fill - enables color fill on plane
679 * @pdpu: Pointer to DPU plane object
680 * @color: RGB fill color value, [23..16] Blue, [15..8] Green, [7..0] Red
681 * @alpha: 8-bit fill alpha value, 255 selects 100% alpha
683 static void _dpu_plane_color_fill(struct dpu_plane *pdpu,
684 uint32_t color, uint32_t alpha)
686 const struct dpu_format *fmt;
687 const struct drm_plane *plane = &pdpu->base;
688 struct dpu_plane_state *pstate = to_dpu_plane_state(plane->state);
689 u32 fill_color = (color & 0xFFFFFF) | ((alpha & 0xFF) << 24);
691 DPU_DEBUG_PLANE(pdpu, "\n");
694 * select fill format to match user property expectation,
695 * h/w only supports RGB variants
697 fmt = dpu_get_dpu_format(DRM_FORMAT_ABGR8888);
698 /* should not happen ever */
703 _dpu_plane_color_fill_pipe(pstate, &pstate->pipe, &pstate->pipe_cfg.dst_rect,
706 if (pstate->r_pipe.sspp)
707 _dpu_plane_color_fill_pipe(pstate, &pstate->r_pipe, &pstate->r_pipe_cfg.dst_rect,
711 int dpu_plane_validate_multirect_v2(struct dpu_multirect_plane_states *plane)
713 struct dpu_plane_state *pstate[R_MAX];
714 const struct drm_plane_state *drm_state[R_MAX];
715 struct drm_rect src[R_MAX], dst[R_MAX];
716 struct dpu_plane *dpu_plane[R_MAX];
717 const struct dpu_format *fmt[R_MAX];
719 unsigned int max_tile_height = 1;
720 bool parallel_fetch_qualified = true;
721 bool has_tiled_rect = false;
723 for (i = 0; i < R_MAX; i++) {
724 const struct msm_format *msm_fmt;
726 drm_state[i] = i ? plane->r1 : plane->r0;
727 msm_fmt = msm_framebuffer_format(drm_state[i]->fb);
728 fmt[i] = to_dpu_format(msm_fmt);
730 if (DPU_FORMAT_IS_UBWC(fmt[i])) {
731 has_tiled_rect = true;
732 if (fmt[i]->tile_height > max_tile_height)
733 max_tile_height = fmt[i]->tile_height;
737 for (i = 0; i < R_MAX; i++) {
740 pstate[i] = to_dpu_plane_state(drm_state[i]);
741 dpu_plane[i] = to_dpu_plane(drm_state[i]->plane);
743 if (pstate[i] == NULL) {
744 DPU_ERROR("DPU plane state of plane id %d is NULL\n",
745 drm_state[i]->plane->base.id);
749 src[i].x1 = drm_state[i]->src_x >> 16;
750 src[i].y1 = drm_state[i]->src_y >> 16;
751 src[i].x2 = src[i].x1 + (drm_state[i]->src_w >> 16);
752 src[i].y2 = src[i].y1 + (drm_state[i]->src_h >> 16);
754 dst[i] = drm_plane_state_dest(drm_state[i]);
756 if (drm_rect_calc_hscale(&src[i], &dst[i], 1, 1) != 1 ||
757 drm_rect_calc_vscale(&src[i], &dst[i], 1, 1) != 1) {
758 DPU_ERROR_PLANE(dpu_plane[i],
759 "scaling is not supported in multirect mode\n");
763 if (DPU_FORMAT_IS_YUV(fmt[i])) {
764 DPU_ERROR_PLANE(dpu_plane[i],
765 "Unsupported format for multirect mode\n");
770 * SSPP PD_MEM is split half - one for each RECT.
771 * Tiled formats need 5 lines of buffering while fetching
772 * whereas linear formats need only 2 lines.
773 * So we cannot support more than half of the supported SSPP
774 * width for tiled formats.
776 width_threshold = dpu_plane[i]->catalog->caps->max_linewidth;
778 width_threshold /= 2;
780 if (parallel_fetch_qualified &&
781 drm_rect_width(&src[i]) > width_threshold)
782 parallel_fetch_qualified = false;
786 /* Validate RECT's and set the mode */
788 /* Prefer PARALLEL FETCH Mode over TIME_MX Mode */
789 if (parallel_fetch_qualified) {
790 pstate[R0]->pipe.multirect_mode = DPU_SSPP_MULTIRECT_PARALLEL;
791 pstate[R1]->pipe.multirect_mode = DPU_SSPP_MULTIRECT_PARALLEL;
797 buffer_lines = 2 * max_tile_height;
799 if (dst[R1].y1 >= dst[R0].y2 + buffer_lines ||
800 dst[R0].y1 >= dst[R1].y2 + buffer_lines) {
801 pstate[R0]->pipe.multirect_mode = DPU_SSPP_MULTIRECT_TIME_MX;
802 pstate[R1]->pipe.multirect_mode = DPU_SSPP_MULTIRECT_TIME_MX;
805 "No multirect mode possible for the planes (%d - %d)\n",
806 drm_state[R0]->plane->base.id,
807 drm_state[R1]->plane->base.id);
812 pstate[R0]->pipe.multirect_index = DPU_SSPP_RECT_0;
813 pstate[R1]->pipe.multirect_index = DPU_SSPP_RECT_1;
815 DPU_DEBUG_PLANE(dpu_plane[R0], "R0: %d - %d\n",
816 pstate[R0]->pipe.multirect_mode, pstate[R0]->pipe.multirect_index);
817 DPU_DEBUG_PLANE(dpu_plane[R1], "R1: %d - %d\n",
818 pstate[R1]->pipe.multirect_mode, pstate[R1]->pipe.multirect_index);
822 static int dpu_plane_prepare_fb(struct drm_plane *plane,
823 struct drm_plane_state *new_state)
825 struct drm_framebuffer *fb = new_state->fb;
826 struct dpu_plane *pdpu = to_dpu_plane(plane);
827 struct dpu_plane_state *pstate = to_dpu_plane_state(new_state);
828 struct dpu_hw_fmt_layout layout;
829 struct dpu_kms *kms = _dpu_plane_get_kms(&pdpu->base);
835 DPU_DEBUG_PLANE(pdpu, "FB[%u]\n", fb->base.id);
838 pstate->aspace = kms->base.aspace;
841 * TODO: Need to sort out the msm_framebuffer_prepare() call below so
842 * we can use msm_atomic_prepare_fb() instead of doing the
843 * implicit fence and fb prepare by hand here.
845 drm_gem_plane_helper_prepare_fb(plane, new_state);
847 if (pstate->aspace) {
848 ret = msm_framebuffer_prepare(new_state->fb,
849 pstate->aspace, pstate->needs_dirtyfb);
851 DPU_ERROR("failed to prepare framebuffer\n");
856 /* validate framebuffer layout before commit */
857 ret = dpu_format_populate_layout(pstate->aspace,
858 new_state->fb, &layout);
860 DPU_ERROR_PLANE(pdpu, "failed to get format layout, %d\n", ret);
867 static void dpu_plane_cleanup_fb(struct drm_plane *plane,
868 struct drm_plane_state *old_state)
870 struct dpu_plane *pdpu = to_dpu_plane(plane);
871 struct dpu_plane_state *old_pstate;
873 if (!old_state || !old_state->fb)
876 old_pstate = to_dpu_plane_state(old_state);
878 DPU_DEBUG_PLANE(pdpu, "FB[%u]\n", old_state->fb->base.id);
880 msm_framebuffer_cleanup(old_state->fb, old_pstate->aspace,
881 old_pstate->needs_dirtyfb);
884 static int dpu_plane_check_inline_rotation(struct dpu_plane *pdpu,
885 const struct dpu_sspp_sub_blks *sblk,
886 struct drm_rect src, const struct dpu_format *fmt)
889 const u32 *supported_formats;
891 if (!sblk->rotation_cfg) {
892 DPU_ERROR("invalid rotation cfg\n");
896 if (drm_rect_width(&src) > sblk->rotation_cfg->rot_maxheight) {
897 DPU_DEBUG_PLANE(pdpu, "invalid height for inline rot:%d max:%d\n",
898 src.y2, sblk->rotation_cfg->rot_maxheight);
902 supported_formats = sblk->rotation_cfg->rot_format_list;
903 num_formats = sblk->rotation_cfg->rot_num_formats;
905 if (!DPU_FORMAT_IS_UBWC(fmt) ||
906 !dpu_find_format(fmt->base.pixel_format, supported_formats, num_formats))
912 static int dpu_plane_atomic_check_pipe(struct dpu_plane *pdpu,
913 struct dpu_sw_pipe *pipe,
914 struct dpu_sw_pipe_cfg *pipe_cfg,
915 const struct dpu_format *fmt)
917 uint32_t min_src_size;
919 min_src_size = DPU_FORMAT_IS_YUV(fmt) ? 2 : 1;
921 if (DPU_FORMAT_IS_YUV(fmt) &&
922 (!(pipe->sspp->cap->features & DPU_SSPP_SCALER) ||
923 !(pipe->sspp->cap->features & DPU_SSPP_CSC_ANY))) {
924 DPU_DEBUG_PLANE(pdpu,
925 "plane doesn't have scaler/csc for yuv\n");
929 /* check src bounds */
930 if (drm_rect_width(&pipe_cfg->src_rect) < min_src_size ||
931 drm_rect_height(&pipe_cfg->src_rect) < min_src_size) {
932 DPU_DEBUG_PLANE(pdpu, "invalid source " DRM_RECT_FMT "\n",
933 DRM_RECT_ARG(&pipe_cfg->src_rect));
937 /* valid yuv image */
938 if (DPU_FORMAT_IS_YUV(fmt) &&
939 (pipe_cfg->src_rect.x1 & 0x1 ||
940 pipe_cfg->src_rect.y1 & 0x1 ||
941 drm_rect_width(&pipe_cfg->src_rect) & 0x1 ||
942 drm_rect_height(&pipe_cfg->src_rect) & 0x1)) {
943 DPU_DEBUG_PLANE(pdpu, "invalid yuv source " DRM_RECT_FMT "\n",
944 DRM_RECT_ARG(&pipe_cfg->src_rect));
948 /* min dst support */
949 if (drm_rect_width(&pipe_cfg->dst_rect) < 0x1 ||
950 drm_rect_height(&pipe_cfg->dst_rect) < 0x1) {
951 DPU_DEBUG_PLANE(pdpu, "invalid dest rect " DRM_RECT_FMT "\n",
952 DRM_RECT_ARG(&pipe_cfg->dst_rect));
959 static int dpu_plane_atomic_check(struct drm_plane *plane,
960 struct drm_atomic_state *state)
962 struct drm_plane_state *new_plane_state = drm_atomic_get_new_plane_state(state,
964 int ret = 0, min_scale;
965 struct dpu_plane *pdpu = to_dpu_plane(plane);
966 struct dpu_plane_state *pstate = to_dpu_plane_state(new_plane_state);
967 struct dpu_sw_pipe *pipe = &pstate->pipe;
968 struct dpu_sw_pipe *r_pipe = &pstate->r_pipe;
969 const struct drm_crtc_state *crtc_state = NULL;
970 const struct dpu_format *fmt;
971 struct dpu_sw_pipe_cfg *pipe_cfg = &pstate->pipe_cfg;
972 struct dpu_sw_pipe_cfg *r_pipe_cfg = &pstate->r_pipe_cfg;
973 struct drm_rect fb_rect = { 0 };
974 uint32_t max_linewidth;
975 unsigned int rotation;
976 uint32_t supported_rotations;
977 const struct dpu_sspp_cfg *pipe_hw_caps = pstate->pipe.sspp->cap;
978 const struct dpu_sspp_sub_blks *sblk = pstate->pipe.sspp->cap->sblk;
980 if (new_plane_state->crtc)
981 crtc_state = drm_atomic_get_new_crtc_state(state,
982 new_plane_state->crtc);
984 min_scale = FRAC_16_16(1, sblk->maxupscale);
985 ret = drm_atomic_helper_check_plane_state(new_plane_state, crtc_state,
987 sblk->maxdwnscale << 16,
990 DPU_DEBUG_PLANE(pdpu, "Check plane state failed (%d)\n", ret);
993 if (!new_plane_state->visible)
996 pipe->multirect_index = DPU_SSPP_RECT_SOLO;
997 pipe->multirect_mode = DPU_SSPP_MULTIRECT_NONE;
998 r_pipe->multirect_index = DPU_SSPP_RECT_SOLO;
999 r_pipe->multirect_mode = DPU_SSPP_MULTIRECT_NONE;
1000 r_pipe->sspp = NULL;
1002 pstate->stage = DPU_STAGE_0 + pstate->base.normalized_zpos;
1003 if (pstate->stage >= pdpu->catalog->caps->max_mixer_blendstages) {
1004 DPU_ERROR("> %d plane stages assigned\n",
1005 pdpu->catalog->caps->max_mixer_blendstages - DPU_STAGE_0);
1009 pipe_cfg->src_rect = new_plane_state->src;
1011 /* state->src is 16.16, src_rect is not */
1012 pipe_cfg->src_rect.x1 >>= 16;
1013 pipe_cfg->src_rect.x2 >>= 16;
1014 pipe_cfg->src_rect.y1 >>= 16;
1015 pipe_cfg->src_rect.y2 >>= 16;
1017 pipe_cfg->dst_rect = new_plane_state->dst;
1019 fb_rect.x2 = new_plane_state->fb->width;
1020 fb_rect.y2 = new_plane_state->fb->height;
1022 /* Ensure fb size is supported */
1023 if (drm_rect_width(&fb_rect) > MAX_IMG_WIDTH ||
1024 drm_rect_height(&fb_rect) > MAX_IMG_HEIGHT) {
1025 DPU_DEBUG_PLANE(pdpu, "invalid framebuffer " DRM_RECT_FMT "\n",
1026 DRM_RECT_ARG(&fb_rect));
1030 fmt = to_dpu_format(msm_framebuffer_format(new_plane_state->fb));
1032 max_linewidth = pdpu->catalog->caps->max_linewidth;
1034 if (drm_rect_width(&pipe_cfg->src_rect) > max_linewidth) {
1036 * In parallel multirect case only the half of the usual width
1037 * is supported for tiled formats. If we are here, we know that
1038 * full width is more than max_linewidth, thus each rect is
1039 * wider than allowed.
1041 if (DPU_FORMAT_IS_UBWC(fmt)) {
1042 DPU_DEBUG_PLANE(pdpu, "invalid src " DRM_RECT_FMT " line:%u, tiled format\n",
1043 DRM_RECT_ARG(&pipe_cfg->src_rect), max_linewidth);
1047 if (drm_rect_width(&pipe_cfg->src_rect) > 2 * max_linewidth) {
1048 DPU_DEBUG_PLANE(pdpu, "invalid src " DRM_RECT_FMT " line:%u\n",
1049 DRM_RECT_ARG(&pipe_cfg->src_rect), max_linewidth);
1053 if (drm_rect_width(&pipe_cfg->src_rect) != drm_rect_width(&pipe_cfg->dst_rect) ||
1054 drm_rect_height(&pipe_cfg->src_rect) != drm_rect_height(&pipe_cfg->dst_rect) ||
1055 (!test_bit(DPU_SSPP_SMART_DMA_V1, &pipe->sspp->cap->features) &&
1056 !test_bit(DPU_SSPP_SMART_DMA_V2, &pipe->sspp->cap->features)) ||
1057 DPU_FORMAT_IS_YUV(fmt)) {
1058 DPU_DEBUG_PLANE(pdpu, "invalid src " DRM_RECT_FMT " line:%u, can't use split source\n",
1059 DRM_RECT_ARG(&pipe_cfg->src_rect), max_linewidth);
1064 * Use multirect for wide plane. We do not support dynamic
1065 * assignment of SSPPs, so we know the configuration.
1067 pipe->multirect_index = DPU_SSPP_RECT_0;
1068 pipe->multirect_mode = DPU_SSPP_MULTIRECT_PARALLEL;
1070 r_pipe->sspp = pipe->sspp;
1071 r_pipe->multirect_index = DPU_SSPP_RECT_1;
1072 r_pipe->multirect_mode = DPU_SSPP_MULTIRECT_PARALLEL;
1074 *r_pipe_cfg = *pipe_cfg;
1075 pipe_cfg->src_rect.x2 = (pipe_cfg->src_rect.x1 + pipe_cfg->src_rect.x2) >> 1;
1076 pipe_cfg->dst_rect.x2 = (pipe_cfg->dst_rect.x1 + pipe_cfg->dst_rect.x2) >> 1;
1077 r_pipe_cfg->src_rect.x1 = pipe_cfg->src_rect.x2;
1078 r_pipe_cfg->dst_rect.x1 = pipe_cfg->dst_rect.x2;
1081 ret = dpu_plane_atomic_check_pipe(pdpu, pipe, pipe_cfg, fmt);
1086 ret = dpu_plane_atomic_check_pipe(pdpu, r_pipe, r_pipe_cfg, fmt);
1091 supported_rotations = DRM_MODE_REFLECT_MASK | DRM_MODE_ROTATE_0;
1093 if (pipe_hw_caps->features & BIT(DPU_SSPP_INLINE_ROTATION))
1094 supported_rotations |= DRM_MODE_ROTATE_90;
1096 rotation = drm_rotation_simplify(new_plane_state->rotation,
1097 supported_rotations);
1099 if ((pipe_hw_caps->features & BIT(DPU_SSPP_INLINE_ROTATION)) &&
1100 (rotation & DRM_MODE_ROTATE_90)) {
1101 ret = dpu_plane_check_inline_rotation(pdpu, sblk, pipe_cfg->src_rect, fmt);
1106 pstate->rotation = rotation;
1107 pstate->needs_qos_remap = drm_atomic_crtc_needs_modeset(crtc_state);
1112 static void dpu_plane_flush_csc(struct dpu_plane *pdpu, struct dpu_sw_pipe *pipe)
1114 const struct dpu_format *format =
1115 to_dpu_format(msm_framebuffer_format(pdpu->base.state->fb));
1116 const struct dpu_csc_cfg *csc_ptr;
1118 if (!pipe->sspp || !pipe->sspp->ops.setup_csc)
1121 csc_ptr = _dpu_plane_get_csc(pipe, format);
1125 DPU_DEBUG_PLANE(pdpu, "using 0x%X 0x%X 0x%X...\n",
1128 csc_ptr->csc_mv[2]);
1130 pipe->sspp->ops.setup_csc(pipe->sspp, csc_ptr);
1134 void dpu_plane_flush(struct drm_plane *plane)
1136 struct dpu_plane *pdpu;
1137 struct dpu_plane_state *pstate;
1139 if (!plane || !plane->state) {
1140 DPU_ERROR("invalid plane\n");
1144 pdpu = to_dpu_plane(plane);
1145 pstate = to_dpu_plane_state(plane->state);
1148 * These updates have to be done immediately before the plane flush
1149 * timing, and may not be moved to the atomic_update/mode_set functions.
1152 /* force white frame with 100% alpha pipe output on error */
1153 _dpu_plane_color_fill(pdpu, 0xFFFFFF, 0xFF);
1154 else if (pdpu->color_fill & DPU_PLANE_COLOR_FILL_FLAG)
1155 /* force 100% alpha */
1156 _dpu_plane_color_fill(pdpu, pdpu->color_fill, 0xFF);
1158 dpu_plane_flush_csc(pdpu, &pstate->pipe);
1159 dpu_plane_flush_csc(pdpu, &pstate->r_pipe);
1162 /* flag h/w flush complete */
1164 pstate->pending = false;
1168 * dpu_plane_set_error: enable/disable error condition
1169 * @plane: pointer to drm_plane structure
1170 * @error: error value to set
1172 void dpu_plane_set_error(struct drm_plane *plane, bool error)
1174 struct dpu_plane *pdpu;
1179 pdpu = to_dpu_plane(plane);
1180 pdpu->is_error = error;
1183 static void dpu_plane_sspp_update_pipe(struct drm_plane *plane,
1184 struct dpu_sw_pipe *pipe,
1185 struct dpu_sw_pipe_cfg *pipe_cfg,
1186 const struct dpu_format *fmt,
1188 struct dpu_hw_fmt_layout *layout)
1191 struct dpu_plane *pdpu = to_dpu_plane(plane);
1192 struct drm_plane_state *state = plane->state;
1193 struct dpu_plane_state *pstate = to_dpu_plane_state(state);
1195 if (layout && pipe->sspp->ops.setup_sourceaddress) {
1196 trace_dpu_plane_set_scanout(pipe, layout);
1197 pipe->sspp->ops.setup_sourceaddress(pipe, layout);
1200 _dpu_plane_set_qos_ctrl(plane, pipe, false, DPU_PLANE_QOS_PANIC_CTRL);
1202 /* override for color fill */
1203 if (pdpu->color_fill & DPU_PLANE_COLOR_FILL_FLAG) {
1204 /* skip remaining processing on color fill */
1208 if (pipe->sspp->ops.setup_rects) {
1209 pipe->sspp->ops.setup_rects(pipe,
1213 _dpu_plane_setup_scaler(pipe, fmt, false, pipe_cfg, pstate->rotation);
1215 if (pipe->sspp->ops.setup_multirect)
1216 pipe->sspp->ops.setup_multirect(
1219 if (pipe->sspp->ops.setup_format) {
1220 unsigned int rotation = pstate->rotation;
1224 if (rotation & DRM_MODE_REFLECT_X)
1225 src_flags |= DPU_SSPP_FLIP_LR;
1227 if (rotation & DRM_MODE_REFLECT_Y)
1228 src_flags |= DPU_SSPP_FLIP_UD;
1230 if (rotation & DRM_MODE_ROTATE_90)
1231 src_flags |= DPU_SSPP_ROT_90;
1234 pipe->sspp->ops.setup_format(pipe, fmt, src_flags);
1236 if (pipe->sspp->ops.setup_cdp) {
1237 struct dpu_hw_cdp_cfg cdp_cfg;
1239 memset(&cdp_cfg, 0, sizeof(struct dpu_hw_cdp_cfg));
1241 cdp_cfg.enable = pdpu->catalog->perf->cdp_cfg
1242 [DPU_PERF_CDP_USAGE_RT].rd_enable;
1243 cdp_cfg.ubwc_meta_enable =
1244 DPU_FORMAT_IS_UBWC(fmt);
1245 cdp_cfg.tile_amortize_enable =
1246 DPU_FORMAT_IS_UBWC(fmt) ||
1247 DPU_FORMAT_IS_TILE(fmt);
1248 cdp_cfg.preload_ahead = DPU_SSPP_CDP_PRELOAD_AHEAD_64;
1250 pipe->sspp->ops.setup_cdp(pipe, &cdp_cfg);
1254 _dpu_plane_set_qos_lut(plane, pipe, fmt, pipe_cfg);
1255 _dpu_plane_set_danger_lut(plane, pipe, fmt);
1257 if (plane->type != DRM_PLANE_TYPE_CURSOR) {
1258 _dpu_plane_set_qos_ctrl(plane, pipe, true, DPU_PLANE_QOS_PANIC_CTRL);
1259 _dpu_plane_set_ot_limit(plane, pipe, pipe_cfg, frame_rate);
1262 if (pstate->needs_qos_remap)
1263 _dpu_plane_set_qos_remap(plane, pipe);
1266 static void dpu_plane_sspp_atomic_update(struct drm_plane *plane)
1268 struct dpu_plane *pdpu = to_dpu_plane(plane);
1269 struct drm_plane_state *state = plane->state;
1270 struct dpu_plane_state *pstate = to_dpu_plane_state(state);
1271 struct dpu_sw_pipe *pipe = &pstate->pipe;
1272 struct dpu_sw_pipe *r_pipe = &pstate->r_pipe;
1273 struct drm_crtc *crtc = state->crtc;
1274 struct drm_framebuffer *fb = state->fb;
1276 const struct dpu_format *fmt =
1277 to_dpu_format(msm_framebuffer_format(fb));
1278 struct dpu_sw_pipe_cfg *pipe_cfg = &pstate->pipe_cfg;
1279 struct dpu_sw_pipe_cfg *r_pipe_cfg = &pstate->r_pipe_cfg;
1280 struct dpu_kms *kms = _dpu_plane_get_kms(&pdpu->base);
1281 struct msm_gem_address_space *aspace = kms->base.aspace;
1282 struct dpu_hw_fmt_layout layout;
1283 bool layout_valid = false;
1286 ret = dpu_format_populate_layout(aspace, fb, &layout);
1288 DPU_ERROR_PLANE(pdpu, "failed to get format layout, %d\n", ret);
1290 layout_valid = true;
1292 pstate->pending = true;
1294 is_rt_pipe = (dpu_crtc_get_client_type(crtc) != NRT_CLIENT);
1295 pstate->needs_qos_remap |= (is_rt_pipe != pdpu->is_rt_pipe);
1296 pdpu->is_rt_pipe = is_rt_pipe;
1298 DPU_DEBUG_PLANE(pdpu, "FB[%u] " DRM_RECT_FP_FMT "->crtc%u " DRM_RECT_FMT
1299 ", %4.4s ubwc %d\n", fb->base.id, DRM_RECT_FP_ARG(&state->src),
1300 crtc->base.id, DRM_RECT_ARG(&state->dst),
1301 (char *)&fmt->base.pixel_format, DPU_FORMAT_IS_UBWC(fmt));
1303 dpu_plane_sspp_update_pipe(plane, pipe, pipe_cfg, fmt,
1304 drm_mode_vrefresh(&crtc->mode),
1305 layout_valid ? &layout : NULL);
1308 dpu_plane_sspp_update_pipe(plane, r_pipe, r_pipe_cfg, fmt,
1309 drm_mode_vrefresh(&crtc->mode),
1310 layout_valid ? &layout : NULL);
1313 if (pstate->needs_qos_remap)
1314 pstate->needs_qos_remap = false;
1316 pstate->plane_fetch_bw = _dpu_plane_calc_bw(pdpu->catalog, fmt,
1317 &crtc->mode, pipe_cfg);
1319 pstate->plane_clk = _dpu_plane_calc_clk(&crtc->mode, pipe_cfg);
1322 pstate->plane_fetch_bw += _dpu_plane_calc_bw(pdpu->catalog, fmt, &crtc->mode, r_pipe_cfg);
1324 pstate->plane_clk = max(pstate->plane_clk, _dpu_plane_calc_clk(&crtc->mode, r_pipe_cfg));
1328 static void _dpu_plane_atomic_disable(struct drm_plane *plane)
1330 struct drm_plane_state *state = plane->state;
1331 struct dpu_plane_state *pstate = to_dpu_plane_state(state);
1332 struct dpu_sw_pipe *r_pipe = &pstate->r_pipe;
1334 trace_dpu_plane_disable(DRMID(plane), false,
1335 pstate->pipe.multirect_mode);
1338 r_pipe->multirect_index = DPU_SSPP_RECT_SOLO;
1339 r_pipe->multirect_mode = DPU_SSPP_MULTIRECT_NONE;
1341 if (r_pipe->sspp->ops.setup_multirect)
1342 r_pipe->sspp->ops.setup_multirect(r_pipe);
1345 pstate->pending = true;
1348 static void dpu_plane_atomic_update(struct drm_plane *plane,
1349 struct drm_atomic_state *state)
1351 struct dpu_plane *pdpu = to_dpu_plane(plane);
1352 struct drm_plane_state *new_state = drm_atomic_get_new_plane_state(state,
1355 pdpu->is_error = false;
1357 DPU_DEBUG_PLANE(pdpu, "\n");
1359 if (!new_state->visible) {
1360 _dpu_plane_atomic_disable(plane);
1362 dpu_plane_sspp_atomic_update(plane);
1366 static void dpu_plane_destroy(struct drm_plane *plane)
1368 struct dpu_plane *pdpu = plane ? to_dpu_plane(plane) : NULL;
1369 struct dpu_plane_state *pstate;
1371 DPU_DEBUG_PLANE(pdpu, "\n");
1374 pstate = to_dpu_plane_state(plane->state);
1375 _dpu_plane_set_qos_ctrl(plane, &pstate->pipe, false, DPU_PLANE_QOS_PANIC_CTRL);
1377 if (pstate->r_pipe.sspp)
1378 _dpu_plane_set_qos_ctrl(plane, &pstate->r_pipe, false, DPU_PLANE_QOS_PANIC_CTRL);
1380 mutex_destroy(&pdpu->lock);
1382 /* this will destroy the states as well */
1383 drm_plane_cleanup(plane);
1389 static void dpu_plane_destroy_state(struct drm_plane *plane,
1390 struct drm_plane_state *state)
1392 __drm_atomic_helper_plane_destroy_state(state);
1393 kfree(to_dpu_plane_state(state));
1396 static struct drm_plane_state *
1397 dpu_plane_duplicate_state(struct drm_plane *plane)
1399 struct dpu_plane *pdpu;
1400 struct dpu_plane_state *pstate;
1401 struct dpu_plane_state *old_state;
1404 DPU_ERROR("invalid plane\n");
1406 } else if (!plane->state) {
1407 DPU_ERROR("invalid plane state\n");
1411 old_state = to_dpu_plane_state(plane->state);
1412 pdpu = to_dpu_plane(plane);
1413 pstate = kmemdup(old_state, sizeof(*old_state), GFP_KERNEL);
1415 DPU_ERROR_PLANE(pdpu, "failed to allocate state\n");
1419 DPU_DEBUG_PLANE(pdpu, "\n");
1421 pstate->pending = false;
1423 __drm_atomic_helper_plane_duplicate_state(plane, &pstate->base);
1425 return &pstate->base;
1428 static const char * const multirect_mode_name[] = {
1429 [DPU_SSPP_MULTIRECT_NONE] = "none",
1430 [DPU_SSPP_MULTIRECT_PARALLEL] = "parallel",
1431 [DPU_SSPP_MULTIRECT_TIME_MX] = "time_mx",
1434 static const char * const multirect_index_name[] = {
1435 [DPU_SSPP_RECT_SOLO] = "solo",
1436 [DPU_SSPP_RECT_0] = "rect_0",
1437 [DPU_SSPP_RECT_1] = "rect_1",
1440 static const char *dpu_get_multirect_mode(enum dpu_sspp_multirect_mode mode)
1442 if (WARN_ON(mode >= ARRAY_SIZE(multirect_mode_name)))
1445 return multirect_mode_name[mode];
1448 static const char *dpu_get_multirect_index(enum dpu_sspp_multirect_index index)
1450 if (WARN_ON(index >= ARRAY_SIZE(multirect_index_name)))
1453 return multirect_index_name[index];
1456 static void dpu_plane_atomic_print_state(struct drm_printer *p,
1457 const struct drm_plane_state *state)
1459 const struct dpu_plane_state *pstate = to_dpu_plane_state(state);
1460 const struct dpu_sw_pipe *pipe = &pstate->pipe;
1461 const struct dpu_sw_pipe_cfg *pipe_cfg = &pstate->pipe_cfg;
1462 const struct dpu_sw_pipe *r_pipe = &pstate->r_pipe;
1463 const struct dpu_sw_pipe_cfg *r_pipe_cfg = &pstate->r_pipe_cfg;
1465 drm_printf(p, "\tstage=%d\n", pstate->stage);
1467 drm_printf(p, "\tsspp[0]=%s\n", pipe->sspp->cap->name);
1468 drm_printf(p, "\tmultirect_mode[0]=%s\n", dpu_get_multirect_mode(pipe->multirect_mode));
1469 drm_printf(p, "\tmultirect_index[0]=%s\n",
1470 dpu_get_multirect_index(pipe->multirect_index));
1471 drm_printf(p, "\tsrc[0]=" DRM_RECT_FMT "\n", DRM_RECT_ARG(&pipe_cfg->src_rect));
1472 drm_printf(p, "\tdst[0]=" DRM_RECT_FMT "\n", DRM_RECT_ARG(&pipe_cfg->dst_rect));
1475 drm_printf(p, "\tsspp[1]=%s\n", r_pipe->sspp->cap->name);
1476 drm_printf(p, "\tmultirect_mode[1]=%s\n",
1477 dpu_get_multirect_mode(r_pipe->multirect_mode));
1478 drm_printf(p, "\tmultirect_index[1]=%s\n",
1479 dpu_get_multirect_index(r_pipe->multirect_index));
1480 drm_printf(p, "\tsrc[1]=" DRM_RECT_FMT "\n", DRM_RECT_ARG(&r_pipe_cfg->src_rect));
1481 drm_printf(p, "\tdst[1]=" DRM_RECT_FMT "\n", DRM_RECT_ARG(&r_pipe_cfg->dst_rect));
1485 static void dpu_plane_reset(struct drm_plane *plane)
1487 struct dpu_plane *pdpu;
1488 struct dpu_plane_state *pstate;
1489 struct dpu_kms *dpu_kms = _dpu_plane_get_kms(plane);
1492 DPU_ERROR("invalid plane\n");
1496 pdpu = to_dpu_plane(plane);
1497 DPU_DEBUG_PLANE(pdpu, "\n");
1499 /* remove previous state, if present */
1501 dpu_plane_destroy_state(plane, plane->state);
1502 plane->state = NULL;
1505 pstate = kzalloc(sizeof(*pstate), GFP_KERNEL);
1507 DPU_ERROR_PLANE(pdpu, "failed to allocate state\n");
1512 * Set the SSPP here until we have proper virtualized DPU planes.
1513 * This is the place where the state is allocated, so fill it fully.
1515 pstate->pipe.sspp = dpu_rm_get_sspp(&dpu_kms->rm, pdpu->pipe);
1516 pstate->pipe.multirect_index = DPU_SSPP_RECT_SOLO;
1517 pstate->pipe.multirect_mode = DPU_SSPP_MULTIRECT_NONE;
1519 pstate->r_pipe.sspp = NULL;
1521 __drm_atomic_helper_plane_reset(plane, &pstate->base);
1524 #ifdef CONFIG_DEBUG_FS
1525 void dpu_plane_danger_signal_ctrl(struct drm_plane *plane, bool enable)
1527 struct dpu_plane *pdpu = to_dpu_plane(plane);
1528 struct dpu_plane_state *pstate = to_dpu_plane_state(plane->state);
1529 struct dpu_kms *dpu_kms = _dpu_plane_get_kms(plane);
1531 if (!pdpu->is_rt_pipe)
1534 pm_runtime_get_sync(&dpu_kms->pdev->dev);
1535 _dpu_plane_set_qos_ctrl(plane, &pstate->pipe, enable, DPU_PLANE_QOS_PANIC_CTRL);
1536 if (pstate->r_pipe.sspp)
1537 _dpu_plane_set_qos_ctrl(plane, &pstate->r_pipe, enable, DPU_PLANE_QOS_PANIC_CTRL);
1538 pm_runtime_put_sync(&dpu_kms->pdev->dev);
1542 static bool dpu_plane_format_mod_supported(struct drm_plane *plane,
1543 uint32_t format, uint64_t modifier)
1545 if (modifier == DRM_FORMAT_MOD_LINEAR)
1548 if (modifier == DRM_FORMAT_MOD_QCOM_COMPRESSED)
1549 return dpu_find_format(format, qcom_compressed_supported_formats,
1550 ARRAY_SIZE(qcom_compressed_supported_formats));
1555 static const struct drm_plane_funcs dpu_plane_funcs = {
1556 .update_plane = drm_atomic_helper_update_plane,
1557 .disable_plane = drm_atomic_helper_disable_plane,
1558 .destroy = dpu_plane_destroy,
1559 .reset = dpu_plane_reset,
1560 .atomic_duplicate_state = dpu_plane_duplicate_state,
1561 .atomic_destroy_state = dpu_plane_destroy_state,
1562 .atomic_print_state = dpu_plane_atomic_print_state,
1563 .format_mod_supported = dpu_plane_format_mod_supported,
1566 static const struct drm_plane_helper_funcs dpu_plane_helper_funcs = {
1567 .prepare_fb = dpu_plane_prepare_fb,
1568 .cleanup_fb = dpu_plane_cleanup_fb,
1569 .atomic_check = dpu_plane_atomic_check,
1570 .atomic_update = dpu_plane_atomic_update,
1573 /* initialize plane */
1574 struct drm_plane *dpu_plane_init(struct drm_device *dev,
1575 uint32_t pipe, enum drm_plane_type type,
1576 unsigned long possible_crtcs)
1578 struct drm_plane *plane = NULL;
1579 const uint32_t *format_list;
1580 struct dpu_plane *pdpu;
1581 struct msm_drm_private *priv = dev->dev_private;
1582 struct dpu_kms *kms = to_dpu_kms(priv->kms);
1583 struct dpu_hw_sspp *pipe_hw;
1584 uint32_t num_formats;
1585 uint32_t supported_rotations;
1588 /* create and zero local structure */
1589 pdpu = kzalloc(sizeof(*pdpu), GFP_KERNEL);
1591 DPU_ERROR("[%u]failed to allocate local plane struct\n", pipe);
1593 return ERR_PTR(ret);
1596 /* cache local stuff for later */
1597 plane = &pdpu->base;
1600 /* initialize underlying h/w driver */
1601 pipe_hw = dpu_rm_get_sspp(&kms->rm, pipe);
1602 if (!pipe_hw || !pipe_hw->cap || !pipe_hw->cap->sblk) {
1603 DPU_ERROR("[%u]SSPP is invalid\n", pipe);
1607 format_list = pipe_hw->cap->sblk->format_list;
1608 num_formats = pipe_hw->cap->sblk->num_formats;
1610 ret = drm_universal_plane_init(dev, plane, 0xff, &dpu_plane_funcs,
1611 format_list, num_formats,
1612 supported_format_modifiers, type, NULL);
1616 pdpu->catalog = kms->catalog;
1618 ret = drm_plane_create_zpos_property(plane, 0, 0, DPU_ZPOS_MAX);
1620 DPU_ERROR("failed to install zpos property, rc = %d\n", ret);
1622 drm_plane_create_alpha_property(plane);
1623 drm_plane_create_blend_mode_property(plane,
1624 BIT(DRM_MODE_BLEND_PIXEL_NONE) |
1625 BIT(DRM_MODE_BLEND_PREMULTI) |
1626 BIT(DRM_MODE_BLEND_COVERAGE));
1628 supported_rotations = DRM_MODE_REFLECT_MASK | DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_180;
1630 if (pipe_hw->cap->features & BIT(DPU_SSPP_INLINE_ROTATION))
1631 supported_rotations |= DRM_MODE_ROTATE_MASK;
1633 drm_plane_create_rotation_property(plane,
1634 DRM_MODE_ROTATE_0, supported_rotations);
1636 drm_plane_enable_fb_damage_clips(plane);
1638 /* success! finalize initialization */
1639 drm_plane_helper_add(plane, &dpu_plane_helper_funcs);
1641 mutex_init(&pdpu->lock);
1643 DPU_DEBUG("%s created for pipe:%u id:%u\n", plane->name,
1644 pipe, plane->base.id);
1649 return ERR_PTR(ret);