func-mmap.xml 6.7 KB

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