← Documents Documentation/userspace-api/media/v4l/vidioc-dbg-g-register.rst GitHub 원문 ↗

Linux 6.18.37 · 사용자 공간 API

VIDIOC_DBG_G_REGISTER와 VIDIOC_DBG_S_REGISTER ioctl

root 권한으로 V4L2 장치의 하드웨어 레지스터를 직접 읽고 쓰는 실험적 디버그 ioctl의 위험, 입력 필드와 반환값을 설명합니다.

Source pathDocumentation/userspace-api/media/v4l/vidioc-dbg-g-register.rst
Source versionLinux v6.18.37
TranslationDUJINLABS 전문 번역 + 해설

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

1. 요약·해설

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

요약·해설

vidioc-dbg-g-register.rst:1-160

root 권한으로 V4L2 장치의 하드웨어 레지스터를 직접 읽고 쓰는 실험적 디버그 ioctl의 위험, 입력 필드와 반환값을 설명합니다.

2. 영어 원문 전체

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

원문 전체 펼치기
1 .. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later
2 .. c:namespace:: V4L
3
4 .. _VIDIOC_DBG_G_REGISTER:
5
6 **************************************************
7 ioctl VIDIOC_DBG_G_REGISTER, VIDIOC_DBG_S_REGISTER
8 **************************************************
9
10 Name
11 ====
12
13 VIDIOC_DBG_G_REGISTER - VIDIOC_DBG_S_REGISTER - Read or write hardware registers
14
15 Synopsis
16 ========
17
18 .. c:macro:: VIDIOC_DBG_G_REGISTER
19
20 ``int ioctl(int fd, VIDIOC_DBG_G_REGISTER, struct v4l2_dbg_register *argp)``
21
22 .. c:macro:: VIDIOC_DBG_S_REGISTER
23
24 ``int ioctl(int fd, VIDIOC_DBG_S_REGISTER, const struct v4l2_dbg_register *argp)``
25
26 Arguments
27 =========
28
29 ``fd``
30 File descriptor returned by :c:func:`open()`.
31
32 ``argp``
33 Pointer to struct :c:type:`v4l2_dbg_register`.
34
35 Description
36 ===========
37
38 .. note::
39
40 This is an :ref:`experimental` interface and may
41 change in the future.
42
43 For driver debugging purposes these ioctls allow test applications to
44 access hardware registers directly. Regular applications must not use
45 them.
46
47 Since writing or even reading registers can jeopardize the system
48 security, its stability and damage the hardware, both ioctls require
49 superuser privileges. Additionally the Linux kernel must be compiled
50 with the ``CONFIG_VIDEO_ADV_DEBUG`` option to enable these ioctls.
51
52 To write a register applications must initialize all fields of a struct
53 :c:type:`v4l2_dbg_register` except for ``size`` and
54 call ``VIDIOC_DBG_S_REGISTER`` with a pointer to this structure. The
55 ``match.type`` and ``match.addr`` or ``match.name`` fields select a chip
56 on the TV card, the ``reg`` field specifies a register number and the
57 ``val`` field the value to be written into the register.
58
59 To read a register applications must initialize the ``match.type``,
60 ``match.addr`` or ``match.name`` and ``reg`` fields, and call
61 ``VIDIOC_DBG_G_REGISTER`` with a pointer to this structure. On success
62 the driver stores the register value in the ``val`` field and the size
63 (in bytes) of the value in ``size``.
64
65 When ``match.type`` is ``V4L2_CHIP_MATCH_BRIDGE``, ``match.addr``
66 selects the nth non-sub-device chip on the TV card. The number zero
67 always selects the host chip, e. g. the chip connected to the PCI or USB
68 bus. You can find out which chips are present with the
69 :ref:`VIDIOC_DBG_G_CHIP_INFO` ioctl.
70
71 When ``match.type`` is ``V4L2_CHIP_MATCH_SUBDEV``, ``match.addr``
72 selects the nth sub-device.
73
74 These ioctls are optional, not all drivers may support them. However
75 when a driver supports these ioctls it must also support
76 :ref:`VIDIOC_DBG_G_CHIP_INFO`. Conversely
77 it may support ``VIDIOC_DBG_G_CHIP_INFO`` but not these ioctls.
78
79 ``VIDIOC_DBG_G_REGISTER`` and ``VIDIOC_DBG_S_REGISTER`` were introduced
80 in Linux 2.6.21, but their API was changed to the one described here in
81 kernel 2.6.29.
82
83 We recommended the v4l2-dbg utility over calling these ioctls directly.
84 It is available from the LinuxTV v4l-dvb repository; see
85 `https://linuxtv.org/repo/ <https://linuxtv.org/repo/>`__ for access
86 instructions.
87
88 .. tabularcolumns:: |p{3.5cm}|p{3.5cm}|p{3.5cm}|p{6.6cm}|
89
90 .. c:type:: v4l2_dbg_match
91
92 .. flat-table:: struct v4l2_dbg_match
93 :header-rows: 0
94 :stub-columns: 0
95 :widths: 1 1 2
96
97 * - __u32
98 - ``type``
99 - See :ref:`chip-match-types` for a list of possible types.
100 * - union {
101 - (anonymous)
102 * - __u32
103 - ``addr``
104 - Match a chip by this number, interpreted according to the ``type``
105 field.
106 * - char
107 - ``name[32]``
108 - Match a chip by this name, interpreted according to the ``type``
109 field. Currently unused.
110 * - }
111 -
112
113
114 .. c:type:: v4l2_dbg_register
115
116 .. flat-table:: struct v4l2_dbg_register
117 :header-rows: 0
118 :stub-columns: 0
119
120 * - struct v4l2_dbg_match
121 - ``match``
122 - How to match the chip, see :c:type:`v4l2_dbg_match`.
123 * - __u32
124 - ``size``
125 - The register size in bytes.
126 * - __u64
127 - ``reg``
128 - A register number.
129 * - __u64
130 - ``val``
131 - The value read from, or to be written into the register.
132
133
134 .. tabularcolumns:: |p{6.6cm}|p{2.2cm}|p{8.5cm}|
135
136 .. _chip-match-types:
137
138 .. flat-table:: Chip Match Types
139 :header-rows: 0
140 :stub-columns: 0
141 :widths: 3 1 4
142
143 * - ``V4L2_CHIP_MATCH_BRIDGE``
144 - 0
145 - Match the nth chip on the card, zero for the bridge chip. Does not
146 match sub-devices.
147 * - ``V4L2_CHIP_MATCH_SUBDEV``
148 - 4
149 - Match the nth sub-device.
150
151 Return Value
152 ============
153
154 On success 0 is returned, on error -1 and the ``errno`` variable is set
155 appropriately. The generic error codes are described at the
156 :ref:`Generic Error Codes <gen-errors>` chapter.
157
158 EPERM
159 Insufficient permissions. Root privileges are required to execute
160 these ioctls.
161

3. 한국어 전문 번역

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

읽기·쓰기 호출 형식과 인자

1-34

`VIDIOC_DBG_G_REGISTER`와 `VIDIOC_DBG_S_REGISTER`는 하드웨어 레지스터를 직접 읽거나 씁니다. 읽기는 변경 가능한 `struct v4l2_dbg_register *argp`를 받고, 쓰기는 `const struct v4l2_dbg_register *argp`를 받습니다.

두 호출 모두 `open()`이 반환한 `fd`와 `struct v4l2_dbg_register` 포인터를 사용합니다. 읽기 결과는 같은 구조체의 `val`과 `size`로 돌아옵니다.

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

.. _VIDIOC_DBG_G_REGISTER:

**************************************************
ioctl VIDIOC_DBG_G_REGISTER, VIDIOC_DBG_S_REGISTER
**************************************************

Name
====

VIDIOC_DBG_G_REGISTER - VIDIOC_DBG_S_REGISTER - Read or write hardware registers

Synopsis
========

.. c:macro:: VIDIOC_DBG_G_REGISTER

``int ioctl(int fd, VIDIOC_DBG_G_REGISTER, struct v4l2_dbg_register *argp)``

.. c:macro:: VIDIOC_DBG_S_REGISTER

``int ioctl(int fd, VIDIOC_DBG_S_REGISTER, const struct v4l2_dbg_register *argp)``

Arguments
=========

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

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

권한, 위험과 레지스터 접근 절차

35-87

이 인터페이스도 실험적이며 드라이버 디버깅용 테스트 프로그램만 사용해야 합니다. 레지스터 읽기나 쓰기는 시스템 보안과 안정성을 해치거나 하드웨어를 손상시킬 수 있으므로 두 ioctl 모두 superuser 권한이 필요합니다. 커널도 `CONFIG_VIDEO_ADV_DEBUG`를 켜서 빌드해야 합니다.

레지스터를 쓰려면 `size`를 제외한 모든 필드를 초기화합니다. `match.type`과 `match.addr` 또는 `match.name`으로 TV 카드의 칩을 고르고, `reg`에 레지스터 번호, `val`에 쓸 값을 넣은 뒤 `VIDIOC_DBG_S_REGISTER`를 호출합니다.

레지스터를 읽으려면 일치 조건과 `reg`를 초기화한 뒤 `VIDIOC_DBG_G_REGISTER`를 호출합니다. 성공하면 드라이버가 `val`에 읽은 값, `size`에 값의 바이트 크기를 저장합니다.

bridge 일치에서 주소 0은 PCI나 USB 버스에 연결된 host 칩이고, 그 밖의 번호는 n번째 비-sub-device 칩을 뜻합니다. 존재하는 칩은 `VIDIOC_DBG_G_CHIP_INFO`로 확인합니다. sub-device 일치에서는 주소가 n번째 sub-device를 선택합니다.

레지스터 ioctl은 선택 기능입니다. 이를 지원하는 드라이버는 반드시 `VIDIOC_DBG_G_CHIP_INFO`도 지원해야 하지만, 칩 정보 조회만 지원하고 레지스터 접근은 제공하지 않을 수 있습니다. ioctl은 Linux 2.6.21에 도입됐고 현재 API 형태는 2.6.29에서 바뀌었습니다. 직접 호출보다 `v4l2-dbg` 도구가 권장됩니다.

읽기와 쓰기 입력·출력
작업응용 프로그램 입력드라이버 결과
읽기`match`, `reg``val`, `size`
쓰기`match`, `reg`, `val` 및 `size` 외 모든 필드레지스터 갱신

호출 전에 채울 필드와 성공 후 결과를 구분합니다.

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

.. note::

    This is an :ref:`experimental` interface and may
    change in the future.

For driver debugging purposes these ioctls allow test applications to
access hardware registers directly. Regular applications must not use
them.

Since writing or even reading registers can jeopardize the system
security, its stability and damage the hardware, both ioctls require
superuser privileges. Additionally the Linux kernel must be compiled
with the ``CONFIG_VIDEO_ADV_DEBUG`` option to enable these ioctls.

To write a register applications must initialize all fields of a struct
:c:type:`v4l2_dbg_register` except for ``size`` and
call ``VIDIOC_DBG_S_REGISTER`` with a pointer to this structure. The
``match.type`` and ``match.addr`` or ``match.name`` fields select a chip
on the TV card, the ``reg`` field specifies a register number and the
``val`` field the value to be written into the register.

To read a register applications must initialize the ``match.type``,
``match.addr`` or ``match.name`` and ``reg`` fields, and call
``VIDIOC_DBG_G_REGISTER`` with a pointer to this structure. On success
the driver stores the register value in the ``val`` field and the size
(in bytes) of the value in ``size``.

When ``match.type`` is ``V4L2_CHIP_MATCH_BRIDGE``, ``match.addr``
selects the nth non-sub-device chip on the TV card. The number zero
always selects the host chip, e. g. the chip connected to the PCI or USB
bus. You can find out which chips are present with the
:ref:`VIDIOC_DBG_G_CHIP_INFO` ioctl.

When ``match.type`` is ``V4L2_CHIP_MATCH_SUBDEV``, ``match.addr``
selects the nth sub-device.

These ioctls are optional, not all drivers may support them. However
when a driver supports these ioctls it must also support
:ref:`VIDIOC_DBG_G_CHIP_INFO`. Conversely
it may support ``VIDIOC_DBG_G_CHIP_INFO`` but not these ioctls.

``VIDIOC_DBG_G_REGISTER`` and ``VIDIOC_DBG_S_REGISTER`` were introduced
in Linux 2.6.21, but their API was changed to the one described here in
kernel 2.6.29.

We recommended the v4l2-dbg utility over calling these ioctls directly.
It is available from the LinuxTV v4l-dvb repository; see
`https://linuxtv.org/repo/ <https://linuxtv.org/repo/>`__ for access
instructions.

v4l2_dbg_match 구조체

88-113
struct v4l2_dbg_match
형식필드의미
`__u32``type`칩 일치 유형을 지정하며 Chip Match Types 표의 값을 사용
union익명주소 또는 이름 중 하나를 담는 익명 union
`__u32``addr``type`의 의미에 따라 해석되는 칩 번호
`char[32]``name``type`에 따라 이름으로 일치시키는 필드이며 현재는 사용하지 않음

레지스터를 가진 대상 칩을 선택합니다.

.. tabularcolumns:: |p{3.5cm}|p{3.5cm}|p{3.5cm}|p{6.6cm}|

.. c:type:: v4l2_dbg_match

.. flat-table:: struct v4l2_dbg_match
    :header-rows:  0
    :stub-columns: 0
    :widths:       1 1 2

    * - __u32
      - ``type``
      - See :ref:`chip-match-types` for a list of possible types.
    * - union {
      - (anonymous)
    * - __u32
      - ``addr``
      - Match a chip by this number, interpreted according to the ``type``
	field.
    * - char
      - ``name[32]``
      - Match a chip by this name, interpreted according to the ``type``
	field. Currently unused.
    * - }
      -

v4l2_dbg_register 구조체

114-133
struct v4l2_dbg_register
형식필드의미
`struct v4l2_dbg_match``match`접근할 칩 선택 조건
`__u32``size`레지스터 값의 바이트 크기
`__u64``reg`레지스터 번호
`__u64``val`읽은 값 또는 쓸 값

레지스터 주소, 폭과 값을 전달합니다.

`reg`와 `val`은 64비트이므로 폭이 다른 하드웨어 레지스터를 담을 수 있습니다. 읽기에서 실제 유효 바이트 수는 드라이버가 반환하는 `size`로 판단해야 합니다.

.. c:type:: v4l2_dbg_register

.. flat-table:: struct v4l2_dbg_register
    :header-rows:  0
    :stub-columns: 0

    * - struct v4l2_dbg_match
      - ``match``
      - How to match the chip, see :c:type:`v4l2_dbg_match`.
    * - __u32
      - ``size``
      - The register size in bytes.
    * - __u64
      - ``reg``
      - A register number.
    * - __u64
      - ``val``
      - The value read from, or to be written into the register.

칩 일치 유형

134-150
Chip Match Types
상수의미
`V4L2_CHIP_MATCH_BRIDGE`0카드의 n번째 비-sub-device 칩; 0은 bridge 또는 host 칩
`V4L2_CHIP_MATCH_SUBDEV`4n번째 sub-device

bridge/host 칩과 sub-device를 서로 다른 번호 공간으로 선택합니다.

.. tabularcolumns:: |p{6.6cm}|p{2.2cm}|p{8.5cm}|

.. _chip-match-types:

.. flat-table:: Chip Match Types
    :header-rows:  0
    :stub-columns: 0
    :widths:       3 1 4

    * - ``V4L2_CHIP_MATCH_BRIDGE``
      - 0
      - Match the nth chip on the card, zero for the bridge chip. Does not
	match sub-devices.
    * - ``V4L2_CHIP_MATCH_SUBDEV``
      - 4
      - Match the nth sub-device.

반환값과 권한 오류

151-160

성공하면 0을 반환하고 실패하면 -1과 `errno`를 반환합니다. `EPERM`은 권한이 부족하다는 뜻이며 이 ioctl을 실행하려면 root 권한이 필요합니다.

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.

EPERM
    Insufficient permissions. Root privileges are required to execute
    these ioctls.