aboutsummaryrefslogtreecommitdiffstats
path: root/Documentation
diff options
context:
space:
mode:
authorTomasz Stanislawski <t.stanislaws@samsung.com>2012-06-14 09:37:36 -0400
committerMauro Carvalho Chehab <mchehab@redhat.com>2012-11-25 14:11:04 -0500
commit4b9c1cb641c466cd3b366132017da3c8ab9d540c (patch)
tree2ffa0298d99b5f0f1ed3e2101ad5d963d5a68542 /Documentation
parent051c7788bcb92f2e98ef86e86651e0420765b121 (diff)
[media] Documentation: media: description of DMABUF importing in V4L2
This patch adds description and usage examples for importing DMABUF file descriptor in V4L2. Signed-off-by: Tomasz Stanislawski <t.stanislaws@samsung.com> Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com> Acked-by: Hans Verkuil <hans.verkuil@cisco.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'Documentation')
-rw-r--r--Documentation/DocBook/media/v4l/compat.xml4
-rw-r--r--Documentation/DocBook/media/v4l/io.xml181
-rw-r--r--Documentation/DocBook/media/v4l/vidioc-create-bufs.xml16
-rw-r--r--Documentation/DocBook/media/v4l/vidioc-qbuf.xml17
-rw-r--r--Documentation/DocBook/media/v4l/vidioc-reqbufs.xml47
5 files changed, 235 insertions, 30 deletions
diff --git a/Documentation/DocBook/media/v4l/compat.xml b/Documentation/DocBook/media/v4l/compat.xml
index 4fdf6b562d1c..50eb63024eb7 100644
--- a/Documentation/DocBook/media/v4l/compat.xml
+++ b/Documentation/DocBook/media/v4l/compat.xml
@@ -2586,6 +2586,10 @@ ioctls.</para>
2586 <para>Vendor and device specific media bus pixel formats. 2586 <para>Vendor and device specific media bus pixel formats.
2587 <xref linkend="v4l2-mbus-vendor-spec-fmts" />.</para> 2587 <xref linkend="v4l2-mbus-vendor-spec-fmts" />.</para>
2588 </listitem> 2588 </listitem>
2589 <listitem>
2590 <para>Importing DMABUF file descriptors as a new IO method described
2591 in <xref linkend="dmabuf" />.</para>
2592 </listitem>
2589 </itemizedlist> 2593 </itemizedlist>
2590 </section> 2594 </section>
2591 2595
diff --git a/Documentation/DocBook/media/v4l/io.xml b/Documentation/DocBook/media/v4l/io.xml
index 7e2f3d7d78ad..be0fad7e1209 100644
--- a/Documentation/DocBook/media/v4l/io.xml
+++ b/Documentation/DocBook/media/v4l/io.xml
@@ -331,7 +331,7 @@ application until one or more buffers can be dequeued. By default
331outgoing queue. When the <constant>O_NONBLOCK</constant> flag was 331outgoing queue. When the <constant>O_NONBLOCK</constant> flag was
332given to the &func-open; function, <constant>VIDIOC_DQBUF</constant> 332given to the &func-open; function, <constant>VIDIOC_DQBUF</constant>
333returns immediately with an &EAGAIN; when no buffer is available. The 333returns immediately with an &EAGAIN; when no buffer is available. The
334&func-select; or &func-poll; function are always available.</para> 334&func-select; or &func-poll; functions are always available.</para>
335 335
336 <para>To start and stop capturing or output applications call the 336 <para>To start and stop capturing or output applications call the
337&VIDIOC-STREAMON; and &VIDIOC-STREAMOFF; ioctl. Note 337&VIDIOC-STREAMON; and &VIDIOC-STREAMOFF; ioctl. Note
@@ -472,6 +472,162 @@ rest should be evident.</para>
472 </footnote></para> 472 </footnote></para>
473 </section> 473 </section>
474 474
475 <section id="dmabuf">
476 <title>Streaming I/O (DMA buffer importing)</title>
477
478 <note>
479 <title>Experimental</title>
480 <para>This is an <link linkend="experimental"> experimental </link>
481 interface and may change in the future.</para>
482 </note>
483
484<para>The DMABUF framework provides a generic method for sharing buffers
485between multiple devices. Device drivers that support DMABUF can export a DMA
486buffer to userspace as a file descriptor (known as the exporter role), import a
487DMA buffer from userspace using a file descriptor previously exported for a
488different or the same device (known as the importer role), or both. This
489section describes the DMABUF importer role API in V4L2.</para>
490
491<para>Input and output devices support the streaming I/O method when the
492<constant>V4L2_CAP_STREAMING</constant> flag in the
493<structfield>capabilities</structfield> field of &v4l2-capability; returned by
494the &VIDIOC-QUERYCAP; ioctl is set. Whether importing DMA buffers through
495DMABUF file descriptors is supported is determined by calling the
496&VIDIOC-REQBUFS; ioctl with the memory type set to
497<constant>V4L2_MEMORY_DMABUF</constant>.</para>
498
499 <para>This I/O method is dedicated to sharing DMA buffers between different
500devices, which may be V4L devices or other video-related devices (e.g. DRM).
501Buffers (planes) are allocated by a driver on behalf of an application. Next,
502these buffers are exported to the application as file descriptors using an API
503which is specific for an allocator driver. Only such file descriptor are
504exchanged. The descriptors and meta-information are passed in &v4l2-buffer; (or
505in &v4l2-plane; in the multi-planar API case). The driver must be switched
506into DMABUF I/O mode by calling the &VIDIOC-REQBUFS; with the desired buffer
507type.</para>
508
509 <example>
510 <title>Initiating streaming I/O with DMABUF file descriptors</title>
511
512 <programlisting>
513&v4l2-requestbuffers; reqbuf;
514
515memset(&amp;reqbuf, 0, sizeof (reqbuf));
516reqbuf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
517reqbuf.memory = V4L2_MEMORY_DMABUF;
518reqbuf.count = 1;
519
520if (ioctl(fd, &VIDIOC-REQBUFS;, &amp;reqbuf) == -1) {
521 if (errno == EINVAL)
522 printf("Video capturing or DMABUF streaming is not supported\n");
523 else
524 perror("VIDIOC_REQBUFS");
525
526 exit(EXIT_FAILURE);
527}
528 </programlisting>
529 </example>
530
531 <para>The buffer (plane) file descriptor is passed on the fly with the
532&VIDIOC-QBUF; ioctl. In case of multiplanar buffers, every plane can be
533associated with a different DMABUF descriptor. Although buffers are commonly
534cycled, applications can pass a different DMABUF descriptor at each
535<constant>VIDIOC_QBUF</constant> call.</para>
536
537 <example>
538 <title>Queueing DMABUF using single plane API</title>
539
540 <programlisting>
541int buffer_queue(int v4lfd, int index, int dmafd)
542{
543 &v4l2-buffer; buf;
544
545 memset(&amp;buf, 0, sizeof buf);
546 buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
547 buf.memory = V4L2_MEMORY_DMABUF;
548 buf.index = index;
549 buf.m.fd = dmafd;
550
551 if (ioctl(v4lfd, &VIDIOC-QBUF;, &amp;buf) == -1) {
552 perror("VIDIOC_QBUF");
553 return -1;
554 }
555
556 return 0;
557}
558 </programlisting>
559 </example>
560
561 <example>
562 <title>Queueing DMABUF using multi plane API</title>
563
564 <programlisting>
565int buffer_queue_mp(int v4lfd, int index, int dmafd[], int n_planes)
566{
567 &v4l2-buffer; buf;
568 &v4l2-plane; planes[VIDEO_MAX_PLANES];
569 int i;
570
571 memset(&amp;buf, 0, sizeof buf);
572 buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
573 buf.memory = V4L2_MEMORY_DMABUF;
574 buf.index = index;
575 buf.m.planes = planes;
576 buf.length = n_planes;
577
578 memset(&amp;planes, 0, sizeof planes);
579
580 for (i = 0; i &lt; n_planes; ++i)
581 buf.m.planes[i].m.fd = dmafd[i];
582
583 if (ioctl(v4lfd, &VIDIOC-QBUF;, &amp;buf) == -1) {
584 perror("VIDIOC_QBUF");
585 return -1;
586 }
587
588 return 0;
589}
590 </programlisting>
591 </example>
592
593 <para>Captured or displayed buffers are dequeued with the
594&VIDIOC-DQBUF; ioctl. The driver can unlock the buffer at any
595time between the completion of the DMA and this ioctl. The memory is
596also unlocked when &VIDIOC-STREAMOFF; is called, &VIDIOC-REQBUFS;, or
597when the device is closed.</para>
598
599 <para>For capturing applications it is customary to enqueue a
600number of empty buffers, to start capturing and enter the read loop.
601Here the application waits until a filled buffer can be dequeued, and
602re-enqueues the buffer when the data is no longer needed. Output
603applications fill and enqueue buffers, when enough buffers are stacked
604up output is started. In the write loop, when the application
605runs out of free buffers it must wait until an empty buffer can be
606dequeued and reused. Two methods exist to suspend execution of the
607application until one or more buffers can be dequeued. By default
608<constant>VIDIOC_DQBUF</constant> blocks when no buffer is in the
609outgoing queue. When the <constant>O_NONBLOCK</constant> flag was
610given to the &func-open; function, <constant>VIDIOC_DQBUF</constant>
611returns immediately with an &EAGAIN; when no buffer is available. The
612&func-select; and &func-poll; functions are always available.</para>
613
614 <para>To start and stop capturing or displaying applications call the
615&VIDIOC-STREAMON; and &VIDIOC-STREAMOFF; ioctls. Note that
616<constant>VIDIOC_STREAMOFF</constant> removes all buffers from both queues and
617unlocks all buffers as a side effect. Since there is no notion of doing
618anything "now" on a multitasking system, if an application needs to synchronize
619with another event it should examine the &v4l2-buffer;
620<structfield>timestamp</structfield> of captured buffers, or set the field
621before enqueuing buffers for output.</para>
622
623 <para>Drivers implementing DMABUF importing I/O must support the
624<constant>VIDIOC_REQBUFS</constant>, <constant>VIDIOC_QBUF</constant>,
625<constant>VIDIOC_DQBUF</constant>, <constant>VIDIOC_STREAMON</constant> and
626<constant>VIDIOC_STREAMOFF</constant> ioctls, and the
627<function>select()</function> and <function>poll()</function> functions.</para>
628
629 </section>
630
475 <section id="async"> 631 <section id="async">
476 <title>Asynchronous I/O</title> 632 <title>Asynchronous I/O</title>
477 633
@@ -673,6 +829,14 @@ memory, set by the application. See <xref linkend="userp" /> for details.
673 <structname>v4l2_buffer</structname> structure.</entry> 829 <structname>v4l2_buffer</structname> structure.</entry>
674 </row> 830 </row>
675 <row> 831 <row>
832 <entry></entry>
833 <entry>int</entry>
834 <entry><structfield>fd</structfield></entry>
835 <entry>For the single-plane API and when
836<structfield>memory</structfield> is <constant>V4L2_MEMORY_DMABUF</constant> this
837is the file descriptor associated with a DMABUF buffer.</entry>
838 </row>
839 <row>
676 <entry>__u32</entry> 840 <entry>__u32</entry>
677 <entry><structfield>length</structfield></entry> 841 <entry><structfield>length</structfield></entry>
678 <entry></entry> 842 <entry></entry>
@@ -744,6 +908,15 @@ should set this to 0.</entry>
744 </entry> 908 </entry>
745 </row> 909 </row>
746 <row> 910 <row>
911 <entry></entry>
912 <entry>int</entry>
913 <entry><structfield>fd</structfield></entry>
914 <entry>When the memory type in the containing &v4l2-buffer; is
915 <constant>V4L2_MEMORY_DMABUF</constant>, this is a file
916 descriptor associated with a DMABUF buffer, similar to the
917 <structfield>fd</structfield> field in &v4l2-buffer;.</entry>
918 </row>
919 <row>
747 <entry>__u32</entry> 920 <entry>__u32</entry>
748 <entry><structfield>data_offset</structfield></entry> 921 <entry><structfield>data_offset</structfield></entry>
749 <entry></entry> 922 <entry></entry>
@@ -964,6 +1137,12 @@ pointer</link> I/O.</entry>
964 <entry>3</entry> 1137 <entry>3</entry>
965 <entry>[to do]</entry> 1138 <entry>[to do]</entry>
966 </row> 1139 </row>
1140 <row>
1141 <entry><constant>V4L2_MEMORY_DMABUF</constant></entry>
1142 <entry>4</entry>
1143 <entry>The buffer is used for <link linkend="dmabuf">DMA shared
1144buffer</link> I/O.</entry>
1145 </row>
967 </tbody> 1146 </tbody>
968 </tgroup> 1147 </tgroup>
969 </table> 1148 </table>
diff --git a/Documentation/DocBook/media/v4l/vidioc-create-bufs.xml b/Documentation/DocBook/media/v4l/vidioc-create-bufs.xml
index a8cda1acacd9..cd9943672434 100644
--- a/Documentation/DocBook/media/v4l/vidioc-create-bufs.xml
+++ b/Documentation/DocBook/media/v4l/vidioc-create-bufs.xml
@@ -6,7 +6,8 @@
6 6
7 <refnamediv> 7 <refnamediv>
8 <refname>VIDIOC_CREATE_BUFS</refname> 8 <refname>VIDIOC_CREATE_BUFS</refname>
9 <refpurpose>Create buffers for Memory Mapped or User Pointer I/O</refpurpose> 9 <refpurpose>Create buffers for Memory Mapped or User Pointer or DMA Buffer
10 I/O</refpurpose>
10 </refnamediv> 11 </refnamediv>
11 12
12 <refsynopsisdiv> 13 <refsynopsisdiv>
@@ -55,11 +56,11 @@
55 </note> 56 </note>
56 57
57 <para>This ioctl is used to create buffers for <link linkend="mmap">memory 58 <para>This ioctl is used to create buffers for <link linkend="mmap">memory
58mapped</link> or <link linkend="userp">user pointer</link> 59mapped</link> or <link linkend="userp">user pointer</link> or <link
59I/O. It can be used as an alternative or in addition to the 60linkend="dmabuf">DMA buffer</link> I/O. It can be used as an alternative or in
60<constant>VIDIOC_REQBUFS</constant> ioctl, when a tighter control over buffers 61addition to the <constant>VIDIOC_REQBUFS</constant> ioctl, when a tighter
61is required. This ioctl can be called multiple times to create buffers of 62control over buffers is required. This ioctl can be called multiple times to
62different sizes.</para> 63create buffers of different sizes.</para>
63 64
64 <para>To allocate device buffers applications initialize relevant fields of 65 <para>To allocate device buffers applications initialize relevant fields of
65the <structname>v4l2_create_buffers</structname> structure. They set the 66the <structname>v4l2_create_buffers</structname> structure. They set the
@@ -109,7 +110,8 @@ information.</para>
109 <entry>__u32</entry> 110 <entry>__u32</entry>
110 <entry><structfield>memory</structfield></entry> 111 <entry><structfield>memory</structfield></entry>
111 <entry>Applications set this field to 112 <entry>Applications set this field to
112<constant>V4L2_MEMORY_MMAP</constant> or 113<constant>V4L2_MEMORY_MMAP</constant>,
114<constant>V4L2_MEMORY_DMABUF</constant> or
113<constant>V4L2_MEMORY_USERPTR</constant>. See <xref linkend="v4l2-memory" 115<constant>V4L2_MEMORY_USERPTR</constant>. See <xref linkend="v4l2-memory"
114/></entry> 116/></entry>
115 </row> 117 </row>
diff --git a/Documentation/DocBook/media/v4l/vidioc-qbuf.xml b/Documentation/DocBook/media/v4l/vidioc-qbuf.xml
index 2d37abefce13..3504a7f2f382 100644
--- a/Documentation/DocBook/media/v4l/vidioc-qbuf.xml
+++ b/Documentation/DocBook/media/v4l/vidioc-qbuf.xml
@@ -109,6 +109,23 @@ they cannot be swapped out to disk. Buffers remain locked until
109dequeued, until the &VIDIOC-STREAMOFF; or &VIDIOC-REQBUFS; ioctl is 109dequeued, until the &VIDIOC-STREAMOFF; or &VIDIOC-REQBUFS; ioctl is
110called, or until the device is closed.</para> 110called, or until the device is closed.</para>
111 111
112 <para>To enqueue a <link linkend="dmabuf">DMABUF</link> buffer applications
113set the <structfield>memory</structfield> field to
114<constant>V4L2_MEMORY_DMABUF</constant> and the <structfield>m.fd</structfield>
115field to a file descriptor associated with a DMABUF buffer. When the
116multi-planar API is used the <structfield>m.fd</structfield> fields of the
117passed array of &v4l2-plane; have to be used instead. When
118<constant>VIDIOC_QBUF</constant> is called with a pointer to this structure the
119driver sets the <constant>V4L2_BUF_FLAG_QUEUED</constant> flag and clears the
120<constant>V4L2_BUF_FLAG_MAPPED</constant> and
121<constant>V4L2_BUF_FLAG_DONE</constant> flags in the
122<structfield>flags</structfield> field, or it returns an error code. This
123ioctl locks the buffer. Locking a buffer means passing it to a driver for a
124hardware access (usually DMA). If an application accesses (reads/writes) a
125locked buffer then the result is undefined. Buffers remain locked until
126dequeued, until the &VIDIOC-STREAMOFF; or &VIDIOC-REQBUFS; ioctl is called, or
127until the device is closed.</para>
128
112 <para>Applications call the <constant>VIDIOC_DQBUF</constant> 129 <para>Applications call the <constant>VIDIOC_DQBUF</constant>
113ioctl to dequeue a filled (capturing) or displayed (output) buffer 130ioctl to dequeue a filled (capturing) or displayed (output) buffer
114from the driver's outgoing queue. They just set the 131from the driver's outgoing queue. They just set the
diff --git a/Documentation/DocBook/media/v4l/vidioc-reqbufs.xml b/Documentation/DocBook/media/v4l/vidioc-reqbufs.xml
index 2b50ef2007f3..78a06a9a5ece 100644
--- a/Documentation/DocBook/media/v4l/vidioc-reqbufs.xml
+++ b/Documentation/DocBook/media/v4l/vidioc-reqbufs.xml
@@ -48,28 +48,30 @@
48 <refsect1> 48 <refsect1>
49 <title>Description</title> 49 <title>Description</title>
50 50
51 <para>This ioctl is used to initiate <link linkend="mmap">memory 51<para>This ioctl is used to initiate <link linkend="mmap">memory mapped</link>,
52mapped</link> or <link linkend="userp">user pointer</link> 52<link linkend="userp">user pointer</link> or <link
53I/O. Memory mapped buffers are located in device memory and must be 53linkend="dmabuf">DMABUF</link> based I/O. Memory mapped buffers are located in
54allocated with this ioctl before they can be mapped into the 54device memory and must be allocated with this ioctl before they can be mapped
55application's address space. User buffers are allocated by 55into the application's address space. User buffers are allocated by
56applications themselves, and this ioctl is merely used to switch the 56applications themselves, and this ioctl is merely used to switch the driver
57driver into user pointer I/O mode and to setup some internal structures.</para> 57into user pointer I/O mode and to setup some internal structures.
58Similarly, DMABUF buffers are allocated by applications through a device
59driver, and this ioctl only configures the driver into DMABUF I/O mode without
60performing any direct allocation.</para>
58 61
59 <para>To allocate device buffers applications initialize all 62 <para>To allocate device buffers applications initialize all fields of the
60fields of the <structname>v4l2_requestbuffers</structname> structure. 63<structname>v4l2_requestbuffers</structname> structure. They set the
61They set the <structfield>type</structfield> field to the respective 64<structfield>type</structfield> field to the respective stream or buffer type,
62stream or buffer type, the <structfield>count</structfield> field to 65the <structfield>count</structfield> field to the desired number of buffers,
63the desired number of buffers, <structfield>memory</structfield> 66<structfield>memory</structfield> must be set to the requested I/O method and
64must be set to the requested I/O method and the <structfield>reserved</structfield> array 67the <structfield>reserved</structfield> array must be zeroed. When the ioctl is
65must be zeroed. When the ioctl 68called with a pointer to this structure the driver will attempt to allocate the
66is called with a pointer to this structure the driver will attempt to allocate 69requested number of buffers and it stores the actual number allocated in the
67the requested number of buffers and it stores the actual number 70<structfield>count</structfield> field. It can be smaller than the number
68allocated in the <structfield>count</structfield> field. It can be 71requested, even zero, when the driver runs out of free memory. A larger number
69smaller than the number requested, even zero, when the driver runs out 72is also possible when the driver requires more buffers to function correctly.
70of free memory. A larger number is also possible when the driver requires 73For example video output requires at least two buffers, one displayed and one
71more buffers to function correctly. For example video output requires at least two buffers, 74filled by the application.</para>
72one displayed and one filled by the application.</para>
73 <para>When the I/O method is not supported the ioctl 75 <para>When the I/O method is not supported the ioctl
74returns an &EINVAL;.</para> 76returns an &EINVAL;.</para>
75 77
@@ -102,7 +104,8 @@ as the &v4l2-format; <structfield>type</structfield> field. See <xref
102 <entry>__u32</entry> 104 <entry>__u32</entry>
103 <entry><structfield>memory</structfield></entry> 105 <entry><structfield>memory</structfield></entry>
104 <entry>Applications set this field to 106 <entry>Applications set this field to
105<constant>V4L2_MEMORY_MMAP</constant> or 107<constant>V4L2_MEMORY_MMAP</constant>,
108<constant>V4L2_MEMORY_DMABUF</constant> or
106<constant>V4L2_MEMORY_USERPTR</constant>. See <xref linkend="v4l2-memory" 109<constant>V4L2_MEMORY_USERPTR</constant>. See <xref linkend="v4l2-memory"
107/>.</entry> 110/>.</entry>
108 </row> 111 </row>