1<html><head><meta http-equiv="Content-Type" content="text/html; charset=ANSI_X3.4-1968"><title>V4L2 mmap()</title><meta name="generator" content="DocBook XSL Stylesheets V1.78.1"><link rel="home" href="index.html" title="LINUX MEDIA INFRASTRUCTURE API"><link rel="up" href="user-func.html" title="Appendix&#160;A.&#160;Function Reference"><link rel="prev" href="vidioc-subscribe-event.html" title="ioctl VIDIOC_SUBSCRIBE_EVENT, VIDIOC_UNSUBSCRIBE_EVENT"><link rel="next" href="func-munmap.html" title="V4L2 munmap()"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">V4L2 mmap()</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="vidioc-subscribe-event.html">Prev</a>&#160;</td><th width="60%" align="center">Appendix&#160;A.&#160;Function Reference</th><td width="20%" align="right">&#160;<a accesskey="n" href="func-munmap.html">Next</a></td></tr></table><hr></div><div class="refentry"><a name="func-mmap"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>v4l2-mmap &#8212; Map device memory into application address space</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><div class="funcsynopsis"><pre class="funcsynopsisinfo">
2#include &lt;unistd.h&gt;
3#include &lt;sys/mman.h&gt;</pre><table border="0" class="funcprototype-table" summary="Function synopsis" style="cellspacing: 0; cellpadding: 0;"><tr><td><code class="funcdef">void *<b class="fsfunc">mmap</b>(</code></td><td>void *<var class="pdparam">start</var>, </td></tr><tr><td>&#160;</td><td>size_t <var class="pdparam">length</var>, </td></tr><tr><td>&#160;</td><td>int <var class="pdparam">prot</var>, </td></tr><tr><td>&#160;</td><td>int <var class="pdparam">flags</var>, </td></tr><tr><td>&#160;</td><td>int <var class="pdparam">fd</var>, </td></tr><tr><td>&#160;</td><td>off_t <var class="pdparam">offset</var><code>)</code>;</td></tr></table><div class="funcprototype-spacer">&#160;</div></div></div><div class="refsect1"><a name="idp1116945684"></a><h2>Arguments</h2><div class="variablelist"><dl class="variablelist"><dt><span class="term"><em class="parameter"><code>start</code></em></span></dt><dd><p>Map the buffer to this address in the
4application's address space. When the <code class="constant">MAP_FIXED</code>
5flag is specified, <em class="parameter"><code>start</code></em> must be a multiple of the
6pagesize and mmap will fail when the specified address
7cannot be used. Use of this option is discouraged; applications should
8just specify a <code class="constant">NULL</code> pointer here.</p></dd><dt><span class="term"><em class="parameter"><code>length</code></em></span></dt><dd><p>Length of the memory area to map. This must be the
9same value as returned by the driver in the struct&#160;<a class="link" href="buffer.html#v4l2-buffer" title="Table&#160;3.1.&#160;struct v4l2_buffer">v4l2_buffer</a>
10<em class="structfield"><code>length</code></em> field for the
11single-planar API, and the same value as returned by the driver
12in the struct&#160;<a class="link" href="buffer.html#v4l2-plane" title="Table&#160;3.2.&#160;struct v4l2_plane">v4l2_plane</a> <em class="structfield"><code>length</code></em> field for the
13multi-planar API.</p></dd><dt><span class="term"><em class="parameter"><code>prot</code></em></span></dt><dd><p>The <em class="parameter"><code>prot</code></em> argument describes the
14desired memory protection. Regardless of the device type and the
15direction of data exchange it should be set to
16<code class="constant">PROT_READ</code> | <code class="constant">PROT_WRITE</code>,
17permitting read and write access to image buffers. Drivers should
18support at least this combination of flags. Note the Linux
19<code class="filename">video-buf</code> kernel module, which is used by the
20bttv, saa7134, saa7146, cx88 and vivi driver supports only
21<code class="constant">PROT_READ</code> | <code class="constant">PROT_WRITE</code>. When
22the driver does not support the desired protection the
23<code class="function">mmap()</code> function fails.</p><p>Note device memory accesses (e.&#160;g. the memory on a
24graphics card with video capturing hardware) may incur a performance
25penalty compared to main memory accesses, or reads may be
26significantly slower than writes or vice versa. Other I/O methods may
27be more efficient in this case.</p></dd><dt><span class="term"><em class="parameter"><code>flags</code></em></span></dt><dd><p>The <em class="parameter"><code>flags</code></em> parameter
28specifies the type of the mapped object, mapping options and whether
29modifications made to the mapped copy of the page are private to the
30process or are to be shared with other references.</p><p><code class="constant">MAP_FIXED</code> requests that the
31driver selects no other address than the one specified. If the
32specified address cannot be used, <code class="function">mmap()</code> will fail. If
33<code class="constant">MAP_FIXED</code> is specified,
34<em class="parameter"><code>start</code></em> must be a multiple of the pagesize. Use
35of this option is discouraged.</p><p>One of the <code class="constant">MAP_SHARED</code> or
36<code class="constant">MAP_PRIVATE</code> flags must be set.
37<code class="constant">MAP_SHARED</code> allows applications to share the
38mapped memory with other (e.&#160;g. child-) processes. Note the Linux
39<code class="filename">video-buf</code> module which is used by the bttv,
40saa7134, saa7146, cx88 and vivi driver supports only
41<code class="constant">MAP_SHARED</code>. <code class="constant">MAP_PRIVATE</code>
42requests copy-on-write semantics. V4L2 applications should not set the
43<code class="constant">MAP_PRIVATE</code>, <code class="constant">MAP_DENYWRITE</code>,
44<code class="constant">MAP_EXECUTABLE</code> or <code class="constant">MAP_ANON</code>
45flag.</p></dd><dt><span class="term"><em class="parameter"><code>fd</code></em></span></dt><dd><p>File descriptor returned by <a class="link" href="func-open.html" title="V4L2 open()"><code class="function">open()</code></a>.</p></dd><dt><span class="term"><em class="parameter"><code>offset</code></em></span></dt><dd><p>Offset of the buffer in device memory. This must be the
46same value as returned by the driver in the struct&#160;<a class="link" href="buffer.html#v4l2-buffer" title="Table&#160;3.1.&#160;struct v4l2_buffer">v4l2_buffer</a>
47<em class="structfield"><code>m</code></em> union <em class="structfield"><code>offset</code></em> field for
48the single-planar API, and the same value as returned by the driver
49in the struct&#160;<a class="link" href="buffer.html#v4l2-plane" title="Table&#160;3.2.&#160;struct v4l2_plane">v4l2_plane</a> <em class="structfield"><code>m</code></em> union
50<em class="structfield"><code>mem_offset</code></em> field for the multi-planar API.</p></dd></dl></div></div><div class="refsect1"><a name="idp1116964676"></a><h2>Description</h2><p>The <code class="function">mmap()</code> function asks to map
51<em class="parameter"><code>length</code></em> bytes starting at
52<em class="parameter"><code>offset</code></em> in the memory of the device specified by
53<em class="parameter"><code>fd</code></em> into the application address space,
54preferably at address <em class="parameter"><code>start</code></em>. This latter
55address is a hint only, and is usually specified as 0.</p><p>Suitable length and offset parameters are queried with the
56<a class="link" href="vidioc-querybuf.html" title="ioctl VIDIOC_QUERYBUF"><code class="constant">VIDIOC_QUERYBUF</code></a> ioctl. Buffers must be allocated with the
57<a class="link" href="vidioc-reqbufs.html" title="ioctl VIDIOC_REQBUFS"><code class="constant">VIDIOC_REQBUFS</code></a> ioctl before they can be queried.</p><p>To unmap buffers the <a class="link" href="func-munmap.html" title="V4L2 munmap()"><code class="function">munmap()</code></a> function is used.</p></div><div class="refsect1"><a name="idp1116969220"></a><h2>Return Value</h2><p>On success <code class="function">mmap()</code> returns a pointer to
58the mapped buffer. On error <code class="constant">MAP_FAILED</code> (-1) is
59returned, and the <code class="varname">errno</code> variable is set
60appropriately. Possible error codes are:</p><div class="variablelist"><dl class="variablelist"><dt><span class="term"><span class="errorcode">EBADF</span></span></dt><dd><p><em class="parameter"><code>fd</code></em> is not a valid file
61descriptor.</p></dd><dt><span class="term"><span class="errorcode">EACCES</span></span></dt><dd><p><em class="parameter"><code>fd</code></em> is
62not open for reading and writing.</p></dd><dt><span class="term"><span class="errorcode">EINVAL</span></span></dt><dd><p>The <em class="parameter"><code>start</code></em> or
63<em class="parameter"><code>length</code></em> or <em class="parameter"><code>offset</code></em> are not
64suitable. (E.&#160;g. they are too large, or not aligned on a
65<code class="constant">PAGESIZE</code> boundary.)</p><p>The <em class="parameter"><code>flags</code></em> or
66<em class="parameter"><code>prot</code></em> value is not supported.</p><p>No buffers have been allocated with the
67<a class="link" href="vidioc-reqbufs.html" title="ioctl VIDIOC_REQBUFS"><code class="constant">VIDIOC_REQBUFS</code></a> ioctl.</p></dd><dt><span class="term"><span class="errorcode">ENOMEM</span></span></dt><dd><p>Not enough physical or virtual memory was available to
68complete the request.</p></dd></dl></div></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="vidioc-subscribe-event.html">Prev</a>&#160;</td><td width="20%" align="center"><a accesskey="u" href="user-func.html">Up</a></td><td width="40%" align="right">&#160;<a accesskey="n" href="func-munmap.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">ioctl VIDIOC_SUBSCRIBE_EVENT, VIDIOC_UNSUBSCRIBE_EVENT&#160;</td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top">&#160;V4L2 munmap()</td></tr></table></div></body></html>
69