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