Merge tag 'compiler-attributes-for-linus-4.20-rc1' of https://github.com/ojeda/linux
[sfrench/cifs-2.6.git] / Documentation / media / uapi / v4l / vidioc-reqbufs.rst
1 .. -*- coding: utf-8; mode: rst -*-
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, however this cannot succeed when any buffers are still mapped.
63 A ``count`` value of zero frees all buffers, after aborting or finishing
64 any DMA in progress, an implicit
65 :ref:`VIDIOC_STREAMOFF <VIDIOC_STREAMON>`.
66
67
68 .. c:type:: v4l2_requestbuffers
69
70 .. tabularcolumns:: |p{4.4cm}|p{4.4cm}|p{8.7cm}|
71
72 .. flat-table:: struct v4l2_requestbuffers
73     :header-rows:  0
74     :stub-columns: 0
75     :widths:       1 1 2
76
77     * - __u32
78       - ``count``
79       - The number of buffers requested or granted.
80     * - __u32
81       - ``type``
82       - Type of the stream or buffers, this is the same as the struct
83         :c:type:`v4l2_format` ``type`` field. See
84         :c:type:`v4l2_buf_type` for valid values.
85     * - __u32
86       - ``memory``
87       - Applications set this field to ``V4L2_MEMORY_MMAP``,
88         ``V4L2_MEMORY_DMABUF`` or ``V4L2_MEMORY_USERPTR``. See
89         :c:type:`v4l2_memory`.
90     * - __u32
91       - ``capabilities``
92       - Set by the driver. If 0, then the driver doesn't support
93         capabilities. In that case all you know is that the driver is
94         guaranteed to support ``V4L2_MEMORY_MMAP`` and *might* support
95         other :c:type:`v4l2_memory` types. It will not support any others
96         capabilities.
97
98         If you want to query the capabilities with a minimum of side-effects,
99         then this can be called with ``count`` set to 0, ``memory`` set to
100         ``V4L2_MEMORY_MMAP`` and ``type`` set to the buffer type. This will
101         free any previously allocated buffers, so this is typically something
102         that will be done at the start of the application.
103     * - __u32
104       - ``reserved``\ [1]
105       - A place holder for future extensions. Drivers and applications
106         must set the array to zero.
107
108 .. tabularcolumns:: |p{6.1cm}|p{2.2cm}|p{8.7cm}|
109
110 .. _v4l2-buf-capabilities:
111 .. _V4L2-BUF-CAP-SUPPORTS-MMAP:
112 .. _V4L2-BUF-CAP-SUPPORTS-USERPTR:
113 .. _V4L2-BUF-CAP-SUPPORTS-DMABUF:
114 .. _V4L2-BUF-CAP-SUPPORTS-REQUESTS:
115
116 .. cssclass:: longtable
117
118 .. flat-table:: V4L2 Buffer Capabilities Flags
119     :header-rows:  0
120     :stub-columns: 0
121     :widths:       3 1 4
122
123     * - ``V4L2_BUF_CAP_SUPPORTS_MMAP``
124       - 0x00000001
125       - This buffer type supports the ``V4L2_MEMORY_MMAP`` streaming mode.
126     * - ``V4L2_BUF_CAP_SUPPORTS_USERPTR``
127       - 0x00000002
128       - This buffer type supports the ``V4L2_MEMORY_USERPTR`` streaming mode.
129     * - ``V4L2_BUF_CAP_SUPPORTS_DMABUF``
130       - 0x00000004
131       - This buffer type supports the ``V4L2_MEMORY_DMABUF`` streaming mode.
132     * - ``V4L2_BUF_CAP_SUPPORTS_REQUESTS``
133       - 0x00000008
134       - This buffer type supports :ref:`requests <media-request-api>`.
135
136 Return Value
137 ============
138
139 On success 0 is returned, on error -1 and the ``errno`` variable is set
140 appropriately. The generic error codes are described at the
141 :ref:`Generic Error Codes <gen-errors>` chapter.
142
143 EINVAL
144     The buffer type (``type`` field) or the requested I/O method
145     (``memory``) is not supported.