FreeBSD Device Driver Writer's Guide : Linking Into the Kernel.
Previous: Header Files
Next: Standard Model

4. Linking Into the Kernel.

In FreeBSD, support for the ISA and EISA busses is i386 specific. While FreeBSD itself is presently available on the i386 platform, some effort has been made to make the PCI, PCCARD, and SCSI code portable. The ISA and EISA specific code resides in /usr/src/sys/i386/isa and /usr/src/sys/i386/eisa respectively. The machine independent PCI, PCCARD, and SCSI code reside in /usr/src/sys/{pci,pccard,scsi}. The i386 specific code for these reside in /usr/src/sys/i386/{pci,pccard,scsi}.

In FreeBSD, a device driver can be either binary or source. There is no ``official'' place for binary drivers to reside. BSD/OS uses something like sys/i386/OBJ. Since most drivers are distributed in source, the following discussion refers to a source driver. Binary only drivers are sometimes provided by hardware vendors who wish to maintain the source as proprietary.

A typical driver has the source code in one c-file, say dev.c. The driver also can have some include files; devreg.h typically contains public device register declarations, macros, and other driver specific declarations. Some drivers call this devvar.h instead. Some drivers, such as the dgb (for the Digiboard PC/Xe), require microcode to be loaded onto the board. For the dgb driver the microcode is compiled and dumped into a header file ala file2c(1).

If the driver has data structures and ioctl's which are specific to the driver/device, and need to be accessible from user-space, they should be put in a separate include file which will reside in /usr/include/machine/ (some of these reside in /usr/include/sys/). These are typically named something like ioctl_dev.h or devio.h.

If a driver is being written which, from user space is identical to a device which already exists, care should be taken to use the same ioctl interface and data structures. For example, from user space, a SCSI CDROM drive should be identical to an IDE cdrom drive; or a serial line on an intelligent multiport card (Digiboard, Cyclades, ...) should be identical to the sio devices. These devices have a fairly well defined interface which should be used.

There are two methods for linking a driver into the kernel, static and the LKM model. The first method is fairly standard across the *BSD family. The other method was originally developed by Sun (I believe), and has been implemented into BSD using the Sun model. I don't believe that the current implementation uses any Sun code.

4.1. Standard Model

4.1.1. Adding to the driver list.
4.1.2. Make room in conf.c
4.1.3. Adding your device to the config file.
4.1.4. config(8)
4.1.5. Making device nodes.
4.1.6. Reboot.

4.2. Loadable Kernel Module (LKM)

4.3. Device Type Idiosyncrasies

4.3.1. Character
4.3.2. Block
4.3.3. Network
4.3.4. Line Discipline

4.4. Bus Type Idiosyncrasies

4.4.1. ISA
4.4.2. EISA
4.4.3. PCI
4.4.4. SCSI
4.4.5. PCCARD

FreeBSD Device Driver Writer's Guide : Linking Into the Kernel.
Previous: Header Files
Next: Standard Model
freebsd-questions@freebsd.org