UNIX System Administration Handbook - Evi Nemeth [155]
struct devprobe pci_probes[] __initdata = {
is followed by an ordered list of devices. The devices higher up in the list are probed first. Probe order does not usually matter for PCI devices, but some devices are sensitive. Just to be sure the snarf device is detected, we’ll add it to the top of the list:
struct devprobe pci_probes[] __initdata = {
#ifdef CONFIG_SNARF
snarf_probe, 0},
#endif
The device has now been added to the Linux kernel. When we next configure the kernel, the device should appear as a configuration option under “network devices.”
Adding a FreeBSD device driver
Adding a completely new device driver to a FreeBSD machine involves adding it to a couple of configuration files and editing the kernel source code to include references to the driver’s routines. This procedure is not for the faint of heart!
We will use a FreeBSD system as our example, but all BSD systems (including NetBSD and OpenBSD) are essentially similar, except that the locations of files may differ. We will add a “snarf” device (a pseudo-network device) for our example.
First, we have to copy our source files to the proper location:
# cp ~bbraun/snarf.c /sys/pci/snarf.c
Since our device is a PCI device, we’ll put the source files in SYS/pci with all the other PCI drivers. If your device doesn’t fall into an existing category, you’ll have to put it in a new directory and edit SYS/i386/conf/files.i386. As long as the driver belongs to an existing category, it will automatically be compiled and linked into the kernel.
Next, we add the device to the kernel configuration file. We put the following entry in our EXAMPLE configuration:
device snf0 # Snarf, our fake network device.
This line instructs the config program to include the files for the driver in the kernel. Since network devices do not have major and minor numbers, we do not need to tell the kernel what the numbers are. If we were adding a block device or a character device, we would have to tell the kernel which major and minor numbers to use.
If you are installing someone else’s driver, the documentation should tell you the major and minor numbers to use. Use only the numbers in the documentation; otherwise, you might create conflicts with already-assigned numbers.
To tell the kernel which major number to use, edit SYS/i386/conf/majors.i386 and add the appropriate entry. What “the appropriate entry” means varies from device to device. Refer to the driver’s documentation.
The next steps include:
• Running config and building a new kernel
• Copying the old kernel aside and installing the new kernel
• Rebooting and testing the new kernel
These steps are all explained earlier in this chapter. Finally, you may need to create device files (see page 252) and test the device itself.
12.9 DEVICE FILES
By convention, device files are kept in the /dev directory.2 Large systems, especially those with networking and pseudo-terminals, may support hundreds of devices. Solaris and HP-UX handle this complexity quite nicely by using a separate subdirectory of /dev for each type of device: disk, cdrom, terminal, etc.
Device files are created with the mknod command, which has the syntax
mknod filename type major minor
where filename is the device file to be created, type is c for a character device or b for a block device, and major and minor are the major and minor device numbers. If you are creating a device file that refers to a driver that’s already present in your kernel, check the man page for the driver to find the appropriate major and minor device numbers (in section 4 for FreeBSD or section 7 for Solaris and HP-UX; Linux doesn’t have man pages for device drivers).
A shell script called MAKEDEV is sometimes provided (in /dev) to automatically supply default values to mknod. Study the script to find the arguments needed for your device. For example, to make PTY entries on a FreeBSD system, you’d use the following commands: