^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) .. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) .. c:namespace:: DTV.dmx
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) .. _DMX_EXPBUF:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) ****************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) ioctl DMX_EXPBUF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) ****************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) Name
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) ====
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) DMX_EXPBUF - Export a buffer as a DMABUF file descriptor.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) .. warning:: this API is still experimental
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) Synopsis
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) ========
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) .. c:macro:: DMX_EXPBUF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) ``int ioctl(int fd, DMX_EXPBUF, struct dmx_exportbuffer *argp)``
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) Arguments
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) =========
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) ``fd``
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) File descriptor returned by :c:func:`open()`.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) ``argp``
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) Pointer to struct :c:type:`dmx_exportbuffer`.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) Description
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) ===========
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) This ioctl is an extension to the memory mapping I/O method.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) It can be used to export a buffer as a DMABUF file at any time after
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) buffers have been allocated with the :ref:`DMX_REQBUFS` ioctl.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) To export a buffer, applications fill struct :c:type:`dmx_exportbuffer`.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) Applications must set the ``index`` field. Valid index numbers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) range from zero to the number of buffers allocated with :ref:`DMX_REQBUFS`
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) (struct :c:type:`dmx_requestbuffers` ``count``) minus one.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) Additional flags may be posted in the ``flags`` field. Refer to a manual
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) for open() for details. Currently only O_CLOEXEC, O_RDONLY, O_WRONLY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) and O_RDWR are supported.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) All other fields must be set to zero. In the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) case of multi-planar API, every plane is exported separately using
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) multiple :ref:`DMX_EXPBUF` calls.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) After calling :ref:`DMX_EXPBUF` the ``fd`` field will be set by a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) driver, on success. This is a DMABUF file descriptor. The application may
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) pass it to other DMABUF-aware devices. It is recommended to close a DMABUF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) file when it is no longer used to allow the associated memory to be reclaimed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) Examples
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) ========
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) .. code-block:: c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) int buffer_export(int v4lfd, enum dmx_buf_type bt, int index, int *dmafd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) struct dmx_exportbuffer expbuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) memset(&expbuf, 0, sizeof(expbuf));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) expbuf.type = bt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) expbuf.index = index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) if (ioctl(v4lfd, DMX_EXPBUF, &expbuf) == -1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) perror("DMX_EXPBUF");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) *dmafd = expbuf.fd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) Return Value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) ============
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) On success 0 is returned, on error -1 and the ``errno`` variable is set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) appropriately. The generic error codes are described at the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) :ref:`Generic Error Codes <gen-errors>` chapter.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) EINVAL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) A queue is not in MMAP mode or DMABUF exporting is not supported or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) ``flags`` or ``index`` fields are invalid.