From patchwork Thu Jun 14 14:32:22 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomasz Stanislawski X-Patchwork-Id: 9301 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 1554D23E53 for ; Thu, 14 Jun 2012 14:32:56 +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 C11D2A189E3 for ; Thu, 14 Jun 2012 14:32:55 +0000 (UTC) Received: by yhpp61 with SMTP id p61so1646759yhp.11 for ; Thu, 14 Jun 2012 07:32:55 -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:date:from :in-reply-to:to:message-id:x-mailer:references: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=a44IVwvaaB7kFCjueciXe7whEm4L78P6ooGtwuySLE8=; b=HE96Zw93l6Fdg1YLMe0PBSe/O7Kd5KrOvhvt+PBhv0fSUriwRtAB4NO9fJBilkog6I eQ401of14e0+3LxNfaZ/KwSsneyfBhSqrGKXgiv1u9OSIj3ZF7o0A4W10rv5crnQanLo z3NXnQOyS7l+P9HS4NoL0hoRwqefDBHRspJODiD+lI6kpkjnolm6UsbjJ5IbPkGPkbDo UPPq4A/ObsOqUrrpyiGLmLMfAP3u9q8CE5q9SGET/Lw3YeFaciSRPcks+pvhJMN5fu5p q8WucNddCZsvARH+eOO8Jg+HZwpmlK7c7d/Xfy9MeKHfAnJ4k+ugldRJ1zIf+bii3QDn VGaQ== Received: by 10.50.193.196 with SMTP id hq4mr12709677igc.57.1339684374900; Thu, 14 Jun 2012 07:32:54 -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 v20csp88219ibb; Thu, 14 Jun 2012 07:32:52 -0700 (PDT) Received: by 10.180.101.170 with SMTP id fh10mr54004521wib.0.1339684371231; Thu, 14 Jun 2012 07:32:51 -0700 (PDT) Received: from mombin.canonical.com (mombin.canonical.com. [91.189.95.16]) by mx.google.com with ESMTP id j13si18511081wie.35.2012.06.14.07.32.49; Thu, 14 Jun 2012 07:32:51 -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 1SfB6L-0007yF-IH; Thu, 14 Jun 2012 14:32:45 +0000 Received: from mailout2.w1.samsung.com ([210.118.77.12]) by mombin.canonical.com with esmtp (Exim 4.71) (envelope-from ) id 1SfB6F-0007uF-UA for linaro-mm-sig@lists.linaro.org; Thu, 14 Jun 2012 14:32:40 +0000 Received: from euspt2 (mailout2.w1.samsung.com [210.118.77.12]) by mailout2.w1.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0M5M00AGE337DX80@mailout2.w1.samsung.com> for linaro-mm-sig@lists.linaro.org; Thu, 14 Jun 2012 15:33:07 +0100 (BST) Received: from linux.samsung.com ([106.116.38.10]) by spt2.w1.samsung.com (iPlanet Messaging Server 5.2 Patch 2 (built Jul 14 2004)) with ESMTPA id <0M5M00GFZ32A22@spt2.w1.samsung.com> for linaro-mm-sig@lists.linaro.org; Thu, 14 Jun 2012 15:32:35 +0100 (BST) Received: from mcdsrvbld02.digital.local (unknown [106.116.37.23]) by linux.samsung.com (Postfix) with ESMTP id 06D08270166; Thu, 14 Jun 2012 16:37:07 +0200 (CEST) Date: Thu, 14 Jun 2012 16:32:22 +0200 From: Tomasz Stanislawski In-reply-to: <1339684349-28882-1-git-send-email-t.stanislaws@samsung.com> To: linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org Message-id: <1339684349-28882-3-git-send-email-t.stanislaws@samsung.com> X-Mailer: git-send-email 1.7.10 References: <1339684349-28882-1-git-send-email-t.stanislaws@samsung.com> X-TM-AS-MML: No Cc: pawel@osciak.com, sumit.semwal@ti.com, linux-doc@vger.kernel.org, mchehab@redhat.com, robdclark@gmail.com, linaro-mm-sig@lists.linaro.org, kyungmin.park@samsung.com, laurent.pinchart@ideasonboard.com, airlied@redhat.com, remi@remlab.net, g.liakhovetski@gmx.de Subject: [Linaro-mm-sig] [PATCHv2 2/9] Documentation: media: description of DMABUF exporting in V4L2 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: ALoCoQk+GZRIxgJYLAeOprUPr9WTJg+hJVfqiBpdn/3pd7n3UDfX2LuPQQoWXErKZZoiWt8psKxn This patch adds description and usage examples for exporting DMABUF file descriptor in V4L2. Signed-off-by: Tomasz Stanislawski Signed-off-by: Kyungmin Park CC: linux-doc@vger.kernel.org --- Documentation/DocBook/media/v4l/compat.xml | 3 + Documentation/DocBook/media/v4l/io.xml | 3 + Documentation/DocBook/media/v4l/v4l2.xml | 1 + Documentation/DocBook/media/v4l/vidioc-expbuf.xml | 223 +++++++++++++++++++++ 4 files changed, 230 insertions(+) create mode 100644 Documentation/DocBook/media/v4l/vidioc-expbuf.xml diff --git a/Documentation/DocBook/media/v4l/compat.xml b/Documentation/DocBook/media/v4l/compat.xml index 07a311f..7773450 100644 --- a/Documentation/DocBook/media/v4l/compat.xml +++ b/Documentation/DocBook/media/v4l/compat.xml @@ -2591,6 +2591,9 @@ ioctls. Importing DMABUF file descriptors as a new IO method described in . + + Exporting DMABUF files using &VIDIOC-EXPBUF; ioctl. + diff --git a/Documentation/DocBook/media/v4l/io.xml b/Documentation/DocBook/media/v4l/io.xml index f55b0ab..7a0dfc9 100644 --- a/Documentation/DocBook/media/v4l/io.xml +++ b/Documentation/DocBook/media/v4l/io.xml @@ -488,6 +488,9 @@ buffer from userspace using a file descriptor previously exported for a different or the same device (known as the importer role), or both. This section describes the DMABUF importer role API in V4L2. + Refer to DMABUF exporting for +details about exporting a V4L2 buffers as DMABUF file descriptors. + Input and output devices support the streaming I/O method when the V4L2_CAP_STREAMING flag in the capabilities field of &v4l2-capability; returned by diff --git a/Documentation/DocBook/media/v4l/v4l2.xml b/Documentation/DocBook/media/v4l/v4l2.xml index 015c561..8f650d2 100644 --- a/Documentation/DocBook/media/v4l/v4l2.xml +++ b/Documentation/DocBook/media/v4l/v4l2.xml @@ -561,6 +561,7 @@ and discussions on the V4L mailing list. &sub-log-status; &sub-overlay; &sub-qbuf; + &sub-expbuf; &sub-querybuf; &sub-querycap; &sub-queryctrl; diff --git a/Documentation/DocBook/media/v4l/vidioc-expbuf.xml b/Documentation/DocBook/media/v4l/vidioc-expbuf.xml new file mode 100644 index 0000000..30ebf67 --- /dev/null +++ b/Documentation/DocBook/media/v4l/vidioc-expbuf.xml @@ -0,0 +1,223 @@ + + + + ioctl VIDIOC_EXPBUF + &manvol; + + + + VIDIOC_EXPBUF + Export a buffer as a DMABUF file descriptor. + + + + + + int ioctl + int fd + int request + struct v4l2_exportbuffer *argp + + + + + + Arguments + + + + fd + + &fd; + + + + request + + VIDIOC_EXPBUF + + + + argp + + + + + + + + + Description + + + Experimental + This is an experimental + interface and may change in the future. + + +This ioctl is an extension to the memory +mapping I/O method therefore it is available only for +V4L2_MEMORY_MMAP buffers. It can be used to export a +buffer as DMABUF file at any time after buffers have been allocated with the +&VIDIOC-REQBUFS; ioctl. + +Prior to exporting an application calls VIDIOC_QUERYBUF to obtain memory offsets. When +using the multi-planar API every plane has +own offset. + +To export a buffer, the application fills &v4l2-exportbuffer;. The + mem_offset field is set to the offset obtained +from VIDIOC_QUERYBUF . Additional flags may be posted in +the flags field. Refer to manual for open syscall +for details. Currently only O_CLOEXEC is guaranteed to be supported. All other +fields must be set to zero. In a case of multi-planar API, every plane is +exported separately using multiple VIDIOC_EXPBUF +calls. + + After calling VIDIOC_EXPBUF the fd + field will be set by a driver. This is a DMABUF file +descriptor. The application may pass it to other API. Refer to DMABUF importing for details about importing DMABUF +files into V4L2 nodes. A developer is encouraged to close a DMABUF file when it +is no longer used. + + + +
+ Examples + + + Exporting a buffer. + +int buffer_export(int v4lfd, &v4l2-buf-type; bt, int index, int *dmafd) +{ + &v4l2-buffer; buf; + &v4l2-exportbuffer; expbuf; + + memset(&buf, 0, sizeof buf); + buf.type = bt; + buf.memory = V4L2_MEMORY_MMAP; + buf.index = index; + + if (ioctl (v4lfd, &VIDIOC-QUERYBUF;, &buf) == -1) { + perror ("VIDIOC_QUERYBUF"); + return -1; + } + + memset(&expbuf, 0, sizeof expbuf); + expbuf.mem_offset = buf.m.offset; + if (ioctl (v4lfd, &VIDIOC-EXPBUF;, &expbuf) == -1) { + perror ("VIDIOC_EXPBUF"); + return -1; + } + + *dmafd = expbuf.fd; + + return 0; +} + + + + + Exporting a buffer using multi plane API. + +int buffer_export_mp(int v4lfd, &v4l2-buf-type; bt, int index, + int dmafd[], int n_planes) +{ + &v4l2-buffer; buf; + &v4l2-plane; planes[VIDEO_MAX_PLANES]; + int i; + + memset(&buf, 0, sizeof buf); + buf.type = bt; + buf.memory = V4L2_MEMORY_MMAP; + buf.index = index; + buf.m.planes = planes; + buf.length = n_planes; + memset(&planes, 0, sizeof planes); + + if (ioctl (v4lfd, &VIDIOC-QUERYBUF;, &buf) == -1) { + perror ("VIDIOC_QUERYBUF"); + return -1; + } + + for (i = 0; i < n_planes; ++i) { + &v4l2-exportbuffer; expbuf; + + memset(&expbuf, 0, sizeof expbuf); + expbuf.mem_offset = plane[i].m.offset; + if (ioctl (v4lfd, &VIDIOC-EXPBUF;, &expbuf) == -1) { + perror ("VIDIOC_EXPBUF"); + while (i) + close(dmafd[--i]); + return -1; + } + dmafd[i] = expbuf.fd; + } + + return 0; +} + + +
+
+ + + + struct <structname>v4l2_exportbuffer</structname> + + &cs-str; + + + __u32 + fd + The DMABUF file descriptor associated with a buffer. Set by + a driver. + + + __u32 + reserved0 + Reserved field for future use. Must be set to zero. + + + __u32 + mem_offset + Buffer memory offset as returned by +VIDIOC_QUERYBUF in &v4l2-buffer; ::m.offset + (for single-plane formats) or &v4l2-plane; +::m.offset (for multi-planar formats) + + + __u32 + flags + Flags for newly created file, currently only +O_CLOEXEC is supported, refer to manual of open syscall for more +details. + + + __u32 + reserved[12] + Reserved field for future use. Must be set to zero. + + + +
+ +
+ + + &return-value; + + + EINVAL + + A queue is not in MMAP mode or DMABUF exporting is not +supported or flag or mem_offset + fields are invalid. + + + + + +