← Documents Documentation/userspace-api/media/dvb/dmx-expbuf.rst GitHub 원문 ↗

Linux 6.18.37 · Userspace API / Media / DVB / Demux

ioctl DMX_EXPBUF

할당된 MMAP 버퍼를 DMABUF file descriptor로 내보내는 실험적 ioctl입니다.

Source pathDocumentation/userspace-api/media/dvb/dmx-expbuf.rst
Source versionLinux v6.18.37
TranslationDUJINLABS 전문 번역 + 해설

요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.

1. 요약·해설

원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.

요약·해설

dmx-expbuf.rst:1-87

DMX_EXPBUF는 DMX_REQBUFS로 할당한 MMAP 버퍼를 다른 DMABUF 인식 장치에 전달할 수 있는 fd로 내보냅니다. 인덱스와 플래그 검증, plane별 호출, 사용 후 close가 핵심입니다.

2. 영어 원문 전체

번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.

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

3. 한국어 전문 번역

영어 원문의 문단 순서와 의미를 유지한 전체 번역입니다. 코드, 함수명, symbol과 URL은 원문 표기를 유지합니다.

이름, 실험 상태와 호출 형식

1-22

이 문서는 GFDL-1.1-no-invariants-or-later 라이선스와 `DTV.dmx` C namespace를 사용하며 `DMX_EXPBUF` ioctl을 설명합니다.

`DMX_EXPBUF`는 버퍼 하나를 DMABUF file descriptor로 내보냅니다. 이 API는 아직 실험적이므로 호환성과 동작이 변경될 수 있다는 경고를 함께 적용해야 합니다.

호출 형식은 `int ioctl(int fd, DMX_EXPBUF, struct dmx_exportbuffer *argp)`입니다.

.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later
.. c:namespace:: DTV.dmx

.. _DMX_EXPBUF:

****************
ioctl DMX_EXPBUF
****************

Name
====

DMX_EXPBUF - Export a buffer as a DMABUF file descriptor.

.. warning:: this API is still experimental

Synopsis
========

.. c:macro:: DMX_EXPBUF

``int ioctl(int fd, DMX_EXPBUF, struct dmx_exportbuffer *argp)``

인자와 선행 조건

23-38

`fd`는 `open()`이 반환한 Demux 장치의 file descriptor이며, `argp`는 `struct dmx_exportbuffer`를 가리키는 포인터입니다.

이 ioctl은 memory mapping I/O 방식의 확장입니다. 애플리케이션이 `DMX_REQBUFS` ioctl로 버퍼를 할당한 뒤라면 언제든 버퍼를 DMABUF 파일로 내보낼 수 있습니다.

따라서 큐가 MMAP 모드가 아니거나 드라이버가 DMABUF 내보내기를 지원하지 않으면 이 호출을 사용할 수 없습니다.


Arguments
=========

``fd``
    File descriptor returned by :c:func:`open()`.

``argp``
    Pointer to struct :c:type:`dmx_exportbuffer`.

Description
===========

This ioctl is an extension to the memory mapping I/O method.
It can be used to export a buffer as a DMABUF file at any time after
buffers have been allocated with the :ref:`DMX_REQBUFS` ioctl.

dmx_exportbuffer 필드와 내보내기

39-55

애플리케이션은 `struct dmx_exportbuffer`를 채우고 반드시 `index` 필드를 설정합니다. 유효한 인덱스 범위는 0부터 `DMX_REQBUFS`로 할당한 버퍼 수, 즉 `struct dmx_requestbuffers`의 `count`에서 1을 뺀 값까지입니다.

`flags`에는 추가 플래그를 지정할 수 있으며 현재 `O_CLOEXEC`, `O_RDONLY`, `O_WRONLY`, `O_RDWR`만 지원합니다. 자세한 의미는 `open()` 매뉴얼을 참조하고, 그 밖의 모든 필드는 0으로 초기화해야 합니다.

multi-planar API에서는 각 plane을 여러 번의 `DMX_EXPBUF` 호출로 따로 내보냅니다.

호출이 성공하면 드라이버가 구조체의 `fd` 필드에 DMABUF file descriptor를 기록합니다. 애플리케이션은 이를 DMABUF를 인식하는 다른 장치로 전달할 수 있고, 더 이상 사용하지 않을 때 닫아 연결된 메모리가 회수되도록 하는 것이 좋습니다.

DMX_EXPBUF 입력 필드
항목설명
index0 이상 count - 1 이하의 내보낼 버퍼 번호
flagsO_CLOEXEC, O_RDONLY, O_WRONLY 또는 O_RDWR
기타 필드0으로 초기화
multi-planarplane마다 별도의 DMX_EXPBUF 호출

호출 전에 애플리케이션이 설정할 값을 정리합니다.

DMABUF 내보내기
DMX_REQBUFS로 MMAP 버퍼 할당dmx_exportbuffer를 0으로 초기화index와 필요한 flags 설정DMX_EXPBUF 호출반환된 fd를 사용하고 완료 후 close

할당된 MMAP 버퍼를 다른 장치와 공유할 수 있는 fd로 바꿉니다.


To export a buffer, applications fill struct :c:type:`dmx_exportbuffer`.
Applications must set the ``index`` field. Valid index numbers
range from zero to the number of buffers allocated with :ref:`DMX_REQBUFS`
(struct :c:type:`dmx_requestbuffers` ``count``) minus one.
Additional flags may be posted in the ``flags`` field. Refer to a manual
for open() for details. Currently only O_CLOEXEC, O_RDONLY, O_WRONLY,
and O_RDWR are supported.
All other fields must be set to zero. In the
case of multi-planar API, every plane is exported separately using
multiple :ref:`DMX_EXPBUF` calls.

After calling :ref:`DMX_EXPBUF` the ``fd`` field will be set by a
driver, on success. This is a DMABUF file descriptor. The application may
pass it to other DMABUF-aware devices. It is recommended to close a DMABUF
file when it is no longer used to allow the associated memory to be reclaimed.

C 예제

56-77

예제의 `buffer_export()`는 `dmx_exportbuffer`를 0으로 초기화하고 버퍼 형식과 인덱스를 설정한 뒤 `DMX_EXPBUF`를 호출합니다.

ioctl이 실패하면 `perror()`로 오류를 출력하고 -1을 반환하며, 성공하면 `expbuf.fd`를 호출자에게 전달하고 0을 반환합니다. 함수명과 C 코드는 실행 가능한 형태 그대로 보존합니다.

예제 함수의 제어 흐름
expbuf 초기화와 type/index 설정ioctl(v4lfd, DMX_EXPBUF, &expbuf) 호출실패 시 perror와 -1 반환성공 시 expbuf.fd 저장 후 0 반환

buffer_export()가 DMABUF fd를 돌려주는 과정입니다.

Examples
========

.. code-block:: c

    int buffer_export(int v4lfd, enum dmx_buf_type bt, int index, int *dmafd)
    {
	struct dmx_exportbuffer expbuf;

	memset(&expbuf, 0, sizeof(expbuf));
	expbuf.type = bt;
	expbuf.index = index;
	if (ioctl(v4lfd, DMX_EXPBUF, &expbuf) == -1) {
	    perror("DMX_EXPBUF");
	    return -1;
	}

	*dmafd = expbuf.fd;

	return 0;
    }

반환값과 EINVAL

78-87

성공하면 0을 반환합니다. 오류가 발생하면 -1을 반환하고 `errno`를 적절히 설정하며, 공통 오류 코드는 `Generic Error Codes <gen-errors>` 장에서 설명합니다.

`EINVAL`은 큐가 MMAP 모드가 아니거나, DMABUF 내보내기를 지원하지 않거나, `flags` 또는 `index` 필드가 유효하지 않을 때 발생합니다.

DMX_EXPBUF 전용 오류
오류조건
EINVALMMAP 모드 아님, DMABUF 내보내기 미지원, 또는 flags/index가 잘못됨

문서가 명시한 EINVAL 조건입니다.

Return Value
============

On success 0 is returned, on error -1 and the ``errno`` variable is set
appropriately. The generic error codes are described at the
:ref:`Generic Error Codes <gen-errors>` chapter.

EINVAL
    A queue is not in MMAP mode or DMABUF exporting is not supported or
    ``flags`` or ``index`` fields are invalid.