On Sat, 5 Jun 1999, Bruce Evans wrote: > > The isa drivers provide many bad examples. Most of them attached the > devsw in a disgusting SYSINIT even if the device is disabled. I moved > the devsw attach to the device attach function in some drivers that > I worked on. This was necessary to support pcvt and syscons sharing a > devsw entry.
Firstly, the SYSINIT code was a stopgap. It will evolve with time.. The question is one of scope. THe devsw[] entry is added at the same time that the driver is activated in the kernel. This is neither at the first probe of a particular device, nor at the attach. Both of the latter cases an occur many times, both before (for probe) and after teh first hardware is found. This is why the SYSINIT was used.. The idea was that a loadable module would have an init() routine that is called when the module is loaded and linked in. This init() should also be called in an identical way during boot for a pre-loaded module. basically the case of a preloaded module (driver) is just a special case of the more general case of a loadable module. Drivers are just a special case of the more general case of loadable modules, so a driver should have all the features of a general module. e.g. an init() routine of some sort. It therefore makes sense that if a driver module has an init() routine that is called once before any other calls to the driver, tehn this is the obvious place to do things such as installing hooks for shutdown, or timeouts etc. and for installing itself into structures such as the devsw[] arrays. It is possible to SIMULATE this by making the first probe or attach calls do the work, but it seems to me rather artificial to do so because we have the ideal place to do the work anyhow. Remember that one of the long term aims that nearly all the FreeBSD developers have expressed at one time or another is to make FreeBSD almost completely dynamic. This means that nearly all components will eventually be loadable. Including boot drivers, which can be loaded and linked in by the boot loader. Making all drivers have the 'form' required, with an separate init() routine to be called at load time is therefore a positive thing. SYSINIT is just a way of making sure that these are called early, so that the driver need not know if it was loaded or was 'preloaded'. I therefore put it to the group that the right place to do devsw[] manipulation is neither in xxx-probe, or xxxx_attach, but in xxx_init(), which is only called once, and IS called at teh right time. It should also be noted that teh devsw[] extraction code should be run from the init() code when it is run with the 'shutdown' argument. (but only when the driver arees to allow itself to be unlinked). julian > > Bruce To Unsubscribe: send mail to majord...@freebsd.org with "unsubscribe freebsd-current" in the body of the message