요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.
1. 요약·해설
원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.
2. 영어 원문 전체
번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.
원문 전체 펼치기
.. 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)``
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.
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.
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;
}
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.
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를 인식하는 다른 장치로 전달할 수 있고, 더 이상 사용하지 않을 때 닫아 연결된 메모리가 회수되도록 하는 것이 좋습니다.
호출 전에 애플리케이션이 설정할 값을 정리합니다.
할당된 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 코드는 실행 가능한 형태 그대로 보존합니다.
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` 필드가 유효하지 않을 때 발생합니다.
문서가 명시한 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.
요약·해설
dmx-expbuf.rst:1-87DMX_EXPBUF는 DMX_REQBUFS로 할당한 MMAP 버퍼를 다른 DMABUF 인식 장치에 전달할 수 있는 fd로 내보냅니다. 인덱스와 플래그 검증, plane별 호출, 사용 후 close가 핵심입니다.