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

Linux 6.18.37 · Userspace API / Media / DVB / Demux

Digital TV mmap()

할당한 Demux 버퍼를 애플리케이션 주소 공간에 매핑하는 실험적 API입니다.

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

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

1. 요약·해설

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

요약·해설

dmx-mmap.rst:1-115

Digital TV mmap 경로는 DMX_REQBUFS 할당과 DMX_QUERYBUF 질의가 선행되어야 합니다. PROT_READ | PROT_WRITE와 MAP_SHARED가 권장 조합이며 길이는 보통 188바이트 패킷 단위입니다.

2. 영어 원문 전체

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

원문 전체 펼치기
1 .. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later
2 .. c:namespace:: DTV.dmx
3
4 .. _dmx-mmap:
5
6 *****************
7 Digital TV mmap()
8 *****************
9
10 Name
11 ====
12
13 dmx-mmap - Map device memory into application address space
14
15 .. warning:: this API is still experimental
16
17 Synopsis
18 ========
19
20 .. code-block:: c
21
22 #include <unistd.h>
23 #include <sys/mman.h>
24
25 .. c:function:: void *mmap( void *start, size_t length, int prot, int flags, int fd, off_t offset )
26
27 Arguments
28 =========
29
30 ``start``
31 Map the buffer to this address in the application's address space.
32 When the ``MAP_FIXED`` flag is specified, ``start`` must be a
33 multiple of the pagesize and mmap will fail when the specified
34 address cannot be used. Use of this option is discouraged;
35 applications should just specify a ``NULL`` pointer here.
36
37 ``length``
38 Length of the memory area to map. This must be a multiple of the
39 DVB packet length (188, on most drivers).
40
41 ``prot``
42 The ``prot`` argument describes the desired memory protection.
43 Regardless of the device type and the direction of data exchange it
44 should be set to ``PROT_READ`` | ``PROT_WRITE``, permitting read
45 and write access to image buffers. Drivers should support at least
46 this combination of flags.
47
48 ``flags``
49 The ``flags`` parameter specifies the type of the mapped object,
50 mapping options and whether modifications made to the mapped copy of
51 the page are private to the process or are to be shared with other
52 references.
53
54 ``MAP_FIXED`` requests that the driver selects no other address than
55 the one specified. If the specified address cannot be used,
56 :c:func:`mmap()` will fail. If ``MAP_FIXED`` is specified,
57 ``start`` must be a multiple of the pagesize. Use of this option is
58 discouraged.
59
60 One of the ``MAP_SHARED`` or ``MAP_PRIVATE`` flags must be set.
61 ``MAP_SHARED`` allows applications to share the mapped memory with
62 other (e. g. child-) processes.
63
64 .. note::
65
66 The Linux Digital TV applications should not set the
67 ``MAP_PRIVATE``, ``MAP_DENYWRITE``, ``MAP_EXECUTABLE`` or ``MAP_ANON``
68 flags.
69
70 ``fd``
71 File descriptor returned by :c:func:`open()`.
72
73 ``offset``
74 Offset of the buffer in device memory, as returned by
75 :ref:`DMX_QUERYBUF` ioctl.
76
77 Description
78 ===========
79
80 The :c:func:`mmap()` function asks to map ``length`` bytes starting at
81 ``offset`` in the memory of the device specified by ``fd`` into the
82 application address space, preferably at address ``start``. This latter
83 address is a hint only, and is usually specified as 0.
84
85 Suitable length and offset parameters are queried with the
86 :ref:`DMX_QUERYBUF` ioctl. Buffers must be allocated with the
87 :ref:`DMX_REQBUFS` ioctl before they can be queried.
88
89 To unmap buffers the :c:func:`munmap()` function is used.
90
91 Return Value
92 ============
93
94 On success :c:func:`mmap()` returns a pointer to the mapped buffer. On
95 error ``MAP_FAILED`` (-1) is returned, and the ``errno`` variable is set
96 appropriately. Possible error codes are:
97
98 EBADF
99 ``fd`` is not a valid file descriptor.
100
101 EACCES
102 ``fd`` is not open for reading and writing.
103
104 EINVAL
105 The ``start`` or ``length`` or ``offset`` are not suitable. (E. g.
106 they are too large, or not aligned on a ``PAGESIZE`` boundary.)
107
108 The ``flags`` or ``prot`` value is not supported.
109
110 No buffers have been allocated with the
111 :ref:`DMX_REQBUFS` ioctl.
112
113 ENOMEM
114 Not enough physical or virtual memory was available to complete the
115 request.
116

3. 한국어 전문 번역

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

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

1-25

이 문서는 GFDL-1.1-no-invariants-or-later 라이선스와 `DTV.dmx` C namespace를 사용하며 Digital TV의 `mmap()` 인터페이스를 설명합니다.

`dmx-mmap`은 장치 메모리를 애플리케이션 주소 공간에 매핑합니다. 이 API는 아직 실험적입니다.

사용자는 `unistd.h`와 `sys/mman.h`를 포함하며, 함수 원형은 `void *mmap(void *start, size_t length, int prot, int flags, int fd, off_t offset)`입니다.

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

.. _dmx-mmap:

*****************
Digital TV mmap()
*****************

Name
====

dmx-mmap - Map device memory into application address space

.. warning:: this API is still experimental

Synopsis
========

.. code-block:: c

    #include <unistd.h>
    #include <sys/mman.h>

.. c:function:: void *mmap( void *start, size_t length, int prot, int flags, int fd, off_t offset )

주소, 길이와 보호 속성

26-46

`start`는 애플리케이션 주소 공간에서 버퍼를 배치할 주소입니다. `MAP_FIXED`를 지정하면 페이지 크기의 배수여야 하고 그 주소를 사용할 수 없을 때 실패합니다. 이 옵션은 권장하지 않으며 애플리케이션은 보통 `NULL`을 지정해야 합니다.

`length`는 매핑할 메모리 영역 길이이며 DVB 패킷 길이의 배수여야 합니다. 대부분의 드라이버에서 패킷 길이는 188바이트입니다.

`prot`는 원하는 메모리 보호 속성입니다. 장치 종류와 데이터 교환 방향에 관계없이 읽기·쓰기를 모두 허용하는 `PROT_READ | PROT_WRITE`로 설정해야 하며, 드라이버는 적어도 이 조합을 지원해야 합니다.

mmap 주소와 보호 인자
항목설명
start보통 NULL. MAP_FIXED에서는 페이지 경계 주소
lengthDVB 패킷 길이의 배수. 대부분 188바이트 단위
protPROT_READ | PROT_WRITE

초기 세 인자의 제약을 정리합니다.


Arguments
=========

``start``
    Map the buffer to this address in the application's address space.
    When the ``MAP_FIXED`` flag is specified, ``start`` must be a
    multiple of the pagesize and mmap will fail when the specified
    address cannot be used. Use of this option is discouraged;
    applications should just specify a ``NULL`` pointer here.

``length``
    Length of the memory area to map. This must be a multiple of the
    DVB packet length (188, on most drivers).

``prot``
    The ``prot`` argument describes the desired memory protection.
    Regardless of the device type and the direction of data exchange it
    should be set to ``PROT_READ`` | ``PROT_WRITE``, permitting read
    and write access to image buffers. Drivers should support at least
    this combination of flags.

매핑 플래그

47-68

`flags`는 매핑할 객체의 종류와 옵션, 매핑된 페이지 사본의 변경을 프로세스 전용으로 둘지 다른 참조와 공유할지를 지정합니다.

`MAP_FIXED`는 지정 주소 외의 다른 주소를 선택하지 말라고 드라이버에 요구합니다. 주소를 쓸 수 없으면 실패하고 `start`는 페이지 크기의 배수여야 하므로 사용을 권장하지 않습니다.

`MAP_SHARED`와 `MAP_PRIVATE` 중 하나는 반드시 설정해야 합니다. `MAP_SHARED`를 사용하면 자식 프로세스 같은 다른 프로세스와 매핑 메모리를 공유할 수 있습니다.

Linux Digital TV 애플리케이션은 `MAP_PRIVATE`, `MAP_DENYWRITE`, `MAP_EXECUTABLE`, `MAP_ANON` 플래그를 설정하지 않아야 합니다. 즉, 형식상 둘 중 하나를 요구하는 앞 문장과 함께 읽을 때 이 API의 실제 권장 선택은 `MAP_SHARED`입니다.

Digital TV mmap 플래그
플래그처리
MAP_SHARED설정 권장. 다른 프로세스와 매핑 공유 가능
MAP_FIXED지원하지만 사용 비권장. 주소와 페이지 정렬을 강제
MAP_PRIVATEDigital TV 애플리케이션에서 설정하지 않음
MAP_DENYWRITE / MAP_EXECUTABLE / MAP_ANON설정하지 않음

요구·권장·금지 상태를 구분합니다.


``flags``
    The ``flags`` parameter specifies the type of the mapped object,
    mapping options and whether modifications made to the mapped copy of
    the page are private to the process or are to be shared with other
    references.

    ``MAP_FIXED`` requests that the driver selects no other address than
    the one specified. If the specified address cannot be used,
    :c:func:`mmap()` will fail. If ``MAP_FIXED`` is specified,
    ``start`` must be a multiple of the pagesize. Use of this option is
    discouraged.

    One of the ``MAP_SHARED`` or ``MAP_PRIVATE`` flags must be set.
    ``MAP_SHARED`` allows applications to share the mapped memory with
    other (e. g. child-) processes.

    .. note::

       The Linux Digital TV applications should not set the
       ``MAP_PRIVATE``, ``MAP_DENYWRITE``, ``MAP_EXECUTABLE`` or ``MAP_ANON``
       flags.

fd, offset과 버퍼 준비

69-89

`fd`는 `open()`이 반환한 file descriptor입니다.

`offset`은 장치 메모리에서 버퍼의 오프셋이며 `DMX_QUERYBUF` ioctl이 반환한 값을 사용합니다.

`mmap()`은 `fd`가 지정한 장치 메모리의 `offset`부터 `length`바이트를 애플리케이션 주소 공간에 매핑하도록 요청합니다. `start`는 선호 주소를 나타내는 힌트일 뿐이며 보통 0입니다.

적절한 `length`와 `offset`은 `DMX_QUERYBUF`로 질의합니다. 버퍼는 질의하기 전에 `DMX_REQBUFS`로 할당해야 합니다.

버퍼 매핑을 해제할 때는 `munmap()`을 사용합니다.

Demux MMAP 버퍼 준비와 사용
DMX_REQBUFS로 버퍼 할당DMX_QUERYBUF로 length와 offset 조회PROT_READ | PROT_WRITE와 MAP_SHARED 준비mmap(fd, offset)으로 사용자 주소 공간에 매핑사용 완료 후 munmap() 호출

할당·질의·매핑·해제를 순서대로 수행합니다.


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

``offset``
    Offset of the buffer in device memory, as returned by
    :ref:`DMX_QUERYBUF` ioctl.

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

The :c:func:`mmap()` function asks to map ``length`` bytes starting at
``offset`` in the memory of the device specified by ``fd`` into the
application address space, preferably at address ``start``. This latter
address is a hint only, and is usually specified as 0.

Suitable length and offset parameters are queried with the
:ref:`DMX_QUERYBUF` ioctl. Buffers must be allocated with the
:ref:`DMX_REQBUFS` ioctl before they can be queried.

To unmap buffers the :c:func:`munmap()` function is used.

반환값과 오류

90-115

성공하면 `mmap()`은 매핑된 버퍼를 가리키는 포인터를 반환합니다. 오류가 발생하면 `MAP_FAILED`(-1)를 반환하고 `errno`를 적절히 설정합니다.

Digital TV mmap 오류
오류조건
EBADFfd가 유효한 file descriptor가 아님
EACCESfd가 읽기와 쓰기용으로 열려 있지 않음
EINVALstart, length 또는 offset이 너무 크거나 페이지 경계에 맞지 않는 등 부적절함
EINVALflags 또는 prot 값이 지원되지 않음
EINVALDMX_REQBUFS로 버퍼를 할당하지 않음
ENOMEM요청을 완료할 물리 또는 가상 메모리가 부족함

문서에 열거된 실패 조건입니다.


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

On success :c:func:`mmap()` returns a pointer to the mapped buffer. On
error ``MAP_FAILED`` (-1) is returned, and the ``errno`` variable is set
appropriately. Possible error codes are:

EBADF
    ``fd`` is not a valid file descriptor.

EACCES
    ``fd`` is not open for reading and writing.

EINVAL
    The ``start`` or ``length`` or ``offset`` are not suitable. (E. g.
    they are too large, or not aligned on a ``PAGESIZE`` boundary.)

    The ``flags`` or ``prot`` value is not supported.

    No buffers have been allocated with the
    :ref:`DMX_REQBUFS` ioctl.

ENOMEM
    Not enough physical or virtual memory was available to complete the
    request.