162306a36Sopenharmony_ci.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later 262306a36Sopenharmony_ci.. c:namespace:: V4L 362306a36Sopenharmony_ci 462306a36Sopenharmony_ci.. _VIDIOC_CREATE_BUFS: 562306a36Sopenharmony_ci 662306a36Sopenharmony_ci************************ 762306a36Sopenharmony_ciioctl VIDIOC_CREATE_BUFS 862306a36Sopenharmony_ci************************ 962306a36Sopenharmony_ci 1062306a36Sopenharmony_ciName 1162306a36Sopenharmony_ci==== 1262306a36Sopenharmony_ci 1362306a36Sopenharmony_ciVIDIOC_CREATE_BUFS - Create buffers for Memory Mapped or User Pointer or DMA Buffer I/O 1462306a36Sopenharmony_ci 1562306a36Sopenharmony_ciSynopsis 1662306a36Sopenharmony_ci======== 1762306a36Sopenharmony_ci 1862306a36Sopenharmony_ci.. c:macro:: VIDIOC_CREATE_BUFS 1962306a36Sopenharmony_ci 2062306a36Sopenharmony_ci``int ioctl(int fd, VIDIOC_CREATE_BUFS, struct v4l2_create_buffers *argp)`` 2162306a36Sopenharmony_ci 2262306a36Sopenharmony_ciArguments 2362306a36Sopenharmony_ci========= 2462306a36Sopenharmony_ci 2562306a36Sopenharmony_ci``fd`` 2662306a36Sopenharmony_ci File descriptor returned by :c:func:`open()`. 2762306a36Sopenharmony_ci 2862306a36Sopenharmony_ci``argp`` 2962306a36Sopenharmony_ci Pointer to struct :c:type:`v4l2_create_buffers`. 3062306a36Sopenharmony_ci 3162306a36Sopenharmony_ciDescription 3262306a36Sopenharmony_ci=========== 3362306a36Sopenharmony_ci 3462306a36Sopenharmony_ciThis ioctl is used to create buffers for :ref:`memory mapped <mmap>` 3562306a36Sopenharmony_cior :ref:`user pointer <userp>` or :ref:`DMA buffer <dmabuf>` I/O. It 3662306a36Sopenharmony_cican be used as an alternative or in addition to the 3762306a36Sopenharmony_ci:ref:`VIDIOC_REQBUFS` ioctl, when a tighter control 3862306a36Sopenharmony_ciover buffers is required. This ioctl can be called multiple times to 3962306a36Sopenharmony_cicreate buffers of different sizes. 4062306a36Sopenharmony_ci 4162306a36Sopenharmony_ciTo allocate the device buffers applications must initialize the relevant 4262306a36Sopenharmony_cifields of the struct :c:type:`v4l2_create_buffers` structure. The 4362306a36Sopenharmony_ci``count`` field must be set to the number of requested buffers, the 4462306a36Sopenharmony_ci``memory`` field specifies the requested I/O method and the ``reserved`` 4562306a36Sopenharmony_ciarray must be zeroed. 4662306a36Sopenharmony_ci 4762306a36Sopenharmony_ciThe ``format`` field specifies the image format that the buffers must be 4862306a36Sopenharmony_ciable to handle. The application has to fill in this struct 4962306a36Sopenharmony_ci:c:type:`v4l2_format`. Usually this will be done using the 5062306a36Sopenharmony_ci:ref:`VIDIOC_TRY_FMT <VIDIOC_G_FMT>` or 5162306a36Sopenharmony_ci:ref:`VIDIOC_G_FMT <VIDIOC_G_FMT>` ioctls to ensure that the 5262306a36Sopenharmony_cirequested format is supported by the driver. Based on the format's 5362306a36Sopenharmony_ci``type`` field the requested buffer size (for single-planar) or plane 5462306a36Sopenharmony_cisizes (for multi-planar formats) will be used for the allocated buffers. 5562306a36Sopenharmony_ciThe driver may return an error if the size(s) are not supported by the 5662306a36Sopenharmony_cihardware (usually because they are too small). 5762306a36Sopenharmony_ci 5862306a36Sopenharmony_ciThe buffers created by this ioctl will have as minimum size the size 5962306a36Sopenharmony_cidefined by the ``format.pix.sizeimage`` field (or the corresponding 6062306a36Sopenharmony_cifields for other format types). Usually if the ``format.pix.sizeimage`` 6162306a36Sopenharmony_cifield is less than the minimum required for the given format, then an 6262306a36Sopenharmony_cierror will be returned since drivers will typically not allow this. If 6362306a36Sopenharmony_ciit is larger, then the value will be used as-is. In other words, the 6462306a36Sopenharmony_cidriver may reject the requested size, but if it is accepted the driver 6562306a36Sopenharmony_ciwill use it unchanged. 6662306a36Sopenharmony_ci 6762306a36Sopenharmony_ciWhen the ioctl is called with a pointer to this structure the driver 6862306a36Sopenharmony_ciwill attempt to allocate up to the requested number of buffers and store 6962306a36Sopenharmony_cithe actual number allocated and the starting index in the ``count`` and 7062306a36Sopenharmony_cithe ``index`` fields respectively. On return ``count`` can be smaller 7162306a36Sopenharmony_cithan the number requested. 7262306a36Sopenharmony_ci 7362306a36Sopenharmony_ci.. c:type:: v4l2_create_buffers 7462306a36Sopenharmony_ci 7562306a36Sopenharmony_ci.. tabularcolumns:: |p{4.4cm}|p{4.4cm}|p{8.5cm}| 7662306a36Sopenharmony_ci 7762306a36Sopenharmony_ci.. flat-table:: struct v4l2_create_buffers 7862306a36Sopenharmony_ci :header-rows: 0 7962306a36Sopenharmony_ci :stub-columns: 0 8062306a36Sopenharmony_ci :widths: 1 1 2 8162306a36Sopenharmony_ci 8262306a36Sopenharmony_ci * - __u32 8362306a36Sopenharmony_ci - ``index`` 8462306a36Sopenharmony_ci - The starting buffer index, returned by the driver. 8562306a36Sopenharmony_ci * - __u32 8662306a36Sopenharmony_ci - ``count`` 8762306a36Sopenharmony_ci - The number of buffers requested or granted. If count == 0, then 8862306a36Sopenharmony_ci :ref:`VIDIOC_CREATE_BUFS` will set ``index`` to the current number of 8962306a36Sopenharmony_ci created buffers, and it will check the validity of ``memory`` and 9062306a36Sopenharmony_ci ``format.type``. If those are invalid -1 is returned and errno is 9162306a36Sopenharmony_ci set to ``EINVAL`` error code, otherwise :ref:`VIDIOC_CREATE_BUFS` returns 9262306a36Sopenharmony_ci 0. It will never set errno to ``EBUSY`` error code in this particular 9362306a36Sopenharmony_ci case. 9462306a36Sopenharmony_ci * - __u32 9562306a36Sopenharmony_ci - ``memory`` 9662306a36Sopenharmony_ci - Applications set this field to ``V4L2_MEMORY_MMAP``, 9762306a36Sopenharmony_ci ``V4L2_MEMORY_DMABUF`` or ``V4L2_MEMORY_USERPTR``. See 9862306a36Sopenharmony_ci :c:type:`v4l2_memory` 9962306a36Sopenharmony_ci * - struct :c:type:`v4l2_format` 10062306a36Sopenharmony_ci - ``format`` 10162306a36Sopenharmony_ci - Filled in by the application, preserved by the driver. 10262306a36Sopenharmony_ci * - __u32 10362306a36Sopenharmony_ci - ``capabilities`` 10462306a36Sopenharmony_ci - Set by the driver. If 0, then the driver doesn't support 10562306a36Sopenharmony_ci capabilities. In that case all you know is that the driver is 10662306a36Sopenharmony_ci guaranteed to support ``V4L2_MEMORY_MMAP`` and *might* support 10762306a36Sopenharmony_ci other :c:type:`v4l2_memory` types. It will not support any other 10862306a36Sopenharmony_ci capabilities. See :ref:`here <v4l2-buf-capabilities>` for a list of the 10962306a36Sopenharmony_ci capabilities. 11062306a36Sopenharmony_ci 11162306a36Sopenharmony_ci If you want to just query the capabilities without making any 11262306a36Sopenharmony_ci other changes, then set ``count`` to 0, ``memory`` to 11362306a36Sopenharmony_ci ``V4L2_MEMORY_MMAP`` and ``format.type`` to the buffer type. 11462306a36Sopenharmony_ci 11562306a36Sopenharmony_ci * - __u32 11662306a36Sopenharmony_ci - ``flags`` 11762306a36Sopenharmony_ci - Specifies additional buffer management attributes. 11862306a36Sopenharmony_ci See :ref:`memory-flags`. 11962306a36Sopenharmony_ci 12062306a36Sopenharmony_ci * - __u32 12162306a36Sopenharmony_ci - ``reserved``\ [6] 12262306a36Sopenharmony_ci - A place holder for future extensions. Drivers and applications 12362306a36Sopenharmony_ci must set the array to zero. 12462306a36Sopenharmony_ci 12562306a36Sopenharmony_ciReturn Value 12662306a36Sopenharmony_ci============ 12762306a36Sopenharmony_ci 12862306a36Sopenharmony_ciOn success 0 is returned, on error -1 and the ``errno`` variable is set 12962306a36Sopenharmony_ciappropriately. The generic error codes are described at the 13062306a36Sopenharmony_ci:ref:`Generic Error Codes <gen-errors>` chapter. 13162306a36Sopenharmony_ci 13262306a36Sopenharmony_ciENOMEM 13362306a36Sopenharmony_ci No memory to allocate buffers for :ref:`memory mapped <mmap>` I/O. 13462306a36Sopenharmony_ci 13562306a36Sopenharmony_ciEINVAL 13662306a36Sopenharmony_ci The buffer type (``format.type`` field), requested I/O method 13762306a36Sopenharmony_ci (``memory``) or format (``format`` field) is not valid. 138