Date: Sat, 01 Feb 1997 18:36:59 -0500 From: "Brian J. McGovern" <mcgovern@spoon.beta.com> To: hackers@freebsd.org Subject: Device driver help needed... Message-ID: <199702012336.SAA12533@spoon.beta.com>
index | next in thread | raw e-mail
Ok. I'm sure that now I've terribly bastardized the uio structure, but at
least the damn thing compiles :) Let see if I can get some comment
on my interpretation of the uio stucture:
struct uio
{
struct iovec *uio_iov; /* Pointer to IO Vector (possible array?) */
int uio_iovcnt; /* Number of IO vectors (?) */
off_t uio_offset; /* Offset in to device */
int uio_resid; /* Length of read request (?) */
enum uio_seg uio_segflg; /* I assume a segment of some kind, but I
can only find reference to UIO_SYSSPACE */
enum uio_rw uio_rw; /* UIO_READ or UIO_WRITE (type of operation(?)) */
struct proc *uio_procp; /* No idea, but I've seen it set to curproc */
};
Ok, guys. Beat me up, and let me know whats incorrect.
With that in mind, I've bent my device driver to look like this:
------ foo.c ---------------------------------------
#define KERNEL
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/reboot.h>
#include <sys/ioctl.h>
#include <sys/tty.h>
#include <sys/proc.h>
#include <sys/conf.h>
#include <sys/file.h>
#include <sys/uio.h>
#include <sys/kernel.h>
#include <sys/malloc.h>
#include <sys/syslog.h>
#ifdef DEVFS
#include <sys/devfsext.h>
#endif
#include <machine/clock.h>
#include <i386/isa/isa.h>
#include <i386/isa/isa_device.h>
static char message[] = "The quick brown fox jumps over a lazy dog\n";
#define CDEV_MAJOR 20
static d_read_t fooread;
static struct cdevsw foo_cdevsw =
{
nxopen, nxclose, fooread, nxwrite,
nxioctl, nxstop, nxreset, nxdevtotty,
nxselect, nxmmap, NULL, "foo", NULL, -1
};
fooinit()
{
}
static int fooread(dev,myuio, flag)
dev_t dev;
struct uio *myuio;
int flag;
{
unsigned char *buffer_pointer;
int toread;
if ((myuio->uio_iovcnt != 1) || (MINOR(dev) != 0))
return ENODEV;
while(myuio->uio_resid)
{
buffer_pointer = (message + (myuio->uio_offset % sizeof(message)));
toread = ((long unsigned int)(message + sizeof(message)) - (long unsigned int)buffer_pointer);
uiomove(buffer_pointer, toread, myuio);
myuio->uio_offset + toread;
myuio->uio_resid = myuio->uio_resid - toread;
}
}
#define CDEV_MAJOR 20
-------------------------------------------------
Now, I'm sure there are bugs in there. Hell, I didn't know what I was doing
half the time :) But, now its time to start debugging, which means I need
to get it in to the kernel. Someone mentioned using SYSINIT to get it working
as a pseudo-device driver. The file above is located in
/usr/src/sys/i386/addons/foo.c. Anyone care to give me a set of steps (and
code changes) to get it in the kernel? Thanks.
-Brian
help
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199702012336.SAA12533>
