简体   繁体   English

低级别驱动程序和tty驱动程序之间的链接

[英]Link between low level drivers and tty drivers

I was writing a console driver for linux and I came across the tty interface that I need to set up for this driver. 我正在为linux编写一个控制台驱动程序,我遇到了我需要为此驱动程序设置的tty接口。 I got confused as to how tty drivers are bound with low-level drivers. 我对tty驱动程序如何与低级驱动程序绑定感到困惑。

Many times the root file system already contains a lot of tty devices. 很多时候,根文件系统已经包含很多tty设备。 I am wondering how low-level devices can bind to one of the existing tty nodes on the root file system. 我想知道低级设备如何绑定到根文件系统上的一个现有tty节点。

For example, /dev/tty7 : Node on the root file system. 例如, /dev/tty7 :根文件系统上的节点。
How does a low-level device driver connect with this node? 低级设备驱动程序如何与此节点连接? Or should that low-level device define a completely new tty device? 或者该低级设备是否应该定义一个全新的tty设备?

How can low-level devices bind to one of the existing tty nodes on the root file system? 低级设备如何绑定到根文件系统上现有的tty节点之一?

The major and minor numbers of the console and tty drivers are hardcoded. 控制台和tty驱动程序的主要和次要编号都是硬编码的。 You can look up the assigned major numbers on your system with: 您可以使用以下方法在系统上查找指定的主要编号:

$ cat /proc/devices

The device files binds to the device driver throgh the mknod utility, eg the device file is created after the device driver is loaded - not the other way around. 设备文件与mknod实用程序绑定到设备驱动程序,例如设备文件是在加载设备驱动程序后创建的 - 而不是相反。 To create the device file /dev/tty7 you'd type 要创建设备文件/ dev / tty7,请键入

$ mknod /dev/tty7 c 4 7

For a reference in the kernel source: drivers/tty/tty_io.c: tty_init allocates the major and minor numbers for /dev/tty and /dev/console. 对于内核源代码中的引用:drivers / tty / tty_io.c: tty_init为/ dev / tty和/ dev / console分配主要和次要编号。 tty_register_driver appears to allocate major and minor numbers for a group of other tty drivers. tty_register_driver似乎为一组其他tty驱动程序分配主要和次要数字。 Perhaps you'll find the answer if you look at the callers. 如果你看看来电者,也许你会找到答案。

If you want a high level overview of how the tty subsystem is structured then tty demystified and LDD3 Chapter 18 TTY drivers are good resources. 如果您想要对tty子系统的结构进行高级概述,那么tty揭秘并且LDD3第18章TTY驱动程序是很好的资源。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM