blob: 2e2fc3933aea73685ee473b9da2f154943850e4c [file] [log] [blame]
<refentry id="func-mmap">
<refentrytitle>V4L2 mmap()</refentrytitle>
<refpurpose>Map device memory into application address space</refpurpose>
#include &lt;unistd.h&gt;
#include &lt;sys/mman.h&gt;</funcsynopsisinfo>
<funcdef>void *<function>mmap</function></funcdef>
<paramdef>void *<parameter>start</parameter></paramdef>
<paramdef>size_t <parameter>length</parameter></paramdef>
<paramdef>int <parameter>prot</parameter></paramdef>
<paramdef>int <parameter>flags</parameter></paramdef>
<paramdef>int <parameter>fd</parameter></paramdef>
<paramdef>off_t <parameter>offset</parameter></paramdef>
<para>Map the buffer to this address in the
application's address space. When the <constant>MAP_FIXED</constant>
flag is specified, <parameter>start</parameter> must be a multiple of the
pagesize and mmap will fail when the specified address
cannot be used. Use of this option is discouraged; applications should
just specify a <constant>NULL</constant> pointer here.</para>
<para>Length of the memory area to map. This must be the
same value as returned by the driver in the &v4l2-buffer;
<structfield>length</structfield> field.</para>
<para>The <parameter>prot</parameter> argument describes the
desired memory protection. Regardless of the device type and the
direction of data exchange it should be set to
<constant>PROT_READ</constant> | <constant>PROT_WRITE</constant>,
permitting read and write access to image buffers. Drivers should
support at least this combination of flags. Note the Linux
<filename>video-buf</filename> kernel module, which is used by the
bttv, saa7134, saa7146, cx88 and vivi driver supports only
<constant>PROT_READ</constant> | <constant>PROT_WRITE</constant>. When
the driver does not support the desired protection the
<function>mmap()</function> function fails.</para>
<para>Note device memory accesses (&eg; the memory on a
graphics card with video capturing hardware) may incur a performance
penalty compared to main memory accesses, or reads may be
significantly slower than writes or vice versa. Other I/O methods may
be more efficient in this case.</para>
<para>The <parameter>flags</parameter> parameter
specifies the type of the mapped object, mapping options and whether
modifications made to the mapped copy of the page are private to the
process or are to be shared with other references.</para>
<para><constant>MAP_FIXED</constant> requests that the
driver selects no other address than the one specified. If the
specified address cannot be used, <function>mmap()</function> will fail. If
<constant>MAP_FIXED</constant> is specified,
<parameter>start</parameter> must be a multiple of the pagesize. Use
of this option is discouraged.</para>
<para>One of the <constant>MAP_SHARED</constant> or
<constant>MAP_PRIVATE</constant> flags must be set.
<constant>MAP_SHARED</constant> allows applications to share the
mapped memory with other (&eg; child-) processes. Note the Linux
<filename>video-buf</filename> module which is used by the bttv,
saa7134, saa7146, cx88 and vivi driver supports only
<constant>MAP_SHARED</constant>. <constant>MAP_PRIVATE</constant>
requests copy-on-write semantics. V4L2 applications should not set the
<constant>MAP_PRIVATE</constant>, <constant>MAP_DENYWRITE</constant>,
<constant>MAP_EXECUTABLE</constant> or <constant>MAP_ANON</constant>
<para>Offset of the buffer in device memory. This must be the
same value as returned by the driver in the &v4l2-buffer;
<structfield>m</structfield> union <structfield>offset</structfield> field.</para>
<para>The <function>mmap()</function> function asks to map
<parameter>length</parameter> bytes starting at
<parameter>offset</parameter> in the memory of the device specified by
<parameter>fd</parameter> into the application address space,
preferably at address <parameter>start</parameter>. This latter
address is a hint only, and is usually specified as 0.</para>
<para>Suitable length and offset parameters are queried with the
&VIDIOC-QUERYBUF; ioctl. Buffers must be allocated with the
&VIDIOC-REQBUFS; ioctl before they can be queried.</para>
<para>To unmap buffers the &func-munmap; function is used.</para>
<title>Return Value</title>
<para>On success <function>mmap()</function> returns a pointer to
the mapped buffer. On error <constant>MAP_FAILED</constant> (-1) is
returned, and the <varname>errno</varname> variable is set
appropriately. Possible error codes are:</para>
<para><parameter>fd</parameter> is not a valid file
<para><parameter>fd</parameter> is
not open for reading and writing.</para>
<para>The <parameter>start</parameter> or
<parameter>length</parameter> or <parameter>offset</parameter> are not
suitable. (E.&nbsp;g. they are too large, or not aligned on a
<constant>PAGESIZE</constant> boundary.)</para>
<para>The <parameter>flags</parameter> or
<parameter>prot</parameter> value is not supported.</para>
<para>No buffers have been allocated with the
&VIDIOC-REQBUFS; ioctl.</para>
<para>Not enough physical or virtual memory was available to
complete the request.</para>
Local Variables:
mode: sgml
sgml-parent-document: "v4l2.sgml"
indent-tabs-mode: nil