요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.
1. 요약·해설
원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.
2. 영어 원문 전체
번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.
원문 전체 펼치기
.. 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 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
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`.
Other Documentation
===================
Miscellaneous documentation can be further found in these documents:
.. toctree::
:maxdepth: 2
moxa-smartio
n_gsm
n_tty
3. 한국어 전문 번역
영어 원문의 문단 순서와 의미를 유지한 전체 번역입니다. 코드, 함수명, symbol과 URL은 원문 표기를 유지합니다.
TTY 계층 개요
1-9Teletypewriter(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 객체의 관계와 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-64TTY 드라이버를 직접 작성하기 전에 먼저 `Serial <../serial/driver>` 계층과 `USB Serial <../../usb/usb-serial>` 계층을 검토해야 합니다. 직렬 장치 드라이버는 대개 이 특화 계층 중 하나로 구현할 수 있으며, 특수한 장치만 TTY 계층에서 직접 처리해야 합니다.
일반적인 TTY 드라이버는 모듈 초기화에서 드라이버를 할당·등록하고, probe에서 장치를 생성·등록합니다. 실행 중에는 TTY core가 연산을 호출하고 장치는 interrupt 같은 event를 발생시킵니다. 제거 시 장치를 해제하고, 모듈 종료에서 드라이버 등록을 취소한 뒤 메모리를 해제합니다.
원문의 다섯 단계를 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을 다룹니다.
Other Documentation
===================
Miscellaneous documentation can be further found in these documents:
.. toctree::
:maxdepth: 2
moxa-smartio
n_gsm
n_tty
요약·해설
index.rst:1-75TTY 계층은 실제·가상 직렬 장치를 공통 구조체와 연산으로 연결하고, line discipline을 통해 문자를 변환합니다. 새 드라이버는 가능한 경우 Serial 또는 USB Serial 계층을 우선 사용하며, 직접 구현할 때는 등록·probe·실행·remove·해제 순서를 따릅니다.