All of lore.kernel.org
 help / color / mirror / Atom feed
From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: dri-devel@lists.freedesktop.org
Cc: Tomi Valkeinen <tomi.valkeinen@ti.com>
Subject: [PATCH v3 04/20] drm: omapdrm: fb: Simplify mode command checks when creating framebuffer
Date: Mon, 19 Sep 2016 15:27:27 +0300	[thread overview]
Message-ID: <1474288063-5315-5-git-send-email-laurent.pinchart@ideasonboard.com> (raw)
In-Reply-To: <1474288063-5315-1-git-send-email-laurent.pinchart@ideasonboard.com>

The hardware requires all planes to have an identical pitch in number of
pixels. Given that all supported formats use the same number of bytes
per pixel in all planes, framebuffer creation checks can be simplified.
The implementations assumes that no format use more than two planes
which is true with the existing hardware.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
Changes since v1:

- Clarify commit message and mention explicitly in the code that only
  one and two planes formats are supported.
- Rebase on top of the switch to drm_format_info()
---
 drivers/gpu/drm/omapdrm/omap_fb.c | 58 +++++++++++++++++++++------------------
 1 file changed, 31 insertions(+), 27 deletions(-)

diff --git a/drivers/gpu/drm/omapdrm/omap_fb.c b/drivers/gpu/drm/omapdrm/omap_fb.c
index 705901bcdfb1..903d61dd910c 100644
--- a/drivers/gpu/drm/omapdrm/omap_fb.c
+++ b/drivers/gpu/drm/omapdrm/omap_fb.c
@@ -387,6 +387,7 @@ struct drm_framebuffer *omap_framebuffer_init(struct drm_device *dev,
 	struct omap_framebuffer *omap_fb = NULL;
 	struct drm_framebuffer *fb = NULL;
 	enum omap_color_mode dss_format = 0;
+	unsigned int pitch = mode_cmd->pitches[0];
 	int ret, i;
 
 	DBG("create framebuffer: dev=%p, mode_cmd=%p (%dx%d@%4.4s)",
@@ -420,41 +421,44 @@ struct drm_framebuffer *omap_framebuffer_init(struct drm_device *dev,
 	omap_fb->dss_format = dss_format;
 	mutex_init(&omap_fb->lock);
 
+	/*
+	 * The code below assumes that no format use more than two planes, and
+	 * that the two planes of multiplane formats need the same number of
+	 * bytes per pixel.
+	 */
+	if (format->num_planes == 2 && pitch != mode_cmd->pitches[1]) {
+		dev_err(dev->dev, "pitches differ between planes 0 and 1\n");
+		ret = -EINVAL;
+		goto fail;
+	}
+
+	if (pitch < mode_cmd->width * format->cpp[0]) {
+		dev_err(dev->dev,
+			"provided buffer pitch is too small! %u < %u\n",
+			pitch, mode_cmd->width * format->cpp[0]);
+		ret = -EINVAL;
+		goto fail;
+	}
+
+	if (pitch % format->cpp[0]) {
+		dev_err(dev->dev,
+			"buffer pitch (%u bytes) is not a multiple of pixel size (%u bytes)\n",
+			pitch, format->cpp[0]);
+		ret = -EINVAL;
+		goto fail;
+	}
+
 	for (i = 0; i < format->num_planes; i++) {
 		struct plane *plane = &omap_fb->planes[i];
-		unsigned int pitch = mode_cmd->pitches[i];
-		unsigned int hsub = i == 0 ? 1 : format->hsub;
 		unsigned int vsub = i == 0 ? 1 : format->vsub;
 		unsigned int size;
 
-		if (pitch < mode_cmd->width * format->cpp[i] / hsub) {
-			dev_err(dev->dev, "provided buffer pitch is too small! %d < %d\n",
-				pitch, mode_cmd->width * format->cpp[i] / hsub);
-			ret = -EINVAL;
-			goto fail;
-		}
-
-		if (pitch % format->cpp[i] != 0) {
-			dev_err(dev->dev,
-				"buffer pitch (%d bytes) is not a multiple of pixel size (%d bytes)\n",
-				pitch, format->cpp[i]);
-			ret = -EINVAL;
-			goto fail;
-		}
-
 		size = pitch * mode_cmd->height / vsub;
 
-		if (size > (omap_gem_mmap_size(bos[i]) - mode_cmd->offsets[i])) {
-			dev_err(dev->dev, "provided buffer object is too small! %d < %d\n",
-					bos[i]->size - mode_cmd->offsets[i], size);
-			ret = -EINVAL;
-			goto fail;
-		}
-
-		if (i > 0 && pitch != mode_cmd->pitches[i - 1]) {
+		if (size > omap_gem_mmap_size(bos[i]) - mode_cmd->offsets[i]) {
 			dev_err(dev->dev,
-				"pitches are not the same between framebuffer planes %d != %d\n",
-				pitch, mode_cmd->pitches[i - 1]);
+				"provided buffer object is too small! %d < %d\n",
+				bos[i]->size - mode_cmd->offsets[i], size);
 			ret = -EINVAL;
 			goto fail;
 		}
-- 
Regards,

Laurent Pinchart

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

  parent reply	other threads:[~2016-09-19 12:27 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-19 12:27 [PATCH v3 00/20] OMAP DRM fixes and improvements Laurent Pinchart
2016-09-19 12:27 ` [PATCH v3 01/20] drm: omapdrm: fb: Limit number of planes per framebuffer to two Laurent Pinchart
2016-09-19 12:27 ` [PATCH v3 02/20] drm: omapdrm: fb: Use format information provided by the DRM core Laurent Pinchart
2016-09-20 12:47   ` Tomi Valkeinen
2016-12-12 21:41     ` Laurent Pinchart
2016-09-19 12:27 ` [PATCH v3 03/20] drm: omapdrm: fb: Simplify objects lookup when creating framebuffer Laurent Pinchart
2016-09-19 12:27 ` Laurent Pinchart [this message]
2016-09-20 12:55   ` [PATCH v3 04/20] drm: omapdrm: fb: Simplify mode command checks " Tomi Valkeinen
2016-09-19 12:27 ` [PATCH v3 05/20] drm: omapdrm: fb: Turn framebuffer creation error messages into debug Laurent Pinchart
2016-09-19 12:27 ` [PATCH v3 06/20] drm: omapdrm: Handle FIFO underflow IRQs internally Laurent Pinchart
2016-09-20 13:17   ` Tomi Valkeinen
2016-09-20 13:27   ` Tomi Valkeinen
2016-12-12 21:59     ` Laurent Pinchart
2016-09-19 12:27 ` [PATCH v3 07/20] drm: omapdrm: Handle CRTC error IRQs directly Laurent Pinchart
2016-09-19 12:27 ` [PATCH v3 08/20] drm: omapdrm: Handle OCP error IRQ directly Laurent Pinchart
2016-09-20 13:34   ` Tomi Valkeinen
2016-12-12 22:09     ` Laurent Pinchart
2016-09-19 12:27 ` [PATCH v3 09/20] drm: omapdrm: Replace DSS manager state check with omapdrm CRTC state Laurent Pinchart
2016-09-20 13:44   ` Tomi Valkeinen
2016-12-12 22:16     ` Laurent Pinchart
2016-09-19 12:27 ` [PATCH v3 10/20] drm: omapdrm: Only commit planes on active CRTCs Laurent Pinchart
2016-09-20 13:51   ` Tomi Valkeinen
2016-12-12 22:53     ` Laurent Pinchart
2016-12-13  7:58       ` Tomi Valkeinen
2016-12-13 13:12         ` Laurent Pinchart
2016-09-19 12:27 ` [PATCH v3 11/20] drm: omapdrm: Check DSS manager state in the enable/disable helpers Laurent Pinchart
2016-09-20 13:57   ` Tomi Valkeinen
2016-12-12 23:07     ` Laurent Pinchart
2016-12-13  8:15       ` Tomi Valkeinen
2016-12-13 23:56         ` Laurent Pinchart
2016-09-19 12:27 ` [PATCH v3 12/20] drm: omapdrm: Prevent processing the same event multiple times Laurent Pinchart
2016-09-27 12:24   ` Tomi Valkeinen
2016-12-12 10:29     ` Laurent Pinchart
2016-09-27 15:05   ` Daniel Kurtz
2016-12-12 10:21     ` Laurent Pinchart
2016-09-19 12:27 ` [PATCH v3 13/20] drm: omapdrm: Use a spinlock to protect the CRTC pending flag Laurent Pinchart
2016-09-27 12:27   ` Tomi Valkeinen
2016-09-19 12:27 ` [PATCH v3 14/20] drm: omapdrm: Keep vblank interrupt enabled while CRTC is active Laurent Pinchart
2016-09-19 12:27 ` [PATCH v3 15/20] drm: omapdrm: Don't expose the omap_irq_(un)register() functions Laurent Pinchart
2016-09-19 12:27 ` [PATCH v3 16/20] drm: omapdrm: Remove unused parameter from omap_drm_irq handler Laurent Pinchart
2016-09-19 12:27 ` [PATCH v3 17/20] drm: omapdrm: Don't call DISPC power handling in IRQ wait functions Laurent Pinchart
2016-09-19 12:27 ` [PATCH v3 18/20] drm: omapdrm: Make pipe2vbl function static Laurent Pinchart
2016-12-12 10:41   ` Tomi Valkeinen
2016-12-12 23:17     ` Laurent Pinchart
2016-09-19 12:27 ` [PATCH v3 19/20] drm: omapdrm: Simplify IRQ wait implementation Laurent Pinchart
2016-09-19 12:27 ` [PATCH v3 20/20] drm: omapdrm: Remove global variables Laurent Pinchart

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1474288063-5315-5-git-send-email-laurent.pinchart@ideasonboard.com \
    --to=laurent.pinchart@ideasonboard.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=tomi.valkeinen@ti.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.