Commit | Line | Data |
---|---|---|
5377d91f MH |
1 | .. -*- coding: utf-8; mode: rst -*- |
2 | ||
3 | .. _func-mmap: | |
4 | ||
5 | *********** | |
6 | V4L2 mmap() | |
7 | *********** | |
8 | ||
9 | *man v4l2-mmap(2)* | |
10 | ||
11 | Map device memory into application address space | |
12 | ||
13 | ||
14 | Synopsis | |
15 | ======== | |
16 | ||
17 | .. code-block:: c | |
18 | ||
19 | #include <unistd.h> | |
20 | #include <sys/mman.h> | |
21 | ||
22 | ||
23 | .. c:function:: void *mmap( void *start, size_t length, int prot, int flags, int fd, off_t offset ) | |
24 | ||
25 | Arguments | |
26 | ========= | |
27 | ||
28 | ``start`` | |
29 | Map the buffer to this address in the application's address space. | |
30 | When the ``MAP_FIXED`` flag is specified, ``start`` must be a | |
31 | multiple of the pagesize and mmap will fail when the specified | |
32 | address cannot be used. Use of this option is discouraged; | |
33 | applications should just specify a ``NULL`` pointer here. | |
34 | ||
35 | ``length`` | |
36 | Length of the memory area to map. This must be the same value as | |
37 | returned by the driver in the struct | |
38 | :ref:`v4l2_buffer <v4l2-buffer>` ``length`` field for the | |
39 | single-planar API, and the same value as returned by the driver in | |
40 | the struct :ref:`v4l2_plane <v4l2-plane>` ``length`` field for | |
41 | the multi-planar API. | |
42 | ||
43 | ``prot`` | |
44 | The ``prot`` argument describes the desired memory protection. | |
45 | Regardless of the device type and the direction of data exchange it | |
46 | should be set to ``PROT_READ`` | ``PROT_WRITE``, permitting read | |
47 | and write access to image buffers. Drivers should support at least | |
48 | this combination of flags. Note the Linux ``video-buf`` kernel | |
49 | module, which is used by the bttv, saa7134, saa7146, cx88 and vivi | |
50 | driver supports only ``PROT_READ`` | ``PROT_WRITE``. When the | |
51 | driver does not support the desired protection the | |
52 | :c:func:`mmap()` function fails. | |
53 | ||
54 | Note device memory accesses (e. g. the memory on a graphics card | |
55 | with video capturing hardware) may incur a performance penalty | |
56 | compared to main memory accesses, or reads may be significantly | |
57 | slower than writes or vice versa. Other I/O methods may be more | |
58 | efficient in this case. | |
59 | ||
60 | ``flags`` | |
61 | The ``flags`` parameter specifies the type of the mapped object, | |
62 | mapping options and whether modifications made to the mapped copy of | |
63 | the page are private to the process or are to be shared with other | |
64 | references. | |
65 | ||
66 | ``MAP_FIXED`` requests that the driver selects no other address than | |
67 | the one specified. If the specified address cannot be used, | |
68 | :c:func:`mmap()` will fail. If ``MAP_FIXED`` is specified, | |
69 | ``start`` must be a multiple of the pagesize. Use of this option is | |
70 | discouraged. | |
71 | ||
72 | One of the ``MAP_SHARED`` or ``MAP_PRIVATE`` flags must be set. | |
73 | ``MAP_SHARED`` allows applications to share the mapped memory with | |
74 | other (e. g. child-) processes. Note the Linux ``video-buf`` module | |
75 | which is used by the bttv, saa7134, saa7146, cx88 and vivi driver | |
76 | supports only ``MAP_SHARED``. ``MAP_PRIVATE`` requests copy-on-write | |
77 | semantics. V4L2 applications should not set the ``MAP_PRIVATE``, | |
78 | ``MAP_DENYWRITE``, ``MAP_EXECUTABLE`` or ``MAP_ANON`` flag. | |
79 | ||
80 | ``fd`` | |
81 | File descriptor returned by :ref:`open() <func-open>`. | |
82 | ||
83 | ``offset`` | |
84 | Offset of the buffer in device memory. This must be the same value | |
85 | as returned by the driver in the struct | |
86 | :ref:`v4l2_buffer <v4l2-buffer>` ``m`` union ``offset`` field for | |
87 | the single-planar API, and the same value as returned by the driver | |
88 | in the struct :ref:`v4l2_plane <v4l2-plane>` ``m`` union | |
89 | ``mem_offset`` field for the multi-planar API. | |
90 | ||
91 | ||
92 | Description | |
93 | =========== | |
94 | ||
95 | The :c:func:`mmap()` function asks to map ``length`` bytes starting at | |
96 | ``offset`` in the memory of the device specified by ``fd`` into the | |
97 | application address space, preferably at address ``start``. This latter | |
98 | address is a hint only, and is usually specified as 0. | |
99 | ||
100 | Suitable length and offset parameters are queried with the | |
7347081e MCC |
101 | :ref:`VIDIOC_QUERYBUF` ioctl. Buffers must be |
102 | allocated with the :ref:`VIDIOC_REQBUFS` ioctl | |
5377d91f MH |
103 | before they can be queried. |
104 | ||
105 | To unmap buffers the :ref:`munmap() <func-munmap>` function is used. | |
106 | ||
107 | ||
108 | Return Value | |
109 | ============ | |
110 | ||
111 | On success :c:func:`mmap()` returns a pointer to the mapped buffer. On | |
112 | error ``MAP_FAILED`` (-1) is returned, and the ``errno`` variable is set | |
113 | appropriately. Possible error codes are: | |
114 | ||
115 | EBADF | |
116 | ``fd`` is not a valid file descriptor. | |
117 | ||
118 | EACCES | |
119 | ``fd`` is not open for reading and writing. | |
120 | ||
121 | EINVAL | |
122 | The ``start`` or ``length`` or ``offset`` are not suitable. (E. g. | |
123 | they are too large, or not aligned on a ``PAGESIZE`` boundary.) | |
124 | ||
125 | The ``flags`` or ``prot`` value is not supported. | |
126 | ||
127 | No buffers have been allocated with the | |
7347081e | 128 | :ref:`VIDIOC_REQBUFS` ioctl. |
5377d91f MH |
129 | |
130 | ENOMEM | |
131 | Not enough physical or virtual memory was available to complete the | |
132 | request. | |
133 | ||
134 | ||
135 | .. ------------------------------------------------------------------------------ | |
136 | .. This file was automatically converted from DocBook-XML with the dbxml | |
137 | .. library (https://github.com/return42/sphkerneldoc). The origin XML comes | |
138 | .. from the linux kernel, refer to: | |
139 | .. | |
140 | .. * https://github.com/torvalds/linux/tree/master/Documentation/DocBook | |
141 | .. ------------------------------------------------------------------------------ |