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.</para>
52 <term><parameter>prot</parameter></term>
54 <para>The <parameter>prot</parameter> argument describes the
55 desired memory protection. Regardless of the device type and the
56 direction of data exchange it should be set to
57 <constant>PROT_READ</constant> | <constant>PROT_WRITE</constant>,
58 permitting read and write access to image buffers. Drivers should
59 support at least this combination of flags. Note the Linux
60 <filename>video-buf</filename> kernel module, which is used by the
61 bttv, saa7134, saa7146, cx88 and vivi driver supports only
62 <constant>PROT_READ</constant> | <constant>PROT_WRITE</constant>. When
63 the driver does not support the desired protection the
64 <function>mmap()</function> function fails.</para>
65 <para>Note device memory accesses (⪚ the memory on a
66 graphics card with video capturing hardware) may incur a performance
67 penalty compared to main memory accesses, or reads may be
68 significantly slower than writes or vice versa. Other I/O methods may
69 be more efficient in this case.</para>
73 <term><parameter>flags</parameter></term>
75 <para>The <parameter>flags</parameter> parameter
76 specifies the type of the mapped object, mapping options and whether
77 modifications made to the mapped copy of the page are private to the
78 process or are to be shared with other references.</para>
79 <para><constant>MAP_FIXED</constant> requests that the
80 driver selects no other address than the one specified. If the
81 specified address cannot be used, <function>mmap()</function> will fail. If
82 <constant>MAP_FIXED</constant> is specified,
83 <parameter>start</parameter> must be a multiple of the pagesize. Use
84 of this option is discouraged.</para>
85 <para>One of the <constant>MAP_SHARED</constant> or
86 <constant>MAP_PRIVATE</constant> flags must be set.
87 <constant>MAP_SHARED</constant> allows applications to share the
88 mapped memory with other (⪚ child-) processes. Note the Linux
89 <filename>video-buf</filename> module which is used by the bttv,
90 saa7134, saa7146, cx88 and vivi driver supports only
91 <constant>MAP_SHARED</constant>. <constant>MAP_PRIVATE</constant>
92 requests copy-on-write semantics. V4L2 applications should not set the
93 <constant>MAP_PRIVATE</constant>, <constant>MAP_DENYWRITE</constant>,
94 <constant>MAP_EXECUTABLE</constant> or <constant>MAP_ANON</constant>
99 <term><parameter>fd</parameter></term>
105 <term><parameter>offset</parameter></term>
107 <para>Offset of the buffer in device memory. This must be the
108 same value as returned by the driver in the &v4l2-buffer;
109 <structfield>m</structfield> union <structfield>offset</structfield> field.</para>
116 <title>Description</title>
118 <para>The <function>mmap()</function> function asks to map
119 <parameter>length</parameter> bytes starting at
120 <parameter>offset</parameter> in the memory of the device specified by
121 <parameter>fd</parameter> into the application address space,
122 preferably at address <parameter>start</parameter>. This latter
123 address is a hint only, and is usually specified as 0.</para>
125 <para>Suitable length and offset parameters are queried with the
126 &VIDIOC-QUERYBUF; ioctl. Buffers must be allocated with the
127 &VIDIOC-REQBUFS; ioctl before they can be queried.</para>
129 <para>To unmap buffers the &func-munmap; function is used.</para>
133 <title>Return Value</title>
135 <para>On success <function>mmap()</function> returns a pointer to
136 the mapped buffer. On error <constant>MAP_FAILED</constant> (-1) is
137 returned, and the <varname>errno</varname> variable is set
138 appropriately. Possible error codes are:</para>
142 <term><errorcode>EBADF</errorcode></term>
144 <para><parameter>fd</parameter> is not a valid file
149 <term><errorcode>EACCES</errorcode></term>
151 <para><parameter>fd</parameter> is
152 not open for reading and writing.</para>
156 <term><errorcode>EINVAL</errorcode></term>
158 <para>The <parameter>start</parameter> or
159 <parameter>length</parameter> or <parameter>offset</parameter> are not
160 suitable. (E. g. they are too large, or not aligned on a
161 <constant>PAGESIZE</constant> boundary.)</para>
162 <para>The <parameter>flags</parameter> or
163 <parameter>prot</parameter> value is not supported.</para>
164 <para>No buffers have been allocated with the
165 &VIDIOC-REQBUFS; ioctl.</para>
169 <term><errorcode>ENOMEM</errorcode></term>
171 <para>Not enough physical or virtual memory was available to
172 complete the request.</para>
182 sgml-parent-document: "v4l2.sgml"
183 indent-tabs-mode: nil