Subject: Re: quickest way to learn about device drivers?
To: None <>
From: Ken Hornstein <>
List: tech-kern
Date: 09/18/1998 00:14:40
>Does anyone have a suggestion as to the best place to quickly learn about
>how NetBSD device drivers work and how to begin adding a new driver?  I'm
>comfortable with C as far as writing smallish userland type programs, but
>know absolutely nothing about kernel programming.  I flipped through a few
>books (in particular the design of 4.4 BSD book), but nothing jumped out
>at me as the place to start.  My interest is so I can start work on
>porting over a preliminary FreeBSD driver for a isa card I have.  I've
>heard talk of "bus_space"?  Any pointers to the correct part of some
>manual for info on that?  

Most of what you need is available .... it's just scattered around.

The 4.4 BSD book gives some general overviews on higher-level concepts
(like process context versus interrupt context).

The _easiest_ thing to do is find a device driver that's closest to
what your card does, and copy it :-)  A large amount of the framework
already exists, and you don't need to worry about how it works at
this stage ... you just need to provide the right routines to hook
into the kernel.

At a bare minimum, you'll want to add information about your driver
to /sys/dev/files.isa, and make a probe routine that the kernel can
call at boot time.  Once you get the probe routine working, you can
then progress onto the attach routine and then to the open/close/read/
write routines (or perhaps other routines, if for example you're
doing a network card or a SCSI adapter).

The bus space stuff is all documented pretty well, and there are plenty
of examples in other device drivers.  In a nutshell, you'll want to
map memory or I/O space with bus_space_map(), and then use the bus_space
read/write functions to access those devices using the tags you got
from the attach routine and from bus_space_map().