Initial import of minimal character device driver based on Brett's Lymn contributions
[eleutheria.git] / cdev / mydev.c
blob4ec652b1cb3cd026fe127d182485dff18bf9fa55
1 #include <sys/param.h>
2 #include <sys/systm.h>
3 #include <sys/proc.h>
4 #include <sys/errno.h>
5 #include <sys/ioctl.h>
6 #include <sys/device.h>
7 #include <sys/conf.h>
8 #include <sys/mydev.h>
10 struct mydev_softc {
11 struct device mydev_dev;
14 /* Autoconfiguration glue */
15 void mydevattach(struct device *parent, struct device *self, void *aux);
16 int mydevopen(dev_t device, int flags, int fmt, struct lwp *process);
17 int mydevclose(dev_t device, int flags, int fmt, struct lwp *process);
18 int mydevioctl(dev_t device, u_long command, caddr_t data,
19 int flags, struct lwp *process);
21 /* just define the character device handlers because that is all we need */
22 const struct cdevsw mydev_cdevsw = {
23 mydevopen,
24 mydevclose,
25 noread,
26 nowrite,
27 mydevioctl,
28 nostop,
29 notty,
30 nopoll,
31 nommap,
32 nokqfilter,
33 0 /* int d_type; */
37 * Attach for autoconfig to find.
39 void
40 mydevattach(struct device *parent, struct device *self, void *aux)
42 /* nothing to do for mydev, this is where resources that
43 need to be allocated/initialised before open is called
44 can be set up */
48 * Handle an open request on the device.
50 int
51 mydevopen(dev_t device, int flags, int fmt, struct lwp *process)
53 return 0; /* this always succeeds */
57 * Handle the close request for the device.
59 int
60 mydevclose(dev_t device, int flags, int fmt, struct lwp *process)
62 return 0; /* again this always succeeds */
66 * Handle the ioctl for the device
68 int
69 mydevioctl(dev_t device, u_long command, caddr_t data, int flags,
70 struct lwp *process)
72 int error;
73 struct mydev_params *params = (struct mydev_params *)data;
75 error = 0;
76 switch (command) {
77 case MYDEVTEST:
78 printf("Got number of %d and string of %s\n",
79 params->number, params->string);
80 break;
82 default:
83 error = ENODEV;
86 return (error);