1
<refentry id="func-mmap">
3
<refentrytitle>V4L2 mmap()</refentrytitle>
8
<refname>v4l2-mmap</refname>
9
<refpurpose>Map device memory into application address space</refpurpose>
15
#include <unistd.h>
16
#include <sys/mman.h></funcsynopsisinfo>
18
<funcdef>void *<function>mmap</function></funcdef>
19
<paramdef>void *<parameter>start</parameter></paramdef>
20
<paramdef>size_t <parameter>length</parameter></paramdef>
21
<paramdef>int <parameter>prot</parameter></paramdef>
22
<paramdef>int <parameter>flags</parameter></paramdef>
23
<paramdef>int <parameter>fd</parameter></paramdef>
24
<paramdef>off_t <parameter>offset</parameter></paramdef>
30
<title>Arguments</title>
33
<term><parameter>start</parameter></term>
35
<para>Map the buffer to this address in the
36
application's address space. When the <constant>MAP_FIXED</constant>
37
flag is specified, <parameter>start</parameter> must be a multiple of the
38
pagesize and mmap will fail when the specified address
39
cannot be used. Use of this option is discouraged; applications should
40
just specify a <constant>NULL</constant> pointer here.</para>
44
<term><parameter>length</parameter></term>
46
<para>Length of the memory area to map. This must be the
47
same value as returned by the driver in the &v4l2-buffer;
48
<structfield>length</structfield> field for the
49
single-planar API, and the same value as returned by the driver
50
in the &v4l2-plane; <structfield>length</structfield> field for the
51
multi-planar API.</para>
55
<term><parameter>prot</parameter></term>
57
<para>The <parameter>prot</parameter> argument describes the
58
desired memory protection. Regardless of the device type and the
59
direction of data exchange it should be set to
60
<constant>PROT_READ</constant> | <constant>PROT_WRITE</constant>,
61
permitting read and write access to image buffers. Drivers should
62
support at least this combination of flags. Note the Linux
63
<filename>video-buf</filename> kernel module, which is used by the
64
bttv, saa7134, saa7146, cx88 and vivi driver supports only
65
<constant>PROT_READ</constant> | <constant>PROT_WRITE</constant>. When
66
the driver does not support the desired protection the
67
<function>mmap()</function> function fails.</para>
68
<para>Note device memory accesses (⪚ the memory on a
69
graphics card with video capturing hardware) may incur a performance
70
penalty compared to main memory accesses, or reads may be
71
significantly slower than writes or vice versa. Other I/O methods may
72
be more efficient in this case.</para>
76
<term><parameter>flags</parameter></term>
78
<para>The <parameter>flags</parameter> parameter
79
specifies the type of the mapped object, mapping options and whether
80
modifications made to the mapped copy of the page are private to the
81
process or are to be shared with other references.</para>
82
<para><constant>MAP_FIXED</constant> requests that the
83
driver selects no other address than the one specified. If the
84
specified address cannot be used, <function>mmap()</function> will fail. If
85
<constant>MAP_FIXED</constant> is specified,
86
<parameter>start</parameter> must be a multiple of the pagesize. Use
87
of this option is discouraged.</para>
88
<para>One of the <constant>MAP_SHARED</constant> or
89
<constant>MAP_PRIVATE</constant> flags must be set.
90
<constant>MAP_SHARED</constant> allows applications to share the
91
mapped memory with other (⪚ child-) processes. Note the Linux
92
<filename>video-buf</filename> module which is used by the bttv,
93
saa7134, saa7146, cx88 and vivi driver supports only
94
<constant>MAP_SHARED</constant>. <constant>MAP_PRIVATE</constant>
95
requests copy-on-write semantics. V4L2 applications should not set the
96
<constant>MAP_PRIVATE</constant>, <constant>MAP_DENYWRITE</constant>,
97
<constant>MAP_EXECUTABLE</constant> or <constant>MAP_ANON</constant>
102
<term><parameter>fd</parameter></term>
108
<term><parameter>offset</parameter></term>
110
<para>Offset of the buffer in device memory. This must be the
111
same value as returned by the driver in the &v4l2-buffer;
112
<structfield>m</structfield> union <structfield>offset</structfield> field for
113
the single-planar API, and the same value as returned by the driver
114
in the &v4l2-plane; <structfield>m</structfield> union
115
<structfield>mem_offset</structfield> field for the multi-planar API.</para>
122
<title>Description</title>
124
<para>The <function>mmap()</function> function asks to map
125
<parameter>length</parameter> bytes starting at
126
<parameter>offset</parameter> in the memory of the device specified by
127
<parameter>fd</parameter> into the application address space,
128
preferably at address <parameter>start</parameter>. This latter
129
address is a hint only, and is usually specified as 0.</para>
131
<para>Suitable length and offset parameters are queried with the
132
&VIDIOC-QUERYBUF; ioctl. Buffers must be allocated with the
133
&VIDIOC-REQBUFS; ioctl before they can be queried.</para>
135
<para>To unmap buffers the &func-munmap; function is used.</para>
139
<title>Return Value</title>
141
<para>On success <function>mmap()</function> returns a pointer to
142
the mapped buffer. On error <constant>MAP_FAILED</constant> (-1) is
143
returned, and the <varname>errno</varname> variable is set
144
appropriately. Possible error codes are:</para>
148
<term><errorcode>EBADF</errorcode></term>
150
<para><parameter>fd</parameter> is not a valid file
155
<term><errorcode>EACCES</errorcode></term>
157
<para><parameter>fd</parameter> is
158
not open for reading and writing.</para>
162
<term><errorcode>EINVAL</errorcode></term>
164
<para>The <parameter>start</parameter> or
165
<parameter>length</parameter> or <parameter>offset</parameter> are not
166
suitable. (E. g. they are too large, or not aligned on a
167
<constant>PAGESIZE</constant> boundary.)</para>
168
<para>The <parameter>flags</parameter> or
169
<parameter>prot</parameter> value is not supported.</para>
170
<para>No buffers have been allocated with the
171
&VIDIOC-REQBUFS; ioctl.</para>
175
<term><errorcode>ENOMEM</errorcode></term>
177
<para>Not enough physical or virtual memory was available to
178
complete the request.</para>
188
sgml-parent-document: "v4l2.sgml"
189
indent-tabs-mode: nil