TTY 驅動程式和 TTY 操作¶
分配¶
驅動程式需要做的第一件事是分配一個 struct tty_driver。這透過 tty_alloc_driver()(或 __tty_alloc_driver())來完成。接下來,新分配的結構填充了資訊。請參閱本文件末尾的 TTY 驅動程式參考,瞭解實際需要填充的內容。
分配例程需要驅動程式最多可以處理的裝置數量和標誌。標誌是那些以 TTY_DRIVER_ 開頭的標誌,如下面的 TTY 驅動程式標誌中列出和描述的。
當驅動程式即將被釋放時,會呼叫 tty_driver_kref_put()。它將遞減引用計數,如果達到零,則驅動程式將被釋放。
作為參考,這裡詳細解釋了分配和釋放函式
-
tty_alloc_driver¶
tty_alloc_driver (lines, flags)
分配 tty 驅動程式
引數
lines此驅動程式最多可以處理的行數
flagsenum tty_driver_flag中的一些,將在 driver->flags 中設定
返回值
struct tty_driver 或 PTR 編碼的錯誤(使用 IS_ERR() 及其同類)。
-
struct tty_driver *__tty_alloc_driver(unsigned int lines, struct module *owner, unsigned long flags)¶
分配 tty 驅動程式
引數
unsigned int lines此驅動程式最多可以處理的行數
struct module *owner負責此驅動程式的模組
unsigned long flagsenum tty_driver_flag中的一些,將在 driver->flags 中設定
描述
不應直接呼叫此函式,而應使用 tty_alloc_driver()。
返回值
struct tty_driver 或 PTR 編碼的錯誤(使用 IS_ERR() 及其同類)。
-
void tty_driver_kref_put(struct tty_driver *driver)¶
釋放對 tty 驅動程式的引用
引數
struct tty_driver *driver要釋放其引用的驅動程式
描述
最後的 put 將銷燬並釋放驅動程式。
TTY 驅動程式標誌¶
以下是 tty_alloc_driver()(或 __tty_alloc_driver())接受的標誌的文件
-
enum tty_driver_flag¶
TTY 驅動程式標誌
常量
TTY_DRIVER_INSTALLED此驅動程式是否已成功安裝。這是一個 tty 內部標誌。請勿觸控。
TTY_DRIVER_RESET_TERMIOS請求 tty 層在最後一個程序關閉裝置時重置 termios 設定。特別是用於 PTY。
TTY_DRIVER_REAL_RAW指示如果為此 tty 設定了此標誌,則驅動程式將保證不設定任何特殊字元處理標誌
(IGNBRK || (!BRKINT && !PARMRK)) && (IGNPAR || !INPCK)也就是說,如果沒有理由讓驅動程式將奇偶校驗和中斷字元的通知傳送到線路驅動程式,它就不會這樣做。如果設定了此標誌,則線路驅動程式可以針對此情況進行最佳化。(請注意,如果上述情況為真,也承諾不發出溢位訊號。)
TTY_DRIVER_DYNAMIC_DEV當在系統中找到裝置時,需要透過呼叫
tty_register_device()註冊各個 tty 裝置,並透過呼叫tty_unregister_device()登出,以便裝置在 sysfs 中正確顯示。如果未設定,則所有tty_driver.num條目將在呼叫tty_register_driver()時由 tty 核心在 sysfs 中建立。這供具有 tty 裝置(可以在主 tty 驅動程式已向 tty 核心註冊時出現和消失)的驅動程式使用。TTY_DRIVER_DEVPTS_MEM不要使用標準陣列(
tty_driver.ttys和tty_driver.termios),而是使用透過 devpts 檔案系統鍵控的動態記憶體。這僅適用於 PTY 驅動程式。TTY_DRIVER_HARDWARE_BREAK硬體處理中斷訊號。將請求的超時傳遞給
tty_operations.break_ctl,而不是使用簡單的開/關介面。TTY_DRIVER_DYNAMIC_ALLOC不要為此驅動程式分配每行所需的結構(
tty_driver.ports),因為它會浪費記憶體。驅動程式將負責。這僅適用於 PTY 驅動程式。TTY_DRIVER_UNNUMBERED_NODE不要建立編號的
/dev節點。例如,建立/dev/ttyprintk而不是/dev/ttyprintk0。僅當分配單個 tty 裝置的驅動程式時適用。
描述
這些是傳遞給 tty_alloc_driver() 的標誌。
註冊¶
分配並填寫 struct tty_driver 後,可以使用 tty_register_driver() 註冊。建議在 tty_alloc_driver() 的標誌中傳遞 TTY_DRIVER_DYNAMIC_DEV。如果未傳遞,則所有裝置也會在 tty_register_driver() 期間註冊,並且可以為這些驅動程式跳過以下注冊裝置段落。但是,註冊裝置中的 struct tty_port 部分仍然相關。
-
int tty_register_driver(struct tty_driver *driver)¶
註冊 tty 驅動程式
引數
struct tty_driver *driver要註冊的驅動程式
描述
由 tty 驅動程式呼叫以註冊自身。
-
void tty_unregister_driver(struct tty_driver *driver)¶
登出 tty 驅動程式
引數
struct tty_driver *driver要登出的驅動程式
描述
由 tty 驅動程式呼叫以登出自身。
註冊裝置¶
每個 TTY 裝置都應由 struct tty_port 支援。通常,TTY 驅動程式將 tty_port 嵌入到裝置的私有結構中。有關處理 tty_port 的更多詳細資訊,請參見 TTY 埠。還建議驅動程式透過 tty_port_get() 和 tty_port_put() 使用 tty_port 的引用計數。最後的 put 應該釋放 tty_port,包括裝置的私有結構。
除非 TTY_DRIVER_DYNAMIC_DEV 作為標誌傳遞給 tty_alloc_driver(),否則 TTY 驅動程式應註冊在系統中發現的每個裝置(後者是首選)。這透過 tty_register_device() 或 tty_register_device_attr() 執行,如果驅動程式想要透過 struct attribute_group 公開一些資訊。它們都註冊 index 的裝置,並且在返回時,可以開啟該裝置。稍後在 將裝置連結到埠中也描述了首選的 tty_port 變體。驅動程式可以管理空閒索引並選擇正確的索引。TTY 層僅拒絕註冊比傳遞給 tty_alloc_driver() 更多的裝置。
當裝置開啟時,TTY 層分配 struct tty_struct 並開始從 tty_driver.ops 呼叫操作,請參見 TTY 操作參考。
註冊例程的文件如下
-
struct device *tty_register_device(struct tty_driver *driver, unsigned index, struct device *device)¶
註冊 tty 裝置
引數
struct tty_driver *driver描述 tty 裝置的 tty 驅動程式
unsigned index此 tty 裝置在 tty 驅動程式中的索引
struct device *device與此 tty 裝置關聯的
struct device。此欄位是可選的,如果此 tty 裝置沒有已知的struct device,則可以安全地將其設定為 NULL。
描述
如果 tty 驅動程式的標誌設定了 TTY_DRIVER_DYNAMIC_DEV 位,則需要進行此呼叫以註冊單個 tty 裝置。如果未設定該位,則 tty 驅動程式不應呼叫此函式。
鎖定:??
返回值
指向此 tty 裝置的 struct device 的指標(或出錯時為 ERR_PTR(-EFOO))。
-
struct device *tty_register_device_attr(struct tty_driver *driver, unsigned index, struct device *device, void *drvdata, const struct attribute_group **attr_grp)¶
註冊 tty 裝置
引數
struct tty_driver *driver描述 tty 裝置的 tty 驅動程式
unsigned index此 tty 裝置在 tty 驅動程式中的索引
struct device *device與此 tty 裝置關聯的
struct device。此欄位是可選的,如果此 tty 裝置沒有已知的struct device,則可以安全地將其設定為NULL。void *drvdata要設定為裝置驅動程式的資料。
const struct attribute_group **attr_grp要在裝置上設定的屬性組。
描述
如果 tty 驅動程式的標誌設定了 TTY_DRIVER_DYNAMIC_DEV 位,則需要進行此呼叫以註冊單個 tty 裝置。如果未設定該位,則 tty 驅動程式不應呼叫此函式。
鎖定:??
返回值
指向此 tty 裝置的 struct device 的指標(或出錯時為 ERR_PTR(-EFOO))。
-
void tty_unregister_device(struct tty_driver *driver, unsigned index)¶
登出 tty 裝置
引數
struct tty_driver *driver描述 tty 裝置的 tty 驅動程式
unsigned index此 tty 裝置在 tty 驅動程式中的索引
描述
如果透過呼叫 tty_register_device() 註冊了 tty 裝置,則當 tty 裝置消失時,必須呼叫此函式。
鎖定:??
將裝置連結到埠¶
如前所述,每個 TTY 裝置都應分配一個 struct tty_port。至少在 tty_driver.ops.install() 時 TTY 層必須知道它。有一些幫助程式可以連結兩者。理想情況下,驅動程式使用 tty_port_register_device() 或 tty_port_register_device_attr() 而不是註冊時的 tty_register_device() 和 tty_register_device_attr()。這樣,驅動程式無需稍後擔心連結。
如果這不可能,驅動程式仍然可以透過 tty_port_link_device() 在實際註冊之前將 tty_port 連結到特定索引。如果仍然不合適,可以從 tty_driver.ops.install 掛鉤中使用 tty_port_install() 作為最後的手段。最後一個主要用於記憶體裝置(如 PTY),其中 tty_ports 是按需分配的。
連結例程在此處記錄
-
void tty_port_link_device(struct tty_port *port, struct tty_driver *driver, unsigned index)¶
連結 tty 和 tty_port
引數
struct tty_port *port裝置的 tty_port
struct tty_driver *driver此裝置的 tty_driver
unsigned indextty 的索引
描述
向 tty 層提供從 tty(由 index 指定)到 tty_port (port) 的連結。僅當驅動程式中未使用 tty_port_register_device() 和 tty_port_install() 中的任何一個時才使用此方法。如果使用,則必須在 tty_register_driver() 之前呼叫此方法。
-
struct device *tty_port_register_device(struct tty_port *port, struct tty_driver *driver, unsigned index, struct device *device)¶
註冊 tty 裝置
引數
struct tty_port *port裝置的 tty_port
struct tty_driver *driver此裝置的 tty_driver
unsigned indextty 的索引
struct device *device如果存在父裝置,否則為 NULL
描述
與 tty_register_device() 相同,只是提供的 port 連結到由 index 指定的特定 tty。使用此方法或 tty_port_install()(或兩者)。將 tty_port_link_device() 作為最後的手段呼叫。
-
struct device *tty_port_register_device_attr(struct tty_port *port, struct tty_driver *driver, unsigned index, struct device *device, void *drvdata, const struct attribute_group **attr_grp)¶
註冊 tty 裝置
引數
struct tty_port *port裝置的 tty_port
struct tty_driver *driver此裝置的 tty_driver
unsigned indextty 的索引
struct device *device如果存在父裝置,否則為 NULL
void *drvdata要設定為裝置驅動程式的資料。
const struct attribute_group **attr_grp要在裝置上設定的屬性組。
描述
與 tty_register_device_attr() 相同,只是提供的 port 連結到由 index 指定的特定 tty。使用此方法或 tty_port_install()(或兩者)。將 tty_port_link_device() 作為最後的手段呼叫。
TTY 驅動程式參考¶
本文件記錄了 struct tty_driver 的所有成員。必需成員在末尾註明。接下來將介紹 struct tty_operations。
-
struct tty_driver¶
TTY 裝置的驅動程式
定義:
struct tty_driver {
struct kref kref;
struct cdev **cdevs;
struct module *owner;
const char *driver_name;
const char *name;
int name_base;
int major;
int minor_start;
unsigned int num;
enum tty_driver_type type;
enum tty_driver_subtype subtype;
struct ktermios init_termios;
unsigned long flags;
struct proc_dir_entry *proc_entry;
struct tty_driver *other;
struct tty_struct **ttys;
struct tty_port **ports;
struct ktermios **termios;
void *driver_state;
const struct tty_operations *ops;
struct list_head tty_drivers;
};
成員
kref引用計數。計數歸零會釋放所有內部結構和驅動程式。
cdevs已分配/註冊的字元 /dev 裝置
owner擁有此驅動程式的模組。正在使用的驅動程式無法使用 rmmod 命令移除。由
tty_alloc_driver()自動設定。driver_name驅動程式在 /proc/tty 中使用的名稱
name用於構造 /dev 節點名稱
name_base用作構造 /dev 節點名稱的數字基數
major主 /dev 裝置號(自動分配為零)
minor_start第一個次 /dev 裝置號
num已分配的裝置數量
typeTTY 驅動程式的型別 (enum tty_driver_type)
subtypeTTY 驅動程式的子型別 (enum tty_driver_subtype)
init_termios最初為每個 TTY 設定的 termios(例如
tty_std_termios)flagsTTY 驅動程式標誌 (
TTY_DRIVER_)proc_entryproc fs 條目,內部使用
other連結的 TTY 的驅動程式;僅用於 PTY 驅動程式
ttys活動
struct tty_struct陣列,由tty_standard_install()設定portsstruct tty_port陣列;可以在初始化期間透過tty_port_link_device()和類似函式設定termios用於儲存每次 TTY 關閉時的 termios,以便下次開啟時使用
driver_state指向驅動程式的任意資料的指標
opsTTY 的驅動程式掛鉤。使用 tty_set_operations() 設定它們。儘可能在其中使用
struct tty_port輔助函式。tty_drivers內部用於連結 tty_drivers
描述
處理 struct tty_driver 的常用方法是透過 tty_alloc_driver() 分配它,設定所有必要的成員,並透過 tty_register_driver() 註冊它。最後,透過呼叫 tty_unregister_driver(),然後呼叫 tty_driver_kref_put() 來關閉驅動程式。
在呼叫 tty_register_driver() 之前需要設定的欄位包括 driver_name、name、type、subtype、init_termios 和 ops。
TTY 操作參考¶
註冊 TTY 後,TTY 層可以呼叫這些驅動程式掛鉤
-
struct tty_operations¶
驅動程式和 tty 之間的介面
定義:
struct tty_operations {
struct tty_struct * (*lookup)(struct tty_driver *driver, struct file *filp, int idx);
int (*install)(struct tty_driver *driver, struct tty_struct *tty);
void (*remove)(struct tty_driver *driver, struct tty_struct *tty);
int (*open)(struct tty_struct * tty, struct file * filp);
void (*close)(struct tty_struct * tty, struct file * filp);
void (*shutdown)(struct tty_struct *tty);
void (*cleanup)(struct tty_struct *tty);
ssize_t (*write)(struct tty_struct *tty, const u8 *buf, size_t count);
int (*put_char)(struct tty_struct *tty, u8 ch);
void (*flush_chars)(struct tty_struct *tty);
unsigned int (*write_room)(struct tty_struct *tty);
unsigned int (*chars_in_buffer)(struct tty_struct *tty);
int (*ioctl)(struct tty_struct *tty, unsigned int cmd, unsigned long arg);
long (*compat_ioctl)(struct tty_struct *tty, unsigned int cmd, unsigned long arg);
void (*set_termios)(struct tty_struct *tty, const struct ktermios *old);
void (*throttle)(struct tty_struct * tty);
void (*unthrottle)(struct tty_struct * tty);
void (*stop)(struct tty_struct *tty);
void (*start)(struct tty_struct *tty);
void (*hangup)(struct tty_struct *tty);
int (*break_ctl)(struct tty_struct *tty, int state);
void (*flush_buffer)(struct tty_struct *tty);
int (*ldisc_ok)(struct tty_struct *tty, int ldisc);
void (*set_ldisc)(struct tty_struct *tty);
void (*wait_until_sent)(struct tty_struct *tty, int timeout);
void (*send_xchar)(struct tty_struct *tty, u8 ch);
int (*tiocmget)(struct tty_struct *tty);
int (*tiocmset)(struct tty_struct *tty, unsigned int set, unsigned int clear);
int (*resize)(struct tty_struct *tty, struct winsize *ws);
int (*get_icount)(struct tty_struct *tty, struct serial_icounter_struct *icount);
int (*get_serial)(struct tty_struct *tty, struct serial_struct *p);
int (*set_serial)(struct tty_struct *tty, struct serial_struct *p);
void (*show_fdinfo)(struct tty_struct *tty, struct seq_file *m);
#ifdef CONFIG_CONSOLE_POLL;
int (*poll_init)(struct tty_driver *driver, int line, char *options);
int (*poll_get_char)(struct tty_driver *driver, int line);
void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
#endif;
int (*proc_show)(struct seq_file *m, void *driver);
};
成員
lookupstruct tty_struct *()(struct tty_driver *self, struct file *, int idx)返回與 idx 對應的 tty 裝置,如果沒有當前正在使用的裝置,則返回
NULL,如果出現錯誤,則返回ERR_PTR值。在tty_mutex下呼叫(目前!)。可選方法。預設行為是使用 self->ttys 陣列。
installint ()(struct tty_driver *self, struct tty_struct *tty)將新的 tty 安裝到 self 的內部表中。與 lookup 和 remove 方法結合使用。
可選方法。預設行為是使用 self->ttys 陣列。
removevoid ()(struct tty_driver *self, struct tty_struct *tty)從 self 的內部表中移除已關閉的 tty。與 lookup 和 remove 方法結合使用。
可選方法。預設行為是使用 self->ttys 陣列。
openint ()(struct tty_struct *tty, struct file *)當開啟特定的 tty 裝置時,將呼叫此例程。此例程是必需的;如果未填寫此例程,則嘗試開啟將失敗並顯示
ENODEV。必需方法。在持有 tty 鎖的情況下呼叫。可能會睡眠。
closevoid ()(struct tty_struct *tty, struct file *)當關閉特定的 tty 裝置時,將呼叫此例程。從此呼叫返回時,驅動程式不得再進行任何型別的 ldisc 呼叫。
備註:即使相應的 open() 失敗,也會呼叫。
必需方法。在持有 tty 鎖的情況下呼叫。可能會睡眠。
shutdownvoid ()(struct tty_struct *tty)當最後一次關閉特定的 tty 裝置時,將在 tty 鎖下呼叫此例程。它在釋放 tty 資源之前執行,因此可以在另一個函式持有 tty kref 時執行。
cleanupvoid ()(struct tty_struct *tty)當最後一次關閉特定的 tty 裝置時,將非同步呼叫此例程,以釋放資源。對於可能會睡眠的例程,這實際上是關閉的第二部分。
writessize_t ()(struct tty_struct *tty, const u8 *buf, size_t count)核心呼叫此例程,以將一系列 (count) 字元 (buf) 寫入 tty 裝置。字元可能來自使用者空間或核心空間。此例程將返回實際接受寫入的字元數。
在特殊情況下可能會並行發生。因為這包括緊急情況路徑,所以驅動程式通常不應嘗試在此處進行巧妙的鎖定。
可選:對於可寫裝置是必需的。可能不會睡眠。
put_charint ()(struct tty_struct *tty, u8 ch)核心呼叫此例程以將單個字元 ch 寫入 tty 裝置。如果核心使用此例程,則在將字元填充到驅動程式中後,必須呼叫 flush_chars() 例程(如果已定義)。如果佇列中沒有空間,則忽略該字元。
可選:如果未提供,核心將使用 write 方法。請勿直接呼叫此函式,請呼叫
tty_put_char()。flush_charsvoid ()(struct tty_struct *tty)在使用 put_char() 將一系列字元寫入 tty 裝置後,核心將呼叫此例程。
可選。請勿直接呼叫此函式,請呼叫 tty_driver_flush_chars()。
write_roomunsigned int ()(struct tty_struct *tty)此例程返回 tty 驅動程式將接受排隊寫入的字元數。此數字會隨著輸出緩衝區清空或輸出流控制生效而發生變化。
ldisc 負責對 write_room/write 呼叫的多執行緒進行智慧處理
如果提供了 write 方法,則為必需方法,否則不需要。請勿直接呼叫此函式,請呼叫
tty_write_room()chars_in_bufferunsigned int ()(struct tty_struct *tty)此例程返回裝置專用輸出佇列中的字元數。用於
tty_wait_until_sent()和 poll() 實現。可選:如果未提供,則假定裝置上沒有佇列。請勿直接呼叫此函式,請呼叫
tty_chars_in_buffer()。ioctlint ()(struct tty_struct *tty, unsigned int cmd, unsigned long arg)此例程允許 tty 驅動程式實現特定於裝置的 ioctl。如果驅動程式無法識別傳入的 ioctl 號 cmd,則應返回
ENOIOCTLCMD。可選。
compat_ioctllong ()(struct tty_struct *tty, unsigned int cmd, unsigned long arg)在 64 位系統上實現 32 位程序的 ioctl 處理。
可選。
set_termiosvoid ()(struct tty_struct *tty, const struct ktermios *old)當裝置的 termios 設定發生更改時,此例程允許通知 tty 驅動程式。新設定位於 tty->termios 中。先前的設定在 old 引數中傳遞。
API 定義為驅動程式應返回所選的實際模式。這意味著驅動程式負責修改 tty->termios 中的任何無法滿足的位,以指示正在使用的實際模式。
可選。在 tty->termios_rwsem 下呼叫。可能會睡眠。
throttlevoid ()(struct tty_struct *tty)此例程通知 tty 驅動程式,線路規程的輸入緩衝區已接近填滿,它應以某種方式發出訊號,指示不應再向 tty 傳送字元。
包括 unthrottle() 的序列化是 ldisc 層的工作。
可選:始終透過
tty_throttle_safe()呼叫。在 tty->termios_rwsem 下呼叫。unthrottlevoid ()(struct tty_struct *tty)此例程通知 tty 驅動程式,它應發出訊號,指示現在可以向 tty 傳送字元,而不必擔心線路規程的輸入緩衝區溢位。
可選。始終透過
tty_unthrottle()呼叫。在 tty->termios_rwsem 下呼叫。stopvoid ()(struct tty_struct *tty)此例程通知 tty 驅動程式,它應停止向 tty 裝置輸出字元。
在持有 tty->flow.lock 的情況下呼叫。與
start()方法序列化。可選。始終透過
stop_tty()呼叫。startvoid ()(struct tty_struct *tty)此例程通知 tty 驅動程式,它已恢復向 tty 裝置傳送字元。
在持有 tty->flow.lock 的情況下呼叫。與
stop()方法序列化。可選。始終透過
start_tty()呼叫。hangupvoid ()(struct tty_struct *tty)此例程通知 tty 驅動程式,它應結束通話 tty 裝置。
可選。在持有 tty 鎖的情況下呼叫。
break_ctlint ()(struct tty_struct *tty, int state)此可選例程請求 tty 驅動程式開啟或關閉 RS-232 埠上的 BREAK 狀態。如果 state 為 -1,則應開啟 BREAK 狀態;如果 state 為 0,則應關閉 BREAK 狀態。
如果實現了此例程,則高階 tty 驅動程式將處理以下 ioctl:
TCSBRK、TCSBRKP、TIOCSBRK、TIOCCBRK。如果驅動程式在
tty_alloc_driver()中設定TTY_DRIVER_HARDWARE_BREAK,則該介面也將使用實際時間呼叫,並且硬體應自行完成延遲工作。0 和 -1 仍用於開/關。可選:
TCSBRK/BRKP/等處理必需。可能會睡眠。flush_buffervoid ()(struct tty_struct *tty)此例程放棄裝置專用輸出緩衝區。在關閉、結束通話時呼叫,以實現
TCOFLUSHioctl 和類似操作。可選:如果未提供,則假定裝置上沒有佇列。請勿直接呼叫此函式,請呼叫
tty_driver_flush_buffer()。ldisc_okint ()(struct tty_struct *tty, int ldisc)此例程允許 tty 驅動程式決定是否可以處理特定的 ldisc。
可選。在 tty->ldisc_sem 和 tty->termios_rwsem 下呼叫。
set_ldiscvoid ()(struct tty_struct *tty)當裝置的線路規程正在更改時,此例程允許通知 tty 驅動程式。此時,該規程尚不可用。
可選。在 tty->ldisc_sem 和 tty->termios_rwsem 下呼叫。
wait_until_sentvoid ()(struct tty_struct *tty, int timeout)此例程等待裝置寫出其發射器 FIFO 中的所有字元。或者直到達到 timeout(以 jiffies 為單位)。
可選:如果未提供,則假定裝置沒有 FIFO。通常可以透過
tty_wait_until_sent()呼叫。可能會睡眠。send_xcharvoid ()(struct tty_struct *tty, u8 ch)此例程用於將高優先順序 XON/XOFF 字元 (ch) 傳送到 tty 裝置。
可選:如果未提供,則在 tty->atomic_write_lock 下呼叫 write 方法,以使其與 ldisc 序列化。
tiocmgetint ()(struct tty_struct *tty)此例程用於從 tty 驅動程式獲取調變解調器狀態位。
可選:如果未提供,則從
TIOCMGETioctl 返回ENOTTY。請勿直接呼叫此函式,請呼叫tty_tiocmget()。tiocmsetint ()(struct tty_struct *tty, unsigned int set, unsigned int clear)此例程用於將調變解調器狀態位設定為 tty 驅動程式。首先,應清除 clear 位,然後設定 set 位。
可選:如果未提供,則從
TIOCMSETioctl 返回ENOTTY。請勿直接呼叫此函式,請呼叫tty_tiocmset()。resizeint ()(struct tty_struct *tty, struct winsize *ws)當發出更改請求的終端幾何形狀為 ws 的 termios 請求時呼叫。
可選:預設操作是更新 termios 結構而不出錯。這通常是正確的行為。如果驅動程式不是可調整大小的物件(例如,序列線路),則不應在此處強制錯誤。如果需要將標準方法包裝在自己的邏輯中(通常情況下),請參閱
tty_do_resize()。get_icountint ()(struct tty_struct *tty, struct serial_icounter *icount)當 tty 裝置收到
TIOCGICOUNTioctl 時呼叫。傳遞一個核心結構 icount 以完成。可選:僅在提供時呼叫,否則將返回
ENOTTY。get_serialint ()(struct tty_struct *tty, struct serial_struct *p)當 tty 裝置收到
TIOCGSERIALioctl 時呼叫。傳遞一個核心結構 p (struct serial_struct) 以完成。可選:僅在提供時呼叫,否則將返回
ENOTTY。請勿直接呼叫此函式,請呼叫 tty_tiocgserial()。set_serialint ()(struct tty_struct *tty, struct serial_struct *p)當 tty 裝置收到
TIOCSSERIALioctl 時呼叫。傳遞一個核心結構 p (struct serial_struct) 以設定值。可選:僅在提供時呼叫,否則將返回
ENOTTY。請勿直接呼叫此函式,請呼叫 tty_tiocsserial()。show_fdinfovoid ()(struct tty_struct *tty, struct seq_file *m)當 tty 裝置檔案描述符收到來自 VFS 的 fdinfo 請求(以顯示在 /proc/<pid>/fdinfo/ 中)時呼叫。應使用資訊填充 m。
可選:僅在提供時呼叫,否則不會將任何內容寫入 m。請勿直接呼叫此函式,請呼叫 tty_show_fdinfo()。
poll_initint ()(struct tty_driver *driver, int line, char *options)kgdboc 支援(使用 kgdb、kdb 和核心偵錯程式內部結構)。呼叫此例程以初始化 HW,以便稍後透過呼叫 poll_get_char 或 poll_put_char 來使用。
可選:僅在提供時呼叫,否則將跳過作為非輪詢驅動程式。
poll_get_charint ()(struct tty_driver *driver, int line)kgdboc 支援(請參閱 poll_init)。driver 應從由 line 標識的 tty 讀取字元並返回它。
可選:僅在提供 poll_init 時呼叫。
poll_put_charvoid ()(struct tty_driver *driver, int line, char ch)kgdboc 支援(請參閱 poll_init)。driver 應將字元 ch 寫入由 line 標識的 tty。
可選:僅在提供 poll_init 時呼叫。
proc_showint ()(struct seq_file *m, void *driver)驅動程式 driver(強制轉換為
struct tty_driver)可以在 /proc/tty/driver/<driver_name> 中顯示其他資訊。只需將資訊填充到 m 中即可。可選:僅在提供時呼叫,否則不會建立 /proc 條目。
描述
此結構定義了底層 tty 驅動程式和 tty 例程之間的介面。可以定義這些例程。除非另有說明,否則它們是可選的,並且可以用 NULL 指標填充。