Documentation/driver-api/tty/index.rst GitHub 원문 ↗

Linux 6.18.37 · Driver API

TTY

Linux TTY 계층의 핵심 구조체, line discipline, 드라이버 작성 순서와 하위 문서를 설명하는 한국어 전문 번역입니다.

Source pathDocumentation/driver-api/tty/index.rst
Source versionLinux v6.18.37
TranslationDUJINLABS 전문 번역 + 해설

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

1. 요약·해설

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

요약·해설

index.rst:1-75

TTY 계층은 실제·가상 직렬 장치를 공통 구조체와 연산으로 연결하고, line discipline을 통해 문자를 변환합니다. 새 드라이버는 가능한 경우 Serial 또는 USB Serial 계층을 우선 사용하며, 직접 구현할 때는 등록·probe·실행·remove·해제 순서를 따릅니다.

문서 구성
원문 줄핵심 내용
1-9TTY와 PTY의 범위
10-42핵심 구조체, line discipline, 하위 문서
43-64TTY 드라이버 작성 순서
65-75기타 TTY 문서

2. 영어 원문 전체

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

원문 전체 펼치기
1 .. SPDX-License-Identifier: GPL-2.0
2
3 ===
4 TTY
5 ===
6
7 Teletypewriter (TTY) layer takes care of all those serial devices. Including
8 the virtual ones like pseudoterminal (PTY).
9
10 TTY structures
11 ==============
12
13 There are several major TTY structures. Every TTY device in a system has a
14 corresponding struct tty_port. These devices are maintained by a TTY driver
15 which is struct tty_driver. This structure describes the driver but also
16 contains a reference to operations which could be performed on the TTYs. It is
17 struct tty_operations. Then, upon open, a struct tty_struct is allocated and
18 lives until the final close. During this time, several callbacks from struct
19 tty_operations are invoked by the TTY layer.
20
21 Every character received by the kernel (both from devices and users) is passed
22 through a preselected :doc:`tty_ldisc` (in
23 short ldisc; in C, struct tty_ldisc_ops). Its task is to transform characters
24 as defined by a particular ldisc or by user too. The default one is n_tty,
25 implementing echoes, signal handling, jobs control, special characters
26 processing, and more. The transformed characters are passed further to
27 user/device, depending on the source.
28
29 In-detail description of the named TTY structures is in separate documents:
30
31 .. toctree::
32 :maxdepth: 2
33
34 tty_driver
35 tty_port
36 tty_struct
37 tty_ldisc
38 tty_buffer
39 tty_ioctl
40 tty_internals
41 console
42
43 Writing TTY Driver
44 ==================
45
46 Before one starts writing a TTY driver, they must consider
47 :doc:`Serial <../serial/driver>` and :doc:`USB Serial <../../usb/usb-serial>`
48 layers first. Drivers for serial devices can often use one of these specific
49 layers to implement a serial driver. Only special devices should be handled
50 directly by the TTY Layer. If you are about to write such a driver, read on.
51
52 A *typical* sequence a TTY driver performs is as follows:
53
54 #. Allocate and register a TTY driver (module init)
55 #. Create and register TTY devices as they are probed (probe function)
56 #. Handle TTY operations and events like interrupts (TTY core invokes the
57 former, the device the latter)
58 #. Remove devices as they are going away (remove function)
59 #. Unregister and free the TTY driver (module exit)
60
61 Steps regarding driver, i.e. 1., 3., and 5. are described in detail in
62 :doc:`tty_driver`. For the other two (devices handling), look into
63 :doc:`tty_port`.
64
65 Other Documentation
66 ===================
67
68 Miscellaneous documentation can be further found in these documents:
69
70 .. toctree::
71 :maxdepth: 2
72
73 moxa-smartio
74 n_gsm
75 n_tty
76

3. 한국어 전문 번역

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

TTY 계층 개요

1-9

Teletypewriter(TTY) 계층은 직렬 장치를 모두 관리합니다. 이 범위에는 실제 직렬 하드웨어뿐 아니라 pseudoterminal(PTY) 같은 가상 장치도 포함됩니다.

TTY 계층이 다루는 장치
범주TTY 계층의 역할
물리 직렬 장치UART 기반 장치 등공통 TTY 인터페이스 제공
가상 직렬 장치pseudoterminal(PTY)동일한 문자 장치 처리 경로 제공

.. SPDX-License-Identifier: GPL-2.0

===
TTY
===

Teletypewriter (TTY) layer takes care of all those serial devices. Including
the virtual ones like pseudoterminal (PTY).

TTY 구조체와 line discipline

10-42

시스템의 각 TTY 장치에는 대응하는 `struct tty_port`가 있습니다. 장치는 `struct tty_driver`인 TTY 드라이버가 관리하며, 이 구조체는 드라이버 자체를 설명하는 동시에 TTY에서 수행할 수 있는 연산 집합인 `struct tty_operations`를 참조합니다.

장치를 열면 `struct tty_struct`가 할당되고 마지막 close까지 유지됩니다. 이 수명 동안 TTY 계층은 `struct tty_operations`의 여러 callback을 호출합니다.

장치나 사용자에게서 커널로 들어오는 모든 문자는 미리 선택된 `tty_ldisc`, 즉 C의 `struct tty_ldisc_ops`를 통과합니다. line discipline(ldisc)은 선택된 규칙이나 사용자 설정에 따라 문자를 변환합니다.

기본 line discipline인 `n_tty`는 echo, signal 처리, job control, 특수 문자 처리 등을 구현합니다. 변환된 문자는 입력 출처에 따라 사용자 또는 장치 쪽으로 계속 전달됩니다.

TTY 핵심 객체와 문자 처리 경로
`struct tty_driver``struct tty_port` 장치 관리
`struct tty_driver``struct tty_operations` 참조
open`struct tty_struct` 할당
장치 또는 사용자 문자`struct tty_ldisc_ops` 변환
`n_tty` 또는 선택된 ldisc사용자 또는 장치로 전달

드라이버·포트·열린 TTY 객체의 관계와 line discipline을 통한 문자 흐름입니다.

각 구조체의 상세 설명은 `tty_driver`, `tty_port`, `tty_struct`, `tty_ldisc`, `tty_buffer`, `tty_ioctl`, `tty_internals`, `console` 문서에서 확인할 수 있습니다.

TTY structures
==============

There are several major TTY structures. Every TTY device in a system has a
corresponding struct tty_port. These devices are maintained by a TTY driver
which is struct tty_driver. This structure describes the driver but also
contains a reference to operations which could be performed on the TTYs. It is
struct tty_operations. Then, upon open, a struct tty_struct is allocated and
lives until the final close. During this time, several callbacks from struct
tty_operations are invoked by the TTY layer.

Every character received by the kernel (both from devices and users) is passed
through a preselected :doc:`tty_ldisc` (in
short ldisc; in C, struct tty_ldisc_ops). Its task is to transform characters
as defined by a particular ldisc or by user too. The default one is n_tty,
implementing echoes, signal handling, jobs control, special characters
processing, and more. The transformed characters are passed further to
user/device, depending on the source.

In-detail description of the named TTY structures is in separate documents:

.. toctree::
   :maxdepth: 2

   tty_driver
   tty_port
   tty_struct
   tty_ldisc
   tty_buffer
   tty_ioctl
   tty_internals
   console

TTY 드라이버 작성과 생명주기

43-64

TTY 드라이버를 직접 작성하기 전에 먼저 `Serial <../serial/driver>` 계층과 `USB Serial <../../usb/usb-serial>` 계층을 검토해야 합니다. 직렬 장치 드라이버는 대개 이 특화 계층 중 하나로 구현할 수 있으며, 특수한 장치만 TTY 계층에서 직접 처리해야 합니다.

일반적인 TTY 드라이버는 모듈 초기화에서 드라이버를 할당·등록하고, probe에서 장치를 생성·등록합니다. 실행 중에는 TTY core가 연산을 호출하고 장치는 interrupt 같은 event를 발생시킵니다. 제거 시 장치를 해제하고, 모듈 종료에서 드라이버 등록을 취소한 뒤 메모리를 해제합니다.

TTY 드라이버의 일반적인 순서
1. module initTTY driver 할당·등록
2. probeTTY device 생성·등록
3. runtimeTTY operation·interrupt event 처리
4. remove사라지는 device 제거
5. module exitTTY driver 등록 취소·해제

원문의 다섯 단계를 module init부터 module exit까지 보존한 생명주기입니다.

드라이버 자체에 관한 1·3·5단계는 `tty_driver`에 자세히 설명되어 있습니다. 장치 처리에 관한 2·4단계는 `tty_port`를 참조합니다.

Writing TTY Driver
==================

Before one starts writing a TTY driver, they must consider
:doc:`Serial <../serial/driver>` and :doc:`USB Serial <../../usb/usb-serial>`
layers first. Drivers for serial devices can often use one of these specific
layers to implement a serial driver. Only special devices should be handled
directly by the TTY Layer. If you are about to write such a driver, read on.

A *typical* sequence a TTY driver performs is as follows:

#. Allocate and register a TTY driver (module init)
#. Create and register TTY devices as they are probed (probe function)
#. Handle TTY operations and events like interrupts (TTY core invokes the
   former, the device the latter)
#. Remove devices as they are going away (remove function)
#. Unregister and free the TTY driver (module exit)

Steps regarding driver, i.e. 1., 3., and 5. are described in detail in
:doc:`tty_driver`. For the other two (devices handling), look into
:doc:`tty_port`.

기타 TTY 문서

65-75

그 밖의 TTY 관련 문서는 별도 toctree에 정리되어 있습니다. `moxa-smartio`는 Moxa SmartIO 장치를, `n_gsm`은 GSM 07.10 multiplexer line discipline을, `n_tty`는 기본 line discipline을 다룹니다.

기타 문서 목록
문서주제
`moxa-smartio`Moxa SmartIO 직렬 장치
`n_gsm`GSM multiplexer line discipline
`n_tty`기본 TTY line discipline

Other Documentation
===================

Miscellaneous documentation can be further found in these documents:

.. toctree::
   :maxdepth: 2

   moxa-smartio
   n_gsm
   n_tty