Mike Smith wrote:
>
> > I'm a newbie to device driver writing and I have been learning well by
> > reading the code of the other drivers in the system. I would ultimately
> > like to port a linux driver for a VoIP telephony card (Quicknet
> > PhoneJack) to FreeBSD, and so far I have a skeleton driver which does
> > successfully probe the card.
>
> It does? How? Is this a PnP card?
Yes, it is a PnP card.
> MAKEDEV is a script which does not interact with the kernel in any way.
> You need to explicitly update MAKEDEV to know about your device.
Ok, thanks for clearing that up. :)
> Where are you initialising these fields in the softc? (I assume, in your
> probe, correct?)
>
Well, I think I'm initializing it correctly...see below.
> You should check the return values from bus_alloc_resource and make_dev,
> both of which you need to save in the softc so that you can detach
> correctly.
Ok, I'll try this...
One thing I did try, was to write a very simple program to open the
device (now that I have correctly created the node in /dev) and I
inserted a printf in my ixj_open() in the driver to indicate that it
entered the open function...and this does seem to work. If open
succeeds, can I safely conclude that I'm doing things right?
On another note, I also compiled my skeleton driver as a module and it
loads ok, but if I try to use my little program to open the device, it
fails. I then tried inserting printf's in the probe and attach
functions, but when I load the module I still don't get any output. It
doesn't seem the driver probes or attaches if I load it as a module.
What am I doing wrong?
Below is the skeleton driver. I apologize if posting the entire thing
was inappropriate, but this way you guys can see exactly what I'm doing,
and more specifically, what I'm doing wrong. ;)
Thanks again.
--
Regards, Devin.
#include <sys/types.h>
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/malloc.h>
#include <sys/conf.h>
#include <sys/kernel.h>
#include <sys/module.h>
#include <sys/uio.h>
#include <sys/bus.h>
#include <machine/bus.h>
#include <machine/resource.h>
#include <sys/rman.h>
#include <isa/isavar.h> /* more ISA stuff... */
struct ixj_softc { /* param struct per a dev. */
dev_t dev;
int port_rid; /* resource id for port range */
int port_used; /* nonzero if ports used */
struct resource* port_res; /* resource for port range */
};
/* Function prototypes */
static devclass_t ixj_isa_devclass;
static int ixj_isa_probe(device_t dev);
static int ixj_isa_attach(device_t dev);
static int ixj_isa_detach(device_t dev);
static d_open_t ixj_open;
static d_close_t ixj_close;
static d_read_t ixj_read;
static d_write_t ixj_write;
static d_ioctl_t ixj_ioctl;
#define CDEV_MAJOR 100
#define NIXJ 16
static struct cdevsw ixj_cdevsw = {
ixj_open, /* open */
ixj_close, /* close */
ixj_read, /* read */
ixj_write, /* write */
ixj_ioctl, /* ioctl */
nopoll,
nommap,
nostrategy,
"ixj", /* name */
CDEV_MAJOR, /* major */
nodump,
nopsize,
0,
-1 /* bmaj */
};
/* Possible Vendor ID's */
/* add ID's for all cards here
*/
static struct isa_pnp_id ixj_ids[] = {
{ 0x10048946, "QTI0400 Internet PhoneJack" }, /* QTI0400 */
{ 0, NULL }
};
static int
ixj_isa_probe(device_t dev) /* isapnp probe */
{
struct ixj_softc *sc = device_get_softc(dev);
/* initialize softc
*/
bzero(sc, sizeof(struct ixj_softc));
/* get value from pnp probe */
if(ISA_PNP_PROBE(device_get_parent(dev), dev, ixj_ids) == ENXIO)
return ENXIO;
return (0);
}
static int
ixj_isa_attach (device_t dev) /* attach device */
{
/* int unit = device_get_unit(dev); */
struct ixj_softc *sc = device_get_softc(dev);
struct resource *res;
int rid;
int size;
printf("attaching device.\n");
if (sc->port_used > 0) {
size = sc->port_used;
rid = sc->port_rid;
res = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid,
0ul, ~0ul, size, RF_ACTIVE);
if (res) {
sc->port_rid = rid;
sc->port_res = res;
sc->port_used = size;
}
}
sc->dev = make_dev(&ixj_cdevsw, 0, UID_ROOT, GID_WHEEL, 0666,
"phone0");
return (0);
}
static int
ixj_isa_detach (dev) /* detach device */
device_t dev;
{
struct ixj_softc *sc = device_get_softc(dev);
/* release io resources */
bus_release_resource(dev, SYS_RES_IOPORT,
sc->port_rid, sc->port_res);
return (0);
}
static device_method_t ixj_isa_methods[] = {
/* Device interface */
DEVMETHOD(device_probe, ixj_isa_probe),
DEVMETHOD(device_attach, ixj_isa_attach),
DEVMETHOD(device_detach, ixj_isa_detach),
{ 0, 0 }
};
static driver_t ixj_isa_driver = {
"ixj",
ixj_isa_methods,
sizeof(struct ixj_softc)
};
static int
ixj_open(dev_t dev, int oflags, int devtype, struct proc *p)
{
/* do stuff here */
printf("Phone device successfully opened.\n");
return (0);
}
static int
ixj_close(dev_t dev, int fflag, int devtype, struct proc *p)
{
/* do stuff here */
printf("Phone device successfully closed.\n");
return (0);
}
static int
ixj_read(dev_t dev, struct uio *uio, int ioflag)
{
/* do stuff here */
return (0);
}
static int
ixj_write(dev_t dev, struct uio *uio, int ioflag)
{
/* do stuff here */
return (0);
}
static int
ixj_ioctl (dev_t dev, u_long cmd, caddr_t data, int flag, struct proc
*p)
{
/* do stuff here */
return (0);
}
DRIVER_MODULE(ixj, isa, ixj_isa_driver, ixj_isa_devclass, 0, 0);
To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-hackers" in the body of the message