xref: /freebsd/share/man/man9/make_dev.9 (revision 48ce5d4cac7dc3c2160ea69dc550e218fbc0e697)
194b1839dSChris Costello.\" Copyright (c) 1999 Chris Costello
294b1839dSChris Costello.\" All rights reserved.
394b1839dSChris Costello.\"
494b1839dSChris Costello.\" Redistribution and use in source and binary forms, with or without
594b1839dSChris Costello.\" modification, are permitted provided that the following conditions
694b1839dSChris Costello.\" are met:
794b1839dSChris Costello.\" 1. Redistributions of source code must retain the above copyright
894b1839dSChris Costello.\"    notice, this list of conditions and the following disclaimer.
994b1839dSChris Costello.\" 2. Redistributions in binary form must reproduce the above copyright
1094b1839dSChris Costello.\"    notice, this list of conditions and the following disclaimer in the
1194b1839dSChris Costello.\"    documentation and/or other materials provided with the distribution.
1294b1839dSChris Costello.\"
1394b1839dSChris Costello.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1494b1839dSChris Costello.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1594b1839dSChris Costello.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1694b1839dSChris Costello.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1794b1839dSChris Costello.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1894b1839dSChris Costello.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
1994b1839dSChris Costello.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2094b1839dSChris Costello.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2194b1839dSChris Costello.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2294b1839dSChris Costello.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2394b1839dSChris Costello.\" SUCH DAMAGE.
2494b1839dSChris Costello.\"
2594b1839dSChris Costello.\" $FreeBSD$
2694b1839dSChris Costello.\"
27*48ce5d4cSKonstantin Belousov.Dd Jan 3, 2016
2894b1839dSChris Costello.Dt MAKE_DEV 9
29aa12cea2SUlrich Spörlein.Os
3094b1839dSChris Costello.Sh NAME
3194b1839dSChris Costello.Nm make_dev ,
32fe754649SKonstantin Belousov.Nm make_dev_cred ,
33fe754649SKonstantin Belousov.Nm make_dev_credf ,
34f36575b5SJaakko Heinonen.Nm make_dev_p ,
35*48ce5d4cSKonstantin Belousov.Nm make_dev_s ,
36f14b89faSDima Dorfman.Nm make_dev_alias ,
378137364fSAndrey V. Elsukov.Nm make_dev_alias_p ,
38f14b89faSDima Dorfman.Nm destroy_dev ,
39fe754649SKonstantin Belousov.Nm destroy_dev_sched ,
40fe754649SKonstantin Belousov.Nm destroy_dev_sched_cb ,
41fe754649SKonstantin Belousov.Nm destroy_dev_drain ,
4244c63b64SDima Dorfman.Nm dev_depends
43e3718e31SRuslan Ermilov.Nd manage
44c97dc39fSChristian Brueffer.Vt cdev Ns 's
45e3718e31SRuslan Ermilovand DEVFS registration for devices
4694b1839dSChris Costello.Sh SYNOPSIS
47212c98aaSBruce Evans.In sys/param.h
4832eef9aeSRuslan Ermilov.In sys/conf.h
49*48ce5d4cSKonstantin Belousov.Ft void
50*48ce5d4cSKonstantin Belousov.Fn make_dev_args_init "struct make_dev_args *args"
51f36575b5SJaakko Heinonen.Ft int
52*48ce5d4cSKonstantin Belousov.Fn make_dev_s "struct make_dev_args *args" "struct cdev **cdev" "const char *fmt" ...
538137364fSAndrey V. Elsukov.Ft int
548137364fSAndrey V. Elsukov.Fn make_dev_alias_p "int flags" "struct cdev **cdev" "struct cdev *pdev" "const char *fmt" ...
5594b1839dSChris Costello.Ft void
56097fcfebSWarner Losh.Fn destroy_dev "struct cdev *dev"
57f14b89faSDima Dorfman.Ft void
58fe754649SKonstantin Belousov.Fn destroy_dev_sched "struct cdev *dev"
59fe754649SKonstantin Belousov.Ft void
60fe754649SKonstantin Belousov.Fn destroy_dev_sched_cb "struct cdev *dev" "void (*cb)(void *)" "void *arg"
61fe754649SKonstantin Belousov.Ft void
62fe754649SKonstantin Belousov.Fn destroy_dev_drain "struct cdevsw *csw"
63fe754649SKonstantin Belousov.Ft void
64097fcfebSWarner Losh.Fn dev_depends "struct cdev *pdev" "struct cdev *cdev"
65*48ce5d4cSKonstantin Belousov.Pp
66*48ce5d4cSKonstantin BelousovLEGACY INTERFACES
67*48ce5d4cSKonstantin Belousov.Ft struct cdev *
68*48ce5d4cSKonstantin Belousov.Fn make_dev "struct cdevsw *cdevsw" "int unit" "uid_t uid" "gid_t gid" "int perms" "const char *fmt" ...
69*48ce5d4cSKonstantin Belousov.Ft struct cdev *
70*48ce5d4cSKonstantin Belousov.Fn make_dev_cred "struct cdevsw *cdevsw" "int unit" "struct ucred *cr" "uid_t uid" "gid_t gid" "int perms" "const char *fmt" ...
71*48ce5d4cSKonstantin Belousov.Ft struct cdev *
72*48ce5d4cSKonstantin Belousov.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" ...
73*48ce5d4cSKonstantin Belousov.Ft int
74*48ce5d4cSKonstantin Belousov.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" ...
75*48ce5d4cSKonstantin Belousov.Ft struct cdev *
76*48ce5d4cSKonstantin Belousov.Fn make_dev_alias "struct cdev *pdev" "const char *fmt" ...
7794b1839dSChris Costello.Sh DESCRIPTION
7894b1839dSChris CostelloThe
79*48ce5d4cSKonstantin Belousov.Fn make_dev_s
8094b1839dSChris Costellofunction creates a
81c97dc39fSChristian Brueffer.Fa cdev
82*48ce5d4cSKonstantin Belousovstructure for a new device, which is returned into the
83*48ce5d4cSKonstantin Belousov.Fa cdev
84*48ce5d4cSKonstantin Belousovargument.
85fe754649SKonstantin BelousovIt also notifies
86fe754649SKonstantin Belousov.Xr devfs 5
87fe754649SKonstantin Belousovof the presence of the new device, that causes corresponding nodes
88fe754649SKonstantin Belousovto be created.
89fe754649SKonstantin BelousovBesides this, a
90fe754649SKonstantin Belousov.Xr devctl 4
91fe754649SKonstantin Belousovnotification is sent.
92*48ce5d4cSKonstantin BelousovThe function takes the structure
93*48ce5d4cSKonstantin Belousov.Va struct make_dev_args args ,
94*48ce5d4cSKonstantin Belousovwhich specifies the parameters for the device creation:
95*48ce5d4cSKonstantin Belousov.Pp
96*48ce5d4cSKonstantin Belousov.Bd -literal -offset indent -compact
97*48ce5d4cSKonstantin Belousovstruct make_dev_args {
98*48ce5d4cSKonstantin Belousov	size_t		 mda_size;
99*48ce5d4cSKonstantin Belousov	int		 mda_flags;
100*48ce5d4cSKonstantin Belousov	struct cdevsw	*mda_devsw;
101*48ce5d4cSKonstantin Belousov	struct ucred	*mda_cr;
102*48ce5d4cSKonstantin Belousov	uid_t		 mda_uid;
103*48ce5d4cSKonstantin Belousov	gid_t		 mda_gid;
104*48ce5d4cSKonstantin Belousov	int		 mda_mode;
105*48ce5d4cSKonstantin Belousov	int		 mda_unit;
106*48ce5d4cSKonstantin Belousov	void		*mda_si_drv1;
107*48ce5d4cSKonstantin Belousov	void		*mda_si_drv2;
108*48ce5d4cSKonstantin Belousov};
109*48ce5d4cSKonstantin Belousov.Ed
110*48ce5d4cSKonstantin BelousovBefore use and filling with the desired values, the structure must be
111*48ce5d4cSKonstantin Belousovinitialized by the
112*48ce5d4cSKonstantin Belousov.Fn make_dev_args_init
113*48ce5d4cSKonstantin Belousovfunction, which ensures that future kernel interface expansion does
114*48ce5d4cSKonstantin Belousovnot affect driver source code or binary interface.
115*48ce5d4cSKonstantin Belousov.Pp
116*48ce5d4cSKonstantin BelousovThe created device will be owned by
117*48ce5d4cSKonstantin Belousov.Va args.mda_uid ,
11894b1839dSChris Costellowith the group ownership as
119*48ce5d4cSKonstantin Belousov.Va args.mda_gid .
1201dfbd9c2SWarner LoshThe name is the expansion of
1211dfbd9c2SWarner Losh.Va fmt
1221dfbd9c2SWarner Loshand following arguments as
1231dfbd9c2SWarner Losh.Xr printf 9
1241dfbd9c2SWarner Loshwould print it.
1251dfbd9c2SWarner LoshThe name determines its path under
1261dfbd9c2SWarner Losh.Pa /dev
1271dfbd9c2SWarner Loshor other
1281dfbd9c2SWarner Losh.Xr devfs 5
1291dfbd9c2SWarner Loshmount point and may contain slash
1301dfbd9c2SWarner Losh.Ql /
1311dfbd9c2SWarner Loshcharacters to denote subdirectories.
13294b1839dSChris CostelloThe permissions of the file specified in
133*48ce5d4cSKonstantin Belousov.Va args.mda_mode
13494b1839dSChris Costelloare defined in
135fe08efe6SRuslan Ermilov.In sys/stat.h :
13694b1839dSChris Costello.Pp
13794b1839dSChris Costello.Bd -literal -offset indent -compact
13894b1839dSChris Costello#define S_IRWXU 0000700    /* RWX mask for owner */
13994b1839dSChris Costello#define S_IRUSR 0000400    /* R for owner */
14094b1839dSChris Costello#define S_IWUSR 0000200    /* W for owner */
14194b1839dSChris Costello#define S_IXUSR 0000100    /* X for owner */
14294b1839dSChris Costello
14394b1839dSChris Costello#define S_IRWXG 0000070    /* RWX mask for group */
14494b1839dSChris Costello#define S_IRGRP 0000040    /* R for group */
14594b1839dSChris Costello#define S_IWGRP 0000020    /* W for group */
14694b1839dSChris Costello#define S_IXGRP 0000010    /* X for group */
14794b1839dSChris Costello
14894b1839dSChris Costello#define S_IRWXO 0000007    /* RWX mask for other */
14994b1839dSChris Costello#define S_IROTH 0000004    /* R for other */
15094b1839dSChris Costello#define S_IWOTH 0000002    /* W for other */
15194b1839dSChris Costello#define S_IXOTH 0000001    /* X for other */
15294b1839dSChris Costello
15394b1839dSChris Costello#define S_ISUID 0004000    /* set user id on execution */
15494b1839dSChris Costello#define S_ISGID 0002000    /* set group id on execution */
15594b1839dSChris Costello#define S_ISVTX 0001000    /* sticky bit */
15694b1839dSChris Costello#ifndef _POSIX_SOURCE
15794b1839dSChris Costello#define S_ISTXT 0001000
15894b1839dSChris Costello#endif
15994b1839dSChris Costello.Ed
16094b1839dSChris Costello.Pp
16194b1839dSChris CostelloThe
162*48ce5d4cSKonstantin Belousov.Va args.mda_cr
163fe754649SKonstantin Belousovargument specifies credentials that will be stored in the
164fe754649SKonstantin Belousov.Fa si_cred
165fe754649SKonstantin Belousovmember of the initialized
166fe754649SKonstantin Belousov.Fa struct cdev .
167*48ce5d4cSKonstantin Belousov.Pp
168fe754649SKonstantin BelousovThe
169*48ce5d4cSKonstantin Belousov.Va args.mda_flags
170fe754649SKonstantin Belousovargument alters the operation of
171*48ce5d4cSKonstantin Belousov.Fn make_dev_s.
172fe754649SKonstantin BelousovThe following values are currently accepted:
173fe754649SKonstantin Belousov.Pp
174*48ce5d4cSKonstantin Belousov.Bl -tag -width "It Dv MAKEDEV_CHECKNAME" -compact -offset indent
175*48ce5d4cSKonstantin Belousov.It Dv MAKEDEV_REF
17668f7a013SJaakko Heinonenreference the created device
177*48ce5d4cSKonstantin Belousov.It Dv MAKEDEV_NOWAIT
178f36575b5SJaakko Heinonendo not sleep, the call may fail
179*48ce5d4cSKonstantin Belousov.It Dv MAKEDEV_WAITOK
18068f7a013SJaakko Heinonenallow the function to sleep to satisfy malloc
181*48ce5d4cSKonstantin Belousov.It Dv MAKEDEV_ETERNAL
18268f7a013SJaakko Heinonencreated device will be never destroyed
183*48ce5d4cSKonstantin Belousov.It Dv MAKEDEV_CHECKNAME
184f36575b5SJaakko Heinonenreturn an error if the device name is invalid or already exists
18568f7a013SJaakko Heinonen.El
186fe754649SKonstantin Belousov.Pp
1878137364fSAndrey V. ElsukovOnly
1888137364fSAndrey V. Elsukov.Dv MAKEDEV_NOWAIT ,
1898137364fSAndrey V. Elsukov.Dv MAKEDEV_WAITOK
1908137364fSAndrey V. Elsukovand
1918137364fSAndrey V. Elsukov.Dv MAKEDEV_CHECKNAME
1928137364fSAndrey V. Elsukovvalues are accepted for the
1938137364fSAndrey V. Elsukov.Fn make_dev_alias_p
1948137364fSAndrey V. Elsukovfunction.
1958137364fSAndrey V. Elsukov.Pp
196fe754649SKonstantin BelousovThe
1972b848cb1SKonstantin Belousov.Dv MAKEDEV_WAITOK
1982b848cb1SKonstantin Belousovflag is assumed if none of
1992b848cb1SKonstantin Belousov.Dv MAKEDEV_WAITOK ,
2002b848cb1SKonstantin Belousov.Dv MAKEDEV_NOWAIT
2012b848cb1SKonstantin Belousovis specified.
2022b848cb1SKonstantin Belousov.Pp
2032b848cb1SKonstantin BelousovThe
204fe754649SKonstantin Belousov.Xr dev_clone 9
205fe754649SKonstantin Belousovevent handler shall specify
206fe754649SKonstantin Belousov.Dv MAKEDEV_REF
207fe754649SKonstantin Belousovflag when creating a device in response to lookup, to avoid race where
208fe754649SKonstantin Belousovthe device created is destroyed immediately after
209fe754649SKonstantin Belousov.Xr devfs_lookup 9
210fe754649SKonstantin Belousovdrops his reference to cdev.
211fe754649SKonstantin Belousov.Pp
212fe754649SKonstantin BelousovThe
2135e9cd1dbSKonstantin Belousov.Dv MAKEDEV_ETERNAL
2145e9cd1dbSKonstantin Belousovflag allows the kernel to not acquire some locks when translating system
2155e9cd1dbSKonstantin Belousovcalls into the cdevsw methods calls.
2165e9cd1dbSKonstantin BelousovIt is responsibility of the driver author to make sure that
2175e9cd1dbSKonstantin Belousov.Fn destroy_dev
2185e9cd1dbSKonstantin Belousovis never called on the returned cdev.
2195e9cd1dbSKonstantin BelousovFor the convenience, use the
2205e9cd1dbSKonstantin Belousov.Dv MAKEDEV_ETERNAL_KLD
2215e9cd1dbSKonstantin Belousovflag for the code that can be compiled into kernel or loaded
2225e9cd1dbSKonstantin Belousov(and unloaded) as loadable module.
2235e9cd1dbSKonstantin Belousov.Pp
224*48ce5d4cSKonstantin BelousovA panic will occur if the
225*48ce5d4cSKonstantin Belousov.Dv MAKEDEV_CHECKNAME
226*48ce5d4cSKonstantin Belousovflag is not specified
22768f7a013SJaakko Heinonenand the device name is invalid or already exists.
22868f7a013SJaakko Heinonen.Pp
2295e9cd1dbSKonstantin BelousovThe
230*48ce5d4cSKonstantin Belousov.Fn make_dev_p
231*48ce5d4cSKonstantin Belousovuse of the form
232*48ce5d4cSKonstantin Belousov.Bd -literal -offset indent
233*48ce5d4cSKonstantin Belousovstruct cdev *dev;
234*48ce5d4cSKonstantin Belousovint res;
235*48ce5d4cSKonstantin Belousovres = make_dev_p(flags, &dev, cdevsw, cred, uid, gid, perms, name);
236*48ce5d4cSKonstantin Belousov.Ed
237*48ce5d4cSKonstantin Belousovis equivalent to the code
238*48ce5d4cSKonstantin Belousov.Bd -literal -offset indent
239*48ce5d4cSKonstantin Belousovstruct cdev *dev;
240*48ce5d4cSKonstantin Belousovstruct make_dev_args args;
241*48ce5d4cSKonstantin Belousovint res;
242*48ce5d4cSKonstantin Belousov
243*48ce5d4cSKonstantin Belousovmake_dev_args_init(&args);
244*48ce5d4cSKonstantin Belousovargs.mda_flags = flags;
245*48ce5d4cSKonstantin Belousovargs.mda_devsw = cdevsw;
246*48ce5d4cSKonstantin Belousovargs.mda_cred = cred;
247*48ce5d4cSKonstantin Belousovargs.mda_uid = uid;
248*48ce5d4cSKonstantin Belousovargs.mda_gid = gid;
249*48ce5d4cSKonstantin Belousovargs.mda_mode = perms;
250*48ce5d4cSKonstantin Belousovres = make_dev_s(&args, &dev, name);
251*48ce5d4cSKonstantin Belousov.Ed
252*48ce5d4cSKonstantin Belousov.Pp
253*48ce5d4cSKonstantin BelousovSimilarly, the
254*48ce5d4cSKonstantin Belousov.Fn make_dev_credf
255*48ce5d4cSKonstantin Belousovfunction call is equivalent to
256*48ce5d4cSKonstantin Belousov.Bd -literal -offset indent
257*48ce5d4cSKonstantin Belousov	(void) make_dev_s(&args, &dev, name);
258*48ce5d4cSKonstantin Belousov.Ed
259*48ce5d4cSKonstantin BelousovIn other words,
260*48ce5d4cSKonstantin Belousov.Fn make_dev_credf
261*48ce5d4cSKonstantin Belousovdoes not allow the caller to obtain the return value, and in
262*48ce5d4cSKonstantin Belousovkernels compiled with the
263*48ce5d4cSKonstantin Belousov.Va INVARIANTS
264*48ce5d4cSKonstantin Belousovoptions, the function asserts that the device creation succeeded.
265*48ce5d4cSKonstantin Belousov.Pp
266*48ce5d4cSKonstantin BelousovThe
267fe754649SKonstantin Belousov.Fn make_dev_cred
268fe754649SKonstantin Belousovfunction is equivalent to the call
269fe754649SKonstantin Belousov.Bd -literal -offset indent
270edde8745SEd Schoutenmake_dev_credf(0, cdevsw, unit, cr, uid, gid, perms, fmt, ...);
271e10c1be4SUlrich Spörlein.Ed
272fe754649SKonstantin Belousov.Pp
273fe754649SKonstantin BelousovThe
274fe754649SKonstantin Belousov.Fn make_dev
275fe754649SKonstantin Belousovfunction call is the same as
276fe754649SKonstantin Belousov.Bd -literal -offset indent
277edde8745SEd Schoutenmake_dev_credf(0, cdevsw, unit, NULL, uid, gid, perms, fmt, ...);
278e10c1be4SUlrich Spörlein.Ed
279fe754649SKonstantin Belousov.Pp
280fe754649SKonstantin BelousovThe
281*48ce5d4cSKonstantin Belousov.Fn make_dev_alias_p
282792b2369SMatt Jacobfunction takes the returned
283c97dc39fSChristian Brueffer.Ft cdev
284792b2369SMatt Jacobfrom
285792b2369SMatt Jacob.Fn make_dev
286edf0984dSRuslan Ermilovand makes another (aliased) name for this device.
287edf0984dSRuslan ErmilovIt is an error to call
288*48ce5d4cSKonstantin Belousov.Fn make_dev_alias_p
289792b2369SMatt Jacobprior to calling
290792b2369SMatt Jacob.Fn make_dev .
291792b2369SMatt Jacob.Pp
292*48ce5d4cSKonstantin BelousovThe
293*48ce5d4cSKonstantin Belousov.Fn make_dev_alias
2948137364fSAndrey V. Elsukovfunction is similar to
2958137364fSAndrey V. Elsukov.Fn make_dev_alias
296*48ce5d4cSKonstantin Belousovbut it returns the resulting aliasing
2978137364fSAndrey V. Elsukov.Ft *cdev
298*48ce5d4cSKonstantin Belousovand may not return an error.
2998137364fSAndrey V. Elsukov.Pp
300792b2369SMatt JacobThe
3012557913dSJohn-Mark Gurney.Fa cdev
3022557913dSJohn-Mark Gurneyreturned by
303*48ce5d4cSKonstantin Belousov.Fn make_dev_s
3042557913dSJohn-Mark Gurneyand
305*48ce5d4cSKonstantin Belousov.Fn make_dev_alias_p
3062557913dSJohn-Mark Gurneyhas two fields,
3072557913dSJohn-Mark Gurney.Fa si_drv1
3082557913dSJohn-Mark Gurneyand
3092557913dSJohn-Mark Gurney.Fa si_drv2 ,
31077213b87SChristian Bruefferthat are available to store state.
31177213b87SChristian BruefferBoth fields are of type
312*48ce5d4cSKonstantin Belousov.Ft void * ,
313*48ce5d4cSKonstantin Belousovand can be initialized simultaneously with the
314*48ce5d4cSKonstantin Belousov.Va cdev
315*48ce5d4cSKonstantin Belousovallocation by filling
316*48ce5d4cSKonstantin Belousov.Va args.mda_si_drv1
317*48ce5d4cSKonstantin Belousovand
318*48ce5d4cSKonstantin Belousov.Va args.mda_si_drv2
319*48ce5d4cSKonstantin Belousovmembers of the
320*48ce5d4cSKonstantin Belousov.Fn make_dev_s
321*48ce5d4cSKonstantin Belousovargument structure, or filled after the
322*48ce5d4cSKonstantin Belousov.Va cdev
323*48ce5d4cSKonstantin Belousovis allocated, if using legacy interfaces.
324*48ce5d4cSKonstantin BelousovIn the latter case, the driver should handle the race of
325*48ce5d4cSKonstantin Belousovaccessing uninitialized
326*48ce5d4cSKonstantin Belousov.Va si_drv1
327*48ce5d4cSKonstantin Belousovand
328*48ce5d4cSKonstantin Belousov.Va si_drv2
329*48ce5d4cSKonstantin Belousovitself.
3302557913dSJohn-Mark GurneyThese are designed to replace the
331edde8745SEd Schouten.Fa unit
3322557913dSJohn-Mark Gurneyargument to
33366c6ebfeSEd Schouten.Fn make_dev ,
33466c6ebfeSEd Schoutenwhich can be obtained with
33566c6ebfeSEd Schouten.Fn dev2unit .
3362557913dSJohn-Mark Gurney.Pp
3372557913dSJohn-Mark GurneyThe
338bd00dbfaSBruce Evans.Fn destroy_dev
33994b1839dSChris Costellofunction takes the returned
340c97dc39fSChristian Brueffer.Fa cdev
34194b1839dSChris Costellofrom
34294b1839dSChris Costello.Fn make_dev
343edf0984dSRuslan Ermilovand destroys the registration for that device.
344fe754649SKonstantin BelousovThe notification is sent to
345fe754649SKonstantin Belousov.Xr devctl 4
346fe754649SKonstantin Belousovabout the destruction event.
347edf0984dSRuslan ErmilovDo not call
348792b2369SMatt Jacob.Fn destroy_dev
349792b2369SMatt Jacobon devices that were created with
350792b2369SMatt Jacob.Fn make_dev_alias .
351f14b89faSDima Dorfman.Pp
352f14b89faSDima DorfmanThe
35344c63b64SDima Dorfman.Fn dev_depends
354f14b89faSDima Dorfmanfunction establishes a parent-child relationship between two devices.
355f14b89faSDima DorfmanThe net effect is that a
356f14b89faSDima Dorfman.Fn destroy_dev
357f14b89faSDima Dorfmanof the parent device will also result in the destruction of the
358f14b89faSDima Dorfmanchild device(s),
359f14b89faSDima Dorfmanif any exist.
360f14b89faSDima DorfmanA device may simultaneously be a parent and a child,
361b82af3f5SMike Pritchardso it is possible to build a complete hierarchy.
362fe754649SKonstantin Belousov.Pp
363fe754649SKonstantin BelousovThe
364fe754649SKonstantin Belousov.Fn destroy_dev_sched_cb
365fe754649SKonstantin Belousovfunction schedules execution of the
366fe754649SKonstantin Belousov.Fn destroy_dev
367fe754649SKonstantin Belousovfor the specified
368fe754649SKonstantin Belousov.Fa cdev
369fe754649SKonstantin Belousovin the safe context.
370fe754649SKonstantin BelousovAfter
371fe754649SKonstantin Belousov.Fn destroy_dev
372fe754649SKonstantin Belousovis finished, and if the supplied
373fe754649SKonstantin Belousov.Fa cb
37495adbc95SJaakko Heinonenis not
37595adbc95SJaakko Heinonen.Dv NULL ,
37695adbc95SJaakko Heinonenthe callback
377fe754649SKonstantin Belousov.Fa cb
378fe754649SKonstantin Belousovis called, with argument
379fe754649SKonstantin Belousov.Fa arg .
380fe754649SKonstantin BelousovThe
381fe754649SKonstantin Belousov.Fn destroy_dev_sched
382fe754649SKonstantin Belousovfunction is the same as
383fe754649SKonstantin Belousov.Bd -literal -offset indent
3843035649eSPawel Jakub Dawidekdestroy_dev_sched_cb(cdev, NULL, NULL);
385e10c1be4SUlrich Spörlein.Ed
386fe754649SKonstantin Belousov.Pp
387fe754649SKonstantin BelousovThe
388fe754649SKonstantin Belousov.Fn d_close
389fe754649SKonstantin Belousovdriver method cannot call
390fe754649SKonstantin Belousov.Fn destroy_dev
391580a4587SAndrey V. Elsukovdirectly.
392580a4587SAndrey V. ElsukovDoing so causes deadlock when
393fe754649SKonstantin Belousov.Fn destroy_dev
394fe754649SKonstantin Belousovwaits for all threads to leave the driver methods.
395fe754649SKonstantin BelousovAlso, because
396fe754649SKonstantin Belousov.Fn destroy_dev
397fe754649SKonstantin Belousovsleeps, no non-sleepable locks may be held over the call.
398fe754649SKonstantin BelousovThe
399fe754649SKonstantin Belousov.Fn destroy_dev_sched
400fe754649SKonstantin Belousovfamily of functions overcome these issues.
401fe754649SKonstantin Belousov.Pp
402fe754649SKonstantin BelousovThe device driver may call the
403fe754649SKonstantin Belousov.Fn destroy_dev_drain
404fe754649SKonstantin Belousovfunction to wait until all devices that have supplied
405fe754649SKonstantin Belousov.Fa csw
406580a4587SAndrey V. Elsukovas cdevsw, are destroyed.
407580a4587SAndrey V. ElsukovThis is useful when driver knows that
408fe754649SKonstantin Belousov.Fn destroy_dev_sched
409fe754649SKonstantin Belousovis called for all instantiated devices, but need to postpone module
410fe754649SKonstantin Belousovunload until
411fe754649SKonstantin Belousov.Fn destroy_dev
412fe754649SKonstantin Belousovis actually finished for all of them.
413f36575b5SJaakko Heinonen.Sh RETURN VALUES
414f36575b5SJaakko HeinonenIf successful,
415*48ce5d4cSKonstantin Belousov.Fn make_dev_s
416*48ce5d4cSKonstantin Belousovand
417f36575b5SJaakko Heinonen.Fn make_dev_p
418*48ce5d4cSKonstantin Belousovwill return 0, otherwise they will return an error.
419f36575b5SJaakko HeinonenIf successful,
420f36575b5SJaakko Heinonen.Fn make_dev_credf
421f36575b5SJaakko Heinonenwill return a valid
422f36575b5SJaakko Heinonen.Fa cdev
423f36575b5SJaakko Heinonenpointer, otherwise it will return
424f36575b5SJaakko Heinonen.Dv NULL .
425f36575b5SJaakko Heinonen.Sh ERRORS
426f36575b5SJaakko HeinonenThe
427*48ce5d4cSKonstantin Belousov.Fn make_dev_s ,
428f36575b5SJaakko Heinonen.Fn make_dev_p
4298137364fSAndrey V. Elsukovand
4308137364fSAndrey V. Elsukov.Fn make_dev_alias_p
431*48ce5d4cSKonstantin Belousovcalls will fail and the device will be not registered if:
432f36575b5SJaakko Heinonen.Bl -tag -width Er
433f36575b5SJaakko Heinonen.It Bq Er ENOMEM
434f36575b5SJaakko HeinonenThe
435f36575b5SJaakko Heinonen.Dv MAKEDEV_NOWAIT
436353429bfSJaakko Heinonenflag was specified and a memory allocation request could not be satisfied.
437f36575b5SJaakko Heinonen.It Bq Er ENAMETOOLONG
438f36575b5SJaakko HeinonenThe
439f36575b5SJaakko Heinonen.Dv MAKEDEV_CHECKNAME
440353429bfSJaakko Heinonenflag was specified and the provided device name is longer than
441f36575b5SJaakko Heinonen.Dv SPECNAMELEN .
442f36575b5SJaakko Heinonen.It Bq Er EINVAL
443f36575b5SJaakko HeinonenThe
444f36575b5SJaakko Heinonen.Dv MAKEDEV_CHECKNAME
445353429bfSJaakko Heinonenflag was specified and the provided device name is empty, contains a
446f36575b5SJaakko Heinonen.Qq \&.
447f36575b5SJaakko Heinonenor
448f36575b5SJaakko Heinonen.Qq ..
449f36575b5SJaakko Heinonenpath component or ends with
450f36575b5SJaakko Heinonen.Ql / .
451b1e1f725SJaakko Heinonen.It Bq Er EINVAL
452b1e1f725SJaakko HeinonenThe
453b1e1f725SJaakko Heinonen.Dv MAKEDEV_CHECKNAME
454b1e1f725SJaakko Heinonenflag was specified and the provided device name contains invalid characters.
455f36575b5SJaakko Heinonen.It Bq Er EEXIST
456f36575b5SJaakko HeinonenThe
457f36575b5SJaakko Heinonen.Dv MAKEDEV_CHECKNAME
458353429bfSJaakko Heinonenflag was specified and the provided device name already exists.
459f36575b5SJaakko Heinonen.El
460e07f1d5fSHiten Pandya.Sh SEE ALSO
461fe754649SKonstantin Belousov.Xr devctl 4 ,
462580a4587SAndrey V. Elsukov.Xr devfs 5 ,
463fe754649SKonstantin Belousov.Xr destroy_dev_drain 9 ,
464580a4587SAndrey V. Elsukov.Xr dev_clone 9
46594b1839dSChris Costello.Sh HISTORY
46694b1839dSChris CostelloThe
46794b1839dSChris Costello.Fn make_dev
46894b1839dSChris Costelloand
469bd00dbfaSBruce Evans.Fn destroy_dev
47094b1839dSChris Costellofunctions first appeared in
47194b1839dSChris Costello.Fx 4.0 .
472792b2369SMatt JacobThe function
473792b2369SMatt Jacob.Fn make_dev_alias
474792b2369SMatt Jacobfirst appeared in
475792b2369SMatt Jacob.Fx 4.1 .
476f14b89faSDima DorfmanThe function
47744c63b64SDima Dorfman.Fn dev_depends
478f14b89faSDima Dorfmanfirst appeared in
479f14b89faSDima Dorfman.Fx 5.0 .
480fe754649SKonstantin BelousovThe functions
481fe754649SKonstantin Belousov.Fn make_dev_credf ,
482fe754649SKonstantin Belousov.Fn destroy_dev_sched ,
483fe754649SKonstantin Belousov.Fn destroy_dev_sched_cb
484fe754649SKonstantin Belousovfirst appeared in
485fe754649SKonstantin Belousov.Fx 7.0 .
486f36575b5SJaakko HeinonenThe function
487f36575b5SJaakko Heinonen.Fn make_dev_p
488f36575b5SJaakko Heinonenfirst appeared in
489f36575b5SJaakko Heinonen.Fx 8.2 .
490*48ce5d4cSKonstantin BelousovThe function
491*48ce5d4cSKonstantin Belousov.Fn make_dev_s
492*48ce5d4cSKonstantin Belousovfirst appeared in
493*48ce5d4cSKonstantin Belousov.Fx 11.0 .
494