func-mmap.xml 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. <refentry id="func-mmap">
  2. <refmeta>
  3. <refentrytitle>V4L2 mmap()</refentrytitle>
  4. &manvol;
  5. </refmeta>
  6. <refnamediv>
  7. <refname>v4l2-mmap</refname>
  8. <refpurpose>Map device memory into application address space</refpurpose>
  9. </refnamediv>
  10. <refsynopsisdiv>
  11. <funcsynopsis>
  12. <funcsynopsisinfo>
  13. #include &lt;unistd.h&gt;
  14. #include &lt;sys/mman.h&gt;</funcsynopsisinfo>
  15. <funcprototype>
  16. <funcdef>void *<function>mmap</function></funcdef>
  17. <paramdef>void *<parameter>start</parameter></paramdef>
  18. <paramdef>size_t <parameter>length</parameter></paramdef>
  19. <paramdef>int <parameter>prot</parameter></paramdef>
  20. <paramdef>int <parameter>flags</parameter></paramdef>
  21. <paramdef>int <parameter>fd</parameter></paramdef>
  22. <paramdef>off_t <parameter>offset</parameter></paramdef>
  23. </funcprototype>
  24. </funcsynopsis>
  25. </refsynopsisdiv>
  26. <refsect1>
  27. <title>Arguments</title>
  28. <variablelist>
  29. <varlistentry>
  30. <term><parameter>start</parameter></term>
  31. <listitem>
  32. <para>Map the buffer to this address in the
  33. application's address space. When the <constant>MAP_FIXED</constant>
  34. flag is specified, <parameter>start</parameter> must be a multiple of the
  35. pagesize and mmap will fail when the specified address
  36. cannot be used. Use of this option is discouraged; applications should
  37. just specify a <constant>NULL</constant> pointer here.</para>
  38. </listitem>
  39. </varlistentry>
  40. <varlistentry>
  41. <term><parameter>length</parameter></term>
  42. <listitem>
  43. <para>Length of the memory area to map. This must be the
  44. same value as returned by the driver in the &v4l2-buffer;
  45. <structfield>length</structfield> field for the
  46. single-planar API, and the same value as returned by the driver
  47. in the &v4l2-plane; <structfield>length</structfield> field for the
  48. multi-planar API.</para>
  49. </listitem>
  50. </varlistentry>
  51. <varlistentry>
  52. <term><parameter>prot</parameter></term>
  53. <listitem>
  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 (&eg; 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>
  70. </listitem>
  71. </varlistentry>
  72. <varlistentry>
  73. <term><parameter>flags</parameter></term>
  74. <listitem>
  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 (&eg; 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>
  95. flag.</para>
  96. </listitem>
  97. </varlistentry>
  98. <varlistentry>
  99. <term><parameter>fd</parameter></term>
  100. <listitem>
  101. <para>&fd;</para>
  102. </listitem>
  103. </varlistentry>
  104. <varlistentry>
  105. <term><parameter>offset</parameter></term>
  106. <listitem>
  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 for
  110. the single-planar API, and the same value as returned by the driver
  111. in the &v4l2-plane; <structfield>m</structfield> union
  112. <structfield>mem_offset</structfield> field for the multi-planar API.</para>
  113. </listitem>
  114. </varlistentry>
  115. </variablelist>
  116. </refsect1>
  117. <refsect1>
  118. <title>Description</title>
  119. <para>The <function>mmap()</function> function asks to map
  120. <parameter>length</parameter> bytes starting at
  121. <parameter>offset</parameter> in the memory of the device specified by
  122. <parameter>fd</parameter> into the application address space,
  123. preferably at address <parameter>start</parameter>. This latter
  124. 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>
  128. <para>To unmap buffers the &func-munmap; function is used.</para>
  129. </refsect1>
  130. <refsect1>
  131. <title>Return Value</title>
  132. <para>On success <function>mmap()</function> returns a pointer to
  133. the mapped buffer. On error <constant>MAP_FAILED</constant> (-1) is
  134. returned, and the <varname>errno</varname> variable is set
  135. appropriately. Possible error codes are:</para>
  136. <variablelist>
  137. <varlistentry>
  138. <term><errorcode>EBADF</errorcode></term>
  139. <listitem>
  140. <para><parameter>fd</parameter> is not a valid file
  141. descriptor.</para>
  142. </listitem>
  143. </varlistentry>
  144. <varlistentry>
  145. <term><errorcode>EACCES</errorcode></term>
  146. <listitem>
  147. <para><parameter>fd</parameter> is
  148. not open for reading and writing.</para>
  149. </listitem>
  150. </varlistentry>
  151. <varlistentry>
  152. <term><errorcode>EINVAL</errorcode></term>
  153. <listitem>
  154. <para>The <parameter>start</parameter> or
  155. <parameter>length</parameter> or <parameter>offset</parameter> are not
  156. suitable. (E.&nbsp;g. they are too large, or not aligned on a
  157. <constant>PAGESIZE</constant> boundary.)</para>
  158. <para>The <parameter>flags</parameter> or
  159. <parameter>prot</parameter> value is not supported.</para>
  160. <para>No buffers have been allocated with the
  161. &VIDIOC-REQBUFS; ioctl.</para>
  162. </listitem>
  163. </varlistentry>
  164. <varlistentry>
  165. <term><errorcode>ENOMEM</errorcode></term>
  166. <listitem>
  167. <para>Not enough physical or virtual memory was available to
  168. complete the request.</para>
  169. </listitem>
  170. </varlistentry>
  171. </variablelist>
  172. </refsect1>
  173. </refentry>