From patchwork Wed Jun 20 14:09:28 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 9506 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 91C5423EE3 for ; Wed, 20 Jun 2012 14:09:33 +0000 (UTC) Received: from mail-yw0-f52.google.com (mail-yw0-f52.google.com [209.85.213.52]) by fiordland.canonical.com (Postfix) with ESMTP id 468F4A18410 for ; Wed, 20 Jun 2012 14:09:33 +0000 (UTC) Received: by yhpp61 with SMTP id p61so6268580yhp.11 for ; Wed, 20 Jun 2012 07:09:32 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-forwarded-to:x-forwarded-for:delivered-to:received-spf:from:to :date:message-id:x-mailer:cc:subject:x-beenthere:x-mailman-version :precedence:list-id:list-unsubscribe:list-archive:list-post :list-help:list-subscribe:mime-version:content-type :content-transfer-encoding:sender:errors-to:x-gm-message-state; bh=hSatSLIoywK2oujNf+CUtOCHeQtCrzwdnEleeecmY/8=; b=hfilja9rS7IMrlVh2jhgcdGhUOCzJ4yRsxlGhbCrRejOougmc4R0r7bLOL0YbtjHc5 faAB3VFdFCFXqjG7zuVn9ASOMi5zuNDBxsPqa1famsJc9kUkojwiCOckdv6TtGZ6W+5y UX7eqQ7O3c9yhWeeFFPmS8a4DsFJFL5SO421u21ZiViHRoC9xliwQdsXaCx/04TwdiMM Z5M418rjGJBPEMzGvte+CFO0BKBNpSqa+5Sl7mu38NFVCiDkjEZnIAc+2edmgRaBAnm0 6TZBGuVGeplYzT3yZH60I3f3Z6dKeFQ/3zeQwCZtArJh7CN+7KSL6ZbVOc2EpnRVGcw2 nLsQ== Received: by 10.50.163.99 with SMTP id yh3mr4554840igb.53.1340201370757; Wed, 20 Jun 2012 07:09:30 -0700 (PDT) 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.231.24.148 with SMTP id v20csp181494ibb; Wed, 20 Jun 2012 07:09:29 -0700 (PDT) Received: by 10.180.8.69 with SMTP id p5mr12337709wia.17.1340201367926; Wed, 20 Jun 2012 07:09:27 -0700 (PDT) Received: from mombin.canonical.com (mombin.canonical.com. [91.189.95.16]) by mx.google.com with ESMTP id n17si29117808wee.46.2012.06.20.07.09.26; Wed, 20 Jun 2012 07:09:27 -0700 (PDT) Received-SPF: neutral (google.com: 91.189.95.16 is neither permitted nor denied by best guess record for domain of linaro-mm-sig-bounces@lists.linaro.org) client-ip=91.189.95.16; Authentication-Results: mx.google.com; spf=neutral (google.com: 91.189.95.16 is neither permitted nor denied by best guess record for domain of linaro-mm-sig-bounces@lists.linaro.org) smtp.mail=linaro-mm-sig-bounces@lists.linaro.org Received: from localhost ([127.0.0.1] helo=mombin.canonical.com) by mombin.canonical.com with esmtp (Exim 4.71) (envelope-from ) id 1ShLb1-0008MM-9x; Wed, 20 Jun 2012 14:09:23 +0000 Received: from perceval.ideasonboard.com ([95.142.166.194]) by mombin.canonical.com with esmtp (Exim 4.71) (envelope-from ) id 1ShLay-0008Ld-0x for linaro-mm-sig@lists.linaro.org; Wed, 20 Jun 2012 14:09:20 +0000 Received: from localhost.localdomain (unknown [91.178.137.47]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 982C57ACE; Wed, 20 Jun 2012 16:09:19 +0200 (CEST) From: Laurent Pinchart To: linux-fbdev@vger.kernel.org Date: Wed, 20 Jun 2012 16:09:28 +0200 Message-Id: <1340201368-20751-1-git-send-email-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 1.7.3.4 Cc: linaro-mm-sig@lists.linaro.org, linux-media@vger.kernel.org Subject: [Linaro-mm-sig] [RFC/PATCH] fb: Add dma-buf support X-BeenThere: linaro-mm-sig@lists.linaro.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Unified memory management interest group." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linaro-mm-sig-bounces@lists.linaro.org Errors-To: linaro-mm-sig-bounces@lists.linaro.org X-Gm-Message-State: ALoCoQkiY/Qa4ntntws+aOvbpsOco4EAJLxbbZqptBY9UUj+PdwmgBgToVjjm9Sr3tqvag27ommi Add support for the dma-buf exporter role to the frame buffer API. The importer role isn't meaningful for frame buffer devices, as the frame buffer device model doesn't allow using externally allocated memory. Signed-off-by: Laurent Pinchart --- Documentation/fb/api.txt | 36 ++++++++++++++++++++++++++++++++++++ drivers/video/fbmem.c | 36 ++++++++++++++++++++++++++++++++++++ include/linux/fb.h | 12 ++++++++++++ 3 files changed, 84 insertions(+), 0 deletions(-) diff --git a/Documentation/fb/api.txt b/Documentation/fb/api.txt index d4ff7de..f0b2173 100644 --- a/Documentation/fb/api.txt +++ b/Documentation/fb/api.txt @@ -304,3 +304,39 @@ extensions. Upon successful format configuration, drivers update the fb_fix_screeninfo type, visual and line_length fields depending on the selected format. The type and visual fields are set to FB_TYPE_FOURCC and FB_VISUAL_FOURCC respectively. + + +5. DMA buffer sharing +--------------------- + +The dma-buf kernel framework allows DMA buffers to be shared across devices +and applications. Sharing buffers across display devices and video capture or +video decoding devices allow zero-copy operation when displaying video content +produced by a hardware device such as a camera or a hardware codec. This is +crucial to achieve optimal system performances during video display. + +While dma-buf supports both exporting internally allocated memory as a dma-buf +object (known as the exporter role) and importing a dma-buf object to be used +as device memory (known as the importer role), the frame buffer API only +supports the exporter role, as the frame buffer device model doesn't support +using externally-allocated memory. + +The export a frame buffer as a dma-buf file descriptors, applications call the +FBIOGET_DMABUF ioctl. The ioctl takes a pointer to a fb_dmabuf_export +structure. + +struct fb_dmabuf_export { + __u32 fd; + __u32 flags; +}; + +The flag field specifies the flags to be used when creating the dma-buf file +descriptor. The only supported flag is O_CLOEXEC. If the call is successful, +the driver will set the fd field to a file descriptor corresponding to the +dma-buf object. + +Applications can then pass the file descriptors to another application or +another device driver. The dma-buf object is automatically reference-counted, +applications can and should close the file descriptor as soon as they don't +need it anymore. The underlying dma-buf object will not be freed before the +last device that uses the dma-buf object releases it. diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c index 0dff12a..400e449 100644 --- a/drivers/video/fbmem.c +++ b/drivers/video/fbmem.c @@ -15,6 +15,7 @@ #include #include +#include #include #include #include @@ -1074,6 +1075,23 @@ fb_blank(struct fb_info *info, int blank) return ret; } +#ifdef CONFIG_DMA_SHARED_BUFFER +int +fb_get_dmabuf(struct fb_info *info, int flags) +{ + struct dma_buf *dmabuf; + + if (info->fbops->fb_dmabuf_export == NULL) + return -ENOTTY; + + dmabuf = info->fbops->fb_dmabuf_export(info); + if (IS_ERR(dmabuf)) + return PTR_ERR(dmabuf); + + return dma_buf_fd(dmabuf, flags); +} +#endif + static long do_fb_ioctl(struct fb_info *info, unsigned int cmd, unsigned long arg) { @@ -1084,6 +1102,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd, struct fb_cmap cmap_from; struct fb_cmap_user cmap; struct fb_event event; + struct fb_dmabuf_export dmaexp; void __user *argp = (void __user *)arg; long ret = 0; @@ -1191,6 +1210,23 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd, console_unlock(); unlock_fb_info(info); break; +#ifdef CONFIG_DMA_SHARED_BUFFER + case FBIOGET_DMABUF: + if (copy_from_user(&dmaexp, argp, sizeof(dmaexp))) + return -EFAULT; + + if (!lock_fb_info(info)) + return -ENODEV; + dmaexp.fd = fb_get_dmabuf(info, dmaexp.flags); + unlock_fb_info(info); + + if (dmaexp.fd < 0) + return dmaexp.fd; + + ret = copy_to_user(argp, &dmaexp, sizeof(dmaexp)) + ? -EFAULT : 0; + break; +#endif default: if (!lock_fb_info(info)) return -ENODEV; diff --git a/include/linux/fb.h b/include/linux/fb.h index ac3f1c6..c9fee75 100644 --- a/include/linux/fb.h +++ b/include/linux/fb.h @@ -39,6 +39,7 @@ #define FBIOPUT_MODEINFO 0x4617 #define FBIOGET_DISPINFO 0x4618 #define FBIO_WAITFORVSYNC _IOW('F', 0x20, __u32) +#define FBIOGET_DMABUF _IOR('F', 0x21, struct fb_dmabuf_export) #define FB_TYPE_PACKED_PIXELS 0 /* Packed Pixels */ #define FB_TYPE_PLANES 1 /* Non interleaved planes */ @@ -403,6 +404,11 @@ struct fb_cursor { #define FB_BACKLIGHT_MAX 0xFF #endif +struct fb_dmabuf_export { + __u32 fd; + __u32 flags; +}; + #ifdef __KERNEL__ #include @@ -418,6 +424,7 @@ struct vm_area_struct; struct fb_info; struct device; struct file; +struct dma_buf; /* Definitions below are used in the parsed monitor specs */ #define FB_DPMS_ACTIVE_OFF 1 @@ -701,6 +708,11 @@ struct fb_ops { /* called at KDB enter and leave time to prepare the console */ int (*fb_debug_enter)(struct fb_info *info); int (*fb_debug_leave)(struct fb_info *info); + +#ifdef CONFIG_DMA_SHARED_BUFFER + /* Export the frame buffer as a dmabuf object */ + struct dma_buf *(*fb_dmabuf_export)(struct fb_info *info); +#endif }; #ifdef CONFIG_FB_TILEBLITTING