Merge tag 'powerpc-5.10-1' of git://git.kernel.org/pub/scm/linux/kernel/git/powerpc...
[linux-2.6-microblaze.git] / Documentation / userspace-api / media / v4l / vidioc-reqbufs.rst
1 .. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later
2
3 .. _VIDIOC_REQBUFS:
4
5 ********************
6 ioctl VIDIOC_REQBUFS
7 ********************
8
9 Name
10 ====
11
12 VIDIOC_REQBUFS - Initiate Memory Mapping, User Pointer I/O or DMA buffer I/O
13
14
15 Synopsis
16 ========
17
18 .. c:function:: int ioctl( int fd, VIDIOC_REQBUFS, struct v4l2_requestbuffers *argp )
19     :name: VIDIOC_REQBUFS
20
21
22 Arguments
23 =========
24
25 ``fd``
26     File descriptor returned by :ref:`open() <func-open>`.
27
28 ``argp``
29     Pointer to struct :c:type:`v4l2_requestbuffers`.
30
31 Description
32 ===========
33
34 This ioctl is used to initiate :ref:`memory mapped <mmap>`,
35 :ref:`user pointer <userp>` or :ref:`DMABUF <dmabuf>` based I/O.
36 Memory mapped buffers are located in device memory and must be allocated
37 with this ioctl before they can be mapped into the application's address
38 space. User buffers are allocated by applications themselves, and this
39 ioctl is merely used to switch the driver into user pointer I/O mode and
40 to setup some internal structures. Similarly, DMABUF buffers are
41 allocated by applications through a device driver, and this ioctl only
42 configures the driver into DMABUF I/O mode without performing any direct
43 allocation.
44
45 To allocate device buffers applications initialize all fields of the
46 struct :c:type:`v4l2_requestbuffers` structure. They set the ``type``
47 field to the respective stream or buffer type, the ``count`` field to
48 the desired number of buffers, ``memory`` must be set to the requested
49 I/O method and the ``reserved`` array must be zeroed. When the ioctl is
50 called with a pointer to this structure the driver will attempt to
51 allocate the requested number of buffers and it stores the actual number
52 allocated in the ``count`` field. It can be smaller than the number
53 requested, even zero, when the driver runs out of free memory. A larger
54 number is also possible when the driver requires more buffers to
55 function correctly. For example video output requires at least two
56 buffers, one displayed and one filled by the application.
57
58 When the I/O method is not supported the ioctl returns an ``EINVAL`` error
59 code.
60
61 Applications can call :ref:`VIDIOC_REQBUFS` again to change the number of
62 buffers. Note that if any buffers are still mapped or exported via DMABUF,
63 then :ref:`VIDIOC_REQBUFS` can only succeed if the
64 ``V4L2_BUF_CAP_SUPPORTS_ORPHANED_BUFS`` capability is set. Otherwise
65 :ref:`VIDIOC_REQBUFS` will return the ``EBUSY`` error code.
66 If ``V4L2_BUF_CAP_SUPPORTS_ORPHANED_BUFS`` is set, then these buffers are
67 orphaned and will be freed when they are unmapped or when the exported DMABUF
68 fds are closed. A ``count`` value of zero frees or orphans all buffers, after
69 aborting or finishing any DMA in progress, an implicit
70 :ref:`VIDIOC_STREAMOFF <VIDIOC_STREAMON>`.
71
72
73 .. c:type:: v4l2_requestbuffers
74
75 .. tabularcolumns:: |p{4.4cm}|p{4.4cm}|p{8.7cm}|
76
77 .. flat-table:: struct v4l2_requestbuffers
78     :header-rows:  0
79     :stub-columns: 0
80     :widths:       1 1 2
81
82     * - __u32
83       - ``count``
84       - The number of buffers requested or granted.
85     * - __u32
86       - ``type``
87       - Type of the stream or buffers, this is the same as the struct
88         :c:type:`v4l2_format` ``type`` field. See
89         :c:type:`v4l2_buf_type` for valid values.
90     * - __u32
91       - ``memory``
92       - Applications set this field to ``V4L2_MEMORY_MMAP``,
93         ``V4L2_MEMORY_DMABUF`` or ``V4L2_MEMORY_USERPTR``. See
94         :c:type:`v4l2_memory`.
95     * - __u32
96       - ``capabilities``
97       - Set by the driver. If 0, then the driver doesn't support
98         capabilities. In that case all you know is that the driver is
99         guaranteed to support ``V4L2_MEMORY_MMAP`` and *might* support
100         other :c:type:`v4l2_memory` types. It will not support any other
101         capabilities.
102
103         If you want to query the capabilities with a minimum of side-effects,
104         then this can be called with ``count`` set to 0, ``memory`` set to
105         ``V4L2_MEMORY_MMAP`` and ``type`` set to the buffer type. This will
106         free any previously allocated buffers, so this is typically something
107         that will be done at the start of the application.
108     * - __u32
109       - ``reserved``\ [1]
110       - A place holder for future extensions. Drivers and applications
111         must set the array to zero.
112
113 .. tabularcolumns:: |p{6.1cm}|p{2.2cm}|p{8.7cm}|
114
115 .. _v4l2-buf-capabilities:
116 .. _V4L2-BUF-CAP-SUPPORTS-MMAP:
117 .. _V4L2-BUF-CAP-SUPPORTS-USERPTR:
118 .. _V4L2-BUF-CAP-SUPPORTS-DMABUF:
119 .. _V4L2-BUF-CAP-SUPPORTS-REQUESTS:
120 .. _V4L2-BUF-CAP-SUPPORTS-ORPHANED-BUFS:
121 .. _V4L2-BUF-CAP-SUPPORTS-M2M-HOLD-CAPTURE-BUF:
122 .. _V4L2-BUF-CAP-SUPPORTS-MMAP-CACHE-HINTS:
123
124 .. cssclass:: longtable
125
126 .. flat-table:: V4L2 Buffer Capabilities Flags
127     :header-rows:  0
128     :stub-columns: 0
129     :widths:       3 1 4
130
131     * - ``V4L2_BUF_CAP_SUPPORTS_MMAP``
132       - 0x00000001
133       - This buffer type supports the ``V4L2_MEMORY_MMAP`` streaming mode.
134     * - ``V4L2_BUF_CAP_SUPPORTS_USERPTR``
135       - 0x00000002
136       - This buffer type supports the ``V4L2_MEMORY_USERPTR`` streaming mode.
137     * - ``V4L2_BUF_CAP_SUPPORTS_DMABUF``
138       - 0x00000004
139       - This buffer type supports the ``V4L2_MEMORY_DMABUF`` streaming mode.
140     * - ``V4L2_BUF_CAP_SUPPORTS_REQUESTS``
141       - 0x00000008
142       - This buffer type supports :ref:`requests <media-request-api>`.
143     * - ``V4L2_BUF_CAP_SUPPORTS_ORPHANED_BUFS``
144       - 0x00000010
145       - The kernel allows calling :ref:`VIDIOC_REQBUFS` while buffers are still
146         mapped or exported via DMABUF. These orphaned buffers will be freed
147         when they are unmapped or when the exported DMABUF fds are closed.
148     * - ``V4L2_BUF_CAP_SUPPORTS_M2M_HOLD_CAPTURE_BUF``
149       - 0x00000020
150       - Only valid for stateless decoders. If set, then userspace can set the
151         ``V4L2_BUF_FLAG_M2M_HOLD_CAPTURE_BUF`` flag to hold off on returning the
152         capture buffer until the OUTPUT timestamp changes.
153     * - ``V4L2_BUF_CAP_SUPPORTS_MMAP_CACHE_HINTS``
154       - 0x00000040
155       - This capability is set by the driver to indicate that the queue supports
156         cache and memory management hints. However, it's only valid when the
157         queue is used for :ref:`memory mapping <mmap>` streaming I/O. See
158         :ref:`V4L2_BUF_FLAG_NO_CACHE_INVALIDATE <V4L2-BUF-FLAG-NO-CACHE-INVALIDATE>` and
159         :ref:`V4L2_BUF_FLAG_NO_CACHE_CLEAN <V4L2-BUF-FLAG-NO-CACHE-CLEAN>`.
160
161
162 Return Value
163 ============
164
165 On success 0 is returned, on error -1 and the ``errno`` variable is set
166 appropriately. The generic error codes are described at the
167 :ref:`Generic Error Codes <gen-errors>` chapter.
168
169 EINVAL
170     The buffer type (``type`` field) or the requested I/O method
171     (``memory``) is not supported.