1 // SPDX-License-Identifier: GPL-2.0+
3 * i.MX IPUv3 DP Overlay Planes
5 * Copyright (C) 2013 Philipp Zabel, Pengutronix
8 #include <drm/drm_atomic.h>
9 #include <drm/drm_atomic_helper.h>
10 #include <drm/drm_fb_cma_helper.h>
11 #include <drm/drm_fourcc.h>
12 #include <drm/drm_gem_cma_helper.h>
13 #include <drm/drm_gem_framebuffer_helper.h>
14 #include <drm/drm_managed.h>
15 #include <drm/drm_plane_helper.h>
17 #include <video/imx-ipu-v3.h>
20 #include "ipuv3-plane.h"
22 struct ipu_plane_state {
23 struct drm_plane_state base;
27 static inline struct ipu_plane_state *
28 to_ipu_plane_state(struct drm_plane_state *p)
30 return container_of(p, struct ipu_plane_state, base);
33 static inline struct ipu_plane *to_ipu_plane(struct drm_plane *p)
35 return container_of(p, struct ipu_plane, base);
38 static const uint32_t ipu_plane_formats[] = {
71 DRM_FORMAT_RGBX8888_A8,
72 DRM_FORMAT_BGRX8888_A8,
75 static const uint64_t ipu_format_modifiers[] = {
76 DRM_FORMAT_MOD_LINEAR,
77 DRM_FORMAT_MOD_INVALID
80 static const uint64_t pre_format_modifiers[] = {
81 DRM_FORMAT_MOD_LINEAR,
82 DRM_FORMAT_MOD_VIVANTE_TILED,
83 DRM_FORMAT_MOD_VIVANTE_SUPER_TILED,
84 DRM_FORMAT_MOD_INVALID
87 int ipu_plane_irq(struct ipu_plane *ipu_plane)
89 return ipu_idmac_channel_irq(ipu_plane->ipu, ipu_plane->ipu_ch,
93 static inline unsigned long
94 drm_plane_state_to_eba(struct drm_plane_state *state, int plane)
96 struct drm_framebuffer *fb = state->fb;
97 struct drm_gem_cma_object *cma_obj;
98 int x = state->src.x1 >> 16;
99 int y = state->src.y1 >> 16;
101 cma_obj = drm_fb_cma_get_gem_obj(fb, plane);
104 return cma_obj->paddr + fb->offsets[plane] + fb->pitches[plane] * y +
105 fb->format->cpp[plane] * x;
108 static inline unsigned long
109 drm_plane_state_to_ubo(struct drm_plane_state *state)
111 struct drm_framebuffer *fb = state->fb;
112 struct drm_gem_cma_object *cma_obj;
113 unsigned long eba = drm_plane_state_to_eba(state, 0);
114 int x = state->src.x1 >> 16;
115 int y = state->src.y1 >> 16;
117 cma_obj = drm_fb_cma_get_gem_obj(fb, 1);
120 x /= fb->format->hsub;
121 y /= fb->format->vsub;
123 return cma_obj->paddr + fb->offsets[1] + fb->pitches[1] * y +
124 fb->format->cpp[1] * x - eba;
127 static inline unsigned long
128 drm_plane_state_to_vbo(struct drm_plane_state *state)
130 struct drm_framebuffer *fb = state->fb;
131 struct drm_gem_cma_object *cma_obj;
132 unsigned long eba = drm_plane_state_to_eba(state, 0);
133 int x = state->src.x1 >> 16;
134 int y = state->src.y1 >> 16;
136 cma_obj = drm_fb_cma_get_gem_obj(fb, 2);
139 x /= fb->format->hsub;
140 y /= fb->format->vsub;
142 return cma_obj->paddr + fb->offsets[2] + fb->pitches[2] * y +
143 fb->format->cpp[2] * x - eba;
146 static void ipu_plane_put_resources(struct drm_device *dev, void *ptr)
148 struct ipu_plane *ipu_plane = ptr;
150 if (!IS_ERR_OR_NULL(ipu_plane->dp))
151 ipu_dp_put(ipu_plane->dp);
152 if (!IS_ERR_OR_NULL(ipu_plane->dmfc))
153 ipu_dmfc_put(ipu_plane->dmfc);
154 if (!IS_ERR_OR_NULL(ipu_plane->ipu_ch))
155 ipu_idmac_put(ipu_plane->ipu_ch);
156 if (!IS_ERR_OR_NULL(ipu_plane->alpha_ch))
157 ipu_idmac_put(ipu_plane->alpha_ch);
160 static int ipu_plane_get_resources(struct drm_device *dev,
161 struct ipu_plane *ipu_plane)
166 ipu_plane->ipu_ch = ipu_idmac_get(ipu_plane->ipu, ipu_plane->dma);
167 if (IS_ERR(ipu_plane->ipu_ch)) {
168 ret = PTR_ERR(ipu_plane->ipu_ch);
169 DRM_ERROR("failed to get idmac channel: %d\n", ret);
173 ret = drmm_add_action_or_reset(dev, ipu_plane_put_resources, ipu_plane);
177 alpha_ch = ipu_channel_alpha_channel(ipu_plane->dma);
179 ipu_plane->alpha_ch = ipu_idmac_get(ipu_plane->ipu, alpha_ch);
180 if (IS_ERR(ipu_plane->alpha_ch)) {
181 ret = PTR_ERR(ipu_plane->alpha_ch);
182 DRM_ERROR("failed to get alpha idmac channel %d: %d\n",
188 ipu_plane->dmfc = ipu_dmfc_get(ipu_plane->ipu, ipu_plane->dma);
189 if (IS_ERR(ipu_plane->dmfc)) {
190 ret = PTR_ERR(ipu_plane->dmfc);
191 DRM_ERROR("failed to get dmfc: ret %d\n", ret);
195 if (ipu_plane->dp_flow >= 0) {
196 ipu_plane->dp = ipu_dp_get(ipu_plane->ipu, ipu_plane->dp_flow);
197 if (IS_ERR(ipu_plane->dp)) {
198 ret = PTR_ERR(ipu_plane->dp);
199 DRM_ERROR("failed to get dp flow: %d\n", ret);
207 static bool ipu_plane_separate_alpha(struct ipu_plane *ipu_plane)
209 switch (ipu_plane->base.state->fb->format->format) {
210 case DRM_FORMAT_RGB565_A8:
211 case DRM_FORMAT_BGR565_A8:
212 case DRM_FORMAT_RGB888_A8:
213 case DRM_FORMAT_BGR888_A8:
214 case DRM_FORMAT_RGBX8888_A8:
215 case DRM_FORMAT_BGRX8888_A8:
222 static void ipu_plane_enable(struct ipu_plane *ipu_plane)
225 ipu_dp_enable(ipu_plane->ipu);
226 ipu_dmfc_enable_channel(ipu_plane->dmfc);
227 ipu_idmac_enable_channel(ipu_plane->ipu_ch);
228 if (ipu_plane_separate_alpha(ipu_plane))
229 ipu_idmac_enable_channel(ipu_plane->alpha_ch);
231 ipu_dp_enable_channel(ipu_plane->dp);
234 void ipu_plane_disable(struct ipu_plane *ipu_plane, bool disable_dp_channel)
238 DRM_DEBUG_KMS("[%d] %s\n", __LINE__, __func__);
240 ret = ipu_idmac_wait_busy(ipu_plane->ipu_ch, 50);
241 if (ret == -ETIMEDOUT) {
242 DRM_ERROR("[PLANE:%d] IDMAC timeout\n",
243 ipu_plane->base.base.id);
246 if (ipu_plane->dp && disable_dp_channel)
247 ipu_dp_disable_channel(ipu_plane->dp, false);
248 ipu_idmac_disable_channel(ipu_plane->ipu_ch);
249 if (ipu_plane->alpha_ch)
250 ipu_idmac_disable_channel(ipu_plane->alpha_ch);
251 ipu_dmfc_disable_channel(ipu_plane->dmfc);
253 ipu_dp_disable(ipu_plane->ipu);
254 if (ipu_prg_present(ipu_plane->ipu))
255 ipu_prg_channel_disable(ipu_plane->ipu_ch);
258 void ipu_plane_disable_deferred(struct drm_plane *plane)
260 struct ipu_plane *ipu_plane = to_ipu_plane(plane);
262 if (ipu_plane->disabling) {
263 ipu_plane->disabling = false;
264 ipu_plane_disable(ipu_plane, false);
267 EXPORT_SYMBOL_GPL(ipu_plane_disable_deferred);
269 static void ipu_plane_state_reset(struct drm_plane *plane)
271 unsigned int zpos = (plane->type == DRM_PLANE_TYPE_PRIMARY) ? 0 : 1;
272 struct ipu_plane_state *ipu_state;
275 ipu_state = to_ipu_plane_state(plane->state);
276 __drm_atomic_helper_plane_destroy_state(plane->state);
281 ipu_state = kzalloc(sizeof(*ipu_state), GFP_KERNEL);
284 __drm_atomic_helper_plane_reset(plane, &ipu_state->base);
285 ipu_state->base.zpos = zpos;
286 ipu_state->base.normalized_zpos = zpos;
290 static struct drm_plane_state *
291 ipu_plane_duplicate_state(struct drm_plane *plane)
293 struct ipu_plane_state *state;
295 if (WARN_ON(!plane->state))
298 state = kmalloc(sizeof(*state), GFP_KERNEL);
300 __drm_atomic_helper_plane_duplicate_state(plane, &state->base);
305 static void ipu_plane_destroy_state(struct drm_plane *plane,
306 struct drm_plane_state *state)
308 struct ipu_plane_state *ipu_state = to_ipu_plane_state(state);
310 __drm_atomic_helper_plane_destroy_state(state);
314 static bool ipu_plane_format_mod_supported(struct drm_plane *plane,
315 uint32_t format, uint64_t modifier)
317 struct ipu_soc *ipu = to_ipu_plane(plane)->ipu;
319 /* linear is supported for all planes and formats */
320 if (modifier == DRM_FORMAT_MOD_LINEAR)
323 /* without a PRG there are no supported modifiers */
324 if (!ipu_prg_present(ipu))
327 return ipu_prg_format_supported(ipu, format, modifier);
330 static const struct drm_plane_funcs ipu_plane_funcs = {
331 .update_plane = drm_atomic_helper_update_plane,
332 .disable_plane = drm_atomic_helper_disable_plane,
333 .reset = ipu_plane_state_reset,
334 .atomic_duplicate_state = ipu_plane_duplicate_state,
335 .atomic_destroy_state = ipu_plane_destroy_state,
336 .format_mod_supported = ipu_plane_format_mod_supported,
339 static int ipu_plane_atomic_check(struct drm_plane *plane,
340 struct drm_plane_state *state)
342 struct drm_plane_state *old_state = plane->state;
343 struct drm_crtc_state *crtc_state;
344 struct device *dev = plane->dev->dev;
345 struct drm_framebuffer *fb = state->fb;
346 struct drm_framebuffer *old_fb = old_state->fb;
347 unsigned long eba, ubo, vbo, old_ubo, old_vbo, alpha_eba;
348 bool can_position = (plane->type == DRM_PLANE_TYPE_OVERLAY);
355 if (WARN_ON(!state->crtc))
359 drm_atomic_get_existing_crtc_state(state->state, state->crtc);
360 if (WARN_ON(!crtc_state))
363 ret = drm_atomic_helper_check_plane_state(state, crtc_state,
364 DRM_PLANE_HELPER_NO_SCALING,
365 DRM_PLANE_HELPER_NO_SCALING,
370 /* nothing to check when disabling or disabled */
371 if (!crtc_state->enable)
374 switch (plane->type) {
375 case DRM_PLANE_TYPE_PRIMARY:
376 /* full plane minimum width is 13 pixels */
377 if (drm_rect_width(&state->dst) < 13)
380 case DRM_PLANE_TYPE_OVERLAY:
383 dev_warn(dev, "Unsupported plane type %d\n", plane->type);
387 if (drm_rect_height(&state->dst) < 2)
391 * We support resizing active plane or changing its format by
392 * forcing CRTC mode change in plane's ->atomic_check callback
393 * and disabling all affected active planes in CRTC's ->atomic_disable
394 * callback. The planes will be reenabled in plane's ->atomic_update
398 (drm_rect_width(&state->dst) != drm_rect_width(&old_state->dst) ||
399 drm_rect_height(&state->dst) != drm_rect_height(&old_state->dst) ||
400 fb->format != old_fb->format))
401 crtc_state->mode_changed = true;
403 eba = drm_plane_state_to_eba(state, 0);
408 if (fb->pitches[0] < 1 || fb->pitches[0] > 16384)
411 if (old_fb && fb->pitches[0] != old_fb->pitches[0])
412 crtc_state->mode_changed = true;
414 switch (fb->format->format) {
415 case DRM_FORMAT_YUV420:
416 case DRM_FORMAT_YVU420:
417 case DRM_FORMAT_YUV422:
418 case DRM_FORMAT_YVU422:
419 case DRM_FORMAT_YUV444:
420 case DRM_FORMAT_YVU444:
422 * Multiplanar formats have to meet the following restrictions:
423 * - The (up to) three plane addresses are EBA, EBA+UBO, EBA+VBO
424 * - EBA, UBO and VBO are a multiple of 8
425 * - UBO and VBO are unsigned and not larger than 0xfffff8
426 * - Only EBA may be changed while scanout is active
427 * - The strides of U and V planes must be identical.
429 vbo = drm_plane_state_to_vbo(state);
431 if (vbo & 0x7 || vbo > 0xfffff8)
434 if (old_fb && (fb->format == old_fb->format)) {
435 old_vbo = drm_plane_state_to_vbo(old_state);
437 crtc_state->mode_changed = true;
440 if (fb->pitches[1] != fb->pitches[2])
444 case DRM_FORMAT_NV12:
445 case DRM_FORMAT_NV16:
446 ubo = drm_plane_state_to_ubo(state);
448 if (ubo & 0x7 || ubo > 0xfffff8)
451 if (old_fb && (fb->format == old_fb->format)) {
452 old_ubo = drm_plane_state_to_ubo(old_state);
454 crtc_state->mode_changed = true;
457 if (fb->pitches[1] < 1 || fb->pitches[1] > 16384)
460 if (old_fb && old_fb->pitches[1] != fb->pitches[1])
461 crtc_state->mode_changed = true;
464 * The x/y offsets must be even in case of horizontal/vertical
465 * chroma subsampling.
467 if (((state->src.x1 >> 16) & (fb->format->hsub - 1)) ||
468 ((state->src.y1 >> 16) & (fb->format->vsub - 1)))
471 case DRM_FORMAT_RGB565_A8:
472 case DRM_FORMAT_BGR565_A8:
473 case DRM_FORMAT_RGB888_A8:
474 case DRM_FORMAT_BGR888_A8:
475 case DRM_FORMAT_RGBX8888_A8:
476 case DRM_FORMAT_BGRX8888_A8:
477 alpha_eba = drm_plane_state_to_eba(state, 1);
481 if (fb->pitches[1] < 1 || fb->pitches[1] > 16384)
484 if (old_fb && old_fb->pitches[1] != fb->pitches[1])
485 crtc_state->mode_changed = true;
492 static void ipu_plane_atomic_disable(struct drm_plane *plane,
493 struct drm_plane_state *old_state)
495 struct ipu_plane *ipu_plane = to_ipu_plane(plane);
498 ipu_dp_disable_channel(ipu_plane->dp, true);
499 ipu_plane->disabling = true;
502 static int ipu_chan_assign_axi_id(int ipu_chan)
505 case IPUV3_CHANNEL_MEM_BG_SYNC:
507 case IPUV3_CHANNEL_MEM_FG_SYNC:
509 case IPUV3_CHANNEL_MEM_DC_SYNC:
516 static void ipu_calculate_bursts(u32 width, u32 cpp, u32 stride,
517 u8 *burstsize, u8 *num_bursts)
519 const unsigned int width_bytes = width * cpp;
520 unsigned int npb, bursts;
522 /* Maximum number of pixels per burst without overshooting stride */
523 for (npb = 64 / cpp; npb > 0; --npb) {
524 if (round_up(width_bytes, npb * cpp) <= stride)
529 /* Maximum number of consecutive bursts without overshooting stride */
530 for (bursts = 8; bursts > 1; bursts /= 2) {
531 if (round_up(width_bytes, npb * cpp * bursts) <= stride)
534 *num_bursts = bursts;
537 static void ipu_plane_atomic_update(struct drm_plane *plane,
538 struct drm_plane_state *old_state)
540 struct ipu_plane *ipu_plane = to_ipu_plane(plane);
541 struct drm_plane_state *state = plane->state;
542 struct ipu_plane_state *ipu_state = to_ipu_plane_state(state);
543 struct drm_crtc_state *crtc_state = state->crtc->state;
544 struct drm_framebuffer *fb = state->fb;
545 struct drm_rect *dst = &state->dst;
546 unsigned long eba, ubo, vbo;
547 unsigned long alpha_eba = 0;
548 enum ipu_color_space ics;
549 unsigned int axi_id = 0;
550 const struct drm_format_info *info;
551 u8 burstsize, num_bursts;
555 if (ipu_plane->dp_flow == IPU_DP_FLOW_SYNC_FG)
556 ipu_dp_set_window_pos(ipu_plane->dp, dst->x1, dst->y1);
558 switch (ipu_plane->dp_flow) {
559 case IPU_DP_FLOW_SYNC_BG:
560 if (state->normalized_zpos == 1) {
561 ipu_dp_set_global_alpha(ipu_plane->dp,
562 !fb->format->has_alpha, 0xff,
565 ipu_dp_set_global_alpha(ipu_plane->dp, true, 0, true);
568 case IPU_DP_FLOW_SYNC_FG:
569 if (state->normalized_zpos == 1) {
570 ipu_dp_set_global_alpha(ipu_plane->dp,
571 !fb->format->has_alpha, 0xff,
577 eba = drm_plane_state_to_eba(state, 0);
580 * Configure PRG channel and attached PRE, this changes the EBA to an
581 * internal SRAM location.
583 if (ipu_state->use_pre) {
584 axi_id = ipu_chan_assign_axi_id(ipu_plane->dma);
585 ipu_prg_channel_configure(ipu_plane->ipu_ch, axi_id,
586 drm_rect_width(&state->src) >> 16,
587 drm_rect_height(&state->src) >> 16,
588 fb->pitches[0], fb->format->format,
592 if (old_state->fb && !drm_atomic_crtc_needs_modeset(crtc_state)) {
593 /* nothing to do if PRE is used */
594 if (ipu_state->use_pre)
596 active = ipu_idmac_get_current_buffer(ipu_plane->ipu_ch);
597 ipu_cpmem_set_buffer(ipu_plane->ipu_ch, !active, eba);
598 ipu_idmac_select_buffer(ipu_plane->ipu_ch, !active);
599 if (ipu_plane_separate_alpha(ipu_plane)) {
600 active = ipu_idmac_get_current_buffer(ipu_plane->alpha_ch);
601 ipu_cpmem_set_buffer(ipu_plane->alpha_ch, !active,
603 ipu_idmac_select_buffer(ipu_plane->alpha_ch, !active);
608 ics = ipu_drm_fourcc_to_colorspace(fb->format->format);
609 switch (ipu_plane->dp_flow) {
610 case IPU_DP_FLOW_SYNC_BG:
611 ipu_dp_setup_channel(ipu_plane->dp, ics, IPUV3_COLORSPACE_RGB);
613 case IPU_DP_FLOW_SYNC_FG:
614 ipu_dp_setup_channel(ipu_plane->dp, ics,
615 IPUV3_COLORSPACE_UNKNOWN);
619 ipu_dmfc_config_wait4eot(ipu_plane->dmfc, drm_rect_width(dst));
621 width = drm_rect_width(&state->src) >> 16;
622 height = drm_rect_height(&state->src) >> 16;
623 info = drm_format_info(fb->format->format);
624 ipu_calculate_bursts(width, info->cpp[0], fb->pitches[0],
625 &burstsize, &num_bursts);
627 ipu_cpmem_zero(ipu_plane->ipu_ch);
628 ipu_cpmem_set_resolution(ipu_plane->ipu_ch, width, height);
629 ipu_cpmem_set_fmt(ipu_plane->ipu_ch, fb->format->format);
630 ipu_cpmem_set_burstsize(ipu_plane->ipu_ch, burstsize);
631 ipu_cpmem_set_high_priority(ipu_plane->ipu_ch);
632 ipu_idmac_enable_watermark(ipu_plane->ipu_ch, true);
633 ipu_idmac_set_double_buffer(ipu_plane->ipu_ch, 1);
634 ipu_cpmem_set_stride(ipu_plane->ipu_ch, fb->pitches[0]);
635 ipu_cpmem_set_axi_id(ipu_plane->ipu_ch, axi_id);
637 switch (fb->format->format) {
638 case DRM_FORMAT_YUV420:
639 case DRM_FORMAT_YVU420:
640 case DRM_FORMAT_YUV422:
641 case DRM_FORMAT_YVU422:
642 case DRM_FORMAT_YUV444:
643 case DRM_FORMAT_YVU444:
644 ubo = drm_plane_state_to_ubo(state);
645 vbo = drm_plane_state_to_vbo(state);
646 if (fb->format->format == DRM_FORMAT_YVU420 ||
647 fb->format->format == DRM_FORMAT_YVU422 ||
648 fb->format->format == DRM_FORMAT_YVU444)
651 ipu_cpmem_set_yuv_planar_full(ipu_plane->ipu_ch,
652 fb->pitches[1], ubo, vbo);
654 dev_dbg(ipu_plane->base.dev->dev,
655 "phy = %lu %lu %lu, x = %d, y = %d", eba, ubo, vbo,
656 state->src.x1 >> 16, state->src.y1 >> 16);
658 case DRM_FORMAT_NV12:
659 case DRM_FORMAT_NV16:
660 ubo = drm_plane_state_to_ubo(state);
662 ipu_cpmem_set_yuv_planar_full(ipu_plane->ipu_ch,
663 fb->pitches[1], ubo, ubo);
665 dev_dbg(ipu_plane->base.dev->dev,
666 "phy = %lu %lu, x = %d, y = %d", eba, ubo,
667 state->src.x1 >> 16, state->src.y1 >> 16);
669 case DRM_FORMAT_RGB565_A8:
670 case DRM_FORMAT_BGR565_A8:
671 case DRM_FORMAT_RGB888_A8:
672 case DRM_FORMAT_BGR888_A8:
673 case DRM_FORMAT_RGBX8888_A8:
674 case DRM_FORMAT_BGRX8888_A8:
675 alpha_eba = drm_plane_state_to_eba(state, 1);
678 dev_dbg(ipu_plane->base.dev->dev, "phys = %lu %lu, x = %d, y = %d",
679 eba, alpha_eba, state->src.x1 >> 16, state->src.y1 >> 16);
681 ipu_cpmem_set_burstsize(ipu_plane->ipu_ch, 16);
683 ipu_cpmem_zero(ipu_plane->alpha_ch);
684 ipu_cpmem_set_resolution(ipu_plane->alpha_ch,
685 drm_rect_width(&state->src) >> 16,
686 drm_rect_height(&state->src) >> 16);
687 ipu_cpmem_set_format_passthrough(ipu_plane->alpha_ch, 8);
688 ipu_cpmem_set_high_priority(ipu_plane->alpha_ch);
689 ipu_idmac_set_double_buffer(ipu_plane->alpha_ch, 1);
690 ipu_cpmem_set_stride(ipu_plane->alpha_ch, fb->pitches[1]);
691 ipu_cpmem_set_burstsize(ipu_plane->alpha_ch, 16);
692 ipu_cpmem_set_buffer(ipu_plane->alpha_ch, 0, alpha_eba);
693 ipu_cpmem_set_buffer(ipu_plane->alpha_ch, 1, alpha_eba);
696 dev_dbg(ipu_plane->base.dev->dev, "phys = %lu, x = %d, y = %d",
697 eba, state->src.x1 >> 16, state->src.y1 >> 16);
700 ipu_cpmem_set_buffer(ipu_plane->ipu_ch, 0, eba);
701 ipu_cpmem_set_buffer(ipu_plane->ipu_ch, 1, eba);
702 ipu_idmac_lock_enable(ipu_plane->ipu_ch, num_bursts);
703 ipu_plane_enable(ipu_plane);
706 static const struct drm_plane_helper_funcs ipu_plane_helper_funcs = {
707 .prepare_fb = drm_gem_fb_prepare_fb,
708 .atomic_check = ipu_plane_atomic_check,
709 .atomic_disable = ipu_plane_atomic_disable,
710 .atomic_update = ipu_plane_atomic_update,
713 bool ipu_plane_atomic_update_pending(struct drm_plane *plane)
715 struct ipu_plane *ipu_plane = to_ipu_plane(plane);
716 struct drm_plane_state *state = plane->state;
717 struct ipu_plane_state *ipu_state = to_ipu_plane_state(state);
719 /* disabled crtcs must not block the update */
723 if (ipu_state->use_pre)
724 return ipu_prg_channel_configure_pending(ipu_plane->ipu_ch);
727 * Pretend no update is pending in the non-PRE/PRG case. For this to
728 * happen, an atomic update would have to be deferred until after the
729 * start of the next frame and simultaneously interrupt latency would
730 * have to be high enough to let the atomic update finish and issue an
731 * event before the previous end of frame interrupt handler can be
736 int ipu_planes_assign_pre(struct drm_device *dev,
737 struct drm_atomic_state *state)
739 struct drm_crtc_state *old_crtc_state, *crtc_state;
740 struct drm_plane_state *plane_state;
741 struct ipu_plane_state *ipu_state;
742 struct ipu_plane *ipu_plane;
743 struct drm_plane *plane;
744 struct drm_crtc *crtc;
745 int available_pres = ipu_prg_max_active_channels();
748 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, crtc_state, i) {
749 ret = drm_atomic_add_affected_planes(state, crtc);
755 * We are going over the planes in 2 passes: first we assign PREs to
756 * planes with a tiling modifier, which need the PREs to resolve into
757 * linear. Any failure to assign a PRE there is fatal. In the second
758 * pass we try to assign PREs to linear FBs, to improve memory access
759 * patterns for them. Failure at this point is non-fatal, as we can
760 * scan out linear FBs without a PRE.
762 for_each_new_plane_in_state(state, plane, plane_state, i) {
763 ipu_state = to_ipu_plane_state(plane_state);
764 ipu_plane = to_ipu_plane(plane);
766 if (!plane_state->fb) {
767 ipu_state->use_pre = false;
771 if (!(plane_state->fb->flags & DRM_MODE_FB_MODIFIERS) ||
772 plane_state->fb->modifier == DRM_FORMAT_MOD_LINEAR)
775 if (!ipu_prg_present(ipu_plane->ipu) || !available_pres)
778 if (!ipu_prg_format_supported(ipu_plane->ipu,
779 plane_state->fb->format->format,
780 plane_state->fb->modifier))
783 ipu_state->use_pre = true;
787 for_each_new_plane_in_state(state, plane, plane_state, i) {
788 ipu_state = to_ipu_plane_state(plane_state);
789 ipu_plane = to_ipu_plane(plane);
791 if (!plane_state->fb) {
792 ipu_state->use_pre = false;
796 if ((plane_state->fb->flags & DRM_MODE_FB_MODIFIERS) &&
797 plane_state->fb->modifier != DRM_FORMAT_MOD_LINEAR)
800 /* make sure that modifier is initialized */
801 plane_state->fb->modifier = DRM_FORMAT_MOD_LINEAR;
803 if (ipu_prg_present(ipu_plane->ipu) && available_pres &&
804 ipu_prg_format_supported(ipu_plane->ipu,
805 plane_state->fb->format->format,
806 plane_state->fb->modifier)) {
807 ipu_state->use_pre = true;
810 ipu_state->use_pre = false;
816 EXPORT_SYMBOL_GPL(ipu_planes_assign_pre);
818 struct ipu_plane *ipu_plane_init(struct drm_device *dev, struct ipu_soc *ipu,
819 int dma, int dp, unsigned int possible_crtcs,
820 enum drm_plane_type type)
822 struct ipu_plane *ipu_plane;
823 const uint64_t *modifiers = ipu_format_modifiers;
824 unsigned int zpos = (type == DRM_PLANE_TYPE_PRIMARY) ? 0 : 1;
827 DRM_DEBUG_KMS("channel %d, dp flow %d, possible_crtcs=0x%x\n",
828 dma, dp, possible_crtcs);
830 ipu_plane = drmm_universal_plane_alloc(dev, struct ipu_plane, base,
831 possible_crtcs, &ipu_plane_funcs,
833 ARRAY_SIZE(ipu_plane_formats),
834 modifiers, type, NULL);
835 if (IS_ERR(ipu_plane)) {
836 DRM_ERROR("failed to allocate and initialize %s plane\n",
837 zpos ? "overlay" : "primary");
841 ipu_plane->ipu = ipu;
842 ipu_plane->dma = dma;
843 ipu_plane->dp_flow = dp;
845 if (ipu_prg_present(ipu))
846 modifiers = pre_format_modifiers;
848 drm_plane_helper_add(&ipu_plane->base, &ipu_plane_helper_funcs);
850 if (dp == IPU_DP_FLOW_SYNC_BG || dp == IPU_DP_FLOW_SYNC_FG)
851 ret = drm_plane_create_zpos_property(&ipu_plane->base, zpos, 0,
854 ret = drm_plane_create_zpos_immutable_property(&ipu_plane->base,
859 ret = ipu_plane_get_resources(dev, ipu_plane);
861 DRM_ERROR("failed to get %s plane resources: %pe\n",
862 zpos ? "overlay" : "primary", &ret);