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