Subject: Re: Need help writing an LKM module
To: Chris Wareham <>
From: Quentin Garnier <>
List: tech-kern
Date: 06/27/2003 18:24:24
Le Fri, 27 Jun 2003 09:36:48 +0100
Chris Wareham a ecrit :
> Bill Studenmund wrote:
> > On Thu, 26 Jun 2003, Chris Wareham wrote:
> > 
> > 
> >>I'm trying to write an LKM module for the MIDI driver so I modify and
> >>test it easily. I started with the vnd LKM, but I can't work out where
> >>the arguments that I need to pass to midiattach() and mididetach()
> >come>from. The vnd wrapper "invents" an argument, but I guess it's not
> >that>simple for the MIDI driver.
> > 
> > 
> > No. The problem you're going to run into is the same as making an LKM
> > for a real device; that routine is called by the configuration code.
> > One of the drivers is the parent, and one is the "driver" struct for
> > this device.
> > 
> > The real problem you'll run into is the parent. It should be the audio
> > device you're attaching to. The problem is that the audio device
> > probes for the midi driver when it attaches, which is at boot. By the
> > time you can load an LKM, it's too late.
> > 
> > I'm not sure how to support what you want to do. I think it'd be good,
> > but I'm not sure how to do it. :-)
> > 
> Thanks for the explanation. I'll just have to put up with booting a new
> kernel whenever I want to test some changes.

Crafting a struct device so that midi_attach_mi (which happens to be the
function you want to call, not midiattach) accept it (and later
config_found and eventually midiattach) is possible.

As Bill said, the problem is with the effective real parent. The first
issue will be to get the softc struct of that parent, to retrieve the
necessary values needed for bus_space access. What may be another issue is
if the parent already tried to attach a midi device, and already
manipulated some registers.

The bottom line of this is that your idea is feasible, but the necessary
glue for NetBSD config system is not trivial and may take time to code.

I had thoughts some time ago about a software MIDI synthetiser that could
be loaded as a LKM. The difficult part of it is not attaching a new midi
device, but using an audio driver. That's another story, but the point is
that you can find a workaround for autoconfig. But accessing existing
devices will be different.

Quentin Garnier -
"Feels like I'm fiddling while Rome is burning down.
Should I lay my fiddle down and take a rifle from the ground ?"
Leigh Nash/Sixpence None The Richer, Paralyzed, Divine Discontents, 2002.