1059b1c5bSMauro Carvalho Chehab.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later
2f9b2e8aaSMauro Carvalho Chehab.. c:namespace:: DTV.dmx
354f38fcaSMauro Carvalho Chehab
454f38fcaSMauro Carvalho Chehab.. _DMX_EXPBUF:
554f38fcaSMauro Carvalho Chehab
654f38fcaSMauro Carvalho Chehab****************
754f38fcaSMauro Carvalho Chehabioctl DMX_EXPBUF
854f38fcaSMauro Carvalho Chehab****************
954f38fcaSMauro Carvalho Chehab
1054f38fcaSMauro Carvalho ChehabName
1154f38fcaSMauro Carvalho Chehab====
1254f38fcaSMauro Carvalho Chehab
1354f38fcaSMauro Carvalho ChehabDMX_EXPBUF - Export a buffer as a DMABUF file descriptor.
1454f38fcaSMauro Carvalho Chehab
1554f38fcaSMauro Carvalho Chehab.. warning:: this API is still experimental
1654f38fcaSMauro Carvalho Chehab
1754f38fcaSMauro Carvalho ChehabSynopsis
1854f38fcaSMauro Carvalho Chehab========
1954f38fcaSMauro Carvalho Chehab
20f9b2e8aaSMauro Carvalho Chehab.. c:macro:: DMX_EXPBUF
2154f38fcaSMauro Carvalho Chehab
22f9b2e8aaSMauro Carvalho Chehab``int ioctl(int fd, DMX_EXPBUF, struct dmx_exportbuffer *argp)``
2354f38fcaSMauro Carvalho Chehab
2454f38fcaSMauro Carvalho ChehabArguments
2554f38fcaSMauro Carvalho Chehab=========
2654f38fcaSMauro Carvalho Chehab
2754f38fcaSMauro Carvalho Chehab``fd``
28f9b2e8aaSMauro Carvalho Chehab    File descriptor returned by :c:func:`open()`.
2954f38fcaSMauro Carvalho Chehab
3054f38fcaSMauro Carvalho Chehab``argp``
3154f38fcaSMauro Carvalho Chehab    Pointer to struct :c:type:`dmx_exportbuffer`.
3254f38fcaSMauro Carvalho Chehab
3354f38fcaSMauro Carvalho ChehabDescription
3454f38fcaSMauro Carvalho Chehab===========
3554f38fcaSMauro Carvalho Chehab
3654f38fcaSMauro Carvalho ChehabThis ioctl is an extension to the memory mapping I/O method.
3754f38fcaSMauro Carvalho ChehabIt can be used to export a buffer as a DMABUF file at any time after
3854f38fcaSMauro Carvalho Chehabbuffers have been allocated with the :ref:`DMX_REQBUFS` ioctl.
3954f38fcaSMauro Carvalho Chehab
4054f38fcaSMauro Carvalho ChehabTo export a buffer, applications fill struct :c:type:`dmx_exportbuffer`.
4154f38fcaSMauro Carvalho ChehabApplications must set the ``index`` field. Valid index numbers
4254f38fcaSMauro Carvalho Chehabrange from zero to the number of buffers allocated with :ref:`DMX_REQBUFS`
4354f38fcaSMauro Carvalho Chehab(struct :c:type:`dmx_requestbuffers` ``count``) minus one.
4454f38fcaSMauro Carvalho ChehabAdditional flags may be posted in the ``flags`` field. Refer to a manual
4554f38fcaSMauro Carvalho Chehabfor open() for details. Currently only O_CLOEXEC, O_RDONLY, O_WRONLY,
4654f38fcaSMauro Carvalho Chehaband O_RDWR are supported.
4754f38fcaSMauro Carvalho ChehabAll other fields must be set to zero. In the
4854f38fcaSMauro Carvalho Chehabcase of multi-planar API, every plane is exported separately using
4954f38fcaSMauro Carvalho Chehabmultiple :ref:`DMX_EXPBUF` calls.
5054f38fcaSMauro Carvalho Chehab
5154f38fcaSMauro Carvalho ChehabAfter calling :ref:`DMX_EXPBUF` the ``fd`` field will be set by a
5254f38fcaSMauro Carvalho Chehabdriver, on success. This is a DMABUF file descriptor. The application may
5354f38fcaSMauro Carvalho Chehabpass it to other DMABUF-aware devices. It is recommended to close a DMABUF
5454f38fcaSMauro Carvalho Chehabfile when it is no longer used to allow the associated memory to be reclaimed.
5554f38fcaSMauro Carvalho Chehab
5654f38fcaSMauro Carvalho ChehabExamples
5754f38fcaSMauro Carvalho Chehab========
5854f38fcaSMauro Carvalho Chehab
5954f38fcaSMauro Carvalho Chehab.. code-block:: c
6054f38fcaSMauro Carvalho Chehab
6154f38fcaSMauro Carvalho Chehab    int buffer_export(int v4lfd, enum dmx_buf_type bt, int index, int *dmafd)
6254f38fcaSMauro Carvalho Chehab    {
6354f38fcaSMauro Carvalho Chehab	struct dmx_exportbuffer expbuf;
6454f38fcaSMauro Carvalho Chehab
6554f38fcaSMauro Carvalho Chehab	memset(&expbuf, 0, sizeof(expbuf));
6654f38fcaSMauro Carvalho Chehab	expbuf.type = bt;
6754f38fcaSMauro Carvalho Chehab	expbuf.index = index;
6854f38fcaSMauro Carvalho Chehab	if (ioctl(v4lfd, DMX_EXPBUF, &expbuf) == -1) {
6954f38fcaSMauro Carvalho Chehab	    perror("DMX_EXPBUF");
7054f38fcaSMauro Carvalho Chehab	    return -1;
7154f38fcaSMauro Carvalho Chehab	}
7254f38fcaSMauro Carvalho Chehab
7354f38fcaSMauro Carvalho Chehab	*dmafd = expbuf.fd;
7454f38fcaSMauro Carvalho Chehab
7554f38fcaSMauro Carvalho Chehab	return 0;
7654f38fcaSMauro Carvalho Chehab    }
7754f38fcaSMauro Carvalho Chehab
7854f38fcaSMauro Carvalho ChehabReturn Value
7954f38fcaSMauro Carvalho Chehab============
8054f38fcaSMauro Carvalho Chehab
8154f38fcaSMauro Carvalho ChehabOn success 0 is returned, on error -1 and the ``errno`` variable is set
8254f38fcaSMauro Carvalho Chehabappropriately. The generic error codes are described at the
8354f38fcaSMauro Carvalho Chehab:ref:`Generic Error Codes <gen-errors>` chapter.
8454f38fcaSMauro Carvalho Chehab
8554f38fcaSMauro Carvalho ChehabEINVAL
8654f38fcaSMauro Carvalho Chehab    A queue is not in MMAP mode or DMABUF exporting is not supported or
8754f38fcaSMauro Carvalho Chehab    ``flags`` or ``index`` fields are invalid.
88