Documentation/driver-api/serial/driver.rst GitHub 원문 ↗

Linux 6.18.37 · Driver API

Low Level Serial API

UART low-level driver의 uart_port·uart_ops 계약, console helper, spinlock·port mutex와 GPIO modem-control API를 다루는 전문 번역입니다.

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

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

1. 요약·해설

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

요약과 해설

driver.rst:1-105

Low-level UART driver는 `uart_port` state와 `uart_ops` callback을 serial core에 제공하고 interrupt·console을 담당합니다. Fast port state는 `port->lock`, add·remove·reconfigure lifecycle은 port mutex가 보호하며, core helper와 GPIO modem-control API를 재사용하는 것이 핵심입니다.

문서 구성
원문 줄내용
1-23문서 범위와 hardware driver 책임
24-35Console option·write helper
36-61Per-port spinlock과 port mutex
62-82`uart_ops`와 serial core helper
83-105`uart_port` 확장과 GPIO modem control

2. 영어 원문 전체

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

원문 전체 펼치기
1 ====================
2 Low Level Serial API
3 ====================
4
5
6 This document is meant as a brief overview of some aspects of the new serial
7 driver. It is not complete, any questions you have should be directed to
9
10 The reference implementation is contained within amba-pl011.c.
11
12
13
14 Low Level Serial Hardware Driver
15 --------------------------------
16
17 The low level serial hardware driver is responsible for supplying port
18 information (defined by uart_port) and a set of control methods (defined
19 by uart_ops) to the core serial driver. The low level driver is also
20 responsible for handling interrupts for the port, and providing any
21 console support.
22
23
24 Console Support
25 ---------------
26
27 The serial core provides a few helper functions. This includes
28 decoding command line arguments (uart_parse_options()).
29
30 There is also a helper function (uart_console_write()) which performs a
31 character by character write, translating newlines to CRLF sequences.
32 Driver writers are recommended to use this function rather than implementing
33 their own version.
34
35
36 Locking
37 -------
38
39 It is the responsibility of the low level hardware driver to perform the
40 necessary locking using port->lock. There are some exceptions (which
41 are described in the struct uart_ops listing below.)
42
43 There are two locks. A per-port spinlock, and an overall semaphore.
44
45 From the core driver perspective, the port->lock locks the following
46 data::
47
48 port->mctrl
49 port->icount
50 port->state->xmit.head (circ_buf->head)
51 port->state->xmit.tail (circ_buf->tail)
52
53 The low level driver is free to use this lock to provide any additional
54 locking.
55
56 The port_sem semaphore is used to protect against ports being added/
57 removed or reconfigured at inappropriate times. Since v2.6.27, this
58 semaphore has been the 'mutex' member of the tty_port struct, and
59 commonly referred to as the port mutex.
60
61
62 uart_ops
63 --------
64
65 .. kernel-doc:: include/linux/serial_core.h
66 :identifiers: uart_ops
67
68 Other functions
69 ---------------
70
71 .. kernel-doc:: drivers/tty/serial/serial_core.c
72 :identifiers: uart_update_timeout uart_get_baud_rate uart_get_divisor
73 uart_match_port uart_write_wakeup uart_register_driver
74 uart_unregister_driver uart_suspend_port uart_resume_port
75 uart_add_one_port uart_remove_one_port uart_console_write
76 uart_parse_earlycon uart_parse_options uart_set_options
77 uart_get_lsr_info uart_handle_dcd_change uart_handle_cts_change
78 uart_try_toggle_sysrq
79
80 .. kernel-doc:: include/linux/serial_core.h
81 :identifiers: uart_port_tx_limited uart_port_tx
82
83 Other notes
84 -----------
85
86 It is intended some day to drop the 'unused' entries from uart_port, and
87 allow low level drivers to register their own individual uart_port's with
88 the core. This will allow drivers to use uart_port as a pointer to a
89 structure containing both the uart_port entry with their own extensions,
90 thus::
91
92 struct my_port {
93 struct uart_port port;
94 int my_stuff;
95 };
96
97 Modem control lines via GPIO
98 ----------------------------
99
100 Some helpers are provided in order to set/get modem control lines via GPIO.
101
102 .. kernel-doc:: drivers/tty/serial/serial_mctrl_gpio.c
103 :identifiers: mctrl_gpio_init mctrl_gpio_to_gpiod
104 mctrl_gpio_set mctrl_gpio_get mctrl_gpio_enable_ms
105 mctrl_gpio_disable_ms_sync mctrl_gpio_disable_ms_no_sync
106

3. 한국어 전문 번역

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

Low Level Serial API 문서 범위

1-13

이 문서는 새로운 serial driver의 일부 측면을 간략히 개관합니다. 완전한 문서가 아니며 질문은 `[email protected]`로 보내야 합니다.

Reference implementation은 `amba-pl011.c`에 들어 있습니다.

문서 식별 정보
항목
문서Low Level Serial API
성격일부 interface에 대한 brief overview
Reference driver`amba-pl011.c`

====================
Low Level Serial API
====================


This document is meant as a brief overview of some aspects of the new serial
driver.  It is not complete, any questions you have should be directed to
<[email protected]>

The reference implementation is contained within amba-pl011.c.


Low-level serial hardware driver 책임

14-23

Low-level serial hardware driver는 `uart_port`로 정의되는 port 정보와 `uart_ops`로 정의되는 control method 집합을 core serial driver에 제공해야 합니다.

Low-level driver는 해당 port의 interrupt를 처리하고 필요한 console support도 제공할 책임이 있습니다.

Low-level serial driver 계약
Serial hardwareLow-level driver`uart_port` informationSerial core
Low-level driver`uart_ops` methodsSerial core
Port interruptsLow-level driver
Console supportLow-level driver

Hardware driver가 port state와 operation callback을 serial core에 제공하고 interrupt·console 경로를 담당합니다.

Low Level Serial Hardware Driver
--------------------------------

The low level serial hardware driver is responsible for supplying port
information (defined by uart_port) and a set of control methods (defined
by uart_ops) to the core serial driver.  The low level driver is also
responsible for handling interrupts for the port, and providing any
console support.

Console helper

24-35

Serial core는 command-line argument를 decode하는 `uart_parse_options()`를 비롯한 여러 helper function을 제공합니다.

`uart_console_write()`는 character 단위 write를 수행하고 newline을 CRLF sequence로 변환합니다. Driver 작성자는 자체 구현 대신 이 function을 사용하는 것이 권장됩니다.

Console output helper
Command-line options`uart_parse_options()`UART settings
Console text`uart_console_write()`Character-by-character writeNewline to CRLFSerial port

Core helper가 option parsing과 newline 변환을 공통 구현으로 제공합니다.

Console Support
---------------

The serial core provides a few helper functions.  This includes
decoding command line arguments (uart_parse_options()).

There is also a helper function (uart_console_write()) which performs a
character by character write, translating newlines to CRLF sequences.
Driver writers are recommended to use this function rather than implementing
their own version.

Per-port spinlock과 port mutex

36-61

필요한 locking을 `port->lock`으로 수행하는 것은 low-level hardware driver의 책임입니다. 다만 아래 `struct uart_ops` 목록에 설명된 일부 예외가 있습니다.

Lock은 per-port spinlock과 전체 semaphore 두 종류입니다. Core driver 관점에서 `port->lock`은 `port->mctrl`, `port->icount`, transmit circular buffer의 `head`와 `tail`을 보호합니다. Low-level driver는 추가 data를 보호하는 데도 이 lock을 사용할 수 있습니다.

`port_sem` semaphore는 부적절한 시점에 port를 add·remove·reconfigure하지 못하게 보호합니다. Linux v2.6.27부터 이 semaphore는 `tty_port` structure의 `mutex` member이며 보통 port mutex라고 부릅니다.

Serial locking 범위
Lock보호 대상
`port->lock``port->mctrl`
`port->lock``port->icount`
`port->lock``port->state->xmit.head`
`port->lock``port->state->xmit.tail`
Port mutexPort add·remove·reconfigure lifecycle

Per-port spinlock은 fast state를, port mutex는 구조 변경 lifecycle을 직렬화합니다.

Locking
-------

It is the responsibility of the low level hardware driver to perform the
necessary locking using port->lock.  There are some exceptions (which
are described in the struct uart_ops listing below.)

There are two locks.  A per-port spinlock, and an overall semaphore.

From the core driver perspective, the port->lock locks the following
data::

        port->mctrl
        port->icount
        port->state->xmit.head (circ_buf->head)
        port->state->xmit.tail (circ_buf->tail)

The low level driver is free to use this lock to provide any additional
locking.

The port_sem semaphore is used to protect against ports being added/
removed or reconfigured at inappropriate times. Since v2.6.27, this
semaphore has been the 'mutex' member of the tty_port struct, and
commonly referred to as the port mutex.

uart_ops callback

62-67

Low-level serial control method 집합인 `uart_ops`는 `include/linux/serial_core.h`의 kernel-doc identifier로 문서화됩니다.

`uart_ops` reference
항목
Header`include/linux/serial_core.h`
Identifier`uart_ops`
역할Low-level hardware control callback contract

uart_ops
--------

.. kernel-doc:: include/linux/serial_core.h
   :identifiers: uart_ops

Serial core와 TX helper

68-82

`drivers/tty/serial/serial_core.c`에서 timeout·baud rate·divisor 계산, port matching, write wakeup, driver 등록·해제, port suspend·resume·add·remove, console write와 option parsing, line status, DCD·CTS change, SysRq toggle 관련 function을 kernel-doc으로 가져옵니다.

`include/linux/serial_core.h`에서는 제한된 TX와 일반 TX helper인 `uart_port_tx_limited`, `uart_port_tx`를 가져옵니다.

Serial helper 분류
분류주요 identifier
Timing`uart_update_timeout`, `uart_get_baud_rate`, `uart_get_divisor`
Lifecycle`uart_register_driver`, `uart_add_one_port`, suspend·resume·remove
Console`uart_console_write`, parse·set option
SignalLSR, DCD, CTS, SysRq helper
Transmit`uart_port_tx_limited`, `uart_port_tx`

Other functions
---------------

.. kernel-doc:: drivers/tty/serial/serial_core.c
   :identifiers: uart_update_timeout uart_get_baud_rate uart_get_divisor
           uart_match_port uart_write_wakeup uart_register_driver
           uart_unregister_driver uart_suspend_port uart_resume_port
           uart_add_one_port uart_remove_one_port uart_console_write
           uart_parse_earlycon uart_parse_options uart_set_options
           uart_get_lsr_info uart_handle_dcd_change uart_handle_cts_change
           uart_try_toggle_sysrq

.. kernel-doc:: include/linux/serial_core.h
   :identifiers: uart_port_tx_limited uart_port_tx

uart_port 확장 구조

83-96

향후 `uart_port`의 unused entry를 제거하고 low-level driver가 개별 `uart_port`를 core에 직접 등록할 수 있게 하는 것이 의도되어 있습니다.

그러면 driver는 `uart_port` entry와 자체 extension을 함께 담는 구조체를 정의하고, 그 구조체를 가리키는 pointer로 `uart_port`를 사용할 수 있습니다.

`my_port` 확장 layout
Member역할
`struct uart_port port`Serial core가 이해하는 공통 port
`int my_stuff`Low-level driver 전용 extension 예시

Common structure를 첫 member로 포함해 core contract와 driver-private state를 한 allocation에 둡니다.

Other notes
-----------

It is intended some day to drop the 'unused' entries from uart_port, and
allow low level drivers to register their own individual uart_port's with
the core.  This will allow drivers to use uart_port as a pointer to a
structure containing both the uart_port entry with their own extensions,
thus::

        struct my_port {
                struct uart_port        port;
                int                        my_stuff;
        };

GPIO modem-control line

97-105

GPIO를 통해 modem-control line을 설정하거나 읽기 위한 helper가 제공됩니다.

`drivers/tty/serial/serial_mctrl_gpio.c`에서 초기화, GPIO descriptor 변환, set·get, modem-status enable과 동기·비동기 disable helper를 kernel-doc으로 가져옵니다.

GPIO modem-control helper
UART modem-control request`mctrl_gpio_*` helpersGPIO descriptorModem-control lines
Modem status monitoringenable / disable sync / disable no-sync

공통 helper가 UART modem signal과 GPIO descriptor·value operation을 연결합니다.

Modem control lines via GPIO
----------------------------

Some helpers are provided in order to set/get modem control lines via GPIO.

.. kernel-doc:: drivers/tty/serial/serial_mctrl_gpio.c
   :identifiers: mctrl_gpio_init mctrl_gpio_to_gpiod
           mctrl_gpio_set mctrl_gpio_get mctrl_gpio_enable_ms
           mctrl_gpio_disable_ms_sync mctrl_gpio_disable_ms_no_sync