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