18c2ecf20Sopenharmony_ci.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later
28c2ecf20Sopenharmony_ci.. c:namespace:: V4L
38c2ecf20Sopenharmony_ci
48c2ecf20Sopenharmony_ci.. _VIDIOC_CREATE_BUFS:
58c2ecf20Sopenharmony_ci
68c2ecf20Sopenharmony_ci************************
78c2ecf20Sopenharmony_ciioctl VIDIOC_CREATE_BUFS
88c2ecf20Sopenharmony_ci************************
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ciName
118c2ecf20Sopenharmony_ci====
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_ciVIDIOC_CREATE_BUFS - Create buffers for Memory Mapped or User Pointer or DMA Buffer I/O
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ciSynopsis
168c2ecf20Sopenharmony_ci========
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_ci.. c:macro:: VIDIOC_CREATE_BUFS
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_ci``int ioctl(int fd, VIDIOC_CREATE_BUFS, struct v4l2_create_buffers *argp)``
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_ciArguments
238c2ecf20Sopenharmony_ci=========
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_ci``fd``
268c2ecf20Sopenharmony_ci    File descriptor returned by :c:func:`open()`.
278c2ecf20Sopenharmony_ci
288c2ecf20Sopenharmony_ci``argp``
298c2ecf20Sopenharmony_ci    Pointer to struct :c:type:`v4l2_create_buffers`.
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_ciDescription
328c2ecf20Sopenharmony_ci===========
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ciThis ioctl is used to create buffers for :ref:`memory mapped <mmap>`
358c2ecf20Sopenharmony_cior :ref:`user pointer <userp>` or :ref:`DMA buffer <dmabuf>` I/O. It
368c2ecf20Sopenharmony_cican be used as an alternative or in addition to the
378c2ecf20Sopenharmony_ci:ref:`VIDIOC_REQBUFS` ioctl, when a tighter control
388c2ecf20Sopenharmony_ciover buffers is required. This ioctl can be called multiple times to
398c2ecf20Sopenharmony_cicreate buffers of different sizes.
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_ciTo allocate the device buffers applications must initialize the relevant
428c2ecf20Sopenharmony_cifields of the struct :c:type:`v4l2_create_buffers` structure. The
438c2ecf20Sopenharmony_ci``count`` field must be set to the number of requested buffers, the
448c2ecf20Sopenharmony_ci``memory`` field specifies the requested I/O method and the ``reserved``
458c2ecf20Sopenharmony_ciarray must be zeroed.
468c2ecf20Sopenharmony_ci
478c2ecf20Sopenharmony_ciThe ``format`` field specifies the image format that the buffers must be
488c2ecf20Sopenharmony_ciable to handle. The application has to fill in this struct
498c2ecf20Sopenharmony_ci:c:type:`v4l2_format`. Usually this will be done using the
508c2ecf20Sopenharmony_ci:ref:`VIDIOC_TRY_FMT <VIDIOC_G_FMT>` or
518c2ecf20Sopenharmony_ci:ref:`VIDIOC_G_FMT <VIDIOC_G_FMT>` ioctls to ensure that the
528c2ecf20Sopenharmony_cirequested format is supported by the driver. Based on the format's
538c2ecf20Sopenharmony_ci``type`` field the requested buffer size (for single-planar) or plane
548c2ecf20Sopenharmony_cisizes (for multi-planar formats) will be used for the allocated buffers.
558c2ecf20Sopenharmony_ciThe driver may return an error if the size(s) are not supported by the
568c2ecf20Sopenharmony_cihardware (usually because they are too small).
578c2ecf20Sopenharmony_ci
588c2ecf20Sopenharmony_ciThe buffers created by this ioctl will have as minimum size the size
598c2ecf20Sopenharmony_cidefined by the ``format.pix.sizeimage`` field (or the corresponding
608c2ecf20Sopenharmony_cifields for other format types). Usually if the ``format.pix.sizeimage``
618c2ecf20Sopenharmony_cifield is less than the minimum required for the given format, then an
628c2ecf20Sopenharmony_cierror will be returned since drivers will typically not allow this. If
638c2ecf20Sopenharmony_ciit is larger, then the value will be used as-is. In other words, the
648c2ecf20Sopenharmony_cidriver may reject the requested size, but if it is accepted the driver
658c2ecf20Sopenharmony_ciwill use it unchanged.
668c2ecf20Sopenharmony_ci
678c2ecf20Sopenharmony_ciWhen the ioctl is called with a pointer to this structure the driver
688c2ecf20Sopenharmony_ciwill attempt to allocate up to the requested number of buffers and store
698c2ecf20Sopenharmony_cithe actual number allocated and the starting index in the ``count`` and
708c2ecf20Sopenharmony_cithe ``index`` fields respectively. On return ``count`` can be smaller
718c2ecf20Sopenharmony_cithan the number requested.
728c2ecf20Sopenharmony_ci
738c2ecf20Sopenharmony_ci.. c:type:: v4l2_create_buffers
748c2ecf20Sopenharmony_ci
758c2ecf20Sopenharmony_ci.. tabularcolumns:: |p{4.4cm}|p{4.4cm}|p{8.7cm}|
768c2ecf20Sopenharmony_ci
778c2ecf20Sopenharmony_ci.. flat-table:: struct v4l2_create_buffers
788c2ecf20Sopenharmony_ci    :header-rows:  0
798c2ecf20Sopenharmony_ci    :stub-columns: 0
808c2ecf20Sopenharmony_ci    :widths:       1 1 2
818c2ecf20Sopenharmony_ci
828c2ecf20Sopenharmony_ci    * - __u32
838c2ecf20Sopenharmony_ci      - ``index``
848c2ecf20Sopenharmony_ci      - The starting buffer index, returned by the driver.
858c2ecf20Sopenharmony_ci    * - __u32
868c2ecf20Sopenharmony_ci      - ``count``
878c2ecf20Sopenharmony_ci      - The number of buffers requested or granted. If count == 0, then
888c2ecf20Sopenharmony_ci	:ref:`VIDIOC_CREATE_BUFS` will set ``index`` to the current number of
898c2ecf20Sopenharmony_ci	created buffers, and it will check the validity of ``memory`` and
908c2ecf20Sopenharmony_ci	``format.type``. If those are invalid -1 is returned and errno is
918c2ecf20Sopenharmony_ci	set to ``EINVAL`` error code, otherwise :ref:`VIDIOC_CREATE_BUFS` returns
928c2ecf20Sopenharmony_ci	0. It will never set errno to ``EBUSY`` error code in this particular
938c2ecf20Sopenharmony_ci	case.
948c2ecf20Sopenharmony_ci    * - __u32
958c2ecf20Sopenharmony_ci      - ``memory``
968c2ecf20Sopenharmony_ci      - Applications set this field to ``V4L2_MEMORY_MMAP``,
978c2ecf20Sopenharmony_ci	``V4L2_MEMORY_DMABUF`` or ``V4L2_MEMORY_USERPTR``. See
988c2ecf20Sopenharmony_ci	:c:type:`v4l2_memory`
998c2ecf20Sopenharmony_ci    * - struct :c:type:`v4l2_format`
1008c2ecf20Sopenharmony_ci      - ``format``
1018c2ecf20Sopenharmony_ci      - Filled in by the application, preserved by the driver.
1028c2ecf20Sopenharmony_ci    * - __u32
1038c2ecf20Sopenharmony_ci      - ``capabilities``
1048c2ecf20Sopenharmony_ci      - Set by the driver. If 0, then the driver doesn't support
1058c2ecf20Sopenharmony_ci        capabilities. In that case all you know is that the driver is
1068c2ecf20Sopenharmony_ci	guaranteed to support ``V4L2_MEMORY_MMAP`` and *might* support
1078c2ecf20Sopenharmony_ci	other :c:type:`v4l2_memory` types. It will not support any other
1088c2ecf20Sopenharmony_ci	capabilities. See :ref:`here <v4l2-buf-capabilities>` for a list of the
1098c2ecf20Sopenharmony_ci	capabilities.
1108c2ecf20Sopenharmony_ci
1118c2ecf20Sopenharmony_ci	If you want to just query the capabilities without making any
1128c2ecf20Sopenharmony_ci	other changes, then set ``count`` to 0, ``memory`` to
1138c2ecf20Sopenharmony_ci	``V4L2_MEMORY_MMAP`` and ``format.type`` to the buffer type.
1148c2ecf20Sopenharmony_ci
1158c2ecf20Sopenharmony_ci    * - __u32
1168c2ecf20Sopenharmony_ci      - ``reserved``\ [7]
1178c2ecf20Sopenharmony_ci      - A place holder for future extensions. Drivers and applications
1188c2ecf20Sopenharmony_ci	must set the array to zero.
1198c2ecf20Sopenharmony_ci
1208c2ecf20Sopenharmony_ciReturn Value
1218c2ecf20Sopenharmony_ci============
1228c2ecf20Sopenharmony_ci
1238c2ecf20Sopenharmony_ciOn success 0 is returned, on error -1 and the ``errno`` variable is set
1248c2ecf20Sopenharmony_ciappropriately. The generic error codes are described at the
1258c2ecf20Sopenharmony_ci:ref:`Generic Error Codes <gen-errors>` chapter.
1268c2ecf20Sopenharmony_ci
1278c2ecf20Sopenharmony_ciENOMEM
1288c2ecf20Sopenharmony_ci    No memory to allocate buffers for :ref:`memory mapped <mmap>` I/O.
1298c2ecf20Sopenharmony_ci
1308c2ecf20Sopenharmony_ciEINVAL
1318c2ecf20Sopenharmony_ci    The buffer type (``format.type`` field), requested I/O method
1328c2ecf20Sopenharmony_ci    (``memory``) or format (``format`` field) is not valid.
133