154f38fcaSMauro Carvalho Chehab.. Permission is granted to copy, distribute and/or modify this 254f38fcaSMauro Carvalho Chehab.. document under the terms of the GNU Free Documentation License, 354f38fcaSMauro Carvalho Chehab.. Version 1.1 or any later version published by the Free Software 454f38fcaSMauro Carvalho Chehab.. Foundation, with no Invariant Sections, no Front-Cover Texts 554f38fcaSMauro Carvalho Chehab.. and no Back-Cover Texts. A copy of the license is included at 654f38fcaSMauro Carvalho Chehab.. Documentation/userspace-api/media/fdl-appendix.rst. 754f38fcaSMauro Carvalho Chehab.. 854f38fcaSMauro Carvalho Chehab.. TODO: replace it to GFDL-1.1-or-later WITH no-invariant-sections 954f38fcaSMauro Carvalho Chehab 1054f38fcaSMauro Carvalho Chehab.. _VIDIOC_REQBUFS: 1154f38fcaSMauro Carvalho Chehab 1254f38fcaSMauro Carvalho Chehab******************** 1354f38fcaSMauro Carvalho Chehabioctl VIDIOC_REQBUFS 1454f38fcaSMauro Carvalho Chehab******************** 1554f38fcaSMauro Carvalho Chehab 1654f38fcaSMauro Carvalho ChehabName 1754f38fcaSMauro Carvalho Chehab==== 1854f38fcaSMauro Carvalho Chehab 1954f38fcaSMauro Carvalho ChehabVIDIOC_REQBUFS - Initiate Memory Mapping, User Pointer I/O or DMA buffer I/O 2054f38fcaSMauro Carvalho Chehab 2154f38fcaSMauro Carvalho Chehab 2254f38fcaSMauro Carvalho ChehabSynopsis 2354f38fcaSMauro Carvalho Chehab======== 2454f38fcaSMauro Carvalho Chehab 2554f38fcaSMauro Carvalho Chehab.. c:function:: int ioctl( int fd, VIDIOC_REQBUFS, struct v4l2_requestbuffers *argp ) 2654f38fcaSMauro Carvalho Chehab :name: VIDIOC_REQBUFS 2754f38fcaSMauro Carvalho Chehab 2854f38fcaSMauro Carvalho Chehab 2954f38fcaSMauro Carvalho ChehabArguments 3054f38fcaSMauro Carvalho Chehab========= 3154f38fcaSMauro Carvalho Chehab 3254f38fcaSMauro Carvalho Chehab``fd`` 3354f38fcaSMauro Carvalho Chehab File descriptor returned by :ref:`open() <func-open>`. 3454f38fcaSMauro Carvalho Chehab 3554f38fcaSMauro Carvalho Chehab``argp`` 3654f38fcaSMauro Carvalho Chehab Pointer to struct :c:type:`v4l2_requestbuffers`. 3754f38fcaSMauro Carvalho Chehab 3854f38fcaSMauro Carvalho ChehabDescription 3954f38fcaSMauro Carvalho Chehab=========== 4054f38fcaSMauro Carvalho Chehab 4154f38fcaSMauro Carvalho ChehabThis ioctl is used to initiate :ref:`memory mapped <mmap>`, 4254f38fcaSMauro Carvalho Chehab:ref:`user pointer <userp>` or :ref:`DMABUF <dmabuf>` based I/O. 4354f38fcaSMauro Carvalho ChehabMemory mapped buffers are located in device memory and must be allocated 4454f38fcaSMauro Carvalho Chehabwith this ioctl before they can be mapped into the application's address 4554f38fcaSMauro Carvalho Chehabspace. User buffers are allocated by applications themselves, and this 4654f38fcaSMauro Carvalho Chehabioctl is merely used to switch the driver into user pointer I/O mode and 4754f38fcaSMauro Carvalho Chehabto setup some internal structures. Similarly, DMABUF buffers are 4854f38fcaSMauro Carvalho Chehaballocated by applications through a device driver, and this ioctl only 4954f38fcaSMauro Carvalho Chehabconfigures the driver into DMABUF I/O mode without performing any direct 5054f38fcaSMauro Carvalho Chehaballocation. 5154f38fcaSMauro Carvalho Chehab 5254f38fcaSMauro Carvalho ChehabTo allocate device buffers applications initialize all fields of the 5354f38fcaSMauro Carvalho Chehabstruct :c:type:`v4l2_requestbuffers` structure. They set the ``type`` 5454f38fcaSMauro Carvalho Chehabfield to the respective stream or buffer type, the ``count`` field to 5554f38fcaSMauro Carvalho Chehabthe desired number of buffers, ``memory`` must be set to the requested 5654f38fcaSMauro Carvalho ChehabI/O method and the ``reserved`` array must be zeroed. When the ioctl is 5754f38fcaSMauro Carvalho Chehabcalled with a pointer to this structure the driver will attempt to 5854f38fcaSMauro Carvalho Chehaballocate the requested number of buffers and it stores the actual number 5954f38fcaSMauro Carvalho Chehaballocated in the ``count`` field. It can be smaller than the number 6054f38fcaSMauro Carvalho Chehabrequested, even zero, when the driver runs out of free memory. A larger 6154f38fcaSMauro Carvalho Chehabnumber is also possible when the driver requires more buffers to 6254f38fcaSMauro Carvalho Chehabfunction correctly. For example video output requires at least two 6354f38fcaSMauro Carvalho Chehabbuffers, one displayed and one filled by the application. 6454f38fcaSMauro Carvalho Chehab 6554f38fcaSMauro Carvalho ChehabWhen the I/O method is not supported the ioctl returns an ``EINVAL`` error 6654f38fcaSMauro Carvalho Chehabcode. 6754f38fcaSMauro Carvalho Chehab 6854f38fcaSMauro Carvalho ChehabApplications can call :ref:`VIDIOC_REQBUFS` again to change the number of 6954f38fcaSMauro Carvalho Chehabbuffers. Note that if any buffers are still mapped or exported via DMABUF, 7054f38fcaSMauro Carvalho Chehabthen :ref:`VIDIOC_REQBUFS` can only succeed if the 7154f38fcaSMauro Carvalho Chehab``V4L2_BUF_CAP_SUPPORTS_ORPHANED_BUFS`` capability is set. Otherwise 7254f38fcaSMauro Carvalho Chehab:ref:`VIDIOC_REQBUFS` will return the ``EBUSY`` error code. 7354f38fcaSMauro Carvalho ChehabIf ``V4L2_BUF_CAP_SUPPORTS_ORPHANED_BUFS`` is set, then these buffers are 7454f38fcaSMauro Carvalho Chehaborphaned and will be freed when they are unmapped or when the exported DMABUF 7554f38fcaSMauro Carvalho Chehabfds are closed. A ``count`` value of zero frees or orphans all buffers, after 7654f38fcaSMauro Carvalho Chehababorting or finishing any DMA in progress, an implicit 7754f38fcaSMauro Carvalho Chehab:ref:`VIDIOC_STREAMOFF <VIDIOC_STREAMON>`. 7854f38fcaSMauro Carvalho Chehab 7954f38fcaSMauro Carvalho Chehab 8054f38fcaSMauro Carvalho Chehab.. c:type:: v4l2_requestbuffers 8154f38fcaSMauro Carvalho Chehab 8254f38fcaSMauro Carvalho Chehab.. tabularcolumns:: |p{4.4cm}|p{4.4cm}|p{8.7cm}| 8354f38fcaSMauro Carvalho Chehab 8454f38fcaSMauro Carvalho Chehab.. flat-table:: struct v4l2_requestbuffers 8554f38fcaSMauro Carvalho Chehab :header-rows: 0 8654f38fcaSMauro Carvalho Chehab :stub-columns: 0 8754f38fcaSMauro Carvalho Chehab :widths: 1 1 2 8854f38fcaSMauro Carvalho Chehab 8954f38fcaSMauro Carvalho Chehab * - __u32 9054f38fcaSMauro Carvalho Chehab - ``count`` 9154f38fcaSMauro Carvalho Chehab - The number of buffers requested or granted. 9254f38fcaSMauro Carvalho Chehab * - __u32 9354f38fcaSMauro Carvalho Chehab - ``type`` 9454f38fcaSMauro Carvalho Chehab - Type of the stream or buffers, this is the same as the struct 9554f38fcaSMauro Carvalho Chehab :c:type:`v4l2_format` ``type`` field. See 9654f38fcaSMauro Carvalho Chehab :c:type:`v4l2_buf_type` for valid values. 9754f38fcaSMauro Carvalho Chehab * - __u32 9854f38fcaSMauro Carvalho Chehab - ``memory`` 9954f38fcaSMauro Carvalho Chehab - Applications set this field to ``V4L2_MEMORY_MMAP``, 10054f38fcaSMauro Carvalho Chehab ``V4L2_MEMORY_DMABUF`` or ``V4L2_MEMORY_USERPTR``. See 10154f38fcaSMauro Carvalho Chehab :c:type:`v4l2_memory`. 10254f38fcaSMauro Carvalho Chehab * - __u32 10354f38fcaSMauro Carvalho Chehab - ``capabilities`` 10454f38fcaSMauro Carvalho Chehab - Set by the driver. If 0, then the driver doesn't support 10554f38fcaSMauro Carvalho Chehab capabilities. In that case all you know is that the driver is 10654f38fcaSMauro Carvalho Chehab guaranteed to support ``V4L2_MEMORY_MMAP`` and *might* support 107fcab45adSHans Verkuil other :c:type:`v4l2_memory` types. It will not support any other 10854f38fcaSMauro Carvalho Chehab capabilities. 10954f38fcaSMauro Carvalho Chehab 11054f38fcaSMauro Carvalho Chehab If you want to query the capabilities with a minimum of side-effects, 11154f38fcaSMauro Carvalho Chehab then this can be called with ``count`` set to 0, ``memory`` set to 11254f38fcaSMauro Carvalho Chehab ``V4L2_MEMORY_MMAP`` and ``type`` set to the buffer type. This will 11354f38fcaSMauro Carvalho Chehab free any previously allocated buffers, so this is typically something 11454f38fcaSMauro Carvalho Chehab that will be done at the start of the application. 11554f38fcaSMauro Carvalho Chehab * - __u32 11654f38fcaSMauro Carvalho Chehab - ``reserved``\ [1] 11754f38fcaSMauro Carvalho Chehab - A place holder for future extensions. Drivers and applications 11854f38fcaSMauro Carvalho Chehab must set the array to zero. 11954f38fcaSMauro Carvalho Chehab 12054f38fcaSMauro Carvalho Chehab.. tabularcolumns:: |p{6.1cm}|p{2.2cm}|p{8.7cm}| 12154f38fcaSMauro Carvalho Chehab 12254f38fcaSMauro Carvalho Chehab.. _v4l2-buf-capabilities: 12354f38fcaSMauro Carvalho Chehab.. _V4L2-BUF-CAP-SUPPORTS-MMAP: 12454f38fcaSMauro Carvalho Chehab.. _V4L2-BUF-CAP-SUPPORTS-USERPTR: 12554f38fcaSMauro Carvalho Chehab.. _V4L2-BUF-CAP-SUPPORTS-DMABUF: 12654f38fcaSMauro Carvalho Chehab.. _V4L2-BUF-CAP-SUPPORTS-REQUESTS: 12754f38fcaSMauro Carvalho Chehab.. _V4L2-BUF-CAP-SUPPORTS-ORPHANED-BUFS: 12854f38fcaSMauro Carvalho Chehab.. _V4L2-BUF-CAP-SUPPORTS-M2M-HOLD-CAPTURE-BUF: 129*ac53503eSSergey Senozhatsky.. _V4L2-BUF-CAP-SUPPORTS-MMAP-CACHE-HINTS: 13054f38fcaSMauro Carvalho Chehab 13154f38fcaSMauro Carvalho Chehab.. cssclass:: longtable 13254f38fcaSMauro Carvalho Chehab 13354f38fcaSMauro Carvalho Chehab.. flat-table:: V4L2 Buffer Capabilities Flags 13454f38fcaSMauro Carvalho Chehab :header-rows: 0 13554f38fcaSMauro Carvalho Chehab :stub-columns: 0 13654f38fcaSMauro Carvalho Chehab :widths: 3 1 4 13754f38fcaSMauro Carvalho Chehab 13854f38fcaSMauro Carvalho Chehab * - ``V4L2_BUF_CAP_SUPPORTS_MMAP`` 13954f38fcaSMauro Carvalho Chehab - 0x00000001 14054f38fcaSMauro Carvalho Chehab - This buffer type supports the ``V4L2_MEMORY_MMAP`` streaming mode. 14154f38fcaSMauro Carvalho Chehab * - ``V4L2_BUF_CAP_SUPPORTS_USERPTR`` 14254f38fcaSMauro Carvalho Chehab - 0x00000002 14354f38fcaSMauro Carvalho Chehab - This buffer type supports the ``V4L2_MEMORY_USERPTR`` streaming mode. 14454f38fcaSMauro Carvalho Chehab * - ``V4L2_BUF_CAP_SUPPORTS_DMABUF`` 14554f38fcaSMauro Carvalho Chehab - 0x00000004 14654f38fcaSMauro Carvalho Chehab - This buffer type supports the ``V4L2_MEMORY_DMABUF`` streaming mode. 14754f38fcaSMauro Carvalho Chehab * - ``V4L2_BUF_CAP_SUPPORTS_REQUESTS`` 14854f38fcaSMauro Carvalho Chehab - 0x00000008 14954f38fcaSMauro Carvalho Chehab - This buffer type supports :ref:`requests <media-request-api>`. 15054f38fcaSMauro Carvalho Chehab * - ``V4L2_BUF_CAP_SUPPORTS_ORPHANED_BUFS`` 15154f38fcaSMauro Carvalho Chehab - 0x00000010 15254f38fcaSMauro Carvalho Chehab - The kernel allows calling :ref:`VIDIOC_REQBUFS` while buffers are still 15354f38fcaSMauro Carvalho Chehab mapped or exported via DMABUF. These orphaned buffers will be freed 15454f38fcaSMauro Carvalho Chehab when they are unmapped or when the exported DMABUF fds are closed. 15554f38fcaSMauro Carvalho Chehab * - ``V4L2_BUF_CAP_SUPPORTS_M2M_HOLD_CAPTURE_BUF`` 15654f38fcaSMauro Carvalho Chehab - 0x00000020 15754f38fcaSMauro Carvalho Chehab - Only valid for stateless decoders. If set, then userspace can set the 15854f38fcaSMauro Carvalho Chehab ``V4L2_BUF_FLAG_M2M_HOLD_CAPTURE_BUF`` flag to hold off on returning the 15954f38fcaSMauro Carvalho Chehab capture buffer until the OUTPUT timestamp changes. 160*ac53503eSSergey Senozhatsky * - ``V4L2_BUF_CAP_SUPPORTS_MMAP_CACHE_HINTS`` 161*ac53503eSSergey Senozhatsky - 0x00000040 162*ac53503eSSergey Senozhatsky - This capability is set by the driver to indicate that the queue supports 163*ac53503eSSergey Senozhatsky cache and memory management hints. However, it's only valid when the 164*ac53503eSSergey Senozhatsky queue is used for :ref:`memory mapping <mmap>` streaming I/O. See 165*ac53503eSSergey Senozhatsky :ref:`V4L2_FLAG_MEMORY_NON_CONSISTENT <V4L2-FLAG-MEMORY-NON-CONSISTENT>`, 166*ac53503eSSergey Senozhatsky :ref:`V4L2_BUF_FLAG_NO_CACHE_INVALIDATE <V4L2-BUF-FLAG-NO-CACHE-INVALIDATE>` and 167*ac53503eSSergey Senozhatsky :ref:`V4L2_BUF_FLAG_NO_CACHE_CLEAN <V4L2-BUF-FLAG-NO-CACHE-CLEAN>`. 168*ac53503eSSergey Senozhatsky 16954f38fcaSMauro Carvalho Chehab 17054f38fcaSMauro Carvalho ChehabReturn Value 17154f38fcaSMauro Carvalho Chehab============ 17254f38fcaSMauro Carvalho Chehab 17354f38fcaSMauro Carvalho ChehabOn success 0 is returned, on error -1 and the ``errno`` variable is set 17454f38fcaSMauro Carvalho Chehabappropriately. The generic error codes are described at the 17554f38fcaSMauro Carvalho Chehab:ref:`Generic Error Codes <gen-errors>` chapter. 17654f38fcaSMauro Carvalho Chehab 17754f38fcaSMauro Carvalho ChehabEINVAL 17854f38fcaSMauro Carvalho Chehab The buffer type (``type`` field) or the requested I/O method 17954f38fcaSMauro Carvalho Chehab (``memory``) is not supported. 180