Subject: driver writer wannabe needs a few hints
To: None <tech-kern@netbsd.org>
From: Jon Buller <jon@bullers.net>
List: tech-kern
Date: 12/12/2002 11:36:10
I had this working on 1.6, but now on -current, my "driver" is not
compiling so well.  If I'm really lucky, I may get audio out of my
SS20 someday, otherwise, I'm just trying to learn the basics of
writing a driver...

I have upgraded config, but either some of my sources are wrong,
or some of the man pages in section 9 are out of date.  (And the
drivers I was looking at for hints just magically work.)  My file
starts out with these struct definitions, and the prototypes to go
with them.

struct dbri_softc {
        struct device sc_dev;           /* generic device info */
        /* device-specific state goes here */
};

struct cfattach dbri_ca = {
        sizeof(struct dbri_softc),      /* size of instance data */
        dbri_match,
        dbri_attach,
        NULL,                           /* dbri_detach */
        dbri_activate
};

At the top of the file I have included sys/param.h sys/device.h
and sys/errno.h, just like driver(9) and autoconf(9) say to.  (At
least one of those pages used to say sys/error.h, but a little
poking around quickly solved that.  I'll commit the change to the
man page if I get this compiling again, and the EOPNOSUPP ->
EOPNOTSUPP change, if that hasn't been done also.)

In files.sparc, I added:

device dbri
attach dbri at sbus
file    arch/sparc/dev/dbri.c                   dbri

But I get this when I compile it now:

/usr/src/sys/arch/sparc/compile/RA/../../../../arch/sparc/dev/dbri.c:52: warning: initialization makes pointer from integer without a cast
/usr/src/sys/arch/sparc/compile/RA/../../../../arch/sparc/dev/dbri.c:53: warning: missing braces around initializer
/usr/src/sys/arch/sparc/compile/RA/../../../../arch/sparc/dev/dbri.c:53: warning: (near initialization for `dbri_ca.ca_list')
/usr/src/sys/arch/sparc/compile/RA/../../../../arch/sparc/dev/dbri.c:53: warning: initialization from incompatible pointer type
/usr/src/sys/arch/sparc/compile/RA/../../../../arch/sparc/dev/dbri.c:54: warning: initialization from incompatible pointer type
/usr/src/sys/arch/sparc/compile/RA/../../../../arch/sparc/dev/dbri.c:57: warning: initialization from incompatible pointer type
*** Error code 1


Looking through the ouput of cc -E, I see that cfattach is defined like this:

struct cfattach {
        const char *ca_name;             
        struct {        struct  cfattach  *le_next;     struct  cfattach  **le_p
rev;    }  ca_list;      
        size_t    ca_devsize;            
        cfmatch_t ca_match;              
        void    (*ca_attach)(struct device *, struct device *, void *);
        int     (*ca_detach)(struct device *, int);
        int     (*ca_activate)(struct device *, enum devact);
};

So do I need to put a string in the first slot of the initializer,
(and update the man page) or do I have something broken?  If my
system is broken, any suggestions on how to fix it?  Grabbing
current sources and rebuilding the tools didn't seem to help.  And
if that is the correct definition for cfattach, what in the world
to I put in ca_list, a pair of NULL's?  And if that is the proper
thing to do, anyone want to proofread the change I'll make to get
the man pages back in line with the code?

Jon