From patchwork Tue Aug 14 15:34:47 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomasz Stanislawski X-Patchwork-Id: 1323511 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by patchwork1.kernel.org (Postfix) with ESMTP id 1225A3FC71 for ; Tue, 14 Aug 2012 21:24:59 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 17C929F5F3 for ; Tue, 14 Aug 2012 14:24:59 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mailout3.samsung.com (mailout3.samsung.com [203.254.224.33]) by gabe.freedesktop.org (Postfix) with ESMTP id 321AC9EB4A for ; Tue, 14 Aug 2012 08:37:25 -0700 (PDT) Received: from epcpsbgm2.samsung.com (mailout3.samsung.com [203.254.224.33]) by mailout3.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0M8R00IQW4Q4O320@mailout3.samsung.com> for dri-devel@lists.freedesktop.org; Wed, 15 Aug 2012 00:37:24 +0900 (KST) X-AuditID: cbfee61b-b7faf6d00000476a-c1-502a70b495f3 Received: from epmmp1.local.host ( [203.254.227.16]) by epcpsbgm2.samsung.com (EPCPMTA) with SMTP id 59.0A.18282.4B07A205; Wed, 15 Aug 2012 00:37:24 +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 dri-devel@lists.freedesktop.org; Wed, 15 Aug 2012 00:37:24 +0900 (KST) From: Tomasz Stanislawski To: linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org Subject: [PATCHv8 17/26] Documentation: media: description of DMABUF exporting in V4L2 Date: Tue, 14 Aug 2012 17:34:47 +0200 Message-id: <1344958496-9373-18-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+NgFnrIJMWRmVeSWpSXmKPExsVy+t9jAd0tBVoBBkf/C1pc+fqezYHR4373 caYAxigum5TUnMyy1CJ9uwSujKdvbApWeFV8mnKBuYHxjE0XIyeHhICJxK1/jcwQtpjEhXvr 2boYuTiEBBYxSlzoOM0EkhASWMckse+zAojNBtRwbMlnRhBbRMBB4vTdWcwgDcwCd5klFv1b xAKSEBaIkPj4aT47iM0ioCrxY8d8sA28Ah4Sr35Oh9omL/H0fh8biM0JFH+5qRtoKAfQMneJ hT/9JzDyLmBkWMUomlqQXFCclJ5rpFecmFtcmpeul5yfu4kR7PFn0jsYVzVYHGIU4GBU4uEt TNQMEGJNLCuuzD3EKMHBrCTCWxSkFSDEm5JYWZValB9fVJqTWnyIUZqDRUmc18T7q7+QQHpi SWp2ampBahFMlomDU6qBcU3hvyU1WSK/OnTkzplzmp98duBkGd9S9x+djZEvdklMMHYL2Zfy ZdKsMx+WakTFOT91iHE4vjGKpav7yJsJDY661eXf+Thd0zlZ3eIviboaFKuE9qffNn236bwf U9iNpEWccvumXHc+2cdVtDct9F1EXhLHEQZOc+E9Sq/9jhm6ixS/iq1TYinOSDTUYi4qTgQA VKj1lvQBAAA= X-TM-AS-MML: No Cc: t.stanislaws@samsung.com, pawel@osciak.com, linux-doc@vger.kernel.org, mchehab@redhat.com, daniel.vetter@ffwll.ch, subashrp@gmail.com, linaro-mm-sig@lists.linaro.org, kyungmin.park@samsung.com, laurent.pinchart@ideasonboard.com, s.nawrocki@samsung.com, airlied@redhat.com, remi@remlab.net, g.liakhovetski@gmx.de, m.szyprowski@samsung.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: dri-devel-bounces+patchwork-dri-devel=patchwork.kernel.org@lists.freedesktop.org Errors-To: dri-devel-bounces+patchwork-dri-devel=patchwork.kernel.org@lists.freedesktop.org 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 ff45330..802c1ab 100644 --- a/Documentation/DocBook/media/v4l/compat.xml +++ b/Documentation/DocBook/media/v4l/compat.xml @@ -2609,6 +2609,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 98253ee..c27e59b 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 0292ed1..874c085 100644 --- a/Documentation/DocBook/media/v4l/v4l2.xml +++ b/Documentation/DocBook/media/v4l/v4l2.xml @@ -568,6 +568,7 @@ and discussions on the V4L mailing list. &sub-overlay; &sub-prepare-buf; &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. + + + + + +