From patchwork Tue Aug 14 15:34:49 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomasz Stanislawski X-Patchwork-Id: 10750 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 470D823E00 for ; Tue, 14 Aug 2012 15:38:08 +0000 (UTC) Received: from mail-gh0-f180.google.com (mail-gh0-f180.google.com [209.85.160.180]) by fiordland.canonical.com (Postfix) with ESMTP id 01D9EA18A29 for ; Tue, 14 Aug 2012 15:38:07 +0000 (UTC) Received: by ghbg10 with SMTP id g10so622554ghb.11 for ; Tue, 14 Aug 2012 08:38:07 -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:x-auditid :from:to:date:message-id:x-mailer:in-reply-to:references :x-brightmail-tracker:x-tm-as-mml: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=ioRRZ5Cjq5fW2mgWTNmTfGNHP80TlIa2GWZcRZcFsog=; b=LMSbHGD/M5jZJOfok7LU0rVqhqRXIqq8OwUhg4QoDhy0kldtUovWoCMEuBlztNDqXs Ja0Uv6WDJd901X39ZCmsj7P4y96oihGiE3O0ISXkiq015+47PAWctA89nXDK8GFogv1X hH5By6Wm0TtM73S/v20QYp2ofIHMQxJxMP9Spz/F6Mvoo6NQ3QcgpexR+fWzJWzE8EJq bKzqARbiCExIFxtj2vYSrSJAdV7XRr7UxU+odt/aWJeZORrXwpHZGGRkPKOaxEyAI2t3 l11KApoGOtTTSmnkNc9XI7/sTFdW/xp5XmrZX3fm6n5RFMdUA0dwm+WTutJqgkszE70x PVGg== Received: by 10.50.181.136 with SMTP id dw8mr12638213igc.31.1344958687003; Tue, 14 Aug 2012 08:38:07 -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.50.184.200 with SMTP id ew8csp20690igc; Tue, 14 Aug 2012 08:38:06 -0700 (PDT) Received: by 10.216.197.12 with SMTP id s12mr8757387wen.4.1344958685433; Tue, 14 Aug 2012 08:38:05 -0700 (PDT) Received: from mombin.canonical.com (mombin.canonical.com. [91.189.95.16]) by mx.google.com with ESMTP id r9si26859694wic.46.2012.08.14.08.38.04; Tue, 14 Aug 2012 08:38:05 -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 1T1JBz-0008Uo-Am; Tue, 14 Aug 2012 15:38:03 +0000 Received: from mailout4.samsung.com ([203.254.224.34]) by mombin.canonical.com with esmtp (Exim 4.71) (envelope-from ) id 1T1JBw-0008Uh-KW for linaro-mm-sig@lists.linaro.org; Tue, 14 Aug 2012 15:38:01 +0000 Received: from epcpsbgm1.samsung.com (mailout4.samsung.com [203.254.224.34]) by mailout4.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0M8R000G64QR3Z20@mailout4.samsung.com> for linaro-mm-sig@lists.linaro.org; Wed, 15 Aug 2012 00:37:39 +0900 (KST) X-AuditID: cbfee61a-b7fc66d0000043b7-cc-502a70c32c66 Received: from epmmp1.local.host ( [203.254.227.16]) by epcpsbgm1.samsung.com (EPCPMTA) with SMTP id 8C.8D.17335.3C07A205; Wed, 15 Aug 2012 00:37:39 +0900 (KST) Received: from mcdsrvbld02.digital.local ([106.116.37.23]) by mmp1.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTPA id <0M8R004J44MBC810@mmp1.samsung.com> for linaro-mm-sig@lists.linaro.org; Wed, 15 Aug 2012 00:37:39 +0900 (KST) From: Tomasz Stanislawski To: linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org Date: Tue, 14 Aug 2012 17:34:49 +0200 Message-id: <1344958496-9373-20-git-send-email-t.stanislaws@samsung.com> X-Mailer: git-send-email 1.7.10 In-reply-to: <1344958496-9373-1-git-send-email-t.stanislaws@samsung.com> References: <1344958496-9373-1-git-send-email-t.stanislaws@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrMJMWRmVeSWpSXmKPExsVy+t9jAd3DBVoBBhdPKlt8ufKQyYHR4/a/ x8wBjFFcNimpOZllqUX6dglcGe8W/mcqmCJTcX9yO2sDY5N4FyMnh4SAicSKVQtYIWwxiQv3 1rN1MXJxCAksYpS4vmoPC4Szlknixdt+FpAqNqCOY0s+M4LYIgIOEqfvzmIGKWIWOMQssb/3 NTtIQljASeL44l9gRSwCqhKfP64Hs3kFPCSa156HWicv8fR+HxuIzQkUf7mpG6iGA2ibu8TC n/4TGHkXMDKsYhRNLUguKE5KzzXUK07MLS7NS9dLzs/dxAj2+jOpHYwrGywOMQpwMCrx8Cqk aQYIsSaWFVfmHmKU4GBWEuEtCtIKEOJNSaysSi3Kjy8qzUktPsQozcGiJM5r7P3VX0ggPbEk NTs1tSC1CCbLxMEp1cCo9EDiAvcPkwX7vzJ2VF3IkN076SJ31hLB53NyFnTIXp50dNZ8o5V+ k1U3xq5O+n77WaHgjSU2vi9E9La3LtyaZLlo7s3jHSb7Hwa0fW6U0dso9G5VTeue8w8ti5TC 5hruuvXpg9vxiWYzpm76qHvCcvb86OhbZQKLt3pdmqYkPE9C5vJXpTM72ZVYijMSDbWYi4oT AclSNK/2AQAA X-TM-AS-MML: No Cc: k.debski@samsung.com, pawel@osciak.com, sumit.semwal@ti.com, mchehab@redhat.com, robdclark@gmail.com, linaro-mm-sig@lists.linaro.org, kyungmin.park@samsung.com, dmitriyz@google.com, laurent.pinchart@ideasonboard.com, s.nawrocki@samsung.com, airlied@redhat.com, remi@remlab.net, g.liakhovetski@gmx.de Subject: [Linaro-mm-sig] [PATCHv8 19/26] v4l: vb2: add buffer exporting via dmabuf 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: ALoCoQkDfNHtk9heNbGvLy1ooenk34mvLHFO0yr3gEeaGyrsPqCntuIwMdppitoBfNgfX5kVi9b7 This patch adds extension to videobuf2-core. It allow to export a mmap buffer as a file descriptor. Signed-off-by: Tomasz Stanislawski Signed-off-by: Kyungmin Park Acked-by: Laurent Pinchart --- drivers/media/video/videobuf2-core.c | 67 ++++++++++++++++++++++++++++++++++ include/media/videobuf2-core.h | 2 + 2 files changed, 69 insertions(+) diff --git a/drivers/media/video/videobuf2-core.c b/drivers/media/video/videobuf2-core.c index aed21e4..61354ec 100644 --- a/drivers/media/video/videobuf2-core.c +++ b/drivers/media/video/videobuf2-core.c @@ -1743,6 +1743,73 @@ static int __find_plane_by_offset(struct vb2_queue *q, unsigned long off, } /** + * vb2_expbuf() - Export a buffer as a file descriptor + * @q: videobuf2 queue + * @eb: export buffer structure passed from userspace to vidioc_expbuf + * handler in driver + * + * The return values from this function are intended to be directly returned + * from vidioc_expbuf handler in driver. + */ +int vb2_expbuf(struct vb2_queue *q, struct v4l2_exportbuffer *eb) +{ + struct vb2_buffer *vb = NULL; + struct vb2_plane *vb_plane; + unsigned int buffer, plane; + int ret; + struct dma_buf *dbuf; + + if (q->memory != V4L2_MEMORY_MMAP) { + dprintk(1, "Queue is not currently set up for mmap\n"); + return -EINVAL; + } + + if (!q->mem_ops->get_dmabuf) { + dprintk(1, "Queue does not support DMA buffer exporting\n"); + return -EINVAL; + } + + if (eb->flags & ~O_CLOEXEC) { + dprintk(1, "Queue does support only O_CLOEXEC flag\n"); + return -EINVAL; + } + + /* + * Find the plane corresponding to the offset passed by userspace. + */ + ret = __find_plane_by_offset(q, eb->mem_offset, &buffer, &plane); + if (ret) { + dprintk(1, "invalid offset %u\n", eb->mem_offset); + return ret; + } + + vb = q->bufs[buffer]; + vb_plane = &vb->planes[plane]; + + dbuf = call_memop(q, get_dmabuf, vb_plane->mem_priv); + if (IS_ERR_OR_NULL(dbuf)) { + dprintk(1, "Failed to export buffer %d, plane %d\n", + buffer, plane); + return -EINVAL; + } + + ret = dma_buf_fd(dbuf, eb->flags); + if (ret < 0) { + dprintk(3, "buffer %d, plane %d failed to export (%d)\n", + buffer, plane, ret); + dma_buf_put(dbuf); + return ret; + } + + dprintk(3, "buffer %d, plane %d exported as %d descriptor\n", + buffer, plane, ret); + eb->fd = ret; + + return 0; +} +EXPORT_SYMBOL_GPL(vb2_expbuf); + +/** * vb2_mmap() - map video buffers into application address space * @q: videobuf2 queue * @vma: vma passed to the mmap file operation handler in the driver diff --git a/include/media/videobuf2-core.h b/include/media/videobuf2-core.h index c306fec..b034424 100644 --- a/include/media/videobuf2-core.h +++ b/include/media/videobuf2-core.h @@ -81,6 +81,7 @@ struct vb2_fileio_data; struct vb2_mem_ops { void *(*alloc)(void *alloc_ctx, unsigned long size); void (*put)(void *buf_priv); + struct dma_buf *(*get_dmabuf)(void *buf_priv); void *(*get_userptr)(void *alloc_ctx, unsigned long vaddr, unsigned long size, int write); @@ -363,6 +364,7 @@ int vb2_queue_init(struct vb2_queue *q); void vb2_queue_release(struct vb2_queue *q); int vb2_qbuf(struct vb2_queue *q, struct v4l2_buffer *b); +int vb2_expbuf(struct vb2_queue *q, struct v4l2_exportbuffer *eb); int vb2_dqbuf(struct vb2_queue *q, struct v4l2_buffer *b, bool nonblocking); int vb2_streamon(struct vb2_queue *q, enum v4l2_buf_type type);