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
, caddr_t 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
, caddr_t data
, int flags
,
75 prop_dictionary_t dict
;
77 struct mydev_params
*params
;
78 const struct plistref
*pref
;
85 /* Pass data in the conventional way */
86 params
= (struct mydev_params
*)data
;
87 printf("Got number of %d and string of %s\n",
88 params
->number
, params
->string
);
92 /* Use proplib(3) for user/kernel communication */
93 pref
= (const struct plistref
*)data
;
94 error
= prop_dictionary_copyin_ioctl(pref
, cmd
, &dict
);
98 /* Print dict's count for debugging purposes */
99 printf("count = %u\n", prop_dictionary_count(dict
));
101 /* Retrieve object associated with "key" key */
102 ps
= prop_dictionary_get(dict
, "key");
104 prop_object_release(dict
);
105 printf("prop_dictionary_get()\n");
110 val
= prop_string_cstring(ps
);
111 prop_object_release(ps
);
112 printf("<key, val> = (%s, %s)\n", "key", val
== NULL
? "null" : val
);
115 prop_object_release(dict
);
119 /* Invalid operation */