xref: /OK3568_Linux_fs/kernel/Documentation/userspace-api/media/dvb/dmx-expbuf.rst (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later
2*4882a593Smuzhiyun.. c:namespace:: DTV.dmx
3*4882a593Smuzhiyun
4*4882a593Smuzhiyun.. _DMX_EXPBUF:
5*4882a593Smuzhiyun
6*4882a593Smuzhiyun****************
7*4882a593Smuzhiyunioctl DMX_EXPBUF
8*4882a593Smuzhiyun****************
9*4882a593Smuzhiyun
10*4882a593SmuzhiyunName
11*4882a593Smuzhiyun====
12*4882a593Smuzhiyun
13*4882a593SmuzhiyunDMX_EXPBUF - Export a buffer as a DMABUF file descriptor.
14*4882a593Smuzhiyun
15*4882a593Smuzhiyun.. warning:: this API is still experimental
16*4882a593Smuzhiyun
17*4882a593SmuzhiyunSynopsis
18*4882a593Smuzhiyun========
19*4882a593Smuzhiyun
20*4882a593Smuzhiyun.. c:macro:: DMX_EXPBUF
21*4882a593Smuzhiyun
22*4882a593Smuzhiyun``int ioctl(int fd, DMX_EXPBUF, struct dmx_exportbuffer *argp)``
23*4882a593Smuzhiyun
24*4882a593SmuzhiyunArguments
25*4882a593Smuzhiyun=========
26*4882a593Smuzhiyun
27*4882a593Smuzhiyun``fd``
28*4882a593Smuzhiyun    File descriptor returned by :c:func:`open()`.
29*4882a593Smuzhiyun
30*4882a593Smuzhiyun``argp``
31*4882a593Smuzhiyun    Pointer to struct :c:type:`dmx_exportbuffer`.
32*4882a593Smuzhiyun
33*4882a593SmuzhiyunDescription
34*4882a593Smuzhiyun===========
35*4882a593Smuzhiyun
36*4882a593SmuzhiyunThis ioctl is an extension to the memory mapping I/O method.
37*4882a593SmuzhiyunIt can be used to export a buffer as a DMABUF file at any time after
38*4882a593Smuzhiyunbuffers have been allocated with the :ref:`DMX_REQBUFS` ioctl.
39*4882a593Smuzhiyun
40*4882a593SmuzhiyunTo export a buffer, applications fill struct :c:type:`dmx_exportbuffer`.
41*4882a593SmuzhiyunApplications must set the ``index`` field. Valid index numbers
42*4882a593Smuzhiyunrange from zero to the number of buffers allocated with :ref:`DMX_REQBUFS`
43*4882a593Smuzhiyun(struct :c:type:`dmx_requestbuffers` ``count``) minus one.
44*4882a593SmuzhiyunAdditional flags may be posted in the ``flags`` field. Refer to a manual
45*4882a593Smuzhiyunfor open() for details. Currently only O_CLOEXEC, O_RDONLY, O_WRONLY,
46*4882a593Smuzhiyunand O_RDWR are supported.
47*4882a593SmuzhiyunAll other fields must be set to zero. In the
48*4882a593Smuzhiyuncase of multi-planar API, every plane is exported separately using
49*4882a593Smuzhiyunmultiple :ref:`DMX_EXPBUF` calls.
50*4882a593Smuzhiyun
51*4882a593SmuzhiyunAfter calling :ref:`DMX_EXPBUF` the ``fd`` field will be set by a
52*4882a593Smuzhiyundriver, on success. This is a DMABUF file descriptor. The application may
53*4882a593Smuzhiyunpass it to other DMABUF-aware devices. It is recommended to close a DMABUF
54*4882a593Smuzhiyunfile when it is no longer used to allow the associated memory to be reclaimed.
55*4882a593Smuzhiyun
56*4882a593SmuzhiyunExamples
57*4882a593Smuzhiyun========
58*4882a593Smuzhiyun
59*4882a593Smuzhiyun.. code-block:: c
60*4882a593Smuzhiyun
61*4882a593Smuzhiyun    int buffer_export(int v4lfd, enum dmx_buf_type bt, int index, int *dmafd)
62*4882a593Smuzhiyun    {
63*4882a593Smuzhiyun	struct dmx_exportbuffer expbuf;
64*4882a593Smuzhiyun
65*4882a593Smuzhiyun	memset(&expbuf, 0, sizeof(expbuf));
66*4882a593Smuzhiyun	expbuf.type = bt;
67*4882a593Smuzhiyun	expbuf.index = index;
68*4882a593Smuzhiyun	if (ioctl(v4lfd, DMX_EXPBUF, &expbuf) == -1) {
69*4882a593Smuzhiyun	    perror("DMX_EXPBUF");
70*4882a593Smuzhiyun	    return -1;
71*4882a593Smuzhiyun	}
72*4882a593Smuzhiyun
73*4882a593Smuzhiyun	*dmafd = expbuf.fd;
74*4882a593Smuzhiyun
75*4882a593Smuzhiyun	return 0;
76*4882a593Smuzhiyun    }
77*4882a593Smuzhiyun
78*4882a593SmuzhiyunReturn Value
79*4882a593Smuzhiyun============
80*4882a593Smuzhiyun
81*4882a593SmuzhiyunOn success 0 is returned, on error -1 and the ``errno`` variable is set
82*4882a593Smuzhiyunappropriately. The generic error codes are described at the
83*4882a593Smuzhiyun:ref:`Generic Error Codes <gen-errors>` chapter.
84*4882a593Smuzhiyun
85*4882a593SmuzhiyunEINVAL
86*4882a593Smuzhiyun    A queue is not in MMAP mode or DMABUF exporting is not supported or
87*4882a593Smuzhiyun    ``flags`` or ``index`` fields are invalid.
88