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_atomic_helper.h>
13 #include <drm/drm_gem_cma_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_atomic_state *state)
342 struct drm_plane_state *new_state = drm_atomic_get_new_plane_state(state,
344 struct drm_plane_state *old_state = drm_atomic_get_old_plane_state(state,
346 struct drm_crtc_state *crtc_state;
347 struct device *dev = plane->dev->dev;
348 struct drm_framebuffer *fb = new_state->fb;
349 struct drm_framebuffer *old_fb = old_state->fb;
350 unsigned long eba, ubo, vbo, old_ubo, old_vbo, alpha_eba;
351 bool can_position = (plane->type == DRM_PLANE_TYPE_OVERLAY);
358 if (WARN_ON(!new_state->crtc))
362 drm_atomic_get_existing_crtc_state(state,
364 if (WARN_ON(!crtc_state))
367 ret = drm_atomic_helper_check_plane_state(new_state, crtc_state,
368 DRM_PLANE_HELPER_NO_SCALING,
369 DRM_PLANE_HELPER_NO_SCALING,
374 /* nothing to check when disabling or disabled */
375 if (!crtc_state->enable)
378 switch (plane->type) {
379 case DRM_PLANE_TYPE_PRIMARY:
380 /* full plane minimum width is 13 pixels */
381 if (drm_rect_width(&new_state->dst) < 13)
384 case DRM_PLANE_TYPE_OVERLAY:
387 dev_warn(dev, "Unsupported plane type %d\n", plane->type);
391 if (drm_rect_height(&new_state->dst) < 2)
395 * We support resizing active plane or changing its format by
396 * forcing CRTC mode change in plane's ->atomic_check callback
397 * and disabling all affected active planes in CRTC's ->atomic_disable
398 * callback. The planes will be reenabled in plane's ->atomic_update
402 (drm_rect_width(&new_state->dst) != drm_rect_width(&old_state->dst) ||
403 drm_rect_height(&new_state->dst) != drm_rect_height(&old_state->dst) ||
404 fb->format != old_fb->format))
405 crtc_state->mode_changed = true;
407 eba = drm_plane_state_to_eba(new_state, 0);
412 if (fb->pitches[0] < 1 || fb->pitches[0] > 16384)
415 if (old_fb && fb->pitches[0] != old_fb->pitches[0])
416 crtc_state->mode_changed = true;
418 switch (fb->format->format) {
419 case DRM_FORMAT_YUV420:
420 case DRM_FORMAT_YVU420:
421 case DRM_FORMAT_YUV422:
422 case DRM_FORMAT_YVU422:
423 case DRM_FORMAT_YUV444:
424 case DRM_FORMAT_YVU444:
426 * Multiplanar formats have to meet the following restrictions:
427 * - The (up to) three plane addresses are EBA, EBA+UBO, EBA+VBO
428 * - EBA, UBO and VBO are a multiple of 8
429 * - UBO and VBO are unsigned and not larger than 0xfffff8
430 * - Only EBA may be changed while scanout is active
431 * - The strides of U and V planes must be identical.
433 vbo = drm_plane_state_to_vbo(new_state);
435 if (vbo & 0x7 || vbo > 0xfffff8)
438 if (old_fb && (fb->format == old_fb->format)) {
439 old_vbo = drm_plane_state_to_vbo(old_state);
441 crtc_state->mode_changed = true;
444 if (fb->pitches[1] != fb->pitches[2])
448 case DRM_FORMAT_NV12:
449 case DRM_FORMAT_NV16:
450 ubo = drm_plane_state_to_ubo(new_state);
452 if (ubo & 0x7 || ubo > 0xfffff8)
455 if (old_fb && (fb->format == old_fb->format)) {
456 old_ubo = drm_plane_state_to_ubo(old_state);
458 crtc_state->mode_changed = true;
461 if (fb->pitches[1] < 1 || fb->pitches[1] > 16384)
464 if (old_fb && old_fb->pitches[1] != fb->pitches[1])
465 crtc_state->mode_changed = true;
468 * The x/y offsets must be even in case of horizontal/vertical
469 * chroma subsampling.
471 if (((new_state->src.x1 >> 16) & (fb->format->hsub - 1)) ||
472 ((new_state->src.y1 >> 16) & (fb->format->vsub - 1)))
475 case DRM_FORMAT_RGB565_A8:
476 case DRM_FORMAT_BGR565_A8:
477 case DRM_FORMAT_RGB888_A8:
478 case DRM_FORMAT_BGR888_A8:
479 case DRM_FORMAT_RGBX8888_A8:
480 case DRM_FORMAT_BGRX8888_A8:
481 alpha_eba = drm_plane_state_to_eba(new_state, 1);
485 if (fb->pitches[1] < 1 || fb->pitches[1] > 16384)
488 if (old_fb && old_fb->pitches[1] != fb->pitches[1])
489 crtc_state->mode_changed = true;
496 static void ipu_plane_atomic_disable(struct drm_plane *plane,
497 struct drm_atomic_state *state)
499 struct ipu_plane *ipu_plane = to_ipu_plane(plane);
502 ipu_dp_disable_channel(ipu_plane->dp, true);
503 ipu_plane->disabling = true;
506 static int ipu_chan_assign_axi_id(int ipu_chan)
509 case IPUV3_CHANNEL_MEM_BG_SYNC:
511 case IPUV3_CHANNEL_MEM_FG_SYNC:
513 case IPUV3_CHANNEL_MEM_DC_SYNC:
520 static void ipu_calculate_bursts(u32 width, u32 cpp, u32 stride,
521 u8 *burstsize, u8 *num_bursts)
523 const unsigned int width_bytes = width * cpp;
524 unsigned int npb, bursts;
526 /* Maximum number of pixels per burst without overshooting stride */
527 for (npb = 64 / cpp; npb > 0; --npb) {
528 if (round_up(width_bytes, npb * cpp) <= stride)
533 /* Maximum number of consecutive bursts without overshooting stride */
534 for (bursts = 8; bursts > 1; bursts /= 2) {
535 if (round_up(width_bytes, npb * cpp * bursts) <= stride)
538 *num_bursts = bursts;
541 static void ipu_plane_atomic_update(struct drm_plane *plane,
542 struct drm_atomic_state *state)
544 struct drm_plane_state *old_state = drm_atomic_get_old_plane_state(state,
546 struct ipu_plane *ipu_plane = to_ipu_plane(plane);
547 struct drm_plane_state *new_state = drm_atomic_get_new_plane_state(state,
549 struct ipu_plane_state *ipu_state = to_ipu_plane_state(new_state);
550 struct drm_crtc_state *crtc_state = new_state->crtc->state;
551 struct drm_framebuffer *fb = new_state->fb;
552 struct drm_rect *dst = &new_state->dst;
553 unsigned long eba, ubo, vbo;
554 unsigned long alpha_eba = 0;
555 enum ipu_color_space ics;
556 unsigned int axi_id = 0;
557 const struct drm_format_info *info;
558 u8 burstsize, num_bursts;
562 if (ipu_plane->dp_flow == IPU_DP_FLOW_SYNC_FG)
563 ipu_dp_set_window_pos(ipu_plane->dp, dst->x1, dst->y1);
565 switch (ipu_plane->dp_flow) {
566 case IPU_DP_FLOW_SYNC_BG:
567 if (new_state->normalized_zpos == 1) {
568 ipu_dp_set_global_alpha(ipu_plane->dp,
569 !fb->format->has_alpha, 0xff,
572 ipu_dp_set_global_alpha(ipu_plane->dp, true, 0, true);
575 case IPU_DP_FLOW_SYNC_FG:
576 if (new_state->normalized_zpos == 1) {
577 ipu_dp_set_global_alpha(ipu_plane->dp,
578 !fb->format->has_alpha, 0xff,
584 eba = drm_plane_state_to_eba(new_state, 0);
587 * Configure PRG channel and attached PRE, this changes the EBA to an
588 * internal SRAM location.
590 if (ipu_state->use_pre) {
591 axi_id = ipu_chan_assign_axi_id(ipu_plane->dma);
592 ipu_prg_channel_configure(ipu_plane->ipu_ch, axi_id,
593 drm_rect_width(&new_state->src) >> 16,
594 drm_rect_height(&new_state->src) >> 16,
595 fb->pitches[0], fb->format->format,
599 if (old_state->fb && !drm_atomic_crtc_needs_modeset(crtc_state)) {
600 /* nothing to do if PRE is used */
601 if (ipu_state->use_pre)
603 active = ipu_idmac_get_current_buffer(ipu_plane->ipu_ch);
604 ipu_cpmem_set_buffer(ipu_plane->ipu_ch, !active, eba);
605 ipu_idmac_select_buffer(ipu_plane->ipu_ch, !active);
606 if (ipu_plane_separate_alpha(ipu_plane)) {
607 active = ipu_idmac_get_current_buffer(ipu_plane->alpha_ch);
608 ipu_cpmem_set_buffer(ipu_plane->alpha_ch, !active,
610 ipu_idmac_select_buffer(ipu_plane->alpha_ch, !active);
615 ics = ipu_drm_fourcc_to_colorspace(fb->format->format);
616 switch (ipu_plane->dp_flow) {
617 case IPU_DP_FLOW_SYNC_BG:
618 ipu_dp_setup_channel(ipu_plane->dp, ics, IPUV3_COLORSPACE_RGB);
620 case IPU_DP_FLOW_SYNC_FG:
621 ipu_dp_setup_channel(ipu_plane->dp, ics,
622 IPUV3_COLORSPACE_UNKNOWN);
626 ipu_dmfc_config_wait4eot(ipu_plane->dmfc, drm_rect_width(dst));
628 width = drm_rect_width(&new_state->src) >> 16;
629 height = drm_rect_height(&new_state->src) >> 16;
630 info = drm_format_info(fb->format->format);
631 ipu_calculate_bursts(width, info->cpp[0], fb->pitches[0],
632 &burstsize, &num_bursts);
634 ipu_cpmem_zero(ipu_plane->ipu_ch);
635 ipu_cpmem_set_resolution(ipu_plane->ipu_ch, width, height);
636 ipu_cpmem_set_fmt(ipu_plane->ipu_ch, fb->format->format);
637 ipu_cpmem_set_burstsize(ipu_plane->ipu_ch, burstsize);
638 ipu_cpmem_set_high_priority(ipu_plane->ipu_ch);
639 ipu_idmac_enable_watermark(ipu_plane->ipu_ch, true);
640 ipu_idmac_set_double_buffer(ipu_plane->ipu_ch, 1);
641 ipu_cpmem_set_stride(ipu_plane->ipu_ch, fb->pitches[0]);
642 ipu_cpmem_set_axi_id(ipu_plane->ipu_ch, axi_id);
644 switch (fb->format->format) {
645 case DRM_FORMAT_YUV420:
646 case DRM_FORMAT_YVU420:
647 case DRM_FORMAT_YUV422:
648 case DRM_FORMAT_YVU422:
649 case DRM_FORMAT_YUV444:
650 case DRM_FORMAT_YVU444:
651 ubo = drm_plane_state_to_ubo(new_state);
652 vbo = drm_plane_state_to_vbo(new_state);
653 if (fb->format->format == DRM_FORMAT_YVU420 ||
654 fb->format->format == DRM_FORMAT_YVU422 ||
655 fb->format->format == DRM_FORMAT_YVU444)
658 ipu_cpmem_set_yuv_planar_full(ipu_plane->ipu_ch,
659 fb->pitches[1], ubo, vbo);
661 dev_dbg(ipu_plane->base.dev->dev,
662 "phy = %lu %lu %lu, x = %d, y = %d", eba, ubo, vbo,
663 new_state->src.x1 >> 16, new_state->src.y1 >> 16);
665 case DRM_FORMAT_NV12:
666 case DRM_FORMAT_NV16:
667 ubo = drm_plane_state_to_ubo(new_state);
669 ipu_cpmem_set_yuv_planar_full(ipu_plane->ipu_ch,
670 fb->pitches[1], ubo, ubo);
672 dev_dbg(ipu_plane->base.dev->dev,
673 "phy = %lu %lu, x = %d, y = %d", eba, ubo,
674 new_state->src.x1 >> 16, new_state->src.y1 >> 16);
676 case DRM_FORMAT_RGB565_A8:
677 case DRM_FORMAT_BGR565_A8:
678 case DRM_FORMAT_RGB888_A8:
679 case DRM_FORMAT_BGR888_A8:
680 case DRM_FORMAT_RGBX8888_A8:
681 case DRM_FORMAT_BGRX8888_A8:
682 alpha_eba = drm_plane_state_to_eba(new_state, 1);
685 dev_dbg(ipu_plane->base.dev->dev, "phys = %lu %lu, x = %d, y = %d",
686 eba, alpha_eba, new_state->src.x1 >> 16,
687 new_state->src.y1 >> 16);
689 ipu_cpmem_set_burstsize(ipu_plane->ipu_ch, 16);
691 ipu_cpmem_zero(ipu_plane->alpha_ch);
692 ipu_cpmem_set_resolution(ipu_plane->alpha_ch,
693 drm_rect_width(&new_state->src) >> 16,
694 drm_rect_height(&new_state->src) >> 16);
695 ipu_cpmem_set_format_passthrough(ipu_plane->alpha_ch, 8);
696 ipu_cpmem_set_high_priority(ipu_plane->alpha_ch);
697 ipu_idmac_set_double_buffer(ipu_plane->alpha_ch, 1);
698 ipu_cpmem_set_stride(ipu_plane->alpha_ch, fb->pitches[1]);
699 ipu_cpmem_set_burstsize(ipu_plane->alpha_ch, 16);
700 ipu_cpmem_set_buffer(ipu_plane->alpha_ch, 0, alpha_eba);
701 ipu_cpmem_set_buffer(ipu_plane->alpha_ch, 1, alpha_eba);
704 dev_dbg(ipu_plane->base.dev->dev, "phys = %lu, x = %d, y = %d",
705 eba, new_state->src.x1 >> 16, new_state->src.y1 >> 16);
708 ipu_cpmem_set_buffer(ipu_plane->ipu_ch, 0, eba);
709 ipu_cpmem_set_buffer(ipu_plane->ipu_ch, 1, eba);
710 ipu_idmac_lock_enable(ipu_plane->ipu_ch, num_bursts);
711 ipu_plane_enable(ipu_plane);
714 static const struct drm_plane_helper_funcs ipu_plane_helper_funcs = {
715 .prepare_fb = drm_gem_plane_helper_prepare_fb,
716 .atomic_check = ipu_plane_atomic_check,
717 .atomic_disable = ipu_plane_atomic_disable,
718 .atomic_update = ipu_plane_atomic_update,
721 bool ipu_plane_atomic_update_pending(struct drm_plane *plane)
723 struct ipu_plane *ipu_plane = to_ipu_plane(plane);
724 struct drm_plane_state *state = plane->state;
725 struct ipu_plane_state *ipu_state = to_ipu_plane_state(state);
727 /* disabled crtcs must not block the update */
731 if (ipu_state->use_pre)
732 return ipu_prg_channel_configure_pending(ipu_plane->ipu_ch);
735 * Pretend no update is pending in the non-PRE/PRG case. For this to
736 * happen, an atomic update would have to be deferred until after the
737 * start of the next frame and simultaneously interrupt latency would
738 * have to be high enough to let the atomic update finish and issue an
739 * event before the previous end of frame interrupt handler can be
744 int ipu_planes_assign_pre(struct drm_device *dev,
745 struct drm_atomic_state *state)
747 struct drm_crtc_state *old_crtc_state, *crtc_state;
748 struct drm_plane_state *plane_state;
749 struct ipu_plane_state *ipu_state;
750 struct ipu_plane *ipu_plane;
751 struct drm_plane *plane;
752 struct drm_crtc *crtc;
753 int available_pres = ipu_prg_max_active_channels();
756 for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, crtc_state, i) {
757 ret = drm_atomic_add_affected_planes(state, crtc);
763 * We are going over the planes in 2 passes: first we assign PREs to
764 * planes with a tiling modifier, which need the PREs to resolve into
765 * linear. Any failure to assign a PRE there is fatal. In the second
766 * pass we try to assign PREs to linear FBs, to improve memory access
767 * patterns for them. Failure at this point is non-fatal, as we can
768 * scan out linear FBs without a PRE.
770 for_each_new_plane_in_state(state, plane, plane_state, i) {
771 ipu_state = to_ipu_plane_state(plane_state);
772 ipu_plane = to_ipu_plane(plane);
774 if (!plane_state->fb) {
775 ipu_state->use_pre = false;
779 if (!(plane_state->fb->flags & DRM_MODE_FB_MODIFIERS) ||
780 plane_state->fb->modifier == DRM_FORMAT_MOD_LINEAR)
783 if (!ipu_prg_present(ipu_plane->ipu) || !available_pres)
786 if (!ipu_prg_format_supported(ipu_plane->ipu,
787 plane_state->fb->format->format,
788 plane_state->fb->modifier))
791 ipu_state->use_pre = true;
795 for_each_new_plane_in_state(state, plane, plane_state, i) {
796 ipu_state = to_ipu_plane_state(plane_state);
797 ipu_plane = to_ipu_plane(plane);
799 if (!plane_state->fb) {
800 ipu_state->use_pre = false;
804 if ((plane_state->fb->flags & DRM_MODE_FB_MODIFIERS) &&
805 plane_state->fb->modifier != DRM_FORMAT_MOD_LINEAR)
808 /* make sure that modifier is initialized */
809 plane_state->fb->modifier = DRM_FORMAT_MOD_LINEAR;
811 if (ipu_prg_present(ipu_plane->ipu) && available_pres &&
812 ipu_prg_format_supported(ipu_plane->ipu,
813 plane_state->fb->format->format,
814 plane_state->fb->modifier)) {
815 ipu_state->use_pre = true;
818 ipu_state->use_pre = false;
824 EXPORT_SYMBOL_GPL(ipu_planes_assign_pre);
826 struct ipu_plane *ipu_plane_init(struct drm_device *dev, struct ipu_soc *ipu,
827 int dma, int dp, unsigned int possible_crtcs,
828 enum drm_plane_type type)
830 struct ipu_plane *ipu_plane;
831 const uint64_t *modifiers = ipu_format_modifiers;
832 unsigned int zpos = (type == DRM_PLANE_TYPE_PRIMARY) ? 0 : 1;
835 DRM_DEBUG_KMS("channel %d, dp flow %d, possible_crtcs=0x%x\n",
836 dma, dp, possible_crtcs);
838 ipu_plane = drmm_universal_plane_alloc(dev, struct ipu_plane, base,
839 possible_crtcs, &ipu_plane_funcs,
841 ARRAY_SIZE(ipu_plane_formats),
842 modifiers, type, NULL);
843 if (IS_ERR(ipu_plane)) {
844 DRM_ERROR("failed to allocate and initialize %s plane\n",
845 zpos ? "overlay" : "primary");
849 ipu_plane->ipu = ipu;
850 ipu_plane->dma = dma;
851 ipu_plane->dp_flow = dp;
853 if (ipu_prg_present(ipu))
854 modifiers = pre_format_modifiers;
856 drm_plane_helper_add(&ipu_plane->base, &ipu_plane_helper_funcs);
858 if (dp == IPU_DP_FLOW_SYNC_BG || dp == IPU_DP_FLOW_SYNC_FG)
859 ret = drm_plane_create_zpos_property(&ipu_plane->base, zpos, 0,
862 ret = drm_plane_create_zpos_immutable_property(&ipu_plane->base,
867 ret = ipu_plane_get_resources(dev, ipu_plane);
869 DRM_ERROR("failed to get %s plane resources: %pe\n",
870 zpos ? "overlay" : "primary", &ret);