tech-kern archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: USB LKM driver question (pwc port)

On Tue, Feb 26, 2008 at 09:12:25PM +0100, Matthias Drochner wrote:
> said:
> > However, I am unsure as to what I shall put in the MOD_DRV declaration
> >  that follows USB_DECLARE_DRIVER. I found no help looking around in
> > the  examples, since no LKM handles USB. 
> I'm currently working on some changes to improve loadable
> driver support for USB. As things look now, you might be able
> to get an LKM working with the existing framework, if you
> load the LKM before plugging in the device.

It definitely works; I've done it.  I sent Vincent the LKM skeleton off-
list, but it's probably worth repeating here for the archives.

> I'd suggest using eg sys/lkm/dev/pci/dummy_pci as a starting
> point. You need to adapt the attachment information to the
> USB "usbifif" interface, see dev/usb/files.usb.

My skeleton is for a whole-device attachment (ie, usbdevif), because
the gadget I was targeting is a something that only comes in a one-
function variant and doesn't have any useful interfaces AFAICT.  But
the idea should be adaptable it a interface-attached device.

A stripped down skeleton for the LKM shim I've been using is attached;
it may be missing a few include files since I noticed it was a little
heavy from my attempt when then LKM shim and driver lived in a single
source file and took the pruning shears to it before posting without
actually testing it again.

I haven't included the driver itself, since this wrapper could  be 
linked with the driver source of any of the USB drivers with the
uxxx -> yourdevice replacment.  The Makefile is also attached.


  Time is an illusion; lunchtime, doubly so.     |/\/\|           Rafal Boni
                   -- Ford Prefect               |\/\/|
/* $NetBSD$ */

#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>

#include <sys/lkm.h>
#include <sys/device.h>

#include <dev/usb/usb.h>
#include <dev/usb/usbdi.h>
#include <dev/usb/usbdi_util.h>
#include <dev/usb/usbdevs.h>


extern struct cfdriver uxxx_cd;
extern struct cfattach uxxx_ca;

/* locators: port, config, iface, vendor, product, release */
static int usbdevloc[] = { -1, -1, -1, -1, -1, -1 }; 

static struct cfparent uhubparent = {
        "usbdevif", "uhub", DVUNIT_ANY
static struct cfdata uxxx_cfdata[] = {
        {"uxxx", "uxxx", 0, FSTATE_STAR, usbdevloc, 0, &uhubparent},
        { 0 }

static struct cfdriver *uxxx_cfdrivers[] = {
static struct cfattach *uxxx_cfattachs[] = {
static const struct cfattachlkminit uxxx_cfattachinit[] = {
        { "uxxx", uxxx_cfattachs },
        { NULL }

int uxxx_lkmentry(struct lkm_table *, int, int);
MOD_DRV("uxxx", uxxx_cfdrivers, uxxx_cfattachinit, uxxx_cfdata);

uxxx_lkmentry(struct lkm_table *lkmtp, int cmd, int ver)

        DISPATCH(lkmtp, cmd, ver, lkm_nofunc, lkm_nofunc, lkm_nofunc);
# $NetBSD: Makefile,v 1.2 2005/12/11 12:24:48 christos Exp $

S= ${.CURDIR}/../../../..

KMOD= uxxx
SRCS= uxxx_lkm.c
NOMAN=  #yes


.PATH:  $S/dev/usb
BUILDSYMLINKS+= uxxx.c real-uxxx.c
SRCS+= real-uxxx.c

.include <>

Home | Main Index | Thread Index | Old Index