1 .\" Copyright (c) 1999 Chris Costello
2 .\" All rights reserved.
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\" notice, this list of conditions and the following disclaimer.
9 .\" 2. Redistributions in binary form must reproduce the above copyright
10 .\" notice, this list of conditions and the following disclaimer in the
11 .\" documentation and/or other materials provided with the distribution.
13 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 .Nm make_dev_alias_p ,
39 .Nm destroy_dev_sched ,
40 .Nm destroy_dev_sched_cb ,
41 .Nm destroy_dev_drain ,
45 and DEVFS registration for devices
50 .Fn make_dev_args_init "struct make_dev_args *args"
52 .Fn make_dev_s "struct make_dev_args *args" "struct cdev **cdev" "const char *fmt" ...
54 .Fn make_dev_alias_p "int flags" "struct cdev **cdev" "struct cdev *pdev" "const char *fmt" ...
56 .Fn destroy_dev "struct cdev *dev"
58 .Fn destroy_dev_sched "struct cdev *dev"
60 .Fn destroy_dev_sched_cb "struct cdev *dev" "void (*cb)(void *)" "void *arg"
62 .Fn destroy_dev_drain "struct cdevsw *csw"
64 .Fn dev_depends "struct cdev *pdev" "struct cdev *cdev"
68 .Fn make_dev "struct cdevsw *cdevsw" "int unit" "uid_t uid" "gid_t gid" "int perms" "const char *fmt" ...
70 .Fn make_dev_cred "struct cdevsw *cdevsw" "int unit" "struct ucred *cr" "uid_t uid" "gid_t gid" "int perms" "const char *fmt" ...
72 .Fn make_dev_credf "int flags" "struct cdevsw *cdevsw" "int unit" "struct ucred *cr" "uid_t uid" "gid_t gid" "int perms" "const char *fmt" ...
74 .Fn make_dev_p "int flags" "struct cdev **cdev" "struct cdevsw *devsw" "struct ucred *cr" "uid_t uid" "gid_t gid" "int mode" "const char *fmt" ...
76 .Fn make_dev_alias "struct cdev *pdev" "const char *fmt" ...
82 structure for a new device, which is returned into the
87 of the presence of the new device, that causes corresponding nodes
92 The function takes the structure
93 .Va struct make_dev_args args ,
94 which specifies the parameters for the device creation:
96 .Bd -literal -offset indent -compact
97 struct make_dev_args {
100 struct cdevsw *mda_devsw;
101 struct ucred *mda_cr;
110 Before use and filling with the desired values, the structure must be
112 .Fn make_dev_args_init
113 function, which ensures that future kernel interface expansion does
114 not affect driver source code or binary interface.
116 The created device will be owned by
118 with the group ownership as
120 The name is the expansion of
122 and following arguments as
125 The name determines its path under
129 mount point and may contain slash
131 characters to denote subdirectories.
132 The permissions of the file specified in
137 .Bd -literal -offset indent -compact
138 #define S_IRWXU 0000700 /* RWX mask for owner */
139 #define S_IRUSR 0000400 /* R for owner */
140 #define S_IWUSR 0000200 /* W for owner */
141 #define S_IXUSR 0000100 /* X for owner */
143 #define S_IRWXG 0000070 /* RWX mask for group */
144 #define S_IRGRP 0000040 /* R for group */
145 #define S_IWGRP 0000020 /* W for group */
146 #define S_IXGRP 0000010 /* X for group */
148 #define S_IRWXO 0000007 /* RWX mask for other */
149 #define S_IROTH 0000004 /* R for other */
150 #define S_IWOTH 0000002 /* W for other */
151 #define S_IXOTH 0000001 /* X for other */
153 #define S_ISUID 0004000 /* set user id on execution */
154 #define S_ISGID 0002000 /* set group id on execution */
155 #define S_ISVTX 0001000 /* sticky bit */
156 #ifndef _POSIX_SOURCE
157 #define S_ISTXT 0001000
163 argument specifies credentials that will be stored in the
165 member of the initialized
170 argument alters the operation of
172 The following values are currently accepted:
174 .Bl -tag -width "It Dv MAKEDEV_CHECKNAME" -compact -offset indent
176 reference the created device
177 .It Dv MAKEDEV_NOWAIT
178 do not sleep, the call may fail
179 .It Dv MAKEDEV_WAITOK
180 allow the function to sleep to satisfy malloc
181 .It Dv MAKEDEV_ETERNAL
182 created device will be never destroyed
183 .It Dv MAKEDEV_CHECKNAME
184 return an error if the device name is invalid or already exists
191 .Dv MAKEDEV_CHECKNAME
192 values are accepted for the
198 flag is assumed if none of
205 event handler shall specify
207 flag when creating a device in response to lookup, to avoid race where
208 the device created is destroyed immediately after
210 drops his reference to cdev.
214 flag allows the kernel to not acquire some locks when translating system
215 calls into the cdevsw methods calls.
216 It is responsibility of the driver author to make sure that
218 is never called on the returned cdev.
219 For the convenience, use the
220 .Dv MAKEDEV_ETERNAL_KLD
221 flag for the code that can be compiled into kernel or loaded
222 (and unloaded) as loadable module.
224 A panic will occur if the
225 .Dv MAKEDEV_CHECKNAME
226 flag is not specified
227 and the device name is invalid or already exists.
232 .Bd -literal -offset indent
235 res = make_dev_p(flags, &dev, cdevsw, cred, uid, gid, perms, name);
237 is equivalent to the code
238 .Bd -literal -offset indent
240 struct make_dev_args args;
243 make_dev_args_init(&args);
244 args.mda_flags = flags;
245 args.mda_devsw = cdevsw;
246 args.mda_cred = cred;
249 args.mda_mode = perms;
250 res = make_dev_s(&args, &dev, name);
255 function call is equivalent to
256 .Bd -literal -offset indent
257 (void) make_dev_s(&args, &dev, name);
261 does not allow the caller to obtain the return value, and in
262 kernels compiled with the
264 options, the function asserts that the device creation succeeded.
268 function is equivalent to the call
269 .Bd -literal -offset indent
270 make_dev_credf(0, cdevsw, unit, cr, uid, gid, perms, fmt, ...);
275 function call is the same as
276 .Bd -literal -offset indent
277 make_dev_credf(0, cdevsw, unit, NULL, uid, gid, perms, fmt, ...);
282 function takes the returned
286 and makes another (aliased) name for this device.
287 It is an error to call
294 function is similar to
296 but it returns the resulting aliasing
298 and may not return an error.
310 that are available to store state.
311 Both fields are of type
313 and can be initialized simultaneously with the
315 allocation by filling
321 argument structure, or filled after the
323 is allocated, if using legacy interfaces.
324 In the latter case, the driver should handle the race of
325 accessing uninitialized
330 These are designed to replace the
334 which can be obtained with
339 function takes the returned
343 and destroys the registration for that device.
344 The notification is sent to
346 about the destruction event.
349 on devices that were created with
354 function establishes a parent-child relationship between two devices.
355 The net effect is that a
357 of the parent device will also result in the destruction of the
360 A device may simultaneously be a parent and a child,
361 so it is possible to build a complete hierarchy.
364 .Fn destroy_dev_sched_cb
365 function schedules execution of the
372 is finished, and if the supplied
378 is called, with argument
381 .Fn destroy_dev_sched
382 function is the same as
383 .Bd -literal -offset indent
384 destroy_dev_sched_cb(cdev, NULL, NULL);
389 driver method cannot call
392 Doing so causes deadlock when
394 waits for all threads to leave the driver methods.
397 sleeps, no non-sleepable locks may be held over the call.
399 .Fn destroy_dev_sched
400 family of functions overcome these issues.
402 The device driver may call the
403 .Fn destroy_dev_drain
404 function to wait until all devices that have supplied
406 as cdevsw, are destroyed.
407 This is useful when driver knows that
408 .Fn destroy_dev_sched
409 is called for all instantiated devices, but need to postpone module
412 is actually finished for all of them.
418 will return 0, otherwise they will return an error.
423 pointer, otherwise it will return
431 calls will fail and the device will be not registered if:
436 flag was specified and a memory allocation request could not be satisfied.
437 .It Bq Er ENAMETOOLONG
439 .Dv MAKEDEV_CHECKNAME
440 flag was specified and the provided device name is longer than
444 .Dv MAKEDEV_CHECKNAME
445 flag was specified and the provided device name is empty, contains a
449 path component or ends with
453 .Dv MAKEDEV_CHECKNAME
454 flag was specified and the provided device name contains invalid characters.
457 .Dv MAKEDEV_CHECKNAME
458 flag was specified and the provided device name already exists.
469 functions first appeared in
481 .Fn destroy_dev_sched ,
482 .Fn destroy_dev_sched_cb