Subject: Need help writing an LKM wrapper
To: NetBSD Help mailing list <netbsd-help@netbsd.org>
From: Chris Wareham <chris.wareham@iosystems.co.uk>
List: netbsd-help
Date: 06/17/2003 16:21:16
This is a multi-part message in MIME format.
--------------030408000506000804010606
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit

I'm trying to write an LKM wrapper for the MIDI driver so I can debug it
a little easier. 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>/. What's the
portable way to add an extra include argument to the Makefile that will
point to this directory?

Chris
-- 
chris.wareham@iosystems.co.uk (work)
chris.wareham@btopenworld.com (home)

--------------030408000506000804010606
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);
}

--------------030408000506000804010606--