tech-kern archive

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

Device driver writing ideas for a beginner



Greetings everyone.
I've been trying to familiarize myself with device writing and kernel
development in general.

What I've done so far is to write a character device driver that
implements open(), read(), close() and some ioctls. The data are
transferred across the kernel/userspace boundary with uiomove(9). The
device parameters are controlled via the "old" and the "proplib" way
as well. I've also written a userland program to actually see if the
driver works ok.

The driver lives inside a domU:

stathis# uname -a
NetBSD stathis.nbsdU 4.99.72 NetBSD 4.99.72 (XEN3_DOMU) #26: Thu Aug
21 23:36:16 EEST 2008
root@netbsd:/usr/obj/sys/arch/i386/compile/XEN3_DOMU i386
stathis#

stathis# dmesg | grep mydev
mydev: pseudo-device attached
stathis#

stathis# ./testdev
Aug 25 21:14:09 stathis /netbsd: mydev: pseudo-device open attempt by
uid=0, pid=369. (dev=49408, major=193, minor=0)
Aug 25 21:14:09 stathis /netbsd: mydev: got number of 42 and string of
Hello World
Aug 25 21:14:09 stathis /netbsd: mydev: dict count = 1
Aug 25 21:14:09 stathis /netbsd: mydev: <key, value> = (number, 42)
Aug 25 21:14:09 stathis /netbsd: mydev: <key, value> = (string, Hello World)
Aug 25 21:14:09 stathis /netbsd: mydev: uio: iov = 0xc69aec98, iovcnt
= 1, resid = 1000, vmspace = 0xc5858340
testdev: read(): ret = 1000, buffer = This is a test
Aug 25 21:14:09 stathis /netbsd: mydev: pseudo-device closed
stathis#

Now I'd like to move to the next level and perhaps turn this dummy
driver into something useful, such as report a kernel statistic or
expose a kernel interface to userland. I have zero knowledge upon
kernel's design and implementation, but I am willing to read. Any
ideas/hints would be highly appreciated.

Best regards,
Stathis Kamperis


Home | Main Index | Thread Index | Old Index