Based on kernel version 4.7.2. Page generated on 2016-08-22 22:45 EST.
1 <refentry id="func-mmap"> 2 <refmeta> 3 <refentrytitle>V4L2 mmap()</refentrytitle> 4 &manvol; 5 </refmeta> 6 7 <refnamediv> 8 <refname>v4l2-mmap</refname> 9 <refpurpose>Map device memory into application address space</refpurpose> 10 </refnamediv> 11 12 <refsynopsisdiv> 13 <funcsynopsis> 14 <funcsynopsisinfo> 15 #include <unistd.h> 16 #include <sys/mman.h></funcsynopsisinfo> 17 <funcprototype> 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> 25 </funcprototype> 26 </funcsynopsis> 27 </refsynopsisdiv> 28 29 <refsect1> 30 <title>Arguments</title> 31 <variablelist> 32 <varlistentry> 33 <term><parameter>start</parameter></term> 34 <listitem> 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> 41 </listitem> 42 </varlistentry> 43 <varlistentry> 44 <term><parameter>length</parameter></term> 45 <listitem> 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> 52 </listitem> 53 </varlistentry> 54 <varlistentry> 55 <term><parameter>prot</parameter></term> 56 <listitem> 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> 73 </listitem> 74 </varlistentry> 75 <varlistentry> 76 <term><parameter>flags</parameter></term> 77 <listitem> 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> 98 flag.</para> 99 </listitem> 100 </varlistentry> 101 <varlistentry> 102 <term><parameter>fd</parameter></term> 103 <listitem> 104 <para>&fd;</para> 105 </listitem> 106 </varlistentry> 107 <varlistentry> 108 <term><parameter>offset</parameter></term> 109 <listitem> 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> 116 </listitem> 117 </varlistentry> 118 </variablelist> 119 </refsect1> 120 121 <refsect1> 122 <title>Description</title> 123 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> 130 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> 134 135 <para>To unmap buffers the &func-munmap; function is used.</para> 136 </refsect1> 137 138 <refsect1> 139 <title>Return Value</title> 140 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> 145 146 <variablelist> 147 <varlistentry> 148 <term><errorcode>EBADF</errorcode></term> 149 <listitem> 150 <para><parameter>fd</parameter> is not a valid file 151 descriptor.</para> 152 </listitem> 153 </varlistentry> 154 <varlistentry> 155 <term><errorcode>EACCES</errorcode></term> 156 <listitem> 157 <para><parameter>fd</parameter> is 158 not open for reading and writing.</para> 159 </listitem> 160 </varlistentry> 161 <varlistentry> 162 <term><errorcode>EINVAL</errorcode></term> 163 <listitem> 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> 172 </listitem> 173 </varlistentry> 174 <varlistentry> 175 <term><errorcode>ENOMEM</errorcode></term> 176 <listitem> 177 <para>Not enough physical or virtual memory was available to 178 complete the request.</para> 179 </listitem> 180 </varlistentry> 181 </variablelist> 182 </refsect1> 183 </refentry>