linux终端设备:tty子系统相关的初始化
? linux類系統相較于windos類系統用“魔幻”也不為過,神奇的控制臺終端如ctrl+alt+F1至F6、UI桌面打開終端、遠程ssh登錄等等,在神奇的命令行協助下總能隨時隨地完成手中的工作。
? 當然,這些功能雖不算復雜,但龐大的架構及繁多的代碼讓人有一種深不測的感覺。經過一段時間對終端相關代碼的分析對它們有了初步的了解。它們采用較為一致的思路方式實現,代碼難度也不算太高,具備字符驅動相關的知識加上足夠的耐心便可以解開這個“龐然大物”。
? linux終端子系統主要圍繞著外設(輸入設備)到內核的輸入事件處理及轉發,到達我們目前看到的效果。
? 大致思路為:外設 -> input事件子系統 -> tty子系統 -> 輸出/輸入對應的終端種類,如console、pty等。
? 終端類型可以分為:tty子系統、tty設備、console設備、pty(偽終端)設備等等,在pty這一層又做了不同的處理對應/dev/pts/ptmx->/dev/ptmx->/dev/pts/*等等,由于這部分內容過于繁多,這里先簡單描述一小部分執行邏輯,之后應該還會有相關文章繼續向后擴展內容。
目錄
1. tty
1.1 tty_class_init
1.2 tty子系統注冊
2. console
2.1 console注冊
2.2 con_init
3. 源碼結構
4. 部分結構定義
5. 擴展函數/變量
1. tty
1.1 tty_class_init
? tty子系統首先創建tty class,綁定設備號(動態生成),由class對象tty_class關聯/dev/目錄下的tty相關訪問文件,如/dev/tty0、/dev/tty1
? 通常情況下,驅動通過class名稱與其建立關系,如pci_driver的.name字段指定class名稱
static int __init tty_class_init(void) {tty_class = class_create(THIS_MODULE, "tty"); // 創建tty class指向__this_module(模塊所有者) || \/ —————————————————————————————————————————————————————————————————————— define class_create(owner, name) \ ({ \static struct lock_class_key __key; \__class_create(owner, name, &__key); \ })#ifdef MODULE extern struct module __this_module; #define THIS_MODULE (&__this_module) #else #define THIS_MODULE ((struct module *)0) #endif ——————————————————————————————————————————————————————————————————————if (IS_ERR(tty_class))return PTR_ERR(tty_class);tty_class->devnode = tty_devnode; // 設備號return 0; }postcore_initcall(tty_class_init);|| \/ ic char *tty_devnode(struct device *dev, umode_t *mode) {if (!mode)return NULL;if (dev->devt == MKDEV(TTYAUX_MAJOR, 0) ||dev->devt == MKDEV(TTYAUX_MAJOR, 2))*mode = 0666;return NULL; }class
1.2 tty子系統注冊
? tty子系統通過tty_init函數完成注冊過程,它在字符設備初始化函數chr_dev_init中調用,tty子系統實際上也屬于字符設備
? tty子系統通過tty_fops結構中的函數完成應用層的訪問,如應用程序調用open(“/dev/tty”…)函數
tty_sysctl_init(); // 注冊tty子系統標簽(配置參數) || \/ register_sysctl_table(tty_root_table);tty_root_table
cdev_init(&tty_cdev, &tty_fops); // 初始化tty_cdev設備,關聯tty_fops結構if (cdev_add(&tty_cdev, MKDEV(TTYAUX_MAJOR, 0), 1) ||register_chrdev_region(MKDEV(TTYAUX_MAJOR, 0), 1, "/dev/tty") < 0) // 注冊tty_cdev設備panic("Couldn't register /dev/tty driver\n");device_create(tty_class, NULL, MKDEV(TTYAUX_MAJOR, 0), NULL, "tty"); // 創建tty_cdev設備,指向tty_class,通過open等函數訪問/dev/tty ...return 0; } fs_initcall(chr_dev_init);tty_fops
2. console
2.1 console注冊
? console緊跟著 tty子系統之后注冊,它具有自己的操作結構console_fops,它在內核中的形式與tty子系統相似,基于tty_class創建consdev設備
? vty_init函數注冊vc0_cdev設備(/dev/tty0),通過創建vcs、vcsu、vcsa相關設備,完成向虛擬圖形界面的數據輸出等工作。vty_init函數末尾可以看到鍵盤驅動注冊函數(通常情況下,不同的按鍵廠商還是會做自己的驅動,至少在設備ID、廠商ID這部分是這樣)。
console_fops
consdev = device_create_with_groups(tty_class, NULL,MKDEV(TTYAUX_MAJOR, 1), NULL,cons_dev_groups, "console"); // 創建consdev設備,指向tty_class,通過open等函數訪問/dev/console if (IS_ERR(consdev))consdev = NULL;cons_dev_groups
#ifdef CONFIG_VTvty_init(&console_fops); #endifreturn 0; } || \/ int __init vty_init(const struct file_operations *console_fops) {cdev_init(&vc0_cdev, console_fops); // 初始化vc0_cdev設備,關聯console_fops結構if (cdev_add(&vc0_cdev, MKDEV(TTY_MAJOR, 0), 1) ||register_chrdev_region(MKDEV(TTY_MAJOR, 0), 1, "/dev/vc/0") < 0) // 注冊vc0_cdev設備panic("Couldn't register /dev/tty0 driver\n");tty0dev = device_create_with_groups(tty_class, NULL,MKDEV(TTY_MAJOR, 0), NULL,vt_dev_groups, "tty0");//注冊tty0dev設備,指向tty_class,通過open等函數訪問/dev/tty0 if (IS_ERR(tty0dev))tty0dev = NULL;vcs_init(); // 注冊、創建vcs、vcsu、vcsa設備vcs_init
console_driver = tty_alloc_driver(MAX_NR_CONSOLES, TTY_DRIVER_REAL_RAW |TTY_DRIVER_RESET_TERMIOS); // 分配cosole驅動if (IS_ERR(console_driver))panic("Couldn't allocate console driver\n");console_driver->name = "tty"; console_driver->name_base = 1;console_driver->major = TTY_MAJOR;console_driver->minor_start = 1;console_driver->type = TTY_DRIVER_TYPE_CONSOLE;console_driver->init_termios = tty_std_termios;tty_alloc_driver
if (default_utf8)console_driver->init_termios.c_iflag |= IUTF8;tty_set_operations(console_driver, &con_ops); // console_driver關聯con_ops結構if (tty_register_driver(console_driver)) // 注冊tty設備,指定tty_class,這里包括tty的多個種類,如console、ptypanic("Couldn't register console driver\n");kbd_init(); // 注冊鍵盤驅動console_map_init(); // 設置默認unicode映射 #ifdef CONFIG_MDA_CONSOLEmda_console_init(); #endifreturn 0; }con_ops
tty_register_driver
kbd_init
2.2 con_init
? 虛擬控制臺相關的初始化,如控制臺的回調、控制臺的屏幕設置、vc_SAK組合按鍵監控觸發的事件、虛擬屏幕緩存分配等等,最后注冊到通知鏈,表示控制臺已分配完成
static int __init con_init(void) {const char *display_desc = NULL;struct vc_data *vc;unsigned int currcons = 0, i;console_lock();if (!conswitchp)conswitchp = &dummy_con; // 虛擬控制臺的控制臺“開關”結構 (consw-控制臺的回調)display_desc = conswitchp->con_startup(); // "dummy device"if (!display_desc) { fg_console = 0;console_unlock();return 0;}dummy_con
for (i = 0; i < MAX_NR_CON_DRIVER; i++) {struct con_driver *con_driver = ®istered_con_driver[i];if (con_driver->con == NULL) { // 虛擬控制臺賦值con_driver->con = conswitchp;con_driver->desc = display_desc; // "dummy device"con_driver->flag = CON_DRIVER_FLAG_INIT;con_driver->first = 0;con_driver->last = MAX_NR_CONSOLES - 1;break;}}for (i = 0; i < MAX_NR_CONSOLES; i++)con_driver_map[i] = conswitchp;if (blankinterval) {blank_state = blank_normal_wait;mod_timer(&console_timer, jiffies + (blankinterval * HZ)); // 虛擬控制臺(屏幕,ctl+alt+F2...F6這種屏幕,而ctl+alt+F1屬于控制臺啟動的類Xwindow這種模擬畫面)刷新時間}for (currcons = 0; currcons < MIN_NR_CONSOLES; currcons++) {vc_cons[currcons].d = vc = kzalloc(sizeof(struct vc_data), GFP_NOWAIT); // 虛擬控制臺分配INIT_WORK(&vc_cons[currcons].SAK_work, vc_SAK); // 初始化工作隊列,vc_SAK屬于組合按鍵監控觸發的事件,如alt+k+Prtscreentty_port_init(&vc->port); // 初始化tty端口及tty_bufhead等結構,用于翻轉緩沖區刷新到線路規程visual_init(vc, currcons, 1); // 初始化虛擬控制臺的一些參數/* Assuming vc->vc_{cols,rows,screenbuf_size} are sane here. */vc->vc_screenbuf = kzalloc(vc->vc_screenbuf_size, GFP_NOWAIT); // 虛擬屏幕緩存分配vc_init(vc, vc->vc_rows, vc->vc_cols,currcons || !vc->vc_sw->con_save_screen); // 虛擬控制臺屏幕的模式、范圍、顏色等設置}tty_port_init
visual_init
vc_init
3. 源碼結構
? tty子系統標簽
tatic struct ctl_table tty_root_table[] = {{.procname = "dev",.mode = 0555,.child = tty_dir_table, // 子級標簽}, { } };? tty子系統子級標簽
static struct ctl_table tty_dir_table[] = {{.procname = "tty",.mode = 0555,.child = tty_table, // 子級標簽}, { } };? tty子系統子級標簽 ,通過/proc/sys/dev/tty/ldisc_autoload來傳遞數字
static struct ctl_table tty_table[] = {{.procname = "ldisc_autoload",.data = &tty_ldisc_autoload,.maxlen = sizeof(tty_ldisc_autoload),.mode = 0644,.proc_handler = proc_dointvec,.extra1 = SYSCTL_ZERO,.extra2 = SYSCTL_ONE,},{ } };? tty_fops 文件操作接口
static const struct file_operations tty_fops = {.llseek = no_llseek,.read_iter = tty_read,.write_iter = tty_write,.splice_read = generic_file_splice_read,.splice_write = iter_file_splice_write,.poll = tty_poll,.unlocked_ioctl = tty_ioctl,.compat_ioctl = tty_compat_ioctl,.open = tty_open,.release = tty_release,.fasync = tty_fasync,.show_fdinfo = tty_show_fdinfo, };? console_fops 文件操作接口
static const struct file_operations console_fops = {.llseek = no_llseek,.read_iter = tty_read,.write_iter = redirected_tty_write,.splice_read = generic_file_splice_read,.splice_write = iter_file_splice_write,.poll = tty_poll,.unlocked_ioctl = tty_ioctl,.compat_ioctl = tty_compat_ioctl,.open = tty_open,.release = tty_release,.fasync = tty_fasync, };? vcs_fops 文件操作接口
static const struct file_operations vcs_fops = {.llseek = vcs_lseek,.read = vcs_read,.write = vcs_write,.poll = vcs_poll,.fasync = vcs_fasync,.open = vcs_open,.release = vcs_release, };? con_ops 文件操作接口
static const struct tty_operations con_ops = {.install = con_install,.open = con_open,.close = con_close,.write = con_write,.write_room = con_write_room,.put_char = con_put_char,.flush_chars = con_flush_chars,.ioctl = vt_ioctl, #ifdef CONFIG_COMPAT.compat_ioctl = vt_compat_ioctl, #endif.stop = con_stop,.start = con_start,.throttle = con_throttle,.unthrottle = con_unthrottle,.resize = vt_resize,.shutdown = con_shutdown,.cleanup = con_cleanup, };? dummy_con 虛擬控制臺的控制臺“開關”結構
const struct consw dummy_con = {.owner = THIS_MODULE,.con_startup = dummycon_startup,.con_init = dummycon_init,.con_deinit = dummycon_deinit,.con_clear = dummycon_clear,.con_putc = dummycon_putc,.con_putcs = dummycon_putcs,.con_cursor = dummycon_cursor,.con_scroll = dummycon_scroll,.con_switch = dummycon_switch,.con_blank = dummycon_blank, }; EXPORT_SYMBOL_GPL(dummy_con);? tty_port_default_client_ops
const struct tty_port_client_operations tty_port_default_client_ops = {.receive_buf = tty_port_default_receive_buf,.lookahead_buf = tty_port_default_lookahead_buf,.write_wakeup = tty_port_default_wakeup, }; EXPORT_SYMBOL_GPL(tty_port_default_client_ops);4. 部分結構定義
? struct class
* struct class——設備類* @name:類名。* @owner:模塊所有者。* @class_groups:該類的默認屬性。* @dev_groups:屬于該類的設備的默認屬性。* @dev_kobj:表示這個類并將其鏈接到層次結構中的kobject。* @dev_uevent:當設備被添加或從該類中移除時調用*很少其他東西生成uevent來添加環境*變量。* @devnode:回調提供devtmpfs。* @class_release:調用來釋放這個類。* @dev_release:被調用釋放設備。* @shutdown_pre:在驅動程序關閉前的關閉時間調用。* @ns_type:回調使sysfs可以確定名稱空間。* @namespace:設備的命名空間屬于該類。* @get_ownership:允許類指定sysfs目錄的uid/gid*表示屬于該類的設備。通常與*設備的名稱空間。* @pm:該類的默認設備電源管理操作。* @p:驅動核心的私有數據,不是別人*驅動核心可以觸摸這個。**類是設備的高級視圖,它抽象出了底層*實現細節。驅動程序可能看到的是SCSI磁盤或ATA磁盤,但是,*在類級別,它們都是簡單的磁盤。類允許用戶空間*根據設備的功能,而不是它們的性能來使用它們*連接或他們如何工作。struct class {const char *name;struct module *owner;const struct attribute_group **class_groups;const struct attribute_group **dev_groups;struct kobject *dev_kobj;int (*dev_uevent)(struct device *dev, struct kobj_uevent_env *env);char *(*devnode)(struct device *dev, umode_t *mode);void (*class_release)(struct class *class);void (*dev_release)(struct device *dev);int (*shutdown_pre)(struct device *dev);const struct kobj_ns_type_operations *ns_type;const void *(*namespace)(struct device *dev);void (*get_ownership)(struct device *dev, kuid_t *uid, kgid_t *gid);const struct dev_pm_ops *pm;struct subsys_private *p; };5. 擴展函數/變量
? cons_dev_groups 經過轉換為 attribute_group結構的靜態對象
ATTRIBUTE_GROUPS(cons_dev); || \/ #define ATTRIBUTE_GROUPS(_name) \ static const struct attribute_group _name##_group = { \.attrs = _name##_attrs, \ }; \ __ATTRIBUTE_GROUPS(_name) || \/ define __ATTRIBUTE_GROUPS(_name) \ static const struct attribute_group *_name##_groups[] = { \&_name##_group, \NULL, \ }轉換成結構定義為: static const struct attribute_group cons_dev_group = { .attrs = cons_dev_attrs, }; static const struct attribute_group *cons_dev_groups[] = { &cons_dev_group, NULL, }? vcs_init 注冊、創建vcs、vcsu、vcsa設備
int __init vcs_init(void) { unsigned int i;if (register_chrdev(VCS_MAJOR, "vcs", &vcs_fops))panic("unable to get major %d for vcs device", VCS_MAJOR); // 注冊vcs設備,關聯vcs_fopsvc_class = class_create(THIS_MODULE, "vc"); // 創建vc class,指向__this_module(模塊所有者)device_create(vc_class, NULL, MKDEV(VCS_MAJOR, 0), NULL, "vcs"); // 創建vcs設備,指向vc_class...device_create(vc_class, NULL, MKDEV(VCS_MAJOR, 64), NULL, "vcsu"); // 創建vcsu設備...device_create(vc_class, NULL, MKDEV(VCS_MAJOR, 128), NULL, "vcsa"); // 創建vcsa設備...for (i = 0; i < MIN_NR_CONSOLES; i++)// define MIN_NR_CONSOLES 1vcs_make_sysfs(i); // 創建多個vcs*、vcsu*、vcsa*設備...return 0; } || \/ void vcs_make_sysfs(int index) {device_create(vc_class, NULL, MKDEV(VCS_MAJOR, index + 1), NULL,"vcs%u", index + 1);device_create(vc_class, NULL, MKDEV(VCS_MAJOR, index + 65), NULL,"vcsu%u", index + 1);device_create(vc_class, NULL, MKDEV(VCS_MAJOR, index + 129), NULL,"vcsa%u", index + 1); }vcs_fops
? tty_alloc_driver 分配tty驅動
struct tty_driver *__tty_alloc_driver(unsigned int lines, struct module *owner,unsigned long flags) {struct tty_driver *driver;unsigned int cdevs = 1;int err;if (!lines || (flags & TTY_DRIVER_UNNUMBERED_NODE && lines > 1))return ERR_PTR(-EINVAL);driver = kzalloc(sizeof(*driver), GFP_KERNEL);if (!driver)return ERR_PTR(-ENOMEM);kref_init(&driver->kref);driver->num = lines;driver->owner = owner;driver->flags = flags;/* TTY_DRIVER_DEVPTS_MEM 0x0010** 不要使用標準的數組(&tty_driver.ttys和&tty_driver.termios)* 而是使用通過devpts文件系統輸入的動態內存* 這只適用于PTY驅動程序**/if (!(flags & TTY_DRIVER_DEVPTS_MEM)) {driver->ttys = kcalloc(lines, sizeof(*driver->ttys),GFP_KERNEL);driver->termios = kcalloc(lines, sizeof(*driver->termios),GFP_KERNEL);if (!driver->ttys || !driver->termios) {err = -ENOMEM;goto err_free_all;}}/* TTY_DRIVER_DYNAMIC_ALLOC 0x0040** 不要為驅動程序(&tty_driver.ports)分配每行需要的結構* 因為這會浪費內存* 這只適用于PTY驅動程序**/if (!(flags & TTY_DRIVER_DYNAMIC_ALLOC)) {driver->ports = kcalloc(lines, sizeof(*driver->ports),GFP_KERNEL);if (!driver->ports) {err = -ENOMEM;goto err_free_all;}cdevs = lines;}driver->cdevs = kcalloc(cdevs, sizeof(*driver->cdevs), GFP_KERNEL);if (!driver->cdevs) {err = -ENOMEM;goto err_free_all;}return driver;... }EXPORT_SYMBOL(__tty_alloc_driver);? tty_register_driver
int tty_register_driver(struct tty_driver *driver) {int error;int i;dev_t dev;struct device *d;if (!driver->major) {error = alloc_chrdev_region(&dev, driver->minor_start,driver->num, driver->name);// 分配設備號if (!error) {driver->major = MAJOR(dev);driver->minor_start = MINOR(dev);}} else {dev = MKDEV(driver->major, driver->minor_start);error = register_chrdev_region(dev, driver->num, driver->name);// 注冊設備號}if (error < 0)goto err;if (driver->flags & TTY_DRIVER_DYNAMIC_ALLOC) {error = tty_cdev_add(driver, dev, 0, driver->num); // 分配、注冊驅動并且關聯tty_fopsif (error)goto err_unreg_char;}tty_cdev_add
mutex_lock(&tty_mutex);list_add(&driver->tty_drivers, &tty_drivers); // 驅動加入tty鏈表mutex_unlock(&tty_mutex);if (!(driver->flags & TTY_DRIVER_DYNAMIC_DEV)) {for (i = 0; i < driver->num; i++) {d = tty_register_device(driver, i, NULL);if (IS_ERR(d)) {error = PTR_ERR(d);goto err_unreg_devs;}}}tty_register_device
proc_tty_register_driver(driver);driver->flags |= TTY_DRIVER_INSTALLED;return 0;? tty_cdev_add
static int tty_cdev_add(struct tty_driver *driver, dev_t dev,unsigned int index, unsigned int count) {int err;/* init here, since reused cdevs cause crashes */driver->cdevs[index] = cdev_alloc(); // 分配字符設備結構if (!driver->cdevs[index])return -ENOMEM;driver->cdevs[index]->ops = &tty_fops; // 為驅動關聯tty_fops結構driver->cdevs[index]->owner = driver->owner;err = cdev_add(driver->cdevs[index], dev, count); // 注冊字符設備if (err)kobject_put(&driver->cdevs[index]->kobj);return err; }? tty_register_device 注冊tty設備,指定tty_class,這里包括tty的多個種類,如console、pty
vice *tty_register_device(struct tty_driver *driver, unsigned index,struct device *device) {return tty_register_device_attr(driver, index, device, NULL, NULL); } || \/ struct device *tty_register_device_attr(struct tty_driver *driver,unsigned index, struct device *device,void *drvdata,const struct attribute_group **attr_grp) {char name[64];dev_t devt = MKDEV(driver->major, driver->minor_start) + index;struct ktermios *tp;struct device *dev;int retval;if (index >= driver->num) {pr_err("%s: Attempt to register invalid tty line number (%d)\n",driver->name, index);return ERR_PTR(-EINVAL);}/* tty設備類型* #define TTY_DRIVER_TYPE_SYSTEM 0x0001 內部使用* #define TTY_DRIVER_TYPE_CONSOLE 0x0002 控制臺* #define TTY_DRIVER_TYPE_SERIAL 0x0003 串口* #define TTY_DRIVER_TYPE_PTY 0x0004 PTY(偽終端)* #define TTY_DRIVER_TYPE_SCC 0x0005 /* scc driver */* #define TTY_DRIVER_TYPE_SYSCONS 0x0006 內部使用*/if (driver->type == TTY_DRIVER_TYPE_PTY)pty_line_name(driver, index, name); // pty通用名稱,PTY_TYPE_SLAVE類型指定為"tty",其他類型為nameelsetty_line_name(driver, index, name); // 包含TTY_DRIVER_UNNUMBERED_NODE類型創建名稱如"/dev/ttyprintk",否則如"/dev/ttyprintk0..."dev = kzalloc(sizeof(*dev), GFP_KERNEL);if (!dev)return ERR_PTR(-ENOMEM);dev->devt = devt;dev->class = tty_class; // 設置指定tty_classdev->parent = device;dev->release = tty_device_create_release;dev_set_name(dev, "%s", name);dev->groups = attr_grp;dev_set_drvdata(dev, drvdata);dev_set_uevent_suppress(dev, 1); // dev->kobj.uevent_suppress=1retval = device_register(dev); // 注冊設備... }? kbd_init 注冊鍵盤驅動
int __init kbd_init(void) {int i;int error;for (i = 0; i < MAX_NR_CONSOLES; i++) {kbd_table[i].ledflagstate = kbd_defleds(); // &0x20 ? 數字鎖定模式kbd_table[i].default_ledflagstate = kbd_defleds();kbd_table[i].ledmode = LED_SHOW_FLAGS; // 傳統模式kbd_table[i].lockstate = KBD_DEFLOCK;kbd_table[i].slockstate = 0;kbd_table[i].modeflags = KBD_DEFMODE; // 鍵盤重復 | 0-meta,1-meta=帶ESC的前綴kbd_table[i].kbdmode = default_utf8 ? VC_UNICODE : VC_XLATE; // Unicode模式}kbd_init_leds(); // LED觸發接口error = input_register_handler(&kbd_handler); // 注冊新的輸入處理程序if (error)return error;tasklet_enable(&keyboard_tasklet); // 用于減小結構體tasklet_struct中字段count的值,等于0時重新相應軟中斷重新使能tasklet_schedule(&keyboard_tasklet); // 等待獲得CPU資源并被調度執行return 0; }? tty_port_init 初始化tty端口及tty_bufhead等結構,用于翻轉緩沖區刷新到線路規程
void tty_port_init(struct tty_port *port) { memset(port, 0, sizeof(*port));tty_buffer_init(port); // 初始化tty_bufhead結構,初始化工作隊列,用于flush_to_ldisc函數 (翻轉緩沖區刷新到線路規程)init_waitqueue_head(&port->open_wait);init_waitqueue_head(&port->delta_msr_wait);mutex_init(&port->mutex);mutex_init(&port->buf_mutex);spin_lock_init(&port->lock);port->close_delay = (50 * HZ) / 100;port->closing_wait = (3000 * HZ) / 100;port->client_ops = &tty_port_default_client_ops;kref_init(&port->kref); } EXPORT_SYMBOL(tty_port_init);tty_port_default_client_ops
? visual_init 初始化虛擬控制臺的一些參數
static void visual_init(struct vc_data *vc, int num, int init) {/* ++Geert: vc->vc_sw->con_init determines console size */if (vc->vc_sw)module_put(vc->vc_sw->owner);vc->vc_sw = conswitchp; // 虛擬控制臺的控制臺“開關”結構 #ifndef VT_SINGLE_DRIVERif (con_driver_map[num])vc->vc_sw = con_driver_map[num]; // consw-控制臺的回調 #endif__module_get(vc->vc_sw->owner);vc->vc_num = num; // 控制臺編號/* 對于每個現有的顯示器,* 我們都有一個指向該顯示器上當前可見的控制臺的指針,* 允許適當刷新fg_console以外的控制臺。* 除非低級驅動程序提供自己的display_fg變量,* 否則我們將此變量用于“主顯示”。* /vc->vc_display_fg = &master_display_fg;if (vc->uni_pagedict_loc)con_free_unimap(vc);vc->uni_pagedict_loc = &vc->uni_pagedict;vc->uni_pagedict = NULL;vc->vc_hi_font_mask = 0;vc->vc_complement_mask = 0;vc->vc_can_do_color = 0;/** #define DEFAULT_BELL_PITCH 750* #define DEFAULT_BELL_DURATION (HZ/8)* #define DEFAULT_CURSOR_BLINK_MS 200*/vc->vc_cur_blink_ms = DEFAULT_CURSOR_BLINK_MS;vc->vc_sw->con_init(vc, init); // dummycon_init函數if (!vc->vc_complement_mask)vc->vc_complement_mask = vc->vc_can_do_color ? 0x7700 : 0x0800;vc->vc_s_complement_mask = vc->vc_complement_mask;vc->vc_size_row = vc->vc_cols << 1;vc->vc_screenbuf_size = vc->vc_rows * vc->vc_size_row; }? vc_init 虛擬控制臺屏幕的模式、范圍、顏色等設置
static void vc_init(struct vc_data *vc, unsigned int rows,unsigned int cols, int do_clear) {int j, k ;vc->vc_cols = cols; vc->vc_rows = rows;vc->vc_size_row = cols << 1;vc->vc_screenbuf_size = vc->vc_rows * vc->vc_size_row;set_origin(vc);vc->vc_pos = vc->vc_origin;reset_vc(vc);for (j=k=0; j<16; j++) {vc->vc_palette[k++] = default_red[j] ;vc->vc_palette[k++] = default_grn[j] ;vc->vc_palette[k++] = default_blu[j] ;}vc->vc_def_color = default_color;vc->vc_ulcolor = default_underline_color;vc->vc_itcolor = default_italic_color;vc->vc_halfcolor = 0x08; /* grey */init_waitqueue_head(&vc->paste_wait);reset_terminal(vc, do_clear); }總結
以上是生活随笔為你收集整理的linux终端设备:tty子系统相关的初始化的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Java图书查询系统实例
- 下一篇: VS2008 断点不起作用 失效