6 #include <sys/device.h>
9 #include <prop/proplib.h>
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
= {
38 * Attach for autoconfig to find.
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
51 * Handle an open request on the dev.
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.
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.
72 mydevioctl(dev_t dev
, u_long cmd
, void *data
, int flags
,
75 prop_dictionary_t dict
, odict
;
77 struct mydev_params
*params
= (struct mydev_params
*)data
;
78 const struct plistref
*pref
;
86 printf("Got number of %d and string of %s\n",
87 params
->number
, params
->string
);
91 pref
= (const struct plistref
*)data
;
92 error
= prop_dictionary_copyin_ioctl(pref
, cmd
, &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
);