drm/rcar-du: Fix buffer pitch alignment
authorLaurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
Thu, 4 Jul 2013 18:05:51 +0000 (20:05 +0200)
committerDave Airlie <airlied@redhat.com>
Fri, 5 Jul 2013 05:35:13 +0000 (15:35 +1000)
The DU requires a 16 pixels pitch alignement. Make sure dumb buffers are
allocated with the correct pitch, and validate the pitch when creating
frame buffers.

Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
Signed-off-by: Dave Airlie <airlied@redhat.com>
drivers/gpu/drm/rcar-du/rcar_du_drv.c
drivers/gpu/drm/rcar-du/rcar_du_kms.c
drivers/gpu/drm/rcar-du/rcar_du_kms.h

index 003b34ee38e372a47f4cccd70072e506a7e3c563..ff82877de876295690c67b0ceb2c68e04405ef3a 100644 (file)
@@ -251,7 +251,7 @@ static struct drm_driver rcar_du_driver = {
        .prime_fd_to_handle     = drm_gem_prime_fd_to_handle,
        .gem_prime_import       = drm_gem_cma_dmabuf_import,
        .gem_prime_export       = drm_gem_cma_dmabuf_export,
-       .dumb_create            = drm_gem_cma_dumb_create,
+       .dumb_create            = rcar_du_dumb_create,
        .dumb_map_offset        = drm_gem_cma_dumb_map_offset,
        .dumb_destroy           = drm_gem_cma_dumb_destroy,
        .fops                   = &rcar_du_fops,
index 06cacf6532c05f39314b3afabf5b8a0b26e050fd..d30c2e29bee2f122d8cff43681449fbe9e8ae46b 100644 (file)
@@ -138,11 +138,25 @@ void rcar_du_encoder_mode_commit(struct drm_encoder *encoder)
  * Frame buffer
  */
 
+int rcar_du_dumb_create(struct drm_file *file, struct drm_device *dev,
+                       struct drm_mode_create_dumb *args)
+{
+       unsigned int min_pitch = DIV_ROUND_UP(args->width * args->bpp, 8);
+       unsigned int align;
+
+       /* The pitch must be aligned to a 16 pixels boundary. */
+       align = 16 * args->bpp / 8;
+       args->pitch = roundup(max(args->pitch, min_pitch), align);
+
+       return drm_gem_cma_dumb_create(file, dev, args);
+}
+
 static struct drm_framebuffer *
 rcar_du_fb_create(struct drm_device *dev, struct drm_file *file_priv,
                  struct drm_mode_fb_cmd2 *mode_cmd)
 {
        const struct rcar_du_format_info *format;
+       unsigned int align;
 
        format = rcar_du_format_info(mode_cmd->pixel_format);
        if (format == NULL) {
@@ -151,7 +165,10 @@ rcar_du_fb_create(struct drm_device *dev, struct drm_file *file_priv,
                return ERR_PTR(-EINVAL);
        }
 
-       if (mode_cmd->pitches[0] & 15 || mode_cmd->pitches[0] >= 8192) {
+       align = 16 * format->bpp / 8;
+
+       if (mode_cmd->pitches[0] & (align - 1) ||
+           mode_cmd->pitches[0] >= 8192) {
                dev_dbg(dev->dev, "invalid pitch value %u\n",
                        mode_cmd->pitches[0]);
                return ERR_PTR(-EINVAL);
index e4d8db069a06b150ec366f6063d72a41aa2f85e2..dba472263486d9521028f4d1c265c196c1e1da47 100644 (file)
@@ -56,4 +56,7 @@ void rcar_du_encoder_mode_commit(struct drm_encoder *encoder);
 
 int rcar_du_modeset_init(struct rcar_du_device *rcdu);
 
+int rcar_du_dumb_create(struct drm_file *file, struct drm_device *dev,
+                       struct drm_mode_create_dumb *args);
+
 #endif /* __RCAR_DU_KMS_H__ */