4
votes

I was writing a console driver for linux and I came across the tty interface that I need to set up for this driver. I got confused as to how tty drivers are bound with low-level drivers.

Many times the root file system already contains a lot of tty devices. I am wondering how low-level devices can bind to one of the existing tty nodes on the root file system.

For example, /dev/tty7 : Node on the root file system.
How does a low-level device driver connect with this node? Or should that low-level device define a completely new tty device?

1

1 Answers

6
votes

How can low-level devices bind to one of the existing tty nodes on the root file system?

The major and minor numbers of the console and tty drivers are hardcoded. 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, e.g. the device file is created after the device driver is loaded - not the other way around. To create the device file /dev/tty7 you'd type

$ 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. tty_register_driver appears to allocate major and minor numbers for a group of other tty drivers. 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.