Subject: Re: when bdev_xxx_init(c,n) is called ?
To: Sera <esha@sharada.ncore.soft.net>
From: Ken Hornstein <kenh@cmf.nrl.navy.mil>
List: tech-kern
Date: 11/06/1998 01:45:47
>I suppose that the init() entry point is called by the kernel
>immediately after the system is booted, so that is provides the driver
>with an opportunity to initialize the driver and the hardware as well as
>to display messages announcing the presence of the driver and the
>hardware. But the entry points for drivers in  conf.c don't have this
>xxx_init().

Actually, you don't want the init() entry point.  You want the attach()
entry point.  That's the point where the kernel "attaches" it to NetBSD,
and typically where all of the initialization stuff happens.

>1.But if you take an example like sd (SCSI Disk) then it has
>bdev_disk_init(NSD,sd) (Is it because SCSC Disk belongs to disk category
>it is initialized by bdev_disk_init() ? )

That bdev_xxx_init() is simply a macro that does prototyping of the
standard Unix device switch routines.

>2. If so, then how many types of this init functions are there, or can
>we have our own defined bdev_xxx_init() functions ?

I think that you don't want a bdev device ... you probably want a cdev
device.  bdevs are only for devices that need to do "block" I/O and
use a strategy routine.

>3. When and where these bdev_xxx_init() functions are called ? Because I
>found these bdev_xxx_init() functions as members of a struct 'bdevsw' in
>the file /usr/src/sys/arch/i386/i386/conf.c

The probe/attach routines are called at boot time.  The open/close/read/
write routines are called when you open up the device special file who's
major number corresponds to the index into that table.  For example, if
you open up a device who's major number is 18, the "open" routine for
device number 18 in cdevsw[]/bdevsw will be called.

--Ken