TTY 埠¶
建議 TTY 驅動程式儘可能使用 struct tty_port 助手。如果驅動程式實現了 tty_port.ops.activate() 和 tty_port.ops.shutdown(),則可以在相應的 tty_struct.ops 鉤子中使用 tty_port_open()、tty_port_close() 和 tty_port_hangup()。
參考和詳細資訊包含在底部的 TTY 埠參考 和 TTY 埠操作參考 部分中。
TTY 埠函式¶
初始化和銷燬¶
引數
struct tty_port *port要初始化的 tty_port
描述
初始化 struct tty_port 的狀態。當使用此函式初始化埠時,必須透過 tty_port_destroy() 銷燬埠。可以透過使用 tty_port 引用計數 (tty_port_put()) 間接銷燬,或者如果未使用引用計數則直接銷燬。
引數
struct tty_port *port要銷燬的 tty 埠
描述
當使用 tty_port_init() 初始化埠時,必須透過此函式銷燬埠。可以透過使用 tty_port 引用計數 (tty_port_put()) 間接銷燬,或者如果未使用引用計數則直接銷燬。
引數
struct tty_port *port要刪除引用的埠(可以為 NULL)
描述
最終的 put 將使用 port->ops->destruct() 鉤子銷燬並釋放 port,或者如果沒有提供鉤子,則使用 kfree()。
開啟/關閉/結束通話助手¶
-
void tty_port_shutdown(struct tty_port *port, struct tty_struct *tty)¶
關閉裝置的內部助手
引數
struct tty_port *port要關閉的 tty 埠
struct tty_struct *tty關聯的 tty
描述
它由 tty_port_hangup() 和 tty_port_close() 使用。它的任務是在裝置初始化後關閉裝置(請注意,控制檯保持執行)。它降低 DTR/RTS(如果 tty 設定了 HUPCL),並呼叫 port->ops->shutdown()。
引數
struct tty_port *porttty 埠
描述
執行埠級別的 tty 結束通話標誌和計數更改。刪除 tty 引用。
呼叫者持有 tty 鎖。
-
int tty_port_block_til_ready(struct tty_port *port, struct tty_struct *tty, struct file *filp)¶
tty 開啟的等待邏輯
引數
struct tty_port *port正在開啟的 tty 埠
struct tty_struct *tty正在繫結的 tty 裝置
struct file *filp開啟器的檔案指標或
NULL
描述
實現開啟 tty 裝置時的核心 POSIX/SuS tty 行為。處理
結束通話(之前和期間)
非阻塞開啟
rts/dtr/dcd
訊號
埠標誌和計數
如果傳遞的 port 可以進行載波檢測,則必須實現 port->ops->carrier_raised 方法;如果支援軟體管理這些線路,則必須實現 port->ops->dtr_rts 方法。請注意,dtr/rts 升高是在每次迭代時完成的,因為結束通話可能之前已在等待時將其刪除。
呼叫者持有 tty 鎖。
注意
在阻塞時可能會刪除和重新獲取 tty 鎖,因此 tty 和 port 的狀態可能已更改(例如,可能已結束通話)。
-
int tty_port_close_start(struct tty_port *port, struct tty_struct *tty, struct file *filp)¶
tty->ops->close 的助手,第 1/2 部分
引數
struct tty_port *port裝置的 tty_port
struct tty_struct *tty正在關閉的 tty
struct file *filp傳遞的檔案指標
描述
遞減並檢查開啟計數。如果是最後一次關閉,則重新整理埠。這意味著從裝置的輸出緩衝區中刪除資料,並等待發送邏輯完成。其餘的關閉處理在 tty_port_close_end() 中執行。
鎖定:呼叫者持有 tty 鎖。
返回
如果是最後一次關閉,則返回 1,否則返回 0
-
void tty_port_close_end(struct tty_port *port, struct tty_struct *tty)¶
tty->ops->close 的助手,第 2/2 部分
引數
struct tty_port *port裝置的 tty_port
struct tty_struct *tty正在關閉的 tty
描述
這是第一部分的延續:tty_port_close_start()。應在關閉裝置後呼叫此函式。它會重新整理線路規程中的資料,並將關閉延遲 port->close_delay。
鎖定:呼叫者持有 tty 鎖。
-
void tty_port_close(struct tty_port *port, struct tty_struct *tty, struct file *filp)¶
通用 tty->ops->close 處理程式
引數
struct tty_port *port裝置的 tty_port
struct tty_struct *tty正在關閉的 tty
struct file *filp傳遞的檔案指標
描述
它是一個通用助手,用於驅動程式的 tty->ops->close 中。它包裝了一系列 tty_port_close_start()、tty_port_shutdown() 和 tty_port_close_end()。後兩個僅在這是最後一次關閉時呼叫。有關詳細資訊,請參閱相應的功能。
鎖定:呼叫者持有 tty 鎖
-
int tty_port_install(struct tty_port *port, struct tty_driver *driver, struct tty_struct *tty)¶
通用 tty->ops->install 處理程式
引數
struct tty_port *port裝置的 tty_port
struct tty_driver *driver此裝置的 tty_driver
struct tty_struct *tty要安裝的 tty
描述
它與 tty_standard_install() 相同,只是提供的 port 連結到由 tty 指定的具體 tty。使用此或 tty_port_register_device()(或兩者)。作為最後的手段,呼叫 tty_port_link_device()。
-
int tty_port_open(struct tty_port *port, struct tty_struct *tty, struct file *filp)¶
通用 tty->ops->open 處理程式
引數
struct tty_port *port裝置的 tty_port
struct tty_struct *tty要開啟的 tty
struct file *filp傳遞的檔案指標
描述
它是一個通用助手,用於驅動程式的 tty->ops->open 中。如果裝置尚未啟用,則使用 port->ops->activate 啟用裝置。並使用 tty_port_block_til_ready() 等待裝置準備就緒(例如,升高 DTR/CTS 並等待載波)。
請注意,當 port->ops->activate 返回錯誤時,不會呼叫 port->ops->shutdown(相反,會呼叫 tty->ops->close)。
鎖定:呼叫者持有 tty 鎖。
注意
可能會刪除並重新獲取 tty 鎖(在 tty_port_block_til_ready() 中),因此 tty 和 port 的狀態可能已更改(例如,現在可能已結束通話)。
TTY 引用計數¶
-
struct tty_struct *tty_port_tty_get(struct tty_port *port)¶
獲取 tty 引用
引數
struct tty_port *porttty 埠
描述
返回一個受引用計數保護的 tty 例項,如果埠未與 tty 關聯(例如,由於關閉或結束通話),則返回 NULL。
-
void tty_port_tty_set(struct tty_port *port, struct tty_struct *tty)¶
設定埠的 tty
引數
struct tty_port *porttty 埠
struct tty_struct *ttytty
描述
關聯埠和 tty 對。管理任何內部引用計數。傳遞 NULL 以取消埠關聯。
TTY 助手¶
引數
struct tty_port *porttty 埠
bool check_clocal僅結束通話
CLOCAL未設定的 tty?
引數
struct tty_port *porttty 埠
調變解調器訊號¶
引數
struct tty_port *porttty 埠
描述
載波檢測邏輯的包裝器。目前,這用於隱藏一些內部細節。最終這將完全成為 tty 埠的內部功能。
引數
struct tty_port *porttty 埠
描述
DTR/RTS 升高邏輯的包裝器。目前,這用於隱藏一些內部細節。最終這將完全成為 tty 埠的內部功能。
引數
struct tty_port *porttty 埠
描述
DTR/RTS 升高邏輯的包裝器。目前,這用於隱藏一些內部細節。最終這將完全成為 tty 埠的內部功能。
TTY 埠參考¶
-
struct tty_port¶
埠級別資訊
定義:
struct tty_port {
struct tty_bufhead buf;
struct tty_struct *tty;
struct tty_struct *itty;
const struct tty_port_operations *ops;
const struct tty_port_client_operations *client_ops;
spinlock_t lock;
int blocked_open;
int count;
wait_queue_head_t open_wait;
wait_queue_head_t delta_msr_wait;
unsigned long flags;
unsigned long iflags;
unsigned char console:1;
struct mutex mutex;
struct mutex buf_mutex;
u8 *xmit_buf;
u8 *xmit_fifo;
unsigned int close_delay;
unsigned int closing_wait;
int drain_delay;
struct kref kref;
void *client_data;
};
成員
buf此埠的緩衝區,內部鎖定
tty返回到
struct tty_struct的指標,僅在 tty 開啟時有效。使用tty_port_tty_get()獲取它(並使用tty_kref_put()釋放它)。itty返回到
struct tty_struct的內部指標。避免使用此指標。長期來看應該消除它。opstty 埠操作(如啟用、關閉),請參見
struct tty_port_operationsclient_opstty 埠客戶端操作(如 receive_buf、write_wakeup)。預設情況下,使用 tty_port_default_client_ops。
lock保護 tty 的鎖
blocked_opentty_port_block_til_ready()中等待開啟的 procs 數量count使用計數
open_wait開啟等待器佇列(例如,等待載波)
delta_msr_wait調變解調器狀態更改佇列(等待 MSR 更改)
flags使用者 TTY 標誌 (
ASYNC_)iflags內部標誌 (
TTY_PORT_)console設定後,埠為控制檯
mutex鎖定,用於開啟、關閉和其他埠操作
buf_mutexxmit_buf 分配鎖
xmit_buf某些驅動程式使用的可選 xmit 緩衝區
xmit_fifo某些驅動程式使用的可選 xmit 緩衝區
close_delay關閉埠時等待的jiffies延遲
closing_wait關閉之前傳送輸出的jiffies延遲
drain_delay如果不需要純粹的基於時間的drain,則設定為零,否則設定為fifo的大小
kref引用計數器。如果非
NULL,則達到零時呼叫 ops->destruct(),否則釋放埠。client_data指向私有資料的指標,用於 client_ops
描述
每個裝置都維護自己的埠級別資訊。struct tty_port 被引入作為此類資訊的通用結構。由於每個TTY裝置都應具有後備tty_port結構,因此每個驅動程式都可以使用這些成員。
tty埠的生命週期與tty不同,因此必須分開儲存。此外,請注意,tty -> port 對映對於tty物件的生命週期有效,但在許多情況下,port -> tty 對映僅在結束通話之前有效,因此請勿使用錯誤的路徑。
Tty埠應由 tty_port_init() 初始化,並透過 tty_port_destroy()(未使用引用計數)或 tty_port_put()(引用計數)關閉。
圍繞 struct tty_port 也有很多助手函式。最重要的是:tty_port_open(),tty_port_close()(或 tty_port_close_start() 和 tty_port_close_end() 如果需要,分開呼叫)和 tty_port_hangup()。這些根據需要呼叫 ops->activate() 和 ops->shutdown()。
TTY埠操作參考¶
-
struct tty_port_operations¶
tty_port上的操作
定義:
struct tty_port_operations {
bool (*carrier_raised)(struct tty_port *port);
void (*dtr_rts)(struct tty_port *port, bool active);
void (*shutdown)(struct tty_port *port);
int (*activate)(struct tty_port *port, struct tty_struct *tty);
void (*destruct)(struct tty_port *port);
};
成員
carrier_raised如果 port 上載波被抬起,則返回true
dtr_rts如果 active 為true,則抬起DTR線,否則降低DTR
shutdown當最後一個關閉完成或結束通話完成時呼叫,如果埠已初始化。不要用來釋放資源。僅關閉裝置。在埠互斥鎖下呼叫以針對 activate 和 shutdown 進行序列化。
activate從
tty_port_open()在埠互斥鎖下呼叫,使用埠互斥鎖進行序列化。應該開啟裝置。FIXME:從長遠來看,將tty引數移出此引數對控制檯來說是好事。
destruct在埠的最後一次put上呼叫。釋放資源,可能包括埠本身。