From patchwork Thu Dec 15 06:16:20 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 5745 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 431CB23E19 for ; Thu, 15 Dec 2011 06:16:27 +0000 (UTC) Received: from mail-ey0-f180.google.com (mail-ey0-f180.google.com [209.85.215.180]) by fiordland.canonical.com (Postfix) with ESMTP id 30334A18112 for ; Thu, 15 Dec 2011 06:16:27 +0000 (UTC) Received: by mail-ey0-f180.google.com with SMTP id k10so1713888eaa.11 for ; Wed, 14 Dec 2011 22:16:27 -0800 (PST) Received: by 10.204.133.213 with SMTP id g21mr376929bkt.126.1323929786646; Wed, 14 Dec 2011 22:16:26 -0800 (PST) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.205.129.2 with SMTP id hg2cs31368bkc; Wed, 14 Dec 2011 22:16:26 -0800 (PST) Received: by 10.236.161.197 with SMTP id w45mr2337471yhk.96.1323929784526; Wed, 14 Dec 2011 22:16:24 -0800 (PST) Received: from mail-gy0-f178.google.com (mail-gy0-f178.google.com [209.85.160.178]) by mx.google.com with ESMTPS id v10si3953360yhi.87.2011.12.14.22.16.24 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 14 Dec 2011 22:16:24 -0800 (PST) Received-SPF: pass (google.com: domain of robdclark@gmail.com designates 209.85.160.178 as permitted sender) client-ip=209.85.160.178; Authentication-Results: mx.google.com; spf=pass (google.com: domain of robdclark@gmail.com designates 209.85.160.178 as permitted sender) smtp.mail=robdclark@gmail.com; dkim=pass (test mode) header.i=@gmail.com Received: by ghbg21 with SMTP id g21so1431366ghb.37 for ; Wed, 14 Dec 2011 22:16:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=sender:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; bh=MmglJoMDykPry17R9YRhRE65uNMBc5QX+Wn2uo6LCn4=; b=PNn+7snE2UYoyFWdoNUkes8gW9N3z0iA8QSCmhyKdV+CGfgt07lMTy4wlmmsYBvVpR rhoAid9D9BhUB5W3zZ8bvz2H1+6UFVlWfd6J6tihYI/cNCntKxbm+NatYc7dE1PXB4EP xGmdxWJRzIFlKH8gN3uhpbGGLQ6WLUVsF7H0M= Received: by 10.101.213.35 with SMTP id p35mr568447anq.45.1323929783763; Wed, 14 Dec 2011 22:16:23 -0800 (PST) Received: from localhost (ppp-70-253-156-7.dsl.rcsntx.swbell.net. [70.253.156.7]) by mx.google.com with ESMTPS id 39sm7439101ans.10.2011.12.14.22.16.22 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 14 Dec 2011 22:16:23 -0800 (PST) Sender: Rob Clark From: Rob Clark To: dri-devel@lists.freedesktop.org Cc: patches@linaro.org, Greg KH , Tomi Valkeinen , Rob Clark Subject: [PATCH 1/3] drm/omap: drm API update: addfb2 Date: Thu, 15 Dec 2011 00:16:20 -0600 Message-Id: <1323929782-11217-2-git-send-email-rob.clark@linaro.org> X-Mailer: git-send-email 1.7.5.4 In-Reply-To: <1323929782-11217-1-git-send-email-rob.clark@linaro.org> References: <1323929782-11217-1-git-send-email-rob.clark@linaro.org> From: Rob Clark Update to reflect changes in: "drm: add an fb creation ioctl that takes a pixel format v5" Signed-off-by: Rob Clark --- drivers/staging/omapdrm/omap_drv.h | 53 +++++++++++++++++- drivers/staging/omapdrm/omap_fb.c | 99 ++++++++++++++++++++++++++------- drivers/staging/omapdrm/omap_fbdev.c | 53 ++++++++++++------- 3 files changed, 163 insertions(+), 42 deletions(-) diff --git a/drivers/staging/omapdrm/omap_drv.h b/drivers/staging/omapdrm/omap_drv.h index 8dd7d74..bc8daa7 100644 --- a/drivers/staging/omapdrm/omap_drv.h +++ b/drivers/staging/omapdrm/omap_drv.h @@ -76,9 +76,9 @@ void omap_connector_flush(struct drm_connector *connector, void omap_connector_dpms(struct drm_connector *connector, int mode); struct drm_framebuffer *omap_framebuffer_create(struct drm_device *dev, - struct drm_file *file, struct drm_mode_fb_cmd *mode_cmd); + struct drm_file *file, struct drm_mode_fb_cmd2 *mode_cmd); struct drm_framebuffer *omap_framebuffer_init(struct drm_device *dev, - struct drm_mode_fb_cmd *mode_cmd, struct drm_gem_object *bo); + struct drm_mode_fb_cmd2 *mode_cmd, struct drm_gem_object **bos); struct drm_gem_object *omap_framebuffer_bo(struct drm_framebuffer *fb); int omap_framebuffer_get_buffer(struct drm_framebuffer *fb, int x, int y, void **vaddr, dma_addr_t *paddr, unsigned int *screen_width); @@ -128,4 +128,53 @@ static inline int align_pitch(int pitch, int width, int bpp) return ALIGN(pitch, 8 * bytespp); } +/* should these be made into common util helpers? + */ + +static inline int num_planes(uint32_t pixel_format) +{ + switch (pixel_format) { + default: + return 1; + case DRM_FORMAT_NV12: + case DRM_FORMAT_NV21: + case DRM_FORMAT_NV16: + case DRM_FORMAT_NV61: + return 2; + case DRM_FORMAT_YUV410: + case DRM_FORMAT_YVU410: + case DRM_FORMAT_YUV411: + case DRM_FORMAT_YVU411: + case DRM_FORMAT_YUV420: + case DRM_FORMAT_YVU420: + case DRM_FORMAT_YUV422: + case DRM_FORMAT_YVU422: + case DRM_FORMAT_YUV444: + case DRM_FORMAT_YVU444: + return 3; + } +} + +static inline int objects_lookup(struct drm_device *dev, + struct drm_file *filp, uint32_t pixel_format, + struct drm_gem_object **bos, uint32_t *handles) +{ + int i, n = num_planes(pixel_format); + + for (i = 0; i < n; i++) { + bos[i] = drm_gem_object_lookup(dev, filp, handles[i]); + if (!bos[i]) { + goto fail; + } + } + + return 0; + +fail: + while (--i > 0) { + drm_gem_object_unreference_unlocked(bos[i]); + } + return -ENOENT; +} + #endif /* __OMAP_DRV_H__ */ diff --git a/drivers/staging/omapdrm/omap_fb.c b/drivers/staging/omapdrm/omap_fb.c index 0b50c5b..0d3a15e 100644 --- a/drivers/staging/omapdrm/omap_fb.c +++ b/drivers/staging/omapdrm/omap_fb.c @@ -22,11 +22,43 @@ #include "drm_crtc.h" #include "drm_crtc_helper.h" - /* * framebuffer funcs */ +/* per-format info: */ +struct format { + enum omap_color_mode dss_format; + uint32_t pixel_format; + struct { + int stride_bpp; /* this times width is stride */ + int sub_y; /* sub-sample in y dimension */ + } planes[4]; + bool yuv; +}; + +static const struct format formats[] = { + /* 16bpp [A]RGB: */ + { OMAP_DSS_COLOR_RGB16, DRM_FORMAT_RGB565, {{2, 1}}, false }, /* RGB16-565 */ + { OMAP_DSS_COLOR_RGB12U, DRM_FORMAT_RGBX4444, {{2, 1}}, false }, /* RGB12x-4444 */ + { OMAP_DSS_COLOR_RGBX16, DRM_FORMAT_XRGB4444, {{2, 1}}, false }, /* xRGB12-4444 */ + { OMAP_DSS_COLOR_RGBA16, DRM_FORMAT_RGBA4444, {{2, 1}}, false }, /* RGBA12-4444 */ + { OMAP_DSS_COLOR_ARGB16, DRM_FORMAT_ABGR4444, {{2, 1}}, false }, /* ARGB16-4444 */ + { OMAP_DSS_COLOR_XRGB16_1555, DRM_FORMAT_XRGB1555, {{2, 1}}, false }, /* xRGB15-1555 */ + { OMAP_DSS_COLOR_ARGB16_1555, DRM_FORMAT_ARGB1555, {{2, 1}}, false }, /* ARGB16-1555 */ + /* 24bpp RGB: */ + { OMAP_DSS_COLOR_RGB24P, DRM_FORMAT_RGB888, {{3, 1}}, false }, /* RGB24-888 */ + /* 32bpp [A]RGB: */ + { OMAP_DSS_COLOR_RGBX32, DRM_FORMAT_RGBX8888, {{4, 1}}, false }, /* RGBx24-8888 */ + { OMAP_DSS_COLOR_RGB24U, DRM_FORMAT_XRGB8888, {{4, 1}}, false }, /* xRGB24-8888 */ + { OMAP_DSS_COLOR_RGBA32, DRM_FORMAT_RGBA8888, {{4, 1}}, false }, /* RGBA32-8888 */ + { OMAP_DSS_COLOR_ARGB32, DRM_FORMAT_ARGB8888, {{4, 1}}, false }, /* ARGB32-8888 */ + /* YUV: */ + { OMAP_DSS_COLOR_NV12, DRM_FORMAT_NV12, {{1, 1}, {1, 2}}, true }, + { OMAP_DSS_COLOR_YUV2, DRM_FORMAT_YUYV, {{2, 1}}, true }, + { OMAP_DSS_COLOR_UYVY, DRM_FORMAT_UYVY, {{2, 1}}, true }, +}; + #define to_omap_framebuffer(x) container_of(x, struct omap_framebuffer, base) struct omap_framebuffer { @@ -34,6 +66,7 @@ struct omap_framebuffer { struct drm_gem_object *bo; int size; dma_addr_t paddr; + const struct format *format; }; static int omap_framebuffer_create_handle(struct drm_framebuffer *fb, @@ -171,39 +204,61 @@ void omap_framebuffer_flush(struct drm_framebuffer *fb, } struct drm_framebuffer *omap_framebuffer_create(struct drm_device *dev, - struct drm_file *file, struct drm_mode_fb_cmd *mode_cmd) + struct drm_file *file, struct drm_mode_fb_cmd2 *mode_cmd) { - struct drm_gem_object *bo; + struct drm_gem_object *bos[4]; struct drm_framebuffer *fb; - bo = drm_gem_object_lookup(dev, file, mode_cmd->handle); - if (!bo) { - return ERR_PTR(-ENOENT); - } - fb = omap_framebuffer_init(dev, mode_cmd, bo); - if (!fb) { - return ERR_PTR(-ENOMEM); + int ret; + + ret = objects_lookup(dev, file, mode_cmd->pixel_format, + bos, mode_cmd->handles); + if (ret) + return ERR_PTR(ret); + + fb = omap_framebuffer_init(dev, mode_cmd, bos); + if (IS_ERR(fb)) { + int i, n = num_planes(mode_cmd->pixel_format); + for (i = 0; i < n; i++) + drm_gem_object_unreference_unlocked(bos[i]); + return fb; } return fb; } struct drm_framebuffer *omap_framebuffer_init(struct drm_device *dev, - struct drm_mode_fb_cmd *mode_cmd, struct drm_gem_object *bo) + struct drm_mode_fb_cmd2 *mode_cmd, struct drm_gem_object **bos) { struct omap_framebuffer *omap_fb; struct drm_framebuffer *fb = NULL; - int size, ret; + const struct format *format = NULL; + int i, size, ret; - DBG("create framebuffer: dev=%p, mode_cmd=%p (%dx%d@%d)", + DBG("create framebuffer: dev=%p, mode_cmd=%p (%dx%d@%4.4s)", dev, mode_cmd, mode_cmd->width, mode_cmd->height, - mode_cmd->bpp); + (char *)&mode_cmd->pixel_format); + + for (i = 0; i < ARRAY_SIZE(formats); i++) { + if (formats[i].pixel_format == mode_cmd->pixel_format) { + format = &formats[i]; + break; + } + } + + if (!format) { + dev_err(dev->dev, "unsupported pixel format: %4.4s\n", + (char *)&mode_cmd->pixel_format); + ret = -EINVAL; + goto fail; + } /* in case someone tries to feed us a completely bogus stride: */ - mode_cmd->pitch = align_pitch(mode_cmd->pitch, - mode_cmd->width, mode_cmd->bpp); + mode_cmd->pitches[0] = align_pitch(mode_cmd->pitches[0], + mode_cmd->width, format->planes[0].stride_bpp); omap_fb = kzalloc(sizeof(*omap_fb), GFP_KERNEL); if (!omap_fb) { dev_err(dev->dev, "could not allocate fb\n"); + ret = -ENOMEM; goto fail; } @@ -216,17 +271,19 @@ struct drm_framebuffer *omap_framebuffer_init(struct drm_device *dev, DBG("create: FB ID: %d (%p)", fb->base.id, fb); - size = PAGE_ALIGN(mode_cmd->pitch * mode_cmd->height); + size = PAGE_ALIGN(mode_cmd->pitches[0] * mode_cmd->height); - if (size > bo->size) { + if (size > bos[0]->size) { dev_err(dev->dev, "provided buffer object is too small!\n"); + ret = -EINVAL; goto fail; } - omap_fb->bo = bo; + omap_fb->bo = bos[0]; omap_fb->size = size; - if (omap_gem_get_paddr(bo, &omap_fb->paddr, true)) { + ret = omap_gem_get_paddr(bos[0], &omap_fb->paddr, true); + if (ret) { dev_err(dev->dev, "could not map (paddr)!\n"); goto fail; } @@ -239,5 +296,5 @@ fail: if (fb) { omap_framebuffer_destroy(fb); } - return NULL; + return ERR_PTR(ret); } diff --git a/drivers/staging/omapdrm/omap_fbdev.c b/drivers/staging/omapdrm/omap_fbdev.c index 093ae2f..a3cd78c 100644 --- a/drivers/staging/omapdrm/omap_fbdev.c +++ b/drivers/staging/omapdrm/omap_fbdev.c @@ -129,10 +129,8 @@ static int omap_fbdev_create(struct drm_fb_helper *helper, struct drm_framebuffer *fb = NULL; union omap_gem_size gsize; struct fb_info *fbi = NULL; - struct drm_mode_fb_cmd mode_cmd = {0}; + struct drm_mode_fb_cmd2 mode_cmd = {0}; dma_addr_t paddr; - void __iomem *vaddr; - int size, screen_width; int ret; /* only doing ARGB32 since this is what is needed to alpha-blend @@ -145,36 +143,56 @@ static int omap_fbdev_create(struct drm_fb_helper *helper, sizes->surface_height, sizes->surface_bpp, sizes->fb_width, sizes->fb_height); + mode_cmd.pixel_format = drm_mode_legacy_fb_format(sizes->surface_bpp, + sizes->surface_depth); + mode_cmd.width = sizes->surface_width; mode_cmd.height = sizes->surface_height; - mode_cmd.bpp = sizes->surface_bpp; - mode_cmd.depth = sizes->surface_depth; - - mode_cmd.pitch = align_pitch( - mode_cmd.width * ((mode_cmd.bpp + 7) / 8), - mode_cmd.width, mode_cmd.bpp); + mode_cmd.pitches[0] = align_pitch( + mode_cmd.width * ((sizes->surface_bpp + 7) / 8), + mode_cmd.width, sizes->surface_bpp); fbdev->ywrap_enabled = priv->has_dmm && ywrap_enabled; if (fbdev->ywrap_enabled) { /* need to align pitch to page size if using DMM scrolling */ - mode_cmd.pitch = ALIGN(mode_cmd.pitch, PAGE_SIZE); + mode_cmd.pitches[0] = ALIGN(mode_cmd.pitches[0], PAGE_SIZE); } /* allocate backing bo */ gsize = (union omap_gem_size){ - .bytes = PAGE_ALIGN(mode_cmd.pitch * mode_cmd.height), + .bytes = PAGE_ALIGN(mode_cmd.pitches[0] * mode_cmd.height), }; DBG("allocating %d bytes for fb %d", gsize.bytes, dev->primary->index); fbdev->bo = omap_gem_new(dev, gsize, OMAP_BO_SCANOUT | OMAP_BO_WC); if (!fbdev->bo) { dev_err(dev->dev, "failed to allocate buffer object\n"); + ret = -ENOMEM; goto fail; } - fb = omap_framebuffer_init(dev, &mode_cmd, fbdev->bo); - if (!fb) { + fb = omap_framebuffer_init(dev, &mode_cmd, &fbdev->bo); + if (IS_ERR(fb)) { dev_err(dev->dev, "failed to allocate fb\n"); + /* note: if fb creation failed, we can't rely on fb destroy + * to unref the bo: + */ + drm_gem_object_unreference(fbdev->bo); + ret = PTR_ERR(fb); + goto fail; + } + + /* note: this keeps the bo pinned.. which is perhaps not ideal, + * but is needed as long as we use fb_mmap() to mmap to userspace + * (since this happens using fix.smem_start). Possibly we could + * implement our own mmap using GEM mmap support to avoid this + * (non-tiled buffer doesn't need to be pinned for fbcon to write + * to it). Then we just need to be sure that we are able to re- + * pin it in case of an opps. + */ + ret = omap_gem_get_paddr(fbdev->bo, &paddr, true); + if (ret) { + dev_err(dev->dev, "could not map (paddr)!\n"); ret = -ENOMEM; goto fail; } @@ -209,15 +227,12 @@ static int omap_fbdev_create(struct drm_fb_helper *helper, drm_fb_helper_fill_fix(fbi, fb->pitch, fb->depth); drm_fb_helper_fill_var(fbi, helper, sizes->fb_width, sizes->fb_height); - size = omap_framebuffer_get_buffer(fb, 0, 0, - &vaddr, &paddr, &screen_width); - dev->mode_config.fb_base = paddr; - fbi->screen_base = vaddr; - fbi->screen_size = size; + fbi->screen_base = omap_gem_vaddr(fbdev->bo); + fbi->screen_size = fbdev->bo->size; fbi->fix.smem_start = paddr; - fbi->fix.smem_len = size; + fbi->fix.smem_len = fbdev->bo->size; /* if we have DMM, then we can use it for scrolling by just * shuffling pages around in DMM rather than doing sw blit.