1059b1c5bSMauro Carvalho Chehab.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later 2407e84cdSMauro Carvalho Chehab.. c:namespace:: V4L 354f38fcaSMauro Carvalho Chehab 454f38fcaSMauro Carvalho Chehab.. _VIDIOC_REQBUFS: 554f38fcaSMauro Carvalho Chehab 654f38fcaSMauro Carvalho Chehab******************** 754f38fcaSMauro Carvalho Chehabioctl VIDIOC_REQBUFS 854f38fcaSMauro Carvalho Chehab******************** 954f38fcaSMauro Carvalho Chehab 1054f38fcaSMauro Carvalho ChehabName 1154f38fcaSMauro Carvalho Chehab==== 1254f38fcaSMauro Carvalho Chehab 1354f38fcaSMauro Carvalho ChehabVIDIOC_REQBUFS - Initiate Memory Mapping, User Pointer I/O or DMA buffer I/O 1454f38fcaSMauro Carvalho Chehab 1554f38fcaSMauro Carvalho ChehabSynopsis 1654f38fcaSMauro Carvalho Chehab======== 1754f38fcaSMauro Carvalho Chehab 18407e84cdSMauro Carvalho Chehab.. c:macro:: VIDIOC_REQBUFS 1954f38fcaSMauro Carvalho Chehab 20407e84cdSMauro Carvalho Chehab``int ioctl(int fd, VIDIOC_REQBUFS, struct v4l2_requestbuffers *argp)`` 2154f38fcaSMauro Carvalho Chehab 2254f38fcaSMauro Carvalho ChehabArguments 2354f38fcaSMauro Carvalho Chehab========= 2454f38fcaSMauro Carvalho Chehab 2554f38fcaSMauro Carvalho Chehab``fd`` 26407e84cdSMauro Carvalho Chehab File descriptor returned by :c:func:`open()`. 2754f38fcaSMauro Carvalho Chehab 2854f38fcaSMauro Carvalho Chehab``argp`` 2954f38fcaSMauro Carvalho Chehab Pointer to struct :c:type:`v4l2_requestbuffers`. 3054f38fcaSMauro Carvalho Chehab 3154f38fcaSMauro Carvalho ChehabDescription 3254f38fcaSMauro Carvalho Chehab=========== 3354f38fcaSMauro Carvalho Chehab 3454f38fcaSMauro Carvalho ChehabThis ioctl is used to initiate :ref:`memory mapped <mmap>`, 3554f38fcaSMauro Carvalho Chehab:ref:`user pointer <userp>` or :ref:`DMABUF <dmabuf>` based I/O. 3654f38fcaSMauro Carvalho ChehabMemory mapped buffers are located in device memory and must be allocated 3754f38fcaSMauro Carvalho Chehabwith this ioctl before they can be mapped into the application's address 3854f38fcaSMauro Carvalho Chehabspace. User buffers are allocated by applications themselves, and this 3954f38fcaSMauro Carvalho Chehabioctl is merely used to switch the driver into user pointer I/O mode and 4054f38fcaSMauro Carvalho Chehabto setup some internal structures. Similarly, DMABUF buffers are 4154f38fcaSMauro Carvalho Chehaballocated by applications through a device driver, and this ioctl only 4254f38fcaSMauro Carvalho Chehabconfigures the driver into DMABUF I/O mode without performing any direct 4354f38fcaSMauro Carvalho Chehaballocation. 4454f38fcaSMauro Carvalho Chehab 4554f38fcaSMauro Carvalho ChehabTo allocate device buffers applications initialize all fields of the 4654f38fcaSMauro Carvalho Chehabstruct :c:type:`v4l2_requestbuffers` structure. They set the ``type`` 4754f38fcaSMauro Carvalho Chehabfield to the respective stream or buffer type, the ``count`` field to 4854f38fcaSMauro Carvalho Chehabthe desired number of buffers, ``memory`` must be set to the requested 4954f38fcaSMauro Carvalho ChehabI/O method and the ``reserved`` array must be zeroed. When the ioctl is 5054f38fcaSMauro Carvalho Chehabcalled with a pointer to this structure the driver will attempt to 5154f38fcaSMauro Carvalho Chehaballocate the requested number of buffers and it stores the actual number 5254f38fcaSMauro Carvalho Chehaballocated in the ``count`` field. It can be smaller than the number 5354f38fcaSMauro Carvalho Chehabrequested, even zero, when the driver runs out of free memory. A larger 5454f38fcaSMauro Carvalho Chehabnumber is also possible when the driver requires more buffers to 5554f38fcaSMauro Carvalho Chehabfunction correctly. For example video output requires at least two 5654f38fcaSMauro Carvalho Chehabbuffers, one displayed and one filled by the application. 5754f38fcaSMauro Carvalho Chehab 5854f38fcaSMauro Carvalho ChehabWhen the I/O method is not supported the ioctl returns an ``EINVAL`` error 5954f38fcaSMauro Carvalho Chehabcode. 6054f38fcaSMauro Carvalho Chehab 6154f38fcaSMauro Carvalho ChehabApplications can call :ref:`VIDIOC_REQBUFS` again to change the number of 6254f38fcaSMauro Carvalho Chehabbuffers. Note that if any buffers are still mapped or exported via DMABUF, 6354f38fcaSMauro Carvalho Chehabthen :ref:`VIDIOC_REQBUFS` can only succeed if the 6454f38fcaSMauro Carvalho Chehab``V4L2_BUF_CAP_SUPPORTS_ORPHANED_BUFS`` capability is set. Otherwise 6554f38fcaSMauro Carvalho Chehab:ref:`VIDIOC_REQBUFS` will return the ``EBUSY`` error code. 6654f38fcaSMauro Carvalho ChehabIf ``V4L2_BUF_CAP_SUPPORTS_ORPHANED_BUFS`` is set, then these buffers are 6754f38fcaSMauro Carvalho Chehaborphaned and will be freed when they are unmapped or when the exported DMABUF 6854f38fcaSMauro Carvalho Chehabfds are closed. A ``count`` value of zero frees or orphans all buffers, after 6954f38fcaSMauro Carvalho Chehababorting or finishing any DMA in progress, an implicit 7054f38fcaSMauro Carvalho Chehab:ref:`VIDIOC_STREAMOFF <VIDIOC_STREAMON>`. 7154f38fcaSMauro Carvalho Chehab 7254f38fcaSMauro Carvalho Chehab.. c:type:: v4l2_requestbuffers 7354f38fcaSMauro Carvalho Chehab 74fea13a69SMauro Carvalho Chehab.. tabularcolumns:: |p{4.4cm}|p{4.4cm}|p{8.5cm}| 7554f38fcaSMauro Carvalho Chehab 76*670cb8f8SHans Verkuil.. cssclass:: longtable 77*670cb8f8SHans Verkuil 7854f38fcaSMauro Carvalho Chehab.. flat-table:: struct v4l2_requestbuffers 7954f38fcaSMauro Carvalho Chehab :header-rows: 0 8054f38fcaSMauro Carvalho Chehab :stub-columns: 0 8154f38fcaSMauro Carvalho Chehab :widths: 1 1 2 8254f38fcaSMauro Carvalho Chehab 8354f38fcaSMauro Carvalho Chehab * - __u32 8454f38fcaSMauro Carvalho Chehab - ``count`` 8554f38fcaSMauro Carvalho Chehab - The number of buffers requested or granted. 8654f38fcaSMauro Carvalho Chehab * - __u32 8754f38fcaSMauro Carvalho Chehab - ``type`` 8854f38fcaSMauro Carvalho Chehab - Type of the stream or buffers, this is the same as the struct 8954f38fcaSMauro Carvalho Chehab :c:type:`v4l2_format` ``type`` field. See 9054f38fcaSMauro Carvalho Chehab :c:type:`v4l2_buf_type` for valid values. 9154f38fcaSMauro Carvalho Chehab * - __u32 9254f38fcaSMauro Carvalho Chehab - ``memory`` 9354f38fcaSMauro Carvalho Chehab - Applications set this field to ``V4L2_MEMORY_MMAP``, 9454f38fcaSMauro Carvalho Chehab ``V4L2_MEMORY_DMABUF`` or ``V4L2_MEMORY_USERPTR``. See 9554f38fcaSMauro Carvalho Chehab :c:type:`v4l2_memory`. 9654f38fcaSMauro Carvalho Chehab * - __u32 9754f38fcaSMauro Carvalho Chehab - ``capabilities`` 9854f38fcaSMauro Carvalho Chehab - Set by the driver. If 0, then the driver doesn't support 9954f38fcaSMauro Carvalho Chehab capabilities. In that case all you know is that the driver is 10054f38fcaSMauro Carvalho Chehab guaranteed to support ``V4L2_MEMORY_MMAP`` and *might* support 101fcab45adSHans Verkuil other :c:type:`v4l2_memory` types. It will not support any other 10254f38fcaSMauro Carvalho Chehab capabilities. 10354f38fcaSMauro Carvalho Chehab 10454f38fcaSMauro Carvalho Chehab If you want to query the capabilities with a minimum of side-effects, 10554f38fcaSMauro Carvalho Chehab then this can be called with ``count`` set to 0, ``memory`` set to 10654f38fcaSMauro Carvalho Chehab ``V4L2_MEMORY_MMAP`` and ``type`` set to the buffer type. This will 10754f38fcaSMauro Carvalho Chehab free any previously allocated buffers, so this is typically something 10854f38fcaSMauro Carvalho Chehab that will be done at the start of the application. 109c0acf9cfSSergey Senozhatsky * - __u8 110c0acf9cfSSergey Senozhatsky - ``flags`` 111c0acf9cfSSergey Senozhatsky - Specifies additional buffer management attributes. 112c0acf9cfSSergey Senozhatsky See :ref:`memory-flags`. 113c0acf9cfSSergey Senozhatsky * - __u8 114c0acf9cfSSergey Senozhatsky - ``reserved``\ [3] 115c0acf9cfSSergey Senozhatsky - Reserved for future extensions. 11654f38fcaSMauro Carvalho Chehab 11754f38fcaSMauro Carvalho Chehab.. _v4l2-buf-capabilities: 11854f38fcaSMauro Carvalho Chehab.. _V4L2-BUF-CAP-SUPPORTS-MMAP: 11954f38fcaSMauro Carvalho Chehab.. _V4L2-BUF-CAP-SUPPORTS-USERPTR: 12054f38fcaSMauro Carvalho Chehab.. _V4L2-BUF-CAP-SUPPORTS-DMABUF: 12154f38fcaSMauro Carvalho Chehab.. _V4L2-BUF-CAP-SUPPORTS-REQUESTS: 12254f38fcaSMauro Carvalho Chehab.. _V4L2-BUF-CAP-SUPPORTS-ORPHANED-BUFS: 12354f38fcaSMauro Carvalho Chehab.. _V4L2-BUF-CAP-SUPPORTS-M2M-HOLD-CAPTURE-BUF: 124ac53503eSSergey Senozhatsky.. _V4L2-BUF-CAP-SUPPORTS-MMAP-CACHE-HINTS: 125d055a76cSBenjamin Gaignard.. _V4L2-BUF-CAP-SUPPORTS-MAX-NUM-BUFFERS: 126a3293a85SBenjamin Gaignard.. _V4L2-BUF-CAP-SUPPORTS-REMOVE-BUFS: 12754f38fcaSMauro Carvalho Chehab 12854f38fcaSMauro Carvalho Chehab.. flat-table:: V4L2 Buffer Capabilities Flags 12954f38fcaSMauro Carvalho Chehab :header-rows: 0 13054f38fcaSMauro Carvalho Chehab :stub-columns: 0 13154f38fcaSMauro Carvalho Chehab :widths: 3 1 4 13254f38fcaSMauro Carvalho Chehab 13354f38fcaSMauro Carvalho Chehab * - ``V4L2_BUF_CAP_SUPPORTS_MMAP`` 13454f38fcaSMauro Carvalho Chehab - 0x00000001 13554f38fcaSMauro Carvalho Chehab - This buffer type supports the ``V4L2_MEMORY_MMAP`` streaming mode. 13654f38fcaSMauro Carvalho Chehab * - ``V4L2_BUF_CAP_SUPPORTS_USERPTR`` 13754f38fcaSMauro Carvalho Chehab - 0x00000002 13854f38fcaSMauro Carvalho Chehab - This buffer type supports the ``V4L2_MEMORY_USERPTR`` streaming mode. 13954f38fcaSMauro Carvalho Chehab * - ``V4L2_BUF_CAP_SUPPORTS_DMABUF`` 14054f38fcaSMauro Carvalho Chehab - 0x00000004 14154f38fcaSMauro Carvalho Chehab - This buffer type supports the ``V4L2_MEMORY_DMABUF`` streaming mode. 14254f38fcaSMauro Carvalho Chehab * - ``V4L2_BUF_CAP_SUPPORTS_REQUESTS`` 14354f38fcaSMauro Carvalho Chehab - 0x00000008 14454f38fcaSMauro Carvalho Chehab - This buffer type supports :ref:`requests <media-request-api>`. 14554f38fcaSMauro Carvalho Chehab * - ``V4L2_BUF_CAP_SUPPORTS_ORPHANED_BUFS`` 14654f38fcaSMauro Carvalho Chehab - 0x00000010 14754f38fcaSMauro Carvalho Chehab - The kernel allows calling :ref:`VIDIOC_REQBUFS` while buffers are still 14854f38fcaSMauro Carvalho Chehab mapped or exported via DMABUF. These orphaned buffers will be freed 14954f38fcaSMauro Carvalho Chehab when they are unmapped or when the exported DMABUF fds are closed. 15054f38fcaSMauro Carvalho Chehab * - ``V4L2_BUF_CAP_SUPPORTS_M2M_HOLD_CAPTURE_BUF`` 15154f38fcaSMauro Carvalho Chehab - 0x00000020 15254f38fcaSMauro Carvalho Chehab - Only valid for stateless decoders. If set, then userspace can set the 15354f38fcaSMauro Carvalho Chehab ``V4L2_BUF_FLAG_M2M_HOLD_CAPTURE_BUF`` flag to hold off on returning the 15454f38fcaSMauro Carvalho Chehab capture buffer until the OUTPUT timestamp changes. 155ac53503eSSergey Senozhatsky * - ``V4L2_BUF_CAP_SUPPORTS_MMAP_CACHE_HINTS`` 156ac53503eSSergey Senozhatsky - 0x00000040 157ac53503eSSergey Senozhatsky - This capability is set by the driver to indicate that the queue supports 158ac53503eSSergey Senozhatsky cache and memory management hints. However, it's only valid when the 159ac53503eSSergey Senozhatsky queue is used for :ref:`memory mapping <mmap>` streaming I/O. See 160965c1e0bSSergey Senozhatsky :ref:`V4L2_BUF_FLAG_NO_CACHE_INVALIDATE <V4L2-BUF-FLAG-NO-CACHE-INVALIDATE>`, 161965c1e0bSSergey Senozhatsky :ref:`V4L2_BUF_FLAG_NO_CACHE_CLEAN <V4L2-BUF-FLAG-NO-CACHE-CLEAN>` and 162965c1e0bSSergey Senozhatsky :ref:`V4L2_MEMORY_FLAG_NON_COHERENT <V4L2-MEMORY-FLAG-NON-COHERENT>`. 163911d5618SHans Verkuil * - ``V4L2_BUF_CAP_SUPPORTS_MAX_NUM_BUFFERS`` 164911d5618SHans Verkuil - 0x00000080 165911d5618SHans Verkuil - If set, then the ``max_num_buffers`` field in ``struct v4l2_create_buffers`` 166911d5618SHans Verkuil is valid. If not set, then the maximum is ``VIDEO_MAX_FRAME`` buffers. 167911d5618SHans Verkuil * - ``V4L2_BUF_CAP_SUPPORTS_REMOVE_BUFS`` 168911d5618SHans Verkuil - 0x00000100 169911d5618SHans Verkuil - If set, then ``VIDIOC_REMOVE_BUFS`` is supported. 170ac53503eSSergey Senozhatsky 171*670cb8f8SHans Verkuil.. _memory-flags: 172*670cb8f8SHans Verkuil.. _V4L2-MEMORY-FLAG-NON-COHERENT: 173*670cb8f8SHans Verkuil 174*670cb8f8SHans Verkuil.. flat-table:: Memory Consistency Flags 175*670cb8f8SHans Verkuil :header-rows: 0 176*670cb8f8SHans Verkuil :stub-columns: 0 177*670cb8f8SHans Verkuil :widths: 3 1 4 178*670cb8f8SHans Verkuil 179*670cb8f8SHans Verkuil * - ``V4L2_MEMORY_FLAG_NON_COHERENT`` 180*670cb8f8SHans Verkuil - 0x00000001 181*670cb8f8SHans Verkuil - A buffer is allocated either in coherent (it will be automatically 182*670cb8f8SHans Verkuil coherent between the CPU and the bus) or non-coherent memory. The 183*670cb8f8SHans Verkuil latter can provide performance gains, for instance the CPU cache 184*670cb8f8SHans Verkuil sync/flush operations can be avoided if the buffer is accessed by the 185*670cb8f8SHans Verkuil corresponding device only and the CPU does not read/write to/from that 186*670cb8f8SHans Verkuil buffer. However, this requires extra care from the driver -- it must 187*670cb8f8SHans Verkuil guarantee memory consistency by issuing a cache flush/sync when 188*670cb8f8SHans Verkuil consistency is needed. If this flag is set V4L2 will attempt to 189*670cb8f8SHans Verkuil allocate the buffer in non-coherent memory. The flag takes effect 190*670cb8f8SHans Verkuil only if the buffer is used for :ref:`memory mapping <mmap>` I/O and the 191*670cb8f8SHans Verkuil queue reports the :ref:`V4L2_BUF_CAP_SUPPORTS_MMAP_CACHE_HINTS 192*670cb8f8SHans Verkuil <V4L2-BUF-CAP-SUPPORTS-MMAP-CACHE-HINTS>` capability. 193*670cb8f8SHans Verkuil 194fea13a69SMauro Carvalho Chehab.. raw:: latex 195fea13a69SMauro Carvalho Chehab 196fea13a69SMauro Carvalho Chehab \normalsize 197fea13a69SMauro Carvalho Chehab 19854f38fcaSMauro Carvalho ChehabReturn Value 19954f38fcaSMauro Carvalho Chehab============ 20054f38fcaSMauro Carvalho Chehab 20154f38fcaSMauro Carvalho ChehabOn success 0 is returned, on error -1 and the ``errno`` variable is set 20254f38fcaSMauro Carvalho Chehabappropriately. The generic error codes are described at the 20354f38fcaSMauro Carvalho Chehab:ref:`Generic Error Codes <gen-errors>` chapter. 20454f38fcaSMauro Carvalho Chehab 20554f38fcaSMauro Carvalho ChehabEINVAL 20654f38fcaSMauro Carvalho Chehab The buffer type (``type`` field) or the requested I/O method 20754f38fcaSMauro Carvalho Chehab (``memory``) is not supported. 208