Subject: Need help writing an LKM module
To: NetBSD tech-kern list <tech-kern@netbsd.org>
From: Chris Wareham <chris.wareham@iosystems.co.uk>
List: tech-kern
Date: 06/26/2003 14:41:17
This is a multi-part message in MIME format.
--------------040303050601050400010905
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit
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.
Also, when compiling the real-midi.c file, it needs to include the
midi.h and sequencer.h files that are generated by the kernel config
process and live in src/sys/arch/<arch>/compile/<kernel>/. On my
system these two header files contain three defines:
#define NMIDI 1
#define NMIDIBUS 1
#define NSEQUENCER 1
These look like sane defaults, so should I just create midi.h and
sequencer.h files in my module directory?
I previously posted a similar message on the general NetBSD Help list,
but received no replies. If that's because my attempt to make a module
for the MIDI driver is miguided, then please let me know, as this is my
first attempt at getting to grips with the kernel source.
Finally, is anyone else using NetBSD for MIDI related things? If so I'd
be keen to know - I'm hoping to write a generic synthesiser patch
editor, but at the moment it seems that SysEx messages arent supported
by the NetBSD MIDI driver, hence my attempts to modify it.
Chris
--
chris.wareham@iosystems.co.uk (work)
chris.wareham@btopenworld.com (home)
--------------040303050601050400010905
Content-Type: text/x-c-code;
name="lkminit_midi.c"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="lkminit_midi.c"
#include <sys/errno.h>
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/lkm.h>
extern const struct cdevsw midi_cdevsw;
extern void midiattach(struct device *, struct device *, void *);
extern int mididetach(struct device *, int);
static int midi_lkm(struct lkm_table *lkmtp, int cmd);
int midi_lkmentry(struct lkm_table *lkmtp, int cmd, int ver);
/* populate the lkm_dev structure for this module */
/* MIDI is a character device, so I think it's safe to pass NULL for the block
* device stuff. Not so sure about the major numbers though - the vnd code
* passed -1 ...
*/
MOD_DEV("midi", "midi", NULL, 0, &midi_cdevsw, 58);
/* called when a load or unload is requested, as per DISPATCH() args */
static int
midi_lkm(struct lkm_table *lkmtp, int cmd)
{
int error = 0;
if (cmd == LKM_E_LOAD)
printf("Request to load MIDI module\n");
/* midiattach(xxx); */
else if (cmd == LKM_E_UNLOAD)
printf("Request to unload MIDI module\n");
/* error = mididetach(xxx); */
return error;
}
/* entry point when LKM is loaded - setup pointers to command functions */
int
midi_lkmentry(struct lkm_table *lkmtp, int cmd, int ver)
{
DISPATCH(lkmtp, cmd, ver, midi_lkm, midi_lkm, lkm_nofunc);
}
--------------040303050601050400010905--