brintos

brintos / linux-shallow public Read only

0
0
Text · 8.0 KiB · daf9a66 Raw
208 lines · plain
1.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later2.. c:namespace:: V4L3 4.. _VIDIOC_REQBUFS:5 6********************7ioctl VIDIOC_REQBUFS8********************9 10Name11====12 13VIDIOC_REQBUFS - Initiate Memory Mapping, User Pointer I/O or DMA buffer I/O14 15Synopsis16========17 18.. c:macro:: VIDIOC_REQBUFS19 20``int ioctl(int fd, VIDIOC_REQBUFS, struct v4l2_requestbuffers *argp)``21 22Arguments23=========24 25``fd``26    File descriptor returned by :c:func:`open()`.27 28``argp``29    Pointer to struct :c:type:`v4l2_requestbuffers`.30 31Description32===========33 34This ioctl is used to initiate :ref:`memory mapped <mmap>`,35:ref:`user pointer <userp>` or :ref:`DMABUF <dmabuf>` based I/O.36Memory mapped buffers are located in device memory and must be allocated37with this ioctl before they can be mapped into the application's address38space. User buffers are allocated by applications themselves, and this39ioctl is merely used to switch the driver into user pointer I/O mode and40to setup some internal structures. Similarly, DMABUF buffers are41allocated by applications through a device driver, and this ioctl only42configures the driver into DMABUF I/O mode without performing any direct43allocation.44 45To allocate device buffers applications initialize all fields of the46struct :c:type:`v4l2_requestbuffers` structure. They set the ``type``47field to the respective stream or buffer type, the ``count`` field to48the desired number of buffers, ``memory`` must be set to the requested49I/O method and the ``reserved`` array must be zeroed. When the ioctl is50called with a pointer to this structure the driver will attempt to51allocate the requested number of buffers and it stores the actual number52allocated in the ``count`` field. It can be smaller than the number53requested, even zero, when the driver runs out of free memory. A larger54number is also possible when the driver requires more buffers to55function correctly. For example video output requires at least two56buffers, one displayed and one filled by the application.57 58When the I/O method is not supported the ioctl returns an ``EINVAL`` error59code.60 61Applications can call :ref:`VIDIOC_REQBUFS` again to change the number of62buffers. Note that if any buffers are still mapped or exported via DMABUF,63then :ref:`VIDIOC_REQBUFS` can only succeed if the64``V4L2_BUF_CAP_SUPPORTS_ORPHANED_BUFS`` capability is set. Otherwise65:ref:`VIDIOC_REQBUFS` will return the ``EBUSY`` error code.66If ``V4L2_BUF_CAP_SUPPORTS_ORPHANED_BUFS`` is set, then these buffers are67orphaned and will be freed when they are unmapped or when the exported DMABUF68fds are closed. A ``count`` value of zero frees or orphans all buffers, after69aborting or finishing any DMA in progress, an implicit70:ref:`VIDIOC_STREAMOFF <VIDIOC_STREAMON>`.71 72.. c:type:: v4l2_requestbuffers73 74.. tabularcolumns:: |p{4.4cm}|p{4.4cm}|p{8.5cm}|75 76.. cssclass:: longtable77 78.. flat-table:: struct v4l2_requestbuffers79    :header-rows:  080    :stub-columns: 081    :widths:       1 1 282 83    * - __u3284      - ``count``85      - The number of buffers requested or granted.86    * - __u3287      - ``type``88      - Type of the stream or buffers, this is the same as the struct89	:c:type:`v4l2_format` ``type`` field. See90	:c:type:`v4l2_buf_type` for valid values.91    * - __u3292      - ``memory``93      - Applications set this field to ``V4L2_MEMORY_MMAP``,94	``V4L2_MEMORY_DMABUF`` or ``V4L2_MEMORY_USERPTR``. See95	:c:type:`v4l2_memory`.96    * - __u3297      - ``capabilities``98      - Set by the driver. If 0, then the driver doesn't support99        capabilities. In that case all you know is that the driver is100	guaranteed to support ``V4L2_MEMORY_MMAP`` and *might* support101	other :c:type:`v4l2_memory` types. It will not support any other102	capabilities.103 104	If you want to query the capabilities with a minimum of side-effects,105	then this can be called with ``count`` set to 0, ``memory`` set to106	``V4L2_MEMORY_MMAP`` and ``type`` set to the buffer type. This will107	free any previously allocated buffers, so this is typically something108	that will be done at the start of the application.109    * - __u8110      - ``flags``111      - Specifies additional buffer management attributes.112	See :ref:`memory-flags`.113    * - __u8114      - ``reserved``\ [3]115      - Reserved for future extensions.116 117.. _v4l2-buf-capabilities:118.. _V4L2-BUF-CAP-SUPPORTS-MMAP:119.. _V4L2-BUF-CAP-SUPPORTS-USERPTR:120.. _V4L2-BUF-CAP-SUPPORTS-DMABUF:121.. _V4L2-BUF-CAP-SUPPORTS-REQUESTS:122.. _V4L2-BUF-CAP-SUPPORTS-ORPHANED-BUFS:123.. _V4L2-BUF-CAP-SUPPORTS-M2M-HOLD-CAPTURE-BUF:124.. _V4L2-BUF-CAP-SUPPORTS-MMAP-CACHE-HINTS:125.. _V4L2-BUF-CAP-SUPPORTS-MAX-NUM-BUFFERS:126.. _V4L2-BUF-CAP-SUPPORTS-REMOVE-BUFS:127 128.. flat-table:: V4L2 Buffer Capabilities Flags129    :header-rows:  0130    :stub-columns: 0131    :widths:       3 1 4132 133    * - ``V4L2_BUF_CAP_SUPPORTS_MMAP``134      - 0x00000001135      - This buffer type supports the ``V4L2_MEMORY_MMAP`` streaming mode.136    * - ``V4L2_BUF_CAP_SUPPORTS_USERPTR``137      - 0x00000002138      - This buffer type supports the ``V4L2_MEMORY_USERPTR`` streaming mode.139    * - ``V4L2_BUF_CAP_SUPPORTS_DMABUF``140      - 0x00000004141      - This buffer type supports the ``V4L2_MEMORY_DMABUF`` streaming mode.142    * - ``V4L2_BUF_CAP_SUPPORTS_REQUESTS``143      - 0x00000008144      - This buffer type supports :ref:`requests <media-request-api>`.145    * - ``V4L2_BUF_CAP_SUPPORTS_ORPHANED_BUFS``146      - 0x00000010147      - The kernel allows calling :ref:`VIDIOC_REQBUFS` while buffers are still148        mapped or exported via DMABUF. These orphaned buffers will be freed149        when they are unmapped or when the exported DMABUF fds are closed.150    * - ``V4L2_BUF_CAP_SUPPORTS_M2M_HOLD_CAPTURE_BUF``151      - 0x00000020152      - Only valid for stateless decoders. If set, then userspace can set the153        ``V4L2_BUF_FLAG_M2M_HOLD_CAPTURE_BUF`` flag to hold off on returning the154	capture buffer until the OUTPUT timestamp changes.155    * - ``V4L2_BUF_CAP_SUPPORTS_MMAP_CACHE_HINTS``156      - 0x00000040157      - This capability is set by the driver to indicate that the queue supports158        cache and memory management hints. However, it's only valid when the159        queue is used for :ref:`memory mapping <mmap>` streaming I/O. See160        :ref:`V4L2_BUF_FLAG_NO_CACHE_INVALIDATE <V4L2-BUF-FLAG-NO-CACHE-INVALIDATE>`,161        :ref:`V4L2_BUF_FLAG_NO_CACHE_CLEAN <V4L2-BUF-FLAG-NO-CACHE-CLEAN>` and162        :ref:`V4L2_MEMORY_FLAG_NON_COHERENT <V4L2-MEMORY-FLAG-NON-COHERENT>`.163    * - ``V4L2_BUF_CAP_SUPPORTS_MAX_NUM_BUFFERS``164      - 0x00000080165      - If set, then the ``max_num_buffers`` field in ``struct v4l2_create_buffers``166        is valid. If not set, then the maximum is ``VIDEO_MAX_FRAME`` buffers.167    * - ``V4L2_BUF_CAP_SUPPORTS_REMOVE_BUFS``168      - 0x00000100169      - If set, then ``VIDIOC_REMOVE_BUFS`` is supported.170 171.. _memory-flags:172.. _V4L2-MEMORY-FLAG-NON-COHERENT:173 174.. flat-table:: Memory Consistency Flags175    :header-rows:  0176    :stub-columns: 0177    :widths:       3 1 4178 179    * - ``V4L2_MEMORY_FLAG_NON_COHERENT``180      - 0x00000001181      - A buffer is allocated either in coherent (it will be automatically182	coherent between the CPU and the bus) or non-coherent memory. The183	latter can provide performance gains, for instance the CPU cache184	sync/flush operations can be avoided if the buffer is accessed by the185	corresponding device only and the CPU does not read/write to/from that186	buffer. However, this requires extra care from the driver -- it must187	guarantee memory consistency by issuing a cache flush/sync when188	consistency is needed. If this flag is set V4L2 will attempt to189	allocate the buffer in non-coherent memory. The flag takes effect190	only if the buffer is used for :ref:`memory mapping <mmap>` I/O and the191	queue reports the :ref:`V4L2_BUF_CAP_SUPPORTS_MMAP_CACHE_HINTS192	<V4L2-BUF-CAP-SUPPORTS-MMAP-CACHE-HINTS>` capability.193 194.. raw:: latex195 196   \normalsize197 198Return Value199============200 201On success 0 is returned, on error -1 and the ``errno`` variable is set202appropriately. The generic error codes are described at the203:ref:`Generic Error Codes <gen-errors>` chapter.204 205EINVAL206    The buffer type (``type`` field) or the requested I/O method207    (``memory``) is not supported.208