Use void* instead of deprecated caddr_t
[eleutheria.git] / cdev / mydev.c
blobcfcb4ca2d583fd421ba345b1e74eb9fcd798b6c4
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>
9 #include <prop/proplib.h>
11 struct mydev_softc {
12 struct device mydev_dev;
15 /* Autoconfiguration glue */
16 void mydevattach(struct device *parent, struct device *self, void *aux);
17 int mydevopen(dev_t dev, int flags, int fmt, struct lwp *process);
18 int mydevclose(dev_t dev, int flags, int fmt, struct lwp *process);
19 int mydevioctl(dev_t dev, u_long cmd, void *data,
20 int flags, struct lwp *process);
22 /* Just define the character dev handlers because that is all we need */
23 const struct cdevsw mydev_cdevsw = {
24 mydevopen,
25 mydevclose,
26 noread,
27 nowrite,
28 mydevioctl,
29 nostop,
30 notty,
31 nopoll,
32 nommap,
33 nokqfilter,
34 0 /* int d_type; */
38 * Attach for autoconfig to find.
40 void
41 mydevattach(struct device *parent, struct device *self, void *aux)
44 * Nothing to do for mydev, this is where resources that
45 * need to be allocated/initialised before open is called
46 * can be set up.
51 * Handle an open request on the dev.
53 int
54 mydevopen(dev_t dev, int flags, int fmt, struct lwp *process)
56 return 0; /* This always succeeds */
60 * Handle the close request for the dev.
62 int
63 mydevclose(dev_t dev, int flags, int fmt, struct lwp *process)
65 return 0; /* Again this always succeeds */
69 * Handle the ioctl for the dev.
71 int
72 mydevioctl(dev_t dev, u_long cmd, void *data, int flags,
73 struct lwp *process)
75 prop_dictionary_t dict, odict;
76 prop_object_t po;
77 struct mydev_params *params = (struct mydev_params *)data;
78 const struct plistref *pref;
79 int error;
80 char *val;
82 error = 0;
83 switch (cmd) {
85 case MYDEVTEST:
86 printf("Got number of %d and string of %s\n",
87 params->number, params->string);
88 break;
90 case MYDEVSETPROPS:
91 pref = (const struct plistref *)data;
92 error = prop_dictionary_copyin_ioctl(pref, cmd, &dict);
93 if (error)
94 return error;
95 odict = mydevprops;
96 mydevprops = dict;
97 prop_object_release(odict);
99 po = prop_dictionary_get(mydevprops, "key");
101 val = prop_string_cstring(po);
102 printf("<key, val> = (%s, %s)\n", "key", val);
104 break;
106 default:
107 error = ENODEV;
110 return error;