Subject: Re: IDE CD-ROM available?
To: Ian Fitchet <I.D.Fitchet@fulcrum.co.uk>
From: Ken Hornstein <kenh@entropic.com>
List: current-users
Date: 01/24/1995 16:59:03
> It doesn't look outrageously difficult so I'm prepared to have a go.
>The only problems I do have are a little more subtely related to how
>you interface to the kernel (eg what do you edit to change the
>kernel's idea of major/minor device numbers, just what is spl()
>anyway, etc etc.) Hopefully, the forthcoming White Paper ( :-) ) on
>writing device drivers will clear these things up for me.

Hey, I'm working on it!  At the end of this month I have a couple of days set
aside for this.  But some quick answers to your questions:

- look at sys/arch/i386/i386/conf.c at the cdevsw[] and bdevsw[] arrays.
  You'll see that these tables are what the kernel uses to map a major device
  number into a particular device.  The minor device number is passed to your
  device driver routines - look at other routines for examples on how to use
  this.  Since your writing a disk device, you'll need to write a strategy
  routine as well (look at the other drivers for hints on this).

- spl stands for "Set priority level" - from the days when BSD ran on machines
  with prioritized interrupts (done in software for the i386).  You'll use this
  for protection of critical regions of code (for example, if a write routine
  modifies a ring buffer that an interrupt routine will read, you will probably
  want to protect this section as the interrupt might occur in the middle of
  updating the ring).  There are various interrupt levels you can set - for
  a disk device you'll probably want to use splbio (block-I/O), and when you
  set up an interrupt handler with intr_establish(), you should set the
  interrupt priority to IPL_BIO (I think that's right).

Best advice - look at another driver that's similar to what you want to do
(like wd.c), and use that as a starting point.  In fact, a good idea is to
tear apart wd.c and try to understand it as much as possible.

(I'm willing to try to answer any question in private, but I certainly don't
have all the answers :-) ).

--Ken