From patchwork Fri Feb 3 09:31:39 2017
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-Patchwork-Submitter: Philipp Zabel
X-Patchwork-Id: 9553661
Return-Path:
Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org
[172.30.200.125])
by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id
EACCC60405 for ;
Fri, 3 Feb 2017 09:31:49 +0000 (UTC)
Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1])
by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DD3C928499
for ;
Fri, 3 Feb 2017 09:31:49 +0000 (UTC)
Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486)
id D16322850E; Fri, 3 Feb 2017 09:31:49 +0000 (UTC)
X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on
pdx-wl-mail.web.codeaurora.org
X-Spam-Level:
X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED
autolearn=ham version=3.3.1
Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177])
(using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256
bits)) (No client certificate requested)
by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 1AC6B28499
for ;
Fri, 3 Feb 2017 09:31:48 +0000 (UTC)
Received: from gabe.freedesktop.org (localhost [127.0.0.1])
by gabe.freedesktop.org (Postfix) with ESMTP id CF8D16E001;
Fri, 3 Feb 2017 09:31:47 +0000 (UTC)
X-Original-To: dri-devel@lists.freedesktop.org
Delivered-To: dri-devel@lists.freedesktop.org
Received: from metis.ext.pengutronix.de (metis.ext.pengutronix.de
[IPv6:2001:67c:670:201:290:27ff:fe1d:cc33])
by gabe.freedesktop.org (Postfix) with ESMTPS id 80D196E001
for ;
Fri, 3 Feb 2017 09:31:46 +0000 (UTC)
Received: from lupine.hi.4.pengutronix.de ([10.1.0.115]
helo=lupine.pengutronix.de.)
by metis.ext.pengutronix.de with esmtp (Exim 4.84_2)
(envelope-from )
id 1cZaDY-0005Lt-Nn; Fri, 03 Feb 2017 10:31:44 +0100
From: Philipp Zabel
To: dri-devel@lists.freedesktop.org
Subject: [PATCH v4] drm/imx: ipuv3-plane: use drm_plane_helper_check_state,
clipped coordinates
Date: Fri, 3 Feb 2017 10:31:39 +0100
Message-Id: <1486114299-9990-1-git-send-email-p.zabel@pengutronix.de>
X-Mailer: git-send-email 2.1.4
MIME-Version: 1.0
X-SA-Exim-Connect-IP: 10.1.0.115
X-SA-Exim-Mail-From: p.zabel@pengutronix.de
X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de);
SAEximRunCond expanded to false
X-PTX-Original-Recipient: dri-devel@lists.freedesktop.org
Cc: kernel@pengutronix.de
X-BeenThere: dri-devel@lists.freedesktop.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: Direct Rendering Infrastructure - Development
List-Unsubscribe: ,
List-Archive:
List-Post:
List-Help:
List-Subscribe: ,
Errors-To: dri-devel-bounces@lists.freedesktop.org
Sender: "dri-devel"
X-Virus-Scanned: ClamAV using ClamSMTP
Use drm_plane_helper_check_state to clip raw user coordinates to crtc
bounds. This checks for full plane coverage and scaling already, so
we can drop some custom checks. Use the clipped coordinates everywhere.
Suggested-by: Ville Syrjälä
Signed-off-by: Philipp Zabel
---
Changes since v3:
- Disallow target frames that start offscreen (state->crtc_x/y < 0), to avoid
confusing userspace: due to the necessary line start address alignment, we
could only support very specific negative values for crtc_x/y, depending on
the pixel format.
---
drivers/gpu/drm/imx/ipuv3-plane.c | 80 +++++++++++++++++++--------------------
1 file changed, 40 insertions(+), 40 deletions(-)
diff --git a/drivers/gpu/drm/imx/ipuv3-plane.c b/drivers/gpu/drm/imx/ipuv3-plane.c
index e74a0ad52950c..5cefa70bd8d17 100644
--- a/drivers/gpu/drm/imx/ipuv3-plane.c
+++ b/drivers/gpu/drm/imx/ipuv3-plane.c
@@ -70,8 +70,8 @@ drm_plane_state_to_eba(struct drm_plane_state *state)
{
struct drm_framebuffer *fb = state->fb;
struct drm_gem_cma_object *cma_obj;
- int x = state->src_x >> 16;
- int y = state->src_y >> 16;
+ int x = state->src.x1 >> 16;
+ int y = state->src.y1 >> 16;
cma_obj = drm_fb_cma_get_gem_obj(fb, 0);
BUG_ON(!cma_obj);
@@ -86,8 +86,8 @@ drm_plane_state_to_ubo(struct drm_plane_state *state)
struct drm_framebuffer *fb = state->fb;
struct drm_gem_cma_object *cma_obj;
unsigned long eba = drm_plane_state_to_eba(state);
- int x = state->src_x >> 16;
- int y = state->src_y >> 16;
+ int x = state->src.x1 >> 16;
+ int y = state->src.y1 >> 16;
cma_obj = drm_fb_cma_get_gem_obj(fb, 1);
BUG_ON(!cma_obj);
@@ -105,8 +105,8 @@ drm_plane_state_to_vbo(struct drm_plane_state *state)
struct drm_framebuffer *fb = state->fb;
struct drm_gem_cma_object *cma_obj;
unsigned long eba = drm_plane_state_to_eba(state);
- int x = state->src_x >> 16;
- int y = state->src_y >> 16;
+ int x = state->src.x1 >> 16;
+ int y = state->src.y1 >> 16;
cma_obj = drm_fb_cma_get_gem_obj(fb, 2);
BUG_ON(!cma_obj);
@@ -218,7 +218,10 @@ static int ipu_plane_atomic_check(struct drm_plane *plane,
struct drm_framebuffer *fb = state->fb;
struct drm_framebuffer *old_fb = old_state->fb;
unsigned long eba, ubo, vbo, old_ubo, old_vbo;
+ bool can_position = (plane->type == DRM_PLANE_TYPE_OVERLAY);
+ struct drm_rect clip;
int hsub, vsub;
+ int ret;
/* Ok to disable */
if (!fb)
@@ -232,44 +235,39 @@ static int ipu_plane_atomic_check(struct drm_plane *plane,
if (WARN_ON(!crtc_state))
return -EINVAL;
+ clip.x1 = 0;
+ clip.y1 = 0;
+ clip.x2 = crtc_state->adjusted_mode.hdisplay;
+ clip.y2 = crtc_state->adjusted_mode.vdisplay;
+ ret = drm_plane_helper_check_state(state, &clip,
+ DRM_PLANE_HELPER_NO_SCALING,
+ DRM_PLANE_HELPER_NO_SCALING,
+ can_position, true);
+ if (ret)
+ return ret;
+
/* CRTC should be enabled */
if (!crtc_state->enable)
return -EINVAL;
- /* no scaling */
- if (state->src_w >> 16 != state->crtc_w ||
- state->src_h >> 16 != state->crtc_h)
+ /* Target frame must not start off-screen */
+ if (state->crtc_x < 0 || state->crtc_y < 0)
return -EINVAL;
switch (plane->type) {
case DRM_PLANE_TYPE_PRIMARY:
- /* full plane doesn't support partial off screen */
- if (state->crtc_x || state->crtc_y ||
- state->crtc_w != crtc_state->adjusted_mode.hdisplay ||
- state->crtc_h != crtc_state->adjusted_mode.vdisplay)
- return -EINVAL;
-
/* full plane minimum width is 13 pixels */
- if (state->crtc_w < 13)
+ if (drm_rect_width(&state->dst) < 13)
return -EINVAL;
break;
case DRM_PLANE_TYPE_OVERLAY:
- if (state->crtc_x < 0 || state->crtc_y < 0)
- return -EINVAL;
-
- if (state->crtc_x + state->crtc_w >
- crtc_state->adjusted_mode.hdisplay)
- return -EINVAL;
- if (state->crtc_y + state->crtc_h >
- crtc_state->adjusted_mode.vdisplay)
- return -EINVAL;
break;
default:
- dev_warn(dev, "Unsupported plane type\n");
+ dev_warn(dev, "Unsupported plane type %d\n", plane->type);
return -EINVAL;
}
- if (state->crtc_h < 2)
+ if (drm_rect_height(&state->dst) < 2)
return -EINVAL;
/*
@@ -279,9 +277,10 @@ static int ipu_plane_atomic_check(struct drm_plane *plane,
* callback. The planes will be reenabled in plane's ->atomic_update
* callback.
*/
- if (old_fb && (state->src_w != old_state->src_w ||
- state->src_h != old_state->src_h ||
- fb->pixel_format != old_fb->pixel_format))
+ if (old_fb &&
+ (drm_rect_width(&state->dst) != drm_rect_width(&old_state->dst) ||
+ drm_rect_height(&state->dst) != drm_rect_height(&old_state->dst) ||
+ fb->pixel_format != old_fb->pixel_format))
crtc_state->mode_changed = true;
eba = drm_plane_state_to_eba(state);
@@ -350,8 +349,8 @@ static int ipu_plane_atomic_check(struct drm_plane *plane,
*/
hsub = drm_format_horz_chroma_subsampling(fb->pixel_format);
vsub = drm_format_vert_chroma_subsampling(fb->pixel_format);
- if (((state->src_x >> 16) & (hsub - 1)) ||
- ((state->src_y >> 16) & (vsub - 1)))
+ if (((state->src.x1 >> 16) & (hsub - 1)) ||
+ ((state->src.y1 >> 16) & (vsub - 1)))
return -EINVAL;
}
@@ -395,8 +394,8 @@ static void ipu_plane_atomic_update(struct drm_plane *plane,
ics = ipu_drm_fourcc_to_colorspace(state->fb->pixel_format);
ipu_dp_setup_channel(ipu_plane->dp, ics,
IPUV3_COLORSPACE_UNKNOWN);
- ipu_dp_set_window_pos(ipu_plane->dp, state->crtc_x,
- state->crtc_y);
+ ipu_dp_set_window_pos(ipu_plane->dp,
+ state->dst.x1, state->dst.y1);
/* Enable local alpha on partial plane */
switch (state->fb->pixel_format) {
case DRM_FORMAT_ARGB1555:
@@ -416,11 +415,12 @@ static void ipu_plane_atomic_update(struct drm_plane *plane,
}
}
- ipu_dmfc_config_wait4eot(ipu_plane->dmfc, state->crtc_w);
+ ipu_dmfc_config_wait4eot(ipu_plane->dmfc, drm_rect_width(&state->dst));
ipu_cpmem_zero(ipu_plane->ipu_ch);
- ipu_cpmem_set_resolution(ipu_plane->ipu_ch, state->src_w >> 16,
- state->src_h >> 16);
+ ipu_cpmem_set_resolution(ipu_plane->ipu_ch,
+ drm_rect_width(&state->src) >> 16,
+ drm_rect_height(&state->src) >> 16);
ipu_cpmem_set_fmt(ipu_plane->ipu_ch, state->fb->pixel_format);
ipu_cpmem_set_high_priority(ipu_plane->ipu_ch);
ipu_idmac_set_double_buffer(ipu_plane->ipu_ch, 1);
@@ -444,7 +444,7 @@ static void ipu_plane_atomic_update(struct drm_plane *plane,
dev_dbg(ipu_plane->base.dev->dev,
"phy = %lu %lu %lu, x = %d, y = %d", eba, ubo, vbo,
- state->src_x >> 16, state->src_y >> 16);
+ state->src.x1 >> 16, state->src.y1 >> 16);
break;
case DRM_FORMAT_NV12:
case DRM_FORMAT_NV16:
@@ -455,11 +455,11 @@ static void ipu_plane_atomic_update(struct drm_plane *plane,
dev_dbg(ipu_plane->base.dev->dev,
"phy = %lu %lu, x = %d, y = %d", eba, ubo,
- state->src_x >> 16, state->src_y >> 16);
+ state->src.x1 >> 16, state->src.y1 >> 16);
break;
default:
dev_dbg(ipu_plane->base.dev->dev, "phys = %lu, x = %d, y = %d",
- eba, state->src_x >> 16, state->src_y >> 16);
+ eba, state->src.x1 >> 16, state->src.y1 >> 16);
break;
}
ipu_cpmem_set_buffer(ipu_plane->ipu_ch, 0, eba);